numbered_edit.php 12 KB

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