コード例 #1
0
ファイル: controller.php プロジェクト: politik86/test2
 function cronNotifications()
 {
     $par = JComponentHelper::getParams('com_djclassifieds');
     $notify_days = $par->get('notify_days', '0');
     if ($notify_days > 0 && $par->get('notify_days_trigger', '1') == 3) {
         DJClassifiedsNotify::notifyExpired(0, 0);
     }
     die('done');
 }
コード例 #2
0
ファイル: contact.php プロジェクト: kidaa30/lojinha
 function bidderMessage()
 {
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $db = JFactory::getDBO();
     $bid_id = JRequest::getInt('bid', 0);
     $id = JRequest::getInt('id', 0);
     $db = JFactory::getDBO();
     $m_title = JRequest::getVar('c_title', 0);
     $m_message = JRequest::getVar('c_message', 0);
     $e_mesage = '';
     $e_type = '';
     $ms = 0;
     if ($user->id > 0) {
         $query = "SELECT i.*, c.name as c_name,c.alias as c_alias, u.name as u_name, u.email as u_email FROM #__djcf_items i, #__djcf_categories c, #__users u  " . "WHERE c.id=i.cat_id AND u.id=i.user_id AND i.id= " . $id . " LIMIT 1 ";
         $db->setQuery($query);
         $item = $db->loadObject();
         //echo '<pre>';print_r($db);print_r($item);die();
         if ($item->user_id == $user->id) {
             $query = "SELECT a.*, u.email FROM #__djcf_auctions a, #__users u " . "WHERE a.user_id=u.id AND a.id= " . $bid_id . " AND a.item_id= " . $id . " LIMIT 1 ";
             $db->setQuery($query);
             $bid = $db->loadObject();
             if ($bid) {
                 $bidder = JFactory::getUser($bid->user_id);
                 DJClassifiedsNotify::messageAuthorToBidder($id, $bidder, $item, $bid->price, $user, $m_title, $m_message);
                 $ms = 1;
             } else {
                 $e_mesage = JText::_('COM_DJCLASSIFIEDS_WRONG_BID');
                 $e_type = 'error';
             }
         } else {
             $e_mesage = JText::_('COM_DJCLASSIFIEDS_WRONG_AD');
             $e_type = 'error';
         }
     } else {
         $e_mesage = JText::_('COM_DJCLASSIFIEDS_PLEASE_LOGIN');
         $e_type = 'error';
     }
     $redirect = "index.php?option=com_djclassifieds&view=contact&id=" . $id . "&bid=" . $bid->id . "&ms=" . $ms . "&tmpl=component";
     $redirect = JRoute::_($redirect, false);
     $app->redirect($redirect, $e_mesage);
 }
コード例 #3
0
ファイル: view.html.php プロジェクト: politik86/test2
 function display($tpl = null)
 {
     $par = JComponentHelper::getParams('com_djclassifieds');
     $user = JFactory::getUser();
     $notify_days = $par->get('notify_days', '0');
     if ($notify_days > 0 && $par->get('notify_days_trigger', '1') == 1) {
         DJClassifiedsNotify::notifyExpired();
     }
     if (class_exists('JHtmlSidebar')) {
         $this->sidebar = JHtmlSidebar::render();
     }
     JToolBarHelper::title('DJ-Classifieds');
     if ($user->authorise('core.admin', 'com_djclassifieds')) {
         JToolBarHelper::preferences('com_djclassifieds', 450, 800);
     }
     $model = $this->getModel();
     $model->checkCFImages();
     $version = new JVersion();
     if (version_compare($version->getShortVersion(), '3.0.0', '<')) {
         $tpl = 'legacy';
     }
     parent::display($tpl);
 }
コード例 #4
0
ファイル: djnotify.php プロジェクト: kidaa30/lojinha
 public static function notifyAuctions()
 {
     $app = JFactory::getApplication();
     $config = JFactory::getConfig();
     $par = JComponentHelper::getParams('com_djclassifieds');
     $db = JFactory::getDBO();
     $date_now = date("Y-m-d H:i:s");
     $query = "SELECT i.*, c.name as c_name, c.alias as c_alias,u.name as u_name,u.email as u_email, u.username as u_username " . "FROM #__djcf_items i " . "LEFT JOIN #__djcf_categories c ON c.id=i.cat_id " . "LEFT JOIN #__users u ON u.id=i.user_id " . "WHERE i.notify<2 AND i.date_exp > '" . $date_now . "' AND i.auction=1 ";
     $db->setQuery($query);
     $items = $db->loadObjectList();
     if ($items) {
         foreach ($items as $item) {
             $query = "SELECT a.*, u.name, u.username, u.email FROM #__djcf_auctions a " . "LEFT JOIN #__users u ON u.id=a.user_id " . "WHERE a.item_id=" . $item->id . " " . "ORDER BY a.price DESC ";
             $db->setQuery($query);
             $bids = $db->loadObjectList();
             $win = 0;
             $win_id = 0;
             if (count($bids)) {
                 foreach ($bids as $b => $bid) {
                     $bidder = new stdClass();
                     $bidder->id = $bid->user_id;
                     $bidder->name = $bid->name;
                     $bidder->username = $bid->username;
                     $bidder->email = $bid->email;
                     if ($b > 0) {
                         if ($win_id != $bid->user_id) {
                             DJClassifiedsNotify::notifyAuctionsWinBidder($item->id, $bidder, $bid->price, 15);
                         }
                     } else {
                         if ($bid->price >= $item->price_reserve) {
                             DJClassifiedsNotify::notifyAuctionsWinBidder($item->id, $bidder, $bid->price);
                             $win = 1;
                         } else {
                             DJClassifiedsNotify::notifyAuctionsWinBidder($item->id, $bidder, $bid->price, 14);
                         }
                         $win_id = $bid->user_id;
                     }
                 }
                 if ($win) {
                     self::notifyAuctionsWinAuthor($item->id, $bidder, $bid->price);
                 } else {
                     self::notifyAuctionsWinAuthor($item->id, $bidder, $bid->price, 13);
                 }
             } else {
                 self::notifyAuctionsWinAuthor($item->id, '', '', 12);
             }
             $query = "UPDATE `#__djcf_items` SET notify=2 WHERE id = " . $item->id . " ";
             $db->setQuery($query);
             $db->query();
         }
     }
     return null;
 }
コード例 #5
0
ファイル: items.php プロジェクト: kidaa30/lojinha
 public function publish()
 {
     $app = JFactory::getApplication();
     $data = array('publish' => 1, 'unpublish' => 0, 'archive' => 2, 'trash' => -2, 'report' => -3);
     $task = $this->getTask();
     $new_status = JArrayHelper::getValue($data, $task, 0, 'int');
     $cid = JRequest::getVar('cid', array(), '', 'array');
     foreach ($cid as $id) {
         DJClassifiedsNotify::notifyUserPublication($id, $new_status);
     }
     $publish = parent::publish();
     return $publish;
 }
