private function _setLanguage()
 {
     $session_lang = $this->Session->read('lang') ? $this->Session->read('lang') : null;
     if ($session_lang == null) {
         $session_lang = Configure::read('DEF_LANG');
         Configure::load('rus_config');
     } else {
         if (!in_array($session_lang, Configure::read('VALID_LANGS'))) {
             $session_lang = Configure::read('DEF_LANG');
             Configure::load('rus_config');
         }
     }
     $this->Session->write('lang', $session_lang);
     $c = 0;
     foreach (Configure::read('VALID_LANGS') as $lang) {
         if ($lang == $session_lang) {
             $key = $c;
         }
         $c++;
     }
     $locale = Configure::read('VALID_LANG_LOCALES')[$key];
     //запись в конфиг локали
     Configure::write('Config.language', $locale);
     Configure::load($locale . '_config');
     $this->Session->write('lang_locale', $locale);
     $lang_prefix = 'name_' . lang_prefix();
     $this->set('lang_prefix', $lang_prefix);
 }
 public function show_category()
 {
     $url_prefix = $this->params->id;
     if (empty($url_prefix)) {
         $this->redirect(array('controller' => 'showerror', 'action' => '/'));
         exit;
     }
     $category = $this->BlogCategory->find('all', array('conditions' => array('BlogCategory.status' => 'active', 'BlogCategory.url_prefix' => $url_prefix)));
     if (count($category) == 0) {
         $this->redirect(array('controller' => 'showerror', 'action' => '/'));
         exit;
     }
     $category = $category[0]['BlogCategory'];
     $category_id = $category['id'];
     $category_name_ru = $category['name_ru'];
     $category_name_en = $category['name_en'];
     $category_name_kz = $category['name_kz'];
     $lang = "name_" . lang_prefix();
     $category_name = $category[$lang];
     $this->set('title', Configure::read('SITENAME') . " - " . L('BLOG') . " - " . $category_name);
     $this->Breadcrumbs->add('Блог', Router::url(array('plugin' => false, 'controller' => 'blog', 'action' => 'index')));
     $this->Breadcrumbs->add($category_name, Router::url(array('plugin' => false, 'controller' => 'blog', 'action' => 'show_category', 'id' => $url_prefix)));
     //список последних тем
     $articles = $this->BlogArticle->find('all', array('conditions' => array('BlogArticle.user_view_status' => 'active', 'BlogArticle.admin_view_status' => 'active', 'BlogArticle.category_id' => $category_id), 'joins' => array(array('table' => 'users', 'alias' => 'User', 'type' => 'LEFT', 'conditions' => array('BlogArticle.author_id = User.id')), array('table' => 'admins', 'alias' => 'Admin', 'type' => 'LEFT', 'conditions' => array('BlogArticle.author_id = Admin.id'))), 'fields' => array('BlogArticle.*', 'User.*', 'Admin.*'), array('order' => 'BlogArticle.id DESC')));
     foreach ($articles as &$article) {
         $a_id = $article['BlogArticle']['id'];
         $comments = $this->BlogArticleComment->find('count', array('conditions' => array('user_view_status' => 'view', 'article_id' => $a_id)));
         $c_count = $comments;
         $article['BlogArticle']['c_count'] = $comments;
     }
     $this->set('articles', $articles);
     //правая колонка
     $this->right_column();
 }
 public function view_offer()
 {
     //проверка вакансии;
     $name = 'name_' . lang_prefix();
     $offer_prefix = $this->request->params['offer'];
     $offer = $this->Contents->find('first', array('conditions' => array('url_prefix' => $offer_prefix, 'content_type' => 'offers')));
     if ($offer == null or $offer['Contents']['status'] == 0) {
         $this->redirect(array('controller' => 'showerror', 'action' => '/'));
         exit;
     } else {
         $this->Breadcrumbs->add($offer['Contents'][$name], Router::url(array('plugin' => false, 'controller' => Configure::read('SERVICE_URL_PREFIX'), 'action' => $offer['Contents']['url_prefix'])));
         $this->set('title', L("OFFER") . " -  " . $offer['Contents'][$name]);
         $this->set('offer', $offer);
     }
 }
 public function show_new()
 {
     $this->Breadcrumbs->add(L('NEWS'), Router::url(array('plugin' => false, 'controller' => 'news', 'action' => 'index')));
     $document_prefix = $this->request->params['id'];
     $document = $this->Contents->find('first', array('conditions' => array('url_prefix' => $document_prefix, 'content_type' => 'news', 'status' => 'active')));
     if ($document == null) {
         $this->redirect(array('controller' => 'showerror', 'action' => '/'));
         exit;
     } else {
         $this->Breadcrumbs->add($document['Contents']['name_ru'], Router::url(array('plugin' => false, 'controller' => 'news', 'action' => $document['Contents']['url_prefix'])));
         $this->set('document', $document);
         $name = 'name_' . lang_prefix();
         $this->set('title', "Новости -  " . $document['Contents'][$name]);
     }
 }
 public function view_content()
 {
     $this->Breadcrumbs->add(L('MATERIALS'), Router::url(array('plugin' => false, 'controller' => 'document', 'action' => 'index')));
     $document_prefix = $this->request->params['url_prefix'];
     $document = $this->Contents->find('first', array('conditions' => array('url_prefix' => $document_prefix, 'content_type' => 'documents', 'status' => 'active')));
     if ($document == null) {
         $this->redirect(array('controller' => 'showerror', 'action' => '/'));
         exit;
     } else {
         $name = 'name_' . lang_prefix();
         $this->Breadcrumbs->add($document['Contents'][$name], Router::url(array('plugin' => false, 'controller' => Configure::read('DOCUMENT_URL_PREFIX'), 'action' => $document['Contents']['url_prefix'])));
         $this->set('document', $document);
         $this->set('title', L('MATERIALS') . " -  " . $document['Contents'][$name]);
     }
 }
