name pour les etats var $has_unimarc = false; //Constructeur. function suggestions_map() { global $dbh; global $include_path; //Recherche des fichiers XML de description $map_file=$include_path.'/suggestions/suggestions_map.xml'; $map_file_subst=$include_path.'/suggestions/suggestions_map_subst.xml'; $xml=file_get_contents($map_file,"r") or die("Can't find XML file $map_file"); if (file_exists($map_file_subst)) { $xml_subst=file_get_contents($map_file_subst,"r"); } //Parse le fichier dans un tableau $param=_parser_text_no_function_($xml, "SUGGESTS"); //Tableau des états ([nom etat]=>[valeurs etat]) for ($i=0;$istates[$param['STATES'][0]['STATE'][$i]['NAME']]=$param['STATES'][0]['STATE'][$i]; $this->id_to_name[$param['STATES'][0]['STATE'][$i]['ID']]=$param['STATES'][0]['STATE'][$i]['NAME']; } /* print 'states=
';
		print_r ($this->states);
		print '


'; */ /* print 'id_to_name=
';
		print_r ($this->id_to_name);
		print '


'; */ //Tableau des flux autorises $this->allowedflow=$param['ALLOWEDFLOW'][0]; /* print 'allowedflow=
';
		print_r ($this->allowedflow);
		print '


'; */ //Tableau des flux definis if ($xml_subst) { $param_subst=_parser_text_no_function_($xml_subst, "SUGGESTS"); $this->workflow=$param_subst['WORKFLOW'][0]; } else { $this->workflow=$param['WORKFLOW'][0]; } /* print 'workflow=
';
		print_r ($this->workflow);
		print '


'; */ //Nom etat initial $this->firststate=$this->workflow['FIRSTSTATE'][0]['value']; /* print 'firststate= '; print ($this->firststate); print '

'; */ //Nom etat final $this->laststate=$this->workflow['LASTSTATE'][0]['value']; /* print 'laststate= '; print ($this->laststate); print '

