diff --git a/ajax/update-links-order.php b/ajax/update-links-order.php new file mode 100644 index 0000000..d7c3e4e --- /dev/null +++ b/ajax/update-links-order.php @@ -0,0 +1,36 @@ + +$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'); \ No newline at end of file diff --git a/class/Links.php b/class/Links.php index b2eb07a..c6c54f3 100644 --- a/class/Links.php +++ b/class/Links.php @@ -5,54 +5,27 @@ class links { 'visibility' ); + const LINKS_FILE = 'db/links.xml'; + public $params = array(); public function __construct($params){ $this->setParams($params); - echo '