Example #1
0
 public function renderForm()
 {
     $form = new HTMLForm();
     $form->open('addgroupusers', '', 'POST');
     $form->setInput('aname')->setAttr('type|text')->setRules('notempty|trim')->setErrorText('Введите наименование группы')->setAttr('class|form-control input-lg')->addInput();
     $form->setInput('addgroupusers')->setAttr('type|submit')->setAttr('class|btn btn-primary btn-lg addpage')->setAttr('value|Создать')->addInput();
     $formAddGroupUsers = $form->close();
     Bufer::set(array('formAddGroupUsers' => $formAddGroupUsers));
     if (!$form->sendForm('addgroupusers')) {
         $errors = $form->getErrors();
         Bufer::add(array('errors' => $errors));
     } else {
         $data = $form->getData();
         $checkName = $this->checkName($data['aname']);
         if ($checkName['success'] === false) {
             Bufer::add(array('errors' => $checkName['error']));
         } else {
             $data = array('aname' => $this->model->escape($data['aname']));
             $result = $this->addGroupUsers($data);
             if ($result['success'] === false) {
                 Bufer::add(array('errors' => $result['error']));
             } else {
                 Route::go('?mode=admin&route=groupsusers');
             }
         }
     }
 }
Example #2
0
 public function renderForm()
 {
     $form = new HTMLForm();
     $hsid = isset($_GET['hsid']) ? (int) $_GET['hsid'] : 0;
     $data = $this->getDataHtmlSnippet($hsid);
     $form->open('editsnippet', '', 'POST');
     $form->setInput('hsname')->setRules('regexp[#[a-z\\-_0-9]{3,15}#i]')->setErrorText('Имя сниппета может содержать след. символы: a-z_-0-9  от 3 до 15 символов')->setAttr('class|form-control input-lg')->setAttr(isset($data['hsname']) ? 'value|' . $data['hsname'] : '')->addInput();
     $form->setTextarea('hsdescription')->setRules('trim|notempty')->setErrorText('Введите описание снипета')->setAttr('class|desc  form-control')->setText(isset($data['hsdescription']) ? $data['hsdescription'] : '')->addTextarea();
     $form->setTextarea('code')->setRules('trim|notempty')->setErrorText('Введите код снипета')->setAttr('class|preview_desc form-control')->setAttr('id|content')->setText(isset($data['code']) ? $data['code'] : '')->addTextarea();
     $form->setInput('editsnippet')->setAttr('type|submit')->setAttr('class|btn btn-primary btn-lg addpage')->setAttr('value|Сохранить')->addInput();
     $formEditSnippet = $form->close();
     Bufer::add(array('formEditSnippet' => $formEditSnippet));
     /**
      * Провервка отправленной формы
      */
     if (!$form->sendForm('editsnippet')) {
         $errors = $form->getErrors();
         Bufer::add(array('errors' => $errors));
     } else {
         $data = $form->getData();
         $data = array('hsid' => $hsid = isset($_GET['hsid']) ? (int) $_GET['hsid'] : 0, 'hsname' => $this->model->escape($data['hsname']), 'hsdescription' => $this->model->escape($data['hsdescription']), 'code' => $this->model->escape($data['code']));
         $checkHsname = $this->model->checkHsname($data);
         if (!isset($checkHsname['error'])) {
             $result = $this->saveSnippet($data);
             if ($result['success'] === false) {
                 Bufer::add(array('errors' => $result['error']));
             } else {
                 Route::go('?mode=admin&route=edithtmlsnippets&hsid=' . $data['hsid']);
             }
         } else {
             Bufer::add(array('errors' => $checkHsname['error']));
         }
     }
 }
