ورود

توجه ! این یک نسخه آرشیو شده میباشد و در این حالت شما عکسی را مشاهده نمیکنید برای مشاهده کامل متن و عکسها بر روی لینک مقابل کلیک کنید : از کار افتادن سما گستر samacrm



alizali
February 21st, 2014, 19:41
درود خدمت دوستان
سایتی داشتیم که با سیستم سما گستر بود
خودبه خود بدون هیچ تغییری در سرور از کار افتاده و هیچ ارور و صفحه ای هم نمیاد که بررسی کنیم

ضمن اینکه جالبه سایت اصلی هم که همون asrenet.com باشه هم از کار افتاده
اقای امیری یا کسی از دوستان توضیحی داره بی زحمت

alizali
March 4th, 2014, 20:26
Up.....
هیچ کسی یعنی تجربه مشابهی ندارد؟

tizparvaz
March 4th, 2014, 21:21
شاید چون سایت اصلی قطعه لایسنس نمیتونه چک کنه و مال شما هم قطع شده باشه
شاید

samansystems
March 4th, 2014, 22:19
وبسرويس نوين پيامک تغيير کرده و بايد بروز رسانی بشه. برای حل مشکل ميتونيد کامپوننت با نام asresms رو از کنترل های زير حذف کنيد:
managers_controller
users_controller

