Bonjour tout le monde ,
Je suis entrain de créer mon site. J'ai un rubrique news et c'est la que vient mon problème.
Chaque fois que j'ajoute un news, la dernière se mélange avec la première. Voila mon script si une âme charitable peut me dire ou se trouve l'erreur.
<?php
ob_start();
session_start(); /// initialize session
include("./inc/pw.php");
check_logged();
include("./inc/dirscan.php");
include("./inc/array_xml.php");
//html meta
include("./inc/jscript.php");
$xml= xml2ary(file_get_contents('../data.xml'));
// print_r($xml);
if(isset($_POST['addnews'])){
$selected= $_POST['itemnumber'];
$tot= count($xml[data][0][_c][item][$selected][_c][news]);
$xml[data][0][_c][item][$selected][_c][news][$tot][_v]="<h5>08-01-2011</h5><p></p><h3>sample</h3><p><span class='newstext'>sample</span></p>";
$last=ary2xml($xml);
//write();
$fh = fopen("../data.xml", "w");
if($fh==false)
die("unable to create file");
fwrite($fh,$last);
fclose($fh);
header('Location:indexlog.php?page=menu&edit='.$selected);
ob_end_flush();
}
if(isset($_POST['deletenews'])){
$selected= $_POST['itemnumber'];
$newssel= $_POST['newsnumber'];
if ($newssel==0){
array_shift($xml[data][0][_c][item][$selected][_c][news]);
}else{
unset($xml[data][0][_c][item][$selected][_c][news][$newssel]);
}
$last=ary2xml($xml);
//write();
$fh = fopen("../data.xml", "w");
if($fh==false)
die("unable to create file");
fwrite($fh,$last);
fclose($fh);
header('Location:indexlog.php?page=menu&edit='.$selected);
ob_end_flush();
}
if(isset($_POST['savenews'])){
$selected= $_POST['itemnumber'];
$newssel= $_POST['newsnumber'];
$newtext = str_replace("../", "", $_POST['text']);
$xml[data][0][_c][item][$selected][_c][news][$newssel][_v]=$newtext;
$last=ary2xml($xml);
//write();
$fh = fopen("../data.xml", "w");
if($fh==false)
die("unable to create file");
fwrite($fh,$last);
fclose($fh);
header('Location:indexlog.php?page=menu&edit='.$selected.'&action=saved');
ob_end_flush();
}
if(isset($_POST['savename'])){
$selected= $_POST['itemnumber'];
$xml[data][0][_c][item][$selected][_c][testo][0][_v]=$_POST['name'];
$last=ary2xml($xml);
//write();
$fh = fopen("../data.xml", "w");
if($fh==false)
die("unable to create file");
fwrite($fh,$last);
fclose($fh);
header('Location:indexlog.php?page=menu&edit='.$selected.'&action=saved');
ob_end_flush();
}
if(isset($_POST['saveimage'])){
$selected= $_POST['itemnumber'];
$xml[data][0][_c][item][$selected][_c][img][0][_v]=$_POST['image'];
$last=ary2xml($xml);
//write();
$fh = fopen("../data.xml", "w");
if($fh==false)
die("unable to create file");
fwrite($fh,$last);
fclose($fh);
header('Location:indexlog.php?page=menu&edit='.$selected.'&action=saved');
ob_end_flush();
}
if(isset($_POST['savebkg'])){
$selected= $_POST['itemnumber'];
$xml[data][0][_c][item][$selected][_c][background][0][_v]=$_POST['bkg'];
$last=ary2xml($xml);
//write();
$fh = fopen("../data.xml", "w");
if($fh==false)
die("unable to create file");
fwrite($fh,$last);
fclose($fh);
header('Location:indexlog.php?page=menu&edit='.$selected.'&action=saved');
ob_end_flush();
}
if(isset($_POST['up'])){
$selected= $_POST['itemnumber'];
$newssel= $_POST['newsnumber'];
$temp = $xml[data][0][_c][item][$selected][_c][news][$newssel-1];
$xml[data][0][_c][item][$selected][_c][news][$newssel-1] = $xml[data][0][_c][item][$selected][_c][news][$newssel];
$xml[data][0][_c][item][$selected][_c][news][$newssel] = $temp;
$last=ary2xml($xml);
//write();
$fh = fopen("../data.xml", "w");
if($fh==false)
die("unable to create file");
fwrite($fh,$last);
fclose($fh);
header('Location:indexlog.php?page=menu&edit='.$selected);
ob_end_flush();
}
if(isset($_POST['down'])){
$selected= $_POST['itemnumber'];
$newssel= $_POST['newsnumber'];
$temp = $xml[data][0][_c][item][$selected][_c][news][$newssel+1];
$xml[data][0][_c][item][$selected][_c][news][$newssel+1] = $xml[data][0][_c][item][$selected][_c][news][$newssel];
$xml[data][0][_c][item][$selected][_c][news][$newssel] = $temp;
$last=ary2xml($xml);
//write();
$fh = fopen("../data.xml", "w");
if($fh==false)
die("unable to create file");
fwrite($fh,$last);
fclose($fh);
header('Location:indexlog.php?page=menu&edit='.$selected);
ob_end_flush();
}
?>
Merci
Afficher la suite