<?php
class ManagersController extends AppController
{
//--- Variables
var $uses = array('User', 'Order', 'Service', 'Product', 'Transaction', 'Payment', 'News', 'Page', 'Menu', 'Slideshow', 'Customer' , 'Setting' , 'Message' , 'Property' , 'Productproperty', 'Ticket', 'Ticketreply','Cardcharge', 'Api', 'Ticketdepartment');
var $components = array('Whois', 'Jtime' , 'Email');
var $helpers = array('Html', 'Form', 'Session', 'Javascript', 'Paginator');
var $paginate = array('limit' => 15);
var $setting;
function beforeFilter ()
{
$this -> setting = $this->Setting->find();
$this -> setting = $this->setting['Setting'];
$this->Auth->fields = array(
'username' => 'email',
'password' => 'password'
);
$this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'home');
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
$this->Auth->autoRedirect = false;
$this->Auth->allow('mailForPay', 'remote');
$this->Auth->loginError="نام کاربری یا رمز عبور اشتباه است";
$this->Auth->authError="شما اجازه دسترسی به این بخش را ندارید";
if($this->Auth->user('role') < 1) $this->redirect('/');
$this->layout = 'admin';
}
function beforeRender()
{
parent::beforeRender();
$this->pageTitle = '- '. __('Management Panel',true);
}
function home()
{
$total_unconfirmed_total = $this->Transaction->find('first', array( 'conditions' => array('Transaction.confirmed' => 0),
'fields' => array('COUNT(Transaction.id) as tot')
)
);
$total_unconfirmed_amount = $this->Transaction->find('first', array( 'conditions' => array('Transaction.confirmed' => 0),
'fields' => array('SUM(Transaction.amount) as tot')
)
);
$total_order_confirmed = $this->Order->find('first', array( 'conditions' => array('Order.confirmed' => 1),
'fields' => array('COUNT(Order.id) as tot')
)
);
$total_notchecked_cardcharge = $this->Cardcharge->find('first', array( 'conditions' => array('Cardcharge.user_id !=' => 0, 'Cardcharge.admin_check' => 0),
'fields' => array('COUNT(Cardcharge.id) as tot')
)
);
$near_elapsed=$this->nearPay(7,0,true);
$ticket_urgent=$this->Ticket->find('first',array('conditions'=>array('Ticket.st atus' => array('0','2') ) ,'fields'=>array( 'COUNT(Ticket.id) as tot')));
$tickets=$this->Ticket->find('first',array('conditions'=>array('Ticket.st atus' => array('0','2' , '4' ,'3') ) ,'fields'=>array( 'COUNT(Ticket.id) as tot')));
$this->set('total', array('transaction_unconfirmed_total' => $total_unconfirmed_total[0]['tot'],
'transaction_unconfirmed_amount' => $total_unconfirmed_amount[0]['tot'],
'order_confirmed' => $total_order_confirmed[0]['tot'],
'near_elapsed' => $near_elapsed,
'tickets'=> $tickets[0]['tot'] ,
'ticket_urgent' => $ticket_urgent[0]['tot'],
'notchecked_cardcharge' => $total_notchecked_cardcharge[0]['tot'])
);
}
function users($operation = 'all')
{
if($operation =='all')
$this->set('client',$this->paginate('User'));
elseif($operation =='unconfirmed')
$this->set('client',$this->paginate('User',array('User.role'=> '-1')));
}
function referred_users($id)
{
$referrer_client=$this->User->findById($id);
$this->set('referrer_client',$referrer_client);
$this->set('client',$this->paginate('User',array('User.referrer_id '=> $id)));
}
function user_search()
{
$this->layout = 'ajax';
$data = $this->User->find('all', array('conditions' => array('User.name LIKE'=>'%'.$_POST['query'].'%')));
foreach($data as $row)
{
$table.='<tr>
<td>'. $row['User']['id'].'</td><td>'.$row['User']['name'].'</td>
<td>'. $row['User']['company'].'</td>
<td>';
if($row['User']['role']=='1')
$table.= '<span style= "color:orange;"><b>ادمين</b></span>';
elseif($row['User']['role']=='0')
$table.='<span style= "color : green;"><b>مشتري</b></span>';
elseif($row['User']['role']=='-1')
$table.= '<span style= "color : red;"><b>تاييد نشده</b></span>';
$table.='
</td>
<td>
<a href="/managers/contact/'.$row['User']['id'].'"><img src="/themed/asrenet/img/icons/profile.png" title="مشخصات مشتری" /></a>
<a href="/managers/add_order/'.$row['User']['id'].'"><img src="/themed/asrenet/img/icons/add.png" title="افزودن سفارش" /></a>
<a href="/managers/orders/user_orders/'.$row['User']['id'].'"><img src="/themed/asrenet/img/icons/orders.png" title="سفارشات و گرفتن فاکتور" /></a>
<a onclick="return confirm("آیا مطمئنید می خواهید این کاربر را حذف کنید ؟");" title="حذف کاربر" href="/managers/user_delete/'.$row['User']['id'].'">
<img alt="" src="/themed/asrenet/img/icons/unconfirm.png"/>
</a>';
if($row['User']['role']=='-1')
{
$table.='<a onclick="return confirm("آیا مطمئنید می خواهید این کاربر را تایید کنید؟ (بعد از تایید پست الکترونیکی به کاربر فرستاده می شود)");" title="تایید کابر" href="/managers/user_confirm/38">
<img alt="" src="/themed/asrenet/img/icons/confirm.png"/>
</a>';
}
if($row['User']['role']=='0')
$table.='<a title="افزودن اعتبار" href="/managers/add_transaction/'.$row['User']['id'].'">
<img alt="" src="/themed/asrenet/img/icons/pay.png"/>
</a>';
$table.='</td>
</tr>';
}
echo $table;
}
function mailForPay($day)
{
$this->layout='ajax';
$data=$this->nearPay($day,$day-1);
foreach($data as $order)
{
if($this -> setting['send_email']==1)
{
$user=$this->User->findById($order['Order']['user_id']);
$this->set('info',$order);
$this->Email->to = $user['User']['email'];
$this->Email->from = $this -> setting['mail_title'].' <'.$this -> setting['mail_address'].'>';
$this->Email->subject = $day.' روز تا انقضا سفارش شماره '.$order['Order']['id'];
$this->Email->template = 'mailForPay';
$this->Email->sendAs = 'html';
$this->Email->send();
}
}
}
function nearPay($day,$until=-1,$count=false)
{
$find = 'all';
if($until<0) $until = $day-1;
if($count==true) $find = 'count';
return $this->Order->find( $find ,array('conditions'=>array('Order.confirmed' => 2 , 'Order.next_pay <' => ($day*86400) + time() ,'Order.next_pay >' => (($until)*86400) + time() ) , 'recursive' => 2));
}
function order_confirm($id)
{
$order = $this->Order->findById($id);
$product = $this->Product->findById($order[Order][product_id]);
$costs = $this->costs($product['Product']['cost']);
$user=$this->User->findById($order['Order']['user_id']);
$this->set('client',$user);
$this->set('id',$id);
$ineditor = '
سفارش شما با فاکتور زير تاييد شد:<br>
<center><table border="1">
<tr>
<td>
نام سرویس
</td>
<td>
نام محصول
</td>
<td>
قيمت (تومان)
</td>
<td>
تاریخ سفارش
</td>
<td>
توضيحات
</td>
</tr>
<tr>
<td>
'.$product[Service][name].'
</td>
<td>
'.$product[Product][name].'
</td>
<td>
'.($costs[$order[Order][monthly]]-$order[Order][discount]).'
</td>
<td>
'.$this->Jtime->pdate("Y/n/j", $order[Order][date]).'
</td>
<td>
'.$order[Order][desc].'
</td>
</table></center>';
$this->set('ineditor',$ineditor);
if(isset($this->data))
{
$this->set('info',$this->data);
$this->set('setting',$this->setting);
$this->Email->to = $user['User']['email'];
$this->Email->from = $this -> setting['mail_title'].' <'.$this -> setting['mail_address'].'>';
$this->Email->subject = 'سفارش شماره '.$order['Order']['id'].' مورد تایید قرار گرفت';
$this->Email->template = 'orderconf';
$this->Email->sendAs = 'html';
$this->Email->send();
$this->Order->id = $id;
$data = $this->Order->read();
$data['Order']['confirmed'] = 2;
$this->Order->save($data);
$this->Session->setFlash('سفارش مورد نظر تایید شد و پست الکترونیکی فرستاده شد.', 'default', array('class' => 'success-msg'));
$this->redirect(array('controller' => 'managers', 'action' => 'orders'));
}
}
function contact($id)
{
$user=$this->User->findById($id);
$this->set('client',$user);
$referrer_client=$this->User->findById($user['User']['referrer_id']);
$this->set('referrer_client',$referrer_client);
$this->set('referred_sum',$this->User->find('count', array('conditions' =>array('User.referrer_id'=>$id))));
if(isset($this->data))
{
$this->set('info',$this->data);
$this->Email->to = $user['User']['email'];
$this->Email->from = $this -> setting['mail_title'].' <'.$this -> setting['mail_address'].'>';
$this->Email->subject = $this->data['Contact']['subject'];
$this->Email->template = 'contact';
$this->Email->sendAs = 'html';
$this->Email->send();
$this->Session->setFlash('پست الکترونیکی فرستاده شد.', 'default', array('class' => 'success-msg'));
$this->redirect(array('controller' => 'managers', 'action' => 'home'));
}
}
function orders ($operation = null,$id=null)
{
if($operation == 'delete'){
$this->Order->id = $id;
$order=$this->Order->read();
$this->Order->del();
$this->Session->setFlash('سفارش مورد نظر حذف شد', 'default', array('class' => 'success-msg'));
$this->redirect(array('controller' => 'managers', 'action' => 'orders'));
}elseif($operation=='before')
{
$this->set('orders',$this->Order->find('all',array('order' => 'Order.id DESC', 'recursive' => 2 , 'conditions'=>array('Order.confirmed' => 0))));
}elseif($operation == 'unconfirmed')
{
$this->set('orders',$this->Order->find('all',array('order' => 'Order.id DESC', 'recursive' => 2 , 'conditions'=>array('Order.confirmed' => 1))));
}elseif($operation == 'confirmed')
{
$this->set('orders',$this->Order->find('all',array('order' => 'Order.id DESC', 'recursive' => 2 , 'conditions'=>array('Order.confirmed' => 2))));
}elseif($operation == 'user_orders')
{
$this->set('orders',$this->Order->find('all',array('order' => 'Order.id DESC', 'recursive' => 2 , 'conditions'=>array('Order.user_id' => $id))));
$this->set('user_order' , '1');
}elseif($operation == 'near_elapsed')
{
$this->set('orders',$this->nearPay(7,0,false));
}else
{
$this->set('orders', $this->Order->find('all', array('order' => 'Order.id DESC','recursive' => 2,'conditions' => array('Order.confirmed >'=> -1 ))));
}
}
function add_order ($user_id,$product_id)
{
$this->set('id',$user_id);
if ( isset($product_id) )
{
$this->set('product',$this->Product->findById($product_id));
if(isset($this->data))
{
if($this->data['Order']['confirmed']!=0)
$this->data['Order']['next_pay'] = $this->Jtime->pmktime(0,0,0,$this->data['Order']['next_pay']['month'],$this->data['Order']['next_pay']['day'],$this->data['Order']['next_pay']['year']);
else
$this->data['Order']['next_pay']=0;
$this->data['Order']['user_id']=$user_id;
$this->data['Order']['date'] = time();
if ( $this->Order->save($this->data) )
{
$this->Session->setFlash('سفارش با موفقيت ثبت شد', 'default', array('class' => 'success-msg'));
$this->redirect('/managers/orders/user_orders/'.$user_id.'/');
}
else
{
$this->Session->setFlash('مشکلی در ثبت سفارش وجود دارد.', 'default', array('class' => 'error-msg'));
}
}
}else{
if(isset($this->data))
{
$this->redirect('/managers/add_order/'.$user_id.'/'.$this->data['Service']['product_id']);
}else
{
$this->set('services', $this->Service->find('all',array('order' => array('Service.name ASC'))));
$this->set('products', $this->Product->find('all'));
}
}
}
function edit_order ($id = null)
{
if ( $id )
{
$this->Order->id = $id;
if ( $this->data )
{
if(isset($this->data['Order']['next_pay']))
$this->data['Order']['next_pay'] = $this->Jtime->pmktime(0,0,0,$this->data['Order']['next_pay']['month'],$this->data['Order']['next_pay']['day'],$this->data['Order']['next_pay']['year']);
$this->data['Order']['date'] = time();
if ( $this->Order->save($this->data) )
{
$this->Session->setFlash('اطلاعات با موفقیت ثبت شد', 'default', array('class' => 'success-msg'));
}
else
{
$this->Session->setFlash('مشکلی در ثبت اطلاعات وجود دارد', 'default', array('class' => 'error-msg'));
}
}
$this->data = $this->Order->read();
}
//$this->set('id',$id);
//$this->set('service_id',$this->data['Product']['service_id']);
//$this->set('productid',$this->data['Product']['id']);
$monthles[1]=' ماهیانه';
$monthles[3]='3 ماهه';
$monthles[6]='6 ماهه';
$monthles[12]='سالیانه';
$monthles[24]='دو ساله';
$monthles[60]='پنج ساله';
$product = $this->Product->find('first',array('fields' => array('Product.cost'),'conditions' => array('Product.id' => $this->data['Order']['product_id']), 'recursive'=> -1));
$costs = $this->costs($product['Product']['cost']);
$this->set('cost',$costs[$this->data['Order']['monthly']]);
$this->set('monthles',$monthles);
$this->set('services', $this->Service->find('all'));
$this->set('products', $this->Product->find('list',array('fields' => array('Product.id','Product.name'),'conditions' => array('Product.service_id' => $this->data['Product']['service_id']))));
}
function slideshows ($delid = null)
{
if($delid)
{
$this->Slideshow->id=$delid;
$this->Slideshow->del();
}
$this -> set( 'slideshows' , $this->Slideshow->find('all',array('order'=>'Slideshow.id DESC')));
}
function add_slideshow()
{
if ( $this->data )
{
if ( $this->Slideshow->save($this->data) )
{
$this->Session->setFlash('اطلاعات با موفقیت ثبت شد', 'default', array('class' => 'success-msg'));
}
else
{
$this->Session->setFlash('مشکلی در ثبت اطلاعات وجود دارد', 'default', array('class' => 'error-msg'));
}
}
}
function edit_slideshow ($id = null)
{
if ( $id )
{
$this->Slideshow->id = $id;
if ( $this->data )
{
if ( $this->Slideshow->save($this->data) )
{
$this->Session->setFlash('اطلاعات با موفقیت ثبت شد', 'default', array('class' => 'success-msg'));
}
else
{
$this->Session->setFlash('مشکلی در ثبت اطلاعات وجود دارد', 'default', array('class' => 'error-msg'));
}
}
$this->data = $this->Slideshow->read();
}
}
function products ($delid = null)
{
if ( $delid )
{
$this->Product->delete($delid,false);
$productproperty=$this->Productproperty->find('all',array('conditions'=>array('Productprop erty.product_id'=>$delid)));
foreach ($productproperty as $row)
{
$this->Productproperty->delete($row['Productproperty']['id'],false);
}
$orders=$this->Order->find('all',array('conditions'=>array('Order.produ ct_id'=>$delid)));
foreach ($orders as $row1)
{
$this->Order->delete($row1['Order']['id'],false);
}
$this->Session->setFlash('محصول با موفقیت حذف شد', 'default', array('class' => 'success-msg'));
}
$this->paginate['order'] = array('Product.id' => 'DESC');
$this->set('products',$this->paginate('Product'));
//$this->set('products', $this->Product->find('all', array('order' => 'Product.id DESC')));
}
function add_product ()
{
if ( $this->data )
{
foreach($this->data['Product']['costs'] as $month => $cost)
{
$this->data['Product']['cost'] .= $month.','.$cost.':';
}
if ( $this->Product->save($this->data) )
{
foreach($this->data['Product']['property'] as $key=>$value)
{
$this->Productproperty->create();
$temp['Productproperty']['property_id']=$key;
$temp['Productproperty']['value']=$value;
$temp['Productproperty']['product_id']=$this->Product->id;
$this->Productproperty->save($temp);
}
$this->Session->setFlash('اطلاعات با موفقیت ثبت شد', 'default', array('class' => 'success-msg'));
$this->redirect('/managers/home');
}
else
{
$this->Session->setFlash('مشکلی در ثبت اطلاعات وجود دارد', 'default', array('class' => 'error-msg'));
}
}
$temp=$this->Service->find('all');
$option[-1]='انتخاب کنید';
foreach($temp as $row)
{
$option[$row['Service']['id']]=$row['Service']['name'];
}
$this->set('options',$option);
}
function edit_product ($id = null)
{
if ( $id )
{
$this->Product->id = $id;
if ( $this->data )
{
$product=$this->Product->read();
$price=$this->costs($product['Product']['cost']);
if(!empty($price))
{
$this->data['Product']['cost']='';
foreach($price as $month => $cost)
{
$flag=false;
foreach($this->data['Product']['costs'] as $month2 => $cost2)
{
if($month==$month2)
{
$this->data['Product']['cost'] .=$month2.','.$cost2.':';
$flag=true;
}
}
if(!$flag)
{
$this->data['Product']['cost'] .=$month.','.$cost.':';
}
}
}else
{
$this->data['Product']['cost']='';
foreach($this->data['Product']['costs'] as $month => $cost)
{
$this->data['Product']['cost'] .= $month.','.$cost.':';
}
}
if ( $this->Product->save($this->data) )
{
foreach($this->data['Product']['oldproperty'] as $key=>$value)
{
$this->Productproperty->id=$key;
$temp['Productproperty']['value']=$value;
$this->Productproperty->save($temp);
}
foreach($this->data['Product']['newproperty'] as $key=>$value)
{
$this->Productproperty->create();
$temp2['Productproperty']['product_id']=$this->Product->id;
$temp2['Productproperty']['property_id']=$key;
$temp2['Productproperty']['value']=$value;
$this->Productproperty->save($temp2);
}
$this->Session->setFlash('اطلاعات با موفقیت ثبت شد', 'default', array('class' => 'success-msg'));
$this->redirect('/managers/products');
}
else
{
$this->Session->setFlash('مشکلی در ثبت اطلاعات وجود دارد', 'default', array('class' => 'error-msg'));
}
}else
{
$product=$this->Product->find('first',array('conditions'=>array('Product.i d'=>$id),'recursive'=>3));
$inputs='<div id="productproperty">';
foreach($product['Service']['Property'] as $property)
{
$productproperty=$this->Productproperty->find('first',array('conditions'=>array('Productpr operty.property_id'=>$property['id'],'Productproperty.product_id'=>$id)));
if(isset($productproperty['Productproperty']['id']))
$inputs .='<label>'.$property['name'] .' :</label><input name="data[Product][oldproperty]['.$productproperty['Productproperty']['id'].']" type="text" value="'.$productproperty['Productproperty']['value'].'" /><br /><br />';
else
$inputs .='<label>'.$property['name'] .' :</label><input name="data[Product][newproperty]['.$property['id'].']" type="text" value="" /><br /><br />';
}
$costs=$this->costs($product['Product']['cost']);
$monthly = $product['Service']['monthly'];
if($monthly-60 >= 0)
{
$period[]='60';
$monthly=$monthly-60;
}
if($monthly-24 >= 0)
{
$period[]='24';
$monthly=$monthly-24;
}
if($monthly-12 >= 0)
{
$period[]='12';
$monthly=$monthly-12;
}
if(($monthly-6) >= 0)
{
$period[]='6';
$monthly=$monthly-6;
}
if(($monthly-3) >= 0)
{
$period[]='3';
$monthly=$monthly-3;
}
if(($monthly-1) >= 0)
{
$period[]='1';
$monthly=$monthly-1;
}
foreach($period as $row)
{
$inputs .='<label> قیمت '.$row .' ماهه'.' :</label><input name="data[Product][costs]['.$row.']" type="text" value="'.$costs[$row].'" /><br /><br />';
}
$inputs.='</div>';
$this->set('inputs',$inputs);
$this->data = $this->Product->read();
}
}
}
function transactions ($operation = null, $id = null)
{
if ( $operation == 'confirm' )
{
$this->Transaction->id = $id;
$this->data['Transaction']['confirmed'] = 1;
$this->Transaction->save($this->data);
$trans=$this->Transaction->findById($id);
$credit=$this->Transaction->find('first', array( 'conditions' => array('Transaction.user_id' => $trans['User']['id'], 'Transaction.confirmed' => 1), 'fields' => array('SUM(Transaction.amount) as tot')));
if($this -> setting['send_email']==1)
{
$this->set('trans',$trans);
$this->set('credit',$credit[0]['tot']);
$this->set('setting',$this->setting);
$this->Email->to = $trans['User']['email'];
$this->Email->from = $this -> setting['mail_title'].' <'.$this -> setting['mail_address'].'>';
$this->Email->subject = 'تراکنش به ارزش '.$trans['Transaction']['amount']. ' تومان تایید شد.';
$this->Email->template = 'transconf';
$this->Email->sendAs = 'html';
$this->Email->send();
}
$this->Session->setFlash('تراکنش با موفقیت تایید شد.', 'default', array('class' => 'success-msg'));
$this->redirect('/managers/transactions');
}
elseif ( $operation == 'unconfirmed' )
{
$this->set('transactions', $this->Transaction->find('all', array('conditions' => array('Transaction.amount >' => '0', 'Transaction.confirmed' => '0'), 'order' => 'Transaction.id DESC')));
}
elseif ( $operation == 'confirmed' )
{
$this->set('transactions', $this->Transaction->find('all', array('conditions' => array('Transaction.amount >' => '0', 'Transaction.confirmed' => '1'), 'order' => 'Transaction.id DESC')));
}
elseif ( $operation == 'delete' )
{
$this->Transaction->id = $id;
$data=$this->Transaction->read();
if($data['Transaction']['confirmed']==0)
$this->Transaction->del();
else
{
$data['Transaction']['confirmed']=0;
$this->Transaction->id = $id;
$this->Transaction->save($data);
}
$this->Session->setFlash('تراکنش مورد نظر حذف يا تاييد نشده گرديد.', 'default', array('class' => 'success-msg'));
$this->redirect('/managers/transactions');
}
else
{
$this->set('transactions', $this->Transaction->find('all', array('conditions' => array('Transaction.amount >' => '0'), 'order' => 'Transaction.id DESC')));
}
}
function add_transaction($user_id=null)
{
if($this->data)
{
$this->data['Transaction']['user_id']=$user_id;
$this->data['Transaction']['date']=time();
$this->data['Transaction']['confirmed']=1;
if($this->Transaction->save($this->data))
{
$this->Session->setFlash('اطلاعات با موفقیت ثبت شد', 'default', array('class' => 'success-msg'));
}else
{
$this->Session->setFlash('مشکلی در ثبت اطلاعات وجود دارد', 'default', array('class' => 'error-msg'));
}
}
$this->set('id',$user_id);
$this->set('payment',$this->Payment->find('list',array('fileds'=>array('Payment.name') )));
}
function edit_transaction ($id = null)
{
if ( $id )
{
$this->Transaction->id = $id;
if ( $this->data )
{
if ( $this->Transaction->save($this->data) )
{
$this->Session->setFlash('اطلاعات با موفقیت ثبت شد', 'default', array('class' => 'success-msg'));
}
else
{
$this->Session->setFlash('مشکلی در ثبت اطلاعات وجود دارد', 'default', array('class' => 'error-msg'));
}
}
$this->data = $this->Transaction->read();
}
}
function services ($delid = null)
{
if ( $delid )
{
$service=$this->Service->find('first',array('conditions'=>array('Service.i d'=>$delid),'recursive'=>2));
foreach($service['Property'] as $property)
{
foreach($property['Productproperty'] as $productproperty)
$this->Productproperty->delete($productproperty['id'],false);
$this->Property->delete($property['id'],false);
}
foreach($service['Product'] as $product)
{
foreach($product['Order'] as $order)
$this->Order->delete($order['id'],false);
$this->Product->delete($product['id'],false);
}
$this->Service->delete($delid,false);
$this->Session->setFlash('سرویس با موفقیت حذف شد', 'default', array('class' => 'success-msg'));
}
$this->set('services', $this->Service->find('all', array('order' => 'Service.id DESC')));
}
function add_service ()
{
if ( $this->data )
{
$monthly = 0;
foreach($this->data['Service']['period'] as $row)
{
$monthly += $row;
}
$this->data['Service']['monthly'] = $monthly;
$this->Service->create();
if ( $this->Service->save($this->data) )
{
foreach($this->data['Service']['property'] as $property)
{
if(!empty($property)){
$temp['Property']['name']=$property;
$temp['Property']['service_id']= $this-> Service->id;
$this->Property->create();
$this->Property->save($temp);
}
}
$this->Session->setFlash('اطلاعات با موفقیت ثبت شد', 'default', array('class' => 'success-msg'));
}
else
{
$this->Session->setFlash('مشکلی در ثبت اطلاعات وجود دارد', 'default', array('class' => 'error-msg'));
}
}
}
function edit_service ($id = null)
{
if ( $id )
{
$this->Service->id = $id;
if ( $this->data )
{
foreach($this->data['Service']['period'] as $row)
{
$this->data['Service']['monthly'] +=$row;
}
if ( $this->Service->save($this->data) )
{
foreach($this->data['Service']['oldproperty'] as $id => $oldProperty)
{
$this->Property->id=$id;
if($oldProperty=='')
$this->Property->del($id,true);
else
{
$temp['Product']['name']=$oldProperty;
$this->Property->save($temp);
}
}
foreach($this->data['Service']['property'] as $property )
{
$temp['Property']['name']=$property;
$temp['Property']['service_id']= $this-> Service->id;
$this->Property->create();
$this->Property->save($temp);
}
$this->Session->setFlash('اطلاعات با موفقیت ثبت شد', 'default', array('class' => 'success-msg'));
$this->redirect('/managers/services');
}
else
{
$this->Session->setFlash('مشکلی در ثبت اطلاعات وجود دارد', 'default', array('class' => 'error-msg'));
}
}
$this->data = $this->Service->read();
$monthly = $this->Service->find('first',array('conditions'=>array('Service.i d'=>$id),'fields'=>array('Service.monthly')));
$monthly = $monthly['Service']['monthly'];
if($monthly-60 >= 0)
{
$period[]='60';
$monthly=$monthly-60;
}
if($monthly-24 >= 0)
{
$period[]='24';
$monthly=$monthly-24;
}
if($monthly-12 >= 0)
{
$period[]='12';
$monthly=$monthly-12;
}
if(($monthly-6) >= 0)
{
$period[]='6';
$monthly=$monthly-6;
}
if(($monthly-3) >= 0)
{
$period[]='3';
$monthly=$monthly-3;
}
if(($monthly-1) >= 0)
{
$period[]='1';
$monthly=$monthly-1;
}
$apis = $this->Api->find('list',array('fields' => array('Api.id','Api.name')));
$apis[0] = 'هيچ يک';
$this->set('period',$period);
$this->set('properties',$this->Property->find('all',array('conditions' => array('Property.service_id' => $id))));
$this->set('apis',$apis );
}
}
function pages ($delid = null)
{
if ( $delid )
{
$this->Page->id = $delid;
$this->Page->del();
}
$this->set('pages', $this->Page->find('all', array('order' => 'Page.id DESC')));
}
function news ($delid = null)
{
if ( $delid )
{
$this->News->id = $delid;
$this->News->del();
}
$this->set('news', $this->News->find('all', array('order' => 'News.id DESC')));
}
function add_news ()
{
if ( $this->data )
{
$this->data['News']['date'] = $this->Jtime->pmktime(0,0,0,$this->data['News']['date']['month'],$this->data['News']['date']['day'],$this->data['News']['date']['year']);
if ( $this->News->save($this->data) )
{
$this->Session->setFlash('اطلاعات با موفقیت ثبت شد', 'default', array('class' => 'success-msg'));
$this->redirect('/managers/news');
}
else
{
$this->Session->setFlash('مشکلی در ثبت اطلاعات وجود دارد', 'default', array('class' => 'error-msg'));
}
}
}
function edit_news ($id = null)
{
if ( $id )
{
$this->News->id = $id;
if ( $this->data )
{
$this->data['News']['date'] = $this->Jtime->pmktime(0,0,0,$this->data['News']['date']['month'],$this->data['News']['date']['day'],$this->data['News']['date']['year']);
if ( $this->News->save($this->data) )
{
$this->Session->setFlash(' خبر مورد نظر با موفقیت ویرایش شد', 'default', array('class' => 'success-msg'));
$this->redirect('/managers/news');
}
else
{
$this->Session->setFlash('مشکلی در ثبت اطلاعات وجود دارد', 'default', array('class' => 'error-msg'));
}
}
$this->data = $this->News->read();
}
}
function add_page ()
{
if ( $this->data )
{
if ( $this->Page->save($this->data) )
{
$this->Session->setFlash('اطلاعات با موفقیت ثبت شد', 'default', array('class' => 'success-msg'));
$this->redirect('/managers/pages');
}
else
{
$this->Session->setFlash('مشکلی در ثبت اطلاعات وجود دارد', 'default', array('class' => 'error-msg'));
}
}
}
function edit_page ($id = null)
{
if ( $id )
{
$this->Page->id = $id;
if ( $this->data )
{
if ( $this->Page->save($this->data) )
{
$this->Session->setFlash('صفحه با موفقیت ویرایش شد', 'default', array('class' => 'success-msg'));
$this->redirect('/managers/pages');
}
else
{
$this->Session->setFlash('مشکلی در ثبت اطلاعات وجود دارد', 'default', array('class' => 'error-msg'));
}
}
$this->data = $this->Page->read();
}
}
function menus ($delid = null)
{
if ( $delid )
{
$this->Menu->id = $delid;
$this->Menu->del();
}
$this->set('menus', $this->Menu->find('all', array('order' => 'Menu.id DESC')));
}
function add_menu ()
{
if ( $this->data )
{
if ( $this->Menu->save($this->data) )
{
$this->Session->setFlash('اطلاعات با موفقیت ثبت شد', 'default', array('class' => 'success-msg'));
$this->redirect('/managers/menus');
}
else
{
$this->Session->setFlash('مشکلی در ثبت اطلاعات وجود دارد', 'default', array('class' => 'error-msg'));
}
}
}
function edit_menu ($id = null)
{
if ( $id )
{
$this->Menu->id = $id;
if ( $this->data )
{
if ( $this->Menu->save($this->data) )
{
$this->Session->setFlash('اطلاعات با موفقیت ثبت شد', 'default', array('class' => 'success-msg'));
$this->redirect('/managers/menus');
}
else
{
$this->Session->setFlash('مشکلی در ثبت اطلاعات وجود دارد', 'default', array('class' => 'error-msg'));
}
}
$this->data = $this->Menu->read();
}
}
function payments ($delid = null)
{
if ( $delid )
{
$this->Payment->id = $delid;
$this->Payment->del();
}
$this->set('payments', $this->Payment->find('all', array('order' => 'Payment.id DESC')));
}
function add_payment ()
{
if ( $this->data )
{
if ( $this->Payment->save($this->data) )
{
$this->Session->setFlash('اطلاعات با موفقیت ثبت شد', 'default', array('class' => 'success-msg'));
$this->redirect('/managers/payments');
}
else
{
$this->Session->setFlash('مشکلی در ثبت اطلاعات وجود دارد', 'default', array('class' => 'error-msg'));
}
}
}
function edit_payment ($id = null)
{
if ( $id )
{
$this->Payment->id = $id;
if ( $this->data )
{
if ( $this->Payment->save($this->data) )
{
$this->Session->setFlash('اطلاعات با موفقیت ثبت شد', 'default', array('class' => 'success-msg'));
$this->redirect('/managers/payments');
}
else
{
$this->Session->setFlash('مشکلی در ثبت اطلاعات وجود دارد', 'default', array('class' => 'error-msg'));
}
}
$this->data = $this->Payment->read();
}
}
function add_customer ()
{
if ( $this->data )
{
if ( $this->Customer->save($this->data) )
{
$this->Session->setFlash('اطلاعات با موفقیت ثبت شد', 'default', array('class' => 'success-msg'));
$this->redirect('/managers/customers');
}
else
{
$this->Session->setFlash('مشکلی در ثبت اطلاعات وجود دارد', 'default', array('class' => 'error-msg'));
}
}
}
function edit_customer ($id = null)
{
if ( $id )
{
$this->Customer->id = $id;
if ( $this->data )
{
if ( $this->Customer->save($this->data) )
{
$this->Session->setFlash('اطلاعات با موفقیت ثبت شد', 'default', array('class' => 'success-msg'));
$this->redirect('/managers/customers');
}
else
{
$this->Session->setFlash('مشکلی در ثبت اطلاعات وجود دارد', 'default', array('class' => 'error-msg'));
}
}
$this->data = $this->Customer->read();
}
}
function customers ($delid = null)
{
if ( $delid )
{
$this->Customer->id = $delid;
$this->Customer->del();
}
$this->set('customers', $this->Customer->find('all', array('order' => 'Customer.id DESC')));
}
function edit_setting()
{
if($this->data)
{
$this->Setting->id=$this->Setting->find('id');
$this->Setting->save($this->data);
$this->Session->setFlash('تنظیمات با موفقیت ذخیره شد', 'default', array('class' => 'success-msg'));
$this->redirect('/managers/home') ;
}else
{
$this->data=$this->Setting->find();
}
}
function invoice($id)
{
if(isset($this->data['invoice']['order_id']))
{
$count=0;
foreach($this->data['invoice']['order_id'] as $id)
{
$order[$count] = $this->Order->find('first',array('conditions'=>array('Order.id' =>$id),'recursive' =>2));
$price=$this->costs($order[$count]['Product']['cost']);
$order[$count]['Product']['cost']=$price[$order[$count]['Order']['monthly']]-$order[$count]['Order']['discount'];
$count++;
}
}else
{
$order[0] = $this->Order->find('first',array('conditions'=>array('Order.id' =>$id),'recursive' =>2));
$price=$this->costs($order[0]['Product']['cost']);
$order[0]['Product']['cost']=$price[$order[0]['Order']['monthly']]-$order[0]['Order']['discount'];
}
$this->set('settings',$this->Setting->find());
//print_r($order);
$this->set('info',$order);
$this->set('client',$this->User->findById($order[0]['Order']['user_id']));
$this->render('/users/invoice' ,'invoice');
}
function edit_user($id=null)
{
if($id)
{
$this->set('id',$id);
$this->User->id=$id;
if($this->data)
{
if($this->User->save($this->data)){
$this->Session->setFlash('مشخصات مشتری با موفقیت ویرایش شد', 'default', array('class' => 'success-msg'));
$this->redirect('/managers/users');
}
else
$this->Session->setFlash('مشکلی در ثبت اطلاعات به وجود آمده است', 'default', array('class' => 'error-msg'));
}else
{
$this->data=$this->User->read();
}
}
}
function messages($id=null,$operation=null)
{
if(empty($id))
$this->set('messages',$this->paginate('Message'));
else
{
if($operation == "delete")
{
$this->Message->id=$id;
$this->Message->del();
$this->Session->setFlash('پیام با موفقیت حذف شد', 'default', array('class' => 'success-msg'));
$this->redirect('/managers/messages');
}else
$this->set('message',$this->Message->findById($id));
}
}
function user_confirm($id)
{
$this->User->id=$id;
$temp['User']['role']='0';
$this->User->save($temp);
$user=$this->User->read();
$this->set('client',$user);
$this->set('setting',$this->setting);
$this->Email->to = $user['User']['email'];
$this->Email->from = $this -> setting['mail_title'].' <'.$this -> setting['mail_address'].'>';
$this->Email->subject = 'شناسه کاربری شما فعال شد';
$this->Email->template = 'userconfirm';
$this->Email->sendAs = 'html';
$this->Email->send();
$this->redirect('/managers/users');
}
function register() {
if ($this->data) {
if ($this->data['User']['password'] == $this->Auth->password($this->data['User']['password_confirm'])) {
$this->User->create();
if($this->data['User']['send_mail']==1)
$this->data['User']['role']=0;
elseif($this->data['User']['send_mail']==0)
$this->data['User']['role']=-1;
if($this->User->save($this->data))
{
$message='شناسه کاربری با موفقیت ساخته شده است';
if($this->data['User']['send_mail']==0)
{
$message .=' و پست الکترونیکی فرستاده شد';
$key=$this->data['User']['password'].'samansystems';
$key=md5($key);
$key=substr($key,2,12);
$this->set('user',$this->data);
$this->set('key',$key);
$this->set('setting',$this->setting);
$this->Email->to = $this->data['User']['email'] ;
$this->Email->from = $this -> setting['mail_title'].' <'.$this -> setting['mail_address'].'>';
$this->Email->subject = 'شناسه کاربری در '.$this->setting['name'].' برای شما ساخته شده است';
$this->Email->template = 'userconfirm';
$this->Email->sendAs = 'html';
$this->Email->send();
}
$this->Session->setFlash($message, 'default', array('class' => 'success-msg'));
$this->redirect('/managers/home');
}else
{
$this->data['User']['password'] = $this->data['User']['password_confirm'] ='';
$this->Session->setFlash('مشکلی در ثبت پیش آمده است ', 'default', array('class' => 'error-msg'));
}
}
}
}
function user_delete($user_id=0)
{
$this->layout='ajax';
$transaction=$this->Transaction->find('count',array('conditions'=>array(
'Transaction.user_id'=>$user_id
)
)
);
if($transaction > 0)
{
$this -> Session->setFlash('کاربر مورد نظر دارای تراکنش فعال است این کاربر نمی تواند حذف بشود', 'default', array('class' => 'error-msg'));
}else{
$this->User->id =$user_id;
if($this->User->del())
$this->Session->setFlash('کاربر مورد نظر با موفقیت حذف شد', 'default', array('class' => 'success-msg'));
else
$this->Session->setFlash('مشکلی در حذف کاربر رخ داده است ', 'default', array('class' => 'error-msg'));
}
$this -> redirect('/managers/users');
}
function productproperty()
{
$this->layout='ajax';
$service=$this->Service->findById($_POST['service_id']);
$monthly = $service['Service']['monthly'];
if($monthly-60 >= 0)
{
$period[]='60';
$monthly=$monthly-60;
}
if($monthly-24 >= 0)
{
$period[]='24';
$monthly=$monthly-24;
}
if($monthly-12 >= 0)
{
$period[]='12';
$monthly=$monthly-12;
}
if(($monthly-6) >= 0)
{
$period[]='6';
$monthly=$monthly-6;
}
if(($monthly-3) >= 0)
{
$period[]='3';
$monthly=$monthly-3;
}
if(($monthly-1) >= 0)
{
$period[]='1';
$monthly=$monthly-1;
}
foreach($service['Property'] as $row)
{
$return .='<label>'.$row['name'] .' :</label><input name="data[Product][property]['.$row['id'].']" type="text" value="" /><br /><br />';
}
foreach($period as $month)
{
$return .='<label>قیمت '.$month.' ماهه'.'</label><input name="data[Product][costs]['.$month.'] type="text" value="" /><br /><br />';
}
echo $return;
}
function costs($string)
{
$costs=explode(':',$string);
foreach($costs as $row)
{
$temp=explode(',',$row);
$price[$temp[0]]=$temp[1];
}
array_pop($price);
return $price;
}
function tickets($ticket_id=null)
{
if(!isset($ticket_id)){
$tickets=$this->Ticket->find('all',array('order' => array('Ticket.status ASC','Ticket.priority DESC')));
$this->set('tickets',$tickets);
}
else
{
switch ($ticket_id) {
case 'open':
$tickets=$this->Ticket->find('all',array('conditions' => array('Ticket.status'=>'0'), 'order' => array('Ticket.status ASC','Ticket.priority DESC')));
$this->set('tickets',$tickets);
break;
case 'answered':
$tickets=$this->Ticket->find('all',array('conditions' => array('Ticket.status'=>'1'), 'order' => array('Ticket.status ASC','Ticket.priority DESC')));
$this->set('tickets',$tickets);
break;
case 'customer-reply':
$tickets=$this->Ticket->find('all',array('conditions' => array('Ticket.status'=>'2'), 'order' => array('Ticket.status ASC','Ticket.priority DESC')));
$this->set('tickets',$tickets);
break;
case 'on-hold':
$tickets=$this->Ticket->find('all',array('conditions' => array('Ticket.status'=>'3'), 'order' => array('Ticket.status ASC','Ticket.priority DESC')));
$this->set('tickets',$tickets);
break;
case 'in-progress':
$tickets=$this->Ticket->find('all',array('conditions' => array('Ticket.status'=>'4'), 'order' => array('Ticket.status ASC','Ticket.priority DESC')));
$this->set('tickets',$tickets);
break;
case 'closed':
$tickets=$this->Ticket->find('all',array('conditions' => array('Ticket.status'=>'5'), 'order' => array('Ticket.status ASC','Ticket.priority DESC')));
$this->set('tickets',$tickets);
break;
default:
$tickets=$this->Ticket->find('first',array('conditions'=>array('Ticket.id '=>$ticket_id),'recursive' => 1));
$ticketreplies=$this->Ticketreply->find('all',array('conditions'=>array('Ticketreply .ticket_id'=>$ticket_id)));
$this->set('ticketreplies',$ticketreplies);
$this->set('departments',$this->Ticketdepartment->find('list',array('fields'=> array('Ticketdepartment.id','Ticketdepartment.name '))));
$this->set('statuses',array('1'=>'پاسخ داده شده','3'=>'در انتظار','4'=>'در دست برسی','5'=>'بسته شده'));
$this->set('priorities',array('0'=>'عادی','1'=>'مه م','2'=>'خيلی مهم'));
$this->set('ticket',$tickets);
}
}
}
function postticket($user_id)
{
if (!empty($this->data)) {
$this->data['Ticket']['user_id'] = $user_id;
$this->data['Ticket']['date'] = time();
$this->data['Ticket']['user_unread'] = 1;
if ($this->Ticket->save($this->data)) {
$temp['Ticketreply']['user_id'] = $this->Auth->user('id');
$temp['Ticketreply']['content'] = $this->data['Ticket']['content'];
$temp['Ticketreply']['date'] = time();
$temp['Ticketreply']['ticket_id'] = $this->Ticket->id;
if($this->Ticketreply->save($temp))
{
if($this -> setting['send_email']==1)
{
$this->set('ticket_title',$this->data['Ticket']['title']);
$this->set('ticket_content',nl2br($temp['Ticketreply']['content']));
$this->set('ticket_id',$this->Ticket->id);
$this->set('opendate',$this->data['Ticket']['date']);
$this->set('setting',$this->setting);
$user=$this->User->find('first' , array('conditions'=>array('User.id'=>$user_id)));
$this->Email->to = $user['User']['email'];
$this->Email->from = $this -> setting['mail_title'].' <'.$this -> setting['mail_address'].'>';
$this->Email->subject = 'تيکت جديد: #'.$this->Ticket->id.' - '.$this->data['Ticket']['title'];
$this->Email->template = 'ticketopen';
$this->Email->sendAs = 'html';
$this->Email->send();
}
$this->Session->setFlash('تيکت شما با موفقيت ثبت شد.','default', array('class' => 'success-msg'));
$this->redirect(array('controller' => 'managers','action' => 'tickets',$this->Ticket->id));
}
}
}
$this->set('priorities',array('0'=>'عادی','1'=>'مه م','2'=>'خيلی مهم'));
$this->set('statuses',array('1'=>'پاسخ داده شده','3'=>'در انتظار','4'=>'در دست برسی','5'=>'بسته شده'));
$this->set('departments',$this->Ticketdepartment->find('list',array('fields'=> array('Ticketdepartment.id','Ticketdepartment.name '))));
$to_user=$this->User->find('first',array('conditions'=>array('User.id ' =>$user_id)));
$this->set('to_user',$to_user);
}
function postticketreply($ticket_id)
{
$ticket=$this->Ticket->find('first',array('conditions'=>array('Ticket.id '=>$ticket_id)));
if(!empty($ticket)){
if (!empty($this->data)) {
$this->data['Ticketreply']['ticket_id'] = $ticket_id;
$this->data['Ticketreply']['user_id'] = $this->Auth->user('id');
$this->data['Ticketreply']['date'] = time();
$this->Ticketreply->create();
if($this->Ticketreply->save($this->data))
{
$temp = array('status' => $this->data['Ticketreply']['status'], 'priority' => $this->data['Ticketreply']['priority']) ;
$this->Ticket->id = $ticket_id;
$this->data['Ticket']['ticketdepartment_id'] = $this->data['Ticketreply']['ticketdepartment_id'];
$this->data['Ticket']['user_unread'] = 1;
$this->data['Ticket']['status'] = $temp['status'];
$this->data['Ticket']['priority'] = $temp['priority'];
if($this->Ticket->save($this->data))
{
if($this -> setting['send_email']==1)
{
$this->set('reply_content',nl2br($this->data['Ticketreply']['content']));
$this->set('ticket_id',$ticket_id);
$this->set('replydate',$this->data['Ticketreply']['date']);
$this->set('setting',$this->setting);
$ticket=$this->Ticket->find('first' , array('conditions'=>array('Ticket.id'=>$ticket_id) ));
$user=$this->User->find('first' , array('conditions'=>array('User.id'=>$ticket['Ticket']['user_id'])));
$this->Email->to = $user['User']['email'];
$this->Email->from = $this -> setting['mail_title'].' <'.$this -> setting['mail_address'].'>';
$this->Email->subject = 'پاسخ جديد در تيکت: #'.$this->Ticket->id.' - '.$ticket['Ticket']['title'];
$this->Email->template = 'ticketreply';
$this->Email->sendAs = 'html';
$this->Email->send();
}
$this->Session->setFlash('پاسخ به تيکت با موفقيت ارسال شد.','default', array('class' => 'success-msg'));
$this->redirect(array('controller' => 'managers','action' => 'tickets',$this->Ticket->id));
}
$this->Session->setFlash('پاسخ به تيکت مورد نظر با موفقيت ارسال شد.','default', array('class' => 'success-msg'));
}else
$this->Session->setFlash('پاسخ ارسالی بايد حاوی نوشته باشد.','default', array('class' => 'error-msg'));
$this->redirect(array('controller' => 'managers','action' => 'tickets',$ticket_id));
}
}
else
{
$this->Session->setFlash('تيکتي با اين مشخصات وجود ندارد.','default', array('class' => 'error-msg'));
$this->redirect(array('controller' => 'managers','action' => 'tickets'));
}
}
function checkcardcharges($status){
if(!empty($this->data)){
foreach($this->data['accept'] as $arow)
{
if(!empty($arow)){
$this->Cardcharge->id = $arow;
$temp['Cardcharge']['admin_check'] = 1;
$this->Cardcharge->save($temp);
unset($temp);
$a++;
}
}
foreach($this->data['failed'] as $frow)
{
if(!empty($frow)){
$this->Cardcharge->id = $frow;
$temp['Cardcharge']['admin_check'] = 2;
$this->Cardcharge->save($temp);
$payment=$this->Payment->find('first' , array('filds'=>array('id'),'conditions'=>array('Pa yment.pin'=>'cardcharge')));
$cardinfo = $this->Cardcharge->find('first' , array('conditions'=>array('Cardcharge.id'=>$frow,' Cardcharge.user_id !='=>0)));
if(!empty($cardinfo['Cardcharge']['user_id'])){
$this->data['Transaction']['user_id'] = $cardinfo['Cardcharge']['user_id'];
$this->data['Transaction']['amount'] = -($cardinfo['Cardcharge']['credit']);
$this->data['Transaction']['date'] = time();
$this->data['Transaction']['confirmed'] = 1;
$this->data['Transaction']['payment_id'] = $payment['Payment']['id'];
$this->data['Transaction']['desc'] = ' رد کارت به شماره '.$cardinfo['Cardcharge']['id'];
$this->Transaction->save($this->data);
}
unset($temp);
$f++;
}
}
if(($a > 0) & ($f > 0))
$this->Session->setFlash('تعداد '.$a.' کارت شارژ تاييد و '.$f.' کارت شارژ رد شد.','default', array('class' => 'success-msg'));
elseif($a > 0)
$this->Session->setFlash('تعداد '.$a.' کارت شارژ با موفقيت تاييد شد.','default', array('class' => 'success-msg'));
elseif($f > 0)
$this->Session->setFlash('تعداد '.$f.' کارت شارژ با موفقيت رد شد.','default', array('class' => 'success-msg'));
else
$this->Session->setFlash('هيچ عملياتی روی کارت شارژ ها انجام نشد.','default', array('class' => 'error-msg'));
$this->redirect(array('controller' => 'managers','action' => 'checkcardcharges'));
}
else{
switch ($status){
case 'notsubmited':
$this->paginate=array('limit'=>15,'order'=>'Cardcharge.s tart_date DESC');
$this->set('listcards',$this->paginate('Cardcharge',array('Cardcharge.user_id'= > 0)));
break;
case 'notchecked':
$this->paginate=array('limit'=>15,'order' => 'Cardcharge.submit_date DESC');
$this->set('listcards',$this->paginate('Cardcharge',array('Cardcharge.user_id !='=> 0,'Cardcharge.admin_check'=>0)));
break;
case 'verified':
$this->paginate=array('limit'=>15,'order' => 'Cardcharge.submit_date DESC');
$this->set('listcards',$this->paginate('Cardcharge',array('Cardcharge.admin_che ck'=> 1)));
break;
case 'faild':
$this->paginate=array('limit'=>15,'order'=>'Cardcharge.s tart_date DESC');
$this->set('listcards',$this->paginate('Cardcharge',array('Cardcharge.admin_che ck'=> 2)));
break;
default:
$this->paginate=array('limit'=>15,'order'=>'Cardcharge.s tart_date DESC');
$this->set('listcards',$this->paginate('Cardcharge'));
}
}
}
function makecardcharge($make){
if($make == 'make' && !empty($this->data['Cardcharge']['credit'])){
$f1 = rand(10, 9999999999);
$f2 = md5($f1);
$p1 = rand(-5, -32);
$this->data['Cardcharge']['security_code'] = substr($f2, $p1, 5);
$this->data['Cardcharge']['start_date'] = time();
if($this->Cardcharge->save($this->data)){
$this->set('cardbarcode',$this->data['Cardcharge']['start_date'].$this->Cardcharge->id);
$this->set('cardid',$this->Cardcharge->id);
$this->set('cardpassword',$this->data['Cardcharge']['security_code']);
$this->set('cardcredit',$this->data['Cardcharge']['credit']);
}
}
}
function printcardcharge($cardid){
$this->layout = 'printcardcharge';
$cardinfo = $this->Cardcharge->find('first' , array('conditions'=>array('Cardcharge.id'=>$cardid )));
$this->set('cardinfo',$cardinfo);
}
function closeticket($ticket_id)
{
$ticket=$this->Ticket->find('first',array('conditions'=>array('Ticket.id '=>$ticket_id)));
if(!empty($ticket))
{
$this->Ticket->id = $ticket_id;
$this->data['Ticket']['status'] = 5;
if($this->Ticket->save($this->data)){
$this->Session->setFlash('وضعيت تيکت به بسته شده تغيير يافت.','default', array('class' => 'success-msg'));
$this->redirect(array('controller' => 'managers','action' => 'tickets',$ticket_id));
}
}
else
{
$this->Session->setFlash('تيکتی با اين مشخصات پيدا نشد.','default', array('class' => 'error-msg'));
$this->redirect(array('controller' => 'managers','action' => 'tickets'));
}
}
}
?>