Example #1
0
    /**
     * Add a post
     */
    public function iframe_add()
    {
        $this->setView('iframe_add.php');
        @set_time_limit(0);
        $uploaded_files = array();
        try {
            if (!isset(User_Model::$auth_data)) {
                throw new Exception(__('POST_ADD_ERROR_SESSION_EXPIRED'));
            }
            $is_student = isset(User_Model::$auth_data['student_number']);
            // Message
            $message = isset($_POST['message']) ? trim($_POST['message']) : '';
            if ($message == '' || $message == __('PUBLISH_DEFAULT_MESSAGE')) {
                throw new Exception(__('POST_ADD_ERROR_NO_MESSAGE'));
            }
            $message = preg_replace('#\\n{2,}#', "\n\n", $message);
            // Category
            if (!isset($_POST['category']) || !ctype_digit($_POST['category'])) {
                throw new Exception(__('POST_ADD_ERROR_NO_CATEGORY'));
            }
            $category = (int) $_POST['category'];
            // Official post (in a group)
            $official = isset($_POST['official']);
            // Group
            $group = isset($_POST['group']) && ctype_digit($_POST['group']) ? (int) $_POST['group'] : 0;
            if ($group == 0) {
                $group = null;
                $official = false;
            } else {
                $groups_auth = Group_Model::getAuth();
                if (isset($groups_auth[$group])) {
                    if ($official && !$groups_auth[$group]['admin']) {
                        throw new Exception(__('POST_ADD_ERROR_OFFICIAL'));
                    }
                } else {
                    throw new Exception(__('POST_ADD_ERROR_GROUP_NOT_FOUND'));
                }
            }
            // Private message
            $private = isset($_POST['private']);
            if ($private && !$is_student) {
                throw new Exception(__('POST_ADD_ERROR_PRIVATE'));
            }
            $attachments = array();
            // Photos
            if (isset($_FILES['attachment_photo']) && is_array($_FILES['attachment_photo']['name'])) {
                foreach ($_FILES['attachment_photo']['size'] as $size) {
                    if ($size > Config::UPLOAD_MAX_SIZE_PHOTO) {
                        throw new Exception(__('POST_ADD_ERROR_PHOTO_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_PHOTO))));
                    }
                }
                if ($filepaths = File::upload('attachment_photo')) {
                    foreach ($filepaths as $filepath) {
                        $uploaded_files[] = $filepath;
                    }
                    foreach ($filepaths as $i => $filepath) {
                        $name = isset($_FILES['attachment_photo']['name'][$i]) ? $_FILES['attachment_photo']['name'][$i] : '';
                        try {
                            $img = new Image();
                            $img->load($filepath);
                            $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->save($filepath);
                            // Thumb
                            $thumbpath = $filepath . '.thumb';
                            $img->thumb(Config::$THUMBS_SIZES[0], Config::$THUMBS_SIZES[1]);
                            $img->setType(IMAGETYPE_JPEG);
                            $img->save($thumbpath);
                            unset($img);
                            $attachments[] = array($filepath, $name, $thumbpath);
                            $uploaded_files[] = $thumbpath;
                        } catch (Exception $e) {
                            throw new Exception(__('POST_ADD_ERROR_PHOTO_FORMAT'));
                        }
                    }
                }
            }
            // Vidéos
            /* @uses PHPVideoToolkit : http://code.google.com/p/phpvideotoolkit/
             * @requires ffmpeg, php5-ffmpeg
             */
            if (isset($_FILES['attachment_video']) && is_array($_FILES['attachment_video']['name'])) {
                foreach ($_FILES['attachment_video']['size'] as $size) {
                    if ($size > Config::UPLOAD_MAX_SIZE_VIDEO) {
                        throw new Exception(__('POST_ADD_ERROR_VIDEO_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_VIDEO))));
                    }
                }
                if ($filepaths = File::upload('attachment_video')) {
                    foreach ($filepaths as $filepath) {
                        $uploaded_files[] = $filepath;
                    }
                    foreach ($filepaths as $i => $filepath) {
                        $name = isset($_FILES['attachment_video']['name'][$i]) ? $_FILES['attachment_video']['name'][$i] : '';
                        try {
                            $video = new ffmpeg_movie($filepath, false);
                            if (!$video->hasVideo()) {
                                throw new Exception('No video stream found in the file');
                            }
                            if (!$video->hasAudio()) {
                                throw new Exception('No audio stream found in the file');
                            }
                        } catch (Exception $e) {
                            throw new Exception(__('POST_ADD_ERROR_VIDEO_FORMAT'));
                        }
                        // Video conversion
                        try {
                            $video_current_width = $video->getFrameWidth();
                            $video_width = min($video_current_width, Config::VIDEO_MAX_WIDTH);
                            if ($video_width % 2 == 1) {
                                // Even number required
                                $video_width--;
                            }
                            $video_height = $video_width * $video->getFrameHeight() / $video_current_width;
                            if ($video_height % 2 == 1) {
                                // Even number required
                                $video_height--;
                            }
                            // Extract thumb
                            $video_thumb = $video->getFrame(round($video->getFrameCount() * 0.2));
                            unset($video);
                            $video_thumb = $video_thumb->toGDImage();
                            $thumbpath = DATA_DIR . Config::DIR_DATA_TMP . File::getName($filepath) . '.thumb';
                            imagejpeg($video_thumb, $thumbpath, 95);
                            unset($video_thumb);
                            $img = new Image();
                            $img->load($thumbpath);
                            $img->setWidth($video_width, true);
                            $img->setType(IMAGETYPE_JPEG);
                            $img->save($thumbpath);
                            $uploaded_files[] = $thumbpath;
                            unset($img);
                            // Convert to FLV
                            if (!preg_match('#\\.flv$#i', $filepath)) {
                                $toolkit = new PHPVideoToolkit();
                                $toolkit->on_error_die = true;
                                // Will throw exception on error
                                $toolkit->setInputFile($filepath);
                                $toolkit->setVideoOutputDimensions($video_width, $video_height);
                                $toolkit->setFormatToFLV(Config::VIDEO_SAMPLING_RATE, Config::VIDEO_AUDIO_BIT_RATE);
                                $toolkit->setOutput(DATA_DIR . Config::DIR_DATA_TMP, File::getName($filepath) . '.flv', PHPVideoToolkit::OVERWRITE_EXISTING);
                                $toolkit->execute(false, false);
                                // Multipass: false, Log: false
                                File::delete($filepath);
                                $filepath = $toolkit->getLastOutput();
                                $filepath = $filepath[0];
                                unset($toolkit);
                            }
                            $attachments[] = array($filepath, $name, $thumbpath);
                            $uploaded_files[] = $filepath;
                        } catch (Exception $e) {
                            throw new Exception(__('POST_ADD_ERROR_VIDEO_CONVERT') . $e->getMessage());
                        }
                    }
                }
            }
            // Audios
            if (isset($_FILES['attachment_audio']) && is_array($_FILES['attachment_audio']['name'])) {
                foreach ($_FILES['attachment_audio']['size'] as $size) {
                    if ($size > Config::UPLOAD_MAX_SIZE_AUDIO) {
                        throw new Exception(__('POST_ADD_ERROR_AUDIO_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_AUDIO))));
                    }
                }
                if ($filepaths = File::upload('attachment_audio')) {
                    foreach ($filepaths as $filepath) {
                        $uploaded_files[] = $filepath;
                    }
                    foreach ($filepaths as $i => $filepath) {
                        if (!preg_match('#\\.mp3$#', $filepath)) {
                            throw new Exception(__('POST_ADD_ERROR_AUDIO_FORMAT'));
                        }
                        $name = isset($_FILES['attachment_audio']['name'][$i]) ? $_FILES['attachment_audio']['name'][$i] : '';
                        $attachments[] = array($filepath, $name);
                    }
                }
            }
            // Files
            if (isset($_FILES['attachment_file']) && is_array($_FILES['attachment_file']['name'])) {
                foreach ($_FILES['attachment_file']['size'] as $size) {
                    if ($size > Config::UPLOAD_MAX_SIZE_FILE) {
                        throw new Exception(__('POST_ADD_ERROR_FILE_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_FILE))));
                    }
                }
                if ($filepaths = File::upload('attachment_file')) {
                    foreach ($filepaths as $filepath) {
                        $uploaded_files[] = $filepath;
                    }
                    foreach ($filepaths as $i => $filepath) {
                        if (!preg_match('#\\.[a-z0-9]{2,4}$#i', $filepath)) {
                            throw new Exception(__('POST_ADD_ERROR_FILE_FORMAT'));
                        }
                        if (preg_match('#\\.(jpg|png|gif|mp3|flv)$#i', $filepath)) {
                            throw new Exception(__('POST_ADD_ERROR_FILE_FORMAT2'));
                        }
                        $name = isset($_FILES['attachment_file']['name'][$i]) ? $_FILES['attachment_file']['name'][$i] : '';
                        $attachments[] = array($filepath, $name);
                    }
                }
            }
            // Event
            if (isset($_POST['event_title']) && isset($_POST['event_start']) && isset($_POST['event_end'])) {
                // Title
                $event_title = trim($_POST['event_title']);
                if ($event_title == '') {
                    throw new Exception(__('POST_ADD_ERROR_EVENT_NO_TITLE'));
                }
                // Dates
                if (!($event_start = strptime($_POST['event_start'], __('PUBLISH_EVENT_DATE_FORMAT')))) {
                    throw new Exception(__('POST_ADD_ERROR_EVENT_DATE'));
                }
                if (!($event_end = strptime($_POST['event_end'], __('PUBLISH_EVENT_DATE_FORMAT')))) {
                    throw new Exception(__('POST_ADD_ERROR_EVENT_DATE'));
                }
                $event_start = mktime($event_start['tm_hour'], $event_start['tm_min'], 0, $event_start['tm_mon'] + 1, $event_start['tm_mday'], $event_start['tm_year'] + 1900);
                $event_end = mktime($event_end['tm_hour'], $event_end['tm_min'], 0, $event_end['tm_mon'] + 1, $event_end['tm_mday'], $event_end['tm_year'] + 1900);
                if ($event_start > $event_end) {
                    throw new Exception(__('POST_ADD_ERROR_EVENT_DATE_ORDER'));
                }
                $event = array($event_title, $event_start, $event_end);
            } else {
                $event = null;
            }
            // Survey
            if (isset($_POST['survey_question']) && isset($_POST['survey_end']) && isset($_POST['survey_answer']) && is_array($_POST['survey_answer'])) {
                // Question
                $survey_question = trim($_POST['survey_question']);
                if ($survey_question == '') {
                    throw new Exception(__('POST_ADD_ERROR_SURVEY_NO_QUESTION'));
                }
                // Date
                if (!($survey_end = strptime($_POST['survey_end'], __('PUBLISH_EVENT_DATE_FORMAT')))) {
                    throw new Exception(__('POST_ADD_ERROR_SURVEY_DATE'));
                }
                $survey_end = mktime($survey_end['tm_hour'], $survey_end['tm_min'], 0, $survey_end['tm_mon'] + 1, $survey_end['tm_mday'], $survey_end['tm_year'] + 1900);
                // Multiple answers
                $survey_multiple = isset($_POST['survey_multiple']);
                // Answers
                $survey_answers = array();
                foreach ($_POST['survey_answer'] as $survey_answer) {
                    $survey_answer = trim($survey_answer);
                    if ($survey_answer != '') {
                        $survey_answers[] = $survey_answer;
                    }
                }
                if (count($survey_answers) < 2) {
                    throw new Exception(__('POST_ADD_ERROR_SURVEY_ANSWERS'));
                }
                $survey = array($survey_question, $survey_end, $survey_multiple, $survey_answers);
            } else {
                $survey = null;
            }
            // Creation of the post
            $id = $this->model->addPost((int) User_Model::$auth_data['id'], $message, $category, $group, $official, $private);
            // Attach files
            foreach ($attachments as $attachment) {
                $this->model->attachFile($id, $attachment[0], $attachment[1], isset($attachment[2]) ? $attachment[2] : null);
            }
            // Event
            if (isset($event)) {
                $this->model->attachEvent($id, $event[0], $event[1], $event[2]);
            }
            // Survey
            if (isset($survey)) {
                $this->model->attachSurvey($id, $survey[0], $survey[1], $survey[2], $survey[3]);
            }
            $this->addJSCode('
				parent.location = "' . Config::URL_ROOT . Routes::getPage('home') . '";
			');
        } catch (Exception $e) {
            // Delete all uploading files in tmp
            foreach ($uploaded_files as $uploaded_file) {
                File::delete($uploaded_file);
            }
            $this->addJSCode('
				with(parent){
					Post.errorForm(' . json_encode($e->getMessage()) . ');
				}
			');
        }
    }
Example #2
0
                    ?>
" method="post" enctype="multipart/form-data" target="publish_iframe" onsubmit="return Post.submitForm();">
										<fieldset id="publish-stock-attachment-photo" class="publish-attachment">
											<legend><img src="<?php 
                    echo Config::URL_STATIC;
                    ?>
images/icons/attachment_photo.png" alt="" class="icon" /> <?php 
                    echo __('ADD_ATTACHMENT_PHOTO');
                    ?>
</legend>
											<?php 
                    echo __('PUBLISH_ATTACHMENT_SEND');
                    ?>
 <input type="file" name="attachment_photo[]" multiple /><br />
											<span class="publish-attachment-info"><?php 
                    echo __('PUBLISH_ATTACHMENT_PHOTO_INFO', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_PHOTO)));
                    ?>
</span>
											<input type="submit" id="publish-submit" value="<?php 
                    echo __('PUBLISH_SUBMIT');
                    ?>
" />
										</fieldset>
									</form>
									<div id="publish-error" class="hidden"></div>
									<iframe name="publish_iframe" class="hidden"></iframe>
								</div>
							<?php 
                }
                ?>
                        <div class="photos <?php 
Example #3
0
echo htmlspecialchars($group['description']);
?>
</textarea>
			<br /><br />
			
			<label for="group_edit_avatar"><?php 
echo __('GROUP_EDIT_FORM_AVATAR');
?>
</label>
			<input type="file" name="avatar" id="group_edit_avatar" /><br />
			<?php 
if (isset($form_error) && $form_error == 'avatar') {
    ?>
			<p class="form-error">
				<?php 
    echo __('GROUP_EDIT_ERROR_AVATAR', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_PHOTO)));
    ?>
			</p>
			<?php 
}
?>
			
			<br />
			<div id="group-edit-members">
				<strong><?php 
echo __('GROUP_MEMBERS');
?>
</strong>
				<ul>
<?php 
foreach ($group['members'] as $member) {
Example #4
0
 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);
         }
     }
 }
Example #5
0
    public function addAttachment($param)
    {
        $this->setView('iframe_add.php');
        $is_logged = isset(User_Model::$auth_data);
        $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1';
        @set_time_limit(0);
        $uploaded_files = array();
        $attachments = array();
        try {
            if ($is_admin && isset($param['id']) && isset($_FILES['attachment_photo']) && is_array($_FILES['attachment_photo']['name'])) {
                foreach ($_FILES['attachment_photo']['size'] as $size) {
                    if ($size > Config::UPLOAD_MAX_SIZE_PHOTO) {
                        throw new Exception(__('POST_ADD_ERROR_PHOTO_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_PHOTO))));
                    }
                }
                if ($filepaths = File::upload('attachment_photo')) {
                    foreach ($filepaths as $filepath) {
                        $uploaded_files[] = $filepath;
                    }
                    foreach ($filepaths as $i => $filepath) {
                        $name = isset($_FILES['attachment_photo']['name'][$i]) ? $_FILES['attachment_photo']['name'][$i] : '';
                        try {
                            $img = new Image();
                            $img->load($filepath);
                            $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->save($filepath);
                            // Thumb
                            $thumbpath = $filepath . '.thumb';
                            $img->thumb(Config::$THUMBS_SIZES[0], Config::$THUMBS_SIZES[1]);
                            $img->setType(IMAGETYPE_JPEG);
                            $img->save($thumbpath);
                            unset($img);
                            $attachments[] = array($filepath, $name, $thumbpath);
                            $uploaded_files[] = $thumbpath;
                        } catch (Exception $e) {
                            throw new Exception(__('POST_ADD_ERROR_PHOTO_FORMAT'));
                        }
                    }
                }
                // Attach files
                foreach ($attachments as $attachment) {
                    $this->model->attachFile($param['id'], $attachment[0], $attachment[1], isset($attachment[2]) ? $attachment[2] : null);
                }
                $this->addJSCode('
						parent.location = "' . Config::URL_ROOT . Routes::getPage('post', array('id' => $param['id'])) . '";
					');
            }
            Post_Model::clearCache();
        } catch (Exception $e) {
            // Delete all uploading files in tmp
            foreach ($uploaded_files as $uploaded_file) {
                File::delete($uploaded_file);
            }
            $this->addJSCode('
				with(parent){
					Post.errorForm(' . json_encode($e->getMessage()) . ');
				}
			');
        }
    }
Example #6
0
    public function isepdorPage($param)
    {
        $this->setView('isepdor.php');
        $questions = $this->model->getquestions();
        for ($i = 0; $i < count($questions); $i++) {
            $type = explode(',', $questions[$i]["type"]);
            $tab = array("students", "associations", "employees", "events");
            $result = array_intersect($type, $tab);
            if (in_array("students", $result)) {
                $questions[$i]["students"] = 1;
            } else {
                $questions[$i]["students"] = 0;
            }
            if (in_array("events", $result)) {
                $questions[$i]["events"] = 1;
            } else {
                $questions[$i]["events"] = 0;
            }
            if (in_array("associations", $result)) {
                $questions[$i]["associations"] = 1;
            } else {
                $questions[$i]["associations"] = 0;
            }
            if (in_array("employees", $result)) {
                $questions[$i]["employees"] = 1;
            } else {
                $questions[$i]["employees"] = 0;
            }
            if ($questions[$i]["extra"] == null) {
                $questions[$i]["extra"] = " ";
            }
        }
        $events = $this->model->getevents();
        for ($i = 0; $i < count($events); $i++) {
            if ($events[$i]['extra'] == "soiree") {
                $events[$i]['extra'] = 1;
            } else {
                $events[$i]['extra'] = 0;
            }
        }
        $myFile = DATA_DIR . Config::DIR_DATA_STORAGE . Config::DIR_DATA_ADMIN . "/diplome.json";
        $file = fopen($myFile, 'r');
        $positions = fread($file, filesize($myFile));
        fclose($file);
        $this->addJSCode('
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxcore.js","js");
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxdata.js","js");
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxbuttons.js","js");
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxscrollbar.js","js");
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxmenu.js","js");
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxgrid.js","js");
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxgrid.edit.js","js");
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxgrid.selection.js","js");
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxgrid.sort.js","js");
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxgrid.filter.js","js");
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxgrid.columnsresize.js","js");
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxlistbox.js","js");
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxdropdownlist.js","js");
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxcheckbox.js","js");
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxcombobox.js","js");
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxgrid.pager.js","js");
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxdragdrop.js","js");
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxcalendar.js","js");
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxtooltip.js","js");				
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxdatetimeinput.js","js");
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jquery.global.js","js");
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jquery.glob.fr-FR.js","js");
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxtabs.js","js");
				
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/crop/jquery.Jcrop.min.js","js");
				Admin.loadjscssfile("' . Config::URL_STATIC . 'js/crop/jquery.color.js","js");
				
				jQuery(document).ready(function () {
					diplomeData=new Array();
					Admin.loadTab();
					Admin.loadCrop();
					Admin.loadCatGrid(' . json_encode($questions) . ');
					Admin.loadEventGrid(' . json_encode($events) . ');
					Admin.loadEmployGrid(' . json_encode($this->model->getemployees()) . ');
					Admin.loadDate(' . json_encode($this->model->getDate()) . ');
					jQuery(".jcrop-holder").ready(function () {
						Admin.loadDiplome(' . $positions . ');
					});
					jQuery("#adminIsepdorTab").removeClass("hidden");
				});
			');
        /* Code qui met à jour le questionnaire pour les ISEP D'or
         *
         */
        if (isset($_POST['categories'])) {
            $id = array();
            $post = json_decode($_POST['categories'], true);
            for ($i = 0; $i < count($post); $i++) {
                if (is_numeric($post[$i]['id'])) {
                    array_push($id, $post[$i]['id']);
                }
            }
            $toDelete = $this->model->checkIsepdorQuestions($id);
            if (count($toDelete) > 0) {
                for ($i = 0; $i < count($toDelete); $i++) {
                    $this->model->deleteQuestions($toDelete[$i]);
                }
            }
            for ($i = 0; $i < count($post); $i++) {
                if ($post[$i]['extra'] == "") {
                    $post[$i]['extra'] = NULL;
                }
                if ($post[$i]['id'] != "") {
                    $this->model->updateisepdor($post[$i]['type'], $post[$i]['extra'], $post[$i]['questions'], $post[$i]['id'], $post[$i]['position']);
                } elseif ($post[$i]['id'] == "") {
                    $this->model->insertisepdor($post[$i]['type'], $post[$i]['extra'], $post[$i]['questions'], $post[$i]['position']);
                }
            }
        }
        /*Code qui met à jour la table isepdor_employees
         *
         */
        if (isset($_POST['employees'])) {
            $id = array();
            $post = json_decode($_POST['employees'], true);
            for ($i = 0; $i < count($post); $i++) {
                if (is_numeric($post[$i]['id'])) {
                    array_push($id, $post[$i]['id']);
                }
            }
            $toDelete = $this->model->checkIsepdorEmployees($id);
            if (count($toDelete) > 0) {
                for ($i = 0; $i < count($toDelete); $i++) {
                    $this->model->deleteEmployees($toDelete[$i]);
                }
            }
            for ($i = 0; $i < count($post); $i++) {
                $username = $this->makeusername($post[$i]['lastname'], $post[$i]['firstname']);
                if ($post[$i]['id'] != "") {
                    $this->model->updateEmployees($post[$i]['lastname'], $post[$i]['firstname'], $post[$i]['id'], $username);
                } elseif ($post[$i]['id'] == "") {
                    $this->model->insertemployees($post[$i]['lastname'], $post[$i]['firstname'], $username);
                }
            }
        }
        /*Code qui met à jour la table isepdor_event
         *
         */
        if (isset($_POST['events'])) {
            $id = array();
            $post = json_decode($_POST['events'], true);
            for ($i = 0; $i < count($post); $i++) {
                if (is_numeric($post[$i]['id'])) {
                    array_push($id, $post[$i]['id']);
                }
            }
            $toDelete = $this->model->checkIsepdorEvents($id);
            if (count($toDelete) > 0) {
                for ($i = 0; $i < count($toDelete); $i++) {
                    $this->model->deleteEvents($toDelete[$i]);
                }
            }
            for ($i = 0; $i < count($post); $i++) {
                if ($post[$i]['extra'] == 1) {
                    $post[$i]['extra'] = "soiree";
                } else {
                    $post[$i]['extra'] = NULL;
                }
                if ($post[$i]['id'] != "") {
                    $this->model->updateEvent($post[$i]['name'], $post[$i]['id'], $post[$i]['extra']);
                } elseif ($post[$i]['id'] == "") {
                    $this->model->insertEvent($post[$i]['name'], $post[$i]['extra']);
                }
            }
        }
        /*Code qui met à jour les date de vote des isep d'or
         *
         */
        if (isset($_POST['dates'])) {
            $post = json_decode($_POST['dates'], true);
            $this->model->insertDate($post[0][0], $post[0][1], $post[1][0], $post[1][1], $post[2][0], $post[2][1]);
        }
        /*
         * Change l'image diplome
         */
        if (isset($_FILES['diplome']) && !is_array($_FILES['diplome']['name'])) {
            if ($_FILES['diplome']['size'] > Config::UPLOAD_MAX_SIZE_PHOTO) {
                throw new FormException('size');
            }
            if ($avatarpath = File::upload('diplome')) {
                $uploaded_files[] = $avatarpath;
                try {
                    $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->getHeight() != 794 || $img->getWidth() != 1122) {
                        throw new FormException('width');
                    }
                    $img->setType($type);
                    $img->save($avatarpath);
                    unset($img);
                    if (isset($avatarpath) && File::exists($avatarpath)) {
                        $avatar_path = DATA_DIR . Config::DIR_DATA_STORAGE . Config::DIR_DATA_ADMIN . "diplomeIsepDOr9652.png";
                        $avatar_dir = File::getPath($avatar_path) . "/diplomeIsepDOr9652.png";
                        File::rename($avatarpath, $avatar_dir);
                    }
                } catch (FormException $e) {
                    $this->set('form_error', $e->getError());
                }
                foreach ($uploaded_files as $uploaded_file) {
                    File::delete($uploaded_file);
                }
            }
            Post_Model::clearCache();
        }
        /*
         * Enregistre les coordonnées
         */
        if (isset($_POST['diplomeData'])) {
            $post = $_POST['diplomeData'];
            $file = fopen($myFile, 'w');
            fwrite($file, $post);
            fclose($file);
        }
        /*
         * Envoie les diplomes
         */
        if (isset($_GET['getDiplome'])) {
            $template = DATA_DIR . Config::DIR_DATA_STORAGE . Config::DIR_DATA_ADMIN . "diplomeIsepDOr9652.png";
            $font = DATA_DIR . Config::DIR_DATA_STORAGE . Config::DIR_DATA_ADMIN . "font2354.ttf";
            $files = array();
            $positions = json_decode($positions, true);
            //récupere les coordonnées précédament demandées
            for ($i = 0; $i < count($positions); $i++) {
                $coord[$positions[$i]['index']] = $positions[$i];
            }
            $questions = IsepOr_Model::fetchQuestions();
            foreach ($questions as $value) {
                if (strpos($value['type'], ',')) {
                    $data = array();
                    foreach (explode(',', $value['type']) as $type) {
                        $data = IsepOr_Controller::__array_rePad($data, IsepOr_Model::fetchFinals($value['id'], $type, 2));
                    }
                    $finalList[$value['id']] = array_slice(IsepOr_Controller::__array_orderby($data, 'cmpt', SORT_DESC), 0, 3);
                } else {
                    $finalList[$value['id']] = IsepOr_Model::fetchFinals($value['id'], $value['type'], 2);
                }
            }
            for ($i = 0; $i < count($questions); $i++) {
                for ($j = 0; $j < count($finalList[$questions[$i]['id']]); $j++) {
                    File::copy($template, DATA_DIR . Config::DIR_DATA_TMP . "diplome" . $i . $j . ".png");
                    array_push($files, DATA_DIR . Config::DIR_DATA_TMP . "diplome" . $i . $j . ".png");
                    $im = ImageCreateFromPng(DATA_DIR . Config::DIR_DATA_TMP . "diplome" . $i . $j . ".png");
                    // Path Images
                    $color = ImageColorAllocate($im, 0, 0, 0);
                    // Text Color
                    $champs[0] = $questions[$i]['questions'];
                    $champs[1] = $finalList[$questions[$i]['id']][$j]["name"];
                    $champs[2] = "";
                    if (!is_numeric($finalList[$questions[$i]['id']][$j]["valid"])) {
                        $champs[2] = $this->model->getBirthDay($finalList[$questions[$i]['id']][$j]["valid"]);
                    }
                    for ($a = 0; $a < 3; $a++) {
                        $pxX = round($coord[$a]['x1']);
                        // X
                        $pxY = round($coord[$a]['y2']);
                        // Y
                        ImagettfText($im, round($coord[$a]['h']), 0, $pxX, $pxY, $color, $font, $champs[$a]);
                    }
                    imagePng($im, DATA_DIR . Config::DIR_DATA_TMP . "diplome" . $i . $j . ".png", 9);
                    ImageDestroy($im);
                    if ($finalList[$questions[$i]['id']][$j]['cmpt'] != $finalList[$questions[$i]['id']][$j + 1]['cmpt']) {
                        break;
                    }
                }
            }
            if (self::create_zip($files, DATA_DIR . Config::DIR_DATA_TMP . "diplomesIsepDor.zip", true)) {
                foreach ($files as $file) {
                    File::delete($file);
                }
                header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
                header("Cache-Control: public");
                // needed for i.e.
                header("Content-Type: application/zip");
                header("Content-Transfer-Encoding: Binary");
                header("Content-Length:" . filesize(DATA_DIR . Config::DIR_DATA_TMP . "diplomesIsepDor.zip"));
                header("Content-Disposition: attachment; filename=diplomesIsepDor.zip");
                readfile(DATA_DIR . Config::DIR_DATA_TMP . "diplomesIsepDor.zip");
                File::delete(DATA_DIR . Config::DIR_DATA_TMP . "diplomesIsepDor.zip");
                die;
            }
            foreach ($files as $file) {
                File::delete($file);
            }
        }
        /*Code qui export les résultats des isep d'or
         *
         */
        if (isset($_GET['export'])) {
            $db = $this->model->getResult();
            header('Content-Type: application/vnd.ms-excel');
            header('Content-Disposition: filename=' . 'Résultats_Isepdor' . '.xls');
            header('Pragma: no-cache');
            header('Expires: 0');
            print '<table border=1 >
						<!-- impression des titres de colonnes -->
							<TR>
								<TD bgcolor="#3366CC">Tour</TD>
								<TD bgcolor="#3366CC">Nom du votant</TD>
								<TD bgcolor="#3366CC">Catégorie</TD>
								<TD bgcolor="#3366CC">Réponse(student)</TD>
								<TD bgcolor="#3366CC">Réponse(admin)</TD>
								<TD bgcolor="#3366CC">Réponse(assoce)</TD>
								<TD bgcolor="#3366CC">Réponse(event)</TD>						
							</TR>
							';
            foreach ($db as $champs) {
                print '<TR>';
                print '<TD>' . $champs['round'] . '</TD>';
                print '<TD>' . $champs['username'] . '</TD>';
                print '<TD>' . utf8_decode($champs['questions']) . '</TD>';
                print '<TD>' . $champs['student_username'] . '</TD>';
                print '<TD>' . utf8_decode($champs['admin']) . '</TD>';
                print '<TD>' . utf8_decode($champs['assoce']) . '</TD>';
                print '<TD>' . utf8_decode($champs['name']) . '</TD>';
                print '</TR>';
            }
            print '</table>';
            exit;
        }
        /*
         * Ajout de la police
         */
        if (isset($_FILES['font']) && $_FILES['font']['name'] != null) {
            if ($_FILES['font']['size'] > Config::UPLOAD_MAX_SIZE_FILE) {
                throw new Exception(__('POST_ADD_ERROR_FILE_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_FILE))));
            }
            if ($filepaths = File::upload('font')) {
                if (!preg_match('#\\.ttf$#i', $filepaths)) {
                    throw new Exception(__('POST_ADD_ERROR_FILE_FORMAT'));
                }
                $avatar_path = DATA_DIR . Config::DIR_DATA_STORAGE . Config::DIR_DATA_ADMIN . "font2354.ttf";
                $avatar_dir = File::getPath($avatar_path) . "/font2354.ttf";
                File::rename($filepaths, $avatar_dir);
            } else {
                throw new Exception(__('ADMIN_UPLOAD_ERROR'));
            }
        }
        /*Code qui met supprime les champs de la table résultat des isep d'or
         *
         */
        if (isset($_GET['delete_result'])) {
            $this->model->deleteresult();
            header("Location: " . Config::URL_ROOT . Routes::getPage('admin', array("nav" => "isepdor")));
        }
    }