コード例 #1
0
ファイル: View.php プロジェクト: rezachez/forum
 function render()
 {
     switch ($this->vars['page']) {
         case 'messages':
             $getter = new Getter();
             $user = $getter->getCurrentUser();
             $messages = $getter->getMessages();
             include './templates/header.php';
             include './templates/messages.php';
             include './templates/footer.php';
             break;
         case 'message':
             $getter = new Getter();
             $user = $getter->getCurrentUser();
             $message = $getter->getMessageById(array('messageId' => $this->vars['messageId']));
             include './templates/header.php';
             include './templates/message.php';
             include './templates/footer.php';
             break;
         case 'profile':
             $getter = new Getter();
             $user = $getter->getCurrentUser();
             include './templates/header.php';
             include './templates/profile.php';
             include './templates/footer.php';
             break;
         case 'foreignProfile':
             $getter = new Getter();
             $user = $getter->getCurrentUser();
             $foreignProfile = $getter->getUserById(array('userId' => $this->vars['userId']));
             include './templates/header.php';
             include './templates/foreignProfile.php';
             include './templates/footer.php';
             break;
         case 'vision':
             include './templates/vision.php';
             break;
     }
 }
コード例 #2
0
ファイル: Controller.php プロジェクト: rezachez/forum
 function updateProfile()
 {
     $user = $_SESSION['user'];
     $userUpdate = new User(array('email' => $_POST['email'], 'password' => $_POST['password'], 'name' => $_POST['name'], 'avatar' => pathinfo($_FILES['avatar']['name'])));
     $userVars = get_object_vars($userUpdate);
     foreach ($userVars as $i => $v) {
         if (!empty($v)) {
             if ($i == 'avatar') {
                 $avatarInfo = pathinfo($_FILES['avatar']['name']);
                 $avatarPath = "./files/images/avatars/{$user->id}.{$avatarInfo['extension']}";
                 move_uploaded_file($_FILES['avatar']['tmp_name'], $avatarPath);
                 try {
                     $this->dbh->query("\n                                update users\n                                set avatar = '{$avatarPath}'\n                                where id = {$user->id}\n                            ");
                 } catch (PDOException $e) {
                     echo $e->getMessage();
                     file_put_contents('./errors.txt', date('jS F Y H:i:s') . ' # ' . $e->getMessage() . PHP_EOL, FILE_APPEND);
                 }
             } else {
                 try {
                     $this->dbh->query("\n                                update users\n                                set {$i} = '{$v}'\n                                where id = {$user->id}\n                            ");
                 } catch (PDOException $e) {
                     echo $e->getMessage();
                     file_put_contents('./errors.txt', date('jS F Y H:i:s') . ' # ' . $e->getMessage() . PHP_EOL, FILE_APPEND);
                 }
             }
         }
     }
     $getter = new Getter();
     $_SESSION['user'] = $getter->getUserById(array('userId' => $user->id));
     header("location: index.php?page=profile");
 }