infocours.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <?php
  2. // $Id: infocours.php 14956 2008-04-20 14:21:32Z yannoo $
  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. $nameTools = get_lang("ModifInfo");
  47. /*
  48. -----------------------------------------------------------
  49. Libraries
  50. -----------------------------------------------------------
  51. */
  52. require_once (api_get_path(LIBRARY_PATH).'course.lib.php');
  53. require_once (api_get_path(INCLUDE_PATH)."conf/course_info.conf.php");
  54. require_once (api_get_path(INCLUDE_PATH)."lib/debug.lib.inc.php");
  55. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  56. /*
  57. -----------------------------------------------------------
  58. Constants and variables
  59. -----------------------------------------------------------
  60. */
  61. define("MODULE_HELP_NAME", "Settings");
  62. define("COURSE_CHANGE_PROPERTIES", "COURSE_CHANGE_PROPERTIES");
  63. $TABLECOURSE = Database :: get_main_table(TABLE_MAIN_COURSE);
  64. $TABLEFACULTY = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  65. $TABLECOURSEHOME = Database :: get_course_table(TABLE_TOOL_LIST);
  66. $TABLELANGUAGES = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
  67. $TABLEBBCONFIG = Database :: get_course_table(TOOL_FORUM_CONFIG_TABLE);
  68. $currentCourseID = $_course['sysCode'];
  69. $currentCourseRepository = $_course["path"];
  70. $is_allowedToEdit = $is_courseAdmin || $is_platformAdmin;
  71. $course_setting_table = Database::get_course_table(TABLE_COURSE_SETTING);
  72. /*
  73. ==============================================================================
  74. LOGIC FUNCTIONS
  75. ==============================================================================
  76. */
  77. function is_settings_editable()
  78. {
  79. return $GLOBALS["course_info_is_editable"];
  80. }
  81. $course_code = $_course["sysCode"];
  82. $course_access_settings = CourseManager :: get_access_settings($course_code);
  83. /*
  84. ==============================================================================
  85. MAIN CODE
  86. ==============================================================================
  87. */
  88. if (!$is_allowedToEdit)
  89. {
  90. api_not_allowed(true);
  91. }
  92. $table_course_category = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  93. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  94. $tbl_admin = Database :: get_main_table(TABLE_MAIN_ADMIN);
  95. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  96. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  97. // Get all course categories
  98. $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";
  99. $res = api_sql_query($sql, __FILE__, __LINE__);
  100. $s_select_course_tutor_name="SELECT tutor_name FROM $tbl_course WHERE code='$course_code'";
  101. $q_tutor=api_sql_query($s_select_course_tutor_name, __FILE__, __LINE__);
  102. $s_tutor=mysql_result($q_tutor,0,"tutor_name");
  103. $s_sql_course_titular="SELECT DISTINCT username, lastname, firstname FROM $tbl_user as user, $tbl_course_user as course_rel_user WHERE (course_rel_user.status='1') AND user.user_id=course_rel_user.user_id AND course_code='".$course_code."'";
  104. $q_result_titulars=api_sql_query($s_sql_course_titular, __FILE__, __LINE__);
  105. if(mysql_num_rows($q_result_titulars)==0){
  106. $sql="SELECT username, lastname, firstname FROM $tbl_user as user, $tbl_admin as admin WHERE admin.user_id=user.user_id ORDER BY lastname ASC";
  107. $q_result_titulars=api_sql_query($sql, __FILE__, __LINE__);
  108. }
  109. $a_profs[0] = '-- '.get_lang('NoManager').' --';
  110. while($a_titulars=mysql_fetch_array($q_result_titulars)){
  111. $s_username=$a_titulars["username"];
  112. $s_lastname=$a_titulars["lastname"];
  113. $s_firstname=$a_titulars["firstname"];
  114. if($s_firstname.' '.$s_lastname==$s_tutor){
  115. $s_selected_tutor=$s_firstname.' '.$s_lastname;
  116. }
  117. $s_disabled_select_titular="";
  118. if(!$is_courseAdmin){
  119. $s_disabled_select_titular="disabled=disabled";
  120. }
  121. $a_profs[$s_firstname.' '.$s_lastname]="$s_lastname $s_firstname ($s_username)";
  122. }
  123. while ($cat = mysql_fetch_array($res))
  124. {
  125. $categories[$cat['code']] = '('.$cat['code'].') '.$cat['name'];
  126. ksort($categories);
  127. }
  128. $linebreak = '<div class="row"><div class="label"></div><div class="formw" style="border-bottom:1px dashed"></div></div>';
  129. // Build the form
  130. $form = new FormValidator('update_course');
  131. $visual_code=$form->addElement('text','visual_code', get_lang('Code'));
  132. $visual_code->freeze();
  133. $form->applyFilter('visual_code', 'strtoupper');
  134. //$form->add_textfield('tutor_name', get_lang('Professors'), true, array ('size' => '60'));
  135. $prof = &$form->addElement('select', 'tutor_name', get_lang('Professors'), $a_profs);
  136. $prof -> setSelected($s_selected_tutor);
  137. $form->add_textfield('title', get_lang('Title'), true, array ('size' => '60'));
  138. $form->addElement('select', 'category_code', get_lang('Fac'), $categories);
  139. $form->add_textfield('department_name', get_lang('Department'), false, array ('size' => '60'));
  140. $form->add_textfield('department_url', get_lang('DepartmentUrl'), false, array ('size' => '60'));
  141. $form->addRule('tutor_name', get_lang('ThisFieldIsRequired'), 'required');
  142. $form->addElement('select_language', 'course_language', get_lang('Ln'));
  143. $form->addElement('static', null, null, get_lang("TipLang"));
  144. $form -> addElement('html',$linebreak);
  145. $form->addElement('radio', 'visibility', get_lang("CourseAccess"), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
  146. $form->addElement('radio', 'visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
  147. $form->addElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
  148. $form->addElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
  149. $form -> addElement('html',$linebreak);
  150. $form->addElement('radio', 'subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
  151. $form->addElement('radio', 'subscribe', null, get_lang('Denied'), 0);
  152. $form -> addElement('html',$linebreak);
  153. $form->addElement('radio', 'unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
  154. $form->addElement('radio', 'unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
  155. $form -> addElement('html',$linebreak);
  156. $form->addElement('radio', 'email_alert_manager_on_new_doc', get_lang('WorkEmailAlert'), get_lang('WorkEmailAlertActivate'), 1);
  157. $form->addElement('radio', 'email_alert_manager_on_new_doc', null, get_lang('WorkEmailAlertDeactivate'), 0);
  158. $form -> addElement('html',$linebreak);
  159. $form->addElement('radio', 'email_alert_on_new_doc_dropbox', get_lang('DropboxEmailAlert'), get_lang('DropboxEmailAlertActivate'), 1);
  160. $form->addElement('radio', 'email_alert_on_new_doc_dropbox', null, get_lang('DropboxEmailAlertDeactivate'), 0);
  161. $form -> addElement('html',$linebreak);
  162. $form->addElement('radio', 'email_alert_manager_on_new_quiz', get_lang('QuizEmailAlert'), get_lang('QuizEmailAlertActivate'), 1);
  163. $form->addElement('radio', 'email_alert_manager_on_new_quiz', null, get_lang('QuizEmailAlertDeactivate'), 0);
  164. $form -> addElement('html',$linebreak);
  165. $form->addElement('radio', 'allow_user_edit_agenda', get_lang('AllowUserEditAgenda'), get_lang('AllowUserEditAgendaActivate'), 1);
  166. $form->addElement('radio', 'allow_user_edit_agenda', null, get_lang('AllowUserEditAgendaDeactivate'), 0);
  167. $form -> addElement('html',$linebreak);
  168. $form->addElement('radio', 'allow_user_edit_announcement', get_lang('AllowUserEditAnnouncement'), get_lang('AllowUserEditAnnouncementActivate'), 1);
  169. $form->addElement('radio', 'allow_user_edit_announcement', null, get_lang('AllowUserEditAnnouncementDeactivate'), 0);
  170. $form -> addElement('html',$linebreak);
  171. $form->addElement('radio', 'allow_user_image_forum', get_lang('AllowUserImageForum'), get_lang('AllowUserImageForumActivate'), 1);
  172. $form->addElement('radio', 'allow_user_image_forum', null, get_lang('AllowUserImageForumDeactivate'), 0);
  173. $form -> addElement('html',$linebreak);
  174. // Course theme picker
  175. if (api_get_setting('allow_course_theme') == 'true')
  176. {
  177. //Allow Learning path
  178. $form->addElement('radio', 'allow_learning_path_theme', get_lang('AllowLearningPathTheme'), get_lang('AllowLearningPathThemeAllow'), 1);
  179. $form->addElement('radio', 'allow_learning_path_theme', null, get_lang('AllowLearningPathThemeDisallow'), 0);
  180. $form -> addElement('html',$linebreak);
  181. $form->addElement('select_theme', 'course_theme', get_lang('Theme'));
  182. $form->applyFilter('course_theme', 'trim');
  183. $form -> addElement('html',$linebreak);
  184. }
  185. $form->addElement('static', null, null, get_lang("ConfTip"));
  186. $form->add_textfield('course_registration_password', get_lang('CourseRegistrationPassword'), false, array ('size' => '60'));
  187. if (is_settings_editable())
  188. {
  189. $form->addElement('submit', null, get_lang('Ok'));
  190. }
  191. else
  192. {
  193. // is it allowed to edit the course settings?
  194. if (!is_settings_editable())
  195. $disabled_output = "disabled";
  196. $form->freeze();
  197. }
  198. // get all the course information
  199. $all_course_information = CourseManager::get_course_information($_course['sysCode']);
  200. // Set the default values of the form
  201. $values['title'] = $_course['name'];
  202. $values['visual_code'] = $_course['official_code'];
  203. $values['category_code'] = $_course['categoryCode'];
  204. //$values['tutor_name'] = $_course['titular'];
  205. $values['course_language'] = $_course['language'];
  206. $values['department_name'] = $_course['extLink']['name'];
  207. $values['department_url'] = $_course['extLink']['url'];
  208. $values['visibility'] = $_course['visibility'];
  209. $values['subscribe'] = $course_access_settings['subscribe'];
  210. $values['unsubscribe'] = $course_access_settings['unsubscribe'];
  211. $values['course_registration_password'] = $all_course_information['registration_code'];
  212. // get send_mail_setting (work)from table
  213. $values['email_alert_manager_on_new_doc'] = api_get_course_setting('email_alert_manager_on_new_doc');
  214. // get send_mail_setting (dropbox) from table
  215. $values['email_alert_on_new_doc_dropbox'] = api_get_course_setting('email_alert_on_new_doc_dropbox');
  216. // get send_mail_setting (work)from table
  217. $values['email_alert_manager_on_new_quiz'] = api_get_course_setting('email_alert_manager_on_new_quiz');
  218. // get allow_user_edit_agenda from table
  219. $values['allow_user_edit_agenda'] = api_get_course_setting('allow_user_edit_agenda');
  220. // get allow_user_edit_announcement from table
  221. $values['allow_user_edit_announcement'] = api_get_course_setting('allow_user_edit_announcement');
  222. // get allow_user_image_forum from table
  223. $values['allow_user_image_forum'] = api_get_course_setting('allow_user_image_forum');
  224. // get course_theme from table
  225. $values['course_theme'] = api_get_course_setting('course_theme');
  226. // get allow_learning_path_theme from table
  227. $values['allow_learning_path_theme'] = api_get_course_setting('allow_learning_path_theme');
  228. $form->setDefaults($values);
  229. // Validate form
  230. if ($form->validate() && is_settings_editable())
  231. {
  232. $update_values = $form->exportValues();
  233. foreach ($update_values as $index => $value)
  234. {
  235. $update_values[$index] = mysql_real_escape_string($value);
  236. }
  237. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  238. $sql = "UPDATE $table_course SET title = '".$update_values['title']."',
  239. visual_code = '".$update_values['visual_code']."',
  240. course_language = '".$update_values['course_language']."',
  241. category_code = '".$update_values['category_code']."',
  242. department_name = '".$update_values['department_name']."',
  243. department_url = '".$update_values['department_url']."',
  244. visibility = '".$update_values['visibility']."',
  245. subscribe = '".$update_values['subscribe']."',
  246. unsubscribe = '".$update_values['unsubscribe']."',
  247. tutor_name = '".$update_values['tutor_name']."',
  248. registration_code = '".$update_values['course_registration_password']."'
  249. WHERE code = '".$course_code."'";
  250. api_sql_query($sql, __FILE__, __LINE__);
  251. //update course_settings table - this assumes those records exist, otherwise triggers an error
  252. $table_course_setting = Database::get_course_table(TABLE_COURSE_SETTING);
  253. if($update_values['email_alert_manager_on_new_doc'] != $values['email_alert_manager_on_new_doc']){
  254. $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['email_alert_manager_on_new_doc']." WHERE variable = 'email_alert_manager_on_new_doc' ";
  255. api_sql_query($sql,__FILE__,__LINE__);
  256. }
  257. if($update_values['email_alert_on_new_doc_dropbox'] != $values['email_alert_on_new_doc_dropbox']){
  258. $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['email_alert_on_new_doc_dropbox']." WHERE variable = 'email_alert_on_new_doc_dropbox' ";
  259. api_sql_query($sql,__FILE__,__LINE__);
  260. }
  261. if($update_values['email_alert_manager_on_new_quiz'] != $values['email_alert_manager_on_new_quiz']){
  262. $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['email_alert_manager_on_new_quiz']." WHERE variable = 'email_alert_manager_on_new_quiz' ";
  263. api_sql_query($sql,__FILE__,__LINE__);
  264. }
  265. if($update_values['allow_user_edit_agenda'] != $values['allow_user_edit_agenda']){
  266. $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['allow_user_edit_agenda']." WHERE variable = 'allow_user_edit_agenda' ";
  267. api_sql_query($sql,__FILE__,__LINE__);
  268. }
  269. if($update_values['allow_user_edit_announcement'] != $values['allow_user_edit_announcement']){
  270. $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['allow_user_edit_announcement']." WHERE variable = 'allow_user_edit_announcement' ";
  271. api_sql_query($sql,__FILE__,__LINE__);
  272. }
  273. if($update_values['allow_user_image_forum'] != $values['allow_user_image_forum']){
  274. $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['allow_user_image_forum']." WHERE variable = 'allow_user_image_forum' ";
  275. api_sql_query($sql,__FILE__,__LINE__);
  276. }
  277. if($update_values['course_theme'] != $values['course_theme']){
  278. $sql = "UPDATE $table_course_setting SET value = '".$update_values['course_theme']."' WHERE variable = 'course_theme' ";
  279. api_sql_query($sql,__FILE__,__LINE__);
  280. }
  281. if($update_values['allow_learningpath_theme'] != $values['allow_learning_path_theme']){
  282. $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['allow_learning_path_theme']." WHERE variable = 'allow_learning_path_theme' ";
  283. api_sql_query($sql,__FILE__,__LINE__);
  284. }
  285. $cidReset = true;
  286. $cidReq = $course_code;
  287. include ('../inc/local.inc.php');
  288. header('Location: infocours.php?action=show_message&amp;cidReq='.$course_code);
  289. exit;
  290. }
  291. /*
  292. -----------------------------------------------------------
  293. Header
  294. -----------------------------------------------------------
  295. */
  296. Display :: display_header($nameTools, MODULE_HELP_NAME);
  297. //api_display_tool_title($nameTools);
  298. if (isset ($_GET['action']) && $_GET['action'] == 'show_message')
  299. {
  300. Display :: display_normal_message(get_lang('ModifDone'));
  301. }
  302. // Display the form
  303. $form->display();
  304. if ($showDiskQuota && $currentCourseDiskQuota != "")
  305. {
  306. ?>
  307. <table>
  308. <tr>
  309. <td><?php echo get_lang("DiskQuota"); ?>&nbsp;:</td>
  310. <td><?php echo $currentCourseDiskQuota; ?> <?php echo $byteUnits[0] ?></td>
  311. </tr>
  312. <?php
  313. }
  314. if ($showLastEdit && $currentCourseLastEdit != "" && $currentCourseLastEdit != "0000-00-00 00:00:00")
  315. {
  316. ?>
  317. <tr>
  318. <td><?php echo get_lang('LastEdit'); ?>&nbsp;:</td>
  319. <td><?php echo format_locale_date($dateTimeFormatLong,strtotime($currentCourseLastEdit)); ?></td>
  320. </tr>
  321. <?php
  322. }
  323. if ($showLastVisit && $currentCourseLastVisit != "" && $currentCourseLastVisit != "0000-00-00 00:00:00")
  324. {
  325. ?>
  326. <tr>
  327. <td><?php echo get_lang('LastVisit'); ?>&nbsp;:</td>
  328. <td><?php echo format_locale_date($dateTimeFormatLong,strtotime($currentCourseLastVisit)); ?></td>
  329. </tr>
  330. <?php
  331. }
  332. if ($showCreationDate && $currentCourseCreationDate != "" && $currentCourseCreationDate != "0000-00-00 00:00:00")
  333. {
  334. ?>
  335. <tr>
  336. <td><?php echo get_lang('CreationDate'); ?>&nbsp;:</td>
  337. <td><?php echo format_locale_date($dateTimeFormatLong,strtotime($currentCourseCreationDate)); ?></td>
  338. </tr>
  339. <?php
  340. }
  341. if ($showExpirationDate && $currentCourseExpirationDate != "" && $currentCourseExpirationDate != "0000-00-00 00:00:00")
  342. {
  343. ?>
  344. <tr>
  345. <td><?php echo get_lang('ExpirationDate'); ?>&nbsp;:</td>
  346. <td>
  347. <?php
  348. echo format_locale_date($dateTimeFormatLong, strtotime($currentCourseExpirationDate));
  349. echo "<br />".get_lang('OrInTime')." : ";
  350. $nbJour = (strtotime($currentCourseExpirationDate) - time()) / (60 * 60 * 24);
  351. $nbAnnees = round($nbJour / 365);
  352. $nbJour = round($nbJour - $nbAnnees * 365);
  353. switch ($nbAnnees)
  354. {
  355. case "1" :
  356. echo $nbAnnees, " an ";
  357. break;
  358. case "0" :
  359. break;
  360. default :
  361. echo $nbAnnees, " ans ";
  362. };
  363. switch ($nbJour)
  364. {
  365. case "1" :
  366. echo $nbJour, " jour ";
  367. break;
  368. case "0" :
  369. break;
  370. default :
  371. echo $nbJour, " jours ";
  372. }
  373. if ($canReportExpirationDate)
  374. {
  375. echo " -&gt; <a href=\"".$urlScriptToReportExpirationDate."\">".get_lang('PostPone')."</a>";
  376. }
  377. ?>
  378. </td>
  379. </tr>
  380. </table>
  381. <?php
  382. }
  383. /*
  384. ==============================================================================
  385. FOOTER
  386. ==============================================================================
  387. */
  388. Display::display_footer();
  389. ?>