access_url_edit_usergroup_to_url.php 11 KB

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