session_edit.php 7.2 KB

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