Example #1
0
 public function changePhotoAction()
 {
     header('Content-Type: application/json; charset=utf-8');
     header('Cache-Control: no-store, no-cache');
     header('Expires: ' . date('r'));
     $this->clearAvatarAction();
     $model = new UserUpdateTableModel();
     $model->setTable('user');
     $userId = Session::get('user_id');
     $model->setId($userId);
     $model->setPath(Path::USERIMG_UPLOAD_DIR);
     $model->setPhoto($_FILES['files']['name'][0]);
     $model->updateAvatar();
     $upload_handler = new UploadHandler(['upload_dir' => Path::USERIMG_UPLOAD_DIR, 'max_number_of_files' => 1, 'user_dirs' => true, 'isAvatar' => true]);
 }
 public function editUserAction()
 {
     $fc = FrontController::getInstance();
     $model = new AdminModel('Редактирование пользователя');
     $userModel = new UserUpdateTableModel();
     $userModel->setTable('user');
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         $userModel->setData('userUpdate');
         $userModel->updateRecord();
         header('Location: /admin/profile/id/' . $userModel->getId());
         exit;
     } else {
         $id = filter_var($fc->getParams()['id'], FILTER_SANITIZE_NUMBER_INT);
         if (!$id) {
             header('Location: /admin/notFound');
             exit;
         }
         $userModel->setId($id);
         $user = [];
         $db = DB::init()->connect();
         $userModel->readRecordsById();
         $userModel->readUserAddress();
         $userModel->readUserPhones();
         $roles = PrivilegedUser::getUserRoleById($db, $id);
         $model->setData(['profile' => $userModel->getRecordsById(), 'contacts' => $userModel->getUserContacts(), 'role' => $roles, 'allRoles' => Role::getRoles($db), 'perms' => Role::getRolePerms($db, $roles['role_id'])->getPermissions()]);
     }
     $output = $model->render('../views/admin/user/editUser.php', 'admin');
     $fc->setPage($output);
 }