コード例 #6
0
ファイル: djcfBankTransfer.php プロジェクト: kidaa30/lojinha
 function process($id)
 {
     $db = JFactory::getDBO();
     $app = JFactory::getApplication();
     $Itemid = JRequest::getInt("Itemid", '0');
     $par = JComponentHelper::getParams('com_djclassifieds');
     $user = JFactory::getUser();
     $config = JFactory::getConfig();
     $ptype = JRequest::getVar('ptype');
     $type = JRequest::getVar('type', '');
     $row = JTable::getInstance('Payments', 'DJClassifiedsTable');
     if ($type == 'prom_top') {
         $query = "SELECT i.* FROM #__djcf_items i " . "WHERE i.id=" . $id . " LIMIT 1";
         $db->setQuery($query);
         $item = $db->loadObject();
         if (!isset($item)) {
             $message = JText::_('COM_DJCLASSIFIEDS_WRONG_AD');
             $redirect = "index.php?option=com_djclassifieds&view=items&cid=0";
         }
         $row->item_id = $id;
         $row->user_id = $user->id;
         $row->method = $ptype;
         $row->status = 'Start';
         $row->ip_address = $_SERVER['REMOTE_ADDR'];
         $row->price = $par->get('promotion_move_top_price', 0);
         $row->type = 2;
         $row->store();
         $amount = $par->get('promotion_move_top_price', 0);
         $itemname = $item->name;
         $item_id = $row->id;
         $item_cid = '&cid=' . $item->cat_id;
     } else {
         if ($type == 'points') {
             $query = "SELECT p.* FROM #__djcf_points p " . "WHERE p.id=" . $id . " LIMIT 1";
             $db->setQuery($query);
             $points = $db->loadObject();
             if (!isset($item)) {
                 $message = JText::_('COM_DJCLASSIFIEDS_WRONG_POINTS_PACKAGE');
                 $redirect = "index.php?option=com_djclassifieds&view=items&cid=0";
             }
             $row->item_id = $id;
             $row->user_id = $user->id;
             $row->method = $ptype;
             $row->status = 'Start';
             $row->ip_address = $_SERVER['REMOTE_ADDR'];
             $row->price = $points->price;
             $row->type = 1;
             $row->store();
             $amount = $points->price;
             $itemname = $points->name;
             $item_id = $row->id;
             $item_cid = '';
         } else {
             if ($type == 'plan') {
                 $query = "SELECT p.* FROM #__djcf_plans p " . "WHERE p.id=" . $id . " LIMIT 1";
                 $db->setQuery($query);
                 $plan = $db->loadObject();
                 if (!isset($plan)) {
                     $message = JText::_('COM_DJCLASSIFIEDS_SUBSCRIPTION_PLAN');
                     $redirect = "index.php?option=com_djclassifieds&view=plans";
                 }
                 $row->item_id = $id;
                 $row->user_id = $user->id;
                 $row->method = $ptype;
                 $row->status = 'Start';
                 $row->ip_address = $_SERVER['REMOTE_ADDR'];
                 $row->price = $plan->price;
                 $row->type = 3;
                 $row->store();
                 $amount = $plan->price;
                 $itemname = $plan->name;
                 $item_id = $row->id;
                 $item_cid = '';
             } else {
                 $query = "SELECT i.*, c.price as c_price, c.alias as c_alias FROM #__djcf_items i " . "LEFT JOIN #__djcf_categories c ON c.id=i.cat_id " . "WHERE i.id=" . $id . " LIMIT 1";
                 $db->setQuery($query);
                 $item = $db->loadObject();
                 if (!isset($item)) {
                     $message = JText::_('COM_DJCLASSIFIEDS_WRONG_AD');
                     $redirect = "index.php?option=com_djclassifieds&view=items&cid=0";
                 }
                 $amount = 0;
                 if (strstr($item->pay_type, 'cat')) {
                     $amount += $item->c_price / 100;
                 }
                 $query = "SELECT * FROM #__djcf_days d " . "WHERE d.days=" . $item->exp_days . " LIMIT 1";
                 $db->setQuery($query);
                 $day = $db->loadObject();
                 if (strstr($item->pay_type, 'duration_renew')) {
                     $amount += $day->price_renew;
                 } else {
                     if (strstr($item->pay_type, 'duration')) {
                         $amount += $day->price;
                     }
                 }
                 if (strstr($item->pay_type, 'extra_img_renew')) {
                     if ($day->img_price_default) {
                         $amount += $par->get('img_price_renew', '0') * $item->extra_images_to_pay;
                     } else {
                         $amount += $day->img_price_renew * $item->extra_images_to_pay;
                     }
                 } else {
                     if (strstr($item->pay_type, 'extra_img')) {
                         if ($day->img_price_default) {
                             $amount += $par->get('img_price', '0') * $item->extra_images_to_pay;
                         } else {
                             $amount += $day->img_price * $item->extra_images_to_pay;
                         }
                     }
                 }
                 if (strstr($item->pay_type, 'extra_chars_renew')) {
                     if ($day->char_price_default) {
                         $amount += $par->get('desc_char_price_renew', '0') * $item->extra_chars_to_pay;
                     } else {
                         $amount += $day->char_price_renew * $item->extra_chars_to_pay;
                     }
                 } else {
                     if (strstr($item->pay_type, 'extra_chars')) {
                         if ($day->char_price_default) {
                             $amount += $par->get('desc_char_price', '0') * $item->extra_chars_to_pay;
                         } else {
                             $amount += $day->char_price * $item->extra_chars_to_pay;
                         }
                     }
                 }
                 $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 (strstr($item->pay_type, $prom->name)) {
                         $amount += $prom->price;
                     }
                 }
                 /*$query = 'DELETE FROM #__djcf_payments WHERE item_id= "'.$id.'" ';
                 		$db->setQuery($query);
                 		$db->query();
                 		
                 		
                 		$query = 'INSERT INTO #__djcf_payments ( item_id,user_id,method,  status)' .
                 				' VALUES ( "'.$id.'" ,"'.$user->id.'","'.$ptype.'" ,"Start" )'
                 				;
                 		$db->setQuery($query);
                 		$db->query();*/
                 $row->item_id = $id;
                 $row->user_id = $user->id;
                 $row->method = $ptype;
                 $row->status = 'Start';
                 $row->ip_address = $_SERVER['REMOTE_ADDR'];
                 $row->price = $amount;
                 $row->type = 0;
                 $row->store();
                 $itemname = $item->name;
                 $item_id = $row->id;
                 $item_cid = '&cid=' . $item->cat_id;
                 $item_slug = $item->id . ':' . $item->alias;
                 $cat_slug = $item->cat_id . ':' . $item->c_alias;
             }
         }
     }
     /*
     		$query ="SELECT i.*, c.price as c_price, c.alias as c_alias FROM #__djcf_items i "
        ."LEFT JOIN #__djcf_categories c ON c.id=i.cat_id "
        ."WHERE i.id=".$id." LIMIT 1";
     		$db->setQuery($query);
     		$item = $db->loadObject();
     		if(!isset($item)){
     $message = JText::_('COM_DJCLASSIFIEDS_WRONG_AD');
     $redirect="index.php?option=com_djclassifieds&view=items&cid=0";
     		}
     		
     $query = 'DELETE FROM #__djcf_payments WHERE item_id= "'.$id.'" ';
     $db->setQuery($query);
     $db->query();
     
     
     $query = 'INSERT INTO #__djcf_payments ( item_id,user_id,method,  status)' .
     		' VALUES ( "'.$id.'" ,"'.$user->id.'","'.$ptype.'" ,"Start" )'
     		;
     $db->setQuery($query);
     $db->query();
     
     		
     		$amount = 0;
     
     if(strstr($item->pay_type, 'cat')){			
     	$amount += $item->c_price/100; 
     }
     if(strstr($item->pay_type, 'duration_renew')){			
     	$query = "SELECT d.price_renew FROM #__djcf_days d "
     	."WHERE d.days=".$item->exp_days;
     	$db->setQuery($query);
     	$amount += $db->loadResult();
     }else if(strstr($item->pay_type, 'duration')){			
     	$query = "SELECT d.price FROM #__djcf_days d "
     	."WHERE d.days=".$item->exp_days;
     	$db->setQuery($query);
     	$amount += $db->loadResult();
     }
     
     $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(strstr($item->pay_type, $prom->name)){	
     		$amount += $prom->price; 
     	}	
     }	
     */
     if ($user->id) {
         /*$mailto = $user->email;			
         				$mailfrom = $app->getCfg( 'mailfrom' );			    
         				$fromname=$config->get('config.sitename').' - '.str_ireplace('administrator/', '', JURI::base());
         	
         				$subject = JText::_('PLG_DJCFBANKTRANSFER_PAYMENT_INFRORMATIONS').' '.$config->get('config.sitename');
         				$m_message = JText::_('PLG_DJCFBANKTRANSFER_PAYMENT_INFRORMATIONS').' '.$config->get('config.sitename')."<br /><br />";
         				
         				if($type=='points'){
         					$m_message .= JText::_('PLG_DJCFBANKTRANSFER_POINTS_PACKAGE').': '.$itemname."<br /><br />";
         				}else{
         					$m_message .= JText::_('PLG_DJCFBANKTRANSFER_PAYMENT_AD_NAME').': '.$itemname."<br /><br />";	
         				}
         				
         				$m_message .= JText::_('PLG_DJCFBANKTRANSFER_PAYMENT_PRICE_TO_PAY').': '.$amount.' '.$par->get('unit_price','')."<br /><br />";
         				$m_message .= JText::_('PLG_DJCFBANKTRANSFER_PAYMENT_PAY_INFORMATION').': <br /><br />'.JHTML::_('content.prepare',nl2br($this->params["pay_info"]))."<br /><br />";
         				
         				if($type==''){
         					$u = JURI::getInstance( JURI::base() );
         					$link=  $u->getHost().JRoute::_(DJClassifiedsSEO::getItemRoute($item_slug,$cat_slug));						
         					$m_message .=JText::_('PLG_DJCFBANKTRANSFER_PAYMENT_AD_LINK').': <a href="'.$link.'">'.$link.'</a><br /><br />';
         					$m_message .=JText::_('PLG_DJCFBANKTRANSFER_PAYMENT_AD_ID').': '.$id.'<br /><br />';				
         				}
         				$m_message .=JText::_('PLG_DJCFBANKTRANSFER_PAYMENT_ID').': '.$item_id;
         				
         				$mailer = JFactory::getMailer();
         				$mailer->sendMail($mailfrom, $fromname, $mailto, $subject, $m_message,$mode=1);*/
         $payment_info = array();
         $payment_info['id'] = $item_id;
         $payment_info['itemname'] = $itemname;
         $payment_info['amount'] = DJClassifiedsTheme::priceFormat($amount, $par->get('unit_price', ''));
         $payment_info['info'] = $this->params["pay_info"];
         DJClassifiedsNotify::notifyUserPayment($type, $id, $payment_info);
     }
     echo '<div id="dj-classifieds" class="clearfix">';
     echo '<table width="98%" cellspacing="0" cellpadding="0" border="0" class="paymentdetails first">';
     echo '<tr><td class="td_title"><h2>' . $this->params["payment_method"] . '</h2></td></tr>';
     echo '<tr><td class="td_pdetails">';
     echo '<div class="pd_row">';
     if ($type == 'points') {
         echo '<span class="djcfpay_label">' . JText::_('PLG_DJCFBANKTRANSFER_POINTS_PACKAGE') . ':</span>';
     } else {
         echo '<span class="djcfpay_label">' . JText::_('PLG_DJCFBANKTRANSFER_PAYMENT_AD_NAME') . ':</span>';
     }
     echo '<span class="djcfpay_value">' . $itemname . '</span>';
     echo '</div>';
     echo '<div class="pd_row">';
     echo '<span class="djcfpay_label">' . JText::_('PLG_DJCFBANKTRANSFER_PAYMENT_PRICE_TO_PAY') . ':</span>';
     echo '<span class="djcfpay_value">' . $amount . ' ' . $par->get('unit_price', '') . '</span>';
     echo '</div>';
     echo '<div class="pd_row">';
     if ($type == 'points') {
         echo '<span class="djcfpay_label">' . JText::_('PLG_DJCFBANKTRANSFER_PAYMENT_POINTS_ID') . ':</span>';
     } else {
         echo '<span class="djcfpay_label">' . JText::_('PLG_DJCFBANKTRANSFER_PAYMENT_AD_ID') . ':</span>';
     }
     echo '<span class="djcfpay_value">' . $id . '</span>';
     echo '</div>';
     echo '<div class="pd_row">';
     echo '<span class="djcfpay_label">' . JText::_('PLG_DJCFBANKTRANSFER_PAYMENT_PAY_INFORMATION') . ': </span><br /><br />';
     echo '<span class="djcfpay_value">' . JHTML::_('content.prepare', nl2br($this->params["pay_info"])) . '</span>';
     echo '</div>';
     echo '</td></tr>';
     echo '</table>';
     echo '</div>';
 }
