Example #1
0
 public static function Instance()
 {
     if (self::$instance == null) {
         self::$instance = new M_MSQL();
     }
     return self::$instance;
 }
Example #2
0
 public function getCurrentTemplate()
 {
     $query = "SELECT option_value FROM options \n\t\t\t\t\t\t\tWHERE option_name='template_name'";
     $res = M_MSQL::Instance()->Select($query);
     $template_name = isset($res[0]['option_value']) ? $res[0]['option_value'] : 'default_template';
     return $template_name;
 }
Example #3
0
 public function __construct()
 {
     $this->msql = M_MSQL::Instance();
     $this->sid = null;
     $this->uid = null;
     $this->onlineMap = null;
 }
Example #4
0
 public function __construct($table, $pk)
 {
     $this->table = $table;
     $this->pk = $pk;
     $this->errors = array();
     $this->valid = null;
     $this->db = M_MSQL::Instance();
 }
Example #5
0
 function __construct()
 {
     $this->db = M_MSQL::Instance();
     $this->tableData = 'comments';
     $this->pkTableData = 'comment_id';
     // $idEntry
     $this->tableTree = 'commentsTree';
 }
Example #6
0
 public function __construct($table, $url_self)
 {
     $this->db = M_MSQL::Instance();
     $this->query['table'] = $table;
     $this->fields = '*';
     $this->on_page = 2;
     $this->url_self = $url_self;
     $this->page_num = 1;
 }
Example #7
0
 public function action_admin()
 {
     $this->title .= ':: Страница администратора';
     $mUsers = M_Users::Instance();
     $this->msql = M_MSQL::Instance();
     //$mUsers->Logout();
     if (!$mUsers->Can('EDIT_USERS')) {
         $this->redirect('/');
     }
     $User = $mUsers->Get();
     // Обработка POST - запроса
     //var_dump ($_POST);
     if (isset($_POST)) {
         $p2r = array();
         $table = 'privs2roles';
         //$result = $this -> msql -> clean ($table);
         $object = array();
         // Изменение ролей пользователей
         foreach ($_POST as $key => $value) {
             if ($value != 'on') {
                 $object[id_role] = $value;
                 $where = "id_user = {$key}";
                 $result = $this->msql->update('users', $object, $where);
             }
             // Изменение привелегий
             if ($value == 'on') {
                 $arr = str_split($key);
                 $role = $arr[1];
                 $priv = $arr[3];
                 $table = 'privs2roles';
                 // if (!($mUsers -> entry_exist ($role, $priv)))
                 // {
                 // $object1 = array ('id_role' => $role, 'id_priv' => $priv);
                 // $result = $this -> msql -> insert($table, $object1);
                 // }
                 $p2r[] = $role;
                 $p2r[] = $priv;
             }
         }
         if ($p2r) {
             $x = $mUsers->replace_privs2roles($p2r);
         }
     }
     // Получение сводной таблицы пользователей
     $userdata = $mUsers->AdminUsersRoles();
     $privcolumns = $this->msql->rows_count('privs');
     $number_roles = $this->msql->rows_count('roles');
     // Получение сводной таблицы привелегий
     $privsdata = $mUsers->AdminPrivsRoles();
     $privs = $mUsers->get_Privs();
     //Вывод
     $layout = 'admin';
     $vars = array('layout' => $layout, 'username' => $User["name"]);
     $this->menu = $this->Template('./v/elements/menu.php', $vars);
     $vars = array('userdata' => $userdata, 'privsdata' => $privsdata, 'number_roles' => $number_roles, 'privs' => $privs, 'privcolumns' => $privcolumns, 'menu' => $this->menu);
     $this->content = $this->Template('./v/v_admin.php', $vars);
 }
Example #8
0
 public function __construct()
 {
     $this->msql = M_MSQL::Instance();
 }
Example #9
0
 public function __construct()
 {
     $this->db = M_MSQL::Instance();
     $this->search_map = (include_once $this->search_path);
 }
Example #10
0
 private function __construct()
 {
     $this->msql = M_MSQL::Instance();
 }
