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'); /** * Subtopics Controller * * @property Subtopic $Subtopic * @property PaginatorComponent $Paginator */ class SubtopicsController extends AppController { private function __getCommonConditions(&$conditions, &$keyword = null, &$opticId = null) { if ( isset($this->params->query['keyword']) && !empty($this->params->query['keyword']) ) { $keyword = $this->params->query['keyword']; $conditions['OR'] = array( 'Subtopic.name LIKE' => '%' . $keyword . '%', 'Subtopic.note LIKE' => '%' . $keyword . '%' ); } if ( isset($this->params->query['topic_id']) && !empty($this->params->query['topic_id']) ) { $topicId = $this->params->query['topic_id']; $conditions['AND']['Subtopic.topic_id'] = $topicId; } } /** * admin_index method * * @return void */ public function admin_index() { $conditions = array(); $keyword = ''; $topicId = ''; $this->__getCommonConditions($conditions, $keyword, $topicId); $this->Paginator->settings['conditions'] = $conditions; $this->Subtopic->recursive = 0; $this->set('subtopics', $this->Paginator->paginate()); $this->set('topicTitle', __('ประเภทสิทธิย่อย')); $this->set('topics', $this->Subtopic->Topic->find('list')); $this->set('keyword', $keyword); $this->set('topic_id', $topicId); } /** * admin_view method * * @throws NotFoundException * @param string $id * @return void */ public function admin_view($id = null) { if (!$this->Subtopic->exists($id)) { throw new NotFoundException(__('Invalid subtopic')); } $options = array('conditions' => array('Subtopic.' . $this->Subtopic->primaryKey => $id)); $this->set('subtopic', $this->Subtopic->find('first', $options)); } /** * admin_add method * * @return void */ public function admin_add() { if ($this->request->is('post')) { $this->Subtopic->create(); if ($this->Subtopic->save($this->request->data)) { $this->Session->setFlash(__('บันทึกขอมูลประเภทสิทธิย่อยสำเร็จ'), 'flash-success'); return $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('ไม่สามารถบันทึกข้อมูลประเภทสิทธิย่อยได้ กรุณาลองใหม่อีกครั้ง')); } } $topics = $this->Subtopic->Topic->find('list'); $activities = $this->Subtopic->Activity->find('list'); $organizations = $this->Subtopic->Organization->find('list'); $people = $this->Subtopic->Person->find('list'); $this->set(compact('topics', 'activities', 'organizations', 'people')); $this->set('topicTitle', __('เพิ่มประเภทสิทธิย่อย')); } /** * admin_edit method * * @throws NotFoundException * @param string $id * @return void */ public function admin_edit($id = null) { if (!$this->Subtopic->exists($id)) { throw new NotFoundException(__('Invalid subtopic')); } if ($this->request->is('post') || $this->request->is('put')) { $this->Subtopic->id = $id; if ($this->Subtopic->save($this->request->data)) { $this->Session->setFlash(__('บันทึกข้อมูลประเภทสิทธิย่อยสำเร็จ'), 'flash-success'); return $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('ไม่สามารถบันทึกข้อมูลประเภทสิทธิย่อยได้ กรุณาลองใหม่อีกครั้ง'), 'flash-fail'); } } else { $options = array('conditions' => array('Subtopic.' . $this->Subtopic->primaryKey => $id)); $subtopic = $this->Subtopic->find('first', $options); $this->request->data = $subtopic; } $topics = $this->Subtopic->Topic->find('list'); $activities = $this->Subtopic->Activity->find('list'); $organizations = $this->Subtopic->Organization->find('list'); $people = $this->Subtopic->Person->find('list'); $this->set(compact('topics', 'activities', 'organizations', 'people')); $this->set('topicTitle', __('แก้ไขข้อมูล: ') . $subtopic['Subtopic']['name']); } /** * admin_delete method * * @throws NotFoundException * @param string $id * @return void */ public function admin_delete($id = null) { $this->Subtopic->id = $id; if (!$this->Subtopic->exists()) { throw new NotFoundException(__('Invalid subtopic')); } //Allowed only `post` method. $this->request->onlyAllow('post', 'delete'); $model = array('OrganizationsSubtopic', 'ActivitiesSubtopic', 'PeopleSubtopic'); //Check `Subtopic` use for people, organization and activity? //If use in somewhere not allowed to delete. for ( $i = 0; $i < count($model); $i++ ) { $this->loadModel( $model[$i] ); $conditions = array( $model[$i] . '.subtopic_id' => $id ); if ( $this->$model[$i]->hasAny( $conditions ) ) { $this->Session->setFlash(__('ประเภทสิทธิย่อยถูกใช้งานอยู่'), 'flash-fail'); $this->redirect(array('action' => 'index', 'admin' => true)); } } if ( !$this->Subtopic->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)); } /** * Get `Sub topic` list. * use topic's id to get all sub topic that belong to topic. * * @param integer $id id of topic * @return json list of `Sub topic` * @author 3Musketeers <3musketeersteam@gmail.com> * @since 14 October 2013 */ public function get( $id = null ) { $this->autoRender = false; $subtopics = $this->Subtopic->find('list', array( 'conditions' => array('Subtopic.topic_id' => $id), 'recursive' => -1 )); if ( !empty($subtopics) ) { return json_encode($subtopics); } return json_encode(false); } public function admin_export() { Configure::write('debug',0); // just in case $this->autoRender = false; // thanks, but no. $modelName = $this->modelClass; $conditions = array(); $this->__getCommonConditions($conditions); // Find fields needed without recursing through associated models $data = $this->{$modelName}->find('all', array( 'conditions' => $conditions, 'order' => $modelName . '.id ASC', 'recursive' => 0 )); // Define column headers for CSV file, in same array format as the data itself $headers = array( $modelName => array( 'id' => __('รหัส'), 'name' => __('ประเภทสิทธิย่อย'), 'topic' => __('ประเภทสิทธิหลัก'), 'note' => __('หมายเหตุ'), 'created' => __('วันที่เพิ่มข้อมูล'), 'modified' => __('แก้ไขล่าสุด') ) ); // $roles = array(); foreach ( $data as &$d ) { $d = array( $modelName => array( 'id' => $d['Subtopic']['id'], 'name' => $d['Subtopic']['name'], 'topic' => $d['Topic']['name'], 'note' => $d['Subtopic']['note'], 'created' => $d['Subtopic']['created'], 'modified' => $d['Subtopic']['modified'] ) ); } $this->set('model', $modelName); if ( $this->request->params['ext'] == 'csv' ) { // Add headers to start of data array array_unshift($data, $headers); // Make the data available to the view (and the resulting CSV file) $this->set(compact('data')); $this->render('/Elements/csv/admin_export', false); } else { $this->set('topicTitle', __('ประเภทสิทธิย่อย')); $this->_renderPdf($data, 'admin_export'); } } }