Permalink
Browse files

adding admin interface

  • Loading branch information...
1 parent 4c149b0 commit d71f589cb61fa93f608411f59861b05a62d42027 d1ffuz0r committed with Roman Mar 16, 2011
View
275 application/bootstrap.php
@@ -1,137 +1,138 @@
-<?php defined('SYSPATH') or die('No direct script access.');
-
-//-- Environment setup --------------------------------------------------------
-
-/**
- * Set the default time zone.
- *
- * @see http://kohanaframework.org/guide/using.configuration
- * @see http://php.net/timezones
- */
-date_default_timezone_set('Europe/Moscow');
-
-/**
- * Set the default locale.
- *
- * @see http://kohanaframework.org/guide/using.configuration
- * @see http://php.net/setlocale
- */
-setlocale(LC_ALL, 'en_US.utf-8');
-
-/**
- * Enable the Kohana auto-loader.
- *
- * @see http://kohanaframework.org/guide/using.autoloading
- * @see http://php.net/spl_autoload_register
- */
-spl_autoload_register(array('Kohana', 'auto_load'));
-
-/**
- * Enable the Kohana auto-loader for unserialization.
- *
- * @see http://php.net/spl_autoload_call
- * @see http://php.net/manual/var.configuration.php#unserialize-callback-func
- */
-ini_set('unserialize_callback_func', 'spl_autoload_call');
-
-//-- Configuration and initialization -----------------------------------------
-
-/**
- * Set Kohana::$environment if a 'KOHANA_ENV' environment variable has been supplied.
- */
-if (getenv('KOHANA_ENV') !== FALSE)
-{
- Kohana::$environment = getenv('KOHANA_ENV');
-}
-
-/**
- * Initialize Kohana, setting the default options.
- *
- * The following options are available:
- *
- * - string base_url path, and optionally domain, of your application NULL
- * - string index_file name of your index file, usually "index.php" index.php
- * - string charset internal character set used for input and output utf-8
- * - string cache_dir set the internal cache directory APPPATH/cache
- * - boolean errors enable or disable error handling TRUE
- * - boolean profile enable or disable internal profiling TRUE
- * - boolean caching enable or disable internal caching FALSE
- */
-Kohana::init(array(
- 'base_url' => '/',
-));
-
-/**
- * Attach the file write to logging. Multiple writers are supported.
- */
-Kohana::$log->attach(new Kohana_Log_File(APPPATH.'logs'));
-
-/**
- * Attach a file reader to config. Multiple readers are supported.
- */
-Kohana::$config->attach(new Kohana_Config_File);
-
-/**
- * Enable modules. Modules are referenced by a relative or absolute path.
- */
-Kohana::modules(array(
- // 'auth' => MODPATH.'auth', // Basic authentication
- // 'cache' => MODPATH.'cache', // Caching with multiple backends
- // 'codebench' => MODPATH.'codebench', // Benchmarking tool
- 'database' => MODPATH.'database', // Database access
- // 'image' => MODPATH.'image', // Image manipulation
- // 'orm' => MODPATH.'orm', // Object Relationship Mapping
- // 'oauth' => MODPATH.'oauth', // OAuth authentication
- 'pagination' => MODPATH.'pagination', // Paging of results
- // 'unittest' => MODPATH.'unittest', // Unit testing
- // 'userguide' => MODPATH.'userguide', // User guide and API documentation
- ));
-
-/**
- * Set the routes. Each route must have a minimum of a name, a URI and a set of
- * defaults for the URI.
- */
-/*Route::set('default', '(<controller>(/<action>(/<id>)))')
- ->defaults(array(
- 'controller' => 'welcome',
- 'action' => 'index',
- ));
- */
-Route::set('auth','auth(/<action>)')
- ->defaults(array(
- 'controller' => 'Auth'
- ));
-Route::set('admin','admin(/<action>(/<id>))')
- ->defaults(array(
- 'controller' => 'Admin',
- 'action' => 'Index'
- ));
-Route::set('cashier','cashier(/<action>(/<id>))')
- ->defaults(array(
- 'controller' => 'Cashier',
- 'action' => 'Index'
- ));
-Route::set('default', '(<action>(/<id>))')
- ->defaults(array(
- 'controller' => 'Page',
- 'action' => 'Home'
- ));
-Route::set('view', '(view(/<action>(/<id>)))')
- ->defaults(array(
- 'controller' => 'View'
- ));
-Route::set('shop','(<controller>(/<action>(/<id>)))')
- ->defaults(array(
- 'controller' => 'Shop'
- ));
-if ( ! defined('SUPPRESS_REQUEST'))
-{
- /**
- * Execute the main request. A source of the URI can be passed, eg: $_SERVER['PATH_INFO'].
- * If no source is specified, the URI will be automatically detected.
- */
- echo Request::instance()
- ->execute()
- ->send_headers()
- ->response;
-}
+<?php defined('SYSPATH') or die('No direct script access.');
+
+//-- Environment setup --------------------------------------------------------
+
+/**
+ * Set the default time zone.
+ *
+ * @see http://kohanaframework.org/guide/using.configuration
+ * @see http://php.net/timezones
+ */
+date_default_timezone_set('Europe/Moscow');
+
+/**
+ * Set the default locale.
+ *
+ * @see http://kohanaframework.org/guide/using.configuration
+ * @see http://php.net/setlocale
+ */
+setlocale(LC_ALL, 'en_US.utf-8');
+
+/**
+ * Enable the Kohana auto-loader.
+ *
+ * @see http://kohanaframework.org/guide/using.autoloading
+ * @see http://php.net/spl_autoload_register
+ */
+spl_autoload_register(array('Kohana', 'auto_load'));
+
+/**
+ * Enable the Kohana auto-loader for unserialization.
+ *
+ * @see http://php.net/spl_autoload_call
+ * @see http://php.net/manual/var.configuration.php#unserialize-callback-func
+ */
+ini_set('unserialize_callback_func', 'spl_autoload_call');
+
+//-- Configuration and initialization -----------------------------------------
+
+/**
+ * Set Kohana::$environment if a 'KOHANA_ENV' environment variable has been supplied.
+ */
+if (getenv('KOHANA_ENV') !== FALSE)
+{
+ Kohana::$environment = getenv('KOHANA_ENV');
+}
+
+/**
+ * Initialize Kohana, setting the default options.
+ *
+ * The following options are available:
+ *
+ * - string base_url path, and optionally domain, of your application NULL
+ * - string index_file name of your index file, usually "index.php" index.php
+ * - string charset internal character set used for input and output utf-8
+ * - string cache_dir set the internal cache directory APPPATH/cache
+ * - boolean errors enable or disable error handling TRUE
+ * - boolean profile enable or disable internal profiling TRUE
+ * - boolean caching enable or disable internal caching FALSE
+ */
+Kohana::init(array(
+ 'base_url' => '/',
+));
+
+/**
+ * Attach the file write to logging. Multiple writers are supported.
+ */
+Kohana::$log->attach(new Kohana_Log_File(APPPATH.'logs'));
+
+/**
+ * Attach a file reader to config. Multiple readers are supported.
+ */
+Kohana::$config->attach(new Kohana_Config_File);
+
+/**
+ * Enable modules. Modules are referenced by a relative or absolute path.
+ */
+Kohana::modules(array(
+ // 'auth' => MODPATH.'auth', // Basic authentication
+ // 'cache' => MODPATH.'cache', // Caching with multiple backends
+ // 'codebench' => MODPATH.'codebench', // Benchmarking tool
+ 'database' => MODPATH.'database', // Database access
+ // 'image' => MODPATH.'image', // Image manipulation
+ // 'orm' => MODPATH.'orm', // Object Relationship Mapping
+ // 'oauth' => MODPATH.'oauth', // OAuth authentication
+ 'pagination' => MODPATH.'pagination', // Paging of results
+ // 'unittest' => MODPATH.'unittest', // Unit testing
+ // 'userguide' => MODPATH.'userguide', // User guide and API documentation
+ ));
+
+/**
+ * Set the routes. Each route must have a minimum of a name, a URI and a set of
+ * defaults for the URI.
+ */
+/*Route::set('default', '(<controller>(/<action>(/<id>)))')
+ ->defaults(array(
+ 'controller' => 'welcome',
+ 'action' => 'index',
+ ));
+ */
+Route::set('auth','auth(/<action>)')
+ ->defaults(array(
+ 'controller' => 'Auth'
+ ));
+Route::set('admin','admin(/<action>(/<id>))')
+ ->defaults(array(
+ 'controller' => 'Admin',
+ 'action' => 'Index'
+ ));
+Route::set('cashier','cashier(/<action>(/<id>))')
+ ->defaults(array(
+ 'controller' => 'Cashier',
+ 'action' => 'Index'
+ ));
+Route::set('default', '(<action>(/<id>))')
+ ->defaults(array(
+ 'controller' => 'Page',
+ 'action' => 'Home'
+ ));
+Route::set('view', '(view(/<action>(/<id>)))')
+ ->defaults(array(
+ 'controller' => 'View'
+ ));
+Route::set('shop','(<controller>(/<action>(/<id>)))')
+ ->defaults(array(
+ 'controller' => 'Shop'
+ ));
+
+if ( ! defined('SUPPRESS_REQUEST'))
+{
+ /**
+ * Execute the main request. A source of the URI can be passed, eg: $_SERVER['PATH_INFO'].
+ * If no source is specified, the URI will be automatically detected.
+ */
+ echo Request::instance()
+ ->execute()
+ ->send_headers()
+ ->response;
+}
View
220 application/classes/controller/admin.php
@@ -1,30 +1,192 @@
-<?php defined('SYSPATH') or die('No direct script access.');
-/**
- * @author d1ffuz0r gladk0w@mail.ru
- * @license GPLv3
- * @copyright 2011
- */
-class Controller_Admin extends Controller_Tpl
- {
-
- /**
- * @param POST читаем имя пользователя
- * @return HTML выводим главную страницы админки
- */
- public function action_index()
- {
- $username = Cookie::get('username');
- $user = Model::factory('users');
- if($user->get_rang($username) == 1)
- {
- $this->template->title = __('Администратор');
- $this->template->content = View::factory('admin/index');
- }
- else
- {
- $this->template->title = __('Ошибка');
- $this->template->content = View::factory('tpl/msg')
- ->set('msg',Kohana::message('msg', 'no_access'));
- }
- }
+<?php defined('SYSPATH') or die('No direct script access.');
+/**
+ * @author d1ffuz0r gladk0w@mail.ru
+ * @license GPLv3
+ * @copyright 2011
+ */
+class Controller_Admin extends Controller_Tpl
+ {
+
+ /**
+ * @param POST читаем имя пользователя
+ * @return void HTML выводим главную страницы админки
+ */
+ public function action_index()
+ {
+ $username = Cookie::get('username');
+ $user = Model::factory('users');
+ if($user->get_rang($username) == 1)
+ {
+ $this->template->title = __('Администратор');
+ $this->template->content = View::factory('admin/index');
+ }
+ else
+ {
+ $this->template->title = __('Ошибка');
+ $this->template->content = View::factory('tpl/msg')
+ ->set('msg',Kohana::message('msg', 'no_access'));
+ }
+ }
+ /**
+ * @return void
+ */
+ public function action_category()
+ {
+ $category = new Model_Shop();
+ $this->template->title = __('Администратор: категории');
+ $this->template->content = View::factory('admin/category')
+ ->set('category',$category->get_category());
+ }
+
+ /**
+ * @param $cat
+ * @return void
+ */
+ public function action_view_category($cat)
+ {
+ $shop = new Model_Shop();
+ $pagination = Pagination::factory(array(
+ 'current_page' => array('source' => 'query_string', 'key' => 'p'),
+ 'total_items' => $shop->count_category($cat),
+ 'items_per_page' => 30,
+ 'view' => 'pagination/floating',
+ 'auto_hide' => TRUE,
+ 'first_page_in_url' => TRUE
+ ));
+ $page = $pagination->current_page;
+ $per_page = $pagination->items_per_page;
+ $offset = $per_page * ($page-1);
+ $page_links = $pagination->render();
+
+ $this->template->title = __('Администратор: Просмотр категории');
+ $this->template->content = View::factory('admin/view_category')
+ ->set('id', $shop->view_category($cat, $offset, $per_page))
+ ->set('pagination', $page_links)
+ ->set('categories',$shop->get_category());
+ }
+
+ /**
+ * @return void
+ */
+ public function action_add_category()
+ {
+ $admin = new Model_Admin();
+ if(!empty($_POST))
+ {
+ $name = Arr::get($_POST, 'name');
+ $rusname = Arr::get($_POST, 'rusname');
+ $admin->add_category($name, $rusname);
+ $this->template->title = __('Администратор: категория добавлена');
+ $this->template->content = View::factory('tpl/msg')
+ ->set('msg','<h1>Категория '.$rusname.' добавлена</h1>');
+ }
+ }
+
+ /**
+ * @param $id
+ * @return void
+ */
+ public function action_delete_category($id)
+ {
+ $admin = new Model_Admin();
+ $admin->delete_category($id);
+ $this->template->title = __('Администратор: категория удалена');
+ $this->template->content = View::factory('tpl/msg')
+ ->set('msg','<h1>Категория id'.$id.' удалена</h1>');
+ }
+
+ /**
+ * @param $id
+ * @return void
+ */
+ public function action_edit_category($id)
+ {
+ $shop = new Model_Shop();
+ $this->template->title = __('Администратор: редактирование категории');
+ $this->template->content = View::factory('admin/edit_category')
+ ->set('category',$shop->get_one_category($id));
+ }
+
+ /**
+ * @return void
+ */
+ public function action_update_category()
+ {
+ $admin = new Model_Admin();
+ if(!empty($_POST))
+ {
+ $id = Arr::get($_POST, 'id');
+ $name = Arr::get($_POST, 'name');
+ $rusname = Arr::get($_POST, 'rusname');
+ $param = Arr::get($_POST, 'param');
+ $etc = Arr::get($_POST, 'etc');
+ $admin->update_category($id, $name, $rusname, $param, $etc);
+ $this->template->title = __('Администратор: категория обновлена');
+ $this->template->content = View::factory('tpl/msg')
+ ->set('msg','<h1>Категория '.$rusname.' изменена</h1>');
+ }
+ }
+
+ /**
+ * @return void
+ */
+ public function action_add_product()
+ {
+ $admin = new Model_Admin();
+ if(!empty($_POST))
+ {
+ $rusname = Arr::get($_POST, 'rusname');
+ $desc = Arr::get($_POST, 'desc');
+ $price = Arr::get($_POST, 'price');
+ $category = Arr::get($_POST, 'category');
+ $admin->add_product($rusname, $desc, $price, $category);
+ $this->template->title = __('Администратор: продукт добавлен');
+ $this->template->content = View::factory('tpl/msg')
+ ->set('msg','<h1>Продукт '.$rusname.' добавлен</h1>');
+ }
+ }
+
+ /**
+ * @param $id
+ * @return void
+ */
+ public function action_delete_product($id)
+ {
+ $admin = new Model_Admin();
+ $admin->delete_product($id);
+ $this->template->title = __('Администратор: продукт удалён');
+ $this->template->content = View::factory('tpl/msg')
+ ->set('msg','<h1>Продукт id:'.$id.' удалён</h1>');
+ }
+
+ /**
+ * @param $id
+ * @return void
+ */
+ public function action_edit_product($id)
+ {
+ $shop = new Model_Shop();
+ $this->template->title = __('Администратор: редактирование продукта');
+ $this->template->content = View::factory('admin/edit_product')
+ ->set('id',$shop->get_one_product($id));
+ }
+
+ /**
+ * @return void
+ */
+ public function action_update_product()
+ {
+ $admin = new Model_Admin();
+ if(!empty($_POST))
+ {
+ $id = Arr::get($_POST, 'id');
+ $rusname = Arr::get($_POST, 'rusname');
+ $desc = Arr::get($_POST, 'desc');
+ $price = Arr::get($_POST, 'price');
+ $admin->update_product($id, $rusname, $desc, $price);
+ $this->template->title = __('Администратор: продукт изменён');
+ $this->template->content = View::factory('tpl/msg')
+ ->set('msg','<h1>Продукт id:'.$id.' изменён</h1>');
+ }
+ }
}
View
26 application/classes/controller/auth.php
@@ -13,15 +13,15 @@ class Controller_Auth extends Controller_Tpl
public function action_login()
{
$auth = Model::factory('Auth');
-
+
if(!empty($_POST))
{
- $login = Arr::get($_POST, 'login');
- $password = Arr::get($_POST, 'password');
+ $login = Arr::get($_POST, 'login');
+ $password = Arr::get($_POST, 'password');
- $this->template->title = __('Авторизация');
- $this->template->content = View::factory('tpl/msg')
- ->set('msg', $auth->login($login,$password));
+ $this->template->title = __('Авторизация');
+ $this->template->content = View::factory('tpl/msg')
+ ->set('msg', $auth->login($login,$password));
}
}
@@ -33,13 +33,13 @@ public function action_register()
$auth = Model::factory('Auth');
if(!empty($_POST))
{
- $login = Arr::get($_POST, 'login');
- $password = Arr::get($_POST, 'password');
- $email = Arr::get($_POST, 'email');
+ $login = Arr::get($_POST, 'login');
+ $password = Arr::get($_POST, 'password');
+ $email = Arr::get($_POST, 'email');
- $this->template->title = __('Зарегистрированы');
- $this->template->content = View::factory('tpl/msg')
- ->set('msg', $auth->register($login,$password,$email));
+ $this->template->title = __('Зарегистрированы');
+ $this->template->content = View::factory('tpl/msg')
+ ->set('msg', $auth->register($login,$password,$email));
}
}
@@ -53,6 +53,6 @@ public function action_logout()
$this->template->title = __('До свидания');
$this->template->content = View::factory('tpl/msg')
- ->set('msg',Kohana::message('msg','bye'));
+ ->set('msg',Kohana::message('msg','bye'));
}
}
View
6 application/classes/controller/cashier.php
@@ -36,9 +36,9 @@ public function action_order_manager()
$order = Model::factory('order');
$this->template->title = __('Кассир: Менеджер заказов');
$this->template->content = View::factory('cashier/order_manager')
- ->set('list',$order->view_order_s(1));
+ ->set('list',$order->view_order_s(1));
}
-
+
/**
* @return HTML вывод формы оформления нового заказа
*/
@@ -47,6 +47,6 @@ public function action_order_add()
$shop = Model::factory('shop');
$this->template->title = __('Кассир: оформление заказа');
$this->template->content = View::factory('cashier/order_add')
- ->set('list_cat', $shop->get_category());
+ ->set('list_cat', $shop->get_category());
}
}
View
226 application/classes/controller/page.php
@@ -1,113 +1,113 @@
-<?php defined('SYSPATH') or die('No direct script access.');
-/**
- * @author d1ffuz0r gladk0w@mail.ru
- * @license GPLv3
- * @copyright 2011
- */
-class Controller_Page extends Controller_Tpl
- {
-
- /**
- * @return HTML вывод главной страницы
- */
- public function action_home()
- {
- $main = Model::factory('main');
- $this->template->title = __('Добро пожаловать');
- $this->template->content = View::factory('page/index')
- ->set('service', $main->get_services())
- ->set('prodone', $main->get_fisttwo())
- ->set('prowthree',$main->get_threefour());
- }
-
- /**
- * @return HTML вывод страницы помощи
- */
- public function action_help()
- {
- $this->template->title = __('Помощь');
- $this->template->content = View::factory('page/help');
- }
-
- /**
- * @return HTML вывод страницы контактов
- */
- public function action_contact()
- {
- $this->template->title = __('Контактная информация');
- $this->template->content = View::factory('page/contact');
- }
-
- /**
- * @param POST читаем из кук имя пользователя
- * @return HTML вывод заказов пользователя
- */
- public function action_orders()
- {
- if(Cookie::get('loged_in')==TRUE)
- {
- $order = Model::factory('order');
- $orders = $order->view_orders(Cookie::get('username'));
- $this->template->title = __('Заказы');
- $this->template->content = View::factory('page/orders')
- ->set('list', $orders);
- }
- else
- {
- $this->template->title = __('Ошибка');
- $this->template->content = View::factory('tpl/msg')
- ->set('msg',Kohana::message('msg','not_login'));
- }
- }
-
- /**
- * @param POST проверяем из кук,залогинен ли пользователь, читаем имя пользователя
- * @return HTML вывод покупок пользователя
- */
- public function action_kart()
- {
- if(Cookie::get('loged_in')==TRUE)
- {
- $shop = Model::factory('shop');
- $orders = $shop->view_kart(Cookie::get('username'));
- $this->template->title = __('Заказы');
- $this->template->content = View::factory('page/kart')
- ->set('list', $orders);
- }
- else
- {
- $this->template->title = __('Ошибка');
- $this->template->content = View::factory('tpl/msg')
- ->set('msg',Kohana::message('msg','not_login'));
- }
- }
-
- /**
- * @return HTML вывод страницы входа
- */
- public function action_login()
- {
- $this->template->title = __('Вход');
- $this->template->content = View::factory('page/auth/login');
- }
-
- /**
- * @return HTML вывод страницы регистрации
- */
- public function action_reg()
- {
- $this->template->title = __('Регистрация');
- $this->template->content = View::factory('page/auth/reg');
- }
-
- /**
- * @return set_cookie && redirect to index page
- */
- public function action_changecity()
- {
- $main = Model::factory('main');
- $main->set_city($_POST['region']);
- $this->request->redirect('/');
- }
- }
-
+<?php defined('SYSPATH') or die('No direct script access.');
+/**
+ * @author d1ffuz0r gladk0w@mail.ru
+ * @license GPLv3
+ * @copyright 2011
+ */
+class Controller_Page extends Controller_Tpl
+ {
+
+ /**
+ * @return HTML вывод главной страницы
+ */
+ public function action_home()
+ {
+ $main = Model::factory('main');
+ $this->template->title = __('Добро пожаловать');
+ $this->template->content = View::factory('page/index')
+ ->set('service', $main->get_services())
+ ->set('prodone', $main->get_fisttwo())
+ ->set('prowthree',$main->get_threefour());
+ }
+
+ /**
+ * @return HTML вывод страницы помощи
+ */
+ public function action_help()
+ {
+ $this->template->title = __('Помощь');
+ $this->template->content = View::factory('page/help');
+ }
+
+ /**
+ * @return HTML вывод страницы контактов
+ */
+ public function action_contact()
+ {
+ $this->template->title = __('Контактная информация');
+ $this->template->content = View::factory('page/contact');
+ }
+
+ /**
+ * @param POST читаем из кук имя пользователя
+ * @return HTML вывод заказов пользователя
+ */
+ public function action_orders()
+ {
+ if(Cookie::get('loged_in')==TRUE)
+ {
+ $order = Model::factory('order');
+ $orders = $order->view_orders(Cookie::get('username'));
+ $this->template->title = __('Заказы');
+ $this->template->content = View::factory('page/orders')
+ ->set('list', $orders);
+ }
+ else
+ {
+ $this->template->title = __('Ошибка');
+ $this->template->content = View::factory('tpl/msg')
+ ->set('msg',Kohana::message('msg','not_login'));
+ }
+ }
+
+ /**
+ * @param POST проверяем из кук,залогинен ли пользователь, читаем имя пользователя
+ * @return HTML вывод покупок пользователя
+ */
+ public function action_kart()
+ {
+ if(Cookie::get('loged_in')==TRUE)
+ {
+ $shop = Model::factory('shop');
+ $orders = $shop->view_kart(Cookie::get('username'));
+ $this->template->title = __('Заказы');
+ $this->template->content = View::factory('page/kart')
+ ->set('list', $orders);
+ }
+ else
+ {
+ $this->template->title = __('Ошибка');
+ $this->template->content = View::factory('tpl/msg')
+ ->set('msg',Kohana::message('msg','not_login'));
+ }
+ }
+
+ /**
+ * @return HTML вывод страницы входа
+ */
+ public function action_login()
+ {
+ $this->template->title = __('Вход');
+ $this->template->content = View::factory('page/auth/login');
+ }
+
+ /**
+ * @return HTML вывод страницы регистрации
+ */
+ public function action_reg()
+ {
+ $this->template->title = __('Регистрация');
+ $this->template->content = View::factory('page/auth/reg');
+ }
+
+ /**
+ * @return set_cookie && redirect to index page
+ */
+ public function action_changecity()
+ {
+ $main = Model::factory('main');
+ $main->set_city($_POST['region']);
+ $this->request->redirect('/');
+ }
+ }
+
View
250 application/classes/controller/shop.php
@@ -1,126 +1,126 @@
-<?php defined('SYSPATH')or die('No direct script access.');
-/**
- * @author d1ffuz0r gladk0w@mail.ru
- * @license GPLv3
- * @copyright 2011
- */
-class Controller_Shop extends Controller_Tpl
- {
-
- /**
- * @param int $id id продукта
- * @return HTML вывод формы для оформления заказа
- */
- public function action_new_order($id)
- {
- if (Cookie::get('loged_in')==TRUE)
- {
- $shop = Model::factory('shop');
-
- $product = $shop->view_product($id);
-
- $this->template->title = __('Оформление заказа');
- $this->template->content = View::factory('page/shop/new_order')
- ->set('product', $product);
- }
- else
- {
- $this->template->title = __('Ошибка');
- $this->template->content = View::factory('tpl/msg')
- ->set('msg',Kohana::message('msg','not_login'));
- }
- }
-
- /**
- * @param mixed POST данные из public action_new_order()
- * @return HTML output
- */
- public function action_add_order()
- {
- $order = Model::factory('order');
-
- $post = Validate::factory($_POST)
- ->filter(TRUE, 'trim')
- ->filter('ord_username', 'strtolower');
- $post->rule('ord_id', 'not_empty');
- $post->rule('ord_count', 'not_empty');
- $post->rule('ord_username', 'not_empty');
- $post->rule('ord_realname', 'not_empty');
- $post->rule('ord_family', 'not_empty');
- $post->rule('ord_ot4estvo', 'not_empty');
- $post->rule('ord_email', 'not_empty');
- $post->rule('ord_telephone', 'not_empty');
- $post->rule('ord_country', 'not_empty');
- $post->rule('ord_region', 'not_empty');
- $post->rule('ord_city', 'not_empty');
- $post->rule('ord_postindex', 'not_empty');
- $post->rule('ord_typebuy', 'not_empty');
- $post->rule('ord_price', 'not_empty');
- if ($post->check())
- {
- $this->template->title = __('Готово');
- $this->template->content = View::factory('tpl/msg')
- ->set('msg', $order->add_order($post,1));
- }
- else
- {
- $this->template->title = __('Ошибка');
- $this->template->content = View::factory('tpl/msg')
- ->set('msg', Kohana::message('msg','empty_field'));
- }
- }
-
- /**
- * @param string POST строка из формы поиска
- * @return HTML вывод результата поиска
- */
- public function action_search()
- {
- $shop = Model::factory('shop');
-
- $post = Validate::factory($_POST);
- $post->rule('search_q', 'not_empty');
-
-
- if ($post->check())
- {
- $this->template->title = __('Готово');
- $this->template->content = View::factory('page/view/search')
- ->set('id', $shop->search($post))
- ->set('query', $post);
- }
- else
- {
- $this->template->title = __('Ошибка');
- $this->template->content = View::factory('tpl/msg')
- ->set('msg', Kohana::message('msg','not_search'));
- }
- }
-
- /**
- * @param int $id id заказа
- * @return HTML
- */
- public function action_order_y($id)
- {
- $order = Model::factory('order');
- $order->set_status($id, 3);
- $this->template->title = __('Подтверждено');
- $this->template->content = View::factory('tpl/msg')
- ->set('msg', Kohana::message('msg','order_add'));
- }
-
- /**
- * @param int $id id заказа
- * @return HTML
- */
- public function action_order_n($id)
- {
- $order = Model::factory('order');
- $order->set_status($id, 2);
- $this->template->title = __('Подтверждено');
- $this->template->content = View::factory('tpl/msg')
- ->set('msg', Kohana::message('msg','order_denied'));
- }
-
+<?php defined('SYSPATH')or die('No direct script access.');
+/**
+ * @author d1ffuz0r gladk0w@mail.ru
+ * @license GPLv3
+ * @copyright 2011
+ */
+class Controller_Shop extends Controller_Tpl
+ {
+
+ /**
+ * @param int $id id продукта
+ * @return HTML вывод формы для оформления заказа
+ */
+ public function action_new_order($id)
+ {
+ if (Cookie::get('loged_in')==TRUE)
+ {
+ $shop = Model::factory('shop');
+
+ $product = $shop->view_product($id);
+
+ $this->template->title = __('Оформление заказа');
+ $this->template->content = View::factory('page/shop/new_order')
+ ->set('product', $product);
+ }
+ else
+ {
+ $this->template->title = __('Ошибка');
+ $this->template->content = View::factory('tpl/msg')
+ ->set('msg',Kohana::message('msg','not_login'));
+ }
+ }
+
+ /**
+ * @param mixed POST данные из public action_new_order()
+ * @return HTML output
+ */
+ public function action_add_order()
+ {
+ $order = Model::factory('order');
+
+ $post = Validate::factory($_POST)
+ ->filter(TRUE, 'trim')
+ ->filter('ord_username', 'strtolower');
+ $post->rule('ord_id', 'not_empty');
+ $post->rule('ord_count', 'not_empty');
+ $post->rule('ord_username', 'not_empty');
+ $post->rule('ord_realname', 'not_empty');
+ $post->rule('ord_family', 'not_empty');
+ $post->rule('ord_ot4estvo', 'not_empty');
+ $post->rule('ord_email', 'not_empty');
+ $post->rule('ord_telephone', 'not_empty');
+ $post->rule('ord_country', 'not_empty');
+ $post->rule('ord_region', 'not_empty');
+ $post->rule('ord_city', 'not_empty');
+ $post->rule('ord_postindex', 'not_empty');
+ $post->rule('ord_typebuy', 'not_empty');
+ $post->rule('ord_price', 'not_empty');
+ if ($post->check())
+ {
+ $this->template->title = __('Готово');
+ $this->template->content = View::factory('tpl/msg')
+ ->set('msg', $order->add_order($post,1));
+ }
+ else
+ {
+ $this->template->title = __('Ошибка');
+ $this->template->content = View::factory('tpl/msg')
+ ->set('msg', Kohana::message('msg','empty_field'));
+ }
+ }
+
+ /**
+ * @param string POST строка из формы поиска
+ * @return HTML вывод результата поиска
+ */
+ public function action_search()
+ {
+ $shop = Model::factory('shop');
+
+ $post = Validate::factory($_POST);
+ $post->rule('search_q', 'not_empty');
+
+
+ if ($post->check())
+ {
+ $this->template->title = __('Готово');
+ $this->template->content = View::factory('page/view/search')
+ ->set('id', $shop->search($post))
+ ->set('query', $post);
+ }
+ else
+ {
+ $this->template->title = __('Ошибка');
+ $this->template->content = View::factory('tpl/msg')
+ ->set('msg', Kohana::message('msg','not_search'));
+ }
+ }
+
+ /**
+ * @param int $id id заказа
+ * @return HTML
+ */
+ public function action_order_y($id)
+ {
+ $order = Model::factory('order');
+ $order->set_status($id, 3);
+ $this->template->title = __('Подтверждено');
+ $this->template->content = View::factory('tpl/msg')
+ ->set('msg', Kohana::message('msg','order_add'));
+ }
+
+ /**
+ * @param int $id id заказа
+ * @return HTML
+ */
+ public function action_order_n($id)
+ {
+ $order = Model::factory('order');
+ $order->set_status($id, 2);
+ $this->template->title = __('Подтверждено');
+ $this->template->content = View::factory('tpl/msg')
+ ->set('msg', Kohana::message('msg','order_denied'));
+ }
+
}
View
78 application/classes/controller/tpl.php
@@ -1,40 +1,40 @@
-<?php defined('SYSPATH') or die('No direct script access.');
-/**
- * @author d1ffuz0r gladk0w@mail.ru
- * @license GPLv3
- * @copyright 2011
- */
-class Controller_Tpl extends Controller_Template
- {
-
- public $template = 'tpl/template';
-
- public function before()
- {
- parent::before();
-
- if ($this->auto_render)
- {
- $this->template->title = '';
- $this->template->content = '';
- $this->template->styles = array();
- $this->template->categories = array();
- $this->template->regions = array();
- $this->template->msg = '';
- }
- }
-
- public function after()
- {
- $main = Model::factory('Main');
- $shop = Model::factory('Shop');
-
- if ($this->auto_render)
- {
- $this->template->categories = $shop->get_category();
- $this->template->regions = $main->get_cities();
- }
- parent::after();
- }
-
+<?php defined('SYSPATH') or die('No direct script access.');
+/**
+ * @author d1ffuz0r gladk0w@mail.ru
+ * @license GPLv3
+ * @copyright 2011
+ */
+class Controller_Tpl extends Controller_Template
+ {
+
+ public $template = 'tpl/template';
+
+ public function before()
+ {
+ parent::before();
+
+ if ($this->auto_render)
+ {
+ $this->template->title = '';
+ $this->template->content = '';
+ $this->template->styles = array();
+ $this->template->categories = array();
+ $this->template->regions = array();
+ $this->template->msg = '';
+ }
+ }
+
+ public function after()
+ {
+ $main = Model::factory('Main');
+ $shop = Model::factory('Shop');
+
+ if ($this->auto_render)
+ {
+ $this->template->categories = $shop->get_category();
+ $this->template->regions = $main->get_cities();
+ }
+ parent::after();
+ }
+
}
View
122 application/classes/controller/view.php
@@ -1,61 +1,61 @@
-<?php defined('SYSPATH') or die('No direct script access.');
-/**
- * @author d1ffuz0r gladk0w@mail.ru
- * @license GPLv3
- * @copyright 2011
- */
-class Controller_View extends Controller_Tpl
- {
-
- /**
- * @param string $cat название категории
- * @return HTML выводим все товары в запрошеной категории
- */
- public function action_cat($cat)
- {
- $shop = Model::factory('shop');
- $pagination = Pagination::factory(array(
- 'current_page' => array('source' => 'query_string', 'key' => 'p'),
- 'total_items' => $shop->count_category($cat),
- 'items_per_page' => 10,
- 'view' => 'pagination/floating',
- 'auto_hide' => TRUE,
- 'first_page_in_url' => TRUE
- ));
- $page = $pagination->current_page;
- $per_page = $pagination->items_per_page;
- $offset = $per_page * ($page-1);
- $page_links = $pagination->render();
-
- $this->template->title = __('Просмотр категории');
- $this->template->content = View::factory('page/view/cat')
- ->set('id', $shop->view_category($cat,$offset))
- ->set('pagination', $page_links);
- }
-
- /**
- * @param int $id id товара
- * @return HTML выводим описание запрошеного товара
- */
- public function action_product($id)
- {
- $shop = Model::factory('shop');
-
- $this->template->title = __('Просмотр товара');
- $this->template->content = View::factory('page/view/product')
- ->set('id',$shop->view_product($id));
- }
-
- /**
- * @param string $name имя пользователя
- * @return HTML выводим информацию о пользователе
- */
- public function action_user($name)
- {
- $user = Model::factory('users');
- $this->template->title = __('Просмотр пользователя');
- $this->template->content = View::factory('page/view/user')
- ->set('desk', $user->view_user($name));
- }
- }
-
+<?php defined('SYSPATH') or die('No direct script access.');
+/**
+ * @author d1ffuz0r gladk0w@mail.ru
+ * @license GPLv3
+ * @copyright 2011
+ */
+class Controller_View extends Controller_Tpl
+ {
+
+ /**
+ * @param string $cat название категории
+ * @return HTML выводим все товары в запрошеной категории
+ */
+ public function action_cat($cat)
+ {
+ $shop = Model::factory('shop');
+ $pagination = Pagination::factory(array(
+ 'current_page' => array('source' => 'query_string', 'key' => 'p'),
+ 'total_items' => $shop->count_category($cat),
+ 'items_per_page' => 10,
+ 'view' => 'pagination/floating',
+ 'auto_hide' => TRUE,
+ 'first_page_in_url' => TRUE
+ ));
+ $page = $pagination->current_page;
+ $per_page = $pagination->items_per_page;
+ $offset = $per_page * ($page-1);
+ $page_links = $pagination->render();
+
+ $this->template->title = __('Просмотр категории');
+ $this->template->content = View::factory('page/view/cat')
+ ->set('id', $shop->view_category($cat, $offset, $per_page))
+ ->set('pagination', $page_links);
+ }
+
+ /**
+ * @param int $id id товара
+ * @return HTML выводим описание запрошеного товара
+ */
+ public function action_product($id)
+ {
+ $shop = Model::factory('shop');
+
+ $this->template->title = __('Просмотр товара');
+ $this->template->content = View::factory('page/view/product')
+ ->set('id',$shop->view_product($id));
+ }
+
+ /**
+ * @param string $name имя пользователя
+ * @return HTML выводим информацию о пользователе
+ */
+ public function action_user($name)
+ {
+ $user = Model::factory('users');
+ $this->template->title = __('Просмотр пользователя');
+ $this->template->content = View::factory('page/view/user')
+ ->set('desk', $user->view_user($name));
+ }
+ }
+
View
93 application/classes/model/admin.php
@@ -0,0 +1,93 @@
+<?php defined('SYSPATH')or die('No direct script access.');
+/**
+ * @author d1ffuz0r gladk0w@mail.ru
+ * @license GPLv3
+ * @copyright 2011
+ */
+class Model_Admin extends Model
+ {
+ /**
+ * @param $c_name
+ * @param $c_rusname
+ * @return void
+ */
+ public function add_category($c_name, $c_rusname)
+ {
+ $c_id = rand(0, 1000);
+ DB::insert('category',array('c_id','c_name','c_rusname','c_param','c_etc'))
+ ->values(array($c_id,$c_name,$c_rusname,0,0))
+ ->execute();
+ }
+
+ /**
+ * @param $id
+ * @return void
+ */
+ public function delete_category($id)
+ {
+ DB::delete('category')->where('c_id','=',$id)->execute();
+ }
+
+ /**
+ * @param $id
+ * @param $name
+ * @param $rusname
+ * @param $param
+ * @param $etc
+ * @return void
+ */
+ public function update_category($id, $name, $rusname, $param, $etc)
+ {
+ DB::update('category')
+ ->set(array(
+ 'c_name' =>$name,
+ 'c_rusname'=>$rusname,
+ 'c_param' =>$param,
+ 'c_etc' =>$etc
+ ))
+ ->where('c_id','=',$id)
+ ->execute();
+ }
+
+ /**
+ * @param $rusname
+ * @param $desc
+ * @param $price
+ * @param $category
+ * @return void
+ */
+ public function add_product($rusname, $desc, $price, $category)
+ {
+ $p_id = rand(0, 100000);
+ DB::insert('product',array('p_id','p_rusname','p_desc','p_price','p_category','p_countsell'))
+ ->values(array($p_id, $rusname, $desc, $p_id, $category, 0))
+ ->execute();
+ }
+ /**
+ * @param $id
+ * @return void
+ */
+ public function delete_product($id)
+ {
+ DB::delete('product')->where('p_id','=',$id)->execute();
+ }
+
+ /**
+ * @param $id
+ * @param $rusname
+ * @param $desc
+ * @param $price
+ * @return void
+ */
+ public function update_product($id, $rusname, $desc, $price)
+ {
+ DB::update('product')
+ ->set(array(
+ 'p_rusname'=>$rusname,
+ 'p_desc'=>$desc,
+ 'p_price'=>$price
+ ))
+ ->where('p_id','=',$id)
+ ->execute();
+ }
+ }
View
123 application/classes/model/auth.php
@@ -1,62 +1,63 @@
-<?php defined('SYSPATH')or die('No direct script access.');
-/**
- * @author d1ffuz0r gladk0w@mail.ru
- * @license GPLv3
- * @copyright 2011
- */
-class Model_Auth extends Model
- {
-
- /**
- * @param string $login логин пользователя
- * @param string $password пароль полльзователя
- * @return boolean если true то логинимся и ставим куку, если false выдаём ошибку
- */
- public function login($login, $password)
- {
- $query = DB::select()
- ->from('users')
- ->where('u_name', '=', $login)
- ->where('u_password', '=', $password)
- ->execute();
- if ($query->count()>=1)
- {
- Cookie::set('loged_in', TRUE);
- Cookie::set('username', $login);
-
- return Kohana::message('msg','auth_success');
- }
- else
- {
- return Kohana::message('msg','auth_error');
- }
- }
-
- /**
- * @param string $login логин пользователя
- * @param string $password пароль полльзователя
- * @param string $email email пользователя
- * @return mixed если пользователь с таким логином существует то выдаём ошибку,если нет то регистрируем. ранг по умолчанию 3(пользователь)
- */
- public function register($login, $password, $email)
- {
- $query = DB::select()
- ->from('users')
- ->where('u_name', '=', $login)
- ->execute();
- if ($query->count()>=1)
- {
- return Kohana::message('msg', 'reg_error');
- }
- else
- {
- DB::insert('users', array('u_name', 'u_password', 'u_email', 'u_data', 'u_allprice', 'u_rang'))
- ->values(array($login, $password, $email, 'etc.', 0, 3))
- ->execute();
- Cookie::set('loged_in', TRUE);
- Cookie::set('username', $login);
- return 'Добро пожаловать! Вы зарегистрированы.<br>Логин:' . $login . '<br>Пароль:' . $password;
- }
- }
-
+<?php defined('SYSPATH')or die('No direct script access.');
+/**
+ * @author d1ffuz0r gladk0w@mail.ru
+ * @license GPLv3
+ * @copyright 2011
+ */
+class Model_Auth extends Model
+ {
+
+ /**
+ * @param string $login логин пользователя
+ * @param string $password пароль полльзователя
+ * @return boolean если true то логинимся и ставим куку, если false выдаём ошибку
+ */
+ public function login($login, $password)
+ {
+ $query = DB::select()
+ ->from('users')
+ ->where('u_name', '=', $login)
+ ->where('u_password', '=', $password)
+ ->execute();
+ if ($query->count()>=1)
+ {
+ Cookie::set('loged_in', TRUE);
+ Cookie::set('username', $login);
+
+ return Kohana::message('msg','auth_success');
+ }
+ else
+ {
+ return Kohana::message('msg','auth_error');
+ }
+ }
+
+ /**
+ * @param string $login логин пользователя
+ * @param string $password пароль полльзователя
+ * @param string $email email пользователя
+ * @return string если пользователь с таким логином существует то выдаём ошибку,если нет то регистрируем. ранг по умолчанию 3(пользователь)
+ */
+ public function register($login, $password, $email)
+ {
+ $query = DB::select()
+ ->from('users')
+ ->where('u_name', '=', $login)
+ ->execute();
+ if ($query->count()>=1)
+ {
+ return Kohana::message('msg', 'reg_error');
+ }
+ else
+ {
+ DB::insert('users', array('u_name', 'u_password', 'u_email', 'u_data', 'u_allprice', 'u_rang'))
+ ->values(array($login, $password, $email, 'etc.', 0, 3))
+ ->execute();
+ Cookie::set('loged_in', TRUE);
+ Cookie::set('username', $login);
+
+ return 'Добро пожаловать! Вы зарегистрированы.<br>Логин:' . $login . '<br>Пароль:' . $password;
+ }
+ }
+
}
View
224 application/classes/model/order.php
@@ -1,113 +1,113 @@
-<?php defined('SYSPATH') or die('No direct script access.');
-/**
- * @author d1ffuz0r gladk0w@mail.ru
- * @license GPLv3
- * @copyright 2011
- */
-class Model_Order extends Model
- {
- /**
- * заказы пользователя
- * @var array
- */
- private $_orders;
-
- /**
- * просмотр заказов выбраного статуса
- * @param string $status статус заказа
- * @return array заказы выбраного статуса.
- * @tutorial 1 - в ожидании, 2 - отказано , 3 - принято
- */
- public function view_order_s($status)
- {
- $this->_orders = DB::select()
- ->from('orders')
- ->where('ord_status', '=', $status)
- ->as_object()
- ->execute();
- return $this->_orders;
- }
-
- /**
- * просмотр заказов пользователем
- * @param string $username имя пользователя
- * @return array заказы 1 пользователя
- */
- public function view_orders($username)
- {
- $this->_orders = DB::select()
- ->from('orders')
- ->where('ord_username', '=', $username)
- ->where('ord_status', '=', 1)
- ->or_where('ord_status', '=', 2)
- ->as_object()
- ->execute();
- return $this->_orders;
- }
-
- /**
- * оформление заказа
- * @param mixed $array массив данных из формы заказа
- * @return string добавление заказа
- * @todo реализовать увеличение счётчика покупок у пользователя при совершении покупки
- */
- public function add_order($array,$status)
- {
- $price = $array['ord_count']*$array['ord_price'];
- $date = date("d.m.y");
- $id = rand(0, 100000);
- $query = DB::insert('orders', array(
- 'ord_id',
- 'ord_username',
- 'ord_product',
- 'ord_realname',
- 'ord_family',
- 'ord_ot4estvo',
- 'ord_email',
- 'ord_telephone',
- 'ord_country',
- 'ord_region',
- 'ord_city',
- 'ord_postindex',
- 'ord_typebuy',
- 'ord_count',
- 'ord_status',
- 'ord_date',
- 'ord_price'
- ))->values(array(
- $id,
- $array['ord_username'],
- $array['ord_id'],
- $array['ord_realname'],
- $array['ord_family'],
- $array['ord_ot4estvo'],
- $array['ord_email'],
- $array['ord_telephone'],
- $array['ord_country'],
- $array['ord_region'],
- $array['ord_city'],
- $array['ord_postindex'],
- $array['ord_typebuy'],
- $array['ord_count'],
- $status,
- $date,
- $price
- ))
- ->execute();
- return Kohana::message('msg','order_add');
- }
-
- /**
- * установка статуса заказа
- * @param int $id id заказа
- * @param int $status статус. 1- в ожидании, 2 - отказано , 3 принято
- */
- public function set_status($id, $status)
- {
- DB::update('orders')
- ->set(array('ord_status' => $status))
- ->where('ord_id', '=', $id)
- ->execute();
- }
-
+<?php defined('SYSPATH') or die('No direct script access.');
+/**
+ * @author d1ffuz0r gladk0w@mail.ru
+ * @license GPLv3
+ * @copyright 2011
+ */
+class Model_Order extends Model
+ {
+ /**
+ * заказы пользователя
+ * @var array
+ */
+ private $_orders;
+
+ /**
+ * просмотр заказов выбраного статуса
+ * @param string $status статус заказа
+ * @return array заказы выбраного статуса.
+ * @tutorial 1 - в ожидании, 2 - отказано , 3 - принято
+ */
+ public function view_order_s($status)
+ {
+ $this->_orders = DB::select()
+ ->from('orders')
+ ->where('ord_status', '=', $status)
+ ->as_object()
+ ->execute();
+ return $this->_orders;
+ }
+
+ /**
+ * просмотр заказов пользователем
+ * @param string $username имя пользователя
+ * @return array заказы 1 пользователя
+ */
+ public function view_orders($username)
+ {
+ $this->_orders = DB::select()
+ ->from('orders')
+ ->where('ord_username', '=', $username)
+ ->where('ord_status', '=', 1)
+ ->or_where('ord_status', '=', 2)
+ ->as_object()
+ ->execute();
+ return $this->_orders;
+ }
+
+ /**
+ * оформление заказа
+ * @param mixed $array массив данных из формы заказа
+ * @return string добавление заказа
+ * @todo реализовать увеличение счётчика покупок у пользователя при совершении покупки
+ */
+ public function add_order($array,$status)
+ {
+ $price = $array['ord_count']*$array['ord_price'];
+ $date = date("d.m.y");
+ $id = rand(0, 100000);
+ $query = DB::insert('orders', array(
+ 'ord_id',
+ 'ord_username',
+ 'ord_product',
+ 'ord_realname',
+ 'ord_family',
+ 'ord_ot4estvo',
+ 'ord_email',
+ 'ord_telephone',
+ 'ord_country',
+ 'ord_region',
+ 'ord_city',
+ 'ord_postindex',
+ 'ord_typebuy',
+ 'ord_count',
+ 'ord_status',
+ 'ord_date',
+ 'ord_price'
+ ))->values(array(
+ $id,
+ $array['ord_username'],
+ $array['ord_id'],
+ $array['ord_realname'],
+ $array['ord_family'],
+ $array['ord_ot4estvo'],
+ $array['ord_email'],
+ $array['ord_telephone'],
+ $array['ord_country'],
+ $array['ord_region'],
+ $array['ord_city'],
+ $array['ord_postindex'],
+ $array['ord_typebuy'],
+ $array['ord_count'],
+ $status,
+ $date,
+ $price
+ ))
+ ->execute();
+ return Kohana::message('msg','order_add');
+ }
+
+ /**
+ * установка статуса заказа
+ * @param int $id id заказа
+ * @param int $status статус. 1- в ожидании, 2 - отказано , 3 принято
+ */
+ public function set_status($id, $status)
+ {
+ DB::update('orders')
+ ->set(array('ord_status' => $status))
+ ->where('ord_id', '=', $id)
+ ->execute();
+ }
+
}
View
329 application/classes/model/shop.php
@@ -1,152 +1,179 @@
-<?php defined('SYSPATH')or die('No direct script access.');
-/**
- * @author d1ffuz0r gladk0w@mail.ru
- * @license GPLv3
- * @copyright 2011
- */
-class Model_Shop extends Model
- {
- /**
- * список категорий товаров
- * @var array
- */
- private $_category;
-
- /**
- * количество товаров в категории
- * @var int
- */
- private $_count;
-
- /**
- * товары в категории
- * @var array
- */
- private $_cat_product;
-
- /**
- * описание товара
- * @var array
- */
- private $_product;
-
- /**
- * сделаные покупки
- * @var array
- */
- private $_kart;
-
- /**
- * найденые товары
- * @var array
- */
- private $_search;
-
- /**
- * @return array массив категорий
- */
- public function get_category()
- {
- $this->_category = DB::select()
- ->from('category')
- ->as_object()
- ->execute();
- return $this->_category;
- }
-
- /**
- * @param int $cat id категории
- * @return int количество строк в категории = id
- */
- public function count_category($cat)
- {
- $this->_count = DB::select()
- ->from('product')->where('p_category', '=', $cat)
- ->execute()
- ->count();
- return $this->_count;
- }
-
- /**
- * @param int $cat - id категории
- * @param int $offset - номер страницы для постраничного вывода
- * @return array массив продуктов в категории
- */
- public function view_category($cat, $offset)
- {
- $_sql = 'SELECT product.*, (product.p_price+((product.p_price*n_nds.n_value)/100)) AS p_ndsprice, product.p_price/k_kurs.k_value AS p_kursprice
- from product
- join (
- select value as n_value
- from nds
- ) as n_nds
- join (
- select value as k_value
- from kurs
- ) as k_kurs
- where p_category = "' . $cat . '"
- limit 10
- offset ' . $offset . '';
-
- $this->_cat_product = DB::query(Database::SELECT, $_sql)
- ->as_object()
- ->execute();
-
- return $this->_cat_product;
- }
-
- /**
- * @param int $id id продукта
- * @return array информация 1 продукта
- */
- public function view_product($id)
- {
- $_sql = 'SELECT product.*, (product.p_price+((product.p_price*n_nds.n_value)/100)) AS p_ndsprice, product.p_price/k_kurs.k_value AS p_kursprice
- from product
- join (
- select value as n_value
- from nds
- ) as n_nds
- join (
- select value as k_value
- from kurs
- ) as k_kurs
- where p_id = "' . $id . '"';
- $this->_product = DB::query(Database::SELECT, $_sql)
- ->as_object()
- ->execute();
-
- return $this->_product;
- }
-
- /**
- * @param string $username имя пользователя
- * @return array заказы выбраного пользователя
- */
- public function view_kart($username)
- {
- $this->_kart = DB::select()
- ->from('orders')
- ->where('ord_username', '=', $username)
- ->where('ord_status', '=', 3)
- ->as_object()
- ->execute();
- return $this->_kart;
- }
-
- /**
- * @param string $searchQuery POST данные из формы
- * @return array найденые товары
- */
- public function search($searchQuery)
- {
- $this->_search = DB::select()
- ->from('product')
- ->where('p_desc', 'like', '%' . $searchQuery['search_q'] . '%')
- ->or_where('p_rusname', 'like', '%' . $searchQuery['search_q'] . '%')
- ->as_object()
- ->execute();
- return $this->_search;
- }
-
+<?php defined('SYSPATH')or die('No direct script access.');
+/**
+ * @author d1ffuz0r gladk0w@mail.ru
+ * @license GPLv3
+ * @copyright 2011
+ */
+class Model_Shop extends Model
+ {
+ /**
+ * список категорий товаров
+ * @var array
+ */
+ private $_category;
+
+ /**
+ * количество товаров в категории
+ * @var int
+ */
+ private $_count;
+
+ /**
+ * товары в категории
+ * @var array
+ */
+ private $_cat_product;
+
+ /**
+ * описание товара
+ * @var array
+ */
+ private $_product;
+
+ /**
+ * сделаные покупки
+ * @var array
+ */
+ private $_kart;
+
+ /**
+ * найденые товары
+ * @var array
+ */
+ private $_search;
+
+ /**
+ * @return array массив категорий
+ */
+ public function get_category()
+ {
+ $this->_category = DB::select()
+ ->from('category')
+ ->as_object()
+ ->execute();
+ return $this->_category;
+ }
+
+ /**
+ * @param int $cat id категории
+ * @return int количество строк в категории = id
+ */
+ public function count_category($cat)
+ {
+ $this->_count = DB::select()
+ ->from('product')->where('p_category', '=', $cat)
+ ->execute()
+ ->count();
+ return $this->_count;
+ }
+
+ /**
+ * @param int $cat - id категории
+ * @param int $offset - номер страницы для постраничного вывода
+ * @return array массив продуктов в категории
+ */
+ public function view_category($cat, $offset, $limit)
+ {
+ $_sql = 'SELECT product.*, (product.p_price+((product.p_price*n_nds.n_value)/100)) AS p_ndsprice, product.p_price/k_kurs.k_value AS p_kursprice
+ from product
+ join (
+ select value as n_value
+ from nds
+ ) as n_nds
+ join (
+ select value as k_value
+ from kurs
+ ) as k_kurs
+ where p_category = "' . $cat . '"
+ limit ' . $limit . '
+ offset ' . $offset . '';
+
+ $this->_cat_product = DB::query(Database::SELECT, $_sql)
+ ->as_object()
+ ->execute();
+
+ return $this->_cat_product;
+ }
+
+ /**
+ * @param int $id id продукта
+ * @return array информация 1 продукта
+ */
+ public function view_product($id)
+ {
+ $_sql = 'SELECT product.*, (product.p_price+((product.p_price*n_nds.n_value)/100)) AS p_ndsprice, product.p_price/k_kurs.k_value AS p_kursprice
+ from product
+ join (
+ select value as n_value
+ from nds
+ ) as n_nds
+ join (
+ select value as k_value
+ from kurs
+ ) as k_kurs
+ where p_id = "' . $id . '"';
+ $this->_product = DB::query(Database::SELECT, $_sql)
+ ->as_object()
+ ->execute();
+
+ return $this->_product;
+ }
+
+ /**
+ * @param string $username имя пользователя
+ * @return array заказы выбраного пользователя
+ */
+ public function view_kart($username)
+ {
+ $this->_kart = DB::select()
+ ->from('orders')
+ ->where('ord_username', '=', $username)
+ ->where('ord_status', '=', 3)
+ ->as_object()
+ ->execute();
+ return $this->_kart;
+ }
+
+ /**
+ * @param string $searchQueryPOST данные из формы
+ * @return array
+ */
+ public function search($searchQuery)
+ {
+ $this->_search = DB::select()
+ ->from('product')
+ ->where('p_desc', 'like', '%' . $searchQuery['search_q'] . '%')
+ ->or_where('p_rusname', 'like', '%' . $searchQuery['search_q'] . '%')
+ ->as_object()
+ ->execute();
+ return $this->_search;
+ }
+ /**
+ * @param $id
+ * @return Database_Result|object
+ */
+ public function get_one_category($id)
+ {
+ $one_category = DB::select()
+ ->from('category')
+ ->where('c_id', '=', $id)
+ ->as_object()
+ ->execute();
+ return $one_category;
+ }
+
+ /**
+ * @param $id
+ * @return Database_Result|object
+ */
+ public function get_one_product($id)
+ {
+ $one_product = DB::select()
+ ->from('product')
+ ->where('p_id', '=', $id)
+ ->as_object()