session_list.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 = 'admin';
  11. $cidReset = true;
  12. require_once '../inc/global.inc.php';
  13. $this_section = SECTION_PLATFORM_ADMIN;
  14. api_protect_teacher_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. $tool_name = get_lang('SessionList');
  20. Display::display_header($tool_name);
  21. if($_configuration['allow_tutors_to_assign_students_to_session'] == 'true') {
  22. $error_message = ''; // Avoid conflict with the global variable $error_msg (array type) in add_course.conf.php.
  23. if (isset($_GET['action']) && $_GET['action'] == 'show_message') {
  24. $error_message = Security::remove_XSS($_GET['message']);
  25. }
  26. if (!empty($error_message)) {
  27. Display::display_normal_message($error_message, false);
  28. }
  29. //jqgrid will use this URL to do the selects
  30. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&from_course_session=1';
  31. if (isset($_REQUEST['keyword'])) {
  32. //Begin with see the searchOper param
  33. $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';
  34. }
  35. //The order is important you need to check the the $column variable in the model.ajax.php file
  36. $columns = array(get_lang('Name'), get_lang('NumberOfCourses'), get_lang('NumberOfUsers'), get_lang('SessionCategoryName'),
  37. get_lang('StartDate'), get_lang('EndDate'), get_lang('Coach'), get_lang('Status'), get_lang('Visibility'), get_lang('Actions'));
  38. //$activeurl = '?sidx=session_active';
  39. //Column config
  40. $column_model = array(
  41. array('name'=>'name', 'index'=>'name', 'width'=>'160', 'align'=>'left', 'search' => 'true', 'wrap_cell' => "true"),
  42. array('name'=>'nbr_courses', 'index'=>'nbr_courses', 'width'=>'30', 'align'=>'left', 'search' => 'true'),
  43. array('name'=>'nbr_users', 'index'=>'nbr_users', 'width'=>'30', 'align'=>'left', 'search' => 'true'),
  44. array('name'=>'category_name', 'index'=>'category_name', 'width'=>'70', 'align'=>'left', 'search' => 'true'),
  45. array('name'=>'date_start', 'index'=>'date_start', 'width'=>'40', 'align'=>'left', 'search' => 'true'),
  46. array('name'=>'date_end', 'index'=>'date_end', 'width'=>'40', 'align'=>'left', 'search' => 'true'),
  47. array('name'=>'coach_name', 'index'=>'coach_name', 'width'=>'80', 'align'=>'left', 'search' => 'false'),
  48. array('name'=>'status', 'index'=>'session_active','width'=>'40', 'align'=>'left', 'search' => 'true', 'stype'=>'select',
  49. //for the bottom bar
  50. 'searchoptions' => array(
  51. 'defaultValue' => '1',
  52. 'value' => '1:'.get_lang('Active').';0:'.get_lang('Inactive')),
  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).'admin/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).'admin/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).'admin/session_category_list.php">'.Display::return_icon('folder.png',get_lang('ListSessionCategory'),'',ICON_SIZE_MEDIUM).'</a>';
  129. echo '</div>';
  130. }
  131. } else {
  132. api_not_allowed();
  133. }
  134. echo Display::grid_html('sessions');
  135. Display::display_footer();