Ejemplo n.º 1
0
 static function wisdomRecord($id = 0, $education = 0)
 {
     db_connect::connect();
     if ($id != 0 && $education == 0) {
         $information = R::load('information', $id);
         $information->shortdescription = $_POST['shortdescription'];
         $information->category_id = $_GET['category'];
         $information->sharedUser[] = $_SESSION['user'];
     } elseif ($id == 0 && $education == 0) {
         $information = R::dispense('information');
         $information->shortdescription = $_POST['shortdescription'];
         $information->category_id = $_GET['category'];
         $information->sharedUser[] = $_SESSION['user'];
     } elseif ($id != 0 && $education != 0) {
         //            echo 1;
         $information = R::load('education', $education);
         $information->number = $_POST['number'];
         $information->information_id = $id;
     }
     $information->name = $_POST['name'];
     $information->description = $_POST['description'];
     $id = R::store($information);
     //        print_r($id);
     return $id;
 }
Ejemplo n.º 2
0
 function __construct()
 {
     require_once dirname(__FILE__) . '/db_connect.php';
     // opening db connection
     $db = new db_connect();
     $this->conn = $db->connect();
 }
Ejemplo n.º 3
0
Archivo: get.php Proyecto: Jluct/blog
 protected static function getData($query)
 {
     $out=array();
     foreach (self::aaa($query) as $key => $value) {
         $out[$key] = $value;
     }
     parent::connect()->close();
     return $out;
 }
Ejemplo n.º 4
0
 function __construct($query, $array)
 {
     //        $this->items = getDataBase::getData("SELECT *
     //        FROM  `menu` ,  `menu_item`
     //        WHERE menu_item.menu_id =" . intval($id) . "
     //        AND menu.menu_id = menu_item.menu_id");
     db_connect::connect();
     $this->items = R::getAll($query, $array);
 }
Ejemplo n.º 5
0
Archivo: set.php Proyecto: Jluct/blog
 protected static function setData($query)
 {
     $out = array();
     $result = parent::connect()->query($query);
     if ($result->num_rows > 0) {
         foreach ($result as $key => $value) {
             $out[$key] = $value;
         }
         return $out;
     }
     return true;
 }
Ejemplo n.º 6
0
 public function __construct()
 {
     include_once 'db_connect.php';
     include_once 'functions.php';
     try {
         $connect_db = new db_connect();
         $this->link = $connect_db->connect();
         $this->functions = new db_functions();
     } catch (Exception $ex) {
         return mysqli_error($this->link);
     }
 }
Ejemplo n.º 7
0
 function getWisdomByType($array, $wisdomArray, $page = 1)
 {
     if (!(int) $array[0]) {
         return false;
     }
     $out = '';
     db_connect::connect();
     if (empty($wisdomArray)) {
         $out .= "<h2>Ничего не найдено</h2>";
         return $out;
     }
     foreach ($wisdomArray as $key => $value) {
         $out .= "<h2>" . $key . "</h2><table class='table table-striped'>\r\n                    <tr>\r\n                        <th>Название</th>\r\n                        <th>Автор</th>\r\n                        <th>Категория</th>\r\n                        <th>Субкатегория</th>\r\n                    </tr>";
         foreach ($value as $smallKey => $subValue) {
             $category = R::load('category', $subValue['subcategory_id']);
             if ($array[3] && $array[2]) {
                 $step = 10;
                 $page3 = ($page - 1) * $step;
                 $data = $category->withCondition('information.category_id = ? LIMIT ?,?', [$array[3], $page3, $step])->ownInformationList;
                 self::$count_data += $category->withCondition('information.category_id = ? LIMIT ?,?', [$array[3], $page3, $step])->countOwn('information');
                 self::$path = "?ctrl=wisdom&action=WisdomType&type=" . $array[0] . "&subtype=" . $array[1] . "&category=" . $array[2] . "&subcategory=" . $array[3];
             } else {
                 $step = 10;
                 $step1 = 2;
                 //                    echo $page;
                 $page2 = ($page - 1) * $step;
                 $page1 = ($page - 1) * $step1;
                 $data = $array[1] ? $category->with(' LIMIT ?,?', [$page2, $step])->ownInformationList : $category->with(' LIMIT ?,?', [$page1, $step1])->ownInformationList;
                 self::$count_data += $array[1] ? $category->with(' LIMIT ?,?', [$page2, $step])->countOwn('information') : $category->with(' LIMIT ?,?', [$page1, $step1])->countOwn('information');
                 //                    echo " ".self::$count_data." ";
                 self::$path = $array[1] ? "?ctrl=wisdom&action=WisdomType&type=" . $array[0] . "&subtype=" . $array[1] : "?ctrl=wisdom&action=WisdomType&type=" . $array[0];
             }
             foreach ($data as $item) {
                 if (!$item && $array[2]) {
                     $out .= "<tr><td colspan='4'><h4 class='text-center'><b>Ничего не найдено</b></h4></td></tr>";
                     continue;
                 }
                 $autor = self::getAuthorName($item->id);
                 $out .= "<tr>\r\n                            <td><a href='?ctrl=wisdom&action=GetWisdomById&id=" . $item->id . "'>" . $item->name . "</a></td>\r\n                            <td><a  href='?ctrl=cabinet&action=UserInfo&id=" . $autor['id'] . "'>" . $autor['login'] . "</a> |\r\n                    <a  href='?ctrl=cabinet&action=UserInfo&id=" . $autor['id'] . "'> " . $autor['surname'] . " " . $autor['name'] . " " . $autor['andername'] . " </a></td>\r\n                            <td>" . $smallKey . "</td>\r\n                            <td>" . $subValue['category_name'] . "</td>\r\n\r\n                        </tr>";
             }
         }
         $out .= "</table>";
     }
     if ($array[3] && $array[2] && $_SESSION['user']->status == 'teacher' && $_SESSION['user']->block == 0) {
         $out .= "<a role='button' href='?ctrl=teacher&action=WisdomData&type=" . $array[0] . "&subtype=" . $array[1] . "&category=" . $array[2] . "&subcategory=" . $array[3] . "&page=1' class='btn btn-info btn-block'>Добавить учебный материал</a>";
     }
     return $out;
 }
