DonatShell
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : C:/AppServ/www/app/Controller/RolesController.php
<?php
App::uses('AppController', 'Controller');
/**
 * Roles Controller
 *
 * @property Role $Role
 * @property PaginatorComponent $Paginator
 */
class RolesController extends AppController {

    private function __getCommonConditions(&$conditions, &$keyword = null, &$froleId = null) {
        if ( isset($this->params->query['keyword']) && !empty($this->params->query['keyword']) ) {
            $keyword = $this->params->query['keyword'];
            $conditions['AND']['Role.name LIKE'] = '%' . $keyword . '%';
        }

        if ( isset($this->params->query['frole_id']) && !empty($this->params->query['frole_id']) ) {
            $froleId = $this->params->query['frole_id'];
            $conditions['AND']['Role.frole_id'] = $froleId;
        }
    }
    /**
     * List all role
     *
     * @return void
     */
    public function admin_index() {

        $conditions = array();
        $keyword = '';
        $froleId = '';

        $this->__getCommonConditions($conditions, $keyword, $froleId);

        $this->Paginator->settings['conditions'] = $conditions;

        $this->Role->recursive = 0;
        $this->set('roles', $this->Paginator->paginate());
        $this->set('topicTitle', __('บทบาทและหน้าที่'));
        $this->set('froles', $this->Role->Frole->find('list'));

        $this->set('keyword', $keyword);
        $this->set('frole_id', $froleId);
    }

    /**
     * Add new role information
     * Get `frole` and send to view.
     *
     * @author 3Musketeers <3musketeersteam@gmail.com>
     * @since 28 September 2013
     */
    public function admin_add() {
        if ( $this->request->is('post') ) {
            $this->Role->create();
            if ( !$this->Role->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));

        }

        //Find all `frole` that `is_activated` is true.
        $options = array('conditions' => array('Frole.is_activated' => true));
        $this->set('froles', $this->Role->Frole->find('list', $options));

        $this->set('topicTitle', __('เพิ่มบทบาทและหน้าที่'));
    }

    /**
     * Edit `Role` information with `frole` detail
     *
     * @throws NotFoundException if not found any record.
     * @param string $id id of `role`
     * @author 3Muksteers <3musketeersteam@gmail.com>
     * @since 28 September 2013
     */
    public function admin_edit( $id = null ) {
        if (!$this->Role->exists($id)) {
            throw new NotFoundException(__('ไม่พบข้อมูลบทบาทและหน้าที่'));
        }

        if ( $this->request->is('post') || $this->request->is('put') ) {
            $this->Role->id = $id;
            if ( !$this->Role->save($this->request->data) ) {
                $this->Session->setFlash(__('ไม่สามารถบันทึกข้อมูลบทบาทและหน้าที่ได้ กรุณาลองใหม่อีกครั้ง'), 'flash-fail');
                $this->redirect(array('action' => 'index', 'admin' => ture));
            }

            $this->Session->setFlash(__('บันทึกข้อมูลบทบาทและหน้าที่สำเร็จ'), 'flash-success');
            $this->redirect(array('action' => 'index', 'admin' => true));
        }

        //Find all `frole` that `is_activated` is true.
        $options = array('conditions' => array('Frole.is_activated' => true));
        $this->set('froles', $this->Role->Frole->find('list', $options));

        //Find role information.
        $this->Role->recursive = -1;
        $role = $this->Role->findById($id);
        $this->set('role', $role);
        $this->set('topicTitle', __('แก้ไขข้อมูล: ') . $role['Role']['name']);
    }

    /**
     * Remove `role` information accually just set `is_activated` to false in `AppModel::delete()`
     *
     * @throws NotFoundException if not found any record
     * @param string $id id of role
     * @author 3Musketeers <3musketeersteam@gmail.com>
     * @since 28 September 2013
     */
    public function admin_delete( $id = null ) {
        $this->Role->id = $id;
        if (!$this->Role->exists()) {
            throw new NotFoundException(__('ไม่พบข้อมูลบทบาทและหน้าที่'));
        }
        //Allowed only `post` method
        $this->request->onlyAllow('post', 'delete');

        if ( !$this->Role->delete() ) {
            $this->Session->setFlash(__('ไม่สามารถลบข้อมูลบทบาทและหน้าที่ได้ กรุณาลองใหม่อีกครั้ง'), 'flash-fail');
            $this->redirect(array('action' => 'index', 'admin' => ture));
        }

        $this->Session->setFlash(__('ลบข้อมูลบทบาทและหน้าที่สำเร็จ'), 'flash-success');
        $this->redirect(array('action' => 'index', 'admin' => true));
    }

    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' => __('ชื่อ'),
                'frole_name' => __('Function Role'),
                'created' => __('วันที่เพิ่มข้อมูล'),
                'modified' => __('แก้ไขล่าสุด')
            )
        );

        // $roles = array();
        foreach ( $data as &$d ) {
            $d = array(
                $modelName => array(
                    'id' => $d['Role']['id'],
                    'name' => $d['Role']['name'],
                    'frole_name' => $d['Frole']['name'],
                    'created' => $d['Role']['created'],
                    'modified' => $d['Role']['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');
        }
    }
}

Anon7 - 2022
AnonSec Team