Ejemplo n.º 1
0
 public static function isAuthorized(\Rebond\Core\User\Model $user, $permission = null, $show = true, $redirect = null)
 {
     if (!isset($permission) || $permission == '') {
         return true;
     }
     if (!self::isAuth($user)) {
         if (isset($redirect)) {
             header('Location: ' . $redirect);
             exit;
         }
         return false;
     }
     $auth = \Rebond\Core\User\Data::hasAccess($user->getId(), $permission, false);
     if ($auth != 0) {
         return true;
     }
     if ($show) {
         Session::add('siteError', Lang::lang('errorAccess', [$permission]));
     }
     Log::log(Error::NOT_ENOUGH_PRIVILEGE, Lang::lang('errorAccess', [$permission]), __FILE__, __LINE__);
     if (isset($redirect)) {
         header('Location: ' . $redirect);
         exit;
     }
     return false;
 }
Ejemplo n.º 2
0
 public function buy_credit()
 {
     // auth
     Util\Auth::isAuthorized($this->signedUser, 'member', true, '/');
     $playerForm = new \Own\Bus\Player\Form($this->player, 'player');
     $credits = $this->player->getCredits();
     $this->player->setCredits(0);
     // action
     $add = Util\Converter::toString('add', 'post');
     if (isset($add)) {
         $creditValidation = ['required' => true, 'integer' => true, 'minValue' => 1, 'maxValue' => 20];
         $playerForm->setFromPost(['credits']);
         $fieldCredits = Util\Validate::validate('credits', $playerForm->getModel()->getCredits(), $creditValidation);
         $validation = new \Rebond\Core\Form();
         $validation->addField($fieldCredits);
         $playerForm->setValidation($validation);
         if ($playerForm->getValidation()->isValid()) {
             $this->player->addCredits($credits);
             $this->player->save();
             Util\Session::siteSuccess('creditsBought', '/profile');
         } else {
             Util\Session::set('siteError', $playerForm->getValidation()->getMessage());
         }
     }
     // layout
     $tplPlayer = new Util\Template(Util\Template::MODULE, ['bus', 'player']);
     $tplPlayer->set('credits', $credits);
     $tplPlayer->set('player', $playerForm);
     return $this->response('tpl-default', ['title' => Util\Lang::lang('profile')], 'layout-home', ['column1' => $tplPlayer->render('buy-credit')]);
 }
Ejemplo n.º 3
0
 public function form()
 {
     $simple = new \Rebond\Bus\Simple\Form();
     $post = Util\Converter::string('send', 'post');
     if (isset($post)) {
         if ($simple->setFromPost()->validate()->isValid()) {
             $result = Util\Media::UploadForm('photoId');
             if ($result->result == ResultType::SUCCESS) {
                 $simple->setPhotoId($result->id);
             }
             if ($result->result != ResultType::ERROR) {
                 $simple->save();
                 Util\Session::set('siteSuccess', 'submitted');
             } else {
                 Util\Session::set('siteError', $result->message);
             }
         } else {
             Util\Session::set('siteError', 'invalid');
         }
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Util\Template(Util\Template::MODULE, ['bus', 'simple']);
     $tplMain->set('item', $simple);
     // layout
     $this->tplLayout->set('column1', $tplMain->render('form'));
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-2-col'));
     return $this->tplMaster->render('tpl-default');
 }
Ejemplo n.º 4
0
Archivo: Base.php Proyecto: vincium/lot
 public function __construct(\Rebond\App $app)
 {
     if ($app->site()->getStatus() == \Rebond\Core\StatusType::INACTIVE) {
         Util\Session::redirect('/error/maintenance');
     }
     parent::__construct($app);
     if ($this->signedUser->getId() != 0) {
         $this->player = \Own\Bus\Player\Data::loadByUserId($this->signedUser->getId());
         if ($this->player == null) {
             $this->player = \Own\Bus\Player\Service::create($this->signedUser);
         }
     } else {
         $this->player = new \Own\Bus\Player\Model();
     }
 }
Ejemplo n.º 5
0
 public function ranking()
 {
     $id = Converter::toInt('id', 'get', $this->player->getLeagueId());
     $league = \Own\Bus\League\Data::loadById($id);
     if (!isset($league)) {
         $league = $this->player->getLeague();
     }
     // player not logged in
     if (!isset($league)) {
         Session::redirect('/league');
     }
     // view
     $this->setTpl();
     $cacheTime = $this->app->site()->getCacheTime();
     $cache = \Rebond\Util\Cache::getCache('league-ranking', $league->getId(), $cacheTime);
     if (isset($cache)) {
         // layout
         $this->tplLayout->set('column1', $cache);
     } else {
         $options = [];
         $options['clearSelect'] = true;
         $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'user_id', 'country', 'experience', 'username', 'league_ranking', 'league_point', 'league_diff']);
         $options['select'][] = \Rebond\Core\User\Data::getList(['id', 'avatar_id'], 'player_user');
         $options['select'][] = \Rebond\Core\Media\Data::getList([], 'player_user_avatar');
         $options['leftJoin'][] = 'core_user player_user ON player_user.id = player.user_id';
         $options['leftJoin'][] = 'core_media player_user_avatar ON player_user_avatar.id = player_user.avatar_id';
         $options['where'][] = 'player.active = 1';
         $options['where'][] = 'player.league_id = ' . $league->getId();
         $options['order'][] = 'player.league_ranking, player.created_date';
         $players = \Own\Bus\Player\Data::loadAll($options);
         // main
         $tplMain = new Template(Template::SITE, ['www']);
         $tplMain->set('league', $league);
         $tplMain->set('player', $this->player);
         $tplMain->set('players', $players);
         // layout
         $cache = $tplMain->render('league-ranking');
         $this->tplLayout->set('column1', $cache);
         // cache
         \Rebond\Util\Cache::saveCache('league-ranking', $league->getId(), $cacheTime, $cache);
     }
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }
Ejemplo n.º 6
0
 public function __construct(\Rebond\App $app)
 {
     if ($app->site()->getStatus() == \Rebond\Core\StatusType::INACTIVE) {
         if ($app->ajax()) {
             return ['result' => ResultType::ERROR, 'message' => Lang::lang('error.maintenance')];
         } else {
             Util\Session::redirect('/error/maintenance');
         }
     }
     parent::__construct($app);
     if ($this->signedUser->getId() != 0) {
         $options = ['where' => [['id = ?', $this->signedUser->getId()]]];
         $this->player = \Own\Bus\Player\Data::load($options);
         if ($this->player == null) {
             $this->player = \Own\Bus\Player\Service::create($this->signedUser);
         }
     } else {
         $this->player = new \Own\Bus\Player\Model();
     }
 }
