Beispiel #1
0
 public function post_index()
 {
     $new = new Files();
     $new->save();
     $response = array('success' => true, 'data' => array('id' => $new->id));
     $json = json_encode($response);
     return $json;
 }
Beispiel #2
0
 /**
  * Вывод инфы о бане
  * @param integer $id ID бана
  */
 public function actionView($id)
 {
     // Подгружаем комментарии и файлы
     $files = new Files();
     //$this->performAjaxValidation($files);
     $files->unsetAttributes();
     $comments = new Comments();
     $comments->unsetAttributes();
     // Подгружаем баны
     $model = Bans::model()->with('admin')->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     $geo = false;
     // Проверка прав на просмотр IP
     $ipaccess = Webadmins::checkAccess('ip_view');
     if ($ipaccess) {
         $geo = array('city' => 'Н/А', 'region' => 'Не определен', 'country' => 'Не определен', 'lat' => 0, 'lng' => 0);
         $get = @file_get_contents('http://ipgeobase.ru:7020/geo?ip=' . $model->player_ip);
         if ($get) {
             $xml = @simplexml_load_string($get);
             if (!empty($xml->ip)) {
                 $geo['city'] = $xml->ip->city;
                 $geo['region'] = $xml->ip->region;
                 $geo['country'] = $xml->ip->country;
                 $geo['lat'] = $xml->ip->lat;
                 $geo['lng'] = $xml->ip->lng;
             }
         }
     }
     // Добавление файла
     if (isset($_POST['Files'])) {
         // Задаем аттрибуты
         $files->attributes = $_POST['Files'];
         $files->bid = intval($id);
         if ($files->save()) {
             $this->refresh();
         }
     }
     // Добавление комментария
     if (isset($_POST['Comments'])) {
         //exit(print_r($_POST['Comments']));
         $comments->attributes = $_POST['Comments'];
         $comments->bid = $id;
         if ($comments->save()) {
             $this->refresh();
         }
     }
     // Выборка комментариев
     $c = new CActiveDataProvider($comments, array('criteria' => array('condition' => 'bid = :bid', 'params' => array(':bid' => $id))));
     // Выборка файлов
     $f = new CActiveDataProvider(Files::model(), array('criteria' => array('condition' => 'bid = :bid', 'params' => array(':bid' => $id))));
     // История банов
     $history = new CActiveDataProvider('Bans', array('criteria' => array('condition' => '`bid` <> :hbid AND (`player_ip` = :hip OR `player_id` = :hid)', 'params' => array(':hbid' => $id, ':hip' => $model->player_ip, ':hid' => $model->player_id)), 'pagination' => array('pageSize' => 5)));
     // Вывод всего на вьюху
     $this->render('view', array('geo' => $geo, 'ipaccess' => $ipaccess, 'model' => $model, 'files' => $files, 'comments' => $comments, 'f' => $f, 'c' => $c, 'history' => $history));
 }
 public function addAction(Files $file)
 {
     if ($this->request->isPost()) {
         //            dd($this->request->getPost());
         $file->save($this->request->getPost());
         EventFacade::fire('standards:addFile', $file);
         return $this->redirectByRoute(['for' => 'index', 'page' => 1]);
     }
     $this->view->form = myForm::buildFormFromModel($file);
 }
Beispiel #4
0
 public function backupDB()
 {
     $dumper = new dbMaster();
     $sql = $dumper->getDump(false);
     $file = new Files();
     $file->name = "DB Backup " . date("d-m-Y_H_i") . ".sql";
     $file->path = '.';
     $file->save();
     $file->writeFile($sql);
     $this->DBback = $file->id;
 }
Beispiel #5
0
 public function action_index()
 {
     $record = new Files();
     $record->parent_id = $_POST['parent_id'];
     $record->text = $_POST['text'];
     $record->extension = $_POST['extension'];
     $record->leaf = $_POST['leaf'];
     $record->save();
     $array = array('success' => 'true', 'msg' => 'Record added successfully');
     $json = json_encode($array);
     return $json;
 }
Beispiel #6
0
 public static function register($name, $filepath, $extension, $module_name, $module_id)
 {
     $file = new Files();
     $file->name = $name;
     $file->path = $filepath;
     $file->extension = $extension;
     $file->type = Files::getType($extension);
     $file->module_name = $module_name;
     $file->module_id = $module_id;
     $file->size = filesize(Files::fullDir($filepath));
     $file->save();
     return $file->id;
 }
