/var/www/doncode.com.ua/www/models
Edit: /var/www/doncode.com.ua/www/models/class.news_model.php (7721B)
database->prepare('SELECT count(id) as `count` FROM `mobile_users` WHERE `deleted`=\'0\'; ');
$sth->execute();
return $sth->fetch ();
}
public function getTypeContractor (){
try{
$sth = $this->database->prepare("SELECT * FROM `news`");
$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 `id`,`news`,`datetime` FROM `news` WHERE `deleted`='0' 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();
$mess_ids = "";
$record = 1+($page_number);
foreach($arr as $k => $v){
$arr[$k]['nn'] = $record;
$record++;
if($mess_ids != ""){
$mess_ids = ",".$mess_ids;
}
$mess_ids = $arr[$k]['id'].$mess_ids;
}
echo json_encode($arr);
}else{
if($page_number==0){
ajax::fail( 'мало клиентов , а это очень грутсно :(' );
return false;
}
$page_number-=1;
$this->clientsGetList($page_number);
}
}
public function deleteRecords($id){
$sth=$this->database->prepare("UPDATE `news` 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 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 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['mobile_users']." обновлены.");
$this->database->log("Данные клиента ".$data['mobile_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('mobile_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."mobile_users");
}
exit;
}
public function search ($ch,$type){
try{
$char = $this->database->quote('%'.$ch.'%');
$sth = $this->database->prepare("SELECT `id`,`name` FROM `mobile_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 `mobile_users` c INNER JOIN `type_mobile_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 ;
}
}
}