Ejemplo n.º 7
0
 public function gadget()
 {
     // auth
     Auth::isAdminAuthorized($this->signedUser, 'admin.page.gadget', true, '/page');
     // check
     $id = Converter::int('id');
     $save = Converter::int('save', 'post');
     $page = \Rebond\Cms\Page\Data::loadById($id);
     if (!isset($page)) {
         header('Location: /page');
         exit;
     }
     $gadget = new \Rebond\Cms\Gadget\Model();
     $gadget->setPageId($page->getId());
     $form = new \Rebond\Cms\Gadget\Form($gadget);
     // action
     if (isset($save)) {
         Auth::isAdminAuthorized($this->signedUser, 'admin.page.gadget.edit', true, '/page/gadget?id=' . $id);
         if ($form->setFromPost()->validate()->isValid()) {
             $gadget->save();
             Session::adminSuccess('saved', '/page/gadget?id=' . $id);
         } else {
             Session::set('adminError', $form->getValidation()->getMessage());
         }
     }
     // view
     $this->setTpl();
     // form
     $layout = \Rebond\Cms\Layout\Data::loadById($page->getLayoutId());
     $columns = $layout->getColumns();
     $columnOptions = [];
     for ($i = 1; $i <= $columns; $i++) {
         $columnOptions[$i] = Lang::lang('column') . ' ' . $i;
     }
     $tplForm = new Template(Template::MODULE, ['cms', 'gadget']);
     $tplForm->set('item', $form);
     $tplForm->set('title', Lang::lang('manageGadgetOf', [$page->getTitle()]));
     $tplForm->set('columnOptions', $columnOptions);
     $tplForm->set('selectedColumn', $gadget->getCol());
     // active listing
     $options = [];
     $options['join'][] = 'cms_page page ON page.id = gadget.page_id';
     $options['join'][] = 'cms_component component ON component.id = gadget.component_id';
     $options['join'][] = 'cms_module module ON module.id = component.module_id';
     $options['where'][] = ['page.id = ?', $page->getId()];
     $options['where'][] = 'module.status = 1';
     $options['where'][] = 'component.status = 1';
     $options['order'][] = 'gadget.col';
     $options['order'][] = 'gadget.display_order';
     $gadgets = \Rebond\Cms\Gadget\Data::loadAll($options);
     if ($gadgets) {
         foreach ($gadgets as $g) {
             $g->prepareFilter();
         }
     }
     // inactive listing
     $options = [];
     $options['join'][] = 'cms_page page ON page.id = gadget.page_id';
     $options['join'][] = 'cms_component component ON component.id = gadget.component_id';
     $options['join'][] = 'cms_module module ON module.id = component.module_id';
     $options['where'][] = ['page.id = ?', $page->getId()];
     $options['where'][] = 'module.status = 0 OR component.status = 0';
     $options['order'][] = 'gadget.col';
     $options['order'][] = 'gadget.display_order';
     $inactiveGadgets = \Rebond\Cms\Gadget\Data::loadAll($options);
     if ($inactiveGadgets) {
         foreach ($inactiveGadgets as $g) {
             $g->prepareFilter();
         }
     }
     $tplListing = new Template(Template::MODULE, ['cms', 'gadget']);
     $tplListing->set('items', $gadgets);
     $tplListing->set('inactiveItems', $inactiveGadgets);
     $tplListing->set('columnOptions', $columnOptions);
     // layout
     $this->tplLayout->add('column1', $tplForm->render('editor-selector'));
     $this->tplLayout->add('column2', $tplListing->render('listing'));
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-2-row'));
     $this->tplMaster->set('jsLauncher', 'pageGadget');
     return $this->tplMaster->render('tpl-default');
 }
