Esempio n. 1
0
 public function user_edit()
 {
     // auth
     Auth::isAdminAuthorized($this->signedUser, 'admin.user', true, '/user');
     // check
     $save = Converter::string('save', 'post');
     $id = \Rebond\Util\Converter::int('id');
     $user = \Rebond\Core\User\Data::loadById($id, true);
     $id = $user->getId();
     $form = new \Rebond\Core\User\Form($user);
     // action
     if (isset($save)) {
         Auth::isAdminAuthorized($this->signedUser, 'admin.user.edit', true, '/user/edit?id=' . $id);
         if ($form->setFromPost()->validate()->isValid()) {
             if ($user->getId() == 0) {
                 $user->setPassword(\Rebond\Util\Security::encryptPassword($user->getPassword()));
             }
             $user->save();
             $userSettings = \Rebond\Cms\UserSettings\Data::loadByUserId($user->getId());
             if (!isset($userSettings)) {
                 $userSettings = new \Rebond\Cms\UserSettings\Model();
                 $userSettings->setUserId($user->getId());
                 $userSettings->save();
             }
             Session::adminSuccess('saved', '/user');
         } else {
             Session::set('adminError', $form->getValidation()->getMessage());
         }
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Template(Template::MODULE, ['core', 'user']);
     $tplMain->set('item', $form);
     // layout
     if (Auth::isAdminAuthorized($this->signedUser, 'admin.user.edit', false)) {
         if ($id == 0) {
             $this->tplLayout->set('column1', $tplMain->render('register'));
         } else {
             $this->tplLayout->set('column1', $tplMain->render('editor'));
         }
     } else {
         $this->tplLayout->set('column1', $tplMain->render('view'));
     }
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     $this->tplMaster->set('jsLauncher', 'userEdit');
     return $this->tplMaster->render('tpl-default');
 }
Esempio n. 2
0
 public function selectMedia()
 {
     if (!$this->hasPrivilege('admin.content.edit')) {
         return $this->noPrivilege('admin.content.edit');
     }
     $json = [];
     $json['result'] = ResultType::ERROR;
     // check
     $field = Converter::string('field', 'post');
     $hashParam = Converter::string('hash', 'post');
     $search = Converter::string('search', 'post');
     if (!isset($field) || !isset($hashParam)) {
         $json['message'] = Lang::lang('errorInvalidParameters');
         return json_encode($json);
     }
     $hash = explode('/', $hashParam);
     $hash = array_slice($hash, 1);
     $folderId = isset($hash[0]) && $hash[0] != '' ? (int) $hash[0] : 0;
     $page = isset($hash[1]) && $hash[1] != '' ? (int) $hash[1] : 1;
     $type = isset($hash[2]) && $hash[2] != '' ? $hash[2] : 'all';
     $order = isset($hash[3]) && $hash[3] != '' ? $hash[3] : 'modified_date';
     $orderType = isset($hash[4]) && $hash[4] != '' ? $hash[4] : 'desc';
     if (!in_array($type, ['all', 'images', 'videos', 'documents'])) {
         $type = 'all';
     }
     if (!in_array($order, ['title', 'extension', 'modified_date'])) {
         $order = 'modified_date';
     }
     if (!in_array($orderType, ['asc', 'desc'])) {
         $orderType = 'desc';
     }
     $options = [];
     $options['where'][] = 'media.status = 1';
     $options['where'][] = 'media.is_selectable = 1';
     if ($folderId != 0) {
         $options['where'][] = ['media.folder_id = ?', $folderId];
     }
     if (isset($search) && $search != '') {
         $options['where'][] = ['media.title LIKE ?', '%' . $search . '%'];
     }
     if ($type != 'all') {
         switch ($type) {
             case 'images':
                 $options['where'][] = 'media.extension IN ("jpg", "jpeg", "png")';
                 break;
             case 'videos':
                 $options['where'][] = 'media.extension IN ("avi", "mov")';
                 break;
             case 'documents':
                 $options['where'][] = 'media.extension IN ("pdf", "xls", "xlsx", "doc", "docx")';
                 break;
         }
     }
     $mediaCount = \Rebond\Core\Media\Data::count($options);
     // get user settings
     $userSettings = \Rebond\Cms\UserSettings\Data::loadByUserId($this->signedUser->getId());
     $mediaView = 'grid';
     $mediaListCount = 10;
     if (isset($userSettings)) {
         $mediaView = $userSettings->getMediaView() == 0 ? 'grid' : 'list';
         $mediaListCount = (int) $userSettings->getMediaPagingValue();
     }
     if ($page < 1) {
         $page = 1;
     }
     if ($page > ceil($mediaCount / $mediaListCount) && $mediaCount > 0) {
         $page = ceil($mediaCount / $mediaListCount);
     }
     $folders = \Rebond\Core\Folder\Service::renderList();
     // add paging and order
     $options['order'][] = 'media.' . $order . ' ' . $orderType;
     $options['limit'][] = ($page - 1) * $mediaListCount . ', ' . $mediaListCount;
     $media = \Rebond\Core\Media\Data::loadAll($options);
     $tpl = new Template(Template::MODULE, ['core', 'media']);
     $tpl->set('items', $media);
     $tpl->set('field', $field);
     $tplFilter = new Template(Template::MODULE, ['core', 'media']);
     $tplFilter->set('current', $page);
     $tplFilter->set('folders', $folders);
     $tplFilter->set('maxByPage', $mediaListCount);
     $tplFilter->set('count', $mediaCount);
     $tplFilter->set('mediaView', $mediaView);
     $tplFilter->set('order', $order . '_' . $orderType);
     $tplFilter->set('type', $type);
     $tplFilter->set('folderId', $folderId);
     $tplFilter->set('hash', '#!/' . $folderId . '/' . $page . '/' . $type . '/' . $order . '/' . $orderType);
     $tplFilter->set('search', $search);
     $json['result'] = ResultType::SUCCESS;
     $json['message'] = Lang::lang('listUpdated') . ' (' . count($media) . ')';
     $json['html'] = $tplFilter->render('select-filter');
     $json['html'] .= $tpl->render('select-' . $mediaView);
     return json_encode($json);
 }