Ok ich habe es jetzt so weit fertig. Vielen Dank!
Und ja, ich benutze mehrere Formulare, um genau zu sein 5. Die layoutBox definiere ich jetzt auch mit der Id. Ich habe mal die Ersten beiden mit dem PHP Code vorweg hier:
[code=php]<?php
$id = 0;
$days = array(
"monday" => "Montag",
"tuesday" => "Dienstag",
"wednesday" => "Mittwoch",
"thursday" => "Donnerstag",
"friday" => "Freitag",
"saturday" => "Samstag",
"sunday" => "Sonntag");
$CONFIG_FILENAME = '/var/www/data/alarmClock.xml';
//config.xml dateisystem rechte überprüfen
if(!file_exists($CONFIG_FILENAME)) {
echo "Kann die Konfiguration (".$CONFIG_FILENAME.") nicht finden!\n";
exit(1);
}
if(!is_readable($CONFIG_FILENAME)) {
echo "Kann die Konfiguration (".$CONFIG_FILENAME.") nicht lesen!\n";
exit(2);
}
if(!is_writable($CONFIG_FILENAME)) {
echo "Kann die Konfiguration (".$CONFIG_FILENAME.") nicht schreiben!\n";
exit(3);
}
libxml_use_internal_errors(true);
$xml = simplexml_load_file($CONFIG_FILENAME);
if (!$xml) {
echo "Kann die Konfiguration (".$CONFIG_FILENAME.") nicht laden!\n";
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
exit(4);
}
//xml schreiben
if(isset($_POST['submit']))
{
if(isset($_POST['alarmAktiv'])) {
$xml->{"alarm".$_POST['id']}->aktiv = "true";
}
else {
$xml->{"alarm".$_POST['id']}->aktiv = "false";
}
if (isset($_POST['repeatAktiv'])) {
$xml->{"alarm".$_POST['id']}->repeat = "true";
}
else {
$xml->{"alarm".$_POST['id']}->repeat = "false";
}
foreach($days as $key => $value) {
if(in_array($key, $_POST['day']))
{
$xml->{"alarm".$_POST['id']}->{$value} = "true";
}
else {
$xml->{"alarm".$_POST['id']}->{$value} = "false";
}
}
$xml->{"alarm".$_POST['id']}->time = $_POST['time'];
$xml->{"alarm".$_POST['id']}->mode = $_POST['mode'];
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($xml->asXML());
$dom->save($CONFIG_FILENAME);
}
?>
<form action="" method='POST'>
<div class="<?php echo 'layoutBox'.$id; ?>">
<label class="alarmClockLabel" > Wecker 1:
<input type="hidden" name="id" value="<?php echo $id;?>" >
<input type="submit" class="saveButton" name="submit" value="Speichern" >
<label class="labelAktiv" > Aktiv:
<input type="checkbox" class="checkBox" name="alarmAktiv" <?php if((string)$xml->{"alarm".$id}->aktiv == "true") { echo 'checked="checked"'; } ?> >
</label>
<label class="labelRepeat" > Wiederholen:
<input type="checkbox" class="checkBox" name="repeatAktiv" <?php if((string)$xml->{"alarm".$id}->repeat == "true") { echo 'checked="checked"'; } ?> >
</label>
<label class="labelDay" > Tag:
<select name="day[]" class="choiceBox" multiple>
<?php
foreach($days as $key => $value)
{
echo '<option value="'.$key.'" ';
if((string)$xml->{"alarm".$id}->{$value} == "true") {
echo 'selected="selected"';
}
echo '>'.$value.'</option>\r\n';
}
?>
</select>
</label>
<label class="labelTime" > Zeit:
<input type="time" class="timeBox" name="time" value="<?php echo (string)$xml->{"alarm".$id}->time; ?>">
</label>
<label class="labelMode" > Modus:
<select name="mode" class="choiceBox" size="1" >
<option value="standad" <?php if((string)$xml->{"alarm".$id}->mode == "standard") { echo 'selected="selected"'; } ?>>Standard</option>
</select>
</label>
</label>
</div>
</form>
<?php $id = 1; ?>
<form action="" method='POST'>
<div class="<?php echo 'layoutBox'.$id; ?>">
<label class="alarmClockLabel" > Wecker 2:
<input type="hidden" name="id" value="<?php echo $id;?>" >
<input type="submit" class="saveButton" name="submit" value="Speichern" >
<label class="labelAktiv" > Aktiv:
<input type="checkbox" class="checkBox" name="alarmAktiv" <?php if((string)$xml->{"alarm".$id}->aktiv == "true") { echo 'checked="checked"'; } ?> >
</label>
<label class="labelRepeat" > Wiederholen:
<input type="checkbox" class="checkBox" name="repeatAktiv" <?php if((string)$xml->{"alarm".$id}->repeat == "true") { echo 'checked="checked"'; } ?> >
</label>
<label class="labelDay" > Tag:
<select name="day[]" class="choiceBox" multiple>
<?php
foreach($days as $key => $value)
{
echo '<option value="'.$key.'" ';
if((string)$xml->{"alarm".$id}->{$value} == "true") {
echo 'selected="selected"';
}
echo '>'.$value.'</option>\r\n';
}
?>
</select>
</label>
<label class="labelTime" > Zeit:
<input type="time" class="timeBox" name="time" value="<?php echo (string)$xml->{"alarm".$id}->time; ?>">
</label>
<label class="labelMode" > Modus:
<select name="mode" class="choiceBox" size="1" >
<option value="standad" <?php if((string)$xml->{"alarm".$id}->mode == "standard") { echo 'selected="selected"'; } ?>>Standard</option>
</select>
</label>
</label>
</div>
</form> [/php]