1 Replies - 1694 Views - Last Post: 03 August 2011 - 05:25 AM Rate Topic: -----

#1 sensorium   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 01-August 11

Delete function in item view in Joomla back-end

Posted 03 August 2011 - 05:00 AM

Hello,

I need to place a delete button in item view in Joomla back-end. I have found the function for deleting items in the category view but it needs a item to be selected from the list. In item view there is no list to be selected, the item itself should be selected. Can the function be modified to work as I need it ?

The function is this:

function removeItem()
{
    $task = JRequest::getVar('t', 'post');
    global $mainframe;
    $cid = JRequest::getVar('cid', array (), '', 'array');
    $db = & JFactory::getDBO();
    if (count($cid))
    {
        $cids = implode(',', $cid);
        $query = "SELECT id,image_url FROM #__djcf_items WHERE id IN ( ".$cids." )";
		$db->setQuery($query);
		$items = $db->loadObjectList();
		$path_to_delete = JPATH_BASE."/../components/com_djclassifieds/images/";
		
		foreach($items as $i){
			if($i->image_url){				
				$images = explode(";",$i->image_url);
				for($ii=0; $ii<count($images)-1;$ii++ ){
						if (JFile::exists($path_to_delete.$images[$ii])){
            				JFile::delete($path_to_delete.$images[$ii]);
        				}
        				if (JFile::exists($path_to_delete.$images[$ii].'.thb.jpg')){
            				JFile::delete($path_to_delete.$images[$ii].'.thb.jpg');
  						}
						if (JFile::exists($path_to_delete.$images[$ii].'.th.jpg')){
            				JFile::delete($path_to_delete.$images[$ii].'.th.jpg');
        				}
						if (JFile::exists($path_to_delete.$images[$ii].'.thm.jpg')){
            				JFile::delete($path_to_delete.$images[$ii].'.thm.jpg');
        				}
        				if (JFile::exists($path_to_delete.$images[$ii].'.ths.jpg')){
            				JFile::delete($path_to_delete.$images[$ii].'.ths.jpg');
        				}
				}
			}
		}

        $query = "DELETE FROM #__djcf_items WHERE id IN ( ".$cids." )";
        $db->setQuery($query);
        if (!$db->query())
        {
            echo "script alert('".$db->getErrorMsg()."');
				window.history.go(-1); </script>\n";
        }
    }
	$limit = JRequest::getVar('limit', 10, '', 'int');
		$limitstart = JRequest::getVar('limitstart', 0, '', 'int');
		$order = JRequest::getVar('order');
		$cat_id = JRequest::getVar('cat_id',0,'',int);
        $redirect = 'index.php?option=com_djclassifieds&task='.$task.'&cat_id='.$cat_id.'&order='.$order.'&limit='.$limit.'&limitstart='.$limitstart;
    $mainframe->redirect($redirect, JText::_('ITEM_REMOVED'));
}



Is This A Good Question/Topic? 0
  • +

Replies To: Delete function in item view in Joomla back-end

#2 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3837
  • View blog
  • Posts: 13,998
  • Joined: 08-August 08

Re: Delete function in item view in Joomla back-end

Posted 03 August 2011 - 05:25 AM

Yes. Read:
http://api.joomla.or...t/JRequest.html
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1