public function pay() { $user = JFactory::getUser(); if ($user->guest) { die("Yêu cầu đăng nhập để mua"); } else { $user_id = $user->id; $image_id = JRequest::getVar("id"); $db = JFactory::getDBO(); $db->setQuery("SELECT imgtitle, owner, catid, imgfilename FROM #__joomgallery WHERE id = " . $image_id); $image = $db->loadObject(); $image_name = $image->imgtitle; $author = $image->owner; $price = JoomHelper::getAdditional($image_id, "price"); $db->setQuery("INSERT INTO #__orders(user_id, image_id, image_name, author, price, buy_date) VALUES (" . $user_id . ", " . $image_id . ", '" . $image_name . "', " . $author . ", " . $price . ", NOW())"); $db->query(); $db->setQuery("UPDATE #__users SET balance = balance - " . (int) $price . " WHERE id = " . $user_id); $db->query(); $catPath = JoomHelper::getCatPath($image->catid); $catPath1 = str_replace("/", DIRECTORY_SEPARATOR, $catPath); $path = JPATH_ROOT . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'joomgallery' . DIRECTORY_SEPARATOR . 'originals' . DIRECTORY_SEPARATOR . $catPath1 . $image->imgfilename; $owner = JFactory::getUser($author); $app = JFactory::getApplication(); $mailfrom = $app->get('mailfrom'); $fromname = $app->get('fromname'); $sitename = $app->get('sitename'); $body = "Xin chào " . $owner->name . "<br/><br/>\n\t\t\tĐây là hình mà bạn đã mua từ Khoảnh khắc Việt Nam:<br/>\n\t\t\t- Tên: " . $image_name . "<br/>\n\t\t\t- Tác giả: " . $owner->name . "<br/>\n\t\t\t- Giá: " . number_format($price, 0, ',', '.') . "<br/><br/>\n\t\t\tKhoảnh khắc Việt Nam\n\t\t\t"; $mail = JFactory::getMailer(); $mail->addRecipient($user->email); $mail->addCC($owner->email); $mail->setSender(array($mailfrom, $fromname)); $mail->setSubject($sitename . ': ' . $image_name); $mail->setBody($body); $mail->IsHTML(true); $mail->AddAttachment($path, $image->imgfilename); $sent = $mail->Send(); //Push notification to android device $db->setQuery("SELECT gcm_id FROM #__users_gsm WHERE user_id = " . $author . " AND login_state = 1"); $gcms = $db->loadColumn(); foreach ($gcms as $gcm) { // prep the bundle $msg = array('message' => 'test', 'user_id' => $user_id, 'author' => $author); $fields = array('registration_ids' => $gcm, 'data' => $msg); $headers = array('Authorization: key=AIzaSyA0r0rtbBIUXi2uU6oqRZ5TSbkeBGWYje8', 'Content-Type: application/json'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://android.googleapis.com/gcm/send'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); $result = curl_exec($ch); curl_close($ch); } $this->setRedirect(JRoute::_('index.php?option=com_recharge&view=cart&layout=success')); } }
<td><a href="<?php echo $link; ?> "><img src="index.php?option=com_joomgallery&view=image&format=raw&type=thumb&id=<?php echo $order->image_id; ?> " alt="" class="thumbnail"></a></td> <td><a href="<?php echo $link; ?> "><?php echo $order->image_name; ?> </a></td> <td><?php echo JoomHelper::getAdditional($order->image_id, "code"); ?> </td> <td><?php echo JHtml::_('date', $order->buy_date, 'H:i d-m-Y'); ?> </td> <td class="text-right strong-me"><?php echo number_format($order->price, 0, ",", "."); ?> </td> </tr> <?php } ?> </tbody>
echo $this->image->id; ?> " class="btn btn-warning btn-blue btn-big btn-sm strong-me text-uppercase">Mua tác phẩm</a> <?php } } ?> </div> </div> <div class="m10t clearfix"> <a class="pull-left btn-action active"> <div class="icon-action pull-left"> <span class="glyphicon glyphicon-thumbs-up" aria-hidden="true"></span> <span class="text-nowrap des"><?php echo JoomHelper::getAdditional($this->image->id, "like"); ?> </span> </div> </a> <?php if (!$user->guest) { ?> <?php if (!$isOwner) { ?> <a href="<?php echo $fav_link; ?> " class="pull-left btn-action <?php if ($favourite) {
?> </td> <td><?php echo JHtml::_('joomgallery.categorypath', $item->catid, true, ' » ', false, false, true); ?> </td> <td><?php echo $orig_info[0] . 'x' . $orig_info[1]; ?> </td> <td><?php echo JoomHelper::getTags($item->id); ?> </td> <td class="text-right"><strong><?php echo number_format(JoomHelper::getAdditional($item->id, "price"), 0, ",", "."); ?> </strong> vnđ</td> <td> <?php if ($item->published) { ?> <a class="btn btn-sm btn-default" href="<?php echo JRoute::_('index.php?task=image.publish&id=' . $item->id . $this->slimitstart); ?> ">Ẩn hình<span class="glyphicon glyphicon-download" aria-hidden="true"></span></a> <?php } else { ?> <a class="btn btn-sm btn-success" href="<?php echo JRoute::_('index.php?task=image.publish&id=' . $item->id . $this->slimitstart);
<span class="label pull-left">Tổng giá tiền cần phải trả:</span> <span class="text-right pull-left fs18 orange-me strong-me"><?php echo number_format(JoomHelper::getAdditional($image->id, "price"), 0, ",", "."); ?> </span> </div> <div class="clearfix"> <span class="label pull-left">Tiền trong tài khoản:</span> <span class="text-right pull-left"><?php echo number_format($user->balance, 0, ",", "."); ?> </span> </div> <div class="clearfix"> <span class="label pull-left">Tiền còn lại sau khi mua:</span> <span class="text-right pull-left"><?php echo number_format((int) $user->balance - (int) JoomHelper::getAdditional($image->id, "price"), 0, ",", "."); ?> </span> </div> <a class="btn btn-warning btn-blue btn-lg strong-me text-uppercase pull-right m10t fs14" href="index.php?option=com_recharge&task=cart.pay&id=<?php echo $id; ?> ">Thanh Toán</a> </div> </div> </div> </div> </div> </div> </div>