Esempio n. 6
0
 public function search_ajax()
 {
     $string = $this->params->query['string'];
     $res = array();
     if (empty($string)) {
         $this->Error->setError('ERROR_251');
         return false;
     } else {
         //поиск по услугам
         $name = 'name_' . lang_prefix();
         $service_result = $this->Service->find('all', array('conditions' => array('OR' => array('name_ru LIKE' => '%' . $string . '%', 'name_en LIKE' => '%' . $string . '%', 'name_kz LIKE' => '%' . $string . '%'))));
         if (count($service_result) > 0) {
             foreach ($service_result as $result) {
                 $category = $this->Categories->find('first', array('conditions' => array('id' => $result['Service']['main_category_id'])));
                 if (count($category) > 0) {
                     //pr($category);
                     $category_prefix = $category['Categories']['url_prefix'];
                     $res['elem'][] = array('name' => $result['Service'][$name], 'link' => site_url() . "/" . Configure::read('SERVICE_URL_PREFIX') . "/" . $category_prefix . "/" . $result['Service']['url_prefix'], 'type' => 'service');
                 }
             }
         }
         //поиск по категориям услуг
         $name = 'name_' . lang_prefix();
         $category_result = $this->Categories->find('all', array('conditions' => array('OR' => array('name_ru LIKE' => '%' . $string . '%', 'name_en LIKE' => '%' . $string . '%', 'name_kz LIKE' => '%' . $string . '%'))));
         if ($category_result !== null) {
             foreach ($category_result as $result) {
                 $res['elem'][] = array('name' => $result['Categories'][$name], 'link' => site_url() . "/" . Configure::read('SERVICE_URL_PREFIX') . "/" . $result['Categories']['url_prefix'], 'type' => 'category');
             }
         }
         $user_result = $this->Master->find('all', array('conditions' => array('OR' => array('Master.lastname LIKE' => '%' . $string . '%', 'Master.firstname LIKE' => '%' . $string . '%'))));
         if (count($user_result) > 0) {
             foreach ($user_result as &$result) {
                 $res['elem'][] = array('name' => prepare_fio($result['Master']['firstname'], $result['Master']['lastname'], $result['Master']['fathername']), 'link' => site_url() . "/profile/" . $result['Master']['login'] . "/", 'type' => 'master');
             }
         }
         $response = array();
         if ($result !== null) {
             $response["result"] = "success";
             $response["query_data"] = $res;
             response_ajax($response, "success");
         } else {
             $response["result"] = "error";
             response_ajax($response, "error");
         }
         exit;
     }
 }
Esempio n. 7
0
 public function step_2()
 {
     $this->Breadcrumbs->add(L('REGISTER_STEP_2'), Router::url(array('plugin' => false, 'controller' => 'register', 'action' => 'step_2')));
     $this->title_name = L('REGISTRATION') . " " . L('REGISTER_STEP_2');
     $this->set('title', Configure::read('SITENAME') . " - " . $this->title_name);
     $this->set('x', $this->Session->read('step_1_data'));
     $city_id = $this->Session->read('step_1_data')['User']['city_id'];
     $this->set('city_id', $city_id);
     $this->loadModel('Paytype');
     $this->Paytype->useTable = 'service_pay_types';
     $service_pay_types = $this->Paytype->find('all');
     $this->set('service_pay_types', $service_pay_types);
     $name = 'name_' . lang_prefix();
     $regions = $this->Regions->find('all', array('conditions' => array('city_id' => $city_id), 'order' => $name . ' ASC'));
     $this->set('regions', $regions);
     $this->render('step_2');
 }
