コード例 #1
0
ファイル: Stats.php プロジェクト: BGCX067/faceutt-git
 public function execute($args = null)
 {
     if (!ServiceAuth::getInstance()->isAdmin()) {
         return header('Location: /admin/login');
     }
     ServiceRenderHtml::newInstance()->load('admin/stats')->setData('res1', CollectionAction::newInstance()->countDesc())->setData('res2', CollectionUser::newInstance()->findAllWithReputation())->setData('res3', CollectionUser_has_user::newInstance()->findAllCoworkers())->render();
 }
コード例 #2
0
ファイル: Profile.php プロジェクト: BGCX067/faceutt-git
    public function findByWithUser($names, $ids)
    {
        if (!is_array($ids)) {
            $ids = array($ids);
        }
        if (!is_array($names)) {
            $names = array($names);
        }
        $c = static::getModelName();
        $sth = ServiceDb::getInstance()->prepare('
				select `' . static::getTableName() . '`.*, `user`.*
				from `' . static::getTableName() . '`
				left join `user` on `user`.`id`=`' . static::getTableName() . '`.`user_id`
				where `' . implode('`=? and `', $names) . '`=?');
        $sth->execute($ids);
        $arr = array();
        foreach ($sth->fetchAll() as $data) {
            if ($data['id'] == ServiceAuth::getInstance()->getUser()->getId()) {
                continue;
            }
            $a = new ModelUser();
            $a->hydrate($data);
            $b = new $c();
            $b->hydrate($data);
            $a->setProfile($b);
            $arr[] = $a;
        }
        return $arr;
    }
コード例 #3
0
ファイル: Search.php プロジェクト: BGCX067/faceutt-git
 public function execute($args = null)
 {
     if (!ServiceAuth::getInstance()->isAuth()) {
         header('Location: /login');
     } else {
         if (empty($_POST)) {
             return ServiceRenderHtml::newInstance()->load('search')->render();
         }
         $res = array();
         if (isset($_POST['search1'])) {
             $res = CollectionProfile::newInstance()->findByWithUser('prog', $_POST['prog']);
         } elseif (isset($_POST['search2'])) {
             $res = CollectionProfile::newInstance()->findByWithUser(array('prog', 'semester'), array($_POST['prog'], $_POST['semester']));
         } elseif (isset($_POST['search3'])) {
             $res = CollectionProfile::newInstance()->findByWithUser('sex', $_POST['sex']);
         } elseif (isset($_POST['search4'])) {
             $resx = CollectionUser_has_user::newInstance()->findByWithUserLoose('user_id1', ServiceAuth::getInstance()->getUser()->getId());
             foreach ($resx as $v) {
                 $res[] = $v->getUser2();
             }
         } elseif (isset($_POST['search5'])) {
             $res = CollectionProfile::newInstance()->findAllWithUser();
         } else {
             return ControllerError::newInstance()->execute($args);
         }
         $_SESSION['search'] = $res;
         header('Location: /search/result');
     }
 }
コード例 #4
0
ファイル: Parameter.php プロジェクト: BGCX067/faceutt-git
 private function updateV($args)
 {
     $p = ServiceRenderJson::newInstance();
     $pro = ServiceAuth::getInstance()->getUser()->getProfile();
     if (isset($_POST['id'], $_POST['value'])) {
         if (!($u = $pro->getParameter($_POST['id']))) {
             $p->setData('success', false)->setData('message', 'Paramètre inconnu');
         } else {
             if (!ModelParameter::isValidVisibility($_POST['value'])) {
                 $p->setData('success', false)->setData('message', 'Valeur incorrecte');
             } else {
                 $u->setVisibility($_POST['value']);
                 // we persist the Profile, not the Parameter ! Be careful
                 if (ServiceDb::getInstance()->persist($pro)) {
                     $p->setData('success', true)->setData('message', 'La visibilité du paramètre a bien été modifiée');
                     ServiceDb::getInstance()->persist(ModelAction::newInstance()->setUser_id(ServiceAuth::getInstance()->getUser()->getId())->setType('update')->setObject('parameter visibility')->setValue($_POST['id'])->setWhen());
                 } else {
                     $p->setData('message', 'L\'opération a échoué !');
                 }
             }
         }
     } else {
         $p->setData('success', false);
     }
     $p->render();
 }
コード例 #5
0
ファイル: Photo.php プロジェクト: BGCX067/faceutt-git
 private function del($args)
 {
     $p = ServiceRenderJson::newInstance();
     $u = ServiceAuth::getInstance()->getUser();
     $i = $u->getId();
     if ($v = $this->getQueryNext()) {
         if (!($o = $u->getPhoto($v))) {
             $p->setData('success', false)->setData('message', 'Cette photo n\'existe pas !');
         } elseif ($o->getUser_id() != $i) {
             $p->setData('success', false)->setData('message', 'Cette photo n\'est pas la votre !');
         } else {
             if (!ServiceDb::getInstance()->delete($o)) {
                 $p->setData('message', 'L\'opération a échoué !');
             } else {
                 $p->setData('success', true)->setData('message', 'La photo a bien été supprimée');
                 $u->delPhoto($o);
                 $f = '../public/uploads/' . $o->getId();
                 //.'.'.$ext;
                 if (@unlink($f)) {
                     ServiceDb::getInstance()->persist(ModelAction::newInstance()->setUser_id($i)->setType('delete')->setObject('photo')->setValue($o->getId())->setWhen());
                 } else {
                     $p->setData('success', false)->setData('message', 'Erreur lors de la suppression de l\'image');
                 }
             }
         }
     } else {
         $p->setData('success', false);
     }
     $p->render();
 }
コード例 #6
0
ファイル: Home.php プロジェクト: BGCX067/faceutt-git
 public function execute($args = null)
 {
     if (!ServiceAuth::getInstance()->isAdmin()) {
         return header('Location: /admin/login');
     }
     ServiceRenderHtml::newInstance()->load('admin/home')->render();
 }
コード例 #7
0
ファイル: Subscribe.php プロジェクト: BGCX067/faceutt-git
 public function execute($args = null)
 {
     if (!empty($_POST)) {
         $_POST['id'] = null;
         $_POST['hash'] = ServiceAuth::createHash($_POST['pass1']);
         $_POST['inBounds'] = 0;
         $_POST['outBounds'] = 0;
         $u = ModelUser::newInstance()->hydrate($_POST);
         $p = ModelProfile::newInstance();
         if ($_POST['pass1'] != $_POST['pass2']) {
             ServiceMessage::getInstance()->addMessage('Les mots de passes ne correspondent pas', 'error');
         } elseif (CollectionUser::newInstance()->findBy('login', $_POST['login'])) {
             ServiceMessage::getInstance()->addMessage('Ce login est déjà utilisé', 'error');
         } else {
             if (ServiceDb::getInstance()->persist($u)) {
                 if ($i = ServiceDb::getInstance()->lastInsertId()) {
                     if (ServiceDb::getInstance()->persist($p->hydrate(array('user_id' => $i)))) {
                         ServiceMessage::getInstance()->addMessage('Votre compte a bien été créé', 'success');
                         ServiceDb::getInstance()->persist(ModelAction::newInstance()->setUser_id($i)->setType('create')->setObject('profile')->setWhen());
                         return header('Location: /logout/quiet');
                     } else {
                         ServiceDb::getInstance()->delete($u);
                         ServiceMessage::getInstance()->addMessage('Une erreur est survenue #2', 'error');
                     }
                 } else {
                     ServiceMessage::getInstance()->addMessage('Une erreur est survenue #1', 'error');
                 }
             }
         }
     }
     ServiceRenderHtml::newInstance()->load('subscribe')->setData('hideNavigation', true)->render();
 }
コード例 #8
0
ファイル: Relation.php プロジェクト: BGCX067/faceutt-git
 public function execute($args = null)
 {
     $p = ServiceRenderJson::newInstance();
     if (isset($_POST['id'], $_POST['type'], $_POST['action'])) {
         if (!($u = CollectionUser::newInstance()->find($_POST['id']))) {
             $p->setData('success', false)->setData('message', 'Membre inconnu');
         } else {
             $c = ($_POST['action'] == 'add' ? 'enable' : 'disable') . 'Type';
             $r = ServiceAuth::getInstance()->getUser()->getUser_has_user($u);
             $r->{$c}($_POST['type']);
             if (ServiceDb::getInstance()->persist($r)) {
                 $p->setData('success', true)->setData('message', 'La relation a bien été ' . ($_POST['action'] == 'add' ? 'ajoutée' : 'supprimée'));
                 ServiceDb::getInstance()->persist(ModelAction::newInstance()->setUser_id(ServiceAuth::getInstance()->getUser()->getId())->setObject('relation')->setValue($u->getLogin() . ' (' . ModelUser_has_user::$shortNames[$_POST['type']] . ')')->setType($_POST['action'] == 'add' ? 'create' : 'delete')->setWhen());
                 if ($r->getType() == 0) {
                     ServiceAuth::getInstance()->getUser()->delUser_has_user($r);
                     ServiceDb::getInstance()->delete($r);
                 } else {
                     ServiceAuth::getInstance()->getUser()->addUser_has_user($r);
                 }
             } else {
                 $p->setData('message', 'L\'opération a échoué !');
             }
         }
     } else {
         $p->setData('success', false);
     }
     $p->render();
 }
コード例 #9
0
ファイル: Lost.php プロジェクト: BGCX067/faceutt-git
 public function execute($args = null)
 {
     $p = ServiceRenderHtml::newInstance()->load('lost')->setData('page', $args)->setData('hideMessages', true);
     if (!ServiceAuth::getInstance()->isAuth()) {
         $p->setData('hideNavigation', true);
     }
     $p->render();
 }
コード例 #10
0
ファイル: Home.php プロジェクト: BGCX067/faceutt-git
 public function execute($args = null)
 {
     if (ServiceAuth::getInstance()->isAuth()) {
         header('Location: /profile');
     } else {
         header('Location: /login');
     }
 }
コード例 #11
0
ファイル: Admin.php プロジェクト: BGCX067/faceutt-git
 public function execute($args = null)
 {
     if (ServiceAuth::getInstance()->isAdmin()) {
         header('Location: /admin/home');
     } else {
         header('Location: /admin/login');
     }
 }
コード例 #12
0
ファイル: Logs.php プロジェクト: BGCX067/faceutt-git
 public function execute($args = null)
 {
     if (!ServiceAuth::getInstance()->isAdmin()) {
         return header('Location: /admin/login');
     }
     $res = CollectionAction::newInstance()->findAll();
     rsort($res);
     ServiceRenderHtml::newInstance()->load('admin/logs')->setData('res', $res)->render();
 }
コード例 #13
0
ファイル: Logout.php プロジェクト: BGCX067/faceutt-git
 public function execute($args = null)
 {
     setcookie('login', '', -1);
     setcookie('value', '', -1);
     ServiceAuth::getInstance()->deAuth();
     $v = $this->getQueryNext();
     if ($v != 'quiet') {
         ServiceMessage::getInstance()->addMessage('Vous avez bien été déconnecté', 'success');
     }
     header('Location: /home');
 }
コード例 #14
0
ファイル: Result.php プロジェクト: BGCX067/faceutt-git
 public function execute($args = null)
 {
     if (!ServiceAuth::getInstance()->isAuth()) {
         header('Location: /login');
     } else {
         if (isset($_SESSION['search'])) {
             $p = ServiceRenderHtml::newInstance()->load('search_result')->setData('result', $_SESSION['search'])->render();
         } else {
             header('Location: /search');
         }
     }
 }
コード例 #15
0
ファイル: Login.php プロジェクト: BGCX067/faceutt-git
 public function execute($args = null)
 {
     if (ServiceAuth::getInstance()->isAdmin()) {
         die(header('Location: /admin'));
     }
     if (!empty($_POST)) {
         if (ServiceAuth::getInstance()->adminAuth($_POST['password'])) {
             ServiceMessage::getInstance()->addMessage('Vous avez bien été connecté', 'success');
             header('Location: /admin');
             return;
         } else {
             ServiceMessage::getInstance()->addMessage('Mauvaise mot de passe', 'error');
         }
     }
     ServiceRenderHtml::newInstance()->load('admin/login')->setData('hideNavigation', true)->render();
 }
コード例 #16
0
ファイル: Profile.php プロジェクト: BGCX067/faceutt-git
 public function execute($args = null)
 {
     if (!ServiceAuth::getInstance()->isAuth()) {
         header('Location: /login');
     } else {
         $p = ServiceRenderHtml::newInstance()->load('profile')->setData('user', ServiceAuth::getInstance()->getUser())->setData('guest', false);
         if ($q = $this->getQueryNext()) {
             if ($q != ServiceAuth::getInstance()->getUser()->getLogin()) {
                 if ($user = CollectionUser::newInstance()->findBy('login', $q)) {
                     $p->setData('user', $user)->setData('guest', true);
                 } else {
                     $p->load('profile_not_found');
                 }
             }
         }
         $p->render();
     }
 }
コード例 #17
0
ファイル: Login.php プロジェクト: BGCX067/faceutt-git
 public function execute($args = null)
 {
     if (ServiceAuth::getInstance()->isAuth()) {
         die(header('Location: /home'));
     } elseif (ServiceAuth::getInstance()->isAdmin()) {
         die(header('Location: /admin'));
     }
     if (!empty($_POST)) {
         if (ServiceAuth::getInstance()->regularAuth($_POST['login'], $_POST['password'])) {
             if (isset($_POST['remember_me'])) {
                 setcookie('login', ServiceAuth::getInstance()->getUser()->getLogin(), time() + 3600 * 24 * 365);
                 setcookie('hash', ServiceAuth::getInstance()->getUser()->gethash(), time() + 3600 * 24 * 365);
             }
             ServiceMessage::getInstance()->addMessage('Vous avez bien été connecté', 'success');
             header('Location: /home');
             return;
         } else {
             ServiceMessage::getInstance()->addMessage('Mauvaise combinaison', 'error');
         }
     }
     ServiceRenderHtml::newInstance()->load('login')->setData('hideNavigation', true)->render();
 }
コード例 #18
0
ファイル: Html.php プロジェクト: BGCX067/faceutt-git
 public function render()
 {
     $hideNavigation = false;
     $hideMessages = false;
     extract(parent::getData());
     $_POST = @array_map_recursive('htmlspecialchars', $_POST);
     $_GET = @array_map_recursive('htmlspecialchars', $_GET);
     require 'View/header.php';
     if (!$hideNavigation) {
         require ServiceAuth::getInstance()->isAdmin() ? 'View/admin/nav.php' : 'View/nav.php';
     }
     require 'View/body.php';
     echo '<div id="messages"></div>';
     if (!$hideMessages && ServiceMessage::getInstance()->hasMessages()) {
         foreach (ServiceMessage::getInstance()->getMessages() as $v) {
             list($message, $level) = $v;
             require 'View/message.php';
         }
     }
     require 'View/' . $this->getFile() . '.php';
     require 'View/footer.php';
     return $this;
 }
コード例 #19
0
ファイル: User_has_user.php プロジェクト: BGCX067/faceutt-git
    public function findByWithUserLoose($names, $ids)
    {
        if (!is_array($names)) {
            $names = array($names);
        }
        if (!is_array($ids)) {
            $ids = array($ids);
        }
        $k = '';
        foreach (array_keys(ModelUser::newInstance()->getPersistentData()) as $v) {
            $k .= "`user2`.`{$v}` `a__{$v}`,";
        }
        $sth = ServiceDb::getInstance()->prepare('
				select `user_has_user`.*,
				' . $k . '
				`user2`.`id` `a__id`
				from `user_has_user`
				left join `user` `user2` on `user2`.`id`=`user_has_user`.`user_id2`
				where `' . implode('`=? or `', $names) . '`=?');
        $sth->execute($ids);
        $arr = array();
        foreach ($sth->fetchAll() as $data) {
            if ($data['a__id'] == ServiceAuth::getInstance()->getUser()->getId()) {
                continue;
            }
            $datax = array();
            foreach ($data as $k => $v) {
                if (strpos($k, 'a__') === 0) {
                    $datax[str_replace('a__', '', $k)] = $v;
                }
            }
            $a = ModelUser_has_user::newInstance()->hydrate($data);
            $a->setUser2(ModelUser::newInstance()->hydrate($datax));
            $arr[] = $a;
        }
        return $arr;
    }
コード例 #20
0
ファイル: Skill.php プロジェクト: BGCX067/faceutt-git
 private function del($args)
 {
     $p = ServiceRenderJson::newInstance();
     $u = ServiceAuth::getInstance()->getUser();
     $i = $u->getId();
     if ($v = $this->getQueryNext()) {
         if (!($o = $u->getSkill($v))) {
             $p->setData('success', false)->setData('message', 'Vous n\'avez pas cette compétence #1');
         } elseif ($o->getUser_id() != $u->getId()) {
             $p->setData('success', false)->setData('message', 'Vous n\'avez pas cette compétence #2');
         } else {
             if (!ServiceDb::getInstance()->delete($o)) {
                 $p->setData('message', 'L\'opération a échoué !');
             } else {
                 $p->setData('success', true)->setData('message', 'La compétence a bien été supprimée');
                 $u->delSkill($o);
                 ServiceDb::getInstance()->persist(ModelAction::newInstance()->setUser_id($i)->setType('delete')->setObject('skill')->setValue($o->getName())->setWhen());
             }
         }
     } else {
         $p->setData('success', false);
     }
     $p->render();
 }
コード例 #21
0
ファイル: profile.php プロジェクト: BGCX067/faceutt-git
    if ($a = $user->getSkills()) {
        foreach ($a as $v) {
            echo '<li>' . $v->getName() . '<a href="/parameter/skill/del/' . $v->getId() . '" class="btn btn-danger btn-small delete">Supprimer</a></li>';
        }
    } else {
        echo '<li class="empty">Pas de compétence</li>';
    }
    echo '</ul>';
    if (!$guest) {
        echo '<form  style="margin-top:10px" action="/parameter/skill/add" method="post" class="form-search"><div class="input-append"><input type="text" name="value" value="" class="btn-small search-query" placeholder="Ajouter une compétence" required="required" style="line-height:100%" /><input type="submit" value="Valider" class="btn btn-small" /></div></form>';
    }
    ?>
</dd>
<?php 
}
if (!$guest || ServiceAuth::getInstance()->getUser()->isAllowedToSee($user, 'photos')) {
    ?>
			<dt class="visibility-<?php 
    echo $user->getProfile()->getParameter('photos')->getVisibility();
    ?>
">Liste de photos<?php 
    if (!$guest) {
        echo showDropDown($user->getProfile()->getParameter('photos'));
    }
    ?>
</dt>
			<dd class="update-photo"><?php 
    echo '<ul>';
    if ($a = $user->getPhotos()) {
        foreach ($a as $v) {
            echo '<li><a href="/uploads/' . $v->getId() . '" target="_blank">Image #' . $v->getId() . '</a><a href="/parameter/photo/del/' . $v->getId() . '" class="btn btn-danger btn-small delete">Supprimer</a></li>';