id_type = $atache["ID"]; $this->name = $atache["NAME"]; $this->comment = $msg[str_replace("msg:", "", $atache["COMMENT"])]; if (!$this->id_type || !$this->name) return false; $tache_path = $base_path."/admin/planificateur/".$this->name; $this->get_messages($tache_path); //fichier de commandes $xml_commands=file_get_contents($base_path."/admin/planificateur/workflow.xml"); $xml_dom_commands = new xml_dom($xml_commands); $filename = $tache_path."/manifest.xml"; //fichier manifest spécifique $xml_manifest=file_get_contents($filename); $xml_dom_manifest = new xml_dom($xml_manifest); $this->states = $this->parse_states($xml_dom_commands, $xml_dom_manifest); $this->commands = $this->parse_commands($xml_dom_commands, $xml_dom_manifest); $this->dir_upload_boolean = $this->parse_dir_upload($xml_dom_manifest); } function get_id_type() { return $this->id_type; } //messages function get_messages($tache_path) { global $lang; if (file_exists($tache_path."/messages/".$lang.".xml")) { $file_name=$tache_path."/messages/".$lang.".xml"; } else if (file_exists($tache_path."/messages/fr_FR.xml")) { $file_name=$tache_path."/messages/fr_FR.xml"; } if ($file_name) { $xmllist=new XMLlist($file_name); $xmllist->analyser(); $this->msg=$xmllist->table; } } // listing des états function parse_states($xml_dom_commands, $xml_dom_manifest) { global $base_path; $nodes_nostates_manifest = $xml_dom_manifest->get_nodes("manifest/capacities/nostates/state"); $nodes_states_manifest = $xml_dom_manifest->get_nodes("manifest/capacities/states/state"); $nodes_states = $xml_dom_commands->get_nodes("workflow/states/state"); foreach ($nodes_states as $id=>$node_state) { $t=array(); $state_impossible = false; if ($nodes_nostates_manifest) { foreach ($nodes_nostates_manifest as $node_nostate_manifest) { if (($xml_dom_manifest->get_attribute($node_nostate_manifest, "name")) == ($xml_dom_commands->get_attribute($node_state,"name"))){ $state_impossible = true; } } } //etat possible if (!$state_impossible) { $t["id"] = $xml_dom_commands->get_attribute($node_state,"id"); $t["name"] = $xml_dom_commands->get_attribute($node_state,"name"); $nodes_next_states = $xml_dom_commands->get_nodes("workflow/states/state[$id]/nextState"); $t2 = array(); if ($nodes_next_states) { foreach ($nodes_next_states as $index=>$node_next_state) { $command_impossible = false; if ($nodes_states_manifest) { foreach ($nodes_states_manifest as $k=>$node_state_manifest) { if (($xml_dom_manifest->get_attribute($node_state_manifest, "name")) == ($xml_dom_commands->get_attribute($node_state,"name"))){ $nodes_nocommands_manifest = $xml_dom_manifest->get_nodes("manifest/capacities/states/state[$k]/nocommand"); if ($nodes_nocommands_manifest) { foreach ($nodes_nocommands_manifest as $node_nocommand_manifest) { if (($xml_dom_manifest->get_attribute($node_nocommand_manifest, "commands")) == ($xml_dom_commands->get_attribute($node_next_state,"commands"))){ $command_impossible = true; } } } } } } if (!$command_impossible) { $t2[$index]["command"] = $xml_dom_commands->get_attribute($node_next_state,"commands"); $t2[$index]["dontsend"] = $xml_dom_commands->get_attribute($node_next_state,"dontsend"); $t2[$index]["value"] = $xml_dom_commands->get_value("workflow/states/state[$id]/nextState[$index]"); $value = $index; } } } if ($nodes_states_manifest) { foreach ($nodes_states_manifest as $k=>$node_state_manifest) { if (($xml_dom_manifest->get_attribute($node_state_manifest, "name")) == ($xml_dom_commands->get_attribute($node_state,"name"))){ $nodes_add_commands_manifest = $xml_dom_manifest->get_nodes("manifest/capacities/states/state[$k]/nextState"); if ($nodes_add_commands_manifest) { foreach ($nodes_add_commands_manifest as $node_add_command_manifest) { //ajout des nouvelles commandes $value++; $t2[$value]["command"] = $xml_dom_manifest->get_attribute($node_add_command_manifest, "commands"); $t2[$value]["dontsend"] = $xml_dom_manifest->get_attribute($node_add_command_manifest,"dontsend"); $t2[$value]["value"] = $xml_dom_manifest->get_value("manifest/capacities/states/state[$k]/nextState"); } } } } } $t["nextState"] = $t2; $tab_states[$t["name"]]=$t; } } return $tab_states; } // listing des commandes function parse_commands($xml_dom_commands, $xml_dom_manifest) { global $base_path, $msg, $lang; $nodes_commands = $xml_dom_commands->get_nodes("workflow/commands/command"); if ($nodes_commands) { foreach ($nodes_commands as $id=>$node_command) { $t=array(); $t["id"] = $xml_dom_commands->get_attribute($node_command,"id"); $t["name"] = $xml_dom_commands->get_attribute($node_command,"name"); $t["label"] = $msg[str_replace("msg:", "", $xml_dom_commands->get_attribute($node_command,"label"))]; $tab_commands[$t["name"]]=$t; } } $nodes_commands_manifest = $xml_dom_manifest->get_nodes("manifest/capacities/commands/command"); if ($nodes_commands_manifest) { foreach ($nodes_commands_manifest as $id=>$node_command_manifest) { $t=array(); $t["id"] = $xml_dom_manifest->get_attribute($node_command_manifest,"id"); $t["name"] = $xml_dom_manifest->get_attribute($node_command_manifest,"name"); $t["label"] = $this->msg[str_replace("msg:", "", $xml_dom_manifest->get_attribute($node_command_manifest,"label"))]; $tab_commands[$t["name"]]=$t; } } return $tab_commands; } // Est-ce une tâche qui demande un répertoire d'upload pour des fichiers générés?? function parse_dir_upload($xml_dom_manifest) { $node_directory = $xml_dom_manifest->get_node("manifest/directory_upload"); if ($node_directory) { return $xml_dom_manifest->get_value("manifest/directory_upload"); } else { return "0"; } } function setEsProxy($proxy) { $this->proxy = $proxy; } function listen_commande($methode_callback) { global $dbh; $query_commande = "select status, commande, next_state from taches where id_tache=".$this->id_tache; $result = mysql_query($query_commande, $dbh); if (mysql_result($result,0,"commande") != '0') { $cmd = mysql_result($result,0,"commande"); $requete = "update taches set status=".mysql_result($result,0, "next_state").", commande=0, next_state=0 where id_tache=".$this->id_tache.""; $res = mysql_query($requete, $dbh); if ($res) { $this->statut = mysql_result($result,0, "next_state"); call_user_func($methode_callback,$cmd); } } } // Envoi d'une commande par la tache, changement du statut de la tâche... function send_command($state=''){ global $dbh; if ($state != '') { $this->statut = $state; mysql_query("update taches set status=".$this->statut." where id_tache='".$this->id_tache."'", $dbh); } // return $cmd; } function make_serialized_task_params() { global $timeout, $histo_day, $histo_number; $t["timeout"] = ($timeout != "0" ? $timeout : ""); $t["histo_day"] = ($histo_day != "0" ? $histo_day : ""); $t["histo_number"] = ($histo_number != "0" ? $histo_number : ""); return $t; } //Sauvegarde des propriétés générales function save_global_properties() { global $dbh; $requete="replace into taches_type (id_type_tache,parameters, timeout, histo_day, histo_number) values('".$this->get_id_type()."', '".serialize($this->parameters)."','".$this->timeout."','".$this->histo_day."','".$this->histo_number."')"; return mysql_query($requete, $dbh); } //sauvegarde des données du formulaire, function save_property_form($planificateur_id) { global $dbh, $type_task_id, $charset; global $task_name, $task_desc,$form_users, $task_active; global $id_rep, $path; global $task_perio_heure, $task_perio_min, $chkbx_task_hebdo, $chkbx_task_mensuel; $params = $this->make_serialized_task_params(); $task_perio_heure = ($task_perio_heure == '') ? '*' : $task_perio_heure; $task_perio_minute = ($task_perio_min == '') ? '*' : $task_perio_min; //concaténation de la periodicité des jours de la semaine $task_perio_hebdo = ""; if ($chkbx_task_hebdo[0] == '*') { $task_perio_hebdo.= $chkbx_task_hebdo[0].","; } else { for ($i=0; $iformate_path_to_save($up->formate_path_to_nom($path)); } else { $id_rep=""; $path_name = ""; } // est-ce une nouvelle tâche ?? if ($planificateur_id == '') { //Nouvelle planification $requete="insert into planificateur (num_type_tache, libelle_tache, desc_tache, num_user, param, statut, rep_upload, path_upload, perio_heure, perio_minute, perio_jour, perio_mois) values(".$type_task_id.",'".addslashes($task_name)."','".addslashes($task_desc)."', '".$form_users."','".$params."','".$task_active."','".$id_rep."','".$path_name."','".$task_perio_heure."','".$task_perio_minute."', '".htmlentities($task_perio_hebdo, ENT_QUOTES,$charset)."','".htmlentities($task_perio_mensuel, ENT_QUOTES,$charset)."')"; mysql_query($requete, $dbh); $planificateur_id = mysql_insert_id(); } else { //Mise à jour des informations $requete="update planificateur set num_type_tache = '".$type_task_id."', libelle_tache = '".addslashes($task_name)."', desc_tache = '".addslashes($task_desc)."', num_user = '".$form_users."', param = '".$params."', statut = '".$task_active."', rep_upload = '".$id_rep."', path_upload = '".$path_name."', perio_heure = '".$task_perio_heure."', perio_minute = '".$task_perio_minute."', perio_jour = '".htmlentities($task_perio_hebdo, ENT_QUOTES,$charset)."', perio_mois = '".htmlentities($task_perio_mensuel, ENT_QUOTES,$charset)."' where id_planificateur='".$planificateur_id."'"; mysql_query($requete, $dbh); } //calcul de la prochaine exécution $this->calcul_execution($planificateur_id); //Vérification des paramètres enregistrés $this->checkParams($planificateur_id); // insertion d'une nouvelle tâche si aucune n'est planifiée $this->insertOfTask($planificateur_id, $task_active); } /* Calcul prochaine execution */ function calcul_execution($id_planificateur) { global $dbh; if ($id_planificateur) { $call_calendar = new tache_calendar($id_planificateur); $jour = $call_calendar->new_date["JOUR"]; $mois = $call_calendar->new_date["MOIS"]; $annee = $call_calendar->new_date["ANNEE"]; $heure = $call_calendar->new_date["HEURE"]; $minute = $call_calendar->new_date["MINUTE"]; $date_exec = $annee."-".$mois."-".$jour; $heure_exec = $heure.":".$minute; } else { $date_exec = ""; $heure_exec = ""; } //mise à jour de la prochaine planification $requete_planificateur = "update planificateur set calc_next_heure_deb='".$heure_exec."', calc_next_date_deb='".$date_exec."' where id_planificateur=".$id_planificateur; mysql_query($requete_planificateur, $dbh); } function insertOfTask($num_planificateur, $active ='') { global $dbh; if ($active == '') { //statut de la tâche $query_state = "select statut from planificateur where id_planificateur=".$num_planificateur; $result_query_state = mysql_query($query_state, $dbh); if (mysql_num_rows($result_query_state) > 0) { $active = mysql_result($result_query_state,0, "statut"); } } // on recherche si cette planification possède une tâche en attente ou en cours d'exécution... $query = "select t.id_tache, t.num_planificateur, p.statut from taches t, planificateur p where t.num_planificateur=p.id_planificateur and t.end_at='0000-00-00 00:00:00' and t.num_planificateur=".$num_planificateur; $result_query = mysql_query($query, $dbh); // nouvelle planification && planification activée if ((mysql_num_rows($result_query) == 0) && ($active == '1')) { //valeur maximale d'identifiant de tâche $reqMaxId = mysql_query("select max(id_tache) as maxId from taches",$dbh); $rowMaxId = mysql_fetch_row($reqMaxId); $id_tache = $rowMaxId[0] + 1; //insertion de la tâche planifiée $requete="insert into taches (id_tache, num_planificateur, status, commande, indicat_progress,id_process) values(".$id_tache.",'".$num_planificateur."',1,0,0,0)"; $res = mysql_query($requete, $dbh); // modification planification && planification désactivée } else if ((mysql_num_rows($result_query) == 1) && ($active == '0')) { //il faut vérifier que la tâche ne soit pas déjà planifiée, si oui on la supprime if (mysql_num_rows($result_query) >= 1) { $requete="delete from taches where start_at='0000-00-00 00:00:00' and num_planificateur='".$num_planificateur."'"; mysql_query($requete, $dbh); } } } function get_report_datas($id_tache) { global $dbh; $sql = "SELECT t.id_tache, p.num_type_tache, p.libelle_tache, t.start_at, t.end_at, t.status, t.indicat_progress, t.rapport FROM taches t,planificateur p Where t.num_planificateur = p.id_planificateur And t.id_tache=".$id_tache." order by p.calc_next_date_deb DESC "; $res=mysql_query($sql, $dbh); if (mysql_num_rows($res)) { $r = mysql_fetch_object($res); $task["id_tache"]=$r->id_tache; $task["num_planificateur"]=$r->num_planificateur; $task["libelle_tache"]=$r->libelle_tache; $task["start_at"]= explode (" ",$r->start_at); $task["end_at"]= explode (" ",$r->end_at); $task["status"] = $r->status; $task["indicat_progress"] = $r->indicat_progress; $task["rapport"] = unserialize(htmlspecialchars_decode($r->rapport, ENT_QUOTES)); } else { $task["id_tache"]=""; $task["num_planificateur"]=""; $task["libelle_tache"]=""; $task["start_at"]=""; $task["end_at"]=""; $task["status"] = ""; $task["indicat_progress"] = ""; $task["rapport"] = ""; } return $task; } function fetch_default_global_values() { $this->parameters=""; $this->timeout=5; $this->histo_day=7; $this->histo_number=3; } //Propriétes globales d'un type de tache du planificateur (timeout, histo_day, ...) function fetch_global_properties() { global $dbh; global $type_task_id; $requete="select parameters, timeout, histo_day, histo_number from taches_type where id_type_tache='".$type_task_id."'"; $resultat=mysql_query($requete, $dbh); if (mysql_num_rows($resultat)) { $r=mysql_fetch_object($resultat); $this->parameters=unserialize($r->parameters); $this->timeout=$r->timeout; $this->histo_day=$r->histo_day; $this->histo_number=$r->histo_number; } else { $this->fetch_default_global_values(); } } /* * Exécution de la tâche - Méthode appelée par la classe spécifique * Modification des données de la base */ function execute() { global $dbh,$charset; //initialisation de la tâche planifiée sur la base $this->initialize(); //appel de la méthode spécifique $this->task_execution(); //, array(&$this, "update_progression") //finalisation de la tâche planifiée sur la base $this->finalize(); // if ($this->error) { // $this->write_log_task(); // } $result_success = mysql_query("select id_tache, num_planificateur from taches where id_tache=".$this->id_tache); //mise à jour de la prochaine exec if (mysql_num_rows($result_success) == 1) { //planification d'une nouvelle tâche $this->calcul_execution(mysql_result($result_success,0,"num_planificateur")); $this->insertOfTask(mysql_result($result_success,0,"num_planificateur")); } } // function write_log_task($msg_,$taskid) { // global $dbh; // // $requete="insert into taches_log (num_tache, message, date) values('$taskid','$msg_',now())"; // mysql_query($requete, $dbh); // } //appelée si show_report non existant classe spécifique fille function show_report($task_rapport) { global $charset; if ($task_rapport != "") { $report_execution = ""; foreach ($task_rapport as $ligne) { if (is_array($ligne)) { foreach ($ligne as $une_ligne) { $report_execution .= html_entity_decode($une_ligne, ENT_QUOTES, $charset)."
"; } } else { $report_execution .= html_entity_decode($ligne, ENT_QUOTES, $charset); } } $report_execution .= "
"; } return $report_execution; } //vérification de deux paramètres génériques (historique, nb exécution conservées) function checkParams($id_planificateur) { global $dbh; $requete = "select param from planificateur where id_planificateur=".$id_planificateur; $resultat=mysql_query($requete, $dbh); if (mysql_num_rows($resultat) > 0) { $r=mysql_fetch_object($resultat); $params=unserialize($r->param); if ($params) { foreach ($params as $index=>$param) { if (($index == "histo_day") && ($param != "") && ($param !="0")) { $requete_suppr = "delete from taches where num_planificateur ='".$id_planificateur."' and end_at < DATE_SUB(curdate(), INTERVAL ".$param." DAY) and end_at != '0000-00-00 00:00:00'"; mysql_query($requete_suppr, $dbh); } if (($index == "histo_number") && ($param != "") && ($param !="0")) { //check nbre exécution $requete_select = "select count(*) as nbre from taches where num_planificateur =".$id_planificateur." and end_at != '0000-00-00 00:00:00'"; $result = mysql_query($requete_select, $dbh); $nb = mysql_result($result, 0,"nbre"); if ($nb > $param) { $nb_r = $nb - $param; $query = "delete from taches where num_planificateur=".$id_planificateur." and end_at != '0000-00-00 00:00:00' order by end_at ASC limit ".$nb_r; mysql_query($query, $dbh); // il faut aussi effacer les documents numériques... //en base... $query_del_docnum = "delete from taches_docnum where num_tache not in (select id_tache from taches)"; mysql_query($query_del_docnum); } } } } } } //recherche les informations de la tâche planifiée si elles est existante, dans le cas d'une modif... function get_property_task_bdd($planificateur_id) { global $dbh; if (!$planificateur_id) { $planificateur_id = 0; } $requete="SELECT id_planificateur, num_type_tache, libelle_tache, desc_tache, num_user, param, statut, rep_upload, path_upload, perio_heure, perio_minute, perio_jour, perio_mois, calc_next_heure_deb, calc_next_date_deb,repertoire_nom, repertoire_path FROM planificateur left join upload_repertoire on rep_upload=repertoire_id where id_planificateur=".$planificateur_id; $res=mysql_query($requete,$dbh); if (mysql_num_rows($res)) { $r = mysql_fetch_object($res); $t["planificateur_id"]=$r->id_planificateur; $t["num_type_tache"]=$r->num_type_tache; $t["libelle_tache"]=htmlspecialchars_decode(stripslashes($r->libelle_tache),ENT_QUOTES); $t["desc_tache"]=htmlspecialchars_decode(stripslashes($r->desc_tache), ENT_QUOTES); $t["num_user"]=$r->num_user; $t["param"] = unserialize($r->param); $t["statut"] = $r->statut; $t["rep_upload"] = $r->rep_upload; $t["path_upload"] = $r->path_upload; $t["perio_heure"] = $r->perio_heure; $t["perio_minute"] = $r->perio_minute; $t["perio_jour"] = explode(",",$r->perio_jour); $t["perio_mois"] = explode(",",$r->perio_mois); $t["calc_next_heure_deb"] = $r->calc_next_heure_deb; $t["calc_next_date_deb"] = $r->calc_next_date_deb; $t["repertoire_nom"] = $r->repertoire_nom; $t["repertoire_path"] = $r->repertoire_path; } else { $t["planificateur_id"]=""; $t["num_type_tache"]=""; $t["libelle_tache"]=""; $t["desc_tache"]=""; $t["num_user"]=""; $t["param"]["timeout"] = $this->timeout; $t["param"]["histo_day"] = $this->histo_day; $t["param"]["histo_number"] = $this->histo_number; $t["statut"] = "1"; $t["rep_upload"] = "0"; $t["path_upload"] = ""; $t["perio_heure"] = "*"; $t["perio_minute"] = "01"; $t["perio_jour"] = ""; $t["perio_mois"] = ""; $t["calc_next_heure_deb"] = ""; $t["calc_next_date_deb"] = ""; $t["repertoire_nom"] = ""; $t["repertoire_path"] = ""; } return $t; } function get_task_params() { $params = ""; if ($this->id_tache) { $result = mysql_query("select param from planificateur, taches where id_planificateur=num_planificateur and id_tache=".$this->id_tache); if ($result) $params = unserialize(mysql_result($result, 0,"param")); } return $params; } function initialize() { global $dbh; $this->statut = RUNNING; $requete = "update taches set start_at = CURRENT_TIMESTAMP, status = ".$this->statut." where id_tache='".$this->id_tache."'"; mysql_query($requete,$dbh); } function finalize() { global $dbh,$base_path; $res = mysql_query("select indicat_progress from taches where id_tache=".$this->id_tache); $progress = mysql_result($res,0, "indicat_progress"); if ($progress == 100) $this->statut=ENDED; else $this->statut = FAILED; //fin de l'exécution, mise à jour sur la base $req = "update taches set end_at = CURRENT_TIMESTAMP, status = ".$this->statut.", commande=0, rapport = '".htmlspecialchars(serialize($this->report), ENT_QUOTES)."',id_process=0 where id_tache='".$this->id_tache."'"; mysql_query($req,$dbh); } function update_progression($percent) { global $dbh; if ($this->id_tache) { $requete = "update taches set indicat_progress ='".$percent."' where id_tache=".$this->id_tache; mysql_query($requete,$dbh); } } function isUploadValide($id_tache) { global $dbh; $query_sel = "select distinct p.libelle_tache, p.rep_upload, p.path_upload from planificateur p left join taches t on t.num_planificateur = p.id_planificateur left join taches_docnum tdn on tdn.tache_docnum_repertoire=p.rep_upload where t.id_tache=".$id_tache; $res_query = mysql_query($query_sel, $dbh); if ($res_query) { $row = mysql_fetch_object($res_query); $up = new upload_folder($row->rep_upload); $nom_chemin = $up->formate_nom_to_path($up->repertoire_nom.$row->path_upload); if ((is_dir($nom_chemin)) && (is_writable($nom_chemin))) return true; } return false; } // que passer à cette fonction datas ou object ?? (objet pdf , contenu xls) function generate_docnum($id_tache, $content, $mimetype="application/pdf", $ext_fichier="pdf") { global $dbh,$msg, $base_path; $tdn = new tache_docnum(); $tdn->num_tache = $id_tache; $query_sel = "select distinct p.libelle_tache, p.rep_upload, p.path_upload from planificateur p left join taches t on t.num_planificateur = p.id_planificateur left join taches_docnum tdn on tdn.tache_docnum_repertoire=p.rep_upload where t.id_tache=".$tdn->num_tache; $res_query = mysql_query($query_sel, $dbh); if ($res_query) { $row = mysql_fetch_object($res_query); $up = new upload_folder($row->rep_upload); $nom_chemin = $up->formate_nom_to_path($up->repertoire_nom.$row->path_upload); // if ((!is_dir($nom_chemin)) || (!is_writable($nom_chemin))) { // $nom_chemin = $base_path."/temp/"; // } //appel de fonction pour le calcul de nom de fichier $date_now = date('Ymd'); // $tdn->tache_docnum_nomfichier = str_replace(" ", "_", $row->libelle_tache)."_".$date_now; $tdn->tache_docnum_nomfichier = clean_string_to_base($row->libelle_tache)."_".$date_now; $tdn->tache_docnum_contenu = $content; $tdn->tache_docnum_extfichier= $ext_fichier; $tdn->tache_docnum_file = ""; $tdn->tache_docnum_mimetype = $mimetype; $tdn->tache_docnum_repertoire = $row->rep_upload; $tdn->tache_docnum_path = $row->path_upload; $path_absolu = $nom_chemin.$tdn->tache_docnum_nomfichier.".".$tdn->tache_docnum_extfichier; if (file_exists($path_absolu)) { $i=2; while (file_exists($nom_chemin.$tdn->tache_docnum_nomfichier."_".$i.".".$tdn->tache_docnum_extfichier)) { $i++; } $path_absolu = $nom_chemin.$tdn->tache_docnum_nomfichier."_".$i.".".$tdn->tache_docnum_extfichier; $tdn->tache_docnum_nomfichier = $tdn->tache_docnum_nomfichier."_".$i; } $path_absolu = $up->encoder_chaine($path_absolu); //verifier permissions d'ecriture... if (is_writable($nom_chemin)) { switch ($mimetype) { case "application/pdf" : $content->Output($path_absolu,"F"); break; case "application/ms-excel" : file_put_contents($path_absolu, $content); break; } // if ($mimetype == "application/pdf") { // $content->Output($path_absolu,"F"); // } else if ($mimetype == "application/ms-excel") { // file_put_contents($path_absolu, $content); // } $tdn->save(); $this->report[] = "".$msg["planificateur_write_success"]." : ".$tdn->tache_docnum_nomfichier.".".$tdn->tache_docnum_extfichier.""; return true; } else { $this->report[] = "".sprintf($msg["planificateur_write_error"],$path_absolu).""; return false; } } } function show_form() { // à surcharger } } class taches { var $types_taches=array(); // liste des types de tâches function taches() { global $base_path; $filename = $base_path."/admin/planificateur/catalog.xml"; $this->parse_catalog($filename); } function parse_catalog($filename) { global $base_path,$type_task_id; $xml=file_get_contents($filename); $param=_parser_text_no_function_($xml,"CATALOG"); foreach ($param["ACTION"] as $anitem) { $this->types_taches[] = new tache($anitem); } } //retourne le nombre de tâches associé à un type de tâche function get_nb_tasks($type_task_id) { global $dbh; $res = mysql_query("select * from planificateur where num_type_tache=".$type_task_id,$dbh); $nb = mysql_num_rows($res); return $nb; } //retourne le nombre de tâches associé à un type de tâche function get_nb_docnum($id_tache) { global $dbh; $res = mysql_query("select * from taches t, taches_docnum tdn where t.id_tache=tdn.num_tache and id_tache=".$id_tache,$dbh); $nb = mysql_num_rows($res); return $nb; } //affiche la planification de tâches par type function get_tasks($num_type_tache) { global $dbh; $sql = "SELECT id_planificateur, libelle_tache, desc_tache FROM planificateur WHERE num_type_tache = '".$num_type_tache."'"; $res = mysql_query($sql, $dbh); $parity_source= $num_type_tache % 2; if ($res) { while ($row=mysql_fetch_object($res)) { $pair_impair_source = $parity_source++ % 2 ? "even" : "odd"; $tr_javascript_source=" onmouseover=\"this.className='surbrillance'\" onmouseout=\"this.className='$pair_impair_source'\" onmousedown=\"if (event) e=event; else e=window.event; if (e.srcElement) target=e.srcElement; else target=e.target; if (target.nodeName!='INPUT') document.location='./admin.php?categ=planificateur&sub=manager&act=task&type_task_id=".$num_type_tache."&planificateur_id=".$row->id_planificateur."';\" "; print " ".htmlspecialchars_decode(stripslashes($row->libelle_tache),ENT_QUOTES)." ".htmlspecialchars_decode(stripslashes(substr($row->desc_tache,0,60)),ENT_QUOTES)." "; } } } //documents numériques par tâches en cours ou exécutées function get_docsnum($task_id) { global $dbh; $sql = "SELECT id_tache_docnum, tache_docnum_nomfichier, tache_docnum_mimetype,tache_docnum_extfichier, tache_docnum_repertoire FROM taches_docnum WHERE num_tache = '".$task_id."'"; $res = mysql_query($sql, $dbh); $tab_docnum = array(); if ($res) { while ($row=mysql_fetch_object($res)) { $t=array(); $t["id_tache_docnum"] = $row->id_tache_docnum; $t["tache_docnum_nomfichier"] = $row->tache_docnum_nomfichier; $t["tache_docnum_mimetype"] = $row->tache_docnum_mimetype; $t["tache_docnum_extfichier"] = $row->tache_docnum_extfichier; $t["tache_docnum_repertoire"] = $row->tache_docnum_repertoire; $tab_docnum[] = $t; } } $tdn = new tache_docnum(); print ""; print $tdn->show_docnum_table($tab_docnum, ""); print ""; } // affichage partie reporting function get_tasks_plan() { global $dbh, $msg,$charset; $sql = "SELECT t.id_tache, p.num_type_tache, p.libelle_tache, t.start_at, t.end_at, t.status, t.msg_statut, p.calc_next_date_deb, p.calc_next_heure_deb, t.commande, t.indicat_progress FROM taches t,planificateur p Where t.num_planificateur = p.id_planificateur "; // order by start_at DESC // if(start_at='0000-00-00 00:00:00','status',''), $sql_first .= $sql." and start_at = '0000-00-00 00:00:00'"; $sql_second .= $sql." and start_at <> '0000-00-00 00:00:00' order by t.start_at DESC"; $res = mysql_query($sql_first, $dbh); $res2 = mysql_query($sql_second, $dbh); $pair_impair=0; $parity=0; print ""; //taches en attente... if ($res) { while ($row=mysql_fetch_object($res)) { global $pair_impair_source; $pair_impair_source = $parity_source++ % 2 ? "even" : "odd"; $this->row_planned($row); } } //taches en cours et terminé if ($res2) { while ($row2=mysql_fetch_object($res2)) { $pair_impair_source = $parity_source++ % 2 ? "even" : "odd"; global $pair_impair_source; $this->row_planned($row2); } } // //recherche du nombre de documents numériques par tâche // $n_docsnum = $this->get_nb_docnum($row->id_tache); // // //comment task // $comment = ""; // foreach ($this->types_taches as $atache) { // if ($atache->id_type == $row->num_type_tache) { // $comment = $atache->comment; // //présence de commandes .. selecteurs ?? // $show_commands = ""; // foreach ($atache->states as $aelement) { // if ($row->status == $aelement["id"]) { // foreach ($aelement["nextState"] as $state) { // if ($state["command"] != "") { // //récupère le label de la commande // foreach($atache->commands as $command) { // if (($state["command"] == $command["name"]) && ($state["dontsend"] != "yes")) { // $show_commands .= ""; // } // } // } // } // } // } // } // } // // //lien du rapport // if ($row->end_at == '0000-00-00 00:00:00') { // $line=" onmouseover=\"this.className='surbrillance'\" onmouseout=\"this.className='$pair_impair_source'\" onmousedown=\"if (event) e=event; else e=window.event; \" "; // } else { // $line=" onmouseover=\"this.className='surbrillance'\" onmouseout=\"this.className='$pair_impair_source'\" onmousedown=\"if (event) e=event; else e=window.event; \" onClick='show_layer(); get_report_content(".$row->id_tache.",".$row->num_type_tache.");' style='cursor: pointer'"; // } // // print " // // // // // ".$this->command_waiting($row->id_tache)." // // // "; // print " // "; // } print "
  ".htmlentities($msg["planificateur_task"], ENT_QUOTES, $charset)." ".htmlentities($msg["planificateur_start_exec"], ENT_QUOTES, $charset)." ".htmlentities($msg["planificateur_end_exec"], ENT_QUOTES, $charset)." ".htmlentities($msg["planificateur_next_exec"],ENT_QUOTES,$charset)." ".htmlentities($msg["planificateur_progress_task"], ENT_QUOTES, $charset)." ".htmlentities($msg["planificateur_etat_exec"], ENT_QUOTES, $charset)." ".htmlentities($msg["planificateur_commande_exec"], ENT_QUOTES, $charset)."