Esempio n. 8
0
 *		array('callable' => $anotherMethod, 'on' => 'after'), // A valid PHP callback type to be called on afterDispatch
 *
 * ));
 */
Configure::write('Dispatcher.filters', array('AssetDispatcher', 'CacheDispatcher'));
/**
 * Configures default file logging options
 */
App::uses('CakeLog', 'Log');
CakeLog::config('debug', array('engine' => 'File', 'types' => array('notice', 'info', 'debug'), 'file' => 'debug'));
CakeLog::config('error', array('engine' => 'File', 'types' => array('warning', 'error', 'critical', 'alert', 'emergency'), 'file' => 'error'));
//загрузка конфига языковой статики
Configure::load('lang_config');
//загрузка общего конфига
Configure::load('main_config');
//загрузка конфига и констант ошибок
Configure::load('error_config');
//Загрузка класса Компонент Auth
App::uses('AuthComponent', 'Controller/Component');
App::build(array('Lib' => array(APP . 'Lib' . DS)));
App::build(array('CONF' => array(APP . 'Config' . DS)));
App::build(array('ADMIN' => array(APP . 'Controller' . DS . 'Admin' . DS)));
//подключение файла с функциями
require_once APP . 'Lib/functions.php';
require_once APP . 'Lib/ip/ip.php';
$lang_prefix = lang_prefix();
$lang_file = 'CONF/' . $lang_prefix . 'config.php';
if (file_exists($lang_file)) {
    require_once APP . $lang_file;
}
Configure::write('lang', 'kaz');
Esempio n. 9
0
 public function api_get_regions_by_city()
 {
     $city_id = $this->request->params['city_id'];
     if (!is_numeric($city_id)) {
         response_ajax(array('error' => 'false city_id'), "error");
         exit;
     }
     $this->loadModel('Cities');
     $city_check = $this->Cities->find('count', array('conditions' => array('id' => $city_id)));
     if ($city_check == 0) {
         response_ajax(array('error' => 'city_not_found'), "error");
         exit;
     }
     $this->loadModel('Regions');
     //если передан $country_id = 0 возвращается список всех городов
     $region_data = $this->Regions->find('all', array('conditions' => array('city_id' => $city_id)));
     $data = array();
     $lang_prefix = 'name_' . lang_prefix();
     if (count($region_data) > 0) {
         foreach ($region_data as $region) {
             $data[] = array('id' => $region['Regions']['id'], 'region_name' => $region['Regions'][$lang_prefix]);
         }
         response_ajax($data, "success");
     } else {
         $data = array("region", '');
         response_ajax($data, "success");
     }
     exit;
 }
 public function view_ticket()
 {
     $this->Breadcrumbs->add(L('TICKETS_AND_SUPPORT'), Router::url(array('plugin' => false, 'controller' => 'backoffice', 'action' => 'tickets')));
     $id = $this->request->params['id'];
     if (!is_numeric($id)) {
         $this->redirect(array('controller' => 'showerror', 'action' => '/'));
         exit;
     }
     $this->loadModel('MessageTypes');
     $this->loadModel('Message');
     $user_tickets = $this->Ticket->find('all', array('conditions' => array('user_id' => $this->user_data["User"]["id"], 'id' => $id)));
     $user_tickets_count = $this->Ticket->find('count', array('conditions' => array('user_id' => $this->user_data["User"]["id"])));
     $lang_prefix = 'name_' . lang_prefix();
     foreach ($user_tickets as &$ticket) {
         $message_type_id = $ticket['Ticket']['message_type'];
         $ticket_id = $ticket['Ticket']['id'];
         $message_type_name = $this->MessageTypes->find('all', array('conditions' => array('id' => $message_type_id)));
         $ticket['message_type_name'] = $message_type_name[0]['MessageTypes'][$lang_prefix];
         $ticket['last_message'] = $this->Message->find('first', array('conditions' => array('ticket_id' => $ticket_id)));
     }
     $this->set('user_tickets', $user_tickets);
     $this->set('user_tickets_count', $user_tickets_count);
     //проверка существования и владения пользователем переданного тикета
     $ticket_data = $this->Ticket->find('all', array('conditions' => array('user_id' => $this->user_data["User"]["id"], 'id' => $id), 'limit' => '1'));
     if (count($ticket_data) == 0) {
         $this->redirect($this->referer());
         exit;
     }
     $ticket_name = $ticket_data[0]['Ticket']['name'];
     $this->Breadcrumbs->add($ticket_name, Router::url(array('plugin' => false, 'controller' => 'backoffice', 'action' => 'view_ticket', 'id' => $id)));
     //загрузка сообщений тикета
     $ticket_messages = $this->Message->find('all', array('conditions' => array('ticket_id' => $id), 'order' => 'created DESC'));
     $lang_prefix = 'name_' . lang_prefix();
     $this->set('ticket_data', $ticket_data);
     $this->set('ticket_messages', $ticket_messages);
 }
