class.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. $htmlHeadXtra[] = api_get_jqgrid_js();
  20. //extra entries in breadcrumb
  21. $interbreadcrumb[] = array ("url" => "user.php", "name" => get_lang("ToolUser"));
  22. $type = isset($_GET['type']) ? Security::remove_XSS($_GET['type']) : 'registered';
  23. switch($type) {
  24. case 'registered':
  25. $tool_name = get_lang("RegisteredClasses");
  26. break;
  27. default:
  28. $tool_name = get_lang("AvailableClasses");
  29. }
  30. Display::display_header($tool_name, "User");
  31. $usergroup = new UserGroup();
  32. if (api_is_allowed_to_edit()) {
  33. echo '<div class="actions">';
  34. if ($type == 'registered') {
  35. echo '<a href="class.php?'.api_get_cidreq().'&type=not_registered">'.Display::return_icon('add.png', get_lang("AddClassesToACourse"), array(), ICON_SIZE_MEDIUM).'</a>';
  36. } else {
  37. echo '<a href="class.php?'.api_get_cidreq().'&type=registered">'.Display::return_icon('empty_evaluation.png', get_lang("Classes"), array(), ICON_SIZE_MEDIUM).'</a>';
  38. }
  39. echo '</div>';
  40. }
  41. if (api_is_allowed_to_edit()) {
  42. $action = isset($_GET['action']) ? $_GET['action'] : null;
  43. switch ($action) {
  44. case 'add_class_to_course':
  45. $id = $_GET['id'];
  46. if (!empty($id)) {
  47. $usergroup->subscribe_courses_to_usergroup($id, array(api_get_course_int_id()), false);
  48. }
  49. break;
  50. case 'remove_class_from_course':
  51. $id = $_GET['id'];
  52. if (!empty($id)) {
  53. $usergroup->unsubscribe_courses_from_usergroup($id, array(api_get_course_int_id()));
  54. }
  55. break;
  56. }
  57. }
  58. //jqgrid will use this URL to do the selects
  59. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups_teacher&type='.$type;
  60. //The order is important you need to check the the $column variable in the model.ajax.php file
  61. $columns = array(get_lang('Name'), get_lang('Users'), get_lang('Actions'));
  62. //Column config
  63. $column_model = array(
  64. array('name'=>'name', 'index'=>'name', 'width'=>'35', 'align'=>'left'),
  65. array('name'=>'users', 'index'=>'users', 'width'=>'15', 'align'=>'left'),
  66. array('name'=>'actions', 'index'=>'actions', 'width'=>'20', 'align'=>'left','sortable'=>'false'),
  67. );
  68. //Autowidth
  69. $extra_params['autowidth'] = 'true';
  70. //height auto
  71. $extra_params['height'] = 'auto';
  72. //$extra_params['rowList'] = array(50, 100, 500, 1000, 2000, 5000);
  73. //With this function we can add actions to the jgrid
  74. $action_links = 'function action_formatter (cellvalue, options, rowObject) {
  75. return \''
  76. .' <a href="class.php?action=add_class&id=\'+options.rowId+\'"><img src="'.api_get_path(WEB_IMG_PATH).'icons/22/user_to_class.png" title="'.get_lang('SubscribeUsersToClass').'"></a>'
  77. .' <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="'.api_get_path(WEB_IMG_PATH).'delete.png"></a>\';
  78. }';
  79. ?>
  80. <script>
  81. $(function() {
  82. <?php
  83. echo Display::grid_js('usergroups', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  84. ?>
  85. });
  86. </script>
  87. <?php
  88. $usergroup->display_teacher_view();
  89. Display :: display_footer();