Dokeos PHP Cross Reference Learning Management Systems

Source: /main/admin/ldap_import_students_to_session.php - 216 lines - 7059 bytes - Summary - Text - Print

   1  <?php
   2  /* For licensing terms, see /dokeos_license.txt */
   3  
   4  /**
   5  * @package dokeos.admin
   6  */
   7  
   8  // name of the language file that needs to be included
   9  $language_file[]='admin';
  10  $language_file[]='registration';
  11  // resetting the course id
  12  $cidReset=true;
  13  require_once ('../inc/global.inc.php');
  14  // setting the section (for the tabs)
  15  $this_section = SECTION_PLATFORM_ADMIN;
  16  require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
  17  require_once(api_get_path(LIBRARY_PATH).'usermanager.lib.php');
  18  // Access restrictions
  19  api_protect_admin_script();
  20  require_once ('../auth/ldap/authldap.php');
  21  //ldap_get_fields();
  22  $annee_base=date('Y');
  23  
  24  $tool_name = get_lang('LDAPImport');
  25  // setting breadcrumbs
  26  $interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
  27  
  28  $htmlHeadXtra[] = '<script language="JavaScript" type="text/javascript">
  29  var buttoncheck = 1;
  30  function checkAll() {
  31      //var boxes = document.form.elements[\'checkboxes[]\'];
  32      var boxes = document.getElementsByName(\'checkboxes[]\');
  33      if (buttoncheck == 0) {
  34          for (i = 0; i < boxes.length; i++) {
  35              boxes[i].checked = true;
  36          }
  37          buttoncheck = 1;
  38          return "'.get_lang('None').'";
  39      }
  40      else {
  41          for (i = 0; i < boxes.length; i++) {
  42              boxes[i].checked = false;
  43          }
  44          buttoncheck = 0;
  45          return " '.get_lang('All').' ";
  46      }
  47  }
  48  </script>';
  49  
  50  $annee = $_GET['annee'];
  51  $id_session = $_POST['id_session'];
  52  
  53  
  54  // form1 annee = 0; composante= 0 etape = 0
  55  //if ($annee == "" && $composante == "" && $etape == "") {
  56  if (empty($annee) && empty($id_session))
  57  {
  58          Display::display_header($tool_name);
  59          echo '<div style="align:center">';
  60          echo Display::return_icon('group.gif', get_lang('LDAPSelectFilterOnUsersOU')).' '.get_lang('LDAPSelectFilterOnUsersOU');
  61          echo '<form method="get" action="'.api_get_self().'"><br />';
  62          echo '<em>'.get_lang('LDAPOUAttributeFilter').' :</em> ';
  63          echo '<input  type="text" name="annee" size="4" maxlength="30" value="'.$annee_base.'"> ';
  64          echo '<input type="submit" value="'.get_lang('Submit').'">';
  65          echo '</form>';
  66          echo '</div>';
  67  
  68  }
  69  elseif(!empty($annee) && empty($id_session))
  70  {
  71      Display::display_header($tool_name);
  72      echo '<div style="align:center">';
  73      echo Display::return_icon('course22.png', get_lang('SelectSessionToImportUsersTo')).' '.get_lang('SelectSessionToImportUsersTo').'<br />';
  74      echo '<form method="post" action="'.api_get_self().'?annee='.Security::remove_XSS($annee).'"><br />';
  75      echo '<select name="id_session">';
  76  
  77      $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  78      $sql = "SELECT id,name,nbr_courses,date_start,date_end " .
  79          " FROM $tbl_session ".
  80          " ORDER BY name";
  81      $result = Database::query($sql,__FILE__,__LINE__);
  82  
  83      $sessions=Database::store_result($result);
  84      $nbr_results=count($sessions);
  85      foreach($sessions as $row)
  86      {
  87          echo '<option value="'.$row['id'].'">'.api_htmlentities($row['name'], ENT_COMPAT, api_get_system_encoding()).' ('.$row['date_start'].' - '.$row['date_end'].')</option>';
  88      }
  89      echo '</select>';
  90      echo '<input type="submit" value="'.get_lang('Submit').'">';
  91      echo '</form>';
  92      echo '</div>';
  93  }
  94  // form4  annee != 0; composante != 0 etape != 0
  95  //elseif ($annee <> "" && $composante <> "" && $etape <> "" && $listeok != 'yes') {
  96  elseif (!empty($annee) && !empty($id_session) && empty($_POST['confirmed']))
  97  {
  98      Display::display_header($tool_name);
  99      echo '<div style="align: center;">';
 100      echo '<br />';
 101      echo '<br />';
 102      echo '<h3>'.Display::return_icon('group.gif', get_lang('SelectStudents')).' '.get_lang('SelectStudents').'</h3>';
 103      //echo "Connection ...";
 104      $ds = ldap_connect($ldap_host, $ldap_port) or die(get_lang('LDAPConnectionError'));
 105      ldap_set_version($ds);
 106  
 107      if ($ds) {
 108  
 109          $r = false;
 110          $res = ldap_handle_bind($ds, $r);
 111  
 112          //$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))");
 113          //echo "(ou=*$annee,ou=$composante)";
 114          $sr = @ ldap_search($ds, $ldap_basedn, "(ou=*$annee)");
 115  
 116          $info = ldap_get_entries($ds, $sr);
 117  
 118          for ($key = 0; $key < $info["count"]; $key ++) {
 119              $nom_form[] = $info[$key]["sn"][0];//api_utf8_decode($info[$key]["sn"][0], api_get_setting('platform_charset'));
 120              $prenom_form[] = $info[$key]["givenname"][0];//api_utf8_decode($info[$key]["givenname"][0], api_get_setting('platform_charset'));
 121              $email_form[] = $info[$key]["mail"][0];
 122              // Get uid from dn
 123              //$dn_array=ldap_explode_dn($info[$key]["dn"],1);
 124              //$username_form[] = $dn_array[0]; // uid is first key
 125              $username_form[] = $info[$key]['uid'][0];
 126              $outab[] = $info[$key]["eduPersonPrimaryAffiliation"][0]; // Ici "student"
 127              //$val = ldap_get_values_len($ds, $entry, "userPassword");
 128              //$password_form[] = $val[0];
 129              $password_form[] = $info[$key]['userPassword'][0];
 130          }
 131          ldap_unbind($ds);
 132  
 133          /*-----------------------------------------------*/
 134  
 135          asort($nom_form);
 136          reset($nom_form);
 137  
 138          $statut=5;
 139          include  ('ldap_form_add_users_group.php');
 140      } else {
 141          echo '<h4>'.get_lang('UnableToConnectTo').' '.$host.'</h4>';
 142      }
 143      echo '<br /><br />';
 144      echo '<a href="ldap_import_students.php?annee=">'.get_lang('BackToNewSearch').'</a>';
 145      echo '<br /><br />';
 146      echo '</div>';
 147  
 148  }
 149  elseif (!empty($annee) && !empty($id_session) && ($_POST['confirmed']=='yes'))
 150  {
 151      $id=$_POST['username_form'];
 152      $UserList=array();
 153      $userid_match_login = array();
 154      foreach ($id as $form_index=>$user_id)
 155      {
 156          if(is_array($_POST['checkboxes']) && in_array($form_index,array_values($_POST['checkboxes'])))
 157          {
 158              $tmp = ldap_add_user($user_id);
 159              $UserList[]= $tmp;
 160              $userid_match_login[$tmp] = $user_id;
 161          }
 162      }
 163      if (!empty($_POST['id_session']))
 164      {
 165          $num = 0;
 166          $tbl_session_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
 167          $tbl_session      = Database::get_main_table(TABLE_MAIN_SESSION);
 168          foreach($UserList as $user_id)
 169          {
 170              $sql = 'INSERT INTO '.$tbl_session_user.' SET
 171                      id_user="'.intval($user_id).'",
 172                      id_session = "'.intval($id_session).'"';
 173              $res_user = Database::query($sql,__FILE__,__LINE__);
 174              if($res_user != false)
 175              {
 176                  $num++;
 177              }
 178          }
 179          if($num>0)
 180          {
 181              $sql = 'UPDATE '.$tbl_session.' SET nbr_users = (nbr_users + '.$num.') WHERE id = '.intval($id_session);
 182              $res = Database::query($sql,__FILE__,__LINE__);
 183          }
 184          header('Location: resume_session.php?id_session='.Security::remove_XSS($_POST['id_session']));
 185      }
 186      /*
 187      else
 188      {
 189          Display :: display_header($tool_name);
 190          if(count($userid_match_login)>0)
 191          {
 192              $message=get_lang('LDAPUsersAddedOrUpdated').':<br />';
 193              foreach($userid_match_login as $user_id => $login)
 194              {
 195                  $message .= '- '.$login.'<br />';
 196              }
 197          }
 198          else
 199          {
 200              $message=get_lang('NoUserAdded');
 201          }
 202          Display :: display_normal_message($message,false);
 203      }
 204      */
 205      else
 206      {
 207          Display::display_header($tool_name);
 208          $message=get_lang('NoUserAdded');
 209          Display :: display_normal_message($message,false);
 210      }
 211      echo '<br /><br />';
 212      echo '<a href="ldap_import_students.php?annee=&composante=&etape=">'.get_lang('BackToNewSearch').'</a>';
 213      echo '<br /><br />';
 214  }
 215  Display::display_footer();
 216  ?>

title

Description

title

Description

title

Description

title

title

Body