/**
  * Appel au serveur communautaire pour envoyer un fichier uploadé par un utilisateur.
  * 
  * @param int       $sesamath_id
  * @param string    $sesamath_key
  * @param string    $matiere_ref
  * @param string    $fichier_nom
  * @param string    $fichier_contenu
  * @return string   url du fichier ou un message d'erreur
  */
 public static function uploader_ressource($sesamath_id,$sesamath_key,$matiere_ref,$fichier_nom,$fichier_contenu)
 {
   $tab_post = array();
   $tab_post['fichier']         = 'ressource_uploader';
   $tab_post['sesamath_id']     = $sesamath_id;
   $tab_post['sesamath_key']    = $sesamath_key;
   $tab_post['matiere_ref']     = $matiere_ref;
   $tab_post['fichier_nom']     = $fichier_nom;
   $tab_post['fichier_contenu'] = base64_encode($fichier_contenu);
   $tab_post['version_prog']    = VERSION_PROG; // Le service web doit être compatible
   $tab_post['adresse_retour']  = URL_INSTALL_SACOCHE;
   $tab_post['integrite_key']   = ServeurCommunautaire::fabriquer_chaine_integrite();
   return cURL::get_contents( SERVEUR_COMMUNAUTAIRE ,$tab_post , 30 /*timeout*/ );
 }
Pour uploader une ressource directement sur le serveur communautaire, le fichier "professeur_referentiel_edition.php" devrait l'appeller dans une iframe (le bouton d'upload du formulaire devant se trouver sur ce serveur). Mais :
- une fois l'upload effectué, pour faire remonter l'info au serveur où est installé SACoche, se pose un souci de cross-domain javascript.
- il faudrait reproduire côté serveur communautaire tout un environnement (js & css) semblable à celui du serveur d'installation de SACoche
Finalement, j'ai opté pour le plus simple même si ce n'est pas le plus économe : uploader sur le serveur SACoche puis transférer vers le serveur communautaire avec cURL::get_contents().
Ca va qu'une limite de 500Ko est imposée...
*/

if($action=='Uploader_document')
{
  $result = FileSystem::recuperer_upload( CHEMIN_DOSSIER_IMPORT /*fichier_chemin*/ , NULL /*fichier_nom*/ , NULL /*tab_extensions_autorisees*/ , array('bat','com','exe','php','zip') /*tab_extensions_interdites*/ , 500 /*taille_maxi*/ , NULL /*filename_in_zip*/ );
  if($result!==TRUE)
  {
    exit($result);
  }
  $fichier_nom = Clean::fichier(FileSystem::$file_upload_name);
  $reponse = ServeurCommunautaire::uploader_ressource( $_SESSION['SESAMATH_ID'] , $_SESSION['SESAMATH_KEY'] , $_SESSION['tmp']['matiere_ref'] , $fichier_nom , file_get_contents(CHEMIN_DOSSIER_IMPORT.FileSystem::$file_saved_name) );
  FileSystem::supprimer_fichier(CHEMIN_DOSSIER_IMPORT.FileSystem::$file_saved_name);
  exit($reponse);
}

// ////////////////////////////////////////////////////////////////////////////////////////////////////
// Il se peut que rien n'ait été récupéré à cause de l'upload d'un fichier trop lourd
// ////////////////////////////////////////////////////////////////////////////////////////////////////

if(empty($_POST))
{
  exit('Erreur : aucune donnée reçue ! Fichier trop lourd ? '.InfoServeur::minimum_limitations_upload());
}

