session_edit.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. $id_coach = $sessionInfo['id_coach'];
  19. $tool_name = get_lang('EditSession');
  20. //$interbreadcrumb[] = array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
  21. $interbreadcrumb[] = array('url' => "session_list.php","name" => get_lang('SessionList'));
  22. $interbreadcrumb[] = array('url' => "resume_session.php?id_session=".$id,"name" => get_lang('SessionOverview'));
  23. if (isset($_POST['formSent']) && $_POST['formSent']) {
  24. $formSent = 1;
  25. }
  26. $order_clause = 'ORDER BY ';
  27. $order_clause .= api_sort_by_first_name() ? 'firstname, lastname, username' : 'lastname, firstname, username';
  28. $sql = "SELECT user_id,lastname,firstname,username
  29. FROM $tbl_user
  30. WHERE status='1'".$order_clause;
  31. if (api_is_multiple_url_enabled()) {
  32. $table_access_url_rel_user= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  33. $access_url_id = api_get_current_access_url_id();
  34. if ($access_url_id != -1) {
  35. $sql = "SELECT DISTINCT u.user_id,lastname,firstname,username
  36. FROM $tbl_user u
  37. INNER JOIN $table_access_url_rel_user url_rel_user
  38. ON (url_rel_user.user_id = u.user_id)
  39. WHERE status='1' AND access_url_id = '$access_url_id' $order_clause";
  40. }
  41. }
  42. $result = Database::query($sql);
  43. $coaches = Database::store_result($result);
  44. $thisYear = date('Y');
  45. $coachesOption = array(
  46. '' => '----- ' . get_lang('None') . ' -----'
  47. );
  48. foreach ($coaches as $coach) {
  49. $personName = api_get_person_name($coach['firstname'], $coach['lastname']);
  50. $coachesOption[$coach['user_id']] = "$personName ({$coach['username']})";
  51. }
  52. $categoriesList = SessionManager::get_all_session_category();
  53. $categoriesOption = array(
  54. '0' => get_lang('None')
  55. );
  56. if ($categoriesList != false) {
  57. foreach ($categoriesList as $categoryItem) {
  58. $categoriesOption[$categoryItem['id']] = $categoryItem['name'];
  59. }
  60. }
  61. $formAction = api_get_self() . '?';
  62. $formAction .= http_build_query(array(
  63. 'page' => Security::remove_XSS($_GET['page']),
  64. 'id' => $id
  65. ));
  66. $form = new FormValidator('edit_session', 'post', $formAction);
  67. $form->addElement('header', $tool_name);
  68. $result = SessionManager::setForm($form, $id);
  69. $htmlHeadXtra[] = '
  70. <script>
  71. $(function() {
  72. '.$result['js'].'
  73. });
  74. </script>';
  75. $form->addButtonUpdate(get_lang('ModifyThisSession'));
  76. $formDefaults = $sessionInfo;
  77. $formDefaults['coach_username'] = $sessionInfo['id_coach'];
  78. $formDefaults['session_category'] = $sessionInfo['session_category_id'];
  79. $formDefaults['session_visibility'] = $sessionInfo['visibility'];
  80. if ($formSent) {
  81. $formDefaults['name'] = api_htmlentities($name, ENT_QUOTES, $charset);
  82. } else {
  83. $formDefaults['name'] = Security::remove_XSS($sessionInfo['name']);
  84. }
  85. $form->setDefaults($formDefaults);
  86. if ($form->validate()) {
  87. $params = $form->getSubmitValues();
  88. $name = $params['name'];
  89. $startDate = $params['access_start_date'];
  90. $endDate = $params['access_end_date'];
  91. $displayStartDate = $params['display_start_date'];
  92. $displayEndDate = $params['display_end_date'];
  93. $coachStartDate = $params['coach_access_start_date'];
  94. $coachEndDate = $params['coach_access_end_date'];
  95. $coach_username = intval($params['coach_username']);
  96. $id_session_category = $params['session_category'];
  97. $id_visibility = $params['session_visibility'];
  98. $duration = isset($params['duration']) ? $params['duration'] : null;
  99. $description = $params['description'];
  100. $showDescription = isset($params['show_description']) ? 1: 0;
  101. $sendSubscritionNotification = isset($params['send_subscription_notification']);
  102. $extraFields = array();
  103. foreach ($params as $key => $value) {
  104. if (strpos($key, 'extra_') === 0) {
  105. $extraFields[$key] = $value;
  106. }
  107. }
  108. $return = SessionManager::edit_session(
  109. $id,
  110. $name,
  111. $startDate,
  112. $endDate,
  113. $displayStartDate,
  114. $displayEndDate,
  115. $coachStartDate,
  116. $coachEndDate,
  117. $coach_username,
  118. $id_session_category,
  119. $id_visibility,
  120. $description,
  121. $showDescription,
  122. $duration,
  123. $extraFields,
  124. null,
  125. $sendSubscritionNotification
  126. );
  127. if ($return == strval(intval($return))) {
  128. header('Location: resume_session.php?id_session=' . $return);
  129. exit();
  130. }
  131. }
  132. // display the header
  133. Display::display_header($tool_name);
  134. $form->display();
  135. ?>
  136. <script>
  137. $(document).ready( function() {
  138. <?php
  139. if (!empty($sessionInfo['duration'])) {
  140. echo 'accessSwitcher(0);';
  141. } else {
  142. echo 'accessSwitcher(1);';
  143. }
  144. ?>
  145. });
  146. function accessSwitcher(accessFromReady) {
  147. var access = $('#access option:selected').val();
  148. if (accessFromReady >= 0) {
  149. access = accessFromReady;
  150. $('[name=access]').val(access);
  151. }
  152. if (access == 1) {
  153. $('#duration').hide();
  154. $('#date_fields').show();
  155. } else {
  156. $('#duration').show();
  157. $('#date_fields').hide();
  158. }
  159. emptyDuration();
  160. }
  161. function emptyDuration() {
  162. if ($('#duration').val()) {
  163. $('#duration').val('');
  164. }
  165. }
  166. $(document).on('ready', function (){
  167. $('#show-options').on('click', function (e) {
  168. e.preventDefault();
  169. var display = $('#options').css('display');
  170. display === 'block' ? $('#options').slideUp() : $('#options').slideDown() ;
  171. });
  172. });
  173. </script>
  174. <?php
  175. Display::display_footer();