|
|
<?php
|
|
|
class reportsController extends ControllerBase{
|
|
|
public function dolist(){
|
|
|
$type = $_GET['ty'];
|
|
|
|
|
|
require("components".DS."com_reports".DS."models".DS."reportsModel.php");
|
|
|
$report = new reportsModel();
|
|
|
|
|
|
$lstReports = $report->dolist($type);
|
|
|
|
|
|
if(count($lstReports) == 0){
|
|
|
$url = "index.php?option=com_reports&controller=reports&action=add&ty=".$type;
|
|
|
header("location: ".$url);
|
|
|
exit(0);
|
|
|
}
|
|
|
|
|
|
$html_title = $this->setTitle($type);
|
|
|
|
|
|
$data["type"] = $type;
|
|
|
$data["lsReports"] = $lstReports;
|
|
|
$data["lsTitle"] = $html_title;
|
|
|
$data["content"] = "components".DS."com_reports".DS."views".DS."dolist.php";
|
|
|
$data["title"] = strtoupper($html_title)."::::::::::::::";
|
|
|
|
|
|
$this->view->show("template.php", $data);
|
|
|
}
|
|
|
|
|
|
public function add(){
|
|
|
$type = $_GET['ty'];
|
|
|
|
|
|
require_once("components".DS."com_areas".DS."models".DS."areasModel.php");
|
|
|
$objAreas = new areasModel();
|
|
|
$lstAreas = $objAreas->dolist();
|
|
|
|
|
|
$html_title = $this->setTitle($type);
|
|
|
|
|
|
$data["type"] = $type;
|
|
|
$data["frm_title"] = $html_title;
|
|
|
$data["lstAreas"] = $lstAreas;
|
|
|
$data["content"] = "components".DS."com_reports".DS."views".DS."form.php";
|
|
|
$data["title"] = "Add Report:::::::::::::";
|
|
|
|
|
|
$this->view->show("template.php", $data);
|
|
|
}
|
|
|
|
|
|
public function save(){
|
|
|
$ty = $_POST['type'];
|
|
|
$area = $_POST['lstArea'];
|
|
|
$title = $_POST['txtTitle'];
|
|
|
$desc = $_POST['description'];
|
|
|
|
|
|
$url = explode(DS, trim(SYS_ROOT));
|
|
|
array_pop($url);
|
|
|
array_pop($url);
|
|
|
$path = implode(DS, $url);
|
|
|
$path = $path.DS."files".DS;
|
|
|
$path_area = $path.DS.$area.DS;
|
|
|
|
|
|
if($_FILES['fpname']['tmp_name'] != ""){
|
|
|
if (is_uploaded_file($_FILES['fpname']['tmp_name'])){
|
|
|
$psize = $_FILES ['fpname']['size'];
|
|
|
$pname = $_FILES ['fpname']['name'];
|
|
|
$man_file = new filesManager($pname);
|
|
|
$type = $man_file->getExtension();
|
|
|
$name_file = $man_file->getName();
|
|
|
|
|
|
if($man_file->isDoc()){
|
|
|
$url_user = $name_file.".".$type;
|
|
|
$date_current = date("YmdHis");
|
|
|
$name_file_system = md5($name_file.$date_current);
|
|
|
$path_final = $name_file_system.".".$type;
|
|
|
$flag_add = false;
|
|
|
if(is_dir($path_area)){
|
|
|
if(is_writable($path)){
|
|
|
copy($_FILES['fpname']['tmp_name'], $path_area.$path_final);
|
|
|
$flag_add = true;
|
|
|
$tipo_msg = 1;
|
|
|
}else{ $message = "No se puede escribir."; }
|
|
|
}else{
|
|
|
mkdir($path_area,0777,true);
|
|
|
copy($_FILES['fpname']['tmp_name'], $path_area.$path_final);
|
|
|
$flag_add = true;
|
|
|
}
|
|
|
if($flag_add){
|
|
|
$message = "Added file";
|
|
|
require("components".DS."com_reports".DS."models".DS."reportsModel.php");
|
|
|
$report = new reportsModel();
|
|
|
|
|
|
$data_sql['idarea'] = $area;
|
|
|
$data_sql['title'] = $title;
|
|
|
$data_sql['description'] = $desc;
|
|
|
$data_sql['url_user'] = $pname;
|
|
|
$data_sql['url_system'] = $path_final;
|
|
|
$data_sql['type'] = $ty;
|
|
|
$data_sql['date_create'] = date("Y-m-d H:i:s");
|
|
|
$data_sql['state'] = 1;
|
|
|
|
|
|
list($query, $id, $message) = $report->addItem($data_sql);
|
|
|
}
|
|
|
}else{
|
|
|
$message .= "Uploaded failed: No file allowed.";
|
|
|
$flu_insertar = false;
|
|
|
$tipo_msg = 2;
|
|
|
}
|
|
|
}else{
|
|
|
// error por tamanio
|
|
|
$message .= "Uploaded failed: size exceeds the limit.";
|
|
|
$flu_insertar = false;
|
|
|
$tipo_msg = 3;
|
|
|
}
|
|
|
}else{
|
|
|
echo "Error: Uploaded failed.";
|
|
|
$flu_insertar = false;
|
|
|
$tipo_msg = 3;
|
|
|
}
|
|
|
|
|
|
$url = "index.php?option=com_reports&controller=reports&action=dolist&ty=".$ty;
|
|
|
|
|
|
header("location: ".$url);
|
|
|
exit (0);
|
|
|
}
|
|
|
|
|
|
public function setTitle($type){
|
|
|
$html_title = "";
|
|
|
|
|
|
switch ($type){
|
|
|
case 1: $html_title = "Lista de Informes";
|
|
|
break;
|
|
|
case 2: $html_title = "Lista de Reportes";
|
|
|
break;
|
|
|
default: $html_title = "Lista de Reportes";
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
return $html_title;
|
|
|
}
|
|
|
}
|
|
|
?>
|