Beispiel #7
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Files();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Files'])) {
         $model->attributes = $_POST['Files'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Beispiel #8
0
 public function post_index()
 {
     $data = file_get_contents('php://input');
     $temp = json_decode($data);
     $new = new Files();
     $new->text = $temp->text;
     $new->parent_id = $temp->parentId;
     $new->leaf = $temp->leaf;
     $new->save();
     $response = array('success' => true, 'data' => array('id' => $new->id));
     $json = json_encode($response);
     return $json;
 }
 public function upload(Request $request)
 {
     $file = $request->file;
     $imageName = md5(time() * rand(1, 100)) . '.' . $file->getClientOriginalExtension();
     $f = new Files();
     $f->name = $imageName;
     $f->mimeType = $file->getMimeType();
     $f->size = $file->getSize();
     $f->user_id = 1;
     $f->produto_id = $request->input('produto_id');
     $file->move(base_path() . '/public/imagens/', $imageName);
     $f->save();
     return 'OK';
 }
Beispiel #10
0
 public function createMongoAction()
 {
     $file = new Files();
     $file->type = "video";
     $file->name = "Astro Boy";
     $file->year = 1952;
     if ($file->save() == false) {
         echo "Umh, We can't store files right now: \n";
         foreach ($file->getMessages() as $message) {
             echo $message, "\n";
         }
     } else {
         echo "Great, a new file was saved successfully !";
     }
 }
Beispiel #11
0
 public function save($runValidation = true, $attributes = NULL)
 {
     $class = get_class($this);
     if ($class == 'Accounts') {
         if (Accounts::model()->findByPk($this->id)) {
             $this->isNewRecord = false;
         }
     }
     $a = parent::save($runValidation, $attributes);
     if ($a) {
         //if (isset($_POST['Files'])) {
         //$this->attributes = $_POST['Files'];
         $tmps = CUploadedFile::getInstancesByName('Files');
         // proceed if the images have been set
         if (isset($tmps) && count($tmps) > 0) {
             Yii::log('saved', 'info', 'app');
             // go through each uploaded image
             $configPath = Yii::app()->user->settings["company.path"];
             foreach ($tmps as $image => $pic) {
                 $img_add = new Files();
                 $img_add->name = $pic->name;
                 //it might be $img_add->name for you, filename is just what I chose to call it in my model
                 $img_add->path = "files/";
                 $img_add->parent_type = get_class($this);
                 $img_add->parent_id = $this->id;
                 // this links your picture model to the main model (like your user, or profile model)
                 $img_add->save();
                 // DONE
                 if ($pic->saveAs($img_add->getFullFilePath())) {
                     // add it to the main model now
                 } else {
                     echo 'Cannot upload!';
                 }
             }
             if (isset($_FILES)) {
                 Yii::log(print_r($_FILES, true), 'info', 'app');
                 unset($_FILES);
                 $tmps = CUploadedFile::reset();
             }
             //}
         }
     }
     //endFile
     return $a;
 }
Beispiel #12
0
 public function save($runValidation = true, $attributes = NULL)
 {
     //adam:
     if ($this->eavType == 'boolean') {
         if ($this->value == '1') {
             $this->value = 'true';
         } else {
             $this->value = 'false';
         }
     } else {
         if ($this->eavType == 'file') {
             $configPath = Yii::app()->user->getSetting("company.path");
             $a = CUploadedFile::getInstanceByName('Settings[' . $this->id . '][value]');
             if ($a) {
                 //exit;
                 $this->value = $a;
                 $ext = $this->value->extensionName;
                 //$fileName = $yiiBasepath."/files/".$configPath."/settings/".$this->id.".".$ext;
                 //echo $this->id.get_class($this);
                 $logo = new Files();
                 $logo->name = $this->id . "." . $ext;
                 //it might be $img_add->name for you, filename is just what I chose to call it in my model
                 $logo->path = "settings/";
                 $logo->parent_type = get_class($this);
                 $logo->parent_id = $this->id;
                 // this links your picture model to the main model (like your user, or profile model)
                 $logo->public = true;
                 $id = $logo->save();
                 // DONE
                 //echo $logo->id;
                 //Yii::app()->end();
                 if ($this->value->saveAs($logo->getFullFilePath())) {
                     $this->value = $logo->hash;
                     //"/files/".$configPath."/settings/".$this->id.".".$ext;
                 }
                 //Yii::app()->end();
             }
         }
     }
     return parent::save($runValidation, $attributes);
 }
Beispiel #13
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postStore()
 {
     if (Session::get('user_level') < Config::get('cms.addFile')) {
         return Redirect::to(_l(URL::action('AdminHomeController@getIndex')))->with('message', Lang::get('admin.notPermitted'))->with('notif', 'warning');
     }
     $rules = array('description' => 'Required', 'url' => 'Required', 'title' => 'Required');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to(_l(URL::action('FileController@getCreate') . '/' . Input::get('newsId')))->withErrors($validator)->withInput();
     } else {
         try {
             $news = News::findOrFail(Input::get('newsId'));
             $file = new Files();
             if (Input::get('createdAt')) {
                 $file->created_at = date("Y-m-d H:i:s", strtotime(Input::get('createdAt')));
             } else {
                 $file->created_at = date("Y-m-d H:i:s", strtotime('now'));
             }
             $file->description = Input::get('description');
             $file->published = Input::get('published');
             $file->user_id = Session::get('id');
             $file->url = Input::get('url');
             $file->news_id = Input::get('newsId');
             $file->title = Input::get('title');
             $file->save();
             return Redirect::to(_l(URL::action('FileController@getEdit') . "/" . $file->id))->with('message', Lang::get('admin.fileSaved'))->with('notif', 'success');
         } catch (Exception $e) {
             return Redirect::to(_l(URL::action('FileController@getIndex')))->with('message', Lang::get('admin.noSuchFile'))->with('notif', 'danger');
         }
     }
 }
 function actionIndex()
 {
     $this->_pathway->addStep('素材上载');
     if ($this->_context->isPOST()) {
         if (isset($_POST["PHPSESSID"])) {
             session_id($_POST["PHPSESSID"]);
         }
         if (!isset($_FILES["filedata"]) || !is_uploaded_file($_FILES["filedata"]["tmp_name"]) || $_FILES["filedata"]["error"] != 0) {
             return '上传失败!';
         }
         $filePath = rtrim(Q::ini('appini/upload/filePath'), '/\\') . DS;
         Helper_Filesys::mkdirs($filePath);
         //获得上传文件夹
         $dir = 'data1';
         $i = 0;
         $handle = opendir($filePath);
         while ($name = readdir($handle)) {
             if ($name != "." && $name != "..") {
                 if (is_dir($filePath . $name) && substr($name, 0, 4) == 'data') {
                     $i++;
                     $dir = $name;
                 }
             }
         }
         closedir($handle);
         if ($i == 0) {
             Helper_Filesys::mkdirs($filePath . $dir);
         }
         //判断文件中的文件是否超出限制
         $j = 0;
         $handle = opendir($filePath . $dir);
         while ($name = readdir($handle)) {
             if ($name != "." && $name != "..") {
                 $j++;
             }
         }
         closedir($handle);
         if ($j > 65535) {
             $dir = 'data' . ($i + 1);
         }
         //得到编码后的文件夹及文件名
         $fileNameMd5 = md5($_FILES["filedata"]["name"] . '-' . microtime(true));
         $filePath .= $dir . DS . $fileNameMd5 . DS;
         //保存路径名
         $fileName = md5_file($_FILES["filedata"]["tmp_name"]);
         //文件名
         $fileExt = pathinfo($_FILES["filedata"]["name"], PATHINFO_EXTENSION);
         //扩展名
         //保存到数据库
         $file = new Files();
         $file->category_id = $this->_context->category_id;
         $file->category_name = $this->_context->category_name;
         $file->title = substr($_FILES["filedata"]["name"], 0, strrpos($_FILES["filedata"]["name"], '.'));
         $file->name = $fileName;
         $file->ext = $fileExt;
         $file->size = $_FILES["filedata"]["size"];
         $file->path = $filePath;
         $file->status = 0;
         $file->catalog_info = '';
         $file->upload_username = $this->_view['currentUser']['username'];
         $file->upload_at = time();
         try {
             $file->save();
         } catch (QDB_ActiveRecord_ValidateFailedException $ex) {
             if (isset($ex->validate_errors['name'])) {
                 return $ex->validate_errors['name'];
             } else {
                 if (isset($ex->validate_errors['type'])) {
                     return $ex->validate_errors['type'];
                 } else {
                     return '上传失败!' . $ex;
                 }
             }
         }
         //保存上传文件
         Helper_Filesys::mkdirs($filePath);
         if (!move_uploaded_file($_FILES["filedata"]["tmp_name"], $filePath . $fileName . '.' . $fileExt)) {
             $file->destroy();
             //保存文件失败回滚数据
             return '上传失败!';
         }
         //返回成功结果
         return 'true_' . url('admin::filecatalog/preview', array('id' => $file->id()));
     } else {
         $categoryId = $this->_context->category_id;
         $categoryId = isset($categoryId) ? $categoryId : 1;
         $category = Category::find()->getById($categoryId);
         $this->_view['category'] = $category;
         $categoryIds = Category::getChildrenIds($categoryId);
         if (count($categoryIds)) {
             //获得历史上传
             $files = Files::find('category_id in (?) and upload_username=?', $categoryIds, $this->_view['currentUser']['username'])->order('upload_at desc')->top(13)->getAll();
             $this->_view['files'] = $files;
         }
     }
 }
 public function actionUpload($id)
 {
     //$id=Yii::app()->user->id;
     Yii::import("ext.Upload.qqFileUploader2");
     $folder = Yii::getPathOfAlias('webroot') . '/users/' . Yii::app()->user->id . '/';
     // folder for uploaded files
     $allowedExtensions = array("jpg", "jpeg", "gif", "png");
     //array("jpg","jpeg","gif","exe","mov" and etc...
     $sizeLimit = 8 * 1024 * 1024;
     // maximum file size in bytes
     $uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
     $result = $uploader->handleUpload($folder);
     $fileSize = filesize($folder . $result['filename']);
     //GETTING FILE SIZE
     $fileName = $result['filename'];
     //GETTING FILE NAME
     //$img = CUploadedFile::getInstance($model,'image');
     $ih = new CImageHandler();
     $ih->load($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/' . $fileName)->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/' . $fileName)->reload()->adaptiveThumb(350, 232)->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/avto350_' . $fileName)->reload()->resize(304, 202)->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/avto304_' . $fileName);
     Yii::import("application.modules.my.models.Files");
     $mFile = new Files();
     $mFile->uid = Yii::app()->user->id;
     $mFile->file = $fileName;
     $mFile->type = 'photo';
     $mFile->portfolio_id = $id;
     $mFile->source = 'avto';
     if ($mFile->save()) {
         //unlink($_SERVER['DOCUMENT_ROOT'] . '/users/'.Yii::app()->user->id.'/'.$fileName);
         $result['res'] = $mFile->id;
     }
     $return = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
     echo $return;
     // it's array
     //echo $ret;
 }
 public function actionAddvideo()
 {
     $mFile = new Files();
     $mFile->uid = Yii::app()->user->id;
     $mFile->file = $_POST['video'];
     $mFile->type = 'video';
     $mFile->source = 'portfolio';
     $mFile->portfolio_id = $_POST['portfolio_id'];
     $str = parse_url($_POST['video']);
     //print_r($str);
     $path = explode('/', $str['path']);
     if ($str['host'] == 'youtu.be' || $str['host'] == 'www.youtube.com') {
         if ($str['host'] == 'youtu.be') {
             $code = $path[1];
         } elseif ($str['host'] == 'www.youtube.com') {
             $code = substr($str['query'], 2, 20);
         }
         $image = 'http://img.youtube.com/vi/' . $code . '/0.jpg';
     } elseif ($str['host'] == 'vimeo.com') {
         if (isset($path[3])) {
             $code = $path[3];
         } else {
             $code = $path[1];
         }
         if ($xml = simplexml_load_file('http://vimeo.com/api/v2/video/' . $code . '.xml')) {
             //$image = $xml->video->thumbnail_large ? (string) $xml->video->thumbnail_large: (string) $xml->video->thumbnail_medium;
             $image = $xml->video->thumbnail_medium;
         }
     }
     $ih = new CImageHandler();
     $ih->load($image)->adaptiveThumb(272, 162)->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/video_' . $code . '.jpg');
     //$mFile->picture='video_'.$code;
     if ($mFile->save()) {
         $this->redirect($_POST['back']);
     }
 }
