Accueil/modules/links/ajax/update-links-order.php

36 lines
968 B
PHP
Raw Permalink Normal View History

<?php
2010-09-21 16:00:04 +02:00
$label = $_POST['label'];
$order = $_POST['order'];
$itemMoved = $_POST['itemMoved'];
$orderArray = explode(',', $order);
$itemIndex = 0;
foreach($orderArray as $index=>$value){
if($value == $itemMoved)
$itemIndex = (int)$index;
}
$itemAfter = '';
if(isset($orderArray[$itemIndex+1]))
$itemAfter = $orderArray[$itemIndex+1];
$doc = new DOMDocument;
$doc->load('../db/links.xml');
$xpath = new DOMXpath($doc);
// Buffering and deleting moved element
foreach($xpath->query('label/link[title = "'.$itemMoved.'"]') as $node) {
$buffer = $node;
$node->parentNode->removeChild($node);
}
if($itemAfter != ''){
$searchLabel = $xpath->query('label[@id="'.$label.'"]/link[title = "'.$itemAfter.'"]')->item(0);
$searchLabel->parentNode->insertBefore($buffer, $searchLabel);
}else{
$searchLabel = $xpath->query('label[@id="'.$label.'"]');
$searchLabel->item(0)->appendChild($buffer);
}
$doc->save('../db/links.xml');