Ejemplo n.º 8
0
 static function categorMenu($array, $page = 1)
 {
     $open = '';
     db_connect::connect();
     $data = R::load('type', $array[0]);
     $item = '';
     if (!$array[1]) {
         $item = $data->ownType;
     } else {
         $item = $data->withCondition('id = :id', ["id" => $array[1]])->ownType;
     }
     $out = "";
     foreach ($item as $i) {
         $i_count = 0;
         if (!$array[2]) {
             $j = $i->ownCategoryList;
         } else {
             $j = $i->withCondition('category.id = ? LIMIT 0,3', [$array[2]])->ownCategoryList;
         }
         foreach ($j as $v) {
             $v_count = 0;
             foreach ($v->ownCategory as $o) {
                 if (!$v_count && $o->name) {
                     $v_count = 1;
                     if ($v->id == $array[2]) {
                         $open = "open";
                     }
                     if (!$i_count) {
                         $i_count = 1;
                         $out .= "<h4>" . $i->name . "</h4>";
                     }
                     $out .= "<div class=\"dropdown {$open}\">\r\n  <button class=\"btn btn-default btn-block dropdown-toggle\" type=\"button\" id=\"dropdownMenu1\" data-toggle=\"tooltip\"\r\n  aria-haspopup=\"true\" aria-expanded=\"true\">\r\n  <a href='?ctrl=wisdom&action=WisdomType&type=" . $data->id . "&subtype=" . $i->id . "&category=" . $v->id . "&page=1'>" . $v->name . "<span class=\"caret\"></span></a></button>\r\n  <ul class=\"dropdown-menu\" aria-labelledby=\"dropdownMenu1\">";
                 }
                 if ($o->name) {
                     self::$information_count += $o->countOwn('information');
                     self::$wisdomArray[$i->name][$o->name]['type_id'] = $data->id;
                     self::$wisdomArray[$i->name][$o->name]['subtype_name'] = $i->name;
                     self::$wisdomArray[$i->name][$o->name]['category_name'] = $v->name;
                     self::$wisdomArray[$i->name][$o->name]['subcategory_id'] = $o->id;
                     $out .= "<li><a href='?ctrl=wisdom&action=WisdomType&type=" . $data->id . "&subtype=" . $i->id . "&category=" . $v->id . "&subcategory=" . $o->id . "&page=1'>" . $o->name . "</a></li>";
                 }
             }
             $out .= "</ul></div>";
         }
     }
     return $out;
 }
