id_exercice = $id_exercice+0; if ($this->id_exercice) { $this->load(); } } // charge l'exercice à partir de la base. public function load(){ $q = "select * from exercices where id_exercice = '".$this->id_exercice."' "; $r = pmb_mysql_query($q) ; $obj = pmb_mysql_fetch_object($r); $this->id_exercice = $obj->id_exercice; $this->num_entite = $obj->num_entite; $this->libelle = $obj->libelle; $this->date_debut = $obj->date_debut; $this->date_fin = $obj->date_fin; $this->statut = $obj->statut; } // enregistre l'exercice en base. public function save(){ if( (!$this->num_entite) || ($this->libelle == '') ) die("Erreur de création exercice"); if($this->id_exercice) { $q = "update exercices set num_entite = '".$this->num_entite."', libelle ='".$this->libelle."', "; $q.= "date_debut = '".$this->date_debut."', date_fin = '".$this->date_fin."', statut = '".$this->statut."' "; $q.= "where id_exercice = '".$this->id_exercice."' "; pmb_mysql_query($q); } else { $q = "insert into exercices set num_entite = '".$this->num_entite."', libelle = '".$this->libelle."', "; $q.= "date_debut = '".$this->date_debut."', date_fin = '".$this->date_fin."', statut = '".$this->statut."' "; pmb_mysql_query($q); $this->id_exercice = pmb_mysql_insert_id(); $this->load(); } } //supprime un exercice de la base public static function delete($id_exercice= 0) { $id_exercice += 0; if(!$id_exercice) return; //Suppression des actes //TODO Voir suppression du lien entre actes et exercices $res_actes = actes::listByExercice($id_exercice); while (($row = pmb_mysql_fetch_object($res_actes))) { actes::delete($row->id_acte); } //Suppression des budgets $res_budgets = budgets::listByExercice($id_exercice); while (($row = pmb_mysql_fetch_object($res_budgets))) { budgets::delete($row->id_budget); } //Suppression de l'exercice $q = "delete from exercices where id_exercice = '".$id_exercice."' "; pmb_mysql_query($q); } //retourne une requete pour la liste des exercices de l'entité public static function listByEntite($id_entite, $mask='-1', $order='date_debut desc') { $q = "select * from exercices where num_entite = '".$id_entite."' "; if ($mask != '-1') $q.= "and (statut & '".$mask."') = '".$mask."' "; $q.= "order by ".$order." "; return $q; } //Vérifie si un exercice existe public static function exists($id_exercice){ $q = "select count(1) from exercices where id_exercice = '".$id_exercice."' "; $r = pmb_mysql_query($q); return pmb_mysql_result($r, 0, 0); } //Vérifie si le libellé d'un exercice existe déjà pour une entité public static function existsLibelle($id_entite, $libelle, $id_exercice=0){ $id_entite += 0; $id_exercice += 0; $q = "select count(1) from exercices where libelle = '".$libelle."' and num_entite = '".$id_entite."' "; if ($id_exercice) $q.= "and id_exercice != '".$id_exercice."' "; $r = pmb_mysql_query($q); return pmb_mysql_result($r, 0, 0); } //Compte le nb de budgets affectés à un exercice public static function hasBudgets($id_exercice=0){ $id_exercice += 0; if (!$id_exercice) return 0; $q = "select count(1) from budgets where num_exercice = '".$id_exercice."' "; $r = pmb_mysql_query($q); return pmb_mysql_result($r, 0, 0); } //Compte le nb de budgets actifs affectés à un exercice public static function hasBudgetsActifs($id_exercice=0){ $id_exercice += 0; if (!$id_exercice) return 0; $q = "select count(1) from budgets where num_exercice = '".$id_exercice."' and statut != '2' "; $r = pmb_mysql_query($q); return pmb_mysql_result($r, 0, 0); } //Compte le nb d'actes affectés à un exercice public static function hasActes($id_exercice=0){ $id_exercice += 0; if (!$id_exercice) return 0; $q = "select count(1) from actes where num_exercice = '".$id_exercice."' "; $r = pmb_mysql_query($q); return pmb_mysql_result($r, 0, 0); } //Compte le nb d'actes actifs affectés à un exercice //Actes actifs == commandes non soldées et non payées public static function hasActesActifs($id_exercice=0){ $id_exercice += 0; if (!$id_exercice) return 0; $q = "select count(1) from actes where num_exercice = '".$id_exercice."' "; $q.= "and (type_acte = 0 and (statut & 32) != 32) "; $r = pmb_mysql_query($q); return pmb_mysql_result($r, 0, 0); } //choix exercice par défaut pour une entité public function setDefault($id_exercice=0) { if (!$id_exercice) $id_exercice = $this->id_exercice; $q = "update exercices set statut = '".STA_EXE_ACT."' where statut = '".STA_EXE_DEF."' and num_entite = '".$this->num_entite."' limit 1 "; pmb_mysql_query($q); $q = "update exercices set statut = '".STA_EXE_DEF."' where id_exercice = '".$this->id_exercice."' limit 1 "; pmb_mysql_query($q); } //Recuperation de l'exercice session public static function getSessionExerciceId($id_bibli,$id_exer) { global $deflt3exercice; $q = "select id_exercice from exercices where num_entite = '".$id_bibli."' and (statut & '".STA_EXE_ACT."') = '".STA_EXE_ACT."' "; $q.= "order by statut desc "; $r = pmb_mysql_query($q); $res=array(); while($row=pmb_mysql_fetch_object($r)) { $res[]=$row->id_exercice; } if (!$id_exer && isset($_SESSION['id_exercice']) && $_SESSION['id_exercice']) { $id_exer=$_SESSION['id_exercice']; } if (in_array($id_exer, $res)) { $_SESSION['id_exercice'] = $id_exer; } elseif (in_array($deflt3exercice, $res)) { $_SESSION['id_exercice'] = $deflt3exercice; } elseif (isset($res[0])) { $_SESSION['id_exercice'] = $res[0]; } else { $_SESSION['id_exercice'] = 0; } return $_SESSION['id_exercice']; } //Definition de l'exercice session public function setSessionExerciceId($deflt3exercice) { $_SESSION['id_exercice']=$deflt3exercice; return; } //optimization de la table exercices public function optimize() { $opt = pmb_mysql_query('OPTIMIZE TABLE exercices'); return $opt; } //Retourne un selecteur html avec la liste des exercices actifs pour une ou plusieurs bibliotheque public static function getHtmlSelect($id_bibli=0, $selected=0, $sel_all=FALSE, $sel_attr=array(), $actif_only = true) { global $msg,$charset; $sel=''; if ($id_bibli) { $q = "select id_exercice, libelle, statut from exercices where num_entite = '".$id_bibli."' "; if($actif_only) { $q .= "and (statut & '".STA_EXE_ACT."') = '".STA_EXE_ACT."' "; } $q.= "order by statut desc, libelle asc "; $r = pmb_mysql_query($q); $res = array(); if ($sel_all) { $res[0]=array( 'label' => $msg['acquisition_exer_all'], 'actif' => '1' ); } while ($row = pmb_mysql_fetch_object($r)){ $res[$row->id_exercice] = array( 'label' => $row->libelle, 'actif' => ($row->statut & STA_EXE_ACT ? 1 : 0) ); } if (count($res)) { $sel="