/var/www/doncode.com.ua/www/models
Edit: /var/www/doncode.com.ua/www/models/class.exchange_model.php (8266B)
database->prepare("SELECT tg.*
FROM `".DB_PREFIX."tarifs` t
INNER JOIN `".DB_PREFIX."tarif_groups` tg ON tg.id = t.category_id
WHERE t.city_id={$city_id} AND t.deleted='0' AND t.active='1' ORDER BY tg.position");
$sth->execute();
$res = $sth->fetchAll(PDO::FETCH_ASSOC);
}catch(PDOException $e){
return $e->getMessage();
}
//var_export($res);exit;
foreach($res as $k => $v){
$ans[$v['id']] = $v;
}
return $ans;
}
public function saveExchangeTarif(){
$id = intval($_POST['id']);
$update['active'] = (isset($_POST['active'])&&($_POST['active']=='checked'))?1:0;
$update['cost'] = $_POST['cost'];
$update['km_free'] = $_POST['km_free'];
$update['km_cost'] = $_POST['km_cost'];
$update['wait_free'] = $_POST['wait_free'];
$update['wait_cost'] = $_POST['wait_cost'];
$count = $this->database->update(DB_PREFIX.'tarif_groups',$update,"id=".$id);
if($count>0){
ajax::success(true);
}else{
echo '{"fail":"Ошибка сохранения тарифа!"}';
}
}
public function addExchangeTarif($exchange_id=0,$category_id=0){
if($exchange_id>0&&$category_id>0){
$count = $this->database->update(DB_PREFIX.'exchange_tarifs',array(
'deleted' =>'0',
'change_date' =>date("Y-m-d H:i:s")
),"exchange_id=".$exchange_id." AND category_id=".$category_id."");
if($count==0){
$insertid = $this->database->insert(DB_PREFIX.'exchange_tarifs',array(
'category_id' =>$category_id,
'exchange_id' =>$exchange_id
));
if($insertid>0){
return $insertid;
}
}
}
return 0;
}
public function deleteExchangeTarif($tar_id=0){
if($tar_id>0){
$count = $this->database->update(DB_PREFIX.'exchange_tarifs',array(
'deleted' =>'1',
'active' =>'0',
'change_date' =>date("Y-m-d H:i:s")
),"id=".$tar_id."");
if($count>0){
return true;
}
}
return false;
}
public function getExchangeTarifs($exchange_id){
$sth = $this->database->prepare("SELECT t.*,et.*
FROM `".DB_PREFIX."exchange_tarifs` et
INNER JOIN `".DB_PREFIX."tarif_groups` tg ON tg.`id` = et.`category_id`
INNER JOIN `".DB_PREFIX."exchange` e ON e.`id` = et.`exchange_id`
INNER JOIN `".DB_PREFIX."tarifs` t ON t.`city_id` = e.`city_id` AND t.`category_id` = et.`category_id`
WHERE et.deleted='0' AND et.exchange_id=".$exchange_id." ORDER BY tg.`position`");
$sth->execute();
$res = $sth->fetchAll(PDO::FETCH_ASSOC);
return $res;
}
public function save_photo($fn,$exchange_id){
if(isset($_POST['data'])){
$path = PATH_EXCHANGE_IMAGES.$exchange_id;
if(!is_dir($path)){
mkdir($path);
}
if(bootstrap::base64_to_jpeg($_POST['data'],$path.'/'.$fn.'.jpg')){
echo '{"status":"success","url":"'.$path.'/'.$fn.'.jpg"}';
exit;
}
}
$save = false;
if($save){
//$json = session::set('json',$json);
ajax::success(true);
}else{
echo '{"error":"Ошибка сохранения"}';
exit;
}
}
//-----------------------------
public function getExchangeSettings($exchange_id){
$sth = $this->database->prepare("SELECT e.json
FROM `".DB_PREFIX."exchange` e
WHERE e.deleted='0' AND e.id=".$exchange_id."");
$sth->execute();
$res = $sth->fetchAll(PDO::FETCH_ASSOC);
return json_decode($res[0]['json'],true);
}
public function saveExchangeSettings(){
$id = intval($_POST['id']);
$update['taxi_name'] = (isset($_POST['taxi']))?$_POST['taxi']:"";
$update['director'] = (isset($_POST['director']))?$_POST['director']:"";
$update['director_phone'] = (isset($_POST['director_phone']))?$_POST['director_phone']:"";
$j['web_site'] = (isset($_POST['web_site']))?$_POST['web_site']:"";
$j['web_view'] = (isset($_POST['web_view']))?$_POST['web_view']:"";
$j['show_pr'] = (isset($_POST['show_pr']))?$_POST['show_pr']:0;
$j['show_bn'] = (isset($_POST['show_bn']))?$_POST['show_bn']:0;
$j['show_card'] = (isset($_POST['show_card']))?$_POST['show_card']:0;
$j['show_cost'] = (isset($_POST['show_cost']))?$_POST['show_cost']:0;
$j['show_phone_numbers'] = (isset($_POST['show_phone_numbers']))?$_POST['show_phone_numbers']:0;
$j['show_phone_driver'] = (isset($_POST['show_phone_driver']))?$_POST['show_phone_driver']:0;
$j['orders_only_for_me'] = (isset($_POST['orders_only_for_me']))?$_POST['orders_only_for_me']:0;
$j['orders_first_for_me'] = (isset($_POST['orders_first_for_me']))?$_POST['orders_first_for_me']:0;
//$j['phone_codes'] = (isset($_POST['phone_codes']))?$_POST['phone_codes']:array();
//$j['phone_numbers'] = (isset($_POST['phone_numbers']))?$_POST['phone_numbers']:array();
$update['json'] = bootstrap::json_encode__($j);
//$update['taxi'] = $_POST['taxi'];
//$update['km_free'] = $_POST['km_free'];
//$update['km_cost'] = $_POST['km_cost'];
//$update['wait_free'] = $_POST['wait_free'];
//$update['wait_cost'] = $_POST['wait_cost'];
$count = $this->database->update(DB_PREFIX.'exchange',$update,"id=".$id);
if($count>0){
ajax::success(true);
}else{
echo '{"fail":"Ошибка сохранения настроек!"}';
}
}
public function activate_apikey(){
$apikey =isset($_POST['apikey'])?$_POST['apikey']:0;
$exchange_id = session::get('exchange_id');
$sth = $this->database->prepare("SELECT * FROM `".DB_PREFIX."dcc` WHERE `key`=:key AND `block`='0';");
$sth->execute(array(':key' => $apikey));
$count = $sth->rowCount();
if ($count > 0) {
$data = $sth->fetch(PDO::FETCH_ASSOC);
$rowcount = $this->database->update(DB_PREFIX.'exchange',array(
'dcc_id' =>$data['id'],
'taxi_name' =>$data['taxi_name'],
'city_id' =>$data['city_id']
),"id={$exchange_id}");
if($rowcount>0){
$this->changeExchange($exchange_id);
//$json = session::set('json',$json);
ajax::success(true);
}else{
echo '{"fail":"Ошибка активации API ключа!"}';
exit;
}
}
}
public function getExchangePhones($exchange_id){
$sth = $this->database->prepare("SELECT ep.*
FROM `".DB_PREFIX."exchange_phones` ep
WHERE ep.deleted='0' AND ep.exchange_id=".$exchange_id." ORDER BY position");
$sth->execute();
$res = $sth->fetchAll(PDO::FETCH_ASSOC);
return $res;
}
public function addExchangePhone($exchange_id=0){
if($exchange_id>0){
$name =isset($_POST['name'])?$_POST['name']:'';
$phone =isset($_POST['phone'])?$_POST['phone']:'';
$position =isset($_POST['position'])?$_POST['position']:'';
$insertid = $this->database->insert(DB_PREFIX.'exchange_phones',array(
'name' =>$name,
'phone' =>$phone,
'position' =>$position,
'exchange_id' =>$exchange_id
));
if($insertid>0){
ajax::success(true);
return;
}
}
ajax::fail('Ошибка добавления телефонв');
}
public function deleteExchangePhone($id=0){
if($id>0){
$count = $this->database->update(DB_PREFIX.'exchange_phones',array(
'deleted' =>'1'
),"id=".$id."");
if($count>0){
return true;
}
}
return false;
}
public function saveExchangePhone($id=0){
if($id>0){
$name =isset($_POST['name'])?$_POST['name']:'';
$phone =isset($_POST['phone'])?$_POST['phone']:'';
$position =isset($_POST['position'])?$_POST['position']:'';
$count = $this->database->update(DB_PREFIX.'exchange_phones',array(
'name' =>$name,
'position' =>$position,
'phone' =>$phone
),"id=".$id."");
if($count>0){
ajax::success(true);
return true;
}
}
ajax::fail('Ошибка созранения телефона');
return false;
}
}
?>