Пример #1
0
 protected function getModels()
 {
     $models = array();
     $files = scandir(Yii::getPathOfAlias('application.models'));
     foreach ($files as $file) {
         if ($file[0] !== '.' && CFileHelper::getExtension($file) === 'php') {
             $fileClassName = substr($file, 0, strpos($file, '.'));
             if (class_exists($fileClassName) && is_subclass_of($fileClassName, 'GiiyActiveRecord')) {
                 $fileClass = new ReflectionClass($fileClassName);
                 if (!$fileClass->isAbstract() && !is_array(GiiyActiveRecord::model($fileClassName)->getPrimaryKey())) {
                     $models[] = $fileClassName;
                 }
             }
         }
     }
     foreach (Yii::app()->getModules() as $module => $moduleConf) {
         if (Yii::getPathOfAlias($module . '.models')) {
             $files = scandir(Yii::getPathOfAlias($module . '.models'));
             foreach ($files as $file) {
                 if ($file[0] !== '.' && CFileHelper::getExtension($file) === 'php') {
                     $fileClassName = substr($file, 0, strpos($file, '.'));
                     if (class_exists($fileClassName) && is_subclass_of($fileClassName, 'GiiyActiveRecord')) {
                         $fileClass = new ReflectionClass($fileClassName);
                         if (!$fileClass->isAbstract() && !is_array(GiiyActiveRecord::model($fileClassName)->getPrimaryKey())) {
                             $models[] = $fileClassName;
                         }
                     }
                 }
             }
         }
     }
     return $models;
 }
Пример #2
0
 public function prepare()
 {
     $this->files = array();
     $templatePath = $this->templatePath;
     $controllerTemplateFile = $templatePath . DIRECTORY_SEPARATOR . 'controller.php';
     $this->files[] = new CCodeFile($this->controllerFile, $this->render($controllerTemplateFile));
     $this->files[] = new CCodeFile(str_replace("Controller.php", "AdminController.php", $this->controllerFile), $this->render(str_replace("controller.php", "adminController.php", $controllerTemplateFile)));
     $files = scandir($templatePath);
     foreach ($files as $file) {
         if (is_file($templatePath . '/' . $file) && CFileHelper::getExtension($file) === 'php' && $file !== 'controller.php') {
             $path = $this->viewPath . DIRECTORY_SEPARATOR . $file;
             if ($file == "adminController.php") {
                 continue;
             }
             if ($file == "form.php") {
                 //                    $path = str_replace('\\', '/', $path);
                 //
                 //                    $path_params = str_replace(
                 //                        array("/form.php", MODULES_PATH),
                 //                        null,
                 //                        $path
                 //                    );
                 //
                 //                    $path_params = explode("/", $path_params);
                 //
                 //                    $module_name = $path_params[0];
                 //                    $model_name  = ucfirst($path_params[2]);
                 //
                 //                    $module_dir = MODULES_PATH . $module_name . "/";
                 //
                 //                    $forms_dir = $module_dir . "forms/";
                 //
                 //
                 //                    if (!is_dir($forms_dir))
                 //                    {
                 //                        mkdir($forms_dir);
                 //                        chmod($forms_dir, 0777);
                 //                    }
                 //
                 //                    $path = $forms_dir . $model_name . "Form.php";
             }
             $this->files[] = new CCodeFile($path, $this->render($templatePath . '/' . $file));
         }
     }
     $templatePath = $templatePath . "/admin/";
     $viewPath = $this->viewPath . "Admin/";
     //        if (!is_dir($viewPath))
     //        {
     //            mkdir($viewPath);
     //            chmod($viewPath, 0777);
     //        }
     $files = scandir($templatePath);
     foreach ($files as $file) {
         if ($file[0] == ".") {
             continue;
         }
         $path = $viewPath . $file;
         $this->files[] = new CCodeFile($path, $this->render($templatePath . '/' . $file));
     }
 }
Пример #3
0
 /**
  * Feltölt egy fájlt a megadott tantárgyhoz.
  * @param int $id A tantárgy azonosítója
  */
 public function actionUpload($id)
 {
     if (!Yii::app()->user->getId()) {
         throw new CHttpException(403, 'A funkció használatához be kell jelentkeznie');
     }
     $id = (int) $id;
     $file = CUploadedFile::getInstanceByName("to_upload");
     if ($file == null) {
         throw new CHttpException(404, 'Nem lett fájl kiválasztva a feltöltéshez');
     }
     $filename = $file->getName();
     $localFileName = sha1($filename . microtime()) . "." . CFileHelper::getExtension($filename);
     if (in_array(strtolower(CFileHelper::getExtension($filename)), Yii::app()->params["deniedexts"])) {
         throw new CHttpException(403, ucfirst(CFileHelper::getExtension($filename)) . ' kiterjesztésű fájl nem tölthető fel a szerverre');
     }
     $model = new File();
     $model->subject_id = $id;
     $model->filename_real = $filename;
     $model->filename_local = $localFileName;
     $model->description = htmlspecialchars($_POST["description"]);
     $model->user_id = Yii::app()->user->getId();
     $model->date_created = new CDbExpression('NOW()');
     $model->date_updated = new CDbExpression('NOW()');
     $model->downloads = 0;
     $model->save();
     if ($file->saveAs("upload/" . $localFileName)) {
         $this->redirect(Yii::App()->createUrl("file/list", array("id" => $id)));
     }
 }
Пример #4
0
 public function prepare()
 {
     $this->files = array();
     $templatePath = $this->templatePath;
     $modulePath = $this->modulePath;
     $moduleTemplateFile = $templatePath . DIRECTORY_SEPARATOR . 'module.php';
     $this->files[] = new CCodeFile($modulePath . '/' . $this->moduleClass . '.php', $this->render($moduleTemplateFile));
     $files = CFileHelper::findFiles($templatePath, array('exclude' => array('.svn')));
     foreach ($files as $file) {
         if ($file !== $moduleTemplateFile) {
             if (CFileHelper::getExtension($file) === 'php') {
                 $content = $this->render($file);
             } else {
                 if (basename($file) === '.yii') {
                     // an empty directory
                     $file = dirname($file);
                     $content = null;
                 } else {
                     $content = file_get_contents($file);
                 }
             }
             $this->files[] = new CCodeFile($modulePath . substr($file, strlen($templatePath)), $content);
         }
     }
 }
Пример #5
0
 public function prepare()
 {
     $this->files = array();
     $templatePath = $this->templatePath;
     $modulePath = $this->modulePath;
     $moduleTemplateFile = $templatePath . DIRECTORY_SEPARATOR . 'module.php';
     $this->files[] = new CCodeFile($modulePath . '/' . $this->moduleClass . '.php', $this->render($moduleTemplateFile));
     $files = CFileHelper::findFiles($templatePath, array('exclude' => array('.svn', '.gitignore')));
     foreach ($files as $file) {
         if ($file !== $moduleTemplateFile && !$this->isIgnireFile($file)) {
             if (CFileHelper::getExtension($file) === 'php') {
                 $content = $this->render($file);
             } elseif (basename($file) === '.gitkeep') {
                 $file = dirname($file);
                 $content = null;
             } else {
                 $content = file_get_contents($file);
             }
             $modifiedFile = $this->getModifiedFile($file);
             if ($modifiedFile !== false) {
                 $file = $modifiedFile;
             }
             $this->files[] = new CCodeFile($modulePath . substr($file, strlen($templatePath)), $content);
         }
     }
 }
Пример #6
0
 protected static function geraFilename($url, $outDir = null, $hash = false)
 {
     if ($outDir === null) {
         $outDir = Yii::app()->runtimePath;
     }
     $name = $hash ? md5($url) : tempnam('', 'external');
     $ext = CFileHelper::getExtension(basename($url));
     return "{$outDir}/{$name}.{$ext}";
 }