Beispiel #17
0
 public function mUpload($name)
 {
     //资源根目录
     $dir_root_url = Yii::app()->getBaseUrl(true) . $this->dir_base;
     if (empty($_FILES[$name])) {
         $this->error = '无文件上传';
         return false;
     }
     $file = $_FILES[$name];
     if (!is_array($_FILES[$name]['name'])) {
         if (!empty($file["error"])) {
             $err = $this->uploadError($file["error"]);
             $this->error = $err;
             return false;
         }
         $hash_name = md5_file($file["tmp_name"]);
         $file_exts = explode('.', $file['name']);
         $file_ext = strtolower(end($file_exts));
         $dir = $this->getDir($hash_name);
         //查询是否已经存在该资源
         $criteria = new CDbCriteria();
         $criteria->addCondition('hash_code = "' . $hash_name . '"');
         $model = Files::model()->find($criteria);
         if (empty($model)) {
             //echo $dir;
             if (!file_exists($dir)) {
                 mkdir($dir, 0755, true);
             }
             if (move_uploaded_file($file["tmp_name"], $dir . '/' . $hash_name)) {
                 $model = new Files();
                 $model->file_name = $file['name'];
                 $model->file_type = $file['type'];
                 $model->file_size = $file['size'];
                 $model->file_extension = $file_ext;
                 $model->hash_code = $hash_name;
                 $model->ctime = time();
                 $model->save();
             }
         }
         //var_dump($model);
         //$result = $model->getAttributes();
         $result[0]['id'] = $model->id;
         $result[0]['hash'] = $model->hash_code;
         $result[0]['name'] = $model->file_name;
         $result[0]['size'] = $model->file_size;
         $result[0]['type'] = $model->file_type;
         $result[0]['extension'] = $model->file_extension;
     } else {
         for ($i = 0; $i < count($file['name']); $i++) {
             if (!empty($file["error"][$i])) {
                 $err = $this->uploadError($file["error"][$i]);
                 $this->error = $err;
                 return false;
             }
             $hash_name = md5_file($file["tmp_name"][$i]);
             $file_exts = explode('.', $file['name'][$i]);
             $file_ext = strtolower(end($file_exts));
             $dir = $this->getDir($hash_name);
             //查询是否已经存在该资源
             $criteria = new CDbCriteria();
             $criteria->addCondition('hash_code = "' . $hash_name . '"');
             $model = Files::model()->find($criteria);
             if (empty($model)) {
                 //echo $dir;
                 if (!file_exists($dir)) {
                     mkdir($dir, 0755, true);
                 }
                 if (move_uploaded_file($file["tmp_name"][$i], $dir . '/' . $hash_name)) {
                     $model = new Files();
                     $model->file_name = $file['name'][$i];
                     $model->file_type = $file['type'][$i];
                     $model->file_size = $file['size'][$i];
                     $model->file_extension = $file_ext;
                     $model->hash_code = $hash_name;
                     $model->ctime = time();
                     $model->save();
                 }
             }
             //var_dump($model);
             //$result = $model->getAttributes();
             $result[$i]['id'] = $model->id;
             $result[$i]['hash'] = $model->hash_code;
             $result[$i]['name'] = $model->file_name;
             $result[$i]['size'] = $model->file_size;
             $result[$i]['type'] = $model->file_type;
             $result[$i]['extension'] = $model->file_extension;
         }
         //pclose(popen("/home/xinchen/backend.php &", 'r'));
     }
     return $result;
 }
