function getPriceDesc(&$subscription, $showType = 'default', $balance = 0, $amount = 0)
 {
     global $JLMS_CONFIG;
     if (!isset($subscription->p1)) {
         $obj = JLMS_RECURRENT_PAY::getObjByReccSubsId($subscription->id);
         foreach (get_object_vars($obj) as $key => $value) {
             $subscription->{$key} = $value;
         }
     }
     /* else {
     			$obj = php4_clone( $subscription );	
     		}	
     		*/
     JLMS_RECURRENT_PAY::initPricesObjects($subscription);
     JLMS_RECURRENT_PAY::recalcSubsParams($subscription, $showType, $balance, $amount);
     $marks = array('{a1}' => $subscription->price1->getCalcPath(), '{a2}' => $subscription->price2->getCalcPath(), '{a3}' => $subscription->price3->getCalcPath(), '{p1}' => $subscription->price1->get('p'), '{p2}' => $subscription->price2->get('p'), '{p3}' => $subscription->price3->get('p'));
     $marks['{free}'] = "";
     $marks['{then}'] = "";
     $marks['{next}'] = "";
     $marks['{srt}'] = $subscription->price3->get('srt');
     $part1 = $part2 = $part3 = $part4 = '';
     $marks['{cur}'] = $JLMS_CONFIG->get('jlms_cur_code');
     if ($subscription->price1->showPrice() || $subscription->price1->isPeriodTrial()) {
         if ($subscription->price1->isPeriodTrial()) {
             $marks['{free}'] = _JLMS_RECURRENT_PAYMENT_FREE;
             $marks['{a1}'] = "";
             $marks['{cur}'] = "";
         }
         if ($subscription->price1->get('p') == 1) {
             $part1 = strtr(_JLMS_RECURRENT_PAYMENT_FIRST_DAY, $marks);
         } else {
             $part1 = strtr(_JLMS_RECURRENT_PAYMENT_FIRST_DAYS, $marks);
         }
         $part1 .= "<br />";
     }
     $marks['{cur}'] = $JLMS_CONFIG->get('jlms_cur_code');
     $marks['{free}'] = "";
     if ($subscription->price2->showPrice()) {
         if ($subscription->price1->showPrice() || $subscription->price1->isPeriodTrial()) {
             $marks['{then}'] = _JLMS_RECURRENT_PAYMENT_THEN;
             $marks['{next}'] = _JLMS_RECURRENT_PAYMENT_THE_NEXT;
         }
         if ($subscription->price2->get('p') == 1) {
             $part2 = strtr(_JLMS_RECURRENT_PAYMENT_NEXT_DAY, $marks);
         } else {
             $part2 = strtr(_JLMS_RECURRENT_PAYMENT_NEXT_DAYS, $marks);
         }
         $part2 .= "<br />";
     }
     $marks['{cur}'] = $JLMS_CONFIG->get('jlms_cur_code');
     if ($subscription->src && $subscription->price3->get('srt') > 0) {
         if ($subscription->price1->showPrice() || $subscription->price2->showPrice()) {
             $marks['{then}'] = _JLMS_RECURRENT_PAYMENT_THEN;
         } else {
             $marks['{then}'] = '';
         }
         if ($subscription->price3->get('a')) {
             if ($subscription->price3->get('p') == 1) {
                 $part4 = strtr(_JLMS_RECURRENT_PAYMENT_INSTALLMENTS, $marks);
             } else {
                 $part4 = strtr(_JLMS_RECURRENT_PAYMENT_INSTALLMENTS_DAYS, $marks);
             }
             $part4 .= "<br />";
         }
     } else {
         if ($subscription->src) {
             if ($subscription->price1->showPrice() || $subscription->price2->showPrice()) {
                 $marks['{then}'] = _JLMS_RECURRENT_PAYMENT_THEN;
             } else {
                 $marks['{then}'] = '';
             }
             if ($subscription->price3->get('a')) {
                 if ($subscription->price3->get('p') == 1) {
                     $part4 = strtr(_JLMS_RECURRENT_PAYMENT_FOREACH, $marks);
                 } else {
                     $part4 = strtr(_JLMS_RECURRENT_PAYMENT_FOREACH_DAYS, $marks);
                 }
                 $part4 .= "<br />";
             }
         } else {
             if ($subscription->price1->showPrice() || $subscription->price2->showPrice()) {
                 $marks['{then}'] = _JLMS_RECURRENT_PAYMENT_THEN;
             } else {
                 $marks['{then}'] = '';
             }
             if ($subscription->price3->get('a')) {
                 if ($subscription->price3->get('p') == 1) {
                     $part3 = strtr(_JLMS_RECURRENT_PAYMENT_ONE_DAY, $marks);
                 } else {
                     $part3 = strtr(_JLMS_RECURRENT_PAYMENT_MORE_DAYS, $marks);
                 }
                 $part3 .= "<br />";
             }
         }
     }
     $res = $part1 . $part2 . $part3 . $part4;
     return $res;
 }