Example #3
0
 public function renderForm()
 {
     $uid = isset($_GET['uid']) ? (int) $_GET['uid'] : 1;
     $result = $this->getUserData($uid);
     $access = $this->getAccessList();
     $form = new HTMLForm();
     $form->open('edituser', '', 'POST');
     $form->setInput('login')->setAttr('type|text')->setAttr(isset($result['userData']['login']) ? 'value|' . $result['userData']['login'] : '')->setRules('notempty|trim')->setErrorText('Введите логин пользователя')->setAttr('class|form-control input-lg')->addInput();
     $form->setInput('uid')->setAttr('type|hidden')->setAttr('value|' . $result['userData']['uid'])->addInput();
     $form->setInput('password')->setAttr('type|text')->setAttr(isset($result['userData']['password']) ? 'value|' . $result['userData']['password'] : '')->setRules('notempty|trim|length[40|40]')->setErrorText('Введите hash пароля пользователя (можно получить в генераторе под формой)')->setAttr('class|form-control input-lg')->addInput();
     $form->setInput('email')->setAttr('type|text')->setAttr(isset($result['userData']['email']) ? 'value|' . $result['userData']['email'] : '')->setRules('email')->setErrorText('Введён не корректный email пользователя')->setAttr('class|form-control input-lg')->addInput();
     $form->setSelect('access')->setAttr('class|form-control')->setAttr('style|width:300px')->setRules('notempty')->addSelect();
     $form->setInput('edituser')->setAttr('type|submit')->setAttr('class|btn btn-primary btn-lg addpage')->setAttr('value|Сохранить')->addInput();
     foreach ($access as $k => $v) {
         if (!in_array($v['acid'], array(2))) {
             $form->setOption($v['aname'])->setAttr('value|' . $v['acid'])->setAttr($result['userData']['isadmin'] == $v['acid'] ? 'selected|selected' : '')->addOption('access');
         }
     }
     $formUserData = $form->close();
     Bufer::set(array('errors' => isset($result['errors']) ? $result['errors'] : array(), 'userData' => $result['userData'], 'formUserData' => $formUserData));
     if (!$form->sendForm('edituser')) {
         $errors = $form->getErrors();
         Bufer::set(array('errors' => $errors, 'formUserData' => $formUserData));
     } else {
         $data = $form->getData();
         $data = array('uid' => $uid, 'login' => $this->model->escape($data['login']), 'password' => $this->model->escape($data['password']), 'email' => $this->model->escape($data['email']), 'access' => $this->model->escape($data['access']));
         $saveUser = $this->saveUser($data);
         if (!isset($saveUser['error'])) {
             Route::go('?mode=admin&route=edituser&uid=' . $uid);
         } else {
             Bufer::set(array('errors' => $saveUser['error'], '$formUserData' => $formUserData));
         }
     }
 }
Example #4
0
 public function renderForm()
 {
     $acid = isset($_GET['acid']) ? (int) $_GET['acid'] : 0;
     $groupUsersData = $this->model->getGroupUsersData($acid);
     //echo '<pre>' . print_r($groupUsersData, 1) . '</pre>';
     $form = new HTMLForm();
     $form->open('editgroupusers', '', 'POST');
     $form->setInput('aname')->setAttr('type|text')->setAttr('value|' . $groupUsersData['groupUsersData']['aname'])->setRules('notempty|trim')->setErrorText('Введите наименование группы')->setAttr('class|form-control input-lg')->addInput();
     $form->setInput('editgroupusers')->setAttr('type|submit')->setAttr('class|btn btn-primary btn-lg addpage')->setAttr('value|Сохранить')->addInput();
     $formEditGroupUsers = $form->close();
     Bufer::set(array('formEditGroupUsers' => $formEditGroupUsers));
     if ($groupUsersData['success'] === false) {
         Bufer::add(array('errors' => $groupUsersData['error']));
     }
     if (!$form->sendForm('editgroupusers')) {
         $errors = $form->getErrors();
         Bufer::add(array('errors' => $errors));
     } else {
         $data = $form->getData();
         $data = array('acid' => $acid, 'aname' => $this->model->escape($data['aname']));
         $checkName = $this->checkName($data);
         if ($checkName['success'] === true) {
             $result = $this->saveGroupUsers($data);
             if ($result['success'] === false) {
                 Bufer::add(array('errors' => $result['error']));
             } else {
                 Route::go('?mode=admin&route=editgroupusers&acid=' . $acid);
             }
         } else {
             Bufer::add(array('errors' => $checkName['error']));
         }
     }
 }