Beispiel #18
0
 /**
  * Uploads a file
  *
  */
 public static function upload($file, $parentId, $parentType, $userId)
 {
     try {
         if ($parentType == 'project') {
             $folder = \Project::where('id', '=', $parentId)->get(array('project_name', 'folder'));
             $destinationPath = 'assets/uploads/projects/' . $folder[0]['folder'] . '/';
             $filename = $file->getClientOriginalName();
             $bytes = $file->getSize();
             $size = static::formatSizeUnits($bytes);
             $filemd5 = md5($filename . new \ExpressiveDate() . time());
             $extension = $file->getClientOriginalExtension();
             $newfilename = $filemd5 . ".{$extension}";
             $fileObj = new \Files();
             $fileObj->file_name = $filename;
             $fileObj->size = $size;
             $fileObj->file_sys_ref = $destinationPath;
             $fileObj->uploaded_by = $userId;
             $fileObj->uploaded_date = date('Y-m-d H:i:s');
             $fileObj->file_md5 = $newfilename;
             $fileObj->key = $filemd5;
             $fileObj->save();
             $fileref_id = $fileObj->id;
             $fileref = new \Fileref();
             $fileref->attachment_id = $fileref_id;
             $fileref->parent_id = $parentId;
             $fileref->parent_type = 'project';
             $fileref->save();
             $upload_success = \Input::file('file')->move($destinationPath, $newfilename);
             return \Response::json('success', 200);
         }
         if ($parentType == 'task') {
             $folder = \Task::where('id', '=', $parentId)->get(array('name', 'folder'));
             $destinationPath = 'assets/uploads/tasks/' . $folder[0]['folder'] . '/';
             $filename = $file->getClientOriginalName();
             $bytes = $file->getSize();
             $size = static::formatSizeUnits($bytes);
             $filemd5 = md5($filename . new \ExpressiveDate() . time());
             $extension = $file->getClientOriginalExtension();
             $newfilename = $filemd5 . ".{$extension}";
             $fileObj = new \Files();
             $fileObj->file_name = $filename;
             $fileObj->size = $size;
             $fileObj->file_sys_ref = $destinationPath;
             $fileObj->uploaded_by = $userId;
             $fileObj->uploaded_date = date('Y-m-d H:i:s');
             $fileObj->file_md5 = $newfilename;
             $fileObj->key = $filemd5;
             $fileObj->save();
             $fileref_id = $fileObj->id;
             $fileref = new \Fileref();
             $fileref->attachment_id = $fileref_id;
             $fileref->parent_id = $parentId;
             $fileref->parent_type = 'task';
             $fileref->save();
             $upload_success = \Input::file('file')->move($destinationPath, $newfilename);
             return \Response::json('success', 200);
         }
     } catch (Exception $e) {
         Log::error('Something went Wrong in Fileupload Class - upload():' . $e->getMessage());
         return \Response::json('error', 400);
     }
 }
 public static function postCourseFiles($id, $course, $idContent)
 {
     $titles = Input::get('titles');
     $inscription = Inscriptions::hasInscription(Auth::user()->user()->id, $course->id);
     $filenumber = count($inscription->files);
     $listedFiles = $inscription->listedFiles();
     $positions = self::positionNulled($listedFiles);
     $count = 0;
     $listedCounter = 0;
     /*if($filenumber<=0):
     			$filenumber = 0;
     			$counttitle = -1;
     		elseif($filenumber<=2):
     			$counttitle = 0;
     		elseif($filenumber <=4):
     			$counttitle = 1;
     		else:
     			$counttitle = 2;
     		endif;*/
     /*var_dump(Input::file('files'));
     		var_dump($filenumber.' - '.$counttitle );*/
     if (Input::file('files') != null) {
         foreach (Input::file('files') as $file) {
             // var_dump("File: ".$count);
             if ($file != null) {
                 // $counttitle = null;
                 // $position = null;
                 /*var_dump('count: '.$count);
                 		if(count($listedFiles) > $filenumber ):
                 			var_dump('listedFiles '.count($listedFiles).' > '.$filenumber.' filenumber');
                 			$temp = -1;
                 			for($i = 0 ; $i <= count($listedFiles) ; $i++):
                 				var_dump("FOR i: ".$i.' to '.(count($listedFiles)-1));
                 				if($listedFiles[$i] == null):
                 					$temp++;
                 					var_dump(" - IF1 temp: ".$temp.' and listedCounter: '.$listedCounter);
                 					if($listedCounter==$temp):
                 						var_dump(" - - IF2 :O listedCounter ".$listedCounter.' == '. $temp.' temp');
                 						$position = $i;
                 					endif;
                 				endif;
                 			endfor;
                 		else:
                 			$position = $filenumber;
                 		endif;*/
                 // var_dump('position: '.$positions[$count]);
                 /*for($i = 0 ; $i <= $count ; $i++):
                 			if($i==$count):
                 				if($listedFiles[$i] == null ):
                 					$filenumber = $count;
                 				endif;
                 				$filenumber = $count;
                 			endif;
                 		endfor;*/
                 switch ($positions[$count]) {
                     case 0:
                     case 1:
                         $counttitle = 0;
                         break;
                     case 2:
                     case 3:
                         $counttitle = 1;
                         break;
                     case 4:
                     case 5:
                         $counttitle = 2;
                         break;
                     default:
                         $counttitle = 2;
                         break;
                 }
                 // var_dump($file);
                 //dd($filenumber.' - '.$counttitle);
                 $url = $file->getRealPath();
                 $extension = $file->getClientOriginalExtension();
                 // str_replace(' ', '',str_replace('/', '-', strtolower($titles[$counttitle])))
                 $name = str_replace(' ', '', strtolower(Auth::user()->user()->id)) . '-' . ($positions[$count] + 1) . '-' . date('YmdHis') . rand(2, 1024 * 512) . '.' . $extension;
                 $size = $file->getSize();
                 $mime = $file->getMimeType();
                 $file->move(public_path('uploads/files/'), $name);
                 $inscription = Inscriptions::hasInscription(Auth::user()->user()->id, $course->id);
                 $my_file = new Files();
                 $my_file->title = $titles[$counttitle] . ' - ' . ($positions[$count] + 1);
                 $my_file->id_course = $course->id;
                 $my_file->id_user = Auth::user()->user()->id;
                 $my_file->id_inscription = $inscription->id;
                 $my_file->url = '/uploads/files/' . $name;
                 $my_file->size = $size;
                 $my_file->mime = $mime;
                 $my_file->status = 'draft';
                 $my_file->save();
                 // var_dump($my_file);
             }
             $count++;
             $listedCounter++;
         }
     }
     // dd($listedFiles);
     $array = array('course' => $course, 'contents' => self::getOrderedContent($course->coursesections));
     return Redirect::to($course->route . '/trabalhosactualizacao')->with($array);
 }
