fetch_data($id,$lazzy_load);
}
function fetch_data($id=0,$lazzy_load=true){
global $base_path, $dbh;
if($this->id_demande && !$id){
$id=$this->id_demande;
}elseif(!$this->id_demande && $id){
$this->id_demande=$id;
}
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, dmde_read_opac
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,$dbh);
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;
if(!count($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'];
}
}
}
} else{
$this->id_demande = 0;
$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;
$workflow = new workflow('ACTIONS');
$this->allowed_actions = $workflow->getTypeList();
$allowed_actions = array();
$this->dmde_read_gestion = 0;
$this->dmde_read_opac = 0;
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,$dbh);
$i=0;
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->id_demande = 0;
$this->etat_demande = 0;
$this->date_demande = '0000-00-00';
$this->deadline_demande = '0000-00-00';
$this->sujet_demande = '';
$this->num_demandeur = 0;
$this->num_user = array();
$this->progression = 0;
$this->date_prevue = '0000-00-00';
$this->theme_demande = 0;
$this->type_demande = 0;
$this->titre_demande = '';
$this->num_notice = 0;
$workflow = new workflow('ACTIONS');
$this->allowed_actions = $workflow->getTypeList();
$allowed_actions = array();
$this->dmde_read_gestion = 0;
$this->dmde_read_opac = 0;
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(!sizeof($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,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=self::get_last_modified_action($this->actions);
}
}
}
static function get_last_modified_action($actions){
$temp=0;
foreach($actions as $id_action=>$action){
//On cherche la dernière note modifiée
if(!$temp && $action->last_modified){
$temp=$action;
}
$dateTemp= new DateTime($temp->last_modified->date_note);
$dateAction= new DateTime($action->last_modified->date_note);
if($dateTemp->format('U') < $dateAction->format('U')){
$temp = $action;
}
}
if($temp){
return $temp;
}
}
function getStateValue($current_value=0){
foreach($this->liste_etat as $key=>$val){
if(!$current_value){
if($val['default']==true){
return $val;
}
}else {
if($val['id']==$current_value){
return $val;
}
}
}
}
/*
* Formulaire de création d'une demande
*/
function show_modif_form(){
global $form_modif_demande, $msg, $charset, $id_empr;
$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('!!sujet!!','',$form_modif_demande);
$form_modif_demande = str_replace('!!progression!!','',$form_modif_demande);
$form_modif_demande = str_replace('!!empr_txt!!','',$form_modif_demande);
$form_modif_demande = str_replace('!!idempr!!',$id_empr,$form_modif_demande);
$form_modif_demande = str_replace('!!iduser!!',"",$form_modif_demande);
$form_modif_demande = str_replace('!!titre!!','',$form_modif_demande);
$etat=$this->getStateValue();
$form_modif_demande = str_replace('!!idetat!!',$etat['id'],$form_modif_demande);
$form_modif_demande = str_replace('!!value_etat!!',$etat['comment'],$form_modif_demande);
$form_modif_demande = str_replace('!!select_theme!!',$themes->getListSelector(),$form_modif_demande);
$form_modif_demande = str_replace('!!select_type!!',$types->getListSelector(),$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('!!iddemande!!','',$form_modif_demande);
} 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('!!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);
$etat=$this->getStateValue($this->etat_demande);
$form_modif_demande = str_replace('!!idetat!!',$etat['id'],$form_modif_demande);
$form_modif_demande = str_replace('!!value_etat!!',$etat['comment'],$form_modif_demande);
$form_modif_demande = str_replace('!!idempr!!',$this->num_demandeur,$form_modif_demande);
$form_modif_demande = str_replace('!!titre!!',$this->titre_demande,$form_modif_demande);
$form_modif_demande = str_replace('!!iduser!!',$this->num_user,$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('!!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);
$form_modif_demande = str_replace('!!iddemande!!',$this->id_demande,$form_modif_demande);
}
$act_cancel = "document.location='./empr.php?tab=request&lvl=list_dmde'";
$act_form = "./empr.php?tab=request&lvl=list_dmde&sub=save_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;
}
static function is_notice_visible($demande){
global $dbh;
//La notice est-elle visible ?
$req = "select notice_visible_opac as visible, notice_visible_opac_abon as visu_abo from notice_statut join notices on id_notice_statut=statut where notice_id='".$demande->num_notice."'";
$res_vis = pmb_mysql_query($req,$dbh);
$noti_display = pmb_mysql_fetch_object($res_vis);
if($noti_display->visible || $noti_display->visu_abo){
return true;
} else{
return false;
}
}
/*
* Formulaire de création de la liste des demandes
*/
function show_list_form(){
global $form_filtre_demande, $form_liste_demande,$base_path,$opac_url_base;
global $dbh, $charset, $msg;
global $idetat,$iduser,$id_empr,$user_input;
global $date_debut,$date_fin, $id_type, $id_theme, $dmde_loc;
global $opac_demandes_affichage_simplifie,$demandes_notice_auto_tpl;
global $view;
if(!$idetat){
$entete = "
".$msg['demandes_etat']." | ";
$form_liste_demande = str_replace('!!entete_etat!!',$entete,$form_liste_demande);
} else{
$entete = " | ";
$form_liste_demande = str_replace('!!entete_etat!!',$entete,$form_liste_demande);
}
$onChange="onchange=\"submit();\"";
$form_liste_demande = str_replace('!!select_etat!!',$this->getStateSelector($idetat,$onChange,true),$form_liste_demande);
$header_champs_perso = "";
$p_perso=new parametres_perso("demandes");
reset($p_perso->t_fields);
while (list($key,$val)=each($p_perso->t_fields)) {
if($val["OPAC_SHOW"]) $header_champs_perso .= "".htmlentities($val["TITRE"],ENT_QUOTES,$charset)." | ";
}
//Formulaire de la liste
$req = self::getQueryFilter($idetat,$iduser,$id_empr,$user_input,$date_debut,$date_fin, $id_theme, $id_type,$dmde_loc);
$res = pmb_mysql_query($req,$dbh);
$liste ="";
$nb_news=0;
if($nb_demande=pmb_mysql_num_rows($res)){
$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='./empr.php?tab=request&lvl=list_dmde&sub=open_demande&iddemande=$dmde->id_demande";
//Ajout des éléments de retour vers la bonne liste
if($idetat){
$action.="&idetat=".$idetat;
}
if($iduser){
$action.="&iduser=".$iduser;
}
// if($id_empr){
// $action.="&id_empr=".$id_empr;
// }
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_opac = demandes::dmde_majRead($dmde->id_demande,"_opac");
if($dmde->dmde_read_opac == 1){
$style=" style='cursor: pointer; font-weight:bold'";
$nb_news++;
$demande_id_new=$dmde->id_demande;
} else {
$style=" style='cursor: pointer'";
}
if($demandes_notice_auto_tpl){
if(self::is_notice_visible($dmde)){
$link_noti = " | ";
} else{
$link_noti = " | ";
}
}
$nom_user='';
if($dmde->users){
foreach($dmde->users as $id=>$user){
if($user['statut']==1){
if($nom_user){
$nom_user.="/ ";
}
$nom_user.=$user['nom'];
}
}
}
$liste .= "";
$liste .= " id_demande."','$dmde->id_demande', true); return false;\" title=\"\" id=\"action".$dmde->id_demande."Img\" name=\"imEx\" class=\"img_plus\" src=\"./images/plus.gif\"> | ";
$liste .= "";
if($dmde->dmde_read_opac == 1){
$liste .= " id_demande."','$dmde->id_demande', true); return false;\" title=\"\" id=\"read".$dmde->id_demande."Img1\" name=\"imRead\" class=\"img_plus\" src=\"".get_url_icon('notification_empty.png')."\" style='display:none'>
id_demande."','$dmde->id_demande', true); return false;\" title=\"\" id=\"read".$dmde->id_demande."Img2\" name=\"imRead\" class=\"img_plus\" src=\"".get_url_icon('notification_new.png')."\">";
} else {
$liste .= " id_demande."','$dmde->id_demande', true); return false;\" title=\"\" id=\"read".$dmde->id_demande."Img1\" name=\"imRead\" class=\"img_plus\" src=\"".get_url_icon('notification_empty.png')."\" >
id_demande."','$dmde->id_demande', true); return false;\" title=\"\" id=\"read".$dmde->id_demande."Img2\" name=\"imRead\" class=\"img_plus\" src=\"".get_url_icon('notification_new.png')."\" style='display:none'>";
}
$liste .= " | ";
if(!$opac_demandes_affichage_simplifie) {
$liste .="
".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->deadline_demande),ENT_QUOTES,$charset)." |
".htmlentities($nom_user,ENT_QUOTES,$charset)." |
progression."%\" title='".$dmde->progression."%' />
| ";
$perso_=$p_perso->show_fields($dmde->id_demande);
for ($i=0; $i";
}
$liste .= $link_noti;
} else {
$liste .="
".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)." | ";
$perso_=$p_perso->show_fields($dmde->id_demande);
for ($i=0; $i";
}
$liste .= $link_noti;
}
$liste .= "
";
//Le détail de l'action, contient les notes
$liste .="id_demande."Child\" style=\"display:none\">
|
id_demande."ChildTd\">";
$liste .=" |
";
if($dmde->etat_demande==2){
$etat_demande_validee++;
$demande_id_validee=$dmde->id_demande;
}
if($dmde->etat_demande==1){
$etat_demande_a_valider++;
$demande_id_a_valider=$dmde->id_demande;
}
}
} else {
$liste .= "".$msg['demandes_liste_vide']." |
";
}
/* plus demandé...
if($etat_demande_validee==1 && $view!="all" && !$etat_demande_a_valider){// une seule validée:
print "";
return;
}
if($etat_demande_a_valider==1 && $view!="all" && !$etat_demande_validee){// une seul à valider:
print "";
return;
}
*/
$form_liste_demande = str_replace('!!header_champs_perso!!',$header_champs_perso,$form_liste_demande);
$form_liste_demande = str_replace('!!liste_dmde!!',$liste,$form_liste_demande);
print $form_liste_demande;
}
static function get_values_from_form(&$demande){
global $sujet,$iddemande ,$idetat, $titre, $id_theme, $id_type;
global $date_debut, $date_fin, $date_prevue, $idempr;
global $iduser, $progression, $demandes_statut_notice;
global $demandes_init_workflow;
if(!$iduser && $demandes_init_workflow==="1"){
$iduser=$GLOBALS['PMBuserid'];
}
if(!$date_prevue)$date_prevue=$date_debut;
if(!$date_fin)$date_fin=$date_debut;
$demande->id_demande=$iddemande;
$demande->titre_demande = $titre;
$demande->sujet_demande = $sujet;
$demande->date_demande = $date_debut;
$demande->date_prevue = $date_prevue;
$demande->deadline_demande = $date_fin;
$demande->num_user = $iduser;
$demande->progression = $progression;
$demande->num_demandeur = $idempr;
$demande->type_demande = $id_type;
$demande->theme_demande = $id_theme;
$demande->etat_demande=$idetat;
if($idetat == 4 || $idetat == 5 ) {
$demande->num_user_cloture=SESSuserid;
}
//Création d'une stdClass (pour alleger) => doit matcher à une notice, mais un peu lourd ...
$demande->notice=new stdClass();
$demande->notice->tit1=$demande->titre_demande;
$demande->notice->n_contenu=$demande->sujet_demande;
$demande->notice->notice_id=$demande->num_notice;
$demande->notice->statut=$demandes_statut_notice;
}
static function save_notice(&$demande){
global $dbh;
global $demandes_notice_auto, $gestion_acces_active, $gestion_acces_user_notice, $gestion_acces_empr_notice;
//CREATION de la notice associée
if($demandes_notice_auto === "1"){
$query = "INSERT INTO notices SET
tit1='".$demande->notice->tit1."',
n_contenu='".$demande->notice->n_contenu."',
statut ='".$demande->notice->statut."'";
pmb_mysql_query($query,$dbh);
$demande->num_notice= $demande->notice->num_notice = pmb_mysql_insert_id($dbh);
notice::majNotices($demande->num_notice);
if($pmb_type_audit) audit::insert_creation(AUDIT_NOTICE,$demande->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, $id_notice);
}
//traitement des droits acces empr_notice
if ($gestion_acces_empr_notice==1) {
$dom_2= $ac->setDomain(2);
$dom_2->storeUserRights(0, $id_notice);
}
}
}
static function save_demandes_users(&$demande){
global $dbh;
//Enregistrement dans demandes_users
$date_creation=date("Y-m-d",time());
if($demande->id_demande && sizeof($demande->num_user)){
$query = "UPDATE demandes_users SET users_statut=0 WHERE num_user NOT IN (".implode(',',$demande->num_user).") AND num_demande='".$demande->id_demande."'";
pmb_mysql_query($query,$dbh);
$query = "UPDATE demandes_users SET users_statut=1 WHERE num_user IN (".implode(',',$demande->num_user).") AND num_demande='".$demande->id_demande."'";
pmb_mysql_query($query,$dbh);
foreach($demande->num_user as $id_user){
$query = "insert into demandes_users set num_user='".$id_user."', num_demande='".$demande->id_demande."', date_creation='".$date_creation."', users_statut=1";
pmb_mysql_query($query,$dbh);
}
}
}
/*
* Création/Modification d'une demande
*/
static function save(&$demande){
global $dbh, $pmb_type_audit, $demandes_email_demandes;
if($demande->id_demande){
//MODIFICATION
$query = "UPDATE demandes SET
sujet_demande='".$demande->sujet_demande."',
num_demandeur='".$demande->num_demandeur."',
date_demande='".$demande->date_demande."',
deadline_demande='".$demande->deadline_demande."',
date_prevue='".$demande->date_prevue."',
progression='".$demande->progression."',
titre_demande='".$demande->titre_demande."',
type_demande='".$demande->type_demande."',
theme_demande='".$demande->theme_demande."',
num_user_cloture='".$demande->num_user_cloture."',
dmde_read_gestion='1'
WHERE id_demande='".$demande->id_demande."'";
pmb_mysql_query($query,$dbh);
if($pmb_type_audit) audit::insert_modif(AUDIT_DEMANDE,$demande->id_demande);
} else {
//On ajoute une notice ?
self::save_notice($demande);
//CREATION de la demande
$query = "INSERT INTO demandes SET
sujet_demande='".$demande->sujet_demande."',
etat_demande='".$demande->etat_demande."',
num_demandeur='".$demande->num_demandeur."',
date_demande='".$demande->date_demande."',
date_prevue='".$demande->date_prevue."',
deadline_demande='".$demande->deadline_demande."',
progression='".$demande->progression."',
titre_demande='".$demande->titre_demande."',
type_demande='".$demande->type_demande."',
theme_demande='".$demande->theme_demande."',
num_notice='".$demande->num_notice."',
dmde_read_gestion='1'" ;
pmb_mysql_query($query,$dbh);
$demande->id_demande = pmb_mysql_insert_id($dbh);
if($pmb_type_audit) audit::insert_creation(AUDIT_DEMANDE,$demande->id_demande);
if ($demandes_email_demandes){
self::send_alert_by_mail($demande->num_demandeur,$demande);
}
}
//MAJ des users de la notice
self::save_demandes_users($demande);
}
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;
$contenu = $msg['demandes_mail_new_demande'];
$contenu=str_replace("!!nom!!", $empr_prenom." ".$empr_nom." ", $contenu);
$contenu=str_replace("!!titre_demande!!", $note->titre_demande, $contenu);
$contenu.='
'.$note->sujet_demande.'
';
$lien_gestion=''.$msg['demandes_see_last_note'].'';
$objet = $msg['demandes_mail_new_demande_object'];
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1";
// Envoi au mail générique
if($demandes_email_generic){
$param=explode(",", $demandes_email_generic);
if(($param[0]==1 || $param[0]==3) && $param[1]){
$envoi_OK = mailpmb("",$param[1],$objet,$contenu.$lien_gestion,$empr_prenom." ".$empr_nom,$empr_mail,$headers,"",$param[2]);
}
}
}
/*
* Suppression d'une demande
*/
static function delete($demande){
global $dbh, $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,$dbh);
if(pmb_mysql_num_rows($result)){
notice::del_notice(pmb_mysql_result($result,0,0));
}
}
// suppression des actions et des notes
if(sizeof($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,$dbh);
//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, $dbh);
// 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,$dbh);
//suppression de l'audit
audit::delete_audit(AUDIT_DEMANDE,$demande->id_demande);
}
}
/*
* Retourne le sélecteur des états de la demandes
*/
function getStateSelector($idetat=0,$action='',$default=false){
global $charset, $msg;
$selector = "";
return $selector;
}
/*
* Retourne le sélecteur des utilisateurs ayant le droit aux demandes
*/
function getUsersSelector($action='',$default=false,$multiple=false,$nonassign=false){
global $dbh,$charset,$msg, $iduser;
if($multiple)
$mul = " name='iduser[]' multiple ";
else $mul = " name='iduser' ";
if(!$this->id_demande){
$req="select concat(prenom,' ',nom) as nom, userid, username
from users
where rights>=16384";
} else {
$req="select concat(prenom,' ',nom) as nom, 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";
}
$res = pmb_mysql_query($req,$dbh);
$select = "";
$selector = "";
return $selector;
}
/*
* Retourne le nom de l'utilisateur (celui qui traitera la demande)
*/
function getUserLib($iduser){
global $dbh;
$req = "select concat(prenom,' ',nom) as nom, userid, username from users where userid='".$iduser."'";
$res = pmb_mysql_query($req,$dbh);
$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
*/
function getCaracEmpr($idempr){
global $dbh;
$req = "select concat(empr_prenom,' ',empr_nom) as nom, id_empr,empr_cb from empr where id_empr='".$idempr."'";
$res = pmb_mysql_query($req,$dbh);
$empr = pmb_mysql_fetch_array($res);
return $empr;
}
/*
* Fonction qui retourne la requete de filtre
*/
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(count($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);
for($i=0;$iusers);$i++){
if($i == sizeof($this->users)-1)
$users .= htmlentities($this->users[$i]['nom'],ENT_QUOTES,$charset);
else $users .= htmlentities($this->users[$i]['nom'],ENT_QUOTES,$charset)." / ";
}
$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!!',$users,$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);
//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; $i
";
} else{
$link_noti = "";
}
$form_consult_dmde = str_replace('!!icone!!',$link_noti,$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((sizeof($this->users) && $demandes_init_workflow!=="2")&& !$opac_demandes_no_action){
$listActionButton=' '.$msg['demandes_action_type_add'].' ';
if(sizeof($this->allowed_actions)){
foreach($this->allowed_actions as $key=>$actionType){
if($actionType['active']==1){
$listActionButton.="id_demande'\" />";
}
}
}
if($listActionButton){
$form_consult_dmde=str_replace('!!add_actions_list!!',$listActionButton,$form_consult_dmde);
}else{
$form_consult_dmde=str_replace('!!add_actions_list!!',"",$form_consult_dmde);
}
}else{
$form_consult_dmde=str_replace('!!add_actions_list!!',"",$form_consult_dmde);
}
$modify_button="";
foreach($this->workflow->object_states_by_id as $key=>$value){
//id d'etat de demande par défaut
if($this->workflow->object_workflow['STARTSTATE'][0]['value']==$value && $key==$this->etat_demande){
$modify_button="id_demande'\" />";
}
}
$form_consult_dmde=str_replace('!!demande_modify!!',$modify_button,$form_consult_dmde);
if(sizeof($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);
}else{
$form_consult_dmde.=demandes_actions::show_list_actions($this->actions, $this->id_demande);
}
}
if($this->etat_demande == 1 && !sizeof($this->actions) && $this->dmde_read_opac == 1){
demandes::demande_read($this->id_demande,true,"_opac");
$this->fetch_data($this->id_demande,false);
}
print $form_consult_dmde;
}
/*
* Affiche la liste des boutons correspondants à l'état en cours
*/
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 = "";
for($i=0;$i";
}
return $display;
}
/*
* Changement d'etat d'une demande
*/
static function change_state($state,$demande){
global $dbh,$demandes_init_workflow, $demandes_default_action, $pmb_type_audit;
global $PMBuserid;
global $sujet, $idtype, $idstatut;
global $date_debut, $date_fin, $detail;
global $time_elapsed, $progression,$cout,$iddemande, $ck_prive;
if($demandes_init_workflow==="1" && $PMBuserid){
//La demande est elle attribué à un utilisateur ?
$query='SELECT 1 FROM demandes_users WHERE num_demande='.$demande->id_demande;
$result=pmb_mysql_query($query,$dbh);
if(!pmb_mysql_num_rows($result)){
//si non, on attribue
$query='INSERT INTO demandes_users SET num_user="'.$PMBuserid.'", num_demande="'.$demande->id_demande.'", date_creation="'.date("Y-m-d",time()).'", users_statut=1';
pmb_mysql_query($query,$dbh);
}
}
$req = "update demandes set etat_demande=$state where id_demande='".$demande->id_demande."'";
pmb_mysql_query($req,$dbh);
if($state == 2 && $demandes_default_action === "1"){
$query = "SELECT id_action FROM demandes_actions WHERE num_demande=".$demande->id_demande;
$result = pmb_mysql_query($query,$dbh);
if(!pmb_mysql_num_rows($result)){
$action_default = new demandes_actions();
$action_default->num_demande = $demande->id_demande;
$action_default->actions_num_user = $PMBuserid;
$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 = "";
for($i=1;$i<=count($action_default->list_statut);$i++){
if($action_default->list_statut[$i]['default']) {
$action_default->statut_action = $action_default->list_statut[$i]['id'];
}
}
if($idstatut == "") {
reset($action_default->list_statut);
$first_statut = current($action_default->list_statut);
$action_default->statut_action = $first_statut['id'];
}
}
$action_default->type_action = $demande->first_action;
$action_default->sujet_action = $demande->titre_demande;
$action_default->detail_action = $demande->sujet_demande;
demandes_actions::save($action_default);
}
}
if($pmb_type_audit) audit::insert_modif(AUDIT_DEMANDE,$demande->id_demande);
}
/*
* Montre la liste des documents pouvant etre inclus dans le document
*/
function show_docnum_to_attach(){
global $dbh, $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,$dbh);
$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
*/
function attach_docnum(){
global $dbh, $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,$dbh);
$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,$dbh);
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,$dbh);
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,$dbh);
$req = "update explnum_doc_actions set num_explnum='0' where num_explnum_doc='".$expl->id_explnum_doc."'";
pmb_mysql_query($req,$dbh);
}
} 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,$dbh);
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,$dbh);
$req = "update explnum_doc_actions set num_explnum='0' where num_explnum_doc='".$expl->id_explnum_doc."'";
pmb_mysql_query($req,$dbh);
}
}
}
/*
* Affiche le formulaire de création/modification d'une notice
*/
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 = "./demandes.php?categ=gestion&act=see_dmde&iddemande=".$this->id_demande;
print $myNotice->show_form();
}
/*
* Formulaire de validation de la suppression de notice
*/
function suppr_notice_form(){
global $msg, $chk, $iddemande;
$display = "
";
print $display;
}
function attribuer(){
global $chk, $iduser,$dbh;
for($i=0;$i action est déjà lue donc pas d'alerte
* false => alerte
*/
static function demande_read($id_demande,$booleen=true,$side="_gestion"){
global $dbh;
$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,$dbh)){
return true;
} else {
return false;
}
}
}
?>