// ////////////////////////////////////////////////////////////////////////////////////////////////////
// On ne devrait pas en arriver là...
// ////////////////////////////////////////////////////////////////////////////////////////////////////
if ($action == 'Afficher_form_geo3' && $geo1 > 0 && $geo2 > 0) {
    exit(ServeurCommunautaire::Sesamath_afficher_formulaire_geo3($geo1, $geo2));
}
// ////////////////////////////////////////////////////////////////////////////////////////////////////
// Afficher le résultat de la recherche de structure, soit à partir du n°UAI soit à partir du code de commune
// ////////////////////////////////////////////////////////////////////////////////////////////////////
if ($action == 'Afficher_structures' && ($geo3 > 0 || $uai != '')) {
    echo $geo3 ? ServeurCommunautaire::Sesamath_lister_structures_by_commune($geo3) : ServeurCommunautaire::Sesamath_recuperer_structure_by_UAI($uai);
    exit;
}
// ////////////////////////////////////////////////////////////////////////////////////////////////////
// Mettre à jour les informations form_sesamath
// ////////////////////////////////////////////////////////////////////////////////////////////////////
if ($sesamath_id && $sesamath_type_nom && $sesamath_key) {
    $retour = ServeurCommunautaire::Sesamath_enregistrer_structure($sesamath_id, $sesamath_key);
    if ($retour != 'ok') {
        exit($retour);
    }
    // Si on arrive là, alors tout s'est bien passé.
    $tab_parametres = array();
    $tab_parametres['sesamath_id'] = $sesamath_id;
    $tab_parametres['sesamath_uai'] = $sesamath_uai;
    $tab_parametres['sesamath_type_nom'] = $sesamath_type_nom;
    $tab_parametres['sesamath_key'] = $sesamath_key;
    DB_STRUCTURE_COMMUN::DB_modifier_parametres($tab_parametres);
    // On modifie aussi la session
    $_SESSION['SESAMATH_ID'] = $sesamath_id;
    $_SESSION['SESAMATH_UAI'] = $sesamath_uai;
    $_SESSION['SESAMATH_TYPE_NOM'] = $sesamath_type_nom;
    $_SESSION['SESAMATH_KEY'] = $sesamath_key;
    $action = $referentiel_id ? 'a importé un nouveau référentiel' : 'a créé un nouveau référentiel vierge';
    $notification_contenu = date('d-m-Y H:i:s') . ' ' . $_SESSION['USER_PRENOM'] . ' ' . $_SESSION['USER_NOM'] . ' ' . $action . ' [' . $matiere_nom . '] [' . $niveau_nom . '].' . "\r\n";
    notifications_referentiel_edition($matiere_id, $notification_contenu);
    // Retour
    exit('ok');
}
// ////////////////////////////////////////////////////////////////////////////////////////////////////
// Supprimer un référentiel
// ////////////////////////////////////////////////////////////////////////////////////////////////////
if ($action == 'supprimer' && $matiere_id && $niveau_id && $partage && $matiere_nom && $niveau_nom) {
    // S'il était partagé, il faut le retirer du serveur communautaire
    if ($partage == 'oui') {
        if (!$_SESSION['SESAMATH_ID'] || !$_SESSION['SESAMATH_KEY']) {
            exit('Pour échanger avec le serveur communautaire, un administrateur doit identifier l\'établissement dans la base Sésamath.');
        }
        $reponse = ServeurCommunautaire::envoyer_arborescence_XML($_SESSION['SESAMATH_ID'], $_SESSION['SESAMATH_KEY'], $matiere_id, $niveau_id, '', $information);
        if ($reponse != 'ok') {
            exit($reponse);
        }
    }
    DB_STRUCTURE_REFERENTIEL::DB_supprimer_referentiel_matiere_niveau($matiere_id, $niveau_id);
    // Log de l'action
    SACocheLog::ajouter('Suppression du référentiel [' . $matiere_nom . '] [' . $niveau_nom . '].');
    // Notifications (rendues visibles ultérieurement)
    $notification_contenu = date('d-m-Y H:i:s') . ' ' . $_SESSION['USER_PRENOM'] . ' ' . $_SESSION['USER_NOM'] . ' a supprimé le référentiel [' . $matiere_nom . '] [' . $niveau_nom . '].' . "\r\n";
    notifications_referentiel_edition($matiere_id, $notification_contenu);
    DB_STRUCTURE_NOTIFICATION::enregistrer_action_sensible($notification_contenu);
    // Retour
    exit('ok');
}
// ////////////////////////////////////////////////////////////////////////////////////////////////////
Beispiel #5
0
 /**
  * Tester si mdp d'un développeur SACoche transmis convient.
  * On réutilise des éléments de la connexion webmestre.
  * 
  * @param string    $password
  * @return string   'ok' ou un message d'erreur
  */
 public static function tester_authentification_developpeur($password)
 {
   return ServeurCommunautaire::tester_auth_devel( crypter_mdp($password) );
 }
if($action=='Afficher_structures') // La vérification concernant le nombre de contraintes s'effectue après
{
  exit( ServeurCommunautaire::afficher_formulaire_structures_communautaires( $_SESSION['SESAMATH_ID'] , $_SESSION['SESAMATH_KEY'] ) );
}

// ////////////////////////////////////////////////////////////////////////////////////////////////////
// Lister les référentiels partagés trouvés selon les critères retenus (matière / niveau / structure)
// ////////////////////////////////////////////////////////////////////////////////////////////////////

if($action=='Lister_referentiels') // La vérification concernant le nombre de contraintes s'effectue après
{
  exit( ServeurCommunautaire::afficher_liste_referentiels( $_SESSION['SESAMATH_ID'] , $_SESSION['SESAMATH_KEY'] , $matiere_id , $niveau_id , $structure_id ) );
}

