infocours.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <?php
  2. // $Id: infocours.php 9822 2006-10-26 09:55:27Z bmol $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004 Dokeos S.A.
  7. Copyright (c) 2003 Ghent University (UGent)
  8. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9. Copyright (c) Hugues Peeters
  10. Copyright (c) Roan Embrechts (Vrije Universiteit Brussel)
  11. Copyright (c) Olivier Brouckaert
  12. Copyright (c) Bart Mollet, Hogeschool Gent
  13. For a full list of contributors, see "credits.txt".
  14. The full license can be read in "license.txt".
  15. This program is free software; you can redistribute it and/or
  16. modify it under the terms of the GNU General Public License
  17. as published by the Free Software Foundation; either version 2
  18. of the License, or (at your option) any later version.
  19. See the GNU General Public License for more details.
  20. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  21. ==============================================================================
  22. */
  23. /**
  24. ==============================================================================
  25. * Code to display the course settings form (for the course admin)
  26. * and activate the changes.
  27. *
  28. * See ./inc/conf/course_info.conf.php for settings
  29. * @todo: Move $canBeEmpty from course_info.conf.php to config-settings
  30. * @todo: Take those config settings into account in this script
  31. * @author Patrick Cool <patrick.cool@UGent.be>
  32. * @author Roan Embrechts, refactoring
  33. * and improved course visibility|subscribe|unsubscribe options
  34. * @package dokeos.course_info
  35. ==============================================================================
  36. */
  37. /*
  38. ==============================================================================
  39. INIT SECTION
  40. ==============================================================================
  41. */
  42. $langFile = array ('create_course', 'course_info');
  43. include ('../inc/global.inc.php');
  44. $this_section = SECTION_COURSES;
  45. /*
  46. -----------------------------------------------------------
  47. Libraries
  48. -----------------------------------------------------------
  49. */
  50. require_once (api_get_path(LIBRARY_PATH).'course.lib.php');
  51. require_once (api_get_path(INCLUDE_PATH)."conf/course_info.conf.php");
  52. require_once (api_get_path(INCLUDE_PATH)."lib/debug.lib.inc.php");
  53. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  54. /*
  55. -----------------------------------------------------------
  56. Constants and variables
  57. -----------------------------------------------------------
  58. */
  59. define("MODULE_HELP_NAME", "Settings");
  60. define("COURSE_CHANGE_PROPERTIES", "COURSE_CHANGE_PROPERTIES");
  61. $TABLECOURSE = Database :: get_main_table(MAIN_COURSE_TABLE);
  62. $TABLEFACULTY = Database :: get_main_table(MAIN_CATEGORY_TABLE);
  63. $TABLECOURSEHOME = Database :: get_course_table(TOOL_LIST_TABLE);
  64. $TABLELANGUAGES = Database :: get_main_table(MAIN_LANGUAGE_TABLE);
  65. $TABLEBBCONFIG = Database :: get_course_table(FORUM_CONFIG_TABLE);
  66. $currentCourseID = $_course['sysCode'];
  67. $currentCourseRepository = $_course["path"];
  68. $is_allowedToEdit = $is_courseAdmin;
  69. $course_setting_table = Database::get_course_table(COURSE_SETTING_TABLE);
  70. /*
  71. ==============================================================================
  72. LOGIC FUNCTIONS
  73. ==============================================================================
  74. */
  75. function is_settings_editable()
  76. {
  77. return $GLOBALS["course_info_is_editable"];
  78. }
  79. $course_code = $_course["sysCode"];
  80. $course_access_settings = CourseManager :: get_access_settings($course_code);
  81. /*
  82. ==============================================================================
  83. MAIN CODE
  84. ==============================================================================
  85. */
  86. if (!$is_allowedToEdit)
  87. {
  88. api_not_allowed();
  89. }
  90. // Get all course categories
  91. $table_course_category = Database :: get_main_table(MAIN_CATEGORY_TABLE);
  92. $sql = "SELECT code,name FROM ".$table_course_category." WHERE auth_course_child ='TRUE' OR code = '".mysql_real_escape_string($_course['categoryCode'])."' ORDER BY tree_pos";
  93. $res = api_sql_query($sql, __FILE__, __LINE__);
  94. $s_select_course_tutor_name="SELECT tutor_name FROM course WHERE code='$course_code'";
  95. $q_tutor=api_sql_query($s_select_course_tutor_name, __FILE__, __LINE__);
  96. $s_tutor=mysql_result($q_tutor,0,"tutor_name");
  97. $s_sql_course_titular="SELECT DISTINCT username, lastname, firstname FROM user, course_rel_user WHERE (course_rel_user.status='1') AND user.user_id=course_rel_user.user_id AND course_code='".$course_code."'";
  98. $q_result_titulars=api_sql_query($s_sql_course_titular, __FILE__, __LINE__);
  99. while($a_titulars=mysql_fetch_array($q_result_titulars)){
  100. $s_username=$a_titulars["username"];
  101. $s_lastname=$a_titulars["lastname"];
  102. $s_firstname=$a_titulars["firstname"];
  103. if($s_username==$s_tutor){
  104. $s_selected_tutor=$s_username;
  105. }
  106. $s_disabled_select_titular="";
  107. if(!$is_courseAdmin){
  108. $s_disabled_select_titular="disabled=disabled";
  109. }
  110. $a_profs[$s_username]="$s_lastname $s_firstname ($s_username)";
  111. }
  112. while ($cat = mysql_fetch_array($res))
  113. {
  114. $categories[$cat['code']] = '('.$cat['code'].') '.$cat['name'];
  115. }
  116. // Build the form
  117. $form = new FormValidator('update_course');
  118. $form->add_textfield('visual_code', get_lang('Code'));
  119. $form->applyFilter('visual_code', 'strtoupper');
  120. //$form->add_textfield('tutor_name', get_lang('Professors'), true, array ('size' => '60'));
  121. $prof = &$form->addElement('select', 'tutor_name', get_lang('Professors'), $a_profs);
  122. $prof -> setSelected($s_selected_tutor);
  123. $form->add_textfield('title', get_lang('Title'), true, array ('size' => '60'));
  124. $form->addElement('select', 'category_code', get_lang('Fac'), $categories);
  125. $form->add_textfield('department_name', get_lang('Department'), false, array ('size' => '60'));
  126. $form->add_textfield('department_url', get_lang('DepartmentUrl'), false, array ('size' => '60'));
  127. $form->addRule('tutor_name', get_lang('ThisFieldIsRequired'), 'required');
  128. $form->addElement('select_language', 'course_language', get_lang('Ln'));
  129. $form->addElement('static', null, null, get_lang("TipLang"));
  130. $form->addElement('radio', 'visibility', get_lang("CourseAccess"), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
  131. $form->addElement('radio', 'visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
  132. $form->addElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
  133. $form->addElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
  134. $form->addElement('radio', 'subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
  135. $form->addElement('radio', 'subscribe', null, get_lang('Denied'), 0);
  136. $form->addElement('radio', 'unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
  137. $form->addElement('radio', 'unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
  138. $form->addElement('radio', 'email_alert_manager_on_new_doc', get_lang('WorkEmailAlert'), get_lang('WorkEmailAlertActivate'), 1);
  139. $form->addElement('radio', 'email_alert_manager_on_new_doc', null, get_lang('WorkEmailAlertDeactivate'), 0);
  140. $form->addElement('radio', 'email_alert_on_new_doc_dropbox', get_lang('DropboxEmailAlert'), get_lang('DropboxEmailAlertActivate'), 1);
  141. $form->addElement('radio', 'email_alert_on_new_doc_dropbox', null, get_lang('DropboxEmailAlertDeactivate'), 0);
  142. $form->addElement('radio', 'allow_user_edit_agenda', get_lang('AllowUserEditAgenda'), get_lang('AllowUserEditAgendaActivate'), 1);
  143. $form->addElement('radio', 'allow_user_edit_agenda', null, get_lang('AllowUserEditAgendaDeactivate'), 0);
  144. $form->addElement('radio', 'allow_user_edit_announcement', get_lang('AllowUserEditAnnouncement'), get_lang('AllowUserEditAnnouncementActivate'), 1);
  145. $form->addElement('radio', 'allow_user_edit_announcement', null, get_lang('AllowUserEditAnnouncementDeactivate'), 0);
  146. $form->addElement('static', null, null, get_lang("ConfTip"));
  147. $form->add_textfield('course_registration_password', get_lang('CourseRegistrationPassword'), false, array ('size' => '60'));
  148. if (is_settings_editable())
  149. {
  150. $form->addElement('submit', null, get_lang('Ok'));
  151. }
  152. else
  153. {
  154. // is it allowed to edit the course settings?
  155. if (!is_settings_editable())
  156. $disabled_output = "disabled";
  157. $form->freeze();
  158. }
  159. // get all the course information
  160. $all_course_information = CourseManager::get_course_information($_course['sysCode']);
  161. // Set the default values of the form
  162. $values['title'] = $_course['name'];
  163. $values['visual_code'] = $_course['official_code'];
  164. $values['category_code'] = $_course['categoryCode'];
  165. //$values['tutor_name'] = $_course['titular'];
  166. $values['course_language'] = $_course['language'];
  167. $values['department_name'] = $_course['extLink']['name'];
  168. $values['department_url'] = $_course['extLink']['url'];
  169. $values['visibility'] = $_course['visibility'];
  170. $values['subscribe'] = $course_access_settings['subscribe'];
  171. $values['unsubscribe'] = $course_access_settings['unsubscribe'];
  172. $values['course_registration_password'] = $all_course_information['registration_code'];
  173. // get send_mail_setting (work)from table
  174. $values['email_alert_manager_on_new_doc'] = api_get_course_setting('email_alert_manager_on_new_doc');
  175. // get send_mail_setting (dropbox) from table
  176. $values['email_alert_on_new_doc_dropbox'] = api_get_course_setting('email_alert_on_new_doc_dropbox');
  177. // get allow_user_edit_agenda from table
  178. $values['allow_user_edit_agenda'] = api_get_course_setting('allow_user_edit_agenda');
  179. // get allow_user_edit_announcement from table
  180. $values['allow_user_edit_announcement'] = api_get_course_setting('allow_user_edit_announcement');
  181. $form->setDefaults($values);
  182. // Validate form
  183. if ($form->validate() && is_settings_editable())
  184. {
  185. $update_values = $form->exportValues();
  186. foreach ($update_values as $index => $value)
  187. {
  188. $update_values[$index] = mysql_real_escape_string($value);
  189. }
  190. $table_course = Database :: get_main_table(MAIN_COURSE_TABLE);
  191. $sql = "UPDATE $table_course SET title = '".$update_values['title']."',
  192. visual_code = '".$update_values['visual_code']."',
  193. course_language = '".$update_values['course_language']."',
  194. category_code = '".$update_values['category_code']."',
  195. department_name = '".$update_values['department_name']."',
  196. department_url = '".$update_values['department_url']."',
  197. visibility = '".$update_values['visibility']."',
  198. subscribe = '".$update_values['subscribe']."',
  199. unsubscribe = '".$update_values['unsubscribe']."',
  200. tutor_name = '".$update_values['tutor_name']."',
  201. registration_code = '".$update_values['course_registration_password']."'
  202. WHERE code = '".$course_code."'";
  203. api_sql_query($sql, __FILE__, __LINE__);
  204. //update course_settings table
  205. $table_course_setting = Database::get_course_table(COURSE_SETTING_TABLE);
  206. if($update_values['email_alert_manager_on_new_doc'] != $values['email_alert_manager_on_new_doc']){
  207. $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['email_alert_manager_on_new_doc']." WHERE variable = 'email_alert_manager_on_new_doc'' ";
  208. api_sql_query($sql,__FILE__,__LINE__);
  209. }
  210. if($update_values['email_alert_on_new_doc_dropbox'] != $values['email_alert_on_new_doc_dropbox']){
  211. $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['email_alert_on_new_doc_dropbox']." WHERE variable = 'email_alert_on_new_doc_dropbox' ";
  212. api_sql_query($sql,__FILE__,__LINE__);
  213. }
  214. if($update_values['allow_user_edit_agenda'] != $values['allow_user_edit_agenda']){
  215. $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['allow_user_edit_agenda']." WHERE variable = 'allow_user_edit_agenda' ";
  216. api_sql_query($sql,__FILE__,__LINE__);
  217. }
  218. if($update_values['allow_user_edit_announcement'] != $values['allow_user_edit_announcement']){
  219. $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['allow_user_edit_announcement']." WHERE variable = 'allow_user_edit_announcement' ";
  220. api_sql_query($sql,__FILE__,__LINE__);
  221. }
  222. $cidReset = true;
  223. $cidReq = $course_code;
  224. include ('../inc/local.inc.php');
  225. header('Location: infocours.php?action=show_message&amp;cidReq='.$course_code);
  226. exit;
  227. }
  228. /*
  229. -----------------------------------------------------------
  230. Header
  231. -----------------------------------------------------------
  232. */
  233. $nameTools = get_lang("ModifInfo");
  234. Display :: display_header($nameTools, MODULE_HELP_NAME);
  235. //api_display_tool_title($nameTools);
  236. if (isset ($_GET['action']) && $_GET['action'] == 'show_message')
  237. {
  238. Display :: display_normal_message(get_lang('ModifDone'));
  239. }
  240. // Display the form
  241. $form->display();
  242. if ($showDiskQuota && $currentCourseDiskQuota != "")
  243. {
  244. ?>
  245. <table>
  246. <tr>
  247. <td><?php echo get_lang("DiskQuota"); ?>&nbsp;:</td>
  248. <td><?php echo $currentCourseDiskQuota; ?> <?php echo $byteUnits[0] ?></td>
  249. </tr>
  250. <?php
  251. }
  252. if ($showLastEdit && $currentCourseLastEdit != "" && $currentCourseLastEdit != "0000-00-00 00:00:00")
  253. {
  254. ?>
  255. <tr>
  256. <td><?php echo get_lang('LastEdit'); ?>&nbsp;:</td>
  257. <td><?php echo format_locale_date($dateTimeFormatLong,strtotime($currentCourseLastEdit)); ?></td>
  258. </tr>
  259. <?php
  260. }
  261. if ($showLastVisit && $currentCourseLastVisit != "" && $currentCourseLastVisit != "0000-00-00 00:00:00")
  262. {
  263. ?>
  264. <tr>
  265. <td><?php echo get_lang('LastVisit'); ?>&nbsp;:</td>
  266. <td><?php echo format_locale_date($dateTimeFormatLong,strtotime($currentCourseLastVisit)); ?></td>
  267. </tr>
  268. <?php
  269. }
  270. if ($showCreationDate && $currentCourseCreationDate != "" && $currentCourseCreationDate != "0000-00-00 00:00:00")
  271. {
  272. ?>
  273. <tr>
  274. <td><?php echo get_lang('CreationDate'); ?>&nbsp;:</td>
  275. <td><?php echo format_locale_date($dateTimeFormatLong,strtotime($currentCourseCreationDate)); ?></td>
  276. </tr>
  277. <?php
  278. }
  279. if ($showExpirationDate && $currentCourseExpirationDate != "" && $currentCourseExpirationDate != "0000-00-00 00:00:00")
  280. {
  281. ?>
  282. <tr>
  283. <td><?php echo get_lang('ExpirationDate'); ?>&nbsp;:</td>
  284. <td>
  285. <?php
  286. echo format_locale_date($dateTimeFormatLong, strtotime($currentCourseExpirationDate));
  287. echo "<br />".get_lang('OrInTime')." : ";
  288. $nbJour = (strtotime($currentCourseExpirationDate) - time()) / (60 * 60 * 24);
  289. $nbAnnees = round($nbJour / 365);
  290. $nbJour = round($nbJour - $nbAnnees * 365);
  291. switch ($nbAnnees)
  292. {
  293. case "1" :
  294. echo $nbAnnees, " an ";
  295. break;
  296. case "0" :
  297. break;
  298. default :
  299. echo $nbAnnees, " ans ";
  300. };
  301. switch ($nbJour)
  302. {
  303. case "1" :
  304. echo $nbJour, " jour ";
  305. break;
  306. case "0" :
  307. break;
  308. default :
  309. echo $nbJour, " jours ";
  310. }
  311. if ($canReportExpirationDate)
  312. {
  313. echo " -&gt; <a href=\"".$urlScriptToReportExpirationDate."\">".get_lang('PostPone')."</a>";
  314. }
  315. ?>
  316. </td>
  317. </tr>
  318. </table>
  319. <?php
  320. }
  321. /*
  322. ==============================================================================
  323. FOOTER
  324. ==============================================================================
  325. */
  326. Display::display_footer();
  327. ?>