public function api_settings() { $settings = array('SITENAME' => Configure::read('SITENAME'), 'SITEPHONE' => '', Configure::read('SITEPHONE'), 'DESIGN_IMAGE_DIR' => Configure::read('DESIGN_IMAGE_DIR_RELATIVE'), 'PAYMENT_SYSTEMS_ICON_DIR' => Configure::read('PAYMENT_SYSTEMS_ICON_DIR_RELATIVE'), 'CATEGORY_IMAGE_PATH' => Configure::read('CATEGORY_IMAGE_PATH_RELATIVE'), 'USER_FILE_UPLOAD_DIR' => Configure::read('USER_FILE_UPLOAD_DIR_RELATIVE')); $status = 'success'; response_ajax($settings, $status); exit; // }
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; } }
public function rename_message_type() { $name = $this->params->data['name']; $id = $this->params->data['id']; if (empty($name)) { $this->Error->setError('ERROR_231'); ///!! return false; } else { if (!is_numeric($id)) { $this->Error->setError('ERROR_231'); ///!! return false; } else { $this->Messagetypes->id = $id; $result = $this->Messagetypes->save($this->request->data); $response = array(); if ($result !== null) { $response["result"] = "success"; response_ajax($response, "success"); } else { $response["result"] = "error"; response_ajax($response, "error"); } exit; } } }
public function api_logout() { $this->Session->write('User', null); $this->Session->write('user_id', null); $status = 'success'; response_ajax(array('result' => 'logout'), $status); exit; }
public function set_user_city() { $id = intval($this->params->data['id']); if ($id > 0) { $this->loadModel('Cities'); $city_data = $this->Cities->find('first', array('conditions' => array('id' => $id))); $data = array('id', 'city_name'); $response = array(); if (count($city_data) > 0) { foreach ($city_data as $city) { //запись сессии в город $session_city_id = $this->Session->write('city_id', $city['id']); $data['id'][] = $city['id']; $data['city_name'][] = $city['name_ru']; } $response["result"] = "found"; $response["query_data"] = $data; response_ajax($response, "success"); } else { $response["result"] = "not_found"; response_ajax($response, "success"); } } elseif ($id == 0) { $data['id'][] = 0; $data['city_name'][] = "Не выбрано"; $response["result"] = "found"; $response["query_data"] = $data; response_ajax($response, "success"); } else { $response["result"] = "not_found"; response_ajax($response, "success"); } exit; }
public function add_comment() { $id = $this->params->data['id']; $comment = $this->params->data['comment']; if (!is_numeric($id)) { $this->Error->setError('ERROR_301'); return false; } if (empty($comment)) { $this->Error->setError('ERROR_301'); return false; } $this->loadModel('Adminordercomment'); $result = $this->Adminordercomment->save(array('text' => $comment, 'admin_id' => $this->Session->read('admin_id'), 'order_id' => $id)); $response = array(); if ($result !== null) { $response["result"] = "success"; $response["query_data"] = $result; $this->ACTION(9, $id, $this->Session->read('admin_id')); response_ajax($response, "success"); } else { $response["result"] = "error"; response_ajax($response, "error"); } exit; }
public function get_article_data() { $id = $this->params->data['id']; if (!is_numeric($id)) { $this->redirect(array('controller' => 'showerror', 'action' => '/')); exit; } //данные региона $region = $this->Service->find('first', array('conditions' => array('id' => $id))); $response = array(); if ($region !== null) { $response["result"] = "success"; $response["query_data"] = $region['Service']; response_ajax($response, "success"); } else { $response["result"] = "error"; response_ajax($response, "error"); } exit; }
public function add_category() { $name_ru = $this->params->data['name_ru']; $name_en = $this->params->data['name_en']; $name_kz = $this->params->data['name_kz']; if (empty($name_ru) and empty($name_en) and empty($name_en)) { $this->Error->setError('ERROR_231'); return false; } else { $this->Categories->create(); $result = $this->Categories->save($this->request->data); $response = array(); if ($result !== null) { $response["result"] = "success"; $response["query_data"] = $result['Categories']['id']; response_ajax($response, "success"); } else { $response["result"] = "error"; response_ajax($response, "error"); } exit; } }
public function set_map_coord() { $response = array(); //проверка пользователя $user_id = $this->Session->read('user_id'); if ($this->user_data['view_on_map'] == 'hidden') { $response["result"] = "error"; response_ajax($response, "error"); exit; } //проверка валидности координат $lat = $this->request->query['lat'] ? $this->request->query['lat'] : null; $long = $this->request->query['long'] ? $this->request->query['long'] : null; if (!valid_lat($lat) or !valid_long($long)) { $response["result"] = "error"; response_ajax($response, "error"); exit; } $data_for_save = array('lat' => $lat, 'long' => $long); $this->User->id = $user_id; $result = $this->User->save($data_for_save); if ($result !== null) { $response["result"] = "success"; $response["query_data"] = $result['User']['id']; response_ajax($response, "success"); } else { $response["result"] = "error"; response_ajax($response, "error"); } exit; }
public function api_profile() { $profile_url_prefix = $this->request->params['master_id']; $user = $this->Master->find('first', array('conditions' => array('OR' => array('login' => $profile_url_prefix, 'id' => $profile_url_prefix)), 'mail_checked' => 1, 'account_status' => 'activated')); // если профиль существует if (count($user) > 0) { $user_id = $user['Master']['id']; //добавление записи в Profile_views $this->Breadcrumbs->add(prepare_fio($user['Master']['lastname'], $user['Master']['firstname'], $user['Master']['fathername']), ''); $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['services'] = $services; $user['prices'] = $user_prices; //файлы мастера $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', 'type' => 'image'), 'order' => 'type ASC, created DESC')); $user['user_files'] = $user_files; //видео мастера $videos = $this->Video->find('all', array('conditions' => array('owner_id' => $user_id, 'owner_type' => 'user', 'view_status' => 'active'), 'order' => 'created DESC')); $user['video'] = $videos; //отзывы $user_feedbacks = $this->Feedback->find('all', array('conditions' => array('user_id' => $user_id, 'user_view_status' => 'active', 'admin_view_status' => 'active'), 'order' => 'id DESC')); unset($user_feedbacks['Feedback']['user_view_status']); unset($user_feedbacks['Feedback']['admin_view_status']); $user['feedbacks'] = $user_feedbacks; //API RESPONSE //Исключение небезопасных полей unset($user['Master']['password']); unset($user['Master']['mail_key']); unset($user['Master']['recover_key']); $status = 'success'; response_ajax($user, $status); exit; // } else { $data = array('error' => 'user_not_found'); $status = 'error'; response_ajax($data, $status); exit; } }
/** * Requisições ajax nao são aceitas. */ static function is_ajax() { if (is_ajax()) { response_ajax('liv responds > that ugly, never pass data in this way.'); } }
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 api_get_lang() { $langs = array(); $langs[] = array('id' => 1, 'name' => 'Русский', 'prefix' => 'RU'); //$langs[] = array('id' => 2, 'name' => 'English', 'prefix' => 'EN'); //$langs[] = array('id' => 3, 'name' => 'қазақ тілі', 'prefix' => 'KZ'); $status = 'success'; response_ajax($langs, $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 api_set_order() { $comment_min_size = 30; $comment_max_size = 3000; $order_mail = isset($this->request->data['email']) ? $this->request->data['email'] : null; $order_phone = isset($this->request->data['phone']) ? $this->request->data['phone'] : null; $order_country_id = isset($this->request->data['country_id']) ? $this->request->data['country_id'] : null; $order_city_id = isset($this->request->data['city_id']) ? $this->request->data['city_id'] : null; $order_comment = isset($this->request->data['comment']) ? $this->request->data['comment'] : null; $order_regions = isset($this->request->data['regions']) ? $this->request->data['regions'] : null; $order_firstname = isset($this->request->data['firstname']) ? $this->request->data['firstname'] : null; $order_lastname = isset($this->request->data['lastname']) ? $this->request->data['lastname'] : null; $order_service_id = isset($this->request->data['service_id']) ? $this->request->data['service_id'] : null; $response = array(); $mail_regexp = "/^[A-Z0-9._-]+@[A-Z0-9.-]+\\.[A-Z]{2,10}\$/i"; $phone_regexp = "/^\\+[0-9]{11,12}\$/"; $name_regexp = "/^[a-zA_ZА-Яа-яёЁ-]{2,32}\$/iu"; if (!preg_match($mail_regexp, $order_mail)) { $response["error"] = "false email!"; response_ajax($response, "error"); } if (!preg_match($phone_regexp, $order_phone)) { $response["error"] = "false phone!"; response_ajax($response, "error"); } if (!preg_match($name_regexp, $order_lastname)) { $response["error"] = "false lastname!"; response_ajax($response, "error"); } if (!preg_match($name_regexp, $order_firstname)) { $response["error"] = "false firstname!"; response_ajax($response, "error"); } if ($order_service_id !== null and !is_numeric($order_service_id)) { $response["error"] = "false service_id!"; response_ajax($response, "error"); } if (!is_numeric($order_city_id)) { $response["error"] = "false city!"; response_ajax($response, "error"); } if (!is_numeric($order_country_id)) { $response["error"] = "false country_id!"; response_ajax($response, "error"); } if (mb_strlen(trim($order_comment)) < $comment_min_size) { $error_text = "too short length comment to order! Min symbols count is {$comment_min_size}"; $response["error"] = $error_text; response_ajax($response, "error"); } if (mb_strlen(trim($order_comment)) > $comment_max_size) { $error_text = "too match length comment to order! Max symbols count is {$comment_max_size}"; $response["error"] = $error_text; response_ajax($response, "error"); } $data_for_save = array("country_id" => $order_country_id, "city_id" => $order_city_id, "mail" => $order_mail, "phone" => $order_phone, "lastname" => $order_lastname, "firstname" => $order_firstname, "text" => $order_comment, "service_id" => $order_service_id, "payed" => 'not_payed', "cost" => 0, "payment_type_id" => 0, 'money_type' => 'rub', 'status' => 'new'); $this->Order->save($data_for_save); $id = $this->Order->getLastInsertId(); for ($p = 0; $p < count($order_regions); $p++) { $check_region = $this->Regions->find('count', array('conditions' => array('id' => $order_regions[$p]))); if ($check_region > 0) { $new_record = array('order_id' => $id, 'region_id' => $order_regions[$p]); $this->OrderRegions->save($new_record, true); $new_record = null; } } /*TODO Отправить уведомление плиенту об созданной заявке*/ if ($id > 0) { $response['id'] = $id; response_ajax($response, "success"); } else { $response["id"] = "0"; response_ajax($response, "error"); } exit; }
public function save_feed() { $user_name = $this->params->data['user_name']; $user_mail = $this->params->data['user_mail']; $user_phone = $this->params->data['user_phone']; $comment = $this->params->data['comment']; $id = $this->params->data['id']; if (empty($user_name) or empty($user_mail) or empty($user_phone)) { $this->Error->setError('ERROR_231'); return false; } else { //пересчет рейтинга $rates = isset($this->params->data['RATE']) ? $this->params->data['RATE'] : null; if ($rates !== null) { $sum_rate = 0; $count_rate = 0; $this->Adminfeed->id = $id; $this->Adminfeed->save($rates); foreach ($rates as $rate) { check_valid_rate($rate, $sum_rate, $count_rate); } if ($count_rate > 0) { $new_rate = sprintf("%01.2f", $sum_rate / $count_rate); $this->Adminfeed->id = $id; $this->Adminfeed->save(array('rate' => $new_rate)); //пересчет среднего рейтинга мастера $feed = $this->Adminfeed->find('first', array('conditions' => array('id' => $id))); $user_id = $feed['Adminfeed']['user_id']; $this->recalc_user_rating($user_id); } } $this->Adminfeed->id = $id; $result = $this->Adminfeed->save($this->request->data); $response = array(); if ($result !== null) { $response["result"] = "success"; response_ajax($response, "success"); } else { $response["result"] = "error"; response_ajax($response, "error"); } exit; } }
public function get_price_data() { $id = $this->params->data['id']; if (!is_numeric($id)) { $this->redirect(array('controller' => 'showerror', 'action' => '/')); exit; } //данные расценки $this->loadModel('Userprices'); $this->Userprices->useTable = 'user_prices'; $price = $this->Userprices->find('first', array('conditions' => array('id' => $id))); $response = array(); if ($price !== null) { $response["result"] = "success"; $response["query_data"] = $price['Userprices']; response_ajax($response, "success"); } else { $response["result"] = "error"; response_ajax($response, "error"); } exit; }
public function api_money_types() { $money_types = array('rub', 'usd', 'kzt'); if (count($money_types) > 0) { response_ajax($money_types, "success"); } else { response_ajax(array(), "error"); } exit; }
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 api_master_comments() { $user_id = $this->request->params['id']; $this->loadModel('Feedback'); $user_feedback = $this->Feedback->find('all', array('conditions' => array('admin_view_status' => 'active', 'user_id' => $user_id), 'order' => array('id ASC'))); if (count($user_feedback) > 0) { response_ajax($user_feedback, "success"); } else { response_ajax(array(), "error"); } exit; }
public function _ajax_error($error_content) { response_ajax(array('data' => $error_content), "error"); }
public function ajax_search_master() { $string = $this->params->data['find']; $order_id = $this->params->data['id']; $data = array(); if (empty($string)) { $this->Error->setError('ERROR_251'); return false; } else { if (!is_numeric($string)) { if (mb_strlen($string) < 3) { exit; } $user_result = $this->Master->find('all', array('conditions' => array('OR' => array(array('Master.lastname LIKE' => '%' . $string . '%'), array('Master.login LIKE' => '%' . $string . '%'), array('Master.firstname LIKE' => '%' . $string . '%'))), 'fields' => array('Master.firstname', 'Master.lastname', 'Master.fathername', 'Master.id', 'Master.login', 'Master.main_foto'))); } else { if (is_numeric($string)) { //поиск по мастерам $user_result = $this->Master->find('all', array('conditions' => array('OR' => array(array('Master.id LIKE' => '%' . $string . '%'))), 'fields' => array('Master.firstname', 'Master.lastname', 'Master.fathername', 'Master.id', 'Master.login', 'Master.main_foto'))); } } if ($user_result !== null) { foreach ($user_result as $result) { $user_id = $result['Master']['id']; $get_status = $this->Masterorder->find('first', array('conditions' => array('order_id' => $order_id, 'user_id' => $user_id))); if (count($get_status) == 0) { $get_status_text = 'free'; // admin_request, admin_reject, admin_done, admin_proceed } else { if ($get_status['Masterorder']['status'] == 'admin_request') { $get_status_text = 'already_sent'; } else { if ($get_status['Masterorder']['status'] == 'admin_reject') { $get_status_text = 'free'; } else { if ($get_status['Masterorder']['status'] == 'master_reject') { $get_status_text = 'master_reject'; } else { if ($get_status['Masterorder']['status'] == 'master_request') { $get_status_text = 'master_request'; } else { $get_status_text = 'free'; } } } } } $data[] = array('name' => prepare_fio($result['Master']['firstname'], $result['Master']['lastname'], $result['Master']['fathername']), 'link' => site_url() . "/profile/" . $result['Master']['login'] . "/", 'type' => 'master', 'id' => $user_id, 'foto' => site_url() . "/" . Configure::read('USER_FILE_UPLOAD_DIR_RELATIVE') . "/u" . $result['Master']['id'] . "/" . $result['Master']['main_foto'], 'order_status' => $get_status_text); } } $response = array(); if ($result !== null) { $response["result"] = "success"; $response["query_data"] = $data; response_ajax($response, "success"); } else { $response["result"] = "error"; response_ajax($response, "error"); } exit; } }
public function get_category_data() { $id = $this->params->data['id']; if (!is_numeric($id)) { $this->redirect(array('controller' => 'showerror', 'action' => '/')); exit; } //данные категории $category = $this->Categories->find('first', array('conditions' => array('id' => $id))); $response = array(); if ($category !== null) { $response["result"] = "success"; $response["query_data"] = $category['Categories']; response_ajax($response, "success"); } else { $response["result"] = "error"; response_ajax($response, "error"); } exit; }
public function checkemail() { $this->loadModel('User'); $email = $this->params->data['email']; $response = array(); if ($this->User->find('count', array('conditions' => array('mail' => $email))) > 0) { $response["result"] = L("MAIL_EXISTS"); response_ajax($response, "error"); } else { $response["result"] = ""; response_ajax($response, "success"); } exit; }