Esempio n. 11
0
 public function edit_order()
 {
     $id = $this->request->query['id'];
     if (!is_numeric($id)) {
         $this->redirect(array('controller' => 'showerror', 'action' => '/'));
         exit;
     }
     $this->admin_path_title_name = "Управление заявками - редактирование";
     $this->set('title', Configure::read('SITENAME') . " - " . Configure::read('ADMIN_PANEL') . " - " . $this->admin_path_title_name);
     $order_data = $this->Order->find('first', array('conditions' => array('id' => $id)));
     if ($order_data !== null) {
         $lang_prefix = 'name_' . lang_prefix();
         foreach ($order_data as &$order) {
             //pr($order);
             if ($order['category_id'] != 0) {
                 $category = $this->Categories->find('first', array('conditions' => array('id' => $order['category_id'])));
                 $order['category_name'] = $category['Categories'][$lang_prefix];
             } else {
                 $order['category_name'] = "Не определена";
             }
             if ($order['category_id'] > 0) {
                 $service_in_cat = $this->Service->find('all', array('conditions' => array('category_id' => $order['category_id']), array('order' => $lang_prefix . ' ASC')));
             }
             if ($order['service_id'] != 0) {
                 $service = $this->Service->find('first', array('conditions' => array('id' => $order['service_id'])));
                 $order['service_name'] = $service['Service'][$lang_prefix];
             } else {
                 $order['service_name'] = "Не определена";
             }
             //выборка стран
             $countries = $this->Countries->find('all', array('order' => 'id ASC'));
             $this->set('countries', $countries);
             $country_id = $order['country_id'];
             if ($country_id > 0) {
                 //выборка городов если указана страна
                 $cities = $this->Cities->find('all', array('conditions' => array('country_id' => $country_id), 'order' => 'id ASC'));
                 $this->set('cities', $cities);
             } else {
                 $cities = null;
                 $this->set('cities', $cities);
             }
         }
         $this->Breadcrumbs->add("Редактирование заявки №" . $order_data['Order']['id'], '');
         $this->set('order_data', $order_data);
         //список категорий
         $categories = $this->Categories->find('all', array('order' => $lang_prefix . ' ASC'));
         $this->set('categories', $categories);
         //список услуг в категории
         $this->set('services', $service_in_cat);
         //вывод типов оплаты для управления стоимостью заявки
         $this->loadModel('Paytype');
         $this->Paytype->useTable = 'service_pay_types';
         $service_pay_types = $this->Paytype->find('all');
         $this->set('service_pay_types', $service_pay_types);
     } else {
         $this->redirect(array('controller' => 'showerror', 'action' => '/'));
     }
 }