コード例 #7
0
ファイル: additem.php プロジェクト: kidaa30/lojinha
 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);
 }
コード例 #8
0
ファイル: item.php プロジェクト: kidaa30/lojinha
 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();
     $task = JRequest::getVar('task');
     $id = JRequest::getInt('id');
     $row->bind(JRequest::get('post'));
     if ($task == 'save2copy') {
         $row->id = 0;
     }
     $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;
     $old_row = '';
     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;
         $query = "SELECT * FROM #__djcf_items WHERE id= " . $row->id . " ";
         $db->setQuery($query);
         $old_row = $db->loadObjectList();
     }
     if ($row->id == 0) {
         $row->exp_days = ceil((strtotime($row->date_exp) - time()) / (60 * 60 * 24));
         $row->date_start = date("Y-m-d H:i:s");
     }
     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();
         $query = "DELETE FROM #__djcf_fields_values_sale 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();
     $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();
     }
     if ($task == 'save2copy' && $id) {
         $query = "SELECT * FROM #__djcf_images WHERE item_id=" . $id . " AND type='item' ";
         $db->setQuery($query);
         $base_item_images = $db->loadObjectList('id');
         if (count($base_item_images)) {
             $query_img = "INSERT INTO #__djcf_images(`item_id`,`type`,`name`,`ext`,`path`,`caption`,`ordering`) VALUES ";
             foreach ($base_item_images as $item_img) {
                 $path_from_copy = JPATH_ROOT . $item_img->path . $item_img->name;
                 $new_img_name = str_ireplace($id . '_', $row->id . '_', $item_img->name);
                 $path_to_copy = JPATH_ROOT . $item_img->path . $new_img_name;
                 if (JFile::exists($path_from_copy . '.' . $item_img->ext)) {
                     JFile::copy($path_from_copy . '.' . $item_img->ext, $path_to_copy . '.' . $item_img->ext);
                 }
                 if (JFile::exists($path_from_copy . '_ths.' . $item_img->ext)) {
                     JFile::copy($path_from_copy . '_ths.' . $item_img->ext, $path_to_copy . '_ths.' . $item_img->ext);
                 }
                 if (JFile::exists($path_from_copy . '_thm.' . $item_img->ext)) {
                     JFile::copy($path_from_copy . '_thm.' . $item_img->ext, $path_to_copy . '_thm.' . $item_img->ext);
                 }
                 if (JFile::exists($path_from_copy . '_thb.' . $item_img->ext)) {
                     JFile::copy($path_from_copy . '_thb.' . $item_img->ext, $path_to_copy . '_thb.' . $item_img->ext);
                 }
                 $query_img .= "('" . $row->id . "','item','" . $new_img_name . "','" . $item_img->ext . "','/components/com_djclassifieds/images/item/','" . $db->escape($item_img->caption) . "','" . $item_img->ordering . "'), ";
             }
             $query_img = substr($query_img, 0, -2) . ';';
             $db->setQuery($query_img);
             $db->query();
         }
     }
     $item_images = '';
     if (!$is_new || $task == 'save2copy') {
         $item_id = $row->id;
         if ($task == 'save2copy') {
             $item_id = $id;
         }
         $query = "SELECT * FROM #__djcf_images WHERE item_id=" . $item_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){
     if ($row->cat_id == '') {
         $row->cat_id = 0;
     }
     $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();
     }
     //}
     $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());
         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();
             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();
             }
         }
     }
     if ($old_row && ($row->user_id || $row->email)) {
         if ($old_row->published != $row->published) {
             DJClassifiedsNotify::notifyUserPublication($row->id, $row->published);
         }
     }
     JPluginHelper::importPlugin('djclassifieds');
     $dispatcher->trigger('onAfterDJClassifiedsSaveAdvert', array($row, $is_new));
     switch ($task) {
         case 'apply':
         case 'save2copy':
             $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);
 }
コード例 #9
0
ファイル: djcfPaypal.php プロジェクト: kidaa30/lojinha
 function _notify_url()
 {
     $db = JFactory::getDBO();
     $par =& JComponentHelper::getParams('com_djclassifieds');
     $account_type = $this->params["testmode"];
     $user = JFactory::getUser();
     $id = JRequest::getInt('id', '0');
     $paypal_info = $_POST;
     /*$fil = fopen('ppraport/pp_raport.txt', 'a');
     		fwrite($fil, "\n\n--------------------post_first-----------------\n");
     		$post = $_POST;
     		foreach ($post as $key => $value) {
     		fwrite($fil, $key.' - '.$value."\n");
     		}
     		fclose($fil);*/
     $paypal_ipn = new paypal_ipn($paypal_info);
     foreach ($paypal_ipn->paypal_post_vars as $key => $value) {
         if (getType($key) == "string") {
             eval("\${$key}=\$value;");
         }
     }
     $paypal_ipn->send_response($account_type);
     if (!$paypal_ipn->is_verified()) {
         die;
     }
     $paymentstatus = 0;
     $status = $paypal_ipn->get_payment_status();
     $txn_id = $paypal_ipn->paypal_post_vars['txn_id'];
     if ($status == 'Completed' || $status == 'Pending' && $account_type == 1) {
         $query = "SELECT p.*  FROM #__djcf_payments p " . "WHERE p.id='" . $id . "' ";
         $db->setQuery($query);
         $payment = $db->loadObject();
         if ($payment) {
             if (JRequest::getVar('mc_gross') != $payment->price) {
                 die('Wrong amount');
             }
             $query = "UPDATE #__djcf_payments SET status='Completed',transaction_id='" . $txn_id . "' " . "WHERE id=" . $id . " AND method='djcfPaypal'";
             $db->setQuery($query);
             $db->query();
             if ($row->type == 3) {
                 //subscription plans
                 $query = "SELECT p.*  FROM #__djcf_plans p WHERE p.id='" . $row->item_id . "' ";
                 $db->setQuery($query);
                 $plan = $db->loadObject();
                 $registry = new JRegistry();
                 $registry->loadString($plan->params);
                 $plan_params = $registry->toObject();
                 //echo '<pre>';print_r($plan_params);die();
                 $date_start = date("Y-m-d H:i:s");
                 $date_exp = '';
                 if ($plan_params->days_limit) {
                     $date_exp_time = time() + $plan_params->days_limit * 24 * 60 * 60;
                     $date_exp = date("Y-m-d H:i:s", $date_exp_time);
                 }
                 $query = "INSERT INTO #__djcf_plans_subscr (`user_id`,`plan_id`,`adverts_limit`,`adverts_available`,`date_start`,`date_exp`,`plan_params`) " . "VALUES ('" . $row->user_id . "','" . $plan->id . "','" . $plan_params->ad_limit . "','" . $plan_params->ad_limit . "','" . $date_start . "','" . $date_exp . "','" . addslashes($plan->params) . "')";
                 $db->setQuery($query);
                 $db->query();
                 $message = JText::_('COM_DJCLASSIFIEDS_STATUS_CHANGED_SUBSCRIPTION_PLAN_ADDED');
             } else {
                 if ($payment->type == 2) {
                     $date_sort = date("Y-m-d H:i:s");
                     $query = "UPDATE #__djcf_items SET date_sort='" . $date_sort . "' " . "WHERE id=" . $payment->item_id . " ";
                     $db->setQuery($query);
                     $db->query();
                 } else {
                     if ($payment->type == 1) {
                         $query = "SELECT p.points  FROM #__djcf_points p WHERE p.id='" . $payment->item_id . "' ";
                         $db->setQuery($query);
                         $points = $db->loadResult();
                         $query = "INSERT INTO #__djcf_users_points (`user_id`,`points`,`description`) " . "VALUES ('" . $payment->user_id . "','" . $points . "','" . JText::_('COM_DJCLASSIFIEDS_POINTS_PACKAGE') . " PayPal <br />" . JText::_('COM_DJCLASSIFIEDS_PAYMENT_ID') . ' ' . $payment->id . "')";
                         $db->setQuery($query);
                         $db->query();
                     } else {
                         $query = "SELECT c.*  FROM #__djcf_items i, #__djcf_categories c " . "WHERE i.cat_id=c.id AND i.id='" . $payment->item_id . "' ";
                         $db->setQuery($query);
                         $cat = $db->loadObject();
                         $pub = 0;
                         if ($cat->autopublish == '1' || $cat->autopublish == '0' && $par->get('autopublish') == '1') {
                             $pub = 1;
                         }
                         $query = "UPDATE #__djcf_items SET payed=1, pay_type='',extra_images_to_pay='0',extra_chars_to_pay='0', published='" . $pub . "' " . "WHERE id=" . $payment->item_id . " ";
                         $db->setQuery($query);
                         $db->query();
                         if ($pub) {
                             DJClassifiedsNotify::notifyUserPublication($payment->item_id, '1');
                         }
                     }
                 }
             }
             $payment->status = 'Completed';
             $dispatcher = JDispatcher::getInstance();
             $dispatcher->trigger('onAfterPaymentStatusChange', array($payment));
         }
     } else {
         $query = "UPDATE #__djcf_payments SET status='" . $status . "',transaction_id='" . $txn_id . "' " . "WHERE id=" . $id . " AND method='djcfPaypal'";
         $db->setQuery($query);
         $db->query();
     }
 }
