numbered.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. <?php
  2. /*
  3. DOKEOS - elearning and course management software
  4. For a full list of contributors, see documentation/credits.html
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. See "documentation/licence.html" more details.
  10. Contact:
  11. Dokeos
  12. Rue des Palais 44 Paleizenstraat
  13. B-1030 Brussels - Belgium
  14. Tel. +32 (2) 211 34 56
  15. */
  16. /**
  17. * @package dokeos.survey
  18. * @author
  19. * @version $Id: numbered.php 10705 2007-01-12 22:40:01Z pcool $
  20. */
  21. // name of the language file that needs to be included
  22. $language_file = 'survey';
  23. // including the global dokeos file
  24. require_once ('../inc/global.inc.php');
  25. // including additional libraries
  26. /** @todo check if these are all needed */
  27. /** @todo check if the starting / is needed. api_get_path probably ends with an / */
  28. require_once ("select_question.php");
  29. require_once (api_get_path(LIBRARY_PATH).'/fileManage.lib.php');
  30. require_once (api_get_path(CONFIGURATION_PATH) ."/add_course.conf.php");
  31. require_once (api_get_path(LIBRARY_PATH)."/add_course.lib.inc.php");
  32. require_once (api_get_path(LIBRARY_PATH)."/surveymanager.lib.php");
  33. require_once (api_get_path(LIBRARY_PATH)."/usermanager.lib.php");
  34. /** @todo replace this with the correct code */
  35. /*
  36. $status = surveymanager::get_status();
  37. api_protect_course_script();
  38. if($status==5)
  39. {
  40. api_protect_admin_script();
  41. }
  42. */
  43. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  44. if (!api_is_allowed_to_edit())
  45. {
  46. Display :: display_header();
  47. Display :: display_error_message(get_lang('NotAllowedHere'));
  48. Display :: display_footer();
  49. exit;
  50. }
  51. // Database table definitions
  52. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  53. $table_group = Database :: get_course_table(TABLE_SURVEY_GROUP);
  54. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  55. $table_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
  56. if(isset($_REQUEST['questtype']))
  57. {
  58. $add_question12=$_REQUEST['questtype'];
  59. }
  60. else
  61. {
  62. $add_question12=$_REQUEST['add_question'];
  63. }
  64. $add_question = $_REQUEST['add_question'];
  65. $groupid = $_REQUEST['groupid'];
  66. $surveyid = $_REQUEST['surveyid'];
  67. $Add = get_lang('AddNewQuestionType');
  68. $Multi = get_lang('Numbered');
  69. $groupid = $_REQUEST['groupid'];
  70. $surveyid = $_REQUEST['surveyid'];
  71. $interbreadcrumb[] = array ("url" => "survey_list.php?n=$n", "name" => get_lang('Survey'));
  72. //$n=$_REQUEST['n'];
  73. if ($_POST['action'] == 'addquestion')
  74. {
  75. $enter_question=$_POST['enterquestion'];
  76. if(isset($_POST['next']))
  77. {
  78. $enter_question=$_POST['enterquestion'];
  79. $answers=$_POST['mutlichkboxtext'];
  80. $rating=$_POST['chkboxpoint'];
  81. $answerT=$_POST['radiotrue'];
  82. $answerD=$_POST['radiodefault'];
  83. $alignment='';
  84. $open_ans="";
  85. $count=count($_POST['mutlichkboxtext']);
  86. $noans=0;
  87. $nopoint=0;
  88. for($i=0;$i<$count;$i++)
  89. {
  90. $answers[$i]=trim($answers[$i]);
  91. if(empty($answers[$i]))
  92. $noans++;
  93. if($rating[$i]<1||$rating[$i]>5)
  94. $nopoint++;
  95. }
  96. $enter_question=trim($enter_question);
  97. if(empty($enter_question))
  98. $error_message = get_lang('PleaseEnterAQuestion')."<br>";
  99. if ($noans)
  100. $error_message = $error_message."<br>".get_lang('PleasFillAllAnswer');
  101. //if($nopoint)
  102. //$error_message = $error_message."<br>".get_lang('PleaseFillAllPoints');
  103. //if(empty($_POST['radiotrue']))
  104. // $error_message=$error_message."<br>".get_lang('PleaseSelectOneTrue');
  105. //if(empty($_POST['radiodefault']))
  106. //$error_message=$error_message."<br>".get_lang('PleaseSelectOneDefault');
  107. if(isset($error_message));
  108. //Display::display_error_message($error_message);
  109. else
  110. {
  111. $groupid = $_POST['groupid'];
  112. $questtype = $_REQUEST['questtype'];
  113. $surveyid = $_REQUEST['surveyid'];
  114. $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");
  115. exit;
  116. }
  117. }
  118. elseif(isset($_POST['back']))
  119. {
  120. $groupid = $_REQUEST['groupid'];
  121. $surveyid = $_REQUEST['surveyid'];
  122. header("location:addanother.php?groupid=$groupid&surveyid=$surveyid");
  123. exit;
  124. }
  125. elseif(isset($_POST['saveandexit']))
  126. {
  127. $enter_question=$_POST['enterquestion'];
  128. $answers=$_POST['mutlichkboxtext'];
  129. $rating=$_POST['chkboxpoint'];
  130. $answerT=$_POST['radiotrue'];
  131. $answerD=$_POST['radiodefault'];
  132. $alignment='';
  133. $open_ans="";
  134. $count=count($_POST['mutlichkboxtext']);
  135. $noans=0;
  136. $nopoint=0;
  137. for($i=0;$i<$count;$i++)
  138. {
  139. $answers[$i]=trim($answers[$i]);
  140. if(empty($answers[$i]))
  141. $noans++;
  142. if(empty($rating[$i])&&($rating[$i]!='0'))
  143. $nopoint++;
  144. }
  145. $enter_question=trim($enter_question);
  146. if(empty($enter_question))
  147. $error_message = get_lang('PleaseEnterAQuestion')."<br>";
  148. if ($noans)
  149. $error_message = $error_message."<br>".get_lang('PleasFillAllAnswer');
  150. //if($nopoint)
  151. //$error_message = $error_message."<br>".get_lang('PleaseFillAllPoints');
  152. //if(empty($_POST['radiotrue']))
  153. // $error_message=$error_message."<br>".get_lang('PleaseSelectOneTrue');
  154. //if(empty($_POST['radiodefault']))
  155. //$error_message=$error_message."<br>".get_lang('PleaseSelectOneDefault');
  156. if(isset($error_message));
  157. //Display::display_error_message($error_message);
  158. else
  159. {
  160. $groupid = $_REQUEST['groupid'];
  161. $questtype = $_REQUEST['questtype'];
  162. $surveyid = $_REQUEST['surveyid'];
  163. $enter_question = addslashes($enter_question); SurveyManager::create_question($groupid,$surveyid,$questtype,$enter_question,$alignment,$answers,$open_ans,$answerT,$answerD,$rating,$curr_dbname);
  164. header("location:survey_list.php?n=$n");
  165. exit;
  166. }
  167. }
  168. }
  169. $tool = get_lang('AddAnotherQuestion');
  170. Display::display_header($tool);
  171. select_question_type($add_question12,$groupid,$surveyid,$cidReq,$curr_dbname);
  172. ?>
  173. <table>
  174. <tr>
  175. <td>
  176. <?php api_display_tool_title($Add);?>
  177. </td>
  178. <td>
  179. <?php 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="numbered" name="frmitemchkboxmulti" action="<?php echo $_SERVER['PHP_SELF'];?>?add_question=<?php echo $add_question; ?>&groupid=<?php echo $groupid; ?>&surveyid=<?php echo $surveyid; ?>&curr_dbname=<?php echo $curr_dbname; ?>">
  199. <input type="hidden" name="groupid" value="<?php echo $groupid; ?>">
  200. <input type="hidden" name="surveyid" value="<?php echo $surveyid; ?>">
  201. <input type="hidden" name="questtype" value="<?php echo $add_question12; ?>">
  202. <input type="hidden" name="curr_dbname" value="<?php echo $curr_dbname; ?>">
  203. <input type="hidden" name="action" value="addquestion" >
  204. <table width="100%" border="0" cellspacing="0" cellpadding="0" class="outerBorder_innertable">
  205. <tr>
  206. <td class="pagedetails_heading"><a class="form_text_bold"><strong>Question</strong></a></td>
  207. </tr>
  208. </table>
  209. <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="outerBorder_innertable">
  210. <tr class="white_bg">
  211. <td height="30" class="form_text1">
  212. Enter the question.
  213. </td>
  214. <td class="form_text1" align="right">&nbsp;
  215. </td>
  216. </tr>
  217. <tr class="form_bg">
  218. <td width="542" height="30" colspan="2" >
  219. <?php
  220. require_once(api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php");
  221. $oFCKeditor = new FCKeditor('enterquestion') ;
  222. $oFCKeditor->BasePath = api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ;
  223. $oFCKeditor->Height = '300';
  224. $oFCKeditor->Width = '400';
  225. $oFCKeditor->Value = stripslashes($enter_question);
  226. $oFCKeditor->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig.js";
  227. $oFCKeditor->ToolbarSet = "Survey";
  228. $sql="SELECT isocode FROM ".$table_languages." WHERE english_name='".$_SESSION["_course"]["language"]."'";
  229. $result_sql=api_sql_query($sql);
  230. $isocode_language=mysql_result($result_sql,0,0);
  231. $oFCKeditor->Config['DefaultLanguage'] = $isocode_language;
  232. $return = $oFCKeditor->CreateHtml();
  233. echo $return;
  234. ?>
  235. </td>
  236. </tr>
  237. </table>
  238. <br>
  239. <table width="100%" border="0" cellspacing="0" cellpadding="0" class="outerBorder_innertable">
  240. <tr>
  241. <td class="pagedetails_heading"><a class="form_text_bold"><strong>Answer</strong></a></td>
  242. </tr>
  243. </table>
  244. <table width="100%" border="0" cellspacing="0" cellpadding="0" class="outerBorder_innertable">
  245. <tr class="white_bg">
  246. <td height="30"><span class="form_text1">Enter the answers</span>.
  247. </td>
  248. <td>&nbsp;</td>
  249. <td width="192" align="right">&nbsp; </td>
  250. </tr>
  251. </table>
  252. <!--table for adding the multiple answers-->
  253. <!--<a name="tbl">-->
  254. <table ID="tblFields" width="70%" border="0" cellpadding="0" cellspacing="0" class="outerBorder_innertable">
  255. <?php
  256. $start=1;$end=5;$upx=2;$upy=1;$dwnx=0;$dwny=1;$jd=0;$sn=1;
  257. $id="id";
  258. $tempmutlichkboxtext="jkjk";
  259. if(isset($_POST['radiodefault']))
  260. $tempradiodefault=$_POST['radiodefault'];
  261. else
  262. $tempradiodefault=1;
  263. $tempchkboxpoint="jkjk";
  264. $up="up";
  265. $down="down";
  266. $flag=1;
  267. if(isset($_POST['mutlichkboxtext']))
  268. $end=count($_POST['mutlichkboxtext']);
  269. for($i=$start;$i<=$end;$i++)
  270. {
  271. $id="id".$i."_x";
  272. //echo ",".$id;
  273. if(isset($_POST[$id]))
  274. {
  275. $jd=$i;
  276. $flag=0;
  277. $end=count($_POST['mutlichkboxtext']);
  278. if($end<=3)
  279. {
  280. $end=3;
  281. }
  282. else
  283. $end-=1;
  284. break;
  285. //echo ",while checking id,end=".$end;
  286. }
  287. }
  288. for($i=$start;$i<=$end;$i++)
  289. {
  290. $up="up".$i."_x";
  291. $down="down".$i."_x";
  292. if(isset($_POST[$up])||isset($_POST[$down]))
  293. {
  294. $flag=0;
  295. if(isset($_POST[$up]))
  296. {
  297. $tempmutlichkboxtext=$_POST['mutlichkboxtext'];
  298. if($tempradiodefault==$i)
  299. $tempradiodefault--;
  300. elseif($tempradiodefault==$i-1)
  301. $tempradiodefault++;
  302. $tempchkboxpoint=$_POST['chkboxpoint'];
  303. $tempm= $tempmutlichkboxtext[$i-2];
  304. $tempchkboxp=$tempchkboxpoint[$i-2];
  305. $tempmutlichkboxtext[$i-2]=$tempmutlichkboxtext[$i-1];
  306. $tempchkboxpoint[$i-2]=$tempchkboxpoint[$i-1];
  307. $tempmutlichkboxtext[$i-1]=$tempm;
  308. $tempchkboxpoint[$i-1]=$tempchkboxp;
  309. $_POST['mutlichkboxtext']=$tempmutlichkboxtext;
  310. $_POST['chkboxpoint']=$tempchkboxpoint;
  311. }
  312. if(isset($_POST[$down]))
  313. {
  314. $tempmutlichkboxtext=$_POST['mutlichkboxtext'];
  315. if($tempradiodefault==$i)
  316. $tempradiodefault++;
  317. elseif($tempradiodefault==$i+1)
  318. $tempradiodefault--;
  319. $tempchkboxpoint=$_POST['chkboxpoint'];
  320. $tempm= $tempmutlichkboxtext[$i];
  321. $tempchkboxp=$tempchkboxpoint[$i];
  322. $tempmutlichkboxtext[$i]=$tempmutlichkboxtext[$i-1];
  323. $tempchkboxpoint[$i]=$tempchkboxpoint[$i-1];
  324. $tempmutlichkboxtext[$i-1]=$tempm;
  325. $tempchkboxpoint[$i-1]=$tempchkboxp;
  326. $_POST['mutlichkboxtext']=$tempmutlichkboxtext;
  327. $_POST['chkboxpoint']=$tempchkboxpoint;
  328. }
  329. //echo ",while checking up/down end=".$end;
  330. $jd=0;
  331. break;
  332. }
  333. }
  334. if($flag==1)
  335. {
  336. if(isset($_POST['addnewrows']))
  337. {
  338. $end=count($_POST['mutlichkboxtext']);
  339. if($end<10)
  340. {
  341. $end=$end+$_POST['addnewrows'];
  342. if($end>10)
  343. $end=10;
  344. }
  345. else
  346. {
  347. $end=10;
  348. $error_message = get_lang('YouCantAddMoreThanTen')."<br>";
  349. if( isset($error_message) )
  350. {
  351. Display::display_error_message($error_message);
  352. }
  353. }
  354. //echo ",while checking select end=".$end;
  355. /*else
  356. $end=$end+$_POST['addnewrows'];*/
  357. }
  358. }
  359. //echo ",after select end=".$end;
  360. for($i=$start;$i<=$end;$i++)
  361. {
  362. if($i==$jd)
  363. /*{
  364. if($end<=3);
  365. else;
  366. //continue;
  367. }*/
  368. {
  369. $end++;
  370. }
  371. else
  372. {
  373. $k=$i-1;
  374. $post_text = $_POST['mutlichkboxtext'];
  375. //$post_check=$_POST['radiodefault'];
  376. $post_point=$_POST['chkboxpoint'];
  377. //$post_true=$_POST['radiotrue'];
  378. ?>
  379. <tr class="form_bg" id="0" >
  380. <td width="16" height="30" align="left" class="form_text">
  381. <?php echo $sn;?>
  382. </td>
  383. <td class="form_bg"><textarea name="mutlichkboxtext[]" cols="50" rows="3" class="text_field" style="width:100%;"><?php echo $post_text[$k]; ?></textarea>
  384. </td>
  385. <td width="10" class="form_text"><img src="../img/blank.gif" width="10" height="8">
  386. </td>
  387. <?php if($i>$start)
  388. {
  389. ?>
  390. <td width="30" align="center" class="form_text1">
  391. <input type="image" src="../img/up.gif" width="24" height="24" border="0" onclick="this.form.submit();" name="<?php echo "up".$i;?>" style="cursor:hand">
  392. </td>
  393. <?php }
  394. else
  395. {
  396. ?> <td width="30" align="center" class="form_text1">
  397. </td>
  398. <?php }
  399. $sn++;
  400. ?>
  401. <?php if($i<$end)
  402. {
  403. ?>
  404. <td width="30" align="center" class="form_text">
  405. <input type="image" src="../img/down.gif" width="24" height="24" border="0" onclick="this.form.submit();" name="<?php echo "down".$i;?>" style="cursor:hand">
  406. </td>
  407. <?php }
  408. else
  409. {
  410. ?> <td width="30" align="center" class="form_text1">
  411. </td>
  412. <?php }
  413. ?>
  414. <td width="30" align="center" class="form_text">
  415. <input type="image" src="../img/delete.gif" width="24" height="24" border="0" style="cursor:hand" name="<?php echo "id".$i;?>" value="<?php echo $end; ?>" onclick="this.form.submit();">
  416. </tr>
  417. <?php }
  418. }
  419. ?>
  420. </table>
  421. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  422. <tr class="white_bg">
  423. <td height="30"><span class="form_text1">Add&nbsp;&nbsp;</span>
  424. <select name="addnewrows" class="text_field_small" style="width:100px" onChange="this.form.submit();">
  425. <option value="0" >0</option>
  426. <option value="1" >1</option>
  427. <option value="2" >2</option>
  428. <option value="3" >3</option>
  429. <option value="4" >4</option>
  430. <option value="5" >5</option>
  431. </select>
  432. <a class="form_text1">New Answer</a>
  433. <span class="form_text"><span class="form_text1">
  434. </td>
  435. </tr>
  436. </table>
  437. <br />
  438. <br />
  439. <div align="center">
  440. <input type="hidden" name="end1" value="<?php echo $end; ?>">
  441. <?php if(isset($_POST['add_question']))
  442. {
  443. echo '<input type="hidden" name="add_question" value="'.$_POST['add_question'].'" />';
  444. }
  445. $sql = "SELECT * FROM $table_survey WHERE survey_id='$surveyid'";
  446. $res=api_sql_query($sql);
  447. $obj=mysql_fetch_object($res);
  448. switch($obj->template)
  449. {
  450. case "template1":
  451. $temp = 'white';
  452. break;
  453. case "template2":
  454. $temp = 'bluebreeze';
  455. break;
  456. case "template3":
  457. $temp = 'brown';
  458. break;
  459. case "template4":
  460. $temp = 'grey';
  461. break;
  462. case "template5":
  463. $temp = 'blank';
  464. break;
  465. }
  466. ?>
  467. <input type="submit" name="back" value="<?php echo get_lang('Back'); ?>">
  468. <input type="submit" name="saveandexit" value="<?php echo get_lang('SaveAndExit'); ?>">
  469. <input type="button" value="<?php echo get_lang('Preview');?>" onClick="preview('numbered','<?php echo $temp; ?>','<?php echo $Multi; ?>')">
  470. <input type="submit" name="next" value="<?php echo get_lang('Next'); ?>">
  471. </div>
  472. <!--this partcular field helps in identify the item to be add at the itemadd.php-->
  473. </form>
  474. </div>
  475. <div id=bottomnav align="center"></DIV>
  476. </body>
  477. </html>
  478. <SCRIPT LANGUAGE="JavaScript">
  479. function preview(form,temp,qtype)
  480. {
  481. var ques = editor.getHTML();
  482. //alert(ques);
  483. var id_str = "";
  484. for(i=0;i<eval("document."+form+"['mutlichkboxtext[]'].length");i++)
  485. {
  486. var box = (eval("document."+form+"['mutlichkboxtext[]']["+i+"]"));
  487. id_str += box.value+"|";
  488. }
  489. window.open(temp+'.php?ques='+ques+'&ans='+id_str+'&qtype='+qtype, 'popup', 'width=800,height=600,scrollbars=yes,toolbar = no, status = no');
  490. }
  491. </script>
  492. <?php
  493. Display :: display_footer();
  494. ?>