// ////////////////////////////////////////////////////////////////////////////////////////////////////
// Voir le contenu d'un référentiel partagé
// ////////////////////////////////////////////////////////////////////////////////////////////////////

if( ($action=='Voir_referentiel') && $referentiel_id )
{
  exit( ServeurCommunautaire::afficher_contenu_referentiel( $_SESSION['SESAMATH_ID'] , $_SESSION['SESAMATH_KEY'] , $referentiel_id ) );
}

// ////////////////////////////////////////////////////////////////////////////////////////////////////
// On en devrait pas en arriver là
// ////////////////////////////////////////////////////////////////////////////////////////////////////

exit('Erreur avec les données transmises !');

?>
         $xml.= '        </competence>'."\r\n";
       }
       $xml.= '      </palier>'."\r\n";
     }
     $xml.= '    </eleve>'."\r\n";
   }
 }
 $fichier_extension = ($action=='export_lpc') ? 'xml' : 'zip' ;
 $fichier_nom = str_replace('export_','import-',$action).'-'.Clean::fichier($_SESSION['WEBMESTRE_UAI']).'_'.fabriquer_fin_nom_fichier__date_et_alea().'.'.$fichier_extension; // LPC recommande le modèle "import-lpc-{timestamp}.xml"
 if($action=='export_lpc')
 {
   $xml.= '  </donnees>'."\r\n";
   $xml.= '</lpc>'."\r\n";
   // Pour LPC, ajouter la signature via un appel au serveur sécurisé
   $xml = utf8_decode($xml);
   $xml = ServeurCommunautaire::signer_exportLPC( $_SESSION['SESAMATH_ID'] , $_SESSION['SESAMATH_KEY'] , $xml ); // fonction sur le modèle de envoyer_arborescence_XML()
   if(substr($xml,0,5)!='<?xml')
   {
     exit(html($xml));
   }
   FileSystem::ecrire_fichier( CHEMIN_DOSSIER_EXPORT.$fichier_nom , $xml );
   $fichier_lien = './force_download.php?fichier='.$fichier_nom;
 }
 else
 {
   $xml.= '  </donnees>'."\r\n";
   $xml.= '</sacoche>'."\r\n";
   // L'export pour SACoche on peut le zipper (le gain est très significatif : facteur 40 à 50 !)
   FileSystem::zip( CHEMIN_DOSSIER_EXPORT.$fichier_nom , 'import_validations.xml' , $xml );
   $fichier_lien = URL_DIR_EXPORT.$fichier_nom;
 }
                 $xml .= '        </competence>' . "\r\n";
             }
             $xml .= '      </palier>' . "\r\n";
         }
         $xml .= '    </eleve>' . "\r\n";
     }
 }
 $fichier_extension = $action == 'export_lpc' ? 'xml' : 'zip';
 $fichier_nom = str_replace('export_', 'import-', $action) . '-' . Clean::fichier($_SESSION['WEBMESTRE_UAI']) . '_' . fabriquer_fin_nom_fichier__date_et_alea() . '.' . $fichier_extension;
 // LPC recommande le modèle "import-lpc-{timestamp}.xml"
 if ($action == 'export_lpc') {
     $xml .= '  </donnees>' . "\r\n";
     $xml .= '</lpc>' . "\r\n";
     // Pour LPC, ajouter la signature via un appel au serveur sécurisé
     $xml = utf8_decode($xml);
     $xml = ServeurCommunautaire::signer_exportLPC($_SESSION['SESAMATH_ID'], $_SESSION['SESAMATH_KEY'], $xml);
     // fonction sur le modèle de envoyer_arborescence_XML()
     if (substr($xml, 0, 5) != '<?xml') {
         exit(html($xml));
     }
     FileSystem::ecrire_fichier(CHEMIN_DOSSIER_EXPORT . $fichier_nom, $xml);
     $fichier_lien = './force_download.php?fichier=' . $fichier_nom;
 } else {
     $xml .= '  </donnees>' . "\r\n";
     $xml .= '</sacoche>' . "\r\n";
     // L'export pour SACoche on peut le zipper (le gain est très significatif : facteur 40 à 50 !)
     FileSystem::zip(CHEMIN_DOSSIER_EXPORT . $fichier_nom, 'import_validations.xml', $xml);
     $fichier_lien = URL_DIR_EXPORT . $fichier_nom;
 }
 // Afficher le retour
 $se = $nb_eleves > 1 ? 's' : '';