attach_existingsurvey.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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: attach_existingsurvey.php 10705 2007-01-12 22:40:01Z pcool $
  20. */
  21. /*
  22. ==============================================================================
  23. INIT SECTION
  24. ==============================================================================
  25. */
  26. // name of the language file that needs to be included
  27. $language_file = 'survey';
  28. // including the global dokeos file
  29. require_once ('../inc/global.inc.php');
  30. // including additional libraries
  31. /** @todo check if these are all needed */
  32. /** @todo check if the starting / is needed. api_get_path probably ends with an / */
  33. require_once (api_get_path(LIBRARY_PATH).'/fileManage.lib.php');
  34. require_once (api_get_path(CONFIGURATION_PATH) ."/add_course.conf.php");
  35. require_once (api_get_path(LIBRARY_PATH)."/add_course.lib.inc.php");
  36. require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
  37. require_once (api_get_path(LIBRARY_PATH)."/groupmanager.lib.php");
  38. require_once (api_get_path(LIBRARY_PATH)."/surveymanager.lib.php");
  39. require_once (api_get_path(LIBRARY_PATH)."/usermanager.lib.php");
  40. /** @todo replace this with the correct code */
  41. /*
  42. $status = surveymanager::get_status();
  43. api_protect_course_script();
  44. if($status==5)
  45. {
  46. api_protect_admin_script();
  47. }
  48. */
  49. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  50. if (!api_is_allowed_to_edit())
  51. {
  52. Display :: display_header();
  53. Display :: display_error_message(get_lang('NotAllowedHere'));
  54. Display :: display_footer();
  55. exit;
  56. }
  57. // Database table definitions
  58. /** @todo use database constants for the survey tables */
  59. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  60. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  61. $table_group = Database :: get_course_table(TABLE_SURVEY_GROUP);
  62. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  63. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  64. $table_course_survey_rel = Database :: get_main_table(TABLE_MAIN_COURSE_SURVEY);
  65. $table_languages = Database::get_main_table(TABLE_MAIN_LANGUAGE);
  66. // Language variables
  67. $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'));
  68. $tool_name = get_lang('CreateNewSurvey');
  69. $tool_name1 = get_lang('CreateNewSurvey');
  70. // Breadcrumbs
  71. $interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('Survey'));
  72. // Variables
  73. $arr_date = explode("-",date("Y-m-d"));
  74. $curr_year = $arr_date[0];
  75. $curr_month = $arr_date[1];
  76. $curr_day = $arr_date[2];
  77. /** @todo use $_course array */
  78. $course_id = $_SESSION['_course']['id'];
  79. // $_GET and $_POST
  80. /** @todo replace $_REQUEST with $_GET or $_POST */
  81. $db_name = $_REQUEST['db_name'];
  82. $oldsurveyid=$_REQUEST['surveyid'];
  83. $survey_name=surveymanager::get_surveyname($db_name,$oldsurveyid);
  84. /** @todo this piece of code is duplicated in many scripts. Find out where it is used and remove all other occurences */
  85. if ($_POST['action'] == 'add_survey')
  86. {
  87. $surveycode=$_POST['survey_code'];
  88. $surveytitle = $_POST['survey_title'];
  89. $surveysubtitle = $_POST['survey_subtitle'];
  90. $author = $_POST['author'];
  91. $survey_language = $_POST['survey_language'];
  92. $availablefrom = $_POST['fyear']."-".$_POST['fmonth']."-".$_POST['fday'];
  93. $availabletill = $_POST['end_fyear']."-".$_POST['end_fmonth']."-".$_POST['end_fday'];
  94. $isshare = $_POST['isshare'];
  95. $surveytemplate = $_POST['template'];
  96. $surveyintroduction = $_POST['content'];
  97. $surveythanks = $_POST['thanks'];
  98. $savailablefrom=mktime(0,0,0,$_POST['fmonth'],$_POST['fday'], $_POST['fyear']);
  99. $savailabletill=mktime(0,0,0,$_POST['end_fmonth'],$_POST['end_fday'], $_POST['end_fyear']);
  100. $db_name = $_REQUEST['db_name'];
  101. $surveyid = $_REQUEST['surveyid'];
  102. if(isset($_POST['back']))
  103. {
  104. $surveyid = $_REQUEST['surveyid'];
  105. $db_name = $_REQUEST['db_name'];
  106. header("location:create_from_existing_survey.php?surveyid=$surveyid&db_name=$db_name");
  107. }
  108. $surveytitle=trim($surveytitle);
  109. $surveycode=trim($surveycode);
  110. if(empty ($surveytitle))
  111. {
  112. $error_message = get_lang('PleaseEnterSurveyTitle');
  113. }
  114. elseif ($savailabletill<=$savailablefrom){
  115. $error_message = get_lang('PleaseEnterValidDate');
  116. }
  117. elseif (empty ($surveycode)){
  118. $error_message = get_lang('PleaseEnterValidCode');
  119. }
  120. else
  121. {
  122. $result=SurveyManager::get_survey_code($table_survey,$surveycode);
  123. if(!empty($result))
  124. {
  125. $error_message=get_lang('ThisCodeAlreadyExist');
  126. }
  127. else
  128. {
  129. $survey_id = SurveyManager::create_survey_attach($surveycode, $surveytitle, $surveysubtitle, $author, $survey_language, $availablefrom, $availabletill, $isshare, $surveytemplate, $surveyintroduction, $surveythanks, $table_survey, $table_group);
  130. $curr_dbname=SurveyManager::create_course_survey_rel($cidReq,$survey_id,$table_course,$table_course_survey_rel);
  131. $oldsurveyid=$_POST['surveyid'];
  132. $db_name = $_REQUEST['db_name'];
  133. SurveyManager::attach_survey($oldsurveyid,$survey_id,$db_name,$curr_dbname);
  134. if (isset($_POST['next']))
  135. {
  136. header("location:select_question_group.php?surveyid=$survey_id");
  137. exit;
  138. }
  139. else
  140. {
  141. header("location:survey_list.php");
  142. exit;
  143. }
  144. }
  145. }
  146. }
  147. Display::display_header($tool_name);
  148. api_display_tool_title($tool_name1);
  149. //echo "<pre>";
  150. //print_r($_SESSION);
  151. //echo "</pre>";
  152. if( isset($error_message) )
  153. {
  154. Display::display_error_message($error_message);
  155. }
  156. ?>
  157. <SCRIPT LANGUAGE="JavaScript">
  158. <!-- Begin
  159. function displayTemplate(form) {
  160. var inf = form.template.value;
  161. if(inf=="")
  162. {
  163. alert("Please Select a Template");
  164. }
  165. else
  166. {
  167. window.open(inf+".htm", 'popup', 'width=600,height=600,toolbar = no, status = no');
  168. }
  169. //window.open(inf+".htm");
  170. //win.document.write("" + inf + "");
  171. }
  172. // End -->
  173. </script>
  174. <script src=tbl_change.js type="text/javascript" language="javascript"></script>
  175. <form name="new_calendar_item" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  176. <input type="hidden" name="action" value="add_survey">
  177. <input type="hidden" name="surveyid" value="<?php echo $oldsurveyid; ?>">
  178. <input type="hidden" name="db_name" value="<?php echo $db_name; ?>">
  179. <table>
  180. <tr>
  181. <td><?php echo get_lang('SurveyCode'); ?></td>
  182. <td><input type="text" name="survey_code" size="20" maxlength="39" value="<?php echo $surveycode; ?>"></td>
  183. </tr>
  184. <tr>
  185. <td><?php echo get_lang('SurveyTitle'); ?></td>
  186. <td><input type="text" name="survey_title" size="40" maxlength="79" value="<?php echo $surveytitle; ?>"></td>
  187. </tr>
  188. <tr>
  189. <td><?php echo get_lang('SurveySubtitle'); ?></td>
  190. <td><input type="text" name="survey_subtitle" size="40" maxlength="79" value="<?php echo $surveysubtitle; ?>"></td>
  191. </tr>
  192. <tr>
  193. <?php
  194. if($_SESSION['is_platformAdmin']=='1'||$_SESSION['is_courseAdmin'])
  195. {
  196. echo "<td>";
  197. echo get_lang('Author');
  198. echo "</td>";
  199. echo "<td>";
  200. UserManager::get_teacher_list($course_id, $author_id);
  201. echo "</td>";
  202. }
  203. ?>
  204. </tr>
  205. <tr>
  206. <td><?php echo get_lang('SurveyLanguage'); ?>&nbsp;</td>
  207. <td>
  208. <select name="survey_language">
  209. <option value="english" selected="selected">English</option>
  210. <option value="french" >Fran&ccedil;ais</option>
  211. <option value="dutch" >Nederlands</option>
  212. </select>
  213. </td>
  214. </tr>
  215. <tr id="subtitle">
  216. <td><?php echo get_lang('AvailableFrom'); ?>&nbsp;</td>
  217. <td>
  218. <select name="fday">
  219. <?php
  220. for($i=1;$i<=31;$i++){
  221. if($i<=9) $val = "0".$i;
  222. else $val = $i;
  223. if ($val==$curr_day) $selected = "selected";
  224. else $selected = "";
  225. echo "<option value=\"$val\" $selected>$i</option>";
  226. }
  227. ?>
  228. </select>
  229. <!-- month: january ->
  230. december -->
  231. <select name="fmonth">
  232. <?php
  233. for($i=1;$i<count($MonthsLong);$i++)
  234. {
  235. if($i<=9)
  236. $val = "0".$i;
  237. else
  238. $val = $i;
  239. if($val == $curr_month)
  240. echo "<option value=\"$val\" selected>".$MonthsLong[$i-1]."</option>\n";
  241. else
  242. echo "<option value=\"$val\">".$MonthsLong[$i-1]."</option>\n";
  243. }
  244. ?>
  245. </select>
  246. <select name="fyear">
  247. <?php
  248. for($i=$curr_year;$i<=$curr_year+10;$i++){
  249. if($i == $curr_year)
  250. echo "<option value=\"$i\" selected>$i</option>\n";
  251. else
  252. echo "<option value=\"$i\">$i</option>\n";
  253. }
  254. ?>
  255. </select>
  256. <a title="Calendar" href="javascript:openCalendar('new_calendar_item', 'f')"><img src="../img/calendar_select.gif" border="0" align="absmiddle"/></a></td>
  257. </tr>
  258. <tr id="subtitle">
  259. <td><?php echo get_lang('AvailableTill'); ?>&nbsp;</td>
  260. <td>
  261. <select name="end_fday">
  262. <?php for($i=1;$i<=31;$i++){
  263. if($i<=9)
  264. $val = "0".$i;
  265. else
  266. $val = $i;
  267. if ($val==$curr_day) $selected = "selected";
  268. else $selected = "";
  269. echo "<option value=\"$val\" $selected>$i</option>";
  270. }
  271. ?>
  272. </select>
  273. <!-- month: january ->
  274. december -->
  275. <select name="end_fmonth">
  276. <?php
  277. for($i=1;$i<count($MonthsLong);$i++)
  278. {
  279. if($i<=9)
  280. $val = "0".$i;
  281. else
  282. $val = $i;
  283. if($val == $curr_month)
  284. echo "<option value=\"$val\" selected>".$MonthsLong[$i-1]."</option>\n";
  285. else
  286. echo "<option value=\"$val\">".$MonthsLong[$i-1]."</option>\n";
  287. }
  288. ?>
  289. </select>
  290. <select name="end_fyear">
  291. <?php
  292. for($i=$curr_year;$i<=$curr_year+10;$i++){
  293. if($i == $curr_year+1)
  294. echo "<option value=\"$i\" selected>$i</option>\n";
  295. else
  296. echo "<option value=\"$i\">$i</option>\n";
  297. }
  298. ?>
  299. </select>
  300. <a title="Calendar" href="javascript:openCalendar('new_calendar_item', 'end_f')"><img src="../img/calendar_select.gif" border="0" align="absmiddle"/></a></td>
  301. </tr>
  302. <tr>
  303. <td valign="top"><?php echo get_lang('IsShareSurvey'); ?>&nbsp;</td>
  304. <td>
  305. <input type="radio" name="isshare" value="1">Yes&nbsp;<input type="radio" name="isshare" value="0" checked>No
  306. </td>
  307. </tr>
  308. <tr>
  309. <td><?php echo get_lang('SurveyTemplate'); ?>&nbsp;</td>
  310. <td>
  311. <select name="template">
  312. <option value="template1" <?php if($template=="template1") echo " selected "; ?>>OFO_nl</option>
  313. <option value="template2" <?php if($template=="template2") echo " selected "; ?>>IFA_fr</option>
  314. <option value="template3" <?php if($template=="template3") echo " selected "; ?>>SPF P&O_FR</option>
  315. <option value="template4" <?php if($template=="template4") echo " selected "; ?>>FOD P&O_NL</option>
  316. <option value="template5" <?php if($template=="template5") echo " selected "; ?>>Blank</option>
  317. </select>
  318. <input type="button" value="<?php echo get_lang('Preview');?>" onClick="displayTemplate(new_calendar_item)">
  319. </td>
  320. </tr>
  321. <tr><td valign="top"><?php echo get_lang('SurveyIntroduction'); ?>&nbsp;</td>
  322. <td>
  323. <?php
  324. require_once(api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php");
  325. $oFCKeditor = new FCKeditor('content') ;
  326. $oFCKeditor->BasePath = api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ;
  327. $oFCKeditor->Height = '300';
  328. $oFCKeditor->Width = '600';
  329. $oFCKeditor->Value = $content;
  330. $oFCKeditor->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig.js";
  331. $oFCKeditor->ToolbarSet = "Survey";
  332. $sql="SELECT isocode FROM ".$table_languages." WHERE english_name='".$_SESSION["_course"]["language"]."'";
  333. $result_sql=api_sql_query($sql);
  334. $isocode_language=mysql_result($result_sql,0,0);
  335. $oFCKeditor->Config['DefaultLanguage'] = $isocode_language;
  336. $return = $oFCKeditor->CreateHtml();
  337. echo $return;
  338. ?>
  339. <br>
  340. </td>
  341. </tr>
  342. <tr><td valign="top"><?php echo get_lang('Thanks'); ?>&nbsp;</td>
  343. <td>
  344. <?php
  345. require_once(api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php");
  346. $oFCKeditor = new FCKeditor('thanks') ;
  347. $oFCKeditor->BasePath = api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ;
  348. $oFCKeditor->Height = '300';
  349. $oFCKeditor->Width = '600';
  350. $oFCKeditor->Value = $thanks;
  351. $oFCKeditor->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig.js";
  352. $oFCKeditor->ToolbarSet = "Survey";
  353. $sql="SELECT isocode FROM ".$table_languages." WHERE english_name='".$_SESSION["_course"]["language"]."'";
  354. $result_sql=api_sql_query($sql);
  355. $isocode_language=mysql_result($result_sql,0,0);
  356. $oFCKeditor->Config['DefaultLanguage'] = $isocode_language;
  357. $return = $oFCKeditor->CreateHtml();
  358. echo $return;
  359. ?>
  360. <br>
  361. </td>
  362. </tr>
  363. <tr>
  364. <td><?php echo get_lang('SurveyAttached');?></td>
  365. <td><?php echo $survey_name;?></td>
  366. </tr>
  367. </table>
  368. <table>
  369. <tr>
  370. <td></td>
  371. <td><input type="submit" name="back" value="<?php echo get_lang('Back'); ?>">&nbsp;<input type="submit" name="saveandexit" value="<?php echo get_lang('CreateLater'); ?>">&nbsp;<input type="submit" name="next" value="<?php echo get_lang('Next'); ?>"></td>
  372. </tr>
  373. </table>
  374. </form>
  375. </table>
  376. <?php
  377. Display :: display_footer();
  378. ?>