ldap_import_students.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <?php //$id: $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2008 Dokeos SPRL
  6. Copyright (c) 2007 Mustapha Alouani (supervised by Michel Moreau-Belliard)
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium, info@dokeos.com
  15. ==============================================================================
  16. */
  17. // name of the language file that needs to be included
  18. $language_file[]='admin';
  19. $language_file[]='registration';
  20. require_once('../inc/global.inc.php');
  21. // resetting the course id
  22. $cidReset=true;
  23. // setting the section (for the tabs)
  24. $this_section = SECTION_PLATFORM_ADMIN;
  25. // Access restrictions
  26. api_protect_admin_script();
  27. require('../auth/ldap/authldap.php');
  28. $annee_base=date('Y');
  29. $tool_name = get_lang('LDAPImport');
  30. // setting breadcrumbs
  31. $interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
  32. $htmlHeadXtra[] = '<script language="JavaScript" type="text/javascript">
  33. var buttoncheck = "false";
  34. function checkAll() {
  35. var boxes = document.form.elements[\'checkboxes[]\'];
  36. if (buttoncheck == "false") {
  37. for (i = 0; i < boxes.length; i++) {
  38. boxes[i].checked = true;
  39. }
  40. buttoncheck = "true";
  41. return "'.get_lang('None').'";
  42. }
  43. else {
  44. for (i = 0; i < boxes.length; i++) {
  45. boxes[i].checked = false;
  46. }
  47. buttoncheck = "false";
  48. return " '.get_lang('All').' ";
  49. }
  50. }
  51. </script>';
  52. Display::display_header($tool_name);
  53. $annee = $_GET['annee'];
  54. $composante = $_GET['composante'];
  55. $etape = $_GET['etape'];
  56. // form1 annee = 0; composante= 0 etape = 0
  57. if ($annee == "" && $composante == "" && $etape == "") {
  58. echo '<div style="align:center">';
  59. echo '<h3><img src="../img/group.gif" alt="'.get_lang('EnterStudentsToSubscribeToCourse').'" />'.get_lang('EnterStudentsToSubscribeToCourse').'</h3>';
  60. echo '<em>'.get_lang('ToDoThisYouMustEnterYearComponentAndComponentStep').'</b><br />';
  61. echo get_lang('FollowEachOfTheseStepsStepByStep').'<br />';
  62. echo '<form method="get" action="'.api_get_self().'"><br />';
  63. echo '<b>'.sprintf(get_lang('RegistrationYearExample'),date('Y'),date('Y'),date('Y')+1).' :</b> ';
  64. echo '<input type="text" name="annee" size="4" maxlength="30" value="'.$annee_base.'"><br />';
  65. echo '<input type="submit" value="'.get_lang('Submit').'">';
  66. echo '</form>';
  67. echo '</div>';
  68. }
  69. elseif ($annee <> "" && $composante == "" && $etape == "") // form 2 annee != 0; composante= 0 etape = 0
  70. {
  71. $ds = ldap_connect($ldap_host, $ldap_port) or die(get_lang('LDAPConnectionError'));
  72. ldap_set_version($ds);
  73. if ($ds) {
  74. $r = false;
  75. $res = ldap_handle_bind($ds, $r);
  76. //$sr = @ ldap_search($ds, "o=groups,$ldap_basedn", "(&(description=etape*)(cn=*$annee))", array ('cn'));
  77. //$sr = @ ldap_search($ds, "ou=$annee, ou=diploma, o=paris1, $ldap_basedn", "ou=02*", array ('description'));
  78. //$sr = @ ldap_search($ds, "ou=structures, o=paris1, $ldap_basedn", "businessCategory=pedagogy", array ('ou','description'));
  79. $sr = ldap_search($ds, "ou=test-ou, o=test-o, $ldap_basedn", "businessCategory=education", array ('ou','description'));
  80. // "ou=2006,ou=diploma,o=Paris1,dc=univ-paris1,dc=fr
  81. $info = ldap_get_entries($ds, $sr);
  82. $composante = array();
  83. for($i = 0; $i < $info['count']; $i ++)
  84. {
  85. //presupose LDAP server is UTF-8
  86. $composante[$info[$i]['ou'][0]] = iconv('utf-8', api_get_setting('platform_charset'), $info[$i]['description'][0]);
  87. }
  88. $oucompotab3=$composante;
  89. echo '<div style="align: center">';
  90. echo '<br />';
  91. echo '<h3><img src="../img/group.gif" alt="'.get_lang('SelectComponent').'" />'.get_lang('SelectComponent').'</h3>';
  92. echo '<form method="get" action="'.api_get_self().'">';
  93. echo '<b>'.get_lang('RegistrationYear').'</b> : ';
  94. echo '<input type="text" name="annee" size="4" maxlength="30" value="'.$annee.'">';
  95. echo '<b>'.get_lang('Component').' : </b> ';
  96. echo '<select name="composante" size="1">';
  97. while (list ($key, $val) = each($oucompotab3)) {
  98. echo '<option value="'.$key.'">'.$oucompotab3[$key].'</option>';
  99. }
  100. echo '</select>';
  101. echo '<br />';
  102. echo '<br />';
  103. echo '<input type="submit" name="valider" value="'.get_lang('Submit').'">';
  104. echo '</form>';
  105. ldap_close($ds);
  106. }
  107. echo '<br />';
  108. echo '<br />';
  109. echo '<br />';
  110. echo '<a href="ldap_import_students.php?annee=&composante=&etape=">'.get_lang('BackToNewSearch').'</a>';
  111. echo '<br />';
  112. echo '</div>';
  113. }
  114. elseif ($annee <> "" && $composante <> "" && $etape == "") // form3 :annee!=0composante=0etape=0
  115. {
  116. echo '<div style="align: center">';
  117. echo '<h3><img src="../img/group.gif" alt="'.get_lang('SearchResults').'" />'.get_lang('SearchResults').'</h3>';
  118. $ds = ldap_connect($ldap_host, $ldap_port);
  119. ldap_set_version($ds);
  120. if ($ds) {
  121. $r = false;
  122. $res = ldap_handle_bind($ds, $r);
  123. // $sr = @ ldap_search($ds, "ou=groups, $LDAPbasedn", "(&(cn=*$annee*)(cn=*$composante*))");
  124. $sr = @ ldap_search($ds, "ou=$annee, ou=diploma, $ldap_basedn", "seeAlso=ou=$composante,ou=structures,$ldap_basedn", array ('ou','description'));
  125. //echo "Le nombre de resultats est : ".ldap_count_entries($ds,$sr)."<p>";
  126. $info = ldap_get_entries($ds, $sr);
  127. for ($i = 0; $i <= $info['count']; $i ++) {
  128. $description = $info[$i]['description'];
  129. $ouetapetab[$i] = $description[0];
  130. $description2 = $info[$i]['ou'];
  131. $ouetapetab2[$i] = $description2[0];
  132. }
  133. asort($ouetapetab);
  134. reset($ouetapetab);
  135. echo '<form method="get" action="'.api_get_self().'">';
  136. echo '<b>'.get_lang('RegistrationYear').':</b><input type="text" name="annee" size="4" maxlength="30" value="'.$annee.'">';
  137. echo '<br /><br />';
  138. echo '<b>'.get_lang('Component').' :</b><input type="text" name="composante" size="4" maxlength="30" value="'.$composante.'">';
  139. echo '<br />';
  140. echo '<h4>'.get_lang('SelectStepAcademicYear').'</h4>';
  141. echo '<br />';
  142. echo '<b>'.get_lang('Step').': </b>';
  143. echo '<select name="etape" size="1">';
  144. $tempcomp = "";
  145. while (list ($key, $val) = each($ouetapetab)) {
  146. if ($ouetapetab[$key] != $tempcomp) {
  147. $etape = $ouetapetab2[$key];
  148. $tempcomp = '"'.$ouetapetab[$key].'"';
  149. $tempcomp = iconv('utf-8',api_get_setting('platform_charset'),$tempcomp);
  150. $annee = str_word_count($etape, 1);
  151. echo '<option value="'.$etape.'">'.$tempcomp.'</option>';
  152. }
  153. }
  154. echo '</select>';
  155. echo '<input type="hidden" name="displayname" value="'.$displayname.'">';
  156. echo '<br />';
  157. echo '<input type="submit" name="envoi" value="'.get_lang('Submit').'">';
  158. echo '</form>';
  159. ldap_close($ds);
  160. } else {
  161. // echo "<h4>Unable to connect to LDAP server</h4>";
  162. }
  163. echo '<br />';
  164. echo '<br />';
  165. echo '<a href="ldap_import_students.php?annee=&composante=&etape=">'.get_lang('BackToNewSearch').'</a>';
  166. echo '</div>';
  167. }
  168. // form4 annee != 0; composante != 0 etape != 0
  169. elseif ($annee <> "" && $composante <> "" && $etape <> "" && $listeok != yes) {
  170. echo '<div style="align: center;">';
  171. echo '<br />';
  172. echo '<br />';
  173. echo '<h3><img src="../img/group.gif" alt="'.get_lang('SelectStudents').'" />'.get_lang('SelectStudents').'</h3>';
  174. //echo "Connection ...";
  175. $ds = ldap_connect($ldap_host, $ldap_port) or die(get_lang('LDAPConnectionError'));
  176. ldap_set_version($ds);
  177. if ($ds) {
  178. $r = false;
  179. $res = ldap_handle_bind($ds, $r);
  180. //$sr = @ ldap_search($ds, "ou=people,$LDAPbasedn", "(|(edupersonprimaryorgunitdn=ou=$etape,ou=$annee,ou=diploma,o=Paris1,$LDAPbasedn)(edupersonprimaryorgunitdn=ou=02PEL,ou=$annee,ou=diploma,o=Paris1,$LDAPbasedn))");
  181. $sr = @ ldap_search($ds, "ou=people,$ldap_basedn", "edupersonprimaryorgunitdn=ou=$etape,ou=$annee,ou=diploma,$ldap_basedn");
  182. $info = ldap_get_entries($ds, $sr);
  183. for ($key = 0; $key < $info["count"]; $key ++) {
  184. $nom_form[] = $info[$key]["sn"][0];//iconv("utf-8",api_get_setting('platform_charset'), $info[$key]["sn"][0]);
  185. $prenom_form[] = $info[$key]["givenname"][0];//iconv("utf-8",api_get_setting('platform_charset'), $info[$key]["givenname"][0]);
  186. $email_form[] = $info[$key]["mail"][0];
  187. // Get uid from dn
  188. $dn_array=ldap_explode_dn($info[$key]["dn"],1);
  189. $username_form[] = $dn_array[0]; // uid is first key
  190. $outab[] = $info[$key]["eduPersonPrimaryAffiliation"][0]; // Ici "student"
  191. $val = ldap_get_values_len($ds, $entry, "userPassword");
  192. $password_form[] = $val[0];
  193. }
  194. /*-----------------------------------------------*/
  195. asort($nom_form);
  196. reset($nom_form);
  197. $statut=5;
  198. ldap_close($ds);
  199. include ('ldap_form_add_users_group.php');
  200. ldap_unbind($ds);
  201. } else {
  202. echo '<h4>'.get_lang('UnableToConnectTo').' '.$host.'</h4>';
  203. }
  204. echo '<br /><br />';
  205. echo '<a href="ldap_import_students.php?annee=&composante=&etape=">'.get_lang('BackToNewSearch').'</a>';
  206. echo '<br /><br />';
  207. echo '</div>';
  208. }
  209. Display::display_footer();
  210. ?>