Пример #1
0
  /**
   * Méthode pour envoyer une requête à l'annuaire
   * Retourne un tableau avec les infos ou une chaine d'erreur ou stoppe (exit).
   *
   * Pour [api] valeurs [ profs | eleves | parents ] prévues mais pas présentes.
   * Pour [api] valeurs [ classes | groupes ] n'apportent aucune informations intéressante supplémentaire.
   *
   * @param string $uai
   * @param string $api   '' | matieres | users
   * @param bool   $exit_if_error
   * @param bool   $with_details   Retourne la même chose sauf pour [api=''] qui ne renvoie que les infos sur l'établissement si [with_details=FALSE]
   * @return array
   */

  public static function get_info_from_annuaire($uai,$api,$exit_if_error,$with_details)
  {
    $annuaire_adresse   = ($api) ? Laclasse::ANNUAIRE_API_ETAB.$uai.'/'.$api : Laclasse::ANNUAIRE_API_ETAB.$uai ;
    $annuaire_tab_param = ($with_details) ? array('expand' => 'true') : array() ;

    $json_reponse = cURL::get_contents( Laclasse::generer_url_appel( $annuaire_adresse , $annuaire_tab_param ) );

    if(substr($json_reponse,0,6)=='Erreur')
    {
      // On récupère par exemple 
      // "Erreur : The requested URL returned error: 401 Unauthorized" si UAI étranger
      // "Erreur : The requested URL returned error: 404 Not Found"    si UAI inconnu
      if($exit_if_error)
      {
        exit( json_encode( array( 'error' => $uai.' '.$api.' - '.$json_reponse ) ) );
      }
      else
      {
        return $uai.' '.$api.' - '.$json_reponse;
      }
    }

    $tab_reponse = json_decode($json_reponse,TRUE);

    if($tab_reponse===NULL)
    {
      if($exit_if_error)
      {
        exit( json_encode( array( 'error' => $uai.' '.$api.' - Chaîne JSON incorrecte : '.$json_reponse ) ) );
      }
      else
      {
        return $uai.' '.$api.' - Chaîne JSON incorrecte : '.$json_reponse;
      }
    }
    elseif(isset($tab_reponse['error']))
    {
      // On récupère par exemple {"error":"Non authentifié"} si API non reconnue ou clef d'API incorrecte
      if($exit_if_error)
      {
        exit($json_reponse);
      }
      else
      {
        return $uai.' '.$api.' - Erreur réponse annuaire : '.$json_reponse;
      }
    }

    return $tab_reponse;
  }
Пример #2
0
      $id = Clean::entier($tab_infos['id']);
      $matiere_id      = ($id%100==0) ? $id/100 : NULL ;
      $matiere_libelle = Clean::texte($tab_infos['libelle_long']);
      $tab_matieres[$id] = array(
        'matiere_id'      => $matiere_id,
        'matiere_libelle' => $matiere_libelle,
      );
    }
  }
}

/****************************************************************************************************
 * Récupérer les adresses mails des personnels et les affectations aux classes / groupes.
 ****************************************************************************************************/

