示例#1
0
 private function getBooks($project_id, $page = 1)
 {
     if (!Session::exists('member')) {
         Router::redirect('home.index');
     }
     $nb = self::NUMBER_ITEM_PER_PAGE;
     $member = Session::get('member');
     $user = $this->checkUser($member['id'], $member['nickname']);
     $search = Helper::post('research');
     $project = Projects::select()->where('id', $project_id)->andWhere('id_leader', $member['id'])->get(0, 1);
     if (empty($project)) {
         Router::url('home.index');
     }
     $project = $project[0];
     $book = UsersBook::select()->addFields(['users_book.status' => 'status', 'F.id' => 'id_from', 'F.nickname' => 'nickname_from', 'T.id' => 'id_to', 'T.nickname' => 'nickname_to'])->innerJoin('users', 'F')->onJoin('F.id', '=', 'users_book.id_user_from')->innerJoin('users', 'T')->onJoin('T.id', '=', 'users_book.id_user_to')->where('status', 2)->andGroup([new Condition('WHERE', '', 'users_book.id_user_from', '!=', $project->id_client, false), new Condition('WHERE', 'AND', 'users_book.id_user_to', '!=', $project->id_client, false)])->andGroup([new Condition('WHERE', '', 'F.nickname', 'LIKE', '%' . $search . '%', false), new Condition('WHERE', 'OR', 'F.mail', 'LIKE', '%' . $search . '%', false), new Condition('WHERE', 'OR', 'T.nickname', 'LIKE', '%' . $search . '%', false), new Condition('WHERE', 'OR', 'T.mail', 'LIKE', '%' . $search . '%', false)])->andGroup([new Condition('WHERE', '', 'id_user_from', '=', $member['id'], false), new Condition('WHERE', 'OR', 'id_user_to', '=', $member['id'], false)])->get(($page - 1) * $nb, $nb);
     $count = UsersBook::select()->addFields(['COUNT(*)' => 'nb_row'])->innerJoin('users', 'F')->onJoin('F.id', '=', 'users_book.id_user_from')->innerJoin('users', 'T')->onJoin('T.id', '=', 'users_book.id_user_to')->where('status', 2)->andGroup([new Condition('WHERE', '', 'F.nickname', 'LIKE', '%' . $search . '%', false), new Condition('WHERE', 'OR', 'F.mail', 'LIKE', '%' . $search . '%', false), new Condition('WHERE', 'OR', 'T.nickname', 'LIKE', '%' . $search . '%', false), new Condition('WHERE', 'OR', 'T.mail', 'LIKE', '%' . $search . '%', false)])->andGroup([new Condition('WHERE', '', 'id_user_from', '=', $member['id'], false), new Condition('WHERE', 'OR', 'id_user_to', '=', $member['id'], false)])->get(0, 1)[0];
     $max_page = ceil($count->nb_row / $nb);
     if ($max_page == 0) {
         $max_page = 1;
     }
     $this->set('books', $book);
     $this->set('max_page', $max_page);
     $this->set('project', $project);
     $this->set('user', $user);
     $this->render('task/detail_user');
 }
示例#2
0
 public function update($id)
 {
     $this->checker('update_full_admin');
     if (Session::get('csrf') != Helper::post('_csrf')) {
         Router::redirect('home.index');
     }
     $user = Users::select()->where('id', $id)->get();
     if (empty($user)) {
         Router::redirect('home.index');
     }
     $modified = false;
     $user = $user[0];
     $nickname = Helper::post('nickname');
     if (!empty($nickname) && $nickname != $user->nickname) {
         $user->nickname = $nickname;
         $modified = true;
     }
     $firstname = Helper::post('firstname');
     if ($firstname != $user->firstname) {
         $user->firstname = $firstname;
         $modified = true;
     }
     $lastname = Helper::post('lastname');
     if ($lastname != $user->lastname) {
         $user->lastname = $lastname;
         $modified = true;
     }
     $id_group = Helper::post('group');
     if ($id_group != $user->id_group) {
         $user->id_group = $id_group;
         $modified = true;
     }
     $mail = Helper::post('mail');
     if (!empty($mail) && $mail != $user->mail) {
         $user->mail = $mail;
         $user->mail_check = sha1($user->user_key . '-----' . time());
         $user->mail_check_at = BaseModel::now();
         Users::sendMailCheck($user);
         $modified = true;
     }
     $result = Helper::post('deleteAvatar') != null;
     if ($result) {
         $user->avatar = '';
         $modified = true;
     }
     if ($modified) {
         $user->save();
     }
     Router::redirect('admin:user.show');
 }