Beispiel #20
0
$ADK_MESSAGE->sanitize();
if ($ADK_MESSAGE->wasdraft && !$ADK_MESSAGE->isdraft) {
    $ADK_MESSAGE->sendDraft($con);
} else {
    if ($ADK_MESSAGE->wasdraft && $ADK_MESSAGE->isdraft) {
        $ADK_MESSAGE->updateDraft($con);
    } else {
        $ADK_MESSAGE->save($con);
    }
}
$ADK_MESSAGE->get($con);
if (!$ADK_MESSAGE->isdraft) {
    $notification = '?m=s';
    $ADK_USER = new User();
    $ADK_USER->id = $ADK_MESSAGE->toid;
    $ADK_USER->get($con);
    sendPMNotifyEmail($ADK_MESSAGE, $ADK_USER);
}
//$replyFileIDs = explode(',', $_POST['replyfileids']);
//if(count($replyFileIDs) > 0 && $replyFileIDs[0] != '')
//    addMessageFileJcts($con, $ADK_MESSAGE['ADK_MESSAGE_ID'], $replyFileIDs);
if (count($ADK_FILES->files) > 0) {
    $ADK_FILES->save($con);
    $ADK_MESSAGE->addFiles($con, $ADK_FILES->fileIDs);
}
if ($_SESSION['ADK_USERGROUP_CDE'] === 'HIK') {
    require_once 'classes/Hiker.php';
    Hiker::updateLastActive($con, intval($_SESSION['ADK_USER_ID']));
}
$con->close();
header('Location: ../messages' . $notification);
Beispiel #21
0
 public static function pdfDoc($model)
 {
     $yiiBasepath = Yii::app()->basePath;
     $yiiUser = Yii::app()->user->id;
     //$configPath = Yii::app()->user->settings["company.path"];
     $user = User::model()->findByPk($yiiUser);
     if (!$user->hasCert()) {
         //create new
         $settings = array('commonName' => $user->username, 'emailAddress' => $user->email);
         if (Yii::app()->user->settings['company.en.city'] != '') {
             $settings['localityName'] = Yii::app()->user->settings['company.en.city'];
         }
         if (Yii::app()->user->settings['company.en.name'] != '') {
             $settings['organizationName'] = Yii::app()->user->settings['company.en.name'];
         }
         $ssl = new SSLHelper($settings);
         $filename = $user->getCertFilePath();
         $user->certpasswd = $ssl->createUserCert($filename);
         $user->save();
     }
     $configCertpasswd = Yii::app()->user->User->getCertPasswd();
     $name = $model->docType->name . "-" . "{$model->docnum}.pdf";
     $file = PrintDoc::findFile($model, $name);
     if (!$file) {
         $model->preview = 2;
         $docfile = PrintDoc::printMe($model);
         $mPDF1 = Yii::app()->ePdf->mpdf();
         $mPDF1->WriteHTML($docfile);
         $file = new Files();
         $file->name = $name;
         $file->path = "docs/";
         $file->parent_type = get_class($model);
         $file->parent_id = $model->id;
         $file->hidden = 1;
         $file->save();
         $file->writeFile($mPDF1->Output("bla", "S"));
     }
     $name = $model->docType->name . "-" . "{$model->docnum}-signed.pdf";
     $doc_file = PrintDoc::findFile($model, $name);
     if (!$doc_file) {
         //'digi';//
         $cerfile = User::getCertFilePath($yiiUser);
         spl_autoload_unregister(array('YiiBase', 'autoload'));
         $oldpath = get_include_path();
         set_include_path($yiiBasepath . '/modules/zend_pdf_certificate/');
         include_once 'Pdf.php';
         include_once 'ElementRaw.php';
         //loads a sample PDF file
         $pdf = Farit_Pdf::load($file->getFullFilePath());
         if (file_exists($cerfile)) {
             $certificate = file_get_contents($cerfile);
             if (empty($certificate)) {
                 set_include_path($oldpath);
                 spl_autoload_register(array('YiiBase', 'autoload'));
                 throw new CHttpException('Cannot open the certificate file');
             }
             //throw new Exception('Uncaught Exception');
             $pdf->attachDigitalCertificate($certificate, $configCertpasswd);
             //restore_exception_handler();
             $docfile = $pdf->render();
             set_include_path($oldpath);
             spl_autoload_register(array('YiiBase', 'autoload'));
             $doc_file = new Files();
             $doc_file->name = $name;
             $doc_file->path = "docs/";
             $doc_file->parent_type = get_class($model);
             $doc_file->parent_id = $model->id;
             $doc_file->public = true;
             $doc_file->save();
             $doc_file->writeFile($docfile);
         } else {
             set_include_path($oldpath);
             spl_autoload_register(array('YiiBase', 'autoload'));
             $link = "";
             $text = Yii::t('app', "Error! <br />\nIt is not possible to create a digitally signed PDF file and/or send it by mail without having certificate file located at current users' configuration page.\nYou should make a certificate file with third party software and import it through 'certificate file' field, separately for each user, within configuration zone of the user. You also should input the password for the certificate file in 'password for digital signature certificate' field in the above mentioned user configuration page.\nYou can find instructions for making self signed certificate file with Acrobat reader (One of the options. There are many applications able to make such a certificate out there)  here: ");
             throw new CHttpException(404, $text);
             //Yii::app()->end();
         }
     }
     return $doc_file;
 }
 public function actionAddvideo()
 {
     $mFile = new Files();
     $mFile->uid = Yii::app()->user->id;
     $mFile->file = $_POST['video'];
     $mFile->type = 'video';
     $mFile->source = 'portfolio';
     if ($mFile->save()) {
         $this->redirect('/my/portfolio/video');
     }
 }
