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')]); }
public function detail() { $this->setBaseTpl(); // auth Auth::isAdminAuthorized($this->signedUser, null, true, '/profile/sign-in'); $logId = Converter::int('id'); if ($logId == 0) { return $this->generic(); } if ($this->app->logLevel() == 1) { return $this->generic(); } $log = \Rebond\Core\Log\Data::loadById($logId); if (!isset($log)) { return $this->generic(); } $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; // main $this->tplMain->set('log', $log); $this->tplMain->set('referer', $referer); // layout $this->tplLayout->set('column1', $this->tplMain->render('detail')); // master $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col')); return $this->tplMaster->render('tpl-error'); }
public function signIn() { if (!isset($_POST['signIn'])) { return; } $this->setFromPost(); $fields = []; $fields['token'] = $this->validateToken(); $fields['email'] = $this->validateEmail(false); $fields['password'] = $this->validatePassword(); $this->getValidation()->setFields($fields); if ($this->getValidation()->isValid()) { $signedUser = Service::loadByEmail($this->getModel()->getEmail(), $this->getModel()->getPassword()); if (Util\Auth::isAuth($signedUser)) { Util\Session::set('allSuccess', Util\Lang::lang('hi', [$signedUser->getUsername()])); Util\Session::set('signedUser', $signedUser->getId()); if (!empty($_POST['persistentCookie'])) { \Rebond\Core\UserSecurity\Service::saveSecure($signedUser, \Rebond\Core\UserSecurity\Model::REMEMBER); } Util\Log::log(Util\Error::USER_SIGNIN, $signedUser->getId(), __FILE__, __LINE__); $this->setModel($signedUser); } else { Util\Session::set('allError', Util\Lang::lang('incorrectEmailPassword')); } } else { Util\Session::set('allError', $this->getValidation()->getMessage()); } }
public function index() { // auth if (!$this->cron) { Util\Auth::isAdminAuthorized($this->app->user(), 'admin.dev', false, '/'); } $this->log('start'); $options = []; $options['where'][] = 'cron.active = 1'; $options['order'][] = 'cron.display_order'; $crons = \Own\Bus\Cron\Data::loadAll($options); foreach ($crons as $cron) { $notExpired = $cron->getLastRun()->add(new \DateInterval('PT' . $cron->getSchedule() . 'M')) > new Util\DateTime(); if ($this->cron && $notExpired) { continue; } if ($cron->getMethod() != 'match' && $notExpired) { continue; } if (!$this->cron && $this->app->timer() > 25) { break; } $cron->setLastRun(date('Y-m-d H:i:s')); $cron->save(); $method = $cron->getMethod(); $this->{$method}(); } $message = $this->app->timer() . 's, ' . $this->app->queryCount() . ' queries, ' . round(memory_get_peak_usage() / 1024) . ' kb'; $this->log($message); }
public function index() { // auth Util\Auth::isAuthorized($this->signedUser, 'member', false, '/profile/sign-in'); if (isset($_POST['sign-out'])) { \Rebond\Core\UserSecurity\Service::signOut($this->signedUser); } // view $this->setTpl(); // main $tplMain = new Util\Template(Util\Template::SITE, ['www']); // layout $this->tplLayout->set('column1', $tplMain->render('index')); // template $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col')); return $this->tplMaster->render('tpl-default'); }
public function bookings_add() { Util\Auth::isAdminAuthorized($this->signedUser, null, false, '/'); $today = new Util\DateTime(); $this->date = Util\Converter::toDate('date'); if (!isset($this->date)) { $this->date = new Util\DateTime(); } /* header('Content-Type: application/json'); echo(json_encode($this->getBookings()));exit(); */ $message = []; $message[] = $this->clearBookings(); $message[] = $this->addBookings($this->getBookings()); // main $tpl = new Util\Template(Util\Template::SITE, ['admin']); $tpl->set('today', $today->format('Y-m-d')); $tpl->set('message', implode($message, '<br>')); return $this->response('tpl-default', ['title' => Util\Lang::lang('own'), 'jsLauncher' => 'integration'], 'layout-1-col', ['column1' => $tpl->render('integration')]); }
public function index() { // auth if (!\Rebond\Util\Auth::isAdminAuthorized($this->signedUser, null, false)) { header('Location: /profile/sign-in'); exit; } // view $this->setTpl(); // main $tplMain = new Template(Template::SITE, ['admin']); $tplMain->set('title', $this->app->site()->getTitle()); // right $tplRight = new Template(Template::SITE, ['admin']); $pendingItems = []; if ($this->app->site()->getIsCms()) { $options = []; $options['where'][] = 'module.status = 1'; $options['where'][] = 'module.has_content = 1'; $modules = \Rebond\Cms\Module\Data::loadAll($options); if ($modules) { foreach ($modules as $module) { $appData = '\\Rebond\\App\\' . $module->getTitle() . '\\Data'; $items = $appData::loadByVersion('pending'); if (count($items) > 0) { $pendingItems[] = $items; } } } } $tplRight->set('items', $pendingItems); $tplRight->set('title', \Rebond\Util\Lang::lang('pendingItems')); // layout $this->tplLayout->set('column1', $tplMain->render('index')); $this->tplLayout->set('column2', $tplRight->render('pending')); // master $this->tplMaster->set('layout', $this->tplLayout->render('layout-2-col')); return $this->tplMaster->render('tpl-default'); }
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')]); }
public function tour_points() { // auth Util\Auth::isAuthorized($this->signedUser, 'member', false, '/profile/sign-in'); \Own\Bus\Match\Data::checkMatchToView($this->player->getId()); $race = Util\Converter::toBool('race', 'get', true); // params $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; } } if ($race) { $options = []; $options['join'][] = 'bus_tournament tournament ON tournament.id = tournament_player.tournament_id'; $options['where'][] = 'tournament.status = ' . TournamentStatus::FINISHED; $options['where'][] = 'tournament.start_date > \'' . Engine::getStartYearDate($this->app->site()->getCreatedDate()) . '\''; $options['order'][] = 'points DESC'; $tournaments = \Own\Bus\TournamentPlayer\Data::loadAllByPlayerId($player->getId(), $options); $oldTournaments = null; } else { $options = []; $options['join'][] = 'bus_tournament tournament ON tournament.id = tournament_player.tournament_id'; $options['where'][] = 'tournament.status = ' . TournamentStatus::FINISHED; $options['where'][] = 'tournament.start_date > NOW() - INTERVAL ' . Engine::DAY * 336 . ' HOUR'; $options['order'][] = 'points DESC'; $tournaments = \Own\Bus\TournamentPlayer\Data::loadAllByPlayerId($player->getId(), $options); $options = []; $options['join'][] = 'bus_tournament tournament ON tournament.id = tournament_player.tournament_id'; $options['where'][] = 'tournament.status = ' . TournamentStatus::FINISHED; $options['where'][] = 'tournament.start_date < NOW() - INTERVAL ' . Engine::DAY * 336 . ' HOUR'; $options['order'][] = 'tournament.start_date DESC'; $oldTournaments = \Own\Bus\TournamentPlayer\Data::loadAllByPlayerId($player->getId(), $options); } // view $this->setTpl(); // filter $tplFilter = new Util\Template(Util\Template::SITE, ['www']); $tplFilter->set('race', $race); $tplFilter->set('playerId', $player->getId()); // main $tplMain = new Util\Template(Util\Template::SITE, ['www']); $tplMain->set('username', $player->getUsername()); $tplMain->set('tournaments', $tournaments); $tplMain->set('oldTournaments', $oldTournaments); // layout $this->tplLayout->set('column1', $tplFilter->render('profile-tour-point-filter')); $this->tplLayout->add('column1', $tplMain->render('profile-tour-point')); // template $this->tplMaster->set('layout', $this->tplLayout->render('layout-center')); return $this->tplMaster->render('tpl-default'); }
public function cache() { // auth Auth::isAdminAuthorized($this->signedUser, 'admin.config.cache', true, '/configuration'); // view $this->setTpl(); // main $files = \Rebond\Util\File::getFiles('files/cache'); $tplMain = new Template(Template::SITE, ['admin', 'configuration']); $tplMain->set('files', $files); $tplMain->set('cache', $this->app->site()->getCacheTime()); $tplMain->set('cachePath', \Rebond\Config::getPath('cache')); // layout $this->tplLayout->set('column1', $tplMain->render('cache')); // master $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col')); $this->tplMaster->set('jsLauncher', 'configCache'); return $this->tplMaster->render('tpl-default'); }
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'); }
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'); }
public function index() { Util\Auth::isAdminAuthorized($this->signedUser, 'member', true, '/'); $tplDefault = new Util\Template(Util\Template::SITE, ['admin']); return $this->response('tpl-default', ['title' => Util\Lang::lang('own'), 'jsLauncher' => 'own'], 'layout-1-col', ['column1' => $tplDefault->render('index')]); }
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'); }
public function delete() { // auth Auth::isAdminAuthorized($this->signedUser, 'admin.content.edit', true, '/content/'); // check $moduleName = Converter::string('module'); $id = Converter::int('id'); $module = $this->findModule($moduleName); $appData = '\\Rebond\\App\\' . $module->getTitle() . '\\Data'; $model = $appData::loadById($id); if (!isset($model)) { Session::adminError('itemNotFound', [$moduleName . ' (' . $id . ')'], '/content/'); } $appData::updateVersion($model, \Rebond\Cms\VersionType::DELETED); Session::adminSuccess('deleted', '/content/#!/' . $moduleName . '/published/'); }
public function in_use() { // auth Auth::isAdminAuthorized($this->signedUser, 'admin.media.image', true, '/media'); $id = Converter::int('id'); if (!isset($id)) { return $this->index(); } // find app modules that use medium $items = []; $moduleMedium = \Rebond\Cms\ModuleMedia\Data::loadAll(); if ($moduleMedium) { foreach ($moduleMedium as $moduleMedia) { $module = \Rebond\Cms\Module\Data::loadById($moduleMedia->getModuleId()); if (isset($module)) { $appData = '\\Rebond\\App\\' . $module->getTitle() . '\\Data'; $options = []; $options['where'][] = [$moduleMedia->getField() . ' = ?', $id]; $options['where'][] = ['content.version NOT IN (?)', [VersionType::DELETED, VersionType::OLD]]; $items = array_merge($items, $appData::loadAll($options)); } } } // view $this->setTpl(); // main $tplMain = new Template(Template::SITE, ['admin', 'media']); $tplMain->set('items', $items); // layout $this->tplLayout->set('column1', $tplMain->render('in-use')); // master $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col')); return $this->tplMaster->render('tpl-default'); }
public function sign() { $isAllowed = Util\Auth::isAuthorized($this->signedUser, 'member'); $json = []; $json['result'] = \Rebond\Core\ResultType::ERROR; if (!$isAllowed) { $json['message'] = Util\Lang::lang('accessNonAuthorized'); return json_encode($json); } $tournamentId = Util\Converter::toInt('tournamentId', 'post'); $action = Util\Converter::toString('action', 'post'); if ($tournamentId == 0 || !in_array($action, ['up', 'out'])) { $json['message'] = 'Invalid options'; return json_encode($json); } $tournament = \Own\Bus\Tournament\Data::loadById($tournamentId); $playerId = $this->player->getId(); if ($tournament->getClassification() == Classification::AMATEUR && $this->player->getTourPoint() >= 10) { $json['message'] = Util\Lang::lang('tooManyPointsForAmateur'); return json_encode($json); } if ($tournament->getClassification() != Classification::AMATEUR && $this->player->getTourPoint() < 10) { $json['message'] = Util\Lang::lang('notEnoughPointForTournament'); return json_encode($json); } if ($tournament->getClassification() <= Classification::ATP_250 && $this->player->getTourPoint() <= 100) { $json['message'] = Util\Lang::lang('needMorePointsForATP'); return json_encode($json); } $options = []; $options['where'][] = 'tournament_player.tournament_id = ' . $tournamentId; $tp = \Own\Bus\TournamentPlayer\Data::loadAllByPlayerId($playerId, $options); if ($action == 'up') { if (count($tp) > 0) { $json['message'] = Util\Lang::lang('alreadySignedUp'); return json_encode($json); } if ($this->player->getIsInTournament() || $this->player->getIsRegistered()) { $json['message'] = Util\Lang::lang('alreadySignedUpInOtherTournament'); return json_encode($json); } $tp = new \Own\Bus\TournamentPlayer\Model(); $tp->setTournamentId($tournamentId); $tp->setPlayerId($playerId); $tp->save(); $this->player->setIsRegistered(true); $this->player->save(); $json['result'] = \Rebond\Core\ResultType::SUCCESS; $json['message'] = Util\Lang::lang('signedUp') . '!'; $json['newAction'] = 'out'; $json['html'] = Util\Lang::lang('signOut'); return json_encode($json); } if ($action == 'out') { if (count($tp) == 0) { $json['message'] = Util\Lang::lang('notRegistered'); return json_encode($json); } \Own\Bus\TournamentPlayer\Data::deleteById($tp[0]->getId()); $this->player->setIsRegistered(false); $this->player->save(); $json['result'] = \Rebond\Core\ResultType::SUCCESS; $json['message'] = Util\Lang::lang('signedOut') . '!'; $json['newAction'] = 'up'; $json['html'] = Util\Lang::lang('signUp'); return json_encode($json); } $json['message'] = 'nothing to do'; return json_encode($json); }
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'); }
public function adminBooking() { $isAllowed = Util\Auth::isAdminAuthorized($this->signedUser); $json = []; $json['result'] = \Rebond\Core\ResultType::ERROR; if (!$isAllowed) { $json['message'] = Util\Lang::lang('accessNonAuthorized'); return json_encode($json); } $title = Util\Converter::toString('title', 'post'); $color = Util\Converter::toString('color', 'post'); $courtIds = Util\Converter::toArray('courtIds', 'post'); $startDate = Util\Converter::toDate('startDate', 'post', new \DateTime()); $endDate = Util\Converter::toDate('endDate', 'post', new \DateTime()); $days = Util\Converter::toArray('days', 'post'); $startTime = Util\Converter::toInt('startTime', 'post'); $endTime = Util\Converter::toInt('endTime', 'post'); $count = 0; // @todo validate param $json['startDate'] = $startDate->format('datetime'); $json['endDate'] = $endDate->format('datetime'); $options = []; $options['where'][] = ['id IN (?)', $courtIds]; $courts = \Own\Bus\Court\Data::loadAll($options); $book = new Book\Model(); $book->setType(\Own\Bus\BookingType::ADMIN); $book->setTitle($title); $book->setSequence(uniqid()); $book->setColor($color); $dateLoop = clone $startDate; $today = new \DateTime(); $now = (int) $today->format('H') * 60 + (int) $today->format('i'); $today->setTime(0, 0, 0); $rule = \Own\Bus\Rule\Data::loadById(1, true); $timeLength = $rule->getTimeLength(); foreach ($courts as $court) { $book->setCourtId($court->getId()); while ($dateLoop <= $endDate) { if ($dateLoop < $today) { $dateLoop->add(new \DateInterval('P1D')); continue; } if (!in_array($dateLoop->format('w'), $days)) { $dateLoop->add(new \DateInterval('P1D')); continue; } $possibleTime = (int) $court->getStartTime()->format('H') * 60 + (int) $court->getStartTime()->format('i'); $limitTime = (int) $court->getEndTime()->format('H') * 60 + (int) $court->getEndTime()->format('i'); while ($possibleTime < min($limitTime, $endTime)) { if ($possibleTime >= $startTime && ($dateLoop != $today || $possibleTime >= $now)) { $dateLoop->setTime(floor($possibleTime / 60), $possibleTime % 60, 0); // check for court already booked $options = []; $options['where'][] = ['court_id = ?', $court->getId()]; $options['where'][] = ['booking_date = ?', $dateLoop->format('Y-m-d H:i:00')]; $booking = Book\Data::load($options); if (!isset($booking)) { $book->setBookingDate($dateLoop); $book->save(); $book->setId(0); $count++; } } $dateLoop->setTime(0, 0, 0); $possibleTime += $timeLength; } $dateLoop->add(new \DateInterval('P1D')); } $dateLoop = clone $startDate; } $json['result'] = \Rebond\Core\ResultType::SUCCESS; $json['count'] = $count; return json_encode($json); }
public function run($app, $friendlyUrl) { // is site active if ($app->site()->getStatus() == 0) { $friendlyUrl = '/inactive'; } // retrieve page $page = \Rebond\Cms\Page\Data::loadByUrl($friendlyUrl); // this should never occur if (!isset($page)) { Error::kill(Error::PAGE_NOT_FOUND, $friendlyUrl, __FILE__, __LINE__); } // redirection if ($page->getRedirect() != '' && $page->getRedirect() != $friendlyUrl) { $friendlyUrl = Nav::readCmsRequest($page->getRedirect()); echo $this->run($app, $friendlyUrl); return; } // permission Auth::isAuthorized($app->user(), $page->getPermission(), true, $app->site()->getSignInUrl()); $app->setUrl($friendlyUrl); // layout $layout = \Rebond\Cms\Layout\Data::loadById($page->getLayoutId()); $tplLayout = new Template(Template::SITE, ['www']); // page components $options = []; $options['where'][] = 'gadget.status = 1'; $options['order'][] = 'gadget.display_order'; $gadgets = \Rebond\Cms\Gadget\Data::loadAllByPageId($page->getId(), $options); $cacheTime = $app->site()->getCacheTime(); if ($gadgets) { $this->app = $app; $this->gadgets = []; foreach ($gadgets as $gadget) { if ($gadget->getComponent()->getId() == 0) { Log::log(Error::COMPONENT_NOT_FOUND, 'title: ' . $gadget->getTitle() . ', componentId: ' . $gadget->getComponentId(), __FILE__, __LINE__); continue; } $component = $gadget->getComponent(); $appGadget = '\\Rebond\\App\\' . $component->getModule()->getTitle() . '\\Gadget'; $appMethod = $component->getMethod(); if (!method_exists($appGadget, $appMethod)) { Log::log(Error::GADGET_NOT_FOUND, 'gadget: ' . $appGadget . ', method: ' . $appMethod, __FILE__, __LINE__); continue; } if ($component->getStatus() !== StatusType::ACTIVE) { continue; } if ($component->getModule()->getStatus() !== StatusType::ACTIVE) { continue; } $name = $component->getModule()->getTitle() . '_' . $component->getMethod(); // look for cache if ($cacheTime > 0) { $html = Cache::getGadgetCache($name, $cacheTime); if (isset($html)) { $tplLayout->add('column' . $gadget->getCol(), $html); continue; } } $gadgetClass = $this->getGadget($appGadget); // get filter if ($component->getType() == ComponentType::SINGLE_ITEM || $component->getType() == ComponentType::FILTERED_LISTING) { if ($gadget->getFilterId() == 0) { Log::log(Error::EMPTY_FILTER, $name, __FILE__, __LINE__); continue; } else { $render = $gadgetClass->{$appMethod}($gadget->getFilterId()); } } else { if ($component->getType() == ComponentType::CUSTOM_LISTING) { $render = $gadgetClass->{$appMethod}($gadget->getCustomFilter()); } else { $render = $gadgetClass->{$appMethod}(); } } $tplLayout->add('column' . $gadget->getCol(), $render); // save cache if ($cacheTime > 0) { Cache::saveGadgetCache($name, $cacheTime, $render); } } } // check for empty columns $columns = $layout->getColumns(); $noComponent = '<div class="no-component">' . Lang::lang('noComponent') . '</div>'; $emptyValue = $app->logLevel() == 0 ? $noComponent : ''; for ($i = 1; $i <= $columns; $i++) { if ($tplLayout->varIsSet('column' . $i) === false) { $tplLayout->set('column' . $i, $emptyValue); } } // template $template = \Rebond\Cms\Template\Data::loadById($page->getTemplateId()); $tplMaster = new Template(Template::SITE, ['www']); // navHeader $isMenuCached = false; if ($template->getMenu() != \Rebond\Cms\MenuType::NONE) { // Get cache if ($cacheTime > 0) { $navHeader = Cache::getCache('navHeader', $template->getMenu() . '_' . $template->getMenuLevel(), $cacheTime); if (isset($navHeader)) { $isMenuCached = true; } } if (!$isMenuCached) { $navHeader = \Rebond\Cms\Page\Data::buildHeaderNav($template->getMenuLevel(), $template->getMenu()); // Save cache if ($cacheTime > 0) { Cache::saveCache('navHeader', $template->getMenu() . '_' . $template->getMenuLevel(), $cacheTime, $navHeader); } } $tpl = new Template(Template::SITE, ['www']); $tpl->set('title', $app->site()->getTitle()); $tpl->set('nav', \Rebond\Cms\Page\Service::renderNav($navHeader, $page->getFullUrl())); $tplMaster->set('navHeader', $tpl->render('nav-header')); } // breacrumb $isMenuCached = false; if ($template->getInBreadcrumb()) { // Get cache if ($cacheTime > 0) { $breadcrumb = Cache::getCache('breadcrumb', $page->getId(), $cacheTime); if (isset($breadcrumb)) { $isMenuCached = true; } } if (!$isMenuCached) { $breadcrumb = \Rebond\Cms\Page\Service::renderBreadcrumb($page->getId()); // Save cache if ($cacheTime > 0) { Cache::saveCache('breadcrumb', $page->getId(), $cacheTime, $breadcrumb); } } $tplMaster->set('breadcrumb', $breadcrumb); } // navSide $isMenuCached = false; if ($template->getSideNav() != \Rebond\Cms\SideNavType::NONE) { // Get cache if ($cacheTime > 0) { $navSide = Cache::getCache('navSide', $template->getSideNav() . '_' . $template->getSideNavLevel(), $cacheTime); if (isset($navSide)) { $isMenuCached = true; } } if (!$isMenuCached) { switch ($template->getSideNav()) { case \Rebond\Cms\SideNavType::PARENT_1: $currentId = $page->getParentId(); break; case \Rebond\Cms\SideNavType::CHILDREN: $currentId = $page->getId(); break; case \Rebond\Cms\SideNavType::HOME: $currentId = 1; break; case \Rebond\Cms\SideNavType::PARENT_2: $currentId = \Rebond\Cms\Page\Data::loadByParent($page->getParentId(), 1); break; case \Rebond\Cms\SideNavType::PARENT_3: $currentId = \Rebond\Cms\Page\Data::loadByParent($page->getParentId(), 2); break; } $navSide = \Rebond\Cms\Page\Data::buildSideNav($currentId, $template->getSideNavLevel()); // Save cache if ($cacheTime > 0) { Cache::saveCache('navSide', $template->getSideNav() . '_' . $template->getSideNavLevel(), $cacheTime, $navSide); } } $tpl = new Template(Template::SITE, ['www']); $tpl->set('nav', \Rebond\Cms\Page\Service::renderNav($navSide, $page->getFullUrl())); $tplMaster->set('navSide', $tpl->render('nav-side')); } // navFooter $isMenuCached = false; if ($template->getInFooter() != 0) { // Get cache if ($cacheTime > 0) { $navFooter = Cache::getCache('navFooter', $template->getFooterLevel(), $cacheTime); if (isset($navFooter)) { $isMenuCached = true; } } if (!$isMenuCached) { $navFooter = \Rebond\Cms\Page\Data::buildFooterNav($template->getFooterLevel()); // Save cache if ($cacheTime > 0) { Cache::saveCache('navFooter', $template->getFooterLevel(), $cacheTime, $navFooter); } } $tpl = new Template(Template::SITE, ['www']); $tpl->set('nav', \Rebond\Cms\Page\Service::renderNav($navFooter, $page->getFullUrl())); $tplMaster->set('navFooter', $tpl->render('nav-footer')); } $tplMaster->set('layout', $tplLayout->render($layout->getFilename())); // master // head if ($app->site()->getKeywords() != '') { $tplMaster->addMeta('keywords', $app->site()->getKeywords()); } if ($app->site()->getDescription() != '') { $tplMaster->addMeta('description', $app->site()->getDescription()); } $tplMaster->set('title', $page->getTitle()); $tplMaster->set('site', $app->site()->getTitle()); $tplMaster->set('skin', $app->skin()); $tplMaster->set('siteUrl', \Rebond\Config::getPath('siteUrl')); // bodyClass $tplMaster->set('bodyClass', $page->getClass()); // footer $ga = \Rebond\Core\Site\Service::renderGoogleAnalytics($app->site()->getGoogleAnalytics()); $tplMaster->set('footer', $ga); $tplMaster->addJs('//code.jquery.com/jquery-2.1.4.min.js'); $tplMaster->addJs('/js/lang-' . $app->lang() . '.js'); if ($app->site()->getJs() != '') { $jsList = explode(',', $app->site()->getJs()); foreach ($jsList as $js) { $tplMaster->addJs($js); } } if ($page->getJs() != '') { $jsList = explode(',', $page->getJs()); foreach ($jsList as $js) { $tplMaster->addJs($js); } } if ($app->env() == \Rebond\Config::ENV_PROD) { $tplMaster->addCss('/css/skin/' . $app->skin() . '/min.css'); $tplMaster->addJs('/js/min.js'); } else { $tplMaster->addCss('/css/normalize.css'); $tplMaster->addCss('/css/skin/' . $app->skin() . '/rebond.css'); $tplMaster->addCss('/css/skin/' . $app->skin() . '/custom.css'); $tplMaster->addJs('/js/rebond.js'); $tplMaster->addJs('/js/custom.js'); } if ($app->site()->getCss() != '') { $cssList = explode(',', $app->site()->getCss()); foreach ($cssList as $css) { $tplMaster->addCss($css); } } if ($page->getCss() != '') { $cssList = explode(',', $page->getCss()); foreach ($cssList as $css) { $tplMaster->addCss($css); } } return $tplMaster->render($template->getFilename()); }
public function phpinfo() { // auth Auth::isAdminAuthorized($this->signedUser, 'admin.tools', true, '/'); // view $this->setTpl(); // main $tplMain = new Template(Template::SITE, ['admin', 'tools']); ob_start(); phpinfo(); $info = ob_get_contents(); ob_end_clean(); $info = preg_replace('%^.*<body>(.*)</body>.*$%ms', '$1', $info); $tplMain->set('info', $info); // layout $this->tplLayout->set('column1', $tplMain->render('phpinfo')); // master $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col')); return $this->tplMaster->render('tpl-default'); }
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'); }
public function changePassword() { $signedUser = $this->app->user(); // auth if (!Util\Auth::isAuth($signedUser)) { header('Location: /profile'); exit; } $form = new \Rebond\Core\User\Form($signedUser); // action $change = Util\Converter::toString('resetPassword', 'post'); if (isset($change)) { $form->changePassword('/profile'); } $tpl = new Util\Template(Util\Template::MODULE, ['app', 'User']); $tpl->set('item', $form); $tpl->set('checkCurrentPassword', true); return $tpl->render('password-change'); }
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'); }
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'); }
private function hasPrivilege($permission) { return Auth::isAdminAuthorized($this->signedUser, $permission); }