".($n_docsnum?"":" ")."".htmlentities(substr(stripslashes($row->libelle_tache),0,25),ENT_QUOTES,$charset).(strlen($row->libelle_tache) > 25 ? "...":"")."".($row->start_at == '0000-00-00 00:00:00' ? "" : htmlentities(formatdate($row->start_at,ENT_QUOTES,$charset)))."".($row->end_at == '0000-00-00 00:00:00' ? "" : htmlentities(formatdate($row->end_at,ENT_QUOTES,$charset))).""; //// $progress_bar=new progress_bar($row->indicat_progress."%",$row->indicat_progress,0); // print " //
//
// // //
// ".$row->indicat_progress." % // //
//
//
"; // print "
".htmlentities($msg['planificateur_state_'.$row->status.''],ENT_QUOTES,$charset).""; // if ($show_commands != "") { // print ""; // } // print "
"; } function row_planned($row) { global $msg, $charset, $pair_impair_source; //recherche du nombre de documents numériques par tâche $n_docsnum = $this->get_nb_docnum($row->id_tache); //comment task $comment = ""; foreach ($this->types_taches as $atache) { if ($atache->id_type == $row->num_type_tache) { $comment = $atache->comment; //présence de commandes .. selecteurs ?? $show_commands = ""; foreach ($atache->states as $aelement) { if ($row->status == $aelement["id"]) { foreach ($aelement["nextState"] as $state) { if ($state["command"] != "") { //récupère le label de la commande foreach($atache->commands as $command) { if (($state["command"] == $command["name"]) && ($state["dontsend"] != "yes")) { $show_commands .= ""; } } } } } } } } //lien du rapport if ($row->end_at == '0000-00-00 00:00:00') { $line=" onmouseover=\"this.className='surbrillance'\" onmouseout=\"this.className='$pair_impair_source'\" onmousedown=\"if (event) e=event; else e=window.event; \" "; } else { $line=" onmouseover=\"this.className='surbrillance'\" onmouseout=\"this.className='$pair_impair_source'\" onmousedown=\"if (event) e=event; else e=window.event; \" onClick='show_layer(); get_report_content(".$row->id_tache.",".$row->num_type_tache.");' style='cursor: pointer'"; } print " ".($n_docsnum?"":" ")." ".htmlentities(substr(stripslashes($row->libelle_tache),0,25),ENT_QUOTES,$charset).(strlen($row->libelle_tache) > 25 ? "...":"")." ".($row->start_at == '0000-00-00 00:00:00' ? "" : htmlentities(formatdate($row->start_at,ENT_QUOTES,$charset)))." ".($row->end_at == '0000-00-00 00:00:00' ? "" : htmlentities(formatdate($row->end_at,ENT_QUOTES,$charset)))." ".$this->command_waiting($row->id_tache)." "; $progress_bar=new progress_bar_tache($row->indicat_progress); print " ".htmlentities($msg['planificateur_state_'.$row->status.''],ENT_QUOTES,$charset)." "; if ($show_commands != "") { print ""; } print ""; print "  "; $this->get_docsnum($row->id_tache); print "
"; } // Envoi d'une commande pour l'interprétation... function command_waiting($id_tache,$cmd=''){ global $dbh,$msg; $requete_sql = "select status, commande from taches where id_tache='".$id_tache."' and end_at='0000-00-00 00:00:00'"; $result = mysql_query($requete_sql); if(mysql_num_rows($result) == "1") { $status = mysql_result($result, 0,"status"); $commande = mysql_result($result, 0,"commande"); } else { $status = ''; $commande = 0; } // une commande a déjà été envoyée auparavant... if ($commande != '0') { $cmd = $commande; } if ($cmd != '') { //check command - la commande envoyée est vérifié par rapport au status foreach($this->types_taches as $type_tache) { foreach ($type_tache->states as $state) { if ($state["id"] == $status) { foreach($state["nextState"] as $nextState) { foreach($type_tache->commands as $command) { if ($nextState["command"] == $command["name"]) { if ($command["id"] == $cmd) mysql_query("update taches set commande=".$cmd.", next_state='".constant($nextState["value"])."' where id_tache=".$id_tache, $dbh); } } } } } } } $rs = mysql_query("select t.start_at, t.commande, p.calc_next_date_deb, p.calc_next_heure_deb from taches t , planificateur p where t.num_planificateur = p.id_planificateur and id_tache=".$id_tache); $tpl = ""; if ($rs) { $row = mysql_fetch_object($rs); if($row->start_at == '0000-00-00 00:00:00') { $tpl .= htmlentities(formatdate($row->calc_next_date_deb),ENT_QUOTES,$charset)." ".htmlentities($row->calc_next_heure_deb,ENT_QUOTES,$charset); } else if (($row->start_at != '0000-00-00 00:00:00') && ($row->commande != NULL)) { $tpl .= utf8_normalize($msg["planificateur_command_$row->commande"]); } } $tpl .= ""; return $tpl; } //affichage du formulaire global au type de tâche function show_type_task_form($num_type_task) { global $base_path,$charset,$msg, $admin_planificateur_global_params; foreach ($this->types_taches as $atache) { if ($atache->id_type == $num_type_task) { $name = $atache->name; $comment = $atache->comment; // $dir_upload_boolean = $atache->dir_upload_boolean; } } //Inclusion de la classe spécifique if (file_exists($base_path."/admin/planificateur/".$name."/".$name.".class.php")) { require_once($base_path."/admin/planificateur/".$name."/".$name.".class.php"); eval("\$conn=new ".$name."();"); $conn->fetch_global_properties(); // $admin_planificateur_global_params=str_replace("!!script_js!!","",$admin_planificateur_global_params); $admin_planificateur_global_params=str_replace("!!script_js!!","",$admin_planificateur_global_params); $admin_planificateur_global_params=str_replace("!!special_form!!","",$admin_planificateur_global_params); //Remplacement des valeurs par défaut $admin_planificateur_global_params=str_replace("!!id!!",$num_type_task,$admin_planificateur_global_params); $admin_planificateur_global_params=str_replace("!!comment!!",htmlentities($comment,ENT_QUOTES,$charset),$admin_planificateur_global_params); //ce type de tâche nécessite-t-il d'un répertoire d'upload pour les documents numériques? $admin_planificateur_global_params=str_replace("!!div_upload!!","",$admin_planificateur_global_params); // if ($dir_upload_boolean != "0") { // $up = new upload_folder($rep_upload); // $nom_chemin = $up->formate_nom_to_path($up->repertoire_nom.$path_upload); // // $admin_planificateur_global_params=str_replace("!!div_upload!!","
//
//
// ".$msg["planificateur_upload"]." : // // // //
//
",$admin_planificateur_global_params); // } else { // $admin_planificateur_global_params=str_replace("!!div_upload!!","",$admin_planificateur_global_params); // } $admin_planificateur_global_params=str_replace("!!timeout!!",$conn->timeout,$admin_planificateur_global_params); $admin_planificateur_global_params=str_replace("!!histo_day!!",$conn->histo_day,$admin_planificateur_global_params); $admin_planificateur_global_params=str_replace("!!histo_number!!",$conn->histo_number,$admin_planificateur_global_params); } return $admin_planificateur_global_params; } // affichage du formulaire de la tâche function show_form_task ($planificateur_id="") { global $charset, $base_path, $msg; global $planificateur_form, $type_task_id, $subaction; foreach($this->types_taches as $type) { if ($type->id_type == $type_task_id) { $comment = $type->comment; $name = $type->name; $dir_upload_boolean = $type->dir_upload_boolean; } } // Inclusion de la classe spécifique if (is_file($base_path.'/admin/planificateur/'.$name.'/'.$name.'.class.php')) { require_once ($base_path.'/admin/planificateur/'.$name.'/'.$name.'.class.php'); eval("\$a_task=new ".$name."();"); //Récupération des données du formulaire if ($subaction == "change") { global $task_name,$task_desc,$form_users,$task_active, $id_rep,$path; global $task_perio_heure, $task_perio_min, $chkbx_task_hebdo, $chkbx_task_mensuel; global $timeout,$radio_histo_day_number,$histo_day, $histo_number; $libelle_tache = $task_name; $desc_tache = $task_desc; $perio_heure = $task_perio_heure; $statut = $task_active; $rep_upload = ($id_rep ? $id_rep : ""); $chemin_upload = ($path ? $path : ""); $perio_heure = $task_perio_heure; $perio_minute = $task_perio_min; $perio_jour = $chkbx_task_hebdo; $perio_mois = $chkbx_task_mensuel; $param["timeout"] = $timeout; $param["histo_day"] = $histo_day; $param["histo_number"] = $histo_number; } else { //Récupération des données de la base $a_task->fetch_global_properties(); $tab_properties = $a_task->get_property_task_bdd($planificateur_id); if (isset($tab_properties)) { if (is_array($tab_properties)) { foreach($tab_properties as $atab_properties=>$atab_propertiesv) { // global $$atab_properties; $$atab_properties = $atab_propertiesv; } } } } //form spécifique $form_specific_task = $a_task->show_form($param); } else { $form_specific_task = ""; } $planificateur_form=str_replace("!!script_js!!"," ",$planificateur_form); $planificateur_form=str_replace("!!submit_action!!","return checkForm();",$planificateur_form); $planificateur_form=str_replace("!!libelle_type_task!!",$comment,$planificateur_form); $planificateur_form=str_replace("!!type_task_id!!",$type_task_id,$planificateur_form); $planificateur_form=str_replace("!!planificateur_id!!",$planificateur_id,$planificateur_form); $planificateur_form=str_replace("!!task_name!!",htmlentities($libelle_tache,ENT_QUOTES,$charset),$planificateur_form); $planificateur_form=str_replace("!!task_desc!!",htmlentities($desc_tache,ENT_QUOTES,$charset),$planificateur_form); $rqt_user = mysql_query("select esuser_id, esuser_username from es_esusers"); $form_users = ""; if (mysql_num_rows($rqt_user) == 0) { $form_users .= "* ".$msg["planificateur_task_users_unknown"]; } $planificateur_form=str_replace("!!task_users!!",$form_users,$planificateur_form); $planificateur_form=str_replace("!!task_statut!!","",$planificateur_form); //ce type de tâche nécessite-t-il d'un répertoire d'upload pour les documents numériques? if ($dir_upload_boolean != "0") { $up = new upload_folder($rep_upload); if ($subaction == 'change') { $nom_chemin = $up->formate_path_to_nom($chemin_upload); } else { $nom_chemin = $up->formate_nom_to_path($up->repertoire_nom.$path_upload); } $planificateur_form=str_replace("!!div_upload!!","
".$msg["planificateur_upload"]." :
",$planificateur_form); } else { $planificateur_form=str_replace("!!div_upload!!","",$planificateur_form); } $planificateur_form = str_replace('!!path!!', htmlentities($nom_chemin ,ENT_QUOTES, $charset), $planificateur_form); $planificateur_form = str_replace('!!id_rep!!', htmlentities($rep_upload ,ENT_QUOTES, $charset), $planificateur_form); $planificateur_form=str_replace("!!task_perio_heure!!","",$planificateur_form); $planificateur_form=str_replace("!!task_perio_min!!","",$planificateur_form); $planificateur_form=str_replace("!!help!!", " Aide...",$planificateur_form); $perio_hebdo .= "".$msg["planificateur_task_all_days"].""; for ($i=1; $i<8; $i++) { $cochee = false; for ($j=0; $j".$msg["week_days_$i"]; if ($i == 3) { $perio_hebdo .= "
"; } } $planificateur_form=str_replace("!!task_perio_hebdo!!",$perio_hebdo,$planificateur_form); $perio_mensuel .= "".$msg["planificateur_task_all_months"].""; for ($i=1; $i<13; $i++) { $cochee = false; for ($j=0; $j".ucfirst($msg[$i+1005]).""; if ($i == 6) { $perio_mensuel .= "
"; } } $planificateur_form=str_replace("!!task_perio_mensuel!!",$perio_mensuel,$planificateur_form); $planificateur_form=str_replace("!!timeout!!",$param["timeout"],$planificateur_form); $planificateur_form=str_replace("!!histo_day_checked!!",($param["histo_day"] != "" ? " checked " : ""),$planificateur_form); $planificateur_form=str_replace("!!histo_number_checked!!",($param["histo_number"] != "" ? " checked " : ""),$planificateur_form); $planificateur_form=str_replace("!!histo_day!!",$param["histo_day"],$planificateur_form); $planificateur_form=str_replace("!!histo_day_visible!!",($param["histo_day"] == "" ? "disabled" : ""),$planificateur_form); $planificateur_form=str_replace("!!histo_number!!",$param["histo_number"],$planificateur_form); $planificateur_form=str_replace("!!histo_number_visible!!",($param["histo_number"] == "" ? "disabled" : ""),$planificateur_form); //Inclusion du formulaire spécifique au type de tâche $planificateur_form=str_replace("!!specific_form!!",$form_specific_task,$planificateur_form); if (!$planificateur_id) { $bt_suppr=""; } else { $bt_suppr=""; } $planificateur_form=str_replace("!!bt_supprimer!!",$bt_suppr,$planificateur_form); return $planificateur_form; } //Suppression d'une planification de tâche associée à un type de tâche function del_task($planificateur_id) { global $dbh, $msg, $base_path; global $template_result, $type_task_id, $confirm, $disabled; $libelle_tache = ""; foreach($this->types_taches as $type) { if ($type->id_type == $type_task_id) { $libelle_tache = $type->comment; } } //disabled == 1 then statut = 0 if ($disabled == "1") { if ($planificateur_id != "") { $query = "update planificateur set statut=0 where id_planificateur=".$planificateur_id; mysql_query($query, $dbh); } } $template_result=str_replace("!!libelle_type_task!!",$libelle_tache,$template_result); //on vérifie tout d'abord que la tâche soit désactivée $query_active = "select statut from planificateur where id_planificateur=".$planificateur_id; $result = mysql_query($query_active, $dbh); if (mysql_num_rows($result)) { $value_statut = mysql_result($result, 0, "statut"); } else { $value_statut = ""; } if ($value_statut == "0") { $body = "
".$msg["planificateur_confirm_phrase"]."
".$msg["40"]." - ".$msg["39"]."
"; } else { $body = "
".$msg["planificateur_error_active"]."
".$msg["40"]." - ".$msg["39"]."
"; } $template_result=str_replace("!!BODY!!",$body,$template_result); //Confirmation de suppression if ($confirm == "1") { //Vérifie si une tâche est en cours sur cette planification $query_check = "select id_tache from taches where num_planificateur=".$planificateur_id." and status <> 3"; $result = mysql_query($query_check); if (mysql_num_rows($result) == '1') { // ne pas la supprimer ! $ident_tache = mysql_result($result, 0,"id_tache"); } //suppression des tâches à l'exclusion de celle en cours $requete="delete from taches where num_planificateur=".$planificateur_id." and id_tache <> ".$ident_tache; mysql_query($requete); $requete="delete from planificateur where id_planificateur=".$planificateur_id.""; mysql_query($requete); //et les documents numériques qu'en fait-on??? print ""; } return $template_result; } /** * * Cette fonction met à jour les tâches en attente n'ayant pu être lancé * Ex : Cron non lancé * Cette fonction vérifie aussi les processus actifs */ // function checkManager(){ // global $dbh; // global $msg; // // $sql = "SELECT t.id_tache, t.num_planificateur, p.num_type_tache // FROM taches t, planificateur p // WHERE t.num_planificateur=p.id_planificateur // And t.start_at='0000-00-00 00:00:00' // And t.status=1 // And (p.calc_next_date_deb < '".date('Y-m-d')."' // Or p.calc_next_date_deb = '".date('Y-m-d')."' // And p.calc_next_heure_deb < '".date('H:i')."')"; // $res = mysql_query($sql); // // while ($row = mysql_fetch_assoc($res)) { // // 5 = STOPPED // $sql_stop_task = "update taches set status=5, start_at=CURRENT_TIMESTAMP, end_at=CURRENT_TIMESTAMP where id_tache=".$row["id_tache"]; // mysql_query($sql_stop_task); // foreach($this->types_taches as $type) { // if ($type->id_type == $row["num_type_tache"]) { // require_once("../admin/planificateur/".$type_tache->name."/".$type_tache->name.".class.php"); // eval("\$conn=new ".$type_tache->name."(\"../admin/planificateur/".$type_tache->name."\");"); // $conn->insertOfTask($row["num_planificateur"]); // } // } // } // // $sql2 = "SELECT t.id_tache, t.num_planificateur, t.id_process, p.num_type_tache // FROM taches t, planificateur p // WHERE t.num_planificateur=p.id_planificateur // And t.id_process <> 0"; // $res2 = mysql_query($sql2); // // while ($row2 = mysql_fetch_assoc($res2)) { // $command = 'ps -p '.$row2['id_process']; // exec($command,$output); // if (!isset($output[1])) { // // 5 = STOPPED // $sql_stop_task2 = "update taches set status=5, end_at=CURRENT_TIMESTAMP, id_process=0 where id_tache=".$row2["id_tache"]; // mysql_query($sql_stop_task2); // foreach($this->types_taches as $type) { // if ($type->id_type == $row2["num_type_tache"]) { // require_once("../admin/planificateur/".$type_tache->name."/".$type_tache->name.".class.php"); // eval("\$conn=new ".$type_tache->name."(\"../admin/planificateur/".$type_tache->name."\");"); // $conn->insertOfTask($row2["num_planificateur"]); // } // } // } // } // } }