Ejemplo n.º 8
0
 public function mastery()
 {
     // auth
     Util\Auth::isAuthorized($this->signedUser, 'member', false, '/profile/sign-in');
     \Own\Bus\Match\Data::checkMatchToView($this->player->getId());
     // params
     $form = true;
     $id = Util\Converter::toInt('id');
     if ($id == 0) {
         $player = $this->player;
     } else {
         $player = \Own\Bus\Player\Data::loadById($id);
         if (!isset($player)) {
             $player = $this->player;
         } else {
             if ($player->getId() != $this->player->getId()) {
                 $form = false;
             }
         }
     }
     $playerForm = new \Own\Bus\Player\Form($player);
     $save = Util\Converter::toString('save', 'post');
     if ($save != '') {
         $oldMastery = $this->player->getMasteryValues();
         $properties = \Own\Bus\Player\Service::getMasteryList();
         if (!$playerForm->setFromPost($properties)->validate($properties)->isValid()) {
             Util\Session::setAndRedirect('siteError', $playerForm->getValidation()->getMessage(), '/profile/mastery');
         }
         if (!$player->isValidMastery($oldMastery)) {
             Util\Session::setAndRedirect('siteError', 'Mastery skills could not be saved!', '/profile/mastery');
         }
         $player->save();
         Util\Session::setAndRedirect('siteSuccess', 'Mastery skills saved', '/profile/mastery');
     }
     // view
     $this->setTpl();
     // form
     $tplForm = new Util\Template(Util\Template::MODULE, ['bus', 'player']);
     $tplForm->set('form', $form);
     // layout
     $tplForm->set('item', $playerForm);
     $this->tplLayout->set('column1', $tplForm->render('form-mastery'));
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }
Ejemplo n.º 9
0
 public function changePassword($redirect, $checkCurrentPassword = true)
 {
     $currentPassword = $this->getModel()->getPassword();
     $this->setFromPost();
     $newPassword = Util\Converter::string('passwordnew', 'post');
     $fields = [];
     $fields['token'] = $this->validateToken();
     if ($checkCurrentPassword) {
         $fields['password'] = $this->validatePassword();
     }
     $fields['passwordnew'] = Util\Validate::validate('passwordnew', $newPassword, ['password' => true, 'required' => true, 'minLength' => 4, 'maxLength' => 40, 'different' => $this->getModel()->getPassword()]);
     $this->getValidation()->setFields($fields);
     if ($this->getValidation()->isValid()) {
         if (!$checkCurrentPassword || Service::validatePassword($currentPassword, $this->getModel()->getPassword())) {
             $this->getModel()->setPassword(Util\Security::encryptPassword($newPassword));
             \Rebond\Core\User\Data::savePassword($this->getModel());
             \Rebond\Core\UserSecurity\Data::deleteSecure($this->getModel()->getId(), \Rebond\Core\UserSecurity\Model::RESET);
             Util\Session::allSuccess('passwordChanged', $redirect);
         } else {
             Util\Session::set('allError', Util\Lang::lang('errorWrongPassword'));
         }
     } else {
         Util\Session::set('allError', $this->getValidation()->getMessage());
     }
 }
Ejemplo n.º 10
0
 public static function kill($code, $error, $file, $line)
 {
     $app = \Rebond\App::instance();
     $redirect = (int) Session::get('redirect');
     if ($redirect > 5) {
         $app->setStep(\Rebond\Config::STEP_REDIRECT);
     } else {
         Session::set('redirect', $redirect + 1);
     }
     $logId = Log::log($code, $error, $file, $line);
     $json = [];
     $json['result'] = ResultType::ERROR;
     if ($app->step() != \Rebond\Config::STEP_RUNNING) {
         if ($app->ajax()) {
             $json['message'] = Lang::locale('configurationError');
             echo json_encode($json);
             exit;
         } else {
             $controller = new \Rebond\Controller\Admin\Error($app);
             echo $controller->config();
             session_write_close();
             exit;
         }
     } else {
         // update log level if user isDev
         $app->user();
         if ($app->logLevel() == 0) {
             if ($app->ajax()) {
                 $json['message'] = Lang::lang('serviceNotAvailable') . ': ' . $error . ' [<a href="http://' . \Rebond\Config::getPath('adminUrl') . '/tools/log" target="_blank">' . Lang::lang('logsView') . '</a>]';
                 echo json_encode($json, JSON_UNESCAPED_SLASHES);
                 exit;
             } else {
                 if (in_array($code, [self::PAGE_NOT_FOUND, self::ADMIN_PAGE_NOT_FOUND])) {
                     header('Location: /error/generic?404=' . $error);
                 } else {
                     header('Location: /error/detail?id=' . $logId);
                 }
                 session_write_close();
                 exit;
             }
         } else {
             if ($app->ajax()) {
                 $json['message'] = Lang::lang('errorUnknown');
                 echo json_encode($json);
                 exit;
             } else {
                 if (in_array($code, [self::PAGE_NOT_FOUND, self::ADMIN_PAGE_NOT_FOUND])) {
                     header('Location: /error/generic?404=' . $error);
                 } else {
                     header('Location: /error/generic');
                 }
                 session_write_close();
                 exit;
             }
         }
     }
 }