Esempio n. 12
0
 public function index()
 {
     $this->title_name = L("MASTER_PROFILE");
     $this->set('title', Configure::read('SITENAME') . " - " . $this->title_name);
     $profile_url_prefix = $this->request->params['profile'];
     $name = 'name_' . lang_prefix();
     $user = $this->Master->find('first', array('conditions' => array('login' => $profile_url_prefix, 'mail_checked' => 1, 'account_status' => 'active'), 'fields' => array('Master.*', 'UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(created) AS reg_time', 'UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(last_activity) AS last_act')));
     // если профиль существует
     if (count($user) > 0) {
         $user_id = $user['Master']['id'];
         //добавление записи в Profile_views
         $referrer = $_SERVER['HTTP_REFERER'];
         if (isset($referrer)) {
             $ip = $_SERVER['REMOTE_ADDR'];
             $referers = Configure::read('VALID_REFERERS');
             $real_ref = parse_url($referrer)['host'];
             $referrer = Configure::read('UNKNOWN_REFERRER_ID');
             foreach ($referers as $key => $value) {
                 if ($key == $real_ref) {
                     $referrer = $value;
                 }
             }
             $data_for_save = array('user_id' => $user_id, 'ip' => $ip, 'referrer_id' => $referrer);
             $this->ProfileView->save($data_for_save);
         }
         $this->Breadcrumbs->add(prepare_fio($user['Master']['lastname'], $user['Master']['firstname'], $user['Master']['fathername']), Router::url(array('plugin' => false, 'controller' => 'profile', 'action' => $profile_url_prefix)));
         //город мастера
         $city_id = $user['Master']['city_id'];
         $this->loadModel('Cities');
         $master_city = $this->Cities->find('first', array('conditions' => array('id' => $city_id)));
         $user['city'] = $master_city['Cities'][$name];
         $this->loadModel('Servicetouser');
         $this->Servicetouser->useTable = 'service_to_users';
         $master_services = $this->Servicetouser->find('all', array('conditions' => array('user_id' => $user_id)));
         $services = array();
         $this->loadModel('Service');
         $this->Service->useTable = 'services';
         foreach ($master_services as $ms) {
             $s_id = $ms['Servicetouser']['service_id'];
             $services[] = $this->Service->find('first', array('conditions' => array('id' => $s_id)));
         }
         //прайс
         $this->loadModel('Userprices');
         $this->Userprices->useTable = 'user_prices';
         $user_prices = $this->Userprices->find('all', array('conditions' => array('user_id' => $user_id), 'joins' => array(array('table' => 'service_pay_types', 'alias' => 'Paytype', 'type' => 'INNER', 'conditions' => array('Paytype.id = Userprices.pay_type_id'))), 'fields' => array('Paytype.*', 'Userprices.*')));
         $user_to_region_guest = $this->UserToRegionGuest->find('all', array('joins' => array(array('table' => 'regions', 'alias' => 'Region', 'type' => 'INNER', 'conditions' => array('Region.id = UserToRegionGuest.region_id'))), 'fields' => array('UserToRegionGuest.*', 'Region.*'), 'conditions' => array('UserToRegionGuest.user_id' => $user_id)));
         $user_to_region_place = $this->UserToRegionPlace->find('all', array('joins' => array(array('table' => 'regions', 'alias' => 'Region', 'type' => 'INNER', 'conditions' => array('Region.id = UserToRegionPlace.region_id'))), 'fields' => array('UserToRegionPlace.*', 'Region.*'), 'conditions' => array('UserToRegionPlace.user_id' => $user_id)));
         $user['services'] = $services;
         $user['prices'] = $user_prices;
         $user['region_place'] = $user_to_region_place;
         $user['region_guest'] = $user_to_region_guest;
         //файлы мастера
         $user_files = $this->Files->find('all', array('conditions' => array('owner_id' => $user_id, 'owner_type' => 'user', 'public_status' => 'public', 'admin_check' => 'active', 'view_status' => 'active'), 'order' => 'type ASC, created DESC'));
         $user['user_files'] = $user_files;
         //расписание мастера
         $timeslots = array();
         $days_count = 15;
         $dates_array = array();
         $now_date = date('Y-M-d');
         for ($d = 0; $d < $days_count; $d++) {
             if ($d > 1) {
                 $day_text = "days";
             } else {
                 $day_text = "day";
             }
             $PREFIX = "+" . $d . " " . $day_text;
             $ts = strtotime($PREFIX, strtotime($now_date));
             $dates_array[] = date('Y-m-d', $ts);
         }
         foreach ($dates_array as $day) {
             $timeslots[$day] = $this->Timeslot->find('all', array('conditions' => array('date' => $day, 'user_id' => $user_id), 'order' => array('start_hour ASC, start_minute ASC')));
         }
         $user['timeslots'] = $timeslots;
         //видео мастера
         $videos = $this->Video->find('all', array('conditions' => array('owner_id' => $user_id, 'owner_type' => 'user', 'view_status' => 'active'), 'order' => 'created DESC'));
         $this->set('master', $user);
         $this->set('user_id', $user_id);
         //отзывы
         $f_count = array();
         $max_c = 0;
         for ($x = 1; $x < 10; $x++) {
             $feedbacks = $this->Feedback->find('count', array('conditions' => array('user_id' => $user_id, 'user_view_status' => 'active', 'admin_view_status' => 'active', 'rate >=' => $x, 'rate <' => $x + 1), 'order' => 'id DESC'));
             if ($feedbacks > $max_c) {
                 $max_c = $feedbacks;
             }
             $f_count[$x] = $feedbacks;
         }
         $this->set('f_count', $f_count);
         $this->set('max_c', $max_c);
         $feedbacks = $this->Feedback->find('all', array('conditions' => array('user_id' => $user_id, 'user_view_status' => 'active', 'admin_view_status' => 'active'), 'order' => 'id DESC'));
         $this->set('feedbacks', $feedbacks);
         $this->set('videos', $videos);
     } else {
         //редирект на ошибку
         $this->redirect(array('controller' => 'showerror', 'action' => '/'));
         exit;
     }
 }
