| Server IP : 180.180.241.3 / Your IP : 216.73.216.35 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 : /AppServ/www/app/Controller/ |
Upload File : |
<?php
App::uses('AppController', 'Controller');
/**
* Topics Controller
*
* @property Topic $Topic
* @property PaginatorComponent $Paginator
*/
class TopicsController extends AppController {
/**
* List all of topic information
*
* @author 3Musketeers <3Musketeersteam@gmal.com>
* @since 28 September 2013
*/
public function admin_index() {
$conditions = array();
$keyword = '';
$this->_getCommonConditions($conditions, $keyword);
$this->Paginator->settings['conditions'] = $conditions;
$this->Topic->recursive = 0;
$this->set('topics', $this->Paginator->paginate());
$this->set('topicTitle', 'ประเภทสิทธิหลัก');
$this->set('title_for_layout', 'ประเภทสิทธิหลัก');
$this->set('keyword', $keyword);
}
/**
* Add `topic` information.
*
* @author 3Musketeers <3musketeersteam@gmail.com>
* @since 28 September 2013
*/
public function admin_add() {
if ($this->request->is('post')) {
$this->Topic->create();
if ( !$this->Topic->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', 'เพิ่มประเภทสิทธิหลัก');
}
/**
* edit `topic` information
*
* @throws NotFoundException
* @param string $id the id of topic.
* @author 3Musketeers <3Musketeersteam@gmail.com>
* @since 28 September 2013
*/
public function admin_edit( $id = null ) {
//If not found any topic information.
if ( !$this->Topic->exists($id) ) {
throw new NotFoundException(__('ไม่พบข้อมูลประเภทสิทธิหลัก'));
}
if ( $this->request->is('post') || $this->request->is('put') ) {
$this->Topic->id = $id;
if ( !$this->Topic->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));
}
//get topic information by `id`.
$this->Topic->recursive = -1;
$topic = $this->Topic->findById($id);
$this->set('topic', $topic);
$this->set('topicTitle', __('แก้ไขข้อมูล: ') . $topic['Topic']['name']);
}
/**
* Remove `topic`
*
* This action will send request to `AppModel::delete()` for set `is_activated` to `false`
* then return `true` back to this action.
*
* @throws NotFoundException
* @param string $id id topic.
* @author 3Muketeers <3Musketeersteam@gmail.com>
* @since 28 September 2013
*/
public function admin_delete( $id = null ) {
$this->Topic->id = $id;
if (!$this->Topic->exists()) {
throw new NotFoundException(__('Invalid topic'));
}
//Allowed only `post` action.
$this->request->onlyAllow('post', 'delete');
$conditions = array( 'Subtopic.topic_id' => $id );
if ( $this->Topic->Subtopic->hasAny( $conditions ) ) {
$this->Session->setFlash(__('ประเภทสิทธิหลักถูกใช้งานอยู่'), 'flash-fail');
$this->redirect(array('action' => 'index', 'admin' => true));
}
if ( !$this->Topic->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();
}
}