public static function getCurrentMatch($id, array $redirect = []) { $options = []; $options['clearSelect'] = true; $options['select'][] = self::getList(['id', 'player_match1_id', 'player_match2_id', 'surface', 'current_set', 'best_of_sets', 'type', 'winner_id', 'position', 'tournament_id', 'league_id', 'status', 'scheduled']); $options['select'][] = \Own\Bus\PlayerMatch\Data::getList(['id', 'player_id'], 'match_player_match'); $options['join'][] = 'bus_player_match match_player_match'; $options['where'][] = 'match_player_match.id = match.player_match1_id OR match_player_match.id = match.player_match2_id'; $options['where'][] = ['match_player_match.player_id = ?', $id]; $options['where'][] = 'match.status IN (1,2,3)'; $options['order'][] = 'match.scheduled'; $match = \Own\Bus\Match\Data::load($options); if (isset($match)) { if (in_array($match->getStatus(), $redirect)) { // match ready/playing and in less than half Engine::DAY if (in_array($match->getStatus(), [MatchStatus::READY, MatchStatus::PLAYING])) { // cannot play if other match in less than 1/10 Day if ($match->getScheduled() < time() + Engine::DAY * 360) { Util\Session::siteError('matchPlaying', null, '/match/schedule'); } else { Util\Session::set('siteSuccess', Util\Lang::lang('nextMatch', [$match->getScheduled()->format()])); } } } return $match; } else { if (in_array(0, $redirect)) { Util\Session::siteError('noMatch', null, '/match'); } } return null; }
public static function isAdminAuthorized(\Rebond\Core\User\Model $user, $permission = null, $show = false, $redirect = null) { if (!self::isAuth($user) || !$user->getIsAdmin()) { if (isset($redirect)) { header('Location: ' . $redirect); exit; } return false; } if (!isset($permission) || $permission == '') { return true; } $auth = \Rebond\Core\User\Data::hasAccess($user->getId(), $permission, true); if ($auth != 0) { return true; } if ($show) { Session::set('adminError', Lang::lang('accessNonAuthorized')); } Log::log(Error::NOT_ENOUGH_PRIVILEGE, Lang::lang('accessNonAuthorized', [$permission]), __FILE__, __LINE__); if (isset($redirect)) { header('Location: ' . $redirect); exit; } return false; }
public function site() { // auth Auth::isAdminAuthorized($this->signedUser, 'admin.config.site', true, '/configuration'); $site = \Rebond\Core\Site\Data::loadById(1); if (!isset($site)) { \Rebond\Util\Error::kill(\Rebond\Util\Error::SITE_NOT_FOUND, 'id: 1', __FILE__, __LINE__); } $siteForm = new \Rebond\Core\Site\Form($site); // action if (isset($_POST['save'])) { Auth::isAdminAuthorized($this->signedUser, 'admin.config.site.edit', true, '/'); if ($siteForm->setFromPost()->validate()->isValid()) { $siteForm->getModel()->save(); \Rebond\Core\Site\Service::updateIsCms($siteForm->getModel()->getIsCms()); Session::adminSuccess('saved', '/configuration/site'); } else { Session::set('adminError', $siteForm->getValidation()->getMessage()); } } // view $this->setTpl(); // main $tplMain = new Template(Template::MODULE, ['core', 'site']); $tplMain->set('item', $siteForm); // layout if (Auth::isAdminAuthorized($this->signedUser, 'admin.config.site.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 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'); }
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 edit() { // auth Auth::isAdminAuthorized($this->signedUser, 'admin.content', true, '/content/'); // check $moduleName = Converter::string('module'); $id = Converter::int('id'); $module = $this->findModule($moduleName); // action $appModel = '\\Rebond\\App\\' . $module->getTitle() . '\\Model'; $appData = '\\Rebond\\App\\' . $module->getTitle() . '\\Data'; $appForm = '\\Rebond\\App\\' . $module->getTitle() . '\\Form'; $model = $appData::loadById($id); if (isset($model)) { $title = $model->getTitle(); } else { $title = \Rebond\Util\Lang::lang('new', [$moduleName]); $model = new $appModel(); } $model->loadModule(); $form = new $appForm($model); // action if (isset($_POST['save'])) { Auth::isAdminAuthorized($this->signedUser, 'admin.content.edit', true, '/content/edit'); $model->setAuthorId($this->signedUser->getId()); if ($form->setFromPost()->validate()->isValid()) { $model->save(); $status = $module->getWorkflow() == 0 ? 'published' : 'pending'; Session::adminSuccess('saved', '/content/#!/' . $moduleName . '/' . $status); } else { Session::set('adminError', $form->getValidation()->getMessage()); } } // view $this->setTpl(); $tplMain = new Template(Template::MODULE, ['app', $moduleName]); // main $tplMain->set('item', $form); $tplMain->set('title', $title); $tplMain->set('filter', $module->getHasFilter()); // layout if (Auth::isAdminAuthorized($this->signedUser, 'admin.content.edit', false)) { $this->tplLayout->set('column1', $tplMain->render('admin-editor')); } else { $this->tplLayout->set('column1', $tplMain->render('admin-view')); } // master $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col')); $this->tplMaster->set('jsLauncher', 'contentEditor'); $this->tplMaster->addJs('/js/tinymce/tinymce.min.js'); return $this->tplMaster->render('tpl-default'); }
public function edit() { // auth Util\Auth::isAuthorized($this->signedUser, 'member', false, '/profile/sign-in'); $playerForm = new \Own\Bus\Player\Form($this->player); $save = Util\Converter::toString('save', 'post'); if ($save != '') { $properties = ['country', 'hand', 'toss', 'acceptChallenge', 'sendNotificationEmail']; $playerForm->setFromPost($properties)->validate($properties); $fieldAvatar = Util\Validate::validate('avatar', $playerForm->getModel()->getUser()->getAvatarId(), ['media' => false, 'image' => true]); $playerForm->getValidation()->addField($fieldAvatar); if (!$playerForm->getValidation()->isValid()) { Util\Session::set('siteError', $playerForm->getValidation()->getMessage()); } else { $this->player->save(); $obj = Util\Media::uploadForm('avatarId'); if ($obj->result == ResultType::SUCCESS) { $this->signedUser->setAvatarId($obj->id); } if ($obj->result != ResultType::ERROR) { $this->signedUser->save(); } else { Util\Session::set('siteError', $obj->message); } Util\Session::setAndRedirect('siteSuccess', 'Profile saved', '/profile'); } } // view $this->setTpl(); // main $tplMain = new Util\Template(Util\Template::MODULE, ['bus', 'player']); $tplMain->set('item', $playerForm); // layout $this->tplLayout->set('column1', $tplMain->render('editor-site')); // template $this->tplMaster->set('layout', $this->tplLayout->render('layout-center')); return $this->tplMaster->render('tpl-default'); }
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'); }
public function editFolder() { // auth Auth::isAdminAuthorized($this->signedUser, 'admin.media', true, '/media'); // check $id = Converter::int('id'); $pid = Converter::int('pid'); $save = Converter::int('save', 'post'); $folder = \Rebond\Core\Folder\Data::loadById($id, true); if ($pid != 0) { $folder->setParentId($pid); } $form = new \Rebond\Core\Folder\Form($folder); // action if (isset($save)) { Auth::isAdminAuthorized($this->signedUser, 'admin.media.folder.edit', true, '/media'); if ($form->setFromPost()->validate()->isValid()) { $folder->save(); Session::adminSuccess('saved', '/media'); } else { Session::set('adminError', $form->getValidation()->getMessage()); } } // view $this->setTpl(); // main $tplMain = new Template(Template::MODULE, ['core', 'folder']); $tplMain->set('item', $form); // layout if (Auth::isAdminAuthorized($this->signedUser, 'admin.media.folder.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 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()); } }
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 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 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 view() { $matchId = Util\Converter::toInt('id'); $live = Util\Converter::toBool('live'); $key = Util\Converter::toString('key'); $options = []; $options['where'][] = 'match.id = ' . $matchId; $options['where'][] = 'match.status IN (' . MatchStatus::PLAYING . ', ' . MatchStatus::FINISHED . ')'; $match = \Own\Bus\Match\Data::load($options); if (!isset($match)) { Util\Session::siteError('matchNotFound', null, '/match/schedule'); } if ($this->player == null) { $this->player = new \Own\Bus\Player\Model(); } $realKey = \Rebond\Util\Security::encrypt($match->getId()); $hasViewed = $match->hasViewed($this->player->getId()); $options = []; $options['where'][] = ['match_id = ?', $match->getId()]; $options['order'][] = 'id'; $matchLog = \Own\Bus\Log\Data::loadAll($options); if ($live && count($matchLog) == 0) { $live = false; Util\Session::set('siteError', Util\Lang::lang('noMatchLog')); $key = $realKey; } // auth if (!$live) { if ($match->getStatus() == MatchStatus::PLAYING) { Util\Session::siteError('matchPlaying', null, '/match/schedule'); } if ($key != $realKey && !$hasViewed && count($matchLog) > 0 && ($this->player->getId() == $match->getPlayerMatch1()->getPlayerId() || $this->player->getId() == $match->getPlayerMatch2()->getPlayerId())) { $live = true; } } // view $this->setTpl(); // main $tplMain = new Util\Template(Util\Template::SITE, ['www']); $tplMain->set('match', $match); if ($live) { $logs = []; foreach ($matchLog as $log) { $logs[] = $log->toArray(); } $tplMain->set('logs', $logs); $isLive = !$hasViewed && $match->getModifiedDate() > time() - 1800 ? 1 : 0; $tplMain->set('isLive', $isLive); $tplMain->set('key', $realKey); $tpl = 'match-view-live'; $this->tplMaster->set('bodyClass', 'body-' . $match->getSurface()); } else { if ($key == $realKey) { $match->setViewed($this->player->getId()); \Own\Bus\Notification\Data::updateViewedByPlayerIdAndMatchId($this->player->getId(), $match->getId()); } $tpl = 'match-view'; $options = []; $options['where'][] = ['match_id = ?', $match->getId()]; $notification = \Own\Bus\Notification\Data::load($options); $tplMain->set('notification', $notification); $tplMain->set('serveLabels', \Own\Bus\PlayerMatch\Service::getServeLabels()); $tplMain->set('player1ServeStats', \Own\Bus\PlayerMatch\Service::getServeStats($match->getPlayerMatch1())); $tplMain->set('player2ServeStats', \Own\Bus\PlayerMatch\Service::getServeStats($match->getPlayerMatch2())); $tplMain->set('returnLabels', \Own\Bus\PlayerMatch\Service::getReturnLabels()); $tplMain->set('player1ReturnStats', \Own\Bus\PlayerMatch\Service::getReturnStats($match->getPlayerMatch1())); $tplMain->set('player2ReturnStats', \Own\Bus\PlayerMatch\Service::getReturnStats($match->getPlayerMatch2())); $tplMain->set('otherLabels', \Own\Bus\PlayerMatch\Service::getOtherLabels()); $tplMain->set('player1OtherStats', \Own\Bus\PlayerMatch\Service::getOtherStats($match->getPlayerMatch1())); $tplMain->set('player2OtherStats', \Own\Bus\PlayerMatch\Service::getOtherStats($match->getPlayerMatch2())); $tplMain->set('attitudeLabels', \Own\Bus\PlayerMatch\Service::getAttitudeLabels()); $tplMain->set('player1AttitudeStats', \Own\Bus\PlayerMatch\Service::getAttitudeStats($match->getPlayerMatch1())); $tplMain->set('player2AttitudeStats', \Own\Bus\PlayerMatch\Service::getAttitudeStats($match->getPlayerMatch2())); $tplMain->set('mentalLabels', \Own\Bus\PlayerMatch\Service::getMentalLabels()); $tplMain->set('player1MentalStats', \Own\Bus\PlayerMatch\Service::getMentalStats($match->getPlayerMatch1())); $tplMain->set('player2MentalStats', \Own\Bus\PlayerMatch\Service::getMentalStats($match->getPlayerMatch2())); $tplMain->set('shotLabels', \Own\Bus\PlayerMatch\Service::getShotLabels()); $tplMain->set('player1ShotStats', \Own\Bus\PlayerMatch\Service::getShotStats($match->getPlayerMatch1())); $tplMain->set('player2ShotStats', \Own\Bus\PlayerMatch\Service::getShotStats($match->getPlayerMatch2())); $tplMain->set('notificationCount', \Own\Bus\Notification\Data::countByPlayerId($this->player->getId())); } // layout $this->tplLayout->set('column1', $tplMain->render($tpl)); // template $this->tplMaster->set('layout', $this->tplLayout->render('layout-center')); 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 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; } } } }
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'); }
public function feedback() { // auth Auth::isAdminAuthorized($this->signedUser, null, true, '/profile/sign-in'); // prep $save = Converter::string('save', 'post'); // check $feedback = new \Rebond\Core\Feedback\Model(); $feedback->setStatus(\Rebond\Core\StatusType::INACTIVE); $feedback->setUserId($this->signedUser->getId()); $feedback->setTitle($this->signedUser->getUsername() . '-' . date('ymd-His')); $form = new \Rebond\Core\Feedback\Form($feedback); // action if (isset($save)) { if ($form->setFromPost()->validate()->isValid()) { $feedback->save(); Session::adminSuccess('feedbackSent', '/profile/feedback'); } else { Session::set('adminError', $form->getValidation()->getMessage()); } } // view $this->setTpl(); $tplMain = new Template(Template::MODULE, ['core', 'feedback']); $tplMain->set('item', $form); // layout $this->tplLayout->set('column1', $tplMain->render('editor')); // master $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col')); $this->tplMaster->set('jsLauncher', 'profile'); return $this->tplMaster->render('tpl-default'); }
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'); }