All pastes #934251 Raw Edit

Something

public php v1 · immutable
·published 2008-03-08 18:47 UTC
rendered paste body
<?php/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: *//** * * This is the Livewire WebX Framework for all sub systems to be derived from. * * LICENSE: * Livewire Designs Limited * Copyright (C) 2007 Livewire Designs Limited * * All materials posted on this site are the property of * Livewire Designs Limited (LWD) * All other rights reserved. * * @category   WebX * @package    WebX Generator * @subpackage UserRecord * @author     Jeff O'Toole <jeff@livewiredesigns.org> * @copyright  2007 Livewire Designs Limited * @license    http://www.livewiredesigns.org/projects/license/ * @version    Subversion: $Id:$ * @link       http://www.livewiredesigns.org/projects/package/Generator * @see        CommonObjects * @since      File available since Release */// {{{ Includes/** * Require WebX Common System */Prado::using('WebX.*');// }}}// {{{ VisioManagerclass VisioManager extends WebXFormPage{        // {{{ getVisioFiles()        /**         * Returns an array of all the Visio Files installed withing the system         *         * @access public         * @return array         */        public function getVisioFiles()        {                $visioPath  = Prado::getPathOfNamespace($this->Application->Parameters["VisioPath"]);                $contents   = scandir( $visioPath );                $visioFiles = array();                foreach ($contents as $file) {                        if ( strtolower( Common::getTool("FileUtils")->getFileExtension($file) ) == 'ddl' ) {                                // We Must Add this File to our List                                $fileInfo = array(                                        'filename'   => basename($file, '.DDL'),                                        'urlencoded' => urlencode(basename($file, '.DDL') ),                                        'accessed'   => date('Y-m-d H:i:s', fileatime($visioPath.'/'.$file)),                                        'modified'   => date('Y-m-d H:i:s', filemtime($visioPath.'/'.$file))                                );                                $visioFiles[] = $fileInfo;                        }                }                return $visioFiles;        }        // }}}        // {{{ onLoad()        /**         * Handles the loading details for this page         *         * @access public         * @param mixed event parameter         */        public function onLoad($param)        {                parent::onLoad($param);                if(!$this->IsPostBack) {                        $this->DG_VisioFiles->DataSource = $this->getVisioFiles();                        $this->DG_VisioFiles->DataBind();                }                $this->PL_Failure->Visible = false;                $this->PL_Success->Visible = false;        }        // }}}        // {{{ validateVisioUpload        /**         * Handles the validation of the Visio Upload         *         * @access public         * @param mixed event sender         * @param mixed event parameter         */        public function validateVisioUpload($sender,$param)        {                $valid = false;                $allowedFileTypes =array('text/plain', 'application/octet-stream');                /* Performs required validations before the file may be uploaded                 * a) Filename must be provided                 * b) File must exist on loacl machine                 * c) File must not exits on server                 * d) Filesize must not be more than 1048576 (1MB)                 */                $UploadFileName = $this->FU_VisioUpload->getFileName(); // filename excl. path                // Do we have a filename                if ($UploadFileName) {                        $tmpName  = $this->FU_VisioUpload->getLocalName();                        $fileSize = $this->FU_VisioUpload->getFileSize();                        $fileType = $this->FU_VisioUpload->getFileType();                        // Is the file real or just a name?                        if ( ($fileSize>0) ) {                                // Is the file greater than the limit?                                if ($fileSize > 1048576 ) {                                        // Don't allow upload of a file larger that 1 MB                                        $MegaBytesSize = round($fileSize/1048576,2);                                        $this->CV_VisioUpload->setErrorMessage("Filesize is $MegaBytesSize MB. Upload of files larger than 1MB is not allowed.");                                } else {                                        // Do we all the file type?                                        if( in_array($this->FU_VisioUpload->FileType, $allowedFileTypes) ) {                                                // Does File already exists?                                                $fullFileName =  Prado::getPathOfNamespace($this->Application->Parameters["VisioPath"]).'/'.$UploadFileName;                                                if ( (is_file($fullFileName) )) {                                                        $this->CV_VisioUpload->setErrorMessage("Can't upload as $UploadFileName already exist on server.");                                                } else {                                                        // Ok to upload                                                        $valid = true;                                                        $this->CV_VisioUpload->setErrorMessage("");                                                }                                        } else {                                                $this->CV_VisioUpload->setErrorMessage("The filetype cannot be  $fileType");                                        }                                }                        } else {                                $this->CV_VisioUpload->setErrorMessage("Invalid filename or file not found. Check filename and/or path.");                        }                } else {                        $this->CV_VisioUpload->setErrorMessage("Filename must be provided.");                }                $param->isValid = $valid;        }        // }}}        // {{{ handleVisioUpload()        /**         * Handles the On File Upload Event         *         * @access public         * @param mixed event sender         * @param mixed event parameter         */        public function handleVisioUpload()        {                $uploadedFile =  Prado::getPathOfNamespace($this->Application->Parameters["VisioPath"]).'/'. $this->FU_VisioUpload->FileName;                $this->setViewState('uploadedFile',$uploadedFile);                copy($this->FU_VisioUpload->LocalName, $uploadedFile);        }        // }}}        // {{{ submitButtonClicked()        /**         * Handles the Submit Button OnClick Event         *         * @access public         * @param mixed event sender         * @param mixed event parameter         */        public function uploadSubmitClicked($sender,$param)        {                if($this->IsValid) {                        $this->handleVisioUpload();                        if ( is_file( Prado::getPathOfNamespace($this->Application->Parameters["VisioPath"]).'/'. $this->FU_VisioUpload->FileName ) ) {                                $this->addSuccessMessage('The Visio File '. $this->FU_VisioUpload->FileName .' has been successfully uploaded!' );                                $this->LB_SuccessMessage->Text = $this->renderSuccess();                                $this->PL_Success->Visible = true;                                $this->PL_Failure->Visible = false;                                $this->DG_VisioFiles->DataSource = $this->getVisioFiles();                                $this->DG_VisioFiles->DataBind();                        } else {                                $this->addFailureMessage('The Visio File '. $this->FU_VisioUpload->FileName .' is valid but has failed to upload!' );                                $this->LB_FailureMessage->Text = $this->renderFailure();                                $this->PL_Failure->Visible = true;                                $this->PL_Success->Visible = false;                        }                } else {                        $this->addFailureMessage('The Visio File '. $this->FU_VisioUpload->FileName .' has failed to upload!' );                        $this->LB_FailureMessage->Text = $this->renderFailure();                        $this->PL_Failure->Visible = true;                        $this->PL_Success->Visible = false;                }        }        // }}}        // {{{ confirmDelete()        /**         * Handles removal of Visio File         *         * @access public         * @param mixed event sender         * @param mixed event parameter         */        public function confirmDelete($sender,$param)        {                $this->setViewState('DeleteVisioIndex', $param->Item->ItemIndex);                $this->PL_ConfirmDelete->Visible = true;                $this->DG_VisioFiles->EditItemIndex=-1;        }        // }}}        // {{{ commitDelete()        /**         * Physically remove the file from the system         *         * @access public         */        public function commitDelete()        {                $visioPath  = Prado::getPathOfNamespace($this->Application->Parameters["VisioPath"]);                $visioFile  = $this->DG_VisioFiles->DataKeys[$this->getViewState('DeleteVisioIndex')].'.DDL';                if (!unlink( $visioPath.'/'.$visioFile )) {                        // Toss an Error                        $this->resetFailure();                        $this->addFailureMessage('The Visio File faild to be removed');                        $this->LB_FailureMessage->Text = $this->renderFailure();                        $this->PL_ConfirmDelete->Visible = false;                        $this->PL_Failure->Visible = true;                } else {                        $this->resetSuccess();                        $this->addSuccessMessage('The Visio File has been successfully removed');                        $this->LB_SuccessMessage->Text = $this->renderSuccess();                        $this->PL_ConfirmDelete->Visible = false;                        $this->PL_Success->Visible = true;                        $this->DG_VisioFiles->DataSource = $this->getVisioFiles();                        $this->DG_VisioFiles->DataBind();                }        }        // }}}        // {{{ cancelDelete()        /**         * Cancel the request to remove a Visio File         *         * @access public         */        public function cancelDelete()        {                $this->PL_ConfirmDelete->Visible = false;        }        // }}}}// }}}/* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */?>