コード例 #10
0
ファイル: item.php プロジェクト: kidaa30/lojinha
    function saveBid()
    {
        header("Content-type: text/html; charset=utf-8");
        $app = JFactory::getApplication();
        $id = JRequest::getInt('id', 0);
        $bid = JRequest::getFloat('bid', 0);
        $db = JFactory::getDBO();
        $user = JFactory::getUser();
        $itemid = JRequest::getVar('Itemid');
        $par = JComponentHelper::getParams('com_djclassifieds');
        $bid_error = 0;
        $error_show_form = 0;
        $error_price = 0;
        $bid_message = JText::_('COM_DJCLASSIFIEDS_OFFER_PUBLISHED');
        if ($user->id > 0) {
            $date_now = date("Y-m-d H:i:s");
            $query = "SELECT * FROM #__djcf_items i " . "WHERE i.id = " . $id . " AND i.published=1 AND i.date_start <= '" . $date_now . "' AND i.date_exp >= '" . $date_now . "' ";
            $db->setQuery($query);
            $item = $db->loadObject();
            if ($item) {
                if ($bid > 0) {
                    $query = "SELECT a.*, u.name as u_name FROM #__djcf_auctions a, #__users u " . " WHERE a.user_id=u.id AND a.item_id=" . $id . " ORDER BY a.date DESC LIMIT 1";
                    $db->setQuery($query);
                    $last_bid = $db->loadObject();
                    if ($item->buynow) {
                        $min_bid = $item->price_start;
                    } else {
                        $min_bid = $item->price;
                    }
                    if ($last_bid) {
                        if ($last_bid->user_id == $user->id) {
                            $bid_error = 1;
                            $bid_message = JText::_('COM_DJCLASSIFIEDS_YOUR_OFFER_IS_LAST_YOU_CAN_BID_ONLY_OTHER_USERS');
                        }
                        $min_bid = $last_bid->price;
                    }
                    if ($item->user_id == $user->id) {
                        $bid_error = 1;
                        $bid_message = JText::_('COM_DJCLASSIFIEDS_YOU_CANT_BID_YOUR_ADVERT');
                    }
                    if ($bid_error == 0) {
                        if (!$item->bid_min) {
                            $item->bid_min = 1;
                        }
                        $min_bid = $min_bid + $item->bid_min;
                        if ($bid < $min_bid) {
                            $bid_error = 1;
                            $error_show_form = 1;
                            $error_price = $min_bid;
                            $bid_message = JText::_('COM_DJCLASSIFIEDS_OFFER_SMALLER_THAN_LIMIT') . ' ' . DJClassifiedsTheme::priceFormat($error_price, $item->currency);
                        }
                        if ($bid_error == 0) {
                            if ($item->bid_max > 0) {
                                $max_bid = $min_bid + $item->bid_max;
                                if ($item->bid_max && $bid > $max_bid) {
                                    $bid_error = 1;
                                    $error_show_form = 1;
                                    $error_price = $max_bid;
                                    $bid_message = JText::_('COM_DJCLASSIFIEDS_OFFER_BIGGER_THAN_LIMIT') . ' ' . DJClassifiedsTheme::priceFormat($error_price, $item->currency);
                                }
                            }
                        }
                        if ($bid_error == 0) {
                            $user_ip = $_SERVER['REMOTE_ADDR'];
                            $win = 0;
                            if ($bid >= $item->price_reserve && $item->bid_autoclose == 1) {
                                $win = 1;
                            }
                            $query = "INSERT INTO #__djcf_auctions (`item_id`, `user_id`, `ip_address`, `price`,`win`)" . " VALUES ( '" . $id . "', '" . $user->id . "','" . $user_ip . "', '" . $bid . "', '" . $win . "' )";
                            $db->setQuery($query);
                            $db->query();
                            $price_start = '';
                            if (!$last_bid) {
                                $price_start = " price_start='" . $item->price . "' ";
                            }
                            $win_notifi = '';
                            if ($win) {
                                if ($price_start || $item->buynow) {
                                    $win_notifi = ", ";
                                }
                                $win_notifi .= "notify=2 ";
                            }
                            $price_new = '';
                            if ($item->buynow == 0) {
                                $price_new = " price='" . $bid . "' ";
                                if ($price_start) {
                                    $price_start = ',' . $price_start;
                                }
                            }
                            if ($price_start || $win_notifi || $price_new) {
                                $query = "UPDATE #__djcf_items SET " . $price_new . $price_start . $win_notifi . " WHERE id=" . $item->id;
                                $db->setQuery($query);
                                $db->query();
                            }
                            DJClassifiedsNotify::notifyAuctionsBidAuthor($id, $user, $bid);
                            DJClassifiedsNotify::notifyAuctionsBidBidder($id, $user, $bid);
                            if ($last_bid) {
                                DJClassifiedsNotify::notifyAuctionsBidOutbid($id, $user, $bid, $last_bid);
                            }
                            if ($win) {
                                DJClassifiedsNotify::notifyAuctionsWinAuthor($id, $user, $bid);
                                DJClassifiedsNotify::notifyAuctionsWinBidder($id, $user, $bid);
                            }
                        }
                    }
                } else {
                    $bid_error = 1;
                    $bid_message = JText::_('COM_DJCLASSIFIEDS_PLEASE_ENTER_PRICE_VALUE');
                }
                $query = "SELECT a.*, u.name as u_name FROM #__djcf_auctions a, #__users u " . " WHERE a.user_id=u.id AND a.item_id=" . $id . " ORDER BY a.date DESC LIMIT " . $par->get('bids_displayed', 5);
                $db->setQuery($query);
                $bids = $db->loadObjectList();
                ?>
				<div class="auction" id="djauctions">
				<div class="auction_bids">
					<div class="bids_title"><h2><?php 
                echo JText::_('COM_DJCLASSIFIEDS_CURRENT_BIDS');
                ?>
</h2></div>
						<?php 
                if (isset($bids[0]) && $item->price_reserve) {
                    if ($bids[0]->price < $item->price_reserve) {
                        ?>
								<div class="bids_subtitle"><?php 
                        echo JText::_('COM_DJCLASSIFIEDS_RESERVE_PRICE_NOT_REACHED');
                        ?>
</div>
						<?php 
                    }
                }
                ?>
						<div class="bids_list">
							<?php 
                if ($bids) {
                    ?>
								<div class="bids_row bids_row_title">
									<div class="bids_col bids_col_name"><?php 
                    echo JText::_('COM_DJCLASSIFIEDS_NAME');
                    ?>
:</div>
									<div class="bids_col bids_col_date"><?php 
                    echo JText::_('COM_DJCLASSIFIEDS_DATE');
                    ?>
:</div>
									<div class="bids_col bids_col_bid"><?php 
                    echo JText::_('COM_DJCLASSIFIEDS_BID');
                    ?>
:</div>
									<div class="clear_both"></div>
								</div>
								<?php 
                    foreach ($bids as $bid) {
                        if ($bid->price > $min_bid) {
                            $min_bid = $bid->price;
                        }
                        if ($par->get('mask_bidder_name', '0') == 1) {
                            $bid->u_name = substr($bid->u_name, 0, 1) . '.....' . substr($bid->u_name, -1, 1);
                        }
                        ?>
 
									<div class="bids_row">
										<div class="bids_col bids_col_name"><?php 
                        echo $bid->u_name;
                        ?>
</div>
										<div class="bids_col bids_col_date"><?php 
                        echo DJClassifiedsTheme::formatDate(strtotime($bid->date));
                        ?>
</div>
										<div class="bids_col bids_col_bid"><?php 
                        echo DJClassifiedsTheme::priceFormat($bid->price, $item->currency);
                        ?>
</div>
										<div class="clear_both"></div>
									</div>		
								<?php 
                    }
                    ?>
			
							<?php 
                } else {
                    ?>
								<div class="bids_row no_bids_row"><?php 
                    echo JText::_('COM_DJCLASSIFIEDS_NO_SUBMITTED_BIDS');
                    ?>
</div>	
							<?php 
                }
                ?>
							<div class="clear_both"></div>
						</div>
					</div>
					
					<?php 
                if ($error_show_form) {
                    ?>
					
						<div class="bids_form" id="djbids_form">
							<div class="bids_box">
								<div class="bids_info">
									<span class="bid_label"><?php 
                    echo JText::_('COM_DJCLASSIFIEDS_PLACE_BID');
                    ?>
</span>					
								</div>
								<div class="bids_input">
									<?php 
                    if ($par->get('unit_price_position', '0') == 1) {
                        echo $item->currency ? $item->currency : $par->get('unit_price');
                    }
                    ?>
     	
									<input class="inputbox" id="djbid_value" type="text" name="bid_max" id="bid_max" size="30" maxlength="250" value="<?php 
                    echo $error_price;
                    ?>
" />
									<?php 
                    if ($par->get('unit_price_position', '0') == 0) {
                        echo $item->currency ? $item->currency : $par->get('unit_price');
                    }
                    ?>
				
								</div>
								<div class="bids_button">
									<button class="button" id="bid_submit"><?php 
                    echo JText::_('COM_DJCLASSIFIEDS_PLACE_BID');
                    ?>
</button>
								</div>								
								<div class="clear_both"></div>
							</div>
							<div class="clear_both"></div>
						</div>
						
					
					<?php 
                }
                ?>
					
					
									
					<div id="djbid_alert">
						<?php 
                if ($bid_error) {
                    echo $bid_message;
                }
                ?>
					</div>
					<div id="djbid_message">
						<?php 
                if (!$bid_error) {
                    echo $bid_message;
                }
                ?>
					</div>
				</div>
				
				
				
				
				
				
				
				
				
				
				
			<?php 
            } else {
                echo '<div class="auction" id="djauctions"><div id="djbid_alert" >';
                echo JText::_('COM_DJCLASSIFIEDS_WRONG_AD');
                echo '</div></div>';
            }
        } else {
            echo '<div class="auction" id="djauctions"><div id="djbid_alert" >';
            echo JText::_('COM_DJCLASSIFIEDS_PLEASE_LOGIN');
            echo '</div></div>';
        }
        die;
    }
