function display($tpl = null)
 {
     $app = JFactory::getApplication();
     $document = JFactory::getDocument();
     $Itemid = JRequest::getVar('Itemid', 0, 'int');
     //$document->link = JRoute::_(WeblinksHelperRoute::getCategoryRoute(JRequest::getVar('id', null, '', 'int')));
     JRequest::setVar('limit', $app->getCfg('feed_limit'));
     $siteEmail = $app->getCfg('mailfrom');
     $fromName = $app->getCfg('fromname');
     $document->editor = $fromName;
     $document->editorEmail = $siteEmail;
     // Get some data from the model
     $model = $this->getModel();
     $cat_id = JRequest::getVar('cid', 0, '', 'int');
     $catlist = '';
     $maincat = '';
     if ($cat_id > 0) {
         $main_cat = $model->getMainCat($cat_id);
         $document->title = $main_cat->name;
         $cats = DJClassifiedsCategory::getSubCatIemsCount($cat_id, 1);
         $catlist = $cat_id;
         foreach ($cats as $c) {
             $catlist .= ',' . $c->id;
         }
     }
     $items = $model->getItems($catlist);
     foreach ($items as $item) {
         // strip html from feed item title
         $title = $this->escape($item->name);
         $title = html_entity_decode($title, ENT_COMPAT, 'UTF-8');
         // url link to article
         //$link = JRoute::_('index.php?option=com_djclassifieds&view=item&cid='.$item->cat_id.'&id='.$item->id.'&Itemid='.$Itemid);
         if (!$item->alias) {
             $item->alias = DJClassifiedsSEO::getAliasName($item->name);
         }
         if (!$item->c_alias) {
             $item->c_alias = DJClassifiedsSEO::getAliasName($item->c_name);
         }
         $link = JRoute::_(DJClassifiedsSEO::getItemRoute($item->id . ':' . $item->alias, $item->cat_id . ':' . $item->c_alias));
         //echo $link;die();
         // strip html from feed item description text
         $description = $item->intro_desc;
         $date = $item->date_start ? date('r', strtotime($item->date_start)) : '';
         if ($item->image_url != '') {
             $images = explode(';', $item->image_url);
             $description .= '<img align="right" src="' . JURI::base() . '/components/com_djclassifieds/images/' . $images[0] . '.ths.jpg" />';
         }
         // load individual item creator class
         $feeditem = new JFeedItem();
         $feeditem->title = $title;
         $feeditem->link = $link;
         $feeditem->description = $description;
         $feeditem->date = $date;
         $feeditem->category = $item->c_name;
         // loads item info into rss array
         $document->addItem($feeditem);
     }
 }
