/var/www/doncode.com.ua/www/models
Edit: /var/www/doncode.com.ua/www/models/class.users_model.php (9154B)
form->post('number','номер телефона')->val('digit')->val('emptyStr');
$this->form->submit();
$data = $this->form->fetch();
}catch(Exception $e){
ajax::fail($e->getMessage());
return false;
}
try{
$sth = $this->database->prepare ("SELECT `id`,`name`,`pincode`,`gid`,`reg_date`,`last_date`,`last_sms`,`city_id`,`auto_type`,`partner` FROM `users` WHERE `deleted`=0 LIMIT 1 ");
if (strlen($data['number'])>10){
$number = substr($data['number'],strlen($data['number'])-10);
}else{
$number = $data['number'];
}
$sth->execute(array(
':phone'=> $number)
);
}catch(PDOException $e){
ajax::fail($e->getMessage());
return false;
}
if($sth->rowCount()==0){
echo json_encode(array('none'=>time()));
return false;
}else{
echo json_encode($sth->fetch());
}
}
public function fetchSingleRecordsFromCode(){
$msg_fail = "Не найден пользователь. ";
try{
$this->form->post('code')->val('emptyStr');
$this->form->submit();
$data = $this->form->fetch();
}catch(Exception $e){
ajax::fail( $msg_fail.$e->getMessage() );
return false;
}
try{
$sth = $this->database->prepare("SELECT * FROM `users` WHERE `deleted`='0' AND `deleted` ='0' LIMIT 1;");
$sth->execute(array(':code'=>$data['code']));
}catch(PDOException $e){
ajax::fail( $msg_fail );
return false;
}
if ($sth->rowCount() > 0)
echo json_encode($sth->fetch());
else
ajax::fail( $msg_fail );
}
public function getTypeContractor (){
try{
$sth = $this->database->prepare("SELECT * FROM `users`");
$sth->execute();
return $sth->fetchAll();
}catch(PDOException $e){
return array();
}
}
public function clientsGetList ($page=0){
if ($page!=0){
$page_number=abs(($page-1)*LIMIT);
}else{
$page_number=0;
}
try{
$sth=$this->database->prepare("SELECT * FROM `users` LIMIT $page_number , ".LIMIT." ");
$sth->execute();
}catch(PDOException $e){
ajax::fail($e->getMessage());
return false;
}
$max_sum_call = 0;
if($sth->rowCount()>0){
$arr= $sth->fetchAll();
echo json_encode($arr);
}else{
if($page_number==0){
ajax::fail( 'нет DCC, а это очень грутсно :(' );
return false;
}
$page_number-=1;
$this->clientsGetList($page_number);
}
}
public function fetchSingleRecordsFromId ($id,$ajax=true){
$sth=$this->database->prepare("SELECT d.*,c.city_name_ru as cName, co.country_name_ru as coName FROM `dcc` d INNER JOIN `city_` c ON (d.city_id=c.id_city) INNER JOIN `country_` co ON (co.id_country=c.id_country) WHERE d.deleted='0' AND `id`=:id");
$sth->execute(array(':id'=>$id));
if ($ajax){
echo json_encode($sth->fetch());
}else{
return $sth->fetch();
}
}
public function get_pay_type ($ajax=true){
$sth=$this->database->prepare("SELECT * FROM `pay_type` WHERE deleted='0'");
$sth->execute();
if ($ajax){
echo json_encode($sth->fetch());
}else{
return $sth->fetchAll();
}
}
public function deleteRecords($id){
$sth=$this->database->prepare("UPDATE `users` SET `deleted`='1' WHERE `id`=$id ;");
$sth->execute();
if ($sth->rowCount()>0){
echo json_encode(array('msg'=>'success'));
$this->database->log('Удален клиент id='.$id);
}else{
echo json_encode(array('msg'=> 'fail'));
$this->database->log('Не удалось удалить клиента id='.$id);
}
}
public function saveEditRecords ( ){
try{
$this->form->post('id')->val('digit')->val('zeroField')
->post('name')
->post('pincode')
->post('gid')
->post('reg_date')
->post('last_date')
->post('last_sms')
->post('city_id')
->post('auto_type')
->post('partner');
$this->form->submit();
$data = $this->form->fetch();
if(isset($data['obmen'])){
if($data['obmen']=='on'){
$data['obmen']=1;
}else{
$data['obmen']=0;
}
}else{
$data['obmen']=0;
}
if(isset($data['internet'])){
if($data['internet']=='on'){
$data['internet']=1;
}else{
$data['internet']=0;
}
}else{
$data['internet']=0;
}
}catch(Exception $e){
ajax::fail($e->getMessage());
$this->database->log('Не удалось обновить данные DCC '.$e->getMessage() );
return false;
}
try{
$id=$data['id'];
unset($data['id']);
$this->database->update('dcc',$data,'id='.$id);
}catch(PDOException $e){
ajax::fail($e->getMessage());
$this->database->log('Не удалось обновить данные DCC '.$e->getMessage() );
return false;
}
ajax::success("Данные клиента ".$data['users']." обновлены.");
$this->database->log("Данные клиента ".$data['users']." обновлены." );
}
public function createContractor(){
try{
$this->form->post('FIO','ФИО')->val('emptyStr')
->post('email')
->post('phone','телефон')->val('emptyStr')
->post('adress')
->post('town')
->post('discount')
->post('code_clients')
->post('type');
$this->form->submit();
$data = $this->form->fetch();
}catch(Exception $e){
if(ajax::check_ajax_request()){
ajax::fail($e->getMessage());
}else{
session::set('msgFail',$e->getMessage());
$this->database->log('Не удалось создать контрагента '.$e->getMessage() );
header("Location:".$_SERVER["HTTP_REFERER"]);
}
exit;
}
try{
$this->database->insert('users',$data);
}catch(PDOException $e){
session::set('msgFail',$e->getMessage());
$this->database->log('Не удалось создать контрагента '.$data['FIO']);
header("Location:".$_SERVER["HTTP_REFERER"]);
exit;
}
if(ajax::check_ajax_request()){
ajax::success("Создан контрагент ".$data['FIO']);
}else{
session::set('msgSuccess',"Создан контрагент ".$data['FIO']);
$this->database->log('Создан контрагент '.$data['FIO']);
header("Location:".URL."users");
}
exit;
}
public function search ($ch,$type){
try{
$char = $this->database->quote('%'.$ch.'%');
$sth = $this->database->prepare("SELECT `id`,`name` FROM `users` WHERE `$type` LIKE $char AND `deleted`='0' LIMIT ".LIMIT);
$sth->execute( );
ajax::out($sth->fetchAll());
} catch (Exception $e){
ajax::fail($e->getMessage());
return false;
}
}
public function fetechContractor ($id){
try{
$sth = $this->database->prepare("SELECT c.*,t.name as tName FROM `users` c INNER JOIN `type_users` t ON (c.type=t.id) WHERE c.deleted='0' AND c.id=:id LIMIT 1 ");
$sth->execute(array(':id'=>$id));
ajax::out($sth->fetchAll());
return;
}catch(PDOException $e){
ajax::fail($e->getMessage());
return ;
}
}
}