yesno_edit.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <?php
  2. $langFile = 'survey';
  3. require_once ('../inc/global.inc.php');
  4. //api_protect_admin_script();
  5. require_once ("select_question.php");
  6. require_once (api_get_path(LIBRARY_PATH).'/fileManage.lib.php');
  7. require_once (api_get_path(CONFIGURATION_PATH) ."/add_course.conf.php");
  8. require_once (api_get_path(LIBRARY_PATH)."/add_course.lib.inc.php");
  9. require_once (api_get_path(LIBRARY_PATH)."/surveymanager.lib.php");
  10. $status = surveymanager::get_status();
  11. if($status==5)
  12. {
  13. api_protect_admin_script();
  14. }
  15. require_once (api_get_path(LIBRARY_PATH)."/usermanager.lib.php");
  16. $n=$_REQUEST['n'];
  17. $interbredcrump[] = array ("url" => "survey_list.php?cidReq=$cidReq&n=$n", "name" => get_lang('Survey'));
  18. $cidReq = $_REQUEST['cidReq'];
  19. $curr_dbname = $_REQUEST['curr_dbname'];
  20. $groupid=$_REQUEST['groupid'];
  21. $surveyid=$_REQUEST['surveyid'];
  22. $qid=$_REQUEST['qid'];
  23. $qtype=$_REQUEST['qtype'];
  24. $table_question = Database :: get_course_table('questions');
  25. $Add = get_lang("updatequestiontype");
  26. $Multi = get_lang("yesno");
  27. $tool_name = $Add.$Multi;
  28. $rs=SurveyManager::get_question_data($qid,$curr_dbname);
  29. if(isset($_REQUEST['questtype']))
  30. $add_question12=$_REQUEST['questtype'];
  31. else
  32. $add_question12=$rs->qtype;
  33. if(isset($_POST['update']))
  34. {
  35. $qid=$_POST['qid'];
  36. $alignment='';
  37. if(isset($_POST['enterquestion']))
  38. $enter_question=$_POST['enterquestion'];
  39. else
  40. $enter_question=$rs->caption;
  41. if(isset($_POST['mutlichkboxtext']))
  42. $answers=$_POST['mutlichkboxtext'];
  43. else
  44. {
  45. $answers=array();
  46. $i=1;
  47. while($rs)
  48. {
  49. $ans=a.$i;
  50. $answers[]=$rs->$ans;
  51. $i++;
  52. }
  53. }
  54. $open_ans="";
  55. $count=count($_POST['mutlichkboxtext']);
  56. $noans=0;
  57. $nopoint=0;
  58. for($i=0;$i<$count;$i++)
  59. {
  60. $answers[$i]=trim($answers[$i]);
  61. if(empty($answers[$i]))
  62. $noans++;
  63. }
  64. $enter_question=trim($enter_question);
  65. if(empty($enter_question))
  66. $error_message = get_lang('PleaseEnterAQuestion')."<br>";
  67. if ($noans)
  68. $error_message = $error_message."<br>".get_lang('PleasFillAllAnswer');
  69. if(isset($error_message))
  70. {
  71. //Display::display_error_message($error_message);
  72. }
  73. else
  74. {
  75. //$groupid = $_POST['groupid'];
  76. //if(isset($_REQUEST['questtype']))
  77. //$questtype = $_REQUEST['questtype'];
  78. //else
  79. $questtype=$rs->qtype;
  80. $curr_dbname = $_REQUEST['curr_dbname'];
  81. $enter_question = addslashes($enter_question);
  82. SurveyManager::update_question($qid,$questtype,$enter_question,$alignment,$answers,$open_ans,$curr_dbname);
  83. $cidReq = $_GET['cidReq']; header("location:select_question_group.php?groupid=$groupid&surveyid=$surveyid&cidReq=$cidReq&curr_dbname=$curr_dbname");
  84. exit;
  85. }
  86. }
  87. elseif(isset($_POST['back']))
  88. {
  89. $groupid = $_REQUEST['groupid'];
  90. $surveyid = $_REQUEST['surveyid'];
  91. $cidReq = $_GET['cidReq'];
  92. $curr_dbname = $_REQUEST['curr_dbname']; header("location:select_question_group.php?groupid=$groupid&surveyid=$surveyid&cidReq=$cidReq&curr_dbname=$curr_dbname");
  93. exit;
  94. }
  95. elseif(isset($_POST['saveandexit']))
  96. {
  97. $groupid = $_REQUEST['groupid'];
  98. $surveyid = $_REQUEST['surveyid'];
  99. $questtype = $_REQUEST['questtype'];
  100. $curr_dbname = $_REQUEST['curr_dbname'];
  101. $enter_question = addslashes($enter_question); SurveyManager::create_question($groupid,$surveyid,$questtype,$enter_question,$alignment,$answers,$open_ans,$answerT,$answerD,$rating,$curr_dbname);
  102. $cidReq = $_GET['cidReq'];
  103. header("location:survey_list.php?cidReq=$cidReq");
  104. exit;
  105. }
  106. ?>
  107. <?
  108. Display::display_header($tool_name);
  109. api_display_tool_title($tool_name);
  110. if( isset($error_message) )
  111. {
  112. Display::display_error_message($error_message);
  113. }
  114. ?>
  115. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  116. <div id=content>
  117. <form method="POST" name="yesno" id="yesno" action="<?php echo $_SERVER['PHP_SELF'];?>?qid=<?=$qid?>&cidReq=<?=$cidReq?>&groupid=<?=$groupid?>&surveyid=<?=$surveyid?>&curr_dbname=<?=$curr_dbname?>">
  118. <input type="hidden" name="qid" value="<?=$qid?>">
  119. <input type="hidden" name="groupid" value="<?=$groupid?>">
  120. <input type="hidden" name="surveyid" value="<?=$surveyid?>">
  121. <input type="hidden" name="qid" value="<?=$qid?>">
  122. <input type="hidden" name="questtype" value="<?=$add_question12?>">
  123. <input type="hidden" name="cidReq" value="<?=$cidReq?>">
  124. <input type="hidden" name="curr_dbname" value="<?=$curr_dbname?>">
  125. <input type="hidden" name="action" value="addquestion" >
  126. <table width="100%" border="0" cellspacing="0" cellpadding="0" class="outerBorder_innertable">
  127. <tr>
  128. <td class="pagedetails_heading"><a class="form_text_bold"><strong>Question</strong></a></td>
  129. </tr>
  130. </table>
  131. <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="outerBorder_innertable">
  132. <tr class="white_bg">
  133. <td height="30" class="form_text1">
  134. Enter the question.
  135. </td>
  136. <td class="form_text1" align="right">&nbsp;
  137. </td>
  138. <tr class="form_bg">
  139. <td width="542" height="30" colspan="2" ><?php api_disp_html_area('enterquestion',$rs->caption,'200px');?>
  140. </td>
  141. <!--<textarea name="enterquestion" id="enterquestion" cols="50" rows="6" class="text_field" style="width:75%;"><?
  142. if(isset($_POST['enterquestion']))
  143. echo $_POST['enterquestion'];
  144. else
  145. echo $rs->caption;
  146. ?></textarea>-->
  147. </td>
  148. </tr>
  149. </table>
  150. <br>
  151. <table width="100%" border="0" cellspacing="0" cellpadding="0" class="outerBorder_innertable">
  152. <tr>
  153. <td class="pagedetails_heading"><a class="form_text_bold"><strong>Answer</strong></a></td>
  154. </tr>
  155. </table>
  156. <table width="100%" border="0" cellspacing="0" cellpadding="0" class="outerBorder_innertable">
  157. <tr class="white_bg">
  158. <td height="30"><span class="form_text1">Enter the answers</span>.
  159. </td>
  160. <td>&nbsp;</td>
  161. <td width="192" align="right">&nbsp; </td>
  162. </tr>
  163. </table>
  164. <table ID="tblFields" width="70%" border="0" cellpadding="0" cellspacing="0" class="outerBorder_innertable">
  165. <?php
  166. $start=1;$end=2;$upx=2;$upy=1;$dwnx=0;$dwny=1;$jd=0;$sn=1;
  167. $id="id";
  168. $tempmutlichkboxtext="jkjk";
  169. $tempchkboxpoint="jkjk";
  170. $up="up";
  171. $down="down";
  172. $flag=1;
  173. if(isset($_POST['mutlichkboxtext']))
  174. $end=count($_POST['mutlichkboxtext']);
  175. for($i=$start;$i<=$end;$i++)
  176. {
  177. $id="id".$i."_x";
  178. if(isset($_POST[$id]))
  179. {
  180. $jd=$i;
  181. $flag=0;
  182. $end=count($_POST['mutlichkboxtext']);
  183. if($end<=3)
  184. {
  185. $end=3;
  186. }
  187. else
  188. $end-=1;
  189. break;
  190. }
  191. }
  192. for($i=$start;$i<=$end;$i++)
  193. {
  194. $up="up".$i."_x";
  195. $down="down".$i."_x";
  196. $ans="a".$i;
  197. $score="r".$i;
  198. if(isset($_POST[$up])||isset($_POST[$down]))
  199. {
  200. $flag=0;
  201. if(isset($_POST[$up]))
  202. {
  203. if(isset($_POST['mutlichkboxtext']))
  204. $tempmutlichkboxtext=$_POST['mutlichkboxtext'];
  205. else
  206. $tempmutlichkboxtext=$rs->$ans['mutlichkboxtext'];
  207. if(isset($_POST['chkboxpoint']))
  208. $tempchkboxpoint=$_POST['chkboxpoint'];
  209. else
  210. $tempchkboxpoint=$rs->$score;
  211. $tempm= $tempmutlichkboxtext[$i-2];
  212. $tempchkboxp=$tempchkboxpoint[$i-2];
  213. $tempmutlichkboxtext[$i-2]=$tempmutlichkboxtext[$i-1];
  214. $tempchkboxpoint[$i-2]=$tempchkboxpoint[$i-1];
  215. $tempmutlichkboxtext[$i-1]=$tempm;
  216. $tempchkboxpoint[$i-1]=$tempchkboxp;
  217. if(isset($_POST['mutlichkboxtext']))
  218. $_POST['mutlichkboxtext']=$tempmutlichkboxtext;
  219. else
  220. $rs->$ans=$tempmutlichkboxtext;
  221. if(isset($_POST['chkboxpoint']))
  222. $_POST['chkboxpoint']=$tempchkboxpoint;
  223. else
  224. $rs->$score=$tempchkboxpoint;
  225. }
  226. if(isset($_POST[$down]))
  227. {
  228. if(isset($_POST['mutlichkboxtext']))
  229. $tempmutlichkboxtext=$_POST['mutlichkboxtext'];
  230. else
  231. $tempmutlichkboxtext=$rs->$ans['mutlichkboxtext'];
  232. if(isset($_POST['chkboxpoint']))
  233. $tempchkboxpoint=$_POST['chkboxpoint'];
  234. else
  235. $tempchkboxpoint=$rs->$score;
  236. $tempm= $tempmutlichkboxtext[$i];
  237. $tempchkboxp=$tempchkboxpoint[$i];
  238. $tempmutlichkboxtext[$i]=$tempmutlichkboxtext[$i-1];
  239. $tempchkboxpoint[$i]=$tempchkboxpoint[$i-1];
  240. $tempmutlichkboxtext[$i-1]=$tempm;
  241. $tempchkboxpoint[$i-1]=$tempchkboxp;
  242. if(isset($_POST['mutlichkboxtext']))
  243. $_POST['mutlichkboxtext']=$tempmutlichkboxtext;
  244. else
  245. $rs->$ans=$tempmutlichkboxtext;
  246. if(isset($_POST['chkboxpoint']))
  247. $_POST['chkboxpoint']=$tempchkboxpoint;
  248. else
  249. $rs->$score=$tempchkboxpoint;
  250. }
  251. //echo ",while checking up/down end=".$end;
  252. $jd=0;
  253. break;
  254. }
  255. }
  256. if($flag==1)
  257. {
  258. if(isset($_POST['addnewrows']))
  259. {
  260. $end=count($_POST['mutlichkboxtext']);
  261. if($end<10)
  262. {
  263. $end=$end+$_POST['addnewrows'];
  264. if($end>10)
  265. $end=10;
  266. }
  267. else
  268. $end=10;
  269. }
  270. }
  271. for($i=$start;$i<=$end;$i++)
  272. {
  273. if($i==$jd)
  274. {
  275. $end++;
  276. }
  277. else
  278. {
  279. $k=$i-1;
  280. $val="a".$i;
  281. $sco="r".$i;
  282. if(isset($_POST['mutlichkboxtext']))
  283. {
  284. $post_text1=$_POST['mutlichkboxtext'];
  285. $post_text = $post_text1[$i-1];
  286. }
  287. else
  288. $post_text=$rs->$val;
  289. if(isset($_POST['chkboxpoint']))
  290. {
  291. $post_point1=$_POST['chkboxpoint'];
  292. $post_point=$post_point1[$i-1];
  293. }
  294. else
  295. $post_point=$rs->$sco;
  296. ?>
  297. <tr class="form_bg" id="0">
  298. <td width="16" height="30" align="left" class="form_text">
  299. <? echo $sn;?>
  300. </td>
  301. <td class="form_bg"><textarea name="mutlichkboxtext[]" cols="50" rows="3" class="text_field" style="width:100%;"><?=$post_text?></textarea>
  302. </td>
  303. <td width="10" class="form_text"><img src="../img/blank.gif" width="10" height="8">
  304. </td>
  305. <td width="10" class="form_text"><img src="../img/blank.gif" width="10" height="8">
  306. </td>
  307. <td width="30" align="center" class="form_text">&nbsp;
  308. </td>
  309. <? if($i>$start)
  310. {
  311. ?>
  312. <td width="30" align="center" class="form_text1">
  313. <input type="image" src="../img/up.gif" width="24" height="24" border="0" onclick="this.form.submit();" name="<?echo "up".$i;?>" style="cursor:hand">
  314. </td>
  315. <? }
  316. else
  317. {
  318. ?> <td width="30" align="center" class="form_text1">
  319. </td>
  320. <? }
  321. $sn++;
  322. ?>
  323. <? if($i<$end)
  324. {
  325. ?>
  326. <td width="30" align="center" class="form_text">
  327. <input type="image" src="../img/down.gif" width="24" height="24" border="0" onclick="this.form.submit();" name="<?echo "down".$i;?>" style="cursor:hand">
  328. </td>
  329. <? }
  330. else
  331. {
  332. ?> <td width="30" align="center" class="form_text1">
  333. </td>
  334. <? }
  335. ?>
  336. <td width="30" align="center" class="form_text">
  337. </tr>
  338. <? }
  339. }
  340. ?>
  341. </table>
  342. <br>
  343. <br>
  344. <div align="center">
  345. <input type="HIDDEN" name="end1" value="<?=$end?>">
  346. <?
  347. if(isset($_POST['add_question']))
  348. {
  349. ?> <input type="hidden" name="add_question" value="<? echo $_POST['add_question'];?>" >
  350. <? }
  351. $sql = "SELECT * FROM $curr_dbname.survey WHERE survey_id='$surveyid'";
  352. $res=api_sql_query($sql);
  353. $obj=mysql_fetch_object($res);
  354. switch($obj->template)
  355. {
  356. case "template1":
  357. $temp = 'white';
  358. break;
  359. case "template2":
  360. $temp = 'bluebreeze';
  361. break;
  362. case "template3":
  363. $temp = 'brown';
  364. break;
  365. case "template4":
  366. $temp = 'grey';
  367. break;
  368. case "template5":
  369. $temp = 'blank';
  370. break;
  371. }
  372. ?>
  373. <input type="submit" name="back" value="<?=get_lang("back");?>">
  374. <input type="button" value="<?php echo get_lang('preview');?>" onClick="preview('yesno','<?=$temp?>','<?=$Multi?>')">
  375. <input type="submit" name="update" value="<?=get_lang("update");?>">
  376. <!--<input name="preview" value="<?=get_lang("preview");?>" type="submit" onClick="return changeAction()" > -->
  377. <!--<input type="submit" name="next" value="<?=get_lang("next");?>"> -->
  378. </div>
  379. <!--this partcular field helps in identify the item to be add at the itemadd.php-->
  380. </form>
  381. </div>
  382. <div id=bottomnav align="center"></DIV>
  383. </body>
  384. </html>
  385. <SCRIPT LANGUAGE="JavaScript">
  386. function preview(form,temp,qtype)
  387. {
  388. var ques = editor.getHTML();
  389. var id_str = "";
  390. for(i=0;i<eval("document."+form+"['mutlichkboxtext[]'].length");i++)
  391. {
  392. var box = (eval("document."+form+"['mutlichkboxtext[]']["+i+"]"));
  393. id_str += box.value+"|";
  394. }
  395. window.open(temp+'.php?temp=<?=$temp;?>&ques='+ques+'&ans='+id_str+'&qtype='+qtype, 'popup', 'width=800,height=600,scrollbars=yes,toolbar = no, status = no');
  396. }
  397. </script>
  398. <?php
  399. Display :: display_footer();
  400. ?>