Esempio n. 2
0
    function show_checkout($option, $subscription, $item_id, $proc)
    {
        global $Itemid, $JLMS_CONFIG, $JLMS_DB;
        $params = new JLMSParameters($proc->params);
        if (!$params->get('server_url') || !$params->get('business_email')) {
            $redirect_task = 'subscription';
            if ($subscription->payment_type == 2) {
                $redirect_task = 'show_cart';
            }
            JLMSredirect(sefRelToAbs("index.php?option=" . $option . "&Itemid=" . $Itemid . "&task={$redirect_task}"), "This payment method is not available at the moment.<br /> Ask site administrator to check payment method settings.");
        }
        //setcookie('joomlalms_cart_contents', '', time()-3600, '/');
        JLMSCookie::setcookie('joomlalms_cart_contents', '$current_cart_cookie', time() - 3600, '/');
        global $JLMS_DB;
        $subscr_ids = implode(',', $subscription->subscriptions);
        if (!$subscription->sub_name && count($subscription->subscriptions) && (strpos($params->get('item_name'), '[sub]') !== false || strpos($params->get('item_name'), '[SUB]') !== false)) {
            $query = "SELECT id, sub_name FROM #__lms_subscriptions WHERE id IN ({$subscr_ids})";
            $JLMS_DB->SetQuery($query);
            $subs_names_list_db = $JLMS_DB->LoadObjectList();
            //create item name from list of all subscriptions separated by comma, ordered as in cart
            $subs_names_list = array();
            foreach ($subscription->subscriptions as $cart_sub_id) {
                foreach ($subs_names_list_db as $subname_item) {
                    if ($subname_item->id == $cart_sub_id) {
                        $subs_names_list[] = $subname_item->sub_name;
                        break;
                    }
                }
            }
            $subscription->sub_name = implode(', ', $subs_names_list);
        }
        if ($subscription->payment_type) {
            $query = "SELECT course_id FROM #__lms_subscriptions_courses WHERE sub_id IN (" . $subscr_ids . ")";
            $JLMS_DB->SetQuery($query);
            $courses = $JLMS_DB->LoadResultArray();
        } else {
            $courses = array();
        }
        $where = '';
        $whereacc = '';
        $where .= " AND ps.subscr_id IN (" . $subscr_ids . ")";
        $query = "SELECT p.id, p.name, p.description, p.published, p.p1, p.t1, p.p2, p.t2, p.p3, p.t3, s.a1, s.a2, s.a3, p.sra, p.src, p.srt, p.params" . "\n FROM #__lms_plans_subscriptions ps, #__lms_plans p, #__lms_subscriptions s" . "\n WHERE s.id=ps.subscr_id AND ps.plan_id=p.id AND s.account_type=6" . $where;
        $JLMS_DB->setQuery($query);
        $plan = $JLMS_DB->loadObject();
        if (is_object($plan)) {
            $plan->tax = $subscription->tax;
            $plan->tax_type = $subscription->tax_type;
            JLMS_RECURRENT_PAY::initPricesObjects($plan);
        }
        //check if there is subscription with account_type==4
        $whereacc .= " AND s.id IN (" . $subscr_ids . ")";
        $query = "SELECT s.id, s.access_days" . "\n FROM #__lms_subscriptions s" . "\n WHERE s.account_type=4" . $whereacc;
        $JLMS_DB->setQuery($query);
        $subscriptionAccesses = $JLMS_DB->loadObjectList();
        $adddays = 0;
        if ($subscriptionAccesses) {
            foreach ($subscriptionAccesses as $subscr) {
                $adddays += $subscr->access_days;
            }
        }
        //get user_id
        $query = "SELECT user_id FROM #__lms_payments WHERE id=" . $item_id;
        $JLMS_DB->setQuery($query);
        $uid = $JLMS_DB->loadResult();
        ?>
	<html>	
  	<head>
  		<meta http-equiv="content-type" content="text/html; charset=utf-8" />
  	</head>
	<body onLoad="document.forms.jlms_checkout_form.submit();">
<?php 
        $print_item_name = $params->get('item_name');
        if (strpos($print_item_name, '[sub]') !== false || strpos($print_item_name, '[SUB]') !== false) {
            //compare and repalce both uppercase and lowercase strings (stri_repalce not used for PHP4 compat)
            $print_item_name = str_replace('[sub]', $subscription->sub_name, $print_item_name);
            $print_item_name = str_replace('[SUB]', $subscription->sub_name, $print_item_name);
        }
        if (!$print_item_name) {
            $print_item_name = $subscription->sub_name;
        }
        if (!is_object($plan)) {
            ?>
	<form action="<?php 
            echo $params->get('server_url');
            ?>
" method="post" name="jlms_checkout_form" id="jlms_checkout_form" />
	<input type="hidden" name="cmd" value="_xclick" />
	<input type="hidden" name="business" value="<?php 
            echo $params->get('business_email');
            ?>
" />
	<input type="hidden" name="on0" value="Tax amount" />
	<input type="hidden" name="os0" value="<?php 
            echo $subscription->tax_amount;
            ?>
" />
	<input type="hidden" name="item_number" value="<?php 
            echo $item_id;
            ?>
" />
	<input type="hidden" name="item_name" value="<?php 
            echo $print_item_name;
            ?>
" />
	<input type="hidden" name="no_shipping" value="1" />
<?php 
            if (count($courses) == 1 && $subscription->payment_type == 0) {
                ?>
	<input type="hidden" name="return" value="<?php 
                echo JURI::root();
                ?>
index.php?option=<?php 
                echo $option;
                ?>
&Itemid=<?php 
                echo $Itemid;
                ?>
&task=details_course&id=<?php 
                echo $courses[0];
                ?>
" />
<?php 
            } else {
                ?>

	<input type="hidden" name="return" value="<?php 
                echo JURI::root();
                ?>
index.php?option=<?php 
                echo $option;
                ?>
&Itemid=<?php 
                echo $Itemid;
                ?>
" />
<?php 
                /*
                	<input type="hidden" name="return" value="<?php echo $JLMS_CONFIG->get('live_site');?>/index.php?option=com_joomla_lms&task=callback&trs_id=<?php echo $item_id?>&proc=<?php echo $proc->id;?>" />
                */
            }
            ?>
	<input type="hidden" name="rm" value="2" />
	<input type="hidden" name="cancel_return" value="<?php 
            if ($params->get('cancel_url') == '') {
                echo sefRelToAbs("index.php?option=com_joomla_lms&Itemid=" . $Itemid);
            } else {
                echo $params->get('cancel_url');
            }
            ?>
">
	<input type="hidden" name="notify_url" value="<?php 
            echo JURI::root();
            ?>
index.php?option=com_joomla_lms&task=callback&trs_id=<?php 
            echo $item_id;
            ?>
&proc=<?php 
            echo $proc->id;
            ?>
" />
	<input type="hidden" name="amount" value="<?php 
            echo number_format($subscription->price + $subscription->tax_amount, 2, '.', '');
            ?>
" />
	<input type="hidden" name="currency_code" value="<?php 
            echo $JLMS_CONFIG->get('jlms_cur_code');
            ?>
" />
	<input type="hidden" name="receiver_email" value="<?php 
            echo $params->get('business_email');
            ?>
" />
	<input type="hidden" name="charset" value="utf-8" />
	</form>
<?php 
        } else {
            if ($subscription->recurrent_obj) {
                $plan = $subscription->recurrent_obj;
            }
            ?>
	<form action="<?php 
            echo $params->get('server_url');
            ?>
" method="post" name="jlms_checkout_form" id="jlms_checkout_form">
	<input type="hidden" name="cmd" value="_xclick-subscriptions" />
	<input type="hidden" name="business" value="<?php 
            echo $params->get('business_email');
            ?>
" />
	<input type="hidden" name="item_name" value="<?php 
            echo $print_item_name;
            ?>
" />
	<input type="hidden" name="item_number" value="<?php 
            echo $item_id;
            ?>
" />	
	<input type="hidden" name="no_shipping" value="1" />	
	<input type="hidden" name="rm" value="2" />
	<input type="hidden" name="no_note" value="1" />	
	<input type="hidden" name="currency_code" value="<?php 
            echo $JLMS_CONFIG->get('jlms_cur_code');
            ?>
" />	
	<?php 
            if (count($courses) == 1 && $subscription->payment_type == 0) {
                ?>
	<input type="hidden" name="return" value="<?php 
                echo JURI::root();
                ?>
index.php?option=<?php 
                echo $option;
                ?>
&Itemid=<?php 
                echo $Itemid;
                ?>
&task=details_course&id=<?php 
                echo $courses[0];
                ?>
" />
	<?php 
            } else {
                ?>

	<input type="hidden" name="return" value="<?php 
                echo JURI::root();
                ?>
index.php?option=<?php 
                echo $option;
                ?>
&Itemid=<?php 
                echo $Itemid;
                ?>
" />
	<?php 
                /*
                	<input type="hidden" name="return" value="<?php echo $JLMS_CONFIG->get('live_site');?>/index.php?option=com_joomla_lms&task=callback&trs_id=<?php echo $item_id?>&proc=<?php echo $proc->id;?>" />
                */
                ?>
	<?php 
            }
            ?>
	
	<input type="hidden" name="cancel_return" value="<?php 
            if ($params->get('cancel_url') == '') {
                echo sefRelToAbs("index.php?option=com_joomla_lms&Itemid=" . $Itemid);
            } else {
                echo $params->get('cancel_url');
            }
            ?>
" />
	<input type="hidden" name="notify_url" value="<?php 
            echo JURI::root();
            ?>
index.php?option=com_joomla_lms&task=callback&trs_id=<?php 
            echo $item_id;
            ?>
&proc=<?php 
            echo $proc->id;
            ?>
&subscr=1" />
	<?php 
            //if is basic then no other parameters should be considered
            if ($plan->price1->showPrice() || $plan->price1->isPeriodTrial()) {
                ?>
		<input type="hidden" name="a1" value="<?php 
                echo $plan->price1->get('a');
                ?>
"/>
		<input type="hidden" name="p1" value="<?php 
                echo $plan->price1->get('p');
                ?>
"/>
		<input type="hidden" name="t1" value="<?php 
                echo $plan->t1;
                ?>
"/>
		<?php 
            }
            if ($plan->price2->showPrice()) {
                ?>
		<input type="hidden" name="a2" value="<?php 
                echo $plan->price2->get('a');
                ?>
"/>
		<input type="hidden" name="p2" value="<?php 
                echo $plan->price2->get('p');
                ?>
"/>
		<input type="hidden" name="t2" value="<?php 
                echo $plan->t2;
                ?>
"/>
		<?php 
            }
            ?>
		<input type="hidden" name="a3" value="<?php 
            echo $plan->price3->get('a');
            ?>
"/>
		<input type="hidden" name="p3" value="<?php 
            echo $plan->price3->get('p');
            ?>
"/>
		<input type="hidden" name="t3" value="<?php 
            echo $plan->t3;
            ?>
"/>
	<?php 
            if ($plan->src && $plan->price3->get('srt') != 1) {
                ?>
		<input type="hidden" name="srt" value="<?php 
                echo $plan->price3->get('srt');
                ?>
"/>
		<input type="hidden" name="src" value="<?php 
                echo $plan->src;
                ?>
"/>
		<input type="hidden" name="sra" value="<?php 
                echo $plan->sra;
                ?>
">
	<?php 
            }
            ?>
	
	<input type="hidden" name="charset" value="utf-8" />
	</form>	
	<?php 
        }
        ?>
	<?php 
        /*<br /><br /><br /><br /><br /><br />
        	<center>
        	<img class="JLMS_png" src="<?php echo $JLMS_CONFIG->get('live_site') . '/' . $JLMS_CONFIG->get('lms_path_to_images', 'components/com_joomla_lms/lms_images');?>/loading.gif" width="32" height="32" border="0" alt="..." title="..." />
        	</center> */
        ?>
	</body>
	</html>
	<?php 
        die;
    }