Rev 15761 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?phpApp::uses('AppController', 'Controller');/*** UserAddresses Controller** @property UserAddress $UserAddress* @property PaginatorComponent $Paginator*/class UserAddressesController extends AppController {/*** Components** @var array*/public $components = array('Paginator');/*** index method** @return void*/public function index() {$this->UserAddress->recursive = 0;$this->set('userAddresses', $this->Paginator->paginate());}/*** view method** @throws NotFoundException* @param string $id* @return void*/public function view($id = null) {if (!$this->UserAddress->exists($id)) {throw new NotFoundException(__('Invalid user address'));}$options = array('conditions' => array('UserAddress.' . $this->UserAddress->primaryKey => $id));$this->set('userAddress', $this->UserAddress->find('first', $options));}/*** add method** @return void*/public function add() {if ($this->request->is('post')) {$this->UserAddress->create();if ($this->UserAddress->save($this->request->data)) {$this->Session->setFlash(__('The user address has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The user address could not be saved. Please, try again.'));}}}/*** edit method** @throws NotFoundException* @param string $id* @return void*/public function edit($id = null) {if (!$this->UserAddress->exists($id)) {throw new NotFoundException(__('Invalid user address'));}if ($this->request->is(array('post', 'put'))) {if ($this->UserAddress->save($this->request->data)) {$this->Session->setFlash(__('The user address has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The user address could not be saved. Please, try again.'));}} else {$options = array('conditions' => array('UserAddress.' . $this->UserAddress->primaryKey => $id));$this->request->data = $this->UserAddress->find('first', $options);}}/*** delete method** @throws NotFoundException* @param string $id* @return void*/public function delete($id = null) {$this->UserAddress->id = $id;if (!$this->UserAddress->exists()) {throw new NotFoundException(__('Invalid user address'));}$this->request->onlyAllow('post', 'delete');if ($this->UserAddress->delete()) {$this->Session->setFlash(__('The user address has been deleted.'));} else {$this->Session->setFlash(__('The user address could not be deleted. Please, try again.'));}return $this->redirect(array('action' => 'index'));}/*** admin_index method** @return void*/public function admin_index() {$this->UserAddress->recursive = 0;$this->set('userAddresses', $this->Paginator->paginate());}/*** admin_view method** @throws NotFoundException* @param string $id* @return void*/public function admin_view($id = null) {if (!$this->UserAddress->exists($id)) {throw new NotFoundException(__('Invalid user address'));}$options = array('conditions' => array('UserAddress.' . $this->UserAddress->primaryKey => $id));$this->set('userAddress', $this->UserAddress->find('first', $options));}/*** admin_add method** @return void*/public function admin_add() {if ($this->request->is('post')) {$this->UserAddress->create();if ($this->UserAddress->save($this->request->data)) {$this->Session->setFlash(__('The user address has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The user address could not be saved. Please, try again.'));}}}/*** admin_edit method** @throws NotFoundException* @param string $id* @return void*/public function admin_edit($id = null) {if (!$this->UserAddress->exists($id)) {throw new NotFoundException(__('Invalid user address'));}if ($this->request->is(array('post', 'put'))) {if ($this->UserAddress->save($this->request->data)) {$this->Session->setFlash(__('The user address has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The user address could not be saved. Please, try again.'));}} else {$options = array('conditions' => array('UserAddress.' . $this->UserAddress->primaryKey => $id));$this->request->data = $this->UserAddress->find('first', $options);}}/*** admin_delete method** @throws NotFoundException* @param string $id* @return void*/public function admin_delete($id = null) {$this->UserAddress->id = $id;if (!$this->UserAddress->exists()) {throw new NotFoundException(__('Invalid user address'));}$this->request->onlyAllow('post', 'delete');if ($this->UserAddress->delete()) {$this->Session->setFlash(__('The user address has been deleted.'));} else {$this->Session->setFlash(__('The user address could not be deleted. Please, try again.'));}return $this->redirect(array('action' => 'index'));}public function admin_by($userId = null) {$postOfficeQuery="select pincode,state from postoffices group by pincode";$postOfficeResult=$this->UserAddress->query($postOfficeQuery);$postOffice=array();foreach($postOfficeResult as $value){$postOffice[$value['postoffices']['pincode']]=$value['postoffices']['state'];}$retailerAddress="SELECT r.title,r.address, r.city,r.state,r.pin from retaileraddresses r join retailerlinks rl on r.retailer_id=rl.retailer_id where rl.user_id=$userId";$new_address=$this->UserAddress->query($retailerAddress);$retailerAddress="SELECT title,address,city,state,pin from retailers r join retailerlinks rl on r.id=rl.retailer_id where rl.user_id=$userId";$retailer_address=$this->UserAddress->query($retailerAddress);$retailerAddress="SELECT ua.store_name,ua.address,ua.city,ua.state,ua.pincode from user_addresses ua join users u on ua.user_id=u.id where ua.user_id=$userId";$user_update_address=$this->UserAddress->query($retailerAddress);$retailerAddress="SELECT concat(' ', address_line_1,address_line_2) as address,city,state,pincode from users where id=$userId";$user_address=$this->UserAddress->query($retailerAddress);if($user_address[0]['users']['state']==null){if($user_address[0]['users']['pincode']==null){}else{$user_address[0]['users']['state']=$postOffice[$user_address[0]['users']['pincode']];}}if(empty($new_address)){}else{if(empty($new_address[0]['r']['state'])){$new_address[0]['r']['state']=$postOffice[$new_address[0]['r']['pin']];}}if(empty($retailer_address)){}else{if(empty($retailer_address[0]['r']['state'])){$retailer_address[0]['r']['state']=$postOffice[$retailer_address[0]['r']['pin']];}}if(empty($user_update_address)){}else{if(empty($user_update_address[0]['ua']['state'])){$user_update_address[0]['ua']['state']=$postOffice[$user_update_address[0]['ua']['pincode']];}}$this->set('newaddress', $new_address);$this->set('retaileraddress', $retailer_address);$this->set('userupdateaddress', $user_update_address);$this->set('useraddress', $user_address);}}