class.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.user
  5. */
  6. /**
  7. * INIT SECTION
  8. */
  9. // name of the language file that needs to be included
  10. $language_file = array('registration','admin');
  11. require_once '../inc/global.inc.php';
  12. $this_section = SECTION_COURSES;
  13. api_protect_course_script();
  14. if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'false') {
  15. if (!api_is_platform_admin()) {
  16. api_not_allowed(true);
  17. }
  18. }
  19. $tool_name = get_lang("Classes");
  20. $htmlHeadXtra[] = api_get_jqgrid_js();
  21. //extra entries in breadcrumb
  22. $interbreadcrumb[] = array ("url" => "user.php", "name" => get_lang("ToolUser"));
  23. $type = isset($_GET['type']) ? Security::remove_XSS($_GET['type']) : 'registered';
  24. Display :: display_header($tool_name, "User");
  25. $usergroup = new UserGroup();
  26. if (api_is_allowed_to_edit()) {
  27. echo '<div class="actions">';
  28. if ($type == 'registered') {
  29. echo '<a href="class.php?'.api_get_cidreq().'&type=not_registered">'.Display::return_icon('add.png', get_lang("AddClassesToACourse"), array(), ICON_SIZE_MEDIUM).'</a>';
  30. } else {
  31. echo '<a href="class.php?'.api_get_cidreq().'&type=registered">'.Display::return_icon('empty_evaluation.png', get_lang("Classes"), array(), ICON_SIZE_MEDIUM).'</a>';
  32. }
  33. echo '</div>';
  34. }
  35. echo Display::page_header($tool_name);
  36. if (api_is_allowed_to_edit()) {
  37. $action = isset($_GET['action']) ? $_GET['action'] : null;
  38. switch ($action) {
  39. case 'add_class_to_course':
  40. $id = $_GET['id'];
  41. if (!empty($id)) {
  42. $usergroup->subscribe_courses_to_usergroup($id, array(api_get_course_int_id()), false);
  43. }
  44. break;
  45. case 'remove_class_from_course':
  46. $id = $_GET['id'];
  47. if (!empty($id)) {
  48. $usergroup->unsubscribe_courses_from_usergroup($id, array(api_get_course_int_id()));
  49. }
  50. break;
  51. }
  52. }
  53. //jqgrid will use this URL to do the selects
  54. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups_teacher&type='.$type;
  55. //The order is important you need to check the the $column variable in the model.ajax.php file
  56. $columns = array(get_lang('Name'), get_lang('Users'), get_lang('Actions'));
  57. //Column config
  58. $column_model = array(
  59. array('name'=>'name', 'index'=>'name', 'width'=>'35', 'align'=>'left'),
  60. array('name'=>'users', 'index'=>'users', 'width'=>'15', 'align'=>'left'),
  61. array('name'=>'actions', 'index'=>'actions', 'width'=>'20', 'align'=>'left','sortable'=>'false'),
  62. );
  63. //Autowidth
  64. $extra_params['autowidth'] = 'true';
  65. //height auto
  66. $extra_params['height'] = 'auto';
  67. //$extra_params['rowList'] = array(50, 100, 500, 1000, 2000, 5000);
  68. //With this function we can add actions to the jgrid
  69. $action_links = 'function action_formatter (cellvalue, options, rowObject) {
  70. return \''
  71. .' <a href="class.php?action=add_class&id=\'+options.rowId+\'"><img src="../img/icons/22/user_to_class.png" title="'.get_lang('SubscribeUsersToClass').'"></a>'
  72. .' <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?action=delete&id=\'+options.rowId+\'"><img title="'.get_lang('Delete').'" src="../img/delete.png"></a>\';
  73. }';
  74. ?>
  75. <script>
  76. $(function() {
  77. <?php
  78. // grid definition see the $usergroup>display() function
  79. echo Display::grid_js('usergroups', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  80. ?>
  81. });
  82. </script>
  83. <?php
  84. $usergroup->display_teacher_view();
  85. Display :: display_footer();