示例#3
0
 public function update($id, $name)
 {
     $user = $this->checkUser($id, $name);
     if (Session::get('csrf') != Helper::post('_csrf')) {
         Router::redirect('home.index');
     }
     $modified = false;
     if (Helper::post('firstname') != null) {
         $user->firstname = Helper::post('firstname');
         $modified = true;
     }
     if (Helper::post('lastname') != null) {
         $user->lastname = Helper::post('lastname');
         $modified = true;
     }
     $password = [Helper::post('last_password'), Helper::post('new_password'), Helper::post('confirm_password')];
     if (password_verify($password[0], $user->password)) {
         if ($password[1] == $password[2]) {
             $user->password = password_hash($password[1], PASSWORD_BCRYPT);
             $modified = true;
         }
     }
     $result = Helper::post('showName') != null;
     if ($user->show_name != $result) {
         $user->show_name = $result ? 1 : 0;
         $modified = true;
     }
     $result = Helper::post('deleteAvatar') != null;
     if ($result) {
         $user->avatar = '';
         $modified = true;
     }
     if (isset($_FILES['avatar']['tmp_name']) && !empty($_FILES['avatar']['tmp_name']) && !$result) {
         $max_size = 10 * 1024 * 1024;
         if ($_FILES['avatar']['size'] > $max_size) {
             Session::setFlash('danger', '', Translate::get('user.modify.error.size'));
             Router::redirect('account.form', ['id' => $user->id, 'name' => $user->nickname]);
         }
         $extensions_valides = ['jpg', 'jpeg', 'gif', 'png'];
         $extension_upload = strtolower(substr(strrchr($_FILES['avatar']['name'], '.'), 1));
         if (!in_array($extension_upload, $extensions_valides)) {
             Session::setFlash('danger', '', Translate::get('user.modify.error.format'));
             Router::redirect('account.form', ['id' => $user->id, 'name' => $user->nickname]);
         }
         $old_avatar = 'public/img/avatar/' . $user->avatar;
         $name = time() . '-' . $user->id . '-avatar.png';
         if (file_exists(__DIR__ . '/../../' . $old_avatar)) {
             unlink(__DIR__ . '/../../' . $old_avatar);
         }
         $manager = new ImageManager();
         $manager->make($_FILES['avatar']['tmp_name'])->fit(128, 128)->save('public/img/avatar/' . $name);
         $user->avatar = $name;
         $modified = true;
     }
     if ($modified) {
         $user->save();
         Users::sessionSet($user);
         Session::setFlash('success', '', Translate::get('user.modify.success'));
     }
     Router::redirect('account.form', ['id' => $user->id, 'name' => $user->nickname]);
 }
示例#4
0
 public function newPassword()
 {
     Users::redirectIf(true);
     try {
         $user = Users::findOrFail('mail', Helper::post('mail'));
         $pass = Config::randomString(8);
         $user->password = password_hash($pass, PASSWORD_BCRYPT);
         $user->save();
         Users::resendPassword($user, $pass);
     } catch (\Exception $e) {
         Session::setFlash('danger', '', 'Aucun compte trouvée avec cette adresse email !');
     }
     Router::redirect('user.signin');
 }
