session_list.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. $this_section = SECTION_PLATFORM_ADMIN;
  10. api_protect_teacher_script(true);
  11. //Add the JS needed to use the jqgrid
  12. $htmlHeadXtra[] = api_get_jqgrid_js();
  13. $action = $_REQUEST['action'];
  14. $idChecked = $_REQUEST['idChecked'];
  15. $tool_name = get_lang('SessionList');
  16. Display::display_header($tool_name);
  17. $allowTutors = api_get_setting('session.allow_tutors_to_assign_students_to_session');
  18. if ($allowTutors == 'true') {
  19. $error_message = ''; // Avoid conflict with the global variable $error_msg (array type) in add_course.conf.php.
  20. if (isset($_GET['action']) && $_GET['action'] == 'show_message') {
  21. $error_message = Security::remove_XSS($_GET['message']);
  22. }
  23. if (!empty($error_message)) {
  24. Display::display_normal_message($error_message, false);
  25. }
  26. //jqgrid will use this URL to do the selects
  27. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&from_course_session=1';
  28. if (isset($_REQUEST['keyword'])) {
  29. //Begin with see the searchOper param
  30. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&from_course_session=1&_search=true&rows=20&page=1&sidx=&sord=asc&filters=&searchField=name&searchString='.Security::remove_XSS($_REQUEST['keyword']).'&searchOper=bw';
  31. }
  32. //The order is important you need to check the the $column variable in the model.ajax.php file
  33. $columns = array(
  34. get_lang('Name'),
  35. get_lang('NumberOfCourses'),
  36. get_lang('NumberOfUsers'),
  37. get_lang('SessionCategoryName'),
  38. get_lang('StartDate'),
  39. get_lang('EndDate'),
  40. get_lang('Coach'),
  41. get_lang('Status'),
  42. get_lang('Visibility'),
  43. get_lang('Actions'),
  44. );
  45. //Column config
  46. $column_model = array(
  47. array('name'=>'name', 'index'=>'name', 'width'=>'160', 'align'=>'left', 'search' => 'true', 'wrap_cell' => "true"),
  48. array('name'=>'nbr_courses', 'index'=>'nbr_courses', 'width'=>'30', 'align'=>'left', 'search' => 'true'),
  49. array('name'=>'nbr_users', 'index'=>'nbr_users', 'width'=>'30', 'align'=>'left', 'search' => 'true'),
  50. array('name'=>'category_name', 'index'=>'category_name', 'width'=>'70', 'align'=>'left', 'search' => 'true'),
  51. array('name'=>'access_start_date', 'index'=>'access_start_date', 'width'=>'40', 'align'=>'left', 'search' => 'true'),
  52. array('name'=>'access_end_date', 'index'=>'access_end_date', 'width'=>'40', 'align'=>'left', 'search' => 'true'),
  53. array('name'=>'coach_name', 'index'=>'coach_name', 'width'=>'80', 'align'=>'left', 'search' => 'false'),
  54. array('name'=>'status', 'index'=>'session_active','width'=>'40', 'align'=>'left', 'search' => 'true', 'stype'=>'select',
  55. //for the bottom bar
  56. 'searchoptions' => array(
  57. 'defaultValue' => '1',
  58. 'value' => '1:'.get_lang('Active').';0:'.get_lang('Inactive')
  59. ),
  60. //for the top bar
  61. 'editoptions' => array('value' => ':'.get_lang('All').';1:'.get_lang('Active').';0:'.get_lang('Inactive'))),
  62. array('name'=>'visibility', 'index'=>'visibility', 'width'=>'40', 'align'=>'left', 'search' => 'false'),
  63. array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false', 'search' => 'false')
  64. );
  65. //Autowidth
  66. $extra_params['autowidth'] = 'true';
  67. //height auto
  68. $extra_params['height'] = 'auto';
  69. //$extra_params['excel'] = 'excel';
  70. //$extra_params['rowList'] = array(10, 20 ,30);
  71. //With this function we can add actions to the jgrid (edit, delete, etc)
  72. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  73. return \'&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>'.
  74. '\';
  75. }';
  76. ?>
  77. <script>
  78. function setSearchSelect(columnName) {
  79. $("#sessions").jqGrid('setColProp', columnName,
  80. {
  81. searchoptions:{
  82. dataInit:function(el){
  83. $("option[value='2']",el).attr("selected", "selected");
  84. setTimeout(function(){
  85. $(el).trigger('change');
  86. },1000);
  87. }
  88. }
  89. });
  90. }
  91. $(function() {
  92. <?php
  93. echo Display::grid_js('sessions', $url,$columns,$column_model,$extra_params, array(), $action_links,true);
  94. ?>
  95. setSearchSelect("status");
  96. $("#sessions").jqGrid('navGrid','#sessions_pager', {edit:false,add:false,del:false},
  97. {height:280,reloadAfterSubmit:false}, // edit options
  98. {height:280,reloadAfterSubmit:false}, // add options
  99. {reloadAfterSubmit:false}, // del options
  100. {width:500} // search options
  101. );
  102. /*
  103. // add custom button to export the data to excel
  104. jQuery("#sessions").jqGrid('navButtonAdd','#sessions_pager',{
  105. caption:"",
  106. onClickButton : function () {
  107. jQuery("#sessions").excelExport();
  108. }
  109. });
  110. jQuery('#sessions').jqGrid('navButtonAdd','#sessions_pager',{id:'pager_csv',caption:'',title:'Export To CSV',onClickButton : function(e)
  111. {
  112. try {
  113. jQuery("#sessions").jqGrid('excelExport',{tag:'csv', url:'grid.php'});
  114. } catch (e) {
  115. window.location= 'grid.php?oper=csv';
  116. }
  117. },buttonicon:'ui-icon-document'})
  118. */
  119. //Adding search options
  120. var options = {
  121. 'stringResult': true,
  122. 'autosearch' : true,
  123. 'searchOnEnter':false
  124. }
  125. jQuery("#sessions").jqGrid('filterToolbar',options);
  126. var sgrid = $("#sessions")[0];
  127. sgrid.triggerToolbar();
  128. });
  129. </script>
  130. <?php if (api_is_platform_admin()) {?>
  131. <div class="actions">
  132. <?php
  133. echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/session_add.php">'.Display::return_icon('new_session.png',get_lang('AddSession'),'',ICON_SIZE_MEDIUM).'</a>';
  134. echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/add_many_session_to_category.php">'.Display::return_icon('session_to_category.png',get_lang('AddSessionsInCategories'),'',ICON_SIZE_MEDIUM).'</a>';
  135. echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/session_category_list.php">'.Display::return_icon('folder.png',get_lang('ListSessionCategory'),'',ICON_SIZE_MEDIUM).'</a>';
  136. echo '</div>';
  137. }
  138. } else {
  139. api_not_allowed();
  140. }
  141. echo Display::grid_html('sessions');
  142. Display::display_footer();