survey_edit.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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: survey_edit.php 10705 2007-01-12 22:40:01Z pcool $
  20. * @todo check if this file is still used. With the rewriting the file is probably no longer in use
  21. */
  22. /*
  23. ==============================================================================
  24. INIT SECTION
  25. ==============================================================================
  26. */
  27. // name of the language file that needs to be included
  28. $language_file = 'survey';
  29. // including the global dokeos file
  30. include ('../inc/global.inc.php');
  31. // including additional libraries
  32. require_once (api_get_path(LIBRARY_PATH).'/fileManage.lib.php');
  33. require_once (api_get_path(LIBRARY_PATH)."/surveymanager.lib.php");
  34. require_once (api_get_path(LIBRARY_PATH)."/usermanager.lib.php");
  35. /** @todo replace this with the correct code */
  36. /*
  37. $status = surveymanager::get_status();
  38. api_protect_course_script();
  39. if($status==5)
  40. {
  41. api_protect_admin_script();
  42. }
  43. */
  44. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  45. if (!api_is_allowed_to_edit())
  46. {
  47. Display :: display_header();
  48. Display :: display_error_message(get_lang('NotAllowedHere'));
  49. Display :: display_footer();
  50. exit;
  51. }
  52. // Database table definitions
  53. /** @todo use database constants for the survey tables */
  54. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  55. $table_course_survey_rel = Database :: get_main_table(TABLE_MAIN_COURSE_SURVEY);
  56. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  57. $tbl_category = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  58. $table_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
  59. // language variables
  60. $MonthsLong = array(get_lang('JanuaryLong'), get_lang('FebruaryLong'), get_lang('"MarchLong'), get_lang('AprilLong'), get_lang('MayLong'), get_lang('JuneLong'), get_lang('JulyLong'), get_lang('AugustLong'), get_lang('SeptemberLong'), get_lang('OctoberLong'), get_lang('NovemberLong'), get_lang('DecemberLong'));
  61. $tool_name = get_lang('ModifySurveyInformation');
  62. $arr_date = explode("-",date("Y-m-d"));
  63. $curr_year = $arr_date[0];
  64. $curr_month = $arr_date[1];
  65. $curr_day = $arr_date[2];
  66. $noPHP_SELF = true;
  67. $interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('Survey'));
  68. $maxFilledSpace = get_setting('default_document_quotum');
  69. $course_code = $id; //note confusion again: int id - string id - string code...
  70. $formSent=0;
  71. if ($_POST['action'] == 'update_survey')
  72. {
  73. $formSent=1;
  74. $surveycode=$_POST['survey_code'];
  75. $surveytitle = $_POST['survey_title'];
  76. $surveysubtitle = $_POST['survey_subtitle'];
  77. $author = $_POST['author'];
  78. $survey_language = $_POST['survey_language'];
  79. $availablefrom = $_POST['fyear']."-".$_POST['fmonth']."-".$_POST['fday'];
  80. $availabletill = $_POST['end_fyear']."-".$_POST['end_fmonth']."-".$_POST['end_fday'];
  81. $isshare = $_POST['isshare'];
  82. $surveytemplate = $_POST['template'];
  83. $surveyintroduction = $_POST['content'];
  84. $surveythanks = $_POST['thanks'];
  85. $savailablefrom=mktime(0,0,0,$_POST['fmonth'],$_POST['fday'], $_POST['fyear']);
  86. $savailabletill=mktime(0,0,0,$_POST['end_fmonth'],$_POST['end_fday'], $_POST['end_fyear']);
  87. $surveytitle=trim($surveytitle);
  88. $surveycode=trim($surveycode);
  89. if(isset($_POST['back']))
  90. {
  91. header('location:survey_list.php');
  92. exit;
  93. }
  94. if(empty ($surveytitle))
  95. {
  96. $error_message = get_lang('PleaseEnterSurveyTitle');
  97. }
  98. elseif ($savailabletill<=$savailablefrom){
  99. $error_message = get_lang('PleaseEnterValidDate');
  100. }
  101. elseif (empty ($surveycode)){
  102. $error_message = get_lang('PleaseEnterValidCode');
  103. }
  104. else
  105. {
  106. $curr_dbname=SurveyManager::update_survey($_GET['survey_id'],$surveycode,$surveytitle,$surveysubtitle,$author,$survey_language,$availablefrom,$availabletill,$isshare,$surveytemplate,$surveyintroduction,$surveythanks,$cidReq,$table_course);
  107. if(isset($_POST['next']))
  108. {
  109. header("location:select_question_group.php?surveyid=".$_GET['survey_id']);
  110. exit;
  111. }
  112. else
  113. {
  114. header('location:survey_list.php');
  115. exit;
  116. }
  117. }
  118. }
  119. Display::display_header($tool_name);
  120. api_display_tool_title($tool_name);
  121. if( isset($error_message) )
  122. {
  123. Display::display_error_message($error_message);
  124. }
  125. ?>
  126. <SCRIPT LANGUAGE="JavaScript">
  127. <!-- Begin
  128. function displayTemplate(form) {
  129. var inf = form.template.value;
  130. if(inf=="")
  131. {
  132. alert("Please Select a Template");
  133. }
  134. else
  135. {
  136. window.open(inf+".htm", 'popup', 'width=600,height=600,toolbar = no, status = no');
  137. }
  138. //window.open(inf+".htm");
  139. //win.document.write("" + inf + "");
  140. }
  141. // End -->
  142. </script>
  143. <script src=tbl_change.js type="text/javascript" language="javascript"></script>
  144. <?php
  145. /**
  146. * Finding the survey we are editing
  147. * @todo use a function for this because this is probably a very common functionality
  148. */
  149. $sql = "SELECT * FROM $table_survey WHERE survey_id='".$_GET['survey_id']."'";
  150. $res = api_sql_query($sql);
  151. $obj = mysql_fetch_object($res);
  152. $arr_avail_from = explode("-",$obj->avail_from);
  153. $avail_year_from = $arr_avail_from['0'];
  154. $avail_month_from = $arr_avail_from['1'];
  155. $avail_day_from = $arr_avail_from['2'];
  156. $arr_avail_till = explode("-",$obj->avail_till);
  157. $avail_year_till = $arr_avail_till['0'];
  158. $avail_month_till = $arr_avail_till['1'];
  159. $avail_day_till = $arr_avail_till['2'];
  160. $template = $obj->template;
  161. $lang=$obj->lang;
  162. ?>
  163. <form name="new_calendar_item" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  164. <input type="hidden" name="surveyid" value="<?php echo $_GET['survey_id']; ?>">
  165. <input type="hidden" name="action" value="update_survey">
  166. <table>
  167. <tr>
  168. <td><?php echo get_lang('SurveyCode'); ?></td>
  169. <td><input type="text" name="survey_code" size="20" maxlength="19" value="<?php if($formSent){echo $surveycode;}else {echo $obj->code;} ?>"></td>
  170. </tr>
  171. <tr>
  172. <td><?php echo get_lang('SurveyTitle'); ?></td>
  173. <td><input type="text" name="survey_title" size="40" maxlength="79" value="<?php if($formSent){echo $surveytitle;}else {echo $obj->title;} ?>"></td>
  174. </tr>
  175. <tr>
  176. <td><?php echo get_lang('SurveySubtitle'); ?></td>
  177. <td><input type="text" name="survey_subtitle" size="40" maxlength="79" value="<?php if($formSent){echo $surveysubtitle;}else {echo $obj->subtitle;} ?>"></td>
  178. </tr>
  179. <tr>
  180. <td><?php echo get_lang('Author'); ?></td>
  181. <td>
  182. <?php
  183. UserManager::get_teacher_list($cidReq,$obj->author);
  184. ?>
  185. </td>
  186. </tr>
  187. <tr>
  188. <td><?php echo get_lang('SurveyLanguage'); ?>&nbsp;</td>
  189. <td>
  190. <select name="survey_language">
  191. <option value="english" <?php if($lang=='english') echo "selected";?>>English</option>
  192. <option value="french" <?php if($lang=='french') echo "selected";?>>Fran&ccedil;ais</option>
  193. <option value="dutch" <?php if($lang=='dutch') echo "selected";?>>Nederlands</option>
  194. </select>
  195. </td>
  196. </tr>
  197. <tr id="subtitle">
  198. <td><?php echo get_lang('AvailableFrom'); ?>&nbsp;</td>
  199. <td>
  200. <select name="fday">
  201. <?php for($i=1;$i<=31;$i++){
  202. if($i<=9)
  203. $val = "0".$i;
  204. else
  205. $val = $i;
  206. if($val==$avail_day_from) $selected="selected";
  207. else $selected="";
  208. echo "<option value=\"$val\" $selected>$i</option>\n";
  209. }
  210. ?>
  211. </select>
  212. <!-- month: january ->
  213. december -->
  214. <select name="fmonth">
  215. <?php
  216. for($i=1;$i<count($MonthsLong);$i++)
  217. {
  218. if($i<=9)
  219. $val = "0".$i;
  220. else
  221. $val = $i;
  222. if($val == $avail_month_from)
  223. echo "<option value=\"$val\" selected>".$MonthsLong[$i-1]."</option>\n";
  224. else
  225. echo "<option value=\"$val\">".$MonthsLong[$i-1]."</option>\n";
  226. }
  227. ?>
  228. </select>
  229. <select name="fyear">
  230. <?php
  231. for($i=$curr_year;$i<=$curr_year+10;$i++){
  232. if($i == $avail_year_from)
  233. echo "<option value=\"$i\" selected>$i</option>\n";
  234. else
  235. echo "<option value=\"$i\">$i</option>\n";
  236. }
  237. ?>
  238. </select>
  239. <a title="Calendar" href="javascript:openCalendar('new_calendar_item', 'f')"><img src="../img/calendar_select.gif" border="0" align="absmiddle"/></a></td>
  240. </tr>
  241. <tr id="subtitle">
  242. <td><?php echo get_lang('AvailableTill'); ?>&nbsp;</td>
  243. <td>
  244. <select name="end_fday">
  245. <?php for($i=1;$i<=31;$i++){
  246. if($i<=9)
  247. $val = "0".$i;
  248. else
  249. $val = $i;
  250. if($val==$avail_day_till) $selected="selected";
  251. else $selected="";
  252. echo "<option value=\"$val\" $selected>$i</option>\n";
  253. }
  254. ?>
  255. </select>
  256. <!-- month: january ->
  257. december -->
  258. <select name="end_fmonth">
  259. <?php
  260. for($i=1;$i<count($MonthsLong);$i++)
  261. {
  262. if($i<=9)
  263. $val = "0".$i;
  264. else
  265. $val = $i;
  266. if($val == $avail_month_till)
  267. echo "<option value=\"$val\" selected>".$MonthsLong[$i-1]."</option>\n";
  268. else
  269. echo "<option value=\"$val\">".$MonthsLong[$i-1]."</option>\n";
  270. }
  271. ?>
  272. </select>
  273. <select name="end_fyear">
  274. <?php
  275. for($i=$curr_year;$i<=$curr_year+10;$i++){
  276. if($i == $avail_year_till)
  277. echo "<option value=\"$i\" selected>$i</option>\n";
  278. else
  279. echo "<option value=\"$i\">$i</option>\n";
  280. }
  281. ?>
  282. </select>
  283. <a title="Calendar" href="javascript:openCalendar('new_calendar_item', 'end_f')"><img src="../img/calendar_select.gif" border="0" align="absmiddle"/></a></td>
  284. </tr>
  285. <tr>
  286. <td valign="top"><?php echo get_lang('IsShareSurvey'); ?>&nbsp;</td>
  287. <td>
  288. <input type="radio" name="isshare" value="1" <?php if($obj->is_shared=='1') echo "checked";?>>Yes&nbsp;<input type="radio" name="isshare" value="0" <?php if($obj->is_shared=='0') echo "checked";?>>No
  289. </td>
  290. </tr>
  291. <tr><td valign="top"><?php echo get_lang('SurveyIntroduction'); ?>&nbsp;</td>
  292. <td>
  293. <?php
  294. require_once(api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php");
  295. $oFCKeditor = new FCKeditor('content') ;
  296. $oFCKeditor->BasePath = api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ;
  297. $oFCKeditor->Height = '300';
  298. $oFCKeditor->Width = '500';
  299. $oFCKeditor->Value = $obj->intro;
  300. $oFCKeditor->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig.js";
  301. $oFCKeditor->ToolbarSet = "Survey";
  302. $sql="SELECT isocode FROM ".$table_languages." WHERE english_name='".$_SESSION["_course"]["language"]."'";
  303. $result_sql=api_sql_query($sql);
  304. $isocode_language=mysql_result($result_sql,0,0);
  305. $oFCKeditor->Config['DefaultLanguage'] = $isocode_language;
  306. $return = $oFCKeditor->CreateHtml();
  307. echo $return;
  308. ?>
  309. <br>
  310. </td>
  311. </tr>
  312. <tr><td valign="top"><?php echo get_lang('Thanks'); ?>&nbsp;</td>
  313. <td>
  314. <?php
  315. require_once(api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php");
  316. $oFCKeditor = new FCKeditor('thanks') ;
  317. $oFCKeditor->BasePath = api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ;
  318. $oFCKeditor->Height = '300';
  319. $oFCKeditor->Width = '500';
  320. $oFCKeditor->Value = $obj->surveythanks;
  321. $oFCKeditor->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig.js";
  322. $oFCKeditor->ToolbarSet = "Survey";
  323. $return = $oFCKeditor->CreateHtml();
  324. echo $return;
  325. ?>
  326. <br>
  327. </td>
  328. </tr>
  329. <tr>
  330. <td></td>
  331. <td><input type="submit" name="back" value="<?php echo get_lang('Back'); ?>">&nbsp;<input type="submit" name="updateandreturn" value="<?php echo get_lang('SaveAndExit'); ?>">&nbsp;<input type="submit" name="next" value="<?php echo get_lang('Next'); ?>"></td>
  332. </tr>
  333. </table>
  334. </form>
  335. </table>
  336. <?php
  337. Display :: display_footer();
  338. ?>