access_url_edit_usergroup_to_url.php 10.0 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. if ($add_type == 'multiple') {
  109. $link_add_type_unique = '<a href="'.api_get_self().'?add_type=unique&access_url_id='.$access_url_id.'">'.get_lang('SessionAddTypeUnique').'</a>';
  110. $link_add_type_multiple = get_lang('SessionAddTypeMultiple');
  111. } else {
  112. $link_add_type_unique = get_lang('SessionAddTypeUnique');
  113. $link_add_type_multiple = '<a href="'.api_get_self().'?add_type=multiple&access_url_id='.$access_url_id.'">'.get_lang('SessionAddTypeMultiple').'</a>';
  114. }
  115. $url_list = UrlManager::get_url_data();
  116. ?>
  117. <div style="text-align: left;">
  118. <?php echo $link_add_type_unique ?>&nbsp;|&nbsp;<?php echo $link_add_type_multiple ?>
  119. </div>
  120. <br /><br />
  121. <form
  122. name="formulaire"
  123. method="post"
  124. action="<?php echo api_get_self(); ?>"
  125. style="margin:0px;" <?php if ($ajax_search){ echo ' onsubmit="valide();"'; } ?>
  126. >
  127. <?php echo get_lang('SelectUrl').' : '; ?>
  128. <select name="access_url_id" onchange="javascript:send();">
  129. <option value="0">-- <?php echo get_lang('SelectUrl')?> -- </option>
  130. <?php
  131. $url_selected = '';
  132. foreach ($url_list as $url_obj) {
  133. $checked = '';
  134. if (!empty($access_url_id)) {
  135. if ($url_obj[0] == $access_url_id) {
  136. $checked = 'selected=true';
  137. $url_selected=$url_obj[1];
  138. }
  139. }
  140. if ($url_obj['active']==1) { ?>
  141. <option <?php echo $checked;?> value="<?php echo $url_obj[0]; ?>"> <?php echo $url_obj[1]; ?>
  142. </option>
  143. <?php
  144. }
  145. }
  146. ?>
  147. </select>
  148. <br /><br />
  149. <input type="hidden" name="form_sent" value="1" />
  150. <input type="hidden" name="add_type" value = "<?php echo $add_type ?>" />
  151. <?php
  152. if (!empty($errorMsg)) {
  153. Display::display_normal_message($errorMsg); //main API
  154. }
  155. ?>
  156. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  157. <!-- Users -->
  158. <tr>
  159. <td align="center"><b><?php echo get_lang('UserGroupListInPlatform') ?> :</b>
  160. </td>
  161. <td></td>
  162. <td align="center"><b><?php printf(get_lang('UserGroupListInX'),$url_selected); ?></b></td>
  163. </tr>
  164. <tr>
  165. <td align="center">
  166. <div id="content_source">
  167. <?php if ($ajax_search) { ?>
  168. <input type="text" id="course_to_add" onkeyup="xajax_searchUserGroupAjax(this.value,document.formulaire.access_url_id.options[document.formulaire.access_url_id.selectedIndex].value)" />
  169. <div id="ajax_list_courses"></div>
  170. <?php } else { ?>
  171. <select id="origin_users" name="no_course_list[]" multiple="multiple" size="15" style="width:380px;">
  172. <?php
  173. foreach ($noUserGroupList as $noItem) {
  174. ?>
  175. <option value="<?php echo $noItem['id']; ?>">
  176. <?php echo $noItem['name']; ?>
  177. </option>
  178. <?php
  179. }
  180. ?>
  181. </select>
  182. <?php
  183. }
  184. ?>
  185. </div>
  186. </td>
  187. <td width="10%" valign="middle" align="center">
  188. <?php
  189. if ($ajax_search) {
  190. ?>
  191. <button class="btn btn-default" type="button" onclick="remove_item(document.getElementById('destination_users'))" >
  192. <i class="fa fa-arrow-left"></i>
  193. </button>
  194. <?php
  195. } else {
  196. ?>
  197. <button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('origin_users'), document.getElementById('destination_users'))" >
  198. <i class="fa fa-arrow-right"></i>
  199. </button>
  200. <br /><br />
  201. <button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('destination_users'), document.getElementById('origin_users'))" >
  202. <i class="fa fa-arrow-left"></i>
  203. </button>
  204. <?php
  205. }
  206. ?>
  207. <br /><br /><br /><br /><br /><br />
  208. </td>
  209. <td align="center">
  210. <select id="destination_users" name="course_list[]" multiple="multiple" size="15" style="width:380px;">
  211. <?php
  212. foreach($userGroupList as $item) {
  213. ?>
  214. <option value="<?php echo $item['id']; ?>">
  215. <?php echo $item['name']; ?>
  216. </option>
  217. <?php
  218. }
  219. ?>
  220. </select>
  221. </td>
  222. </tr>
  223. <tr>
  224. <td colspan="3" align="center">
  225. <br />
  226. <?php
  227. if(isset($_GET['add']))
  228. echo '<button class="save" onclick="valide()" >'.get_lang('AddUserGroupToURL').'</button>';
  229. else
  230. echo '<button class="save" onclick="valide()" >'.get_lang('EditUserGroupToURL').'</button>';
  231. ?>
  232. </td>
  233. </tr>
  234. </table>
  235. </form>
  236. <script>
  237. function moveItem(origin , destination) {
  238. for(var i = 0 ; i<origin.options.length ; i++) {
  239. if(origin.options[i].selected) {
  240. destination.options[destination.length] = new Option(origin.options[i].text,origin.options[i].value);
  241. origin.options[i]=null;
  242. i = i-1;
  243. }
  244. }
  245. destination.selectedIndex = -1;
  246. sortOptions(destination.options);
  247. }
  248. function sortOptions(options) {
  249. newOptions = new Array();
  250. for (i = 0 ; i<options.length ; i++)
  251. newOptions[i] = options[i];
  252. newOptions = newOptions.sort(mysort);
  253. options.length = 0;
  254. for(i = 0 ; i < newOptions.length ; i++)
  255. options[i] = newOptions[i];
  256. }
  257. function mysort(a, b) {
  258. if(a.text.toLowerCase() > b.text.toLowerCase()){
  259. return 1;
  260. }
  261. if(a.text.toLowerCase() < b.text.toLowerCase()){
  262. return -1;
  263. }
  264. return 0;
  265. }
  266. function valide(){
  267. var options = document.getElementById('destination_users').options;
  268. for (i = 0 ; i<options.length ; i++)
  269. options[i].selected = true;
  270. document.forms.formulaire.submit();
  271. }
  272. function loadUsersInSelect(select){
  273. var xhr_object = null;
  274. if(window.XMLHttpRequest) // Firefox
  275. xhr_object = new XMLHttpRequest();
  276. else if(window.ActiveXObject) // Internet Explorer
  277. xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
  278. else // XMLHttpRequest non supporté par le navigateur
  279. alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
  280. xhr_object.open("POST", "loadUsersInSelect.ajax.php");
  281. xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  282. nosessionUsers = makepost(document.getElementById('origin_users'));
  283. sessionUsers = makepost(document.getElementById('destination_users'));
  284. nosessionClasses = makepost(document.getElementById('origin_classes'));
  285. sessionClasses = makepost(document.getElementById('destination_classes'));
  286. xhr_object.send("nosessionusers="+nosessionUsers+"&sessionusers="+sessionUsers+"&nosessionclasses="+nosessionClasses+"&sessionclasses="+sessionClasses);
  287. xhr_object.onreadystatechange = function() {
  288. if(xhr_object.readyState == 4) {
  289. document.getElementById('content_source').innerHTML = result = xhr_object.responseText;
  290. }
  291. }
  292. }
  293. function makepost(select){
  294. var options = select.options;
  295. var ret = "";
  296. for (i = 0 ; i<options.length ; i++)
  297. ret = ret + options[i].value +'::'+options[i].text+";;";
  298. return ret;
  299. }
  300. </script>
  301. <?php
  302. Display::display_footer();