fetch_data($id_note,$id_action); } function fetch_data($id_note=0,$id_action=0){ global $dbh; if($this->id_note && !$id_note){ $id_note=$this->id_note; }elseif(!$this->id_note && $id_note){ $this->id_note=$id_note; } if($this->num_action && !$id_action){ $id_action=$this->num_action; }elseif(!$this->num_action && $id_action){ $this->num_action=$id_action; } if($this->id_note){ $req = "select id_note, prive, rapport,contenu,date_note, sujet_action, id_demande, titre_demande, notes_num_user, notes_type_user, num_action, num_note_parent, notes_read_gestion, notes_read_opac from demandes_notes join demandes_actions on num_action=id_action join demandes on num_demande=id_demande where id_note='".$this->id_note."'"; $res = pmb_mysql_query($req,$dbh); if(pmb_mysql_num_rows($res)){ $obj = pmb_mysql_fetch_object($res); $this->date_note = $obj->date_note; $this->contenu = $obj->contenu; $this->rapport = $obj->rapport; $this->prive = $obj->prive; $this->num_note_parent = $obj->num_note_parent; $this->num_action = $obj->num_action; $this->libelle_action = $obj->sujet_action; $this->libelle_demande = $obj->titre_demande; $this->num_demande = $obj->id_demande; $this->notes_num_user = $obj->notes_num_user; $this->notes_type_user = $obj->notes_type_user; $this->notes_read_gestion = $obj->notes_read_gestion; $this->notes_read_opac = $obj->notes_read_opac; } else { $this->date_note = '0000-00-00 00:00:00'; $this->contenu = ''; $this->rapport = 0; $this->prive = 0; $this->num_note_parent = 0; $this->num_action = 0; $this->notes_num_user = 0; $this->notes_type_user = 0; $this->notes_read_gestion = 0; $this->notes_read_opac = 0; } } else { $this->date_note = '0000-00-00 00:00:00'; $this->contenu = ''; $this->rapport = 0; $this->prive = 0; $this->num_note_parent = 0; $this->notes_num_user = 0; $this->notes_type_user = 0; $this->notes_read_gestion = 0; $this->notes_read_opac = 0; } if($this->num_action){ $req = "select sujet_action, titre_demande, id_demande from demandes_actions join demandes on num_demande=id_demande where id_action='".$this->num_action."' "; $res = pmb_mysql_query($req,$dbh); $obj = pmb_mysql_fetch_object($res); $this->libelle_action = $obj->sujet_action; $this->libelle_demande = $obj->titre_demande; $this->num_demande = $obj->id_demande; } if($this->notes_num_user){ $this->createur_note = $this->getCreateur($this->notes_num_user,$this->notes_type_user); } } /* * Formulaire d'ajout/modification */ function show_modif_form($reply=false){ global $form_modif_note, $msg, $charset, $demandes_include_note; $act_cancel = "document.location='./demandes.php?categ=action&act=see&idaction=$this->num_action#fin'"; $form_modif_note = str_replace('!!cancel_action!!',$act_cancel,$form_modif_note); $form_modif_note = str_replace('!!iduser!!',$this->notes_num_user,$form_modif_note); $form_modif_note = str_replace('!!typeuser!!',$this->notes_type_user,$form_modif_note); if($this->id_note && !$reply){ $title = (strlen($this->contenu)>30 ? substr($this->contenu,0,30).'...' : $this->contenu); $form_modif_note = str_replace('!!form_title!!',$msg['demandes_note_modif'].' : '.$title,$form_modif_note); $form_modif_note = str_replace('!!contenu!!',htmlentities($this->contenu,ENT_QUOTES,$charset),$form_modif_note); if($this->rapport){ $form_modif_note = str_replace('!!ck_rapport!!','checked',$form_modif_note); }else{ $form_modif_note = str_replace('!!ck_rapport!!','',$form_modif_note); } if($this->prive){ $form_modif_note = str_replace('!!ck_prive!!','checked',$form_modif_note); }else{ $form_modif_note = str_replace('!!ck_prive!!','',$form_modif_note); } if($this->notes_read_opac){ $form_modif_note = str_replace('!!ck_vue!!','',$form_modif_note); }else{ $form_modif_note = str_replace('!!ck_vue!!','checked',$form_modif_note); } $form_modif_note = str_replace('!!date_note_btn!!',formatdate($this->date_note),$form_modif_note); $form_modif_note = str_replace('!!date_note!!',$this->date_note,$form_modif_note); $form_modif_note = str_replace('!!idnote!!',$this->id_note,$form_modif_note); $form_modif_note = str_replace('!!idaction!!',$this->num_action,$form_modif_note); $btn_suppr = "id_note && $reply){ $nots = new demandes_notes($this->id_note); $title = (strlen($nots->contenu)>30 ? substr($nots->contenu,0,30).'...' : $nots->contenu); $form_modif_note = str_replace('!!form_title!!',$msg['demandes_note_reply'].' : '.$title,$form_modif_note); $form_modif_note = str_replace('!!contenu!!','',$form_modif_note); if($demandes_include_note) $form_modif_note = str_replace('!!ck_rapport!!','checked',$form_modif_note); else $form_modif_note = str_replace('!!ck_rapport!!','',$form_modif_note); $form_modif_note = str_replace('!!ck_prive!!','',$form_modif_note); $date = formatdate(today()); $date_note=date("Ymd",time()); $form_modif_note = str_replace('!!date_note_btn!!',$date,$form_modif_note); $form_modif_note = str_replace('!!date_note!!',$date_note,$form_modif_note); $form_modif_note = str_replace('!!idnote!!','',$form_modif_note); $form_modif_note = str_replace('!!idaction!!',$this->num_action,$form_modif_note); } else { $form_modif_note = str_replace('!!form_title!!',$msg['demandes_note_creation'],$form_modif_note); $form_modif_note = str_replace('!!ck_prive!!','',$form_modif_note); if($demandes_include_note) $form_modif_note = str_replace('!!ck_rapport!!','checked',$form_modif_note); else $form_modif_note = str_replace('!!ck_rapport!!','',$form_modif_note); $form_modif_note = str_replace('!!contenu!!','',$form_modif_note); $date = formatdate(today()); $date_note=date("Ymd",time()); $form_modif_note = str_replace('!!date_note_btn!!',$date,$form_modif_note); $form_modif_note = str_replace('!!date_note!!',$date_note,$form_modif_note); $form_modif_note = str_replace('!!idnote!!','',$form_modif_note); $form_modif_note = str_replace('!!idaction!!',$this->num_action,$form_modif_note); $form_modif_note = str_replace('!!parent_text!!','',$form_modif_note); $form_modif_note = str_replace('!!id_note_parent!!','',$form_modif_note); $form_modif_note = str_replace('!!style!!','',$form_modif_note); } $path = "num_demande>".htmlentities($this->libelle_demande,ENT_QUOTES,$charset).""; $path .= " > num_action>".htmlentities($this->libelle_action,ENT_QUOTES,$charset).""; $form_modif_note = str_replace('!!path!!',$path,$form_modif_note); $form_modif_note = str_replace('!!btn_suppr!!',$btn_suppr,$form_modif_note); print $form_modif_note; } static function get_values_from_form(&$note){ global $contenu_note, $idaction,$idnote ,$iddemande , $iduser,$id_empr,$typeuser; global $date_note, $ck_rapport, $ck_prive, $ck_vue,$id_note_parent, $PMBuserid; $typeuser='1'; $note->id_note=$idnote; $note->num_action=$idaction; $note->num_demande=$iddemande; $note->contenu=$contenu_note; $note->num_note_parent=$id_note_parent; if(!$date_note){ $note->date_note=date("Y-m-d h:i:s",time()); }else{ $note->date_note=$date_note; } if($ck_prive){ $note->prive=1; }else{ $note->prive=0; } if($ck_rapport){ $note->rapport=1; }else{ $note->rapport=0; } if($ck_vue){ $note->notes_read_opac=0; }else{ $note->notes_read_opac=1; } $note->notes_num_user=$id_empr; $note->notes_type_user=$typeuser; } /* * Création/Modification d'une note */ static function save(&$note){ global $dbh; global $demandes_email_demandes, $pmb_type_audit; if($note->id_note){ //MODIFICATION $query = "UPDATE demandes_notes SET contenu='".$note->contenu."', date_note='".$note->date_note."', prive='".$note->prive."', rapport='".$note->rapport."', num_action='".$note->num_action."', notes_num_user='".$note->notes_num_user."', notes_type_user='".$note->notes_type_user."', num_note_parent='".$note->num_note_parent."', notes_read_gestion='1', notes_read_opac='".$note->notes_read_opac."' WHERE id_note='".$note->id_note."'"; pmb_mysql_query($query,$dbh); if($pmb_type_audit) audit::insert_modif(AUDIT_NOTE,$note->id_note); } else { //CREATION $query = "INSERT INTO demandes_notes SET contenu='".$note->contenu."', date_note='".$note->date_note."', prive='".$note->prive."', rapport='".$note->rapport."', num_action='".$note->num_action."', notes_num_user='".$note->notes_num_user."', notes_type_user='".$note->notes_type_user."', num_note_parent='".$note->num_note_parent."', notes_read_gestion='1', notes_read_opac='".$note->notes_read_opac."'"; pmb_mysql_query($query,$dbh); $note->id_note=pmb_mysql_insert_id($dbh); if($pmb_type_audit) audit::insert_creation(AUDIT_NOTE,$note->id_note); if(!$note->prive) { if ($demandes_email_demandes){ $note->fetch_data($note->id_note,$note->num_action); $note->send_alert_by_mail($note->notes_num_user,$note); } } } } /* * Suppression d'une note */ static function delete($note){ global $dbh; if($note->id_note){ $req = "delete from demandes_notes where id_note='".$note->id_note."'"; pmb_mysql_query($req,$dbh); $req = "delete from demandes_notes where num_note_parent='".$note->id_note."'"; pmb_mysql_query($req,$dbh); audit::delete_audit(AUDIT_NOTE,$note->id_note); } } static function show_dialog($notes,$num_action,$num_demande,$redirect_to='demandes_actions-show_consultation_form'){ global $form_dialog_note, $dbh, $msg, $charset,$id_empr; $form_dialog_note = str_replace('!!redirectto!!',$redirect_to,$form_dialog_note); $form_dialog_note = str_replace('!!idaction!!',$num_action,$form_dialog_note); $form_dialog_note = str_replace('!!iddemande!!',$num_demande,$form_dialog_note); $dialog=''; if(sizeof($notes)){ foreach($notes as $idNote=>$note){ //Utilisateur ou lecteur ? if($note->notes_type_user==="1"){ $side='note_opac'; }elseif($note->notes_type_user==="0"){ $side='note_gest'; } $dialog.='
'; $dialog.='
'; if($note->prive){ $dialog.=""; } if($note->rapport){ $dialog.=""; } if($note->notes_read_opac){ $dialog.=""; } $dialog.='
'; $dialog.="
"; $dialog.='
'.$note->createur_note.' '.$msg['381'].' '.formatdate($note->date_note).'
'; $dialog.='

'.$note->contenu.'

'; $dialog.='
'; $dialog.='
'; demandes_notes::note_read($note->id_note,true,"_opac"); } $dialog.=''; } // Annulation de l'alerte sur l'action dépliée après lecture des nouvelles notes si c'est la personne à laquelle est affectée l'action qui la lit demandes_actions::action_read($num_action,true,"_opac"); // Mise à jour de la demande dont est issue l'action demandes_actions::action_majParentEnfant($num_action,$num_demande,"_opac"); $form_dialog_note = str_replace('!!dialog!!',$dialog,$form_dialog_note); return $form_dialog_note; } /* * Inutile depuis la refonte * Affichage de la liste des notes associées à une action */ function show_list_notes($idaction=0){ global $form_table_note, $dbh, $msg, $charset; $req = "select id_note, CONCAT(SUBSTRING(contenu,1,50),'','...') as titre, contenu, date_note, prive, rapport,notes_num_user,notes_type_user from demandes_notes where num_action='".$idaction."' and num_note_parent=0 order by date_note desc ,id_note desc"; $res = pmb_mysql_query($req,$dbh); $liste =""; if(pmb_mysql_num_rows($res)){ while(($note = pmb_mysql_fetch_object($res))){ $createur = $this->getCreateur($note->notes_num_user,$note->notes_type_user); $contenu = "
  ".( $note->prive ? $msg['40'] : $msg['39'])."
  ".( $note->rapport ? $msg['40'] : $msg['39'])."
  ".nl2br(htmlentities($note->contenu,ENT_QUOTES,$charset))."
"; $contenu .= $this->getChilds($note->id_note); if(strlen($note->titre)<50){ $note->titre = str_replace('...','',$note->titre); } $liste .= gen_plus("note_".$note->id_note,"[".formatdate($note->date_note)."] ".$note->titre.($createur ? " ".sprintf($msg['demandes_action_by'],$createur."") : ""), $contenu); } } else { $liste .= htmlentities($msg['demandes_note_no_list'],ENT_QUOTES,$charset); } $form_table_note = str_replace('!!idaction!!',$this->num_action,$form_table_note); $form_table_note = str_replace('!!liste_notes!!',$liste,$form_table_note); print $form_table_note; } /* * Inutile depuis la refonte * Affichage des notes enfants */ function getChilds($id_note){ global $dbh, $charset, $msg; $req = "select id_note, CONCAT(SUBSTRING(contenu,1,50),'','...') as titre, contenu, date_note, prive, rapport, notes_num_user,notes_type_user from demandes_notes where num_note_parent='".$id_note."' and num_action='".$this->num_action."' order by date_note desc, id_note desc"; $res = pmb_mysql_query($req,$dbh); $display=""; if(pmb_mysql_num_rows($res)){ while(($fille = pmb_mysql_fetch_object($res))){ $createur = $this->getCreateur($fille->notes_num_user,$fille->notes_type_user); $contenu = "
  ".( $fille->prive ? $msg['40'] : $msg['39'])."
  ".( $fille->rapport ? $msg['40'] : $msg['39'])."
  ".nl2br(htmlentities($fille->contenu,ENT_QUOTES,$charset))."
"; $contenu .= $this->getChilds($fille->id_note); if(strlen($fille->titre)<50){ $fille->titre = str_replace('...','',$fille->titre); } $display .= "".gen_plus("note_".$fille->id_note,"[".formatdate($fille->date_note)."] ".$fille->titre.($createur ? " ".sprintf($msg['demandes_action_by'],$createur."") : ""), $contenu).""; } } return $display; } /* * Alerte par mail */ function send_alert_by_mail($idsender,$note){ global $msg, $empr_nom, $empr_prenom, $empr_mail, $dbh,$opac_url_base,$pmb_url_base,$demandes_email_generic; if ($demandes_email_generic) { $deg=explode(",",$demandes_email_generic); if (($deg[0]==2)||($deg[0]==3)) { $bcc=$deg[1]; } else $bcc=""; } $contenu = sprintf($msg['demandes_note_mail_new'],$empr_prenom." ".$empr_nom." " ,$note->libelle_action,$note->libelle_demande).'
'; $contenu.=$note->contenu.'
'; $lien_opac=''.$msg['demandes_see_last_note'].''; $lien_gestion=''.$msg['demandes_see_last_note'].''; $objet = $msg['demandes_note_mail_new_object']; $headers = "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=iso-8859-1"; //Envoi du mail aux autres documentalistes concernés par la demande $req = "SELECT user_email, prenom,nom FROM users JOIN demandes_users ON num_user=userid WHERE num_demande='".$note->num_demande."' AND num_user !='".$idsender."'"; $res = pmb_mysql_query($req,$dbh); while(($user = pmb_mysql_fetch_object($res))){ if($user->user_email){ if($user->prenom){ $user->nom=$user->prenom.' '.$user->nom; } $envoi_OK = mailpmb($user->nom,$user->user_email,$objet,$contenu.$lien_gestion,$empr_prenom." ".$empr_nom,$empr_mail,$headers,"", $bcc ); } } } /* * Retourne le nom de celui qui a créé l'action */ function getCreateur($id_createur,$type_createur=0){ global $dbh; if(!$type_createur) $rqt = "select concat(prenom,' ',nom) as nom, username from users where userid='".$id_createur."'"; else $rqt = "select concat(empr_prenom,' ',empr_nom) as nom from empr where id_empr='".$id_createur."'"; $res = pmb_mysql_query($rqt,$dbh); if(pmb_mysql_num_rows($res)){ $createur = pmb_mysql_fetch_object($res); return (trim($createur->nom) ? $createur->nom : $createur->username); } return ""; } /* * Met à jour les alertes sur l'action et la demande en gestion dont dépend la note */ static function note_majParent($id_note,$id_action,$id_demande,$side="_opac"){ global $dbh; $ok = false; if($id_note){ $select = "SELECT notes_read".$side." FROM demandes_notes WHERE id_note=".$id_note; $result = pmb_mysql_query($select,$dbh); $read = pmb_mysql_result($result,0,0); if($read == 1){ if(demandes_actions::action_read($id_action,false,$side) && demandes::demande_read($id_demande,false,$side)){ $ok = true; } } else { // maj action : controle s'il existe des notes non lues pour l'action en cours $query = "SELECT notes_read".$side." FROM demandes_notes WHERE num_action=".$id_action." AND id_note!=".$id_note." AND notes_read".$side."=1"; $result = pmb_mysql_query($query,$dbh); if(pmb_mysql_num_rows($result)){ $ok = demandes_actions::action_read($id_action,false,$side); } else { $ok = demandes_actions::action_read($id_action,true,$side); } // maj demande : controle s'il existe des actions non lues pour la demande en cours if($ok){ $query = "SELECT actions_read".$side." FROM demandes_actions WHERE num_demande=".$id_demande." AND id_action!=".$id_action." AND actions_read".$side."=1"; $result = pmb_mysql_query($query,$dbh); if(pmb_mysql_num_rows($result)){ $ok = demandes::demande_read($id_demande,false,$side); } else { $ok = demandes::demande_read($id_demande,true,$side); } } } } return $ok; } /* * Met à jour les alertes sur l'action et la demande dont dépend la note */ static function note_read($id_note,$booleen=true,$side="_opac"){ global $dbh; $value = ""; if($booleen){ $value = 0; } else { $value = 1; } $query = "UPDATE demandes_notes SET notes_read".$side."=".$value." WHERE id_note=".$id_note; pmb_mysql_query($query,$dbh); } } ?>