id = intval($id);
$this->getData();
}
/* ---------------------------------------------------------------
getData() : récupération des propriétés
--------------------------------------------------------------- */
public function getData() {
if(!$this->id) return;
$requete = 'SELECT * FROM abts_status WHERE abts_status_id='.$this->id;
$result = @pmb_mysql_query($requete);
if(!pmb_mysql_num_rows($result)) {
pmb_error::get_instance(static::class)->add_message("not_found", "not_found_object");
return;
}
$data = pmb_mysql_fetch_object($result);
$this->gestion_libelle = $data->abts_status_gestion_libelle;
$this->opac_libelle = $data->abts_status_opac_libelle;
$this->class_html = $data->abts_status_class_html;
$this->bulletinage_active = $data->abts_status_bulletinage_active;
}
public function get_form() {
global $msg,$charset;
global $admin_abts_status_content_form;
$content_form = $admin_abts_status_content_form;
$content_form = str_replace('!!id!!', $this->id, $content_form);
$interface_form = new interface_admin_form('statusform');
if($this->id){
$interface_form->set_label($msg['118']);
}else{
$interface_form->set_label($msg['115']);
}
$couleur = array();
for ($i=1;$i<=20; $i++) {
if ($this->class_html == "statutnot".$i){
$checked = "checked";
}
else {
$checked = "";
}
$couleur[$i]="
";
if ($i==10) $couleur[10].="
";
elseif ($i!=20) $couleur[$i].="|";
}
$couleurs=implode("",$couleur);
$content_form = str_replace("!!class_html!!", $couleurs, $content_form);
$content_form = str_replace("!!bulletinage_active_checked!!", ($this->bulletinage_active ? 'checked=checked' : ''), $content_form);
$content_form = str_replace("!!gestion_libelle!!", htmlentities($this->gestion_libelle,ENT_QUOTES,$charset),$content_form);
$interface_form->set_object_id($this->id)
->set_confirm_delete_msg($msg['confirm_suppr_de']." ".$this->gestion_libelle." ?")
->set_content_form($content_form)
->set_table_name('abts_status')
->set_field_focus('form_gestion_libelle');
return $interface_form->get_display();
}
public function set_properties_from_form() {
global $form_gestion_libelle,$form_class_html, $form_bulletinage_active;
$this->gestion_libelle = stripslashes($form_gestion_libelle);
$this->opac_libelle = stripslashes($form_gestion_libelle);
$this->class_html = stripslashes($form_class_html);
$this->bulletinage_active = intval($form_bulletinage_active);
}
public function save() {
if($this->gestion_libelle){
if($this->id){
$query = " update abts_status set ";
$where = "where abts_status_id = ".$this->id;
}else{
$query = " insert into abts_status set ";
$where = "";
}
$query.="
abts_status_gestion_libelle = '".addslashes($this->gestion_libelle)."',
abts_status_opac_libelle = '".addslashes($this->opac_libelle)."',
abts_status_class_html = '".addslashes($this->class_html)."',
abts_status_bulletinage_active = '".addslashes($this->bulletinage_active)."'
";
$result = pmb_mysql_query($query.$where);
if(!$result){
return false;
}
}
return true;
}
public static function check_data_from_form() {
global $form_gestion_libelle;
if(empty($form_gestion_libelle)) {
return false;
}
return true;
}
public static function delete($id) {
global $msg;
$id=intval($id);
if($id==1) return true;
$used = static::check_used($id);
if(!count($used)){
$query = "delete from abts_status where abts_status_id = ".$id;
pmb_mysql_query($query);
return true;
} else {
$msg_suppr_err= $msg['abts_status_used'].'
';
foreach($used as $auth){
$msg_suppr_err.=$auth['link'].'
';
}
pmb_error::get_instance(static::class)->add_message('abts_status_used', $msg_suppr_err);
return false;
}
}
public static function get_list(){
if(!static::$status_fetched){
static::$status = array();
$query = "select abts_status_id, abts_status_gestion_libelle,abts_status_class_html,abts_status_bulletinage_active
from abts_status order by abts_status_gestion_libelle";
$result = pmb_mysql_query($query);
if(pmb_mysql_num_rows($result)){
while($row = pmb_mysql_fetch_object($result)){
static::$status[$row->abts_status_id] = array(
'label' => $row->abts_status_gestion_libelle,
'class_html' => $row->abts_status_class_html,
'bulletinage_active' => $row->abts_status_bulletinage_active,
);
}
}
static::$status_fetched = true;
}
}
public static function get_ids_bulletinage_active(){
static::get_list();
$ids = array();
foreach(static::$status as $id_statut => $statut){
if($statut['bulletinage_active']) {
$ids[] = $id_statut;
}
}
return $ids;
}
/**
* Fonction qui controle si le status est utilisé
* @param integer $id du statut
* @return array: ids des abonnemets
*/
public static function check_used($id){
$id+=0;
$used = array();
$query="select abt_id from abts_abts where abt_status=".$id;
$res = pmb_mysql_query($query);
if (pmb_mysql_num_rows($res)) {
while($r = pmb_mysql_fetch_object($res)) {
$used[] = $r->abt_id;
}
}
return $used;
}
/**
* Fonction permettant de générer le selecteur des statuts
* @param integer $id du statut sélectionné
* @param boolean $selector_search Sélécteur affiché dans la page de recherche
* @return string
*/
public static function get_form_for($id, $search=false){
global $msg;
$id=intval($id);
static::get_list();
$on_change='';
if($search){
$on_change='onchange="if(this.form) this.form.submit();"';
}
$selector = '';
return $selector;
}
/**
* Fonction qui construit l'affichage du statut
* @param integer $id du statut
* @return string
*/
public static function get_display($id){
global $charset;
$id=intval($id);
static::get_list();
$statut = static::$status[$id];
$display = "";
$display .= "