Esempio n. 13
0
 public function api_master_search()
 {
     $name = 'name_' . lang_prefix();
     $default_count = 6;
     $response = array();
     $category_id = isset($this->request->data['category_id']) ? $this->request->data['category_id'] : null;
     $city_id = isset($this->request->data['city_id']) ? $this->request->data['city_id'] : null;
     $region_id = isset($this->request->data['region_id']) ? $this->request->data['region_id'] : null;
     $find_string = isset($this->request->data['string']) ? $this->request->data['string'] : null;
     $data_count = isset($this->request->data['count']) ? $this->request->data['count'] : null;
     $data_page = isset($this->request->data['page']) ? $this->request->data['page'] : 1;
     if (!is_numeric($city_id)) {
         $city_id = 0;
     }
     if (!is_numeric($region_id)) {
         $region_id = 0;
     }
     if (!is_numeric($category_id)) {
         $category_id = 0;
     }
     if (!is_numeric($data_count)) {
         $data_count = $default_count;
     }
     $this->loadModel('Servicetouser');
     $this->Servicetouser->useTable = 'service_to_users';
     if ($category_id > 0) {
         //подкатегории
         $subcategories = $this->Categories->find('all', array('conditions' => array('parent_id' => $category_id), 'order' => $name . ' ASC'));
         //субкатегории и все подуслуги
         $sub_services = array();
         $this_services = $this->Service->find('all', array('order' => 'id DESC', 'conditions' => array('category_id' => $category_id, 'status' => 'active')));
         if (count($this_services) > 0) {
             foreach ($this_services as $serv) {
                 $sub_services[] = array('name' => $serv['Service'][$name], 'url_prefix' => $serv['Service']['url_prefix'], 'id' => $serv['Service']['id']);
             }
         }
         foreach ($subcategories as &$cur_category) {
             $id = $cur_category['Categories']['id'];
             $services = $this->Service->find('all', array('order' => 'id DESC', 'conditions' => array('category_id' => $id, 'status' => 'active')));
             if (count($services) > 0) {
                 foreach ($services as $serv) {
                     $sub_services[] = array('name' => $serv['Service'][$name], 'url_prefix' => $serv['Service']['url_prefix'], 'id' => $serv['Service']['id']);
                 }
             }
         }
         //все услуги в данной категории
         $included_services = $this->Categories->findRecursiveCategoriesByCategoryId($category_id);
         $included_services_ids = $this->Categories->ids;
         //листинг мастеров
         //если выбран город производится поиск по мастерам города
         //			$session_city_id = $this->Session->read('city_id');
         //			if(is_numeric($session_city_id) AND $session_city_id>0){
         //				$city_id = $session_city_id;
         //				$city_regions = $this->Region->find('all', array('conditions' => array('city_id' => $city_id), 'order' => $name . ' ASC'));
         //				$this->set('city_regions',$city_regions);
         //			} else $city_id = 0;
         //			pr($city_id);
         //		exit;
         //			pr($sub_services);
         if ($category_id > 0 and count($sub_services) == 0) {
             //мастера не найдены так как в выбранной категории отсутствуют услуги
             $response["masters"] = array();
             response_ajax($response, "error");
             exit;
         }
     } else {
         $sub_services = array();
     }
     $_users = array();
     if ($region_id !== 0 and is_numeric($region_id)) {
         $user_to_region_guest = $this->UserToRegionGuest->find('all', array('joins' => array(array('table' => 'regions', 'alias' => 'Region', 'type' => 'INNER', 'conditions' => array('Region.id = UserToRegionGuest.region_id'))), 'fields' => array('UserToRegionGuest.user_id'), 'conditions' => array('UserToRegionGuest.region_id' => $region_id)));
         $user_to_region_place = $this->UserToRegionPlace->find('all', array('joins' => array(array('table' => 'regions', 'alias' => 'Region', 'type' => 'INNER', 'conditions' => array('Region.id = UserToRegionPlace.region_id'))), 'fields' => array('UserToRegionPlace.user_id'), 'conditions' => array('UserToRegionPlace.region_id' => $region_id)));
         foreach ($user_to_region_guest as $reg) {
             $user__id = $reg['UserToRegionGuest']['user_id'];
             if (!in_array($user__id, $_users)) {
                 $_users[] = $user__id;
             }
         }
         foreach ($user_to_region_place as $reg2) {
             $user__id = $reg2['UserToRegionPlace']['user_id'];
             if (!in_array($user__id, $_users)) {
                 $_users[] = $user__id;
             }
         }
     }
     $page = ($data_page - 1) * $data_count;
     $category_masters = $this->Servicetouser->findMastersServices($sub_services, $city_id, $_users, $find_string, $data_count, $page);
     // количество мастеров, которые оказывают услуги по данной категории - в данном городе, районе, по указанной строке
     $all_category_masters = count($this->Servicetouser->findMastersServices($sub_services, $city_id, $_users, $find_string, 99999999, 0));
     $pages = ceil($all_category_masters / $data_count);
     $cm = array();
     foreach ($category_masters as &$master) {
         $u_id = $master['Servicetouser']['user_id'];
         $__master = $this->Master->find('all', array('conditions' => array('id' => $u_id), 'fields' => array('Master.id', 'Master.firstname', 'Master.lastname', 'Master.mail', 'Master.phone', 'Master.skype', 'Master.login', 'Master.city_id', 'Master.country_id', 'Master.business_type', 'Master.rate', 'Master.about_me', 'Master.education', 'Master.regards', 'Master.specialization', 'Master.main_foto', 'UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(created) AS reg_time', 'UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(last_activity) AS last_act', 'UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(created) AS reg_time')));
         $IMG__DIR = Configure::read('USER_FILE_UPLOAD_DIR');
         foreach ($__master as &$elem) {
             $master_image = $elem['Master']['main_foto'];
             $u__id = $elem['Master']['id'];
             $img_path = site_url() . "/" . "files" . "/" . "user_files" . "/" . "u" . $u__id . "/";
             $def_img_path = site_url() . "/img/design/";
             $real_foto = $IMG__DIR . DS . "u" . $u__id . DS . $master_image;
             if (!empty($master_image) and file_exists($real_foto)) {
                 $image = $img_path . $master_image;
             } else {
                 $image = $def_img_path . "default_user_icon.png";
             }
             $elem['Master']['image'] = $image;
         }
         $master_services = $this->Servicetouser->find('all', array('conditions' => array('user_id' => $u_id)));
         $services = array();
         if (!isset($included_services_ids)) {
             $included_services_ids = array();
         }
         foreach ($master_services as $ms) {
             $s_id = $ms['Servicetouser']['service_id'];
             if (in_array($s_id, $included_services_ids)) {
                 $services[] = $this->Service->find('all', array('conditions' => array('id' => $s_id)));
             }
         }
         //загрузка расценок пользователя
         $this->loadModel('Userprices');
         $this->Userprices->useTable = 'user_prices';
         $user_prices = $this->Userprices->find('all', array('conditions' => array('user_id' => $u_id), 'joins' => array(array('table' => 'service_pay_types', 'alias' => 'Paytype', 'type' => 'INNER', 'conditions' => array('Paytype.id = Userprices.pay_type_id'))), 'fields' => array('Paytype.*', 'Userprices.*')));
         //$prices = $this->Userprice->find('all', array('conditions' => array('user_id' => $u_id)));
         $feedback = $this->Feedback->find('all', array('conditions' => array('user_id' => $u_id), 'limit' => 3));
         $feedback_count = $this->Feedback->find('count', array('conditions' => array('user_id' => $u_id)));
         $user_to_region_guest = $this->UserToRegionGuest->find('all', array('joins' => array(array('table' => 'regions', 'alias' => 'Region', 'type' => 'INNER', 'conditions' => array('Region.id = UserToRegionGuest.region_id'))), 'fields' => array('UserToRegionGuest.*', 'Region.*'), 'conditions' => array('UserToRegionGuest.user_id' => $u_id)));
         $user_to_region_place = $this->UserToRegionPlace->find('all', array('joins' => array(array('table' => 'regions', 'alias' => 'Region', 'type' => 'INNER', 'conditions' => array('Region.id = UserToRegionPlace.region_id'))), 'fields' => array('UserToRegionPlace.*', 'Region.*'), 'conditions' => array('UserToRegionPlace.user_id' => $u_id)));
         $cm['masters'][] = array('user' => $__master, 'user_to_region_guest' => $user_to_region_guest, 'user_to_region_place' => $user_to_region_place, 'services' => $services, 'prices' => $user_prices, 'feedback' => $feedback, 'feedback_count' => $feedback_count);
     }
     $cm['total_master'] = $all_category_masters;
     $cm['pages'] = $pages;
     if (count($cm) > 0) {
         response_ajax($cm, "success");
     } else {
         response_ajax(array(), "error");
     }
     exit;
 }
 public function api_set_lang()
 {
     $lang = isset($this->params['lang']) ? $this->params['lang'] : null;
     if ($lang == null) {
         $session_lang = Configure::read('DEF_LANG');
     } else {
         if (in_array($lang, Configure::read('VALID_LANGS'))) {
             $session_lang = $lang;
         } else {
             $session_lang = Configure::read('DEF_LANG');
         }
     }
     $this->Session->write('lang', $session_lang);
     $status = 'success';
     $lang_res = lang_prefix();
     response_ajax(array('lang' => $lang_res), $status);
     exit;
 }
 public function get_cat_services()
 {
     $c_id = $this->params->data['id'];
     $this->loadModel('Services');
     $services = $this->Services->find('all', array('conditions' => array('category_id' => $c_id, 'status' => 'active')), array('order' => 'id DESC'));
     $data = array('id', 'name');
     $response = array();
     $lang_prefix = 'name_' . lang_prefix();
     if (count($services) > 0) {
         foreach ($services as $service) {
             $data['id'][] = $service['Services']['id'];
             $data['name'][] = $service['Services'][$lang_prefix];
         }
         $response["result"] = "found";
         $response["query_data"] = $data;
         response_ajax($response, "success");
     } else {
         $response["result"] = "not_found";
         response_ajax($response, "success");
     }
     exit;
 }
 public function view_ticket()
 {
     $id = $this->request->params['id'];
     if (!is_numeric($id)) {
         $this->redirect(array('controller' => 'showerror', 'action' => '/'));
         exit;
     }
     $this->loadModel('MessageTypes');
     $this->loadModel('Message');
     $user_tickets = $this->Ticket->find('first', array('conditions' => array('id' => $id)));
     $lang_prefix = 'name_' . lang_prefix();
     $message_type_id = $user_tickets['Ticket']['message_type'];
     $ticket_id = $user_tickets['Ticket']['id'];
     $user_id = $user_tickets['Ticket']['user_id'];
     //тип сообщения
     $message_type_name = $this->MessageTypes->find('all', array('conditions' => array('id' => $message_type_id)));
     $ticket['message_type_name'] = $message_type_name[0]['MessageTypes'][$lang_prefix];
     $ticket_name = $user_tickets['Ticket']['name'];
     $this->Breadcrumbs->add($ticket_name, Router::url(array('plugin' => false, 'controller' => 'admin', 'action' => 'view_ticket/' . $id)));
     //загрузка сообщений тикета
     $ticket_messages = $this->Message->find('all', array('conditions' => array('ticket_id' => $id), 'order' => 'Message.created DESC'));
     foreach ($ticket_messages as &$message) {
         $sender_type = $message['Message']['sender_type'];
         $receiver_type = $message['Message']['receiver_type'];
         $sender_id = $message['Message']['sender_id'];
         $receiver_id = $message['Message']['receiver_id'];
         if ($sender_type == "admin") {
             $admin = $this->Admin->find('first', array('conditions' => array('id' => $sender_id)));
             $message['Message']['sender_type'] = "Администратор";
             $message['Message']['sender_link'] = "control";
             if (count($admin) > 0) {
                 $message['Message']['sender_firstname'] = $admin['Admin']['firstname'];
                 $message['Message']['sender_lastname'] = $admin['Admin']['lastname'];
                 $message['Message']['sender_fathername'] = $admin['Admin']['fathername'];
             } else {
                 $message['Message']['sender_firstname'] = '';
                 $message['Message']['sender_lastname'] = '';
                 $message['Message']['sender_fathername'] = '';
             }
         } else {
             $user = $this->User->find('first', array('conditions' => array('id' => $sender_id)));
             $message['Message']['sender_type'] = "Пользователь";
             $message['Message']['sender_link'] = "user";
             $message['Message']['sender_firstname'] = $user['User']['firstname'];
             $message['Message']['sender_lastname'] = $user['User']['lastname'];
             $message['Message']['sender_fathername'] = $user['User']['fathername'];
         }
         if ($receiver_type == "admin") {
             $admin = $this->Admin->find('first', array('conditions' => array('id' => $receiver_id)));
             $message['Message']['receiver_type'] = "Администратор";
             $message['Message']['receiver_link'] = "control";
             if (count($admin) > 0) {
                 $message['Message']['receiver_firstname'] = $admin['Admin']['firstname'];
                 $message['Message']['receiver_lastname'] = $admin['Admin']['lastname'];
                 $message['Message']['receiver_fathername'] = $admin['Admin']['fathername'];
             } else {
                 $message['Message']['receiver_firstname'] = '';
                 $message['Message']['receiver_lastname'] = '';
                 $message['Message']['receiver_fathername'] = '';
             }
         } else {
             $user = $this->User->find('first', array('conditions' => array('id' => $receiver_id)));
             $message['Message']['receiver_type'] = "Пользователь";
             $message['Message']['receiver_link'] = "user";
             $message['Message']['receiver_firstname'] = $user['User']['firstname'];
             $message['Message']['receiver_lastname'] = $user['User']['lastname'];
             $message['Message']['receiver_fathername'] = $user['User']['fathername'];
         }
         $message_type = $this->MessageType->find('first', array('conditions' => array('id' => $message['Message']['message_type'])));
         $message['Message']['message_type'] = $message_type['MessageType']['name_ru'];
     }
     $ticket_data = $this->Ticket->find('all', array('conditions' => array('id' => $id), 'limit' => '1'));
     $ticket_name = $ticket_data[0]['Ticket']['name'];
     $ticket_cat = $message['Message']['message_type'];
     $ticket_status = $user_tickets['Ticket']['status'];
     $this->set('user_id', $user_id);
     $this->set('ticket_id', $ticket_id);
     $this->set('ticket_data', $ticket_data);
     $this->set('ticket_messages', $ticket_messages);
     $this->set('ticket_name', $ticket_name);
     $this->set('ticket_cat', $ticket_cat);
     $this->set('ticket_status', $ticket_status);
     $this->set('message_count', count($ticket_messages));
 }