Server IP : 180.180.241.3 / Your IP : 216.73.216.194 Web Server : Microsoft-IIS/7.5 System : Windows NT NETWORK-NHRC 6.1 build 7601 (Windows Server 2008 R2 Standard Edition Service Pack 1) i586 User : IUSR ( 0) PHP Version : 5.3.28 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/AppServ/www/app/Controller/ |
Upload File : |
<?php App::uses('AppController', 'Controller'); /** * Targets Controller * * @property Target $Target * @property PaginatorComponent $Paginator */ class TargetsController extends AppController { /** * List all `target` * * @author 3Musketeers <3musketeersteam@gmail.com> * @since 28 September 2013 */ public function admin_index() { $conditions = array(); $keyword = ''; $this->_getCommonConditions($conditions, $keyword); $this->Paginator->settings['conditions'] = $conditions; $this->Target->recursive = 0; $this->set('targets', $this->Paginator->paginate()); $this->set('topicTitle', __('กลุ่มเป้าหมาย')); $this->set('keyword', $keyword); } /** * Add `target` information * * @author 3Muksteers <3muksteersteam@gmail.com> * @since 28 September 2013 */ public function admin_add() { if ( $this->request->is('post') ) { $this->Target->create(); if ( !$this->Target->save($this->request->data) ) { $this->Session->setFlash(__('ไม่สามารถบันทึกข้อมูลกลุมเป้าหมายได้ กรุณาลองใหม่อีกครั้ง'), 'flash-fail'); $this->redirect(array('action' => 'index', 'admin' => true)); } $this->Session->setFlash(__('บันทึกข้อมูลกลุ่มเป้าหมายสำเร็จ'), 'flash-success'); $this->redirect(array('action' => 'index', 'admin' => true)); } $this->set('topicTitle', __('เพิ่มกลุ่มเป้าหมาย')); } /** * Get `target` detail and edit the information * * @throws NotFoundException if not found any record * @param string $id id of target * @author 3Musketeers <3musketeersteam@gmail.com> * @since 28 September 2013 */ public function admin_edit( $id = null ) { if (!$this->Target->exists($id)) { throw new NotFoundException(__('ไม่พบข้อมูลกลุ่มเป้าหมาย')); } if ( $this->request->is('post') || $this->request->is('put') ) { $this->Target->id = $id; if ( !$this->Target->save($this->request->data) ) { $this->Session->setFlash(__('ไม่สามารถบันทึกข้อมูลกลุ่มเป้าหมายได้ กรุณาลองใหม่อีกครั้ง'), 'flash-fail'); $this->redirect(array('action' => 'index', 'admin' => true)); } $this->Session->setFlash(__('บันทึกข้อมูลกลุ่มเป้าหมายสำเร็จ'), 'flash-success'); return $this->redirect(array('action' => 'index', 'admin' => true)); } //Find `target` data by id. $this->Target->recursive = -1; $target = $this->Target->findById($id); $this->set('target', $target); $this->set('topicTitle', __('แก้ไขข้อมูล: ') . $target['Target']['name']); } /** * Remove `target` information accually just set `is_activated` to false in `AppModel::delete()` * * @throws NotFoundException if not found any record * @param string $id id of target. * @author 3Muksteers <3musketeersteam@gmail.com> * @since 28 September 2013 */ public function admin_delete( $id = null ) { $this->Target->id = $id; if ( !$this->Target->exists() ) { throw new NotFoundException(__('ไม่พบข้อมูลกลุ่มเป้าหมาย')); } //Allowed only `post` method. $this->request->onlyAllow('post', 'delete'); $model = array('OrganizationsTarget', 'PeopleTarget'); //Check `Target` use for people, organization? //If use in somewhere not allowed to delete. for ( $i = 0; $i < count($model); $i++ ) { $this->loadModel( $model[$i] ); $conditions = array( $model[$i] . '.target_id' => $id ); if ( $this->$model[$i]->hasAny( $conditions ) ) { $this->Session->setFlash(__('กลุ่มเป้าหมายถูกใช้งานอยู่'), 'flash-fail'); $this->redirect(array('action' => 'index', 'admin' => true)); } } if ( !$this->Target->delete() ) { $this->Session->setFlash(__('ไม่สามารถลบข้อมูลกลุ่มเป้าหมายได้ กรุณาลองใหม่อีกครั้ง'), 'flash-fail'); $this->redirect(array('action' => 'index', 'admin' => true)); } $this->Session->setFlash(__('ลบข้อมูลกลุ่มเป้าหมายสำเร็จ'), 'flash-success'); $this->redirect(array('action' => 'index', 'admin' => true)); } public function admin_export() { $this->set('topicTitle', __('กลุ่มเป้าหมาย')); parent::admin_export(); } }