access_url_edit_usergroup_to_url.php 10 KB

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