Beispiel #23
0
 public function imageUpload($module_name, $width, $height, $resize, $compare_width, $compare_height, $with_album = false, $album_id = null)
 {
     Yii::import("ext.EAjaxUpload.qqFileUploader");
     $result = false;
     try {
         $uploader = new qqFileUploader(array("jpg", "jpeg", "gif", "png", "bmp"), 8 * 1024 * 1024);
         $upload_folder = $this->getUploadFolder($module_name);
         $result = $uploader->handleUpload($upload_folder);
         if (isset($result["error"]) && strlen($result["error"]) > 0) {
             throw new Exception("Не удаётся загрузить файл.");
         } else {
             $image_path = $upload_folder . $result["filename"];
             $thumb = Yii::app()->thumb->create($image_path);
             if ($resize) {
                 $thumb->resize($width, $height);
                 $thumb->save($image_path);
             } else {
                 list($current_width, $current_height) = getimagesize($image_path);
                 if ($this->resolutionCompare($current_width, $width, $compare_width) || $this->resolutionCompare($current_height, $height, $compare_height)) {
                     $result = array('error' => 'Upload image resolution is incorrect !');
                 }
             }
             if (!isset($result["error"])) {
                 $model = new Files();
                 $model->file_name = $result["filename"];
                 $model->temp = 1;
                 $model->module = $module_name;
                 $model->save();
                 if ($with_album) {
                     if (is_null($album_id)) {
                         $album_id = ModuleGalleryAlbums::model()->createAlbum($module_name);
                         Yii::app()->session->add('album_id', $album_id);
                     }
                     $photo_id = ModuleGalleryPhotos::model()->createPhoto($album_id, $model->id);
                 }
                 $result["image_id"] = $model->id;
                 $result["album_id"] = $album_id;
                 if (isset($photo_id)) {
                     $result["photo_id"] = $photo_id;
                 }
             }
         }
     } catch (Exception $e) {
         $result = array('error' => $result["filename"]);
     }
     return $result;
 }
