public function index() { $this->setView('index.php'); $is_logged = isset(User_Model::$auth_data); $is_student = $is_logged && isset(User_Model::$auth_data['student_number']); $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1'; $this->set(array('username' => User_Model::$auth_data['username'], 'is_logged' => $is_logged, 'is_student' => $is_student, 'is_admin' => $is_admin)); //Fonction qui met à jour l'annuaire dans mysql et ajoute les avatars //$uploaded_files=array(); if (isset($_FILES['uploadzip'])) { if ($_FILES['uploadzip']['size'] > Config::UPLOAD_MAX_SIZE_FILE) { throw new Exception(__('POST_ADD_ERROR_FILE_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_FILE)))); } //On déplace le fichier zipper vers le serveur if ($filepaths = File::upload('uploadzip')) { // foreach($filepaths as $filepath) // $uploaded_files[] = $filepath; //foreach($filepaths as $i => $filepath){ if (!preg_match('#\\.zip$#', $filepaths)) { throw new Exception(__('POST_ADD_ERROR_FILE_FORMAT')); } $name = $filepaths; //} } $path = DATA_DIR . Config::DIR_DATA_TMP . 'annuaire/'; // On dézip celui-ci if (FILE::exists($path)) { FILE::delete($path); } File::makeDir($path); $zip = new ZipArchive(); $res = $zip->open($name); if ($res === TRUE) { $zip->extractTo($path); $zip->close(); unlink($name); } else { throw new Exception(__('ADMIN_POST_ZIPERROR')); } if (File::delete(DATA_DIR . Config::DIR_DATA_TMP . $name)) { // On aplique le chmod a tous les dossiers et fichiers du zip FILE::chmodDirectory($path, 0); // on traite les fichiers students.csv et users.csv if (file_exists($path . 'users.csv')) { $fp = fopen($path . 'users.csv', "r"); } else { throw new Exception(__('ADMIN_POST_CSVERROR1')); } $i = 0; while (!feof($fp)) { $i = $i + 1; // Tant qu'on n'atteint pas la fin du fichier $ligne = fgets($fp, 4096); /* On lit une ligne */ // On récupère les champs séparés par ; dans liste $liste = explode(";", $ligne); // On assigne les variables if (strlen($liste[0]) > 1) { if (isset($liste[0])) { $username = $liste[0]; } if (isset($liste[1])) { $admin = $liste[1]; } if (isset($liste[2])) { $mail = $liste[2]; } if (isset($liste[3])) { $msn = $liste[3]; } if (isset($liste[4])) { $jabber = $liste[4]; } if (isset($liste[5])) { $address = $liste[5]; } if (isset($liste[6])) { $zipcode = $liste[6]; } if (isset($liste[7])) { $city = $liste[7]; } if (isset($liste[8])) { $cellphone = $liste[8]; } if (isset($liste[9])) { $phone = $liste[9]; } if (isset($liste[10])) { $birthday = $liste[10]; } if (!$this->model->checkuser($username, 1)) { $this->model->insertUsers(trim($username), trim($admin), trim($mail), trim($msn), trim($jabber), trim($address), trim($zipcode), trim($city), trim($cellphone), trim($phone), trim($birthday)); } } } fclose($fp); if (file_exists($path . 'students.csv')) { $fp = fopen($path . 'students.csv', "r"); } else { throw new Exception(__('ADMIN_POST_CSVERROR2')); } $i = 0; while (!feof($fp)) { $i = $i + 1; // Tant qu'on n'atteint pas la fin du fichier $ligne = fgets($fp, 4096); /* On lit une ligne */ // On récupère les champs séparés par ; dans liste $liste = explode(";", $ligne); // On assigne les variables if (strlen($liste[0]) > 1) { if (isset($liste[0])) { $username = $liste[0]; } if (isset($liste[1])) { $lastname = $liste[1]; } if (isset($liste[2])) { $firstname = $liste[2]; } if (isset($liste[3])) { $student_number = $liste[3]; } if (isset($liste[4])) { $promo = $liste[4]; } if (isset($liste[5])) { $cesure = $liste[5]; } if (!$this->model->checkuser($username, 2)) { $this->model->insertStudents(trim($username), trim($lastname), trim($firstname), trim($student_number), trim($promo), trim($cesure)); } // On déplace et formate les photos dans le dossier avatars $avatarpath = $path . 'photos_students/' . $student_number . '.jpg'; $img = new Image(); $img->load($avatarpath); $type = $img->getType(); if ($type == IMAGETYPE_JPEG) { $ext = 'jpg'; } else { if ($type == IMAGETYPE_GIF) { $ext = 'gif'; } else { if ($type == IMAGETYPE_PNG) { $ext = 'png'; } else { throw new Exception(); } } } if ($img->getWidth() > 800) { $img->setWidth(800, true); } $img->setType(IMAGETYPE_JPEG); $img->save($avatarpath); // Thumb $avatarthumbpath = $path . 'photos_students/' . $student_number . '_thumb.jpg'; $img->thumb(Config::$AVATARS_THUMBS_SIZES[0], Config::$AVATARS_THUMBS_SIZES[1]); $img->setType(IMAGETYPE_JPEG); $img->save($avatarthumbpath); if (FILE::exists(DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/')) { FILE::move($avatarthumbpath, DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/'); FILE::move($avatarpath, DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/'); } else { FILE::makeDir(DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/'); FILE::move($avatarthumbpath, DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/'); FILE::move($avatarpath, DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/'); } unset($img); } } fclose($fp); // On supprime le tout du dossier temp FILE::delete($path); } } }