Skip to content
Snippets Groups Projects
Commit 67f937ca authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Version 0.9: Everything seems to be working, needs some more testing...

parent 034e79ee
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@ if (!class_exists('vmCustomPlugin')) require(JPATH_VM_PLUGINS . DS . 'vmcustompl
if(!class_exists('VmTable'))require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'vmtable.php');
class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
var $status_allowed = array ('S', 'C');
function __construct(& $subject, $config) {
parent::__construct($subject, $config);
......@@ -44,10 +45,6 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
return $db->loadObject();
}
function hasBoughtItem ($uid, $customitem) {
}
function checkDownloadable ($field, &$output) {
$userId = (int) JFactory::getUser()->get('id');
if ($field->download_type == 'free_download') {
......@@ -58,18 +55,28 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
}
return ($userId>0);
} elseif ($field->download_type == 'paid_download') {
// if ($this->hasBoughtItem ($userId, $field->
// TODO: check whether the logged-in user has bought the product or the correct ordernumber/password is given
$order_number = JRequest::getString('order_number', null);//JRequest::getString('username', null, 'GET', JREQUEST_ALLOWRAW);
$order_number = JRequest::getString('order_number', null);
$order_pass = JRequest::getString('order_pass', null);
$orderModel = VmModel::getModel('orders');
$order_id = $orderModel->getOrderIdByOrderPass ($order_number, $order_pass);
if (!order_id) {
if ($order_id) {
$order = $orderModel->getOrder($order_id);
if ($order && in_array($order['details']['BT']->order_status, $this->status_allowed)) {
foreach ($order['items'] as $i) {
if ($i->virtuemart_product_id == $field->virtuemart_product_id) {
if (in_array($i->order_status, $this->status_allowed)) {
return $i->virtuemart_order_item_id;
} else {
JFactory::getApplication()->enqueueMessage(JText::_('VMCUSTOM_DLSALE_ERROR_STATUS_NOT_AUTHORIZED'), 'error');
}
}
}
} else {
JFactory::getApplication()->enqueueMessage(JText::_('VMCUSTOM_DLSALE_ERROR_STATUS_NOT_AUTHORIZED'), 'error');
}
} else {
JFactory::getApplication()->enqueueMessage(JText::_('VMCUSTOM_DLSALE_ERROR_WRONG_PASSWD'), 'error');
return false;
}
return $order_id;
}
return false;
}
......@@ -125,63 +132,13 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
return false;
}
// print("<pre>checkDownloadable</pre>");
if ($this->checkDownloadable ($field, $render)) {
// print("<pre>checkDownloadable SUCCESS</pre>");
$this->downloadFile ($field->media_id, $render);
// } else {
// print("<pre>checkDownloadable FAILURE</pre>");
}
}
/*
$dlkey = JRequest::getString('dlkey', 0);
$dloid = JRequest::getInt('oid', 0);
if ( !$order =$this->getOrderData( $dlkey, $dloid ) ) {
vmInfo(JText::_('VMCUSTOM_SPIRAL_DOWNLOAD_NO_FILE_FOUND'));
return ;
}
$order_status = $order['order_status'];
$params = $this->getMediaParams($custom_id, $order['virtuemart_product_id']);
$status = $params->orderstatus;
if(empty($status))
{
$paramStatus = array("C","S");
}
else
{
$paramStatus = (array)$params->orderstatus;
}
//if(empty($paramStatus))
//vmDebug('plgVmOnSelfCallFE - params',$params);
if (in_array($order_status,$paramStatus)) {
$orderdata = new stdClass();
$orderdata->virtuemart_order_id = $order['virtuemart_order_id'];
$orderdata->virtuemart_order_item_id = $dloid;
$orderdata->created_on = $order['created_on'];
//update downloads table
if ($this->checkDownloadTable($orderdata,$custom_id,$params))
{
$orderModel = VmModel::getModel('orders');
$orderdata->order_status = 'S';
$orderModel->updateSingleItem($dloid,$orderdata);
return $this->startDownload($params->media_id, $output);
}
else
{
vmInfo(JText::_('VMCUSTOM_SPIRAL_DOWNLOAD_EXPIRED'));
}
} else vmInfo(JText::_('VMCUSTOM_SPIRAL_DOWNLOAD_PAYMENT_NOT_CONFIRMED'));
return;
}
*/
/**
* plgVmOnSelfCallBE ... Called to execute some plugin action in the backend (e.g. set/reset dl counter etc.
* plgVmOnSelfCallBE ... Called to execute some plugin action in the backend (e.g. set/reset dl counter, show statistics etc.)
*/
/* function plgVmOnSelfCallBE($type, $name, &$output) {
if ($name != $this->_name || $type != 'vmcustom') return false;
......@@ -216,7 +173,9 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
$link_types = array('none' => 'VMCUSTOM_DLSALE_LINK_NONE', 'text'=>'VMCUSTOM_DLSALE_LINK_TEXT', 'image'=>'VMCUSTOM_DLSALE_LINK_IMAGE');
$html .= VmHTML::row('select', 'VMCUSTOM_DLSALE_DOWNLOAD_FILE', 'custom_param['.$row.'][media_id]', $download_files, $field->media_id,'','virtuemart_media_id', 'file_title', false);
$html .= VmHTML::row ('select','VMCUSTOM_DLSALE_INVOICE_LINK', 'custom_param['.$row.'][invoice_link_type]',$link_types,$field->invoice_link_type, '', '', '', false);
if ($field->is_cart_attribute) {
$html .= VmHTML::row ('select','VMCUSTOM_DLSALE_INVOICE_LINK', 'custom_param['.$row.'][invoice_link_type]',$link_types,$field->invoice_link_type, '', '', '', false);
}
$html .= VmHTML::row ('select','VMCUSTOM_DLSALE_PRODUCT_LINK', 'custom_param['.$row.'][product_link_type]',$link_types,$field->product_link_type, '', '', '', false);
$html .= VmHTML::row('select', 'VMCUSTOM_DLSALE_TYPE', 'custom_param['.$row.'][download_type]',
array('free_download'=>'VMCUSTOM_DLSALE_TYPE_FREE', 'registered_download'=>'VMCUSTOM_DLSALE_TYPE_REGISTERED', 'paid_download'=>'VMCUSTOM_DLSALE_TYPE_PAID'),
......@@ -233,21 +192,19 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
$url = JURI::root().'index.php?option=com_virtuemart&view=plugin&name=downloads_for_sale&customfield_id='.(int)$field->virtuemart_customfield_id;
$_currentUser = JFactory::getUser();
$cuid = $_currentUser->get('id');
$this->parseCustomParams($field);
switch ($field->download_type) {
case 'free_download': break;
case 'registered_download': break;
case 'registered_download': if ($cuid<=0) return false; break;
case 'paid_download':
if ($orderitem) {
$order = $this->orderDataFromItem ($orderitem->virtuemart_order_item_id);
} elseif ($cuid>0) {
$orderModel = VmModel::getModel('orders');
$orderList = $orderModel->getOrdersList($cuid, true);
foreach ($orderList as $ol) {
foreach ($orderModel->getOrdersList($cuid, true) as $ol) {
$o = $orderModel->getOrder($ol->virtuemart_order_id);
foreach ($o['items'] as $i) {
if ($i->virtuemart_product_id == $field->virtuemart_product_id) {
if ($i->virtuemart_product_id == $field->virtuemart_product_id && in_array($i->order_status, $this->status_allowed)) {
$order = $o['details']['BT'];
}
}
......@@ -256,12 +213,11 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
if (empty($order)) {
return false;
}
print("<pre>order= ".print_r($order,true)."</pre>");
$url .= '&order_number='.urlencode($order->order_number).'&order_pass='.urlencode($order->order_pass);
break;
}
$media = $this->getDownloadFile ($field->media_id);
return $this->renderByLayout($view.'_'.$type, array($field, $media, $url));
return $this->renderByLayout($view.'_'.$type, array($url, $field, $media));
}
/**
......@@ -288,15 +244,20 @@ print("<pre>order= ".print_r($order,true)."</pre>");
/**
* plgVmOnDisplayProductFE ... Called for NON-product variant custom fields to display on the product details page
*/
function plgVmOnDisplayProductFE( $product, &$idx,&$group){
function plgVmOnDisplayProductFE( $product, &$idx,&$field){
// default return if it's not this plugin
if ($field->custom_element != $this->_name) return '';
$group->display .= "<h1>plgVmOnDisplayProductFE</h1>";
$this->getCustomParams($field);
$this->parseCustomParams($field);
$type = $field->product_link_type;
if ($type != 'none') {
$group->display .= $this->createDownloadLink($field, "product", $type);
return true;
// The $field for non-cart-variant fields does NOT have the product_id set!
$field->virtuemart_product_id = $product->virtuemart_product_id;
$ret = $this->createDownloadLink($field, "product", $type);
if (!empty($ret)) {
$field->display .= $ret;
return true;
} else
return false;
} else {
return false;
}
......@@ -324,43 +285,17 @@ $group->display .= "<h1>plgVmOnDisplayProductFE</h1>";
*/
function plgVmDisplayInOrderFE($item, $row, &$html) {
if (empty($item->productCustom->custom_element) or $item->productCustom->custom_element != $this->_name) return '';
$this->parseCustomParams($item->productCustom);
// print("<pre>plgVmDisplayInOrderFE, item=".print_r($item,true)."</pre>");
$type = $item->productCustom->product_link_type;
if ($type != 'none') {
$html .= $this->createDownloadLink($item->productCustom, "product", $type, $item);
$html .= $this->createDownloadLink($item->productCustom, "order", $type, $item);
return true;
} else {
return false;
}
}
/*
$_currentUser = JFactory::getUser();
$cuid = $_currentUser->get('id');
$orderModel = VmModel::getModel('orders');
$orderList = $orderModel->getOrdersList($cuid, true);
foreach ($orderList as $o) {
$order = $orderModel->getOrder($o->virtuemart_order_id);
foreach ($order['items'] as $i) {
if ($i->virtuemart_product_id == $field->virtuemart_product_id) {
$downloadInfo = $this->getDownloadInfo($order['details']['BT']->virtuemart_order_id, $i->virtuemart_order_item_id, $field->value, $order['details']['BT']->created_on, $field );
if(!$downloadInfo->downloadsExpired) {
$url = JURI::root().'index.php?option=com_virtuemart&view=plugin&name=downloads_for_sale&custom_id='.$field->value . '&dlkey='.base64_encode($order['details']['BT']-> ).'&oid='.$i->virtuemart_order_item_id ;
$html .= JHTML::link ( $url, JTEXT::_('VMCUSTOM_DLSALE_LINK') , array ('title' => $media->title, 'class' => 'dlink' ) );
} else {
$html .= '<p><strong>'.JText::_('VMCUSTOM_DLSALE_EXPIRED_INFO').'</strong></p>';
}
}
}
}
*/
/**
* We must reimplement this triggers for joomla 1.7
* vmplugin triggers note by Max Milbers
......@@ -391,8 +326,7 @@ $group->display .= "<h1>plgVmOnDisplayProductFE</h1>";
}
function getTableSQLFields() {
/*
$SQLfields = array(
/* $SQLfields = array(
'id' => 'int(1) UNSIGNED NOT NULL AUTO_INCREMENT',
'virtuemart_customfield_id' => 'int(11) UNSIGNED NOT NULL DEFAULT 0',
'downloaded' => 'int(11) UNSIGNED NOT NULL DEFAULT 0',
......
downloads_for_sale/download_medium.png

4.47 KiB

downloads_for_sale/download_small.png

1.5 KiB

......@@ -9,7 +9,5 @@
*
**/
defined('_JEXEC') or die();
?>
<h1>IMAGE LINK</h1>
defined('_JEXEC') or die();
?><a href="<?php echo $viewData[0]; ?>"><img height="16" src="<?php echo JURI::root().'plugins/vmcustom/downloads_for_sale/downloads_for_sale/download_medium.png'; ?>" alt="Download"> <?php echo $viewData[2]->file_title; ?></a>
<?php
/**
*
* @author Reinhold Kainhofer
* @package VirtueMart
* @subpackage custom
......@@ -9,7 +8,6 @@
*
**/
defined('_JEXEC') or die();
defined('_JEXEC') or die();
?>
<h1>TEXT LINK</h1>
?>Download: <a href="<?php echo $viewData[0]; ?>"><?php echo $viewData[2]->file_title; ?></a>
......@@ -9,9 +9,8 @@
*
**/
defined('_JEXEC') or die();
defined('_JEXEC') or die();
?>
<h1>IMAGE LINK</h1><pre>
<?php // print_r($viewData) ?></pre>
<a href="<?php echo $viewData[2]; ?>">Download</a>
<div class="download-for-sale-image">
<a href="<?php echo $viewData[0]; ?>"><img style="vertical-align:middle; display: inline;" src="<?php echo JURI::root().'plugins/vmcustom/downloads_for_sale/downloads_for_sale/download_medium.png'; ?>" alt="<?php echo $viewData[2]->file_title; ?>"></a></div>
<br clear="all"/>
......@@ -9,9 +9,6 @@
*
**/
defined('_JEXEC') or die();
defined('_JEXEC') or die();
?>
<h1>TEXT LINK</h1>
<?php print_r($viewData) ?></pre>
<a href="<?php echo $viewData[2]; ?>">Download</a>
<p><img style="vertical-align:middle; display: inline;" src="<?php echo JURI::root().'plugins/vmcustom/downloads_for_sale/downloads_for_sale/download_small.png'; ?>" alt=""/> <a href="<?php echo $viewData[0]; ?>"><?php echo $viewData[2]->file_title; ?></a></p>
......@@ -30,4 +30,4 @@ VMCUSTOM_DLSALE_ERROR_LOAD_FAILURE="Unable to load custom field data."
VMCUSTOM_DLSALE_ERROR_NO_FILE_SET="Media file is not available."
VMCUSTOM_DLSALE_ERROR_ORDER_NOT_FOUND="Unable to find order data in database."
VMCUSTOM_DLSALE_ERROR_WRONG_PASSWD="Invalid combination of order number and password."
VMCUSTOM_DLSALE_ERROR_STATUS_NOT_AUTHORIZED="Order status does not allow download."
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment