From 1ccf6db73adcef3aa079bf54c1fdba975732adae Mon Sep 17 00:00:00 2001 From: andryeyev Date: Fri, 11 Dec 2015 14:17:38 +0200 Subject: [PATCH] + класс Extra для вкл./выкл доп. функций на сайте в админке --- ajax/extra.php | 28 ++++++++++++++++++++++++++++ css/admin.css | 23 +++++++++++++++++++++++ js/extra.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ libs/extra.class.php | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ modules/admin/extra.php | 4 ++++ 5 files changed, 196 insertions(+), 0 deletions(-) create mode 100644 ajax/extra.php create mode 100644 js/extra.js create mode 100644 libs/extra.class.php create mode 100644 modules/admin/extra.php diff --git a/ajax/extra.php b/ajax/extra.php new file mode 100644 index 0000000..fa1c45d --- /dev/null +++ b/ajax/extra.php @@ -0,0 +1,28 @@ +setupClass ('Extra'); + if ($objExtra->setExtraStatus ($_REQUEST)) + { + echo json_encode (array ( + 'html' => htmlMessage ('success', 'Сохранено') + )); + } + else + { + echo json_encode (array ( + 'html' => htmlMessage ('error', 'Не сохранено') + )); + } + + break; +} \ No newline at end of file diff --git a/css/admin.css b/css/admin.css index 0785c1b..3cf5b24 100644 --- a/css/admin.css +++ b/css/admin.css @@ -61,9 +61,13 @@ p{margin:0px;} } + /* + =================== ==== adminMenu ==== + =================== */ + div.adminMenu { width: 190px; } @@ -125,6 +129,25 @@ div.adminMenu .activeMenu { filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#001560', endColorstr='#103782',GradientType=0 ); } +/* + =============== + ==== Extra ==== + =============== +*/ + +#Extra .line .label { + text-transform: uppercase; + color: #000; + margin: 0 1px 0 0; + text-align: center; + text-decoration: none; + white-space: nowrap; + width: 100px; +} + +#Extra .line > div { + display: inline-block; +} .td_top {background-color:#296da4; color:#ffffff;} .td_1 {background-color:#f6f6f6; color:#000000;} diff --git a/js/extra.js b/js/extra.js new file mode 100644 index 0000000..50b5b24 --- /dev/null +++ b/js/extra.js @@ -0,0 +1,44 @@ + + function extraAction ($array) + { + $.ajax({ + type: 'GET', + url: '/ajax/extra.php', + dataType: 'json', + data: $.param ($array['json']), + success: function (response) + { + switch ($array['json']['jaction']) + { + case 'extra': + + modalBoxLoad (response.html, { + autoClose: 800, + }); + break; + } + }, + error: function() + { + modalBoxLoad ('- ...'); + } + }); + + } + +$(function() +{ + $(".switch").bootstrapSwitch( + { + onSwitchChange: function(event, state) + { + extraAction ({ + 'json': { + 'jaction': 'extra', + 'status_id': state === false ? 0 : 1, + 'extra_id': $(this).closest('.line').attr('id').replace('extra-', ''), + } + }); + } + }); +}); \ No newline at end of file diff --git a/libs/extra.class.php b/libs/extra.class.php new file mode 100644 index 0000000..3193e7a --- /dev/null +++ b/libs/extra.class.php @@ -0,0 +1,97 @@ +db = &$db; + $this->tpl = &$tpl; + $this->error = &$error; + $this->cache = &$cache; + } + + public function trim (&$data) + { + foreach ($data as $key => $value) + { + if (! is_array ($data[$key])) + { + $data[$key] = trim ($value); + } + } + } + + public function valid ($data, $upload = null) + { + return true; + } + + public function getAll () + { + return $this->db->getAll(' + SELECT * + FROM `extra` + INNER JOIN `extra_status` ON `extra_status`.status_id = `extra`.status_id + ', array (), DB_FETCHMODE_ASSOC); + } + + public function init () + { + // assign var + $this->tpl->assign('mass', array ( + 'extra' => $this->getAll(), + )); + + // assign template + $this->tpl->assign("tpl", "extra.tpl"); + } + + public function getOneByName ($NAME) + { + return $this->db->getRow(' + SELECT * + FROM `extra` + INNER JOIN `extra_status` ON `extra_status`.status_id = `extra`.status_id + WHERE `extra`.extra_name=? + ', array ($NAME), DB_FETCHMODE_ASSOC); + } + + public function getOneById ($id) + { + return $this->db->getRow(' + SELECT * + FROM `extra` + INNER JOIN `extra_status` ON `extra_status`.status_id = `extra`.status_id + WHERE `extra`.extra_id=? + ', array ($id), DB_FETCHMODE_ASSOC); + } + + public function getStatusIdByName ($NAME) + { + $result = $this->getOneByName ($NAME); + + return $result['status_id']; + } + + public function setExtraStatus ($param) + { + return $this->db->query(' + UPDATE `extra` + SET status_id = '.(int)$param['status_id'].' + WHERE extra_id = '.(int)$param['extra_id'].' + '); + } + + public function displaySnow () + { + return ' + + '; + // + } +} diff --git a/modules/admin/extra.php b/modules/admin/extra.php new file mode 100644 index 0000000..98ac679 --- /dev/null +++ b/modules/admin/extra.php @@ -0,0 +1,4 @@ +init(); \ No newline at end of file -- libgit2 0.21.4