$tab_annuaire = Laclasse::get_info_from_annuaire( $WS_uai , 'users' , TRUE /*exit_if_error*/ , TRUE /*with_details*/ );
if(!empty($tab_annuaire['data']))
{
  foreach($tab_annuaire['data'] as $tab_infos)
  {
    $user_id = Clean::entier($tab_infos['id']);
    // Cas d'un personnel : on ajoute login et email
    if(isset($tab_personnels[$user_id]))
    {
      $tab_personnels[$user_id]['login'] = Clean::lower($tab_infos['login']);
      $tab_personnels[$user_id]['email'] = Clean::courriel($tab_infos['emails'][0]['adresse']);
      // Cas d'un prof : on ajoute classes et groupes
      if( ($tab_personnels[$user_id]['profil']=='ENS') && (!empty($tab_infos['enseigne_regroupements'])) )
      {
        foreach($tab_infos['enseigne_regroupements'] as $tab_infos_groupe)
        {
Пример #3
0
/**
 * recuperer_infos_Laclasse
 * 
 * @param string   $UAI
 * @return array|string
 */
function recuperer_infos_Laclasse($UAI)
{
  // Appeler l'annuaire ENT Laclasse.com
  $tab_Laclasse = Laclasse::get_info_from_annuaire( $UAI , '' , FALSE /*exit_if_error*/ , TRUE /*with_details*/ );
  // Enregistrer la réponse pour aider au débuggage si besoin
  FileSystem::ecrire_fichier( CHEMIN_DOSSIER_IMPORT.'Laclasse_'.$UAI.'_recup_IdEnt_'.fabriquer_fin_nom_fichier__date_et_alea().'.txt' , print_r($tab_Laclasse,TRUE) );
  // On examine la réponse
  if(!is_array($tab_Laclasse))
  {
    exit($tab_Laclasse);
  }
  // Pour récupérer les données des utilisateurs
  $tab_users_annuaire              = array();
  $tab_users_annuaire['ordre']     = array();
  $tab_users_annuaire['profil']    = array();
  $tab_users_annuaire['id_ent']    = array();
  $tab_users_annuaire['nom']       = array();
  $tab_users_annuaire['prenom']    = array();
  $tab_users_annuaire['id_sconet'] = array(); // Ne servira que pour les élèves
  if(!empty($tab_Laclasse['personnel']))
  {
    foreach($tab_Laclasse['personnel'] as $tab_infos)
    {
      $user_profil = NULL;
      if( in_array( $tab_infos['profil_id'] , array('DIR','DOC','ENS') ) )
      {
        // Personnels de direction, enseignants y compris professeur documentaliste
        $ordre = 1;
        $user_profil = $tab_infos['profil_id'];
      }
      else if($tab_infos['profil_id']=='ETA')
      {
        if($tab_infos['libelle']=='EDUCATION')
        {
          // CPE
          $ordre = 1;
          $user_profil = 'EDU';
        }
        elseif($tab_infos['description']=='ENCADRE. SUR. DES ELEVES (HORS INTERNAT)')
        {
          // Surveillants
          $ordre = 4;
          $user_profil = 'SUR';
        }
        elseif($tab_infos['libelle']=='ASSISTANT D\'EDUCATION')
        {
          // AED
          $ordre = 4;
          $user_profil = 'AED';
        }
        elseif($tab_infos['libelle']=='ORIENTATION')
        {
          // Co-Psy
          $ordre = 4;
          $user_profil = 'ORI';
        }
        elseif($tab_infos['libelle']=='PERSONNELS ADMINISTRATIFS')
        {
          // Personnels administratifs
          $ordre = 4;
          $user_profil = 'ADF';
        }
      }
      else if($tab_infos['profil_id']=='EVS')
      {
        // Personnels medico-sociaux
        $ordre = 4;
        $user_profil = 'MDS';
      }
      if($user_profil)
      {
        $tab_users_annuaire['ordre'    ][] = $ordre;
        $tab_users_annuaire['profil'   ][] = $user_profil;
        $tab_users_annuaire['id_ent'   ][] = Clean::id_ent($tab_infos['id_ent']);
        $tab_users_annuaire['nom'      ][] = Clean::nom($tab_infos['nom']);
        $tab_users_annuaire['prenom'   ][] = Clean::prenom($tab_infos['prenom']);
        $tab_users_annuaire['id_sconet'][] = NULL;
      }
    }
  }
  // Les élèves
  if(!empty($tab_Laclasse['eleves']))
  {
    foreach($tab_Laclasse['eleves'] as $tab_infos)
    {
      $tab_users_annuaire['ordre'    ][] = 2;
      $tab_users_annuaire['profil'   ][] = 'ELV';
      $tab_users_annuaire['id_ent'   ][] = Clean::id_ent($tab_infos['id_ent']);
      $tab_users_annuaire['nom'      ][] = Clean::nom($tab_infos['nom']);
      $tab_users_annuaire['prenom'   ][] = Clean::prenom($tab_infos['prenom']);
      $tab_users_annuaire['id_sconet'][] = Clean::entier($tab_infos['id_sconet']);
    }
  }
  // Les parents
  if(!empty($tab_Laclasse['parents']))
  {
    foreach($tab_Laclasse['parents'] as $tab_infos)
    {
      $tab_users_annuaire['ordre'    ][] = 3;
      $tab_users_annuaire['profil'   ][] = 'TUT';
      $tab_users_annuaire['id_ent'   ][] = Clean::id_ent($tab_infos['id_ent']);
      $tab_users_annuaire['nom'      ][] = Clean::nom($tab_infos['nom']);
      $tab_users_annuaire['prenom'   ][] = Clean::prenom($tab_infos['prenom']);
      $tab_users_annuaire['id_sconet'][] = NULL;
    }
  }
  // On trie
  array_multisort(
    $tab_users_annuaire['ordre'] , SORT_ASC,SORT_NUMERIC,
    $tab_users_annuaire['profil'], SORT_ASC,SORT_STRING,
    $tab_users_annuaire['nom']   , SORT_ASC,SORT_STRING,
    $tab_users_annuaire['prenom'], SORT_ASC,SORT_STRING,
    $tab_users_annuaire['id_ent'],
    $tab_users_annuaire['id_sconet']
  );
  // On retire l'ordre dont on n'a plus besoin
  unset($tab_users_annuaire['ordre']);
  // On retourne le tableau
  return $tab_users_annuaire;
}