/**
  * Обрабатывает 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;
 }
Esempio n. 2
0
<?php

define('IS_PHP_JS', true);
require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/stdf.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/city.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/country.php';
$membuf = new memBuff();
$memkey = 'b-combo-getcitiesandcountries';
$s = 0;
//$membuf->get($memkey);
if (!$s) {
    $rows = country::GetCountriesByCountUser();
    $result = array(0 => "'0' : 'Все страны'");
    foreach ($rows as $k => $i) {
        $i['name'] = str_replace('"', '"', $i['name']);
        $result[$i['id']] = str_replace("'", "\\'", $i['name']);
    }
    //города России 1
    $rows = city::GetCities(1);
    $cResult = array('0' => "'0' : 'Россия'", 'undefined_value' => "'undefined_value' : 'Все города'");
    foreach ($rows as $k => $i) {
        $i = str_replace('"', '"', $i);
        $i = str_replace("'", "\\'", $i);
        $cResult[$k] = "'{$k}' : '{$i}'";
    }
    $result[1] = $cResult;
    //города Украины 2
    $rows = city::GetCities(2);
    $cResult = array('0' => "'0' : 'Украина'", 'undefined_value' => "'undefined_value' : 'Все города'");
    foreach ($rows as $k => $i) {
        $i = str_replace('"', '"', $i);