public function getRequirementList($studentID, $signatoryID, $sysemID)
 {
     $stud_model = new Student_Model();
     $stud_model->queryStudent_Info($studentID);
     $t_deptID = $stud_model->getStud_DeptID();
     $t_courseID = $stud_model->getStud_CourseID();
     $t_yl = $stud_model->getStud_Yearlevel();
     $t_program = $stud_model->getStud_Program();
     $arrayTemp = array();
     $this->query = mysql_query("select Requirement_ID, Title, Description, Requirement_Type, Prerequisite_Signatory from requirements \r\n                                    where Signatory_ID='{$signatoryID}' and SY_SEM_ID='{$sysemID}' and \r\n                                    (Visibility='All' or Department_ID='{$t_deptID}' or Course_ID='{$t_courseID}' or Year_Level='{$t_yl}' or Program='{$t_program}')");
     /*
     var_dump("select Requirement_ID, Title, Description from requirements 
                                 where Signatory_ID='$signatoryID' and SY_SEM_ID='$sysemID' and 
                                 (Visibility='All' or Department_ID='$t_deptID' or Course_ID='$t_courseID' or Year_Level='$t_yl' or Program='$t_program')");
     */
     while ($row = mysql_fetch_array($this->query)) {
         if ($row['Requirement_Type'] == 'Textual') {
             $status = $this->getRequirementClearanceStatus($studentID, $row['Requirement_ID']);
         } else {
             $sigID = $row['Prerequisite_Signatory'];
             if ($this->isStudentUnderSpecifiedSignatory($studentID, $sigID)) {
                 $status = $this->getOverallSignatoryClearanceStatus($studentID, $sigID, $sysemID);
                 if ($status == "No Requirements") {
                     $status = "Cleared";
                 }
             }
         }
         array_push($arrayTemp, array($row['Requirement_ID'], $row['Title'], $row['Description'], $status, $row['Requirement_Type']));
     }
     return $arrayTemp;
 }
示例#2
0
 /**
  * Search posts, groups, and students
  */
 public function index($params)
 {
     $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';
     if (!isset($_GET['q'])) {
         throw new ActionException('Page', 'error404');
     }
     $limit = 100;
     $results = $this->model->search($_GET['q'], null, $limit, !$is_logged, $is_student);
     $posts_ids = array();
     $students_usernames = array();
     $groups_ids = array();
     foreach ($results as &$result) {
         switch ($result['_type']) {
             case 'student':
                 $students_usernames[] = $result['_id'];
                 break;
             case 'group':
                 $groups_ids[] = (int) $result['_id'];
                 break;
             case 'post':
                 $posts_ids[] = (int) $result['_id'];
                 break;
         }
     }
     $post_model = new Post_Model();
     $this->setTitle(__('SEARCH_TITLE', array('query' => htmlspecialchars($_GET['q']))));
     $this->set(array('query' => $_GET['q'], 'posts' => $post_model->getPosts(array('restricted' => true, 'ids' => $posts_ids, 'show_private' => $is_student), $limit), 'students' => Student_Model::getInfoByUsernames($students_usernames), 'groups' => Group_Model::getInfoByIds($groups_ids), 'is_logged' => true, 'is_student' => $is_student, 'is_admin' => $is_admin));
     if ($is_logged) {
         $this->set(array('username' => User_Model::$auth_data['username']));
     }
     if ($is_student) {
         $this->set(array('firstname' => User_Model::$auth_data['firstname'], 'lastname' => User_Model::$auth_data['lastname'], 'avatar_url' => User_Model::$auth_data['avatar_url']));
     }
 }