コード例 #11
0
ファイル: checkout.php プロジェクト: kidaa30/lojinha
 function saveCheckout()
 {
     $app = JFactory::getApplication();
     $par = JComponentHelper::getParams('com_djclassifieds');
     $user = JFactory::getUser();
     $db = JFactory::getDBO();
     $id = JRequest::getInt('item_id', 0);
     $quantity = JRequest::getInt('quantity', 0);
     $opt_id = JRequest::getInt('buynow_option', 0);
     $dispatcher = JDispatcher::getInstance();
     $query = "SELECT i.*, c.points as c_points, c.autopublish as c_autopublish, c.alias as c_alias FROM #__djcf_items i " . "LEFT JOIN #__djcf_categories c ON c.id=i.cat_id " . "WHERE i.id=" . $id . " LIMIT 1";
     $db->setQuery($query);
     $item = $db->loadObject();
     $redirect_a = 0;
     if (!$item) {
         $redirect_a = 1;
         $redirect = "index.php?option=com_djclassifieds&view=items&cid=0";
         $message = JText::_('COM_DJCLASSIFIEDS_WRONG_AD');
     } else {
         $opt_name = '';
         if ($opt_id) {
             $query = "SELECT f.* FROM #__djcf_fields_values_sale f " . "WHERE f.id=" . $opt_id . " AND f.item_id =" . $id . " ORDER BY f.id";
             $db->setQuery($query);
             $item_opt = $db->loadObject();
             if ($item_opt) {
                 $options = json_decode($item_opt->options);
                 foreach ($options as $o) {
                     if ($opt_name) {
                         $opt_name .= ' - ';
                     }
                     $opt_name .= $o->label . ': ' . $o->value;
                 }
                 $item->quantity = $item_opt->quantity;
             }
         }
     }
     if ($item->quantity < $quantity) {
         $redirect_a = 1;
         $redirect = DJClassifiedsSEO::getItemRoute($item->id . ':' . $item->alias, $item->cat_id . ':' . $item->c_alias);
         $message = JText::_('COM_DJCLASSIFIEDS_NUMBER_OF_PRODUCTS_IS_LESS_THEN_SELECTED');
     }
     if ($user->id == 0) {
         $redirect_a = 1;
         $redirect = DJClassifiedsSEO::getItemRoute($item->id . ':' . $item->alias, $item->cat_id . ':' . $item->c_alias);
         $redirect = "index.php?option=com_djclassifieds&view=items&cid=0";
         $message = JText::_('COM_DJCLASSIFIEDS_PLEASE_LOGIN');
     }
     if ($redirect_a == 0) {
         $user_ip = $_SERVER['REMOTE_ADDR'];
         $query = "INSERT INTO #__djcf_orders (`item_id`, `user_id`, `ip_address`, `price`,`currency`, `quantity`, `status`,`item_name`,`item_option`)" . " VALUES ( '" . $item->id . "','" . $user->id . "','" . $user_ip . "', '" . $item->price . "', '" . $item->currency . "','" . $quantity . "','1','" . addslashes($item->name) . "','" . addslashes($opt_name) . "')";
         $db->setQuery($query);
         $db->query();
         $query = "SELECT * FROM #__djcf_orders WHERE item_id='" . $item->id . "' AND user_id='" . $user->id . "' " . " ORDER BY id DESC LIMIT 1";
         $db->setQuery($query);
         $order = $db->loadObject();
         $dispatcher->trigger('onAfterCheckoutSave', array(&$item, &$user, $order));
         $new_quantity = $item->quantity - $quantity;
         $query = "UPDATE #__djcf_items SET quantity='" . $new_quantity . "' " . " WHERE id=" . $item->id;
         $db->setQuery($query);
         $db->query();
         if ($opt_id) {
             $query = "UPDATE #__djcf_fields_values_sale SET quantity='" . $new_quantity . "' " . " WHERE id=" . $opt_id;
             $db->setQuery($query);
             $db->query();
         }
         DJClassifiedsNotify::notifyBuynowBuyer($id, $user, $quantity, $opt_name);
         DJClassifiedsNotify::notifyBuynowAuthor($id, $user, $quantity, $opt_name);
         $redirect = DJClassifiedsSEO::getItemRoute($item->id . ':' . $item->alias, $item->cat_id . ':' . $item->c_alias);
         $message = JText::_('COM_DJCLASSIFIEDS_ORDER_PLACED_SUCCESSFULLY');
     }
     $redirect = JRoute::_($redirect, false);
     $app->redirect($redirect, $message);
 }