Пример #7
0
 protected function renderContent()
 {
     if (isset($this->block) && $this->block != null) {
         $model = new UserAvatarForm();
         if (isset($_POST['UserAvatarForm'])) {
             $model->attributes = $_POST['UserAvatarForm'];
             $model->image = CUploadedFile::getInstance($model, 'image');
             if ($model->validate()) {
                 //Get the User Id to determine the folder
                 $folder = user()->id >= 1000 ? (string) (round(user()->id / 1000) * 1000) : '1000';
                 $filename = user()->id . '_' . gen_uuid();
                 if (!(file_exists(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $folder) && AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $folder)) {
                     mkdir(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $folder, 0777, true);
                 }
                 if (file_exists(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $filename . '.' . strtolower(CFileHelper::getExtension($model->image->name)))) {
                     $filename .= '_' . time();
                 }
                 $filename = $filename . '.' . strtolower(CFileHelper::getExtension($model->image->name));
                 $path = $folder . DIRECTORY_SEPARATOR . $filename;
                 if ($model->image->saveAs(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $path)) {
                     //Generate thumbs
                     //
                     GxcHelpers::generateAvatarThumb($filename, $folder, $filename);
                     //So we will start to check the info from the user
                     $current_user = User::model()->findByPk(user()->id);
                     if ($current_user) {
                         if ($current_user->avatar != null && $current_user->avatar != '') {
                             //We will delete the old avatar here
                             $old_avatar_path = $current_user->avatar;
                             $current_user->avatar = $path;
                             if (file_exists(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $old_avatar_path)) {
                                 @unlink(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $old_avatar_path);
                             }
                             //Delete old file Sizes
                             $sizes = AvatarSize::getSizes();
                             foreach ($sizes as $size) {
                                 if (file_exists(AVATAR_FOLDER . DIRECTORY_SEPARATOR . $size['id'] . DIRECTORY_SEPARATOR . $old_avatar_path)) {
                                     @unlink(AVATAR_FOLDER . DIRECTORY_SEPARATOR . $size['id'] . DIRECTORY_SEPARATOR . $old_avatar_path);
                                 }
                             }
                         } else {
                             //$current_user
                             $current_user->avatar = $path;
                         }
                         $current_user->save();
                     }
                 } else {
                     throw new CHttpException('503', 'Error while uploading!');
                 }
             }
         }
         $this->render(BlockRenderWidget::setRenderOutput($this), array('model' => $model));
     } else {
         echo '';
     }
 }
Пример #8
0
 /**
  * Serve files.
  */
 public function actionServe()
 {
     Yii::$enableIncludePath = false;
     // preload CFileHelper before disabling Yii autoload
     $tmp = CFileHelper::getExtension('');
     $tmp = CLogger::LEVEL_ERROR;
     //@YiiBase::autoload('CHttpException');
     //@YiiBase::autoload('CExceptionEvent');
     spl_autoload_unregister(array('YiiBase', 'autoload'));
     require dirname(dirname(__FILE__)) . '/vendors/minify/min/index.php';
 }
Пример #9
0
 /**
  * Returns the model names in an array.
  * Only non abstract and subclasses of AweActiveRecord models are returned.
  * The array is used to build the autocomplete field.
  * @return array The names of the models
  */
 protected function getModels()
 {
     $models = array();
     $files = scandir(Yii::getPathOfAlias('application.models'));
     foreach ($files as $file) {
         if ($file[0] !== '.' && CFileHelper::getExtension($file) === 'php') {
             $fileClassName = substr($file, 0, strpos($file, '.'));
             $models[] = $fileClassName;
         }
     }
     return $models;
 }
Пример #10
0
 public function UploadFile(&$resource, $model, &$process, &$message, $remote = false)
 {
     if ($model->upload->size > $this->max_file_size) {
         $allow_size = $this->max_file_size / (1024 * 1024);
         $model->addError('upload', t('cms', 'File size is larger than allowed size : ') . $allow_size . ' mb');
         $process = false;
         return false;
     }
     if ($model->upload->size < $this->min_file_size) {
         $model->addError('upload', t('cms', 'File is too small!'));
         $process = false;
         return false;
     }
     if (count($this->allow_types) > 0) {
         if (!in_array(strtolower(CFileHelper::getExtension($model->upload->name)), $this->allow_types)) {
             $model->addError('upload', t('cms', 'File extension is not allowed!'));
             $process = false;
             return false;
         }
     }
     $filename = $resource->resource_name = $model->upload->name;
     if (settings()->get('system', 'keep_file_name_upload') == '0') {
         $filename = gen_uuid();
     } else {
         $filename = str_replace(" ", "-", $filename);
     }
     // folder for uploaded files
     $folder = date('Y') . DIRECTORY_SEPARATOR . date('m') . DIRECTORY_SEPARATOR;
     if (!(file_exists(self::RESOURCES_FOLDER . DIRECTORY_SEPARATOR . $folder) && is_dir(self::RESOURCES_FOLDER . DIRECTORY_SEPARATOR . $folder))) {
         mkdir(self::RESOURCES_FOLDER . DIRECTORY_SEPARATOR . $folder, 0777, true);
     }
     if (settings()->get('cms', 'system', 'keep_file_name_upload') == '1') {
         //Check if File exists, so Rename the Filename again;
         while (file_exists(self::RESOURCES_FOLDER . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $filename . '.' . strtolower(CFileHelper::getExtension($model->upload->name)))) {
             $filename .= rand(10, 99);
         }
     }
     if (settings()->get('system', 'keep_file_name_upload') == '0') {
         $filename = $filename . '.' . strtolower(CFileHelper::getExtension($model->upload->name));
     }
     $path = $folder . $filename;
     if ($model->upload->saveAs(self::RESOURCES_FOLDER . DIRECTORY_SEPARATOR . $path)) {
         $resource->resource_path = $path;
         //Resource::generateThumb($model->upload->name,$folder,$filename);
         $process = true;
         return true;
     } else {
         $process = false;
         $message = t('cms', 'Error while Uploading. Try again later.');
         return false;
     }
 }
Пример #11
0
 public function prepare()
 {
     $this->files = array();
     $templatePath = $this->templatePath;
     $controllerTemplateFile = $templatePath . DIRECTORY_SEPARATOR . 'controller.php';
     $this->files[] = new CCodeFile($this->controllerFile, $this->render($controllerTemplateFile));
     $files = scandir($templatePath);
     foreach ($files as $file) {
         if (is_file($templatePath . '/' . $file) && CFileHelper::getExtension($file) === 'php' && $file !== 'controller.php') {
             $this->files[] = new CCodeFile($this->viewPath . DIRECTORY_SEPARATOR . $file, $this->render($templatePath . '/' . $file));
         }
     }
 }
Пример #12
0
 /**
  * Получает расширение файла
  * @param string $fileName - имя файла
  * @param string $lower - приводить расширение к нижнему регистру
  * @return string 
  */
 public static function getExtension($fileName, $lower = true)
 {
     $ext = parent::getExtension($fileName);
     if ($lower) {
         $ext = mb_strtolower($ext);
     }
     return $ext;
     preg_match_all('~\\.([^\\.]*)$~u', $fileName, $matches);
     $ext = '';
     if (isset($matches[1][0])) {
         $ext = $matches[1][0];
     }
     return $ext;
 }
Пример #13
0
 public static function generateAvatarThumb($upload_name, $folder, $filename)
 {
     //Start to check if the File type is Image type, so we Generate Everythumb size for it
     if (in_array(strtolower(CFileHelper::getExtension($upload_name)), array('gif', 'jpg', 'png'))) {
         //Start to create Thumbs for it
         $sizes = AvatarSize::getSizes();
         foreach ($sizes as $size) {
             if (!(file_exists(AVATAR_FOLDER . DIRECTORY_SEPARATOR . $size['id'] . DIRECTORY_SEPARATOR . $folder) && AVATAR_FOLDER . DIRECTORY_SEPARATOR . $size . DIRECTORY_SEPARATOR . $folder)) {
                 mkdir(AVATAR_FOLDER . DIRECTORY_SEPARATOR . $size['id'] . DIRECTORY_SEPARATOR . $folder, 0777, true);
             }
             $thumbs = new ImageResizer(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR, $filename, AVATAR_FOLDER . DIRECTORY_SEPARATOR . $size['id'] . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR, $filename, $size['width'], $size['height'], $size['ratio'], 90, '#FFFFFF');
             $thumbs->output();
         }
     }
 }
Пример #14
0
 /**
  * Renders a view file.
  *
  * @param string $viewFile view file path
  * @param array $data data to be extracted and made available to the view
  * @param boolean $return whether the rendering result should be returned instead of being echoed
  * @return string the rendering result. Null if the rendering result is not required.
  * @throws CException if the view file does not exist
  */
 public function renderFile($viewFile, $data = null, $return = false)
 {
     $widgetCount = count($this->_widgetStack);
     if (($renderer = Yii::app()->getViewRenderer()) !== null && $renderer->fileExtension === '.' . CFileHelper::getExtension($viewFile)) {
         $content = $renderer->renderFile($this, $viewFile, $data, $return);
     } else {
         $content = $this->renderInternal($viewFile, $data, $return);
     }
     if (count($this->_widgetStack) === $widgetCount) {
         return $content;
     } else {
         $widget = end($this->_widgetStack);
         throw new CException(Yii::t('yii', '{controller} contains improperly nested widget tags in its view "{view}". A {widget} widget does not have an endWidget() call.', array('{controller}' => get_class($this), '{view}' => $viewFile, '{widget}' => get_class($widget))));
     }
 }
