Current File : /home/pacjaorg/public_html/kmm/plugins/user/djcfplans/djcfplans.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( 'Restricted access' );

class plgUserdjcfplans extends JPlugin
{
	public function onUserAfterLogin($options)
	{		
		$user = $options['user'];
		
		$db = JFactory::getDBO();
		$query = "SELECT * FROM #__djcf_plans_subscr WHERE user_id=".$user->id." ORDER BY id DESC ";
		$db->setQuery($query);
		$user_plans = $db->loadObjectList();
		
		$query = "SELECT * FROM #__djcf_plans";
		$db->setQuery($query);
		$plans = $db->loadObjectList('id');
		
		$plans_plugin = JPluginHelper::getPlugin('djclassifieds', 'plans');
		if(!$plans_plugin){
			return;
		}
		$plugin_params = new JRegistry($plans_plugin->params);
		$free_expiration =  $plugin_params->get('ps_free_plan_expiration','0'); // 'expiration date or 0 adverts limit reached' OR 'only when expiration date reached'
		
		for($i=0;$i<10;$i++){
			$plan_id = $this->params->get('plan_id'.$i, '');
			if($plan_id && isset($plans[$plan_id])){
				if(isset($user->groups[$this->params->get('usergroup'.$i, '')])){
					$plan_found = 0;
					$plan_active = 0;

					foreach($user_plans as $uplan){				
						if($plan_id==$uplan->plan_id){
							$plan_found++;

							$free_expiration_check = $free_expiration == '0' ? $uplan->adverts_available : true;
							if(($uplan->date_exp > JFactory::getDate()->toSQL() || $uplan->date_exp == '0000-00-00 00:00:00') && ($plans[$plan_id]->price > 0 || ($plans[$plan_id]->price == 0 && $free_expiration_check))){
								$plan_active++;
								break;
							}
						}												
					}
					
					if($plan_active==0 && ($plan_found==0 || $this->params->get('plan_renew'.$i, '')==1)){
						$plan = $plans[$plan_id];
						$registry = new JRegistry();
						$registry->loadString($plan->params);
						$plan_params = $registry->toObject();
						
						$date_exp = $plan_params->days_limit ? JFactory::getDate('now +'.$plan_params->days_limit.'day') : '0000-00-00 00:00:00';

						$query = "INSERT INTO #__djcf_plans_subscr (`user_id`,`plan_id`,`adverts_limit`,`adverts_available`,`date_start`,`date_exp`,`plan_params`) "
								."VALUES (".$user->id.",".$plan->id.",".$plan_params->ad_limit.",".($plan_params->ad_limit == '-1' ? '9999999' : $plan_params->ad_limit).",".$db->q(JFactory::getDate()->toSQL()).",".$db->q($date_exp).",".$db->q(addslashes($plan->params)).")";
						$db->setQuery($query);
						$db->execute();
					}
					
				}				
			}
		}
	}
}
Site is undergoing maintenance

PACJA Events

Maintenance mode is on

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