コード例 #12
0
ファイル: djcfPayU.php プロジェクト: kidaa30/lojinha
 function _notify_url()
 {
     $db = JFactory::getDBO();
     $par = JComponentHelper::getParams('com_djclassifieds');
     $user = JFactory::getUser();
     $id = JRequest::getInt('session_id', '0');
     $app = JFactory::getApplication();
     $itemid = JRequest::getInt("Itemid", "");
     $payu_info = $_POST;
     $server = 'www.platnosci.pl';
     $server_script = '/paygw/ISO/Payment/get';
     $PLATNOSCI_POS_ID = $this->params["pos_id"];
     $PLATNOSCI_KEY1 = $this->params["md5_key"];
     $PLATNOSCI_KEY2 = $this->params["md5_key2"];
     /*$fil = fopen('payu_data.txt', 'a');			
     		fwrite($fil, "\n\n--------------------post_first-----------------\n");
     		$post = $_POST;
     		foreach ($post as $key => $value) {
     				fwrite($fil, $key.' - '.$value."\n");
     			}				
     		fclose($fil);*/
     if (!isset($_POST['pos_id']) || !isset($_POST['session_id']) || !isset($_POST['ts']) || !isset($_POST['sig'])) {
         die('ERROR: EMPTY PARAMETERS');
     }
     //-- brak wszystkich parametrow
     if ($_POST['pos_id'] != $PLATNOSCI_POS_ID) {
         die('ERROR: WRONG POS ID');
     }
     //--- błędny numer POS
     $sig = md5($_POST['pos_id'] . $_POST['session_id'] . $_POST['ts'] . $PLATNOSCI_KEY2);
     if ($_POST['sig'] != $sig) {
         die('ERROR: WRONG SIGNATURE');
     }
     //--- błędny podpis
     $ts = time();
     $sig = md5($PLATNOSCI_POS_ID . $_POST['session_id'] . $ts . $PLATNOSCI_KEY1);
     $parameters = "pos_id=" . $PLATNOSCI_POS_ID . "&session_id=" . $_POST['session_id'] . "&ts=" . $ts . "&sig=" . $sig;
     $fsocket = false;
     $curl = false;
     $result = false;
     if (PHP_VERSION >= 4.3 && ($fp = @fsockopen('ssl://' . $server, 443, $errno, $errstr, 30))) {
         $fsocket = true;
     } elseif (function_exists('curl_exec')) {
         $curl = true;
     }
     if ($fsocket == true) {
         $header = 'POST ' . $server_script . ' HTTP/1.0' . "\r\n" . 'Host: ' . $server . "\r\n" . 'Content-Type: application/x-www-form-urlencoded' . "\r\n" . 'Content-Length: ' . strlen($parameters) . "\r\n" . 'Connection: close' . "\r\n\r\n";
         @fputs($fp, $header . $parameters);
         $platnosci_response = '';
         while (!@feof($fp)) {
             $res = @fgets($fp, 1024);
             $platnosci_response .= $res;
         }
         @fclose($fp);
     } elseif ($curl == true) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, "https://" . $server . $server_script);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
         curl_setopt($ch, CURLOPT_HEADER, 0);
         curl_setopt($ch, CURLOPT_TIMEOUT, 20);
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $platnosci_response = curl_exec($ch);
         curl_close($ch);
     } else {
         die("ERROR: No connect method ...\n");
     }
     if (eregi("<trans>.*<pos_id>([0-9]*)</pos_id>.*<session_id>(.*)</session_id>.*<order_id>(.*)</order_id>.*<amount>([0-9]*)</amount>.*<status>([0-9]*)</status>.*<desc>(.*)</desc>.*<ts>([0-9]*)</ts>.*<sig>([a-z0-9]*)</sig>.*</trans>", $platnosci_response, $parts)) {
         $result = $this->get_status($parts);
     }
     if ($result['code']) {
         //--- rozpoznany status transakcji
         $pos_id = $parts[1];
         $session_id = $parts[2];
         $order_id = $parts[3];
         $amount = $parts[4];
         //-- w groszach
         $status = $parts[5];
         $desc = $parts[6];
         $ts = $parts[7];
         $sig = $parts[8];
         /*$fil = fopen('payu_data.txt', 'a');
         
         					foreach ($result as $key => $value) {
         						fwrite($fil, $key.' - '.$value."\n");
         					}*/
         /* TODO: zmiana statusu transakcji w systemie Sklepu */
         if ($result['code'] == '99') {
             $query = "SELECT p.*  FROM #__djcf_payments p " . "WHERE p.id='" . $id . "' ";
             $db->setQuery($query);
             $payment = $db->loadObject();
             if ($payment) {
                 $query = "UPDATE #__djcf_payments SET status='Completed',transaction_id='" . $id . "' " . "WHERE id=" . $id . " AND method='djcfPayU'";
                 $db->setQuery($query);
                 $db->query();
                 if ($row->type == 3) {
                     //subscription plans
                     $query = "SELECT p.*  FROM #__djcf_plans p WHERE p.id='" . $row->item_id . "' ";
                     $db->setQuery($query);
                     $plan = $db->loadObject();
                     $registry = new JRegistry();
                     $registry->loadString($plan->params);
                     $plan_params = $registry->toObject();
                     //echo '<pre>';print_r($plan_params);die();
                     $date_start = date("Y-m-d H:i:s");
                     $date_exp = '';
                     if ($plan_params->days_limit) {
                         $date_exp_time = time() + $plan_params->days_limit * 24 * 60 * 60;
                         $date_exp = date("Y-m-d H:i:s", $date_exp_time);
                     }
                     $query = "INSERT INTO #__djcf_plans_subscr (`user_id`,`plan_id`,`adverts_limit`,`adverts_available`,`date_start`,`date_exp`,`plan_params`) " . "VALUES ('" . $row->user_id . "','" . $plan->id . "','" . $plan_params->ad_limit . "','" . $plan_params->ad_limit . "','" . $date_start . "','" . $date_exp . "','" . addslashes($plan->params) . "')";
                     $db->setQuery($query);
                     $db->query();
                     $message = JText::_('COM_DJCLASSIFIEDS_STATUS_CHANGED_SUBSCRIPTION_PLAN_ADDED');
                 } else {
                     if ($payment->type == 2) {
                         $date_sort = date("Y-m-d H:i:s");
                         $query = "UPDATE #__djcf_items SET date_sort='" . $date_sort . "' " . "WHERE id=" . $payment->item_id . " ";
                         $db->setQuery($query);
                         $db->query();
                     } else {
                         if ($payment->type == 1) {
                             $query = "SELECT p.points  FROM #__djcf_points p WHERE p.id='" . $payment->item_id . "' ";
                             $db->setQuery($query);
                             $points = $db->loadResult();
                             $query = "INSERT INTO #__djcf_users_points (`user_id`,`points`,`description`) " . "VALUES ('" . $payment->user_id . "','" . $points . "','" . JText::_('COM_DJCLASSIFIEDS_POINTS_PACKAGE') . " PayU " . JText::_('COM_DJCLASSIFIEDS_PAYMENT_ID') . ' ' . $payment->id . "')";
                             $db->setQuery($query);
                             $db->query();
                         } else {
                             $query = "SELECT c.*  FROM #__djcf_items i, #__djcf_categories c " . "WHERE i.cat_id=c.id AND i.id='" . $payment->item_id . "' ";
                             $db->setQuery($query);
                             $cat = $db->loadObject();
                             $pub = 0;
                             if ($cat->autopublish == '1' || $cat->autopublish == '0' && $par->get('autopublish') == '1') {
                                 $pub = 1;
                             }
                             $query = "UPDATE #__djcf_items SET payed=1, pay_type='',extra_images_to_pay='0',extra_chars_to_pay='0', published='" . $pub . "' " . "WHERE id=" . $payment->item_id . " ";
                             $db->setQuery($query);
                             $db->query();
                             if ($pub) {
                                 DJClassifiedsNotify::notifyUserPublication($payment->item_id, '1');
                             }
                         }
                     }
                 }
                 $payment->status = 'Completed';
                 $dispatcher = JDispatcher::getInstance();
                 $dispatcher->trigger('onAfterPaymentStatusChange', array($payment));
             }
             echo "OK";
             exit;
             // udalo sie zapisac dane wiec odsylamy OK
         } else {
             if ($result['code'] == '2') {
                 $query = "UPDATE #__djcf_payments SET status='Cancelled',transaction_id='" . $id . "' " . "WHERE id=" . $id . " AND method='djcfPayU'";
                 $db->setQuery($query);
                 $db->query();
                 //if ($this->model->set_status_platnosci($session_id,0)){
                 echo "OK";
                 exit;
                 //}
                 // transakcja anulowana mozemy również anulować zamowienie
             }
         }
         // jezeli wszytskie operacje wykonane poprawnie wiec odsylamy ok
         // w innym przypadku należy wygenerować błąd
         // if ( wszystko_ok ) {
         echo "OK";
         exit;
         // } else {
         //
         // }
     } else {
         /* TODO: obsługa powiadamiania o błędnych statusach transakcji*/
         /*$fil = fopen('payu_data.txt', 'a');
           fwrite($fil, "\n\n------------------------BLAD--------------\n");
           fwrite($fil, "code=" . $result['code'] . " message=" . $result['message'] . "\n");
           fwrite($fil, $platnosci_response . "\n\n");*/
         // powiadomienie bedzie wysłane ponownie przez platnosci.pl
         // ewentualnie dodajemy sobie jakis wpis do logow ...
     }
     $message = JTExt::_('PLG_DJCFPAYU_AFTER_SUCCESSFULL_MSG');
     $redirect = 'index.php?option=com_djclassifieds&view=items&cid=0&Itemid=' . $itemid;
     $app->redirect($redirect, $message);
 }