Example #5
0
 /**
  * Установка региона
  */
 public function setRegion()
 {
     $_SESSION['reg'] = isset($_SESSION['reg']) ? $_SESSION['reg'] : 'All';
     if (isset($_GET['set_reg'])) {
         $_SESSION['reg'] = $_GET['set_reg'];
         Route::go('?mode=public&route=' . ROUTE);
     }
 }
Example #6
0
 /**
  * Установка валюты
  */
 public function setCurr()
 {
     $_SESSION['curr'] = isset($_SESSION['curr']) ? $_SESSION['curr'] : 'USD';
     if (isset($_GET['set_curr'])) {
         $_SESSION['curr'] = $_GET['set_curr'];
         Route::go('?mode=public&route=' . ROUTE);
     }
 }
Example #7
0
 public function addpage($data)
 {
     $result = $this->model->addpage($data);
     if (!$result['success']) {
         Bufer::add(array('errors' => array('Произошла ошибка при создании страницы')));
     } else {
         Route::go('?mode=admin&route=pages');
     }
 }
Example #8
0
 public function renderForm()
 {
     $model = $this->model;
     $pid = isset($_GET['pid']) ? (int) $_GET['pid'] : 0;
     $pageData = $this->getPage($pid);
     if (isset($pageData['errors'])) {
         Bufer::set(array('errors' => $pageData['errors']));
     } else {
         Bufer::set(array('pageData' => $pageData['pageData']));
     }
     $errors = isset($pageData['errors']) ? $pageData['errors'] : false;
     $dataPage = isset($pageData['pageData'][0]) ? $pageData['pageData'][0] : false;
     $getSections = $model->returnData("select * from section");
     $form = new HTMLForm();
     $form->open('addpage', '', 'POST');
     $form->setInput('title')->setAttr('type|text')->setAttr('onkeyup|document.getElementById(\'child\').value=translit(this.value)')->setAttr(isset($dataPage['title']) ? 'value|' . $dataPage['title'] : '')->setRules('notempty|trim')->setErrorText('Введите Title страницы')->setAttr('class|form-control input-lg')->addInput();
     $form->setInput('pid')->setAttr('type|hidden')->setAttr('value|' . $pid)->setRules('notempty')->addInput();
     $form->setInput('description')->setAttr('type|text')->setAttr(isset($dataPage['description']) ? 'value|' . $dataPage['description'] : '')->setRules('notempty')->setErrorText('Введите описание для страницы')->setAttr('class|form-control input-lg')->addInput();
     $form->setInput('keywords')->setAttr('type|text')->setAttr(isset($dataPage['keywords']) ? 'value|' . $dataPage['keywords'] : '')->setRules('notempty')->setErrorText('Введите ключевые слова для  страницы')->setAttr('class|form-control input-lg')->addInput();
     $form->setInput('index')->setAttr('type|text')->setAttr('id|child')->setAttr(isset($dataPage['name']) ? 'value|' . $dataPage['name'] : '')->setRules('notempty')->setErrorText('Введите псевдоним страницы')->setAttr('class|form-control input-lg')->addInput();
     $form->setSelect('section')->setAttr('class|form-control')->setAttr('style|width:300px')->setRules('notempty')->addSelect();
     foreach ($getSections as $s) {
         $form->setOption($s['sname'] . ' (' . $s['sindex'] . ')')->setAttr('value|' . $s['sid'])->setAttr(isset($dataPage['sid']) && $dataPage['sid'] == $s['sid'] ? 'selected|selected' : '')->addOption('section');
     }
     $form->setSelect('display')->setAttr('class|form-control')->setAttr('style|width:300px')->setRules('notempty')->addSelect();
     $display = array(1 => 'да', 2 => 'нет', 3 => 'только для администрации');
     foreach ($display as $k => $v) {
         $form->setOption($v)->setAttr('value|' . $k)->setAttr(isset($dataPage['display']) && $dataPage['display'] == $k ? 'selected|selected' : '')->addOption('display');
     }
     $form->setTextarea('preview')->setAttr('id|preview')->setText(isset($dataPage['preview']) ? $dataPage['preview'] : '')->setAttr('class|preview form-control')->setRules('trim')->addTextarea();
     $form->setTextarea('content')->setAttr('id|content')->setText(isset($dataPage['content']) ? $dataPage['content'] : '')->setAttr('class|addpage form-control content')->setRules('notempty')->addTextarea();
     $form->setInput('editpage')->setAttr('type|submit')->setAttr('class|btn btn-primary btn-lg addpage')->setAttr('value|Сохранить')->addInput();
     $formEditpage = $form->close();
     Bufer::set(array('errors' => $errors, 'formEditpage' => $formEditpage, 'titlePage' => isset($dataPage['title']) ? $dataPage['title'] : ''));
     /**
      * Провервка отправленной формы
      */
     if (!$form->sendForm('editpage')) {
         $errors = $form->getErrors();
         Bufer::set(array('errors' => $errors, 'formEditpage' => $formEditpage, 'titlePage' => isset($dataPage['title']) ? $dataPage['title'] : ''));
     } else {
         $data = $form->getData();
         $data = array('pid' => (int) $data['pid'], 'title' => $this->model->escape($data['title']), 'description' => $this->model->escape($data['description']), 'keywords' => $this->model->escape($data['keywords']), 'index' => $this->model->escape($data['index']), 'sid' => (int) $data['section'], 'display' => (int) $data['display'], 'preview' => $this->model->escape($data['preview']), 'content' => $this->model->escape($data['content']));
         $savePage = $this->savePage($data);
         $checkIndexPage = $this->model->checkIndexPage($data);
         if (!isset($checkIndexPage['error'])) {
             $result = $this->savePage($data, $formEditpage);
             if (!isset($savePage['errors'])) {
                 Route::go('?mode=admin&route=editpage&pid=' . $data['pid']);
             } else {
                 Bufer::set(array('errors' => $savePage['error'], 'formEditpage' => $formEditpage, 'titlePage' => isset($data['title']) ? $data['title'] : ''));
             }
         } else {
             Bufer::set(array('errors' => $checkIndexPage['error'], 'formEditpage' => $formEditpage, 'titlePage' => isset($data['title']) ? $data['title'] : ''));
         }
     }
 }
