attach_existingsurvey.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <?php
  2. // $Id: course_add.php,v 1.10 2005/05/30 11:46:48 bmol Exp $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004 Dokeos S.A.
  7. Copyright (c) 2003 University of Ghent (UGent)
  8. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9. Copyright (c) Olivier Brouckaert
  10. For a full list of contributors, see "credits.txt".
  11. The full license can be read in "license.txt".
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. See the GNU General Public License for more details.
  17. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. ==============================================================================
  22. * @package dokeos.admin
  23. ==============================================================================
  24. */
  25. /*
  26. ==============================================================================
  27. INIT SECTION
  28. ==============================================================================
  29. */
  30. $langFile = 'survey';
  31. require_once ('../inc/global.inc.php');
  32. //api_protect_admin_script();
  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 (api_get_path(LIBRARY_PATH)."/groupmanager.lib.php");
  38. require_once (api_get_path(LIBRARY_PATH)."/surveymanager.lib.php");
  39. $status = surveymanager::get_status();
  40. if($status==5)
  41. {
  42. api_protect_admin_script();
  43. }
  44. require_once (api_get_path(LIBRARY_PATH)."/usermanager.lib.php");
  45. $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"));
  46. $arr_date = explode("-",date("Y-m-d"));
  47. $curr_year = $arr_date[0];
  48. $curr_month = $arr_date[1];
  49. $curr_day = $arr_date[2];
  50. $coursePathWeb = api_get_path(WEB_COURSE_PATH);
  51. $coursePathSys = api_get_path(SYS_COURSE_PATH);
  52. $table_user = Database :: get_main_table(MAIN_USER_TABLE);
  53. $cidReq = $_REQUEST['cidReq'];
  54. $db_name = $_REQUEST['db_name'];
  55. $table_survey = Database :: get_course_table('survey');
  56. $table_group = Database :: get_course_table('survey_group');
  57. $table_question = Database :: get_course_table('questions');
  58. $table_course = Database :: get_main_table(MAIN_COURSE_TABLE);
  59. $table_course_survey_rel = Database :: get_main_table(MAIN_COURSE_SURVEY_TABLE);
  60. $tool_name = get_lang('New_survey');
  61. $tool_name1 = get_lang('Newsurvey');
  62. $interbredcrump[] = array ("url" => "survey_list.php", "name" => get_lang('Survey'));
  63. $course_id = $_SESSION['_course']['id'];
  64. $oldsurveyid=$_REQUEST['surveyid'];
  65. $survey_name=surveymanager::get_surveyname($db_name,$oldsurveyid);
  66. if ($_POST['action'] == 'add_survey')
  67. {
  68. $surveycode=$_POST['survey_code'];
  69. $surveytitle = $_POST['survey_title'];
  70. $surveysubtitle = $_POST['survey_subtitle'];
  71. //$cidReq = $dbNamePrefix.$_POST['cidReq'];
  72. $author = $_POST['author'];
  73. $survey_language = $_POST['survey_language'];
  74. $availablefrom = $_POST['fyear']."-".$_POST['fmonth']."-".$_POST['fday'];
  75. $availabletill = $_POST['end_fyear']."-".$_POST['end_fmonth']."-".$_POST['end_fday'];
  76. $isshare = $_POST['isshare'];
  77. $surveytemplate = $_POST['template'];
  78. $surveyintroduction = $_POST['content'];
  79. $surveythanks = $_POST['thanks'];
  80. $savailablefrom=mktime(0,0,0,$_POST['fmonth'],$_POST['fday'], $_POST['fyear']);
  81. $savailabletill=mktime(0,0,0,$_POST['end_fmonth'],$_POST['end_fday'], $_POST['end_fyear']);
  82. $cidReq=$_REQUEST['cidReq'];
  83. $db_name = $_REQUEST['db_name'];
  84. $surveyid = $_REQUEST['surveyid'];
  85. if(isset($_POST['back']))
  86. {
  87. $cidReq = $_REQUEST['cidReq'];
  88. $surveyid = $_REQUEST['surveyid'];
  89. $db_name = $_REQUEST['db_name'];
  90. header("location:create_from_existing_survey.php?cidReq=$cidReq&surveyid=$surveyid&db_name=$db_name");
  91. }
  92. $surveytitle=trim($surveytitle);
  93. $surveycode=trim($surveycode);
  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. $result=SurveyManager::get_survey_code($table_survey,$surveycode);
  107. if(!empty($result))
  108. {
  109. $error_message=get_lang('thiscodealradyexist');
  110. }
  111. else
  112. {
  113. $survey_id = SurveyManager::create_survey_attach($surveycode, $surveytitle, $surveysubtitle, $author, $survey_language, $availablefrom, $availabletill, $isshare, $surveytemplate, $surveyintroduction, $surveythanks, $table_survey, $table_group);
  114. $cidReq=$_GET['cidReq'];
  115. $curr_dbname=SurveyManager::create_course_survey_rel($cidReq,$survey_id,$table_course,$table_course_survey_rel);
  116. $oldsurveyid=$_POST['surveyid'];
  117. $db_name = $_REQUEST['db_name'];
  118. SurveyManager::attach_survey($oldsurveyid,$survey_id,$db_name,$curr_dbname);
  119. if (isset($_POST['next']))
  120. {
  121. $cidReq=$_GET['cidReq'];
  122. header("location:select_question_group.php?surveyid=$survey_id&cidReq=$cidReq&curr_dbname=$curr_dbname");
  123. exit;
  124. }
  125. else
  126. {
  127. $cidReq=$_GET['cidReq'];
  128. header("location:survey_list.php?&cidReq=$cidReq");
  129. exit;
  130. }
  131. }
  132. }
  133. }
  134. Display::display_header($tool_name);
  135. api_display_tool_title($tool_name1);
  136. //echo "<pre>";
  137. //print_r($_SESSION);
  138. //echo "</pre>";
  139. if( isset($error_message) )
  140. {
  141. Display::display_error_message($error_message);
  142. }
  143. ?>
  144. <SCRIPT LANGUAGE="JavaScript">
  145. <!-- Begin
  146. function displayTemplate(form) {
  147. var inf = form.template.value;
  148. if(inf=="")
  149. {
  150. alert("Please Select a Template");
  151. }
  152. else
  153. {
  154. window.open(inf+".htm", 'popup', 'width=600,height=600,toolbar = no, status = no');
  155. }
  156. //window.open(inf+".htm");
  157. //win.document.write("" + inf + "");
  158. }
  159. // End -->
  160. </script>
  161. <script src=tbl_change.js type="text/javascript" language="javascript"></script>
  162. <form name="new_calendar_item" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>?cidReq=<?=$cidReq?>">
  163. <input type="hidden" name="action" value="add_survey">
  164. <input type="hidden" name="surveyid" value="<?=$oldsurveyid?>">
  165. <input type="hidden" name="db_name" value="<?=$db_name?>">
  166. <table>
  167. <tr>
  168. <td><?php echo get_lang('surveycode'); ?></td>
  169. <td><input type="text" name="survey_code" size="20" maxlength="39" value="<?php echo $surveycode; ?>"></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 echo $surveytitle ?>"></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 echo $surveysubtitle ?>"></td>
  178. </tr>
  179. <tr>
  180. <?php
  181. if($_SESSION['is_platformAdmin']=='1'||$_SESSION['is_courseAdmin'])
  182. {
  183. echo "<td>";
  184. echo get_lang('author');
  185. echo "</td>";
  186. echo "<td>";
  187. UserManager::get_teacher_list($course_id, $author_id);
  188. echo "</td>";
  189. }
  190. ?>
  191. </tr>
  192. <tr>
  193. <td><?php echo get_lang('surveylanguage'); ?>&nbsp;</td>
  194. <td>
  195. <select name="survey_language">
  196. <option value="english" selected="selected">English</option>
  197. <option value="french" >Fran&ccedil;ais</option>
  198. <option value="dutch" >Nederlands</option>
  199. </select>
  200. </td>
  201. </tr>
  202. <tr id="subtitle">
  203. <td><?php echo get_lang('availablefrom'); ?>&nbsp;</td>
  204. <td>
  205. <select name="fday">
  206. <?
  207. for($i=1;$i<=31;$i++){
  208. if($i<=9) $val = "0".$i;
  209. else $val = $i;
  210. if ($val==$curr_day) $selected = "selected";
  211. else $selected = "";
  212. echo "<option value=\"$val\" $selected>$i</option>";
  213. }
  214. ?>
  215. </select>
  216. <!-- month: january ->
  217. december -->
  218. <select name="fmonth">
  219. <?
  220. for($i=1;$i<count($MonthsLong);$i++)
  221. {
  222. if($i<=9)
  223. $val = "0".$i;
  224. else
  225. $val = $i;
  226. if($val == $curr_month)
  227. echo "<option value=\"$val\" selected>".$MonthsLong[$i-1]."</option>\n";
  228. else
  229. echo "<option value=\"$val\">".$MonthsLong[$i-1]."</option>\n";
  230. }
  231. ?>
  232. </select>
  233. <select name="fyear">
  234. <?
  235. for($i=$curr_year;$i<=$curr_year+10;$i++){
  236. if($i == $curr_year)
  237. echo "<option value=\"$i\" selected>$i</option>\n";
  238. else
  239. echo "<option value=\"$i\">$i</option>\n";
  240. }
  241. ?>
  242. </select>
  243. <a title="Calendar" href="javascript:openCalendar('new_calendar_item', 'f')"><img src="../img/calendar_select.gif" border="0" align="absmiddle"/></a></td>
  244. </tr>
  245. <tr id="subtitle">
  246. <td><?php echo get_lang('availabletill'); ?>&nbsp;</td>
  247. <td>
  248. <select name="end_fday">
  249. <? for($i=1;$i<=31;$i++){
  250. if($i<=9)
  251. $val = "0".$i;
  252. else
  253. $val = $i;
  254. if ($val==$curr_day) $selected = "selected";
  255. else $selected = "";
  256. echo "<option value=\"$val\" $selected>$i</option>";
  257. }
  258. ?>
  259. </select>
  260. <!-- month: january ->
  261. december -->
  262. <select name="end_fmonth">
  263. <?
  264. for($i=1;$i<count($MonthsLong);$i++)
  265. {
  266. if($i<=9)
  267. $val = "0".$i;
  268. else
  269. $val = $i;
  270. if($val == $curr_month)
  271. echo "<option value=\"$val\" selected>".$MonthsLong[$i-1]."</option>\n";
  272. else
  273. echo "<option value=\"$val\">".$MonthsLong[$i-1]."</option>\n";
  274. }
  275. ?>
  276. </select>
  277. <select name="end_fyear">
  278. <?
  279. for($i=$curr_year;$i<=$curr_year+10;$i++){
  280. if($i == $curr_year+1)
  281. echo "<option value=\"$i\" selected>$i</option>\n";
  282. else
  283. echo "<option value=\"$i\">$i</option>\n";
  284. }
  285. ?>
  286. </select>
  287. <a title="Calendar" href="javascript:openCalendar('new_calendar_item', 'end_f')"><img src="../img/calendar_select.gif" border="0" align="absmiddle"/></a></td>
  288. </tr>
  289. <tr>
  290. <td valign="top"><?php echo get_lang('IsShareSurvey'); ?>&nbsp;</td>
  291. <td>
  292. <input type="radio" name="isshare" value="1">Yes&nbsp;<input type="radio" name="isshare" value="0" checked>No
  293. </td>
  294. </tr>
  295. <tr>
  296. <td><?php echo get_lang('surveytemplate'); ?>&nbsp;</td>
  297. <td>
  298. <select name="template">
  299. <option value="template1" <?php if($template=="template1") echo " selected "; ?>>OFO_nl</option>
  300. <option value="template2" <?php if($template=="template2") echo " selected "; ?>>IFA_fr</option>
  301. <option value="template3" <?php if($template=="template3") echo " selected "; ?>>SPF P&O_FR</option>
  302. <option value="template4" <?php if($template=="template4") echo " selected "; ?>>FOD P&O_NL</option>
  303. <option value="template5" <?php if($template=="template5") echo " selected "; ?>>Blank</option>
  304. </select>
  305. <input type="button" value="<?php echo get_lang('preview');?>" onClick="displayTemplate(new_calendar_item)">
  306. </td>
  307. </tr>
  308. <tr><td valign="top"><?php echo get_lang('surveyintroduction'); ?>&nbsp;</td>
  309. <td>
  310. <?php
  311. api_disp_html_area('content',$content,'300px');
  312. /*$oFCKeditor = new FCKeditor('content') ;
  313. $oFCKeditor->BasePath = 'FCKeditor/';
  314. $oFCKeditor->Value = 'Enter your introduction text here';
  315. $oFCKeditor->Width = '600' ;
  316. $oFCKeditor->Height = '400' ;
  317. $oFCKeditor->Create();
  318. */
  319. ?>
  320. <br>
  321. </td>
  322. </tr>
  323. <tr><td valign="top"><?php echo get_lang('Thanks'); ?>&nbsp;</td>
  324. <td>
  325. <?php
  326. api_disp_html_area('thanks',$thanks,'200px');
  327. ?>
  328. <br>
  329. </td>
  330. </tr>
  331. <tr>
  332. <td><?php echo get_lang('surveyattached');?></td>
  333. <td><?php echo $survey_name;?></td>
  334. </tr>
  335. </table>
  336. <table>
  337. <tr>
  338. <td></td>
  339. <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>
  340. </tr>
  341. </table>
  342. </form>
  343. </table>
  344. <?php
  345. Display :: display_footer();
  346. ?>