示例#1
0
 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();
     }
 }
示例#2
0
 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();
 }
示例#3
0
 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();
     }
 }
示例#4
0
 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();
     }
 }
示例#5
0
 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();
     }
 }
示例#6
0
 function getList()
 {
     $registry = Registry::getInstance();
     $application = Application::getInstance();
     $i18n = new I18n($registry->get('i18n_path') . 'setup.xml');
     $tpl = new Template($registry->get('template_path') . 'setup.htm');
     $tpli = new Template($registry->get('template_path') . 'setup_item.htm');
     $listItems = '';
     $setup = new Setup();
     foreach ($setup->getList() as $variable) {
         $listItems .= $tpli->apply(['name' => htmlspecialchars($variable->getProperty('name')), 'value' => htmlspecialchars($variable->getProperty('value')), 'desc' => $variable->getProperty('description')]);
     }
     $renderer = new Renderer(Page::MODE_NORMAL);
     $pTitle = $i18n->get('title');
     $renderer->page->set('title', $pTitle)->set('h1', $pTitle)->set('content', $tpl->apply(['items' => $listItems, 'site_root' => $application->siteRoot]));
     $renderer->loadPage();
     $renderer->output();
 }
示例#7
0
 function edit()
 {
     $router = new Router(intval($_GET['id']));
     if ($_POST['action'] == 'save') {
         $router->name = trim($_POST['name']);
         $router->url = trim($_POST['url']);
         $router->controller = trim($_POST['controller']);
         $router->save();
         header('Location: /cms/router');
         exit;
     } else {
         $application = Application::getInstance();
         $registry = Registry::getInstance();
         $i18n = new I18n($registry->get('i18n_path') . 'router.xml');
         $pTitle = $i18n->get($id ? 'update_mode' : 'append_mode');
         $renderer = new Renderer(Page::MODE_NORMAL);
         $renderer->page->set('title', $pTitle)->set('h1', $pTitle)->set('content', RouterEditView::get(['router' => $router]));
         $renderer->loadPage();
         $renderer->output();
     }
 }
示例#8
0
 function edit()
 {
     $registry = Registry::getInstance();
     $application = Application::getInstance();
     $locale = $registry->get('locale');
     $locales = LocaleManager::getLocales();
     $id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
     $lesson = new Lesson($id);
     if (!$lesson->id) {
         $course = new Course(filter_input(INPUT_GET, 'course_id', FILTER_VALIDATE_INT));
     } else {
         $course = new Course($lesson->courseId);
     }
     if (!$course->id) {
         header('Location: /cms/course/list');
         exit;
     }
     if ('save' == filter_input(INPUT_POST, 'action')) {
         if (!$lesson->id) {
             $lesson->courseId = $course->id;
         }
         foreach (array_keys($locales) as $localeId) {
             $lesson->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])]);
         }
         $lesson->save();
         header('Location: /cms/course/edit?id=' . $lesson->courseId);
         exit;
     } else {
         $i18n = new I18n($registry->get('i18n_path') . 'lesson.xml');
         $data['lesson'] = $lesson;
         $data['exercises'] = Exercise::getList();
         $data['stages'] = Stage::getList($lesson->id);
         $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', LessonEditView::get($data));
         $renderer->loadPage();
         $renderer->output();
     }
 }
示例#9
0
 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();
     }
 }