Ejemplo n.º 11
0
 public function quickedit()
 {
     // auth
     Auth::isAdminAuthorized($this->signedUser, 'admin.tools', true, '/');
     // check
     $module = Converter::string('module');
     $id = Converter::int('id');
     $id2 = Converter::int('id2');
     $save = Converter::string('save', 'post');
     if ($module == '') {
         header('Location: /tools/quickview');
         exit;
     }
     $busModel = '\\Rebond\\Bus\\' . $module . '\\Model';
     $busData = '\\Rebond\\Bus\\' . $module . '\\Data';
     $busForm = '\\Rebond\\Bus\\' . $module . '\\Form';
     if ($id == 0) {
         $entity = new $busModel();
     } else {
         if ($id2 != 0) {
             $entity = $busData::loadById($id, $id2);
         } else {
             $entity = $busData::loadById($id);
         }
         if (!isset($entity)) {
             $entity = new $busModel();
         }
     }
     $form = new $busForm($entity);
     // action
     if (isset($save)) {
         if ($form->setFromPost()->validate()->isValid()) {
             $entity->save();
             Session::adminSuccess('saved', '/tools/quickview/#!/' . $module);
         }
         Session::set('adminError', $form->getValidation()->getMessage());
     }
     // view
     $this->setTpl();
     // nav
     $entities = \Rebond\Util\File::getFolders('Rebond/Bus/');
     $tplNav = new Template(Template::SITE, ['admin', 'tools']);
     $tplNav->set('entities', $entities);
     $tplNav->set('active', $module);
     // main
     $tplMain = new Template(Template::MODULE, ['Bus', $module]);
     $tplMain->set('item', $form);
     // layout
     $this->tplLayout->set('column1', $tplMain->render('bus-editor'));
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     $this->tplMaster->set('navSide', $tplNav->render('nav'));
     $this->tplMaster->set('page', 'tools');
     $this->tplMaster->addJs('/js/tinymce/tinymce.min.js');
     $this->tplMaster->set('jsLauncher', 'toolsQuickEdit');
     return $this->tplMaster->render('tpl-default');
 }
