function main() { \CO::RE()->header('content-type', 'text/html; charset=utf-8'); \CO::SQL(new \DB\SQLi())->connect('188.120.227.83', 'root', 'kolkol123', 'test_sete_pw')->query("set names utf8;"); \CO::AUTH(new Model\Auth('039hg0whas9w8bp3wg')); $this->router(); }
public final function __construct() { $spaces = explode('\\', get_called_class()); if (is_null($this->table)) { $this->table = strtolower(array_pop($spaces)); } $this->sql = CO::SQL(); $this->update = []; $places = $this->sql->query("\nselect COLUMN_NAME, COLUMN_TYPE\nfrom information_schema.columns \nwhere\n\ttable_name = ?\n\tand\n\ttable_schema = database();\n\t\t\t", [['s', $this->table]]); foreach ($places as $column) { $this->type[$column['COLUMN_NAME']] = $column['COLUMN_TYPE']; $this->place[] = $column['COLUMN_NAME']; } }
function add($params) { if (!isset($params['id_set'])) { return [ApiConstants::$STATUS => ApiConstants::$ERROR, ApiConstants::$ERROR_MESSAGE => ApiConstants::$ERROR_PARAMS_STRING, ApiConstants::$ERROR_CODE => ApiConstants::$ERROR_PARAMS_CODE]; } if (\CO::AUTH()->user()) { // Корзина $bin = new \Application\Test\Model\Bin(); // Проверяем, есть ли корзина у пользователя $binId = $bin->QUERY("SELECT id_order\nfrom orders\nwhere\n user_id = ?\n and\n state = 'bin'\nlimit 1;\n ", [['i', \CO::AUTH()->who()->ID()]]); if (count($binId)) { //Если есть, то забираем ее $bin->findBy_id_order($binId[0]['id_order']); } else { //Если нет, то создаем $bin->user_id = \CO::AUTH()->who()->ID(); $bin->state = 'bin'; $bin->price = 0; $bin->CREATE(); } //Позиция $set = new \Application\Test\Model\OrderSet(); //Проверка существования стола и его статуса $setId = $set->QUERY("\nSELECT id_set\nFROM sets\nWHERE id_set = ? and id_set not in (SELECt set_id FROM order_sets WHERE state <> 'delete')\n ", [['i', (int) $params['id_set']]]); if (!count($setId)) { return [ApiConstants::$STATUS => ApiConstants::$ERROR, ApiConstants::$ERROR_MESSAGE => ApiConstants::$ERROR_BUSY_SET_STRING, ApiConstants::$ERROR_CODE => ApiConstants::$ERROR_BUSY_SET_CODE]; } $setId = $set->QUERY("\nSELECT id_order_set\nFROM order_sets\nWHERE set_id = ? and state <> 'delete'\n ", [['i', $params['id_set']]]); if (count($setId)) { return [ApiConstants::$STATUS => ApiConstants::$ERROR, ApiConstants::$ERROR_MESSAGE => ApiConstants::$ERROR_BUSY_SET_STRING, ApiConstants::$ERROR_CODE => ApiConstants::$ERROR_BUSY_SET_CODE]; } //Пытаемся добавить позицию $set->QUERY("INSERT INTO order_sets(\n order_id,\n set_id,\n state\n)values(\n ?, ?, 'add'\n);\n ", [['i', $bin->ID()], ['i', (int) $params['id_set']]]); $set->findBy_id_order_set(\CO::SQL()->iid()); if (isset($set->id_order_set)) { $returnRequest = ['id_order_set' => $set->ID()]; $bin->price += $this->QUERY("\nSELECT price\nFROM tables inner join sets on tables.id_table = sets.table_id\nWHERE id_set=?", [['i', $set->set_id]])[0]['price']; $bin->UPDATE(); return $returnRequest; } return null; /** ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ (insert id) */ } if (\CO::AUTH()->unknown()) { return [ApiConstants::$STATUS => ApiConstants::$ERROR, ApiConstants::$ERROR_MESSAGE => ApiConstants::$ERROR_AUTH__STRING, ApiConstants::$ERROR_CODE => ApiConstants::$ERROR_AUTH_CODE]; } }
<?php if (CO::AUTH()->user()) { if (isset(CO::RE()->post['passwd']) && isset(CO::RE()->post['passwd_new']) && CO::RE()->post['passwd'] != CO::RE()->post['passwd_new'] && CO::AUTH()->who('passwd') === CO::AUTH()->getHash(CO::AUTH()->who('id_user'), CO::RE()->post['passwd'])) { CO::SQL()->query("UPDATE users\n\t\t\t\tset\n\t\t\t\t\tpasswd = ?\n\t\t\t\twhere\n\t\t\t\t\tid_user = ?\n\t\t\t\tlimit 1;\n\t\t\t", [['s', CO::AUTH()->getHash(CO::AUTH()->who('id_user'), CO::RE()->post['passwd_new'])], ['i', CO::AUTH()->who('id_user')]]); CO::AUTH()->login(CO::AUTH()->who('email'), CO::RE()->post['passwd_new']); } if (isset(CO::RE()->post['name'])) { CO::SQL()->query("UPDATE users\n\t\t\t\tset\n\t\t\t\t\tname = ?\n\t\t\t\twhere\n\t\t\t\t\tid_user = ?\n\t\t\t\tlimit 1;\n\t\t\t", [['s', strip_tags(CO::RE()->post['name'])], ['i', CO::AUTH()->who('id_user')]]); CO::AUTH()->update(); } ?> <h1> <?php echo CO::AUTH()->who('name'); ?> </h1> <div class="col-lg-8"> <ul class="nav nav-tabs"> <li class="active"><a href="#profile" data-toggle="tab" aria-expanded="true">Профиль</a></li> <li class=""><a href="#security" data-toggle="tab" aria-expanded="false">Безопасность</a></li> </ul> <div class="tab-content"> <div class="tab-pane fade active in" id="profile"> <form class="form-horizontal col-lg-8" action="" method="post"> <input type="hidden" name="act" value="edit"> <fieldset>
<?php $data = CO::RE()->post; $dataReturn = json_decode('{}'); $dataReturn->status = json_decode('{}'); if (isset($data['id'])) { $query = CO::SQL()->query("\nSELECT id_image as id, url, transition, user_id\nFROM images\nWHERE id_image = ?\n ", [['i', (int) $data['id']]]); if (count($query) == 0) { $dataReturn->status = 'error'; } else { foreach ($query as &$img) { $img['url'] = '/image/' . $img['url'] . '/origin'; } CO::SQL()->query("\nUPDATE images\nSET transition = transition + 1\nWHERE id_image = ?\n ", [['i', (int) $data['id']]]); $dataReturn->status = 'success'; $dataReturn->response = $query[0]; } } else { $dataReturn->status = 'error'; } echo json_encode($dataReturn);
<?php $img = CO::SQL()->query("SELECT *\n\t\tfrom images\n\t\twhere\n\t\t\turl = ?\n\t\tlimit 1;\n\t", [['s', $args['url']]]); if (count($img)) { $img = $img[0]; ?> <img src="/image/<?php echo $img['url']; ?> /origin" alt="<?php echo $img['category']; ?> " class="col-xs-12" style="margin-bottom: 20px;"> <br> <h1 class="col-xs-12"> Категория: <strong><?php echo $img['category']; ?> </strong> / Просмотры: <?php echo $img['transition']; ?> </h1> <div class="col-xs-12" style="margin-bottom: 50px;"> <a href="<?php echo $img['url_ext']; ?> " target="_blank"><?php echo $img['url_ext'];
<?php $data = CO::RE()->post; $dataReturn = json_decode('{}'); $dataReturn->status = json_decode('{}'); if (isset($data['category'])) { $query = CO::SQL()->query("\nSELECT id_image as id, url_ext, transition\nFROM images\nWHERE category = ?\n ", [['s', mb_strtolower(strip_tags(trim($data['category'])), 'utf-8')]]); foreach ($query as &$img) { $img['url'] = '/image/' . $img['url'] . '/preview'; } $dataReturn->status = 'success'; $dataReturn->response = $query; } else { $dataReturn->status = 'error'; } echo json_encode($dataReturn);
if (!CO::AUTH()->user()) { redirect('/'); } else { if (isset(CO::RE()->post['delete'])) { $id = (int) CO::RE()->post['delete']; $file = CO::SQL()->query("SELECT *\n\t\t\t\tfrom images\n\t\t\t\twhere\n\t\t\t\t\tid_image = ?\n\t\t\t\tlimit 1;\n\t\t\t", [['i', $id]]); if (count($file)) { $file = $file[0]['url']; CO::SQL()->query("DELETE from images\n\t\t\t\t\twhere\n\t\t\t\t\t\tid_image = ?\n\t\t\t\t\tlimit 1;\n\t\t\t\t", [['i', $id]]); unlink(DIR_PRIVATE . 'data/image/' . $file); unlink(DIR_PRIVATE . 'data/image-preview/' . $file); } } $onPage = 30; $startId = isset(CO::RE()->get['start']) ? (int) CO::RE()->get['start'] : 0; $list = CO::SQL()->query("SELECT *\n\t\t\tfrom images\n\t\t\twhere\n\t\t\t\tid_image > ?\n\t\t\torder by id_image desc\n\t\t\tlimit ?;\n\t\t", [['i', $startId], ['i', $onPage]]); CO::RE()->push('css', '/assets/css/file-manager.css'); CO::RE()->push('js', '/assets/js/file-manager.css'); ?> <h1> Файловый менеджер </h1> <div class="row image-list"> <?php foreach ($list as $img) { $img['url_view'] = '/view/' . $img['url']; $img['url'] = '/image/' . $img['url']; $img['url_preview'] = $img['url'] . '/preview'; ?>
<?php define('DIR_LIB', DIR_PRIVATE . 'lib/'); include DIR_LIB . 'co.php'; include DIR_LIB . 'mysql.php'; include DIR_LIB . 'auth.php'; include DIR_LIB . 'router.php'; include DIR_LIB . 'resize.php'; CO::RE(); CO::PROJECT([name => 'WorkImage']); CO::RE()->header('content-type', 'text/html; charset=utf-8'); CO::RE()->www = function ($file, $args = null) { CO::RE()->ARR('js'); CO::RE()->ARR('css'); include DIR_PRIVATE . 'www/' . $file; $content = ob_get_clean(); ob_start(); include DIR_PRIVATE . 'template.php'; CO::RE()->end(); }; CO::SQL(new \DB\SQLi())->connect('test.sete.pw', 'root', 'kolkol123', 'test_images')->query("SET names utf8;\n\t"); CO::AUTH(new \Auth('fsdnoFi3h0W9ghGpsdi234E2')); CO::ROUTER(new \Router()); include DIR_PRIVATE . 'init_router.php'; CO::ROUTER()->start(CO::RE()->url);
function getUserById($id) { $result = CO::SQL()->query("SELECT *\n\t\t\t\tfrom users\n\t\t\t\twhere\n\t\t\t\t\tid_user = ?\n\t\t\t\tlimit 1;\n\t\t\t", [['i', (int) $id]]); return $result[0]; }
<?php if (isset(CO::RE()->files['image'])) { $imgs = CO::RE()->files['image']; foreach ($imgs['type'] as $key => $type) { if (explode('/', $type)[0] == 'image') { do { $url = md5(date('Y-m-d H:i:s') . '->' . rand(-99999, 99999) . ':' . rand(-99999, 99999) . ':' . rand(-99999, 99999) . ':' . rand(-99999, 99999)); $ext = explode('.', $imgs['name'][$key]); $ext = array_pop($ext); $url .= '.' . $ext; CO::SQL()->query("INSERT INTO images\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\turl,\n\t\t\t\t\t\t\turl_ext,\n\t\t\t\t\t\t\tcategory,\n\t\t\t\t\t\t\tuser_id\n\t\t\t\t\t\t)values(\n\t\t\t\t\t\t\t?,\n\t\t\t\t\t\t\t?,\n\t\t\t\t\t\t\t?,\n\t\t\t\t\t\t\t?\n\t\t\t\t\t\t);\n\t\t\t\t\t", [['s', $url], ['s', mb_strtolower(trim(strip_tags(CO::RE()->post['url_ext'][$key])), 'utf-8')], ['s', mb_strtolower(trim(strip_tags(CO::RE()->post['file'][$key])), 'utf-8')], ['i', CO::AUTH()->who('id_user')]]); $id = CO::SQL()->iid(); if (!copy($imgs['tmp_name'][$key], DIR_PRIVATE . 'data/image/' . $url)) { CO::SQL()->query("DELETE from images\n\t\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t\tid_image = ?\n\t\t\t\t\t\t\tlimit 1;\n\t\t\t\t\t\t", [['i', $id]]); break; } createPreview($url); } while ($id == 0); } } } CO::RE()->redirect('/file-manager.php');