mcma_edit.php 14 KB

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