infocours.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <?php
  2. // $Id: infocours.php 10204 2006-11-26 20:46:53Z pcool $
  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. // name of the language file that needs to be included
  43. $language_file = array ('create_course', 'course_info');
  44. include ('../inc/global.inc.php');
  45. $this_section = SECTION_COURSES;
  46. /*
  47. -----------------------------------------------------------
  48. Libraries
  49. -----------------------------------------------------------
  50. */
  51. require_once (api_get_path(LIBRARY_PATH).'course.lib.php');
  52. require_once (api_get_path(INCLUDE_PATH)."conf/course_info.conf.php");
  53. require_once (api_get_path(INCLUDE_PATH)."lib/debug.lib.inc.php");
  54. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  55. /*
  56. -----------------------------------------------------------
  57. Constants and variables
  58. -----------------------------------------------------------
  59. */
  60. define("MODULE_HELP_NAME", "Settings");
  61. define("COURSE_CHANGE_PROPERTIES", "COURSE_CHANGE_PROPERTIES");
  62. $TABLECOURSE = Database :: get_main_table(TABLE_MAIN_COURSE);
  63. $TABLEFACULTY = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  64. $TABLECOURSEHOME = Database :: get_course_table(TABLE_TOOL_LIST);
  65. $TABLELANGUAGES = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
  66. $TABLEBBCONFIG = Database :: get_course_table(TOOL_FORUM_CONFIG_TABLE);
  67. $currentCourseID = $_course['sysCode'];
  68. $currentCourseRepository = $_course["path"];
  69. $is_allowedToEdit = $is_courseAdmin;
  70. $course_setting_table = Database::get_course_table(TABLE_COURSE_SETTING);
  71. /*
  72. ==============================================================================
  73. LOGIC FUNCTIONS
  74. ==============================================================================
  75. */
  76. function is_settings_editable()
  77. {
  78. return $GLOBALS["course_info_is_editable"];
  79. }
  80. $course_code = $_course["sysCode"];
  81. $course_access_settings = CourseManager :: get_access_settings($course_code);
  82. /*
  83. ==============================================================================
  84. MAIN CODE
  85. ==============================================================================
  86. */
  87. if (!$is_allowedToEdit)
  88. {
  89. api_not_allowed();
  90. }
  91. // Get all course categories
  92. $table_course_category = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  93. $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";
  94. $res = api_sql_query($sql, __FILE__, __LINE__);
  95. $s_select_course_tutor_name="SELECT tutor_name FROM course WHERE code='$course_code'";
  96. $q_tutor=api_sql_query($s_select_course_tutor_name, __FILE__, __LINE__);
  97. $s_tutor=mysql_result($q_tutor,0,"tutor_name");
  98. $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."'";
  99. $q_result_titulars=api_sql_query($s_sql_course_titular, __FILE__, __LINE__);
  100. while($a_titulars=mysql_fetch_array($q_result_titulars)){
  101. $s_username=$a_titulars["username"];
  102. $s_lastname=$a_titulars["lastname"];
  103. $s_firstname=$a_titulars["firstname"];
  104. if($s_username==$s_tutor){
  105. $s_selected_tutor=$s_username;
  106. }
  107. $s_disabled_select_titular="";
  108. if(!$is_courseAdmin){
  109. $s_disabled_select_titular="disabled=disabled";
  110. }
  111. $a_profs[$s_username]="$s_lastname $s_firstname ($s_username)";
  112. }
  113. while ($cat = mysql_fetch_array($res))
  114. {
  115. $categories[$cat['code']] = '('.$cat['code'].') '.$cat['name'];
  116. }
  117. // Build the form
  118. $form = new FormValidator('update_course');
  119. $form->add_textfield('visual_code', get_lang('Code'));
  120. $form->applyFilter('visual_code', 'strtoupper');
  121. //$form->add_textfield('tutor_name', get_lang('Professors'), true, array ('size' => '60'));
  122. $prof = &$form->addElement('select', 'tutor_name', get_lang('Professors'), $a_profs);
  123. $prof -> setSelected($s_selected_tutor);
  124. $form->add_textfield('title', get_lang('Title'), true, array ('size' => '60'));
  125. $form->addElement('select', 'category_code', get_lang('Fac'), $categories);
  126. $form->add_textfield('department_name', get_lang('Department'), false, array ('size' => '60'));
  127. $form->add_textfield('department_url', get_lang('DepartmentUrl'), false, array ('size' => '60'));
  128. $form->addRule('tutor_name', get_lang('ThisFieldIsRequired'), 'required');
  129. $form->addElement('select_language', 'course_language', get_lang('Ln'));
  130. $form->addElement('static', null, null, get_lang("TipLang"));
  131. $form->addElement('radio', 'visibility', get_lang("CourseAccess"), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
  132. $form->addElement('radio', 'visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
  133. $form->addElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
  134. $form->addElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
  135. $form->addElement('radio', 'subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
  136. $form->addElement('radio', 'subscribe', null, get_lang('Denied'), 0);
  137. $form->addElement('radio', 'unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
  138. $form->addElement('radio', 'unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
  139. $form->addElement('radio', 'email_alert_manager_on_new_doc', get_lang('WorkEmailAlert'), get_lang('WorkEmailAlertActivate'), 1);
  140. $form->addElement('radio', 'email_alert_manager_on_new_doc', null, get_lang('WorkEmailAlertDeactivate'), 0);
  141. $form->addElement('radio', 'email_alert_on_new_doc_dropbox', get_lang('DropboxEmailAlert'), get_lang('DropboxEmailAlertActivate'), 1);
  142. $form->addElement('radio', 'email_alert_on_new_doc_dropbox', null, get_lang('DropboxEmailAlertDeactivate'), 0);
  143. $form->addElement('radio', 'allow_user_edit_agenda', get_lang('AllowUserEditAgenda'), get_lang('AllowUserEditAgendaActivate'), 1);
  144. $form->addElement('radio', 'allow_user_edit_agenda', null, get_lang('AllowUserEditAgendaDeactivate'), 0);
  145. $form->addElement('radio', 'allow_user_edit_announcement', get_lang('AllowUserEditAnnouncement'), get_lang('AllowUserEditAnnouncementActivate'), 1);
  146. $form->addElement('radio', 'allow_user_edit_announcement', null, get_lang('AllowUserEditAnnouncementDeactivate'), 0);
  147. $form->addElement('static', null, null, get_lang("ConfTip"));
  148. $form->add_textfield('course_registration_password', get_lang('CourseRegistrationPassword'), false, array ('size' => '60'));
  149. if (is_settings_editable())
  150. {
  151. $form->addElement('submit', null, get_lang('Ok'));
  152. }
  153. else
  154. {
  155. // is it allowed to edit the course settings?
  156. if (!is_settings_editable())
  157. $disabled_output = "disabled";
  158. $form->freeze();
  159. }
  160. // get all the course information
  161. $all_course_information = CourseManager::get_course_information($_course['sysCode']);
  162. // Set the default values of the form
  163. $values['title'] = $_course['name'];
  164. $values['visual_code'] = $_course['official_code'];
  165. $values['category_code'] = $_course['categoryCode'];
  166. //$values['tutor_name'] = $_course['titular'];
  167. $values['course_language'] = $_course['language'];
  168. $values['department_name'] = $_course['extLink']['name'];
  169. $values['department_url'] = $_course['extLink']['url'];
  170. $values['visibility'] = $_course['visibility'];
  171. $values['subscribe'] = $course_access_settings['subscribe'];
  172. $values['unsubscribe'] = $course_access_settings['unsubscribe'];
  173. $values['course_registration_password'] = $all_course_information['registration_code'];
  174. // get send_mail_setting (work)from table
  175. $values['email_alert_manager_on_new_doc'] = api_get_course_setting('email_alert_manager_on_new_doc');
  176. // get send_mail_setting (dropbox) from table
  177. $values['email_alert_on_new_doc_dropbox'] = api_get_course_setting('email_alert_on_new_doc_dropbox');
  178. // get allow_user_edit_agenda from table
  179. $values['allow_user_edit_agenda'] = api_get_course_setting('allow_user_edit_agenda');
  180. // get allow_user_edit_announcement from table
  181. $values['allow_user_edit_announcement'] = api_get_course_setting('allow_user_edit_announcement');
  182. $form->setDefaults($values);
  183. // Validate form
  184. if ($form->validate() && is_settings_editable())
  185. {
  186. $update_values = $form->exportValues();
  187. foreach ($update_values as $index => $value)
  188. {
  189. $update_values[$index] = mysql_real_escape_string($value);
  190. }
  191. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  192. $sql = "UPDATE $table_course SET title = '".$update_values['title']."',
  193. visual_code = '".$update_values['visual_code']."',
  194. course_language = '".$update_values['course_language']."',
  195. category_code = '".$update_values['category_code']."',
  196. department_name = '".$update_values['department_name']."',
  197. department_url = '".$update_values['department_url']."',
  198. visibility = '".$update_values['visibility']."',
  199. subscribe = '".$update_values['subscribe']."',
  200. unsubscribe = '".$update_values['unsubscribe']."',
  201. tutor_name = '".$update_values['tutor_name']."',
  202. registration_code = '".$update_values['course_registration_password']."'
  203. WHERE code = '".$course_code."'";
  204. api_sql_query($sql, __FILE__, __LINE__);
  205. //update course_settings table
  206. $table_course_setting = Database::get_course_table(TABLE_COURSE_SETTING);
  207. if($update_values['email_alert_manager_on_new_doc'] != $values['email_alert_manager_on_new_doc']){
  208. $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['email_alert_manager_on_new_doc']." WHERE variable = 'email_alert_manager_on_new_doc'' ";
  209. api_sql_query($sql,__FILE__,__LINE__);
  210. }
  211. if($update_values['email_alert_on_new_doc_dropbox'] != $values['email_alert_on_new_doc_dropbox']){
  212. $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['email_alert_on_new_doc_dropbox']." WHERE variable = 'email_alert_on_new_doc_dropbox' ";
  213. api_sql_query($sql,__FILE__,__LINE__);
  214. }
  215. if($update_values['allow_user_edit_agenda'] != $values['allow_user_edit_agenda']){
  216. $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['allow_user_edit_agenda']." WHERE variable = 'allow_user_edit_agenda' ";
  217. api_sql_query($sql,__FILE__,__LINE__);
  218. }
  219. if($update_values['allow_user_edit_announcement'] != $values['allow_user_edit_announcement']){
  220. $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['allow_user_edit_announcement']." WHERE variable = 'allow_user_edit_announcement' ";
  221. api_sql_query($sql,__FILE__,__LINE__);
  222. }
  223. $cidReset = true;
  224. $cidReq = $course_code;
  225. include ('../inc/local.inc.php');
  226. header('Location: infocours.php?action=show_message&amp;cidReq='.$course_code);
  227. exit;
  228. }
  229. /*
  230. -----------------------------------------------------------
  231. Header
  232. -----------------------------------------------------------
  233. */
  234. $nameTools = get_lang("ModifInfo");
  235. Display :: display_header($nameTools, MODULE_HELP_NAME);
  236. //api_display_tool_title($nameTools);
  237. if (isset ($_GET['action']) && $_GET['action'] == 'show_message')
  238. {
  239. Display :: display_normal_message(get_lang('ModifDone'));
  240. }
  241. // Display the form
  242. $form->display();
  243. if ($showDiskQuota && $currentCourseDiskQuota != "")
  244. {
  245. ?>
  246. <table>
  247. <tr>
  248. <td><?php echo get_lang("DiskQuota"); ?>&nbsp;:</td>
  249. <td><?php echo $currentCourseDiskQuota; ?> <?php echo $byteUnits[0] ?></td>
  250. </tr>
  251. <?php
  252. }
  253. if ($showLastEdit && $currentCourseLastEdit != "" && $currentCourseLastEdit != "0000-00-00 00:00:00")
  254. {
  255. ?>
  256. <tr>
  257. <td><?php echo get_lang('LastEdit'); ?>&nbsp;:</td>
  258. <td><?php echo format_locale_date($dateTimeFormatLong,strtotime($currentCourseLastEdit)); ?></td>
  259. </tr>
  260. <?php
  261. }
  262. if ($showLastVisit && $currentCourseLastVisit != "" && $currentCourseLastVisit != "0000-00-00 00:00:00")
  263. {
  264. ?>
  265. <tr>
  266. <td><?php echo get_lang('LastVisit'); ?>&nbsp;:</td>
  267. <td><?php echo format_locale_date($dateTimeFormatLong,strtotime($currentCourseLastVisit)); ?></td>
  268. </tr>
  269. <?php
  270. }
  271. if ($showCreationDate && $currentCourseCreationDate != "" && $currentCourseCreationDate != "0000-00-00 00:00:00")
  272. {
  273. ?>
  274. <tr>
  275. <td><?php echo get_lang('CreationDate'); ?>&nbsp;:</td>
  276. <td><?php echo format_locale_date($dateTimeFormatLong,strtotime($currentCourseCreationDate)); ?></td>
  277. </tr>
  278. <?php
  279. }
  280. if ($showExpirationDate && $currentCourseExpirationDate != "" && $currentCourseExpirationDate != "0000-00-00 00:00:00")
  281. {
  282. ?>
  283. <tr>
  284. <td><?php echo get_lang('ExpirationDate'); ?>&nbsp;:</td>
  285. <td>
  286. <?php
  287. echo format_locale_date($dateTimeFormatLong, strtotime($currentCourseExpirationDate));
  288. echo "<br />".get_lang('OrInTime')." : ";
  289. $nbJour = (strtotime($currentCourseExpirationDate) - time()) / (60 * 60 * 24);
  290. $nbAnnees = round($nbJour / 365);
  291. $nbJour = round($nbJour - $nbAnnees * 365);
  292. switch ($nbAnnees)
  293. {
  294. case "1" :
  295. echo $nbAnnees, " an ";
  296. break;
  297. case "0" :
  298. break;
  299. default :
  300. echo $nbAnnees, " ans ";
  301. };
  302. switch ($nbJour)
  303. {
  304. case "1" :
  305. echo $nbJour, " jour ";
  306. break;
  307. case "0" :
  308. break;
  309. default :
  310. echo $nbJour, " jours ";
  311. }
  312. if ($canReportExpirationDate)
  313. {
  314. echo " -&gt; <a href=\"".$urlScriptToReportExpirationDate."\">".get_lang('PostPone')."</a>";
  315. }
  316. ?>
  317. </td>
  318. </tr>
  319. </table>
  320. <?php
  321. }
  322. /*
  323. ==============================================================================
  324. FOOTER
  325. ==============================================================================
  326. */
  327. Display::display_footer();
  328. ?>