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.
496 righe
20 KiB
496 righe
20 KiB
<? |
|
|
|
class publicConcorso extends concorso { |
|
|
|
public $potentialAction; // serve ad identificare se l'utente che ha istanziato l'oggetto può interagire con la concorso |
|
private $managerPartecipazione; |
|
|
|
public static function getList($codice_gestore,$filters=[],$order=["b_concorsi.codice"=>"DESC"],$start=0,$length=1) { |
|
global $pdo; |
|
$bind = []; |
|
$select = "SELECT b_concorsi.codice, b_concorsi.codice_ente, b_concorsi.id, b_concorsi.stato, b_concorsi.prezzoRiferimento, b_concorsi.oggetto, b_concorsi.fase_attiva, b_concorsi_round.numero, |
|
b_concorsi_round.codice AS codice_round, b_concorsi_round.pubblicazione, b_concorsi_round.chiarimenti, b_concorsi_round.scadenza, |
|
GROUP_CONCAT(DISTINCT b_concorsi_lotti.cig) AS cig "; |
|
$from = " FROM b_concorsi JOIN b_concorsi_round ON b_concorsi.codice = b_concorsi_round.codice_concorso AND b_concorsi.fase_attiva = b_concorsi_round.numero |
|
JOIN b_concorsi_lotti ON b_concorsi.codice = b_concorsi_lotti.codice_concorso "; |
|
$where = " WHERE (b_concorsi.fase_attiva > 1 |
|
OR (b_concorsi_round.pubblica = 2 AND b_concorsi_round.pubblicazione <= now()) "; |
|
if (isset($_SESSION["utente"])) { |
|
$where .= " OR (b_concorsi_round.pubblica = 1 AND b_concorsi_round.pubblicazione <= now()) "; |
|
} |
|
$where .= ")"; |
|
if (!empty($filters)) { |
|
$keys = ["b_concorsi.id","b_concorsi.oggetto","b_concorsi_lotti.oggetto","b_concorsi_lotti.cig"]; |
|
$addWhere = []; |
|
foreach($keys AS $key) { |
|
if (isset($filters[$key]) || isset($filters["*"])) { |
|
$value = $filters[$key] ?? $filters["*"]; |
|
$sudd = suddivisione_pdo($value,$key); |
|
if (!empty($sudd)) { |
|
$bind = $bind + $sudd["bind"]; |
|
$addWhere[] = $sudd["sql"]; |
|
} |
|
} |
|
} |
|
|
|
if (count($addWhere) > 0) { $where .= " AND (" . implode(" OR ",$addWhere) . ") "; } |
|
if (isset($filters["b_concorsi.codice_ente"])) { |
|
$bind[":codice_ente"] = (int)$filters["b_concorsi.codice_ente"]; |
|
$where .= " AND b_concorsi.codice_ente = :codice_ente "; |
|
} |
|
if (isset($filters["b_concorsi.stato"])) { |
|
if (is_numeric($filters["b_concorsi.stato"])) { |
|
$bind[":stato"] = (int)$filters["b_concorsi.stato"]; |
|
$where .= " AND b_concorsi.stato = :stato "; |
|
} else if (!empty($_SESSION["utente"]->oe)) { |
|
$stato = $filters["b_concorsi.stato"]; |
|
if ($stato == "bozza") { |
|
$bind[":operatore"] = $_SESSION["utente"]->oe["codice"]; |
|
$from .= " JOIN r_partecipanti_concorsi ON b_concorsi_round.codice = r_partecipanti_concorsi.codice_round "; |
|
$where .= " AND r_partecipanti_concorsi.codice_operatore = :operatore AND b_concorsi_round.scadenza > now() AND r_partecipanti_concorsi.conferma = 'N' "; |
|
} else if ($stato == "aggiudicati") { |
|
$bind[":operatore"] = $_SESSION["utente"]->oe["codice"]; |
|
$from .= " JOIN r_partecipanti_concorsi ON b_concorsi_round.codice = r_partecipanti_concorsi.codice_round "; |
|
$from = str_replace("AND b_concorsi.fase_attiva = b_concorsi_round.numero","",$from); |
|
$where .= " AND r_partecipanti_concorsi.codice_operatore = :operatore AND r_partecipanti_concorsi.aggiudicatario = 'S' AND b_concorsi.stato === 100 "; |
|
} else if ($stato == "archivio") { |
|
$bind[":operatore"] = $_SESSION["utente"]->oe["codice"]; |
|
$from .= " JOIN r_partecipanti_concorsi ON b_concorsi_round.codice = r_partecipanti_concorsi.codice_round "; |
|
$from = str_replace("AND b_concorsi.fase_attiva = b_concorsi_round.numero","",$from); |
|
$where .= " AND r_partecipanti_concorsi.codice_operatore = :operatore AND r_partecipanti_concorsi.conferma = 'S' "; |
|
} |
|
} else { |
|
return []; |
|
} |
|
} |
|
if (isset($filters["b_concorsi.codice"])) { |
|
$bind[":codice"] = (int)$filters["b_concorsi.codice"]; |
|
$where .= " AND b_concorsi.codice = :codice "; |
|
} |
|
} |
|
$sort = "ORDER BY b_concorsi.codice DESC "; |
|
if (!empty($order)) { |
|
$keys = ["b_concorsi.codice","b_concorsi.stato","b_concorsi.oggetto","b_concorsi.prezzoRiferimento","b_concorsi_round.pubblicazione","b_concorsi_round.chiarimenti","b_concorsi_round.numero","b_concorsi_round.scadenza"]; |
|
$sortArray = []; |
|
foreach($keys AS $key) { |
|
if (isset($order[$key])) { |
|
if (strcmp($order[$key],"ASC") === 0) { |
|
$sortArray[] = "{$key} ASC"; |
|
} else { |
|
$sortArray[] = "{$key} DESC"; |
|
} |
|
} |
|
} |
|
if (!empty($sortArray)) { |
|
$sort = " ORDER BY " . implode(",",$sortArray); |
|
} |
|
} |
|
$limit = ""; |
|
if (is_numeric($start) && is_numeric($length) && $length > 0) { |
|
$start = (int)$start; |
|
$length = (int)$length; |
|
$limit = " LIMIT {$start}, {$length}"; |
|
} |
|
$result = $pdo->go($select.$from.$where." GROUP BY b_concorsi.codice ".$sort.$limit,$bind)->fetchAll(PDO::FETCH_ASSOC); |
|
return $result; |
|
} |
|
|
|
private function __construct() { |
|
global $pdo; |
|
$this->db = $pdo; |
|
$this->commissario = false; |
|
$this->potentialAction = false; |
|
$this->managerPartecipazione = null; |
|
} |
|
|
|
public function miaPartecipazione() { |
|
if (isset($_SESSION["utente"]) && $_SESSION["utente"]->gerarchia >= 100 && !empty($_SESSION["utente"]->oe) && !empty($this->lotto)) { |
|
global $config; |
|
$bind = [":codice_round"=>$this->round["codice"]]; |
|
$bind[":codice_operatore"]=$_SESSION["utente"]->oe["codice"]; |
|
$bind[":codice_lotto"]=$this->lotto["codice"]; |
|
$sql = "SELECT * FROM r_partecipanti_concorsi WHERE codice_round = :codice_round AND codice_lotto = :codice_lotto AND codice_operatore = :codice_operatore"; |
|
$return = $this->db->go($sql,$bind)->fetchAll(PDO::FETCH_ASSOC)[0] ?? false; |
|
if (!empty($return)) { |
|
$decrypted = json_decode(simple_decrypt(base64_decode($return["encryptedData"]),$config["simple_encrypt"]["offer"]),true); |
|
$return = array_merge($return,$decrypted); |
|
return $return; |
|
} |
|
return false; |
|
} |
|
} |
|
|
|
public function partecipato($confirmed = null) { |
|
if (isset($_SESSION["utente"]) && $_SESSION["utente"]->gerarchia >= 100 && !empty($_SESSION["utente"]->oe)) { |
|
$bind = [":codice_round"=>$this->round["codice"]]; |
|
$bind[":codice_operatore"]=$_SESSION["utente"]->oe["codice"]; |
|
$sql = "SELECT codice FROM r_partecipanti_concorsi WHERE codice_round = :codice_round AND codice_operatore = :codice_operatore"; |
|
if (isset($confirmed)) { |
|
$sql .= " AND conferma = :conferma "; |
|
$bind[":conferma"] = ($confirmed) ? "S" : "N"; |
|
} |
|
return ($this->db->go($sql,$bind)->rowCount() > 0) ? true : false; |
|
} |
|
} |
|
|
|
public function getRicevuta() { |
|
ob_start(); |
|
include __DIR__."/views/ricevuta.php"; |
|
return ob_get_clean(); |
|
} |
|
|
|
public function listPartecipanti($partecipante=null) { |
|
return parent::listPartecipanti($this->miaPartecipazione()["codice"] ?? false); |
|
} |
|
|
|
public function listPartecipantiSeduta($partecipante=null) { |
|
if ($this->sedutaAperta()) { |
|
return parent::listPartecipanti($partecipante); |
|
} |
|
return false; |
|
} |
|
|
|
public function revoca($delete = false) { |
|
$return = false; |
|
if ($this->partecipazioneAttiva()) { |
|
$partecipante = $this->miaPartecipazione(); |
|
if (!empty($partecipante)) { |
|
if (!$delete) { |
|
$partecipante["conferma"] = "N"; |
|
$partecipante["timestamp_invio"] = ""; |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "r_partecipanti_concorsi"; |
|
$salva->operazione = "UPDATE"; |
|
$salva->oggetto = $partecipante; |
|
$return = $salva->save(); |
|
} else { |
|
$richieste = $this->getRichieste(); |
|
foreach($richieste AS $richiesta) { |
|
$this->deleteBusta($richiesta["codice"]); |
|
} |
|
$ris = $this->db->go("DELETE FROM r_partecipanti_concorsi WHERE codice = :codice",[":codice"=>$partecipante["codice"]]); |
|
if ($ris->rowCount() > 0) { |
|
$return = true; |
|
scriviLog("r_partecipanti_concorsi","DELETE",$this->db->getSQL()); |
|
} |
|
} |
|
} |
|
} |
|
return $return; |
|
} |
|
|
|
public function getPartecipantiSeduta($codice = "") { |
|
if ($this->sedutaAperta()) { |
|
if (empty($codice)) { |
|
return parent::getPartecipanti(); |
|
} else { |
|
return parent::getPartecipante($codice); |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public function getBusta($partecipante,$richiesta,$aggiuntive = false,bool $contenuto = false) { |
|
$partecipante = $this->miaPartecipazione(); |
|
if (!empty($partecipante)) { |
|
$partecipante = $partecipante["codice"]; |
|
return parent::getBusta($partecipante,$richiesta,$aggiuntive,$contenuto); |
|
} |
|
return false; |
|
} |
|
|
|
public function getRaggruppamento($partecipante) |
|
{ |
|
$partecipante = $this->miaPartecipazione(); |
|
if (!empty($this->lotto) && !empty($partecipante)) { |
|
$bind = [":codice_round" => $this->round["codice"], ":codice_partecipante" => $partecipante["codice"],":codice_lotto" => $this->lotto["codice"]]; |
|
$sql = "SELECT r_raggruppamenti_concorsi.* FROM r_raggruppamenti_concorsi JOIN r_partecipanti_concorsi |
|
ON r_raggruppamenti_concorsi.codice_padre = r_partecipanti_concorsi.codice |
|
WHERE r_partecipanti_concorsi.codice_round = :codice_round AND r_partecipanti_concorsi.codice = :codice_partecipante AND codice_lotto = :codice_lotto"; |
|
$tmp = $this->db->go($sql, $bind)->fetchAll(PDO::FETCH_ASSOC); |
|
$return = []; |
|
if (!empty($tmp)) { |
|
global $config; |
|
foreach($tmp AS $membro) { |
|
$decrypted = json_decode(simple_decrypt(base64_decode($membro["encryptedData"]),$config["simple_encrypt"]["offer"]),true); |
|
$membro = array_merge($membro,$decrypted); |
|
$return[] = $membro; |
|
} |
|
} |
|
return $return; |
|
} |
|
} |
|
|
|
public function deleteBusta($codice_richiesta) { |
|
if ($this->partecipazioneAttiva() && !empty($this->miaPartecipazione())) { |
|
$busta = $this->getBusta($this->miaPartecipazione(),$codice_richiesta,false); |
|
if (!empty($busta)) { |
|
unlink($this->getSpecificBustaPath($busta)); |
|
$sql = "DELETE FROM b_concorsi_buste WHERE codice_partecipante = :codice_partecipante AND codice_richiesta = :codice_richiesta "; |
|
$this->db->go($sql,array(":codice_partecipante"=>$this->miaPartecipazione()["codice"],":codice_richiesta"=>$codice_richiesta)); |
|
scriviLog("b_concorsi_buste","DELETE",$this->db->getSQL()); |
|
} |
|
} |
|
} |
|
|
|
public function showPanel() { |
|
$return = $this->partecipazioneAttiva(); |
|
if (!$return) { |
|
$return = $this->miaPartecipazione(); |
|
if (!empty($return)) { |
|
if ($return["conferma"] != "S") { |
|
return false; |
|
} |
|
} |
|
} |
|
if (!empty($return)) { |
|
return true; |
|
} |
|
return false; |
|
} |
|
|
|
public function hasInvito($codice_lotto = null) { |
|
if ((int)$this->round["numero"] === 1) { |
|
return true; |
|
} else { |
|
$unsetLotto = true; |
|
if (!empty($this->lotto)) { |
|
$lotti = [$this->lotto["codice"]]; |
|
$unsetLotto = false; |
|
} else if (empty($codice_lotto)) { |
|
$lotti = array_column($this->getLotti(),"codice"); |
|
} else { |
|
$lotti = [$codice_lotto]; |
|
} |
|
foreach($lotti AS $checkLotto) { |
|
if ($this->setLotto($checkLotto)) { |
|
if (!empty($this->miaPartecipazione())) { |
|
if ($unsetLotto) { |
|
$this->lotto = null; |
|
} |
|
return true; |
|
} |
|
} |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public function partecipazioneAttiva() { |
|
if ($this->potentialAction) { |
|
if ($this->info["stato"] == "20") { |
|
if ($this->info["fase_attiva"] == $this->round["numero"]) { |
|
if (strtotime($this->round["scadenza"]) > time()) { |
|
if (empty($this->lotto)) { |
|
return true; |
|
} else { |
|
return $this->hasInvito(); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public function savePartecipante($placeholder = null) { |
|
$return = false; |
|
if (!empty($this->lotto)) { |
|
$partecipante = array(); |
|
$partecipante["id"] = generateStrongPassword(9,false,'lud') . "-" . time(); |
|
$partecipante["codice_round"] = $this->round["codice"]; |
|
$partecipante["codice_lotto"] = $this->lotto["codice"]; |
|
$partecipante["codice_operatore"] = $_SESSION["utente"]->oe["codice"]; |
|
$data = [ |
|
"stato" => $_SESSION["utente"]->oe["stato_legale"], |
|
"codice_fiscale" => $_SESSION["utente"]->oe["codice_fiscale_impresa"], |
|
"ragione_sociale" => $_SESSION["utente"]->oe["ragione_sociale"] |
|
]; |
|
global $config; |
|
$partecipante["encryptedData"] = base64_encode(simple_encrypt(json_encode($data),$config["simple_encrypt"]["offer"])); |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "r_partecipanti_concorsi"; |
|
$salva->operazione = "INSERT"; |
|
$salva->oggetto = $partecipante; |
|
$salva->oggetto["uuid"] = uuidgen_v4(); |
|
|
|
if ($salva->save()) { |
|
$return = $this->miaPartecipazione(); |
|
} |
|
} |
|
return $return; |
|
} |
|
|
|
public function checkFormFill($busta="") { |
|
$return = false; |
|
$partecipante = $this->miaPartecipazione(); |
|
if (!empty($partecipante)) { |
|
$bind = []; |
|
$bind[":partecipante"] = $partecipante["codice"]; |
|
$bind[":busta"] = $busta; |
|
$check = "SELECT codice,md5,sha1,sha256,shaContent,salt FROM b_offerte_concorsi WHERE codice_partecipante = :partecipante AND tipo = :busta ORDER BY codice DESC"; |
|
$return = $this->db->go($check,$bind)->fetch(PDO::FETCH_ASSOC); |
|
} |
|
return $return; |
|
} |
|
|
|
public function chiarimentiAperti() { |
|
if ($this->potentialAction) { |
|
if ($this->info["stato"] == "20") { |
|
if ($this->info["fase_attiva"] == $this->round["numero"]) { |
|
if (strtotime($this->round["chiarimenti"]) > time()) { |
|
return true; |
|
} |
|
} |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public function sopralluogoAperti() { |
|
if ($this->potentialAction) { |
|
if ($this->info["stato"] == "20") { |
|
if ($this->info["fase_attiva"] == $this->round["numero"]) { |
|
if (!empty(mysql2datetime($this->round["sopralluogo"])) && strtotime($this->round["sopralluogo"]) > time()) { |
|
return true; |
|
} |
|
} |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public static function init($codice,$codice_round=NULL,$valutazione=NULL) { |
|
if (!empty($codice) && !empty($_SESSION["ente"])) { |
|
$check = self::getList($_SESSION["ente"]->codice,["b_concorsi.codice"=>$codice]); |
|
if (!empty($check) && count($check) == 1) { |
|
global $pdo; |
|
$bind = [":codice"=>$codice]; |
|
$sql = "SELECT * FROM b_concorsi WHERE codice = :codice "; |
|
$concorso = $pdo->go($sql,$bind)->fetch(PDO::FETCH_ASSOC); |
|
if (!empty($concorso)) { |
|
$continua = false; |
|
$bind = [":codice_concorso"=>$codice]; |
|
$sql = "SELECT * FROM b_concorsi_round WHERE codice_concorso = :codice_concorso "; |
|
if (!empty($codice_round)) { |
|
$bind[":codice_round"] = $codice_round; |
|
$sql .= " AND codice = :codice_round "; |
|
} |
|
$sql .= " ORDER BY numero DESC"; |
|
$rounds = $pdo->go($sql,$bind)->fetchAll(PDO::FETCH_ASSOC); |
|
if (!empty($rounds)) { |
|
if (empty($codice_round)) { |
|
foreach($rounds AS $round) { |
|
if ($round["numero"] == $concorso["fase_attiva"]) { break; } |
|
} |
|
} else { |
|
$round = reset($rounds); |
|
} |
|
} |
|
if (isset($round)) { |
|
$instance = new publicConcorso(); |
|
$instance->info = $concorso; |
|
$instance->round = $round; |
|
$instance->activeRound = false; |
|
if ($round["numero"] == $concorso["fase_attiva"]) { |
|
$instance->activeRound = true; |
|
} |
|
if ($instance->round["numero"] == count($rounds)) { |
|
$instance->lastRound = true; |
|
} |
|
if ($round["numero"] < $concorso["fase_attiva"]) { |
|
$instance->info["stato"] = 100; |
|
} else if ($round["numero"] > $concorso["fase_attiva"]) { |
|
$instance->info["stato"] = 0; |
|
if ($concorso["stato"] > 0) { $instance->info["stato"] = 10; } |
|
} |
|
if (isset($_SESSION["utente"])) { |
|
if ($_SESSION["utente"]->gerarchia >= 100 && !empty($_SESSION["utente"]->oe)) { |
|
if ($instance->round["numero"] === "1") { |
|
$instance->potentialAction = true; |
|
} else { |
|
if (strtotime($round["pubblicazione"]) <= time()) { |
|
$instance->potentialAction = $instance->hasInvito(); |
|
} |
|
} |
|
} |
|
} |
|
if ($concorso["stato"] == 20 AND strtotime($round["scadenza"]) < time() && $instance->activeRound) { |
|
$pdo->go("UPDATE b_concorsi SET stato = 21 WHERE codice = :codice AND stato = 20",[":codice"=>$concorso["codice"]]); |
|
$instance->info["stato"] = 21; |
|
} |
|
return $instance; |
|
} |
|
} |
|
} |
|
return false; |
|
} |
|
} |
|
|
|
public function getChiarimenti($codice = NULL) { |
|
$tmp = parent::getChiarimenti($codice); |
|
$chiarimenti = []; |
|
$codice_oe = $_SESSION["utente"]->oe["codice"] ?? null; |
|
foreach($tmp AS $chiarimento) { |
|
if ($codice_oe == $chiarimento["codice_richiedente"] || (!empty($chiarimento["risposta"]) && $chiarimento["attivo"] == "S")) { |
|
$chiarimenti[] = $chiarimento; |
|
} |
|
} |
|
return $chiarimenti; |
|
} |
|
|
|
public function getSopralluoghi($codice = NULL) { |
|
$tmp = parent::getSopralluoghi($codice); |
|
$sopralluoghi = []; |
|
$codice_oe = $_SESSION["utente"]->oe["codice"] ?? null; |
|
foreach($tmp AS $chiarimento) { |
|
if ($codice_oe == $chiarimento["codice_richiedente"]) { |
|
if ($chiarimento["attivo"] == "P") { |
|
$chiarimento["risposta"] = ""; |
|
$chiarimento["appuntamento"] = null; |
|
} |
|
$sopralluoghi[] = $chiarimento; |
|
} |
|
} |
|
return $sopralluoghi; |
|
} |
|
|
|
public function getAvvisi() { |
|
return parent::getManagerAvvisi()->getAvvisi(); |
|
} |
|
|
|
public function getManagerRichieste() { |
|
$manager = new publicRichiesteOE("concorsi",$this->info["codice"],$this->round["codice"]); |
|
if (!empty($manager)) { |
|
return $manager; |
|
} |
|
} |
|
|
|
public function getRichiesteIntegrazione() { |
|
$manager = $this->getManagerRichieste(); |
|
if (!empty($manager)) { |
|
return $manager->getRichieste(); |
|
} |
|
} |
|
|
|
public function getManagerPartecipazione() { |
|
if (empty($this->managerPartecipazione)) { |
|
$manager = new busteOE; |
|
$manager->submit = ($this->hasInvito() && $this->partecipazioneAttiva()); |
|
$manager->obj = $this; |
|
$manager->deletable = $this->partecipazioneAttiva(); |
|
$manager->modulo = "concorsi"; |
|
$manager->avvalimentoPossibile = false; |
|
$manager->variables = ["codice_concorso"=>$this->info["codice"],"codice_lotto"=>$this->lotto["codice"],"codice_round"=>$this->round["codice"]]; |
|
$this->managerPartecipazione = $manager; |
|
} |
|
return $this->managerPartecipazione; |
|
} |
|
|
|
} |
|
|
|
?>
|