Пример #15
0
 /**
  * @return array
  */
 protected function getLayouts()
 {
     $layouts = array();
     $files = scandir(Yii::getPathOfAlias('application.views.layouts'));
     foreach ($files as $file) {
         if ($file[0] !== '.') {
             if (CFileHelper::getExtension($file) === 'php') {
                 $layoutName = substr($file, 0, strpos($file, '.'));
             } else {
                 $layoutName = $file;
             }
             $layoutName = '//layouts/' . $layoutName;
             $layouts[$layoutName] = $layoutName;
         }
     }
     return $layouts;
 }
Пример #16
0
 /**
  * @param string $fileName uploaded file
  * @param string $originalName original file name. Used for getting extension. If null - using $fileName.
  * @return string Uid of new file
  */
 public function publishFile($fileName, $originalName = null)
 {
     if (is_null($originalName)) {
         $originalName = $fileName;
     }
     $ext = strtolower(CFileHelper::getExtension($originalName));
     if (empty($ext)) {
         // we have empty extension. Trying determine using mime type
         $ext = EFileHelper::getExtensionByMimeType($fileName);
     }
     if (!empty($ext)) {
         $ext = '.' . $ext;
     }
     $uid = $this->getUniqId() . $ext;
     $publishedFileName = $this->getFilePath($uid);
     $newDirName = pathinfo($publishedFileName, PATHINFO_DIRNAME);
     if (!file_exists($newDirName)) {
         mkdir($newDirName, 0775, true);
     }
     copy($fileName, $publishedFileName);
     return $uid;
 }
Пример #17
0
 public function prepare()
 {
     $this->files = array();
     $templatePath = $this->templatePath;
     $widgetPath = Yii::getPathOfAlias($this->widgetPath);
     $widgetTemplateFile = $templatePath . DIRECTORY_SEPARATOR . 'widget.php';
     $this->files[] = new CCodeFile($widgetPath . '/' . $this->widgetClass . '.php', $this->render($widgetTemplateFile));
     $files = CFileHelper::findFiles($templatePath, array('exclude' => array('.svn', '.gitignore')));
     foreach ($files as $file) {
         if ($file !== $widgetTemplateFile) {
             if (CFileHelper::getExtension($file) === 'php') {
                 $content = $this->render($file);
             } elseif (basename($file) === '.yii') {
                 $file = dirname($file);
                 $content = null;
             } else {
                 $content = file_get_contents($file);
             }
             $this->files[] = new CCodeFile($widgetPath . substr($file, strlen($templatePath)), $content);
         }
     }
 }
Пример #18
0
 public function prepare()
 {
     $this->files = array();
     foreach ($this->models as $model) {
         $this->model = $model;
         $this->controller = $model;
         $templatePath = $this->templatePath;
         $controllerTemplateFile = $templatePath . DIRECTORY_SEPARATOR . 'controller.php';
         if (!file_exists($this->controllerFile) || strpos(file_get_contents($this->controllerFile), ' extends GiiyCRUDController') === false) {
             $this->files[] = new CCodeFile($this->controllerFile, $this->render($controllerTemplateFile));
         }
         $files = scandir($templatePath);
         foreach ($files as $file) {
             if (is_file($templatePath . '/' . $file) && CFileHelper::getExtension($file) === 'php' && $file !== 'controller.php') {
                 $this->files[] = new CCodeFile($this->viewPath . DIRECTORY_SEPARATOR . '_base' . DIRECTORY_SEPARATOR . $file, $this->render($templatePath . '/_base/' . $file));
                 if (!file_exists($this->viewPath . DIRECTORY_SEPARATOR . $file)) {
                     $this->files[] = new CCodeFile($this->viewPath . DIRECTORY_SEPARATOR . $file, $this->render($templatePath . DIRECTORY_SEPARATOR . $file));
                 }
             }
         }
     }
 }
 public function prepare()
 {
     $this->files = array();
     $templatePath = $this->templatePath;
     $controllerTemplateFile = $templatePath . DIRECTORY_SEPARATOR . 'controller.php';
     $this->files[] = new CCodeFile($this->controllerFile, $this->render($controllerTemplateFile));
     $files = scandir($templatePath);
     foreach ($files as $file) {
         if (is_file($templatePath . '/' . $file) && CFileHelper::getExtension($file) === 'php' && $file !== 'controller.php') {
             $this->files[] = new CCodeFile($this->viewPath . DIRECTORY_SEPARATOR . $file, $this->render($templatePath . '/' . $file));
         }
     }
     if ($this->generateComponents) {
         $templatePath = $this->templatePath . DIRECTORY_SEPARATOR . 'components';
         $files = scandir($templatePath);
         foreach ($files as $file) {
             if (is_file($templatePath . '/' . $file) && CFileHelper::getExtension($file) === 'php') {
                 $this->files[] = new CCodeFile(Yii::getPathOfAlias('application.components') . DIRECTORY_SEPARATOR . $file, $this->render($templatePath . '/' . $file));
             }
         }
         $templatePath = $this->templatePath . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'widgets';
         $files = scandir($templatePath);
         foreach ($files as $file) {
             if (is_file($templatePath . '/' . $file) && CFileHelper::getExtension($file) === 'php') {
                 $this->files[] = new CCodeFile(Yii::getPathOfAlias('application.components.widgets') . DIRECTORY_SEPARATOR . $file, $this->render($templatePath . '/' . $file));
             }
         }
     }
     if ($this->generateLayouts) {
         $templatePath = $this->templatePath . DIRECTORY_SEPARATOR . 'layouts';
         $files = scandir($templatePath);
         foreach ($files as $file) {
             if (is_file($templatePath . '/' . $file) && CFileHelper::getExtension($file) === 'php') {
                 $this->files[] = new CCodeFile($this->layoutPath . DIRECTORY_SEPARATOR . $file, $this->render($templatePath . '/' . $file));
             }
         }
     }
 }
Пример #20
0
 public function uploadFile()
 {
     if (!$this->owner->isNewRecord) {
         $tmpFile = $this->_tmpFile;
     }
     $path = $this->uploadDirectory;
     if (!is_dir($path)) {
         mkdir($path);
     }
     $fileField = $this->owner->{$this->fileField};
     $fileField = CUploadedFile::getInstance($this->owner, $this->fileField);
     if ($fileField instanceof CUploadedFile) {
         //generate unique name for uploaded file
         $newName = trim(md5(time() . $fileField)) . '.' . CFileHelper::getExtension($fileField->name);
         $fileField->saveAs($path . $newName);
         $this->owner->{$this->fileField} = $this->_getDirName() . $newName;
         if (!$this->owner->isNewRecord) {
             $this->removeFile($path . $tmpFile);
         }
         return true;
     }
     $this->owner->{$this->fileField} = $tmpFile;
 }
Пример #21
0
 public function prepare()
 {
     $this->files = array();
     $templatePath = $this->templatePath;
     $modulePath = $this->modulePath;
     $moduleTemplateFile = $templatePath . DIRECTORY_SEPARATOR . 'module.php';
     // Файл описывающий модуль
     $moduleFile = $modulePath . '/' . $this->moduleClass . '.php';
     $this->isNewModule = file_exists($moduleFile) ? false : true;
     if ($this->isNewModule) {
         $this->files[] = new CCodeFile($moduleFile, $this->render($moduleTemplateFile));
     }
     $files = CFileHelper::findFiles($templatePath, array('exclude' => array('.svn', '.gitignore')));
     foreach ($files as $file) {
         if ($file !== $moduleTemplateFile) {
             if (CFileHelper::getExtension($file) === 'php') {
                 $content = $this->render($file);
             } else {
                 if (basename($file) === '.yii') {
                     $file = dirname($file);
                     $content = null;
                 } else {
                     $content = file_get_contents($file);
                 }
             }
             // Controller custom filename
             if (basename($file) == 'controller.php') {
                 $filePath = $modulePath . substr(dirname($file) . '/' . ucfirst($this->controllerID) . 'Controller.php', strlen($templatePath));
             } else {
                 //$filePath = $modulePath . substr($file, strlen($templatePath));
                 $filePath = $modulePath . '/views/' . $this->controllerID . '/' . basename($file);
             }
             $this->files[] = new CCodeFile($filePath, $content);
         }
     }
 }
