Exemple #1
0
 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);
 }
Exemple #2
0
 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;
 }
Exemple #3
0
 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();
     }
 }
Exemple #4
0
 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);
 }
Exemple #5
0
 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);
 }
Exemple #6
0
 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);
 }
Exemple #7
0
 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);
 }