Example #11
0
 public function action_edit()
 {
     $mArticles = M_Articles::Instance();
     $mComments = M_Comments::Instance();
     $mUsers = M_Users::Instance();
     $User = $mUsers->Get();
     if (!$mUsers->Can('EDIT_ARTICLES')) {
         $this->redirect('/editor/editor');
     }
     $this->title .= ':: Редактирование';
     $this->id = isset($this->params[0]) ? (int) $this->params[0] : 1;
     $record = $mArticles->Get($this->id);
     $article = $record[0];
     if (isset($article)) {
         $this->art_title = $article['title'];
         $this->art_text = $article['content'];
         $this->error = false;
     } else {
         $this->redirect('/editor/editor/');
     }
     // Обработка отправки формы - Удаление статьи
     if (!empty($_POST) && $_POST['delete_'] == 'on') {
         $this->msql = M_MSQL::Instance();
         $table1 = 'articles';
         $table2 = 'comments';
         $where = '`id_article` = ' . $this->id;
         if ($this->msql->delete($table1, $where) || $this->msql->delete($table2, $where)) {
             $this->redirect('/editor/editor/');
         }
     }
     // Изменение статьи
     if (!empty($_POST) && $_POST['delete_'] != 'on') {
         // Данные изменены, редирект
         if ($mArticles->is_real_article($_POST['title'], $_POST['content'])) {
             if ($mArticles->articles_edit($this->id, $_POST['title'], $_POST['content'])) {
                 $this->redirect('/editor/editor/');
             }
         } else {
             $this->art_title = $_POST['title'];
             $this->art_text = $_POST['content'];
             $error = true;
             $this->message = 'В заголовке должно присутствовать хотябы одно слово, в тексте - несколько предложений!';
         }
     }
     //Вывод
     $vars = array('layout' => 'regular', 'username' => $User["name"]);
     $this->menu = $this->Template('./v/elements/menu.php', $vars);
     $this->left_block = $mComments->latest_comments();
     $vars = array('left_block' => $this->left_block);
     $this->left_block = $this->Template('./v/elements/new_comments.php', $vars);
     $vars = array('art_title' => $this->art_title, 'art_text' => $this->art_text, 'menu' => $this->menu, 'error' => $this->error, 'left_block' => $this->left_block, 'message' => $this->message);
     $this->content = $this->Template('./v/v_edit.php', $vars);
 }
Example #12
0
 public function action_show()
 {
     $mArticles = M_Articles::Instance();
     $mComments = M_Comments::Instance();
     $mUsers = M_Users::Instance();
     $User = $mUsers->Get();
     $this->id = isset($this->params[0]) ? (int) $this->params[0] : 1;
     //array_shift($params);
     $display_page = (int) $this->id;
     if ($display_page < 1) {
         // Неверный запрос, редирект
         die(header('Location: ./index.php?c=index&act=index'));
     }
     //var_dump ($this -> comments);
     $record = $mArticles->Get($display_page);
     $article = $record[0];
     $this->requested_id = $article['id_article'];
     $this->requested_name = $article['title'];
     $this->requested_text = $article['content'];
     if ($this->requested_name == '') {
         // Неверный запрос, редирект
         die(redirect('/page/index'));
     }
     // получение массива комментариев к статье
     //$this-> mysql = M_MYSQL::getInstance();
     $mComments = M_Comments::Instance();
     $this->comments = $mComments->All_by_art_id($this->requested_id);
     //Обработка POST-запроса
     $this->mysql = M_MSQL::Instance();
     if (!empty($_POST) && isset($_POST['com_text'])) {
         $mUsers = M_Users::Instance();
         $User = $mUsers->Get();
         // успешно данные добавлены, редирект
         $table = 'comments';
         $object = array();
         $object['id_article'] = $this->requested_id;
         $object['name'] = $User['name'];
         $object['comment'] = $_POST['com_text'];
         $object['date'] = date("Y-m-d");
         if ($this->mysql->insert($table, $object)) {
             $i = (int) $this->requested_id;
             $this->redirect('/page/index');
         }
     }
     if ($mUsers->Can('DELETE_COMMENTS')) {
         $comm_delete = true;
     } else {
         $comm_delete = false;
     }
     $comm_add = '';
     if (!$mUsers->Can('ADD_ARTICLES')) {
         $comm_add = 'hidden';
     }
     $nick = $User["name"];
     if ($User["name"] == '') {
         $nick = 'Гость';
     }
     $this->title .= ':: Статья ' . $this->requested_id;
     $vars = array('layout' => 'regular', 'username' => $nick);
     $this->menu = $this->Template('./v/elements/menu.php', $vars);
     $this->left_block = $mComments->latest_comments();
     $vars = array('left_block' => $this->left_block);
     $this->left_block = $this->Template('./v/elements/new_comments.php', $vars);
     $vars = array('comments' => $this->comments, 'comm_delete' => $comm_delete, 'comm_add' => $comm_add);
     $this->comments_ = $this->Template('./v/elements/comments.php', $vars);
     $vars = array('requested_name' => $this->requested_name, 'requested_text' => $this->requested_text, 'menu' => $this->menu, 'comments' => $this->comments_, 'left_block' => $this->left_block);
     $this->content = $this->Template('./v/v_article.php', $vars);
 }
Example #13
0
 private function unique($query, $pk = null)
 {
     $primary_key = $this->rules['pk'];
     if ($pk == null) {
         $result = M_MSQL::Instance()->Select("SELECT * FROM {$this->table} WHERE {$query}");
     } else {
         $result = M_MSQL::Instance()->Select("SELECT * FROM {$this->table} WHERE ({$query}) AND {$primary_key}<>{$pk}");
     }
     return $result;
 }