| 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
/**
* Application level Controller
*
* This file is application-wide controller file. You can put all
* application-wide controller-related methods here.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package app.Controller
* @since CakePHP(tm) v 0.2.9
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Controller', 'Controller');
App::uses('CakeTime', 'Utility');
/**
* Application Controller
*
* Add your application-wide methods in the class below, your controllers
* will inherit them.
*
* @package app.Controller
* @link http://book.cakephp.org/2.0/en/controllers.html#the-app-controller
*/
class AppController extends Controller {
public $components = array(
// 'DebugKit.Toolbar',
'Acl',
'Auth' => array(
'authorize' => array(
'Actions' => array('actionPath' => 'controllers')
)
),
'Session',
'Paginator',
'RequestHandler',
'Mpdf'
);
public $helpers = array('Html', 'Form', 'Session');
/**
* Auth Login configuration
*
* @modified 2013-10-04 - Mike - Added the paginator settings
*/
public function beforeFilter() {
// make PagesController::display available
$this->Auth->allow('display', 'index', 'index_mou', 'index_member', 'get', 'view', 'getVisitors', 'admin_export');
//Configure AuthComponent
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login', 'admin' => false);
$this->Auth->logoutRedirect = array('controller' => 'pages', 'action' => 'index', 'admin' => false);
$this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'dashboard', 'admin' => true);
//Set admin layout for action that have admin prefix
if ( $this->request->prefix == 'admin' ) {
$this->layout = 'admin';
}
$this->Paginator->settings = array(
// 'limit' => 20,
// 'maxLimit' => 100
'limit' => 20,
'order' => array( $this->modelClass . '.id' => 'asc' )
);
$this->set('username', AuthComponent::user('username'));
}
/**
* set list values (for <select>) of the models into the view
* @param array $models
* @param string $order order of the SELECT
*
* @modified 2014-02-04 - Mike - Added the $order parameter
*/
protected function _setListValues($models, $order = '') {
if ( !is_array($models) ) {
return;
}
$options = array();
if( !empty( $order ) ) {
$options['order'] = array( $order => 'ASC' );
}
foreach ( $models as $model ) {
$this->loadModel($model);
$this->set( Inflector::tableize( $model ), $this->$model->find('list', $options ) );
}
}
/**
* get commond find conditions used in admin_index and admin_export function
*/
protected function _getCommonConditions(&$conditions, &$keyword = null) {
$modelName = $this->modelClass;
if ( isset($this->params->query['keyword'])
&& !empty($this->params->query['keyword']) ) {
$keyword = $this->params->query['keyword'];
$conditions['OR'] = array(
$modelName . '.name LIKE' => '%' . $keyword . '%',
$modelName . '.note LIKE' => '%' . $keyword . '%',
);
}
}
// shared functions for admin_export actions for (most of) controllers
protected 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,
'fields' => array('id','name','note','created', 'modified'),
'order' => $modelName . '.id ASC',
'recursive' => -1
));
// Define column headers for CSV file, in same array format as the data itself
$headers = array(
$modelName => array(
'id' => __('รหัส'),
'name' => __('ชื่อ'),
'note' => __('หมายเหตุ'),
'created' => __('วันที่เพิ่มข้อมูล'),
'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->_renderPdf($data);
}
}
protected function _renderPdf($data, $viewFile = '/Elements/pdf/admin_export') {
// force pdf export to always use admin layout
// the layout file is /View/Layouts/pdf/admin
$this->layout = 'admin';
// pdf - use /Views/Layouts/pdf/admin.ctp layout file
$this->Mpdf->init();
// setting filename of output pdf file
$this->Mpdf->setFilename('export.pdf');
$this->Mpdf->cacheTables = true;
$this->Mpdf->simpleTables=true;
$this->Mpdf->packTableData=true;
// setting output to
// I = inline (display in browser)
// D = download
// F = save to local file system
// S = return as strings
$this->Mpdf->setOutput('D');
$this->set(compact('data'));
// will render /View/<controller-name>/pdf/admin_export.ctp
$this->render($viewFile);
}
// /**
// * redirect to the proper error pages based on user's logged in status
// * @param object $error error object (stuff from cake)
// * @return void
// */
// public function appError($error) {
// $message = $error->getMessage();
// if ( $this->Auth->loggedIn() ) {
// return $this->redirect(array(
// 'controller' => 'pages',
// 'action' => 'error404',
// 'admin' => true,
// 'message' => $message
// ));
// }
// return $this->redirect(array(
// 'controller' => 'pages',
// 'action' => 'error404'
// ));
// }
}