'; */ //Tableaux des transitions possibles pour un etat et d'envoi des mails sur transitions for($i=0;$iworkflow['FROMSTATE']);$i++) { $to_transitions=array(); for($j=0;$jworkflow['FROMSTATE'][$i]['TOSTATE']); $j++) { $to_transitions[] = $this->workflow['FROMSTATE'][$i]['TOSTATE'][$j]['NAME']; $this->mail_on_transition[$this->workflow['FROMSTATE'][$i]['NAME']][$this->workflow['FROMSTATE'][$i]['TOSTATE'][$j]['NAME']]=$this->workflow['FROMSTATE'][$i]['TOSTATE'][$j]['MAIL']; } $this->transitions[$this->workflow['FROMSTATE'][$i]['NAME']]=$to_transitions; } /* print 'transitions=
';
		print_r ($this->transitions);
		print '


'; */ //Test workflow if (!$this->workflowCheck()) die ("Workflow error ...") ; } //Verification du workflow function workflowCheck() { //Etat initial $allowed_firststates=array(); for ($i=0;$iallowedflow['FIRSTSTATE']);$i++) { $allowed_firststates[]=$this->allowedflow['FIRSTSTATE'][$i]['value']; } if (in_array($this->workflow['FIRSTSTATE'][0]['value'], $allowed_firststates)===false) return FALSE; //Etat final $allowed_laststates=array(); for ($i=0;$iallowedflow['LASTSTATE']);$i++) { $allowed_laststates[$i]=$this->allowedflow['LASTSTATE'][$i]['value']; } if (in_array($this->workflow['LASTSTATE'][0]['value'], $allowed_laststates)===false) return FALSE; //Enchainements $allowed_transitions=$this->allowedflow['FROMSTATE']; $work_transitions=$this->workflow['FROMSTATE']; for($i=0;$istates[$state_name]['ID']; } //Retourne l'attribut ADD associe à un etat function getState_ADD($state_name) { return $this->states[$state_name]['ADD']; } //Retourne l'attribut DISPLAY associe à un etat function getState_DISPLAY($state_name) { return $this->states[$state_name]['DISPLAY']; } //Retourne l'attribut MERGE associe à un etat function getState_MERGE($state_name) { return $this->states[$state_name]['MERGE']; } //Retourne l'attribut CATALOG associe à un etat function getState_CATALOG($state_name) { return $this->states[$state_name]['CATALOG']; } //Retourne l'attribut CATEG associe à un etat function getState_CATEG($state_name) { return $this->states[$state_name]['CATEG']; } //Retourne l'attribut COMMENT associe à un etat function getState_COMMENT($state_name) { return $this->states[$state_name]['COMMENT']; } //Retourne le tableau des actions associees a un etat function getState_ACTION($state_name) { return $this->states[$state_name]['ACTION']; } //Construction du sélecteur en fonction de la liste des états possibles et de l'état en cours function getStateSelector() { global $msg, $charset; $selector=""; return $selector; } //Retourne la liste des états possibles (valeur, libelle) function getStateList() { global $msg; $t=array(); $t[-1]=$msg['acquisition_sug_tous']; foreach ($this->states as $name=>$content) { if ($this->getState_DISPLAY($name) != 'NO') { $t[$this->getState_ID($name)]=$msg[$this->getState_COMMENT($name)]; } } return $t; } //Construction de la liste des boutons en fonction de l'état en cours function getButtonList($state='-1') { global $msg, $charset; if (!$state) $state='-1'; $button_list=""; if ($state == '-1') { //Tous états possibles $button_list.= $this->getButtonList_MERGE(); $button_list.=' '; foreach($this->states as $name=>$value) { if( $name != 'DELETED' && $name != 'TODO' ) { eval('$button_list.= $this->getButtonList_'.$name.'();'); $button_list.=' '; } } } else { $state_name=$this->id_to_name[$state]; $tostates=$this->transitions[$state_name]; if ($this->getState_MERGE($state_name)!='NO') { $button_list.= $this->getButtonList_MERGE(); $button_list.= ' '; } foreach($tostates as $id=>$name) { if( $name != 'DELETED' && $name != 'TODO' ) { eval('$button_list.= $this->getButtonList_'.$name.'();'); $button_list.=' '; } } } return $button_list; } function getButtonList_MERGE() { global $msg; return ""; } function getButtonList_VALIDATED() { global $msg; return ""; } function getButtonList_REJECTED() { global $msg; return ""; } function getButtonList_CONFIRMED() { global $msg; return ""; } function getButtonList_GIVENUP() { global $msg; return ""; } function getButtonList_ORDERED() { global $msg; return ""; } function getButtonList_ESTIMATED() { global $msg; return ""; } function getButtonList_RECEIVED() { global $msg; return ""; } function getButtonList_FILED() { global $msg; return ""; } function getButtonList_TODO($state='-1') { global $msg; $button = ""; if (!$state) $state='-1'; if ($state == '-1') { //Tous états possibles return $button; } else { $state_name=$this->id_to_name[$state]; $tostates=$this->transitions[$state_name]; if (in_array('TODO', $tostates)) { return $button; } } return ""; } function getCategModifier($state='-1', $num_categ='-1', $nb_per_page) { global $msg, $charset; $selector = " "; $selector.= ""; $script = " "; $selector.=$script; if ($state == '-1') { //Tous états possibles return $selector; } else { $state_name=$this->id_to_name[$state]; if ($this->getState_CATEG($state_name) == 'YES') { return $selector; } } return ""; } function getButtonList_DELETED($state='-1') { global $msg; $button = ""; if (!$state) $state='-1'; if ($state == '-1') { //Tous états possibles return $button; } else { $state_name=$this->id_to_name[$state]; $tostates=$this->transitions[$state_name]; if (in_array('DELETED', $tostates)) { return $button; } } return ""; } //Retourne le bouton supprimer dans le formulaire de modification function getButton_DELETED($state,$id_bibli,$id_sug) { global $msg; $button = ""; $mask = $this->getMask_FILED(); if (($state & $mask) == $mask ) { //Archive return $button; } $state = ($state & ~$mask); $state_name=$this->id_to_name[$state]; $tostates=$this->transitions[$state_name]; if (in_array('DELETED', $tostates)) { return $button; } return ""; } //Retourne le bouton cataloguer dans le formulaire de modification function getButton_CATALOG($state,$id_bibli,$id_sug) { global $msg,$charset; $button = "!!type_catal!!"; $state_name=$this->id_to_name[$state]; if ($this->getState_CATALOG($state_name)=='YES') { return $button; } return ""; } //Retourne un masque pour tenir compte des statuts archives function getMask_FILED() { $mask=(int)($this->states['FILED']['ID']); return $mask; } //Retourne le commentaire Texte associe a un etat function getTextComment($state) { global $msg,$charset; $mask = $this->getMask_FILED(); $disp_state = ($state & ~$mask); $comment = $msg[$this->getState_COMMENT($this->id_to_name[$disp_state])]; return $comment; } //Retourne le commentaire Html associe a un etat function getHtmlComment($state) { global $msg,$charset; $mask = $this->getMask_FILED(); $disp_state = ($state & ~$mask); $comment = htmlentities($msg[$this->getState_COMMENT($this->id_to_name[$disp_state])], ENT_QUOTES, $charset); if (($state & $mask) == $mask) $comment = ''.$comment.''; return $comment; } //Retourne le commentaire PDF associe a un etat function getPdfComment($state) { global $msg,$charset; $mask = $this->getMask_FILED(); $disp_state = ($state & ~$mask); $comment = htmlentities($msg[$this->getState_COMMENT($this->id_to_name[$disp_state])], ENT_QUOTES, $charset); if (($state & $mask) == $mask) $comment.= "\n".$msg['acquisition_sug_arc']; return $comment; } //Construction de la liste des boutons en fonction de l'état en cours function getScriptList($state='-1', $num_categ='-1',$nb_per_page) { global $msg, $charset; $script_list=""; if (!$state) $state='-1'; if ($state == '-1') { //Tous états possibles $script_list.= $this->getScriptList_MERGE($num_categ, $nb_per_page); foreach($this->states as $name=>$value) { eval('$script_list.= $this->getScriptList_'.$name.'('.$num_categ.', '.$nb_per_page.');'); } } else { $state_name=$this->id_to_name[$state]; $tostates=$this->transitions[$state_name]; if ($this->getState_MERGE[$state_name]!='NO') { $script_list.= $this->getScriptList_MERGE($num_categ, $nb_per_page); } foreach($tostates as $id=>$name) { eval('$script_list.= $this->getScriptList_'.$name.'('.$num_categ.', '.$nb_per_page.');'); } } return $script_list; } function getScriptList_MERGE($num_categ='-1',$nb_per_page) { global $msg; $script = " //Fusionne les éléments cochés function chk_MERGE() { if(!verifChk(2)) return false; r = confirm(\"".$msg['acquisition_sug_msg_fus']."\"); if (r) { document.forms['sug_list_form'].setAttribute('action', './acquisition.php?categ=sug&action=fusChk&num_categ=".$num_categ."&nb_per_page=".$nb_per_page."'); document.forms['sug_list_form'].submit(); return true; } return false; }"; return $script; } function getScriptList_VALIDATED($num_categ='-1',$nb_per_page) { global $msg; $script = " //Valide les éléments cochés function chk_VALIDATED() { if(!verifChk(1)) return false; r = confirm(\"".$msg['acquisition_sug_msg_val']."\"); if (r) { document.forms['sug_list_form'].setAttribute('action', './acquisition.php?categ=sug&transition=VALIDATED&action=list&num_categ=".$num_categ."&nb_per_page=".$nb_per_page."'); document.forms['sug_list_form'].submit(); return true; } return false; }"; return $script; } function getScriptList_REJECTED($num_categ='-1',$nb_per_page) { global $msg; $script = " //Rejete les éléments cochés function chk_REJECTED() { if(!verifChk(1)) return false; r = confirm(\"".$msg['acquisition_sug_msg_rej']."\"); if (r) { document.forms['sug_list_form'].setAttribute('action', './acquisition.php?categ=sug&transition=REJECTED&action=list&num_categ=".$num_categ."&nb_per_page=".$nb_per_page."'); document.forms['sug_list_form'].submit(); return true; } return false; }"; return $script; } function getScriptList_CONFIRMED($num_categ='-1',$nb_per_page) { global $msg; $script = " //Confirme les éléments cochés function chk_CONFIRMED() { if(!verifChk(1)) return false; r = confirm(\"".$msg['acquisition_sug_msg_con']."\"); if (r) { document.forms['sug_list_form'].setAttribute('action', './acquisition.php?categ=sug&transition=CONFIRMED&action=list&num_categ=".$num_categ."&nb_per_page=".$nb_per_page."'); document.forms['sug_list_form'].submit(); return true; } return false; }"; return $script; } function getScriptList_GIVENUP($num_categ='-1',$nb_per_page) { global $msg; $script = " //Abandonne les éléments cochés function chk_GIVENUP() { if(!verifChk(1)) return false; r = confirm(\"".$msg['acquisition_sug_msg_aba']."\"); if (r) { document.forms['sug_list_form'].setAttribute('action', './acquisition.php?categ=sug&transition=GIVENUP&action=list&num_categ=".$num_categ."&nb_per_page=".$nb_per_page."'); document.forms['sug_list_form'].submit(); return true; } return false; }"; return $script; } function getScriptList_ORDERED($num_categ='-1',$nb_per_page) { global $msg; global $acquisition_sugg_to_cde; if ($acquisition_sugg_to_cde) { $script.=" //Commande les éléments cochés function chk_ORDERED() { if(!verifChk(1)) return false; r = confirm(\"".$msg['acquisition_sug_msg_cde']."\"); if (r) { document.forms['sug_list_form'].setAttribute('action', './acquisition.php?categ=ach&sub=cde&action=from_sug'); document.forms['sug_list_form'].submit(); return true; } return false; }"; } else { $script.=" //Commande les éléments cochés function chk_ORDERED() { if(!verifChk(1)) return false; r = confirm(\"".$msg['acquisition_sug_msg_cde']."\"); if (r) { document.forms['sug_list_form'].setAttribute('action', './acquisition.php?categ=sug&transition=ORDERED&action=list&num_categ=".$num_categ."&nb_per_page=".$nb_per_page."'); document.forms['sug_list_form'].submit(); return true; } return false; }"; } return $script; } function getScriptList_ESTIMATED($num_categ='-1',$nb_per_page) { global $msg; global $acquisition_sugg_to_cde; if ($acquisition_sugg_to_cde) { $script.=" //Devise les éléments cochés function chk_ESTIMATED() { if(!verifChk(1)) return false; r = confirm(\"".$msg['acquisition_sug_msg_dev']."\"); if (r) { document.forms['sug_list_form'].setAttribute('action', './acquisition.php?categ=ach&sub=devi&action=from_sug'); document.forms['sug_list_form'].submit(); return true; } return false; }"; } else { $script.=" //Devise les éléments cochés function chk_ESTIMATED() { if(!verifChk(1)) return false; r = confirm(\"".$msg['acquisition_sug_msg_dev']."\"); if (r) { document.forms['sug_list_form'].setAttribute('action', './acquisition.php?categ=sug&transition=ESTIMATED&action=list&num_categ=".$num_categ."&nb_per_page=".$nb_per_page."'); document.forms['sug_list_form'].submit(); return true; } return false; }"; } return $script; } function getScriptList_RECEIVED($num_categ='-1',$nb_per_page) { global $msg; $script = " //Reçoit les éléments cochés function chk_RECEIVED() { if(!verifChk(1)) return false; r = confirm(\"".$msg['acquisition_sug_msg_rec']."\"); if (r) { document.forms['sug_list_form'].setAttribute('action', './acquisition.php?categ=sug&transition=RECEIVED&action=list&num_categ=".$num_categ."&nb_per_page=".$nb_per_page."'); document.forms['sug_list_form'].submit(); return true; } return false; }"; return $script; } function getScriptList_FILED($num_categ='-1',$nb_per_page) { global $msg; $script = " //Archive les éléments cochés function chk_FILED() { if(!verifChk(1)) return false; r = confirm(\"".$msg['acquisition_sug_msg_arc']."\"); if (r) { document.forms['sug_list_form'].setAttribute('action', './acquisition.php?categ=sug&transition=FILED&action=list&num_categ=".$num_categ."&nb_per_page=".$nb_per_page."'); document.forms['sug_list_form'].submit(); return true; } return false; }"; return $script; } function getScriptList_TODO($num_categ='-1',$nb_per_page) { global $msg; $script = " //Archive les éléments cochés function chk_TODO() { if(!verifChk(1)) return false; r = confirm(\"".$msg['acquisition_sug_msg_todo']."\"); if (r) { document.forms['sug_list_form'].setAttribute('action', './acquisition.php?categ=sug&transition=TODO&num_categ=".$num_categ."&nb_per_page=".$nb_per_page."'); document.forms['sug_list_form'].submit(); return true; } return false; }"; return $script; } function getScriptList_DELETED() { global $msg; $script = " //Supprime les éléments cochés function chk_DELETED() { if(!verifChk(1)) return false; r = confirm(\"".$msg['acquisition_sug_msg_sup']."\"); if (r) { document.forms['sug_list_form'].setAttribute('action', './acquisition.php?categ=sug&transition=DELETED'); document.forms['sug_list_form'].submit(); return true; } return false; }"; return $script; } //Effectue une transition function doTransition($toname,$chk){ global $acquisition_email_sugg; foreach($chk as $key=>$id_sug){ if ($id_sug) { $sug = new suggestions($id_sug); $state_name = $this->getStateNameFromId($sug->statut); if ($state_name) { //Statut existant if (in_array($toname, $this->transitions[$state_name])) { if ($this->getState_ADD($toname)== 'YES' ){ $sug->statut = (int)($sug->statut) | (int)($this->getState_ID($toname)); } else { $sug->statut = (int)($this->getState_ID($toname)); } if ($acquisition_email_sugg && $this->mail_on_transition[$state_name][$this->getStateNameFromId($sug->statut)]=='YES') $this->sendmail($sug); } $sug->save(); } } } $this->has_unimarc = false; foreach($chk as $key=>$id_sug){ if ($id_sug) { $sug = new suggestions($id_sug); $state_name = $this->getStateNameFromId($sug->statut); if ($state_name) { //Statut existant $tab_action=$this->getState_ACTION($state_name); if (is_array($tab_action)){ foreach($tab_action as $dummykey=>$action){ switch ($action['NAME']) { case 'GOTOFIRSTSTATE' : $sug->statut = $this->getState_ID($this->firststate); $sug->save(); break; case 'DELETE' : $sug->delete(); suggestions_origine::delete($id_sug); break; case 'CATALOG' : if($sug->sugg_noti_unimarc) $this->has_unimarc = true; break; } } } } else { //statut inexistant if ($toname == 'DELETE'){ //Si transition = DELETE, on supprime la suggestion $sug->delete(); suggestions_origine::delete($id_sug); } } } } } //Change la categorie pour un tableau de suggestions function changeCateg($chk, $to_categ) { foreach($chk as $key=>$id_sug){ $sug = new suggestions($id_sug); $state_name = $this->getStateNameFromId($sug->statut); if ($this->getState_CATEG($state_name)== 'YES' && suggestions_categ::exists($to_categ) ){ $sug->num_categ = $to_categ; $sug->save(); } } } //Retourne l'id de l'etat de depart function getFirstStateId() { return $this->getState_ID($this->firststate); } //Retourne le nom de l'etat a partir de l'id function getStateNameFromId($state_id) { $mask = $this->getMask_FILED(); if (($state_id & $mask)==$mask ) $state_id=$mask; return $this->id_to_name[$state_id]; } //Fonction d'envoi de mail function sendMail($sug) { global $dbh, $msg, $charset; global $biblio_name,$biblio_email,$biblio_phone; global $acquisition_mel_rej_obj, $acquisition_mel_rej_cor; global $acquisition_mel_con_obj, $acquisition_mel_con_cor; global $acquisition_mel_aba_obj, $acquisition_mel_aba_cor; global $acquisition_mel_cde_obj, $acquisition_mel_cde_cor; global $acquisition_mel_rec_obj, $acquisition_mel_rec_cor; $mask = $this->getMask_FILED(); if (($sug->statut & $mask)==0 ) $state=$sug->statut; else $state=$mask; $state_name = $this->id_to_name[$state]; switch($state_name) { case 'REJECTED' : //Rejet $objet = $acquisition_mel_rej_obj; $corps = $acquisition_mel_rej_cor; break; case 'CONFIRMED' : //Confirmation $objet = $acquisition_mel_con_obj; $corps = $acquisition_mel_con_cor; break; case 'GIVENUP' : //Abandon $objet = $acquisition_mel_aba_obj; $corps = $acquisition_mel_aba_cor; break; case 'ORDERED' : //Commande $objet = $acquisition_mel_cde_obj; $corps = $acquisition_mel_cde_cor; break; case 'RECEIVED' : //Réception $objet = $acquisition_mel_rec_obj; $corps = $acquisition_mel_rec_cor; break; default : return; break; } $corps.="\n\n ".$msg['acquisition_sug_tit']." :\t ".$sug->titre."\n"; if($sug->auteur) $corps.= $msg['acquisition_sug_aut']." :\t ".$sug->auteur."\n"; if($sug->editeur) $corps.= $msg['acquisition_sug_edi']." :\t ".$sug->editeur."\n"; if($sug->code) $corps.= $msg['acquisition_sug_cod']." :\t ".$sug->code."\n"; if($sug->prix) $corps.= $msg['acquisition_sug_pri']." :\t ".$sug->prix."\n"; if($sug->commentaires) $corps.= $msg['acquisition_sug_com']." :\t ".$sug->commentaires."\n"; $corps.= "\n\n"; $corps = str_replace('!!date!!', formatdate($sug->date_creation), $corps); $q = suggestions_origine::listOccurences($sug->id_suggestion); $list_orig = mysql_query($q, $dbh); while($row = mysql_fetch_object($list_orig)) { switch($row->type_origine){ default: case '0' : $q = "SELECT nom, prenom, user_email FROM users where userid = '".$row->origine."' limit 1 "; $r = mysql_fetch_object(mysql_query($q, $dbh)); $tonom = $r->prenom." ".$r->nom; $tomail = $r->user_email; break; case '1' : $q = "SELECT empr_nom, empr_prenom, empr_mail FROM empr where id_empr = '".$row->origine."' limit 1 "; $r = mysql_fetch_object(mysql_query($q, $dbh)); $tonom = $r->empr_prenom." ".$r->empr_nom; $tomail = $r->empr_mail; break; case '2' : $tonom = $row->origine; $tomail = $row->origine; break; } if($tomail != '') { $res_envoi=mailpmb($tonom, $tomail, $objet, $corps, $biblio_name, $biblio_email,"Content-Type: text/plain; charset=\"$charset\"\n", "", ""); } } } } ?>