yesno.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <?php
  2. $langFile = 'survey';
  3. require_once ('../inc/global.inc.php');
  4. //api_protect_admin_script();
  5. $cidReq=$_GET['cidReq'];
  6. $curr_dbname = $_REQUEST['curr_dbname'];
  7. $add_question = $_REQUEST['add_question'];
  8. $groupid = $_REQUEST['groupid'];
  9. $surveyid = $_REQUEST['surveyid'];
  10. if(isset($_REQUEST['questtype']))
  11. $add_question12=$_REQUEST['questtype'];
  12. else
  13. $add_question12=$_REQUEST['add_question'];
  14. require_once ("select_question.php");
  15. require_once (api_get_path(LIBRARY_PATH).'/fileManage.lib.php');
  16. require_once (api_get_path(CONFIGURATION_PATH) ."/add_course.conf.php");
  17. require_once (api_get_path(LIBRARY_PATH)."/add_course.lib.inc.php");
  18. require_once (api_get_path(LIBRARY_PATH)."/surveymanager.lib.php");
  19. $status = surveymanager::get_status();
  20. if($status==5)
  21. {
  22. api_protect_admin_script();
  23. }
  24. require_once (api_get_path(LIBRARY_PATH)."/usermanager.lib.php");
  25. $interbredcrump[] = array ("url" => "survey_list.php?cidReq=$cidReq&n=$n", "name" => get_lang('Survey'));
  26. $table_question = Database :: get_course_table('questions');
  27. $Add = get_lang("addnewquestiontype");
  28. $Multi = get_lang("yesno");
  29. $groupid = $_REQUEST['groupid'];
  30. $surveyid = $_REQUEST['surveyid'];
  31. //$tool_name = get_lang('QuestionType');
  32. if ($_POST['action'] == 'addquestion')
  33. {
  34. if(isset($_POST['next']))
  35. {
  36. $enter_question=$_POST['enterquestion'];
  37. $answers=$_POST['mutlichkboxtext'];
  38. $rating=$_POST['chkboxpoint'];
  39. $answerT=$_POST['radiotrue'];
  40. $answerD=$_POST['radiodefault'];
  41. $alignment='';
  42. $open_ans="";
  43. $count=count($_POST['mutlichkboxtext']);
  44. $noans=0;
  45. $nopoint=0;
  46. for($i=0;$i<$count;$i++)
  47. {
  48. $answers[$i]=trim($answers[$i]);
  49. if(empty($answers[$i]))
  50. $noans++;
  51. if(!is_numeric($rating[$i]))
  52. $number=1;
  53. }
  54. $enter_question=trim($enter_question);
  55. if(empty($enter_question))
  56. $error_message = get_lang('PleaseEnterAQuestion')."<br>";
  57. if ($noans)
  58. $error_message = $error_message."<br>".get_lang('PleasFillAllAnswer');
  59. if(isset($error_message))
  60. {
  61. //Display::display_error_message($error_message);
  62. }
  63. else
  64. {
  65. $groupid = $_POST['groupid'];
  66. $questtype = $_REQUEST['questtype'];
  67. $curr_dbname = $_REQUEST['curr_dbname'];
  68. $enter_question = addslashes($enter_question); SurveyManager::create_question($groupid,$surveyid,$questtype,$enter_question,$alignment,$answers,$open_ans,$answerT,$answerD,$rating,$curr_dbname);
  69. $cidReq = $_GET['cidReq']; header("location:select_question_group.php?groupid=$groupid&surveyid=$surveyid&cidReq=$cidReq&curr_dbname=$curr_dbname");
  70. exit;
  71. }
  72. }
  73. elseif(isset($_POST['back']))
  74. {
  75. $groupid = $_REQUEST['groupid'];
  76. $surveyid = $_REQUEST['surveyid'];
  77. $cidReq = $_GET['cidReq'];
  78. $curr_dbname = $_REQUEST['curr_dbname'];
  79. header("location:addanother.php?groupid=$groupid&surveyid=$surveyid&cidReq=$cidReq&curr_dbname=$curr_dbname");
  80. exit;
  81. }
  82. elseif(isset($_POST['saveandexit']))
  83. {
  84. $enter_question=$_POST['enterquestion'];
  85. $answers=$_POST['mutlichkboxtext'];
  86. $rating=$_POST['chkboxpoint'];
  87. $answerT=$_POST['radiotrue'];
  88. $answerD=$_POST['radiodefault'];
  89. $alignment='';
  90. $open_ans="";
  91. $count=count($_POST['mutlichkboxtext']);
  92. $noans=0;
  93. $nopoint=0;
  94. for($i=0;$i<$count;$i++)
  95. {
  96. $answers[$i]=trim($answers[$i]);
  97. if(empty($answers[$i]))
  98. $noans++;
  99. if(empty($rating[$i])&&($rating[$i]!='0'))
  100. $nopoint++;
  101. }
  102. $enter_question=trim($enter_question);
  103. if(empty($enter_question))
  104. $error_message = get_lang('PleaseEnterAQuestion')."<br>";
  105. if ($noans)
  106. $error_message = $error_message."<br>".get_lang('PleasFillAllAnswer');
  107. if(isset($error_message))
  108. {
  109. //Display::display_error_message($error_message);
  110. }
  111. else
  112. {
  113. $groupid = $_REQUEST['groupid'];
  114. $surveyid = $_REQUEST['surveyid'];
  115. $questtype = $_REQUEST['questtype'];
  116. $curr_dbname = $_REQUEST['curr_dbname'];
  117. $enter_question = addslashes($enter_question); SurveyManager::create_question($groupid,$surveyid,$questtype,$enter_question,$alignment,$answers,$open_ans,$answerT,$answerD,$rating,$curr_dbname);
  118. $cidReq = $_GET['cidReq'];
  119. header("location:survey_list.php?cidReq=$cidReq&n=$n");
  120. exit;
  121. }
  122. }
  123. }
  124. ?>
  125. <?
  126. $tool = get_lang('AddAnotherQuestion');
  127. Display::display_header($tool);
  128. select_question_type($add_question12,$groupid,$surveyid,$cidReq,$curr_dbname);
  129. ?>
  130. <table>
  131. <tr>
  132. <td>
  133. <? api_display_tool_title($Add);?>
  134. </td>
  135. <td>
  136. <? api_display_tool_title($Multi);?>
  137. </td>
  138. </tr>
  139. </table>
  140. <?php
  141. if( isset($error_message) )
  142. {
  143. Display::display_error_message($error_message);
  144. }
  145. ?>
  146. <SCRIPT LANGUAGE="JAVASCRIPT">
  147. function checkLength(form){
  148. if (form.description.value.length > 250){
  149. alert("Text too long. Must be 250 characters or less");
  150. return false;
  151. }
  152. return true;
  153. }
  154. </SCRIPT>
  155. <form method="POST" name = "yesno" id="yesno" action="<?php echo $_SERVER['PHP_SELF'];?>?cidReq=<?=$cidReq?>&add_question=<?=$add_question?>&groupid=<?=$groupid?>&surveyid=<?=$surveyid?>&curr_dbname=<?=$curr_dbname?>">
  156. <input type="hidden" name="groupid" value="<?=$groupid?>">
  157. <input type="hidden" name="surveyid" value="<?=$surveyid?>">
  158. <input type="hidden" name="questtype" value="<?=$add_question12?>">
  159. <input type="hidden" name="curr_dbname" value="<?=$curr_dbname?>">
  160. <!--<input type="hidden" name="cidReq" value="<?=$cidReq?>">-->
  161. <input type="hidden" name="action" value="addquestion" >
  162. <table width="100%" border="0" cellspacing="0" cellpadding="0" class="outerBorder_innertable">
  163. <tr>
  164. <td class="pagedetails_heading"><a class="form_text_bold"><strong>Question</strong></a></td>
  165. </tr>
  166. </table>
  167. <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="outerBorder_innertable">
  168. <tr class="white_bg">
  169. <td height="30" class="form_text1">
  170. Enter the question.
  171. </td>
  172. <td class="form_text1" align="right">&nbsp;
  173. </td>
  174. </tr>
  175. <tr class="form_bg">
  176. <td width="542" height="30" colspan="2" ><?php api_disp_html_area('enterquestion',$enterquestion,'200px');?>
  177. </td>
  178. </tr>
  179. </table>
  180. <br>
  181. <table width="100%" border="0" cellspacing="0" cellpadding="0" class="outerBorder_innertable">
  182. <tr>
  183. <td class="pagedetails_heading"><a class="form_text_bold"><strong>Answer</strong></a></td>
  184. </tr>
  185. </table>
  186. <table width="100%" border="0" cellspacing="0" cellpadding="0" class="outerBorder_innertable">
  187. <tr class="white_bg">
  188. <td height="30"><span class="form_text1">Enter the answers</span>.
  189. </td>
  190. <td>&nbsp;</td>
  191. <td width="192" align="right">&nbsp; </td>
  192. </tr>
  193. </table>
  194. <table ID="tblFields" width="70%" border="0" cellpadding="0" cellspacing="0" class="outerBorder_innertable">
  195. <?php
  196. $start=1;$end=2;$upx=2;$upy=1;$dwnx=0;$dwny=1;$jd=0;$sn=1;
  197. $id="id";
  198. $tempmutlichkboxtext="jkjk";
  199. if(isset($_POST['radiodefault']))
  200. $tempradiodefault=$_POST['radiodefault'];
  201. else
  202. $tempradiodefault=1;
  203. $tempchkboxpoint="jkjk";
  204. if(isset($_POST['radiotrue']))
  205. $tempradiotrue=$_POST['radiotrue'];
  206. else
  207. $tempradiotrue=1;
  208. $up="up";
  209. $down="down";
  210. $flag=1;
  211. if(isset($_POST['mutlichkboxtext']))
  212. $end=count($_POST['mutlichkboxtext']);
  213. for($i=$start;$i<=$end;$i++)
  214. {
  215. $id="id".$i."_x";
  216. //echo ",".$id;
  217. if(isset($_POST[$id]))
  218. {
  219. $jd=$i;
  220. $flag=0;
  221. $end=count($_POST['mutlichkboxtext']);
  222. if($end<=3)
  223. {
  224. $end=3;
  225. }
  226. else
  227. $end-=1;
  228. break;
  229. //echo ",while checking id,end=".$end;
  230. }
  231. }
  232. for($i=$start;$i<=$end;$i++)
  233. {
  234. $up="up".$i."_x";
  235. $down="down".$i."_x";
  236. if(isset($_POST[$up])||isset($_POST[$down]))
  237. {
  238. $flag=0;
  239. if(isset($_POST[$up]))
  240. {
  241. $tempmutlichkboxtext=$_POST['mutlichkboxtext'];
  242. if($tempradiodefault==$i)
  243. $tempradiodefault--;
  244. elseif($tempradiodefault==$i-1)
  245. $tempradiodefault++;
  246. $tempchkboxpoint=$_POST['chkboxpoint'];
  247. if($tempradiotrue==$i)
  248. $tempradiotrue--;
  249. elseif($tempradiotrue==$i-1)
  250. $tempradiotrue++;
  251. $tempm= $tempmutlichkboxtext[$i-2];
  252. $tempchkboxp=$tempchkboxpoint[$i-2];
  253. $tempmutlichkboxtext[$i-2]=$tempmutlichkboxtext[$i-1];
  254. $tempchkboxpoint[$i-2]=$tempchkboxpoint[$i-1];
  255. $tempmutlichkboxtext[$i-1]=$tempm;
  256. $tempchkboxpoint[$i-1]=$tempchkboxp;
  257. $_POST['mutlichkboxtext']=$tempmutlichkboxtext;
  258. $_POST['chkboxpoint']=$tempchkboxpoint;
  259. }
  260. if(isset($_POST[$down]))
  261. {
  262. $tempmutlichkboxtext=$_POST['mutlichkboxtext'];
  263. if($tempradiodefault==$i)
  264. $tempradiodefault++;
  265. elseif($tempradiodefault==$i+1)
  266. $tempradiodefault--;
  267. $tempchkboxpoint=$_POST['chkboxpoint'];
  268. if($tempradiotrue==$i)
  269. $tempradiotrue++;
  270. elseif($tempradiotrue==$i+1)
  271. $tempradiotrue--;
  272. $tempm= $tempmutlichkboxtext[$i];
  273. $tempchkboxp=$tempchkboxpoint[$i];
  274. $tempmutlichkboxtext[$i]=$tempmutlichkboxtext[$i-1];
  275. $tempchkboxpoint[$i]=$tempchkboxpoint[$i-1];
  276. $tempmutlichkboxtext[$i-1]=$tempm;
  277. $tempchkboxpoint[$i-1]=$tempchkboxp;
  278. $_POST['mutlichkboxtext']=$tempmutlichkboxtext;
  279. $_POST['chkboxpoint']=$tempchkboxpoint;
  280. }
  281. //echo ",while checking up/down end=".$end;
  282. $jd=0;
  283. break;
  284. }
  285. }
  286. if($flag==1)
  287. {
  288. if(isset($_POST['addnewrows']))
  289. {
  290. $end=count($_POST['mutlichkboxtext']);
  291. if($end<10)
  292. {
  293. $end=$end+$_POST['addnewrows'];
  294. if($end>10)
  295. $end=10;
  296. }
  297. else
  298. $end=10;
  299. //echo ",while checking select end=".$end;
  300. /*else
  301. $end=$end+$_POST['addnewrows'];*/
  302. }
  303. }
  304. //echo ",after select end=".$end;
  305. for($i=$start;$i<=$end;$i++)
  306. {
  307. if($i==$jd)
  308. /*{
  309. if($end<=3);
  310. else;
  311. //continue;
  312. }*/
  313. {
  314. $end++;
  315. }
  316. else
  317. {
  318. $k=$i-1;
  319. $post_text = $_POST['mutlichkboxtext'];
  320. //$post_check=$_POST['radiodefault'];
  321. $post_point=$_POST['chkboxpoint'];
  322. //$post_true=$_POST['radiotrue'];
  323. ?>
  324. <tr class="form_bg" id="0">
  325. <td width="16" height="30" align="left" class="form_text">
  326. <? echo $sn;?>
  327. </td>
  328. <td class="form_bg"><textarea name="mutlichkboxtext[]" cols="50" rows="3" class="text_field" style="width:100%;"><?=$post_text[$k]?></textarea>
  329. </td>
  330. <td width="10" class="form_text"><img src="../img/blank.gif" width="10" height="8">
  331. </td>
  332. <td width="10" class="form_text"><img src="../img/blank.gif" width="10" height="8">
  333. </td>
  334. <? if($i>$start)
  335. {
  336. ?>
  337. <td width="30" align="center" class="form_text1">
  338. <input type="image" src="../img/up.gif" width="24" height="24" border="0" onclick="this.form.submit();" name="<?echo "up".$i;?>" style="cursor:hand">
  339. </td>
  340. <? }
  341. else
  342. {
  343. ?> <td width="30" align="center" class="form_text1">
  344. </td>
  345. <? }
  346. $sn++;
  347. ?>
  348. <? if($i<$end)
  349. {
  350. ?>
  351. <td width="30" align="center" class="form_text">
  352. <input type="image" src="../img/down.gif" width="24" height="24" border="0" onclick="this.form.submit();" name="<?echo "down".$i;?>" style="cursor:hand">
  353. </td>
  354. <? }
  355. else
  356. {
  357. ?> <td width="30" align="center" class="form_text1">
  358. </td>
  359. <? }
  360. ?>
  361. <td width="30" align="center" class="form_text">
  362. </tr>
  363. <? }
  364. }
  365. ?>
  366. </table>
  367. <br>
  368. <br>
  369. <div align="center">
  370. <input type="HIDDEN" name="end1" value="<?=$end?>">
  371. <?
  372. if(isset($_POST['add_question']))
  373. {
  374. ?> <input type="hidden" name="add_question" value="<? echo $_POST['add_question'];?>" >
  375. <? }
  376. $sql = "SELECT * FROM $curr_dbname.survey WHERE survey_id='$surveyid'";
  377. $res=api_sql_query($sql);
  378. $obj=mysql_fetch_object($res);
  379. switch($obj->template)
  380. {
  381. case "template1":
  382. $temp = 'white';
  383. break;
  384. case "template2":
  385. $temp = 'bluebreeze';
  386. break;
  387. case "template3":
  388. $temp = 'brown';
  389. break;
  390. case "template4":
  391. $temp = 'grey';
  392. break;
  393. case "template5":
  394. $temp = 'blank';
  395. break;
  396. }
  397. ?>
  398. <input type="submit" name="back" value="<?=get_lang("back");?>">
  399. <input type="submit" name="saveandexit" value="<?=get_lang("saveandexit");?>">
  400. <input type="button" value="<?php echo get_lang('preview');?>" onClick="preview('yesno','<?=$temp?>','<?=$Multi?>')">
  401. <input type="submit" name="next" value="<?=get_lang("next");?>">
  402. </div>
  403. <!--this partcular field helps in identify the item to be add at the itemadd.php-->
  404. </form>
  405. </div>
  406. <div id=bottomnav align="center"></DIV>
  407. </body>
  408. </html>
  409. <SCRIPT LANGUAGE="JavaScript">
  410. function preview(form,temp,qtype)
  411. {
  412. var ques = editor.getHTML();
  413. //alert(ques);
  414. var id_str = "";
  415. for(i=0;i<eval("document."+form+"['mutlichkboxtext[]'].length");i++)
  416. {
  417. var box = (eval("document."+form+"['mutlichkboxtext[]']["+i+"]"));
  418. id_str += box.value+"|";
  419. }
  420. window.open(temp+'.php?temp=<?=$temp;?>&ques='+ques+'&ans='+id_str+'&qtype='+qtype, 'popup', 'width=800,height=600,scrollbars=yes,toolbar = no, status = no');
  421. }
  422. </script>
  423. <?php
  424. Display :: display_footer();
  425. ?>