Esempio n. 1
0
function approve_links($link_id, $publish = 0, $option)
{
    global $mainframe;
    $database =& JFactory::getDBO();
    if (!is_array($link_id) || count($link_id) < 1) {
        echo "<script> alert('" . JText::_('Select an item to approve') . "'); window.history.go(-1);</script>\n";
        exit;
    }
    if (count($link_id)) {
        foreach ($link_id as $lid) {
            $mtLinks = new mtLinks($database);
            $mtLinks->load($lid);
            $mtLinks->publishLink($publish);
            // Only increase Link count if this is an approval to a new listing
            if ($mtLinks->link_approved == 0) {
                $mtLinks->updateLinkCount(1);
            } elseif ($mtLinks->link_approved < 0) {
                // Check if there is any category change during modification
                $database->setQuery("SELECT cat_id FROM #__mt_cl WHERE link_id = ABS(" . $mtLinks->link_approved . ") AND main = '1'");
                $ori_cat_id = $database->loadResult();
                if ($ori_cat_id != $mtLinks->cat_id) {
                    $mtLinks->updateLinkCount(1);
                    mtUpdateLinkCount($ori_cat_id, -1);
                }
            }
            $mtLinks->approveLink();
            unset($mtLinks);
        }
    }
    $mainframe->redirect("index2.php?option={$option}&task=listpending_links", sprintf(JText::_('Links have been aprroved'), count($link_id)));
}