Example #9
0
 public function addSnippet($data)
 {
     $result = $this->model->addSnippet($data);
     if ($result['success'] === false) {
         Bufer::add(array('errors' => $result['error']));
     } else {
         Route::go('?mode=admin&route=htmlsnippets');
     }
 }
Example #10
0
 /**
  *  Реакция на правильно заполненную форму
  *  @param array - ассоц. массив значений полей формы
  *  @param array - массив с элементами формы из renderForm()
  */
 public function access($data, $form)
 {
     $login = $this->model->escape($data['login']);
     $password = sha1(SALT . $data['password']);
     $result = $this->model->sqlQuery("select \r\n                                            *\r\n                                           from \r\n                                             users \r\n                                           where \r\n                                             isadmin=1 and login='******' and password='******'");
     if ($result->num_rows > 0) {
         $_SESSION['fw'][INDEX_SESSION_ADMIN] = true;
         Route::go('?mode=admin&route=pages');
     } else {
         Bufer::set(array('errors' => array('Не верный логин или пароль!'), 'formAutorize' => $form));
     }
 }
Example #11
0
 public function deleteImage($giid)
 {
     $result = $this->model->deleteImage($giid);
     $glid = isset($_GET['glid']) ? (int) $_GET['glid'] : 0;
     if ($result['success'] === false) {
         Bufer::add(array('errors' => $result['error']));
     } else {
         Route::go('http://fw.local/?mode=admin&route=editgalery&glid=' . $glid);
     }
 }
Example #12
0
 public static function logout()
 {
     unset($_SESSION['fw']);
     session_destroy();
     Route::go('/');
 }
