session_list.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * List sessions in an efficient and usable way
  5. * @package chamilo.admin
  6. */
  7. $language_file = array('admin', 'courses');
  8. $cidReset = true;
  9. require_once '../inc/global.inc.php';
  10. $this_section = SECTION_PLATFORM_ADMIN;
  11. api_protect_admin_script(true);
  12. //Add the JS needed to use the jqgrid
  13. $htmlHeadXtra[] = api_get_jqgrid_js();
  14. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
  15. $idChecked = isset($_REQUEST['idChecked']) ? $_REQUEST['idChecked'] : null;
  16. if ($action == 'delete') {
  17. SessionManager::delete_session($idChecked);
  18. header('Location: session_list.php');
  19. exit();
  20. } elseif ($action == 'copy') {
  21. SessionManager::copy_session($idChecked);
  22. header('Location: session_list.php');
  23. exit();
  24. }
  25. $interbreadcrumb[]=array("url" => "index.php","name" => get_lang('PlatformAdmin'));
  26. $tool_name = get_lang('SessionList');
  27. Display::display_header($tool_name);
  28. $error_message = '';
  29. // Avoid conflict with the global variable $error_msg (array type) in add_course.conf.php.
  30. if (isset($_GET['action']) && $_GET['action'] == 'show_message') {
  31. $error_message = Security::remove_XSS($_GET['message']);
  32. }
  33. if (!empty($error_message)) {
  34. Display::display_normal_message($error_message, false);
  35. }
  36. $sessionFilter = new FormValidator('course_filter', 'get', '', '', array('class'=> 'form-search'), false);
  37. $url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_course';
  38. $courseList = array();
  39. $courseId = isset($_GET['course_id']) ? $_GET['course_id'] : null;
  40. if (!empty($courseId)) {
  41. require_once api_get_path(LIBRARY_PATH).'course_category.lib.php';
  42. $courseInfo = api_get_course_info_by_id($courseId);
  43. $parents = getParentsToString($courseInfo['categoryCode']);
  44. $courseList[] = array('id' => $courseInfo['id'], 'text' => $parents.$courseInfo['title']);
  45. }
  46. $sessionFilter->addElement('select_ajax', 'course_name', get_lang('SearchCourse'), null, array('url' => $url, 'defaults' => $courseList));
  47. $url = api_get_self();
  48. $actions = '
  49. <script>
  50. $(function() {
  51. $("#course_name").on("change", function() {
  52. var courseId = $(this).val();
  53. window.location = "'.$url.'?course_id="+courseId;
  54. });
  55. });
  56. </script>';
  57. // jqgrid will use this URL to do the selects
  58. if (!empty($courseId)) {
  59. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&course_id='.$courseId;
  60. } else {
  61. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions';
  62. }
  63. if (isset($_REQUEST['keyword'])) {
  64. //Begin with see the searchOper param
  65. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&_force_search=true&rows=20&page=1&sidx=&sord=asc&filters=&searchField=s.name&searchString='.Security::remove_XSS($_REQUEST['keyword']).'&searchOper=bw';
  66. }
  67. if (isset($_REQUEST['id_category'])) {
  68. $sessionCategory = SessionManager::get_session_category($_REQUEST['id_category']);
  69. if (!empty($sessionCategory)) {
  70. //Begin with see the searchOper param
  71. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&_force_search=true&rows=20&page=1&sidx=&sord=asc&filters=&searchField=sc.name&searchString='.Security::remove_XSS($sessionCategory['name']).'&searchOper=bw';
  72. }
  73. }
  74. //The order is important you need to check the the $column variable in the model.ajax.php file
  75. $columns = array(
  76. get_lang('Name'),
  77. get_lang('NumberOfCourses'),
  78. get_lang('NumberOfUsers'),
  79. get_lang('SessionCategoryName'),
  80. get_lang('StartDate'),
  81. get_lang('EndDate'),
  82. get_lang('Coach'),
  83. get_lang('Status'),
  84. get_lang('Visibility'),
  85. get_lang('Actions')
  86. );
  87. //Column config
  88. $column_model = array(
  89. array('name'=>'name', 'index'=>'s.name', 'width'=>'160', 'align'=>'left', 'search' => 'true', 'wrap_cell' => "true"),
  90. array('name'=>'nbr_courses', 'index'=>'nbr_courses', 'width'=>'30', 'align'=>'left', 'search' => 'true'),
  91. array('name'=>'nbr_users', 'index'=>'nbr_users', 'width'=>'30', 'align'=>'left', 'search' => 'true'),
  92. array('name'=>'category_name', 'index'=>'sc.name', 'width'=>'70', 'align'=>'left', 'search' => 'true'),
  93. array('name'=>'date_start', 'index'=>'s.date_start', 'width'=>'40', 'align'=>'left', 'search' => 'true'),
  94. array('name'=>'date_end', 'index'=>'s.date_end', 'width'=>'40', 'align'=>'left', 'search' => 'true'),
  95. array('name'=>'coach_name', 'index'=>'coach_name', 'width'=>'80', 'align'=>'left', 'search' => 'false'),
  96. array('name'=>'status', 'index'=>'session_active','width'=>'45',
  97. 'align'=>'left', 'search' => 'true', 'stype'=>'select',
  98. //for the bottom bar
  99. 'searchoptions' => array(
  100. 'defaultValue' => ':',
  101. 'value' => ':'.get_lang('All').';1:'.get_lang('Active').';0:'.get_lang('Inactive')
  102. ),
  103. //for the top bar
  104. 'editoptions' => array(
  105. 'value' => ':'.get_lang('All').';1:'.get_lang('Active').';0:'.get_lang('Inactive')
  106. )
  107. ),
  108. array('name'=>'visibility', 'index'=>'visibility', 'width'=>'45', 'align'=>'left', 'search' => 'false'),
  109. array('name'=>'actions', 'index'=>'actions', 'width'=>'90',
  110. 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false', 'search' => 'false')
  111. );
  112. //Autowidth
  113. $extra_params['autowidth'] = 'true';
  114. //height auto
  115. $extra_params['height'] = 'auto';
  116. //With this function we can add actions to the jgrid (edit, delete, etc)
  117. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  118. return \'<a href="session_edit.php?page=resume_session.php&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
  119. '&nbsp;<a href="add_users_to_session.php?page=session_list.php&id_session=\'+options.rowId+\'">'.Display::return_icon('user_subscribe_session.png',get_lang('SubscribeUsersToSession'),'',ICON_SIZE_SMALL).'</a>'.
  120. '&nbsp;<a href="add_courses_to_session.php?page=session_list.php&id_session=\'+options.rowId+\'">'.Display::return_icon('courses_to_session.png',get_lang('SubscribeCoursesToSession'),'',ICON_SIZE_SMALL).'</a>'.
  121. '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="session_list.php?action=copy&idChecked=\'+options.rowId+\'">'.Display::return_icon('copy.png',get_lang('Copy'),'',ICON_SIZE_SMALL).'</a>'.
  122. '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="session_list.php?action=delete&idChecked=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
  123. '\';
  124. }';
  125. ?>
  126. <script>
  127. function setSearchSelect(columnName) {
  128. $("#sessions").jqGrid(
  129. 'setColProp',
  130. columnName,
  131. {
  132. searchoptions: {
  133. dataInit:function(el) {
  134. $("option[value='2']",el).attr("selected", "selected");
  135. setTimeout(function() {
  136. $(el).trigger('change');
  137. }, 1000);
  138. }
  139. }
  140. }
  141. );
  142. }
  143. $(function() {
  144. <?php
  145. echo Display::grid_js('sessions', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  146. ?>
  147. setSearchSelect("status");
  148. $("#sessions").jqGrid(
  149. 'navGrid',
  150. '#sessions_pager',
  151. { edit: false, add: false, del: false},
  152. { height:280, reloadAfterSubmit:false }, // edit options
  153. { height:280, reloadAfterSubmit:false }, // add options
  154. { reloadAfterSubmit:false }, // del options
  155. { width:500 } // search options
  156. );
  157. /*
  158. // add custom button to export the data to excel
  159. jQuery("#sessions").jqGrid('navButtonAdd','#sessions_pager',{
  160. caption:"",
  161. onClickButton : function () {
  162. jQuery("#sessions").excelExport();
  163. }
  164. });
  165. jQuery('#sessions').jqGrid('navButtonAdd','#sessions_pager',{id:'pager_csv',caption:'',title:'Export To CSV',onClickButton : function(e)
  166. {
  167. try {
  168. jQuery("#sessions").jqGrid('excelExport',{tag:'csv', url:'grid.php'});
  169. } catch (e) {
  170. window.location= 'grid.php?oper=csv';
  171. }
  172. },buttonicon:'ui-icon-document'})
  173. */
  174. // Adding search options
  175. var options = {
  176. 'stringResult': true,
  177. 'autosearch' : true,
  178. 'searchOnEnter':false
  179. }
  180. jQuery("#sessions").jqGrid('filterToolbar', options);
  181. var sgrid = $("#sessions")[0];
  182. sgrid.triggerToolbar();
  183. });
  184. </script>
  185. <div class="actions">
  186. <?php
  187. echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/session_add.php">'.Display::return_icon('new_session.png',get_lang('AddSession'),'',ICON_SIZE_MEDIUM).'</a>';
  188. echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/add_many_session_to_category.php">'.Display::return_icon('session_to_category.png',get_lang('AddSessionsInCategories'),'',ICON_SIZE_MEDIUM).'</a>';
  189. echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_list.php">'.Display::return_icon('folder.png',get_lang('ListSessionCategory'),'',ICON_SIZE_MEDIUM).'</a>';
  190. echo $actions;
  191. echo '<div class="pull-right">';
  192. echo $sessionFilter->return_form();
  193. echo '</div>';
  194. echo '</div>';
  195. echo Display::grid_html('sessions');
  196. Display::display_footer();