function get_paulo_entries($date, $hour, $bdd, $path, $duration = 1) { $result = array(); if ($bdd == null) { return $result; } $fullhour = "" . $hour; if (strlen($fullhour) == 1) { $fullhour = "0" . $fullhour; } $datetime = $date . " " . $fullhour . ":00:00"; $file_logs = ""; if (nb_day_from_today($date) > 1) { $file_logs = $path . "/paulo/" . $date . ".txt"; if (file_exists($file_logs)) { $array = get_paulo_entries_from_file($file_logs); return filterbyhour($array, $hour, $duration); } else { $datetimebegin = $date . " " . "00:00:00"; $datetimeend = $date . " " . "23:59:59"; $sql = "Select * From titres_paulo where (begin >= " . $bdd->quote($datetimebegin) . " and begin <= " . $bdd->quote($datetimeend) . ") or (end >= " . $bdd->quote($datetimebegin) . " and end <= " . $bdd->quote($datetimeend) . ") order by begin;"; $prep = $bdd->query($sql); $prep->execute(); for ($i = 0; $row = $prep->fetch(); $i++) { $subtime = explode(" ", $row["begin"]); $subhour = explode(":", $subtime[1]); $result[$subhour[0]][] = array("title" => $row["title"], "author" => $row["author"], "time" => $subtime[1]); } if (save_paulo_entries_from_file($file_logs, $result)) { $sql = "DELETE From titres_paulo where (begin >= " . $bdd->quote($datetimebegin) . " and begin <= " . $bdd->quote($datetimeend) . ") or (end >= " . $bdd->quote($datetimebegin) . " and end <= " . $bdd->quote($datetimeend) . ");"; $prep = $bdd->query($sql); $prep->execute(); } return filterbyhour($result, $hour, $duration); } } $sql = "Select * From titres_paulo where (begin >= " . $bdd->quote($datetime) . " and begin <= DATE_ADD(" . $bdd->quote($datetime) . ", INTERVAL " . $duration . " HOUR)) or (end >= " . $bdd->quote($datetime) . " and end <= DATE_ADD(" . $bdd->quote($datetime) . ", INTERVAL " . $duration . " HOUR)) order by begin;"; $prep = $bdd->query($sql); $prep->execute(); for ($i = 0; $row = $prep->fetch(); $i++) { $subtime = explode(" ", $row["begin"]); $result[] = array("title" => $row["title"], "author" => $row["author"], "time" => $subtime[1]); } return $result; }
function convert_paulo_entries($date, $duration = 1) { global $bdd; $result = array(); if ($bdd == null) { return $result; } $fullhour = "" . $hour; if (strlen($fullhour) == 1) { $fullhour = "0" . $fullhour; } $datetimebegin = $date . " " . "00:00:00"; $datetimeend = $date . " " . "23:59:59"; if (nb_day_from_today($date) < 7) { return true; } $file_logs = "paulo/" . $date . ".txt"; if (file_exists($file_logs)) { $sql = "DELETE From titres_paulo where (begin >= " . $bdd->quote($datetimebegin) . " and begin <= " . $bdd->quote($datetimeend) . ") or (end >= " . $bdd->quote($datetimebegin) . " and end <= " . $bdd->quote($datetimeend) . ");"; echo $sql . "<br/>"; $prep = $bdd->query($sql); $prep->execute(); return false; } $sql = "Select * From titres_paulo where (begin >= " . $bdd->quote($datetimebegin) . " and begin <= " . $bdd->quote($datetimeend) . ") or (end >= " . $bdd->quote($datetimebegin) . " and end <= " . $bdd->quote($datetimeend) . ") order by begin;"; $prep = $bdd->query($sql); $prep->execute(); for ($i = 0; $row = $prep->fetch(); $i++) { $subtime = explode(" ", $row["begin"]); $subhour = explode(":", $subtime[1]); $result[$subhour[0]][] = array("title" => $row["title"], "author" => $row["author"], "time" => $subtime[1]); } if ($file_logs != "") { if (save_paulo_entries_from_file($file_logs, $result)) { /*$sql = "DELETE From titres_paulo where (begin >= ".$bdd->quote($datetime)." and begin <= DATE_ADD(".$bdd->quote($datetime).", INTERVAL ".$duration." HOUR)) or (end >= ".$bdd->quote($datetime)." and end <= DATE_ADD(".$bdd->quote($datetime).", INTERVAL ".$duration." HOUR));"; $prep = $bdd->query($sql); $prep->execute();*/ } } return true; }
return strcmp($a["time"], $b["time"]); } function trier_array(&$array) { usort($array, "cmp"); } include '../player/lib/paulo_entries.php'; $date = $_GET['date']; $pattern = '/^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])/'; preg_match($pattern, $date, $matches); if (count($matches) != 4) { echo "<p>Format de date incorrect. Retour <a href=\"./index.php\">à l'administration</a>.</p>"; } else { echo "<p>Retour <a href=\"./index.php\">à l'administration</a>.</p>"; $file_logs = "../player/paulo/" . $date . ".txt"; if (nb_day_from_today($date) > 1 && file_exists($file_logs)) { $action = $_GET['action']; $array = get_paulo_entries_from_file($file_logs); if (isset($action)) { $file_logs_backup = "../player/paulo/" . $date . "-backup.txt"; if (strcmp($action, "supprimer") == 0) { $key_action = $_GET['key']; $id_action = $_GET['id']; $entry = $array[$key_action][$id_action]; if (!isset($id_action) || !isset($key_action) || !isset($entry)) { echo "<p><strong>Erreur :</strong> impossible de trouver l'entrée sélectionnée.</p>"; } else { copy($file_logs, $file_logs_backup); echo "<p>Le titre suivant a été supprimé : " . $entry["time"] . ", " . $entry["title"] . ", " . $entry["author"] . "</p>"; unset($array[$key_action][$id_action]); $array[$key_action] = array_values($array[$key_action]);