Beispiel #24
0
 public function saveFile($key, &$filedata, &$postdata)
 {
     $subject = isset($postdata[$key . 'subject']) ? $postdata[$key . 'subject'] : '';
     $note = isset($postdata[$key . 'note']) ? $postdata[$key . 'note'] : '';
     $file = new Files();
     if ($file_id = $file->save($filedata, $this->folder, $subject, $note, $key)) {
         self::$dbh->query('INSERT INTO article_file (file_id, article_id) VALUES (?, ?)', array($file_id, $this->id));
         return true;
     } else {
         return false;
     }
 }
        $sql = "SELECT * FROM files WHERE applicant_id=" . $session->applicant_id . " AND caption='Document " . $counter . "'";
        $result = Files::find_by_sql($sql);
        $result = array_shift($result);
        $document = new Files();
        $document->upload_dir = $upload_dir;
        if (!empty($result->file_id) && !empty($value['name'])) {
            $document->file_id = $result->file_id;
            unlink(SITE_ROOT . DS . $document->upload_dir . DS . $result->filename);
        }
        $filedetails = explode('.', $value['name']);
        $extension = $filedetails[sizeof($filedetails) - 1];
        $value['name'] = $session->applicant_id . '-Document-' . $counter . '.' . $extension;
        if ($document->attach_file($value)) {
            $document->caption = 'Document ' . $counter;
            $document->applicant_id = $session->applicant_id;
            if ($document->save()) {
                $document_upload_msg = 1;
            }
        } else {
            sleep(2);
            echo "<table>";
            echo '<h4 class="alert alert-error"><i class="iconic-o-x" style="color: red"></i> Error!</h4>';
            echo '<hr>';
            echo "<tr><td>You attached an incorrect file, please ensure that the document you are uploading is in pdf format.<br>Also ensure that each file is not more than 2MB</td></tr>";
            echo "</table>";
        }
    } else {
        $empty_file_msg += $counter;
    }
    $counter++;
}
Beispiel #26
0
 public function backup()
 {
     $folder = $this->getFilePath($this);
     $file = $folder . "db.sql";
     $dumper = new dbMaster();
     $handle = fopen($file, 'w');
     fwrite($handle, $dumper->getDump(false, $this->prefix));
     fclose($handle);
     Zipper::zip($folder, $folder . "tenant.zip", "backup");
     $file = new Files();
     $file->name = date("d-m-Y_H_i") . ".zip";
     $file->path = 'backup' . DIRECTORY_SEPARATOR;
     $file->save();
     if (!is_dir($folder . $file->path)) {
         mkdir($folder . $file->path);
     }
     rename($folder . "tenant.zip", $folder . $file->path . $file->id);
     return true;
 }
     foreach ($result_thesis_upload_file as $row) {
         $thesis_file_id = $row->file_id;
         $thesis_filename = $row->filename;
     }
     $files->upload_dir = "documents" . DS . "thesis";
     if (!empty($thesis_file_id) && !empty($_FILES['attach_thesis_proposal']['name'])) {
         $files->file_id = $thesis_file_id;
         unlink(SITE_ROOT . DS . "documents" . DS . "thesis" . DS . $thesis_filename);
     }
     $arrayfiledetails = explode('.', $_FILES['attach_thesis_proposal']['name']);
     $extension = $arrayfiledetails[sizeof($arrayfiledetails) - 1];
     $_FILES['attach_thesis_proposal']['name'] = $session->applicant_id . '-thesis.' . $extension;
     if ($files->attach_file($_FILES['attach_thesis_proposal'])) {
         $files->caption = 'Thesis Proposal';
         $files->applicant_id = $session->applicant_id;
         if ($files->save()) {
             $fileuploadmessage = 1;
         } else {
             $fileuploadmessage = 'Thesis not uploaded';
         }
     } else {
         $fileuploadmessage = 'You attached an incorrect file, please ensure that the file is in doc or pdf format';
     }
 }
 $user = new User();
 $user->applicant_id = $session->applicant_id;
 $user->updateProgress('D');
 sleep(2);
 echo '<h4 class="alert alert-success">Success</h4>';
 echo '<hr>';
 echo 'Your thesis details have been saved';
Beispiel #28
0
 private function createMedia($fileName, $filePath)
 {
     $fullFilePath = Yii::getPathOfAlias(Yii::app()->params['filesAlias']) . DIRECTORY_SEPARATOR . $fileName;
     $md5 = md5_file($fullFilePath);
     $getimagesize = getimagesize($fullFilePath);
     $model = new Files();
     //$model->detachBehavior('Upload');
     $model->title = Files::cleanName($fileName, 32);
     $model->originalname = $fileName;
     //$model->type = 1; //P3Media::TYPE_FILE;
     $model->path = $filePath;
     $model->md5 = $md5;
     if (!($mime = $this->_mime_content_type($fullFilePath))) {
         $mime = $getimagesize['mime'];
     }
     $model->mimetype = $mime;
     //$model->info = CJSON::encode(getimagesize($fullFilePath));
     $model->size = filesize($fullFilePath);
     if ($model->save()) {
         if (!is_dir(Yii::getPathOfAlias(Yii::app()->params['filesAlias']) . DIRECTORY_SEPARATOR . $model->id)) {
             mkdir(Yii::getPathOfAlias(Yii::app()->params['filesAlias']) . DIRECTORY_SEPARATOR . $model->id . '/');
         }
         rename($fullFilePath, Yii::getPathOfAlias(Yii::app()->params['filesAlias']) . DIRECTORY_SEPARATOR . $model->id . DIRECTORY_SEPARATOR . $fileName);
         return $model->attributes;
     } else {
         $errorMessage = "";
         foreach ($model->errors as $attrErrors) {
             $errorMessage .= implode(',', $attrErrors);
         }
         throw new CHttpException(500, $errorMessage);
     }
 }
