function edit() { $registry = Registry::getInstance(); $locales = LocaleManager::getLocales(); $course = new Course(intval($_GET['id'])); $owner = new Admin($course->ownerId); if ($_POST['action'] == 'save') { //d($_POST, 1); $course->ownerId = intval($_SESSION['admin']['id']); $course->state = intval($_POST['state'] == 'on'); foreach (array_keys($locales) as $localeId) { $course->l10n->loadDataFromArray($localeId, ['name' => trim($_POST['name_' . $localeId]), 'meta' => trim($_POST['meta_' . $localeId]), 'description' => trim($_POST['description_' . $localeId]), 'brief' => trim($_POST['brief_' . $localeId]), 'url' => trim($_POST['url_' . $localeId]), 'title' => trim($_POST['title_' . $localeId]), 'state' => intval($_POST['state_' . $localeId])]); } $course->save(); header('Location: /cms/course/list'); exit; } else { $i18n = new I18n($registry->get('i18n_path') . 'course.xml'); $data = ['course' => $course, 'lessons' => Lesson::getList($course->id), 'owner' => $owner]; $renderer = new Renderer(Page::MODE_NORMAL); $pTitle = $i18n->get($course->id ? 'update_mode' : 'append_mode'); $renderer->page->set('title', $pTitle)->set('h1', $pTitle)->set('content', CourseEditView::get($data)); $renderer->loadPage(); $renderer->output(); } }
function __construct() { $registry = Registry::getInstance(); $i18n = new I18n($registry->get('i18n_path') . 'admin.xml'); if ($_POST['action'] == 'login') { if ($_POST['login'] . $_POST['password']) { if (LoginError::isBlocked()) { $message = $i18n->get('error_limit_exceeded'); } else { $admin = Admin::getInstance($_POST['login'], $_POST['password']); if ($admin->id) { Admin::setProperty($admin->id, 'date_login', date('Y-m-d H:i:s')); $_SESSION['admin'] = ['id' => $admin->id, 'locale' => $admin->locale, 'name' => $admin->name]; unset($_SESSION['login_error']); header("Location: /cms"); exit; } else { LoginError::register($_POST['login'], $_POST['password']); $message = $i18n->get('login_error'); $_SESSION['login_error'] = 1; } } } else { $message = $i18n->get('empty_login_of_password'); } } $renderer = new Renderer(Page::MODE_NORMAL); $pTitle = $i18n->get('login_title'); $renderer->page->set('title', $pTitle)->set('h1', $pTitle)->set('content', LoginView::get(['message' => $message])); $renderer->loadPage(); $renderer->output(); }
function edit() { $registry = Registry::getInstance(); $application = Application::getInstance(); $locale = $registry->get('locale'); $locales = LocaleManager::getLocales(); $exercise = new Exercise(intval($_GET['id'])); if ($_POST['action'] == 'save') { //d($_POST, 1); $exercise->name = trim($_POST['name']); $exercise->description = trim($_POST['description']); $exercise->controller = trim($_POST['controller']); $exercise->configTemplate = trim($_POST['config_template']); $exercise->save(); header('Location: /cms/exercise/list'); exit; } else { $i18n = new I18n($registry->get('i18n_path') . 'exercise.xml'); $data = ['exercise' => $exercise]; $renderer = new Renderer(Page::MODE_NORMAL); $pTitle = $i18n->get($exercise->id ? 'update_mode' : 'append_mode'); $renderer->page->set('title', $pTitle)->set('h1', $pTitle)->set('content', ExerciseEditView::get($data)); $renderer->loadPage(); $renderer->output(); } }
static function get($data) { $application = Application::getInstance(); $registry = Registry::getInstance(); $tpl = new Template($registry->get('template_path') . 'login.htm'); return $tpl->apply(['message' => $data['message'], 'loginError' => $_SESSION['login_error'], 'site_root' => $application->siteRoot]); }
function __construct($url = NULL, $forceHidden = FALSE, $alternativeUrl = '404') { if ($url) { $registry = Registry::getInstance(); $db = $registry->get(self::DB); $rsp = $db->query("SELECT * FROM `" . self::TABLE . "` WHERE `url`=" . $db->escape($url) . ($forceHidden ? '' : ' AND `show`<>0')); if ($sap = $db->fetch($rsp)) { $this->headers = array('HTTP/1.1 200 OK' => TRUE, 'Status: 200 OK' => TRUE); $this->content = $sap['html']; $this->breadcrumbs = $sap['breadcrumbs']; $this->h1 = $sap['h1']; $this->mode = $sap['mode']; $this->title = $sap['title']; $this->metaTags = $sap['meta']; } else { $this->headers = array('HTTP/1.1 404 Not found' => TRUE, 'Status: 404 Not found' => TRUE); $rsp = $db->query("SELECT * FROM `" . self::TABLE . "` WHERE `url`=" . $db->escape($alternativeUrl)); if ($sap = $db->fetch($rsp)) { $this->content = $sap['html']; $this->breadcrumbs = $sap['breadcrumbs']; $this->h1 = $sap['title']; $this->mode = $sap['mode']; $this->title = $sap['meta_title']; $this->metaTags = $sap['meta']; $this->renderProperty('content_main', array('original_url' => $url)); } else { $this->content = 'Error: Page not found.'; } } } }
function edit() { $registry = Registry::getInstance(); $admin = new Admin($id = intval($_GET['id'])); if ($_POST['action'] == 'save') { //d($_POST, 1); $admin->description = trim($_POST['description']); $admin->email = trim($_POST['email']); $admin->login = trim($_POST['login']); $admin->name = trim($_POST['name']); $admin->rights = intval($_POST['rights']); $admin->state = intval($_POST['state'] == 'on'); $admin->locale = trim($_POST['locale']); if ($_POST['password']) { $admin->setNewPassword($_POST['password']); } $admin->save(); header('Location: /cms/admin/list'); exit; } else { $i18n = new I18n($registry->get('i18n_path') . 'admin.xml'); $pTitle = $i18n->get($admin->id ? 'update_mode' : 'append_mode'); $renderer = new Renderer(Page::MODE_NORMAL); $renderer->page->set('title', $pTitle)->set('h1', $pTitle)->set('content', AdminEditView::get(['admin' => $admin])); $renderer->loadPage(); $renderer->output(); } }
function __construct($table = self::TABLE) { $db = Registry::getInstance()->get(self::DB); $recordset = $db->getRecordset("SELECT * FROM `" . self::TABLE . "` ORDER BY `name`"); while ($record = $recordset->fetch()) { $this->values[$record->name] = new SetupItem($this, $record); } }
function save() { if ($name = $_GET['name']) { $value = $_GET['value'] . ''; Registry::getInstance()->get('setup')->updateValue($name, $value); } echo $value; }
static function get($data) { $application = Application::getInstance(); $registry = Registry::getInstance(); $router = $data['router']; $tpl = new Template($registry->get('template_path') . 'router_edit.htm'); return $tpl->apply(['id' => $router->id, 'name' => htmlspecialchars($router->name), 'url' => htmlspecialchars($router->url), 'controller' => $router->controller, 'site_root' => $application->siteRooot]); }
static function get($data) { $application = Application::getInstance(); $registry = Registry::getInstance(); $exercise = $data['exercise']; $tpl = new Template($registry->get('template_path') . 'exercise_edit.htm'); return $tpl->apply(['id' => $exercise->id, 'name' => htmlspecialchars($exercise->name), 'description' => htmlspecialchars($exercise->description), 'controller' => htmlspecialchars($exercise->controller), 'config_template' => htmlspecialchars($exercise->configTemplate), 'site_root' => $application->siteRooot]); }
static function deleteAll($parentId) { $l10n = new self($parentId); $materialPath = Registry::getInstance()->get('material_path'); foreach (array_keys($l10n->getLocales()) as $localeId) { @unlink($materialPath . $l10n->get('fileName', $localeId)); } parent::deleteAll($parentId); }
/** * Создание экземпляра объекта из БД. * @param string $templateAlias идентификатор шаблона * @param string $dbName ключ для поиска объекта БД в Registry * @param string $tableName имя таблицы в БД * @param string $keyField имя поля, по которому происходит поиск идентификатора шаблона в БД * @param string $valueField имя поля, содержащего шаблон */ function __construct($templateAlias, $dbName = self::DEFAULT_DB, $tableName = self::DEFAULT_TABLE, $keyField = self::DEFAULT_FIELD_KEY, $valueField = self::DEFAULT_FIELD_VALUE) { $db = Registry::getInstance()->get('db'); $record = $db->getRecord("SELECT * FROM `" . $db->realEscapeString($tableName) . "` WHERE `" . $db->realEscapeString($keyField) . "`=" . $db->escape($templateAlias)); if ($record) { $this->tpl = $record->getValue($valueField); } else { echo __METHOD__ . "({$tableName}.{$keyField}={$templateAlias}) Alias not found."; } }
static function getList() { $list = []; $db = Registry::getInstance()->get(self::DB); $db->query("SELECT * FROM `" . self::TABLE . "` ORDER BY `alias`"); while ($sa = $db->fetch($rs)) { $list[$sa['id']] = $sa; } return $list; }
function save() { $db = Registry::getInstance()->get(self::DB); $record = ['name' => $this->name, 'description' => $this->description, 'controller' => $this->controller, 'config_template' => $this->configTemplate]; if ($this->id) { $db->update(self::TABLE, $record, "`id`=" . intval($this->id)); } else { $db->insert(self::TABLE, $record) or die($db->lastError); $this->id = $db->insertId(); } }
function save() { $db = Registry::getInstance()->get('db'); $record = array('name' => trim($this->name), 'url' => trim($this->url), 'controller' => trim($this->controller)); if ($this->id) { $db->update(self::TABLE, $record, "id=" . $this->id); } else { $record[self::ORDER_FIELD_NAME] = self::getNextOrderIndex(); $db->insert(self::TABLE, $record); } }
function edit() { $registry = Registry::getInstance(); $locales = LocaleManager::getLocales(); $id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT); if (!$id) { $lesson = new Lesson(filter_input(INPUT_GET, 'lesson_id', FILTER_VALIDATE_INT)); $lessonId = $lesson->id; if (!$lessonId) { header('Location: /cms/course/list'); exit; } } $stage = new Stage($id); if ($_POST['action'] == 'save') { //d($_POST, 1); if (!$stage->id) { $exercise = new Exercise(filter_input(INPUT_POST, 'exercise_id', FILTER_VALIDATE_INT)); $exerciseId = $exercise->id; //die(print_r($_POST)); if (!$exerciseId) { header('Location: /cms/course/list'); exit; } $stage->lessonId = $lessonId; $stage->exerciseId = $exerciseId; $stage->settings = $exercise->configTemplate; } foreach (array_keys($locales) as $localeId) { $stage->l10n->loadDataFromArray($localeId, ['name' => trim($_POST['name_' . $localeId]), 'meta' => trim($_POST['meta_' . $localeId]), 'description' => trim($_POST['description_' . $localeId]), 'brief' => trim($_POST['brief_' . $localeId]), 'url' => trim($_POST['url_' . $localeId]), 'title' => trim($_POST['title_' . $localeId])]); } $stage->name = filter_input(INPUT_POST, 'name'); $stage->save(); header('Location: /cms/lesson/edit?id=' . $stage->lessonId); exit; } else { $i18n = new I18n($registry->get('i18n_path') . 'stage.xml'); $data['stage'] = $stage; $data['materials'] = Material::getList($this->id); if ($stage->id) { $exercise = new Exercise($stage->exerciseId); $data['exerciseName'] = $exercise->name; } else { $data['exercises'] = Exercise::getList(); } $renderer = new Renderer(Page::MODE_NORMAL); $pTitle = $i18n->get($lesson->id ? 'update_mode' : 'append_mode'); $renderer->page->set('title', $pTitle)->set('h1', $pTitle)->set('content', StageEditView::get($data)); $renderer->loadPage(); $renderer->output(); } }
/** * Сохранение объекта в базе данных */ function save() { $db = Registry::getInstance()->get('db'); $record = ['source' => $this->source, 'destination' => $this->destination, 'active' => $this->active, 'status' => $this->status]; if ($this->id) { $db->update(self::TABLE, $record, "`id`=" . $this->id); } else { $record['date_create'] = $db->makeForcedValue('NOW()'); $record[self::ORDER_FIELD_NAME] = 0; $db->insert(self::TABLE, $record) or die($db->lastError); $db->update(self::TABLE, ['num' => $db->makeForcedValue('`num`+1')], ''); } }
static function get($data) { $registry = Registry::getInstance(); $application = Application::getInstance(); $localeId = $registry->get('locale'); $localeData = LocaleManager::getLocaleData($localeId); $tpl = new Template($registry->get('template_path') . 'course.htm'); $tpli = new template($registry->get('template_path') . 'course_item.htm'); $listItems = ''; foreach ($data['list'] as $item) { $listItems .= $tpli->apply(['id' => $item->id, 'name' => $item->l10n->get('name', $localeId), 'owner' => $data['ownerList'][$item->ownerId]->name, 'dateCreate' => date($localeData['dateFormat'], $item->dateCreate), 'dateUpdate' => $item->dateUpdate ? date($localeData['dateFormat'], $item->dateUpdate) : '', 'active' => $item->state, 'rights' => $item->rights]); } return $tpl->apply(['items' => $listItems, 'site_root' => $application->siteRoot]); }
static function delete($entityId) { if ($id = intval($entityId)) { $db = Registry::getInstance()->get('db'); if (defined('static::ORDER_FIELD_NAME')) { if ($record = $db->getRecord("SELECT `" . static::ORDER_FIELD_NAME . "` FROM `" . static::TABLE . "` WHERE `id`={$id}")) { $db->delete(static::TABLE, $id); $db->update(static::TABLE, [static::ORDER_FIELD_NAME => $db->makeForcedValue("`" . static::ORDER_FIELD_NAME . "`-1")], "`" . static::ORDER_FIELD_NAME . "`>={$sa[static::ORDER_FIELD_NAME]}"); } } else { $db->delete(static::TABLE, $id); } } }
static function get($data) { $registry = Registry::getInstance(); switch ($data['pageMode']) { case Page::MODE_POPUP: $templateFileName = 'popup.htm'; break; case Page::MODE_NORMAL: default: $templateFileName = 'main.htm'; } $tpl = new TemplateFile($registry->get('template_path') . $templateFileName); return $tpl->getContent(); }
static function get($data) { $application = Application::getInstance(); $registry = Registry::getInstance(); $tpl = new Template($registry->get('template_path') . 'exercise.htm'); $tpli = new Template($registry->get('template_path') . 'exercise_item.htm'); $list = $data['list']; $cnt = count($data['list']); $listItems = ''; foreach ($list as $line) { $listItems .= $tpli->apply(['id' => $line->id, 'name' => $line->name, 'description' => $line->description, 'controller' => $line->controller, 'configTemplate' => $line->configTemplate]); } return $tpl->apply(['count' => $cnt, 'items' => $listItems, 'site_root' => $application->siteRoot]); }
static function get($data) { $application = Application::getInstance(); $registry = Registry::getInstance(); $i18n = new I18n($registry->get('i18n_path') . 'admin.xml'); $localeData = LocaleManager::getLocaleData($registry->get('locale')); $tpl = new Template($registry->get('template_path') . 'admin.htm'); $tpli = new template($registry->get('template_path') . 'admin_item.htm'); $listItems = ''; foreach ($data['list'] as $item) { $listItems .= $tpli->apply(['id' => $item->id, 'description' => $item->description, 'email' => $item->email, 'login' => $item->login, 'name' => $item->name, 'state' => $i18n->get('state' . $item->state), 'rights' => $item->rights, 'dateCreate' => date($localeData['dateFormat'], $item->dateCreate), 'dateLogin' => $item->dateLogin ? date($localeData['dateFormat'], $item->dateLogin) : '', 'locale' => $item->locale]); } return $tpl->apply(['items' => $listItems, 'site_root' => $application->siteRoot]); }
/** * Сохранение объекта в БД при добавлении или редактировании */ function save() { $db = Registry::getInstance()->get(self::DB); $properties = ['stage_id' => $this->stageId, 'name' => $this->name, 'description' => $this->description]; if ($this->id) { $db->update(self::TABLE, $properties, "`id`=" . intval($this->id)); } else { $properties['hash'] = sha1(time()); $db->insert(self::TABLE, $properties) or die($db->lastError); $this->id = $db->insertId(); $this->l10n->parentId = $this->id; } $this->l10n->save(); }
static function setApplicationLocale() { $registry = Registry::getInstance(); if (isset($_SESSION['admin']['locale'])) { $locale = $_SESSION['admin']['locale']; } elseif ($userId = intval($_SESSION['user']['locale'])) { $locale = $_SESSION['user']['locale']; } else { $locale = $registry->get('setup')->get('locale'); } $registry->set('locale', $locale); $localeData = self::getLocaleData($locale); setlocale(LC_ALL, $localeData['locale']); // echo strftime("%A %d %B %Y", mktime(0, 0, 0, 12, 1, 1968)); }
/** * Сохранение объекта в БД при добавлении или редактировании */ function save() { $db = Registry::getInstance()->get(self::DB); $properties = ['lesson_id' => $this->lessonId, 'exercise_id' => $this->exerciseId, 'name' => $this->name, 'settings' => $this->settings]; if ($this->id) { $db->update(self::TABLE, $properties, "`id`=" . intval($this->id)); } else { $this->order = self::getNextOrderIndex(); $properties[self::ORDER_FIELD_NAME] = $this->order; $db->insert(self::TABLE, $properties) or die($db->lastError); $this->id = $db->insertId(); $this->l10n->parentId = $this->id; } $this->l10n->save(); }
function __construct() { $application = Application::getInstance(); if ($_SESSION['admin']['id']) { // main menu switch ($application->segment[1]) { case 'admin': $controller = new AdminController(); break; case 'router': $controller = new RouterController(); break; case 'redirect': $controller = new RedirectController(); break; case 'setup': $controller = new SetupController(); break; case 'course': $controller = new CourseController(); break; case 'lesson': $controller = new LessonController(); break; case 'stage': $controller = new StageController(); break; case 'exercise': $controller = new ExerciseController(); break; case 'logout': unset($_SESSION['admin']); header('Location: /cms'); break; default: $registry = Registry::getInstance(); $i18n = new I18n($registry->get('i18n_path') . 'cms.xml'); $renderer = new Renderer(Page::MODE_NORMAL); $pTitle = $i18n->get('title'); $renderer->page->set('title', $pTitle)->set('h1', $pTitle)->set('content', ''); $renderer->loadPage(); $renderer->output(); } } else { // authent $controller = new LoginController(); } }
static function get($data) { $application = Application::getInstance(); $registry = Registry::getInstance(); $locale = $registry->get('locale'); $locales = LocaleManager::getLocales(); $tplso = new Template($registry->get('template_path') . 'select_option.htm'); $admin = $data['admin']; $localeItems = ''; foreach ($locales as $locale => $localeData) { $localeItems .= $tplso->apply(['name' => $localeData['name'], 'value' => $locale, 'selected' => $locale == $admin->locale]); } $localeData = LocaleManager::getLocaleData($registry->get('locale')); $tpl = new Template($registry->get('template_path') . 'admin_edit.htm'); return $tpl->apply(['id' => $admin->id, 'description' => htmlspecialchars($admin->description), 'email' => htmlspecialchars($admin->email), 'login' => htmlspecialchars($admin->login), 'name' => htmlspecialchars($admin->name), 'rights' => $admin->rights, 'state' => $admin->state, 'localeItems' => $localeItems, 'dateCreate' => date($localeData['dateFormat'], $admin->dateCreate), 'dateLogin' => $admin->dateLogin ? date($localeData['dateFormat'] . ' H:i', $admin->dateLogin) : '', 'site_root' => $application->siteRoot]); }
static function get($data) { $registry = Registry::getInstance(); $application = Application::getInstance(); $locales = LocaleManager::getLocales(); $locale = $registry->get('locale'); $tpl = new Template($registry->get('template_path') . 'stage_edit.htm'); $tplTab = new Template($registry->get('template_path') . 'stage_edit_tab.htm'); $tplTabContent = new Template($registry->get('template_path') . 'stage_edit_tab_content.htm'); $tplMaterialItem = new Template($registry->get('template_path') . 'material_item.htm'); $tplMaterialL10hHeaderItem = new Template($registry->get('template_path') . 'material_l10n_header_item.htm'); $tplMaterialL10nItem = new Template($registry->get('template_path') . 'material_l10n_item.htm'); $tplMaterialAddItem = new Template($registry->get('template_path') . 'material_add_item.htm'); $tplMaterialAddL10nItem = new Template($registry->get('template_path') . 'material_add_l10n_item.htm'); $tplso = new Template($registry->get('template_path') . 'select_option.htm'); $stage = $data['stage']; $tabItems = ''; $tabContentItems = ''; $materialL10nItems = ''; foreach ($locales as $localeId => $localeData) { $tabItems .= $tplTab->apply(['localeId' => $localeId, 'name' => $localeData['name']]); $tabContentItems .= $tplTabContent->apply(['name' => htmlspecialchars($stage->l10n->get('name', $localeId)), 'meta' => htmlspecialchars($stage->l10n->get('meta', $localeId)), 'description' => htmlspecialchars($stage->l10n->get('description', $localeId)), 'brief' => htmlspecialchars($stage->l10n->get('brief', $localeId)), 'url' => htmlspecialchars($stage->l10n->get('url', $localeId)), 'title' => htmlspecialchars($stage->l10n->get('title', $localeId)), 'localeId' => $localeId]); $materialL10nHeaderItems .= $tplMaterialL10hHeaderItem->apply(['locale' => $localeData['name']]); } $materialItems = ''; foreach ($data['materials'] as $materialId => $material) { $materialL10nItems = ''; foreach ($locales as $localeId => $localeData) { $materialL10nItems .= $tplMaterialL10nItem->apply(['localeId' => $localeId, 'materialId' => $material->id, 'mimeType' => $material->l10n->get('mimeType', $localeId)]); } $materialItems .= $tplMaterialItem->apply(['id' => $materialId, 'hash' => $material->hash, 'name' => $material->l10n->get('name', $registry->get('locale')), 'description' => $material->l10n->get('description', $registry->get('locale')), 'l10nItems' => $materialL10nItems]); } $materialAddL10nItems = ''; foreach ($locales as $localeId => $localeData) { $materialAddL10nItems .= $tplMaterialAddL10nItem->apply(['materialId' => 0, 'localeId' => $localeId]); } $materialItems = $tplMaterialAddItem->apply(['l10nItems' => $materialAddL10nItems]); if (!$stage->id) { $exerciseItems = ''; foreach ($data['exercises'] as $exerciseId => $exercise) { $exerciseItems .= $tplso->apply(['name' => $exercise->name, 'value' => $exerciseId, 'selected' => FALSE]); } } return $tpl->apply(['id' => $stage->id, 'lessonId' => $data['lessonId'], 'name' => $stage->name, 'config' => $stage->settings, 'tabItems' => $tabItems, 'tabContentItems' => $tabContentItems, 'materialL10nHeaderItems' => $materialL10nHeaderItems, 'materialItems' => $materialItems, 'exerciseName' => $data['exerciseName'], 'exerciseItems' => $exerciseItems, 'site_root' => $application->siteRoot]); }
static function getList($mode = self::VISIBLE) { $db = Registry::getInstance()->get(self::DB); if ($mode == self::VISIBLE) { $sql = "SELECT * FROM `" . self::TABLE . "` WHERE `state`=" . self::VISIBLE . " ORDER BY `" . self::ORDER_FIELD_NAME . "`"; } else { $sql = "SELECT * FROM `" . self::TABLE . "` ORDER BY `" . self::ORDER_FIELD_NAME . "`"; } $result = parent::getList($sql); $l10nList = CourseL10n::getListByIds(array_keys($result)); foreach ($result as $courseId => $course) { if (isset($l10nList[$courseId])) { $l10n = $l10nList[$courseId]; } else { $l10n = new CourseL10n($l10nList[$courseId]->id); } $result[$courseId]->l10n = $l10n; } return $result; }
public function route() { $registry = Registry::getInstance(); foreach (Redirect::getList(Redirect::ACTIVE) as $redirect) { if (preg_match($redirect->source, $this->redirectSourceUrl)) { Redirect::updateRequestDate($redirect->id); RedirectQuery::register(); $destination = str_replace('{site_root}', $registry->get('site_root'), $redirect->destination); header('Location: ' . $destination, TRUE, $registry->status); die; } } foreach (Router::getList() as $router) { if (preg_match($router->url, substr($this->originalUrl, 1))) { $controllerName = $router->controller . 'Controller'; $controller = new $controllerName(); exit; } } }