示例#3
0
 /**
  * Add a group
  */
 public function add($params)
 {
     $this->setView('add.php');
     $this->setTitle(__('GROUP_ADD_TITLE'));
     $is_logged = isset(User_Model::$auth_data);
     $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1';
     // Authorization
     if (!$is_admin) {
         throw new ActionException('Page', 'error404');
     }
     $group = array();
     // Saving data
     if (isset($_POST['name']) && isset($_POST['creation_date']) && isset($_POST['mail']) && isset($_POST['description'])) {
         $uploaded_files = array();
         try {
             // Members
             $members = array();
             if (isset($_POST['members_ids']) && is_array($_POST['members_ids'])) {
                 foreach ($_POST['members_ids'] as $id) {
                     if (ctype_digit($id)) {
                         $id = (int) $id;
                         $members[$id] = array('title' => isset($_POST['member_title_' . $id]) ? $_POST['member_title_' . $id] : '', 'admin' => isset($_POST['member_admin_' . $id]));
                     }
                 }
             }
             // Other info
             $data = array('name' => $_POST['name'], 'creation_date' => $_POST['creation_date'], 'mail' => $_POST['mail'], 'description' => $_POST['description'], 'members' => $members);
             // Avatar
             if (isset($_FILES['avatar']) && !is_array($_FILES['avatar']['name'])) {
                 if ($_FILES['avatar']['size'] > Config::UPLOAD_MAX_SIZE_PHOTO) {
                     throw new FormException('avatar');
                 }
                 if ($avatarpath = File::upload('avatar')) {
                     $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->getWidth() > 800) {
                             $img->setWidth(800, true);
                         }
                         $img->setType(IMAGETYPE_JPEG);
                         $img->save($avatarpath);
                         // Thumb
                         $avatarthumbpath = $avatarpath . '.thumb';
                         $img->thumb(Config::$AVATARS_THUMBS_SIZES[0], Config::$AVATARS_THUMBS_SIZES[1]);
                         $img->setType(IMAGETYPE_JPEG);
                         $img->save($avatarthumbpath);
                         unset($img);
                         $uploaded_files[] = $avatarthumbpath;
                         $data['avatar_path'] = $avatarthumbpath;
                         $data['avatar_big_path'] = $avatarpath;
                     } catch (Exception $e) {
                         throw new FormException('avatar');
                     }
                 }
             }
             $url_name = $this->model->create($data);
             Routes::redirect('group', array('group' => $url_name));
         } catch (FormException $e) {
             foreach ($uploaded_files as $uploaded_file) {
                 File::delete($uploaded_file);
             }
             foreach ($data as $key => $value) {
                 $group[$key] = $value;
             }
             $group['members'] = Student_Model::getInfoByUsersIds(array_keys($members));
             foreach ($group['members'] as &$member) {
                 if (isset($members[(int) $member['user_id']])) {
                     $member['title'] = $members[(int) $member['user_id']]['title'];
                     $member['admin'] = $members[(int) $member['user_id']]['admin'] ? '1' : '0';
                 }
             }
             $this->set('form_error', $e->getError());
         }
     }
     $this->set('group', $group);
     $this->addJSCode('Group.initEdit();');
 }
