numbered.php 15 KB

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