示例#5
0
 public function update($id)
 {
     $this->checker('update_full_admin');
     if (Session::get('csrf') != Helper::post('_csrf')) {
         Router::redirect('home.index');
     }
     $group = Groups::select()->where('id', $id)->get();
     if (empty($group)) {
         Router::redirect('home.index');
     }
     $group = $group[0];
     $name = Helper::post('name');
     if (!empty($name) && $name != $group->name) {
         $group->name = $name;
     }
     $description = Helper::post('description');
     if (!empty($description) && $description != $group->description) {
         $group->description = $description;
     }
     $group->auth_site = '' . $this->calculBinaryRight('site');
     $group->auth_news = '' . $this->calculBinaryRight('news');
     $group->save();
     Router::redirect('admin:group.show');
 }
示例#6
0
 private function getForContact($page = 1)
 {
     if (!Session::exists('member')) {
         Router::redirect('home.index');
     }
     $nb = self::NUMBER_ITEM_PER_PAGE;
     $member = Session::get('member');
     $member = $this->checkUser($member['id'], $member['nickname']);
     $search = Helper::post('research');
     $all_contact = UsersBook::select()->where('id_user_from', $member->id)->orWhere('id_user_to', $member->id)->get();
     $list = [$member->id];
     foreach ($all_contact as $contact) {
         if ($contact->id_user_from == $member->id) {
             $list[] = $contact->id_user_to;
         } else {
             $list[] = $contact->id_user_from;
         }
     }
     $users = Users::select()->addFields(['users.id' => 'user_id', 'users.nickname' => 'user_nickname', 'users.mail' => 'user_mail'])->where('users.mail_check', '1')->andWhere('users.id', 'NOT IN', $list)->andGroup([new Condition('WHERE', '', 'users.nickname', 'LIKE', '%' . $search . '%', false), new Condition('WHERE', 'OR', 'users.mail', 'LIKE', '%' . $search . '%', false)])->get(($page - 1) * $nb, $nb);
     $count = Users::select()->addFields(['COUNT(*)' => 'nb_user'])->where('users.mail_check', '1')->andWhere('users.id', 'NOT IN', $list)->andGroup([new Condition('WHERE', '', 'users.nickname', 'LIKE', '%' . $search . '%', false), new Condition('WHERE', 'OR', 'users.mail', 'LIKE', '%' . $search . '%', false)])->get(0, 1);
     $max_page = 0;
     if (!empty($count)) {
         $count = $count[0];
         $max_page = ceil($count->nb_user / $nb);
     }
     if ($max_page == 0) {
         $max_page = 1;
     }
     $this->set('max_page', $max_page);
     $this->set('users', $users);
     $this->set('member', $member);
     $this->render('user/search');
 }
示例#7
0
 public function update($id)
 {
     Users::redirectIf(false);
     $member = Session::get('member');
     $project = Projects::select()->where('id', $id)->andWhere('id_leader', $member['id'])->get(0, 1);
     if (empty($project)) {
         Session::setFlash('danger', '', 'Vous n\'avez pas l\'autorisation de modifier ce projet !');
         Router::redirect('task:home.index');
     }
     $project = $project[0];
     $modified = false;
     $name = Helper::post('name');
     if (!empty($name) && $project->name != $name) {
         $project->name = $name;
         $modified = true;
     }
     $description = Helper::post('description');
     if (!empty($description) && $project->description != $description) {
         $project->description = $description;
         $modified = true;
     }
     $price = Helper::post('price');
     if (!empty($price) && $project->price != $price) {
         $project->price = $price;
         $modified = true;
     }
     $date = Helper::post('date');
     $hour = Helper::post('hour');
     $deadline = $project->deadline;
     if (!empty($date) && !empty($hour)) {
         try {
             $dl = new \DateTime($date . ' ' . $hour);
             $now = new \DateTime();
             if ($now < $dl) {
                 $deadline = $dl->format('Y-m-d H:i:s');
             }
         } catch (\Exception $e) {
             // Nothing do
         }
     }
     if ($deadline != $project->deadline) {
         $project->deadline = $deadline;
         $modified = true;
     }
     if ($modified) {
         $project->save();
         Session::setFlash('success', '', 'Vos modifications ont été prise en compte !');
     }
     Router::redirect('task:home.index');
 }