Current File : /home/pacjaorg/public_html/km/administrator/components/com_djclassifieds/controllers/regions.php
<?php
/**
 * @package DJ-Classifieds
 * @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
 * @license http://www.gnu.org/licenses GNU/GPL
 * @author url: http://dj-extensions.com
 * @author email: contact@dj-extensions.com
 */

defined('_JEXEC') or die;

class DJClassifiedsControllerRegions extends JControllerAdmin
{
	public function getModel($name = 'Region', $prefix = 'DJClassifiedsModel', $config = array('ignore_request' => true))
	{
		$model = parent::getModel($name, $prefix, $config);

		return $model;
	}
	
	function delete()
	{
	    $app = JFactory::getApplication();
	    $db = JFactory::getDBO();
		$user = JFactory::getUser();
		$cid = $app->input->getVar('cid', array()); 
	    
	    if(!$user->authorise('core.delete', 'com_djclassifieds')) {
	    	$this->setMessage(JText::_('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED'), 'error');
	    	$this->setRedirect( 'index.php?option=com_djclassifieds&view=regions' );
	    	return false;
	    }
		
	    if($cid){
			$cid_w_children = $cid;
			foreach($cid as $cat_id){
				$new_children = array_map(function($v){ 
					return $v->id;
				}, DJClassifiedsRegion::getSubReg($cat_id));
				$cid_w_children = array_merge($cid_w_children, $new_children);
			}

	        $query = "DELETE FROM #__djcf_regions WHERE ID IN (".implode(',', $cid_w_children).")";
	        $db->setQuery($query);
	        $db->execute();

			$app->enqueueMessage(JText::_('COM_DJCLASSIFIEDS_REGIONS_DELETED'), 'success');
	    }
		
	    $app->redirect('index.php?option=com_djclassifieds&view=regions');
	}

	function regenerateAliases()
	{
		$app = JFactory::getApplication();   		
	    $db = JFactory::getDBO();
			    	    
		$query = "SELECT * FROM #__djcf_regions";
		$db->setQuery($query);
		$regs = $db->loadObjectList();
	
		foreach($regs as $r){									
			$alias = DJClassifiedsSEO::getAliasName($r->name);
			$query = "UPDATE #__djcf_regions SET alias=".$db->q($alias)." WHERE id=".$r->id;
			$db->setQuery($query);
			$db->execute();
		}				        
	    
		$app->enqueueMessage(JText::_('COM_DJCLASSIFIEDS_ALIASES_RECREATED'), 'success');
	    $app->redirect('index.php?option=com_djclassifieds&view=regions');
	}

	public function batch()
	{
		$app = JFactory::getApplication();
	    $db = JFactory::getDBO();
		$user = JFactory::getUser();
		$redirect = 'index.php?option=com_djclassifieds&view=regions';

		if (!$user->authorise('core.admin', 'com_djclassifieds')) {
	    	$this->setMessage(JText::_('JGLOBAL_BATCH_CANNOT_EDIT'), 'error');
	    	$this->setRedirect($redirect);
	    	return false;
	    }
		
		$cid_arr = $app->input->get('cid', array());
		$reg_id = $app->input->get('batch_rid', '');
		$updated = '0';

	    if ($cid_arr && $reg_id != ''){
	        $ids = implode(',', $cid_arr);

			$query = "UPDATE #__djcf_regions SET parent_id=".$reg_id." WHERE id IN (".$ids.")";
			$db->setQuery($query);
			$db->execute();
			
			$updated = count($cid_arr);
		}

		$app->enqueueMessage(JText::sprintf('COM_DJCLASSIFIEDS_BATCH_REGIONS_UPDATED', $updated), 'success');
	    $app->redirect($redirect);
	}
	
	function checkRegions()
	{
		$app = JFactory::getApplication();
		$db = JFactory::getDBO();
			
		$query = "SELECT * FROM #__djcf_regions ORDER BY id";
		$db->setQuery($query);
		$regs = $db->loadObjectList('id');
		echo 'Total regions '.count($regs).'<br /><br />';
	
		$r = 0;
		foreach($regs as $reg){
			$parent_id = $reg->parent_id;
			echo $reg->id.' ';
			for($i=0;$i<=15;$i++){
				echo $parent_id.' ';
				if($parent_id==0){break;}
				$parent_id = $regs[$parent_id]->parent_id;
			}
			echo '<br />';
				
			if($parent_id>0){
				echo '------------------------------------------<br />';
				echo 'error for region id '.$reg->id.'<br />';
				echo '------------------------------------------<br />';
			}
				
			$r++;
			//if($r>10000){break;}
		}
		
		$app->close();
	}
}
Site is undergoing maintenance

PACJA Events

Maintenance mode is on

Site will be available soon. Thank you for your patience!