コード例 #13
0
ファイル: djcfAuthorizeNET.php プロジェクト: kidaa30/lojinha
 function _notify_url()
 {
     require_once JPATH_BASE . '/plugins/djclassifiedspayment/djcfAuthorizeNET/djcfAuthorizeNET/anet_php_sdk/AuthorizeNet.php';
     $db = JFactory::getDBO();
     $app = JFactory::getApplication();
     $account_type = $this->params["account_type"];
     $Itemid = JRequest::getInt("Itemid", '0');
     $merchant_id = $this->params["login_id"];
     $merchant_key = $this->params["transaction_key"];
     $currency = $this->params["currency_code"];
     $user = JFactory::getUser();
     $id = JRequest::getInt('id', '0');
     $ptype = JRequest::getVar('ptype');
     $par =& JComponentHelper::getParams('com_djclassifieds');
     $type = JRequest::getVar('type', '');
     $row =& JTable::getInstance('Payments', 'DJClassifiedsTable');
     //print_r($type);die();
     if ($type == 'prom_top') {
         $query = "SELECT i.* FROM #__djcf_items i " . "WHERE i.id=" . $id . " LIMIT 1";
         $db->setQuery($query);
         $item = $db->loadObject();
         if (!isset($item)) {
             $message = JText::_('COM_DJCLASSIFIEDS_WRONG_AD');
             $redirect = "index.php?option=com_djclassifieds&view=items&cid=0";
         }
         $row->item_id = $id;
         $row->user_id = $user->id;
         $row->method = $ptype;
         $row->status = 'Start';
         $row->ip_address = $_SERVER['REMOTE_ADDR'];
         $row->price = $par->get('promotion_move_top_price', 0);
         $row->type = 2;
         $row->store();
         $amount = $par->get('promotion_move_top_price', 0);
         $itemname = $item->name;
         $item_id = $row->id;
         $item_cid = '&cid=' . $item->cat_id;
     } else {
         if ($type == 'points') {
             $query = "SELECT p.* FROM #__djcf_points p " . "WHERE p.id=" . $id . " LIMIT 1";
             $db->setQuery($query);
             $points = $db->loadObject();
             if (!isset($item)) {
                 $message = JText::_('COM_DJCLASSIFIEDS_WRONG_POINTS_PACKAGE');
                 $redirect = "index.php?option=com_djclassifieds&view=items&cid=0";
             }
             $row->item_id = $id;
             $row->user_id = $user->id;
             $row->method = $ptype;
             $row->status = 'Start';
             $row->ip_address = $_SERVER['REMOTE_ADDR'];
             $row->price = $points->price;
             $row->type = 1;
             $row->store();
             $amount = $points->price;
             $itemname = $points->name;
             $item_id = $row->id;
             $item_cid = '';
         } else {
             if ($type == 'plan') {
                 $query = "SELECT p.* FROM #__djcf_plans p " . "WHERE p.id=" . $id . " LIMIT 1";
                 $db->setQuery($query);
                 $plan = $db->loadObject();
                 if (!isset($plan)) {
                     $message = JText::_('COM_DJCLASSIFIEDS_SUBSCRIPTION_PLAN');
                     $redirect = "index.php?option=com_djclassifieds&view=plans";
                 }
                 $row->item_id = $id;
                 $row->user_id = $user->id;
                 $row->method = $ptype;
                 $row->status = 'Start';
                 $row->ip_address = $_SERVER['REMOTE_ADDR'];
                 $row->price = $plan->price;
                 $row->type = 3;
                 $row->store();
                 $amount = $plan->price;
                 $itemname = $plan->name;
                 $item_id = $row->id;
                 $item_cid = '';
             } else {
                 $query = "SELECT i.*, c.price as c_price FROM #__djcf_items i " . "LEFT JOIN #__djcf_categories c ON c.id=i.cat_id " . "WHERE i.id=" . $id . " LIMIT 1";
                 $db->setQuery($query);
                 $item = $db->loadObject();
                 if (!isset($item)) {
                     $message = JText::_('COM_DJCLASSIFIEDS_WRONG_AD');
                     $redirect = "index.php?option=com_djclassifieds&view=items&cid=0";
                 }
                 $amount = 0;
                 if (strstr($item->pay_type, 'cat')) {
                     $amount += $item->c_price / 100;
                 }
                 $query = "SELECT * FROM #__djcf_days d " . "WHERE d.days=" . $item->exp_days . " LIMIT 1";
                 $db->setQuery($query);
                 $day = $db->loadObject();
                 if (strstr($item->pay_type, 'duration_renew')) {
                     $amount += $day->price_renew;
                 } else {
                     if (strstr($item->pay_type, 'duration')) {
                         $amount += $day->price;
                     }
                 }
                 if (strstr($item->pay_type, 'extra_img_renew')) {
                     if ($day->img_price_default) {
                         $amount += $par->get('img_price_renew', '0') * $item->extra_images_to_pay;
                     } else {
                         $amount += $day->img_price_renew * $item->extra_images_to_pay;
                     }
                 } else {
                     if (strstr($item->pay_type, 'extra_img')) {
                         if ($day->img_price_default) {
                             $amount += $par->get('img_price', '0') * $item->extra_images_to_pay;
                         } else {
                             $amount += $day->img_price * $item->extra_images_to_pay;
                         }
                     }
                 }
                 if (strstr($item->pay_type, 'extra_chars_renew')) {
                     if ($day->char_price_default) {
                         $amount += $par->get('desc_char_price_renew', '0') * $item->extra_chars_to_pay;
                     } else {
                         $amount += $day->char_price_renew * $item->extra_chars_to_pay;
                     }
                 } else {
                     if (strstr($item->pay_type, 'extra_chars')) {
                         if ($day->char_price_default) {
                             $amount += $par->get('desc_char_price', '0') * $item->extra_chars_to_pay;
                         } else {
                             $amount += $day->char_price * $item->extra_chars_to_pay;
                         }
                     }
                 }
                 $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 (strstr($item->pay_type, $prom->name)) {
                         $amount += $prom->price;
                     }
                 }
                 /*$query = 'DELETE FROM #__djcf_payments WHERE item_id= "'.$id.'" ';
                 		 $db->setQuery($query);
                 		$db->query();
                 	
                 	
                 		$query = 'INSERT INTO #__djcf_payments ( item_id,user_id,method,  status)' .
                 		' VALUES ( "'.$id.'" ,"'.$user->id.'","'.$ptype.'" ,"Start" )'
                 		;
                 		$db->setQuery($query);
                 		$db->query();*/
                 $row->item_id = $id;
                 $row->user_id = $user->id;
                 $row->method = $ptype;
                 $row->status = 'Start';
                 $row->ip_address = $_SERVER['REMOTE_ADDR'];
                 $row->price = $amount;
                 $row->type = 0;
                 $row->store();
                 $itemname = $item->name;
                 $item_id = $row->id;
                 $item_cid = '&cid=' . $item->cat_id;
             }
         }
     }
     $query = "SELECT p.*  FROM #__djcf_payments p " . "WHERE p.id='" . $item_id . "' ";
     $db->setQuery($query);
     $payment = $db->loadObject();
     $login_id = $this->params["login_id"];
     $transaction_key = $this->params["transaction_key"];
     $card_no = JRequest::getVar('card_no');
     $msg_style = '';
     //include_once "phpcreditcard.php";
     $card_num = JRequest::getVar('card_no', '0', '', 'string');
     $card_type = JRequest::getVar('card_type');
     $exp_date = JRequest::getVar('exp_date', '0', '', 'int') . '/' . JRequest::getVar('exp_year', '0', '', 'int');
     $cvv = JRequest::getVar('card_code', '0', '', 'int');
     if ($card_num == 0 || $cvv == '0') {
         $message = JText::_('COM_DJCLASSIFIEDS_ENTER_ALL_VALUES');
         $redirect = 'index.php?option=com_djclassifieds&view=payment&id=' . $id . '&type=' . $type . '&Itemid=' . $Itemid;
         $app->redirect($redirect, $message, 'Error');
     }
     define("AUTHORIZENET_API_LOGIN_ID", $merchant_id);
     define("AUTHORIZENET_TRANSACTION_KEY", $merchant_key);
     if ($account_type == 'secure') {
         define("AUTHORIZENET_SANDBOX", false);
     } else {
         define("AUTHORIZENET_SANDBOX", true);
     }
     $sale = new AuthorizeNetAIM();
     $sale->amount = $amount;
     $sale->card_num = $card_num;
     $sale->exp_date = $exp_date;
     //$sale->card_num = '4007000000027';
     //$sale->exp_date = $exp_date;
     //$sale->card_type = 'V';
     $sale->auth_code = JRequest::getVar('auth_code', '0', '', 'int');
     $response = $sale->authorizeAndCapture();
     //echo '<pre>'; print_r($response);die();
     if ($response->approved) {
         $query = "UPDATE #__djcf_payments SET status='Completed' " . "WHERE id=" . $item_id . " AND method='djcfAuthorizeNET'";
         $db->setQuery($query);
         $db->query();
         if ($type == 'prom_top') {
             $date_sort = date("Y-m-d H:i:s");
             $query = "UPDATE #__djcf_items SET date_sort='" . $date_sort . "' " . "WHERE id=" . $id . " ";
             $db->setQuery($query);
             $db->query();
         } else {
             if ($type == 'points') {
                 $query = "SELECT p.points  FROM #__djcf_points p WHERE p.id='" . $id . "' ";
                 $db->setQuery($query);
                 $points = $db->loadResult();
                 $query = "INSERT INTO #__djcf_users_points (`user_id`,`points`,`description`) " . "VALUES ('" . $payment->user_id . "','" . $points . "','" . JText::_('COM_DJCLASSIFIEDS_POINTS_PACKAGE') . " AuthorizeNET <br />" . JText::_('COM_DJCLASSIFIEDS_PAYMENT_ID') . ' ' . $payment->id . "')";
                 $db->setQuery($query);
                 $db->query();
             } else {
                 $query = "SELECT c.*  FROM #__djcf_items i, #__djcf_categories c " . "WHERE i.cat_id=c.id AND i.id='" . $id . "' ";
                 $db->setQuery($query);
                 $cat = $db->loadObject();
                 $pub = 0;
                 if ($cat->autopublish == '1' || $cat->autopublish == '0' && $par->get('autopublish') == '1') {
                     $pub = 1;
                 }
                 $query = "UPDATE #__djcf_items SET payed=1, pay_type='',extra_images_to_pay='0',extra_chars_to_pay='0', published='" . $pub . "' " . "WHERE id=" . $id . " ";
                 $db->setQuery($query);
                 $db->query();
                 if ($pub) {
                     DJClassifiedsNotify::notifyUserPublication($payment->item_id, '1');
                 }
             }
         }
         $payment->status = 'Completed';
         $dispatcher = JDispatcher::getInstance();
         $dispatcher->trigger('onAfterPaymentStatusChange', array($payment));
         $message = JTExt::_('COM_DJCLASSIFIEDS_THANKS_FOR_PAYMENT_WAIT_FOR_CONFIRMATION');
         $redirect = 'index.php?option=com_djclassifieds&view=items&cid=0&Itemid=' . $Itemid;
     } else {
         if ($response->response_reason_text) {
             $message = $response->response_reason_text;
         } else {
             $message = $response->error_message;
         }
         $redirect = 'index.php?option=com_djclassifieds&view=payment&id=' . $id . '&type=' . $type . '&Itemid=' . $Itemid;
         $msg_style = 'Error';
     }
     $app->redirect($redirect, $message, $msg_style);
 }
