Exemple #1
0
function confirmdelete($link_id, $option)
{
    global $mtconf, $mainframe, $Itemid;
    // Check for request forgeries
    JRequest::checkToken() or jexit('Invalid Token');
    $database =& JFactory::getDBO();
    $my =& JFactory::getUser();
    $jdate = JFactory::getDate();
    $now = $jdate->toMySQL();
    $nullDate = $database->getNullDate();
    $database->setQuery("SELECT * FROM #__mt_links WHERE " . "\n link_published='1' AND link_approved > 0 AND link_id='" . $link_id . "'" . "\n AND ( publish_up = " . $database->Quote($nullDate) . " OR publish_up <= '{$now}'  ) " . "\n AND ( publish_down = " . $database->Quote($nullDate) . " OR publish_down >= '{$now}' ) ");
    $link = $database->loadObject();
    if ($mtconf->get('user_allowdelete') && $my->id == $link->user_id && $my->id > 0) {
        $link = new mtLinks($database);
        $link->load($link_id);
        if ($mtconf->get('notifyadmin_delete') == 1) {
            // Get owner's email
            $database->setQuery("SELECT email FROM #__users WHERE id = '" . $my->id . "' LIMIT 1");
            $my_email = $database->loadResult();
            $subject = JText::_('Admin notify delete subject');
            $body = sprintf(JText::_('Admin notify delete msg'), $link->link_name, $link->link_name, $link->link_id, $my->username, $my_email, $link->link_created);
            mosMailToAdmin($subject, $body);
        }
        $link->updateLinkCount(-1);
        $link->delLink();
        $cache =& JFactory::getCache('com_mtree');
        $cache->clean();
        $mainframe->redirect(JRoute::_("index.php?option={$option}&task=viewowner&user_id=" . $my->id . "&Itemid={$Itemid}"), JText::_('Listing have been deleted'));
    } else {
        echo _NOT_EXIST;
    }
}
 function delCatLinks($cat_id)
 {
     $this->_db->setQuery("SELECT l.link_id FROM #__mt_links AS l, #__mt_cl AS cl WHERE cl.link_id = l.link_id AND cl.cat_id = '" . $cat_id . "' AND cl.main = '1'");
     $link_ids = $this->_db->loadResultArray();
     # Remove all hard listing
     foreach ($link_ids as $link_id) {
         mtLinks::delLink($link_id);
     }
     # Remove all soft listing
     $this->_db->setQuery("DELETE FROM #__mt_cl WHERE cat_id = '" . $cat_id . "'");
     $this->_db->query();
     return true;
 }
Exemple #3
0
function removeLinks($link_id, $option, $post = null)
{
    global $mainframe;
    $database =& JFactory::getDBO();
    $row = new mtLinks($database);
    $row->load($link_id[0]);
    if (!is_array($link_id) || count($link_id) < 1) {
        echo "<script> alert('" . JText::_('Select an item to delete') . "'); window.history.go(-1);</script>\n";
        exit;
    }
    if (count($link_id)) {
        $link_ids = implode(',', $link_id);
        $total = count($link_id);
        # Locate all CL mapping and decrease the categories' link count
        foreach ($link_id as $id) {
            $database->setQuery('SELECT cat_id FROM #__mt_cl WHERE main = 0 AND link_id = ' . $database->quote($id));
            $link_cls = $database->loadResultArray();
            if (count($link_cls) > 0) {
                foreach ($link_cls as $link_cl) {
                    $row->updateLinkCount(-1, $link_cl);
                }
            }
        }
        # Delete the main records
        foreach ($link_id as $id) {
            $database->setQuery('SELECT link_approved FROM #__mt_links WHERE link_id = ' . $database->quote($id));
            $link_approved = $database->loadResult();
            if ($link_approved <= 0) {
                $total--;
            }
            $row->delLink($id);
        }
        # Update link count for all category
        if ($total > 0) {
            $row->updateLinkCount(-1 * $total);
        }
    }
    if (is_null($post)) {
        $returntask = JRequest::getCmd('returntask', '', 'post');
    } else {
        $returntask = $post['returntask'];
    }
    if ($returntask != '') {
        $mainframe->redirect("index2.php?option={$option}&task={$returntask}", sprintf(JText::_('Links have been deleted'), count($link_id)));
    } else {
        $mainframe->redirect("index2.php?option={$option}&task=listcats&cat_id=" . $row->cat_id);
    }
}