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.

update-links-order.php 968B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. $label = $_POST['label'];
  3. $order = $_POST['order'];
  4. $itemMoved = $_POST['itemMoved'];
  5. $orderArray = explode(',', $order);
  6. $itemIndex = 0;
  7. foreach($orderArray as $index=>$value){
  8. if($value == $itemMoved)
  9. $itemIndex = (int)$index;
  10. }
  11. $itemAfter = '';
  12. if(isset($orderArray[$itemIndex+1]))
  13. $itemAfter = $orderArray[$itemIndex+1];
  14. $doc = new DOMDocument;
  15. $doc->load('../db/links.xml');
  16. $xpath = new DOMXpath($doc);
  17. // Buffering and deleting moved element
  18. foreach($xpath->query('label/link[title = "'.$itemMoved.'"]') as $node) {
  19. $buffer = $node;
  20. $node->parentNode->removeChild($node);
  21. }
  22. if($itemAfter != ''){
  23. $searchLabel = $xpath->query('label[@id="'.$label.'"]/link[title = "'.$itemAfter.'"]')->item(0);
  24. $searchLabel->parentNode->insertBefore($buffer, $searchLabel);
  25. }else{
  26. $searchLabel = $xpath->query('label[@id="'.$label.'"]');
  27. $searchLabel->item(0)->appendChild($buffer);
  28. }
  29. $doc->save('../db/links.xml');