usergroup_users.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. $cidReset = true;
  7. require_once __DIR__.'/../inc/global.inc.php';
  8. $this_section = SECTION_PLATFORM_ADMIN;
  9. $id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
  10. $usergroup = new UserGroup();
  11. $userGroupInfo = $usergroup->get($id);
  12. if (empty($userGroupInfo)) {
  13. api_not_allowed(true);
  14. }
  15. $usergroup->protectScript($userGroupInfo);
  16. $calendarPlugin = null;
  17. if (api_get_plugin_setting('learning_calendar', 'enabled') === 'true') {
  18. $calendarPlugin = LearningCalendarPlugin::create();
  19. }
  20. // Add the JS needed to use the jqgrid
  21. $htmlHeadXtra[] = api_get_jqgrid_js();
  22. $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
  23. $userId = isset($_GET['user_id']) ? (int) $_GET['user_id'] : 0;
  24. $calendarId = isset($_REQUEST['calendar_id']) ? (int) $_REQUEST['calendar_id'] : 0;
  25. // setting breadcrumbs
  26. $interbreadcrumb[] = ['url' => 'usergroups.php', 'name' => get_lang('Classes')];
  27. $interbreadcrumb[] = ['url' => '#', 'name' => $userGroupInfo['name']];
  28. switch ($action) {
  29. case 'add_calendar':
  30. $form = new FormValidator(
  31. 'add_calendar',
  32. 'post',
  33. api_get_self().'?id='.$id.'&user_id='.$userId.'&action=add_calendar'
  34. );
  35. $userInfo = api_get_user_info($userId);
  36. $form->addHeader($userInfo['complete_name']);
  37. $calendarPlugin->getAddUserToCalendarForm($form);
  38. $form->addButtonSave(get_lang('Add'));
  39. $form->display();
  40. if ($form->validate()) {
  41. $calendarId = $form->getSubmitValue('calendar_id');
  42. if (!empty($calendarId)) {
  43. $calendarPlugin->addUserToCalendar($calendarId, $userId);
  44. Display::addFlash(Display::return_message(get_lang('Added'), 'confirmation'));
  45. header('Location: '.api_get_self().'?id='.$id);
  46. exit;
  47. }
  48. }
  49. exit;
  50. break;
  51. case 'edit_calendar':
  52. $form = new FormValidator(
  53. 'add_calendar',
  54. 'post',
  55. api_get_self().'?id='.$id.'&user_id='.$userId.'&action=edit_calendar&calendar_id='.$calendarId
  56. );
  57. $userInfo = api_get_user_info($userId);
  58. $form->addHeader($userInfo['complete_name']);
  59. $calendarPlugin->getAddUserToCalendarForm($form);
  60. $form->setDefaults(['calendar_id' => $calendarId]);
  61. $form->addButtonSave(get_lang('Update'));
  62. $form->display();
  63. if ($form->validate()) {
  64. $calendarId = $form->getSubmitValue('calendar_id');
  65. if (!empty($calendarId)) {
  66. $calendarPlugin->updateUserToCalendar($calendarId, $userId);
  67. Display::addFlash(Display::return_message(get_lang('Added'), 'confirmation'));
  68. header('Location: '.api_get_self().'?id='.$id);
  69. exit;
  70. }
  71. }
  72. exit;
  73. break;
  74. case 'delete':
  75. $res = $usergroup->delete_user_rel_group($_GET['user_id'], $_GET['id']);
  76. Display::addFlash(Display::return_message(get_lang('Deleted'), 'confirmation'));
  77. header('Location: '.api_get_self().'?id='.$id);
  78. exit;
  79. break;
  80. case 'create_control_point':
  81. $value = isset($_GET['value']) ? (int) $_GET['value'] : 0;
  82. $calendarPlugin->addControlPoint($userId, $value);
  83. Display::addFlash(
  84. Display::return_message($calendarPlugin->get_lang('ControlPointAdded'), 'confirmation')
  85. );
  86. header('Location: '.api_get_self().'?id='.$id);
  87. exit;
  88. case 'add_multiple_users_to_calendar':
  89. $userList = isset($_REQUEST['user_list']) ? explode(',', $_REQUEST['user_list']) : 0;
  90. foreach ($userList as $userId) {
  91. $isAdded = $calendarPlugin->addUserToCalendar($calendarId, $userId);
  92. if (!$isAdded) {
  93. $isAdded = $calendarPlugin->updateUserToCalendar($calendarId, $userId);
  94. }
  95. }
  96. Display::addFlash(
  97. Display::return_message(get_lang('Added'), 'confirmation')
  98. );
  99. header('Location: '.api_get_self().'?id='.$id);
  100. exit;
  101. break;
  102. }
  103. Display::display_header();
  104. // jqgrid will use this URL to do the selects
  105. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups_users&id='.$id;
  106. // The order is important you need to check the the $column variable in the model.ajax.php file
  107. $columns = [
  108. get_lang('Name'),
  109. get_lang('Actions'),
  110. ];
  111. // Column config
  112. $column_model = [
  113. ['name' => 'name', 'index' => 'name', 'width' => '35', 'align' => 'left', 'sortable' => 'false'],
  114. [
  115. 'name' => 'actions',
  116. 'index' => 'actions',
  117. 'width' => '20',
  118. 'align' => 'center',
  119. 'sortable' => 'false',
  120. 'formatter' => 'action_formatter',
  121. ],
  122. ];
  123. if (api_get_plugin_setting('learning_calendar', 'enabled') === 'true') {
  124. $columns = [
  125. get_lang('Name'),
  126. get_lang('Calendar'),
  127. get_lang('ClassroomActivity'),
  128. get_lang('TimeSpentByStudentsInCourses'),
  129. $calendarPlugin->get_lang('NumberDaysAccumulatedInCalendar'),
  130. $calendarPlugin->get_lang('DifferenceOfDaysAndCalendar'),
  131. get_lang('Actions'),
  132. ];
  133. // Column config
  134. $column_model = [
  135. ['name' => 'name', 'index' => 'name', 'width' => '35', 'align' => 'left', 'sortable' => 'false'],
  136. [
  137. 'name' => 'calendar',
  138. 'index' => 'calendar',
  139. 'width' => '35',
  140. 'align' => 'left',
  141. 'sortable' => 'false',
  142. 'formatter' => 'extra_formatter',
  143. ],
  144. [
  145. 'name' => 'gradebook_items',
  146. 'index' => 'gradebook_items',
  147. 'width' => '35',
  148. 'align' => 'left',
  149. 'sortable' => 'false',
  150. ],
  151. ['name' => 'time_spent', 'index' => 'time_spent', 'width' => '35', 'align' => 'left', 'sortable' => 'false'],
  152. [
  153. 'name' => 'lp_day_completed',
  154. 'index' => 'lp_day_completed',
  155. 'width' => '35',
  156. 'align' => 'left',
  157. 'sortable' => 'false',
  158. ],
  159. ['name' => 'days_diff', 'index' => 'days_diff', 'width' => '35', 'align' => 'left', 'sortable' => 'false'],
  160. [
  161. 'name' => 'actions',
  162. 'index' => 'actions',
  163. 'width' => '20',
  164. 'align' => 'center',
  165. 'sortable' => 'false',
  166. 'formatter' => 'action_formatter',
  167. ],
  168. ];
  169. }
  170. // Autowidth
  171. $extraParams['autowidth'] = 'true';
  172. // height auto
  173. $extraParams['height'] = 'auto';
  174. $extraParams['sortname'] = 'name';
  175. $extraParams['sortorder'] = 'desc';
  176. $extraParams['multiselect'] = true;
  177. $deleteIcon = Display::return_icon('delete.png', get_lang('Delete'), null, ICON_SIZE_SMALL);
  178. $urlStats = api_get_path(WEB_CODE_PATH);
  179. //$addCalendar = '<a href="'.$urlStats.'mySpace/myStudents.php?student=\'+options.rowId+\'">'.Display::return_icon('agenda.png', get_lang('Agenda'), '', ICON_SIZE_SMALL).'</a>';
  180. $reportingIcon = Display::return_icon('statistics.png', get_lang('Reporting'), '', ICON_SIZE_SMALL);
  181. $controlPoint = Display::return_icon('add.png', get_lang('ControlPoint'), '', ICON_SIZE_SMALL);
  182. //return \'<a href="session_edit.php?page=resume_session.php&id=\'+options.rowId+\'">'.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>'.
  183. // With this function we can add actions to the jgrid
  184. $action_links = '
  185. function action_formatter(cellvalue, options, rowObject) {
  186. var value = rowObject[5];
  187. return \''.
  188. '&nbsp;<a href="'.$urlStats.'admin/usergroup_users.php?action=create_control_point&value=\'+value+\'&id='.$id.'&user_id=\'+options.rowId+\'">'.$controlPoint.'</a>'.
  189. '&nbsp;<a href="'.$urlStats.'mySpace/myStudents.php?student=\'+options.rowId+\'">'.$reportingIcon.'</a>'.
  190. ' <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."\'".')) return false;" href="?id='.$id.'&action=delete&user_id=\'+options.rowId+\'">'.$deleteIcon.'</a>\';
  191. }
  192. function extra_formatter(cellvalue, options, rowObject) {
  193. var calendarName = rowObject[1];
  194. var calendarId = rowObject[7];
  195. if (calendarName == "") {
  196. return \'<a href="'.
  197. api_get_path(WEB_CODE_PATH).'admin/usergroup_users.php?user_id=\'+options.rowId+\'&id='.$id.'&action=add_calendar&width=700" class="btn btn-primary ajax">'.get_lang('Add').'</a>\';
  198. } else {
  199. return \' \'+calendarName+\' <a href="'.
  200. api_get_path(WEB_CODE_PATH).'admin/usergroup_users.php?calendar_id=\'+calendarId+\'&user_id=\'+options.rowId+\'&id='.$id.'&action=edit_calendar&width=700" class="btn btn-primary ajax"> '.get_lang('Edit').'</a>\';
  201. }
  202. return calendarName;
  203. return \''.
  204. '&nbsp;<a href="'.$urlStats.'mySpace/myStudents.php?student=\'+options.rowId+\'">'.Display::return_icon('statistics.png', get_lang('Reporting'), '', ICON_SIZE_SMALL).'</a>'.
  205. ' <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."\'".')) return false;" href="?id='.$id.'&action=delete&user_id=\'+options.rowId+\'">'.$deleteIcon.'</a>\';
  206. }';
  207. $deleteUrl = api_get_path(WEB_AJAX_PATH).'usergroup.ajax.php?a=delete_user_in_usergroup&group_id='.$id;
  208. $form = new FormValidator(
  209. 'add_multiple_calendar',
  210. 'post',
  211. api_get_self().'?id='.$id.'&action=add_multiple_users_to_calendar'
  212. );
  213. $calendarPlugin->getAddUserToCalendarForm($form);
  214. $form->addHidden('user_list', '');
  215. $form->addButtonSave(get_lang('Add'));
  216. ?>
  217. <script>
  218. $(function() {
  219. <?php
  220. // grid definition see the $usergroup>display() function
  221. echo Display::grid_js(
  222. 'usergroups',
  223. $url,
  224. $columns,
  225. $column_model,
  226. $extraParams,
  227. [],
  228. $action_links,
  229. true
  230. );
  231. ?>
  232. $("#usergroups").jqGrid(
  233. "navGrid",
  234. "#usergroups_pager",
  235. { edit: false, add: false, del: true, search: false},
  236. { height:280, reloadAfterSubmit:false }, // edit options
  237. { height:280, reloadAfterSubmit:false }, // add options
  238. { reloadAfterSubmit:false, url: "<?php echo $deleteUrl; ?>" }, // del options
  239. { width:500 } // search options
  240. )
  241. .navButtonAdd('#usergroups_pager',{
  242. caption:"<?php echo addslashes($calendarPlugin->get_lang('UpdateCalendar')); ?>",
  243. buttonicon:"ui-icon ui-icon-plus",
  244. onClickButton: function(a) {
  245. var userIdList = $("#usergroups").jqGrid('getGridParam', 'selarrrow');
  246. if (userIdList.length) {
  247. $(".modal-body #add_multiple_calendar_user_list").val(userIdList);
  248. $('#myModal').modal();
  249. } else {
  250. alert("<?php echo addslashes(get_lang('SelectStudents')); ?>");
  251. }
  252. },
  253. position:"last"
  254. });
  255. });
  256. </script>
  257. <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  258. <div class="modal-dialog" role="document">
  259. <div class="modal-content">
  260. <div class="modal-header">
  261. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  262. <span aria-hidden="true">&times;</span></button>
  263. <h4 class="modal-title" id="myModalLabel">
  264. <?php echo $calendarPlugin->get_lang('AddMultipleUsersToCalendar'); ?>
  265. </h4>
  266. </div>
  267. <div class="modal-body">
  268. <?php echo $form->display(); ?>
  269. </div>
  270. </div>
  271. </div>
  272. </div>
  273. <?php
  274. $usergroup->showGroupTypeSetting = true;
  275. // Action handling: Adding a note
  276. if ($action === 'delete' && is_numeric($_GET['id'])) {
  277. $res = $usergroup->delete_user_rel_group($_GET['user_id'], $_GET['id']);
  278. Display::addFlash(Display::return_message(get_lang('Deleted'), 'confirmation'));
  279. header('Location: '.api_get_self().'?id='.$id);
  280. exit;
  281. } else {
  282. $usergroup->displayToolBarUserGroupUsers();
  283. }
  284. Display::display_footer();