question.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. <?php
  2. include "Connection.php";
  3. $conn = new Connection();
  4. if(isset($_REQUEST["funName"])) {
  5. $db = $conn->getConnection();
  6. $fun = $_REQUEST["funName"];
  7. switch($fun) {
  8. case "questionlist":
  9. case "addquestion":
  10. case "editquestion":
  11. case "deletequestion":
  12. case "questionoptionlist":
  13. case "questiondetails":
  14. $fun();
  15. break;
  16. }
  17. }
  18. // QUESTION LIST
  19. function questionlist() {
  20. global $conn;
  21. try{
  22. $lang = (isset($_REQUEST["lang"]))?$_REQUEST["lang"]:'en_us';
  23. //$pageData = $conn->loadJSON($lang);
  24. $pn = escape_str($_REQUEST["pn"]);
  25. $nr = escape_str($_REQUEST["nr"]);
  26. $key = escape_str($_REQUEST["key"]);
  27. $cateid = escape_str($_REQUEST['cateid']);
  28. if(isset($_SESSION["userid"])) {
  29. // Search
  30. if (!empty($key)) {
  31. $econd= " AND ((a.questiontext like '%".$key."%') OR (f.questiontype like '%$key%') ) ";
  32. }
  33. if ($cateid!='') {
  34. $econd.= " and a.cateid='".$cateid."'";
  35. }
  36. $certified = escape_str($_REQUEST['certified']);
  37. if ($certified!='') {
  38. $econd.= " and a.cateid>'0'";
  39. }
  40. $tag = escape_str($_REQUEST['tag']);
  41. if ($tag!='') {
  42. $econd.= " and a.tag='".$tag."'";
  43. }
  44. $selectstr = "SELECT SQL_CALC_FOUND_ROWS a.id,a.id as qid,a.cateid,a.questiontypeid, a.tag, a.`questiontext`, a.`qimage`, a.`qvideo`, a.`creatorid`, a.`status`,f.questiontype FROM ".TABLE_QUESTION." a INNER JOIN " . TABLE_QUESTIONTYPE . " f ON f.id = a.questiontypeid WHERE 1=1 ".$econd." ORDER BY a.id DESC";
  45. // Pagination
  46. if (!empty($pn) and !empty($nr)) {
  47. // Navigation
  48. $selectstr .= " limit " . (($pn - 1) * $nr) . ", " . $nr;
  49. }
  50. $query = $conn->query($selectstr);
  51. // Total records
  52. $rows_query = $conn->query("select FOUND_ROWS() as total_records");
  53. $rows_result = $rows_query->fetchAll(PDO::FETCH_OBJ);
  54. $total_records = $rows_result[0]->total_records;
  55. $question_arr=$query->fetchAll(PDO::FETCH_OBJ);
  56. if(count($question_arr)>0)
  57. {
  58. require_once (dirname(__FILE__).'/awsfileserver.php');
  59. $s3=awsfileserver::connectS3();
  60. foreach($question_arr as $qkey=>$res_ques)
  61. {
  62. $check_ques_str = "SELECT * FROM ".TABLE_ASSESSMENT_QUESTION." WHERE qid = '".$res_ques->id."' LIMIT 1";
  63. $check_ques_query = $conn->query($check_ques_str);
  64. $question_arr[$qkey]->is_edit=($check_ques_query->rowCount()>0)?"0":"1";
  65. $image_url='';
  66. if($res_ques->qimage!='')
  67. {
  68. $obj = new stdClass();
  69. $obj->key_name=S3_QUESTION_URL.$res_ques->qimage;
  70. $url=awsfileserver::getS3Url($s3,S3_BUCKET,$obj);
  71. $image_url=$url;
  72. }
  73. $question_arr[$qkey]->qimage_url=$image_url;
  74. $video_url='';
  75. if($res_ques->qvideo!='')
  76. {
  77. $obj = new stdClass();
  78. $obj->key_name=S3_QUESTION_URL.$res_ques->qvideo;
  79. $url=awsfileserver::getS3Url($s3,S3_BUCKET,$obj);
  80. $video_url=$url;
  81. }
  82. $question_arr[$qkey]->qvideo_url=$video_url;
  83. switch($res_ques->questiontypeid)
  84. {
  85. case '1':
  86. case '2':
  87. $question_arr[$qkey]->type='1';
  88. break;
  89. case '3':
  90. case '4':
  91. case '5':
  92. case '6':
  93. $question_arr[$qkey]->type='2';
  94. break;
  95. }
  96. }
  97. }
  98. $arr['total_records'] = $total_records;
  99. $arr['questions'] = $question_arr;
  100. if(count($arr) != 0)
  101. {
  102. $conn->message(true,$conn->getMessage($lang,'question','success1'),$arr );
  103. }else{
  104. $conn->message(false,$conn->getMessage($lang,'question','error3'));
  105. }
  106. }else{
  107. $conn->message(false,$conn->getMessage($lang,'question','error1'));
  108. }
  109. }catch(PDOException $e){
  110. $conn->message(false,$conn->getMessage($lang,'question','error4'));
  111. }
  112. }
  113. // ADD QUESTION
  114. function addquestion() {
  115. global $conn;
  116. try {
  117. $lang = (isset($_REQUEST["lang"]))?$_REQUEST["lang"]:'en_us';
  118. if(isset($_SESSION["userid"])){
  119. $userid = $_SESSION["userid"];
  120. $questiontext = escape_str($_REQUEST["questiontext"]);
  121. $questiontypeid = escape_str($_REQUEST["questiontypeid"]);
  122. $cateid= (isset($_REQUEST["cateid"]))?escape_str($_REQUEST["cateid"]):'0';
  123. $tag = escape_str($_REQUEST["tag"]);
  124. if(!($questiontext!='' && $questiontypeid!='' && $tag!='')) $conn->message(false,"Data Missing");
  125. $childs = (isset($_REQUEST["child"]) && in_array($questiontypeid,array('1','2','5','6')))?json_decode($_REQUEST["child"]):array();
  126. //$supplierid = (in_array($questiontypeid,array('1','2')))?$supplierid:0;
  127. switch($questiontypeid)
  128. {
  129. case "1":
  130. case "2":
  131. case "5":
  132. case "6":
  133. if(!(count($childs)>0 && is_array($childs))){ $conn->message(false,$conn->getMessage($lang,'question','error5')); }
  134. $is_correct=0;
  135. if(count($childs)>0)
  136. {
  137. for($n = 0;$n < count($childs);$n++)
  138. {
  139. if(isset($childs[$n]->iscorrect) && $childs[$n]->iscorrect=='1'){ $is_correct=1; }
  140. }
  141. if( $is_correct=='0' && $questiontypeid<5){ $conn->message(false,$conn->getMessage($lang,'question','error6')); }
  142. }
  143. break;
  144. case "3":
  145. case "4":
  146. break;
  147. }
  148. $insertstr = "INSERT INTO ".TABLE_QUESTION." ( questiontext, questiontypeid,cateid,tag,status, creatorid, created_on, modified_on) VALUES('".$questiontext."', '".$questiontypeid."','".$cateid."','".$tag."', '1', '".$userid."', '".NOW."', '".NOW."')";
  149. $insertquery = $conn->query($insertstr);
  150. $insertid = $conn->lastinsetid();
  151. // FILE UPLOAD
  152. if(isset($_FILES['file']) && $_FILES['file']['name']) {
  153. // S3 UPLOAD
  154. require_once (dirname(__FILE__).'/awsfileserver.php');
  155. $file_name = $_FILES['file']['name'];
  156. $fileParts = pathinfo($file_name);
  157. $fileExtension = strtolower($fileParts['extension']);
  158. $filetype = $fileExtension;
  159. $obj = new stdClass();
  160. $obj->filekey = 'file';
  161. //S3 OBJ
  162. $s3 = awsfileserver::connectS3();
  163. if($filetype != 'mp4')
  164. {
  165. $obj->size = '10'; //IN MB
  166. $obj->type = array('jpg','jpeg','png');
  167. $conn->validateFile($obj);
  168. $obj->path = "../".S3_QUESTION_URL;
  169. $obj->filename = 'question_image_'.date('Ymd')."_".uniqid();
  170. $qimage = $conn->uploadFile($obj);
  171. awsfileserver::checkupload($s3,S3_BUCKET,S3_QUESTION_URL.$qimage,dirname(__FILE__)."/../".S3_QUESTION_URL.$qimage);
  172. //DELETE AFTER MOVE TO S3
  173. @unlink(dirname(__FILE__).'/../'.S3_QUESTION_URL.$qimage);
  174. $updatestr = "UPDATE ".TABLE_QUESTION." SET qimage = '".$qimage."' WHERE id='".$insertid."'";
  175. }
  176. else {
  177. $obj->size = '512';
  178. $obj->type = array('mp4');
  179. $conn->validateFile($obj);
  180. $obj->path = "../".S3_QUESTION_URL;
  181. $obj->filename = 'question_video_'.date('Ymd')."_".uniqid();
  182. $qvideo = $conn->uploadFile($obj);
  183. awsfileserver::checkupload($s3,S3_BUCKET,S3_QUESTION_URL.$qvideo,dirname(__FILE__)."/../".S3_QUESTION_URL.$qvideo);
  184. //DELETE AFTER MOVE TO S3
  185. @unlink(dirname(__FILE__).'/../'.S3_QUESTION_URL.$qvideo);
  186. $updatestr = "UPDATE ".TABLE_QUESTION." SET qvideo = '".$qvideo."' WHERE id='".$insertid."'";
  187. }
  188. $updatequery = $conn->query($updatestr);
  189. }
  190. // Question options data inserting
  191. if((in_array($questiontypeid,array('1','2','5','6'))))
  192. {
  193. if($childs) {
  194. for($id = 0;$id < count($childs);$id++){
  195. $iscorrect = (isset($childs[$id]->iscorrect) && $childs[$id]->iscorrect=='1')?"1":"0";
  196. $opttext = escape_str($childs[$id]->opttext);
  197. $score = $childs[$id]->score;
  198. $choiceinsert_arr[] = " ('".$insertid."','".$opttext."','".$score."','".$iscorrect."','".$userid."','".NOW."','".NOW."')";
  199. }
  200. $choiceinsertstr = "INSERT INTO ".TABLE_QUESTIONOPTION." (qid, opttext, score, iscorrect, creatorid, created_on, modified_on) VALUES ".@implode(',',$choiceinsert_arr);
  201. $choiceinsertquery = $conn->query($choiceinsertstr);
  202. }
  203. }
  204. $conn->message(true,$conn->getMessage($lang,'question','success1'),getQuestion ($insertid));
  205. }
  206. else {
  207. $conn->message(false,$conn->getMessage($lang,'question','error1'));
  208. }
  209. }catch(PDOException $e){
  210. echo $e;
  211. $conn->message(false,$conn->getMessage($lang,'question','error4'));
  212. }
  213. }
  214. // UPDATE QUESTION
  215. function editquestion() {
  216. global $conn;
  217. try {
  218. $lang = (isset($_REQUEST["lang"]))?$_REQUEST["lang"]:'en_us';
  219. if(isset($_SESSION["userid"])){
  220. $id = escape_str($_REQUEST["id"]);
  221. $userid = $_SESSION["userid"];
  222. //$supplierid = $_REQUEST["supplierid"];
  223. $questiontext = escape_str($_REQUEST["questiontext"]);
  224. $questiontypeid = escape_str($_REQUEST["questiontypeid"]);
  225. $childs = (isset($_REQUEST["child"]))?json_decode($_REQUEST["child"]):array();
  226. $cateid= (isset($_REQUEST["cateid"]))?escape_str($_REQUEST["cateid"]):'0';
  227. $tag = escape_str($_REQUEST["tag"]);
  228. if(!($questiontext!='' && $questiontypeid!='' && $tag!='' && $id!='')) $conn->message(false,"Data Missing");
  229. switch($questiontypeid)
  230. {
  231. case "1":
  232. case "2":
  233. case "5":
  234. case "6":
  235. if(!(count($childs)>0 && is_array($childs))){ $conn->message(false,$conn->getMessage($lang,'question','error5'));}
  236. $is_correct=0;
  237. if(count($childs)>0)
  238. {
  239. for($n = 0;$n < count($childs);$n++)
  240. {
  241. if(isset($childs[$n]->iscorrect) && $childs[$n]->iscorrect=='1'){ $is_correct=1; }
  242. }
  243. if( $is_correct=='0' && $questiontypeid<5){ $conn->message(false,$conn->getMessage($lang,'question','error6'));}
  244. }
  245. break;
  246. case "3":
  247. case "4":
  248. break;
  249. }
  250. $check_ques_str = "SELECT * FROM ".TABLE_QUESTION." WHERE id = '".$id."' LIMIT 1";
  251. $check_ques_arr=$conn->getQueryValue($check_ques_str);
  252. if(!(count($check_ques_arr)>0)) $conn->message(false,$conn->getMessage($lang,'question','error9'));
  253. // FILE UPLOAD
  254. if(isset($_FILES['file']) && $_FILES['file']['name']) {
  255. // S3 UPLOAD
  256. require_once (dirname(__FILE__).'/awsfileserver.php');
  257. $file_name = $_FILES['file']['name'];
  258. $fileParts = pathinfo($file_name);
  259. $fileExtension = strtolower($fileParts['extension']);
  260. $filetype = $fileExtension;
  261. $obj = new stdClass();
  262. $obj->filekey = 'file';
  263. $s3 = awsfileserver::connectS3();
  264. if($filetype != 'mp4') {
  265. $obj->size = '10'; //IN MB
  266. $obj->type = array('jpg','jpeg','png');
  267. $conn->validateFile($obj);
  268. $obj->path = "../".S3_QUESTION_URL;
  269. $obj->filename = 'question_image_'.date('Ymd')."_".uniqid();
  270. $qimage = $conn->uploadFile($obj);
  271. awsfileserver::checkupload($s3,S3_BUCKET,S3_QUESTION_URL.$qimage,dirname(__FILE__)."/../".S3_QUESTION_URL.$qimage);
  272. //DELETE AFTER MOVE TO S3
  273. @unlink(dirname(__FILE__).'/../'.S3_QUESTION_URL.$qimage);
  274. $updatestr = "UPDATE ".TABLE_QUESTION." SET qimage = '".$qimage."' WHERE id='".$id."'";
  275. if($check_ques_arr[0]->qimage!='')
  276. {
  277. //awsfileserver::deleteobject($s3,S3_BUCKET,S3_QUESTION_URL.$check_ques_arr[0]->qimage);
  278. }
  279. }
  280. else
  281. {
  282. $obj->size = '512';
  283. $obj->type = array('mp4');
  284. $conn->validateFile($obj);
  285. $obj->path = "../".S3_QUESTION_URL;
  286. $obj->filename = 'question_video_'.date('Ymd')."_".uniqid();
  287. $qvideo = $conn->uploadFile($obj);
  288. awsfileserver::checkupload($s3,S3_BUCKET,S3_QUESTION_URL.$qvideo,dirname(__FILE__)."/../".S3_QUESTION_URL.$qvideo);
  289. //DELETE AFTER MOVE TO S3
  290. @unlink(dirname(__FILE__).'/../'.S3_QUESTION_URL.$qvideo);
  291. $updatestr = "UPDATE ".TABLE_QUESTION." SET qvideo = '".$qvideo."' WHERE id='".$id."'";
  292. if($check_ques_arr[0]->qvideo!='')
  293. {
  294. //awsfileserver::deleteobject($s3,S3_BUCKET,S3_QUESTION_URL.$check_ques_arr[0]->qvideo);
  295. }
  296. }
  297. $updatequery = $conn->query($updatestr);
  298. }
  299. $upddate_str = "UPDATE ".TABLE_QUESTION." SET cateid='".$cateid."',questiontext='".$questiontext."',tag='".$tag."',questiontypeid='".$questiontypeid."', creatorid='".$userid."', modified_on = '".NOW."' ".$updatecond." WHERE id='".$id."'";
  300. $insertquery = $conn->query($upddate_str);
  301. //DELETE OPTIONS
  302. $deleteoptstr = "DELETE FROM ".TABLE_QUESTIONOPTION." WHERE qid = '".$id."'";
  303. $deleteoptquery = $conn->query($deleteoptstr);
  304. $qid=$id;
  305. if((in_array($questiontypeid,array('1','2','5','6'))))
  306. {
  307. if($childs) {
  308. for($id = 0;$id < count($childs);$id++){
  309. $iscorrect = (isset($childs[$id]->iscorrect)&& $childs[$id]->iscorrect=='1')?"1":"0";
  310. $opttext = escape_str($childs[$id]->opttext);
  311. $score = $childs[$id]->score;
  312. $choiceinsert_arr[] = " ('".$qid."','".escape_str($opttext)."','".$score."','".$iscorrect."','".$userid."','".NOW."','".NOW."')";
  313. }
  314. $choiceinsertstr = "INSERT INTO ".TABLE_QUESTIONOPTION." (qid, opttext, score, iscorrect, creatorid, created_on, modified_on) VALUES ".@implode(',',$choiceinsert_arr);
  315. $choiceinsertquery = $conn->query($choiceinsertstr);
  316. }
  317. }
  318. $conn->message(true,$conn->getMessage($lang,'question','success1'),getQuestion ($qid));
  319. }else{
  320. $conn->message(false,$conn->getMessage($lang,'question','error1'));
  321. }
  322. }catch(PDOException $e){
  323. $conn->message(false,$conn->getMessage($lang,'question','error4'));
  324. }
  325. }
  326. // DELETE QUESTION
  327. function deletequestion() {
  328. global $conn;
  329. try {
  330. $lang = (isset($_REQUEST["lang"]))?$_REQUEST["lang"]:'en_us';
  331. if(isset($_SESSION["userid"]))
  332. {
  333. $userid = $_SESSION["userid"];
  334. $id = escape_str($_REQUEST["id"]);
  335. $selectassessstr = "SELECT * FROM ".TABLE_ASSESSMENT_QUESTION." WHERE qid='".$id."' LIMIT 1";
  336. $selectassessquesy = $conn->query($selectassessstr);
  337. if($selectassessquesy->rowCount() == 0)
  338. {
  339. $selectquest = "SELECT * FROM ".TABLE_ASSESSMENT_USERRESULT." WHERE qid='".$id."'";
  340. $selectquery = $conn->query($selectquest);
  341. if($selectquery->rowCount() == 0) {
  342. $delete1 = $conn->query("DELETE FROM ".TABLE_QUESTION." WHERE id='".$id."'");
  343. $selectstr = "SELECT * FROM ".TABLE_QUESTIONOPTION." WHERE qid='".$id."'";
  344. $selectquery = $conn->query($selectstr);
  345. $arr = $selectquery->fetchAll(PDO::FETCH_OBJ);
  346. $conn->message(true,$conn->getMessage($lang,'question','success1') );
  347. }
  348. else{
  349. $conn->message(false,$conn->getMessage($lang,'question','error8'));
  350. }
  351. $ques_arr=$conn->getQueryValue($selectassessstr);
  352. //S3 IMAGE REMOVE
  353. $s3 = awsfileserver::connectS3();
  354. if($ques_arr[0]->qimage!='')
  355. {
  356. // awsfileserver::deleteobject($s3,S3_BUCKET,S3_QUESTION_URL.$ques_arr[0]->qimage);
  357. }
  358. //S3 VIDEO REMOVE
  359. if($ques_arr[0]->qvideo!='')
  360. {
  361. //awsfileserver::deleteobject($s3,S3_BUCKET,S3_QUESTION_URL.$ques_arr[0]->qvideo);
  362. }
  363. }else{
  364. $conn->message(false,$conn->getMessage($lang,'question','error7'));
  365. }
  366. }else{
  367. $conn->message(false,$conn->getMessage($lang,'question','error1'));
  368. }
  369. }
  370. catch(PDOException $e) {
  371. $conn->message(false,$conn->getMessage($lang,'question','error4'));
  372. }
  373. }
  374. // Question Option List
  375. function questionoptionlist() {
  376. global $conn;
  377. try {
  378. $lang = (isset($_REQUEST["lang"]))?$_REQUEST["lang"]:'en_us';
  379. if(isset($_SESSION["userid"]))
  380. {
  381. $id = escape_str($_REQUEST["id"]);
  382. $selectstr = "SELECT * FROM " . TABLE_QUESTIONOPTION . " WHERE qid='".$id."'";
  383. $selectquery = $conn->query($selectstr);
  384. $arr = $selectquery->fetchAll(PDO::FETCH_OBJ);
  385. if(!count($arr)>0)
  386. {
  387. $arr=array();
  388. }
  389. $conn->message(true,$conn->getMessage($lang,'question','success1'),$arr );
  390. }
  391. else {
  392. $conn->message(false,$conn->getMessage($lang,'question','error1'));
  393. }
  394. }
  395. catch(PDOException $e) {
  396. $conn->message(false,$conn->getMessage($lang,'question','error4'));
  397. }
  398. }
  399. // GET QUESTION
  400. function getQuestion($qid)
  401. {
  402. global $conn;
  403. $data_arr=array();
  404. if($qid!='')
  405. {
  406. require_once (dirname(__FILE__).'/awsfileserver.php');
  407. $s3=awsfileserver::connectS3();
  408. $data_arr=$conn->getQueryValue( "SELECT a.id,a.id as qid,a.questiontypeid,a.cateid, a.tag,a.`questiontext`, a.`qimage`, a.`qvideo`, a.`creatorid`, a.`status`,f.questiontype FROM ".TABLE_QUESTION." a INNER JOIN " . TABLE_QUESTIONTYPE . " f ON f.id = a.questiontypeid WHERE a.id='".$qid."' LIMIT 1");
  409. if(count($data_arr)>0)
  410. {
  411. $check_ques_str = "SELECT * FROM ".TABLE_ASSESSMENT_QUESTION." WHERE qid = '".$qid."' LIMIT 1";
  412. $check_ques_query = $conn->query($check_ques_str);
  413. $data_arr[0]->is_edit=($check_ques_query->rowCount()>0)?"0":"1";
  414. }
  415. $image_url='';
  416. if($data_arr[0]->qimage!='')
  417. {
  418. $obj = new stdClass();
  419. $obj->key_name=S3_QUESTION_URL.$data_arr[0]->qimage;
  420. $url=awsfileserver::getS3Url($s3,S3_BUCKET,$obj);
  421. $image_url=$url;
  422. }
  423. $data_arr[0]->qimage_url=$image_url;
  424. $video_url='';
  425. if($data_arr[0]->qvideo!='')
  426. {
  427. $obj = new stdClass();
  428. $obj->key_name=S3_QUESTION_URL.$data_arr[0]->qvideo;
  429. $url=awsfileserver::getS3Url($s3,S3_BUCKET,$obj);
  430. $video_url=$url;
  431. }
  432. $data_arr[0]->qvideo_url=$video_url;
  433. $data_arr=(count($data_arr)>0)?$data_arr[0]:array();
  434. }
  435. return $data_arr;
  436. }
  437. // Question
  438. function questiondetails() {
  439. global $conn;
  440. try {
  441. $lang = (isset($_REQUEST["lang"]))?$_REQUEST["lang"]:'en_us';
  442. if(isset($_SESSION["userid"]))
  443. {
  444. $id = escape_str($_REQUEST["id"]);
  445. $selectstr = "SELECT a.id,a.id as qid,a.cateid,a.questiontypeid, a.tag, a.`questiontext`, a.`qimage`, a.`qvideo`, a.`creatorid`, a.`status`,f.questiontype FROM ".TABLE_QUESTION." a INNER JOIN " . TABLE_QUESTIONTYPE . " f ON f.id = a.questiontypeid WHERE a.id='".$id."' LIMIT 1";
  446. $query = $conn->query($selectstr);
  447. $arr = $query->fetchAll(PDO::FETCH_OBJ);
  448. if(count($arr)>0)
  449. {
  450. $selectstr = "SELECT * FROM " . TABLE_QUESTIONOPTION . " WHERE qid='".$id."'";
  451. $selectquery = $conn->query($selectstr);
  452. $options = $selectquery->fetchAll(PDO::FETCH_OBJ);
  453. $arr[0]->options=(count($options)>0)?$options:array();
  454. }else
  455. {
  456. $arr=array();
  457. }
  458. $conn->message(true,$conn->getMessage($lang,'question','success1'),$arr );
  459. }
  460. else {
  461. $conn->message(false,$conn->getMessage($lang,'question','error1'));
  462. }
  463. }
  464. catch(PDOException $e) {
  465. $conn->message(false,$conn->getMessage($lang,'question','error4'));
  466. }
  467. }
  468. ?>