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 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 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 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 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 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 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 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 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 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 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 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); }