برند عصر نت ادغام شده با شرکت نويدان و انشالله بزودی خدمات تحت نام نويدان (http://www.navidan.com) شروع به فعاليت عمومی ميکنه. به همين دليل هست که عصر نت هم از دسترس خارج شده.

alizali
March 6th, 2014, 11:11
با تشکر مجدد از شما
من از لیست کامپوننتها حذف کردم
ولی ظاهرا هر دو فایل نیاز به ادیت بیشتری داره
میشه لطف کنید و ادیت شده این دو فایل رو بزارید
خیلی ممنون می شم

samansystems
March 8th, 2014, 01:57
لطفا اطلاعات ورود به پنل هاست رو پيام خصوصی کنيد تا برسی بشه.

asrhosting
March 8th, 2014, 02:38
برا فایل منیجر کافیه کد های زیر رو جایگزین کنید :

<?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.status' => array('0','2') ) ,'fields'=>array( 'COUNT(Ticket.id) as tot')));
$tickets=$this->Ticket->find('first',array('conditions'=>array('Ticket.status' => 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('Productproperty.product_id'=>$delid)));
foreach ($productproperty as $row)
{
$this->Productproperty->delete($row['Productproperty']['id'],false);
}
$orders=$this->Order->find('all',array('conditions'=>array('Order.product_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.id'=>$id),'recursive'=>3));
$inputs='<div id="productproperty">';

foreach($product['Service']['Property'] as $property)
{
$productproperty=$this->Productproperty->find('first',array('conditions'=>array('Productproperty.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.id'=>$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.id'=>$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('Payment.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.start_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_chec k'=> 1)));
break;
case 'faild':
$this->paginate=array('limit'=>15,'order'=>'Cardcharge.start_date DESC');
$this->set('listcards',$this->paginate('Cardcharge',array('Cardcharge.admin_chec k'=> 2)));
break;
default:
$this->paginate=array('limit'=>15,'order'=>'Cardcharge.start_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'));
}
}
}
?>
و برای یوزر هم :

<?php

class UsersController extends AppController
{
//--- Variables
var $uses = array('User', 'Order', 'Service', 'Product', 'Transaction', 'Payment', 'Setting', 'Ticket', 'Ticketreply', 'Cardcharge', 'Ticketdepartment', 'Api');
var $components = array('Security', 'Whois', 'Jtime', 'Email', 'Cookie', 'Directiapi', 'Pasargad', 'Cpanelapi', 'Nicapi');
var $helpers = array('Html', 'Form', 'Session', 'Javascript', 'Paginator', 'Qoute');
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->set('users',$this->Auth->user());
$this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'home');
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
$this->Auth->autoRedirect = false;
$this->Auth->loginError="نام کاربری یا رمز عبور اشتباه است";
$this->Auth->authError="شما اجازه دسترسی به این بخش را ندارید";
$this->Auth->allow('login', 'logout', 'register' , 'whois', 'confirmation', 'forget_password');
if($this->Auth->user('role')==-1 & ( $this->action != 'home' && $this->action !='logout' && $this->action !='confirmation' && $this->action !='sendconfirmatinemail' ) ){
$this->Session->setFlash('آدرس پست الکترونيکی شما مورد تاييد قرار نگرفته است لطفا پست الکترونيکی خود را چک کنيد و مراحل ثبت نام را تکميل نماييد.<br />در صورت عدم دريافت ايميل و نياز به ارسال مجدد اينجا <a href="/users/sendconfirmatinemail/">کليک کنيد</a>.', 'default', array('class' => 'error-msg'));
$this->redirect(array('action'=>'home'));
}

}

function home()
{
$total_unconfirmed = $this->Transaction->find('first', array( 'conditions' => array('Transaction.user_id' => $this->Auth->user('id'), 'Transaction.confirmed' => 0),
'fields' => array('SUM(Transaction.amount) as tot')
)
);
$total_confirmed = $this->Transaction->find('first', array( 'conditions' => array('Transaction.user_id' => $this->Auth->user('id'), 'Transaction.confirmed' => 1, 'Transaction.amount >' =>'0'),
'fields' => array('SUM(Transaction.amount) as tot')
)
);
$total_credit = $this->Transaction->find('first', array( 'conditions' => array('Transaction.user_id' => $this->Auth->user('id'), 'Transaction.confirmed' => 1),
'fields' => array('SUM(Transaction.amount) as tot')
)
);
$referred_users = $this->User->find('count', array('conditions' =>array('User.referrer_id'=>$this->Auth->user('id'))));
$top_user=$this->User->findById($this->Auth->user('referrer_id'));
$this ->set('top_user', $top_user);
$this->set('total', array('credit' => $total_credit[0]['tot'],'confirmed' => $total_confirmed[0]['tot'],'unconfirmed' => $total_unconfirmed[0]['tot'], 'referred_users' => $referred_users));

$ticket_unread=$this->Ticket->find('first',array('conditions'=>array('Ticket.user_id' => $this->Auth->user('id'),'Ticket.user_unread' => '1' ) ,'fields'=>array( 'COUNT(Ticket.id) as tot')));
$ticket_open=$this->Ticket->find('first',array('conditions'=>array('Ticket.user_id' => $this->Auth->user('id'),'Ticket.status' => '0' ) ,'fields'=>array( 'COUNT(Ticket.id) as tot')));
$ticket_areply=$this->Ticket->find('first',array('conditions'=>array('Ticket.user_id' => $this->Auth->user('id'),'Ticket.status' => '1' ) ,'fields'=>array( 'COUNT(Ticket.id) as tot')));
$ticket_inporonh=$this->Ticket->find('first',array('conditions'=>array('Ticket.user_id' => $this->Auth->user('id'),'Ticket.status' => array('3','4') ) ,'fields'=>array( 'COUNT(Ticket.id) as tot')));

$order_confirmed =$this->Order->find('count',array('conditions'=>array('Order.user_id'=>$this->Auth->User('id') , 'Order.confirmed' => 2)));
$order_unconfirmed =$this->Order->find('count',array('conditions'=>array('Order.user_id'=>$this->Auth->User('id') , 'Order.confirmed' => 1)));
$order_before =$this->Order->find('count',array('conditions'=>array('Order.user_id'=>$this->Auth->User('id') , 'Order.confirmed' => 0)));
$this->set('orders',array('confirmed'=>$order_confirmed , 'unconfirmed'=>$order_unconfirmed , 'before'=>$order_before));
$this ->set('tickets', array('unread'=>$ticket_unread[0]['tot'] ,'open'=>$ticket_open[0]['tot'] , 'areply'=> $ticket_areply[0]['tot'], 'inporonh'=> $ticket_inporonh[0]['tot']));
}

function login()
{
$this->layout = 'ajax';
if(isset($this->data)){
if ($this->Auth->user()) {
echo 'success#';
$this->render('/elements/login-block');
}else{
echo 'error#';
}
}else {
$this->redirect('/');
}
}

function register($referrer=0) {
if ($this->data) {
if ($this->data['User']['password'] == $this->Auth->password($this->data['User']['password_confirm'])) {

$this->User->create();
$this->data['User']['role']=-1;
$ureferrer = $this->Cookie->read('referrer');

if(!empty($ureferrer)){
$referrer_user = $this->User->find('first',array('conditions'=>array('User.email'=>base64_decode($ureferrer))));
$this->data['User']['referrer_id'] = $referrer_user['User']['id'];
}

if($this->User->save($this->data))
{
$key=$this->data['User']['password'].'samansystems';
$key=md5($key);
$key=substr($key,2,12);
$this->set('info',$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('لطفا ايميل خود را چک کنيد و مراحل ثبت نام را تکميل کنيد. ممکن است ايميل در شاخه اسپم یا بالک قرار گيرد.', 'default', array('class' => 'success-msg'));
$this->redirect('/');

}else
{
$this->data['User']['password'] = $this->data['User']['password_confirm'] ='';
$this->Session->setFlash('‍‍مشکلی در ثبت پیش آمده است ', 'default', array('class' => 'error-msg'));
}
}
}
elseif(!empty($referrer)){
$referrer_email = base64_decode($referrer);
$referrer_user = $this->User->find('first',array('conditions'=>array('User.email'=>$referrer_email)));
if (!empty($referrer_user['User']['id'])){
$this->Cookie->write('referrer',$referrer,false, 5184000);
}
else{
$this->Session->setFlash('اطلاعات معرف وارد شده صحيح نمی باشد.', 'default', array('class' => 'error-msg'));
}
}
$ureferrer = $this->Cookie->read('referrer');
if(!empty($ureferrer)){
$referrer_user = $this->User->find('first',array('conditions'=>array('User.email'=>base64_decode($ureferrer))));
$referrer_name = $referrer_user['User']['name'];
if(!empty($referrer_user['User']['company']))
$referrer_name .= " (".$referrer_user['User']['company'].")";
$this->set('referrer_name',$referrer_name);
}
}

function logout()
{
$this->redirect($this->Auth->logout());
}
function update()
{
$this->User->id=$this->Auth->user('id');
if(empty($this->data)){
$this->data=$this->User->read();
}else {
if($this->User->save($this->data))
{
$this->Session->setFlash(__('Your information has been updated',true), 'default', array('class' => 'success-msg'));
$this->redirect(array('action'=>'home'));
}
}

}

function change_password()
{
if ( $this->data )
{
$user_password = $this->User->find('count',array('conditions'=>array('User.id'=>$this->Auth->user('id'),'User.password'=> $this->Auth->password($this->data['User']['old_password']))));
if($user_password){
$this->User->id = $this->Auth->user('id');
if ( $this->data['User']['password'] == $this->data['User']['password_confirm'] )
{
$this->data['User']['password'] = $this->Auth->password($this->data['User']['password']);
if($this->User->save($this->data)){
$this->Session->setFlash('رمز عبور با موفقیت تغییر یافت', 'default', array('class' => 'success-msg'));
$this->redirect(array('controller' => 'users', 'action' => 'home'));
}
unset($this->data['User']);
}
else
{
$this->Session->setFlash('رمز عبور شما با تکرار آن مطابقت ندارد', 'default', array('class' => 'error-msg'));
}
}
else{
$this->Session->setFlash('رمز عبور فعلی اشتباه است', 'default', array('class' => 'error-msg'));
}
}
}
function orders($order_id)
{
//$this->paginate = array ('limit' => 25, 'order' => array('Order.id' => 'desc'));
if(!isset($order_id))
$orders=$this->Order->find('all',array('conditions'=>array('Order.user_id' =>$this->Auth->user('id')),'recursive' => 2));
else
$orders=$this->Order->find('all',array('conditions'=>array('Order.id' =>$order_id , 'Order.user_id' =>$this->Auth->user('id')),'recursive' => 2));
foreach($orders as $key=>$row)
{
$costs=$this->costs($row['Product']['cost']);
$orders[$key]['Product']['cost']=$costs[$row['Order']['monthly']];
}
$this->set('orders',$orders);
}


function invoice($id)
{
$this->layout='invoice';
$order[0]=$this->Order->find('first',array('conditions'=>array('Order.id'=>$id,'Order.user_id'=>$this->Auth->User('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());
$this->set('info',$order);
$this->set('client',$this->User->findById($this->Auth->User('id')));
}

function pay($id)
{
$this -> layout = 'ajax';
$data = $this -> Order -> find('first',array(
'conditions'=>array(
'Order.id'=>$id ,
'Order.user_id' => $this->Auth->User('id')
)
)
);
if(empty($data))
{
$this -> Session -> setFlash("چنین سفارشی یافت نشد", 'default', array('class' => 'error-msg'));
$this -> redirect('/users/orders');
exit();
}

$credit = $this -> Transaction -> find('first', array(
'conditions' => array(
'Transaction.user_id' => $this->Auth->user('id'),
'Transaction.confirmed' => 1
)
, 'fields' => array('SUM(Transaction.amount) as tot')
)
);
$credit = $credit[0]['tot'];
$price=$this->costs($data['Product']['cost']);
if( $price[$data['Order']['monthly']] - $data['Order']['discount'] <= $credit)
{

$trans['Transaction']['user_id'] = $this -> Auth -> User('id');
$trans['Transaction']['order_id'] = $id;
$trans['Transaction']['amount'] = '-'.( $price[$data['Order']['monthly']] - $data['Order']['discount'] ) ;
$trans['Transaction']['date'] = time();
$trans['Transaction']['confirmed'] = 1;

$this -> Transaction -> save($trans);

if ( $data['Order']['next_pay'] > 0 ) {

$data['Order']['next_pay'] = ( $data['Order']['monthly'] * 2592000 ) + $data['Order']['next_pay'];

}else{
$data['Order']['next_pay'] = ( $data['Order']['monthly'] * 2592000 ) + time();
$data['Order']['confirmed'] = 1;
}

$this -> Order -> id = $id;
$this -> Order -> save($data);

if($this -> setting['send_email'] == 1)
{
$product = $this->Product->findById($data['Order']['product_id']);
$credit = $this -> Transaction -> find( 'first', array(
'conditions' => array(
'Transaction.user_id' => $this->Auth->user('id'),
'Transaction.confirmed' => 1
),
'fields' => array('SUM(Transaction.amount) as tot')
)
);
$costs= $this->costs($product['Product']['cost']);
$product['Product']['cost'] = $costs[$data['Order']['monthly']];
$info = array($data,$product,$credit[0]['tot']);
$this -> set('info',$info);
$this->set('setting',$this->setting);

$this -> Email -> to = $this -> Auth -> User('email');
$this -> Email -> from = $this -> setting['mail_title'].' <'.$this -> setting['mail_address'].'>';
$this -> Email -> subject = 'سفارش شماره '.$id.' با موفقیت پرداخت شد';
$this -> Email -> template = 'orderpay';
$this -> Email -> sendAs = 'html';
$this -> Email -> send();
}

$this->Session->setFlash('سفارش مورد نظر شما با موفقیت پرداخت شد', 'default', array('class' => 'success-msg'));
}else
{
$this->Session->setFlash("اعتبار شما به اندازه کافی نیست", 'default', array('class' => 'error-msg'));
}

$this->redirect('/users/orders');
}

function accounting()
{
$this->paginate = array ('limit' => 15, 'order' => array('Transaction.id' => 'desc'));
$this->set('transactions',$this->Paginate('Transaction',array('Transaction.user_id =' => $this->Auth->user('id'))));
$this->set('page', $this->params['named']['page']);
}
function charge($method='')
{
if(!empty($method)){
if($method=='bank'){
if( $this->data ){
$this->Transaction->create();
$this->data['Transaction']['date'] = $this->Jtime->pmktime(0,0,0,$this->data['Transaction']['tdate']['month'],$this->data['Transaction']['tdate']['day'],$this->data['Transaction']['tdate']['year']);
$this->data['Transaction']['payment_id'] = $this->data['Transaction']['payment'];
$this->data['Transaction']['user_id'] = $this->Auth->user('id');
$this->data['Transaction']['desc'] = __('Reference Number',true). ': '. $this->data['Transaction']['reference_number'];
$payment_info = $this->Payment->findById($this->data['Transaction']['payment']);
if ( $this->Transaction->save($this->data) ) {
$temp1['Transaction']['id'] = $this->Transaction->id;

//open ticket
$this->data['Ticket']['title'] = 'تراکنش شماره '.$temp1['Transaction']['id'].' ثبت شد';
$this->data['Ticket']['content'] = "با سلام
فیش پرداختی شما به مبلغ ".$this->data['Transaction']['amount']." تومان که به حساب ".$payment_info['Payment']['name']." پرداخت کرديد در سيستم ثبت شد.
تا ساعات آينده نتيجه تاييد فيش اعلام خواهد شد.
(اين تيکت به صورت خودکار توسط سيستم ثبت شد.)";
$this->data['Ticket']['ticketdepartment_id'] = 0;
$this->data['Ticket']['priority'] = 0;
$this->data['Ticket']['user_unread'] = 1;
$this->data['Ticket']['status'] = 6;
$this->postticket(1);

if($this->Auth->user('referrer_id') != 0){
$this->Transaction->create();
$temp['Transaction']['date'] = time();
$temp['Transaction']['amount'] = ($this->setting['top_user_percent']/100)*$this->data['Transaction']['amount'];
$temp['Transaction']['user_id'] = $this->Auth->user('referrer_id');
$temp['Transaction']['payment_id'] = 0;
$temp['Transaction']['confirmed'] = 0;
$temp['Transaction']['desc'] = 'پورسانت حاصل از تراکنش '.$temp1['Transaction']['id'];
$this->Transaction->save($temp);
}
$this->Session->setFlash(__('Transaction saved successfully!',true), 'default', array('class' => 'success-msg'));
$this->redirect(array('controller' => 'users', 'action' => 'accounting'));
} else {
$this->Session->setFlash(__('There\'s an error on saving transaction',true), 'default', array('class' => 'error-msg'));
}
}

$this->set('payments' , $this->Payment->find('list',array('conditions' => array('Payment.list' => '1') ,'fields' => array('Payment.id', 'Payment.name'))));
}elseif($method=='online'){
$this->set('merchents', array( 'Pasargad' => 'دروازه پرداخت بانک پاسارگاد' ));
if($this->data){
$data['amount'] = $this->data['Transaction']['amount'];
$data['user_id'] = $this->Auth->user('id');
$this->set('params', $this->Pasargad->Execute($data));
$this->render('/users/redirectmerchant');
unset($method);
}
}
elseif($method=='cardcharge'){
if( $this->data ){
$card=$this->Cardcharge->find('first' , array('conditions'=>array('Cardcharge.id'=>$this->data['Cardcharge']['cardid'],'Cardcharge.security_code'=>$this->data['Cardcharge']['cardpassword'])));
if(!empty($card[Cardcharge][user_id])){
$this->Session->setFlash('اين کارت قبلا توسط شخص ديگری ثبت شده است.','default', array('class' => 'error-msg'));
}
elseif(!empty($card[Cardcharge][id])){
$this->Transaction->create();
$payment=$this->Payment->find('first' , array('filds'=>array('id'),'conditions'=>array('Payment.pin'=>'cardcharge')));
$this->data['Transaction']['user_id'] = $this->Auth->user('id');
$this->data['Transaction']['amount'] = $card[Cardcharge][credit];
$this->data['Transaction']['date'] = time();
$this->data['Transaction']['confirmed'] = 1;
$this->data['Transaction']['payment_id'] = $payment['Payment']['id'];
$this->data['Transaction']['desc'] = ' ثبت کارت به شماره '.$card[Cardcharge][id];
if($this->Transaction->save($this->data)){
$temp1['Transaction']['id'] = $this->Transaction->id;
$this->Cardcharge->id = $this->data['Cardcharge']['cardid'];
$this->Cardcharge->security_code = $this->data['Cardcharge']['cardpassword'];
$this->data['Cardcharge']['submit_date'] = time();
$this->data['Cardcharge']['user_id'] = $this->Auth->user('id');
$this->data['Cardcharge']['transaction_id'] = $this->Transaction->id;
if ( $this->Cardcharge->save($this->data) ) {
if($this->Auth->user('referrer_id') != 0){
$this->Transaction->create();
$temp['Transaction']['date'] = time();
$temp['Transaction']['amount'] = ($this->setting['top_user_percent']/100)*$card[Cardcharge][credit];
$temp['Transaction']['user_id'] = $this->Auth->user('referrer_id');
$temp['Transaction']['payment_id'] = $this->Transaction->id;
$temp['Transaction']['confirmed'] = 0;
$temp['Transaction']['desc'] = 'پورسانت حاصل از تراکنش '.$temp1['Transaction']['id'];
$this->Transaction->save($temp);
}
$this->Session->setFlash('کارت به ارزش '.$card[Cardcharge][credit].' تومان برای شما ثبت شد.', 'default', array('class' => 'success-msg'));
$this->redirect(array('controller' => 'users', 'action' => 'accounting'));
}
} else {
$this->Session->setFlash(__('There\'s an error on saving transaction',true), 'default', array('class' => 'error-msg'));
}
}
else{
$this->Session->setFlash('شماره کارت و رمز کارت با هم مطابقت ندارند.','default', array('class' => 'error-msg'));
}
}
}
if(!empty($method)) $this->render('/users/charge_'.$method);
}
else $this->render();
}

function neworder ( $product_id = 0, $domain = '' )
{
//user's credit
$credit = $this -> Transaction -> find( 'first', array(
'conditions' => array(
'Transaction.user_id' => $this->Auth->user('id'),
'Transaction.confirmed' => 1
),
'fields' => array('SUM(Transaction.amount) as tot')
)
);

$this -> set ( 'credit', $credit[0]['tot'] );

//product properties
$product = $this -> Product -> findById( $product_id );
if($product['Service']['api_id']) {
$api_info = $this->Api->findById($product['Service']['api_id']);
$this->set('extras', $this->{$api_info['Api']['component_name']}->ExtraFields());
}

if(!empty($product))
{
$this -> set('product', $product );
$monthly=$product['Service']['monthly'];

$price=$this->costs($product['Product']['cost']);
$monthles[0] ='انتخاب کنید';
foreach($price as $month => $cost)
{
if($month==1)
$monthles[1] =' ماهیانه';
elseif($month==3)
$monthles[3] ='3 ماهه';
elseif($month==6)
$monthles[6] ='6 ماهه';
elseif($month==12)
$monthles[12] ='سالیانه';
elseif($month==24)
$monthles[24] ='دو ساله';
elseif($month==60)
$monthles[60] ='پنج ساله';
}
$this->set('monthlies',$monthles);
//if data fill in view
if($this->data){
if ( $this -> data['Order']['monthly'] != 0 )
{

//some of order's properties
$this -> data['Order']['product_id']=$product_id;
$this -> data['Order']['user_id'] = $this -> Auth -> user('id');
$this -> data['Order']['date'] = time();

//if user want to pay
if ( $this -> data['Order']['payment_method'] == 'credit' )
{
//check if user can payup for order
$product['Product']['cost'] = $price[$this->data['Order']['monthly']];
if ($credit[0]['tot'] < ($price[$this->data['Order']['monthly']]) )
{
$this -> Session -> setFlash('متاسفانه اعتبار شما برای این سفارش کافی نمی باشد', 'default', array('class' => 'error-msg'));
}
else
{
//make Order confirmed option to one that indicate this order is payedup
$this->data['Order']['confirmed'] = 1;
$this->data['Order']['next_pay'] = time()+(2592000*$this->data['Order']['monthly']);

//make sure that order save
if($this -> Order -> save($this -> data)){

$this -> data['Order']['id'] = $this -> Order -> id;

//make transaction properties

$trans['Transaction']['user_id'] = $this -> Auth ->User('id');
$trans['Transaction']['order_id'] = $this -> Order -> id;
$trans['Transaction']['amount'] = -($price[$this->data['Order']['monthly']]);
$trans['Transaction']['date'] = time();
$trans['Transaction']['confirmed'] = 1;
$success = false;

if($api_info){
if(!empty($product['Product']['plan_name'])){
if($product['Product']['plan_name']{0} == '.') $ext = $product['Product']['plan_name'];

$this->{$api_info['Api']['component_name']}->SetVar('plan_name', $product['Product']['plan_name']);
}

eval($api_info['Api']['settings']);
foreach($settings as $key => $setting) $this->{$api_info['Api']['component_name']}->SetVar($key, $setting);
foreach($this->data['Api'] as $key => $api_data) $this->{$api_info['Api']['component_name']}->SetVar($key, $api_data);
$parameters['domain'] = $this->data['Order']['desc'].$ext;
$parameters['duration'] = $this->data['Order']['monthly'];
$parameters['email'] = $this->Auth->User('email');

$this -> Transaction -> save($trans);
$status = $this->{$api_info['Api']['component_name']}->Create($parameters);
$this->data['Order']['desc'] .= $ext;
if($status == 'success'){
$this->data['Order']['confirmed'] = 2;
$success = true;
$answer_info = $this->{$api_info['Api']['component_name']}->GetInfo();
} elseif($status=='failed') {
//Order Status ro bayad bezarim rooye yechizi ke neshoon bede error sabt shode.. masalan 5
$this->Transaction->del();
$this->Session->setFlash('اطلاعات وارد شده و مدت زمان ثبت با يکديگر تطابق ندارند', 'default', array('class' => 'error-msg'));

}else{
$this->data['Order']['confirmed'] = 1;
$this->Session->setFlash('مشکلی در ثبت سفارش به وجود آمده است. لطفا با بخش پشتيبانی تماس حاصل فرماييد.', 'default', array('class' => 'error-msg'));
}

if($status != 'failed') $this -> Order -> save($this->data);
else $this->Order->del();

} else{
$this -> Transaction -> save($trans);
$success = true;
}

if($success)
{
//calculate new credit after payup
$credit = $this -> Transaction -> find( 'first', array(
'conditions' => array(
'Transaction.user_id' => $this->Auth->user('id'),
'Transaction.confirmed' => 1
),
'fields' => array(
'SUM(Transaction.amount) as tot'
)
)
);

//make an array for sending mail

$info = array( $this -> data , $product , $credit[0]['tot']);
$this -> set('info',$info);
$this->set('setting',$this->setting);


//open ticket
$this->data['Ticket']['title'] = 'سفارش شماره '.$this -> data['Order']['id'].' با موفقیت ثبت شد';
$this->data['Ticket']['content'] = "با سلام
سفارش شما به شماره ".$info[0]['Order']['id']."ثبت گردید
مشخصات محصول سفارش داده شده :
<center><table style='width: 96%; border: 1px solid #ccc;'><tr><th style='text-align: center; padding: 5px; background: #ccc;'>نام سرویس</th><th style='text-align: center; padding: 5px; background: #ccc;'>نام محصول</th><th style='text-align: center; padding: 5px; background: #ccc;'>قیمت</th><th style='text-align: center; padding: 5px; background: #ccc;'>تاریخ سفارش</th><th style='text-align: center; padding: 5px; background: #ccc;'>توضيحات</th></tr><tr><td>".$info[1]['Service']['name']."</td><td>".$info[1]['Product']['name']."</td><td>".$info[1]['Product']['cost']."</td><td>".$this->Jtime->pdate("Y/n/j", $info[0]['Order']['date'])."</td><td>".$info[0]['Order']['desc']."</td></table></center><br />".
$answer_info;
if(!isset($info[2])) {
$this->data['Ticket']['content'] .="برای نحوه پرداخت این سفارش با شما تماس گرفته خواهد شد.";
} else{
$this->data['Ticket']['content'] .="اعتبار شما در حال حاضر :".$info[2];
}
$this->data['Ticket']['ticketdepartment_id'] = 0;
$this->data['Ticket']['priority'] = 0;
$this->data['Ticket']['user_unread'] = 1;
$this->data['Ticket']['status'] = 6;
$this->postticket(1);

/**
//send email
$this -> Email -> to = $this -> Auth -> User('email');
$this -> Email -> from = $this -> setting['mail_title'].' <'.$this -> setting['mail_address'].'>';
$this -> Email -> subject = 'سفارش شماره '.$this -> data['Order']['id'].' با موفقیت ثبت شد';
$this -> Email -> template = 'ordernew';
$this -> Email -> sendAs = 'html';
$this -> Email -> send();
**/
}
if( $success==true ) $this->Session->setFlash('سفارش شما با موفقیت ثبت شد', 'default', array('class' => 'success-msg'));

$this->redirect('/users/orders');
}else{
$this->Session->setFlash('سفارش شما ثبت نشد لطفا همه موارد را پر کنید.', 'default', array('class' => 'error-msg'));
}
}
}
elseif($this->data['Order']['payment_method'] == 'skip')
{
$product['Product']['cost'] = $price[$this->data['Order']['monthly']];
$this->data['Order']['confirmed']=0;

if($product['Product']['plan_name']{0} == '.')
$this->data['Order']['desc'] .= $product['Product']['plan_name'];


if($this->Order->save($this->data)){

$this->data['Order']['id']=$this->Order->id;



$info = array( $this -> data , $product , $credit[0]['tot']);
$this -> set('info',$info);
$this->set('setting',$this->setting);

//open ticket
$this->data['Ticket']['title'] = 'سفارش شماره '.$this -> data['Order']['id'].' با موفقیت ثبت شد';
$this->data['Ticket']['content'] = "با سلام
سفارش شما به شماره ".$info[0]['Order']['id']."ثبت گردید
مشخصات محصول سفارش داده شده :
<center><table style='width: 96%; border: 1px solid #ccc;'><tr><th style='text-align: center; padding: 5px; background: #ccc;'>نام سرویس</th><th style='text-align: center; padding: 5px; background: #ccc;'>نام محصول</th><th style='text-align: center; padding: 5px; background: #ccc;'>قیمت</th><th style='text-align: center; padding: 5px; background: #ccc;'>تاریخ سفارش</th><th style='text-align: center; padding: 5px; background: #ccc;'>توضيحات</th></tr><tr><td>".$info[1]['Service']['name']."</td><td>".$info[1]['Product']['name']."</td><td>".$info[1]['Product']['cost']."</td><td>".$this->Jtime->pdate("Y/n/j", $info[0]['Order']['date'])."</td><td>".$info[0]['Order']['desc']."</td></table></center><br />";
if(!isset($info[2])) {
$this->data['Ticket']['content'] .="برای نحوه پرداخت این سفارش با شما تماس گرفته خواهد شد.";
} else{
$this->data['Ticket']['content'] .="اعتبار شما در حال حاضر :".$info[2];
}
$this->data['Ticket']['ticketdepartment_id'] = 0;
$this->data['Ticket']['priority'] = 0;
$this->data['Ticket']['user_unread'] = 1;
$this->data['Ticket']['status'] = 6;
$this->postticket(1);

/**
$this->Email->to = $this->Auth->User('email');
$this->Email->from = $this -> setting['mail_title'].' <'.$this -> setting['mail_address'].'>';
$this->Email->subject = 'سفارش شماره '.$this->data['Order']['id'].' با موفقیت ثبت شد';
$this->Email->template = 'ordernew';
$this->Email->sendAs = 'html';
$this->Email->send();
**/

$this->Session->setFlash('سفارش شما با موفقیت ثبت شد', 'default', array('class' => 'success-msg'));
$this->redirect('/users/orders');
}else{
$this->Session->setFlash('سفارش شما ثبت نشد لطفا همه موارد را پر کنید.', 'default', array('class' => 'error-msg'));
}
} else{
$this->Session->setFlash('سفارش شما ثبت نشد لطفا همه موارد را پر کنید.', 'default', array('class' => 'error-msg'));
}

} else{
$this->Session->setFlash('لطفا دوره پرداخت مورد نظر خود را انتخاب نماييد', 'default', array('class' => 'error-msg'));
}
}
}else
{
$this->Session->setFlash('محصول مورد نظر پیدا نشد', 'default', array('class' => 'error-msg'));
$this->redirect('/users/home');
}
if(!empty($domain)) $this->data['Order']['desc'] = $domain;
$this->data['Order']['product_id'] = $product_id;
}

function reneworder ( $order_id )
{
//user's credit
$credit = $this -> Transaction -> find( 'first', array(
'conditions' => array(
'Transaction.user_id' => $this->Auth->user('id'),
'Transaction.confirmed' => 1
),
'fields' => array('SUM(Transaction.amount) as tot')
)
);

$this -> set ( 'credit', $credit[0]['tot'] );

$order = $this -> Order -> findById( $order_id );
if($order['Order']['user_id'] == $this->Auth->user('id'))
{
//product properties
$product = $this -> Product -> findById( $order['Order']['product_id'] );
if(!empty($product))
{
$this->set('order_id',$order_id);
$this -> set('order', $order );
$this -> set('product', $product );
$monthly=$product['Service']['monthly'];

$price=$this->costs($product['Product']['cost']);
$monthles[0] ='انتخاب کنید';
foreach($price as $month => $cost)
{
if($month==1)
$monthles[1] =' ماهیانه';
elseif($month==3)
$monthles[3] ='3 ماهه';
elseif($month==6)
$monthles[6] ='6 ماهه';
elseif($month==12)
$monthles[12] ='سالیانه';
elseif($month==24)
$monthles[24] ='دو ساله';
elseif($month==60)
$monthles[60] ='پنج ساله';
}
$this->set('monthlies',$monthles);
//if data fill in view
if($this->data){
if($order['Order']['discount']>0) $this->data['Order']['monthly'] = $order['Order']['monthly'];
if ( $this -> data['Order']['monthly'] != 0 )
{

//some of order's properties
//$this -> data['Order']['date'] = time();

//if user want to pay
if ( $this -> data['Order']['payment_method'] == 'credit' )
{
//check if user can payup for order
$product['Product']['cost'] = $price[$this->data['Order']['monthly']];
if ($credit[0]['tot'] < ($price[$this->data['Order']['monthly']] - $order['Order']['discount']) )
{
$this -> Session -> setFlash('متاسفانه اعتبار شما برای این سفارش کافی نمی باشد', 'default', array('class' => 'error-msg'));
}
else
{
//make Order confirmed option to one that indicate this order is payedup
$this->Order->id=$order_id;
$this->data['Order']['confirmed'] = 1;
if($order['Order']['next_pay'] < time())
$this->data['Order']['next_pay'] = time()+(2592000*$this->data['Order']['monthly']);
else
$this->data['Order']['next_pay'] = $order['Order']['next_pay']+(2592000*$this->data['Order']['monthly']);



//make sure that order save
if($this -> Order -> save($this -> data)){

$this -> data['Order']['id'] = $this -> Order -> id;

//make transaction properties

$trans['Transaction']['user_id'] = $this -> Auth ->User('id');
$trans['Transaction']['order_id'] = $this -> Order -> id;
$trans['Transaction']['amount'] = -($price[$this->data['Order']['monthly']] - $order['Order']['discount']);
$trans['Transaction']['date'] = time();
$trans['Transaction']['confirmed'] = 1;
$success = false;

if($product['Service']['api_id']){
$parameters['domain'] = $this->data['Order']['desc'];
$parameters['duration'] = $this->data['Order']['monthly'];
if($this->Directiapi->Create($parameters) != 'error'){
$this -> Transaction -> save($trans);
$success = true;
} else {
//Order Status ro bayad bezarim rooye yechizi ke neshoon bede error sabt shode.. masalan 5
$this->Session->setFlash('مشکلی در ثبت سفارش به وجود آمده است. لطفا با بخش پشتيبانی تماس حاصل فرماييد.', 'default', array('class' => 'error-msg'));
}
} else {
$this -> Transaction -> save($trans);
$success = true;
}

//save transaction

if($success)
{
//calculate new credit after payup
$credit = $this -> Transaction -> find( 'first', array(
'conditions' => array(
'Transaction.user_id' => $this->Auth->user('id'),
'Transaction.confirmed' => 1
),
'fields' => array(
'SUM(Transaction.amount) as tot'
)
)
);

//make an array for sending mail

$info = array( $this -> data , $product , $credit[0]['tot']);
$this -> set('info',$info);
$this->set('setting',$this->setting);

$checkticket = $this -> Ticket -> find( 'first', array('conditions' => array('Ticket.user_id' => $this -> Auth -> User('id'),'Ticket.title LIKE' => '%سفارش شماره '.$this -> data['Order']['id'].' با موفقیت ثبت شد%')));
if(empty($checkticket['Ticket']['id'])){
//open ticket
$this->data['Ticket']['title'] = 'سفارش شماره '.$this -> data['Order']['id'].' با موفقیت ثبت شد';
$this->data['Ticket']['content'] = "با سلام
سفارش شما به شماره ".$info[0]['Order']['id']."ثبت گردید
مشخصات محصول سفارش داده شده :
<center><table style='width: 96%; border: 1px solid #ccc;'><tr><th style='text-align: center; padding: 5px; background: #ccc;'>نام سرویس</th><th style='text-align: center; padding: 5px; background: #ccc;'>نام محصول</th><th style='text-align: center; padding: 5px; background: #ccc;'>قیمت</th><th style='text-align: center; padding: 5px; background: #ccc;'>تاریخ سفارش</th><th style='text-align: center; padding: 5px; background: #ccc;'>توضيحات</th></tr><tr><td>".$info[1]['Service']['name']."</td><td>".$info[1]['Product']['name']."</td><td>".$info[1]['Product']['cost']."</td><td>".$this->Jtime->pdate("Y/n/j", $info[0]['Order']['date'])."</td><td>".$info[0]['Order']['desc']."</td></table></center><br />";
if(!isset($info[2])) {
$this->data['Ticket']['content'] .="برای نحوه پرداخت این سفارش با شما تماس گرفته خواهد شد.";
} else{
$this->data['Ticket']['content'] .="اعتبار شما در حال حاضر :".$info[2];
}
$this->data['Ticket']['ticketdepartment_id'] = 0;
$this->data['Ticket']['priority'] = 0;
$this->data['Ticket']['user_unread'] = 1;
$this->data['Ticket']['status'] = 6;
$this->postticket(1);
}
else{
$this->data['Ticketreply']['content'] = 'سفارش شماره '.$order['Order']['id'].' پرداخت شد.
(اين پاسخ توسط سيستم و به صورت خودکار ثبت شد.)';
$this->data['Ticketreply']['user_unread'] = 1;
$this->data['Ticketreply']['status'] = 6;
$this->postticketreply($checkticket['Ticket']['id'],1);
}

/**
//send email
$this -> Email -> to = $this -> Auth -> User('email');
$this -> Email -> from = $this -> setting['mail_title'].' <'.$this -> setting['mail_address'].'>';
$this -> Email -> subject = 'سفارش شماره '.$this -> data['Order']['id'].' با موفقیت ثبت شد';
$this -> Email -> template = 'ordernew';
$this -> Email -> sendAs = 'html';
$this -> Email -> send();
**/
}
if( $success==true ) $this->Session->setFlash('سفارش شما با موفقیت ثبت شد', 'default', array('class' => 'success-msg'));
$this->redirect('/users/orders');

}else{
$this->Session->setFlash('سفارش شما ثبت نشد لطفا همه موارد را پر کنید.', 'default', array('class' => 'error-msg'));
}
}
}
else{
$this->Session->setFlash('سفارش شما ثبت نشد لطفا همه موارد را پر کنید.', 'default', array('class' => 'error-msg'));
}

} else{
$this->Session->setFlash('لطفا دوره پرداخت مورد نظر خود را انتخاب نماييد', 'default', array('class' => 'error-msg'));
}
}
}else
{
$this->Session->setFlash('محصول مورد نظر پیدا نشد', 'default', array('class' => 'error-msg'));
$this->redirect('/users/home');
}
$this->data['Order']['desc'] = $order['Order']['desc'];
$this->data['Order']['monthly'] = $order['Order']['monthly'];
$this->data['Order']['product_id'] = $order['Order']['product_id'];
}
else
{
$this->Session->setFlash('سفارش مربوط به شما نميباشد.', 'default', array('class' => 'error-msg'));
$this->redirect('/users/orders');
}
}

function serviceproducts ()
{
$this->layout = 'ajax';
$data = $this->Product->find('all',array('conditions' => array('Service.id' => $_POST['service_id'])));
$return='<option cost="0">انتخاب کنید</option>';
foreach ( $data as $row )
$return .= '<option value="'.$row['Product']['id'].'" cost="'.$row['Product']['cost'].'">'.$row['Product']['name'].'</option>';

echo $return;
}

function showByServiceId($service_id)
{
$this->set('products', $this->Product->findAllByServiceId($service_id));
$this->set('service', $this->Service->findById($service_id));
}

function showById($product_id)
{
$this->set('product',$this->Product->findById($product_id));
$this->set('product_id',$product_id);
}

function buy($product_id)
{
$data=array('Order'=>array('product_id'=>$product_id,'user_id'=>$this->Auth->user('id')));
$this->Order->save($data);
}

function whois()
{
$keys = array_keys($this->Whois->whois_servers);
foreach($keys as $key) $exts[$key] = $key;
$this->set('exts', $exts);
if(isset($this->data)){
$result = $this->Whois->lookupdomain($this->data['User']['domain'],$this->data['User']['ext']);
$ext = substr($this->data['User']['ext'],1);
$product = $this->Product->find('first',array('conditions'=> array("Product.name LIKE" => "%$ext%")));
$domain = array ( 'status' => $result['result'], 'domain' => $this->data['User']['domain'].$this->data['User']['ext'], 'product_id' => $product['Product']['id']);
$this->set('domain', $domain );
}
}

function confirmation($email , $hash)
{
$user=$this->User->find('first',array('conditions'=>array('User.email' =>base64_decode($email))));
$temp=substr(md5($user['User']['password'].'samansystems'),2,12);
if($temp == $hash)
{
$this->User->id=$user['User']['id'];
$user['User']['role']=0;
$this->User->save($user);
$this->Session->setFlash('شناسه کاربری شما با مو فقیت فعال شد', 'default', array('class' => 'success-msg'));
$this->redirect('/');
}else
{
$this->Session->setFlash('لینک وارد شده اشتباه است', 'default', array('class' => 'error-msg'));
$this->redirect('/');
}

}

function forget_password($step = NULL,$email = NULL, $key = NULL)
{
if($step == 'step2'){
$email_decode = base64_decode($email);
$user = $this->User->findByEmail($email_decode);
$org_key=$user['User']['password'].'samansystems';
$org_key=md5($org_key);
$org_key=substr($org_key,2,12);

if($org_key == $key){
if ( $this->data )
{
if ( $this->data['User']['password'] == $this->data['User']['password_confirm'] )
{
$this->User->id = $user['User']['id'];
$data['User']['password'] = $this->Auth->password($this->data['User']['password']);
if($this->User->save($data)){
$this->Session->setFlash('رمز عبور با موفقیت تغییر یافت', 'default', array('class' => 'success-msg'));

$this->set('setting',$this->setting);
$this->set('user',$user);
$this->set('password',$this->data['User']['password']);
$this->Email->to = $user['User']['email'];
$this->Email->from = $this -> setting['mail_title'].' <'.$this -> setting['mail_address'].'>' ;
$this->Email->subject = 'بازیابی رمز عبور';
$this->Email->template = 'forget_password_2';
$this->Email->sendAs = 'html';
$this->Email->send();
unset($this->data);
$this->redirect('/');
}
}
else
{
$this->Session->setFlash('رمز عبور شما با تکرار آن مطابقت ندارد', 'default', array('class' => 'error-msg'));
$this->redirect('/users/forget_password/step2/'.$email.'/'.$key.'/');
}
}
else{
$this->set('key',$key);
$this->set('email', $email);
$this->set('step', $step);
}
}
else{
$this->Session->setFlash('لينک وارد شده صحيح نيست.', 'default', array('class' => 'error-msg'));
$this->redirect('/');
}
}
elseif ( $this->data )
{
if ( $user = $this->User->findByEmail($this->data['User']['email']) )
{
$key=$user['User']['password'].'samansystems';
$key=md5($key);
$key=substr($key,2,12);
$this->set('user',$user);
$this->set('key',$key);
$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->setting['name'];
$this->Email->template = 'forget_password';
$this->Email->sendAs = 'html';
$this->Email->send();
$this->Session->setFlash('به منظور تکميل عمليات ايميلی برای شما ارسال شد.', 'default', array('class' => 'success-msg'));
$this->redirect('/');
}
else
{
$this->Session->setFlash('کاربری با این مشخصات یافت نشد', 'default', array('class' => 'error-msg'));
}
}
}

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('conditions'=>array('Ticket.user_id' =>$this->Auth->user('id')),'order' => array('Ticket.user_unread DESC','Ticket.status ASC','Ticket.priority DESC')));
$this->set('tickets',$tickets);
}
else
{
$tickets=$this->Ticket->find('first',array('conditions'=>array('Ticket.user_id' =>$this->Auth->user('id') , 'Ticket.id'=>$ticket_id),'recursive' => 1));
$ticketreplies=$this->Ticketreply->find('all',array('conditions'=>array('Ticketreply.ticket_id'=>$ticket_id, 'Ticketreply.note'=>0),'order' => array('Ticketreply.date ASC'),'recursive' => 1));

if ($tickets['Ticket']['user_id'] != $this->Auth->user('id'))
{
$this->Session->setFlash('تيکت مربوط به شما نمي باشد.','default', array('class' => 'error-msg'));
$this->redirect(array('controller' => 'users','action' => 'tickets'));
}
elseif ($tickets['Ticket']['user_unread'] == 1)
{
$temp['Ticket']['user_unread'] = 0;
$this->Ticket->id = $tickets['Ticket']['id'];
$this->Ticket->save($temp);
}
$this->set('setting',$this -> setting);
$this->set('ticketreplies',$ticketreplies);
$this->set('ticket',$tickets);
}

}
function postticket($remote = 0)
{
if (!empty($this->data)) {
$this->data['Ticket']['user_id'] = $this->Auth->user('id');
$this->data['Ticket']['date'] = time();
if ($this->Ticket->save($this->data)) {

$temp['Ticketreply']['content']=$this->data['Ticket']['content'];
if(!$remote)
$temp['Ticketreply']['user_id'] = $this->Auth->user('id');
else
$temp['Ticketreply']['user_id'] = 0;
$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',$this->blockqoute($this->data['Ticket']['content']));
$this->set('ticket_id',$this->Ticket->id);
$this->set('opendate',$this->data['Ticket']['date']);
$this->set('setting',$this->setting);
$this->Email->to = $this -> setting['mail_address'];
$this->Email->from = $this->Auth->user('name').' <'.$this->Auth->user('email').'>';
$this->Email->subject = 'تيکت جديد: #'.$this->Ticket->id.' - '.$this->data['Ticket']['title'];
$this->Email->template = 'ticketopen';
$this->Email->sendAs = 'html';
$this->Email->send();
if($remote){
$this->Email->reset();
$this->Email->to = $this->Auth->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();
}
}
if(!$remote){
$this->Session->setFlash('تيکت شما با موفقيت ثبت شد.','default', array('class' => 'success-msg'));
$this->redirect(array('controller' => 'users','action' => 'tickets',$this->Ticket->id));
}
}
}
}
else
{
$this->set('priorities',array('0'=>'عادی','1'=>'مهم','2'=>'خيلی مهم'));
$this->set('departments',$this->Ticketdepartment->find('list',array('fields'=> array('Ticketdepartment.id','Ticketdepartment.name '))));
}
}
function postticketreply($ticket_id,$remote = 0)
{
$ticket=$this->Ticket->find('first',array('conditions'=>array('Ticket.user_id' =>$this->Auth->user('id') , 'Ticket.id'=>$ticket_id)));
if(!empty($ticket)){
if (!empty($this->data)) {
$this->data['Ticketreply']['ticket_id'] = $ticket_id;
if(!$remote)
$this->data['Ticketreply']['user_id'] = $this->Auth->user('id');
else
$this->data['Ticketreply']['user_id'] = 0;
$this->data['Ticketreply']['date'] = time();
$this->Ticketreply->create();
$this->Ticketreply->save($this->data);
if($this -> setting['send_email']==1)
{
$this->set('reply_content',$this->blockqoute($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 = $this -> setting['mail_address'];
$this->Email->from = $user['User']['name'].' <'.$user['User']['email'].'>';
$this->Email->subject = 'پاسخ جديد در تيکت: #'.$ticket_id.' - '.$ticket['Ticket']['title'];
$this->Email->template = 'ticketreply';
$this->Email->sendAs = 'html';
$this->Email->send();
}

if($this->Ticketreply->save($this->data))
{
$temp['Ticketreply']['user_unread'] = $this->data['Ticketreply']['user_unread'];
$temp['Ticketreply']['status'] = $this->data['Ticketreply']['status'];
unset($this->data);
$this->Ticket->id = $ticket_id;
if(!$remote){
$this->data['Ticket']['status'] = 2;
}
else{
$this->data['Ticket']['status'] = $temp['Ticketreply']['user_unread'];
$this->data['Ticket']['status'] = $temp['Ticketreply']['status'];
}
$this->Ticket->save($this->data);
if(!$remote){
$this->Session->setFlash('پاسخ به تيکت مورد نظر با موفقيت ارسال شد.','default', array('class' => 'success-msg'));
}
}else
$this->Session->setFlash('پاسخ ارسالی بايد حاوی نوشته باشد.','default', array('class' => 'error-msg'));
if(!$remote){
$this->redirect(array('controller' => 'users','action' => 'tickets',$ticket_id));
}
}
}
else
{
$this->Session->setFlash('تيکت مربوط به شما نمي باشد.','default', array('class' => 'error-msg'));
$this->redirect(array('controller' => 'users','action' => 'tickets'));
}
}
function closeticket($ticket_id)
{
$ticket=$this->Ticket->find('first',array('conditions'=>array('Ticket.user_id' =>$this->Auth->user('id') , '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' => 'users','action' => 'tickets',$ticket_id));
}
}
else
{
$this->Session->setFlash('تيکت مربوط به شما نمي باشد.','default', array('class' => 'error-msg'));
$this->redirect(array('controller' => 'users','action' => 'tickets'));
}
}
function refer_user()
{
$this->set('website',$this->setting['website']);
$this->set('base64mail',base64_encode ($this->Auth->user('email')));
$referred_users=$this->User->find('all',array('conditions'=>array('User.referrer_id' => $this->Auth->user('id')) ,'fields'=>array('id','name','company','role')));
$this->set('referred_users',$referred_users);
}
function sendconfirmatinemail()
{
$user = $this->User->findById($this->Auth->user('id'));
$key=md5($user['User']['password'].'samansystems');
$key=substr($key,2,12);
$this->set('info',$this->Auth->user());
$this->set('setting',$this->setting);
$this->set('key',$key);
$this->Email->to = $this->Auth->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('لطفا ايميل خود را چک کنيد و مراحل ثبت نام را تکميل کنيد. ممکن است ايميل در شاخه اسپم یا بالک قرار گيرد.', 'default', array('class' => 'success-msg'));
$this->redirect('/users/home');
}


function getprice($product_id,$duration){
$this->layout = 'ajax';
$product=$this->Product->find('first',array('conditions'=>array('Product.id'=>$product_id), 'fields' => array('Product.cost'),'recursive' =>-1));
$price=$this->costs($product['Product']['cost']);
echo $price[$duration];
}

function verify_online($merchent){
$url = $this->params['url'];
$res = $this->{$merchent}->Verify($url);
if($res){
if($this->Auth->user('referrer_id') != 0){
$this->Transaction->create();
$temp['Transaction']['date'] = time();
$temp['Transaction']['amount'] = ($this->setting['top_user_percent']/100)*$res['Transaction']['amount'];
$temp['Transaction']['user_id'] = $this->Auth->user('referrer_id');
$temp['Transaction']['payment_id'] = 0;
$temp['Transaction']['confirmed'] = 1;
$temp['Transaction']['desc'] = 'پورسانت حاصل از تراکنش آنلاين کاربر'.$res['Transaction']['user_id'];
$this->Transaction->save($temp);
}
$this->Session->setFlash('تراکنش شما با موفقيت ثبت گرديد', 'default', array('class' => 'success-msg'));
$this->redirect(array('controller'=>'users', 'action' => 'home'));
}else{
$this->Session->setFlash('مشکلی در ثبت تراکنش به وجود آمده است', 'default', array('class' => 'error-msg'));
$this->redirect(array('controller'=>'users', 'action' => 'home'));
}
}
}

?>

مشکل حل خواهد شد .

alizali
March 8th, 2014, 17:23
باتشکر از عصرهاستینگ
تغییرات داده شد ولی مشکل همچنان پابرجاست

جناب سامان سیستم اطلاعات ارسال شد
خیلی ممنونم

asrhosting
March 9th, 2014, 09:31
باتشکر از عصرهاستینگ
تغییرات داده شد ولی مشکل همچنان پابرجاست

جناب سامان سیستم اطلاعات ارسال شد
خیلی ممنونم

هاستتون دایرکت ادمین نیست ؟
این مشکل می تونه برای این باشه که مازولی از کار افتاده یا soap دچار مشکل شده .
ماژول های بانکی تون رو بررسی کنید .

alizali
March 9th, 2014, 10:28
هاستتون دایرکت ادمین نیست ؟
این مشکل می تونه برای این باشه که مازولی از کار افتاده یا soap دچار مشکل شده .
ماژول های بانکی تون رو بررسی کنید .

خیر سی پنل است
ماژوب بانک هم فعال نبوده از اول
برای پرداختهای از اسکریپت دیگری استفاده میشده که هنوز هم فعال است

alizali
March 19th, 2014, 00:01
والا ما موندیم باید چه کنیم
کلیه فایلها رو پاک کردم
دوباره اوررایت کردم
دو تا فایل کنترلر رو هم تغییر دادم
و الان در هوم پیج این ارورها رو داریم
Deprecated: Assigning the return value of new by reference is deprecated in /home/paydarho/public_html/cake/libs/inflector.php on line 131

Deprecated: Assigning the return value of new by reference is deprecated in /home/paydarho/public_html/cake/libs/configure.php on line 136

Deprecated: Assigning the return value of new by reference is deprecated in /home/paydarho/public_html/cake/libs/configure.php on line 226

Deprecated: Assigning the return value of new by reference is deprecated in /home/paydarho/public_html/cake/libs/configure.php on line 903

Deprecated: Assigning the return value of new by reference is deprecated in /home/paydarho/public_html/cake/libs/configure.php on line 943

Deprecated: Assigning the return value of new by reference is deprecated in /home/paydarho/public_html/cake/libs/cache.php on line 71

Deprecated: Assigning the return value of new by reference is deprecated in /home/paydarho/public_html/cake/libs/cache.php on line 155