Ejemplo n.º 12
0
 public function reinitialize()
 {
     // auth
     Util\Auth::isAdminAuthorized($this->signedUser, 'admin.dev', true, '/');
     // check
     $action = Util\Converter::string('action');
     if (isset($action)) {
         $result = [];
         $result['status'] = true;
         $result['message'] = '';
         $site = \Rebond\Core\Site\Data::loadById(1);
         $db = new \Rebond\Util\Data();
         switch ($action) {
             case 'file':
                 \Rebond\Core\Site\Service::resetFiles();
                 break;
             case 'restore':
                 $files = \Rebond\Util\File::getFiles('files/backup');
                 $fileFound = false;
                 foreach ($files as $file) {
                     if (stripos($file, 'launch') !== false) {
                         $fileFound = true;
                         $result = $db->restore($file);
                         break;
                     }
                 }
                 if (!$fileFound) {
                     $result['status'] = false;
                     $result['message'] = Util\Lang::lang('dbLaunchFileNotFound');
                 } else {
                     \Rebond\Core\Site\Service::resetFiles();
                 }
                 break;
             case 'full':
                 \Rebond\Core\Site\Service::resetFiles();
                 $result = $db->reset();
                 Util\Session::adminSuccess('resetSuccessful', '/');
                 break;
         }
         if ($result['status']) {
             Util\Session::set('adminSuccess', Util\Lang::lang('resetSuccessful'));
         } else {
             Util\Session::set('adminError', $result['message']);
         }
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Util\Template(Util\Template::SITE, ['admin', 'dev']);
     // layout
     $this->tplLayout->set('column1', $tplMain->render('reinitialize'));
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     $this->tplMaster->set('jsLauncher', 'dev');
     return $this->tplMaster->render('tpl-default');
 }
Ejemplo n.º 13
0
 public function permission_edit()
 {
     // auth
     Auth::isAdminAuthorized($this->signedUser, 'admin.user.permission', true, '/user');
     // check
     $id = Converter::int('id');
     $save = Converter::int('save', 'post');
     $permission = \Rebond\Core\Permission\Data::loadById($id, true);
     $form = new \Rebond\Core\Permission\Form($permission);
     // action
     if (isset($save)) {
         Auth::isAdminAuthorized($this->signedUser, 'admin.user.permission.edit', true, '/user/permission-edit?id=' . $id);
         if ($form->setFromPost()->validate()->isValid()) {
             $permission->save();
             Session::adminSuccess('saved', '/user/permission');
         } else {
             Session::set('adminError', $form->getValidation()->getMessage());
         }
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Template(Template::MODULE, ['core', 'permission']);
     $tplMain->set('item', $form);
     // layout
     if (Auth::isAdminAuthorized($this->signedUser, 'admin.user.permission.edit', false)) {
         $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'));
     return $this->tplMaster->render('tpl-default');
 }
Ejemplo n.º 14
0
 public function tpl_edit()
 {
     // auth
     Util\Auth::isAdminAuthorized($this->signedUser, 'admin.designer', true, '/');
     // check
     $file = Util\Converter::string('f');
     $app = Util\Converter::string('app');
     $save = Util\Converter::string('save', 'post');
     if (empty($file)) {
         Util\Session::adminError('itemNotFound', [$file], '/designer/tpl');
     }
     $validator = Util\Validate::validateFilename('file', $file, true);
     if (!$validator->isValid()) {
         Util\Session::setAndRedirect('adminError', $validator->getMessage(), '/designer/tpl');
     }
     $filePath = FULL_PATH . 'views/www/';
     if (!empty($app)) {
         $filePath = FULL_PATH . 'Rebond/App/' . $app . '/template/';
         $validator = Util\Validate::validateAlphaNumeric('app', $app, true);
         if (!$validator->isValid()) {
             Util\Session::setAndRedirect('adminError', $validator->getMessage(), '/designer/tpl');
         }
     }
     if (!file_exists($filePath)) {
         Util\Session::adminError('itemNotFound', [$filePath], '/designer/tpl');
     }
     // action
     if (isset($save)) {
         $filePost = Util\Converter::string('file', 'post');
         $tplFile = Util\Converter::string('tpl-file', 'post');
         $appPost = Util\Converter::string('app', 'post');
         $file = FULL_PATH . 'views/' . \Rebond\Config::getPath('siteFolder') . '/' . $filePost;
         if (!empty($appPost)) {
             $file = \Rebond\Config::getPath('rebond') . 'App/' . $appPost . '/template/' . $filePost;
         }
         if (!isset($file) || Util\File::getExtension($file) != 'tpl') {
             Util\Session::adminError('fileNotFoundOrValid', [$file], '/designer/css');
         }
         if (!copy($file, Util\File::getNoExtension($file) . '-' . Util\Format::date(time(), 'string') . '.bak')) {
             Util\Session::adminError('itemNotCopied', [$file], '/designer/css');
         }
         file_put_contents($file, $tplFile);
         Util\Session::adminSuccess('saved', '/designer/tpl');
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Util\Template(Util\Template::SITE, ['admin', 'designer']);
     $tplMain->set('file', $file);
     $tplMain->set('app', $app);
     $tplMain->set('filePath', $filePath);
     $tplMain->set('editable', Util\File::getExtension($file) == 'tpl');
     // layout
     $this->tplLayout->set('column1', $tplMain->render('tpl-form'));
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     $this->tplMaster->set('jsLauncher', 'designerTpl');
     $this->tplMaster->addCss('/css/codemirror.css');
     $this->tplMaster->addJs('/js/codemirror/codemirror.js');
     $this->tplMaster->addJs('/js/codemirror/htmlmixed.js');
     $this->tplMaster->addJs('/js/codemirror/xml.js');
     $this->tplMaster->addJs('/js/codemirror/clike.js');
     $this->tplMaster->addJs('/js/codemirror/php.js');
     return $this->tplMaster->render('tpl-default');
 }
Ejemplo n.º 15
0
 public function view()
 {
     $id = Converter::toInt('id');
     $playerId = $this->player->getId();
     $tournament = \Own\Bus\Tournament\Data::loadById($id);
     if (!isset($tournament)) {
         Session::siteError('itemNotFound', [$id], '/tournament');
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Template(Template::MODULE, ['bus', 'match']);
     $tplMain->set('tournament', $tournament);
     if ($tournament->getStatus() >= TournamentStatus::PLAYING) {
         $orderedMatches = \Own\Bus\Match\Data::loadAllByTournamentId($tournament->getId());
         foreach ($orderedMatches as $match) {
             if ($match->getPlayerMatch1() != null && $match->getPlayerMatch1()->getPlayerId() == $playerId && !$match->getPlayerMatch1()->getHasViewed() || $match->getPlayerMatch2() != null && $match->getPlayerMatch2()->getPlayerId() == $playerId && !$match->getPlayerMatch2()->getHasViewed()) {
                 $position = $match->getPosition();
                 $nextPosition = floor($position / 2);
                 while ($nextPosition >= 1) {
                     if (!isset($orderedMatches[$nextPosition])) {
                         break;
                     }
                     if ($nextPosition == 1) {
                         $orderedMatches[$nextPosition]->setWinnerId(0);
                     }
                     if ($position % 2 == 1) {
                         $orderedMatches[$nextPosition]->setPlayerMatch1Id(0);
                     } else {
                         $orderedMatches[$nextPosition]->setPlayerMatch2Id(0);
                     }
                     $position = $nextPosition;
                     $nextPosition = floor($position / 2);
                 }
             }
         }
         $tplMain->set('items', $orderedMatches);
         $tplMain->set('size', $tournament->getSize() / 2);
         $tplMain->set('round', 1);
         $tplMain->set('playerId', $this->player->getId());
         // layout
         $this->tplLayout->set('column1', $tplMain->render('draw'));
     } else {
         $tplMain->set('players', \Own\Bus\Tournament\Data::getPlayerList($tournament->getId()));
         // layout
         $this->tplLayout->set('column1', $tplMain->render('registration'));
     }
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }
Ejemplo n.º 16
0
 public function media_link_edit()
 {
     // auth
     Auth::isAdminAuthorized($this->signedUser, 'admin.cms.media-link', true, '/cms/media-link');
     // check
     $id = Converter::int('id');
     $moduleMedia = \Rebond\Cms\ModuleMedia\Data::loadById($id, true);
     $form = new \Rebond\Cms\ModuleMedia\Form($moduleMedia);
     // action
     if (isset($_POST['save'])) {
         Auth::isAdminAuthorized($this->signedUser, 'admin.cms.media-link.edit', true, '/cms/media-link-edit?id=' . $id);
         if ($form->setFromPost()->validate()->isValid()) {
             $moduleMedia->save();
             Session::adminSuccess('saved', '/cms/media_link');
         } else {
             Session::set('adminError', $form->getValidation()->getMessage());
         }
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Template(Template::MODULE, ['cms', 'moduleMedia']);
     $tplMain->set('item', $form);
     // layout
     if (Auth::isAdminAuthorized($this->signedUser, 'admin.cms.media-link.edit', false)) {
         $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'));
     return $this->tplMaster->render('tpl-default');
 }
Ejemplo n.º 17
0
Archivo: Own.php Proyecto: vincium/resa
 public function membership()
 {
     Util\Auth::isAdminAuthorized($this->signedUser, 'member', true, '/');
     $this->setTpl();
     $membershipId = Util\Converter::toInt('id');
     if (!isset($membershipId)) {
         Util\Session::adminError('item.not.found', [Util\Lang::lang('membership'), $membershipId], '/own/memberships');
     }
     $membership = \Own\Bus\Membership\Data::loadById($membershipId, true);
     $membershipForm = new \Own\Bus\Membership\Form($membership);
     // action
     $save = Util\Converter::toString('save', 'post');
     $courtIds = Util\Converter::toArray('court', 'post');
     if (isset($save)) {
         if ($membershipForm->setFromPost()->validate()->isValid()) {
             \Own\Bus\MembershipCourt\Data::deleteByMembershipId($membership->getId());
             $newCourts = [];
             if (isset($courtIds)) {
                 foreach ($courtIds as $courtId) {
                     $membershipCourt = new \Own\Bus\MembershipCourt\Model();
                     $membershipCourt->setMembershipId($membership->getId());
                     $membershipCourt->setCourtId($courtId);
                     $newCourts[] = $membershipCourt;
                 }
             }
             \Own\Bus\MembershipCourt\Data::saveAll($newCourts);
             $membership->save();
             Util\Session::adminSuccess('saved', '/own/memberships');
         } else {
             Util\Session::set('adminError', $membershipForm->getValidation()->getMessage());
         }
     }
     $tplEditor = new Util\Template(Util\Template::SITE, ['admin']);
     $tplEditor->set('item', $membershipForm);
     return $this->response('tpl-default', ['title' => Util\Lang::lang('own'), 'jsLauncher' => 'own'], 'layout-1-col', ['column1' => $tplEditor->render('membership-editor')]);
 }
Ejemplo n.º 18
0
 public function lang_edit()
 {
     // auth
     Auth::isAdminAuthorized($this->signedUser, 'admin.config.lang.edit', true, '/configuration/lang');
     // check
     $file = Converter::string('f');
     $tplFile = Converter::string('tpl-file', 'post');
     $filePath = \Rebond\Config::getPath('lang') . $file;
     if ($file == '') {
         header('Location: /configuration/lang');
         exit;
     }
     if (!file_exists($filePath)) {
         Session::adminError('itemNotFound', [$filePath], '/configuration/lang');
     }
     // action
     if (isset($_POST['save'])) {
         file_put_contents($filePath, $tplFile);
         Session::adminSuccess('saved', '/configuration/lang');
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Template(Template::SITE, ['admin', 'configuration']);
     $tplMain->set('file', $file);
     $tplMain->set('filePath', $filePath);
     // layout
     $this->tplLayout->set('column1', $tplMain->render('lang-form'));
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     $this->tplMaster->set('jsLauncher', 'configLang');
     $this->tplMaster->addCss('/css/codemirror.css');
     $this->tplMaster->addJs('/js/codemirror/codemirror.js');
     $this->tplMaster->addJs('/js/codemirror/xml.js');
     return $this->tplMaster->render('tpl-default');
 }
Ejemplo n.º 19
0
 public function viewProto()
 {
     // auth
     Util\Auth::isAuthorized($this->signedUser, 'member', false, '/profile/sign-in');
     $matchId = Util\Converter::toInt('id');
     $options = [];
     $options['where'][] = 'match.id = ' . $matchId;
     $options['where'][] = 'match.status IN (' . MatchStatus::FINISHED . ', ' . MatchStatus::PLAYING . ')';
     $matches = \Own\Bus\Match\Data::loadAll($options);
     if (count($matches) != 1) {
         Util\Session::siteError('matchNotFound', null, '/match/schedule');
     }
     $match = $matches[0];
     $matchLog = \Rebond\Config::getPath('config') . 'match/match_' . $match->getId() . '.json';
     if (!file_exists($matchLog)) {
         Util\Session::siteError('noMatchLog', null, '/match/schedule');
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Util\Template(Util\Template::SITE, ['www']);
     $tplMain->set('match', $match);
     $logs = json_decode(file_get_contents($matchLog), true);
     $tplMain->set('logs', $logs);
     // layout
     $this->tplLayout->set('column1', $tplMain->render('match-view-proto'));
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     $this->tplMaster->addJs('/js/proto.js');
     return $this->tplMaster->render('tpl-default');
 }
Ejemplo n.º 20
0
 public function generated_photos()
 {
     // auth
     Auth::isAdminAuthorized($this->signedUser, 'admin.media.image', true, '/media');
     $photos = \Rebond\Util\File::getFiles('www/media');
     $generated = [];
     $pattern = '/-(.*).(.*)/';
     $count = count($photos);
     for ($i = 0; $i < $count; $i++) {
         if (preg_match($pattern, $photos[$i])) {
             $generated[] = $photos[$i];
             unset($photos[$i]);
         }
     }
     $cleanup = Converter::bool('cleanup');
     if ($cleanup) {
         foreach ($generated as $photo) {
             \Rebond\Util\File::deleteAllMedia('', $photo);
         }
         Session::adminSuccess('generatedPhotosDeleted', '/media/generated-photos');
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Template(Template::SITE, ['admin', 'media']);
     $tplMain->set('photos', $photos);
     $tplMain->set('generated', $generated);
     // layout
     $this->tplLayout->set('column1', $tplMain->render('generated-photos'));
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     return $this->tplMaster->render('tpl-default');
 }
Ejemplo n.º 21
0
 private function findModule($moduleName)
 {
     if ($moduleName == '') {
         header('Location: /content/');
         exit;
     }
     $module = \Rebond\Cms\Module\Data::loadByTitle($moduleName);
     if (!isset($module)) {
         Session::adminError('itemNotFound', [$moduleName], '/content/');
     }
     return $module;
 }
Ejemplo n.º 22
0
 public function forgotPassword()
 {
     $signedUser = $this->app->user();
     // auth
     if (Util\Auth::isAuth($signedUser)) {
         header('Location: /profile');
         exit;
     }
     $form = new \Rebond\Core\User\Form($signedUser);
     $tpl = new Util\Template(Util\Template::MODULE, ['app', 'User']);
     // action
     // request
     $requestForgotPassword = Util\Converter::toString('requestForgotPassword', 'post');
     if (isset($requestForgotPassword)) {
         $email = Util\Converter::toString('email', 'post');
         if ($email == '') {
             Util\Session::set(Util\Lang::lang('siteError', 'emptyEmailAddress'));
         } else {
             $user = \Rebond\Core\User\Data::loadByEmail($email);
             if (isset($user)) {
                 Util\Mail::resetPassword($this->app->site()->getTitle(), $user);
                 return $tpl->render('forgot-password-send');
             } else {
                 Util\Session::set('siteError', Util\Lang::lang('emailAddressNotFound'));
             }
         }
     }
     // reset password form
     $reset = Util\Converter::toString('reset');
     if (isset($reset)) {
         $user = \Rebond\Core\UserSecurity\Service::getUserBySecure($reset, \Rebond\Core\UserSecurity\Model::RESET);
         if (isset($user)) {
             $form = new \Rebond\Core\User\Form($user);
             // reset password
             $resetPassword = Util\Converter::toString('resetPassword', 'post');
             if (isset($resetPassword)) {
                 $form->changePassword('/profile', false);
             }
             $tpl = new Util\Template(Util\Template::MODULE, ['app', 'User']);
             $tpl->set('item', $form);
             $tpl->set('checkCurrentPassword', false);
             return $tpl->render('password-change');
         }
     }
     $tpl = new Util\Template(Util\Template::MODULE, ['app', 'User']);
     $tpl->set('item', $form);
     return $tpl->render('forgot-password');
 }
Ejemplo n.º 23
0
Archivo: Data.php Proyecto: vincium/lot
 public static function checkMatchToView($playerId)
 {
     $match = self::loadRecentByPlayerId($playerId);
     if (isset($match)) {
         Util\Session::siteSuccess('matchView', '/');
     }
 }
Ejemplo n.º 24
0
 public function sign_in()
 {
     // auth
     if (Auth::isAdminAuthorized($this->signedUser)) {
         Session::redirect('/');
     }
     // action
     $form = new \Rebond\Core\User\Form($this->signedUser);
     $form->signIn();
     if (Auth::isAdmin($form->getModel())) {
         Session::redirect('/');
     }
     if (Auth::isAuth($form->getModel())) {
         Session::setAndRedirect('siteError', Lang::lang('accessNonAuthorized'), 'http://' . \Rebond\Config::getPath('siteUrl'));
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Template(Template::MODULE, ['core', 'user']);
     $tplMain->set('item', $form);
     // master
     $this->tplMaster->set('column1', $tplMain->render('sign-in'));
     $this->tplMaster->set('jsLauncher', 'profile');
     return $this->tplMaster->render('tpl-signin');
 }
Ejemplo n.º 25
0
 public function index()
 {
     // check
     $this->db = new \Rebond\Util\Data();
     $this->authFile = \Rebond\Config::getPath('config') . 'authentication.txt';
     $this->queryTables = 'SELECT COUNT(TABLE_NAME) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = \'' . \Rebond\Config::getDb('name') . '\'';
     $this->queryCheckUser = '******';
     $this->info = [];
     $isAuth = Session::int('auth');
     $action = Converter::string('action');
     // action
     if ($isAuth == 0) {
         $this->step = 'auth';
         // check auth
         if (!file_exists($this->authFile)) {
             $auth = \Rebond\Util\Security::encrypt(time());
             File::save($this->authFile, 'w', $auth);
         } else {
             $auth = File::read($this->authFile, 'r');
         }
         if (isset($_POST['submitAuth'])) {
             if ($auth == $_POST['auth']) {
                 Session::set('auth', 1);
                 $isAuth = 1;
                 unlink($this->authFile);
                 $this->step = 'db';
                 $this->info[] = '<p class="bg-success">You have been authenticated!</p>';
             } else {
                 $this->info[] = '<p class="bg-error">The identification number you entered is incorrect. Please try again.</p>';
             }
         }
     }
     if ($isAuth == 1) {
         // check db
         $tableCount = $this->db->count($this->queryTables);
         $userTable = $this->db->selectOne($this->queryCheckUser);
         if ($tableCount != 0 && $tableCount !== self::TABLECOUNT) {
             $this->info[] = '<p class="bg-error">Your database contains ' . $tableCount . ' table(s). A fresh install of Rebond should contain ' . self::TABLECOUNT . ' tables. Please check your database name to make sure that you want to install Rebond in this database.</p>';
         }
         if (count($userTable) == 0) {
             $this->step = 'db';
             if ($action == 'db') {
                 $scripts = \Rebond\Util\File::getFiles('files/install');
                 sort($scripts);
                 foreach ($scripts as $script) {
                     $result = $this->db->runScript('files/install', $script);
                     if ($result['status'] == \Rebond\Core\ResultType::SUCCESS) {
                         $this->info[] = '<p>' . $script . '... success.</p>';
                     } else {
                         $this->info[] = '<p>' . $script . '... failed: <span class="error">' . $result['message'] . '</span></p>';
                         break;
                     }
                 }
                 $tableCount = $this->db->count($this->queryTables);
                 $userTable = $this->db->selectOne($this->queryCheckUser);
                 if (count($userTable) == 0) {
                     $this->info[] = '<p class="bg-error">The database has NOT been installed correctly. Please try to reinstall the database.</p>';
                 } else {
                     $this->info[] = '<p class="bg-success">The database has been installed successfully.</p>';
                     $this->step = 'db-ok';
                 }
             }
             // check user
         } else {
             if (\Rebond\Core\User\Data::count() == 0) {
                 $this->step = 'user';
                 $user = new \Rebond\Core\User\Model();
                 $userForm = new \Rebond\Core\User\Form($user);
                 if (isset($_POST['submitUser'])) {
                     if ($userForm->setFromPost()->validate()->isValid()) {
                         $user->setPassword(Security::encryptPassword($user->getPassword()));
                         $user->setIsAdmin(true);
                         $user->setIsDev(true);
                         $user->save();
                         $this->step = 'ready';
                     } else {
                         Session::set('adminError', $userForm->getValidation()->getMessage());
                     }
                 }
                 // ready
             } else {
                 $this->step = 'ready';
                 if ($action == 'launch') {
                     $adminPath = \Rebond\Config::getPath('admin');
                     $sitePath = \Rebond\Config::getPath('site');
                     rename($adminPath . 'index.php', $adminPath . 'index_install.php');
                     rename($adminPath . 'index_admin.php', $adminPath . 'index.php');
                     rename($sitePath . 'index.php', $sitePath . 'index_install.php');
                     rename($sitePath . 'index_cms.php', $sitePath . 'index.php');
                     $db = new \Rebond\Util\Data();
                     $db->backup('launch');
                     Session::kill('auth');
                     Session::setAndRedirect('signedUser', 1, '/configuration/site');
                 }
             }
         }
     }
     // menu
     $tplMenu = new Template(Template::SITE, ['admin', 'install']);
     $tplMenu->set('menuAuth', $this->step == 'auth' ? ' class="active"' : '');
     $tplMenu->set('menuDb', in_array($this->step, ['db', 'db-ok']) ? ' class="active"' : '');
     $tplMenu->set('menuUser', $this->step == 'user' ? ' class="active"' : '');
     $tplMenu->set('menuReady', $this->step == 'ready' ? ' class="active"' : '');
     // main
     $tplMain = new Template(Template::SITE, ['admin', 'install']);
     // layout
     $this->tplLayout->set('column1', $tplMenu->render('menu'));
     $this->tplLayout->add('column1', implode($this->info));
     if ($this->step == 'user') {
         if (!isset($user)) {
             $userForm = new \Rebond\Core\User\Form();
             $userForm->setFromPost();
         }
         $tplMain->set('form', $userForm);
     }
     $this->tplLayout->add('column1', $tplMain->render($this->step));
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     $this->tplMaster->set('jsLauncher', 'install');
     $this->tplMaster->addCss('/css/normalize.css');
     $this->tplMaster->addCss('/css/rebond.css');
     $this->tplMaster->addCss('/css/custom.css');
     $this->tplMaster->addJs('//code.jquery.com/jquery-2.1.3.min.js');
     $this->tplMaster->addJs('/js/rebond.js');
     $this->tplMaster->addJs('/js/custom.js');
     return $this->tplMaster->render('tpl-install');
 }