Пример #22
0
 /**
  * Renders a view file.
  *
  * @param string $viewFile view file path
  * @param array $data data to be extracted and made available to the view
  * @param boolean $return whether the rendering result should be returned instead of being echoed
  * @return string the rendering result. Null if the rendering result is not required.
  * @throws CException if the view file does not exist
  */
 private function renderFile($viewFile, $data = null, $return = false)
 {
     if (($renderer = Yii::app()->getViewRenderer()) !== null && $renderer->fileExtension === '.' . CFileHelper::getExtension($viewFile)) {
         $content = $renderer->renderFile($this, $viewFile, $data, $return);
     } else {
         $content = $this->renderInternal($viewFile, $data, $return);
     }
     return $content;
 }
 public function prepare()
 {
     if ($this->mode == 'create') {
         $this->initialise(array('moduleID' => ucfirst(strtolower(Specialty::model()->findByPk($_REQUEST['Specialty']['id'])->abbreviation)) . ucfirst(strtolower(EventGroup::model()->findByPk($_REQUEST['EventGroup']['id'])->code)) . Yii::app()->request->getQuery('Specialty[id]') . preg_replace("/ /", "", ucfirst(strtolower($this->moduleSuffix))), 'moduleShortID' => ucfirst(strtolower(Specialty::model()->findByPk($_REQUEST['Specialty']['id'])->abbreviation)) . ucfirst(strtolower(EventGroup::model()->findByPk($_REQUEST['EventGroup']['id'])->code)) . Yii::app()->request->getQuery('Specialty[id]') . preg_replace("/ /", "", ucfirst(strtolower($this->moduleShortSuffix))), 'eventGroupName' => EventGroup::model()->findByPk($_REQUEST['EventGroup']['id'])->name));
     } else {
         if ($this->mode == 'update') {
             $this->event_type = EventType::model()->findByPk(@$_POST['EventTypeModuleEventType']);
             $short_suffix = $this->getEventShortName($this->event_type);
             $this->initialise(array('moduleID' => $this->event_type->class_name, 'moduleShortID' => Specialty::model()->findByPk($_REQUEST['Specialty']['id'])->abbreviation . EventGroup::model()->findByPk($_REQUEST['EventGroup']['id'])->code . $short_suffix, 'event_group' => EventGroup::model()->findByPk($_REQUEST['EventGroup']['id']), 'specialty' => Specialty::model()->findByPk($_REQUEST['Specialty']['id']), 'eventGroupName' => $this->event_type->name));
         }
     }
     if ($this->mode == 'update') {
         $current_class = $this->event_type->class_name;
         $target_class = Yii::app()->getController()->target_class = ucfirst(strtolower($this->specialty->abbreviation)) . ucfirst(strtolower($this->event_group->code)) . Yii::app()->request->getQuery('Specialty[id]') . preg_replace("/ /", "", ucfirst(strtolower($this->moduleSuffix)));
         if (@$_POST['generate'] == 'Generate') {
             $this->handleViewChanges();
             if ($current_class != $target_class) {
                 $this->handleModuleNameChange($current_class, $target_class);
             }
         }
     }
     $elements = $this->getElementsFromPost();
     foreach ($this->files_to_process as $file) {
         $destination_file = preg_replace("/EVENTNAME|EVENTTYPENAME|MODULENAME/", $this->moduleID, $file);
         if ($file !== $this->moduleTemplateFile) {
             if (CFileHelper::getExtension($file) === 'php' || CFileHelper::getExtension($file) === 'js' || CFileHelper::getExtension($file) === 'json' || CFileHelper::getExtension($file) === 'scss') {
                 if (preg_match("/" . preg_quote(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR) . "migrations" . preg_quote(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR) . "/", $file)) {
                     if (preg_match('/_create\\.php$/', $file) && $this->mode == 'create') {
                         # $matches = Array();
                         if (file_exists($this->modulePath . '/migrations/') and $matches = $this->regExpFile("/m([0-9]+)\\_([0-9]+)\\_event_type_" . $this->moduleID . "/", $this->modulePath . '/migrations/')) {
                             // migration file exists, so overwrite it rather than creating a new timestamped file
                             $migrationid = $matches[1] . '_' . $matches[2];
                         } else {
                             $migrationid = gmdate('ymd_His');
                         }
                         $destination_file = preg_replace("/" . preg_quote(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR) . "migrations" . preg_quote(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR) . "/", '/migrations/m' . $migrationid . '_', preg_replace('/_create/', '', $destination_file));
                         $content = $this->renderMigrations($file, $migrationid);
                         $this->files[] = new CCodeFile($this->modulePath . substr($destination_file, strlen($this->templatePath)), $content);
                     } else {
                         if (preg_match('/_update\\.php$/', $file) && $this->mode == 'update') {
                             $elements_have_changed = false;
                             foreach ($_POST as $key => $value) {
                                 if (preg_match('/^elementName[0-9]+$/', $key) || preg_match('/^elementId[0-9]+$/', $key)) {
                                     $elements_have_changed = true;
                                 }
                             }
                             if ($elements_have_changed) {
                                 $migrationid = gmdate('ymd_His');
                                 $destination_file = preg_replace("/\\/migrations\\//", '/migrations/m' . $migrationid . '_', preg_replace('/_update/', '', $destination_file));
                                 $content = $this->renderMigrations($file, $migrationid);
                                 $this->files[] = new CCodeFile($this->modulePath . substr($destination_file, strlen($this->templatePath)), $content);
                             }
                         }
                     }
                 } elseif (preg_match("/ELEMENTNAME|ELEMENTTYPENAME/", $file)) {
                     foreach ($elements as $element) {
                         $destination_file = preg_replace("/ELEMENTNAME|ELEMENTTYPENAME/", $element['class_name'], $file);
                         $content = $this->render($file, array('element' => $element));
                         $this->files[] = new CCodeFile($this->modulePath . substr($destination_file, strlen($this->templatePath)), $content);
                     }
                 } elseif (preg_match('/LOOKUPTABLE/', $file)) {
                     foreach ($elements as $element) {
                         foreach ($element['lookup_tables'] as $lookup_table) {
                             $destination_file = preg_replace('/LOOKUPTABLE/', $lookup_table['class'], $file);
                             $content = $this->render($file, array('lookup_table' => $lookup_table));
                             $this->files[] = new CCodeFile($this->modulePath . substr($destination_file, strlen($this->templatePath)), $content);
                         }
                     }
                 } elseif (preg_match('/MAPPINGTABLE/', $file)) {
                     foreach ($elements as $element) {
                         foreach ($element['mapping_tables'] as $mapping_table) {
                             $destination_file = preg_replace('/MAPPINGTABLE/', $mapping_table['class'], $file);
                             $content = $this->render($file, array('mapping_table' => $mapping_table));
                             $this->files[] = new CCodeFile($this->modulePath . substr($destination_file, strlen($this->templatePath)), $content);
                         }
                     }
                 } elseif (preg_match('/DEFAULTSTABLE/', $file)) {
                     foreach ($elements as $element) {
                         foreach ($element['defaults_tables'] as $defaults_table) {
                             $destination_file = preg_replace('/DEFAULTSTABLE/', $defaults_table['class'], $file);
                             $content = $this->render($file, array('defaults_table' => $defaults_table));
                             $this->files[] = new CCodeFile($this->modulePath . substr($destination_file, strlen($this->templatePath)), $content);
                         }
                     }
                 } elseif (preg_match('/\\.js$/', $file)) {
                     $content = $this->render($file, array('elements' => $elements));
                     $this->files[] = new CCodeFile($this->modulePath . substr($destination_file, strlen($this->templatePath)), $content);
                 } else {
                     $content = $this->render($file);
                     $this->files[] = new CCodeFile($this->modulePath . substr($destination_file, strlen($this->templatePath)), $content);
                 }
                 // an empty directory
             } else {
                 if (basename($file) === '.yii') {
                     $file = dirname($file);
                     $content = null;
                 } else {
                     $content = file_get_contents($file);
                     $this->files[] = new CCodeFile($this->modulePath . substr($destination_file, strlen($this->templatePath)), $content);
                 }
             }
         }
     }
 }
