mcma.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. <?
  2. $langFile = 'survey';
  3. require_once ('../inc/global.inc.php');
  4. //api_protect_admin_script();
  5. require_once ("select_question.php");
  6. if(isset($_REQUEST['questtype']))
  7. $add_question12=$_REQUEST['questtype'];
  8. else
  9. $add_question12=$_REQUEST['add_question'];
  10. require_once (api_get_path(LIBRARY_PATH).'/fileManage.lib.php');
  11. require_once (api_get_path(CONFIGURATION_PATH) ."/add_course.conf.php");
  12. require_once (api_get_path(LIBRARY_PATH)."/add_course.lib.inc.php");
  13. require_once (api_get_path(LIBRARY_PATH)."/surveymanager.lib.php");
  14. $status = surveymanager::get_status();
  15. if($status==5)
  16. {
  17. api_protect_admin_script();
  18. }
  19. require_once (api_get_path(LIBRARY_PATH)."/usermanager.lib.php");
  20. $cidReq=$_GET['cidReq'];
  21. $curr_dbname = $_REQUEST['curr_dbname'];
  22. $add_question = $_REQUEST['add_question'];
  23. $groupid = $_REQUEST['groupid'];
  24. $surveyid = $_REQUEST['surveyid'];
  25. $table_survey = Database :: get_course_table('survey');
  26. $table_group = Database :: get_course_table('survey_group');
  27. $table_question = Database :: get_course_table('questions');
  28. $Add = get_lang("addnewquestiontype");
  29. $Multi = get_lang("MultipleChoiceMulti");
  30. $interbredcrump[] = array ("url" => "survey_list.php?cidReq=$cidReq&n=$n", "name" => get_lang('Survey'));
  31. //$interbredcrump[] = array ("url" => "survey.php?cidReq=$cidReq&n=$n", "name" => get_lang('CreateSurvey'));
  32. /*
  33. if($n=="n")
  34. $interbredcrump[] = array ("url" => "create_new_survey.php?cidReq=$cidReq&n=$n", "name" => get_lang('New_survey'));
  35. else
  36. $interbredcrump[] = array ("url" => "create_from_existing.php?cidReq=$cidReq&n=$n", "name" => get_lang('New_survey'));
  37. */
  38. //$n=$_REQUEST['n'];
  39. if ($_POST['action'] == 'addquestion')
  40. {
  41. $groupid = $_REQUEST['groupid'];
  42. $surveyid = $_REQUEST['surveyid'];
  43. $questtype = $_REQUEST['questtype'];
  44. $enter_question=$_POST['enterquestion'];
  45. if(isset($_POST['next']))
  46. {
  47. $enter_question=$_POST['enterquestion'];
  48. $answers=$_POST['mutlichkboxtext'];
  49. $rating=$_POST['chkboxpoint'];
  50. $answerT=$_POST['chkboxdefault1'];
  51. $answerD=$_POST['chkboxdefault'];
  52. $alignment=$_POST['alignment'];
  53. $open_ans="";
  54. $count=count($_POST['mutlichkboxtext']);
  55. $default=0;
  56. $true=0;
  57. $noans=0;
  58. $nopoint=0;
  59. for($i=0;$i<$count;$i++)
  60. {
  61. $answers[$i]=trim($answers[$i]);
  62. if(!empty($answerT[$i]))
  63. $true++;
  64. if(!empty($answerD[$i]))
  65. $default++;
  66. if(empty($answers[$i]))
  67. $noans++;
  68. if(!is_numeric($rating[$i]))
  69. $number=1;
  70. }
  71. $enter_question=trim($enter_question);
  72. if(empty($enter_question))
  73. $error_message = get_lang('PleaseEnterAQuestion')."<br>";
  74. if ($noans)
  75. $error_message = $error_message."<br>".get_lang('PleasFillAllAnswer');
  76. //if($number==1)
  77. //$error_message = $error_message."<br>".get_lang('PleaseFillNumber');
  78. //if($nopoint)
  79. //$error_message = $error_message."<br>".get_lang('PleaseFillAllPoints');
  80. //if($true<1)
  81. //$error_message=$error_message."<br>".get_lang('PleaseSelectOneTrue');
  82. //if($default<1)
  83. //$error_message=$error_message."<br>".get_lang('PleaseSelectOneDefault');
  84. if(isset($error_message));
  85. //Display::display_error_message($error_message);
  86. else
  87. {
  88. $groupid = $_REQUEST['groupid'];
  89. $questtype = $_REQUEST['questtype'];
  90. $curr_dbname = $_REQUEST['curr_dbname'];
  91. $surveyid = $_REQUEST['surveyid'];
  92. $enter_question = addslashes($enter_question); SurveyManager::create_question($groupid,$surveyid,$questtype,$enter_question,$alignment,$answers,$open_ans,$answerT,$answerD,$rating,$curr_dbname);
  93. $cidReq = $_GET['cidReq']; header("location:select_question_group.php?groupid=$groupid&surveyid=$surveyid&cidReq=$cidReq&curr_dbname=$curr_dbname");
  94. exit;
  95. }
  96. }
  97. elseif(isset($_POST['back']))
  98. {
  99. $groupid = $_REQUEST['groupid'];
  100. $surveyid = $_REQUEST['surveyid'];
  101. $cidReq = $_GET['cidReq'];
  102. $curr_dbname = $_REQUEST['curr_dbname'];
  103. header("location:addanother.php?groupid=$groupid&surveyid=$surveyid&cidReq=$cidReq&curr_dbname=$curr_dbname");
  104. exit;
  105. }
  106. elseif(isset($_POST['saveandexit']))
  107. {
  108. $enter_question=$_POST['enterquestion'];
  109. $answers=$_POST['mutlichkboxtext'];
  110. $rating=$_POST['chkboxpoint'];
  111. $answerT=$_POST['chkboxdefault1'];
  112. $answerD=$_POST['chkboxdefault'];
  113. $alignment=$_POST['alignment'];
  114. $open_ans="";
  115. $count=count($_POST['mutlichkboxtext']);
  116. $default=0;
  117. $true=0;
  118. $noans=0;
  119. $nopoint=0;
  120. for($i=0;$i<$count;$i++)
  121. {
  122. $answers[$i]=trim($answers[$i]);
  123. if(!empty($answerT[$i]))
  124. $true++;
  125. if(!empty($answerD[$i]))
  126. $default++;
  127. if(empty($answers[$i]))
  128. $noans++;
  129. if(empty($rating[$i])&&($rating[$i]!='0'))
  130. $nopoint++;
  131. }
  132. $enter_question=trim($enter_question);
  133. if(empty($enter_question))
  134. $error_message = get_lang('PleaseEnterAQuestion')."<br>";
  135. if ($noans)
  136. $error_message = $error_message."<br>".get_lang('PleasFillAllAnswer');
  137. //if($nopoint)
  138. //$error_message = $error_message."<br>".get_lang('PleaseFillAllPoints');
  139. //if($true<1)
  140. //$error_message=$error_message."<br>".get_lang('PleaseSelectOneTrue');
  141. //if($default<1)
  142. //$error_message=$error_message."<br>".get_lang('PleaseSelectOneDefault');
  143. if(isset($error_message));
  144. //Display::display_error_message($error_message);
  145. else
  146. {
  147. $groupid = $_REQUEST['groupid'];
  148. $cidReq = $_GET['cidReq'];
  149. $curr_dbname = $_REQUEST['curr_dbname'];
  150. $surveyid = $_REQUEST['surveyid'];
  151. $enter_question = addslashes($enter_question); SurveyManager::create_question($groupid,$surveyid,$questtype,$enter_question,$alignment,$answers,$open_ans,$answerT,$answerD,$rating,$curr_dbname);
  152. header("location:survey_list.php?cidReq=$cidReq&n=$n");
  153. exit;
  154. }
  155. }
  156. }
  157. ?>
  158. <?
  159. $tool = get_lang('AddAnotherQuestion');
  160. Display::display_header($tool);
  161. ?>
  162. <script type="text/javascript">
  163. function changeAction()
  164. {
  165. var x=document.getElementById("myForm")
  166. x.action="preview_mcma.php"
  167. return true;
  168. }
  169. </script>
  170. <?
  171. select_question_type($add_question12,$groupid,$surveyid,$cidReq,$curr_dbname);
  172. ?>
  173. <table>
  174. <tr>
  175. <td>
  176. <? api_display_tool_title($Add);?>
  177. </td>
  178. <td>
  179. <? api_display_tool_title($Multi);?>
  180. </td>
  181. </tr>
  182. </table>
  183. <?php
  184. if( isset($error_message) )
  185. {
  186. Display::display_error_message($error_message);
  187. }
  188. ?>
  189. <SCRIPT LANGUAGE="JAVASCRIPT">
  190. function checkLength(form){
  191. if (form.description.value.length > 250){
  192. alert("Text too long. Must be 250 characters or less");
  193. return false;
  194. }
  195. return true;
  196. }
  197. </SCRIPT>
  198. <form method="POST" name ="mcma" id="myForm" action="<?php echo $_SERVER['PHP_SELF'];?>?cidReq=<?=$cidReq?>&add_question=<?=$add_question?>&groupid=<?=$groupid?>&surveyid=<?=$surveyid?>&curr_dbname=<?=$curr_dbname?>">
  199. <input type="hidden" name="groupid" value="<?=$groupid?>">
  200. <input type="hidden" name="surveyid" value="<?=$surveyid?>">
  201. <input type="hidden" name="questtype" value="<?=$add_question12?>">
  202. <input type="hidden" name="curr_dbname" value="<?=$curr_dbname?>">
  203. <!--<input type="hidden" name="cidReq" value="<?=$cidReq?>">-->
  204. <input type="hidden" name="action" value="addquestion" >
  205. <table width="100%" border="0" cellspacing="0" cellpadding="0" class="outerBorder_innertable">
  206. <tr><td>
  207. <tr>
  208. <td valign="top"><strong><?php echo get_lang('SelectDisplayType'); ?></strong>&nbsp;</td>
  209. </tr>
  210. <tr><td>
  211. <input type="radio" name="alignment" value="horizontal" checked>Horizontal</td>
  212. </tr>
  213. <tr><td>
  214. <input type="radio" name="alignment" value="vertical">Vertical</td>
  215. </tr>
  216. </td></tr>
  217. <tr><td><br></td></tr>
  218. <tr>
  219. <td class="pagedetails_heading"><a class="form_text_bold"><strong>Question</strong></a></td>
  220. </tr>
  221. </table>
  222. <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="outerBorder_innertable">
  223. <tr class="white_bg">
  224. <td height="30" class="form_text1">
  225. Enter the question.
  226. </td>
  227. <td class="form_text1" align="right">&nbsp;
  228. </td>
  229. </tr>
  230. <tr class="form_bg">
  231. <td width="542" height="30" colspan="2" ><?php api_disp_html_area('enterquestion',stripslashes($enterquestion),'200px');?><!--<textarea name="enterquestion" id="enterquestion" cols="50" rows="6" class="text_field" style="width:100%;" ><?if(isset($_POST['enterquestion']))echo $_POST['enterquestion'];?></textarea>-->
  232. </td>
  233. </tr>
  234. </table>
  235. <br>
  236. <table width="100%" border="0" cellspacing="0" cellpadding="0" class="outerBorder_innertable">
  237. <tr>
  238. <td class="pagedetails_heading"><a class="form_text_bold"><strong>Answer</strong></a></td>
  239. </tr>
  240. </table>
  241. <table width="100%" border="0" cellspacing="0" cellpadding="0" class="outerBorder_innertable">
  242. <tr class="white_bg">
  243. <td height="30"><span class="form_text1">Enter the answers</span>.
  244. </td>
  245. <td>&nbsp;</td>
  246. <td width="192" align="right">&nbsp; </td>
  247. </tr>
  248. </table>
  249. <table ID="tblFields" width="70%" border="0" cellpadding="0" cellspacing="0" class="outerBorder_innertable">
  250. <?php
  251. $start=1;$end=5;$upx=2;$upy=1;$dwnx=0;$dwny=1;$jd=0;$sn=1;
  252. $id="id";
  253. $tempmutlichkboxtext="jkjk";
  254. $tempchkboxdefault="jkjk";
  255. $tempchkboxpoint="jkjk";
  256. $tempchkboxdefault1="jkjk";
  257. $up="up";
  258. $down="down";
  259. $flag=1;
  260. if(isset($_POST['mutlichkboxtext']))
  261. $end=count($_POST['mutlichkboxtext']);
  262. //echo ",before 1st loop end=".$end;
  263. for($i=$start;$i<=$end;$i++)
  264. {
  265. $id="id".$i."_x";
  266. //echo ",".$id;
  267. if(isset($_POST[$id]))
  268. {
  269. $jd=$i;
  270. $flag=0;
  271. $end=count($_POST['mutlichkboxtext']);
  272. if($end<=3)
  273. {
  274. $end=3;
  275. }
  276. else
  277. $end-=1;
  278. break;
  279. //echo ",while checking id,end=".$end;
  280. }
  281. }
  282. for($i=$start;$i<=$end;$i++)
  283. {
  284. $up="up".$i."_x";
  285. $down="down".$i."_x";
  286. if(isset($_POST[$up])||isset($_POST[$down]))
  287. {
  288. //if(isset($_POST['up2_x']))
  289. $flag=0;
  290. if(isset($_POST[$up]))
  291. {
  292. $tempmutlichkboxtext=$_POST['mutlichkboxtext'];
  293. $tempchkboxdefault=$_POST['chkboxdefault'];
  294. $tempchkboxpoint=$_POST['chkboxpoint'];
  295. $tempchkboxdefault1=$_POST['chkboxdefault1'];
  296. $tempm= $tempmutlichkboxtext[$i-2];
  297. $tempchkboxd=$tempchkboxdefault[$i-2];
  298. $tempchkboxp=$tempchkboxpoint[$i-2];
  299. $tempchkboxd1=$tempchkboxdefault1[$i-2];
  300. $tempmutlichkboxtext[$i-2]=$tempmutlichkboxtext[$i-1];
  301. $tempchkboxdefault[$i-2]=$tempchkboxdefault[$i-1];
  302. $tempchkboxpoint[$i-2]=$tempchkboxpoint[$i-1];
  303. $tempchkboxdefault1[$i-2]=$tempchkboxdefault1[$i-1];
  304. $tempmutlichkboxtext[$i-1]=$tempm;
  305. $tempchkboxdefault[$i-1]=$tempchkboxd;
  306. $tempchkboxpoint[$i-1]=$tempchkboxp;
  307. $tempchkboxdefault1[$i-1]=$tempchkboxd1;
  308. $_POST['mutlichkboxtext']=$tempmutlichkboxtext;
  309. $_POST['chkboxdefault']=$tempchkboxdefault;
  310. $_POST['chkboxpoint']=$tempchkboxpoint;
  311. $_POST['chkboxdefault1']=$tempchkboxdefault1;
  312. }
  313. if(isset($_POST[$down]))
  314. {
  315. $tempmutlichkboxtext=$_POST['mutlichkboxtext'];
  316. $tempchkboxdefault=$_POST['chkboxdefault'];
  317. $tempchkboxpoint=$_POST['chkboxpoint'];
  318. $tempchkboxdefault1=$_POST['chkboxdefault1'];
  319. $tempm= $tempmutlichkboxtext[$i];
  320. $tempchkboxd=$tempchkboxdefault[$i];
  321. $tempchkboxp=$tempchkboxpoint[$i];
  322. $tempchkboxd1=$tempchkboxdefault1[$i];
  323. $tempmutlichkboxtext[$i]=$tempmutlichkboxtext[$i-1];
  324. $tempchkboxdefault[$i]=$tempchkboxdefault[$i-1];
  325. $tempchkboxpoint[$i]=$tempchkboxpoint[$i-1];
  326. $tempchkboxdefault1[$i]=$tempchkboxdefault1[$i-1];
  327. $tempmutlichkboxtext[$i-1]=$tempm;
  328. $tempchkboxdefault[$i-1]=$tempchkboxd;
  329. $tempchkboxpoint[$i-1]=$tempchkboxp;
  330. $tempchkboxdefault1[$i-1]=$tempchkboxd1;
  331. $_POST['mutlichkboxtext']=$tempmutlichkboxtext;
  332. $_POST['chkboxdefault']=$tempchkboxdefault;
  333. $_POST['chkboxpoint']=$tempchkboxpoint;
  334. $_POST['chkboxdefault1']=$tempchkboxdefault1;
  335. }
  336. //echo ",while checking up/down end=".$end;
  337. $jd=0;
  338. break;
  339. }
  340. }
  341. if($flag==1)
  342. {
  343. if(isset($_POST['addnewrows']))
  344. {
  345. $end=count($_POST['mutlichkboxtext']);
  346. if($end<10)
  347. {
  348. $end=$end+$_POST['addnewrows'];
  349. if($end>10)
  350. $end=10;
  351. }
  352. else
  353. {
  354. $end=10;
  355. $error_message = get_lang('YouCanntAddmorethanTen')."<br>";
  356. if( isset($error_message) )
  357. {
  358. Display::display_error_message($error_message);
  359. }
  360. }
  361. //echo ",while checking select end=".$end;
  362. /*else
  363. $end=$end+$_POST['addnewrows'];*/
  364. }
  365. }
  366. //echo ",after select end=".$end;
  367. for($i=$start;$i<=$end;$i++)
  368. {
  369. if($i==$jd)
  370. /*{
  371. if($end<=3);
  372. else;
  373. //continue;
  374. }*/
  375. {
  376. $end++;
  377. }
  378. else
  379. {
  380. $k=$i-1;
  381. $post_text = $_POST['mutlichkboxtext'];
  382. $post_check=$_POST['chkboxdefault'];
  383. $post_point=$_POST['chkboxpoint'];
  384. $post_true=$_POST['chkboxdefault1'];
  385. ?>
  386. <tr class="form_bg" id="0">
  387. <td width="16" height="30" align="left" class="form_text">
  388. <? echo $sn;?>
  389. </td>
  390. <td class="form_bg"><textarea name="mutlichkboxtext[]" cols="50" rows="3" class="text_field" style="width:100%;"><?=$post_text[$k]?></textarea>
  391. </td>
  392. <td width="10" class="form_text"><img src="../img/blank.gif" width="10" height="8">
  393. </td>
  394. <td width="10" class="form_text"><img src="../img/blank.gif" width="10" height="8">
  395. </td>
  396. <? if($i>$start)
  397. {
  398. ?>
  399. <td width="30" align="center" class="form_text1">
  400. <input type="image" src="../img/up.gif" width="24" height="24" border="0" onclick="this.form.submit();" name="<?echo "up".$i;?>" style="cursor:hand">
  401. </td>
  402. <? }
  403. else
  404. {
  405. ?> <td width="30" align="center" class="form_text1">
  406. </td>
  407. <? }
  408. $sn++;
  409. ?>
  410. <? if($i<$end)
  411. {
  412. ?>
  413. <td width="30" align="center" class="form_text">
  414. <input type="image" src="../img/down.gif" width="24" height="24" border="0" onclick="this.form.submit();" name="<?echo "down".$i;?>" style="cursor:hand">
  415. </td>
  416. <? }
  417. else
  418. {
  419. ?> <td width="30" align="center" class="form_text1">
  420. </td>
  421. <? }
  422. ?>
  423. <td width="30" align="center" class="form_text">
  424. <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();">
  425. </tr>
  426. <? }
  427. }
  428. ?>
  429. </table>
  430. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  431. <tr class="white_bg">
  432. <td height="30"><span class="form_text1">Add&nbsp;&nbsp;</span>
  433. <select name="addnewrows" class="text_field_small" style="width:100px" onChange="this.form.submit();">
  434. <!--<option value="1" <?if(isset($_POST['addnewrows'])){if($_POST['addnewrows']=="1")echo "selected";}?>>1</option>
  435. <option value="2" <?if(isset($_POST['addnewrows'])){if($_POST['addnewrows']=="2")echo "selected";}?>>2</option>
  436. <option value="3" <?if(isset($_POST['addnewrows'])){if($_POST['addnewrows']=="3")echo "selected";}?>>3</option>
  437. <option value="4" <?if(isset($_POST['addnewrows'])){if($_POST['addnewrows']=="4")echo "selected";}?>>4</option>
  438. <option value="5" <?if(isset($_POST['addnewrows'])){if($_POST['addnewrows']=="5")echo "selected";}?>>5</option>-->
  439. <option value="0" >0</option>
  440. <option value="1" >1</option>
  441. <option value="2" >2</option>
  442. <option value="3" >3</option>
  443. <option value="4" >4</option>
  444. <option value="5" >5</option>
  445. </select>
  446. <a class="form_text1">New Answer</a>
  447. <span class="form_text"><span class="form_text1">
  448. </td>
  449. </tr>
  450. </table>
  451. <br>
  452. <br>
  453. <div align="center">
  454. <!--
  455. <input type="hidden" name="type" value="mcma">-->
  456. <input type="HIDDEN" name="end1" value="<?=$end?>">
  457. <? if(isset($_POST['add_question']))
  458. {
  459. ?> <input type="hidden" name="add_question" value="<? echo $_POST['add_question'];?>" >
  460. <? }
  461. $sql = "SELECT * FROM $curr_dbname.survey WHERE survey_id='$surveyid'";
  462. $res=api_sql_query($sql);
  463. $obj=mysql_fetch_object($res);
  464. switch($obj->template)
  465. {
  466. case "template1":
  467. $temp = 'white';
  468. break;
  469. case "template2":
  470. $temp = 'bluebreeze';
  471. break;
  472. case "template3":
  473. $temp = 'brown';
  474. break;
  475. case "template4":
  476. $temp = 'grey';
  477. break;
  478. case "template5":
  479. $temp = 'blank';
  480. break;
  481. }
  482. ?>
  483. <input type="submit" name="back" value="<?=get_lang("back");?>">
  484. <input type="submit" name="saveandexit" value="<?=get_lang("saveandexit");?>">
  485. <input type="button" value="<?php echo get_lang('preview');?>" onClick="preview('mcma','<?=$temp?>','<?=$Multi?>')">
  486. <input type="submit" name="next" value="<?=get_lang("next");?>">
  487. </div>
  488. <!--this partcular field helps in identify the item to be add at the itemadd.php-->
  489. </form>
  490. </div>
  491. <div id=bottomnav align="center"></DIV>
  492. </body>
  493. </html>
  494. <SCRIPT LANGUAGE="JavaScript">
  495. function preview(form,temp,qtype)
  496. {
  497. var ques = editor.getHTML();
  498. //alert(ques);
  499. var id_str = "";
  500. for(i=0;i<eval("document."+form+"['mutlichkboxtext[]'].length");i++)
  501. {
  502. var box = (eval("document."+form+"['mutlichkboxtext[]']["+i+"]"));
  503. id_str += box.value+"|";
  504. }
  505. window.open(temp+'.php?ques='+ques+'&ans='+id_str+'&qtype='+qtype, 'popup', 'width=800,height=600,scrollbars=yes,toolbar = no, status = no');
  506. }
  507. </script>
  508. <?php
  509. Display :: display_footer();
  510. ?>