access_url_edit_usergroup_to_url.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. * @author Julio Montoya <gugli100@gmail.com>
  6. */
  7. // resetting the course id
  8. $cidReset = true;
  9. require_once '../inc/global.inc.php';
  10. $xajax = new xajax();
  11. $xajax->registerFunction(array('searchUserGroupAjax', 'UserGroup', 'searchUserGroupAjax'));
  12. $userGroup = new UserGroup();
  13. // Setting the section (for the tabs)
  14. $this_section = SECTION_PLATFORM_ADMIN;
  15. // Access restrictions
  16. api_protect_global_admin_script();
  17. if (!api_get_multiple_access_url()) {
  18. header('Location: index.php');
  19. exit;
  20. }
  21. // setting breadcrumbs
  22. $tool_name = get_lang('EditUserGroupToURL');
  23. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  24. $interbreadcrumb[] = array('url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs'));
  25. $add_type = 'multiple';
  26. if (isset($_REQUEST['add_type']) && $_REQUEST['add_type'] != '') {
  27. $add_type = Security::remove_XSS($_REQUEST['add_type']);
  28. }
  29. $access_url_id = 1;
  30. if (isset($_REQUEST['access_url_id']) && $_REQUEST['access_url_id'] != '') {
  31. $access_url_id = Security::remove_XSS($_REQUEST['access_url_id']);
  32. }
  33. $xajax->processRequests();
  34. $htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
  35. $htmlHeadXtra[] = '
  36. <script>
  37. function add_user_to_url(code, content) {
  38. document.getElementById("course_to_add").value = "";
  39. document.getElementById("ajax_list_courses").innerHTML = "";
  40. destination = document.getElementById("destination_users");
  41. destination.options[destination.length] = new Option(content,code);
  42. destination.selectedIndex = -1;
  43. sortOptions(destination.options);
  44. }
  45. function send() {
  46. if (document.formulaire.access_url_id.value!=0) {
  47. document.formulaire.form_sent.value=0;
  48. document.formulaire.add_type.value=\'' . $add_type . '\';
  49. document.formulaire.submit();
  50. }
  51. }
  52. function remove_item(origin) {
  53. for(var i = 0 ; i<origin.options.length ; i++) {
  54. if(origin.options[i].selected) {
  55. origin.options[i]=null;
  56. i = i-1;
  57. }
  58. }
  59. }
  60. </script>';
  61. $form_sent = 0;
  62. $errorMsg = '';
  63. $UserList = $SessionList = array();
  64. $users = $sessions = array();
  65. if (isset($_POST['form_sent']) && $_POST['form_sent']) {
  66. $form_sent = $_POST['form_sent'];
  67. $course_list = $_POST['course_list'];
  68. if (!is_array($course_list)) {
  69. $course_list = array();
  70. }
  71. if ($form_sent == 1) {
  72. if ($access_url_id == 0) {
  73. header('Location: access_url_edit_users_to_url.php?action=show_message&message='.get_lang('SelectURL'));
  74. } elseif (is_array($course_list)) {
  75. UrlManager::update_urls_rel_usergroup($course_list, $access_url_id);
  76. header('Location: access_urls.php?action=show_message&message='.get_lang('Updated'));
  77. }
  78. exit;
  79. }
  80. }
  81. Display::display_header($tool_name);
  82. echo '<div class="actions">';
  83. echo Display::url(
  84. Display::return_icon('view_more_stats.gif', get_lang('AddUserGroupToURL'), ''),
  85. api_get_path(WEB_CODE_PATH) . 'admin/access_url_add_usergroup_to_url.php'
  86. );
  87. echo '</div>';
  88. api_display_tool_title($tool_name);
  89. if ($_GET['action'] == 'show_message') {
  90. Display :: display_normal_message(Security::remove_XSS(stripslashes($_GET['message'])));
  91. }
  92. $noUserGroupList = $userGroupList = array();
  93. $ajax_search = $add_type == 'unique' ? true : false;
  94. if ($ajax_search) {
  95. $userGroups = UrlManager::get_url_rel_usergroup_data($access_url_id);
  96. foreach ($userGroups as $item) {
  97. $userGroupList[$item['id']] = $item;
  98. }
  99. } else {
  100. $userGroups = UrlManager::get_url_rel_usergroup_data();
  101. foreach ($userGroups as $item) {
  102. if ($item['access_url_id'] == $access_url_id) {
  103. $userGroupList[$item['id']] = $item;
  104. }
  105. }
  106. $noUserGroupList = $userGroup->getUserGroupNotInList(array_keys($userGroupList));
  107. }
  108. $link_add_type_unique = ['class' => 'disabled'];
  109. $link_add_type_multiple = [];
  110. if ($add_type == 'multiple') {
  111. $link_add_type_unique = [];
  112. $link_add_type_multiple = ['class' => 'disabled'];
  113. }
  114. ?>
  115. <div class="btn-toolbar">
  116. <div class="btn-group">
  117. <?php
  118. echo Display::toolbarButton(
  119. get_lang('SessionAddTypeUnique'),
  120. api_get_self() . '?' . http_build_query([
  121. 'add_type' => 'unique',
  122. 'access_url_id' => $access_url_id
  123. ]),
  124. 'file-o',
  125. 'default',
  126. $link_add_type_unique
  127. );
  128. echo Display::toolbarButton(
  129. get_lang('SessionAddTypeMultiple'),
  130. api_get_self() . '?' . http_build_query([
  131. 'add_type' => 'multiple',
  132. 'access_url_id' => $access_url_id
  133. ]),
  134. 'files-o',
  135. 'default',
  136. $link_add_type_multiple
  137. );
  138. ?>
  139. </div>
  140. </div>
  141. <?php
  142. $url_list = UrlManager::get_url_data();
  143. ?>
  144. <form
  145. name="formulaire"
  146. method="post"
  147. action="<?php echo api_get_self(); ?>"
  148. style="margin:0px;" <?php if ($ajax_search) {
  149. echo ' onsubmit="valide();"';
  150. } ?>
  151. >
  152. <div class="row">
  153. <div class="col-xs-2">
  154. <label for="access_url_id"><?php echo get_lang('SelectUrl') ?></label>
  155. </div>
  156. <div class="col-xs-5">
  157. <select name="access_url_id" id="access_url_id" onchange="javascript:send();" class="form-control">
  158. <option value="0">-- <?php echo get_lang('SelectUrl') ?> --</option>
  159. <?php
  160. $url_selected = '';
  161. foreach ($url_list as $url_obj) {
  162. $checked = '';
  163. if (!empty($access_url_id)) {
  164. if ($url_obj[0] == $access_url_id) {
  165. $checked = 'selected=true';
  166. $url_selected = $url_obj[1];
  167. }
  168. }
  169. if ($url_obj['active'] == 1) { ?>
  170. <option <?php echo $checked; ?>
  171. value="<?php echo $url_obj[0]; ?>"> <?php echo $url_obj[1]; ?>
  172. </option>
  173. <?php
  174. }
  175. }
  176. ?>
  177. </select>
  178. </div>
  179. </div>
  180. <input type="hidden" name="form_sent" value="1"/>
  181. <input type="hidden" name="add_type" value="<?php echo $add_type ?>"/>
  182. <?php
  183. if (!empty($errorMsg)) {
  184. Display::display_normal_message($errorMsg); //main API
  185. }
  186. ?>
  187. <div class="row">
  188. <div class="col-sm-5">
  189. <label for="<?php echo $ajax_search ? 'course_to_add' : 'origin_users' ?>"><?php echo get_lang('UserGroupListInPlatform') ?></label>
  190. <div id="content_source">
  191. <?php if ($ajax_search) { ?>
  192. <input type="text" id="course_to_add" class="form-control"
  193. onkeyup="xajax_searchUserGroupAjax(this.value,document.formulaire.access_url_id.options[document.formulaire.access_url_id.selectedIndex].value)"/>
  194. <div id="ajax_list_courses"></div>
  195. <?php } else { ?>
  196. <select id="origin_users" name="no_course_list[]" multiple="multiple" size="15" class="form-control">
  197. <?php foreach ($noUserGroupList as $noItem) { ?>
  198. <option value="<?php echo $noItem['id']; ?>"><?php echo $noItem['name']; ?></option>
  199. <?php } ?>
  200. </select>
  201. <?php } ?>
  202. </div>
  203. </div>
  204. <div class="col-sm-2 text-center">
  205. <br><br><br><br>
  206. <?php if ($ajax_search) { ?>
  207. <button class="btn btn-default" type="button"
  208. onclick="remove_item(document.getElementById('destination_users'))">
  209. <em class="fa fa-arrow-left"></em>
  210. </button>
  211. <?php } else { ?>
  212. <button class="btn btn-default" type="button"
  213. onclick="moveItem(document.getElementById('origin_users'), document.getElementById('destination_users'))">
  214. <em class="fa fa-arrow-right"></em>
  215. </button>
  216. <br/><br/>
  217. <button class="btn btn-default" type="button"
  218. onclick="moveItem(document.getElementById('destination_users'), document.getElementById('origin_users'))">
  219. <em class="fa fa-arrow-left"></em>
  220. </button>
  221. <?php } ?>
  222. </div>
  223. <div class="col-sm-5">
  224. <label for="destination_users"><?php printf(get_lang('UserGroupListInX'), $url_selected); ?></label>
  225. <select id="destination_users" name="course_list[]" multiple="multiple" size="15" class="form-control">
  226. <?php foreach ($userGroupList as $item) { ?>
  227. <option value="<?php echo $item['id']; ?>">
  228. <?php echo $item['name']; ?>
  229. </option>
  230. <?php } ?>
  231. </select>
  232. </div>
  233. </div>
  234. <div class="row">
  235. <div class="col-xs-12 text-center">
  236. <button class="save btn btn-primary" onclick="valide()">
  237. <span class="fa fa-save fa-fw" aria-hidden="true"></span>
  238. <?php echo isset($_GET['add']) ? get_lang('AddUserGroupToURL') : get_lang('EditUserGroupToURL') ?>
  239. </button>
  240. </div>
  241. </div>
  242. </form>
  243. <script>
  244. function moveItem(origin, destination) {
  245. for (var i = 0; i < origin.options.length; i++) {
  246. if (origin.options[i].selected) {
  247. destination.options[destination.length] = new Option(origin.options[i].text, origin.options[i].value);
  248. origin.options[i] = null;
  249. i = i - 1;
  250. }
  251. }
  252. destination.selectedIndex = -1;
  253. sortOptions(destination.options);
  254. }
  255. function sortOptions(options) {
  256. newOptions = new Array();
  257. for (i = 0; i < options.length; i++)
  258. newOptions[i] = options[i];
  259. newOptions = newOptions.sort(mysort);
  260. options.length = 0;
  261. for (i = 0; i < newOptions.length; i++)
  262. options[i] = newOptions[i];
  263. }
  264. function mysort(a, b) {
  265. if (a.text.toLowerCase() > b.text.toLowerCase()) {
  266. return 1;
  267. }
  268. if (a.text.toLowerCase() < b.text.toLowerCase()) {
  269. return -1;
  270. }
  271. return 0;
  272. }
  273. function valide() {
  274. var options = document.getElementById('destination_users').options;
  275. for (i = 0; i < options.length; i++)
  276. options[i].selected = true;
  277. document.forms.formulaire.submit();
  278. }
  279. function loadUsersInSelect(select) {
  280. var xhr_object = null;
  281. if (window.XMLHttpRequest) // Firefox
  282. xhr_object = new XMLHttpRequest();
  283. else if (window.ActiveXObject) // Internet Explorer
  284. xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
  285. else // XMLHttpRequest non supporté par le navigateur
  286. alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
  287. xhr_object.open("POST", "loadUsersInSelect.ajax.php");
  288. xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  289. nosessionUsers = makepost(document.getElementById('origin_users'));
  290. sessionUsers = makepost(document.getElementById('destination_users'));
  291. nosessionClasses = makepost(document.getElementById('origin_classes'));
  292. sessionClasses = makepost(document.getElementById('destination_classes'));
  293. xhr_object.send("nosessionusers=" + nosessionUsers + "&sessionusers=" + sessionUsers + "&nosessionclasses=" + nosessionClasses + "&sessionclasses=" + sessionClasses);
  294. xhr_object.onreadystatechange = function () {
  295. if (xhr_object.readyState == 4) {
  296. document.getElementById('content_source').innerHTML = result = xhr_object.responseText;
  297. }
  298. }
  299. }
  300. function makepost(select) {
  301. var options = select.options;
  302. var ret = "";
  303. for (i = 0; i < options.length; i++)
  304. ret = ret + options[i].value + '::' + options[i].text + ";;";
  305. return ret;
  306. }
  307. </script>
  308. <?php
  309. Display::display_footer();