mcsa.php 16 KB

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