?>
 = new google.maps.Map(document.getElementById("djmod_map<?php 
echo $module->id;
?>
"), opcjeMapy); 				    				    
					 var size = new google.maps.Size(32,32);
	                 var start_point = new google.maps.Point(0,0);
	                 var anchor_point = new google.maps.Point(0,16);	            			 
					<?php 
$ia = 0;
foreach ($items as $item) {
    if (!$item->alias) {
        $item->alias = DJClassifiedsSEO::getAliasName($item->name);
    }
    if (!$item->c_alias) {
        $item->c_alias = DJClassifiedsSEO::getAliasName($item->c_name);
    }
    if (isset($gm_cat_icons[$item->cat_id])) {
        $gm_icon_a = $gm_cat_icons[$item->cat_id]['width'] / 2;
        ?>
			                var size = new google.maps.Size(<?php 
        echo $gm_cat_icons[$item->cat_id]['width'] . ',' . $gm_cat_icons[$item->cat_id]['height'];
        ?>
);
		             		var start_point = new google.maps.Point(0,0);
		             		var anchor_point = new google.maps.Point(<?php 
        echo $gm_icon_a . ',' . $gm_cat_icons[$item->cat_id]['height'];
        ?>
);
		             		var icon = new google.maps.MarkerImage("<?php 
        echo $gm_cat_icons[$item->cat_id]['img'];
Example #3
0
 public function onAfterDJClassifiedsDisplayProfile(&$profile, $params, $view)
 {
     $app = JFactory::getApplication();
     if (!$profile['id']) {
         return false;
     }
     $group_id = $this->params->get('rating_group_author', false);
     if (!$group_id) {
         return false;
     }
     require_once JPath::clean(JPATH_ROOT . '/components/com_djreviews/lib/api.php');
     require_once JPath::clean(JPATH_ROOT . '/administrator/components/com_djclassifieds/lib/djseo.php');
     $uid_slug = $profile['id'] . ':' . DJClassifiedsSEO::getAliasName($profile['name']);
     $name = $profile['name'] ? $profile['name'] : $profile['id'];
     $review = DJReviewsAPI::getInstance(array('group' => $group_id, 'type' => 'com_djclassifieds.author', 'name' => $name, 'link' => 'index.php?option=com_djclassifieds&view=profile&uid=' . $uid_slug, 'id' => $profile['id']));
     return $review->getFullReview();
 }
				</div>
			<?php 
}
if ($par->get('showauthor', '1') == 1) {
    ?>
		<div class="row_gd user_name">
			<span class="row_label"><?php 
    echo JText::_('COM_DJCLASSIFIEDS_CREATED_BY');
    ?>
</span>
			<span class="row_value">
				<?php 
    if ($item->user_id == 0) {
        echo JText::_('COM_DJCLASSIFIEDS_GUEST');
    } else {
        $uid_slug = $item->user_id . ':' . DJClassifiedsSEO::getAliasName($item->username);
        ?>
					<div class="profile_item_box">
						<?php 
        if ($this->profile['img']) {
            echo '<a class="profile_img" href="index.php?option=com_djclassifieds&view=profile&uid=' . $uid_slug . '&Itemid=' . $Itemid . '"><img src="' . JURI::base() . $this->profile['img']->path . $this->profile['img']->name . '_ths.' . $this->profile['img']->ext . '" /></a>';
        }
        ?>
						<div class="profile_name_data">
							<?php 
        echo '<a class="profile_name" href="index.php?option=com_djclassifieds&view=profile&uid=' . $uid_slug . '&Itemid=' . $Itemid . '">' . $item->username . ' <span>(' . $this->user_items_c . ')</span></a>';
        ?>
							<?php 
        if ($this->profile['data']) {
            ?>
								<div class="profile_data">
Example #5
0
 public static function getCategoriesSortParent($p = '0', $ord = 'ord')
 {
     if (!self::$_categories_sparent) {
         self::$_categories_sparent = array();
     }
     if (isset(self::$_categories_sparent[$p . '_' . $ord])) {
         return self::$_categories_sparent[$p . '_' . $ord];
     }
     if ($p) {
         $pub = 'WHERE c.published=1 ';
     } else {
         $pub = '';
     }
     if ($ord == 'name') {
         $order = 'c.name';
     } else {
         $order = 'c.ordering';
     }
     $db = JFactory::getDBO();
     $query = "SELECT c.*, cc.name as parent_name,IFNULL(i.items_count,0) items_count FROM #__djcf_categories c " . "LEFT JOIN #__djcf_categories cc ON c.parent_id=cc.id " . "LEFT JOIN (SELECT i.cat_id, count(i.id) as items_count " . "FROM #__djcf_items i WHERE i.published=1 AND i.date_exp > NOW() GROUP BY i.cat_id) i ON i.cat_id=c.id " . $pub . "ORDER BY c.parent_id, " . $order;
     $db->setQuery($query);
     $allcategories = $db->loadObjectList();
     $categories = array();
     foreach ($allcategories as $cat) {
         if (!$cat->alias) {
             $cat->alias = DJClassifiedsSEO::getAliasName($cat->name);
         }
         if (!isset($categories[$cat->parent_id])) {
             $categories[$cat->parent_id] = array();
         }
         $categories[$cat->parent_id][] = $cat;
     }
     //echo '<pre>';print_r($db);print_r($allcategories);die();
     self::$_categories_sparent[$p . '_' . $ord] = $categories;
     return self::$_categories_sparent[$p . '_' . $ord];
 }
Example #6
0
 function save()
 {
     $app = JFactory::getApplication();
     JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
     jimport('joomla.database.table');
     JPluginHelper::importPlugin('djclassifieds');
     $row = JTable::getInstance('Items', 'DJClassifiedsTable');
     $par = JComponentHelper::getParams('com_djclassifieds');
     $user = JFactory::getUser();
     $lang = JFactory::getLanguage();
     $dispatcher = JDispatcher::getInstance();
     $db = JFactory::getDBO();
     $id = JRequest::getVar('id', 0, '', 'int');
     $token = JRequest::getCMD('token', '');
     $redirect = '';
     $menus = $app->getMenu('site');
     $menu_item = $menus->getItems('link', 'index.php?option=com_djclassifieds&view=items&cid=0', 1);
     $menu_item_blog = $menus->getItems('link', 'index.php?option=com_djclassifieds&view=items&layout=blog&cid=0', 1);
     $itemid = '';
     if ($menu_item) {
         $itemid = '&Itemid=' . $menu_item->id;
     } else {
         if ($menu_item_blog) {
             $itemid = '&Itemid=' . $menu_item_blog->id;
         }
     }
     $menu_newad_itemid = $menus->getItems('link', 'index.php?option=com_djclassifieds&view=additem', 1);
     $new_ad_link = 'index.php?option=com_djclassifieds&view=additem';
     if ($menu_newad_itemid) {
         $new_ad_link .= '&Itemid=' . $menu_newad_itemid->id;
     }
     $new_ad_link = JRoute::_($new_ad_link);
     if ($user->id == 0 && $id > 0) {
         $message = JText::_('COM_DJCLASSIFIEDS_WRONG_AD');
         //$redirect="index.php?option=com_djclassifieds&view=items&cid=0".$itemid;
         $redirect = DJClassifiedsSEO::getCategoryRoute('0:all');
         $redirect = JRoute::_($redirect);
         $app->redirect($redirect, $message, 'error');
     }
     $db = JFactory::getDBO();
     if ($id > 0) {
         $query = "SELECT user_id FROM #__djcf_items WHERE id='" . $id . "' LIMIT 1";
         $db->setQuery($query);
         $item_user_id = $db->loadResult();
         if ($item_user_id != $user->id) {
             $message = JText::_('COM_DJCLASSIFIEDS_WRONG_AD');
             $redirect = DJClassifiedsSEO::getCategoryRoute('0:all');
             $redirect = JRoute::_($redirect);
             $app->redirect($redirect, $message, 'error');
         }
     }
     if ($par->get('user_type') == 1 && $user->id == '0') {
         //$uri = "index.php?option=com_djclassifieds&view=items&cid=0".$itemid;
         $uri = DJClassifiedsSEO::getCategoryRoute('0:all');
         $app->redirect('index.php?option=com_users&view=login&return=' . base64_encode($uri), JText::_('COM_DJCLASSIFIEDS_PLEASE_LOGIN'));
     }
     $row->bind(JRequest::get('post'));
     if ($token && !$user->id && !$id) {
         $query = "SELECT i.id FROM #__djcf_items i " . "WHERE i.user_id=0 AND i.token=" . $db->Quote($db->escape($token));
         $db->setQuery($query);
         $ad_id = $db->loadResult();
         if ($ad_id) {
             $row->id = $ad_id;
         } else {
             $uri = DJClassifiedsSEO::getCategoryRoute('0:all');
             $app->redirect('index.php?option=com_users&view=login&return=' . base64_encode($uri), JText::_('COM_DJCLASSIFIEDS_WRONG_TOKEN'));
         }
     }
     $dispatcher->trigger('onAfterInitialiseDJClassifiedsSaveAdvert', array(&$row, &$par));
     if ($par->get('title_char_limit', '0') > 0) {
         $row->name = mb_substr($row->name, 0, $par->get('title_char_limit', '100'), "UTF-8");
     }
     if ((int) $par->get('allow_htmltags', '0')) {
         $row->description = JRequest::getVar('description', '', 'post', 'string', JREQUEST_ALLOWRAW);
         $allowed_tags = explode(';', $par->get('allowed_htmltags', ''));
         $a_tags = '';
         for ($a = 0; $a < count($allowed_tags); $a++) {
             $a_tags .= '<' . $allowed_tags[$a] . '>';
         }
         $row->description = strip_tags($row->description, $a_tags);
     } else {
         $row->description = nl2br(JRequest::getVar('description', '', 'post', 'string'));
     }
     $row->intro_desc = mb_substr(strip_tags(nl2br($row->intro_desc)), 0, $par->get('introdesc_char_limit', '120'), "UTF-8");
     if (!$row->intro_desc) {
         $row->intro_desc = mb_substr(strip_tags($row->description), 0, $par->get('introdesc_char_limit', '120'), "UTF-8");
     }
     $row->contact = nl2br(JRequest::getVar('contact', '', 'post', 'string'));
     $row->price_negotiable = JRequest::getInt('price_negotiable', '0');
     $row->bid_min = str_ireplace(',', '.', JRequest::getVar('bid_min', '', 'post', 'string'));
     $row->bid_max = str_ireplace(',', '.', JRequest::getVar('bid_max', '', 'post', 'string'));
     $row->price_reserve = str_ireplace(',', '.', JRequest::getVar('price_reserve', '', 'post', 'string'));
     if (!$id && !$token && !$user->id && $par->get('guest_can_edit', 0)) {
         $characters = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
         $row->token = '';
         for ($p = 0; $p < 20; $p++) {
             $row->token .= $characters[mt_rand(0, strlen($characters))];
         }
     }
     /*
     	//removing images from folder and from database
     	$path = JPATH_BASE."/components/com_djclassifieds/images/";
     $images = $row->image_url;
     		if(isset($_POST['del_img'])){			
     			$del_image = $_POST['del_img'];	
     		}else{
     			$del_image = array();
     		}    
     
     
     for ($i = 0; $i < count($del_image); $i++){
     
         $images = str_replace($del_image[$i].';', '', $images);
         //deleting the main image
         if (JFile::exists($path.$del_image[$i])){
             JFile::delete($path.$del_image[$i]);
         }
         //deleting thumbnail of image
     		if (JFile::exists($path.$del_image[$i].'.thb.jpg')){
             JFile::delete($path.$del_image[$i].'.thb.jpg');
         }
         if (JFile::exists($path.$del_image[$i].'.th.jpg')){
             JFile::delete($path.$del_image[$i].'.th.jpg');
         }
     		if (JFile::exists($path.$del_image[$i].'.thm.jpg')){
             JFile::delete($path.$del_image[$i].'.thm.jpg');
         }
         if (JFile::exists($path.$del_image[$i].'.ths.jpg')){
             JFile::delete($path.$del_image[$i].'.ths.jpg');
         }
     }
     
      
     //add images
     $new_files = $_FILES['image'];
     if(count($new_files['name'])>0 && $row->id==0){			
     		$query = "SELECT id FROM #__djcf_items ORDER BY id DESC LIMIT 1";
     		$db->setQuery($query);
     		$last_id =$db->loadResult();
     		$last_id++;
     	}else{
     		$last_id= $row->id;
     	}
     	
     	$nw = (int)$par->get('th_width',-1);
     $nh = (int)$par->get('th_height',-1);
     	$nws = $par->get('smallth_width',-1);
     $nhs = $par->get('smallth_height',-1);
     	$nwm = $par->get('middleth_width',-1);
     $nhm = $par->get('middleth_height',-1);			
     	$nwb = $par->get('bigth_width',-1);
     $nhb = $par->get('bigth_height',-1);		
     	$img_maxsize = $par->get('img_maxsize',0);		
     		if($img_maxsize>0){
     			$img_maxsize = $img_maxsize*1024*1024;
     		}
     	
     	$lang = JFactory::getLanguage();
     for ($i = 0; $i < count($new_files['name']); $i++)
     {
         if (substr($new_files['type'][$i], 0, 5) == "image")
         {
        			if($img_maxsize>0 && $new_files['size'][$i]>$img_maxsize){
        				$app->enqueueMessage(JText::_('COM_DJCLASSIFIEDS_TO_BIG_IMAGE').' : \''.$new_files['name'][$i].'\'','error');
     				continue;
     			}
     			if(!getimagesize($new_files['tmp_name'][$i])){
     				$app->enqueueMessage(JText::_('COM_DJCLASSIFIEDS_WRONG_IMAGE_TYPE').' : \''.$new_files['name'][$i].'\'','error');
     				continue;
     			}				
     			$n_name = $last_id.'_'.$new_files['name'][$i];    				
     			$n_name = $lang->transliterate($n_name);
     			$n_name = strtolower($n_name);
     			$n_name = JFile::makeSafe($n_name);
     			        	
         	$new_path = JPATH_BASE."/components/com_djclassifieds/images/".$n_name;
     			$nimg= 0;			
     			while(JFile::exists($new_path)){
     				$nimg++;
     			$n_name = $last_id.'_'.$nimg.'_'.$new_files['name'][$i];
     					$n_name = $lang->transliterate($n_name);
     					$n_name = strtolower($n_name);
     					$n_name = JFile::makeSafe($n_name);            	
         		$new_path = JPATH_BASE."/components/com_djclassifieds/images/".$n_name;
     			}
     			$images .= $n_name.';';
         	move_uploaded_file($new_files['tmp_name'][$i], $new_path);
     			//DJClassifiedsImage::makeThumb($new_path, $nw, $nh, 'th');
     			 	DJClassifiedsImage::makeThumb($new_path, $nws, $nhs, 'ths');
     				DJClassifiedsImage::makeThumb($new_path, $nwm, $nhm, 'thm');
     				DJClassifiedsImage::makeThumb($new_path, $nwb, $nhb, 'thb');
         }else if($new_files['name'][$i]){
     			$app->enqueueMessage(JText::_('COM_DJCLASSIFIEDS_WRONG_IMAGE_TYPE').' : \''.$new_files['name'][$i].'\'','error');	        	
         }
     }
     	
     $row->image_url = $images;
     */
     $row->image_url = '';
     $duration_price = 0;
     if ($row->id == 0) {
         if ($par->get('durations_list', '')) {
             $exp_days = JRequest::getVar('exp_days', $par->get('exp_days'), '', 'int');
             $query = "SELECT * FROM #__djcf_days WHERE days = " . $exp_days;
             $db->setQuery($query);
             $duration = $db->loadObject();
             if ($duration) {
                 $duration_price = $duration->price;
             } else {
                 //$exp_days = $par->get('exp_days','7');
                 $message = JText::_('COM_DJCLASSIFIEDS_WRONG_DURATION_LIMIT');
                 $app->redirect($new_ad_link, $message, 'error');
             }
         } else {
             $exp_days = $par->get('exp_days', '7');
         }
         if ($exp_days == 0) {
             $row->date_exp = "2038-01-01 00:00:00";
         } else {
             $row->date_exp = date("Y-m-d G:i:s", mktime(date("G"), date("i"), date("s"), date("m"), date("d") + $exp_days, date("Y")));
         }
         if ($row->date_exp == '1970-01-01 1:00:00') {
             $row->date_exp = '2038-01-19 00:00:00';
         }
         $row->exp_days = $exp_days;
         $row->date_start = date("Y-m-d H:i:s");
     }
     $row->cat_id = end($_POST['cats']);
     if (!$row->cat_id) {
         $row->cat_id = $_POST['cats'][count($_POST['cats']) - 2];
     }
     $row->cat_id = str_ireplace('p', '', $row->cat_id);
     /*if($par->get('region_add_type','1')){
     			$g_area = JRequest::getVar('g_area','');
     			$g_locality = JRequest::getVar('g_locality','');
     			$g_country = JRequest::getVar('g_country','');			
     			$latlong = str_ireplace(array('(',')'), array('',''), JRequest::getVar('latlong',''));
     			
     				$query = "SELECT id FROM #__djcf_regions WHERE name = '".$g_area."'";	
     				$db->setQuery($query);
     				$parent_r_id = $db->loadResult();
     				
     				if($parent_r_id){					
     					$query = "SELECT id FROM #__djcf_regions WHERE name = '".$g_locality."' AND parent_id=".$parent_r_id;	
     					$db->setQuery($query);
     					$region_id = $db->loadResult();
     					
     					if($region_id){
     						$row->region_id=$region_id;
     					}else{					
     						$region_row = &JTable::getInstance('Regions', 'DJClassifiedsTable');
     							$region_row->country=0;
     							$region_row->city=1;
     							$region_row->name=$g_locality;
     							$region_row->parent_id=$parent_r_id;
     													
     							//$ll = explode(',', $latlong);
     							//$region_row->latitude=$ll[0];
     							//$region_row->longitude=$ll[0];	
     							$region_row->published=1;
     							//echo '<pre>';print_r($region_row);die();							
     							if (!$region_row->store()){
     				        		exit ();	
     				    		}
     						$row->region_id=$region_row->id;	
     					}
     				}else{
     					$query = "SELECT id FROM #__djcf_regions WHERE name = '".$g_country."' ";	
     					$db->setQuery($query);
     					$country_id = $db->loadResult();
     					
     					if(!$country_id){$country_id=0;}
     					
     					$area_row = &JTable::getInstance('Regions', 'DJClassifiedsTable');
     						$area_row->country=0;
     						$area_row->city=0;
     						$area_row->name=$g_area;
     						$area_row->parent_id=$country_id;
     						$area_row->published=1;
     						//echo '<pre>';print_r($region_row);die();							
     						if (!$area_row->store()){
     			        		exit ();	
     			    		}
     					
     					$region_row = &JTable::getInstance('Regions', 'DJClassifiedsTable');
     						$region_row->country=0;
     						$region_row->city=1;
     						$region_row->name=$g_locality;
     						$region_row->parent_id=$area_row->id;
     												
     						//$ll = explode(',', $latlong);
     						//$region_row->latitude=$ll[0];
     						//$region_row->longitude=$ll[0];
     						$region_row->published=1;		
     						//echo '<pre>';print_r($region_row);die();							
     						if (!$region_row->store()){
     			        		exit ();	
     			    		}
     					$row->region_id=$region_row->id;	
     					
     				} 						
     		}else{*/
     $row->region_id = end($_POST['regions']);
     if (!$row->region_id) {
         $row->region_id = $_POST['regions'][count($_POST['regions']) - 2];
     }
     //}
     if (($row->region_id || $row->address) && ($row->latitude == '0.000000000000000' && $row->longitude == '0.000000000000000' || !$row->latitude && !$row->longitude)) {
         $address = '';
         if ($row->region_id) {
             $reg_path = DJClassifiedsRegion::getParentPath($row->region_id);
             for ($r = count($reg_path) - 1; $r >= 0; $r--) {
                 if ($reg_path[$r]->country) {
                     $address = $reg_path[$r]->name;
                 }
                 if ($reg_path[$r]->city) {
                     if ($address) {
                         $address .= ', ';
                     }
                     $address .= $reg_path[$r]->name;
                 }
             }
         }
         if ($address) {
             $address .= ', ';
         }
         $address .= $row->address;
         if ($row->post_code) {
             $address .= ', ' . $row->post_code;
         }
         $loc_coord = DJClassifiedsGeocode::getLocation($address);
         if (is_array($loc_coord)) {
             $row->latitude = $loc_coord['lat'];
             $row->longitude = $loc_coord['lng'];
         }
     }
     //echo '<pre>';print_r($row);die();
     $row->user_id = $user->id;
     $row->ip_address = $_SERVER['REMOTE_ADDR'];
     $row->promotions = '';
     if ($par->get('promotion', '1') == '1') {
         $query = "SELECT p.* FROM #__djcf_promotions p WHERE p.published=1 ORDER BY p.id ";
         $db->setQuery($query);
         $promotions = $db->loadObjectList();
         foreach ($promotions as $prom) {
             if (JRequest::getVar($prom->name, '0')) {
                 $row->promotions .= $prom->name . ',';
             }
         }
         if ($row->promotions) {
             $row->promotions = substr($row->promotions, 0, -1);
         }
     } else {
         if ($row->id > 0) {
             $row->promotions = $old_row->promotions;
         }
     }
     if (strstr($row->promotions, 'p_first')) {
         $row->special = 1;
     } else {
         $row->special = 0;
     }
     $cat = '';
     if ($row->cat_id) {
         $query = "SELECT name,alias,price,autopublish FROM #__djcf_categories WHERE id = " . $row->cat_id;
         $db->setQuery($query);
         $cat = $db->loadObject();
         if (!$cat->alias) {
             $cat->alias = DJClassifiedsSEO::getAliasName($cat->name);
         }
     }
     $is_new = 1;
     if ($row->id > 0) {
         $query = "SELECT * FROM #__djcf_items WHERE id = " . $row->id;
         $db->setQuery($query);
         $old_row = $db->loadObject();
         $query = "DELETE FROM #__djcf_fields_values WHERE item_id= " . $row->id . " ";
         $db->setQuery($query);
         $db->query();
         $query = "DELETE FROM #__djcf_fields_values_sale WHERE item_id= " . $row->id . " ";
         $db->setQuery($query);
         $db->query();
         $row->payed = $old_row->payed;
         $row->pay_type = $old_row->pay_type;
         $row->exp_days = $old_row->exp_days;
         $row->alias = $old_row->alias;
         $row->published = $old_row->published;
         $is_new = 0;
     }
     if (!$row->alias) {
         $row->alias = DJClassifiedsSEO::getAliasName($row->name);
     }
     $dispatcher->trigger('onBeforePaymentsDJClassifiedsSaveAdvert', array(&$row, $is_new, &$cat, &$promotions));
     if ($cat->autopublish == '0') {
         if ($par->get('autopublish') == '1') {
             $row->published = 1;
             if ($row->id) {
                 $message = JText::_('COM_DJCLASSIFIEDS_AD_SAVED_SUCCESSFULLY');
             } else {
                 $message = JText::_('COM_DJCLASSIFIEDS_AD_ADDED_SUCCESSFULLY');
             }
         } else {
             $row->published = 0;
             if ($row->id) {
                 $message = JText::_('COM_DJCLASSIFIEDS_AD_SAVED_SUCCESSFULLY_WAITING_FOR_PUBLISH');
             } else {
                 $message = JText::_('COM_DJCLASSIFIEDS_AD_ADDED_SUCCESSFULLY_WAITING_FOR_PUBLISH');
             }
             //$redirect="index.php?option=com_djclassifieds&view=items&cid=0".$itemid;
             $redirect = DJClassifiedsSEO::getItemRoute($row->id . ':' . $row->alias, $row->cat_id . ':' . $i->c_alias);
         }
     } elseif ($cat->autopublish == '1') {
         $row->published = 1;
         if ($row->id) {
             $message = JText::_('COM_DJCLASSIFIEDS_AD_SAVED_SUCCESSFULLY');
         } else {
             $message = JText::_('COM_DJCLASSIFIEDS_AD_ADDED_SUCCESSFULLY');
         }
     } elseif ($cat->autopublish == '2') {
         $row->published = 0;
         if ($row->id) {
             $message = JText::_('COM_DJCLASSIFIEDS_AD_SAVED_SUCCESSFULLY_WAITING_FOR_PUBLISH');
         } else {
             $message = JText::_('COM_DJCLASSIFIEDS_AD_ADDED_SUCCESSFULLY_WAITING_FOR_PUBLISH');
         }
         $redirect = DJClassifiedsSEO::getCategoryRoute('0:all');
     }
     $pay_redirect = 0;
     $row->pay_type = '';
     $row->payed = 1;
     //echo '<pre>';print_r($old_row);print_r($row);die();
     if (isset($old_row)) {
         if ($cat->price == 0 && $row->promotions == '' && !strstr($old_row->pay_type, 'duration')) {
             $row->payed = 1;
             $row->pay_type = '';
         } else {
             if ($old_row->cat_id != $row->cat_id && $cat->price > 0 || $old_row->promotions != $row->promotions || strstr($old_row->pay_type, 'duration') || $old_row->pay_type) {
                 $row->pay_type = '';
                 if ($old_row->cat_id != $row->cat_id && $cat->price > 0) {
                     $row->pay_type = 'cat,';
                 } else {
                     if ($old_row->cat_id == $row->cat_id && $cat->price > 0 && strstr($old_row->pay_type, 'cat')) {
                         $row->pay_type = 'cat,';
                     }
                 }
                 //if($old_row->promotions!=$row->promotions){
                 $prom_new = explode(',', $row->promotions);
                 for ($pn = 0; $pn < count($prom_new); $pn++) {
                     if (!strstr($old_row->promotions, $prom_new[$pn]) || strstr($old_row->pay_type, $prom_new[$pn])) {
                         $row->pay_type .= $prom_new[$pn] . ',';
                     }
                 }
                 //}
                 if (strstr($old_row->pay_type, 'duration')) {
                     $row->pay_type .= 'duration,';
                 }
                 if ($row->pay_type) {
                     $row->published = 0;
                     $row->payed = 0;
                     $pay_redirect = 1;
                 }
                 //echo $row->pay_type;print_r($old_row);
                 //print_r($row);echo $pay_redirect;die();
             } else {
                 if ($row->payed == 0 && ($cat->price > 0 || $row->promotions != '')) {
                     $row->payed = 0;
                     $row->published = 0;
                     $pay_redirect = 1;
                 }
             }
         }
     } else {
         if ($cat->price > 0 || $row->promotions != '' || $duration_price > 0) {
             if ($cat->price > 0) {
                 $row->pay_type .= 'cat,';
             }
             if ($duration_price > 0) {
                 $row->pay_type .= 'duration,';
             }
             if ($row->promotions != '') {
                 $row->pay_type .= $row->promotions;
             }
             $row->published = 0;
             $row->payed = 0;
             $pay_redirect = 1;
         } else {
             $row->payed = 1;
             $row->pay_type = '';
         }
     }
     //check for free promotions
     if (!strstr($row->pay_type, 'cat') && !strstr($row->pay_type, 'duration') && strstr($row->pay_type, 'p_')) {
         $prom_to_pay = explode(',', $row->pay_type);
         $prom_price = 0;
         for ($pp = 0; $pp < count($prom_to_pay); $pp++) {
             foreach ($promotions as $prom) {
                 if ($prom->name == $prom_to_pay[$pp]) {
                     $prom_price += $prom->price;
                 }
             }
         }
         if ($prom_price == 0) {
             $row->pay_type = '';
             $redirect = '';
             $pay_redirect = 0;
             if ($cat->autopublish == '0' && $par->get('autopublish') == '1' || $cat->autopublish == '1') {
                 $row->published = 1;
             }
         }
     }
     //echo '<pre>';print_r($row);die();echo '</pre>';
     $dispatcher->trigger('onBeforeDJClassifiedsSaveAdvert', array(&$row, $is_new));
     if (!$row->store()) {
         //echo $row->getError();exit ();
     }
     if ($is_new) {
         $query = "UPDATE #__djcf_items SET date_sort=date_start WHERE id=" . $row->id . " ";
         $db->setQuery($query);
         $db->query();
     }
     $item_images = '';
     $images_c = 0;
     if (!$is_new) {
         $query = "SELECT * FROM #__djcf_images WHERE item_id=" . $row->id . " AND type='item' ";
         $db->setQuery($query);
         $item_images = $db->loadObjectList('id');
         $images_c = count($item_images);
     }
     $img_ids = JRequest::getVar('img_id', array(), 'post', 'array');
     $img_captions = JRequest::getVar('img_caption', array(), 'post', 'array');
     $img_images = JRequest::getVar('img_image', array(), 'post', 'array');
     $img_id_to_del = '';
     if ($item_images) {
         foreach ($item_images as $item_img) {
             $img_to_del = 1;
             foreach ($img_ids as $img_id) {
                 if ($item_img->id == $img_id) {
                     $img_to_del = 0;
                     break;
                 }
             }
             if ($img_to_del) {
                 $images_c--;
                 $path_to_delete = JPATH_ROOT . $item_img->path . $item_img->name;
                 if (JFile::exists($path_to_delete . '.' . $item_img->ext)) {
                     JFile::delete($path_to_delete . '.' . $item_img->ext);
                 }
                 if (JFile::exists($path_to_delete . '_ths.' . $item_img->ext)) {
                     JFile::delete($path_to_delete . '_ths.' . $item_img->ext);
                 }
                 if (JFile::exists($path_to_delete . '_thm.' . $item_img->ext)) {
                     JFile::delete($path_to_delete . '_thm.' . $item_img->ext);
                 }
                 if (JFile::exists($path_to_delete . '_thb.' . $item_img->ext)) {
                     JFile::delete($path_to_delete . '_thb.' . $item_img->ext);
                 }
                 $img_id_to_del .= $item_img->id . ',';
             }
         }
         if ($img_id_to_del) {
             $query = "DELETE FROM #__djcf_images WHERE item_id=" . $row->id . " AND type='item' AND ID IN (" . substr($img_id_to_del, 0, -1) . ") ";
             $db->setQuery($query);
             $db->query();
         }
     }
     $last_id = $row->id;
     $imglimit = $par->get('img_limit', '3');
     $nw = (int) $par->get('th_width', -1);
     $nh = (int) $par->get('th_height', -1);
     $nws = (int) $par->get('smallth_width', -1);
     $nhs = (int) $par->get('smallth_height', -1);
     $nwm = (int) $par->get('middleth_width', -1);
     $nhm = (int) $par->get('middleth_height', -1);
     $nwb = (int) $par->get('bigth_width', -1);
     $nhb = (int) $par->get('bigth_height', -1);
     $img_ord = 1;
     $img_to_insert = 0;
     $query_img = "INSERT INTO #__djcf_images(`item_id`,`type`,`name`,`ext`,`path`,`caption`,`ordering`) VALUES ";
     $new_img_path = JPATH_SITE . "/components/com_djclassifieds/images/item/";
     for ($im = 0; $im < count($img_ids); $im++) {
         if ($img_ids[$im]) {
             if ($item_images[$img_ids[$im]]->ordering != $img_ord || $item_images[$img_ids[$im]]->caption != $img_captions[$im]) {
                 $query = "UPDATE #__djcf_images SET ordering='" . $img_ord . "', caption='" . $db->escape($img_captions[$im]) . "' WHERE item_id=" . $row->id . " AND type='item' AND id=" . $img_ids[$im] . " ";
                 $db->setQuery($query);
                 $db->query();
             }
         } else {
             if ($images_c >= $imglimit) {
                 break;
             }
             $new_img_name = explode(';', $img_images[$im]);
             if (is_array($new_img_name)) {
                 $new_img_name_u = JPATH_ROOT . '/tmp/djupload/' . $new_img_name[0];
                 if (JFile::exists($new_img_name_u)) {
                     if (getimagesize($new_img_name_u)) {
                         $new_img_n = $last_id . '_' . str_ireplace(' ', '_', $new_img_name[1]);
                         $new_img_n = $lang->transliterate($new_img_n);
                         $new_img_n = strtolower($new_img_n);
                         $new_img_n = JFile::makeSafe($new_img_n);
                         $nimg = 0;
                         $name_parts = pathinfo($new_img_n);
                         $img_name = $name_parts['filename'];
                         $img_ext = $name_parts['extension'];
                         $new_path_check = $new_img_path . $new_img_n;
                         $new_path_check = str_ireplace('.' . $img_ext, '_thm.' . $img_ext, $new_path_check);
                         while (JFile::exists($new_path_check)) {
                             $nimg++;
                             $new_img_n = $last_id . '_' . $nimg . '_' . str_ireplace(' ', '_', $new_img_name[1]);
                             $new_img_n = $lang->transliterate($new_img_n);
                             $new_img_n = strtolower($new_img_n);
                             $new_img_n = JFile::makeSafe($new_img_n);
                             $new_path_check = $new_img_path . $new_img_n;
                             $new_path_check = str_ireplace('.' . $img_ext, '_thm.' . $img_ext, $new_path_check);
                         }
                         rename($new_img_name_u, $new_img_path . $new_img_n);
                         $name_parts = pathinfo($new_img_n);
                         $img_name = $name_parts['filename'];
                         $img_ext = $name_parts['extension'];
                         DJClassifiedsImage::makeThumb($new_img_path . $new_img_n, $new_img_path . $img_name . '_ths.' . $img_ext, $nws, $nhs);
                         DJClassifiedsImage::makeThumb($new_img_path . $new_img_n, $new_img_path . $img_name . '_thm.' . $img_ext, $nwm, $nhm);
                         DJClassifiedsImage::makeThumb($new_img_path . $new_img_n, $new_img_path . $img_name . '_thb.' . $img_ext, $nwb, $nhb);
                         $query_img .= "('" . $row->id . "','item','" . $img_name . "','" . $img_ext . "','/components/com_djclassifieds/images/item/','" . $db->escape($img_captions[$im]) . "','" . $img_ord . "'), ";
                         $img_to_insert++;
                         if ($par->get('store_org_img', '1') == 0) {
                             JFile::delete($new_img_path . $new_img_n);
                         }
                     }
                 }
             }
             $images_c++;
         }
         $img_ord++;
     }
     if ($img_to_insert) {
         $query_img = substr($query_img, 0, -2) . ';';
         $db->setQuery($query_img);
         $db->query();
     }
     $imgfreelimit = $par->get('img_free_limit', '-1');
     if ($imgfreelimit > -1 && $images_c > $imgfreelimit) {
         $extra_images = $images_c - $imgfreelimit;
         $images_to_pay = $extra_images;
         if (!$is_new) {
             if ($old_row->extra_images >= $images_to_pay) {
                 $images_to_pay = 0;
             } else {
                 $images_to_pay = $images_to_pay - $old_row->extra_images;
             }
         }
         $images_to_pay = $images_to_pay + $old_row->extra_images_to_pay;
         if ($images_to_pay > 0) {
             $row->extra_images = $extra_images;
             $row->extra_images_to_pay = $images_to_pay;
             $row->pay_type .= 'extra_img,';
             $row->published = 0;
             $row->payed = 0;
             $pay_redirect = 1;
             $row->store();
         }
     }
     $desc_chars_limit = $par->get('pay_desc_chars_free_limit', 0);
     $desc_c = strlen($row->description);
     if ($par->get('pay_desc_chars', 0) && $desc_c > $desc_chars_limit) {
         $extra_chars = $desc_c - $desc_chars_limit;
         $chars_to_pay = $extra_chars;
         if (!$is_new) {
             if ($old_row->extra_chars >= $chars_to_pay) {
                 $chars_to_pay = 0;
             } else {
                 $chars_to_pay = $chars_to_pay - $old_row->extra_chars;
             }
         }
         $chars_to_pay = $chars_to_pay + $old_row->extra_chars_to_pay;
         if ($chars_to_pay > 0) {
             $row->extra_chars = $extra_chars;
             $row->extra_chars_to_pay = $chars_to_pay;
             $row->pay_type .= 'extra_chars,';
             $row->published = 0;
             $row->payed = 0;
             $pay_redirect = 1;
             $row->store();
         }
     }
     $query = "SELECT f.* FROM #__djcf_fields f " . "LEFT JOIN #__djcf_fields_xref fx ON f.id=fx.field_id " . " WHERE fx.cat_id  = " . $row->cat_id . " OR f.source=1 ";
     $db->setQuery($query);
     $fields_list = $db->loadObjectList();
     //echo '<pre>'; print_r($db);print_r($fields_list);die();
     $a_tags_cf = '';
     if ((int) $par->get('allow_htmltags_cf', '0')) {
         $allowed_tags_cf = explode(';', $par->get('allowed_htmltags_cf', ''));
         for ($a = 0; $a < count($allowed_tags_cf); $a++) {
             $a_tags_cf .= '<' . $allowed_tags_cf[$a] . '>';
         }
     }
     $ins = 0;
     if (count($fields_list) > 0) {
         $query = "INSERT INTO #__djcf_fields_values(`field_id`,`item_id`,`value`,`value_date`) VALUES ";
         foreach ($fields_list as $fl) {
             if ($fl->type == 'checkbox') {
                 if (isset($_POST[$fl->name])) {
                     $field_v = $_POST[$fl->name];
                     $f_value = ';';
                     for ($fv = 0; $fv < count($field_v); $fv++) {
                         $f_value .= $field_v[$fv] . ';';
                     }
                     $query .= "('" . $fl->id . "','" . $row->id . "','" . $db->escape($f_value) . "',''), ";
                     $ins++;
                 }
             } else {
                 if ($fl->type == 'date') {
                     if (isset($_POST[$fl->name])) {
                         $f_var = JRequest::getVar($fl->name, '', '', 'string');
                         $query .= "('" . $fl->id . "','" . $row->id . "','','" . $db->escape($f_var) . "'), ";
                         $ins++;
                     }
                 } else {
                     if (isset($_POST[$fl->name])) {
                         if ($a_tags_cf) {
                             $f_var = JRequest::getVar($fl->name, '', '', 'string', JREQUEST_ALLOWRAW);
                             $f_var = strip_tags($f_var, $a_tags_cf);
                         } else {
                             $f_var = JRequest::getVar($fl->name, '', '', 'string');
                         }
                         $query .= "('" . $fl->id . "','" . $row->id . "','" . $db->escape($f_var) . "',''), ";
                         $ins++;
                     }
                 }
             }
         }
     }
     //print_r($query);die();
     if ($ins > 0) {
         $query = substr($query, 0, -2) . ';';
         $db->setQuery($query);
         $db->query();
     }
     $query = "SELECT f.* FROM #__djcf_fields f " . "LEFT JOIN #__djcf_fields_xref fx ON f.id=fx.field_id " . "WHERE fx.cat_id  = " . $row->cat_id . " AND f.in_buynow=1 ";
     $db->setQuery($query);
     $fields_list = $db->loadObjectList();
     //echo '<pre>'; print_r($_POST);print_r($fields_list);die();
     $ins = 0;
     if (count($fields_list) > 0) {
         $query = "INSERT INTO #__djcf_fields_values_sale(`item_id`,`quantity`,`options`) VALUES ";
         $bn_quantity = JRequest::getVar('bn-quantity', array());
         $quantity_total = 0;
         foreach ($fields_list as &$fl) {
             $fl->bn_values = JRequest::getVar('bn-' . $fl->name, array());
         }
         $bn_options = array();
         for ($q = 0; $q < count($bn_quantity); $q++) {
             if ($bn_quantity[$q] == '' || $bn_quantity[$q] == 0) {
                 continue;
             }
             $bn_option = array();
             $bn_option['quantity'] = $bn_quantity[$q];
             $bn_option['options'] = array();
             $quantity_total = $quantity_total + $bn_quantity[$q];
             foreach ($fields_list as &$fl) {
                 if ($fl->bn_values[$q]) {
                     $bn_opt = array();
                     $bn_opt['id'] = $fl->id;
                     $bn_opt['name'] = $fl->name;
                     $bn_opt['label'] = $fl->label;
                     $bn_opt['value'] = $fl->bn_values[$q];
                     $bn_option['options'][] = $bn_opt;
                 }
             }
             if (count($bn_option['options'])) {
                 $bn_options[] = $bn_option;
             }
         }
         if (count($bn_options)) {
             foreach ($bn_options as $opt) {
                 $query .= "('" . $row->id . "','" . $opt['quantity'] . "','" . $db->escape(json_encode($opt['options'])) . "'), ";
                 $ins++;
             }
             if ($ins) {
                 $query = substr($query, 0, -2) . ';';
                 $db->setQuery($query);
                 $db->query();
                 $query = "UPDATE #__djcf_items SET quantity=" . $quantity_total . " WHERE id=" . $row->id . " ";
                 $db->setQuery($query);
                 $db->query();
             }
         }
     }
     if ($par->get('notify_admin', '0')) {
         if ($id > 0) {
             $new_ad = 0;
         } else {
             $new_ad = 1;
         }
         if ($par->get('notify_admin', '0') == 1) {
             DJClassifiedsNotify::notifyAdmin($row, $cat, $new_ad);
         } else {
             if ($par->get('notify_admin', '0') == 2 && $id == 0) {
                 DJClassifiedsNotify::notifyAdmin($row, $cat, $new_ad);
             }
         }
     }
     if ($id == 0 && $par->get('user_new_ad_email', '0') && ($user->id > 0 || $par->get('email_for_guest', '0') && $row->email)) {
         DJClassifiedsNotify::notifyNewAdvertUser($row, $cat);
     }
     $dispatcher->trigger('onAfterDJClassifiedsSaveAdvert', array(&$row, $is_new));
     if ($pay_redirect == 1) {
         $menu_uads_itemid = $menus->getItems('link', 'index.php?option=com_djclassifieds&view=useritems', 1);
         $redirect = 'index.php?option=com_djclassifieds&view=payment&id=' . $row->id;
         if ($menu_uads_itemid) {
             $redirect .= '&Itemid=' . $menu_uads_itemid->id;
         }
         //$redirect= 'index.php?option=com_djclassifieds&view=payment&id='.$row->id.$itemid;
         if ($row->id) {
             $message = JTExt::_('COM_DJCLASSIFIEDS_AD_SAVED_SUCCESSFULLY_CHOOSE_PAYMENT');
         } else {
             $message = JTExt::_('COM_DJCLASSIFIEDS_AD_ADDED_SUCCESSFULLY_CHOOSE_PAYMENT');
         }
     }
     if (!$redirect) {
         //$redirect= 'index.php?option=com_djclassifieds&view=item&cid='.$row->cat_id.'&id='.$row->id.$itemid;
         $redirect = DJClassifiedsSEO::getItemRoute($row->id . ':' . $row->alias, $row->cat_id . ':' . $cat->alias);
     }
     $redirect = JRoute::_($redirect, false);
     $app->redirect($redirect, $message);
 }
Example #7
0
 public function save()
 {
     $app = JFactory::getApplication();
     $model = $this->getModel('category');
     $row = JTable::getInstance('Categories', 'DJClassifiedsTable');
     $par = JComponentHelper::getParams('com_djclassifieds');
     $db = JFactory::getDBO();
     $row->bind(JRequest::get('post'));
     $icon_url = $row->icon_url;
     $row->description = JRequest::getVar('description', '', 'post', 'string', JREQUEST_ALLOWRAW);
     if ($row->alias) {
         $row->alias = DJClassifiedsSEO::getAliasName($row->alias);
     } else {
         $row->alias = DJClassifiedsSEO::getAliasName($row->name);
     }
     $del_icon_id = JRequest::getInt('del_icon_id', 0);
     $del_icon_path = JRequest::getVar('del_icon_path', '');
     $del_icon_name = JRequest::getVar('del_icon_name', '');
     $del_icon_ext = JRequest::getVar('del_icon_ext', '');
     if (JRequest::getVar('del_icon', '0', '', 'int')) {
         if ($del_icon_path && $del_icon_name && $del_icon_ext) {
             $path_to_delete = JPATH_SITE . $del_icon_path . $del_icon_name;
             if (JFile::exists($path_to_delete . '.' . $del_icon_ext)) {
                 JFile::delete($path_to_delete . '.' . $del_icon_ext);
             }
             if (JFile::exists($path_to_delete . '_ths.' . $del_icon_ext)) {
                 JFile::delete($path_to_delete . '_ths.' . $del_icon_ext);
             }
             $query = "DELETE FROM #__djcf_images WHERE type='category' AND item_id=" . $row->id . " AND id=" . $del_icon_id . " ";
             $db->setQuery($query);
             $db->query();
         }
     }
     $row->price = $row->price * 100;
     //echo '<pre>';print_r($row);die();
     if (!$row->ordering) {
         $query = "SELECT ordering FROM #__djcf_categories WHERE parent_id = " . $row->parent_id . " ORDER BY ordering DESC LIMIT 1";
         $db = JFactory::getDBO();
         $db->setQuery($query);
         $order = $db->loadObject();
         $row->ordering = $order->ordering + 1;
     }
     if (!$row->store()) {
         echo $row->getError();
         exit;
     }
     $new_icon = $_FILES['icon'];
     if (substr($new_icon['type'], 0, 5) == "image") {
         $path_to_delete = JPATH_SITE . $del_icon_path . $del_icon_name;
         if (JFile::exists($path_to_delete . '.' . $del_icon_ext)) {
             JFile::delete($path_to_delete . '.' . $del_icon_ext);
         }
         if (JFile::exists($path_to_delete . '_ths.' . $del_icon_ext)) {
             JFile::delete($path_to_delete . '_ths.' . $del_icon_ext);
         }
         $query = "DELETE FROM #__djcf_images WHERE type='category' AND item_id=" . $row->id . " AND id=" . $del_icon_id . " ";
         $db->setQuery($query);
         $db->query();
         $last_id = $row->id;
         $lang = JFactory::getLanguage();
         $icon_name = str_ireplace(' ', '_', $new_icon['name']);
         $icon_name = $lang->transliterate($icon_name);
         $icon_name = strtolower($icon_name);
         $icon_name = JFile::makeSafe($icon_name);
         $icon_name = $last_id . '_' . $icon_name;
         $icon_url = $icon_name;
         $path = JPATH_SITE . "/components/com_djclassifieds/images/category/" . $icon_name;
         move_uploaded_file($new_icon['tmp_name'], $path);
         $nw = $par->get('catth_width', -1);
         $nh = $par->get('catth_height', -1);
         $name_parts = pathinfo($path);
         $img_name = $name_parts['filename'];
         $img_ext = $name_parts['extension'];
         $new_path = JPATH_SITE . "/components/com_djclassifieds/images/category/";
         //DJClassifiedsImage::makeThumb($path, $nw, $nh, 'ths');
         DJClassifiedsImage::makeThumb($path, $new_path . $img_name . '_ths.' . $img_ext, $nw, $nh);
         $query = "INSERT INTO #__djcf_images(`item_id`,`type`,`name`,`ext`,`path`,`caption`,`ordering`) VALUES ";
         $query .= "('" . $row->id . "','category','" . $img_name . "','" . $img_ext . "','/components/com_djclassifieds/images/category/','','1'); ";
         $db->setQuery($query);
         $db->query();
     }
     $db = JFactory::getDBO();
     $query = "DELETE FROM #__djcf_categories_groups WHERE cat_id= " . $row->id . " ";
     $db->setQuery($query);
     $db->query();
     if (isset($_POST['cat_groups'])) {
         $query = "INSERT INTO #__djcf_categories_groups(`cat_id`,`group_id`) VALUES ";
         for ($i = 0; $i < count($_POST['cat_groups']); $i++) {
             $group_id = $_POST['cat_groups'][$i];
             $query .= "('" . $row->id . "','" . $group_id . "'), ";
         }
         $query = substr($query, 0, -2) . ';';
         $db->setQuery($query);
         $db->query();
     }
     switch (JRequest::getVar('task')) {
         case 'apply':
             $link = 'index.php?option=com_djclassifieds&task=category.edit&id=' . $row->id;
             $msg = JText::_('COM_DJCLASSIFIEDS_CATEGORY_SAVED');
             break;
         case 'save2new':
             $link = 'index.php?option=com_djclassifieds&task=category.add';
             $msg = JText::_('COM_DJCLASSIFIEDS_CATEGORY_SAVED');
             break;
         case 'saveItem':
         default:
             $link = 'index.php?option=com_djclassifieds&view=categories';
             $msg = JText::_('COM_DJCLASSIFIEDS_CATEGORY_SAVED');
             break;
     }
     $app->redirect($link, $msg);
 }
Example #8
0
 function regenerateAliases()
 {
     $app = JFactory::getApplication();
     $par = JComponentHelper::getParams('com_djclassifieds');
     $db = JFactory::getDBO();
     $query = "SELECT * FROM #__djcf_categories";
     $db->setQuery($query);
     $cats = $db->loadObjectList();
     foreach ($cats as $c) {
         $alias = DJClassifiedsSEO::getAliasName($c->name);
         $query = "UPDATE #__djcf_categories SET alias='" . $alias . "' WHERE id=" . $c->id;
         $db->setQuery($query);
         $db->query();
     }
     $redirect = 'index.php?option=com_djclassifieds&view=categories';
     $app->redirect($redirect, JText::_('COM_DJCLASSIFIEDS_ALIASES_RECREATED'));
 }
 public function save()
 {
     $app = JFactory::getApplication();
     $model = $this->getModel('item');
     $row = JTable::getInstance('Items', 'DJClassifiedsTable');
     $par = JComponentHelper::getParams('com_djclassifieds');
     $db = JFactory::getDBO();
     $lang = JFactory::getLanguage();
     $dispatcher = JDispatcher::getInstance();
     $row->bind(JRequest::get('post'));
     $row->description = JRequest::getVar('description', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $row->intro_desc = JRequest::getVar('intro_desc', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $row->contact = nl2br(JRequest::getVar('contact', '', 'post', 'string'));
     if ($row->alias) {
         $row->alias = DJClassifiedsSEO::getAliasName($row->alias);
     } else {
         $row->alias = DJClassifiedsSEO::getAliasName($row->name);
     }
     $row->image_url = '';
     //$exp_date = explode('-', $_POST['date_expir']);
     //$exp_time = explode(':', $_POST['time_expir']);
     //$row->date_exp = mktime($exp_time[0],$exp_time[1],0,$exp_date[1],$exp_date[2],$exp_date[0]);
     $row->date_exp = $_POST['date_expir'] . ' ' . $_POST['time_expir'] . ':00';
     $is_new = 1;
     if ($row->id > 0) {
         $old_date_exp = JRequest::getVar('date_exp_old', '');
         if ($old_date_exp != $row->date_exp) {
             $row->notify = 0;
         }
         $is_new = 0;
     }
     if ($row->id == 0) {
         $row->exp_days = ceil((strtotime($row->date_exp) - time()) / (60 * 60 * 24));
     }
     if ($row->user_id == 0 && $row->id == 0) {
         $user = JFactory::getUser();
         $row->user_id = $user->id;
         $row->ip_address = $_SERVER['REMOTE_ADDR'];
     }
     $row->region_id = end($_POST['regions']);
     if (!$row->region_id) {
         $row->region_id = $_POST['regions'][count($_POST['regions']) - 2];
         if (!reset($_POST['regions'])) {
             $row->region_id = 0;
         }
     }
     if ($row->id > 0) {
         $query = "DELETE FROM #__djcf_fields_values WHERE item_id= " . $row->id . " ";
         $db->setQuery($query);
         $db->query();
         if ($row->payed == 1) {
             $row->pay_type = '';
             $query = "UPDATE #__djcf_payments SET status='Completed' WHERE item_id= " . $row->id . " AND type=0 ";
             $db->setQuery($query);
             $db->query();
         }
     }
     $row->promotions = '';
     $query = "SELECT p.* FROM #__djcf_promotions p ORDER BY p.id ";
     $db->setQuery($query);
     $promotions = $db->loadObjectList();
     foreach ($promotions as $prom) {
         if (JRequest::getVar($prom->name, '0')) {
             $row->promotions .= $prom->name . ',';
         }
     }
     if ($row->promotions) {
         $row->promotions = substr($row->promotions, 0, -1);
     }
     if (strstr($row->promotions, 'p_first')) {
         $row->special = 1;
     } else {
         $row->special = 0;
     }
     if (($row->region_id || $row->address) && ($row->latitude == '0.000000000000000' && $row->longitude == '0.000000000000000' || !$row->latitude && !$row->longitude)) {
         $address = '';
         if ($row->region_id) {
             $reg_path = DJClassifiedsRegion::getParentPath($row->region_id);
             for ($r = count($reg_path) - 1; $r >= 0; $r--) {
                 if ($reg_path[$r]->country) {
                     $address = $reg_path[$r]->name;
                 }
                 if ($reg_path[$r]->city) {
                     if ($address) {
                         $address .= ', ';
                     }
                     $address .= $reg_path[$r]->name;
                 }
             }
         }
         if ($address) {
             $address .= ', ';
         }
         $address .= $row->address;
         if ($row->post_code) {
             $address .= ', ' . $row->post_code;
         }
         $loc_coord = DJClassifiedsGeocode::getLocation($address);
         if (is_array($loc_coord)) {
             $row->latitude = $loc_coord['lat'];
             $row->longitude = $loc_coord['lng'];
         }
     }
     //echo '<pre>';print_r($_POST);print_r($row);echo '</pre>';die();
     if (!$row->store()) {
         echo $row->getError();
         exit;
     }
     if ($is_new) {
         $query = "UPDATE #__djcf_items SET date_sort=date_start WHERE id=" . $row->id . " ";
         $db->setQuery($query);
         $db->query();
     }
     $item_images = '';
     if (!$is_new) {
         $query = "SELECT * FROM #__djcf_images WHERE item_id=" . $row->id . " AND type='item' ";
         $db->setQuery($query);
         $item_images = $db->loadObjectList('id');
     }
     $img_ids = JRequest::getVar('img_id', array(), 'post', 'array');
     $img_captions = JRequest::getVar('img_caption', array(), 'post', 'array');
     $img_images = JRequest::getVar('img_image', array(), 'post', 'array');
     $img_id_to_del = '';
     foreach ($item_images as $item_img) {
         $img_to_del = 1;
         foreach ($img_ids as $img_id) {
             if ($item_img->id == $img_id) {
                 $img_to_del = 0;
                 break;
             }
         }
         if ($img_to_del) {
             $path_to_delete = JPATH_ROOT . $item_img->path . $item_img->name;
             if (JFile::exists($path_to_delete . '.' . $item_img->ext)) {
                 JFile::delete($path_to_delete . '.' . $item_img->ext);
             }
             if (JFile::exists($path_to_delete . '_ths.' . $item_img->ext)) {
                 JFile::delete($path_to_delete . '_ths.' . $item_img->ext);
             }
             if (JFile::exists($path_to_delete . '_thm.' . $item_img->ext)) {
                 JFile::delete($path_to_delete . '_thm.' . $item_img->ext);
             }
             if (JFile::exists($path_to_delete . '_thb.' . $item_img->ext)) {
                 JFile::delete($path_to_delete . '_thb.' . $item_img->ext);
             }
             $img_id_to_del .= $item_img->id . ',';
         }
     }
     if ($img_id_to_del) {
         $query = "DELETE FROM #__djcf_images WHERE item_id=" . $row->id . " AND type='item' AND ID IN (" . substr($img_id_to_del, 0, -1) . ") ";
         $db->setQuery($query);
         $db->query();
     }
     $last_id = $row->id;
     $nw = (int) $par->get('th_width', -1);
     $nh = (int) $par->get('th_height', -1);
     $nws = (int) $par->get('smallth_width', -1);
     $nhs = (int) $par->get('smallth_height', -1);
     $nwm = (int) $par->get('middleth_width', -1);
     $nhm = (int) $par->get('middleth_height', -1);
     $nwb = (int) $par->get('bigth_width', -1);
     $nhb = (int) $par->get('bigth_height', -1);
     $img_ord = 1;
     $img_to_insert = 0;
     $query_img = "INSERT INTO #__djcf_images(`item_id`,`type`,`name`,`ext`,`path`,`caption`,`ordering`) VALUES ";
     $new_img_path = JPATH_SITE . "/components/com_djclassifieds/images/item/";
     for ($im = 0; $im < count($img_ids); $im++) {
         if ($img_ids[$im]) {
             if ($item_images[$img_ids[$im]]->ordering != $img_ord || $item_images[$img_ids[$im]]->caption != $img_captions[$im]) {
                 $query = "UPDATE #__djcf_images SET ordering='" . $img_ord . "', caption='" . $db->escape($img_captions[$im]) . "' WHERE item_id=" . $row->id . " AND type='item' AND id=" . $img_ids[$im] . " ";
                 $db->setQuery($query);
                 $db->query();
             }
         } else {
             $new_img_name = explode(';', $img_images[$im]);
             if (is_array($new_img_name)) {
                 $new_img_name_u = JPATH_ROOT . '/tmp/djupload/' . $new_img_name[0];
                 if (JFile::exists($new_img_name_u)) {
                     if (getimagesize($new_img_name_u)) {
                         $new_img_n = $last_id . '_' . str_ireplace(' ', '_', $new_img_name[1]);
                         $new_img_n = $lang->transliterate($new_img_n);
                         $new_img_n = strtolower($new_img_n);
                         $new_img_n = JFile::makeSafe($new_img_n);
                         $new_path_check = $new_img_path . $new_img_n;
                         $nimg = 0;
                         while (JFile::exists($new_path_check)) {
                             $nimg++;
                             $new_img_n = $last_id . '_' . $nimg . '_' . str_ireplace(' ', '_', $new_img_name[1]);
                             $new_img_n = $lang->transliterate($new_img_n);
                             $new_img_n = strtolower($new_img_n);
                             $new_img_n = JFile::makeSafe($new_img_n);
                             $new_path_check = $new_img_path . $new_img_n;
                         }
                         rename($new_img_name_u, $new_img_path . $new_img_n);
                         $name_parts = pathinfo($new_img_n);
                         $img_name = $name_parts['filename'];
                         $img_ext = $name_parts['extension'];
                         DJClassifiedsImage::makeThumb($new_img_path . $new_img_n, $new_img_path . $img_name . '_ths.' . $img_ext, $nws, $nhs);
                         DJClassifiedsImage::makeThumb($new_img_path . $new_img_n, $new_img_path . $img_name . '_thm.' . $img_ext, $nwm, $nhm);
                         DJClassifiedsImage::makeThumb($new_img_path . $new_img_n, $new_img_path . $img_name . '_thb.' . $img_ext, $nwb, $nhb);
                         $query_img .= "('" . $row->id . "','item','" . $img_name . "','" . $img_ext . "','/components/com_djclassifieds/images/item/','" . $db->escape($img_captions[$im]) . "','" . $img_ord . "'), ";
                         $img_to_insert++;
                         if ($par->get('store_org_img', '1') == 0) {
                             JFile::delete($new_img_path . $new_img_n);
                         }
                     }
                 }
             }
         }
         $img_ord++;
     }
     if ($img_to_insert) {
         $query_img = substr($query_img, 0, -2) . ';';
         $db->setQuery($query_img);
         $db->query();
     }
     //if($row->cat_id){
     $query = "SELECT f.* FROM #__djcf_fields f " . "LEFT JOIN #__djcf_fields_xref fx ON f.id=fx.field_id " . "WHERE (fx.cat_id  = " . $row->cat_id . " OR f.source=1) ";
     $db->setQuery($query);
     $fields_list = $db->loadObjectList();
     //echo '<pre>'; print_r($db);print_r($fields_list);die();
     $ins = 0;
     if (count($fields_list) > 0) {
         $query = "INSERT INTO #__djcf_fields_values(`field_id`,`item_id`,`value`,`value_date`) VALUES ";
         foreach ($fields_list as $fl) {
             if ($fl->type == 'checkbox') {
                 if (isset($_POST[$fl->name])) {
                     $field_v = $_POST[$fl->name];
                     $f_value = ';';
                     for ($fv = 0; $fv < count($field_v); $fv++) {
                         $f_value .= $field_v[$fv] . ';';
                     }
                     $query .= "('" . $fl->id . "','" . $row->id . "','" . $db->escape($f_value) . "',''), ";
                     $ins++;
                 }
             } else {
                 if ($fl->type == 'date') {
                     if (isset($_POST[$fl->name])) {
                         $f_var = JRequest::getVar($fl->name, '', '', 'string');
                         $query .= "('" . $fl->id . "','" . $row->id . "','','" . $db->escape($f_var) . "'), ";
                         $ins++;
                     }
                 } else {
                     if (isset($_POST[$fl->name])) {
                         $f_var = JRequest::getVar($fl->name, '', '', 'string', JREQUEST_ALLOWRAW);
                         $query .= "('" . $fl->id . "','" . $row->id . "','" . $db->escape($f_var) . "',''), ";
                         $ins++;
                     }
                 }
             }
         }
     }
     //print_r($query);die();
     if ($ins) {
         $query = substr($query, 0, -2) . ';';
         $db->setQuery($query);
         $db->query();
     }
     //}
     JPluginHelper::importPlugin('djclassifieds');
     $dispatcher->trigger('onAfterDJClassifiedsSaveAdvert', array($row, $is_new));
     switch (JRequest::getVar('task')) {
         case 'apply':
             $link = 'index.php?option=com_djclassifieds&task=item.edit&id=' . $row->id;
             $msg = JText::_('COM_DJCLASSIFIEDS_ITEM_SAVED');
             break;
         case 'save2new':
             $link = 'index.php?option=com_djclassifieds&task=item.add';
             $msg = JText::_('COM_DJCLASSIFIEDS_ITEM_SAVED');
             break;
         case 'saveItem':
         default:
             $link = 'index.php?option=com_djclassifieds&view=items';
             $msg = JText::_('COM_DJCLASSIFIEDS_ITEM_SAVED');
             break;
     }
     $app->redirect($link, $msg);
 }
 function removeFavourite()
 {
     $app = JFactory::getApplication();
     $id = JRequest::getInt('id', 0);
     $cid = JRequest::getVar('cid', 0, '', 'int');
     $db = JFactory::getDBO();
     $user = JFactory::getUser();
     $itemid = JRequest::getVar('Itemid');
     $par = JComponentHelper::getParams('com_djclassifieds');
     $query = "SELECT i.id, i.name, i.alias,i.cat_id,c.name as c_name, c.alias as c_alias FROM #__djcf_items i " . "LEFT JOIN #__djcf_categories c ON c.id=i.cat_id " . "WHERE i.id = " . $id;
     $db->setQuery($query);
     $item = $db->loadObject();
     if (!$item->alias) {
         $item->alias = DJClassifiedsSEO::getAliasName($item->name);
     }
     if (!$item->c_alias) {
         $item->c_alias = DJClassifiedsSEO::getAliasName($item->c_name);
     }
     $link = DJClassifiedsSEO::getItemRoute($item->id . ':' . $item->alias, $item->cat_id . ':' . $item->c_alias);
     $m_type = '';
     if ($par->get('favourite', '1')) {
         if ($user->id > 0) {
             $query = "DELETE FROM #__djcf_favourites WHERE item_id=" . $id . " AND user_id=" . $user->id . " ";
             $db->setQuery($query);
             $db->query();
             $msg = JText::_('COM_DJCLASSIFIEDS_AD_REMOVED_FROM_FAVOURITES');
         } else {
             $msg = JText::_('COM_DJCLASSIFIEDS_PLEASE_LOGIN');
             $m_type = 'error';
         }
     } else {
         $msg = JText::_('COM_DJCLASSIFIEDS_FUNCTION_NOT_AVAILABLE');
         $m_type = 'error';
     }
     //$link = 'index.php?option=com_djclassifieds&view=item&cid='.$cid.'&id='.$id.'&Itemid='.$itemid;
     $link = JRoute::_($link);
     $app->redirect($link, $msg, $m_type);
 }
Example #11
0
 function delBid()
 {
     header("Content-type: text/html; charset=utf-8");
     $app = JFactory::getApplication();
     $id = JRequest::getInt('id', 0);
     $cid = JRequest::getInt('cid', 0);
     $bid = JRequest::getFloat('bid', 0);
     $db = JFactory::getDBO();
     $user = JFactory::getUser();
     $itemid = JRequest::getVar('Itemid');
     $par = JComponentHelper::getParams('com_djclassifieds');
     $m_type = '';
     $query = "SELECT i.*, c.name as c_name, c.alias as c_alias FROM #__djcf_items i " . "LEFT JOIN #__djcf_categories c ON c.id=i.cat_id " . "WHERE i.id = " . $id . " ";
     $db->setQuery($query);
     $item = $db->loadObject();
     if (!$item->alias) {
         $item->alias = DJClassifiedsSEO::getAliasName($item->name);
     }
     if (!$item->c_alias) {
         $item->c_alias = DJClassifiedsSEO::getAliasName($item->c_name);
     }
     $link = DJClassifiedsSEO::getItemRoute($item->id . ':' . $item->alias, $item->cat_id . ':' . $item->c_alias);
     if ($user->id > 0) {
         if ($item) {
             if ($item->user_id == $user->id && $item->user_id > 0) {
                 $query = "DELETE FROM #__djcf_auctions WHERE item_id = " . $item->id . " AND id=" . $bid;
                 $db->setQuery($query);
                 $db->query();
                 $price_start = $item->price_start;
                 $query = "SELECT a.* FROM #__djcf_auctions a " . " WHERE a.item_id=" . $item->id . " ORDER BY a.date DESC LIMIT 1";
                 $db->setQuery($query);
                 $last_bid = $db->loadObject();
                 if ($last_bid) {
                     $price_start = $last_bid->price;
                 }
                 $query = "UPDATE #__djcf_items SET price='" . $price_start . "' " . " WHERE id=" . $item->id;
                 $db->setQuery($query);
                 $db->query();
                 $msg = JText::_('COM_DJCLASSIFIEDS_BID_DELETED');
             } else {
                 $msg = JText::_('COM_DJCLASSIFIEDS_WRONG_AD');
                 $m_type = 'error';
             }
         } else {
             $msg = JText::_('COM_DJCLASSIFIEDS_WRONG_AD');
             $m_type = 'error';
         }
     } else {
         $msg = JText::_('COM_DJCLASSIFIEDS_PLEASE_LOGIN');
         $m_type = 'error';
     }
     $link = JRoute::_($link);
     $app->redirect($link, $msg, $m_type);
     die('aaaa');
 }
Example #12
0
 public static function getCategoriesSortParent($p = '0', $ord = 'ord', $ord_dir = 'ASC')
 {
     $user = JFactory::getUser();
     if (!self::$_categories_sparent) {
         self::$_categories_sparent = array();
     }
     if (isset(self::$_categories_sparent[$p . '_' . $ord])) {
         return self::$_categories_sparent[$p . '_' . $ord];
     }
     if ($p) {
         $pub = 'WHERE c.published=1 ';
         $groups_acl = implode(',', $user->getAuthorisedViewLevels());
         $access_view = " AND c.access_view IN (" . $groups_acl . ") ";
     } else {
         $pub = '';
         $access_view = '';
     }
     if ($ord == 'name') {
         $order = 'c.name';
     } else {
         if ($ord == 'id') {
             $order = 'c.id';
         } else {
             if ($ord == 'price') {
                 $order = 'c.price';
             } else {
                 if ($ord == 'pub') {
                     $order = 'c.published';
                 } else {
                     $order = 'c.ordering';
                 }
             }
         }
     }
     $db = JFactory::getDBO();
     $date_now = date("Y-m-d H:i:s");
     $query = "SELECT c.*, cc.name as parent_name,IFNULL(i.items_count,0) items_count FROM #__djcf_categories c " . "LEFT JOIN #__djcf_categories cc ON c.parent_id=cc.id " . "LEFT JOIN (SELECT i.cat_id, count(i.id) as items_count " . "FROM #__djcf_items i WHERE i.published=1 AND i.date_exp > '" . $date_now . "' GROUP BY i.cat_id) i ON i.cat_id=c.id " . $pub . $access_view . "ORDER BY c.parent_id, " . $order . " " . $ord_dir;
     $db->setQuery($query);
     $allcategories = $db->loadObjectList();
     $categories = array();
     foreach ($allcategories as $cat) {
         if (!$cat->alias) {
             $cat->alias = DJClassifiedsSEO::getAliasName($cat->name);
         }
         if (!isset($categories[$cat->parent_id])) {
             $categories[$cat->parent_id] = array();
         }
         $categories[$cat->parent_id][] = $cat;
     }
     //echo '<pre>';print_r($db);print_r($allcategories);die();
     self::$_categories_sparent[$p . '_' . $ord] = $categories;
     return self::$_categories_sparent[$p . '_' . $ord];
 }
Example #13
0
					</div>
					<div class="djcf_prow_desc_row djcf_prow_date">
						<span class="djcf_prow_desc_label" ><?php 
    echo JText::_("COM_DJCLASSIFIEDS_ORDER_DATE");
    ?>
:</span>
						<span class="djcf_prow_desc_value" ><?php 
    echo DJClassifiedsTheme::formatDate(strtotime($order->date));
    ?>
</span>
						<div class="clear_both"></div>
					</div>
				</div>	
				<div class="item_col"> 
					<?php 
    $uid_slug = $order->user_id . ':' . DJClassifiedsSEO::getAliasName($order->username);
    echo '<a class="profile_name" href="index.php?option=com_djclassifieds&view=profile&uid=' . $uid_slug . DJClassifiedsSEO::getMainAdvertsItemid() . '">' . $order->username;
    if ($order->i_user_items_count) {
        echo ' <span>(' . $order->i_user_items_count . ')</span>';
    }
    echo '</a>';
    echo '<div class="profile_email_outer"><a class="profile_email button" href="mailto:' . $order->email . '">' . JText::_('COM_DJCLASSIFIEDS_CONTACT_SELLER') . '</a></div>';
    ?>
						
				</div>
				<?php 
    echo '</div>';
}
?>
	</div>
	<div class="pagination">