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'); /** * Activities Controller * * @property Activity $Activity * @property PaginatorComponent $Paginator */ class ActivitiesController extends AppController { // all actions require log in public function beforeFilter() { parent::beforeFilter(); $this->Auth->deny(); $this->Auth->allow('index', 'view', 'admin_export'); } private function __getCommonConditions(&$conditions, &$joins) { // keyword filter $modelName = $this->modelClass; $keyword = ''; if( isset($this->params->query['filter_keyword']) && !empty( $this->params->query['filter_keyword'] ) ) { $keyword = $this->params->query['filter_keyword']; $conditions['OR'] = array( $modelName . '.name LIKE' => '%' . $keyword . '%', $modelName . '.address LIKE' => '%' . $keyword . '%', $modelName . '.description LIKE' => '%' . $keyword . '%' ); } // keyword filter $this->set('keyword', $keyword); // chief filter $chiefName = ''; if( isset($this->params->query['filter_chief']) && !empty( $this->params->query['filter_chief'] ) ) { $chiefName = $this->params->query['filter_chief']; $joins[] = array( 'alias' => 'IJ_ActivityChief', 'table' => 'activities_chiefs', 'type' => 'INNER', 'conditions' => array( '`Activity`.`id` = `IJ_ActivityChief`.`activity_id`' ), ); $joins[] = array( 'alias' => 'IJ_Chief', 'table' => 'chiefs', 'type' => 'INNER', 'conditions' => array( '`IJ_Chief`.`id` = `IJ_ActivityChief`.`chief_id`', '`IJ_Chief`.`name` LIKE "%' . $chiefName . '%"' ), ); } // chief filter $this->set('chief_name', $chiefName); // topic filter $topicId = 0; $subtopicId = 0; $subtopics = array(); if ( isset($this->params->query['topic_id']) && !empty($this->params->query['topic_id']) ) { $topicId = (int)$this->params->query['topic_id']; $subtopics = $this->Activity->Subtopic->find('list', array( 'conditions' => array('topic_id' => $topicId) )); if ( isset($this->params->query['subtopic_id']) && !empty($this->params->query['subtopic_id']) ) { // selected a subtopic $subtopicId = (int)$this->params->query['subtopic_id']; $joins[] = array( 'alias' => 'IJ_ActivityTopic', 'table' => 'activities_subtopics', 'type' => 'INNER', 'conditions' => array( '`Activity`.`id` = `IJ_ActivityTopic`.`activity_id`', '`IJ_ActivityTopic`.`subtopic_id` = ' . $subtopicId ) ); } else { // all subtopics in selected topic_id $joins[] = array( 'alias' => 'ActivitiesSubtopic', 'table' => 'activities_subtopics', 'type' => 'inner', 'conditions' => array( 'ActivitiesSubtopic.activity_id = Activity.id' ) ); $joins[] = array( 'alias' => 'Subtopic', 'table' => 'subtopics', 'type' => 'inner', 'conditions' => array( 'ActivitiesSubtopic.subtopic_id = Subtopic.id', 'Subtopic.topic_id = ' . $topicId ) ); } } $this->set('topic_id', $topicId); $this->set('subtopic_id', $subtopicId); $this->set('subtopics', $subtopics); // target $targetId = 0; if ( isset($this->params->query['target_id']) && !empty($this->params->query['target_id']) ) { $targetId = (int)$this->params->query['target_id']; // @todo - activity has no relationship with target // $joins[] = array( // 'alias' => 'IJ_ActivityTarget', // 'table' => 'organizations_targets', // 'type' => 'INNER', // 'conditions' => array( // '`Organization`.`id` = `IJ_ActivityTarget`.`organization_id`', // '`IJ_ActivityTarget`.`target_id` = ' . $targetId // ), // ); } $this->set('target_id', $targetId); // region, province, district $regionId = 0; $provinceId = 0; $districtId = 0; $provinces = array(); $districts = array(); if ( isset($this->params->query['region_id']) && !empty($this->params->query['region_id']) ) { $regionId = (int)$this->params->query['region_id']; // set list values for province_id field in the view $this->loadModel('Province'); $provinces = $this->Province->find('list', array( 'conditions' => array('region_id' => $regionId) )); // select region and province if ( isset($this->params->query['province_id']) && !empty($this->params->query['province_id']) ) { $provinceId = (int)$this->params->query['province_id']; $districts = $this->Activity->District->find('list', array( 'conditions' => array('District.province_id' => $provinceId) )); // specific district if ( isset($this->params->query['district_id']) && !empty($this->params->query['district_id']) ) { $districtId = (int)$this->params->query['district_id']; $conditions['AND']['Activity.district_id'] = $districtId; } else { // all districts in selected province $joins[] = array( 'alias' => 'IJ_ActivityDistrict', 'table' => 'districts', 'type' => 'INNER', 'conditions' => array( '`IJ_ActivityDistrict`.`id` = `Activity`.`district_id`' ) ); $joins[] = array( 'alias' => 'IJ_DistrictProvince', 'table' => 'provinces', 'type' => 'INNER', 'conditions' => array( '`IJ_ActivityDistrict`.`province_id` = `IJ_DistrictProvince`.`id`', '`IJ_DistrictProvince`.`id` = ' . $provinceId ) ); } } else { // select only region, search in all districts in all provinces in selected region // all districts in selected province $joins[] = array( 'alias' => 'IJ_ActivityDistrict', 'table' => 'districts', 'type' => 'INNER', 'conditions' => array( '`IJ_ActivityDistrict`.`id` = `Activity`.`district_id`' ) ); $joins[] = array( 'alias' => 'IJ_DistrictProvince', 'table' => 'provinces', 'type' => 'INNER', 'conditions' => array( '`IJ_ActivityDistrict`.`province_id` = `IJ_DistrictProvince`.`id`', '`IJ_DistrictProvince`.`region_id` = ' . $regionId ) ); } } $this->set('region_id', $regionId); $this->set('province_id', $provinceId); $this->set('district_id', $districtId); $this->set('provinces', $provinces); $this->set('districts', $districts); $started = ''; $ended = ''; if ( isset($this->params->query['started']) && !empty($this->params->query['started'])) { $started = $this->params->query['started']; $dateConditions = array( 'Activity.started >= ?' => array($started) ); if ( isset($this->params->query['ended']) && !empty($this->params->query['ended']) ) { $ended = $this->params->query['ended']; $dateConditions['Activity.ended <= ?'] = array($ended); } $conditions['AND'] = $dateConditions; } $this->set('started', $started); $this->set('ended', $ended); } /** * admin_index method * * @return void */ public function admin_index() { $conditions = array(); $joins = array(); $this->__getCommonConditions($conditions, $joins); //Set status for query if ( !isset($this->params->query['status']) ) { $this->params->query['status'] = 1; } $conditions['Activity.is_activated'] = array($this->params->query['status']); $this->Paginator->settings['conditions'] = $conditions; $this->Paginator->settings['joins'] = $joins; $this->Paginator->settings['group'] = 'Activity.id'; $this->Activity->recursive = 1; $this->set('activities', $this->Paginator->paginate() ); $this->set('topicTitle', __('กิจกรรม')); // $this->loadModel('Topic'); // $this->set('topics', $this->Topic->find('list')); $this->_setListValues(array('Topic', 'Target', 'Region')); } /** * admin_view method * * @throws NotFoundException * @param string $id * @return void */ public function admin_view($id = null) { if (!$this->Activity->exists($id)) { throw new NotFoundException(__('ไม่พบข้อมูลกิจกรรม')); } $options = array('conditions' => array('Activity.' . $this->Activity->primaryKey => $id)); $this->set('activity', $this->Activity->find('first', $options)); $this->set('topicTitle', __('กิจกรรม')); } /** * Create activity detail * * @author Mike <3Musketeersteam@gmail.com> * @since 12 October 2013 * @modified get topic data. By Ting */ public function admin_add() { if ( $this->request->is('post') ) { $this->Activity->create(); $this->request->data['Activity']['createdby']=$this->Session->read('Auth.User.username'); // print_r($this->request->data['upload_docs']);exit(); if ( !$this->Activity->save($this->request->data) ) { $this->Session->setFlash(__('ไม่สามารถบันทึกข้อมูลกิจกรรมได้ กรุณาลองใหม่อีกครั้ง'), 'flash-fail'); $this->redirect(array('action' => 'index')); } $id = $this->Activity->getLastInsertId(); $this->__handlePhotos( $id ); if(!empty($this->request->data['upload_docs'])){ ///////////////// // common code for delete and upload files $destinationFolder = WWW_ROOT . 'img' . DS . 'activities' . DS . $id . DS; // delete files if( isset( $this->request->data['File']['delete'] ) ) { $delDocs = $this->request->data['File']['delete']; // make sure we are working on an array if( !is_array( $delDocs ) ) { $delDocs = array( $delDocs ); } foreach( $delDocs as $delDocs ) { $docsName = $this->Activity->Photo->find( 'first', array( 'conditions' => array( 'id' => $delDocs, 'model' => 'activity', 'type' => 'docs', ), 'fields' => array( 'id', 'name' ), ) ); // delete file @unlink( $destinationFolder . $docsName['Docs']['name'] ); // delete record from db $this->Activity->Photo->delete( $docsName['Docs']['id'] ); } } // upload files if( isset( $this->request->data['upload_docs'] ) ) { $uploadedDocs = $this->request->data['upload_docs']; // make sure we are working on an array if( !is_array( $uploadedDocs ) ) { $uploadedDocs = array( $uploadedDocs ); } // does the destination folder exist? if( !file_exists( $destinationFolder ) && !is_dir( $destinationFolder ) ) { mkdir( $destinationFolder, 0755, true ); } // the common data to insert $data = array( 'fk_id' => $id, 'model' => 'activity', 'type' => 'docs', ); foreach( $uploadedDocs as $uploadedDocs ) { $data['name'] = $uploadedDocs; $this->Activity->Photo->create(); if( copy( TMP . $uploadedDocs, $destinationFolder . $uploadedDocs ) ) { $this->Activity->Photo->save( $data ); } @unlink( TMP . $uploadedDocs ); } } } ////////////////// $this->Session->setFlash(__('บันทึกข้อมูลกิจกรรมสำเร็จ'), 'flash-success'); $this->redirect(array('action' => 'index')); } //Get all topic data. $this->loadModel('Topic'); $this->set('topics', $this->Topic->find('list')); //Get another relation with Activity. $districts = $this->Activity->District->find('list'); $provinces = $this->Activity->District->Province->find('list'); $chiefsList = $this->Activity->Chief->find('list'); $organizationsList = $this->Activity->Organization->find('list'); $peopleList = $this->Activity->Person->find('list'); // $subtopics = $this->Activity->Subtopic->find('list'); // $visitors = $this->Activity->Visitor->find('list'); $this->set(compact('districts', 'provinces', 'chiefsList', 'organizationsList', 'peopleList')); $this->set('topicTitle', __('เพิ่มข้อมูลกิจกรรม')); } /** * edit activity data * * @throws NotFoundException if not found any activity. * @param string $id activity's id * @author Mike <3musketeersteam@gmail.com> * @since 12 October 2013 * @modified 20 October 2013 Send variable for `organization`, `people` and `chief`: By Ting. */ public function admin_edit( $id = null ) { if ( !$this->Activity->exists($id) ) { throw new NotFoundException(__('ไม่พบข้อมูลกิจกรรม')); } if ($this->request->is('post') || $this->request->is('put')) { $this->Activity->id = $id; $this->request->data['Activity']['modifiedby']=$this->Session->read('Auth.User.username'); if ( !$this->Activity->save($this->request->data) ) { $this->Session->setFlash(__('ไม่สามารถแก้ไขข้อมูลกิจกรรมได้ กรุณาลองอีกครั่ง.'), 'flash-fail'); $this->redirect(array('action' => 'index')); } $this->__handlePhotos( $id ); if(!empty($this->request->data['upload_docs'])){ ///////////////// // common code for delete and upload files $destinationFolder = WWW_ROOT . 'img' . DS . 'activities' . DS . $id . DS; // upload files if( isset( $this->request->data['upload_docs'] ) ) { $uploadedDocs = $this->request->data['upload_docs']; // make sure we are working on an array if( !is_array( $uploadedDocs ) ) { $uploadedDocs = array( $uploadedDocs ); } // does the destination folder exist? if( !file_exists( $destinationFolder ) && !is_dir( $destinationFolder ) ) { mkdir( $destinationFolder, 0755, true ); } // the common data to insert $data = array( 'fk_id' => $id, 'model' => 'activity', 'type' => 'docs', ); foreach( $uploadedDocs as $uploadedDocs ) { $data['name'] = $uploadedDocs; $this->Activity->Photo->create(); if( copy( TMP . $uploadedDocs, $destinationFolder . $uploadedDocs ) ) { $this->Activity->Photo->save( $data ); } @unlink( TMP . $uploadedDocs ); } } } ////////////////// $this->Session->setFlash(__('แก้ไขข้อมูลกิจกรรมสำเร็จ'), 'flash-success'); $this->redirect(array('action' => 'index')); } $options = array('conditions' => array('Activity.' . $this->Activity->primaryKey => $id)); $this->request->data = $this->Activity->find('first', $options); // build the url for the photos $photosUrl = 'activities/' . $id; $this->set( 'photos_url', $photosUrl ); $docsUrl = 'activities/' . $id; $this->set( 'docs_url', $docsUrl ); $this->Activity->District->recursive = -1; $currentDistrict = $this->Activity->District->find( 'first', array( 'contain' => 'Province', 'conditions' => array( 'District.id' => $this->request->data['Activity']['district_id'], ) ) ); $this->request->data['Activity']['province_id'] = $currentDistrict['District']['province_id']; $currentDistricts = $this->Activity->District->find( 'list', array( 'conditions' => array( 'District.province_id' => $currentDistrict['District']['province_id'], ) ) ); $districts = $this->Activity->District->find('list'); $provinces = $this->Activity->District->Province->find('list'); $chiefsList = $this->Activity->Chief->find('list'); $organizationsList = $this->Activity->Organization->find('list'); $peopleList = $this->Activity->Person->find('list'); $this->set(compact('districts', 'provinces', 'chiefsList', 'organizationsList', 'peopleList', 'subtopics', 'visitors', 'currentDistricts')); $this->loadModel('Topic'); $this->set('topics', $this->Topic->find('list')); //Try to make data for mutil checkbox $models = array( 'chiefs' => 'Chief', 'subtopics' => 'Subtopic', 'organizations' => 'Organization', 'people' => 'Person' ); foreach( $models as $kModel => $vModel ) { $$kModel = array(); foreach( $this->request->data[$vModel] as $vData ) { ${$kModel}[$vData['id']] = $vData['name']; } } $this->set( compact( array_keys( $models ) ) ); // $this->set(compact('subtopics', 'chiefs', 'organizations', 'people')); $this->set('topicTitle', __('แก้ไขข้อมูล: ') . $this->request->data['Activity']['name']); } /** * This function will save in the database the photos that have been uploaded in the `tmp` folder and will also copy them to the folder `img/activities/{$activityID}/` * * @todo Should this function move to a component or something? We will need it for `Organization` and `Person` too * * @param int $id the ID of the activity * * @author Mike * @since 2013-10-06 */ private function __handlePhotos( $id ) { // common code for delete and upload files $destinationFolder = WWW_ROOT . 'img' . DS . 'activities' . DS . $id . DS; // delete files if( isset( $this->request->data['File']['delete'] ) ) { $delPhotos = $this->request->data['File']['delete']; // make sure we are working on an array if( !is_array( $delPhotos ) ) { $delPhotos = array( $delPhotos ); } foreach( $delPhotos as $delPhoto ) { $photoName = $this->Activity->Photo->find( 'first', array( 'conditions' => array( 'id' => $delPhoto, 'model' => 'activity' ), 'fields' => array( 'id', 'name' ), ) ); // delete file @unlink( $destinationFolder . $photoName['Photo']['name'] ); // delete record from db $this->Activity->Photo->delete( $photoName['Photo']['id'] ); } } // upload files if( isset( $this->request->data['upload_photos'] ) ) { $uploadedPhotos = $this->request->data['upload_photos']; // make sure we are working on an array if( !is_array( $uploadedPhotos ) ) { $uploadedPhotos = array( $uploadedPhotos ); } // does the destination folder exist? if( !file_exists( $destinationFolder ) && !is_dir( $destinationFolder ) ) { mkdir( $destinationFolder, 0755, true ); } // the common data to insert $data = array( 'fk_id' => $id, 'model' => 'activity', ); foreach( $uploadedPhotos as $uploadedPhoto ) { $data['name'] = $uploadedPhoto; $this->Activity->Photo->create(); if( copy( TMP . $uploadedPhoto, $destinationFolder . $uploadedPhoto ) ) { $this->Activity->Photo->save( $data ); } @unlink( TMP . $uploadedPhoto ); } } } /** * admin_delete method * * @throws NotFoundException * @param string $id * @return void */ public function admin_delete($id = null) { $this->Activity->id = $id; if (!$this->Activity->exists()) { throw new NotFoundException(__('Invalid activity')); } $this->request->onlyAllow('get', 'delete', 'post'); if ($this->Activity->delete()) { $this->Session->setFlash(__('ลบข้อมูลกิจกรรมเรียบร้อยแล้ว'), 'flash-success'); } else { $this->Session->setFlash(__('ไม่สามารถลบข้อมูลกิจกรรมได้'), 'flash-fail'); } return $this->redirect(array('action' => 'index')); } /** * acvtivate itams from inactivated. * * @param int $id activity's id * @author Ting <3Musketeersteam@gmail.com> * @since 27 January 2014 */ public function admin_active($id = null) { $this->Activity->id = $id; if (!$this->Activity->exists()) { throw new NotFoundException(__('ไม่พบข้อมูลกิจกรรม')); } $this->request->onlyAllow('get', 'delete', 'post'); if ($this->Activity->activate()) { $this->Session->setFlash(__('เปิดใช้งานกิจกรรมเรียบร้อยแล้ว'), 'flash-success'); } else { $this->Session->setFlash(__('ไม่สามารถเปิดการใช้งานกิจกรรม'), 'flash-fail'); } return $this->redirect(array('action' => 'index')); } /** * This function will receive the photos uploaded through Ajax requests and store them in the `tmp` folder * * @todo Where should we move this function?? It should also be used by `Organization` and `Person` * * @author Mike * @since 2013-10-06 * * @modified 2013-10-13 - Mike - Verify the file type by using `getimagesize()` */ public function admin_add_photo($type) { $this->autoRender = false; $result = array( 'error' => 0, 'data' => '', ); try { if($type == 1){ if( !$this->request->is( 'post' ) && !$this->request->is( 'put' ) ) { throw new BadRequestException( __( 'Invalid request.' ) ); } if( !isset( $_FILES['data'] ) || !isset( $_FILES['data']['name']['File'] ) || !isset( $_FILES['data']['name']['File']['upload'] ) ) { throw new BadRequestException( __( 'The system could not find the uploaded file.' ) ); } $name = $_FILES['data']['name']['File']['upload']; $tmpName = $_FILES['data']['tmp_name']['File']['upload']; $error = $_FILES['data']['error']['File']['upload']; $type = @getimagesize( $tmpName ); if( $error != 0 ) { throw new Exception( __( 'An error occured while uploading the file.' ) ); } if( ( $type === false ) || !in_array( $type[2], Configure::read( 'image_types_allowed' ) ) ){ // getimagesize() could return false for video files // so, check if this a video file $type = $_FILES['data']['type']['File']['upload']; if (!in_array($type, Configure::read('video_types_allowed'))) { throw new Exception( __( 'The type of the image is not allowed.' ) ); } } if( !is_uploaded_file( $tmpName ) || !move_uploaded_file( $tmpName, TMP . DS . $name ) ) { throw new Exception( __( 'The system cannot access your uploaded file.' ) ); } $result['data'] = $name; }else if($type == 3){ if( !$this->request->is( 'post' ) && !$this->request->is( 'put' ) ) { throw new BadRequestException( __( 'Invalid request.' ) ); } if( !isset( $_FILES['data'] ) || !isset( $_FILES['data']['name']['File'] ) || !isset( $_FILES['data']['name']['File']['upload'] ) ) { throw new BadRequestException( __( 'The system could not find the uploaded file.' ) ); } $name = $_FILES['data']['name']['File']['upload']; $tmpName = $_FILES['data']['tmp_name']['File']['upload']; $error = $_FILES['data']['error']['File']['upload']; $type = @getimagesize( $tmpName ); if( $error != 0 ) { throw new Exception( __( 'An error occured while uploading the file.' ) ); } if( ( $type === false ) || !in_array( $type[2], Configure::read( 'img_types_allowed' ) ) ){ // getimagesize() could return false for video files // so, check if this a video file $type = $_FILES['data']['type']['File']['upload']; if (!in_array($type, Configure::read('img_types_allowed'))) { throw new Exception( __( 'The type of the image is not allowed.' ) ); } } if( !is_uploaded_file( $tmpName ) || !move_uploaded_file( $tmpName, TMP . DS . $name ) ) { throw new Exception( __( 'The system cannot access your uploaded file.' ) ); } $result['data'] = $name; }else{ if( !$this->request->is( 'post' ) && !$this->request->is( 'put' ) ) { throw new BadRequestException( __( 'Invalid request.' ) ); } if( !isset( $_FILES['data'] ) || !isset( $_FILES['data']['name']['File'] ) || !isset( $_FILES['data']['name']['File']['upload'] ) ) { throw new BadRequestException( __( 'The system could not find the uploaded file.' ) ); } $name = $_FILES['data']['name']['File']['upload']; $tmpName = $_FILES['data']['tmp_name']['File']['upload']; $error = $_FILES['data']['error']['File']['upload']; $type = @getimagesize( $tmpName ); if( $error != 0 ) { throw new Exception( __( 'An error occured while uploading the file.' ) ); } if( ( $type === false ) || !in_array( $type[2], Configure::read( 'docs_types_allowed' ) ) ){ // getimagesize() could return false for video files // so, check if this a video file $type = $_FILES['data']['type']['File']['upload']; if (!in_array($type, Configure::read('docs_types_allowed'))) { throw new Exception( __( 'The type of the docs is not allowed.' ) ); } } if( !is_uploaded_file( $tmpName ) || !move_uploaded_file( $tmpName, TMP . DS . $name ) ) { throw new Exception( __( 'The system cannot access your uploaded file.' ) ); } $result['data'] = $name; } } catch (Exception $e ) { $result['error'] = 1; $result['data'] = $e->getMessage(); } return json_encode( $result ); } // ข้อมูลการจัดกิจกรรมเครือข่าย page - frontend public function index() { $conditions = array(); $joins = array(); $this->__getCommonConditions($conditions, $joins); $conditions['Activity.is_activated'] = array(0, 1); $this->Paginator->settings['conditions'] = $conditions; $this->Paginator->settings['joins'] = $joins; $this->Paginator->settings['group'] = 'Activity.id'; $this->set('activities', $this->Paginator->paginate()); $this->_setListValues(array('Topic', 'Target', 'Region')); $this->set('topicTitle', __('การจัดกิจกรรมที่ กสม ร่วมกับเครือข่าย')); } // ข้อมูลสมาชิกเครือข่ายที่เข้าร่วมกิจกรรม page -frontend public function index_member() { $this->_setListValues(array('Topic')); $this->set('topicTitle', __('ข้อมูลสมาชิกเครือข่ายที่เข้าร่วมกิจกรรม')); } /** * Show all information of each activity. * * @param integer $id activity's id * @author Ting <3musketeersteam@gmail.com> * @since 6 November 2013 */ public function view( $id = null ) { if ( !$this->Activity->exists($id) ) { throw new NotFoundException(__('ไม่พบข้อมูลกิจกรรม')); } // build the url for the photos $photosUrl = 'activities/' . $id; $this->set( 'photos_url', $photosUrl ); //use contain model to avoid plenty of result from activity's visitors. $activity = $this->Activity->find('first', array( 'conditions' => array('Activity.id' => $id), 'contain' => array('District', 'Photo', 'Chief', 'Subtopic'), )); //Count organization and people that came to event. $model = array('ActivitiesPerson', 'ActivitiesOrganization'); for ( $i = 0; $i < count($model); $i++ ) { $activity[$model[$i]] = $this->Activity->$model[$i]->find('count', array( 'conditions' => array($model[$i] . '.activity_id' => $id))); } $this->loadModel('Province'); $provinces = $this->Province->find('list'); $this->set('provinces', $provinces); $this->set('activity', $activity); $this->set('topicTitle', __('แสดงข้อมูลกิจกรรม')); if ( isset($this->params->ext) && $this->params->ext == 'pdf') { $this->_renderPdf( array_merge($activity, array('Province' => $provinces)), '/Activities/pdf/view' ); } } /** * Get visitor information * * @param integer $id organization or people id. * @param string $type Type of data * @return json organization information * @author Ting <3musketeersteam@gmail.com> * @since 23 November 2013 */ public function getVisitors( $id = null, $type ) { $this->autoRender = false; if ( $id == null ) { return json_encode(false); } $model = 'Activities' . $type; //Set paginate to find only org that come to visit activity. $this->Paginator->settings = array( 'conditions' => array( $model . '.' . 'activity_id' => $id ) ); $orgs = $this->Paginator->paginate($model); $this->Activity->$type->recursive = -1; for ( $i = 0; $i < count($orgs); $i++) { $orgs[$i] = $this->Activity->$type->findById($orgs[$i][$model][strtolower($type) . '_id']); } $orgs = Hash::extract($orgs, '{n}.' . $type . '.name'); echo json_encode($orgs); } public function admin_export() { Configure::write('debug',0); // just in case $this->autoRender = false; // thanks, but no. $modelName = $this->modelClass; $conditions = array(); $joins = array(); $this->__getCommonConditions($conditions, $joins); // Find fields needed without recursing through associated models $data = $this->{$modelName}->find('all', array( 'conditions' => $conditions, 'joins' => $joins, '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' => __('ชื่อ'), 'started' => __('วันที่เริ่มกิจกรรม'), 'ended' => __('วันที่สิ้นสุดกิจกรรม'), 'address' => __('สถานที่จัดกิจกรรม'), 'district' => __('อำเภอ'), 'description' => __('รายละกิจกรรม'), 'expected' => __('จำนวนสมาชิกที่คาดว่าจะมาร่วมงาน'), 'created' => __('วันที่เพิ่มข้อมูล'), 'modified' => __('แก้ไขล่าสุด') ) ); // $roles = array(); foreach ( $data as &$d ) { $d = array( $modelName => array( 'id' => $d['Activity']['id'], 'name' => $d['Activity']['name'], 'started' => $d['Activity']['started'], 'ended' => $d['Activity']['ended'], 'address' => $d['Activity']['address'], 'district' => $d['District']['name'], 'description' => $d['Activity']['description'], 'expected' => $d['Activity']['expected'], 'created' => $d['Activity']['created'], 'modified' => $d['Activity']['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'); } } }