Ejemplo n.º 9
0
 function actionUpdateUserData($view)
 {
     $userArray = array();
     $errorArray = array();
     $session = $_SESSION['user'];
     if (!empty($_POST['firstPassword']) && !empty($_POST['anderPassword']) && $_POST['firstPassword'] === $_POST['anderPassword']) {
         $session->password = $_POST['firstPassword'];
     } elseif (empty($_POST['firstPassword']) && $_POST['firstPassword'] != '' && empty($_POST['anderPassword']) && $_POST['firstPassword'] === $_POST['anderPassword']) {
         $view->message = ["Пароли не совпадают или не все поля заполненны", "Внимание", 4];
         $errorArray = $_POST;
         $view->data = cabinet::getUserData($userArray, $errorArray);
         echo $view->render('cabinet.php');
         return;
     }
     foreach ($_POST as $key => $value) {
         if ($key == 'firstPassword' || $key == 'anderPassword') {
             if (empty($value)) {
                 continue;
             }
         }
         if ($key == 'email') {
             if (preg_match("~([a-zA-Z0-9!#\$%&\\'*+-/=?^_`{|}\\~])@([a-zA-Z0-9-]).([a-zA-Z0-9]{2,4})~", $value)) {
                 $userArray[$key] = htmlspecialchars($value);
                 continue;
             } else {
                 $errorArray[$key] = htmlspecialchars($value);
                 continue;
             }
         }
         if ($key == 'about') {
             if (count($value) < 2000) {
                 $userArray[$key] = htmlspecialchars($value);
                 continue;
             } else {
                 $errorArray[$key] = htmlspecialchars($value);
                 continue;
             }
         }
         if ($key == 'phone') {
             if (preg_match("/^[+0-9-]{5,30}\$/", $value)) {
                 $userArray[$key] = htmlspecialchars($value);
                 continue;
             } else {
                 $errorArray[$key] = htmlspecialchars($value);
                 continue;
             }
         }
         if (!preg_match('/^[A-Za-zАаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя0-9_]{2,30}$/', trim($value))) {
             $errorArray[$key] = htmlspecialchars($value);
         } else {
             $userArray[$key] = htmlspecialchars($value);
         }
         //
     }
     if (!isset($errorArray)) {
         $view->message = ["Неверные данные или заполненны не все обязательные поля", "Внимание", 4];
     } elseif (isset($userArray) && empty($errorArray)) {
         foreach ($session->dossier as $key => $value) {
             if ($_SESSION['user']->dossier->{$key} && isset($userArray[$key])) {
                 $session->dossier->{$key} = $userArray[$key];
             }
         }
         db_connect::connect();
         $id = R::store($session);
         if (!$id) {
             $view->message = ["Ошибка записи. Проверьте данные", "Ошибка", 4];
         }
         $view->message = ["Ваши личные данные изменены:", "Данные изменены", 1];
         $userArray = $errorArray = '';
     } else {
         $view->message = ["Ошибка записи. Проверьте данные", "Ошибка", 4];
     }
     $view->data = cabinet::getUserData($userArray, $errorArray);
     echo $view->render('cabinet.php');
 }
Ejemplo n.º 10
0
<?php

/**
 * Created by PhpStorm.
 * User: инкогнито
 * Date: 03.01.2016
 * Time: 16:08
 */
require_once __DIR__ . '/autoload.php';
require_once __DIR__ . '/application/core/connect/db_connect.php';
//try {
if (!isset($_GET['ctrl'])) {
    $ctrl = "defaultController";
    $action = "actionDefault";
} else {
    $controller = $ctrl = $_GET['ctrl'];
    $ctrl .= 'Controller';
    $action = 'action';
    $action .= $_GET['action'];
}
spl_autoload_register('myAutoload');
db_connect::connect();
$view = new View();
$controller = new $ctrl();
$controller->{$action}($view);
//    $view = new View();
//    $view->abc = 123;
//} catch(Exception $e) {
//    die('Ошибка');
//}
Ejemplo n.º 11
0
 static function getPageById($id)
 {
     db_connect::connect();
     $page = R::load('page', $id);
     return $page;
 }
