attach_survey.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. $gids = $_REQUEST['gids'];
  66. $survey_name=surveymanager::get_surveyname($db_name,$oldsurveyid);
  67. if ($_POST['action'] == 'add_survey')
  68. {
  69. $surveycode=$_POST['survey_code'];
  70. $surveytitle = $_POST['survey_title'];
  71. $surveysubtitle = $_POST['survey_subtitle'];
  72. //$cidReq = $dbNamePrefix.$_POST['cidReq'];
  73. $author = $_POST['author'];
  74. $survey_language = $_POST['survey_language'];
  75. $availablefrom = $_POST['fyear']."-".$_POST['fmonth']."-".$_POST['fday'];
  76. $availabletill = $_POST['end_fyear']."-".$_POST['end_fmonth']."-".$_POST['end_fday'];
  77. $isshare = $_POST['isshare'];
  78. $surveytemplate = $_POST['template'];
  79. $surveyintroduction = $_POST['content'];
  80. $surveythanks = $_POST['thanks'];
  81. $savailablefrom=mktime(0,0,0,$_POST['fmonth'],$_POST['fday'], $_POST['fyear']);
  82. $savailabletill=mktime(0,0,0,$_POST['end_fmonth'],$_POST['end_fday'], $_POST['end_fyear']);
  83. $cidReq=$_REQUEST['cidReq'];
  84. $gids = $_POST['gids'];
  85. $db_name = $_REQUEST['db_name'];
  86. $surveyid = $_REQUEST['surveyid'];
  87. if(isset($_POST['back']))
  88. {
  89. $cidReq=$_REQUEST['cidReq'];
  90. $surveyid=$_REQUEST['surveyid'];
  91. $db_name=$_REQUEST['db_name'];
  92. header("location:create_from_existing_survey.php?cidReq=$cidReq&surveyid=$surveyid&db_name=$db_name");
  93. }
  94. $surveytitle=trim($surveytitle);
  95. $surveycode=trim($surveycode);
  96. if(empty ($surveytitle))
  97. {
  98. $error_message = get_lang('PleaseEnterSurveyTitle');
  99. }
  100. elseif ($savailabletill<=$savailablefrom){
  101. $error_message = get_lang('PleaseEnterValidDate');
  102. }
  103. elseif (empty ($surveycode)){
  104. $error_message = get_lang('PleaseEnterValidCode');
  105. }
  106. else
  107. {
  108. $result=SurveyManager::get_survey_code($table_survey,$surveycode);
  109. if(!empty($result))
  110. {
  111. $error_message=get_lang('thiscodealradyexist');
  112. }
  113. else
  114. {
  115. $survey_id = SurveyManager::create_survey($surveycode, $surveytitle, $surveysubtitle, $author, $survey_language, $availablefrom, $availabletill, $isshare, $surveytemplate, $surveyintroduction, $surveythanks, $table_survey, $table_group);
  116. $cidReq=$_GET['cidReq'];
  117. $curr_dbname=SurveyManager::create_course_survey_rel($cidReq,$survey_id,$table_course,$table_course_survey_rel);
  118. $oldsurveyid=$_POST['surveyid'];
  119. $gids = $_POST['gids'];
  120. $db_name = $_REQUEST['db_name'];
  121. //surveymanager::insert_existing_groups($survey_id,$gids,$table_group,$table_question);
  122. surveymanager::import_group($survey_id,$gids,$db_name,$curr_dbname);
  123. /*
  124. $survey_id = SurveyManager::create_survey_attach($surveycode, $surveytitle, $surveysubtitle, $author, $survey_language, $availablefrom, $availabletill, $isshare, $surveytemplate, $surveyintroduction,$table_survey, $table_group);
  125. $oldsurveyid=$_POST['oldsurveyid'];
  126. SurveyManager::attach_survey($oldsurveyid,$survey_id,$table_group,$table_question);
  127. */
  128. if (isset($_POST['next']))
  129. {
  130. $cidReq=$_GET['cidReq'];
  131. header("location:select_question_group.php?surveyid=$survey_id&cidReq=$cidReq&curr_dbname=$curr_dbname");
  132. exit;
  133. }
  134. else
  135. {
  136. $cidReq=$_GET['cidReq'];
  137. header("location:survey_list.php?&cidReq=$cidReq");
  138. exit;
  139. }
  140. }
  141. }
  142. }
  143. Display::display_header($tool_name);
  144. api_display_tool_title($tool_name1);
  145. //echo "<pre>";
  146. //print_r($_SESSION);
  147. //echo "</pre>";
  148. if( isset($error_message) )
  149. {
  150. Display::display_error_message($error_message);
  151. }
  152. ?>
  153. <SCRIPT LANGUAGE="JavaScript">
  154. <!-- Begin
  155. function displayTemplate(form) {
  156. var inf = form.template.value;
  157. if(inf=="")
  158. {
  159. alert("Please Select a Template");
  160. }
  161. else
  162. {
  163. window.open(inf+".htm", 'popup', 'width=900,height=800,toolbar = no, status = no');
  164. }
  165. //window.open(inf+".htm");
  166. //win.document.write("" + inf + "");
  167. }
  168. // End -->
  169. </script>
  170. <script src=tbl_change.js type="text/javascript" language="javascript"></script>
  171. <form name="new_calendar_item" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>?cidReq=<?=$cidReq?>">
  172. <input type="hidden" name="action" value="add_survey">
  173. <input type="hidden" name="surveyid" value="<?=$oldsurveyid?>">
  174. <input type="hidden" name="db_name" value="<?=$db_name?>">
  175. <input type="hidden" name="gids" value="<?=$gids?>">
  176. <table>
  177. <tr>
  178. <td><?php echo get_lang('surveycode'); ?></td>
  179. <td><input type="text" name="survey_code" size="20" maxlength="39" value="<?php echo $surveycode; ?>"></td>
  180. </tr>
  181. <tr>
  182. <td><?php echo get_lang('surveytitle'); ?></td>
  183. <td><input type="text" name="survey_title" size="40" maxlength="79" value="<?php echo $surveytitle ?>"></td>
  184. </tr>
  185. <tr>
  186. <td><?php echo get_lang('surveysubtitle'); ?></td>
  187. <td><input type="text" name="survey_subtitle" size="40" maxlength="79" value="<?php echo $surveysubtitle ?>"></td>
  188. </tr>
  189. <tr>
  190. <?php
  191. if($_SESSION['is_platformAdmin']=='1'||$_SESSION['is_courseAdmin'])
  192. {
  193. echo "<td>";
  194. echo get_lang('author');
  195. echo "</td>";
  196. echo "<td>";
  197. UserManager::get_teacher_list($course_id, $author_id);
  198. echo "</td>";
  199. }
  200. ?>
  201. </tr>
  202. <tr>
  203. <td><?php echo get_lang('surveylanguage'); ?>&nbsp;</td>
  204. <td>
  205. <select name="survey_language">
  206. <option value="english" selected="selected">English</option>
  207. <option value="french" >Fran&ccedil;ais</option>
  208. <option value="dutch" >Nederlands</option>
  209. </select>
  210. </td>
  211. </tr>
  212. <tr id="subtitle">
  213. <td><?php echo get_lang('availablefrom'); ?>&nbsp;</td>
  214. <td>
  215. <select name="fday">
  216. <?
  217. for($i=1;$i<=31;$i++){
  218. if($i<=9) $val = "0".$i;
  219. else $val = $i;
  220. if ($val==$curr_day) $selected = "selected";
  221. else $selected = "";
  222. echo "<option value=\"$val\" $selected>$i</option>";
  223. }
  224. ?>
  225. </select>
  226. <!-- month: january ->
  227. december -->
  228. <select name="fmonth">
  229. <?
  230. for($i=1;$i<count($MonthsLong);$i++)
  231. {
  232. if($i<=9)
  233. $val = "0".$i;
  234. else
  235. $val = $i;
  236. if($val == $curr_month)
  237. echo "<option value=\"$val\" selected>".$MonthsLong[$i-1]."</option>\n";
  238. else
  239. echo "<option value=\"$val\">".$MonthsLong[$i-1]."</option>\n";
  240. }
  241. ?>
  242. </select>
  243. <select name="fyear">
  244. <?
  245. for($i=$curr_year;$i<=$curr_year+10;$i++){
  246. if($i == $curr_year)
  247. echo "<option value=\"$i\" selected>$i</option>\n";
  248. else
  249. echo "<option value=\"$i\">$i</option>\n";
  250. }
  251. ?>
  252. </select>
  253. <a title="Calender" href="javascript:openCalendar('new_calendar_item', 'f')"><img src="../img/calendar_select.gif" border="0" align="absmiddle"/></a></td>
  254. </tr>
  255. <tr id="subtitle">
  256. <td><?php echo get_lang('availabletill'); ?>&nbsp;</td>
  257. <td>
  258. <select name="end_fday">
  259. <? for($i=1;$i<=31;$i++){
  260. if($i<=9)
  261. $val = "0".$i;
  262. else
  263. $val = $i;
  264. if ($val==$curr_day) $selected = "selected";
  265. else $selected = "";
  266. echo "<option value=\"$val\" $selected>$i</option>";
  267. }
  268. ?>
  269. </select>
  270. <!-- month: january ->
  271. december -->
  272. <select name="end_fmonth">
  273. <?
  274. for($i=1;$i<count($MonthsLong);$i++)
  275. {
  276. if($i<=9)
  277. $val = "0".$i;
  278. else
  279. $val = $i;
  280. if($val == $curr_month)
  281. echo "<option value=\"$val\" selected>".$MonthsLong[$i-1]."</option>\n";
  282. else
  283. echo "<option value=\"$val\">".$MonthsLong[$i-1]."</option>\n";
  284. }
  285. ?>
  286. </select>
  287. <select name="end_fyear">
  288. <?
  289. for($i=$curr_year;$i<=$curr_year+10;$i++){
  290. if($i == $curr_year+1)
  291. echo "<option value=\"$i\" selected>$i</option>\n";
  292. else
  293. echo "<option value=\"$i\">$i</option>\n";
  294. }
  295. ?>
  296. </select>
  297. <a title="Calender" href="javascript:openCalendar('new_calendar_item', 'end_f')"><img src="../img/calendar_select.gif" border="0" align="absmiddle"/></a></td>
  298. </tr>
  299. <tr>
  300. <td valign="top"><?php echo get_lang('IsShareSurvey'); ?>&nbsp;</td>
  301. <td>
  302. <input type="radio" name="isshare" value="1">Yes&nbsp;<input type="radio" name="isshare" value="0" checked>No
  303. </td>
  304. </tr>
  305. <tr>
  306. <td><?php echo get_lang('surveytemplate'); ?>&nbsp;</td>
  307. <td>
  308. <select name="template">
  309. <option value="template1">OFO_nl</option>
  310. <option value="template2">IFA_fr</option>
  311. <option value="template3">SPF P&O_FR</option>
  312. <option value="template4">FOD P&O_NL</option>
  313. <option value="template5">Blank</option>
  314. </select>
  315. <input type="button" value="<?php echo get_lang('preview');?>" onClick="displayTemplate(new_calendar_item)">
  316. </td>
  317. </tr>
  318. <tr><td valign="top"><?php echo get_lang('surveyintroduction'); ?>&nbsp;</td>
  319. <td>
  320. <?php
  321. api_disp_html_area('content',$content,'300px');
  322. /*$oFCKeditor = new FCKeditor('content') ;
  323. $oFCKeditor->BasePath = 'FCKeditor/';
  324. $oFCKeditor->Value = 'Enter your introduction text here';
  325. $oFCKeditor->Width = '600' ;
  326. $oFCKeditor->Height = '400' ;
  327. $oFCKeditor->Create();
  328. */
  329. ?>
  330. <br>
  331. </td>
  332. </tr>
  333. <tr><td valign="top"><?php echo get_lang('Thanks'); ?>&nbsp;</td>
  334. <td>
  335. <?php
  336. api_disp_html_area('thanks',$thanks,'200px');
  337. ?>
  338. <br>
  339. </td>
  340. </tr>
  341. <tr>
  342. <td><?php echo get_lang('surveyattached');?>&nbsp;&nbsp;<?php echo $survey_name;?></td>
  343. </tr>
  344. </table>
  345. <tr>
  346. <td>&nbsp;</td>
  347. <td><input type="submit" name="back" value="<? echo get_lang('back');?>"></td>
  348. <td><input type="submit" name="saveandexit" value="<?php echo get_lang('createlater'); ?>"></td>
  349. <td><input type="submit" name="next" value="<?php echo get_lang('next'); ?>"></td>
  350. </tr>
  351. </table>
  352. </form>
  353. </table>
  354. <?php
  355. Display :: display_footer();
  356. ?>