access_url_edit_courses_to_url.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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).'access_url_edit_courses_to_url_functions.lib.php';
  14. $xajax = new xajax();
  15. $xajax -> registerFunction (array('search_courses', 'Accessurleditcoursestourl', 'search_courses'));
  16. // setting the section (for the tabs)
  17. $this_section = SECTION_PLATFORM_ADMIN;
  18. // Access restrictions
  19. api_protect_global_admin_script();
  20. if (!api_get_multiple_access_url()) {
  21. header('Location: index.php');
  22. exit;
  23. }
  24. // Database Table Definitions
  25. $tbl_access_url_rel_course = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  26. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  27. $tbl_access_url = Database :: get_main_table(TABLE_MAIN_ACCESS_URL);
  28. // setting breadcrumbs
  29. $tool_name = get_lang('EditCoursesToURL');
  30. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  31. $interbreadcrumb[] = array ('url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs'));
  32. $add_type = 'multiple';
  33. if(isset($_REQUEST['add_type']) && $_REQUEST['add_type']!='') {
  34. $add_type = Security::remove_XSS($_REQUEST['add_type']);
  35. }
  36. $access_url_id=1;
  37. if (isset($_REQUEST['access_url_id']) && $_REQUEST['access_url_id']!='') {
  38. $access_url_id = Security::remove_XSS($_REQUEST['access_url_id']);
  39. }
  40. $xajax -> processRequests();
  41. $htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
  42. $htmlHeadXtra[] = '<script>
  43. function add_user_to_url(code, content) {
  44. document.getElementById("course_to_add").value = "";
  45. document.getElementById("ajax_list_courses").innerHTML = "";
  46. destination = document.getElementById("destination_users");
  47. destination.options[destination.length] = new Option(content,code);
  48. destination.selectedIndex = -1;
  49. sortOptions(destination.options);
  50. }
  51. function send() {
  52. if (document.formulaire.access_url_id.value != 0) {
  53. document.formulaire.form_sent.value=0;
  54. document.formulaire.add_type.value=\''.$add_type.'\';
  55. document.formulaire.submit();
  56. }
  57. }
  58. function remove_item(origin) {
  59. for(var i = 0 ; i<origin.options.length ; i++) {
  60. if(origin.options[i].selected) {
  61. origin.options[i]=null;
  62. i = i-1;
  63. }
  64. }
  65. }
  66. </script>';
  67. $form_sent = 0;
  68. $errorMsg = '';
  69. $UserList = $SessionList = array();
  70. $users = $sessions = array();
  71. if (isset($_POST['form_sent']) && $_POST['form_sent']) {
  72. $form_sent=$_POST['form_sent'];
  73. $course_list=$_POST['course_list'];
  74. if (!is_array($course_list)) {
  75. $course_list=array();
  76. }
  77. if ($form_sent == 1) {
  78. if ($access_url_id==0) {
  79. header('Location: access_url_edit_users_to_url.php?action=show_message&message='.get_lang('SelectURL'));
  80. }
  81. elseif(is_array($course_list) ) {
  82. UrlManager::update_urls_rel_course($course_list, $access_url_id);
  83. header('Location: access_urls.php?action=show_message&message='.get_lang('CoursesWereEdited'));
  84. }
  85. }
  86. }
  87. Display::display_header($tool_name);
  88. echo '<div class="actions">';
  89. echo Display::url( Display::return_icon('view_more_stats.gif', get_lang('AddUserToURL'),''), api_get_path(WEB_CODE_PATH).'admin/access_url_add_courses_to_url.php');
  90. echo '</div>';
  91. api_display_tool_title($tool_name);
  92. if (isset($_GET['action']) && $_GET['action'] == 'show_message')
  93. Display :: display_normal_message(Security::remove_XSS(stripslashes($_GET['message'])));
  94. $no_course_list = $course_list = array();
  95. $ajax_search = $add_type == 'unique' ? true : false;
  96. if($ajax_search) {
  97. $courses=UrlManager::get_url_rel_course_data($access_url_id);
  98. foreach($courses as $course) {
  99. $course_list[$course['course_code']] = $course ;
  100. }
  101. } else {
  102. $courses=UrlManager::get_url_rel_course_data();
  103. foreach($courses as $course) {
  104. if($course['access_url_id'] == $access_url_id) {
  105. $course_list[$course['course_code']] = $course ;
  106. }
  107. }
  108. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  109. $sql="SELECT code, title
  110. FROM $tbl_course u
  111. ORDER BY title, code";
  112. $result=Database::query($sql);
  113. $courses=Database::store_result($result);
  114. $course_list_leys = array_keys($course_list);
  115. foreach($courses as $course) {
  116. if (!in_array($course['code'],$course_list_leys))
  117. $no_course_list[$course['code']] = $course ;
  118. }
  119. }
  120. if($add_type == 'multiple') {
  121. $link_add_type_unique = '<a href="'.api_get_self().'?add_type=unique&access_url_id='.$access_url_id.'">'.get_lang('SessionAddTypeUnique').'</a>';
  122. $link_add_type_multiple = get_lang('SessionAddTypeMultiple');
  123. } else {
  124. $link_add_type_unique = get_lang('SessionAddTypeUnique');
  125. $link_add_type_multiple = '<a href="'.api_get_self().'?add_type=multiple&access_url_id='.$access_url_id.'">'.get_lang('SessionAddTypeMultiple').'</a>';
  126. }
  127. $url_list = UrlManager::get_url_data();
  128. ?>
  129. <div style="text-align: left;">
  130. <?php echo $link_add_type_unique ?>&nbsp;|&nbsp;<?php echo $link_add_type_multiple ?>
  131. </div>
  132. <br /><br />
  133. <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;" <?php if($ajax_search){echo ' onsubmit="valide();"';}?> >
  134. <?php echo get_lang('SelectUrl').' : '; ?>
  135. <select name="access_url_id" onchange="javascript:send();">
  136. <option value="0">-- <?php echo get_lang('SelectUrl')?> -- </option>
  137. <?php
  138. $url_selected='';
  139. foreach ($url_list as $url_obj) {
  140. $checked = '';
  141. if (!empty($access_url_id)) {
  142. if ($url_obj[0]==$access_url_id) {
  143. $checked = 'selected=true';
  144. $url_selected=$url_obj[1];
  145. }
  146. }
  147. if ($url_obj['active']==1) {
  148. ?>
  149. <option <?php echo $checked;?> value="<?php echo $url_obj[0]; ?>"> <?php echo $url_obj[1]; ?></option>
  150. <?php
  151. }
  152. }
  153. ?>
  154. </select>
  155. <br /><br />
  156. <input type="hidden" name="form_sent" value="1" />
  157. <input type="hidden" name="add_type" value = "<?php echo $add_type ?>" />
  158. <?php
  159. if(!empty($errorMsg)) {
  160. Display::display_normal_message($errorMsg); //main API
  161. }
  162. ?>
  163. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  164. <!-- Users -->
  165. <tr>
  166. <td align="center"><b><?php echo get_lang('CourseListInPlatform') ?> :</b>
  167. </td>
  168. <td></td>
  169. <td align="center"><b><?php echo get_lang('CourseListIn').' '.$url_selected; ?></b></td>
  170. </tr>
  171. <tr>
  172. <td align="center">
  173. <div id="content_source">
  174. <?php
  175. if($ajax_search) {
  176. ?>
  177. <input type="text" id="course_to_add" onkeyup="xajax_search_courses(this.value,document.formulaire.access_url_id.options[document.formulaire.access_url_id.selectedIndex].value)" />
  178. <div id="ajax_list_courses"></div>
  179. <?php
  180. } else {
  181. ?>
  182. <select id="origin_users" name="no_course_list[]" multiple="multiple" size="15" style="width:380px;">
  183. <?php
  184. foreach($no_course_list as $no_course) {
  185. ?>
  186. <option value="<?php echo $no_course['code']; ?>"><?php echo $no_course['title'].' ('.$no_course['code'].')'; ?></option>
  187. <?php
  188. }
  189. unset($no_course_list);
  190. ?>
  191. </select>
  192. <?php
  193. }
  194. ?>
  195. </div>
  196. </td>
  197. <td width="10%" valign="middle" align="center">
  198. <?php
  199. if($ajax_search) {
  200. ?>
  201. <button class="arrowl" type="button" onclick="remove_item(document.getElementById('destination_users'))" ></button>
  202. <?php
  203. } else {
  204. ?>
  205. <button class="arrowr" type="button" onclick="moveItem(document.getElementById('origin_users'), document.getElementById('destination_users'))" ></button>
  206. <br /><br />
  207. <button class="arrowl" type="button" onclick="moveItem(document.getElementById('destination_users'), document.getElementById('origin_users'))" ></button>
  208. <?php
  209. }
  210. ?>
  211. <br /><br /><br /><br /><br /><br />
  212. </td>
  213. <td align="center">
  214. <select id="destination_users" name="course_list[]" multiple="multiple" size="15" style="width:380px;">
  215. <?php
  216. foreach($course_list as $course) {
  217. ?>
  218. <option value="<?php echo $course['course_code']; ?>"><?php echo $course['title'].' ('.$course['course_code'].')'; ?></option>
  219. <?php
  220. }
  221. unset($course_list);
  222. ?>
  223. </select></td>
  224. </tr>
  225. <tr>
  226. <td colspan="3" align="center">
  227. <br />
  228. <?php
  229. if(isset($_GET['add']))
  230. echo '<button class="save" onclick="valide()" >'.get_lang('AddCoursesToURL').'</button>';
  231. else
  232. echo '<button class="save" onclick="valide()" >'.get_lang('EditCoursesToURL').'</button>';
  233. ?>
  234. </td>
  235. </tr>
  236. </table>
  237. </form>
  238. <script type="text/javascript">
  239. function moveItem(origin , destination) {
  240. for(var i = 0 ; i<origin.options.length ; i++) {
  241. if(origin.options[i].selected) {
  242. destination.options[destination.length] = new Option(origin.options[i].text,origin.options[i].value);
  243. origin.options[i]=null;
  244. i = i-1;
  245. }
  246. }
  247. destination.selectedIndex = -1;
  248. sortOptions(destination.options);
  249. }
  250. function sortOptions(options) {
  251. newOptions = new Array();
  252. for (i = 0 ; i<options.length ; i++)
  253. newOptions[i] = options[i];
  254. newOptions = newOptions.sort(mysort);
  255. options.length = 0;
  256. for(i = 0 ; i < newOptions.length ; i++)
  257. options[i] = newOptions[i];
  258. }
  259. function mysort(a, b) {
  260. if (a.text.toLowerCase() > b.text.toLowerCase()) {
  261. return 1;
  262. }
  263. if (a.text.toLowerCase() < b.text.toLowerCase()) {
  264. return -1;
  265. }
  266. return 0;
  267. }
  268. function valide(){
  269. var options = document.getElementById('destination_users').options;
  270. for (i = 0 ; i<options.length ; i++)
  271. options[i].selected = true;
  272. document.forms.formulaire.submit();
  273. }
  274. function loadUsersInSelect(select) {
  275. var xhr_object = null;
  276. if(window.XMLHttpRequest) // Firefox
  277. xhr_object = new XMLHttpRequest();
  278. else if(window.ActiveXObject) // Internet Explorer
  279. xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
  280. else // XMLHttpRequest non supporté par le navigateur
  281. alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
  282. xhr_object.open("POST", "loadUsersInSelect.ajax.php");
  283. xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  284. nosessionUsers = makepost(document.getElementById('origin_users'));
  285. sessionUsers = makepost(document.getElementById('destination_users'));
  286. nosessionClasses = makepost(document.getElementById('origin_classes'));
  287. sessionClasses = makepost(document.getElementById('destination_classes'));
  288. xhr_object.send("nosessionusers="+nosessionUsers+"&sessionusers="+sessionUsers+"&nosessionclasses="+nosessionClasses+"&sessionclasses="+sessionClasses);
  289. xhr_object.onreadystatechange = function() {
  290. if(xhr_object.readyState == 4) {
  291. document.getElementById('content_source').innerHTML = result = xhr_object.responseText;
  292. //alert(xhr_object.responseText);
  293. }
  294. }
  295. }
  296. function makepost(select){
  297. var options = select.options;
  298. var ret = "";
  299. for (i = 0 ; i<options.length ; i++)
  300. ret = ret + options[i].value +'::'+options[i].text+";;";
  301. return ret;
  302. }
  303. </script>
  304. <?php
  305. Display::display_footer();