yesno_edit.php 14 KB

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