session_list.php 9.1 KB

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