diff --git a/downloads_for_sale.php b/downloads_for_sale.php index 0fd1b15b02b71b248aa785c3e72cf297c5349ad5..ddbdbec597529b240c0626e391a96ed93e2f2f0a 100644 --- a/downloads_for_sale.php +++ b/downloads_for_sale.php @@ -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', diff --git a/downloads_for_sale/download_medium.png b/downloads_for_sale/download_medium.png new file mode 100644 index 0000000000000000000000000000000000000000..7204fe9511a6ee4f72692288dcdbf2ff4483d1c0 Binary files /dev/null and b/downloads_for_sale/download_medium.png differ diff --git a/downloads_for_sale/download_small.png b/downloads_for_sale/download_small.png new file mode 100644 index 0000000000000000000000000000000000000000..102b11bb4ce22b1119bf9a6e22b3271bb5ae8388 Binary files /dev/null and b/downloads_for_sale/download_small.png differ diff --git a/downloads_for_sale/tmpl/order_image.php b/downloads_for_sale/tmpl/order_image.php index 3568bd91ebaa56d272eff877fc41975f1ef4e2d6..caa3e6eeebe69286191d38496cf618384b85879e 100644 --- a/downloads_for_sale/tmpl/order_image.php +++ b/downloads_for_sale/tmpl/order_image.php @@ -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> diff --git a/downloads_for_sale/tmpl/order_text.php b/downloads_for_sale/tmpl/order_text.php index adb0260da4bd1b27a63a55b3ef1773ff6e7cac0c..3259a38990b5c79e23e08318c9a8aaf09ef615ed 100644 --- a/downloads_for_sale/tmpl/order_text.php +++ b/downloads_for_sale/tmpl/order_text.php @@ -1,6 +1,5 @@ <?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> diff --git a/downloads_for_sale/tmpl/product_image.php b/downloads_for_sale/tmpl/product_image.php index aba5d2be7cf82e0d469e06fb7d1e47e01eaa8ccc..1de1c165af10f526ddb757993a7c82370baa26df 100644 --- a/downloads_for_sale/tmpl/product_image.php +++ b/downloads_for_sale/tmpl/product_image.php @@ -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"/> diff --git a/downloads_for_sale/tmpl/product_text.php b/downloads_for_sale/tmpl/product_text.php index afca31f645a33f18691353f211a739bfd44a15e2..0f2ec55bf6e27367e0cf801c24250e9837263b19 100644 --- a/downloads_for_sale/tmpl/product_text.php +++ b/downloads_for_sale/tmpl/product_text.php @@ -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> diff --git a/en-GB.plg_vmcustom_downloads_for_sale.ini b/en-GB.plg_vmcustom_downloads_for_sale.ini index 7d6c6d99e57acbca96aa95ef79442802261abe8b..01a7e005040da04c04a0d68f862d632d73798263 100644 --- a/en-GB.plg_vmcustom_downloads_for_sale.ini +++ b/en-GB.plg_vmcustom_downloads_for_sale.ini @@ -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."