Ejemplo n.º 12
0
 static function userInfo($id)
 {
     db_connect::connect();
     $user = R::load('user', $id);
     $status = $user->status == 'teacher' ? 'Преподаватель' : 'Студент';
     $out = "<div class='col-sm-4 text-center'>\r\n                    <img style=\"max-width: 100%;max-height:100%;margin: 15px; \" src='images/user/" . $user->dossier->image . "'>\r\n                </div>\r\n                    <div class='col-sm-8'>\r\n                    <h3>" . $user->login . " | " . $user->dossier->surname . " " . $user->dossier->name . " " . $user->dossier->andername . "</h3>";
     $out .= "<ul class=\"list-group\">\r\n                    <li class=\"list-group-item\"><h4>Основная информация</h4></li>\r\n                    <li class=\"list-group-item\">Статус: " . $status . "</li>\r\n                    <li class=\"list-group-item\">Страна: " . $user->dossier->land . "</li>\r\n                    <li class=\"list-group-item\">Город: " . $user->dossier->sity . "</li>\r\n                    <li class=\"list-group-item\">Электронная почта: " . $user->dossier->email . "</li>\r\n                    <li class=\"list-group-item\">Количество учебных материалов: " . $user->withCondition('activ = 1 and education_id is null and lesson_id is null')->countShared('information') . " </li>\r\n                </ul>\r\n                </div>";
     $about = $user->dossier->about ? $user->dossier->about : '<h3>Нет инфориации</h3>';
     $out .= "<div class='col-sm-12'>\r\n                    <div class=\"panel panel-primary\">\r\n                        <div class=\"panel-heading\">О себе</div>\r\n                        <div class=\"panel-body\">" . $about . "</div>\r\n                    </div>\r\n                </div>";
     if ($user->status === 'teacher') {
         $data = $user->withCondition('activ=1')->sharedInformationList;
         //    print_r($data);
         $out .= "<div class='col-sm-12'><div class=\"list-group\"><ul style='padding-left:0; '>";
         $out .= "<li class=\"list-group-item active\">\r\n            <h4 class=\"list-group-item-heading \">Разработанные учебные материалы</h4>\r\n  </li>";
         foreach ($data as $item) {
             $short_description = !empty($item->shortdescription) ? $item->shortdescription : 'Краткое описание отсутствует';
             $out .= "<li class=\"list-group-item\">\r\n            <h4 class=\"list-group-item-heading\"><a href='?ctrl=wisdom&action=GetWisdomById&id=" . $item->id . "'>" . $item->name . "</a></h4>\r\n    <p class=\"list-group-item-text\">" . $short_description . "</p>\r\n  </li>";
         }
         $out .= "</ul></div></div>";
     }
     return $out;
 }
Ejemplo n.º 13
0
<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.echo
 */
include_once 'db_connect.php';
// opening db connection
$db = new db_connect();
$connetion = $db->connect();
$errors = array();
$data = array();
// put all the value from the input value, here we can see the value of key['myEmail']
$_POST = json_decode(file_get_contents('php://input'), true);
// checking for blank values.
if (empty($_POST['myPassword'])) {
    $errors['myPassword'] = '******';
}
if (empty($_POST['myEmail'])) {
    $errors['myEmail'] = 'Email is required.';
}
if (empty($_POST['rolecode'])) {
    $errors['rolecode'] = 'Role is required.';
}
if (!empty($errors)) {
    // put the errors array in data array
    $data['errors'] = $errors;
} else {
    $data['message'] = 'Form data is going well';
    // response back. and put the value out of json_decoded array
Ejemplo n.º 14
0
    //connect to database
    function connect()
    {
        $this->connect = mysql_connect($this->server, $this->user, $this->pass);
        if (!$this->connect) {
            die("connection can not be established");
        }
        $db_select = mysql_select_db($this->database, $this->connect);
        if (!$db_select) {
            die("Database selection failed : " . mysql_error());
        }
    }
    //ping to see whether the database has gone offline or not
    private function ping_db()
    {
    }
    //sanitize query to prevent sql-injection
    function sanitize_query($query)
    {
    }
    function close()
    {
        if (isset($this->connection)) {
            mysql_close($this->connection);
        }
    }
}
$val = new db_connect();
$val->set_var($server, $user, $pass, $database);
$val->connect();
 function __construct()
 {
     include_once './connect.php';
     $connect = new db_connect();
     $this->link = $connect->connect();
 }
Ejemplo n.º 16
0
 public function __construct()
 {
     include_once 'db_connect.php';
     $connect_db = new db_connect();
     $this->link = $connect_db->connect();
 }
Ejemplo n.º 17
0
 public static function getArticle($id)
 {
     $id = (int) $id;
     db_connect::connect();
     return R::getAll("SELECT * FROM news WHERE id=?", [$id])[0];
 }
Ejemplo n.º 18
0
 /**
  * Подсчитывает элементы в таблице, по полю имя_таблицы + "_id"
  * @return int - число страниц по формуле число_записей_в_таблице/$number,
  * округлённое до целого в наибольшую сторону
  * если текущая_страница/-1 =0 || >$number елемент управления пагинацией удаляется
  */
 private function getPaginationNumber()
 {
     db_connect::connect();
     if (is_numeric($this->table)) {
         $count_table = $this->table;
     } else {
         $count_table = R::count($this->table, " WHERE " . $this->table . ".activ = 1");
     }
     $number = (int) ceil($count_table / $this->number);
     if ($this->page_number >= $number || $number === 1) {
         $this->tpl_next = '';
     }
     if ($this->page_number - 1 <= 0 || $number === 1) {
         $this->tpl_previous = '';
     }
     return $number;
 }