Пример #24
0
 public function actionRegisteruser()
 {
     $model = new User();
     $this->registerAjaxValidation($model);
     //   $model->setIsNewRecord(TRUE);
     if (isset($_POST["User"])) {
         $model->attributes = $_POST["User"];
         $model->user_name = $_POST["User"]["user_name"];
         $model->register_time = time();
         $uploadedFiles = CUploadedFile::getInstance($model, 'avatar');
         $model->avatar = empty($uploadedFiles) ? "" : $uploadedFiles->getName();
         $model->password = crypt($_POST["User"]["password"]);
         $model->retype_password = $model->password;
         $recvArray = array("subscribe_member_follow" => 1, "subscribe_ask_like" => 1, "subscribe_diary_like" => 1, "subscribe_recent_like" => 1, "subscribe_picture_like" => 1, "subscribe_timeline_like" => 1, "subscribe_message_like" => 0);
         $model->recv_option = serialize($recvArray);
         $visitArray = array("visit_count" => 0, "refuse_count" => 0);
         $model->visit_count = serialize($visitArray);
         $privArray = array("visit_priv" => 0, "comment_priv" => 0);
         $model->priv = serialize($privArray);
         if ($model->save()) {
             // 头像缩略图
             if (!empty($uploadedFiles)) {
                 if (!is_dir(Yii::app()->params["avatarPath"] . $model->id)) {
                     mkdir(Yii::app()->params["avatarPath"] . $model->id);
                 }
                 $fileExt = CFileHelper::getExtension($uploadedFiles->getName());
                 $fileName = rtrim($uploadedFiles->getName(), "." . $fileExt);
                 $filepath = Yii::app()->params["avatarPath"] . $model->id . '/' . md5($fileName) . '.' . $fileExt;
                 $ret = $uploadedFiles->saveAs($filepath);
                 $image = Yii::app()->image->load($filepath);
                 $image->resize(100, 100, Image::NONE);
                 $image->save($filepath);
                 // or $image->save('images/small.jpg');
             }
             $score = Sys::model()->getvaluesByType("register_score");
             $wealthModel = new Wealth();
             if (Sys::model()->getvaluesByType("register_type") == "0") {
                 $content = "注册成功,奖励" . $score . "个财富值";
                 $data = array('content' => $content, 'create_time' => $model->register_time, 'create_user' => $model->id);
                 $wealthModel->insertWealth($data);
                 User::model()->updateByPk($model->id, array("wealth" => intval($score)));
             }
             $this->redirect(Yii::app()->request->getUrlReferrer());
         }
     } else {
         $this->redirect(array("alluser"));
     }
     //     var_dump($_POST["User"]);
 }
Пример #25
0
 /**
  * 
  * Download a file with resume, stream and speed options
  * 
  * @param string $filename path to file including filename
  * @param integer $speed maximum download speed
  * @param boolean $doStream if stream or not
  */
 public static function download($filepath, $maxSpeed = 100, $doStream = false)
 {
     $seek_start = 0;
     $seek_end = -1;
     $data_section = false;
     $buffsize = 2048;
     // you can set by multiple of 1024
     if (!file_exists($filepath) && is_file($filepath)) {
         throw new CException(Yii::t('EDownloadHelper', 'Filepath does not exists on specified location or is not a regular file'));
     }
     $mimeType = CFileHelper::getMimeType($filepath);
     $filename = basename($filepath);
     if ($mimeType == null) {
         $mimeType = "application/octet-stream";
     }
     $extension = CFileHelper::getExtension($filepath);
     // resuming?
     if (isset($_SERVER['HTTP_RANGE'])) {
         $seek_range = substr($_SERVER['HTTP_RANGE'], strlen('bytes='));
         $range = explode('-', $seek_range);
         // do it the old way, no fancy stuff
         // to avoid problems
         if ($range[0] > 0) {
             $seek_start = intval($range[0]);
         }
         if ($range[1] > 0) {
             $seek_end = intval($range[1]);
         }
         $data_section = true;
     }
     // do some cleaning before we start
     ob_end_clean();
     $old_status = ignore_user_abort(true);
     set_time_limit(0);
     $size = filesize($filepath);
     if ($seek_start > $size - 1) {
         $seek_start = 0;
     }
     // open the file and move pointer
     // to started chunk
     $res = fopen($filepath, 'rb');
     if ($seek_start) {
         fseek($res, $seek_start);
     }
     if ($seek_end < $seek_start) {
         $seek_end = $size - 1;
     }
     header('Content-Type: ' . $mimeType);
     $contentDisposition = 'attachment';
     if ($doStream == true) {
         if (in_array($extension, self::$stream_types)) {
             $contentDisposition = 'inline';
         }
     }
     if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
         $fileName = preg_replace('/\\./', '%2e', $filename, substr_count($filename, '.') - 1);
     }
     header('Content-Disposition: ' . $contentDisposition . '; filename="' . $filename . '"');
     header('Last-Modified: ' . date('D, d M Y H:i:s \\G\\M\\T', filemtime($filepath)));
     // flushing a data section?
     if ($data_section) {
         header("HTTP/1.0 206 Partial Content");
         header("Status: 206 Partial Content");
         header('Accept-Ranges: bytes');
         header("Content-Range: bytes {$seek_start}-{$seek_end}/{$size}");
         header("Content-Length: " . ($seek_end - $seek_start + 1));
     } else {
         // nope, just
         header('Content-Length: ' . $size);
     }
     $size = $seek_end - $seek_start + 1;
     while (!(connection_aborted() || connection_status() == 1) && !feof($res)) {
         print fread($res, $buffsize * $maxSpeed);
         flush();
         @ob_flush();
         sleep(1);
     }
     // close file
     fclose($res);
     // restore defaults
     ignore_user_abort($old_status);
     set_time_limit(ini_get('max_execution_time'));
 }
Пример #26
0
 /**
  * 根据文件扩展名取得对应的icon路径
  * Enter description here ...
  * @param unknown_type $ext
  */
 public static function getIconByExt($filename)
 {
     $path = "/images/fileicon/";
     $ext2Icon = array('doc' => $path . "word.png", 'docx' => $path . "word.png", 'xls' => $path . "excel.png", 'xlsx' => $path . "excel.png", 'jpg' => $path . "img.png", 'png' => $path . "img.png", 'gif' => $path . "img.png", 'jpeg' => $path . "img.png", 'ppt' => $path . "ppt.png", 'pptx' => $path . "ppt.png", 'txt' => $path . "txt.png", 'zip' => $path . "rar.png", 'rar' => $path . "rar.png", 'mp3' => $path . "music.png", 'pdf' => $path . "pdf.png", 'default' => $path . "apple.png");
     $ext = CFileHelper::getExtension($filename);
     return isset($ext2Icon[$ext]) ? $ext2Icon[$ext] : $ext2Icon['default'];
 }
