session_edit.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Sessions edition script
  5. * @package chamilo.admin
  6. */
  7. $cidReset = true;
  8. //require_once '../inc/global.inc.php';
  9. // setting the section (for the tabs)
  10. $this_section = SECTION_PLATFORM_ADMIN;
  11. $formSent = 0;
  12. // Database Table Definitions
  13. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  14. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  15. $id = intval($_GET['id']);
  16. SessionManager::protectSession($id);
  17. $sessionInfo = SessionManager::fetch($id);
  18. // Sets to local time to show it correctly when you edit a session
  19. if (!empty($sessionInfo['display_start_date'])) {
  20. $sessionInfo['display_start_date'] = api_get_local_time($sessionInfo['display_start_date']);
  21. }
  22. if (!empty($sessionInfo['display_end_date'])) {
  23. $sessionInfo['display_end_date'] = api_get_local_time($sessionInfo['display_end_date']);
  24. }
  25. if (!empty($sessionInfo['access_start_date'])) {
  26. $sessionInfo['access_start_date'] = api_get_local_time($sessionInfo['access_start_date']);
  27. }
  28. if (!empty($sessionInfo['access_end_date'])) {
  29. $sessionInfo['access_end_date'] = api_get_local_time($sessionInfo['access_end_date']);
  30. }
  31. if (!empty($sessionInfo['coach_access_start_date'])) {
  32. $sessionInfo['coach_access_start_date'] = api_get_local_time($sessionInfo['coach_access_start_date']);
  33. }
  34. if (!empty($sessionInfo['coach_access_end_date'])) {
  35. $sessionInfo['coach_access_end_date'] = api_get_local_time($sessionInfo['coach_access_end_date']);
  36. }
  37. $id_coach = $sessionInfo['id_coach'];
  38. $tool_name = get_lang('EditSession');
  39. //$interbreadcrumb[] = array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
  40. $interbreadcrumb[] = array('url' => "session_list.php","name" => get_lang('SessionList'));
  41. $interbreadcrumb[] = array('url' => "resume_session.php?id_session=".$id,"name" => get_lang('SessionOverview'));
  42. if (isset($_POST['formSent']) && $_POST['formSent']) {
  43. $formSent = 1;
  44. }
  45. $order_clause = 'ORDER BY ';
  46. $order_clause .= api_sort_by_first_name() ? 'firstname, lastname, username' : 'lastname, firstname, username';
  47. $sql = "SELECT user_id,lastname,firstname,username
  48. FROM $tbl_user
  49. WHERE status='1'".$order_clause;
  50. if (api_is_multiple_url_enabled()) {
  51. $table_access_url_rel_user= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  52. $access_url_id = api_get_current_access_url_id();
  53. if ($access_url_id != -1) {
  54. $sql = "SELECT DISTINCT u.user_id,lastname,firstname,username
  55. FROM $tbl_user u
  56. INNER JOIN $table_access_url_rel_user url_rel_user
  57. ON (url_rel_user.user_id = u.user_id)
  58. WHERE status='1' AND access_url_id = '$access_url_id' $order_clause";
  59. }
  60. }
  61. $result = Database::query($sql);
  62. $coaches = Database::store_result($result);
  63. $thisYear = date('Y');
  64. $coachesOption = array(
  65. '' => '----- ' . get_lang('None') . ' -----'
  66. );
  67. foreach ($coaches as $coach) {
  68. $personName = api_get_person_name($coach['firstname'], $coach['lastname']);
  69. $coachesOption[$coach['user_id']] = "$personName ({$coach['username']})";
  70. }
  71. $categoriesList = SessionManager::get_all_session_category();
  72. $categoriesOption = array(
  73. '0' => get_lang('None')
  74. );
  75. if ($categoriesList != false) {
  76. foreach ($categoriesList as $categoryItem) {
  77. $categoriesOption[$categoryItem['id']] = $categoryItem['name'];
  78. }
  79. }
  80. $formAction = api_get_self() . '?';
  81. $formAction .= http_build_query(array(
  82. 'page' => Security::remove_XSS($_GET['page']),
  83. 'id' => $id
  84. ));
  85. $form = new FormValidator('edit_session', 'post', $formAction);
  86. $form->addElement('header', $tool_name);
  87. $result = SessionManager::setForm($form, $id);
  88. $htmlHeadXtra[] = '
  89. <script>
  90. $(function() {
  91. '.$result['js'].'
  92. });
  93. </script>';
  94. $form->addButtonUpdate(get_lang('ModifyThisSession'));
  95. $formDefaults = $sessionInfo;
  96. $formDefaults['coach_username'] = $sessionInfo['id_coach'];
  97. $formDefaults['session_category'] = $sessionInfo['session_category_id'];
  98. $formDefaults['session_visibility'] = $sessionInfo['visibility'];
  99. if ($formSent) {
  100. $formDefaults['name'] = api_htmlentities($name, ENT_QUOTES, $charset);
  101. } else {
  102. $formDefaults['name'] = Security::remove_XSS($sessionInfo['name']);
  103. }
  104. $form->setDefaults($formDefaults);
  105. if ($form->validate()) {
  106. $params = $form->getSubmitValues();
  107. $name = $params['name'];
  108. $startDate = $params['access_start_date'];
  109. $endDate = $params['access_end_date'];
  110. $displayStartDate = $params['display_start_date'];
  111. $displayEndDate = $params['display_end_date'];
  112. $coachStartDate = $params['coach_access_start_date'];
  113. $coachEndDate = $params['coach_access_end_date'];
  114. $coach_username = intval($params['coach_username']);
  115. $id_session_category = $params['session_category'];
  116. $id_visibility = $params['session_visibility'];
  117. $duration = isset($params['duration']) ? $params['duration'] : null;
  118. if ($params['access'] == 1) {
  119. $duration = null;
  120. }
  121. $description = $params['description'];
  122. $showDescription = isset($params['show_description']) ? 1: 0;
  123. $sendSubscriptionNotification = isset($params['send_subscription_notification']);
  124. $extraFields = array();
  125. foreach ($params as $key => $value) {
  126. if (strpos($key, 'extra_') === 0) {
  127. $extraFields[$key] = $value;
  128. }
  129. }
  130. $return = SessionManager::edit_session(
  131. $id,
  132. $name,
  133. $startDate,
  134. $endDate,
  135. $displayStartDate,
  136. $displayEndDate,
  137. $coachStartDate,
  138. $coachEndDate,
  139. $coach_username,
  140. $id_session_category,
  141. $id_visibility,
  142. $description,
  143. $showDescription,
  144. $duration,
  145. $extraFields,
  146. null,
  147. $sendSubscriptionNotification
  148. );
  149. if ($return == strval(intval($return))) {
  150. header('Location: resume_session.php?id_session=' . $return);
  151. exit();
  152. }
  153. }
  154. // display the header
  155. Display::display_header($tool_name);
  156. $form->display();
  157. ?>
  158. <script>
  159. $(document).ready( function() {
  160. <?php
  161. if (!empty($sessionInfo['duration'])) {
  162. echo 'accessSwitcher(0);';
  163. } else {
  164. echo 'accessSwitcher(1);';
  165. }
  166. ?>
  167. });
  168. function accessSwitcher(accessFromReady) {
  169. var access = $('#access option:selected').val();
  170. if (accessFromReady >= 0) {
  171. access = accessFromReady;
  172. $('[name=access]').val(access);
  173. }
  174. if (access == 1) {
  175. $('#duration').hide();
  176. $('#date_fields').show();
  177. } else {
  178. $('#duration').show();
  179. $('#date_fields').hide();
  180. }
  181. emptyDuration();
  182. }
  183. function emptyDuration() {
  184. if ($('#duration').val()) {
  185. $('#duration').val('');
  186. }
  187. }
  188. $(document).on('ready', function (){
  189. $('#show-options').on('click', function (e) {
  190. e.preventDefault();
  191. var display = $('#options').css('display');
  192. display === 'block' ? $('#options').slideUp() : $('#options').slideDown() ;
  193. });
  194. });
  195. </script>
  196. <?php
  197. Display::display_footer();