Rev 15403 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?phpApp::uses('AppController', 'Controller');/*** Stores Controller** @property Store $Store* @property PaginatorComponent $Paginator*/class StoresController extends AppController {/*** Components** @var array*/public $components = array('Paginator');public function beforeFilter() {parent::beforeFilter();$this->Auth->allow('redirectto');}/*** index method** @return void*/public function index() {throw new NotFoundException(__('Unauthorized access'));$this->Store->recursive = 0;$this->set('stores', $this->Paginator->paginate());}/*** view method** @throws NotFoundException* @param string $id* @return void*/public function view($id = null) {throw new NotFoundException(__('Unauthorized access'));if (!$this->Store->exists($id)) {throw new NotFoundException(__('Invalid store'));}$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));$this->set('store', $this->Store->find('first', $options));}public function redirectto(){$this->layout = 'innerpages';$userId = $this->request->query('user_id');if(isset($userId) && !empty($userId)){$this->loadModel('User');$dbuser = $this->User->findById($userId);$this->Auth->login($dbuser['User']);}$storeId = $this->request->query('store_id');$cachekey = 'store-'.$storeId;// $store = Cache::read($cachekey,'month');if(empty($store)) {$store = $this->Store->find('first',array('recursive'=>-1,'conditions'=>array('id'=>$storeId)));Cache::write($cachekey,$store,'month');}$prefix = "SHA".$storeId;$tag = $prefix.time();if($storeId == 2){$url = "http://dl.flipkart.com/dl/";} elseif($storeId == 3) {$url = "http://m.snapdeal.com/products/mobiles?utm_source=aff_prog&utm_campaign=afts&offer_id=17";} elseif($storeId == 1){$url = "http://www.amazon.in/gp/goldbox";}if( strpos($url, '?') === false ) {$firstChar = '?';} else {$firstChar = '&';}$url .= $firstChar.$store['Store']['affid_param'].'='.$store['Store']['affiliate_id'];if(!empty($store['Store']['sub_tag_param'])){$url .= '&'.$store['Store']['sub_tag_param'].'='.$tag;}$extras = array('store'=>$store['Store']['name']);$data = array('user_id'=>$userId,'store_product_id'=>0,'price'=>0,'tag'=>$tag,'url'=>$url,'extras'=>json_encode($extras));$this->loadModel('Click');$this->Click->create();if ($this->Click->save($data)) {$result = array('success'=>true,'message'=>__('The click has been saved.'),'type'=>'redirect','url'=>$url);} else {$result = array('success'=>false,'message'=>__('The click could not be saved. Please, try again.'));}$this->set(compact('store','url'));}/*** add method** @return void*/public function add() {throw new NotFoundException(__('Unauthorized access'));if ($this->request->is('post')) {$this->Store->create();if ($this->Store->save($this->request->data)) {$this->Session->setFlash(__('The store has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The store could not be saved. Please, try again.'));}}$affiliates = $this->Store->Affiliate->find('list');$this->set(compact('affiliates'));}/*** edit method** @throws NotFoundException* @param string $id* @return void*/public function edit($id = null) {throw new NotFoundException(__('Unauthorized access'));if (!$this->Store->exists($id)) {throw new NotFoundException(__('Invalid store'));}if ($this->request->is(array('post', 'put'))) {if ($this->Store->save($this->request->data)) {$this->Session->setFlash(__('The store has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The store could not be saved. Please, try again.'));}} else {$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));$this->request->data = $this->Store->find('first', $options);}$affiliates = $this->Store->Affiliate->find('list');$this->set(compact('affiliates'));}/*** delete method** @throws NotFoundException* @param string $id* @return void*/public function delete($id = null) {throw new NotFoundException(__('Unauthorized access'));$this->Store->id = $id;if (!$this->Store->exists()) {throw new NotFoundException(__('Invalid store'));}$this->request->onlyAllow('post', 'delete');if ($this->Store->delete()) {$this->Session->setFlash(__('The store has been deleted.'));} else {$this->Session->setFlash(__('The store could not be deleted. Please, try again.'));}return $this->redirect(array('action' => 'index'));}/*** admin_index method** @return void*/public function admin_index() {throw new NotFoundException(__('Unauthorized access'));$this->Store->recursive = 0;$this->set('stores', $this->Paginator->paginate());}/*** admin_view method** @throws NotFoundException* @param string $id* @return void*/public function admin_view($id = null) {throw new NotFoundException(__('Unauthorized access'));if (!$this->Store->exists($id)) {throw new NotFoundException(__('Invalid store'));}$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));$this->set('store', $this->Store->find('first', $options));}/*** admin_add method** @return void*/public function admin_add() {throw new NotFoundException(__('Unauthorized access'));if ($this->request->is('post')) {$this->Store->create();if ($this->Store->save($this->request->data)) {$this->Session->setFlash(__('The store has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The store could not be saved. Please, try again.'));}}$statuses = array('active'=>'Active','paused'=>'Paused','deleted'=>'Deleted');$cashback_statuses = array('active'=>'Active','inactive'=>'In-active');$this->set(compact('statuses','cashback_statuses'));}/*** admin_edit method** @throws NotFoundException* @param string $id* @return void*/public function admin_edit($id = null) {throw new NotFoundException(__('Unauthorized access'));if (!$this->Store->exists($id)) {throw new NotFoundException(__('Invalid store'));}if ($this->request->is(array('post', 'put'))) {if ($this->Store->save($this->request->data)) {$this->Session->setFlash(__('The store has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The store could not be saved. Please, try again.'));}} else {$options = array('conditions' => array('Store.' . $this->Store->primaryKey => $id));$this->request->data = $this->Store->find('first', $options);}$statuses = array('active'=>'Active','paused'=>'Paused','deleted'=>'Deleted');$cashback_statuses = array('active'=>'Active','inactive'=>'In-active');$this->set(compact('statuses','cashback_statuses'));}/*** admin_delete method** @throws NotFoundException* @param string $id* @return void*/public function admin_delete($id = null) {throw new NotFoundException(__('Unauthorized access'));$this->Store->id = $id;if (!$this->Store->exists()) {throw new NotFoundException(__('Invalid store'));}$this->request->onlyAllow('post', 'delete');if ($this->Store->delete()) {$this->Session->setFlash(__('The store has been deleted.'));} else {$this->Session->setFlash(__('The store could not be deleted. Please, try again.'));}return $this->redirect(array('action' => 'index'));}}