Exemple #1
0
     $a = $_POST['age'][0];
     $age[0] = $age[1];
     $age[1] = $a;
 }
 $from_cost = __paramInit('int', 'from_cost', 'from_cost');
 $to_cost = __paramInit('int', 'to_cost', 'to_cost');
 if ($from_cost > $to_cost && $to_cost != 0) {
     $a = $from_cost;
     $from_cost = $to_cost;
     $to_cost = $a;
 }
 $filter_prof = array();
 if ($prof_id > 0) {
     $filter_prof = array(1 => array($prof_id => 1));
 } elseif ($prof_group_id > 0) {
     $profs = professions::GetProfs($prof_group_id);
     $filter_prof = array();
     foreach ($profs as $prof) {
         $filter_prof[1][$prof['id']] = 1;
     }
 }
 $filter = array("is_pro" => $is_pro, 'prof' => $filter_prof);
 $string_professions = '';
 if ($action == "search_advanced") {
     $filter = array("active" => "t", "prof" => $filter_prof, "cost_type" => intval(@$_POST['cost_type_db_id']), "from_cost" => $from_cost, "to_cost" => $to_cost, "curr_type" => intval(@$_POST['curr_type_db_id']), "exp" => is_array($_POST['exp']) ? array_map("intval", $_POST['exp']) : @$_POST['exp'], "exp_from" => $exp[0], "exp_to" => $exp[1], "age" => is_array($_POST['age']) ? array_map("intval", $_POST['age']) : @$_POST['age'], "age_from" => $age[0], "age_to" => $age[1], "country" => (int) @$_POST['location_columns'][0], "city" => (int) @$_POST['location_columns'][1], "in_office" => (bool) @$_POST['in_office'], "in_fav" => (bool) @$_POST['in_fav'], "only_free" => (bool) @$_POST['only_free'], "is_pro" => $is_pro, "is_verify" => (bool) @$_POST['is_verify'], "is_preview" => (bool) @$_POST['is_preview'], "sbr_is_positive" => (bool) @$_POST['sbr_is_positive'], "sbr_not_negative" => (bool) @$_POST['sbr_not_negative'], "opi_is_positive" => (bool) @$_POST['sbr_is_positive'], "opi_not_negative" => (bool) @$_POST['sbr_not_negative']);
     if ($filter['cost_type']) {
         $filter['cost'][] = array('cost_type' => $filter['curr_type'], 'cost_from' => $filter['from_cost'], 'cost_to' => $filter['to_cost'], 'type_date' => $filter['cost_type']);
     }
     $countryObj = new country();
     $countryCityName = $countryObj->getCountryAndCityNames($filter['country'], $filter['city']);
     $countryCityName = @$countryCityName['name'];
 /**
  * Обрабатывает POST переменную action  и  возвращает null или данные.
  *
  * @return string
  */
 public function processRequest()
 {
     $expire = 1;
     //3600;
     $action = __paramInit('string', '', 'action');
     switch ($action) {
         case 'getdays':
             $days = array(1 => iconv('WINDOWS-1251', 'UTF-8//IGNORE', '1 день'));
             $max = __paramInit('integer', '', 'max', 1);
             $all = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 14, 21, 30, 45, 60, 90);
             if ($max > 1) {
                 $days = array();
                 foreach ($all as $day) {
                     if ($day >= $max) {
                         break;
                     }
                     $days[$day] = iconv('WINDOWS-1251', 'UTF-8//IGNORE', $day . ending($day, ' день', ' дня', ' дней'));
                 }
             }
             $days = array(array('parentId' => '0'), $days);
             return json_encode($days);
             break;
         case 'gettucategories':
             $expire = 300;
             //3600;
             $membuf = new memBuff();
             $memkey = 'b-combo-gettucategories';
             $result = $membuf->get($memkey);
             if (!$result) {
                 /*
                  * Получаем из базы иерархию категорий для
                  * типовой услуги
                  */
                 $DB = new DB('master');
                 $sql = 'SELECT 
                             g.id AS gid, 
                             g.title AS gname, 
                             g.ucnt AS gucnt, 
                             p.id AS pid, 
                             p.title AS name,
                             p.ucnt AS pucnt
                          FROM tservices_categories AS g 
                          INNER JOIN tservices_categories AS p ON p.parent_id = g.id 
                          ORDER BY g.ucnt DESC, p.ucnt DESC --gid, pid --g.n_order, p.n_order';
                 $rows = $DB->rows($sql);
                 $result = array();
                 if (count($rows)) {
                     foreach ($rows as $k => $i) {
                         if ($result[$i['gid']] === null) {
                             $result[$i['gid']] = array('0' => array(iconv('WINDOWS-1251', 'UTF-8//IGNORE', $i['gname']), $i['gucnt']));
                             if ($i['pid'] !== null) {
                                 $result[$i['gid']][$i['pid']] = array(iconv('WINDOWS-1251', 'UTF-8//IGNORE', $i['name']), $i['pucnt']);
                             } else {
                                 $result[$i['gid']] = array(iconv('WINDOWS-1251', 'UTF-8//IGNORE', $i['gname']), $i['gucnt']);
                             }
                         } elseif (is_array($result[$i['gid']])) {
                             $result[$i['gid']][$i['pid']] = array(iconv('WINDOWS-1251', 'UTF-8//IGNORE', $i['name']), $i['pucnt']);
                         }
                     }
                 }
                 //print_r($result);
                 //exit;
                 $result = json_encode($result);
                 $membuf->add($memkey, $result, $expire);
             }
             return $result;
             break;
         case 'getlettergrouplist':
             require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/letters.php';
             $lettergroups = letters::getGroups($_POST['word'], (int) $_POST['limit']);
             $result = array();
             $n = 0;
             foreach ($lettergroups as $k => $i) {
                 $result[$n]['uid'] = $i['id'];
                 $result[$n]['uname'] = iconv('WINDOWS-1251', 'UTF-8//IGNORE', $i['title']);
                 $result[$n]['usurname'] = '';
                 $result[$n]['login'] = '';
                 $result[$n]['photo'] = '';
                 $result[$n]['path'] = '';
                 $result[$n]['isContacts'] = '';
                 ++$n;
             }
             $list = array();
             $list['list'] = $result;
             $list['counters']['moreContacts'] = 0;
             $list['counters']['moreUsers'] = 0;
             $list['dav'] = WDCPREFIX;
             return json_encode($list);
             break;
         case 'getlettergroupinfo':
             require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/letters.php';
             $group = letters::getGroup($_POST['uid']);
             if ($group) {
                 $data = array('record' => array('uid' => $group['id'], 'uname' => iconv('WINDOWS-1251', 'UTF-8//IGNORE', $group['title']), 'usurname' => '', 'login' => '', 'photo' => '', 'path' => '', 'isContacts' => ''), 'found' => 1, 'dav' => WDCPREFIX);
             }
             return json_encode($data);
             break;
         case 'getletterdocinfo':
             require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/letters.php';
             $doc = letters::getDocument($_POST['uid']);
             if ($doc) {
                 $data = array('record' => array('uid' => $doc['id'], 'uname' => iconv('WINDOWS-1251', 'UTF-8//IGNORE', $doc['id'] . ' ' . htmlspecialchars($doc['group_title']) . ' - ' . htmlspecialchars($doc['title'])), 'usurname' => '', 'login' => '', 'photo' => '', 'path' => '', 'isContacts' => ''), 'found' => 1, 'dav' => WDCPREFIX);
             }
             return json_encode($data);
             break;
         case 'getletterdoclist':
             require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/letters.php';
             $letterdocs = letters::getDocuments($_POST['word'], (int) $_POST['limit']);
             $result = array();
             $n = 0;
             foreach ($letterdocs as $k => $i) {
                 $result[$n]['uid'] = $i['id'];
                 $result[$n]['uname'] = iconv('WINDOWS-1251', 'UTF-8//IGNORE', $i['id'] . ' ' . htmlspecialchars($i['group_title']) . ' - ' . htmlspecialchars($i['title']));
                 $result[$n]['usurname'] = '';
                 $result[$n]['login'] = '';
                 $result[$n]['photo'] = '';
                 $result[$n]['path'] = '';
                 $result[$n]['isContacts'] = '';
                 ++$n;
             }
             $list = array();
             $list['list'] = $result;
             $list['counters']['moreContacts'] = 0;
             $list['counters']['moreUsers'] = 0;
             $list['dav'] = WDCPREFIX;
             return json_encode($list);
             break;
         case 'getletterdocsearch':
             require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/letters.php';
             $letterdocs = letters::getSearchDocuments($_POST['word'], (int) $_POST['limit']);
             $result = array();
             $n = 0;
             foreach ($letterdocs as $k => $i) {
                 $result[$n]['uid'] = $i['id'];
                 $result[$n]['uname'] = iconv('WINDOWS-1251', 'UTF-8//IGNORE', $i['id'] . ' ' . htmlspecialchars($i['group_title']) . ' - ' . htmlspecialchars($i['title']));
                 $result[$n]['usurname'] = '';
                 $result[$n]['login'] = '';
                 $result[$n]['photo'] = '';
                 $result[$n]['path'] = '';
                 $result[$n]['isContacts'] = '';
                 ++$n;
             }
             $list = array();
             $list['list'] = $result;
             $list['counters']['moreContacts'] = 0;
             $list['counters']['moreUsers'] = 0;
             $list['dav'] = WDCPREFIX;
             return json_encode($list);
             break;
         case 'getdate':
             return date('Y-m-d');
         case 'getprofgroups':
             $membuf = new memBuff();
             $memkey = 'b-combo-getprofgroups';
             $result = $membuf->get($memkey);
             if (!$result) {
                 $rows = professions::GetAllGroupsLite();
                 $result = array();
                 foreach ($rows as $k => $i) {
                     $result[$i['id']] = iconv('WINDOWS-1251', 'UTF-8//IGNORE', $i['name']);
                 }
                 $membuf->add($memkey, $result, $expire);
             }
             return json_encode($result);
         case 'getprofessionsandgroups':
             $membuf = new memBuff();
             $memkey = 'b-combo-getprofandgroups';
             $result = $membuf->get($memkey);
             if (!$result) {
                 $rows = professions::GetProfessionsAndGroup();
                 $result = array();
                 foreach ($rows as $k => $i) {
                     if ($result[$i['gid']] === null) {
                         $result[$i['gid']] = array($i['gid'] => iconv('WINDOWS-1251', 'UTF-8//IGNORE', $i['gname']));
                         if ($i['id'] !== null) {
                             $result[$i['gid']][$i['id']] = iconv('WINDOWS-1251', 'UTF-8//IGNORE', $i['name']);
                         } else {
                             $result[$i['gid']] = iconv('WINDOWS-1251', 'UTF-8//IGNORE', $i['gname']);
                         }
                     } elseif (is_array($result[$i['gid']])) {
                         $result[$i['gid']][$i['id']] = iconv('WINDOWS-1251', 'UTF-8//IGNORE', $i['name']);
                     }
                 }
                 $membuf->add($memkey, $result, $expire);
             }
             return json_encode($result);
         case 'getprofessions':
             $n = __paramInit('integer', '', 'id');
             if ($n !== false) {
                 $membuf = new memBuff();
                 $memkey = "b-combo-getprofbygroup{$n}";
                 $result = $membuf->get($memkey);
                 if (!$result) {
                     $rows = professions::GetProfs($n);
                     $result = array(0 => iconv('WINDOWS-1251', 'UTF-8//IGNORE', 'Все специальности'));
                     foreach ($rows as $k => $i) {
                         $result[$i['id']] = iconv('WINDOWS-1251', 'UTF-8//IGNORE', $i['name']);
                     }
                     $membuf->add($memkey, $result, $expire);
                 }
                 $data = array(array('parentId' => "{$n}"), $result);
                 return json_encode($data);
             }
         case 'get_pro_types':
             $membuf = new memBuff();
             $memkey = 'b-combo-get_pro_type';
             $result = $membuf->get($memkey);
             if (!$result) {
                 $rows = op_codes::getCodes(array(47, 48, 49, 50, 51));
                 $result = array();
                 foreach ($rows as $k => $i) {
                     $result[$i['id']] = iconv('WINDOWS-1251', 'UTF-8//IGNORE', $i['op_name']);
                 }
                 $result[76] = iconv('WINDOWS-1251', 'UTF-8//IGNORE', 'На несколько недель');
                 $membuf->add($memkey, $result, $expire);
             }
             return json_encode($result);
         case 'getcountries':
         case 'getrelevantcountries':
             $membuf = new memBuff();
             $memkey = 'b-combo-getcountriesr';
             $result = $membuf->get($memkey);
             if (!$result) {
                 $rows = country::GetCountriesByCountUser();
                 $result = array();
                 foreach ($rows as $k => $i) {
                     $result[$i['id']] = iconv('WINDOWS-1251', 'UTF-8//IGNORE', $i['name']);
                 }
                 $membuf->add($memkey, $result, $expire);
             }
             return json_encode($result);
         case 'getcities':
             $n = __paramInit('integer', '', 'id');
             if ($n !== false) {
                 $membuf = new memBuff();
                 $memkey = "b-combo-getcitybycountry{$n}";
                 $result = $membuf->get($memkey);
                 if (!$result) {
                     $rows = city::GetCities($n);
                     $result = array('0' => iconv('WINDOWS-1251', 'UTF-8//IGNORE', 'Все города'));
                     if (is_array($rows)) {
                         foreach ($rows as $k => $i) {
                             $result[$k] = iconv('WINDOWS-1251', 'UTF-8//IGNORE', $i);
                         }
                     }
                     $membuf->add($memkey, $result, $expire);
                 }
                 $data = array(array('parentId' => "{$n}"), $result);
                 return json_encode($data);
             }
         case 'getcitiesbyid':
             $n = __paramInit('integer', '', 'id');
             if ($n !== false) {
                 $membuf = new memBuff();
                 $memkey = "b-combo-getcitybycountry{$n}";
                 $result = $membuf->get($memkey);
                 if (!$result) {
                     $rows = city::GetCities($n);
                     $result = array('0' => iconv('WINDOWS-1251', 'UTF-8//IGNORE', 'Все города'));
                     foreach ($rows as $k => $i) {
                         $result[$k] = iconv('WINDOWS-1251', 'UTF-8//IGNORE', $i);
                     }
                     $membuf->add($memkey, $result, $expire);
                 }
                 return json_encode($result);
             }
         case 'getuserlistbysbr':
         case 'getuserlistold':
         case 'getuserlist':
             return $this->getUsersList($_POST['word'], (int) $_POST['limit'], (int) $_POST['userType'], (int) $_POST['scope']);
         case 'get_user_info':
             return json_encode(users::GetUserShortInfo((int) $_POST['uid']));
         case 'getusersandcompanies':
             return $this->getUsersAndCompany($_POST['word'], (int) $_POST['limit'], (int) $_POST['userType'], (int) $_POST['scope'], false);
         case 'get_user_or_company_info':
             return $this->getUserOrCompanyRecord();
         case 'getsms':
             require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/registration.php';
             $registration = new registration();
             $registration->listenerAction(__paramInit('string', null, 'action'));
     }
     return false;
 }
 /**
  * Добавляем категории профессий в фильтр
  *
  * @param arrya $category Категории
  * @return string Сообщение об ошибке
  */
 function addGroup($category)
 {
     include_once realpath(dirname(__FILE__)) . '/professions.php';
     $added = array();
     if (get_uid(false)) {
         if ($this->fid > 0) {
             global $DB;
             $sql = "DELETE FROM freelancers_filters_group WHERE filter_id = ?";
             $DB->query($sql, $this->fid);
             $all_mirrored_specs = professions::GetAllMirroredProfsId();
             $mirrored_specs = array();
             for ($is = 0; $is < sizeof($all_mirrored_specs); $is++) {
                 $mirrored_specs[$all_mirrored_specs[$is]['main_prof']] = (int) $all_mirrored_specs[$is]['mirror_prof'];
                 $mirrored_specs[$all_mirrored_specs[$is]['mirror_prof']] = (int) $all_mirrored_specs[$is]['main_prof'];
             }
             $sql = "";
             function isMirrored($group_id, $level, $mirrored_specs, $added)
             {
                 if (!empty($mirrored_specs[$group_id]) && isset($added[$mirrored_specs[$group_id]])) {
                     return true;
                 }
             }
             if (count($category) > 0) {
                 foreach ($category as $level => $ids) {
                     foreach ($ids as $group_id => $val) {
                         if (!(int) $group_id) {
                             continue;
                         }
                         if (isMirrored($group_id, $level, $mirrored_specs, $added) || !empty($added[(int) $group_id])) {
                             continue;
                         }
                         $sql .= "INSERT INTO freelancers_filters_group (filter_id, group_id, level) VALUES ('{$this->fid}', '" . intval($group_id) . "', '" . intval($level) . "');";
                         if (!(int) $level) {
                             $subs = professions::GetProfs($group_id);
                             foreach ($subs as $itm) {
                                 $added[$itm['id']] = true;
                             }
                         } else {
                             $added[(int) $group_id] = true;
                         }
                     }
                 }
                 if (!$sql) {
                     return false;
                 }
                 $DB->squery($sql);
                 return $DB->error;
             }
         }
     } else {
         $_SESSION['f_freelancers_filter']['f_freelancers_category'] = $category;
         $_SESSION['f_freelancers_filter']['freelancers_filters_group'] = array();
         $all_mirrored_specs = professions::GetAllMirroredProfsId();
         $mirrored_specs = array();
         for ($is = 0; $is < sizeof($all_mirrored_specs); $is++) {
             $mirrored_specs[$all_mirrored_specs[$is]['main_prof']] = (int) $all_mirrored_specs[$is]['mirror_prof'];
             $mirrored_specs[$all_mirrored_specs[$is]['mirror_prof']] = (int) $all_mirrored_specs[$is]['main_prof'];
         }
         $sql = "";
         function isMirrored($group_id, $level, $mirrored_specs, $added)
         {
             if (!empty($mirrored_specs[$group_id]) && isset($added[$mirrored_specs[$group_id]])) {
                 return true;
             }
         }
         $data = array();
         if (count($category) > 0) {
             foreach ($category as $level => $ids) {
                 foreach ($ids as $group_id => $val) {
                     $tdata = array();
                     if (!(int) $group_id) {
                         continue;
                     }
                     if (isMirrored($group_id, $level, $mirrored_specs, $added) || !empty($added[(int) $group_id])) {
                         continue;
                     }
                     $tdata['group_id'] = intval($group_id);
                     $tdata['level'] = intval($level);
                     $data[] = $tdata;
                     $sql = '1';
                     if (!(int) $level) {
                         $subs = professions::GetProfs($group_id);
                         foreach ($subs as $itm) {
                             $added[$itm['id']] = true;
                         }
                     } else {
                         $added[(int) $group_id] = true;
                     }
                 }
             }
             if (!$sql) {
                 return false;
             }
             $_SESSION['f_freelancers_filter']['freelancers_filters_group'] = $data;
             return;
         }
     }
     return false;
 }