id_note = intval($id_note); $this->num_action = intval($id_action); $this->fetch_data(); } public function fetch_data(){ $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; $this->demande_final_note_num = 0; 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 , demande_note_num 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); 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; $this->demande_final_note_num = $obj->demande_note_num; } } 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); $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); } } public function get_path() { global $charset; $path = "num_demande>".htmlentities($this->libelle_demande,ENT_QUOTES,$charset).""; $path .= " > num_action>".htmlentities($this->libelle_action,ENT_QUOTES,$charset).""; return $path; } /* * Formulaire d'ajout/modification */ public function show_modif_form($reply=false){ global $content_form_modif_note, $msg, $charset, $demandes_include_note; print "

".$this->get_path()."

"; $content_form = $content_form_modif_note; $interface_form = new interface_demandes_form('modif_note'); $interface_form->set_num_action($this->num_action); $title = (strlen($this->contenu)>30 ? substr($this->contenu,0,30).'...' : $this->contenu); if($this->id_note && !$reply){ $interface_form->set_label($msg['demandes_note_modif'].' : '.$title); $content_form = str_replace('!!ck_rapport!!', ($this->rapport ? 'checked' : ''),$content_form); $content_form = str_replace('!!ck_prive!!', ($this->prive ? 'checked' : ''),$content_form); $content_form = str_replace('!!ck_vue!!', ($this->notes_read_gestion ? '' : 'checked'),$content_form); if($this->demande_final_note_num == $this->id_note){ $content_form = str_replace('!!ck_final_note!!','checked',$content_form); }else{ $content_form = str_replace('!!ck_final_note!!','',$content_form); } $content_form = str_replace('!!date_note_btn!!',formatdate($this->date_note),$content_form); $content_form = str_replace('!!date_note!!',$this->date_note,$content_form); $content_form = str_replace('!!idnote!!',$this->id_note,$content_form); } elseif($this->id_note && $reply) { $interface_form->set_label($msg['demandes_note_reply'].' : '.$title); if($demandes_include_note) $content_form = str_replace('!!ck_rapport!!','checked',$content_form); else $content_form = str_replace('!!ck_rapport!!','',$content_form); $content_form = str_replace('!!ck_prive!!','',$content_form); $date = formatdate(today()); $date_note=date("Ymd",time()); $content_form = str_replace('!!date_note_btn!!',$date,$content_form); $content_form = str_replace('!!date_note!!',$date_note,$content_form); $content_form = str_replace('!!idnote!!','',$content_form); $content_form = str_replace('!!ck_final_note!!','',$content_form); } else { $interface_form->set_label($msg['demandes_note_creation']); $content_form = str_replace('!!ck_prive!!','',$content_form); if($demandes_include_note) $content_form = str_replace('!!ck_rapport!!','checked',$content_form); else $content_form = str_replace('!!ck_rapport!!','',$content_form); $date = formatdate(today()); $date_note=date("Ymd",time()); $content_form = str_replace('!!date_note_btn!!',$date,$content_form); $content_form = str_replace('!!date_note!!',$date_note,$content_form); $content_form = str_replace('!!idnote!!','',$content_form); $content_form = str_replace('!!parent_text!!','',$content_form); $content_form = str_replace('!!id_note_parent!!','',$content_form); $content_form = str_replace('!!style!!','',$content_form); $content_form = str_replace('!!ck_final_note!!','',$content_form); } $content_form = str_replace('!!contenu!!',htmlentities($this->contenu,ENT_QUOTES,$charset),$content_form); $content_form = str_replace('!!idaction!!',$this->num_action,$content_form); $content_form = str_replace('!!iduser!!',$this->notes_num_user,$content_form); $content_form = str_replace('!!typeuser!!',$this->notes_type_user,$content_form); $content_form = str_replace('!!iddemande!!',$this->num_demande,$content_form); $interface_form->set_object_id($this->id_note) ->set_confirm_delete_msg($msg['demandes_note_confirm_suppr']) ->set_content_form($content_form) ->set_table_name('demandes_notes') ->set_field_focus('contenu_note'); print $interface_form->get_display(); } public function set_properties_from_form() { global $contenu_note, $idaction,$idnote ,$iddemande , $iduser,$typeuser; global $date_note, $ck_rapport, $ck_prive, $ck_vue,$id_note_parent, $PMBuserid,$demande_end; if(!$iduser){ $iduser=$PMBuserid; $typeuser='0'; } $this->id_note = intval($idnote); $this->num_action = intval($idaction); $this->num_demande = intval($iddemande); $this->contenu = stripslashes($contenu_note); $this->num_note_parent = intval($id_note_parent); if(!$date_note){ $this->date_note=date("Y-m-d h:i:s",time()); }else{ $this->date_note=$date_note; } if($ck_prive){ $this->prive=1; }else{ $this->prive=0; } if($ck_rapport){ $this->rapport=1; }else{ $this->rapport=0; } if($ck_vue){ $this->notes_read_gestion=0; }else{ $this->notes_read_gestion=1; } if($demande_end){ $this->demande_end=1; }else{ $this->demande_end=0; } $this->notes_num_user = intval($iduser); $this->notes_type_user=$typeuser; } /* * Création/Modification d'une note */ public function save(){ global $demandes_email_demandes, $pmb_type_audit; if($this->id_note){ //MODIFICATION $query = "UPDATE demandes_notes SET contenu='".addslashes($this->contenu)."', date_note='".$this->date_note."', prive='".$this->prive."', rapport='".$this->rapport."', num_action='".$this->num_action."', notes_num_user='".$this->notes_num_user."', notes_type_user='".$this->notes_type_user."', num_note_parent='".$this->num_note_parent."', notes_read_gestion='".$this->notes_read_gestion."', notes_read_opac='1' WHERE id_note='".$this->id_note."'"; pmb_mysql_query($query); if($pmb_type_audit) audit::insert_modif(AUDIT_NOTE,$this->id_note); } else { //CREATION $query = "INSERT INTO demandes_notes SET contenu='".addslashes($this->contenu)."', date_note='".$this->date_note."', prive='".$this->prive."', rapport='".$this->rapport."', num_action='".$this->num_action."', notes_num_user='".$this->notes_num_user."', notes_type_user='".$this->notes_type_user."', num_note_parent='".$this->num_note_parent."', notes_read_gestion='".$this->notes_read_gestion."', notes_read_opac='1'"; pmb_mysql_query($query); $this->id_note=pmb_mysql_insert_id(); if($pmb_type_audit) audit::insert_creation(AUDIT_NOTE,$this->id_note); if(!$this->prive) { if ($demandes_email_demandes){ $this->fetch_data($this->id_note,$this->num_action); $this->send_alert_by_mail($this->notes_num_user); } } } // Générer la réponse finale de la demande avec cette note if($this->demande_end){ global $f_message; $f_message=$this->contenu; $demande = new demandes($this->num_demande); $demande->save_repfinale($this->id_note); demandes_notes::note_majParent($this->id_note,$this->num_action,$this->num_demande,"_gestion"); } } /* * Suppression d'une note */ public static function delete($note){ if($note->id_note){ $req = "delete from demandes_notes where id_note='".$note->id_note."'"; pmb_mysql_query($req); $req = "delete from demandes_notes where num_note_parent='".$note->id_note."'"; pmb_mysql_query($req); audit::delete_audit(AUDIT_NOTE,$note->id_note); } } public static function show_dialog($notes,$num_action,$num_demande,$redirect_to='demandes_actions-show_consultation_form',$from_ajax=false){ global $msg, $charset; global $content_dialog_note, $form_dialog_note, $js_dialog_note; if($from_ajax) { $dialog_note = $content_dialog_note; $form_name = "liste_action"; } else { $dialog_note = $js_dialog_note.$form_dialog_note; $form_name = "modif_notes"; } $dialog_note = str_replace('!!redirectto!!',$redirect_to,$dialog_note); $dialog_note = str_replace('!!idaction!!',$num_action,$dialog_note); $dialog = ''; if (!empty($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_gestion){ $dialog.="id_note."','$note->id_note','".$num_action."','".$num_demande."', true); return false;\" title=\"\" id=\"note_".$note->id_note."Img1\" class=\"img_plus\" src='".get_url_icon('notification_empty.png')."' style='display:none'> id_note."','$note->id_note','".$num_action."','".$num_demande."', true); return false;\" title=\"" . $msg['demandes_new']. "\" id=\"note_".$note->id_note."Img2\" class=\"img_plus\" src='".get_url_icon('notification_new.png')."'>"; } else { $dialog .= "id_note."','$note->id_note','".$num_action."','".$num_demande."', true); return false;\" title=\"\" id=\"note_".$note->id_note."Img1\" class=\"img_plus\" src='".get_url_icon('notification_empty.png')."' > id_note."','$note->id_note','".$num_action."','".$num_demande."', true); return false;\" title=\"" . $msg['demandes_new']. "\" id=\"note_".$note->id_note."Img2\" class=\"img_plus\" src='".get_url_icon('notification_new.png')."' style='display:none'>"; } $dialog.=""; // affichage de l'audit des notes seulement si nécessaire $audit_note = new audit(16,$note->id_note); $audit_note->get_all(); if (count($audit_note->all_audit) > 1) { $dialog.="id_note', 'audit_popup'); return false;\" title=\"".$msg['audit_button']."\" value=\"".$msg['audit_button']."\" />"; } if(!$note->notes_read_gestion && !$note->notes_type_user){ $req = "select demande_note_num from demandes where demande_note_num='".$note->id_note."'" ; $res = pmb_mysql_query($req); if(pmb_mysql_num_rows($res)){ $color_img="red"; }else $color_img="blue"; $dialog.="id_note."','$note->id_note','".$num_action."','".$num_demande."', true);\" >"; } $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,"_gestion"); } $dialog.=''; } $dialog_note = str_replace('!!dialog!!',$dialog,$dialog_note); if($from_ajax) { $dialog_note = str_replace('!!change_action_form!!','document.forms["'.$form_name.'"].action="./demandes.php?categ=notes#fin";',$dialog_note); } else { $dialog_note = str_replace('!!change_action_form!!','',$dialog_note); } return $dialog_note; } /* * Inutile depuis la refonte * Affichage de la liste des notes associées à une action */ public function show_list_notes($idaction=0){ global $form_table_note, $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); $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 */ public function getChilds($id_note){ global $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); $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 */ public function send_alert_by_mail($idsender){ global $msg, $PMBusernom, $PMBuserprenom, $PMBuseremail,$opac_url_base,$pmb_url_base,$demandes_email_generic; $contenu = sprintf($msg['demandes_note_mail_new'],$PMBuserprenom." ".$PMBusernom." ",$this->libelle_action,$this->libelle_demande).'
'; $contenu.=$this->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='".$this->num_demande."' AND num_user !='".$idsender."'"; $res = pmb_mysql_query($req); 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,$PMBuserprenom." ".$PMBusernom,$PMBuseremail,$headers,"" ); } } //Envoi du mail au demandeur $req= "SELECT empr_prenom,empr_nom, empr_mail FROM empr JOIN demandes ON id_empr=num_demandeur WHERE id_demande='".$this->num_demande."'"; $res = pmb_mysql_query($req); $empr = pmb_mysql_fetch_object($res); if($empr->empr_mail) { if($empr->empr_prenom){ $empr->empr_nom=$empr->empr_prenom.' '.$empr->empr_nom; } $envoi_OK = mailpmb($empr->empr_nom,$empr->empr_mail,$objet,$contenu.$lien_opac,$PMBuserprenom." ".$PMBusernom,$PMBuseremail,$headers,""); } // Envoi au mail générique if($demandes_email_generic){ $param=explode(",", $demandes_email_generic); if(($param[0]==2 || $param[0]==3) && $param[1]){ $envoi_OK = mailpmb("",$param[1],$objet,$contenu.$lien_gestion,$PMBuserprenom." ".$PMBusernom,$PMBuseremail,$headers,"",$param[2]); } } } /* * Retourne le nom de celui qui a créé l'action */ public function getCreateur($id_createur,$type_createur=0){ 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); 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 dont dépend la note */ public static function note_majParent($id_note,$id_action,$id_demande,$side="_gestion"){ $id_note = intval($id_note); $id_action = intval($id_action); $id_demande = intval($id_demande); $ok = false; if($id_note){ $select = "SELECT notes_read".$side." FROM demandes_notes WHERE id_note=".$id_note; $result = pmb_mysql_query($select); $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); 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); 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 */ public static function note_read($id_note,$booleen=true,$side="_gestion"){ $id_note += 0; $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); } /* * fonction qui renvoie un booléen indiquant si une note a été lue ou pas */ public static function read($note,$side="_gestion"){ $read = false; $query = "SELECT notes_read".$side." FROM demandes_notes WHERE id_note=".$note->id_note; $result = pmb_mysql_query($query); if($result){ $tmp = pmb_mysql_result($result,0,0); if($tmp == 0){ $read = true; } } return $read; } /* * Change l'alerte de la note : si elle est lue, elle passe en non lue et inversement */ public static function change_read($note,$side="_gestion"){ $read = demandes_notes::read($note,$side); $value = ""; if($read){ $value = 1; } else { $value = 0; } $query = "UPDATE demandes_notes SET notes_read".$side."=".$value." WHERE id_note=".$note->id_note; if(pmb_mysql_query($query)){ return true; } else { return false; } } } ?>