function go($route = null)
{
    Route::go($route ?: '/' . hierarchy());
}
Example #14
0
 public function createModule($module, $form)
 {
     $file_tpl_controller = DIR . '/' . PATH . 'app/createmodule/controller.tpl';
     $file_tpl_model = DIR . '/' . PATH . 'app/createmodule/model.tpl';
     $file_tpl_templte = DIR . '/' . PATH . 'app/createmodule/template.tpl';
     $file_public_tpl_controller = DIR . '/' . PATH . 'app/createmodule/public/controller.tpl';
     $file_public_tpl_model = DIR . '/' . PATH . 'app/createmodule/public/model.tpl';
     $file_public_tpl_templte = DIR . '/' . PATH . 'app/createmodule/public/template.tpl';
     if (!file_exists($file_tpl_templte) or !is_readable($file_tpl_templte)) {
         $errors[] = 'Не могу найти или прочитать файл шаблона *.tpl нового модуля';
     }
     if (!file_exists($file_tpl_controller) or !is_readable($file_tpl_controller)) {
         $errors[] = 'Не могу найти или прочитать файл шаблона контроллера нового модуля';
     }
     if (!file_exists($file_tpl_model) or !is_readable($file_tpl_model)) {
         $errors[] = 'Не могу найти или прочитать файл шаблона модели нового модуля';
     }
     if (isset($errors)) {
         Bufer::add(array('errors' => $errors));
     } else {
         $mode = $module['mode'];
         $namefilemodule = strtolower($module['name']);
         $nameclassmodule = ucfirst(strtolower($module['name']));
         switch ($module['mode']) {
             case 1:
                 //public module
                 $dir_tpls = TPLS_DIR;
                 $dir_controllers = CONTROLLERS_DIR;
                 $dir_models = MODELS_DIR;
                 $tpl = file_get_contents($file_public_tpl_templte);
                 $controller = file_get_contents($file_public_tpl_controller);
                 $model = file_get_contents($file_public_tpl_model);
                 break;
             case 2:
                 //admin module
                 $dir_tpls = ADMIN_TPLS_DIR;
                 $dir_controllers = ADMIN_CONTROLLERS_DIR;
                 $dir_models = ADMIN_MODELS_DIR;
                 $tpl = file_get_contents($file_tpl_templte);
                 $controller = file_get_contents($file_tpl_controller);
                 $model = file_get_contents($file_tpl_model);
                 break;
         }
         $tpl = strtr($tpl, array('{namemodule}' => $nameclassmodule));
         $controller = strtr($controller, array('{namemodule}' => $nameclassmodule, '{tpl}' => $namefilemodule));
         $model = strtr($model, array('{namemodule}' => $nameclassmodule));
         if (file_exists($dir_tpls . '/' . $namefilemodule . '.tpl')) {
             $errors[] = 'Шаблон с таким именем уже найден';
         }
         if (file_exists($dir_controllers . '/' . $namefilemodule . '.php')) {
             $errors[] = 'Контроллер с таким именем уже найден';
         }
         if (file_exists($dir_models . '/' . $namefilemodule . '.php')) {
             $errors[] = 'Модель с таким именем уже найдена';
         }
         if (isset($errors)) {
             Bufer::add(array('errors' => $errors));
         }
         if (!file_put_contents($dir_tpls . '/' . $namefilemodule . '.tpl', $tpl)) {
             $errors[] = 'Не могу сохранить файл шаблона нового модуля';
         }
         if (!file_put_contents($dir_controllers . '/' . $namefilemodule . '.php', $controller)) {
             $errors[] = 'Не могу сохранить файл контроллера нового модуля';
         }
         if (!file_put_contents($dir_models . '/' . $namefilemodule . '.php', $model)) {
             $errors[] = 'Не могу сохранить файл модели нового модуля';
         }
         if (isset($errors)) {
             return Bufer::set(array('errors' => $errors, 'formAddModule' => $form));
         } else {
             Route::go('?mode=admin&route=addmodule');
         }
     }
 }
Example #15
0
 public function addImagesOnDb($gid, $images)
 {
     $result = $this->model->addImagesOnDb($gid, $images);
     if ($result['success'] === false) {
         $this->model->deleteGalery($gid);
         @rmdir('uploads/images/galery/' . $gid);
         Bufer::add(array('errors' => array($result['error'])));
     } else {
         Route::go('?mode=admin&route=galery');
     }
 }