Beispiel #29
0
 public function make()
 {
     $this->id = rand(0, 999999);
     //$this->iniArr=array('b110'=>0,'b100'=>0,'m100'=>0,'c100'=>0,'d100'=>0,'d110'=>0,'d120'=>0,);
     //$this->docArr=array(0=>0,305=>0,300=>0,);
     $bkmv = '';
     //$this->line=1;
     $yiidatetimesec = Yii::app()->locale->getDateFormat('yiidatetimesec');
     $phpdbdatetime = Yii::app()->locale->getDateFormat('phpdbdatetime');
     $from_date = date($phpdbdatetime, CDateTimeParser::parse($this->from_date . ":00", $yiidatetimesec));
     $to_date = date($phpdbdatetime, CDateTimeParser::parse($this->to_date . ":00", $yiidatetimesec));
     //$types=array(3,4,9,11,13,14);
     //accounts
     $criteria = new CDbCriteria();
     $accounts = Accounts::model()->findAll($criteria);
     $record = array('id' => 'B110', 'name' => OpenFormatType::model()->getDesc('B110'), 'count' => 0);
     foreach ($accounts as $account) {
         $this->line++;
         $bkmv .= $account->openfrmt($this->line, $from_date, $to_date);
         $record['count']++;
     }
     $this->iniArr[] = $record;
     //items
     $criteria = new CDbCriteria();
     $items = Item::model()->findAll($criteria);
     $record = array('id' => 'M100', 'name' => OpenFormatType::model()->getDesc('M100'), 'count' => 0);
     foreach ($items as $item) {
         $this->line++;
         $bkmv .= $item->openfrmt($this->line, $from_date, $to_date);
         $record['count']++;
     }
     $this->iniArr[] = $record;
     //
     //transactions
     $criteria = new CDbCriteria();
     $criteria->condition = "valuedate BETWEEN :from_date AND :to_date";
     $criteria->params = array(':from_date' => $from_date, ':to_date' => $to_date);
     $transactions = Transactions::model()->findAll($criteria);
     $record = array('id' => 'B100', 'name' => OpenFormatType::model()->getDesc('B100'), 'count' => 0);
     foreach ($transactions as $transaction) {
         $this->line++;
         $bkmv .= $transaction->openfrmt($this->line, $from_date, $to_date);
         $record['count']++;
     }
     $this->iniArr[] = $record;
     //docs
     $criteria = new CDbCriteria();
     $criteria->condition = "due_date BETWEEN :from_date AND :to_date";
     $criteria->params = array(':from_date' => $from_date, ':to_date' => $to_date);
     $docs = Docs::model()->findAll($criteria);
     //OpenFormatType::model()->getDesc('C100')
     $record = array('id' => 'C100', 'name' => OpenFormatType::model()->getDesc('C100'), 'count' => 0);
     $d110 = array('id' => 'D110', 'name' => OpenFormatType::model()->getDesc('D110'), 'count' => 0);
     $d120 = array('id' => 'D120', 'name' => OpenFormatType::model()->getDesc('D120'), 'count' => 0);
     foreach ($docs as $doc) {
         if ($doc->docType->openformat != '0') {
             $this->line++;
             $bkmv .= $doc->openfrmt($this->line, $from_date, $to_date);
             foreach ($doc->docDetailes as $detial) {
                 $this->line++;
                 $bkmv .= $detial->openfrmt($this->line, $from_date, $to_date);
                 $d110['count']++;
             }
             foreach ($doc->docCheques as $detial) {
                 $this->line++;
                 $bkmv .= $detial->openfrmt($this->line, $from_date, $to_date);
                 $d120['count']++;
             }
             $type = $doc->getType();
             $this->docArr[$type] = isset($this->docArr[$type]) ? $this->docArr[$type] + 1 : 0;
             $this->docSumArr[$type] = isset($this->docSumArr[$type]) ? $this->docSumArr[$type] + $doc->total : $doc->total;
             $record['count']++;
         }
     }
     $this->iniArr[] = $record;
     $this->iniArr[] = $d110;
     $this->iniArr[] = $d120;
     $company = Settings::model()->findByPk('company.name');
     //A100
     $bkmv = $company->a100(1, $this->id) . $bkmv;
     //Z900
     $bkmv = $bkmv . $company->z900($this->line + 1, $this->id, $this->line + 1);
     $bkmvFile = new Files();
     $bkmvFile->name = 'bkmvdata.txt';
     $bkmvFile->path = 'openformat/';
     //
     $bkmvFile->expire = 360;
     $bkmvFile->save();
     $bkmvFile->writeFile($bkmv);
     $this->bkmvId = $bkmvFile->id;
     //A000
     $ini = $company->a000(1, $this->id, $this->line + 1);
     foreach ($this->iniArr as $line) {
         $ini .= $line['id'] . sprintf("%015d", $line['count']) . "\r\n";
     }
     //Z
     $iniFile = new Files();
     $iniFile->name = 'ini.txt';
     $iniFile->path = 'openformat/';
     //
     $iniFile->expire = 360;
     $iniFile->save();
     $iniFile->writeFile($ini);
     $this->iniId = $iniFile->id;
     return $this->id;
 }
Beispiel #30
0
 public function productXmlAdd($product)
 {
     $model = new ModuleCatalogProduct();
     $album_id = false;
     foreach ($product as $key => $value) {
         if ($key == 'Ид') {
             $model->xml_id = $value;
         } else {
             if ($key == 'Наименование') {
                 $model->name = $value;
             } else {
                 if ($key == 'БазоваяЕдиница') {
                     $model->unit = $value;
                 } else {
                     if ($key == 'Картинка') {
                         if (!is_array($value)) {
                             $value = array($value);
                         }
                         foreach ($value as $value_img) {
                             $name = explode('\\', $value_img);
                             $src = $_SERVER['DOCUMENT_ROOT'] . '/upload/xml/extract/e' . str_replace('\\', '//', $value_img);
                             $folder = $_SERVER['DOCUMENT_ROOT'] . '/' . Files::model()->getUploadFolder('catalog', true, true);
                             if (count($name) - 1 > 0 && file_exists($src) && $name[count($name) - 1] != 'www.eldorado.ru') {
                                 $thumb = Yii::app()->thumb->create($src);
                                 $iname = explode('.', $name[count($name) - 1]);
                                 //&& copy($src, $folder.'/'.$name[count($name) - 1])
                                 if (empty($album_id)) {
                                     $album_id = ModuleGalleryAlbums::model()->createAlbum('catalog');
                                 }
                                 $thumb->resize(320, 340);
                                 $thumb->save($folder . '/' . $iname[count($iname) - 2] . '_large.' . $iname[count($iname) - 1]);
                                 $files = new Files();
                                 $files->file_name = $iname[count($iname) - 2] . '_large.' . $iname[count($iname) - 1];
                                 $files->temp = 1;
                                 $files->save();
                                 ModuleGalleryPhotos::model()->createPhoto($album_id, $files->id);
                                 $thumb->resize(190, 190);
                                 $thumb->save($folder . '/' . $iname[count($iname) - 2] . '_catalog.' . $iname[count($iname) - 1]);
                                 $files = new Files();
                                 $files->file_name = $iname[count($iname) - 2] . '_catalog.' . $iname[count($iname) - 1];
                                 $files->temp = 1;
                                 $files->save();
                                 ModuleGalleryPhotos::model()->createPhoto($album_id, $files->id);
                                 $thumb->resize(100, 100);
                                 $thumb->save($folder . '/' . $iname[count($iname) - 2] . '_small.' . $iname[count($iname) - 1]);
                                 $files = new Files();
                                 $files->file_name = $iname[count($iname) - 2] . '_small.' . $iname[count($iname) - 1];
                                 $files->temp = 1;
                                 $files->save();
                                 ModuleGalleryPhotos::model()->createPhoto($album_id, $files->id);
                             }
                         }
                     } else {
                         if ($key == 'Группы' && is_array($value)) {
                             $value_group = $this->getProductGroupXmlId($value);
                             $category_id = ModuleCatalogCategory::model()->getCategoryIdByXmlCode($value_group);
                             if (!empty($category_id)) {
                                 $model->category_id = $category_id;
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!empty($album_id)) {
         $model->album_id = $album_id;
     }
     if ($model->save() && isset($product["ХарактеристикиТовара"]["ХарактеристикаТовара"])) {
         $this->addProperties($product["ХарактеристикиТовара"]["ХарактеристикаТовара"], $model->id, $product);
     }
 }