mcma_edit.php 12 KB

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