mcsa_edit.php 12 KB

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