session_list.php 9.1 KB

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