setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//echo " close session
";
/*
if (!empty($_POST)) {
_pr($_POST);
}
Array
(
[lens] => EF17-40mm f/4L USM
[keywords] => _vert_,neige,vigne
[titre] => Vignes
[creator] => Pesenti Bruno
[city] => Fixin
[department] => Côte d'Or
[code] => FR
[country] => France
[copyright] => © bruno@clicclac.info
[legende] => Vignes dans la neige
[id] => 77
[update] => update
)
*/
if (isset($_POST['update']) && $_POST['update'] === 'update') {
$w = filter_var_array($_POST['id'], FILTER_VALIDATE_INT);
$z = "";
$count = 0;
$requests = array();
foreach ($w as $key => $value) {
if (isset($_POST['id'][$key]) && (! empty($_POST['id'][$key]))) {
$id = filter_var($_POST['id'][$key], FILTER_VALIDATE_INT);
$lens = filter_var($_POST['lens'][$key], FILTER_SANITIZE_SPECIAL_CHARS);
$keywords = filter_var($_POST['keywords'][$key], FILTER_SANITIZE_SPECIAL_CHARS);
$title = filter_var($_POST['title'][$key], FILTER_SANITIZE_SPECIAL_CHARS);
$creator = filter_var($_POST['creator'][$key], FILTER_SANITIZE_SPECIAL_CHARS);
$city = filter_var($_POST['city'][$key], FILTER_SANITIZE_SPECIAL_CHARS);
$department = filter_var($_POST['department'][$key], FILTER_SANITIZE_SPECIAL_CHARS);
$code = filter_var($_POST['code'][$key], FILTER_SANITIZE_SPECIAL_CHARS);
$country = filter_var($_POST['country'][$key], FILTER_SANITIZE_SPECIAL_CHARS);
$copyright = filter_var($_POST['copyright'][$key], FILTER_SANITIZE_SPECIAL_CHARS);
$legende = filter_var($_POST['legende'][$key], FILTER_SANITIZE_SPECIAL_CHARS);
$z .= "id = '" . $id . "' OR ";
//echo $id . "----" . $lens. "----" . $keywords. "----" . $title. "----" . $creator. "----" . $city . "
";
//echo $department . "----" . $code. "----" . $country. "----" . $copyright. "----" . $legende . "
";
/*
echo "id:$id--". "
";
echo "lens:$lens--". "
";
echo "keywords:$keywords--". "
";
echo "title:$title--". "
";
echo "creator:$creator--". "
";
echo "city :$city --". "
";
echo "department:$department--". "
";
echo "code:$code--". "
";
echo "country:$country--". "
";
echo "copyright:$copyright--". "
";
echo "legende:$legende--". "
". "
";
*/
/*
$id = $_POST['id'];
$lens = (isset($_POST['lens']) && (! empty($_POST['lens']))) ? $_POST['lens'] : '';
$keywords = (isset($_POST['keywords']) && (! empty($_POST['keywords']))) ? $_POST['keywords'] : '';
$title = (isset($_POST['title']) && (! empty($_POST['title']))) ? $_POST['title'] : '';
$creator = (isset($_POST['creator']) && (! empty($_POST['creator']))) ? $_POST['creator'] : '';
$city = (isset($_POST['city']) && (! empty($_POST['city']))) ? $_POST['city'] : '';
$department = (isset($_POST['department']) && (! empty($_POST['department']))) ? $_POST['department'] : '';
$code = (isset($_POST['code']) && (! empty($_POST['code']))) ? $_POST['code'] : '';
$country = (isset($_POST['country']) && (! empty($_POST['country']))) ? $_POST['country'] : '';
$copyright = (isset($_POST['copyright']) && (! empty($_POST['copyright']))) ? $_POST['copyright'] : '';
$legende = (isset($_POST['legende']) && (! empty($_POST['legende']))) ? $_POST['legende'] : '';
*/
$req = "UPDATE photos SET lens = :lens , keywords = :keywords , title = :title , creator = :creator ";
$req .= ", city = :city , department = :department , code = :code , country = :country ";
$req .= ", copyright = :copyright , legende = :legende WHERE id= :id";
// affichage requetes
$keys = array_keys($_POST);
$count_id = count($_POST["id"]);
for ($i = 0; $i < $count_id; $i++) {
foreach ($keys as $key => $value) {
if ($value != "update") {
$search = ":" . $value;
$replace = "'" . $_POST[$value][$i] . "'";
$replacements[$search] = $replace;
}
}
$requests[$i] = strtr($req, $replacements);
//$requests[$i] = wordwrap(strtr($req, $replacements), 120, "\n", true);
}
try {
$stmt = $conn->prepare($req);
$stmt->bindValue(':id', $id);
$stmt->bindValue(':lens', $lens);
$stmt->bindValue(':keywords', $keywords);
$stmt->bindValue(':title', $title);
$stmt->bindValue(':creator', $creator);
$stmt->bindValue(':city', $city);
$stmt->bindValue(':department', $department);
$stmt->bindValue(':code', $code);
$stmt->bindValue(':country', $country);
$stmt->bindValue(':copyright', $copyright);
$stmt->bindValue(':legende', $legende);
$stmt->execute();
$count = $count + $stmt->rowCount();
}
catch(PDOException $e) {
echo $e->getMessage();
}
}
}
$msg = "Updated $count rows with following request:";
$conn = null;
}
else {
$url = "view_bdd.php?message=" . urlencode(gettext("No image select !"));
header("location: $url");
}
?>
';
foreach ($requests as $request) {
echo $request . "
";
}
echo '';
$req = substr($z, 0, -4);
$req_edit = "SELECT * FROM photos WHERE " . $req . " ORDER BY id";
try {
$conn = new PDO("sqlite:../$base");
$stmt = $conn->prepare($req_edit);
$stmt->execute();
echo '© 2013- sur-le-sentier.fr