Session::init();
// Determine if a session doesn't exists and if the current user is not a student
if (!(Session::user_exist() && Session::get_Account_type() == "Student")) {
    // if it is, force the browser to redirect to the home page
    header('Location: /SOCS/index.php');
}
$sy_model = new SchoolYearSem_Model();
$signatory_model = new Signatory_Model();
$current_sy = $sy_model->getCurSchool_Year();
$current_sem = $sy_model->getCurSemester();
if ($current_sem != "Summer") {
    $current_sem .= " Semester";
}
$current_sysemID = $_GET["sy_sem_id"];
$stud_status = $_GET['status'] == "Grad" ? "Graduate" : "Under Graduate";
$student_model = new Student_Model();
$stud_id = Session::get_user();
$student_model->queryStudent_Info($stud_id);
$stud_name = $student_model->getStud_Name();
$stud_gender = $student_model->getStud_Gender();
$stud_year = $student_model->getStud_Yearlevel();
$stud_course = $student_model->getStud_Course();
$stud_dept = $student_model->getStud_DeptName();
$stud_deptID = $student_model->getStud_DeptID();
$signatorial_model = new SignatorialList_Model();
$signatorial_model->getListofSignatoryByDept($stud_deptID, $stud_status);
$listOfSignatories["name"] = $signatorial_model->getSign_Name();
$listOfSignatories["id"] = $signatorial_model->getSign_ID();
$clearance_model = new ClearanceStatus();
foreach ($listOfSignatories["id"] as $key => $value) {
    $status = $clearance_model->getOverallSignatoryClearanceStatus($stud_id, $value, $current_sysemID);
示例#5
0
文件: User.php 项目: hugonicolas/Site
    /**
     * Load data of an user into the $auth_data static var
     *
     * @param string $username	User name
     * @return boolean	True on success, false on failure
     */
    public function loadUser($username)
    {
        $users = DB::select('
			SELECT u.*, s.firstname, s.lastname, s.student_number, s.promo
			FROM users u
			LEFT JOIN students s ON s.username = u.username
			WHERE u.username = ?
		', array($username));
        if (isset($users[0])) {
            User_Model::$auth_data = $users[0];
        } else {
            throw new Exception('User not found');
        }
        //permet de checker l'autenticit� de l'admin
        if (isset(User_Model::$auth_data['admin']) && User_Model::$auth_data['admin'] == 1) {
            if (Cache::read('auth_admin')) {
                Cache::delete('auth_admin');
            }
            Cache::write('auth_admin', 1, 3600);
        }
        // If the user is a student
        if (isset(User_Model::$auth_data['student_number'])) {
            // Avatar
            User_Model::$auth_data['avatar_url'] = Student_Model::getAvatarURL(User_Model::$auth_data['student_number'], true);
            User_Model::$auth_data['avatar_big_url'] = Student_Model::getAvatarURL(User_Model::$auth_data['student_number'], false);
        }
    }
示例#6
0
文件: Post.php 项目: hugonicolas/Site
    /**
     * Returns the information of the N last posts, with attachments, surveys, events...
     * 
     * @param array $params	Associative array of paramaters. Possibles keys :
     *							* official: Only official posts if true, only non-official posts if false, all posts if null
     *							* show_private: Private posts include if true
     *							* category_id: Category's id
     *							* category_name: Category's name
     *							* group_id: Group's id
     *							* group_name: Group's name
     *							* user_id: User's id
     *							* id: ID of a post to get
     *							* ids: List of IDs of post to get
     *							* restricted: If true, limits the number of photos displayed
     * @param int $limit	Number of posts to be returned
     * @param int $offset	Number of posts to skip
     * @return array
     */
    public function getPosts($params, $limit, $offset = 0)
    {
        $cache_entry = 'posts-' . $limit . '-' . $offset;
        foreach ($params as $key => $value) {
            if (isset($value)) {
                $cache_entry .= '-' . $key . ':' . (is_array($value) ? implode(',', $value) : $value);
            }
        }
        $posts = Cache::read($cache_entry);
        if ($posts !== false) {
            return $posts;
        }
        $where = array();
        if (isset($params['group_id'])) {
            $where[] = 'p.group_id = ' . $params['group_id'];
        }
        if (isset($params['group_name'])) {
            $where[] = 'a.url_name = ' . DB::quote($params['group_name']);
        }
        if (isset($params['official'])) {
            $where[] = 'p.official = ' . ($params['official'] ? 1 : 0);
        }
        if (!isset($params['show_private']) || !$params['show_private']) {
            $where[] = 'p.private = 0';
        }
        if (isset($params['category_id'])) {
            $where[] = 'c.id = "' . $params['category_id'] . '"';
        }
        if (isset($params['category_name'])) {
            $where[] = 'c.url_name = ' . DB::quote($params['category_name']);
        }
        if (isset($params['user_id'])) {
            $where[] = 'p.user_id = ' . DB::quote($params['user_id']);
        }
        if (isset($params['ids']) && is_array($params['ids'])) {
            if (count($params['ids']) == 0) {
                return array();
            }
            $where[] = 'p.id IN (' . implode(',', $params['ids']) . ')';
        }
        if (isset($params['id']) && (is_int($params['id']) || ctype_digit($params['id']))) {
            $where[] = 'p.id = ' . $params['id'];
        }
        $posts = DB::select('
			SELECT
				p.id, p.message, p.time, p.private, p.official, p.category_id,p.dislike,
				a.id AS group_id, a.name AS group_name, a.url_name AS group_url,
				u.username,
				s.student_number, s.firstname, s.lastname
			FROM posts p
			INNER JOIN categories c ON c.id = p.category_id
			INNER JOIN users u ON u.id = p.user_id
			' . (isset($params['group_id']) || isset($params['group_name']) ? 'INNER' : 'LEFT') . ' JOIN groups a ON a.id = p.group_id
			LEFT JOIN students s ON s.username = u.username
			' . (count($where) != 0 ? 'WHERE ' . implode(' AND ', $where) : '') . '
			ORDER BY p.time DESC
			LIMIT ' . $offset . ', ' . $limit . '
		');
        if (count($posts) != 0) {
            if (isset($params['ids']) && is_array($params['ids'])) {
                Utils::arraySort($posts, 'id', $params['ids']);
            }
            $post_ids = array();
            foreach ($posts as $post) {
                $post_ids[] = (int) $post['id'];
            }
            // Comments
            $comments = DB::select('
				SELECT
					pc.post_id, pc.id, pc.message, pc.time, pc.attachment_id, pc.id,
					u.username,
					s.student_number, s.firstname, s.lastname
				FROM post_comments pc
				INNER JOIN users u ON u.id = pc.user_id
				INNER JOIN students s ON s.username = u.username
				WHERE pc.post_id IN (' . implode(',', $post_ids) . ')
				' . (isset($params['restricted']) && $params['restricted'] ? 'AND pc.attachment_id IS NULL' : '') . '
				ORDER BY pc.time ASC
			');
            $comment_likes = DB::select('
				SELECT
					pcl.comment_id, pcl.user_id as comment_like_user_id,
					u.username,
					s.student_number, s.firstname, s.lastname
				FROM post_comment_likes pcl
                                INNER JOIN post_comments pc ON pcl.comment_id = pc.id
				INNER JOIN users u ON u.id = pcl.user_id
				INNER JOIN students s ON s.username = u.username
				WHERE pc.post_id IN (' . implode(',', $post_ids) . ')
                                ' . (isset($params['restricted']) && $params['restricted'] ? 'AND pc.attachment_id IS NULL' : '') . '
			');
            $comments_by_post_id = array();
            foreach ($comments as $comment) {
                $post_id = (int) $comment['post_id'];
                if (!isset($comments_by_post_id[$post_id])) {
                    $comments_by_post_id[$post_id] = array();
                }
                unset($comment['post_id']);
                $comment['avatar_url'] = Student_Model::getAvatarURL($comment['student_number'], true);
                /* Traitement des Likes */
                foreach ($comment_likes as $comment_like) {
                    // Si c'est le like en question :
                    if ($comment['id'] == $comment_like['comment_id']) {
                        $comment['like'][] = $comment_like;
                        $comment['user_liked'][] = $comment_like['comment_like_user_id'];
                    }
                }
                $comments_by_post_id[$post_id][] = $comment;
            }
            unset($comments);
            // Posts Likes
            $likes = DB::select('
				SELECT
					li.post_id, li.id, li.user_id as like_user_id,li.attachment_id,
					u.username,
					s.firstname, s.lastname
				FROM post_likes li
				INNER JOIN users u ON u.id = li.user_id
				INNER JOIN students s ON s.username = u.username
				WHERE li.post_id IN (' . implode(',', $post_ids) . ')
                                ' . (isset($params['restricted']) && $params['restricted'] ? 'AND li.attachment_id IS NULL' : '') . '
				ORDER BY li.id DESC
			');
            $likes_by_post_id = array();
            $users_likes = array();
            foreach ($likes as $like) {
                // Les trie par post_id => puis par $attachement_id
                $post_id = (int) $like['post_id'];
                // On Extrait le n° d'attachment
                if ($like['attachment_id'] == null) {
                    $attachment_id = 0;
                } else {
                    $attachment_id = (int) $like['attachment_id'];
                }
                if (empty($likes_by_post_id[$post_id][$attachment_id])) {
                    $likes_by_post_id[$post_id][$attachment_id] = array();
                }
                // Pour savoir qui a "Aimé"
                if (empty($users_likes[$post_id][$attachment_id])) {
                    $users_likes[$post_id][$attachment_id] = array();
                }
                $users_likes[$post_id][$attachment_id][] = $like['like_user_id'];
                unset($like['post_id']);
                unset($like['attachment_id']);
                $likes_by_post_id[$post_id][$attachment_id][] = $like;
            }
            unset($likes);
            // Posts Dislikes
            $dislikes = DB::select('
				SELECT
					dli.post_id, dli.id, dli.user_id as dislike_user_id,dli.attachment_id,
					u.username,
					s.firstname, s.lastname
				FROM post_dislikes dli
				INNER JOIN users u ON u.id = dli.user_id
				INNER JOIN students s ON s.username = u.username
				WHERE dli.post_id IN (' . implode(',', $post_ids) . ')
                                ' . (isset($params['restricted']) && $params['restricted'] ? 'AND dli.attachment_id IS NULL' : '') . '
				ORDER BY dli.id DESC
			');
            $dislikes_by_post_id = array();
            $users_dislikes = array();
            foreach ($dislikes as $dislike) {
                // Les trie par post_id => puis par $attachement_id
                $post_id = (int) $dislike['post_id'];
                // On Extrait le n° d'attachment
                if ($dislike['attachment_id'] == null) {
                    $attachment_id = 0;
                } else {
                    $attachment_id = (int) $dislike['attachment_id'];
                }
                if (empty($dislikes_by_post_id[$post_id][$attachment_id])) {
                    $dislikes_by_post_id[$post_id][$attachment_id] = array();
                }
                // Pour savoir qui a "Aimé"
                if (empty($users_dislikes[$post_id][$attachment_id])) {
                    $users_dislikes[$post_id][$attachment_id] = array();
                }
                $users_dislikes[$post_id][$attachment_id][] = $dislike['dislike_user_id'];
                unset($dislike['post_id']);
                unset($dislike['attachment_id']);
                $dislikes_by_post_id[$post_id][$attachment_id][] = $dislike;
            }
            unset($dislikes);
            //                        echo '<pre>';
            //                            print_r($likes_by_post_id);
            //                        echo '</pre>';
            // Attachments
            $attachments = DB::select('
				SELECT post_id, id, name, ext
				FROM attachments
				WHERE post_id IN (' . implode(',', $post_ids) . ')
				ORDER BY ext, id ASC
			');
            $attachments_by_post_id = array();
            $nb_photos_by_post_id = array();
            foreach ($attachments as $attachment) {
                $post_id = (int) $attachment['post_id'];
                // Limitation of the number of displayed photos
                if (in_array($attachment['ext'], array('jpg', 'png', 'gif'))) {
                    if (!isset($nb_photos_by_post_id[$post_id])) {
                        $nb_photos_by_post_id[$post_id] = 0;
                    }
                    $nb_photos_by_post_id[$post_id]++;
                    if (isset($params['restricted']) && $params['restricted'] && $nb_photos_by_post_id[$post_id] > Config::PHOTOS_PER_POST) {
                        continue;
                    }
                }
                $attachment['url'] = self::getAttachedFileURL((int) $attachment['id'], $attachment['ext']);
                if (in_array($attachment['ext'], array('jpg', 'png', 'gif', 'flv', 'mp4'))) {
                    $attachment['thumb'] = self::getAttachedFileURL((int) $attachment['id'], 'jpg', 'thumb');
                }
                if (!isset($attachments_by_post_id[$post_id])) {
                    $attachments_by_post_id[$post_id] = array();
                }
                unset($attachment['post_id']);
                $attachments_by_post_id[$post_id][] = $attachment;
            }
            unset($attachments);
            // Events
            $events = DB::select('
				SELECT post_id, id, title, date_start, date_end
				FROM events
				WHERE post_id IN (' . implode(',', $post_ids) . ')
			');
            $events_by_post_id = array();
            foreach ($events as $event) {
                $post_id = (int) $event['post_id'];
                unset($event['post_id']);
                $events_by_post_id[$post_id] = $event;
            }
            unset($events);
            // Surveys
            $surveys = DB::select('
				SELECT post_id, id, question, multiple, date_end
				FROM surveys
				WHERE post_id IN (' . implode(',', $post_ids) . ')
			');
            $surveys_by_post_id = array();
            if (count($surveys) != 0) {
                $surveys_ids = array();
                foreach ($surveys as $survey) {
                    $surveys_ids[] = (int) $survey['id'];
                }
                $survey_answers = DB::select('
					SELECT id, survey_id, answer, nb_votes, votes 
					FROM survey_answers
					WHERE survey_id IN (' . implode(',', $surveys_ids) . ')
					ORDER BY id ASC
				');
                $survey_answers_by_survey_id = array();
                foreach ($survey_answers as $survey_answer) {
                    $survey_id = (int) $survey_answer['survey_id'];
                    unset($survey_answer['survey_id']);
                    if (!isset($survey_answers_by_survey_id[$survey_id])) {
                        $survey_answers_by_survey_id[$survey_id] = array();
                    }
                    $survey_answers_by_survey_id[$survey_id][] = $survey_answer;
                }
                unset($survey_answers);
                foreach ($surveys as $survey) {
                    $post_id = (int) $survey['post_id'];
                    unset($survey['post_id']);
                    $survey['answers'] = isset($survey_answers_by_survey_id[(int) $survey['id']]) ? $survey_answers_by_survey_id[(int) $survey['id']] : array();
                    $surveys_by_post_id[$post_id] = $survey;
                }
                unset($survey_answers_by_survey_id);
            }
            unset($surveys);
            foreach ($posts as &$post) {
                $post_id = (int) $post['id'];
                if (isset($comments_by_post_id[$post_id])) {
                    $post['comments'] =& $comments_by_post_id[$post_id];
                }
                if (isset($likes_by_post_id[$post_id])) {
                    $post['likes']['data'] =& $likes_by_post_id[$post_id];
                }
                if (isset($users_likes[$post_id])) {
                    $post['likes']['users'] =& $users_likes[$post_id];
                }
                if (isset($dislikes_by_post_id[$post_id])) {
                    $post['dislikes']['data'] =& $dislikes_by_post_id[$post_id];
                }
                if (isset($users_dislikes[$post_id])) {
                    $post['dislikes']['users'] =& $users_dislikes[$post_id];
                }
                if (isset($attachments_by_post_id[$post_id])) {
                    $post['attachments'] =& $attachments_by_post_id[$post_id];
                }
                if (isset($events_by_post_id[$post_id])) {
                    $post['event'] =& $events_by_post_id[$post_id];
                }
                if (isset($surveys_by_post_id[$post_id])) {
                    $post['survey'] =& $surveys_by_post_id[$post_id];
                }
                $post['attachments_nb_photos'] = isset($nb_photos_by_post_id[$post_id]) ? $nb_photos_by_post_id[$post_id] : 0;
                // Avatar
                if (isset($post['group_id']) && $post['official'] == '1') {
                    $post['avatar_url'] = Group_Model::getAvatarURL((int) $post['group_id'], true);
                } else {
                    if (isset($post['student_number'])) {
                        $post['avatar_url'] = Student_Model::getAvatarURL((int) $post['student_number'], true);
                    }
                }
            }
        }
        // Write the cache
        Cache::write($cache_entry, $posts, 20 * 60);
        $cache_list = Cache::read('posts-cachelist');
        if (!$cache_list) {
            $cache_list = array();
        }
        if (!in_array($cache_entry, $cache_list)) {
            $cache_list[] = $cache_entry;
        }
        Cache::write('posts-cachelist', $cache_list, 20 * 60);
        return $posts;
    }
示例#7
0
define('CLI_MODE', true);
define('APP_DIR', realpath(dirname(__FILE__) . '/../') . '/');
define('CF_DIR', realpath(dirname(__FILE__) . '/../../confeature/') . '/');
define('DATA_DIR', realpath(dirname(__FILE__) . '/../../data/') . '/');
try {
    // Loading Confeature
    require_once CF_DIR . 'init.php';
    $avatars_tmp_path = DATA_DIR . Config::DIR_DATA_TMP . '/avatars';
    if (!is_dir($avatars_tmp_path)) {
        throw new Exception($avatars_tmp_path . ' not found!');
    }
    $students = DB::createQuery('students')->fields('student_number', 'firstname', 'lastname')->select();
    foreach ($students as $student) {
        try {
            $avatar_path = Student_Model::getAvatarPath((int) $student['student_number']);
            $avatar_thumb_path = Student_Model::getAvatarPath((int) $student['student_number'], true);
            if (file_exists($avatar_path)) {
                continue;
            }
            $original_path = $avatars_tmp_path . '/' . $student['student_number'] . '.jpg';
            if (!file_exists($original_path)) {
                throw new Exception('Photo of the student n°' . $student['student_number'] . ' (' . $student['firstname'] . ' ' . $student['lastname'] . ') not found!');
            }
            $avatar_dir = File::getPath($avatar_path);
            if (!is_dir($avatar_dir)) {
                File::makeDir($avatar_dir, 0777, true);
            }
            File::copy($original_path, $avatar_path);
            // Thumb
            $img = new Image();
            $img->load($original_path);
示例#8
0
    /**
     * Load data of an user into the $auth_data static var
     *
     * @param string $username	User name
     * @return boolean	True on success, false on failure
     */
    public function loadUser($username)
    {
        $users = DB::select('
			SELECT u.*, s.firstname, s.lastname, s.student_number, s.promo
			FROM users u
			LEFT JOIN students s ON s.username = u.username
			WHERE u.username = ?
		', array($username));
        if (isset($users[0])) {
            User_Model::$auth_data = $users[0];
        } else {
            throw new Exception('User not found');
        }
        // If the user is a student
        if (isset(User_Model::$auth_data['student_number'])) {
            // Avatar
            User_Model::$auth_data['avatar_url'] = Student_Model::getAvatarURL(User_Model::$auth_data['student_number'], true);
            User_Model::$auth_data['avatar_big_url'] = Student_Model::getAvatarURL(User_Model::$auth_data['student_number'], false);
        }
    }
示例#9
0
 public function usersPage($param)
 {
     $this->setView('users.php');
     /*
      * Enregistrement du post dans la table users	
      */
     if (isset($_FILES['uploadxml1']) && $_FILES['uploadxml1']['name'] != null) {
         if ($_FILES['uploadxml1']['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 vers le serveur
         if ($filepaths = File::upload('uploadxml1')) {
             if (!preg_match('#\\.xml$#', $filepaths)) {
                 throw new Exception(__('POST_ADD_ERROR_FILE_FORMAT'));
             }
             $name = $filepaths;
         }
         $student = array();
         $path = DATA_DIR . Config::DIR_DATA_TMP . $_FILES['uploadxml1']['name'];
         if (file_exists($path)) {
             $data = simplexml_load_file($path);
             foreach ($data->data as $data) {
                 if (isset($data->username) && isset($data->admin) && isset($data->mail) && isset($data->msn) && isset($data->jabber) && isset($data->address) && isset($data->address) && isset($data->zipcode) && isset($data->city) && isset($data->cellphone) && isset($data->phone) && isset($data->birthday)) {
                     $username = $data->username;
                     $admin = $data->admin;
                     $mail = $data->mail;
                     $msn = $data->msn;
                     $jabber = $data->jabber;
                     $address = $data->address;
                     $zipcode = $data->zipcode;
                     $city = $data->city;
                     $cellphone = $data->cellphone;
                     $phone = $data->phone;
                     $birthday = $data->birthday;
                     if (!$this->model->checkuser($username, 1)) {
                         $this->model->insertUsers($username, $admin, utf8_decode($mail), utf8_decode($msn), utf8_decode($jabber), utf8_decode($address), $zipcode, $city, $cellphone, $phone, $birthday);
                     } else {
                         array_push($student, $username);
                     }
                 } else {
                     throw new Exception(__('ADMIN_UPLOAD_ERROR2'));
                 }
             }
         } else {
             throw new Exception(__('ADMIN_UPLOAD_ERROR'));
         }
         FILE::delete($path);
         $this->set('fail', $student);
     }
     /*
      * Enregistrement du post dans la table students
      */
     if (isset($_FILES['uploadxml2']) && $_FILES['uploadxml2']['name'] != null) {
         if ($_FILES['uploadxml2']['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('uploadxml2')) {
             if (!preg_match('#\\.xml$#', $filepaths)) {
                 throw new Exception(__('POST_ADD_ERROR_FILE_FORMAT'));
             }
             $name = $filepaths;
         }
         $student = array();
         $path = DATA_DIR . Config::DIR_DATA_TMP . $_FILES['uploadxml2']['name'];
         if (file_exists($path)) {
             $data = simplexml_load_file($path);
             foreach ($data->data as $data) {
                 if (isset($data->username) && isset($data->lastname) && isset($data->firstname) && isset($data->student_number) && isset($data->promo) && isset($data->cesure)) {
                     $username = $data->username;
                     $lastname = $data->lastname;
                     $firstname = $data->firstname;
                     $student_number = $data->student_number;
                     $promo = $data->promo;
                     $cesure = $data->cesure;
                     if (!$this->model->checkuser($username, 2)) {
                         $this->model->insertStudents($username, utf8_decode($lastname), utf8_decode($firstname), $student_number, $promo, $cesure);
                     } else {
                         array_push($student, $username);
                     }
                 } else {
                     throw new Exception(__('ADMIN_UPLOAD_ERROR2'));
                 }
             }
         } else {
             throw new Exception(__('ADMIN_UPLOAD_ERROR'));
         }
         FILE::delete($path);
         $this->set('fail', $student);
     }
     /*
      * Enregistrement des avatars
      */
     if (isset($_FILES['avatar_photo']) && is_array($_FILES['avatar_photo']['name'])) {
         foreach ($_FILES['avatar_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))));
             }
         }
         $student = array();
         if ($avatarpaths = File::upload('avatar_photo')) {
             foreach ($avatarpaths as $avatarpath) {
                 $uploaded_files[] = $avatarpath;
             }
             foreach ($avatarpaths as $i => $avatarpath) {
                 $name = $_FILES['avatar_photo']['name'][$i];
                 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->getWidth() > 800) {
                         $img->setWidth(800, true);
                     }
                     $img->setType(IMAGETYPE_JPEG);
                     $img->save($avatarpath);
                     // Thumb
                     $avatarthumbpath = $avatarpath . '.thumb';
                     $img->thumb(Config::$AVATARS_THUMBS_SIZES[0], Config::$AVATARS_THUMBS_SIZES[1]);
                     $img->setType(IMAGETYPE_JPEG);
                     $img->save($avatarthumbpath);
                     unset($img);
                     $uploaded_files[] = $avatarthumbpath;
                     $student_data['avatar_path'] = $avatarthumbpath;
                     $student_data['avatar_big_path'] = $avatarpath;
                     $student_data['student_number'] = preg_replace('/\\.[a-z0-9]+$/i', '', $name);
                     if (isset($student_data['avatar_path']) && isset($student_data['student_number']) && File::exists($student_data['avatar_path'])) {
                         $avatar_path = Student_Model::getAvatarPath((int) $student_data['student_number'], true);
                         $avatar_dir = File::getPath($avatar_path);
                         if (!is_dir($avatar_dir)) {
                             File::makeDir($avatar_dir, 0777, true);
                         }
                         File::rename($student_data['avatar_path'], $avatar_path);
                     }
                     if (isset($student_data['avatar_big_path']) && isset($student_data['student_number']) && File::exists($student_data['avatar_big_path'])) {
                         $avatar_path = Student_Model::getAvatarPath((int) $student_data['student_number'], false);
                         $avatar_dir = File::getPath($avatar_path);
                         if (!is_dir($avatar_dir)) {
                             File::makeDir($avatar_dir, 0777, true);
                         }
                         File::rename($student_data['avatar_big_path'], $avatar_path);
                     }
                 } catch (Exception $e) {
                     array_push($student, $name);
                 }
             }
             $this->set('fail2', $student);
             foreach ($uploaded_files as $uploaded_file) {
                 File::delete($uploaded_file);
             }
         }
     }
 }
<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
ob_start();
include 'export.inc.php';
$content = ob_get_clean();
require_once '../libs/html2pdf/html2pdf.class.php';
try {
    $student_model = new Student_Model();
    $stud_id = Session::get_user();
    $student_model->queryStudent_Info($stud_id);
    $stud_name = $student_model->getStud_Name();
    $html2pdf = new HTML2PDF('P', 'Legal', 'en', true, 'UTF-8', array(15, 10, 15, 10));
    $html2pdf->pdf->SetDisplayMode('fullpage');
    $html2pdf->writeHTML($content);
    $html2pdf->Output("SOCS Clearance Export - {$stud_name}.pdf");
} catch (HTML2PDF_exception $e) {
    echo $e;
    exit;
}