session_list.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * List sessions in an efficient and usable way.
  5. *
  6. * @package chamilo.admin
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. $this_section = SECTION_PLATFORM_ADMIN;
  11. api_protect_teacher_script(true);
  12. // Add the JS needed to use the jqgrid
  13. $htmlHeadXtra[] = api_get_jqgrid_js();
  14. $tool_name = get_lang('Session list');
  15. $allowTutors = api_get_setting('allow_tutors_to_assign_students_to_session');
  16. if ($allowTutors !== 'true') {
  17. api_not_allowed(true);
  18. }
  19. Display::display_header($tool_name);
  20. // jqgrid will use this URL to do the selects
  21. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&from_course_session=1';
  22. if (isset($_REQUEST['keyword'])) {
  23. //Begin with see the searchOper param
  24. $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';
  25. }
  26. //The order is important you need to check the the $column variable in the model.ajax.php file
  27. $columns = [
  28. get_lang('Name'),
  29. get_lang('Courses'),
  30. get_lang('Number of users'),
  31. get_lang('Category name'),
  32. get_lang('Start Date'),
  33. get_lang('End Date'),
  34. get_lang('Coach'),
  35. get_lang('Status'),
  36. get_lang('Visibility'),
  37. get_lang('Detail'),
  38. ];
  39. //Column config
  40. $column_model = [
  41. ['name' => 'name', 'index' => 'name', 'width' => '160', 'align' => 'left', 'search' => 'true', 'wrap_cell' => "true"],
  42. ['name' => 'nbr_courses', 'index' => 'nbr_courses', 'width' => '30', 'align' => 'left', 'search' => 'true'],
  43. ['name' => 'nbr_users', 'index' => 'nbr_users', 'width' => '30', 'align' => 'left', 'search' => 'true'],
  44. ['name' => 'category_name', 'index' => 'category_name', 'width' => '70', 'align' => 'left', 'search' => 'true'],
  45. ['name' => 'access_start_date', 'index' => 'access_start_date', 'width' => '40', 'align' => 'left', 'search' => 'true'],
  46. ['name' => 'access_end_date', 'index' => 'access_end_date', 'width' => '40', 'align' => 'left', 'search' => 'true'],
  47. ['name' => 'coach_name', 'index' => 'coach_name', 'width' => '80', 'align' => 'left', 'search' => 'false'],
  48. ['name' => 'status', 'index' => 'session_active', 'width' => '40', 'align' => 'left', 'search' => 'true', 'stype' => 'select',
  49. //for the bottom bar
  50. 'searchoptions' => [
  51. 'defaultValue' => '1',
  52. 'value' => '1:'.get_lang('active').';0:'.get_lang('inactive'),
  53. ],
  54. //for the top bar
  55. 'editoptions' => ['value' => ':'.get_lang('All').';1:'.get_lang('active').';0:'.get_lang('inactive')], ],
  56. ['name' => 'visibility', 'index' => 'visibility', 'width' => '40', 'align' => 'left', 'search' => 'false'],
  57. ['name' => 'actions', 'index' => 'actions', 'width' => '100', 'align' => 'left', 'formatter' => 'action_formatter', 'sortable' => 'false', 'search' => 'false'],
  58. ];
  59. //Autowidth
  60. $extra_params['autowidth'] = 'true';
  61. //height auto
  62. $extra_params['height'] = 'auto';
  63. //$extra_params['excel'] = 'excel';
  64. //$extra_params['rowList'] = array(10, 20 ,30);
  65. //With this function we can add actions to the jgrid (edit, delete, etc)
  66. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  67. 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('Subscribe users to this session'), '', ICON_SIZE_SMALL).'</a>'.
  68. '\';
  69. }';
  70. ?>
  71. <script>
  72. function setSearchSelect(columnName) {
  73. $("#sessions").jqGrid('setColProp', columnName,
  74. {
  75. searchoptions:{
  76. dataInit:function(el){
  77. $("option[value='2']",el).attr("selected", "selected");
  78. setTimeout(function(){
  79. $(el).trigger('change');
  80. },1000);
  81. }
  82. }
  83. });
  84. }
  85. $(function() {
  86. <?php
  87. echo Display::grid_js('sessions', $url, $columns, $column_model, $extra_params, [], $action_links, true);
  88. ?>
  89. setSearchSelect("status");
  90. $("#sessions").jqGrid('navGrid','#sessions_pager', {edit:false,add:false,del:false},
  91. {height:280,reloadAfterSubmit:false}, // edit options
  92. {height:280,reloadAfterSubmit:false}, // add options
  93. {reloadAfterSubmit:false}, // del options
  94. {width:500} // search options
  95. );
  96. /*
  97. // add custom button to export the data to excel
  98. jQuery("#sessions").jqGrid('navButtonAdd','#sessions_pager',{
  99. caption:"",
  100. onClickButton : function () {
  101. jQuery("#sessions").excelExport();
  102. }
  103. });
  104. jQuery('#sessions').jqGrid('navButtonAdd','#sessions_pager',{id:'pager_csv',caption:'',title:'Export To CSV',onClickButton : function(e)
  105. {
  106. try {
  107. jQuery("#sessions").jqGrid('excelExport',{tag:'csv', url:'grid.php'});
  108. } catch (e) {
  109. window.location= 'grid.php?oper=csv';
  110. }
  111. },buttonicon:'ui-icon-document'})
  112. */
  113. //Adding search options
  114. var options = {
  115. 'stringResult': true,
  116. 'autosearch' : true,
  117. 'searchOnEnter':false
  118. }
  119. jQuery("#sessions").jqGrid('filterToolbar',options);
  120. var sgrid = $("#sessions")[0];
  121. sgrid.triggerToolbar();
  122. });
  123. </script>
  124. <?php
  125. if (api_is_platform_admin()) {
  126. echo '<div class="actions">';
  127. echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/session_add.php">'.
  128. Display::return_icon('new_session.png', get_lang('Add a training session'), '', ICON_SIZE_MEDIUM).'</a>';
  129. echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/add_many_session_to_category.php">'.
  130. Display::return_icon('session_to_category.png', get_lang('Add a training sessionsInCategories'), '', ICON_SIZE_MEDIUM).'</a>';
  131. echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/session_category_list.php">'.
  132. Display::return_icon('folder.png', get_lang('Sessions categories list'), '', ICON_SIZE_MEDIUM).'</a>';
  133. echo '</div>';
  134. }
  135. echo Display::grid_html('sessions');
  136. Display::display_footer();