yesno.php 15 KB

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