usergroup_users.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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 ($calendarPlugin) {
  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. $reportingIcon = Display::return_icon('statistics.png', get_lang('Reporting'), '', ICON_SIZE_SMALL);
  180. $controlPoint = Display::return_icon('add.png', get_lang('ControlPoint'), '', ICON_SIZE_SMALL);
  181. $link = '';
  182. if ($calendarPlugin) {
  183. $link = '<a href="'.$urlStats.'admin/usergroup_users.php?action=create_control_point&value=\'+value+\'&id='.$id.'&user_id=\'+options.rowId+\'">'.$controlPoint.'</a>';
  184. }
  185. //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>'.
  186. // With this function we can add actions to the jgrid
  187. $action_links = '
  188. function action_formatter(cellvalue, options, rowObject) {
  189. var value = rowObject[5];
  190. return \''.
  191. '&nbsp;'.$link.
  192. '&nbsp;<a href="'.$urlStats.'mySpace/myStudents.php?student=\'+options.rowId+\'">'.$reportingIcon.'</a>'.
  193. ' <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>\';
  194. }
  195. function extra_formatter(cellvalue, options, rowObject) {
  196. var calendarName = rowObject[1];
  197. var calendarId = rowObject[7];
  198. if (calendarName == "") {
  199. return \'<a href="'.
  200. 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>\';
  201. } else {
  202. return \' \'+calendarName+\' <a href="'.
  203. 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>\';
  204. }
  205. return calendarName;
  206. return \''.
  207. '&nbsp;<a href="'.$urlStats.'mySpace/myStudents.php?student=\'+options.rowId+\'">'.Display::return_icon('statistics.png', get_lang('Reporting'), '', ICON_SIZE_SMALL).'</a>'.
  208. ' <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>\';
  209. }';
  210. $deleteUrl = api_get_path(WEB_AJAX_PATH).'usergroup.ajax.php?a=delete_user_in_usergroup&group_id='.$id;
  211. if ($calendarPlugin) {
  212. $form = new FormValidator(
  213. 'add_multiple_calendar',
  214. 'post',
  215. api_get_self().'?id='.$id.'&action=add_multiple_users_to_calendar'
  216. );
  217. $calendarPlugin->getAddUserToCalendarForm($form);
  218. $form->addHidden('user_list', '');
  219. $form->addButtonSave(get_lang('Add'));
  220. }
  221. ?>
  222. <script>
  223. $(function() {
  224. <?php
  225. // grid definition see the $usergroup>display() function
  226. echo Display::grid_js(
  227. 'usergroups',
  228. $url,
  229. $columns,
  230. $column_model,
  231. $extraParams,
  232. [],
  233. $action_links,
  234. true
  235. );
  236. ?>
  237. $("#usergroups").jqGrid(
  238. "navGrid",
  239. "#usergroups_pager",
  240. { edit: false, add: false, del: true, search: false},
  241. { height:280, reloadAfterSubmit:false }, // edit options
  242. { height:280, reloadAfterSubmit:false }, // add options
  243. { reloadAfterSubmit:false, url: "<?php echo $deleteUrl; ?>" }, // del options
  244. { width:500 } // search options
  245. )
  246. <?php if ($calendarPlugin) { ?>
  247. .navButtonAdd('#usergroups_pager',{
  248. caption:"<?php echo addslashes($calendarPlugin->get_lang('UpdateCalendar')); ?>",
  249. buttonicon:"ui-icon ui-icon-plus",
  250. onClickButton: function(a) {
  251. var userIdList = $("#usergroups").jqGrid('getGridParam', 'selarrrow');
  252. if (userIdList.length) {
  253. $(".modal-body #add_multiple_calendar_user_list").val(userIdList);
  254. $('#myModal').modal();
  255. } else {
  256. alert("<?php echo addslashes(get_lang('SelectStudents')); ?>");
  257. }
  258. },
  259. position:"last"
  260. })
  261. <?php } ?>
  262. ;
  263. });
  264. </script>
  265. <?php if ($calendarPlugin) { ?>
  266. <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  267. <div class="modal-dialog" role="document">
  268. <div class="modal-content">
  269. <div class="modal-header">
  270. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  271. <span aria-hidden="true">&times;</span></button>
  272. <h4 class="modal-title" id="myModalLabel">
  273. <?php echo $calendarPlugin->get_lang('AddMultipleUsersToCalendar'); ?>
  274. </h4>
  275. </div>
  276. <div class="modal-body">
  277. <?php echo $form->display(); ?>
  278. </div>
  279. </div>
  280. </div>
  281. </div>
  282. <?php } ?>
  283. <?php
  284. $usergroup->showGroupTypeSetting = true;
  285. // Action handling: Adding a note
  286. if ($action === 'delete' && is_numeric($_GET['id'])) {
  287. $res = $usergroup->delete_user_rel_group($_GET['user_id'], $_GET['id']);
  288. Display::addFlash(Display::return_message(get_lang('Deleted'), 'confirmation'));
  289. header('Location: '.api_get_self().'?id='.$id);
  290. exit;
  291. }
  292. $usergroup->displayToolBarUserGroupUsers();
  293. Display::display_footer();