numbered_edit.php 11 KB

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