/**
 * The following function was taken from admin.frontpage.php Joomla 1.0
 * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
 * modification aHa - additional saveorder for categories
 * @see admin.joomgallery.php // only backend
 * @param int $cid
 * @param unknown_type $catg
 */
function Joom_SaveOrder(&$cid, &$catg)
{
    $mainframe =& JFactory::getApplication('administrator');
    $database =& JFactory::getDBO();
    $returntask = Joom_mosGetParam('returntask', null);
    if ($returntask == 'pictures') {
        $total = count($cid);
        $order = Joom_mosGetParam('order', array(0), 'post');
        for ($i = 0; $i < $total; $i++) {
            //get catid
            $database->setQuery("SELECT catid\n          FROM #__joomgallery\n          WHERE id={$cid[$i]}");
            $piccatid = $database->loadResult();
            $query = "UPDATE #__joomgallery\n          SET ordering = {$order[$i]}\n          WHERE id = {$cid[$i]}";
            $database->setQuery($query);
            if (!$database->query()) {
                echo "<script> alert('" . $database->getErrorMsg() . "');\n              window.history.go(-1); </script>\n";
                exit;
            }
            // update ordering
            $row = new mosjoomgallery($database);
            $row->load($cid[$i]);
            $row->reorder('catid=' . $piccatid);
        }
        $mainframe->redirect('index.php?option=' . _JOOM_OPTION . '&act=pictures', JText::_('JG_NEW_ORDERING_SAVED'));
    } else {
        $total = count($catg);
        $order = Joom_mosGetParam('order', array(0), 'post');
        for ($i = 0; $i < $total; $i++) {
            $query = "UPDATE #__joomgallery_catg\n          SET ordering = {$order[$i]}\n          WHERE cid = {$catg[$i]}";
            $database->setQuery($query);
            if (!$database->query()) {
                echo "<script> alert('" . $database->getErrorMsg() . "');\n              window.history.go(-1); </script>\n";
                exit;
            }
            // update ordering
            $row = new mosjoomgallery($database);
            $row->load($catg[$i]);
            $row->reorder('');
        }
        $mainframe->redirect('index.php?option=' . _JOOM_OPTION . '&act=categories', JText::_('JG_NEW_ORDERING_SAVED'));
    }
}
 /**
  * provide functionality to set ordering with arrow symbols
  *
  * @param int $uid: id from picture e.g. 10
  * @param int $inc: control varaible up oder down, 1 or -1
  */
 function Joom_OrderPictures($uid, $inc)
 {
     $mainframe =& JFactory::getApplication('administrator');
     $database =& JFactory::getDBO();
     //get catid
     $database->setQuery("SELECT catid\n        FROM #__joomgallery\n        WHERE id={$uid}");
     $piccatid = $database->loadResult();
     $fp = new mosjoomgallery($database);
     $fp->load($uid);
     $fp->move($inc, 'catid=' . $piccatid);
     $fp->reorder('catid=' . $piccatid);
     $mainframe->redirect('index.php?option=' . _JOOM_OPTION . '&act=pictures');
 }