fetch_data($id,$lazzy_load);
}
public function fetch_data($id=0,$lazzy_load=true){
if($this->id_demande && !$id){
$id=$this->id_demande;
}elseif(!$this->id_demande && $id){
$this->id_demande=intval($id);
}
$this->etat_demande = 0;
$this->date_demande = '0000-00-00';
$this->deadline_demande = '0000-00-00';
$this->sujet_demande = '';
$this->num_demandeur = 0;
$this->progression = 0;
$this->date_prevue = '0000-00-00';
$this->theme_demande = 0;
$this->type_demande = 0;
$this->titre_demande = '';
$this->num_notice = 0;
$this->dmde_read_gestion = 0;
$this->dmde_read_opac = 0;
$this->reponse_finale = '';
$this->num_linked_notice = 0;
if($this->id_demande){
$req = "select etat_demande, date_demande, deadline_demande, sujet_demande, num_demandeur, progression, num_notice,
date_prevue, theme_demande, type_demande, titre_demande, libelle_theme,libelle_type, allowed_actions,
dmde_read_gestion, reponse_finale , dmde_read_opac, num_linked_notice
from demandes d, demandes_theme dt, demandes_type dy
where dy.id_type=d.type_demande and dt.id_theme=d.theme_demande and id_demande='".$this->id_demande."'";
$res=pmb_mysql_query($req);
if(pmb_mysql_num_rows($res)){
$dmde = pmb_mysql_fetch_object($res);
$this->etat_demande = $dmde->etat_demande;
$this->date_demande = $dmde->date_demande;
$this->deadline_demande = $dmde->deadline_demande;
$this->sujet_demande = $dmde->sujet_demande;
$this->num_demandeur = $dmde->num_demandeur;
$this->progression = $dmde->progression;
$this->date_prevue = $dmde->date_prevue;
$this->theme_demande = $dmde->theme_demande;
$this->type_demande = $dmde->type_demande;
$this->titre_demande = $dmde->titre_demande;
$this->theme_libelle = $dmde->libelle_theme;
$this->type_libelle = $dmde->libelle_type;
$this->num_notice = $dmde->num_notice;
$this->allowed_actions = unserialize($dmde->allowed_actions);
$this->dmde_read_gestion = $dmde->dmde_read_gestion;
$this->dmde_read_opac = $dmde->dmde_read_opac;
$this->reponse_finale = $dmde->reponse_finale;
$this->num_linked_notice = $dmde->num_linked_notice;
if(empty($this->allowed_actions)){
$workflow = new workflow('ACTIONS');
$this->allowed_actions = $workflow->getTypeList();
$allowed_actions = array();
foreach($this->allowed_actions as $allowed_action){
$allowed_action['active'] = 1;
$allowed_actions[] = $allowed_action;
if($allowed_action['default']){
$this->first_action = $allowed_action['id'];
}
}
}
//recherche de l'entrée dans la FAQ
$query = "select id_faq_question from faq_questions where faq_question_num_demande = ".$this->id_demande;
$result = pmb_mysql_query($query);
if(pmb_mysql_num_rows($result)){
$this->num_faq_question = pmb_mysql_result($result,0,0);
}
} else{
$workflow = new workflow('ACTIONS');
$this->allowed_actions = $workflow->getTypeList();
$allowed_actions = array();
foreach($this->allowed_actions as $allowed_action){
$allowed_action['active'] = 1;
$allowed_actions[] = $allowed_action;
if($allowed_action['default']){
$this->first_action = $allowed_action['id'];
}
}
}
$req = "select num_user, concat(prenom,' ',nom) as nom, username, users_statut from demandes_users, users where num_user=userid
and num_demande='".$this->id_demande."' and users_statut=1";
$res = pmb_mysql_query($req);
$i=0;
$this->users = array();
while($user = pmb_mysql_fetch_object($res)){
$this->users[$i]['nom'] = (trim($user->nom) ? $user->nom : $user->username);
$this->users[$i]['id'] = $user->num_user;
$this->users[$i]['statut'] = $user->users_statut;
$i++;
}
} else {
$this->num_user = array();
$workflow = new workflow('ACTIONS');
$this->allowed_actions = $workflow->getTypeList();
$allowed_actions = array();
foreach($this->allowed_actions as $allowed_action){
$allowed_action['active'] = 1;
$allowed_actions[] = $allowed_action;
if($allowed_action['default']){
$this->first_action = $allowed_action['id'];
}
}
}
if(empty($this->workflow)){
$this->workflow = new workflow('DEMANDES','INITIAL');
$this->liste_etat = $this->workflow->getStateList();
}
if($this->id_demande){
$this->actions=array();
//On charge la liste d'id des actions
$query='SELECT id_action FROM demandes_actions WHERE num_demande='.$this->id_demande;
$result=pmb_mysql_query($query);
while($action=pmb_mysql_fetch_array($result,PMB_MYSQL_ASSOC)){
if($lazzy_load){
$this->actions[$action['id_action']]=new stdClass();
$this->actions[$action['id_action']]->id_action=$action['id_action'];
}else{
$this->actions[$action['id_action']]=new demandes_actions($action['id_action']);
}
}
if(!$lazzy_load){
$this->last_modified=$this->get_last_modified_action();
}
}
}
public function get_last_modified_action(){
$temp=0;
foreach($this->actions as $action){
//On cherche la dernière note modifiée
if(!$temp && $action->last_modified){
$temp=$action;
}
$temp_date_note = '';
$action_date_note = '';
if(isset($temp->last_modified->date_note)) $temp_date_note = $temp->last_modified->date_note;
if(isset($action->last_modified->date_note)) $action_date_note = $action->last_modified->date_note;
$dateTemp= new DateTime($temp_date_note);
$dateAction= new DateTime($action_date_note);
if($dateTemp->format('U') < $dateAction->format('U')){
$temp = $action;
}
}
if($temp){
return $temp;
}
}
/*
* Formulaire de création d'une demande
*/
public function show_modif_form(){
global $form_modif_demande, $msg, $charset, $form_linked_record;
$themes = new demandes_themes('demandes_theme','id_theme','libelle_theme',$this->theme_demande);
$types = new demandes_types('demandes_type','id_type','libelle_type',$this->type_demande);
if(!$this->id_demande){
$form_modif_demande = str_replace('!!form_title!!',htmlentities($msg['demandes_creation'],ENT_QUOTES,$charset),$form_modif_demande);
$form_modif_demande = str_replace('!!empr_txt!!','',$form_modif_demande);
$form_modif_demande = str_replace('!!select_etat!!',$this->getStateSelector(),$form_modif_demande);
$date = formatdate(today());
$date_debut=date("Y-m-d",time());
$date_dmde = " ";
$form_modif_demande = str_replace('!!date_demande!!',$date_dmde,$form_modif_demande);
$form_modif_demande = str_replace('!!date_fin_btn!!',$date,$form_modif_demande);
$form_modif_demande = str_replace('!!date_debut_btn!!',$date,$form_modif_demande);
$form_modif_demande = str_replace('!!date_debut!!',$date_debut,$form_modif_demande);
$form_modif_demande = str_replace('!!date_fin!!',$date_debut,$form_modif_demande);
$form_modif_demande = str_replace('!!date_prevue!!',$date_debut,$form_modif_demande);
$form_modif_demande = str_replace('!!date_prevue_btn!!',$date,$form_modif_demande);
$form_modif_demande = str_replace('!!btn_suppr!!','',$form_modif_demande);
$act_cancel = "document.location='./demandes.php?categ=list'";
$act_form = "./demandes.php?categ=list";
} else {
$btn_suppr = " ";
$form_modif_demande = str_replace('!!form_title!!',htmlentities(sprintf($msg['demandes_modification'],' : '.$this->titre_demande),ENT_QUOTES,$charset),$form_modif_demande);
$form_modif_demande = str_replace('!!btn_suppr!!',$btn_suppr,$form_modif_demande);
$carac_empr = $this->getCaracEmpr($this->num_demandeur);
$nom = $carac_empr['nom'];
$form_modif_demande = str_replace('!!empr_txt!!',htmlentities($nom,ENT_QUOTES,$charset),$form_modif_demande);
$form_modif_demande = str_replace('!!select_etat!!',$this->workflow->getStateCommentById($this->etat_demande),$form_modif_demande);
$form_modif_demande = str_replace('!!date_fin_btn!!',formatdate($this->deadline_demande),$form_modif_demande);
$form_modif_demande = str_replace('!!date_demande!!',formatdate($this->date_demande),$form_modif_demande);
$form_modif_demande = str_replace('!!date_debut!!',htmlentities($this->date_demande,ENT_QUOTES,$charset),$form_modif_demande);
$form_modif_demande = str_replace('!!date_fin!!',htmlentities($this->deadline_demande,ENT_QUOTES,$charset),$form_modif_demande);
$form_modif_demande = str_replace('!!date_prevue_btn!!',formatdate($this->date_prevue),$form_modif_demande);
$form_modif_demande = str_replace('!!date_prevue!!',htmlentities($this->date_prevue,ENT_QUOTES,$charset),$form_modif_demande);
$act_cancel = "document.location='./demandes.php?categ=gestion&act=see_dmde&iddemande=$this->id_demande'";
$act_form = "./demandes.php?categ=gestion";
}
$form_modif_demande = str_replace('!!iddemande!!',$this->id_demande,$form_modif_demande);
$form_modif_demande = str_replace('!!idempr!!',$this->num_demandeur,$form_modif_demande);
$form_modif_demande = str_replace('!!titre!!',htmlentities($this->titre_demande,ENT_QUOTES,$charset),$form_modif_demande);
$form_modif_demande = str_replace('!!sujet!!',htmlentities($this->sujet_demande,ENT_QUOTES,$charset),$form_modif_demande);
$form_modif_demande = str_replace('!!progression!!',htmlentities($this->progression,ENT_QUOTES,$charset),$form_modif_demande);
$form_modif_demande = str_replace('!!select_theme!!',$themes->getListSelector($this->theme_demande),$form_modif_demande);
$form_modif_demande = str_replace('!!select_type!!',$types->getListSelector($this->type_demande),$form_modif_demande);
$form_modif_demande = str_replace('!!select_user!!',$this->getUsersSelector('',false,true),$form_modif_demande);
$form_modif_demande = str_replace('!!form_linked_record!!', $form_linked_record, $form_modif_demande);
if ($this->num_linked_notice) {
$display = new mono_display($this->num_linked_notice, 0, '', 0, '', '', '',0, 0, 0, 0,"", 0, false, true);
$form_modif_demande = str_replace('!!linked_record!!', htmlentities($display->result, ENT_QUOTES, $charset), $form_modif_demande);
$form_modif_demande = str_replace('!!linked_record_id!!', htmlentities($this->num_linked_notice, ENT_QUOTES, $charset), $form_modif_demande);
} else {
$form_modif_demande = str_replace('!!linked_record!!', "", $form_modif_demande);
$form_modif_demande = str_replace('!!linked_record_id!!', 0, $form_modif_demande);
}
$perso = '';
$p_perso=new parametres_perso("demandes");
if (!$p_perso->no_special_fields) {
$c=0;
$perso="
";
$perso_=$p_perso->show_editable_fields($this->id_demande);
for ($i=0; $i";
$perso.="".$p["TITRE"]." ".$p["COMMENT_DISPLAY"]."
".$p["AFF"]."
";
$c++;
if ($c==2) {
$perso.="";
$c=0;
}
}
if ($c==1) $perso.="
";
$perso=$perso_["CHECK_SCRIPTS"]."\n".$perso;
} else {
$perso="";
}
$form_modif_demande = str_replace("!!champs_perso!!",$perso,$form_modif_demande);
$form_modif_demande = str_replace('!!form_action!!',$act_form,$form_modif_demande);
$form_modif_demande = str_replace('!!cancel_action!!',$act_cancel,$form_modif_demande);
print $form_modif_demande;
}
/*
* Formulaire de création de la liste des demandes
*/
public function show_list_form(){
global $form_filtre_demande, $form_liste_demande;
global $charset, $msg;
global $idetat,$iduser,$idempr,$user_input;
global $date_debut,$date_fin, $id_type, $id_theme, $dmde_loc;
//Formulaire des filtres
$date_deb="
";
$date_but="
";
//Affichage de l'état en entete de page (si séléctioné)
if($idetat){
$form_filtre_demande=str_replace('!!etat_demandes!!',htmlentities(stripslashes($this->liste_etat[$idetat]['comment']),ENT_QUOTES, $charset),$form_filtre_demande);
}else{
$form_filtre_demande=str_replace('!!etat_demandes!!',"",$form_filtre_demande);
}
if($date_debut && $date_fin){
$date_deb = str_replace('!!date_debut_btn!!',formatdate($date_debut),$date_deb);
$date_but = str_replace('!!date_fin_btn!!',formatdate($date_fin),$date_but);
$date_deb = str_replace('!!date_debut!!',$date_debut,$date_deb);
$date_but = str_replace('!!date_fin!!',$date_fin,$date_but);
} else {
$date_lib = formatdate(today());
$date_sql = date("Y-m-d",time());
$date_deb = str_replace('!!date_debut_btn!!',$date_lib,$date_deb);
$date_but = str_replace('!!date_fin_btn!!',$date_lib,$date_but);
$date_deb = str_replace('!!date_debut!!',$date_sql,$date_deb);
$date_but = str_replace('!!date_fin!!',$date_sql,$date_but);
}
if($idempr){
$form_filtre_demande = str_replace('!!idempr!!',$idempr,$form_filtre_demande);
$carac_empr = $this->getCaracEmpr($idempr);
$nom = $carac_empr['nom'];
$form_filtre_demande = str_replace('!!empr_txt!!',$nom,$form_filtre_demande);
} else {
$form_filtre_demande = str_replace('!!idempr!!','',$form_filtre_demande);
$form_filtre_demande = str_replace('!!empr_txt!!','',$form_filtre_demande);
}
$form_filtre_demande = str_replace('!!user_input!!',htmlentities(stripslashes($user_input),ENT_QUOTES, $charset),$form_filtre_demande);
$form_filtre_demande = str_replace('!!periode!!',sprintf($msg['demandes_filtre_periode_lib'],$date_deb,$date_but),$form_filtre_demande);
$onchange = "onchange='this.form.act.value=\"search\";submit()'";
$form_filtre_demande = str_replace('!!affectation!!',$this->getUsersSelector($onchange,true,false,true),$form_filtre_demande);
$form_filtre_demande = str_replace('!!state!!',$this->getStateSelector($idetat,$onchange,true),$form_filtre_demande);
$themes = new demandes_themes('demandes_theme','id_theme','libelle_theme',$id_type);
$types = new demandes_types('demandes_type','id_type','libelle_type',$id_theme);
$form_filtre_demande = str_replace('!!theme!!',$themes->getListSelector($id_theme,$onchange,true),$form_filtre_demande);
$form_filtre_demande = str_replace('!!type!!',$types->getListSelector($id_type,$onchange,true),$form_filtre_demande);
$req_loc = "select idlocation, location_libelle from docs_location";
$res_loc = pmb_mysql_query($req_loc);
$sel_loc = "";
$sel_loc .= "".htmlentities($msg['demandes_localisation_all'],ENT_QUOTES,$charset)." ";
while($loc = pmb_mysql_fetch_object($res_loc)){
$sel_loc .= "idlocation) ? 'selected' : '').">".htmlentities($loc->location_libelle,ENT_QUOTES,$charset)." ";
}
$sel_loc.= " ";
$form_filtre_demande = str_replace('!!localisation!!',$sel_loc,$form_filtre_demande);
$perso = '';
$p_perso=new parametres_perso("demandes");
if (!$p_perso->no_special_fields) {
$c=0;
$perso_=$p_perso->show_search_fields();
if (count($perso_)) {
for ($i=0; $i";
$perso.="".$p["TITRE"]." ".$p["AFF"]."
";
$c++;
if ($c==3) {
$perso.="";
$c=0;
}
}
if ($c==1) {
$perso.="
";
} elseif ($c==2) {
$perso.="
";
}
}
}
$form_filtre_demande = str_replace("!!champs_perso!!",$perso,$form_filtre_demande);
print $form_filtre_demande;
$header_champs_perso = "";
reset($p_perso->t_fields);
$nb_cp_column = 0;
foreach ($p_perso->t_fields as $val) {
$header_champs_perso .= "".htmlentities($val["TITRE"],ENT_QUOTES,$charset)." ";
$nb_cp_column++;
}
//Formulaire de la liste
$req = self::getQueryFilter($idetat,$iduser,$idempr,$user_input,$date_debut,$date_fin, $id_theme, $id_type,$dmde_loc);
$res = pmb_mysql_query($req);
$liste ="";
$states_btn ="";
$affectation_btn ="";
$btn_suppr ="";
$nb_demandes = pmb_mysql_num_rows($res);
if($nb_demandes){
$parity=1;
while(($dmde = pmb_mysql_fetch_object($res))){
$dmde=new demandes($dmde->id_demande);
if ($parity % 2) {
$pair_impair = "even";
} else {
$pair_impair = "odd";
}
$parity += 1;
$tr_javascript = "onmouseover=\"this.className='surbrillance'\" onmouseout=\"this.className='".$pair_impair."'\" ";
$action = "onclick=\"document.location='".$dmde->get_gestion_link();
//Ajout des éléments de retour vers la bonne liste
if($idetat){
$action.="&idetat=".$idetat;
}
if ($iduser) {
if (is_array($iduser)) {
$action .= "&iduser=[".implode(',', $iduser)."]";
} else {
$action .= "&iduser=$iduser";
}
}
if($idempr){
$action.="&idempr=".$idempr;
}
if($user_input){
$action.="&user_input=".$user_input;
}
if($date_debut){
$action.="&date_debut=".$date_debut;
}
if($date_fin){
$action.="&date_fin=".$date_fin;
}
if($id_type){
$action.="&id_type=".$id_type;
}
if($id_theme){
$action.="&id_theme=".$id_theme;
}
if($dmde_loc){
$action.="&dmde_loc=".$dmde_loc;
}
$action.="'\"";
// affichage en gras si nouveauté du côté des notes ou des actions
$dmde->dmde_read_gestion = demandes::dmde_majRead($dmde->id_demande,"_gestion");
if($dmde->dmde_read_gestion == 1){
$style=" style='cursor: pointer; font-weight:bold'";
} else {
$style=" style='cursor: pointer'";
}
$liste .= "";
$carac_empr = $dmde->getCaracEmpr($dmde->num_demandeur);
$nom_empr = $carac_empr['nom'];
$nom_user = '';
if (!empty($dmde->users)) {
foreach ($dmde->users as$user) {
if ($user['statut'] == 1) {
if (!empty($nom_user)) {
$nom_user .= "/ ";
}
$nom_user .= $user['nom'];
}
}
}
$liste .= " id_demande."','$dmde->id_demande', true); return false;\" title=\"\" id=\"action".$dmde->id_demande."Img\" name=\"imEx\" class=\"img_plus\" src=\"".get_url_icon('plus.gif')."\"> ";
$liste .= "";
if($dmde->dmde_read_gestion == 1){
// remplacer $action le jour où on décide d'activer la modif d'état manuellement par onclick=\"change_read_dmde('dmde".$dmde->id_demande."','$dmde->id_demande', true); return false;\"
$liste .= " id_demande."Img1\" class=\"img_plus\" src='".get_url_icon('notification_empty.png')."' style='display:none'>
id_demande."Img2\" class=\"img_plus\" src='".get_url_icon('notification_new.png')."'>";
} else {
// remplacer $action le jour où on décide d'activer la modif d'état manuellement par onclick=\"change_read_dmde('dmde".$dmde->id_demande."','$dmde->id_demande', true); return false;\"
$liste .= " id_demande."Img1\" class=\"img_plus\" src='".get_url_icon('notification_empty.png')."' >
id_demande."Img2\" class=\"img_plus\" src='".get_url_icon('notification_new.png')."' style='display:none'>";
}
$liste .= "
".htmlentities($themes->getLabel($dmde->theme_demande),ENT_QUOTES,$charset)."
".htmlentities($types->getLabel($dmde->type_demande),ENT_QUOTES,$charset)."
".htmlentities($dmde->titre_demande,ENT_QUOTES,$charset)."
".htmlentities($dmde->workflow->getStateCommentById($dmde->etat_demande),ENT_QUOTES,$charset)."
".htmlentities(formatdate($dmde->date_demande),ENT_QUOTES,$charset)."
".htmlentities(formatdate($dmde->date_prevue),ENT_QUOTES,$charset)."
".htmlentities(formatdate($dmde->deadline_demande),ENT_QUOTES,$charset)."
".htmlentities($nom_empr,ENT_QUOTES,$charset)."
".htmlentities($nom_user,ENT_QUOTES,$charset)."
progression."%\" title='".$dmde->progression."%' />
";
$perso_=$p_perso->show_fields($dmde->id_demande);
if(isset($perso_["FIELDS"])) {
for ($i=0; $i";
}
}
if($dmde->num_linked_notice)
$liste .= " ";
else $liste .= " ";
$liste .= " ";
$liste .= " ";
//Le détail de l'action, contient les notes
$liste .="id_demande."Child\" style=\"display:none\">
id_demande."ChildTd\">";
$liste .="
";
}
$btn_suppr = " ";
//afficher la liste des boutons de changement d'état
if($idetat){
$states = $this->workflow->getStateList($idetat);
$states_btn = $this->getDisplayStateBtn($states,1);
}
if($iduser==-1){
$affectation_btn = " ".$this->getUsersSelector();
}
} else {
$liste .= "".$msg['demandes_liste_vide']." ";
}
$form_liste_demande = str_replace('!!header_champs_perso!!',$header_champs_perso,$form_liste_demande);
$form_liste_demande = str_replace('!!btn_etat!!',$states_btn,$form_liste_demande);
$form_liste_demande = str_replace('!!btn_attribue!!',$affectation_btn,$form_liste_demande);
$form_liste_demande = str_replace('!!btn_suppr!!',$btn_suppr,$form_liste_demande);
$form_liste_demande = str_replace('!!count_dmde!!',($nb_demandes ? '('.$nb_demandes.')' : ''),$form_liste_demande);
$form_liste_demande = str_replace('!!liste_dmde!!',$liste,$form_liste_demande);
print $form_liste_demande;
}
public function set_properties_from_form() {
global $sujet,$iddemande ,$idetat, $titre, $id_theme, $id_type;
global $date_debut, $date_fin, $date_prevue, $idempr;
global $iduser, $progression, $demandes_statut_notice, $linked_record_id;
$this->id_demande = intval($iddemande);
$this->titre_demande = stripslashes($titre);
$this->sujet_demande = stripslashes($sujet);
$this->date_demande = $date_debut;
$this->date_prevue = $date_prevue;
$this->deadline_demande = $date_fin;
$this->num_user = intval($iduser);
$this->progression = $progression;
$this->num_demandeur = intval($idempr);
$this->type_demande = intval($id_type);
$this->theme_demande = intval($id_theme);
$this->etat_demande = intval($idetat);
if (!isset($linked_record_id)) $linked_record_id = 0;
$this->set_num_linked_notice($linked_record_id);
$this->num_user_cloture = '';
if($this->etat_demande == 4 || $this->etat_demande == 5 ) {
$this->num_user_cloture=SESSuserid;
}
//Création d'une stdClass (pour alleger) => doit matcher à une notice, mais un peu lourd ...
$this->notice=new stdClass();
$this->notice->tit1=$this->titre_demande;
$this->notice->n_contenu=$this->sujet_demande;
$this->notice->notice_id=$this->num_notice;
$this->notice->statut=$demandes_statut_notice;
}
protected function save_notice(){
global $demandes_notice_auto, $gestion_acces_active, $gestion_acces_user_notice, $gestion_acces_empr_notice;
global $pmb_type_audit;
//CREATION de la notice associée
if($demandes_notice_auto === "1"){
$query = "INSERT INTO notices SET
tit1='".$this->notice->tit1."',
n_contenu='".$this->notice->n_contenu."',
statut ='".$this->notice->statut."',
create_date='".date('Y-m-d H:i:s')."'";
pmb_mysql_query($query);
$this->num_notice= $this->notice->num_notice = pmb_mysql_insert_id();
notice::majNotices($this->num_notice);
if($pmb_type_audit) audit::insert_creation(AUDIT_NOTICE,$this->num_notice);
//droits d'acces
if ($gestion_acces_active==1) {
$ac= new acces();
//traitement des droits acces user_notice
if ($gestion_acces_user_notice==1) {
$dom_1= $ac->setDomain(1);
$dom_1->storeUserRights(0, $this->num_notice);
}
//traitement des droits acces empr_notice
if ($gestion_acces_empr_notice==1) {
$dom_2= $ac->setDomain(2);
$dom_2->storeUserRights(0, $this->num_notice);
}
}
}
}
protected function save_demandes_users() {
//Enregistrement dans demandes_users
$date_creation = date("Y-m-d",time());
if (!empty($this->id_demande) && !empty($this->num_user)) {
$query = "UPDATE demandes_users SET users_statut=0 WHERE num_user NOT IN (".implode(',',$this->num_user).") AND num_demande='$this->id_demande'";
pmb_mysql_query($query);
$query = "UPDATE demandes_users SET users_statut=1 WHERE num_user IN (".implode(',',$this->num_user).") AND num_demande='$this->id_demande'";
pmb_mysql_query($query);
foreach ($this->num_user as $id_user) {
$query = "insert into demandes_users set num_user='$id_user', num_demande='$this->id_demande', date_creation='$date_creation', users_statut=1";
pmb_mysql_query($query);
}
} elseif (!empty($this->id_demande) && empty($this->num_user)) {
$query = "UPDATE demandes_users SET users_statut=0 WHERE num_demande='$this->id_demande'";
pmb_mysql_query($query);
}
}
/*
* Création/Modification d'une demande
*/
public function save(){
global $pmb_type_audit;
if($this->id_demande){
//MODIFICATION
$query = "UPDATE demandes SET
sujet_demande='".addslashes($this->sujet_demande)."',
num_demandeur='".$this->num_demandeur."',
date_demande='".$this->date_demande."',
deadline_demande='".$this->deadline_demande."',
date_prevue='".$this->date_prevue."',
progression='".$this->progression."',
titre_demande='".addslashes($this->titre_demande)."',
type_demande='".$this->type_demande."',
theme_demande='".$this->theme_demande."',
num_user_cloture='".$this->num_user_cloture."',
num_linked_notice = '".$this->get_num_linked_notice()."'
WHERE id_demande='".$this->id_demande."'";
pmb_mysql_query($query);
if($pmb_type_audit) audit::insert_modif(AUDIT_DEMANDE,$this->id_demande);
} else {
//On ajoute une notice ?
$this->save_notice();
//CREATION de la demande
$query = "INSERT INTO demandes SET
sujet_demande='".addslashes($this->sujet_demande)."',
etat_demande='".$this->etat_demande."',
num_demandeur='".$this->num_demandeur."',
date_demande='".$this->date_demande."',
date_prevue='".$this->date_prevue."',
deadline_demande='".$this->deadline_demande."',
progression='".$this->progression."',
titre_demande='".addslashes($this->titre_demande)."',
type_demande='".$this->type_demande."',
theme_demande='".$this->theme_demande."',
num_notice='".$this->num_notice."',
dmde_read_opac='1',
num_linked_notice = '".$this->get_num_linked_notice()."'" ;
pmb_mysql_query($query);
$this->id_demande = pmb_mysql_insert_id();
if($pmb_type_audit) audit::insert_creation(AUDIT_DEMANDE,$this->id_demande);
}
//Vérification des champs personalisés
$p_perso=new parametres_perso("demandes");
$nberrors=$p_perso->check_submited_fields();
if ($nberrors) {
error_message_history("",$p_perso->error_message,1);
} else {
//Insertion des champs personalisés
$p_perso->rec_fields_perso($this->id_demande);
}
//MAJ des users de la demande
$this->save_demandes_users();
}
/*
* Suppression d'une demande
*/
public static function delete($demande){
global $delnoti;
if($demande->id_demande){
$demande->fetch_data($demande->id_demande,false);
if($delnoti){
//Si on supprime la notice associée
$query = "SELECT num_notice FROM demandes WHERE id_demande = ".$demande->id_demande." AND num_notice!=0";
$result = pmb_mysql_query($query);
if(pmb_mysql_num_rows($result)){
notice::del_notice(pmb_mysql_result($result,0,0));
}
}
// suppression des actions et des notes
if (!empty($demande->actions)) {
foreach($demande->actions as $action) {
demandes_actions::delete($action);
}
}
// suppression des liens user - demande
$req = "delete from demandes_users where num_demande='".$demande->id_demande."'";
pmb_mysql_query($req);
//suppression des doc num
$req = "delete ed,eda from explnum_doc ed
join explnum_doc_actions eda on ed.id_explnum_doc=eda.num_explnum_doc
join demandes_actions da on eda.num_action=da.id_action
where da.num_demande=".$demande->id_demande;
pmb_mysql_query($req);
// suppression des valeurs de CP
$p_perso=new parametres_perso("demandes");
$p_perso->delete_values($demande->id_demande);
// suppression de la demande
$req = "delete from demandes where id_demande='".$demande->id_demande."'";
pmb_mysql_query($req);
//suppression de l'audit
audit::delete_audit(AUDIT_DEMANDE,$demande->id_demande);
}
}
/*
* Retourne le sélecteur des états de la demandes
*/
public function getStateSelector($idetat=0,$action='',$default=false){
global $charset, $msg;
$selector = "";
$select="";
if($default) $selector .= "".htmlentities($msg['demandes_all_states'],ENT_QUOTES,$charset)." ";
for($i=1;$i<=count($this->liste_etat);$i++){
if($idetat == $i) $select = "selected";
$selector .= "".htmlentities($this->liste_etat[$i]['comment'],ENT_QUOTES,$charset)." ";
$select = "";
}
$selector .= " ";
return $selector;
}
/*
* Retourne le sélecteur des utilisateurs ayant le droit aux demandes
*/
public function getUsersSelector($action='',$default=false,$multiple=false,$nonassign=false){
global $charset,$msg, $iduser;
if($multiple)
$mul = " name='iduser[]' multiple ";
else $mul = " name='iduser' ";
if(!$this->id_demande){
$req="select TRIM(concat(prenom,' ',nom)) as name, userid, 0 as actif, username
from users
where rights&16384 order by name";
} else {
$req="select TRIM(concat(prenom,' ',nom)) as name, userid , if(isnull(num_demande),0,if((users_statut),1,0)) as actif, username
from users
left join demandes_users on (num_user=userid and num_demande='".$this->id_demande."')
where rights&16384 order by name";
}
$res = pmb_mysql_query($req);
$select = "";
$selector = "";
if($default) $selector .= "".htmlentities($msg['demandes_all_users'],ENT_QUOTES,$charset)." ";
if($nonassign) $selector .= "".htmlentities($msg['demandes_not_assigned'],ENT_QUOTES,$charset)." ";
while(($user=pmb_mysql_fetch_object($res))){
if($user->actif) $select="selected";
$name = (trim($user->name) ? $user->name :$user->username);
if($iduser == $user->userid) $select="selected";
$selector .= "".htmlentities($name,ENT_QUOTES,$charset)." ";
$select = "";
}
$selector .= " ";
return $selector;
}
/*
* Retourne le nom de l'utilisateur (celui qui traitera la demande)
*/
public function getUserLib($iduser){
$req = "select concat(prenom,' ',nom) as nom, userid, username from users where userid='".$iduser."'";
$res = pmb_mysql_query($req);
$user = pmb_mysql_fetch_object($res);
return ( trim($user->nom) ? $user->nom : $user->username );
}
/*
* Retourne les caractéristiques de l'emprunteur qui effectue la demande
*/
public function getCaracEmpr($idempr){
$req = "select concat(empr_prenom,' ',empr_nom) as nom, id_empr,empr_cb from empr where id_empr='".$idempr."'";
$res = pmb_mysql_query($req);
$empr = pmb_mysql_fetch_array($res);
return $empr;
}
/*
* Fonction qui retourne la requete de filtre
*/
public static function getQueryFilter($idetat,$iduser,$idempr,$user_input,$date_dmde,$date_but,$id_theme,$id_type,$dmde_loc){
$date_deb = str_replace('-','',$date_dmde);
$date_fin = str_replace('-','',$date_but);
$params = array();
//Filtre d'etat
if($idetat){
$etat = " etat_demande = '".$idetat."'";
$params[] = $etat;
}
//Filtre d'utilisateur
$join_filtre_user="";
if($iduser){
if($iduser == -1)
$user = " nom is null ";
else $user = " duf.num_user = '".(is_array($iduser) ? $iduser[0] : $iduser)."' and duf.users_statut=1";
$join_filtre_user = "left join demandes_users duf on (duf.num_demande=d.id_demande )";
$params[] = $user;
}
//Filtre de demandeur
if($idempr){
$empr = " num_demandeur = '".$idempr."'";
$params[] = $empr;
}
//Filtre de recherche
if($user_input){
$user_input = str_replace('*','%',$user_input);
$saisie = " titre_demande like '%".$user_input."%'";
$params[] = $saisie;
}
//Filtre date
if($date_deb<$date_fin){
$date = " (date_demande >= '".$date_dmde."' and deadline_demande <= '".$date_but."' )";
$params[] = $date;
}
//Filtre theme
if($id_theme){
$theme = " theme_demande = '".$id_theme."'";
$params[] = $theme;
}
//Filtre type
if($id_type){
$type = " type_demande = '".$id_type."'";
$params[] = $type;
}
//Filtre localisation
$join_loc="";
if($dmde_loc){
$join_loc = "left join empr on (num_demandeur=id_empr)";
$loc = " empr_location = '".$dmde_loc."'";
$params[] = $loc;
}
//Champs perso
$join_cp="";
$p_perso=new parametres_perso("demandes");
$perso_=$p_perso->read_search_fields_from_form();
if(isset($perso_["FIELDS"])) {
for ($i=0; $ititre_demande,ENT_QUOTES,$charset),$form_consult_dmde);
$form_consult_dmde = str_replace('!!sujet_dmde!!',htmlentities($this->sujet_demande,ENT_QUOTES,$charset),$form_consult_dmde);
$form_consult_dmde = str_replace('!!etat_dmde!!',htmlentities($this->workflow->getStateCommentById($this->etat_demande),ENT_QUOTES,$charset),$form_consult_dmde);
$form_consult_dmde = str_replace('!!date_dmde!!',htmlentities(formatdate($this->date_demande),ENT_QUOTES,$charset),$form_consult_dmde);
$form_consult_dmde = str_replace('!!date_butoir_dmde!!',htmlentities(formatdate($this->deadline_demande),ENT_QUOTES,$charset),$form_consult_dmde);
$form_consult_dmde = str_replace('!!date_prevue_dmde!!',htmlentities(formatdate($this->date_prevue),ENT_QUOTES,$charset),$form_consult_dmde);
$form_consult_dmde = str_replace('!!progression_dmde!!',htmlentities($this->progression.'%',ENT_QUOTES,$charset),$form_consult_dmde);
$nom_user = '';
if (!empty($this->users)) {
foreach ($this->users as $user) {
if ($user['statut'] == 1) {
if (!empty($nom_user)) {
$nom_user .= " / ";
}
$nom_user .= $user['nom'];
}
}
}
$carac_empr = $this->getCaracEmpr($this->num_demandeur);
$nom = $carac_empr['nom'];
$cb = $carac_empr['empr_cb'];
$nom_emprunteur ="";
if(SESSrights & CIRCULATION_AUTH)
$nom_emprunteur = "".htmlentities($nom,ENT_QUOTES,$charset)." ";
$form_consult_dmde = str_replace('!!demandeur!!',($nom_emprunteur ? $nom_emprunteur :$nom),$form_consult_dmde);
$form_consult_dmde = str_replace('!!attribution!!',$nom_user,$form_consult_dmde);
$form_consult_dmde = str_replace('!!iddemande!!',$this->id_demande,$form_consult_dmde);
$form_consult_dmde = str_replace('!!theme_dmde!!',htmlentities($this->theme_libelle,ENT_QUOTES,$charset),$form_consult_dmde);
$form_consult_dmde = str_replace('!!type_dmde!!',htmlentities($this->type_libelle,ENT_QUOTES,$charset),$form_consult_dmde);
if ($this->num_linked_notice) {
$display = new mono_display($this->num_linked_notice, 0, '', 0, '', '', '',0, 0, 0, 0,"", 0, false, true);
$form_consult_dmde = str_replace('!!form_linked_record!!',$form_consult_linked_record,$form_consult_dmde);
$form_consult_dmde = str_replace('!!linked_record!!',htmlentities($display->header_texte, ENT_QUOTES, $charset),$form_consult_dmde);
$form_consult_dmde = str_replace('!!linked_record_icon!!', $display->icondoc, $form_consult_dmde);
$form_consult_dmde = str_replace('!!linked_record_id!!',htmlentities($this->num_linked_notice, ENT_QUOTES, $charset),$form_consult_dmde);
$form_consult_dmde = str_replace('!!linked_record_link!!',htmlentities($url_base."catalog.php?categ=isbd&id=".$this->num_linked_notice, ENT_QUOTES, $charset),$form_consult_dmde);
} else {
$form_consult_dmde = str_replace('!!form_linked_record!!'," ",$form_consult_dmde);
}
//Champs personalisés
$perso_aff = "" ;
$p_perso = new parametres_perso("demandes");
if (!$p_perso->no_special_fields) {
$perso_=$p_perso->show_fields($this->id_demande);
for ($i=0; $ietat_demande) && !empty($this->users)) || $demandes_init_workflow !== "2") {
$states = $this->workflow->getStateList($this->etat_demande);
$states_btn = $this->getDisplayStateBtn($states);
$form_consult_dmde = str_replace('!!btn_etat!!', $states_btn, $form_consult_dmde);
} else {
$form_consult_dmde = str_replace('!!btn_etat!!', "", $form_consult_dmde);
}
//afficher la liste des boutons de la notice
if($this->num_notice != 0){
$notice = "num_notice."')\" href='#'> ";
} else {
$notice = "";
}
$form_consult_dmde = str_replace('!!icone!!',$notice,$form_consult_dmde);
if (!empty($this->users) || $demandes_init_workflow !== "2") {
$req = "select count(1) as nb from demandes join demandes_actions on id_demande=num_demande join explnum_doc_actions on num_action=id_action where id_demande='".$this->id_demande."'";
$res = pmb_mysql_query($req);
$docnum = pmb_mysql_fetch_object($res);
// bouton doc num
if($docnum->nb){
$btn_attach = " ";
} else $btn_attach = "";
// boutons notice
if($this->num_notice != 0){
$btn_notices = " ".
$btn_attach." ";
$btn_suppr_notice = " ";
} else {
$btn_notices = " ".
$btn_attach."
";
$btn_suppr_notice = "";
}
// bouton audit
if($pmb_type_audit){
$btn_audit = audit::get_dialog_button($this->id_demande, 14);
} else {
$btn_audit = "";
}
// affichage des boutons de création de la réponse finale
$btn_repfinal = $btn_faq ="";
if($this->etat_demande == 4){
if(!$this->reponse_finale || $this->reponse_finale==''){
$btn_repfinal = " ";
}
}
if($this->etat_demande == 4){
if(!$this->num_faq_question){
$btn_faq = " ";
}else{
$btn_faq = " ";
}
}
$form_consult_dmde = str_replace('!!btns_notice!!',$btn_notices,$form_consult_dmde);
$form_consult_dmde = str_replace('!!btn_suppr_notice!!',$btn_suppr_notice,$form_consult_dmde);
$form_consult_dmde = str_replace('!!btn_audit!!',$btn_audit,$form_consult_dmde);
$form_consult_dmde = str_replace('!!btn_repfinal!!',$btn_repfinal,$form_consult_dmde);
$form_consult_dmde = str_replace('!!btn_faq!!',$btn_faq,$form_consult_dmde);
} else {
$form_consult_dmde = str_replace('!!btns_notice!!',"",$form_consult_dmde);
$form_consult_dmde = str_replace('!!btn_suppr_notice!!',"",$form_consult_dmde);
$form_consult_dmde = str_replace('!!btn_audit!!',"",$form_consult_dmde);
$form_consult_dmde = str_replace('!!btn_repfinal!!',$btn_repfinal,$form_consult_dmde);
$form_consult_dmde = str_replace('!!btn_faq!!',"",$form_consult_dmde);
}
//construction de l'url de retour
$params_retour='';
if($idetat){
$params_retour.="&idetat=".$idetat;
}
if($iduser){
$params_retour.="&iduser=".$iduser;
}
if($idempr){
$params_retour.="&idempr=".$idempr;
}
if($user_input){
$params_retour.="&user_input=".$user_input;
}
if($date_debut){
$params_retour.="&date_debut=".$date_debut;
}
if($date_fin){
$params_retour.="&date_fin=".$date_fin;
}
if($id_type){
$params_retour.="&id_type=".$id_type;
}
if($id_theme){
$params_retour.="&id_theme=".$id_theme;
}
if($dmde_loc){
$params_retour.="&dmde_loc=".$dmde_loc;
}
if($params_retour){
$form_consult_dmde=str_replace('!!params_retour!!',htmlentities(stripslashes($params_retour),ENT_QUOTES, $charset),$form_consult_dmde);
}else{
$form_consult_dmde=str_replace('!!params_retour!!',"",$form_consult_dmde);
}
if (!empty($this->users) || $demandes_init_workflow !== "2") {
//Liste des actions
$this->fetch_data($this->id_demande,false);
if($this->etat_demande == 4 || $this->etat_demande == 5){
$form_consult_dmde.=demandes_actions::show_list_actions($this->actions, $this->id_demande);
}elseif($last_modified){
$form_consult_dmde.=demandes_actions::show_list_actions($this->actions, $this->id_demande,$last_modified);
}elseif($this->last_modified){
$form_consult_dmde.=demandes_actions::show_list_actions($this->actions, $this->id_demande,$this->last_modified->id_action);
}elseif($this->last_modified){
$form_consult_dmde.=demandes_actions::show_list_actions($this->actions, $this->id_demande,$this->last_modified->id_action);
}else{
$form_consult_dmde.=demandes_actions::show_list_actions($this->actions, $this->id_demande);
}
}
if($this->etat_demande == 4 && $this->reponse_finale != ''){
$reponse_finale = str_replace('!!repfinale!!',$this->reponse_finale,$reponse_finale);
$reponse_finale = str_replace('!!iddemande!!',htmlentities($this->id_demande,ENT_QUOTES,$charset),$reponse_finale);
$act_form = "./demandes.php?categ=gestion";
$reponse_finale = str_replace('!!form_action!!',htmlentities($act_form,ENT_QUOTES,$charset),$reponse_finale);
$form_consult_dmde.= $reponse_finale;
}
if ($this->etat_demande == 1 && empty($this->actions) && $this->dmde_read_gestion == 1) {
demandes::demande_read($this->id_demande, true, "_gestion");
$this->fetch_data($this->id_demande, false);
}
print $form_consult_dmde;
}
/*
* Affiche la liste des boutons correspondants à l'état en cours
*/
public function getDisplayStateBtn($list_etat=array(),$multi=0){
global $charset,$msg;
if($multi){
$message = $msg['demandes_change_checked_states'];
} else $message = $msg['demandes_change_state'];
$display = "".$message." : ";
for($i=0;$i";
}
return $display;
}
/*
* Changement d'etat d'une demande
*/
public function change_state($state){
global $demandes_init_workflow, $demandes_default_action, $pmb_type_audit;
global $PMBuserid;
global $idstatut;
if($demandes_init_workflow==="1" && $PMBuserid){
//La demande est elle attribué à un utilisateur ?
$query='SELECT 1 FROM demandes_users WHERE num_demande='.$this->id_demande;
$result=pmb_mysql_query($query);
if(!pmb_mysql_num_rows($result)){
//si non, on attribue
$query='INSERT INTO demandes_users SET num_user="'.$PMBuserid.'", num_demande="'.$this->id_demande.'", date_creation="'.date("Y-m-d",time()).'", users_statut=1';
pmb_mysql_query($query);
}
}
$req = "update demandes set etat_demande=$state where id_demande='".$this->id_demande."'";
pmb_mysql_query($req);
if($state == 2 && $demandes_default_action === "1"){
$query = "SELECT id_action FROM demandes_actions WHERE num_demande=".$this->id_demande;
$result = pmb_mysql_query($query);
if(!pmb_mysql_num_rows($result)){
$action_default = new demandes_actions();
$action_default->num_demande = $this->id_demande;
$action_default->actions_num_user = $this->num_demandeur;
$action_default->actions_type_user =1;
$action_default->date_action = date("Y-m-d",time());
$action_default->deadline_action = date("Y-m-d",time());
if($action_default->list_statut){
$action_default->statut_action = "";
foreach($action_default->list_statut as $value){
if(!empty($value['default'])) {
$action_default->statut_action = $value['id'];
}
}
if($idstatut == "" && !$action_default->statut_action) {
reset($action_default->list_statut);
$first_statut = current($action_default->list_statut);
$action_default->statut_action = $first_statut['id'];
}
}
$action_default->type_action = $this->first_action;
$action_default->sujet_action = addslashes($this->titre_demande);
$action_default->detail_action = addslashes($this->sujet_demande);
$action_default->save();
}
}
if($pmb_type_audit) audit::insert_modif(AUDIT_DEMANDE,$this->id_demande);
}
/*
* Montre la liste des documents pouvant etre inclus dans le document
*/
public function show_docnum_to_attach(){
global $form_liste_docnum, $msg, $charset, $base_path, $pmb_indexation_docnum_default;
$req="select id_explnum_doc as id, explnum_doc_nomfichier as nom, num_explnum,
concat(explnum_index_sew,'',explnum_index_wew) as indexer
from explnum_doc
join explnum_doc_actions on (id_explnum_doc=num_explnum_doc and rapport=1)
join demandes_actions on num_action=id_action
left join explnum on explnum_id=num_explnum
where num_demande='".$this->id_demande."'";
$res = pmb_mysql_query($req);
$liste="";
if(pmb_mysql_num_rows($res)){
while(($doc = pmb_mysql_fetch_object($res))){
if($doc->num_explnum) {
$check = 'checked';
}
if($pmb_indexation_docnum_default || $doc->indexer){
$check_index = 'checked';
}
$liste .= "
";
$check = "";
$check_index = "";
}
$btn_attach = " ";
$form_liste_docnum = str_replace('!!btn_attach!!',$btn_attach,$form_liste_docnum);
} else {
$liste = htmlentities($msg['demandes_no_docnum'],ENT_QUOTES,$charset);
$form_liste_docnum = str_replace('!!btn_attach!!','',$form_liste_docnum);
}
$form_liste_docnum = str_replace('!!liste_docnum!!',$liste,$form_liste_docnum);
$form_liste_docnum = str_replace('!!iddemande!!',$this->id_demande,$form_liste_docnum);
print $form_liste_docnum;
}
/*
* Attache les documents numériques à la notice
*/
public function attach_docnum(){
global $chk, $ck_index, $pmb_indexation_docnum;
for($i=0;$inum_notice."','".addslashes($expl->nom)."','".addslashes($expl->nom)."','".addslashes($expl->mime)."','".addslashes($expl->data)."','".addslashes($expl->ext)."')";
pmb_mysql_query($req);
$id_explnum = pmb_mysql_insert_id();
$req = "update explnum_doc_actions set num_explnum='".$id_explnum."' where num_explnum_doc='".$chk[$i]."'";
pmb_mysql_query($req);
if($ck_index[$i] && $pmb_indexation_docnum){
$expl = new explnum($id_explnum);
$expl->indexer_docnum();
}
}
}
//On désattache les autres
if($chk){
$req = "select id_explnum_doc from explnum_doc where id_explnum_doc not in ('".implode('\',\'',$chk)."')";
$res = pmb_mysql_query($req);
while(($expl = pmb_mysql_fetch_object($res))){
$req = "delete e from explnum e
join explnum_doc_actions on num_explnum=explnum_id
where num_explnum_doc='".$expl->id_explnum_doc."'";
pmb_mysql_query($req);
$req = "update explnum_doc_actions set num_explnum='0' where num_explnum_doc='".$expl->id_explnum_doc."'";
pmb_mysql_query($req);
}
} else {
$req ="select id_explnum_doc
from explnum_doc
join explnum_doc_actions on num_explnum_doc=id_explnum_doc
join demandes_actions on num_action=id_action
where num_explnum != 0
and num_demande='".$this->id_demande."'";
$res = pmb_mysql_query($req);
while(($expl = pmb_mysql_fetch_object($res))){
$req = "delete e from explnum e
join explnum_doc_actions on num_explnum=explnum_id
where num_explnum_doc='".$expl->id_explnum_doc."'";
pmb_mysql_query($req);
$req = "update explnum_doc_actions set num_explnum='0' where num_explnum_doc='".$expl->id_explnum_doc."'";
pmb_mysql_query($req);
}
}
}
/*
* Affiche le formulaire de création/modification d'une notice
*/
public function show_notice_form(){
// affichage du form de création/modification d'une notice
$myNotice = new notice($this->num_notice);
if(!$myNotice->id) {
$myNotice->tit1 = $this->titre_demande;
}
$myNotice->action = "./demandes.php?categ=gestion&act=upd_notice&iddemande=".$this->id_demande."&id=";
$myNotice->link_annul = $this->get_gestion_link();
print $myNotice->show_form();
}
/*
* Formulaire de validation de la suppression de notice
*/
public function suppr_notice_form(){
global $msg, $chk, $iddemande, $current_module;
$display = "
";
print $display;
}
public function attribuer(){
global $chk, $iduser;
for($i=0;$i action est déjà lue donc pas d'alerte
* false => alerte
*/
public static function demande_read($id_demande,$booleen=true,$side="_gestion"){
$value = "";
if($booleen){
$value = 0;
} else {
$value = 1;
}
$query = "UPDATE demandes SET dmde_read".$side."=".$value." WHERE id_demande=".$id_demande;
if(pmb_mysql_query($query)){
return true;
} else {
return false;
}
}
// mise à jour de l'alerte sur les actions et les notes de la demande
public static function dmde_propageLu($id_demande,$side="_gestion"){
if($id_demande){
$dmde = new demandes($id_demande);
$read = demandes::read($dmde,$side);
if($read){
$query1 = "UPDATE demandes_actions SET actions_read".$side."=0 WHERE num_demande=".$id_demande;
pmb_mysql_query($query1);
$query2 = "SELECT id_action FROM demandes_actions WHERE num_demande=".$id_demande;
$result2 = pmb_mysql_query($query2);
if(pmb_mysql_num_rows($result2)){
while($action = pmb_mysql_fetch_object($result2)){
$query3 = "UPDATE demandes_notes SET notes_read".$side."=0 WHERE num_action=".$action->id_action;
pmb_mysql_query($query3);
}
}
return "lu";
} else {
return "nonlu";
}
}
}
/*
* Formulaire de création d'une demande
*/
public function show_repfinale_form(){
global $form_reponse_final, $msg, $charset, $pmb_javascript_office_editor,$base_path;
if($pmb_javascript_office_editor){
print $pmb_javascript_office_editor;
print "";
}
$form_reponse_final = str_replace('!!titre_dmde!!',htmlentities($this->titre_demande,ENT_QUOTES,$charset),$form_reponse_final);
$form_reponse_final = str_replace('!!form_title!!',htmlentities($msg['demandes_reponse_finale'],ENT_QUOTES,$charset),$form_reponse_final);
$form_reponse_final = str_replace('!!theme_dmde!!',htmlentities($this->theme_libelle,ENT_QUOTES,$charset),$form_reponse_final);
$form_reponse_final = str_replace('!!type_dmde!!',htmlentities($this->type_libelle,ENT_QUOTES,$charset),$form_reponse_final);
$form_reponse_final = str_replace('!!sujet_dmde!!',htmlentities($this->sujet_demande,ENT_QUOTES,$charset),$form_reponse_final);
$form_reponse_final = str_replace('!!iddemande!!',htmlentities($this->id_demande,ENT_QUOTES,$charset),$form_reponse_final);
$act_cancel = "document.location='".$this->get_gestion_link()."'";
$act_form = "./demandes.php?categ=gestion";
if(!$this->reponse_finale){
$form_reponse_final = str_replace('!!reponse!!','',$form_reponse_final);
$form_reponse_final = str_replace('!!btn_suppr!!','',$form_reponse_final);
} else {
$form_reponse_final = str_replace('!!reponse!!',htmlentities($this->reponse_finale,ENT_QUOTES,$charset),$form_reponse_final);
$btn_suppr = " ";
$form_reponse_final = str_replace('!!btn_suppr!!',$btn_suppr,$form_reponse_final);
}
$form_reponse_final = str_replace('!!form_action!!',$act_form,$form_reponse_final);
$form_reponse_final = str_replace('!!cancel_action!!',$act_cancel,$form_reponse_final);
print $form_reponse_final;
}
/*
* Formulaire de création d'une demande
*/
public function save_repfinale($id_note=0){
global $f_message;
$f_message=strip_tags($f_message);
if($this->id_demande){
$query = "UPDATE demandes SET reponse_finale='".$f_message."', demande_note_num=$id_note WHERE id_demande=".$this->id_demande;
pmb_mysql_query($query);
}
}
/*
* Formulaire de création d'une demande
*/
public function suppr_repfinale(){
if($this->id_demande){
$query = "UPDATE demandes SET reponse_finale='' WHERE id_demande=".$this->id_demande;
pmb_mysql_query($query);
}
}
/**
* Retourne l'identifiant de la notice liée
* @return int
*/
public function get_num_linked_notice() {
return $this->num_linked_notice;
}
/**
* Setter de l'identifiant de la notice liée à la demande
* @param int $num_linked_notice
*/
public function set_num_linked_notice($num_linked_notice) {
$this->num_linked_notice = $num_linked_notice;
}
public function get_gestion_link(){
global $base_path;
return $base_path.'/demandes.php?categ=gestion&act=see_dmde&iddemande='.$this->id_demande;
}
public function get_id() {
return $this->id_demande;
}
}
?>