Пример #27
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     //this parameter is the issueId!
     Result::model()->cleanRecords();
     //clean old remaining records
     $this->layout = "//layouts/column1";
     $issue = $this->loadIssue($id);
     $redirect = false;
     $issueId = $id;
     //checking if the document is already opened
     $opened = Opendocs::model()->find("issueId={$issueId}");
     //if there has been any
     if (isset($_POST['Result']) or isset($_POST['Checks']) or isset($_POST['Table']) or isset($_POST['File'])) {
         $redirect = true;
         //true means it is actually saving a document. False means is opening the update view
     }
     if (isset($opened)) {
         //the issue has a record in open docs
         $now = time();
         $morethanyesterday = strtotime($opened->createTime);
         $morethanyesterday = $morethanyesterday + 86400;
         if ($now < $morethanyesterday) {
             //less than 24h
             $user = User::model()->findByPk($opened->userId);
             if ($opened->userId == Yii::app()->user->id) {
                 //actual user is the issue's owner
                 if ($redirect) {
                     // the user is on the update view already and has clicked "save" button
                     //saving process:
                     if (isset($_POST['Result'])) {
                         //Result::model()->reset($id);//RESET
                         $redirect = true;
                         $post = $_POST['Result'];
                         if (isset($post['elementid'])) {
                             $elementId = $post['elementid'];
                             foreach ($elementId as $key => $value) {
                                 //if ($value != '') {
                                 if (is_array($value)) {
                                     foreach ($value as $option) {
                                         $model = new Result();
                                         $model->elementId = $key;
                                         $model->issueId = $issueId;
                                         if ($model->value != $option) {
                                             $model->value = $option;
                                             $model->save();
                                         }
                                     }
                                 } else {
                                     $model = Result::model()->find("elementId = {$key} and issueId = {$issueId}");
                                     if ($model === null) {
                                         $model = new Result();
                                         $model->elementId = $key;
                                         $model->issueId = $issueId;
                                     }
                                     if ($model->value != $value) {
                                         $model->value = $value;
                                         $model->save();
                                     }
                                 }
                                 //}
                             }
                         }
                     }
                     if (isset($_POST['Checks'])) {
                         //For Checkboxes: once one is selected there must be at least one checked option. It's impossible to uncheck all of them.
                         // that's the way is supposed to be. Keep track record.
                         $redirect = true;
                         $typeId = 6;
                         $post = $_POST['Checks'];
                         $values = array();
                         if (isset($post['elementid'])) {
                             $elementId = $post['elementid'];
                             foreach ($elementId as $key => $value) {
                                 if (is_array($value)) {
                                     foreach ($value as $option) {
                                         $values[] = $option;
                                         $model = new Result();
                                         $model->elementId = $key;
                                         $model->issueId = $issueId;
                                         if (in_array($option, $value)) {
                                             $what = Element::doesExist($key, $issueId, $option);
                                             if ($what < 1) {
                                                 $model->value = $option;
                                                 $model->save();
                                             }
                                         }
                                     }
                                 }
                                 $statement = " ";
                                 foreach ($values as $cond) {
                                     $statement .= " and t.value NOT like '{$cond}'";
                                 }
                                 $statement = "issueId= {$issueId} and elementId = {$key} " . $statement;
                                 $criteria = new CDbCriteria();
                                 $criteria->condition = $statement;
                                 //"issueId = $issueId and elementId = $key and value NOT LIKE ('$values')";
                                 $modelo = Result::model()->findAll($criteria);
                                 foreach ($modelo as $borrar) {
                                     $borrar->delete();
                                 }
                             }
                         }
                     }
                     if (isset($_POST['Table'])) {
                         //Result::model()->resetTable($id);
                         //Result::model()->setTableOFF($id);
                         $redirect = true;
                         $tables = $_POST['Table'];
                         foreach ($tables as $key => $value) {
                             $elementId = $key;
                             foreach ($value as $row => $array) {
                                 foreach ($array as $column => $response) {
                                     if ($elementId != "xxx") {
                                         $res = Result::model()->find("elementId = {$elementId} and issueId = {$issueId} and colonne = {$column} and ligne = {$row}");
                                         if ($res === null) {
                                             $res = new Result();
                                             $res->elementId = $elementId;
                                             $res->issueId = $issueId;
                                             $res->colonne = $column;
                                             $res->ligne = $row;
                                             //if($response!=null || $response!="" || !isset($response)){
                                         }
                                         if ($response != $res->value) {
                                             $res->value = $response;
                                             $res->save();
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     if (isset($_FILES['File'])) {
                         //throw new CHttpException(403, "update de resultcontroller");
                         foreach ($_FILES['File']['name']['elementid'] as $key => $value) {
                             if (is_array($value)) {
                                 foreach ($value as $k => $v) {
                                     if ($v != '') {
                                         $rnd = rand(0, 99999);
                                         $tmpname = $_FILES['File']['tmp_name']['elementid'][$key][$k];
                                         $fichier = "{$rnd}-" . preg_replace("/[^a-zA-Z0-9\\/_|.-]/", "_", $v);
                                         $extensions = 'img';
                                         $fileType = CFileHelper::getMimeType($v);
                                         //this makes sure it is an image, getimagesize doesn't work
                                         if (move_uploaded_file($tmpname, Yii::app()->params['dfs'] . "/result/" . $fichier)) {
                                             $file = new File();
                                             if (strpos($fileType, 'image') !== false) {
                                                 $image = 1;
                                             } else {
                                                 $image = 0;
                                             }
                                             $file->image = $image;
                                             $file->userId = Yii::app()->user->id;
                                             $file->fileSelected = $v;
                                             $file->link = "result/" . $fichier;
                                             if ($file->save()) {
                                                 $fileId = $file->id;
                                                 $res = new Result();
                                                 $res->elementId = $key;
                                                 $res->issueId = $issueId;
                                                 $res->fileId = $fileId;
                                                 $res->value = $file->id;
                                                 $res->save();
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 if ($value != '') {
                                     $tmp = $_FILES['File']['tmp_name']['elementid'][$key];
                                     $rnd = rand(0, 99999);
                                     $fichier = "{$rnd}-" . preg_replace("/[^a-zA-Z0-9\\/_|.-]/", "_", $value);
                                     if (@getimagesize($tmp)) {
                                         $image = 1;
                                     } else {
                                         $image = 0;
                                     }
                                     if (move_uploaded_file($tmp, Yii::app()->params['dfs'] . "result/" . $fichier)) {
                                         //Si la fonction renvoie TRUE, c'est que ça a fonctionné...
                                         $file = new File();
                                         $file->image = $image;
                                         $file->userId = Yii::app()->user->id;
                                         $file->fileSelected = $value;
                                         $file->link = "result/" . $fichier;
                                         if ($file->save()) {
                                             $fileId = $file->id;
                                             $res = new Result();
                                             $res->elementId = $key;
                                             $res->issueId = $issueId;
                                             $res->fileId = $fileId;
                                             $res->value = $file->id;
                                             $res->save();
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     //delete record in opendocs and exit to view
                     $opened->delete();
                     //the document has been saved and exit. Then the opendoc item has to be deleted
                     $this->redirect(array('issue/view', 'id' => $issueId));
                 } else {
                     //user is accessing the update view of an issue. He's the owner of the issue therefore he can access it.
                     //creates a new opened doc item and access the update view
                     $opened->createTime = new CDbExpression('NOW()');
                     $opened->save();
                     $this->render('update', array('model' => $issue, 'traveler' => $issue->traveler, 'issueId' => $issueId));
                 }
             } else {
                 //less than 24h, not the owner. Then the user has to access the unlocking view if he still wants to access the update view
                 $this->render('open', array('user' => $user, 'opened' => $opened, 'issueId' => $issueId));
             }
         } else {
             //opendocs record is older than 24h.
             if ($redirect) {
                 //the user is on the update view already and has clicked "save" button
                 if (isset($_POST['Result'])) {
                     //Result::model()->reset($id);//RESET
                     $redirect = true;
                     $post = $_POST['Result'];
                     if (isset($post['elementid'])) {
                         $elementId = $post['elementid'];
                         foreach ($elementId as $key => $value) {
                             //if ($value != '') {
                             if (is_array($value)) {
                                 foreach ($value as $option) {
                                     $model = new Result();
                                     $model->elementId = $key;
                                     $model->issueId = $issueId;
                                     if ($model->value != $option) {
                                         $model->value = $option;
                                         $model->save();
                                     }
                                 }
                             } else {
                                 $model = Result::model()->find("elementId = {$key} and issueId = {$issueId}");
                                 if ($model === null) {
                                     $model = new Result();
                                     $model->elementId = $key;
                                     $model->issueId = $issueId;
                                 }
                                 if ($model->value != $value) {
                                     $model->value = $value;
                                     $model->save();
                                 }
                             }
                             //}
                         }
                     }
                 }
                 if (isset($_POST['Checks'])) {
                     //Result::model()->resetBox($id);//RESET
                     $redirect = true;
                     $typeId = 6;
                     $post = $_POST['Checks'];
                     $values = array();
                     if (isset($post['elementid'])) {
                         $elementId = $post['elementid'];
                         foreach ($elementId as $key => $value) {
                             if (is_array($value)) {
                                 foreach ($value as $option) {
                                     $values[] = $option;
                                     $model = new Result();
                                     $model->elementId = $key;
                                     $model->issueId = $issueId;
                                     if (in_array($option, $value)) {
                                         $what = Element::doesExist($key, $issueId, $option);
                                         if ($what < 1) {
                                             $model->value = $option;
                                             $model->save();
                                         }
                                     }
                                 }
                             }
                             $statement = " ";
                             foreach ($values as $cond) {
                                 $statement .= " and t.value NOT like '{$cond}'";
                             }
                             $statement = "issueId= {$issueId} and elementId = {$key} " . $statement;
                             $criteria = new CDbCriteria();
                             $criteria->condition = $statement;
                             //"issueId = $issueId and elementId = $key and value NOT LIKE ('$values')";
                             $modelo = Result::model()->findAll($criteria);
                             foreach ($modelo as $borrar) {
                                 $borrar->delete();
                             }
                         }
                     }
                 }
                 if (isset($_POST['Table'])) {
                     //Result::model()->resetTable($id);
                     //Result::model()->setTableOFF($id);
                     $redirect = true;
                     $tables = $_POST['Table'];
                     foreach ($tables as $key => $value) {
                         $elementId = $key;
                         foreach ($value as $row => $array) {
                             foreach ($array as $column => $response) {
                                 if ($elementId != "xxx") {
                                     $res = Result::model()->find("elementId = {$elementId} and issueId = {$issueId} and colonne = {$column} and ligne = {$row}");
                                     if ($res === null) {
                                         $res = new Result();
                                         $res->elementId = $elementId;
                                         $res->issueId = $issueId;
                                         $res->colonne = $column;
                                         $res->ligne = $row;
                                         //if($response!=null || $response!="" || !isset($response)){
                                     }
                                     if ($response != $res->value) {
                                         $res->value = $response;
                                         $res->save();
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if (isset($_FILES['File'])) {
                     //throw new CHttpException(403, "update de resultcontroller");
                     foreach ($_FILES['File']['name']['elementid'] as $key => $value) {
                         if (is_array($value)) {
                             foreach ($value as $k => $v) {
                                 if ($v != '') {
                                     $rnd = rand(0, 99999);
                                     $tmpname = $_FILES['File']['tmp_name']['elementid'][$key][$k];
                                     $fichier = "{$rnd}-" . preg_replace("/[^a-zA-Z0-9\\/_|.-]/", "_", $v);
                                     if (move_uploaded_file($tmpname, Yii::app()->params['dfs'] . "/result/" . $fichier)) {
                                         $file = new File();
                                         if (@getimagesize($tmpname)) {
                                             $image = 1;
                                         } else {
                                             $image = 0;
                                         }
                                         $file->image = $image;
                                         $file->userId = Yii::app()->user->id;
                                         $file->fileSelected = $v;
                                         $file->link = "result/" . $fichier;
                                         if ($file->save()) {
                                             $fileId = $file->id;
                                             $res = new Result();
                                             $res->elementId = $key;
                                             $res->issueId = $issueId;
                                             $res->fileId = $fileId;
                                             $res->value = $file->id;
                                             $res->save();
                                         }
                                     }
                                 }
                             }
                         } else {
                             if ($value != '') {
                                 $tmp = $_FILES['File']['tmp_name']['elementid'][$key];
                                 $rnd = rand(0, 99999);
                                 $fichier = "{$rnd}-" . preg_replace("/[^a-zA-Z0-9\\/_|.-]/", "_", $value);
                                 if (@getimagesize($tmp)) {
                                     $image = 1;
                                 } else {
                                     $image = 0;
                                 }
                                 if (move_uploaded_file($tmp, Yii::app()->params['dfs'] . "/result/" . $fichier)) {
                                     //Si la fonction renvoie TRUE, c'est que ça a fonctionné...
                                     $file = new File();
                                     $file->image = $image;
                                     $file->userId = Yii::app()->user->id;
                                     $file->fileSelected = $value;
                                     $file->link = "result/" . $fichier;
                                     if ($file->save()) {
                                         $fileId = $file->id;
                                         $res = new Result();
                                         $res->elementId = $key;
                                         $res->issueId = $issueId;
                                         $res->fileId = $fileId;
                                         $res->value = $file->id;
                                         $res->save();
                                     }
                                 }
                             }
                         }
                     }
                 }
                 //delete record in opendocs and exit to view
                 $opened->delete();
                 $this->redirect(array('issue/view', 'id' => $issueId));
             } else {
                 //user is accessing the update view of an issue
                 //delete old opendocs record and create a new one
                 $opened->delete();
                 $model = new Opendocs();
                 $model->issueId = $issueId;
                 $model->userId = Yii::app()->user->id;
                 $model->createTime = new CDbExpression('GETDATE()');
                 $model->save();
                 $this->render('update', array('model' => $issue, 'traveler' => $issue->traveler, 'issueId' => $issueId));
             }
         }
     } else {
         //there is not previous opendocs record. Then no restrictions.
         if ($redirect) {
             //user is saving the issue
             if (isset($_POST['Result'])) {
                 //Result::model()->reset($id);//RESET
                 $redirect = true;
                 $post = $_POST['Result'];
                 if (isset($post['elementid'])) {
                     $elementId = $post['elementid'];
                     foreach ($elementId as $key => $value) {
                         //if ($value != '') {
                         if (is_array($value)) {
                             foreach ($value as $option) {
                                 $model = new Result();
                                 $model->elementId = $key;
                                 $model->issueId = $issueId;
                                 if ($model->value != $option) {
                                     $model->value = $option;
                                     $model->save();
                                 }
                             }
                         } else {
                             $model = Result::model()->find("elementId = {$key} and issueId = {$issueId}");
                             if ($model === null) {
                                 $model = new Result();
                                 $model->elementId = $key;
                                 $model->issueId = $issueId;
                             }
                             if ($model->value != $value) {
                                 $model->value = $value;
                                 $model->save();
                             }
                         }
                         //}
                     }
                 }
             }
             if (isset($_POST['Checks'])) {
                 //Result::model()->resetBox($id);//RESET
                 $redirect = true;
                 $typeId = 6;
                 $post = $_POST['Checks'];
                 $values = array();
                 if (isset($post['elementid'])) {
                     $elementId = $post['elementid'];
                     foreach ($elementId as $key => $value) {
                         if (is_array($value)) {
                             foreach ($value as $option) {
                                 $values[] = $option;
                                 $model = new Result();
                                 $model->elementId = $key;
                                 $model->issueId = $issueId;
                                 if (in_array($option, $value)) {
                                     $what = Element::doesExist($key, $issueId, $option);
                                     if ($what < 1) {
                                         $model->value = $option;
                                         $model->save();
                                     }
                                 }
                             }
                         }
                         $statement = " ";
                         foreach ($values as $cond) {
                             $statement .= " and t.value NOT like '{$cond}'";
                         }
                         $statement = "issueId= {$issueId} and elementId = {$key} " . $statement;
                         $criteria = new CDbCriteria();
                         $criteria->condition = $statement;
                         //"issueId = $issueId and elementId = $key and value NOT LIKE ('$values')";
                         $modelo = Result::model()->findAll($criteria);
                         foreach ($modelo as $borrar) {
                             $borrar->delete();
                         }
                     }
                 }
             }
             if (isset($_POST['Table'])) {
                 //Result::model()->resetTable($id);
                 //Result::model()->setTableOFF($id);
                 $redirect = true;
                 $tables = $_POST['Table'];
                 foreach ($tables as $key => $value) {
                     $elementId = $key;
                     foreach ($value as $row => $array) {
                         foreach ($array as $column => $response) {
                             if ($elementId != "xxx") {
                                 $res = Result::model()->find("elementId = {$elementId} and issueId = {$issueId} and colonne = {$column} and ligne = {$row}");
                                 if ($res === null) {
                                     $res = new Result();
                                     $res->elementId = $elementId;
                                     $res->issueId = $issueId;
                                     $res->colonne = $column;
                                     $res->ligne = $row;
                                     //if($response!=null || $response!="" || !isset($response)){
                                 }
                                 if ($response != $res->value) {
                                     $res->value = $response;
                                     $res->save();
                                 }
                             }
                         }
                     }
                 }
             }
             if (isset($_FILES['File'])) {
                 //throw new CHttpException(403, "update de resultcontroller");
                 foreach ($_FILES['File']['name']['elementid'] as $key => $value) {
                     if (is_array($value)) {
                         foreach ($value as $k => $v) {
                             if ($v != '') {
                                 $rnd = rand(0, 99999);
                                 $tmpname = $_FILES['File']['tmp_name']['elementid'][$key][$k];
                                 $fichier = "{$rnd}-" . preg_replace("/[^a-zA-Z0-9\\/_|.-]/", "_", $v);
                                 $fileType = CFileHelper::getMimeType($v);
                                 //this makes sure it is an image, getimagesize doesn't work
                                 $noexe = CFileHelper::getExtension($v);
                                 if (strpos($noexe, 'py') !== false or strpos($noexe, 'exe') !== false) {
                                     throw new CHttpException(403, "Forbidden type of file");
                                 }
                                 if (move_uploaded_file($tmpname, Yii::app()->params['dfs'] . "/result/" . $fichier)) {
                                     $file = new File();
                                     if (strpos($fileType, 'image') !== false) {
                                         $image = 1;
                                     } else {
                                         $image = 0;
                                     }
                                     $file->image = $image;
                                     $file->userId = Yii::app()->user->id;
                                     $file->fileSelected = $v;
                                     $file->link = "result/" . $fichier;
                                     if ($file->save()) {
                                         $fileId = $file->id;
                                         $res = new Result();
                                         $res->elementId = $key;
                                         $res->issueId = $issueId;
                                         $res->fileId = $fileId;
                                         $res->value = $file->id;
                                         $res->save();
                                     }
                                 }
                             }
                         }
                     } else {
                         if ($value != '') {
                             $tmp = $_FILES['File']['tmp_name']['elementid'][$key];
                             $rnd = rand(0, 99999);
                             $fichier = "{$rnd}-" . preg_replace("/[^a-zA-Z0-9\\/_|.-]/", "_", $value);
                             $fileType = CFileHelper::getMimeType($v);
                             //this makes sure it is an image, getimagesize doesn't work
                             $noexe = CFileHelper::getExtension($v);
                             if (strpos($noexe, 'py') !== false or strpos($noexe, 'exe') !== false) {
                                 throw new CHttpException(403, "Forbidden type of file");
                             }
                             if (move_uploaded_file($tmp, Yii::app()->params['dfs'] . "/result/" . $fichier)) {
                                 //Si la fonction renvoie TRUE, c'est que ça a fonctionné...
                                 $file = new File();
                                 if (strpos($fileType, 'image') !== false) {
                                     $image = 1;
                                 } else {
                                     $image = 0;
                                 }
                                 $file->image = $image;
                                 $file->userId = Yii::app()->user->id;
                                 $file->fileSelected = $value;
                                 $file->link = "result/" . $fichier;
                                 if ($file->save()) {
                                     $fileId = $file->id;
                                     $res = new Result();
                                     $res->elementId = $key;
                                     $res->issueId = $issueId;
                                     $res->fileId = $fileId;
                                     $res->value = $file->id;
                                     $res->save();
                                 }
                             }
                         }
                     }
                 }
             }
             $this->redirect(array('issue/view', 'id' => $issueId));
         } else {
             //user is trying to access the update view. Then create a new record in opendocs and access update view
             $model = new Opendocs();
             $model->issueId = $issueId;
             $model->userId = Yii::app()->user->id;
             $model->createTime = new CDbExpression('GETDATE()');
             $model->save();
             $this->render('update', array('model' => $issue, 'traveler' => $issue->traveler, 'issueId' => $issueId));
         }
     }
 }
Пример #28
0
 /**
  * Saves the uploaded file.
  * @param string $file the file path used to save the uploaded file
  * @param boolean $deleteTempFile whether to delete the temporary file after saving.
  * If true, you will not be able to save the uploaded file again in the current request.
  * @return boolean true whether the file is saved successfully
  */
 public function saveAs($file, $deleteTempFile = true)
 {
     if ($this->_error == UPLOAD_ERR_OK) {
         if (strpos("/", $this->_name) || strpos("\\", $this->_name) || strpos("'", $this->_name) || strpos("\"", $this->_name) || strpos(":", $this->_name) || strpos("*", $this->_name) || strpos("?", $this->_name) || strpos("<", $this->_name) || strpos(">", $this->_name) || strpos("|", $this->_name)) {
             $this->_errorDesc = sprintf("文件名[%s]包含[/\\'\":*?<>|]等非法字符", $this->_name);
         } else {
             if (!TFileUtil::isUploadable($this->_name)) {
                 $this->_errorDesc = sprintf("禁止上传后缀名为[%s]的文件", CFileHelper::getExtension($this->_name));
             } else {
                 if ($this->_size == 0) {
                     $this->_errorDesc = sprintf("文件[%s]大小为0字节", $this->_name);
                 }
             }
         }
         if ($deleteTempFile) {
             if (!Yii::app()->storage->move($this->_tempName, $file, false)) {
                 $this->_errorDesc = '上传文件失败';
             }
         } else {
             if (is_uploaded_file($this->_tempName)) {
                 if (!Yii::app()->storage->copy($this->_tempName, $file)) {
                     $this->_errorDesc = '上传文件失败';
                 }
             }
         }
     } else {
         if ($this->_error == UPLOAD_ERR_INI_SIZE) {
             $this->_errorDesc = sprintf("文件[%s]的大小超过了系统限制(%s)", $this->_name, ini_get('upload_max_filesize'));
         } else {
             if ($this->_error == UPLOAD_ERR_FORM_SIZE) {
                 $this->_errorDesc = sprintf("文件[%s]的大小超过了表单限制", $this->_name);
             } else {
                 if ($this->_error == UPLOAD_ERR_PARTIAL) {
                     $this->_errorDesc = sprintf("文件[%s]上传不完整", $this->_name);
                 } else {
                     if ($this->_error == UPLOAD_ERR_NO_TMP_DIR) {
                         $this->_errorDesc = sprintf("文件[%s]上传失败:找不到临时文件夹", $this->_name);
                     } else {
                         if ($this->_error == UPLOAD_ERR_CANT_WRITE) {
                             $this->_errorDesc = sprintf("文件[%s]写入失败", $this->_name);
                         } else {
                             $this->_errorDesc = sprintf("未知错误[代码:%s]", $this->_error);
                         }
                     }
                 }
             }
         }
     }
     if ($this->_errorDesc != '') {
         return $this->_errorDesc;
     } else {
         return true;
     }
 }
 /**
  * This method is overridden to be able to copy certain templates to backend and frontend themes' view directories
  * More specifically, views placed in _frontend will be copied to the destination as specified by $this->frontendViewPathAlias
  * and views placed in _backend will be copied to the destination as specified by $this->backendViewPathAlias
  */
 public function prepare()
 {
     parent::prepare();
     // Add backend theme views
     $templatePath = $this->templatePath . DIRECTORY_SEPARATOR . "_backend";
     if (is_dir($templatePath)) {
         $files = scandir($templatePath);
         foreach ($files as $file) {
             if (is_file($templatePath . '/' . $file) && CFileHelper::getExtension($file) === 'php') {
                 $this->files[] = new CCodeFile(Yii::getPathOfAlias($this->backendViewPathAlias) . DIRECTORY_SEPARATOR . $this->getControllerID() . DIRECTORY_SEPARATOR . $file, $this->render($templatePath . '/' . $file));
             }
         }
     }
     // Add frontend theme views
     $templatePath = $this->templatePath . DIRECTORY_SEPARATOR . "_frontend";
     if (is_dir($templatePath)) {
         $files = scandir($templatePath);
         foreach ($files as $file) {
             if (is_file($templatePath . '/' . $file) && CFileHelper::getExtension($file) === 'php') {
                 $this->files[] = new CCodeFile(Yii::getPathOfAlias($this->frontendViewPathAlias) . DIRECTORY_SEPARATOR . $this->getControllerID() . DIRECTORY_SEPARATOR . $file, $this->render($templatePath . '/' . $file));
             }
         }
     }
 }
Пример #30
0
 /**
  * 批处理
  */
 public function actionOperate()
 {
     $command = trim($this->_request->getParam('command'));
     switch ($command) {
         case 'deleteFile':
             $filenames = $this->_request->getParam('sqlfile');
             if ($filenames) {
                 if (is_array($filenames)) {
                     foreach ($filenames as $filename) {
                         if (CFileHelper::getExtension($filename) == 'sql') {
                             @unlink($this->_bakupPath . $filename);
                         }
                     }
                     $this->message('success', '删除完成', $this->createUrl('import'));
                 } else {
                     if (CFileHelper::getExtension($filenames) == 'sql') {
                         @unlink($this->_bakupPath . $filename);
                         $this->message('success', '删除完成', $this->createUrl('import'));
                     }
                 }
             } else {
                 $this->message('error', '请选择要删除的文件', $this->createUrl('import'));
             }
             break;
         case 'downloadFile':
             $sqlfile = $this->_bakupPath . $this->_request->getParam('sqlfile');
             Yii::app()->request->sendFile($this->_request->getParam('sqlfile'), file_get_contents($sqlfile));
             break;
         default:
             throw new CHttpException(404, '未找到操作');
             break;
     }
 }