| Server IP : 162.214.74.102 / Your IP : 216.73.217.114 Web Server : Apache System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64 User : lrsys ( 1015) PHP Version : 5.6.40 Disable Function : exec,passthru,shell_exec,system MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/lrsys/www/lrsys_apps/leo/application/plugins/module_imobles/models/ |
Upload File : |
<?php
include_once __DIR__ . "/../../../autoload/My_Model.php";
include_once __DIR__ . "/../factories/DocsFactory.php";
include_once __DIR__ . "/../models/EnterprisesModel.php";
include_once __DIR__ . "/../models/Docs_categoryModel.php";
class DocsModel extends My_Model {
/**
* @var string
*/
public $table = 'module_imobles_docs';
public function createDocs($data) {
$docs = self::create();
DocsFactory::create($data, $docs, true);
$docs->save();
if (isset($data['downloadFile'])){
$fileName = $data['fileName'];
$fileURL = $data['fileURL'];
$this->downloadFile($docs, $fileName, $fileURL);
} else {
$docs = $this->uploadDoc($docs, true);
$this->processCSVPriceTable($docs);
}
return $docs;
}
public function updateDocs($data, $docs) {
ORM::for_table($this->table)->create($docs);
DocsFactory::create($data, $docs);
$docs->save();
$docs = $this->uploadDoc($docs, false);
$this->processCSVPriceTable($docs);
return $docs;
}
private function downloadFile($docs, $fileName, $fileURL){
$file = file_get_contents($fileURL);
if($file){
$dir = 'application/plugins/module_imobles/uploads/docs/' . $docs->id . "/";
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
$parts = explode(".", $fileName);
$ext = strtolower($parts[count($parts)-1]);
$uploadName = "_".substr(md5(rand(1111,9999)),0,8)._raid().time().rand(1111,1000).rand(99,9999).".".$ext;
file_put_contents($dir . "/" . $uploadName, $file);
$docs->src = $uploadName;
$docs->name = $fileName;
$docs->save();
}
}
public function uploadDoc($docs, $remove) {
if ($_FILES['file'] && !empty($_FILES['file']['name'])) {
$uploader = new Uploader();
$dir = 'application/plugins/module_imobles/uploads/docs/' . $docs->id . "/";
$src_old = $docs->src;
$uploader->setDir($dir);
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
$uploader->sameName(false);
// $uploader->setExtensions(array('jpg', 'jpeg', 'png', 'gif','pdf','doc'));
$uploader->allowAllFormats();
$uploader->setMaxSize(20);
if ($uploader->uploadFile('file')) {
$uploaded = $uploader->getUploadName();
$docs->src = $uploaded;
$docs->name = $uploader->getOldName();
$docs->save();
if (!empty($src_old)) {
unlink('application/plugins/module_imobles/uploads/docs/' . $docs->id . "/" . $src_old); //remove
}
} else {//upload failed
if ($remove) {
$docs->delete(); //remove o cadastro para dar o erro na tela
}
$docs->errorFile = $uploader->getMessage();
}
}
return $docs;
}
public function deleteDocs($docs) {
ORM::for_table($this->table)->create($docs);
$now = new DateTime('now', new DateTimeZone('America/Sao_Paulo'));
$user = User::_info();
$docs->delete_at = $now->format('Y-m-d H:i:s');
$docs->delete_by = $user->id;
$docs->save();
return $docs;
}
private function processCSVPriceTable(&$doc){
// Processa o Arquivo CSV se for Documento de Empreendimento, se a extensão for CSV e se a categoria for "CSV TABELA PREÇO"
if($doc->module_imobles_enterprise_id != null){
$ext = strtolower(pathinfo($doc->src, PATHINFO_EXTENSION));
if ($ext == 'csv'){
$docsCategoryModel = new Docs_categoryModel();
$category = $docsCategoryModel->getOne($doc->module_imobles_docs_category_id);
if ($category->alias == "CSV TABELA PREÇO"){
$enterpriseModel = new EnterprisesModel();
$path = 'application/plugins/module_imobles/uploads/docs/' . $doc->id . "/" . $doc->src;
$msg = $enterpriseModel->processCSVPriceTable($doc->module_imobles_enterprise_id, $path);
if (!empty($msg)){
$doc->csv_price_table_message = $msg;
}
}
}
}
}
}