You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

36 lines
966 B

<?
$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');