Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
205 righe
7.3 KiB
205 righe
7.3 KiB
<? |
|
|
|
class editorManager { |
|
public $idEditor; |
|
public $vocabolario; |
|
public $exportFormat; |
|
public $exportSize; |
|
private $tipologia; |
|
private $riferimento; |
|
private $ente; |
|
private $db; |
|
|
|
public function __construct($tipologia,$riferimento) { |
|
if (!empty($tipologia) && isset($riferimento) && isset($_SESSION["ente"])) { |
|
global $pdo; |
|
$this->db = $pdo; |
|
$this->vocabolario = self::defaultVocabolario(); |
|
$this->ente = $_SESSION["ente"]->getInfo(); |
|
$this->tipologia = $tipologia; |
|
$this->riferimento = $riferimento; |
|
$this->idEditor = "editorStandard"; |
|
$this->exportFormat = "portrait"; |
|
$this->exportSize = "A4"; |
|
} else { |
|
return false; |
|
} |
|
} |
|
|
|
public static function defaultVocabolario() { |
|
return [ |
|
"linkNormeTecniche" => $_SESSION["config"]["link_sito"]."/norme_tecniche.php", |
|
"linkRegistrazione" => $_SESSION["config"]["link_sito"]."/register.php", |
|
"ente" => $_SESSION["ente"]->getInfo() |
|
]; |
|
} |
|
|
|
public function getIDS() { |
|
$return = ["index"=>0,"content"=>0]; |
|
$index = $this->db->go("SELECT codice FROM b_editor WHERE tipologia = :tipologia AND riferimento = :riferimento AND codice_ente = :codice_ente AND attivo = 'S' ORDER BY codice DESC LIMIT 0,1",[":tipologia"=>$this->tipologia,":riferimento"=>$this->riferimento,":codice_ente"=>$this->ente["codice"]])->fetch(PDO::FETCH_COLUMN); |
|
if (!empty($index)) { |
|
$content = $this->db->go("SELECT codice FROM b_editor_content WHERE codice_riferimento = :index",[":index"=>$index])->fetch(PDO::FETCH_COLUMN); |
|
if (!empty($content)) { |
|
$return = ["index"=>$index,"content"=>$content]; |
|
} |
|
} |
|
return $return; |
|
} |
|
|
|
public function printVersionButton() { |
|
if (count($this->versions()) > 1) { |
|
include(__DIR__."/views/versionButton.php"); |
|
} |
|
} |
|
|
|
public function getContent($codice_riferimento) { |
|
$return = ""; |
|
$content = $this->db->go("SELECT content FROM b_editor_content WHERE codice_riferimento = :codice",[":codice"=>$codice_riferimento])->fetch(PDO::FETCH_COLUMN) ?? null; |
|
if (isset($content)) { |
|
$return = simple_decrypt($content,hash("sha256","editorManager".$codice_riferimento)); |
|
} |
|
return $return; |
|
} |
|
|
|
public function versions($number=NULL) { |
|
$where = ""; |
|
if ($number===0) $where = " AND attivo = 'S' "; |
|
$sql = "SELECT * FROM b_editor WHERE tipologia = :tipologia AND riferimento = :riferimento AND codice_ente = :codice_ente {$where} ORDER BY codice DESC"; |
|
$return = $this->db->go($sql,[":tipologia"=>$this->tipologia,":riferimento"=>$this->riferimento,":codice_ente"=>$this->ente["codice"]])->fetchAll(PDO::FETCH_ASSOC); |
|
if ($number === NULL) { |
|
return $return; |
|
} else if (!empty($return[$number])) { |
|
$return[$number]["content"] = $this->getContent($return[$number]["codice"]); |
|
return $return[$number]; |
|
} |
|
return false; |
|
} |
|
|
|
public static function fixValue($value) { |
|
$return = $value; |
|
if (!is_array($value)) { |
|
if (is_numeric($value)) { |
|
$explode = explode(".",$value); |
|
if (count($explode) > 1) { |
|
$return = number_format($value,2,",","."); |
|
} |
|
} else { |
|
if (preg_match("/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/", $value)) { |
|
$return = mysql2datetime($value); |
|
} |
|
} |
|
} |
|
return $return; |
|
} |
|
|
|
public static function replacePlaceholder($content,$vocabolario) { |
|
if (!empty($vocabolario) && !empty($content)) { |
|
$replace = []; |
|
foreach($vocabolario AS $key => $values) { |
|
if (is_array($values)) { |
|
foreach($values AS $valueKey => $value) { |
|
$value = static::fixValue($value); |
|
$replace["##--{$key}-{$valueKey}--##"] = $value; |
|
} |
|
} else { |
|
$values = static::fixValue($values); |
|
$replace["##--{$key}--##"] = $values; |
|
} |
|
} |
|
$content = strtr($content,$replace); |
|
} |
|
return $content; |
|
} |
|
|
|
public function getModello() { |
|
$sql = "SELECT content FROM b_modelli WHERE attivo = 'S' AND soft_delete = 'N' AND tipologia = :tipologia AND codice_ente = :codice_ente"; |
|
$content = $this->db->go($sql,[":tipologia"=>$this->tipologia,":codice_ente"=>$this->ente["codice"]])->fetch(PDO::FETCH_ASSOC); |
|
$return = false; |
|
if (!empty($content)) { |
|
$return = $content["content"]; |
|
} else { |
|
global $pdo; |
|
$content = $this->db->go($sql,[":tipologia"=>$this->tipologia,":codice_ente"=>0])->fetch(PDO::FETCH_ASSOC); |
|
if (!empty($content)) { $return = $content["content"]; } |
|
} |
|
if (!empty($return)) { |
|
if (!empty($this->ente["logo"])) { |
|
$logo = $_SESSION["config"]["link_sito"]."/documenti/{$this->ente["logo"]}"; |
|
$ente["logo"] = "<img src=\"{$logo}\" width=\"150\" alt=\"".__("logo")."\">"; |
|
} |
|
$return = $this->replacePlaceholder($return,$this->vocabolario); |
|
} |
|
return $return; |
|
} |
|
|
|
public function latest() { |
|
$content = $this->versions(0); |
|
if (!empty($content)) { |
|
$content = $content["content"]; |
|
} |
|
return $content; |
|
} |
|
|
|
public function edit($version=0) { |
|
$content = $this->versions($version)["content"] ?? null; |
|
if (!isset($content)) { |
|
$content = $this->getModello(); |
|
$content = self::replacePlaceholder($content,$this->vocabolario); |
|
} |
|
self::printEditor($content,$this->idEditor,$this->exportFormat,$this->exportSize); |
|
} |
|
|
|
public function delete() { |
|
$return = false; |
|
$ids = $this->getIDS(); |
|
if (!empty($ids["index"])) { |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "b_editor"; |
|
$salva->operazione = "UPDATE"; |
|
$salva->oggetto = ["codice"=>$ids["index"],"attivo"=>"N"]; |
|
$return = $salva->save(); |
|
} |
|
return $return; |
|
} |
|
|
|
public function save($content,$bozza = "N") { |
|
$return = false; |
|
if (!empty($content)) { |
|
$ids = $this->getIDS(); |
|
$object = []; |
|
$object["codice"] = $ids["index"]; |
|
$object["codice_ente"] = $this->ente["codice"]; |
|
$object["tipologia"] = $this->tipologia; |
|
$object["riferimento"] = $this->riferimento; |
|
$object["bozza"] = $bozza; |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "b_editor"; |
|
$salva->operazione = (!empty($ids["index"])) ? "UPDATE":"INSERT"; |
|
$salva->oggetto = $object; |
|
$return = $salva->save(); |
|
if (!empty($return)) { |
|
$object = []; |
|
$object["codice"] = $ids["content"]; |
|
$object["codice_riferimento"] = $return; |
|
$object["content"] = simple_encrypt($content,hash("sha256","editorManager".$return)); |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "b_editor_content"; |
|
$salva->operazione = (!empty($ids["content"])) ? "UPDATE":"INSERT"; |
|
$salva->oggetto = $object; |
|
$salva->save(); |
|
} |
|
} |
|
return $return; |
|
} |
|
|
|
public static function printEditor($content="",$idEditor="editorStandard",$exportFormat = "portrait",$exportSize = "A4") { |
|
include(__DIR__."/form.php"); |
|
} |
|
} |
|
?>
|