コード例 #14
0
ファイル: djcfPrzelewy24.php プロジェクト: kidaa30/lojinha
 function _notify_url()
 {
     $db = JFactory::getDBO();
     $par = JComponentHelper::getParams('com_djclassifieds');
     $user = JFactory::getUser();
     $id = JRequest::getInt('id', '0');
     $app = JFactory::getApplication();
     $itemid = JRequest::getInt("Itemid", "");
     $przelewy24_info = $_POST;
     $przelewy24_ipn = new przelewy24_ipn();
     $p24_session_id = $_POST["p24_session_id"];
     $p24_order_id = $_POST["p24_order_id"];
     $p24_id_sprzedawcy = $this->params["p24_id"];
     $query = "SELECT p.*  FROM #__djcf_payments p " . "WHERE p.id='" . $id . "' ";
     $db->setQuery($query);
     $payment = $db->loadObject();
     $p24_kwota = $payment->price * 100;
     //		$p24_kwota = WYNIK POBRANY Z TWOJEJ BAZY (w groszach)
     $res = $przelewy24_ipn->send_response($p24_id_sprzedawcy, $p24_session_id, $p24_order_id, $p24_kwota, $this->params);
     //print_R($res);die();
     if ($res[0] != 'TRUE') {
         $message = JTExt::_('PLG_DJCFPRZELEWY24_AFTER_ERROR_MSG');
         $redirect = 'index.php?option=com_djclassifieds&view=items&cid=0&Itemid=' . $itemid;
         $app->redirect($redirect, $message);
         die;
     } else {
         if ($payment) {
             $query = "UPDATE #__djcf_payments SET status='Completed',transaction_id='" . $p24_session_id . "' " . "WHERE id=" . $id . " AND method='djcfPrzelewy24'";
             $db->setQuery($query);
             $db->query();
             if ($row->type == 3) {
                 //subscription plans
                 $query = "SELECT p.*  FROM #__djcf_plans p WHERE p.id='" . $row->item_id . "' ";
                 $db->setQuery($query);
                 $plan = $db->loadObject();
                 $registry = new JRegistry();
                 $registry->loadString($plan->params);
                 $plan_params = $registry->toObject();
                 //echo '<pre>';print_r($plan_params);die();
                 $date_start = date("Y-m-d H:i:s");
                 $date_exp = '';
                 if ($plan_params->days_limit) {
                     $date_exp_time = time() + $plan_params->days_limit * 24 * 60 * 60;
                     $date_exp = date("Y-m-d H:i:s", $date_exp_time);
                 }
                 $query = "INSERT INTO #__djcf_plans_subscr (`user_id`,`plan_id`,`adverts_limit`,`adverts_available`,`date_start`,`date_exp`,`plan_params`) " . "VALUES ('" . $row->user_id . "','" . $plan->id . "','" . $plan_params->ad_limit . "','" . $plan_params->ad_limit . "','" . $date_start . "','" . $date_exp . "','" . addslashes($plan->params) . "')";
                 $db->setQuery($query);
                 $db->query();
                 $message = JText::_('COM_DJCLASSIFIEDS_STATUS_CHANGED_SUBSCRIPTION_PLAN_ADDED');
             } else {
                 if ($payment->type == 2) {
                     $date_sort = date("Y-m-d H:i:s");
                     $query = "UPDATE #__djcf_items SET date_sort='" . $date_sort . "' " . "WHERE id=" . $payment->item_id . " ";
                     $db->setQuery($query);
                     $db->query();
                 } else {
                     if ($payment->type == 1) {
                         $query = "SELECT p.points  FROM #__djcf_points p WHERE p.id='" . $payment->item_id . "' ";
                         $db->setQuery($query);
                         $points = $db->loadResult();
                         $query = "INSERT INTO #__djcf_users_points (`user_id`,`points`,`description`) " . "VALUES ('" . $payment->user_id . "','" . $points . "','" . JText::_('COM_DJCLASSIFIEDS_POINTS_PACKAGE') . " Przelewy24 <br />" . JText::_('COM_DJCLASSIFIEDS_PAYMENT_ID') . ' ' . $payment->id . "')";
                         $db->setQuery($query);
                         $db->query();
                     } else {
                         $query = "SELECT c.*  FROM #__djcf_items i, #__djcf_categories c " . "WHERE i.cat_id=c.id AND i.id='" . $payment->item_id . "' ";
                         $db->setQuery($query);
                         $cat = $db->loadObject();
                         $pub = 0;
                         if ($cat->autopublish == '1' || $cat->autopublish == '0' && $par->get('autopublish') == '1') {
                             $pub = 1;
                         }
                         $query = "UPDATE #__djcf_items SET payed=1, pay_type='',extra_images_to_pay='0',extra_chars_to_pay='0', published='" . $pub . "' " . "WHERE id=" . $payment->item_id . " ";
                         $db->setQuery($query);
                         $db->query();
                         if ($pub) {
                             DJClassifiedsNotify::notifyUserPublication($payment->item_id, '1');
                         }
                     }
                 }
             }
             $payment->status = 'Completed';
             $dispatcher = JDispatcher::getInstance();
             $dispatcher->trigger('onAfterPaymentStatusChange', array($payment));
         }
     }
     $message = JTExt::_('PLG_DJCFPRZELEWY24_AFTER_SUCCESSFULL_MSG');
     $redirect = 'index.php?option=com_djclassifieds&view=items&cid=0&Itemid=' . $itemid;
     $app->redirect($redirect, $message);
 }
コード例 #15
0
ファイル: payments.php プロジェクト: kidaa30/lojinha
 function changeStatus()
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     $ids = JRequest::getVar('cid', array(), '', 'array');
     $row = JTable::getInstance('Payments', 'DJClassifiedsTable');
     if (isset($ids[0])) {
         $id = $ids[0];
         $status = JRequest::getVar('change_status_' . $id, '');
     } else {
         $redirect = 'index.php?option=com_djclassifieds&view=payments';
         $app->redirect($redirect, JText::_('COM_DJCLASSIFIEDS_WRONG_PAYMENT'));
     }
     $row->load($id);
     if ($row->type == 3) {
         //subscription plans
         $query = "SELECT p.*  FROM #__djcf_plans p WHERE p.id='" . $row->item_id . "' ";
         $db->setQuery($query);
         $plan = $db->loadObject();
         $registry = new JRegistry();
         $registry->loadString($plan->params);
         $plan_params = $registry->toObject();
         //echo '<pre>';print_r($plan_params);die();
         if ($status == 'Completed' && $row->status != 'Completed') {
             $date_start = date("Y-m-d H:i:s");
             $date_exp = '';
             if ($plan_params->days_limit) {
                 $date_exp_time = time() + $plan_params->days_limit * 24 * 60 * 60;
                 $date_exp = date("Y-m-d H:i:s", $date_exp_time);
             }
             $query = "INSERT INTO #__djcf_plans_subscr (`user_id`,`plan_id`,`adverts_limit`,`adverts_available`,`date_start`,`date_exp`,`plan_params`) " . "VALUES ('" . $row->user_id . "','" . $plan->id . "','" . $plan_params->ad_limit . "','" . $plan_params->ad_limit . "','" . $date_start . "','" . $date_exp . "','" . addslashes($plan->params) . "')";
             $db->setQuery($query);
             $db->query();
             $message = JText::_('COM_DJCLASSIFIEDS_STATUS_CHANGED_SUBSCRIPTION_PLAN_ADDED');
         }
     } else {
         if ($row->type == 2) {
             //promotion move to top
             if ($status == 'Completed') {
                 $item = JTable::getInstance('Items', 'DJClassifiedsTable');
                 $item->load($row->item_id);
                 $item->date_sort = date("Y-m-d H:i:s");
                 $message = JText::_('COM_DJCLASSIFIEDS_STATUS_CHANGED_PROMOTION_MOVE_TO_TOP_ACTIVATED');
                 if (!$item->store()) {
                     echo $row->getError();
                     exit;
                 }
             }
         } else {
             if ($row->type == 1) {
                 //points package
                 $query = "SELECT p.points  FROM #__djcf_points p WHERE p.id='" . $row->item_id . "' ";
                 $db->setQuery($query);
                 $points = $db->loadResult();
                 //echo '<pre>';print_r($row);die();
                 if ($status == 'Completed' && $row->status != 'Completed') {
                     $query = "INSERT INTO #__djcf_users_points (`user_id`,`points`,`description`) " . "VALUES ('" . $row->user_id . "','" . $points . "','" . JText::_('COM_DJCLASSIFIEDS_POINTS_PACKAGE') . " " . $row->method . " " . JText::_('COM_DJCLASSIFIEDS_PAYMENT_ID') . " " . $row->id . " " . JText::_('COM_DJCLASSIFIEDS_COMPLETED') . "')";
                     $db->setQuery($query);
                     $db->query();
                     $message = JText::_('COM_DJCLASSIFIEDS_STATUS_CHANGED_POINTS_PACKAGE_ADDED');
                 } else {
                     if ($status != 'Completed' && $row->status == 'Completed') {
                         $query = "INSERT INTO #__djcf_users_points (`user_id`,`points`,`description`) " . "VALUES ('" . $row->user_id . "','-" . $points . "','" . JText::_('COM_DJCLASSIFIEDS_POINTS_PACKAGE') . " " . $row->method . " " . JText::_('COM_DJCLASSIFIEDS_PAYMENT_ID') . " " . $row->id . " " . $status . "')";
                         $db->setQuery($query);
                         $db->query();
                         $message = JText::_('COM_DJCLASSIFIEDS_STATUS_CHANGED_POINTS_PACKAGE_DELETED');
                     }
                 }
             } else {
                 //advert
                 $item = JTable::getInstance('Items', 'DJClassifiedsTable');
                 $item->load($row->item_id);
                 if ($status == 'Completed') {
                     $item->payed = 1;
                     $item->pay_type = '';
                     $item->published = 1;
                     $item->extra_images_to_pay = 0;
                     $message = JText::_('COM_DJCLASSIFIEDS_STATUS_CHANGED_ADVERT_PUBLISHED');
                     DJClassifiedsNotify::notifyUserPublication($item->id, '1');
                 } else {
                     if ($row->status == 'Completed') {
                         $item->published = 0;
                         $message = JText::_('COM_DJCLASSIFIEDS_STATUS_CHANGED_ADVERT_UNPUBLISHED');
                     }
                 }
                 if (!$item->store()) {
                     echo $row->getError();
                     exit;
                 }
             }
         }
     }
     //echo '<pre>';print_r($row);die();
     $row->status = $status;
     if (!$row->store()) {
         echo $row->getError();
         exit;
     }
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onAfterPaymentStatusChange', array($row));
     $redirect = 'index.php?option=com_djclassifieds&view=payments';
     $app->redirect($redirect, $message);
 }