session_list.php 5.9 KB

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