0"; $resultat=mysql_query($requete, $dbh); while ($row = mysql_fetch_object($resultat)) { $params=unserialize($row->param); foreach ($params as $index=>$param) { if (($index == "timeout") && ($param != "")) { // 6 = FAIL - Sera mis à l'échec à l'écoute de la tâche $requete_check_timeout = "update taches set commande=6 where DATE_ADD('".$row->start_at."', INTERVAL ".($param)." MINUTE) <= CURRENT_TIMESTAMP and id_tache=".$row->id_tache; mysql_query($requete_check_timeout, $dbh); } } } } function getOS() { if (stripos($_SERVER['SERVER_SOFTWARE'], "win")!==false || stripos(PHP_OS, "win")!==false ) $os = "Windows"; elseif (stripos($_SERVER['SERVER_SOFTWARE'], "mac")!==false || stripos(PHP_OS, "mac")!==false || stripos($_SERVER['SERVER_SOFTWARE'], "ppc")!==false || stripos(PHP_OS, "ppc")!==false ) $os = "Mac"; elseif (stripos($_SERVER['SERVER_SOFTWARE'], "linux")!==false || stripos(PHP_OS, "linux")!==false ) $os = "Linux"; elseif (stripos($_SERVER['SERVER_SOFTWARE'], "freebsd")!==false || stripos(PHP_OS, "freebsd")!==false ) $os = "FreeBSD"; elseif (stripos($_SERVER['SERVER_SOFTWARE'], "sunos")!==false || stripos(PHP_OS, "sunos")!==false ) $os = "SunOS"; elseif (stripos($_SERVER['SERVER_SOFTWARE'], "irix")!==false || stripos(PHP_OS, "irix")!==false ) $os = "IRIX"; elseif (stripos($_SERVER['SERVER_SOFTWARE'], "beos")!==false || stripos(PHP_OS, "beos")!==false ) $os = "BeOS"; elseif (stripos($_SERVER['SERVER_SOFTWARE'], "os/2")!==false || stripos(PHP_OS, "os/2")!==false ) $os = "OS/2"; elseif (stripos($_SERVER['SERVER_SOFTWARE'], "aix")!==false || stripos(PHP_OS, "aix")!==false ) $os = "AIX"; else $os = "Autre"; return $os; } /*Vérifie les processus actifs*/ function checkTasks() { global $dbh; global $msg; //Récupération de l'OS pour la vérification des processus $os = $this->getOS(); $sql = "SELECT id_tache, start_at, id_process FROM taches WHERE id_process <> 0"; $res = mysql_query($sql,$dbh); while ($row = mysql_fetch_assoc($res)) { if ($os == "Linux") { $command = 'ps -p '.$row['id_process']; } else if ($os == "Windows") { $command = 'PsList '.$row['id_process']; } else if ($os == "Mac") { $command = 'ps -p '.$row['id_process']; } else { $command = 'ps -p '.$row['id_process']; } exec($command,$output); if (!isset($output[1])) { // 5 = STOPPED $sql_stop_task = "update taches set status=5, "; if ($row['start_at'] == '0000-00-00 00:00:00') $sql_stop_task .= "start_at=CURRENT_TIMESTAMP, "; $sql_stop_task .= "end_at=CURRENT_TIMESTAMP, id_process=0, commande=0 where id_tache=".$row["id_tache"]; $res = mysql_query($sql_stop_task); } } } /*Vérifie si une ou plusieurs tâches doivent être exécutées et lance celles-ci*/ function runTasks($connectors_out_source_id) { global $dbh; global $base_path; global $pmb_path_php; //Récupération de l'OS sur lequel est exécuté la tâche $os = $this->getOS(); //Y-a t-il une ou plusieurs tâches à exécuter... $sql = "SELECT id_planificateur, p.num_type_tache, p.libelle_tache, p.num_user, t.id_tache FROM planificateur p, taches t 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,$dbh); while ($row = mysql_fetch_assoc($res)) { if ($os == "Linux") { exec("nohup $pmb_path_php $base_path/admin/planificateur/run_task.php ".$row["id_tache"]." ".$row["num_type_tache"]." ".$row["id_planificateur"]." ".$row["num_user"]." ".$connectors_out_source_id." > /dev/null 2>&1 & echo $!", $output); } else if ($os == "Windows") { exec("PsExec -d $pmb_path_php $base_path/admin/planificateur/run_task.php ".$row["id_tache"]." ".$row["num_type_tache"]." ".$row["id_planificateur"]." ".$row["num_user"]." ".$connectors_out_source_id,$output); } else if ($os == "Mac") { exec("nohup $pmb_path_php $base_path/admin/planificateur/run_task.php ".$row["id_tache"]." ".$row["num_type_tache"]." ".$row["id_planificateur"]." ".$row["num_user"]." ".$connectors_out_source_id." > /dev/null 2>&1 & echo $!", $output); } else { exec("nohup $pmb_path_php $base_path/admin/planificateur/run_task.php ".$row["id_tache"]." ".$row["num_type_tache"]." ".$row["id_planificateur"]." ".$row["num_user"]." ".$connectors_out_source_id." > /dev/null 2>&1 & echo $!", $output); } $id_process = (int)$output[0]; $update_process = "update taches set id_process='".$id_process."' where id_tache='".$row["id_tache"]."'"; mysql_query($update_process,$dbh); } } /*Retourne la liste des tâches réalisées et planifiées */ function listTasksPlanned() { global $dbh; global $msg; $result = array(); $sql = "SELECT t.id_tache, p.libelle_tache, p.desc_tache,"; $sql .= "t.start_at, t.end_at, t.indicat_progress, t.status"; $sql .= "FROM taches t, planificateur p WHERE t.num_planificateur=p.id_planificateur"; $res = mysql_query($sql, $dbh); if ($res) { while($row = mysql_fetch_assoc($res)) { $result[] = array ( "id_tache" => $row["id_tache"], "libelle_tache" => utf8_normalize($row["libelle_tache"]), "desc_tache" => utf8_normalize($row["desc_tache"]), "start_at" => $row["start_at"], "end_at" => $row["end_at"], "indicat_progress" => $row["indicat_progress"], "status" => $row["status"], ); } } return $result; } /*Retourne les types de tâches*/ function listTypesTasks() { global $dbh; global $msg; $result = array(); $filename="../admin/planificateur/catalog.xml"; $xml=file_get_contents($filename); $param=_parser_text_no_function_($xml,"CATALOG"); foreach ($param["ACTION"] as $anitem) { $t=array(); $t["ID"] = $anitem["ID"]; $t["NAME"] = $anitem["NAME"]; $t["COMMENT"] = $anitem["COMMENT"]; $types_taches[$t["ID"]] = $t; } return $types_taches; } /*Retourne les informations concernant une tâche planifiée */ function getInfoTaskPlanned($planificateur_id, $active="") { global $dbh; global $msg; $result = array(); $planificateur_id += 0; if (!$planificateur_id) throw new Exception("Missing parameter: planificateur_id"); if ($active !="") { $critere = " and statut=".$active; } else { $critere =""; } $sql = "SELECT * FROM planificateur WHERE id_planificateur = ".$planificateur_id; $sql = $sql.$critere; $res = mysql_query($sql,$dbh); if (!$res) throw new Exception("Not found: planificateur_id = ".$planificateur_id); while ($row = mysql_fetch_assoc($res)) { $result[] = array( "id_planificateur" => $row["id_planificateur"], "num_type_tache" => $row["num_type_tache"], "libelle_tache" => utf8_normalize($row["libelle_tache"]), "desc_tache" => utf8_normalize($row["desc_tache"]), "num_user" => $row["num_user"], "statut" => $row["statut"], "calc_next_date_deb" => utf8_normalize($row["calc_next_date_deb"]), "calc_next_heure_deb" => utf8_normalize($row["calc_next_heure_deb"]), ); } return $result; } /** * * Change le statut d'une planification * @param $id_planificateur * @param $activation (0=false, 1=true) */ function changeStatut($id_planificateur,$activation='') { global $dbh; if (!$id_planificateur) throw new Exception("Missing parameter: id_planificateur"); $sql = "select statut from planificateur where id_planificateur=".$id_planificateur; $res = mysql_query($sql, $dbh); if (mysql_num_rows($res) == "1") { $statut_sql = mysql_result($res, 0,"statut"); if ((($statut_sql == "0") && ($activation == "1")) || (($statut_sql == "1") && ($activation == "0"))) { $sql_update = "update planificateur set statut=".$activation." where id_planificateur=".$id_planificateur; mysql_query($sql_update, $dbh); return true; } else { return false; } } else { return false; } } } ?>