';
if(!empty($_POST) || !empty($_GET)){
$action = htmlspecialchars($_GET['action']);
if($action == 'ajouter'){
$this->saveFormation();
}else if($action == 'supprimer'){
$id = htmlspecialchars($_GET['id']);
$this->deleteFormation($id);
}
}
echo $this->displayList();
}
public function saveFormation(){
global $wpdb;
$nom = htmlspecialchars($_POST['nom']);
$file = preg_replace('/http:\/\/www.syntaxis.fr/', '', htmlspecialchars($_POST['fichier_zip']));
$path = pathinfo(realpath('../'.$file));
$zip = new ZipArchive();
$res = $zip->open($path['dirname'].'/'.$path['basename']);
if ($res === TRUE) {
//on vérifie que le répertoire d'upload du module existe
if(!is_dir($path['dirname'].'/../../pw-upload-formation')){
mkdir($path['dirname'].'/../../pw-upload-formation');
}
//création du répertoire pour extraire la formation
$randDirectory = md5(uniqid(rand(), true));
$fullPath = $path['dirname'].'/../../pw-upload-formation/'.$randDirectory;
mkdir($fullPath);
chmod($fullPath, 0777);
$zip->extractTo($fullPath);
$zip->close();
$wpdb->insert($wpdb->prefix.'mod_upload_formation',
array('nom'=>$nom, 'url'=>'http://www.syntaxis.fr/wp-content/uploads/pw-upload-formation/'.$randDirectory.'/story.html'));
} else {
echo 'Erreur lors l\'ouverture de l\'archive. Vérifiez qu\'elle n\'est pas corrompue.';
}
return true;
}
public function deleteFormation($id){
global $wpdb;
$formation = $wpdb->get_row($wpdb->prepare( 'SELECT * FROM '.$wpdb->prefix.'mod_upload_formation WHERE id = '.$id ), ARRAY_A);
if($formation['id']){
$file = preg_replace('/http:\/\/www.syntaxis.fr/', '', htmlspecialchars($formation['url']));
$path = pathinfo(realpath('../'.$file));
$path = $path['dirname'];
//si le dossier existe on le supprime
if (is_dir($path)) {
pwuploadformation::delTree($path);
//si il existe encore ça n'a pas marché
if (is_dir($path)) {
echo 'Erreur lors de la suppression du répertoire