function ShowCart($option, &$subscriptions, &$lists, $procs = array()) { global $Itemid, $JLMS_CONFIG, $JLMS_SESSION, $JLMS_DB, $my; $jlms_tax_counting = $JLMS_CONFIG->get('enabletax'); $sub_total = 0; $tax_amount = 0; $rows2 = array(); $custom_code = ''; $discounts = array(); $app =& JFactory::getApplication(); $coupon_code = $app->getUserStateFromRequest('com_joomla_lms_dis_coupon_code', 'dis_coupon_code', ''); $discounts['t_coupon_disc'] = JLMS_DISCOUNTS::getTotalCouponDiscount($coupon_code, $subscriptions); $discounts['t_disc'] = JLMS_DISCOUNTS::getTotalDiscounts($subscriptions); // counting taxes if ($jlms_tax_counting) { $is_cb_installed = $JLMS_CONFIG->get('is_cb_installed', 0); $get_country_info = $JLMS_CONFIG->get('get_country_info', 0); $cb_country_filed_id = intval($JLMS_CONFIG->get('jlms_cb_country')); $isset_country = false; if ($is_cb_installed && $get_country_info && $cb_country_filed_id) { //by Max (get country info) $query = "SELECT cf.name" . "\n FROM #__comprofiler_fields as cf" . "\n WHERE 1" . "\n AND cf.fieldid = '" . $cb_country_filed_id . "'"; $JLMS_DB->setQuery($query); $cb_country_field_name = $JLMS_DB->loadResult(); $query = "SELECT " . $cb_country_field_name . "" . "\n FROM #__comprofiler" . "\n WHERE 1" . "\n AND user_id = '" . $my->id . "'"; $JLMS_DB->setQuery($query); $country_name = $JLMS_DB->loadResult(); require_once 'components' . DS . $option . DS . 'includes' . DS . 'libraries' . DS . 'lms.lib.countries.php'; $CodeCountry = new CodeCountries(); $code = $CodeCountry->code($country_name); if ($code) { $user_country = $code; } $user_country_name = ''; $us_state = ''; } else { $ip_address = $_SERVER['REMOTE_ADDR']; //$ip_address = '213.184.248.211'; // $ip_address = '12.225.42.19'; // $ip_address = '111.215.41.12'; if (@ini_get('allow_url_fopen')) { $fn = @file('http://api.hostip.info/get_html.php?ip=' . $ip_address); // country ip identified if ($fn != false) { $ip_info = implode('', $fn); preg_match_all("(\\(..\\))", $ip_info, $dop); $user_country = str_replace('(', '', str_replace(")", '', $dop[0][0])); preg_match_all("(\\:.*\\()", $ip_info, $dop2); $user_country_name = str_replace(': ', '', str_replace(" (", '', $dop2[0][0])); preg_match_all("(\\, ..)", $ip_info, $dop3); $us_state = @str_replace(', ', '', $dop3[0][0]); } } } if (isset($user_country)) { $query = "SELECT * FROM #__lms_subscriptions_countries WHERE published = 1 AND code='" . $user_country . "' "; $JLMS_DB->setQuery($query); $rows2 = $JLMS_DB->loadObjectList(); // if no country found if (!count($rows2)) { // check if in EU $query = "SELECT * FROM #__lms_subscriptions_countries WHERE published = 1 AND code='EU' AND list REGEXP '" . $user_country . "' "; $JLMS_DB->setQuery($query); $rows_eu = $JLMS_DB->loadObjectList(); if (count($rows_eu)) { $isset_country = true; $rows2[0]->tax_type = $rows_eu[0]->tax_type; $rows2[0]->tax = $rows_eu[0]->tax; $user_country_name = $rows_eu[0]->name . ' (' . $user_country_name . ')'; } } else { $isset_country = true; } // additional check for US if ($user_country == 'US') { $query = "SELECT * FROM #__lms_subscriptions_countries WHERE published = 1 AND code = 'US-" . $us_state . "' "; $JLMS_DB->setQuery($query); $rows_states = $JLMS_DB->loadObjectList(); if (count($rows_states)) { $isset_country = true; $rows2 = array(); $rows2[0]->tax_type = $rows_states[0]->tax_type; $rows2[0]->tax = $rows_states[0]->tax; $user_country_name = 'United states (' . $rows_states[0]->name . ' )'; } } } //10.01.09 (Max) default tax option if (!$isset_country) { $rows2[0]->tax_type = $JLMS_CONFIG->get('default_tax_type', 1); $rows2[0]->tax = $JLMS_CONFIG->get('default_tax', 0); } } ?> <script language="javascript" type="text/javascript"> <!-- function jq_Check_selectCheckbox(check_name, form_name) { selItem = eval("document."+form_name+"['"+check_name+"']"); if (selItem) { if (selItem.length) { var i; for (i = 0; i<selItem.length; i++) { if (selItem[i].checked) { if (selItem[i].value) { return true; } }} } else if (selItem.checked) { return true; }} return false; } function jlms_submitbutton(pressbutton) { var form = document.JLMS_adminForm; if( pressbutton == 'remove_from_cart' ){ var ttt = jq_Check_selectCheckbox('jlms_sub[]', 'JLMS_adminForm'); if (ttt) { form.task.value = pressbutton; form.submit(); } else { alert("<?php echo _JLMS_ALERT_SELECT_ITEM; ?> "); } } if( pressbutton == 'update_cart' ){ form.task.value = pressbutton; form.submit(); } if (pressbutton == 'cart_login') { form.task.value = pressbutton; form.submit(); } if (pressbutton == 'apply_coupon_code') { form.task.value = pressbutton; form.submit(); } } //--> </script> <form action="<?php echo sefRelToAbs("index.php?option={$option}&Itemid={$Itemid}"); ?> " method="post" name="JLMS_adminForm"> <input type="hidden" value="<?php echo $option; ?> " name="option"> <input type="hidden" value="<?php echo $Itemid; ?> " name="Itemid"> <input type="hidden" value="" name="task"> <input type="hidden" value="" name="id"> <?php JLMS_TMPL::OpenMT(); $params = array('show_menu' => true, 'simple_menu' => true); JLMS_TMPL::ShowHeader('cart', _JLMS_MY_CART, $params); JLMS_TMPL::ShowPageTip('show_cart'); JLMS_TMPL::CloseMT(); $count_subs = count($subscriptions); ?> <br /> <?php if ($count_subs > 0) { ?> <input type="text" name="dis_coupon_code" value="<?php echo $coupon_code; ?> " /> <input type="button" value="Check coupon" onclick="jlms_submitbutton('apply_coupon_code');" /> <?php } ?> <table cellpadding="0" cellspacing="0" border="0" width="100%" class="jlms_cart_list_outer" style="width:100%"> <?php if ($count_subs > 0) { ?> <tr> <td> <?php $need_upd_txt = false; for ($i = 0, $n = count($subscriptions); $i < $n; $i++) { if (isset($subscriptions[$i]->allow_multiple) && $subscriptions[$i]->allow_multiple) { $need_upd_txt = true; break; } } $jlms_cs = $JLMS_CONFIG->get('jlms_cur_sign'); $total_subs = 0; $total_disc = 0; $total_tax = 0; $discounts['total_p_disc'] = 0; $reccSubId = false; for ($i = 0, $n = count($subscriptions); $i < $n; $i++) { JLMS_CART_html::initSubscriptionPaymentParams($subscriptions[$i], $rows2); if ($subscriptions[$i]->account_type == '6') { $reccSubId = $i; } if (isset($subscriptions[$i]->count_items) && $subscriptions[$i]->count_items && isset($subscriptions[$i]->allow_multiple) && $subscriptions[$i]->allow_multiple) { $total_subs += $subscriptions[$i]->sub_total * $subscriptions[$i]->count_items; $total_tax += $subscriptions[$i]->tax_amount * $subscriptions[$i]->count_items; $total_disc += $subscriptions[$i]->disc * $subscriptions[$i]->count_items; } else { $total_subs += $subscriptions[$i]->sub_total; $total_tax += $subscriptions[$i]->tax_amount; $total_disc += $subscriptions[$i]->disc; } if ($subscriptions[$i]->p_coupon_disc || $subscriptions[$i]->p_disc) { $params['showDiscount'] = true; } } if (isset($rows2[0]->tax_type) && $rows2[0]->tax_type == 2) { $total_tax += $rows2[0]->tax; // if tx is not in percentage.... } $discounts['total_p_disc'] = $total_disc; $total_disc = $total_disc + ($discounts['t_coupon_disc'] + $discounts['t_disc']); $total_price = $total_subs - $total_disc; if ($total_price < 0) { $total_price = $total_tax; } else { $total_price += $total_tax; } $price_diff = $total_subs - $total_disc; if ($price_diff < 0) { $balance = abs($price_diff); } else { $balance = 0; } $recurr_total_desc = ''; if ($reccSubId !== false) { $price = JLMS_RECURRENT_PAY::getPriceDesc($subscriptions[$reccSubId], 'basket_list', $balance, $total_price); $recurr_total_desc = JLMS_RECURRENT_PAY::getPriceDesc($subscriptions[$reccSubId], 'total', $balance, $total_price); if ($total_price == 0) { $total_price = JLMS_RECURRENT_PAY::getAmountFromReccurentPrice($subscriptions[$reccSubId]); } } ?> <div style="float:right; padding-top:5px; padding-right:25px"> <b><?php echo _JLMS_SUBSCR_SUB_TOTAL . ' ' . $jlms_cs . sprintf('%.2f', round($total_price, 2)); ?> </b> </div> </td> </tr> <tr> <td> <?php if ($need_upd_txt) { ?> <table width="100%" cellpadding="0" cellspacing="0" border="0" class="jlms_table_no_borders"> <tr> <td><div style="float:right; text-align:center"><?php echo _JLMS_CART_HAVE_CHANGED_QUANTITY; ?> <a href="javascript:jlms_submitbutton('update_cart');"><?php echo _JLMS_CART_UPDATE; ?> </a></div></td> </tr> </table> <?php } ?> <?php $do_show_index = false; for ($i = 0, $n = count($subscriptions); $i < $n; $i++) { $subscription = $subscriptions[$i]; $s = 1; foreach ($subscription->course_names as $course_name) { $course_usertype = 0; if (in_array($subscription->courses[$s - 1], $JLMS_CONFIG->get('teacher_in_courses', array(0)))) { $course_usertype = 1; } elseif (in_array($subscription->courses[$s - 1], $JLMS_CONFIG->get('student_in_courses', array(0)))) { $course_usertype = 2; } if ($course_usertype) { $do_show_index = true; break; } $s++; } if ($do_show_index) { break; } } ?> <table width="100%" cellpadding="0" cellspacing="0" border="0" class="<?php echo JLMSCSS::_('jlmslist', 'jlms_cart_list'); ?> "> <tr> <?php if ($do_show_index) { ?> <<?php echo JLMSCSS::tableheadertag(); ?> class="<?php echo JLMSCSS::_('sectiontableheader'); ?> " align="center" width="16">#</<?php echo JLMSCSS::tableheadertag(); ?> ><?php } ?> <<?php echo JLMSCSS::tableheadertag(); ?> class="<?php echo JLMSCSS::_('sectiontableheader'); ?> " align="left" width="20"> </<?php echo JLMSCSS::tableheadertag(); ?> > <<?php echo JLMSCSS::tableheadertag(); ?> class="<?php echo JLMSCSS::_('sectiontableheader'); ?> " align="left"><?php echo _JLMS_SUBSCRIBE_SUB_COURSES; ?> </<?php echo JLMSCSS::tableheadertag(); ?> > <<?php echo JLMSCSS::tableheadertag(); ?> class="<?php echo JLMSCSS::_('sectiontableheader'); ?> " align="left"><?php echo _JLMS_DETAILS; ?> </<?php echo JLMSCSS::tableheadertag(); ?> > <<?php echo JLMSCSS::tableheadertag(); ?> class="<?php echo JLMSCSS::_('sectiontableheader'); ?> " align="center" width="170"><?php echo _JLMS_COURSES_PRICE; ?> </<?php echo JLMSCSS::tableheadertag(); ?> > <?php if (isset($params['showDiscount']) && $params['showDiscount']) { ?> <<?php echo JLMSCSS::tableheadertag(); ?> class="<?php echo JLMSCSS::_('sectiontableheader'); ?> " align="center" width="40" nowrap="nowrap"><?php echo _JLMS_CART_DISCOUNT; ?> </<?php echo JLMSCSS::tableheadertag(); ?> > <?php } if (isset($rows2[0]) && $rows2[0]->tax_type == 1 && $rows2[0]->tax) { ?> <<?php echo JLMSCSS::tableheadertag(); ?> class="<?php echo JLMSCSS::_('sectiontableheader'); ?> " align="center" width="40" nowrap="nowrap"><?php echo _JLMS_CART_TAX; ?> </<?php echo JLMSCSS::tableheadertag(); ?> > <?php } ?> <<?php echo JLMSCSS::tableheadertag(); ?> class="<?php echo JLMSCSS::_('sectiontableheader'); ?> " align="center" width="40" nowrap="nowrap"><?php echo _JLMS_CART_QUANTITY; ?> </<?php echo JLMSCSS::tableheadertag(); ?> > </tr> <?php for ($i = 0, $n = count($subscriptions); $i < $n; $i++) { $subscription = $subscriptions[$i]; $tax_amount = 0; $disc = 0; if ($subscription->account_type != '6') { $price = $jlms_cs . sprintf('%.2f', round($subscriptions[$i]->sub_total, 2)); } $price_sub = $price; $custom_code .= JLMS_CART_html::ShowSub($subscription, $i + 1, '', $price_sub, $do_show_index, false, $params); } ?> </table> </td> </tr> <tr> <td> <div style="float:right; padding-top:5px; padding-right:25px; text-align:right;"> <?php if ($total_tax || $total_disc) { echo '<b>' . $jlms_cs . sprintf('%.2f', round($total_subs, 2)) . '</b><br />'; if ($total_disc) { echo '<b>' . _JLMS_SUBSCR_DISCOUNT_AMOUNT . ' ' . $jlms_cs . sprintf('%.2f', round($total_disc, 2)) . '</b><br />'; } if ($total_tax) { echo '<b>' . _JLMS_SUBSCR_TAX_AMOUNT . ' ' . $jlms_cs . sprintf('%.2f', round($total_tax, 2)) . '</b><br />'; } } echo '<b>' . _JLMS_SUBSCR_SUB_TOTAL . ' ' . $jlms_cs . sprintf('%.2f', round($total_price, 2)) . '</b><br />'; echo '<b>' . $recurr_total_desc . '</b>'; ?> </div> </td> </tr> <?php $controls = array(); if ($JLMS_CONFIG->get('under_ssl') && $JLMS_CONFIG->get('real_live_site')) { $temp_href = $JLMS_CONFIG->get('real_live_site') . "/index.php?option={$option}&Itemid={$Itemid}&task=subscription"; } else { $temp_href = $JLMS_CONFIG->get('live_site') . "/index.php?option={$option}&Itemid={$Itemid}&task=subscription"; } $controls[] = array('href' => $temp_href, 'title' => _JLMS_CART_BACK_TO_SHOP, 'img' => 'back'); $controls[] = array('href' => "javascript:jlms_submitbutton('remove_from_cart');", 'title' => _JLMS_CART_REMOVE, 'img' => 'cartremove'); JLMS_TMPL::ShowControlsFooter($controls, '', false); ?> </table> <?php if ($my->id && !empty($procs)) { JLMS_TMPL::OpenMT('jlms_table_no_borders'); JLMS_TMPL::OpenTS(); $sub_proc = $JLMS_SESSION->get('sub_proc'); if (isset($_COOKIE['proc_id'])) { $sub_proc = $_COOKIE['proc_id']; } $temp2 = ""; foreach ($procs as $proc) { $checked = ''; if (count($procs) == 1) { $temp2 = "checkProcessor('" . $proc->id . "','" . $proc->filename . "');"; $checked = 'checked="checked"'; } if ($sub_proc) { if ($sub_proc == $proc->id) { $temp2 = "checkProcessor('" . $proc->id . "','" . $proc->filename . "');"; $checked = 'checked="checked"'; } } else { if ($proc->default_p) { $temp2 = "checkProcessor('" . $proc->id . "','" . $proc->filename . "');"; $checked = 'checked="checked"'; } } echo '<input type="radio" name="proc_id" value="' . $proc->id . '" onclick="checkProcessor(\'' . $proc->id . '\',\'' . $proc->filename . '\');" id="proc_' . $proc->id . '" ' . $checked . ' /> <label class="msspro_sel_proc2" for="proc_' . $proc->id . '">' . $proc->name . '</label><br />'; } if ($temp2) { echo '<script type="text/javascript" language="javascript"><!--' . "\r\n"; echo $temp2; echo "\r\n--></script>"; } JLMS_TMPL::CloseTS(); JLMS_TMPL::CloseMT(); } ?> <?php echo "</form>"; if (!$my->id) { JLMS_UserSessions_html::loginPanel(); } } else { echo "<tr><td><div class='joomlalms_sys_message'>"; echo _JLMS_CART_IS_EMPTY; echo '<br />'; if ($JLMS_CONFIG->get('under_ssl') && $JLMS_CONFIG->get('real_live_site')) { $temp_href = $JLMS_CONFIG->get('real_live_site') . "/index.php?option={$option}&Itemid={$Itemid}&task=subscription"; } else { $temp_href = $JLMS_CONFIG->get('live_site') . "/index.php?option={$option}&Itemid={$Itemid}&task=subscription"; } echo '<a href="' . $temp_href . '" title="' . _JLMS_CART_BACK_TO_SHOP . '">[' . _JLMS_CART_BACK_TO_SHOP . ']</a>'; echo "</div></td></tr></table>"; echo "</form>"; } return $custom_code; }
function getPercentCouponDiscount($code, $subscription_id) { global $JLMS_DB; $step3 = true; if (!$subscription_id) { return false; } $code = JString::strtoupper($code); $groups_id = JLMS_DISCOUNTS::getUserGroups(); $query = "SELECT * FROM #__lms_discount_coupons \n\t\t\t\t\tWHERE enabled = 1 AND discount_type = 0 AND removed = 0\n\t\t\t\t\tAND\t( \n\t\t\t\t\t\t\t( start_date = '0000-00-00' AND end_date = '0000-00-00' ) OR\n\t\t\t\t\t\t\t( start_date < CURDATE() AND end_date = '0000-00-00' ) OR\n\t\t\t\t\t\t\t( start_date = '0000-00-00' AND end_date > CURDATE() ) OR\n\t\t\t\t\t\t\t( CURDATE() = start_date AND CURDATE() = end_date ) OR\n\t\t\t\t\t\t\t( CURDATE() BETWEEN start_date AND end_date ) \n\t\t\t\t\t\t)\n\t\t\t\t\tAND code = " . $JLMS_DB->quote($code) . " LIMIT 1"; $JLMS_DB->setQuery($query); $coupon = $JLMS_DB->loadObject(); if (is_object($coupon) && isset($coupon->code)) { if ($coupon->coupon_type == 1) { $query = "SELECT count(*) FROM lms_disc_c_usage_stats WHERE coupon_id = " . $coupon->id; $JLMS_DB->setQuery($query); if ($JLMS_DB->loadResult()) { return 0; } } $step1 = true; $step2 = true; $step3 = true; if ($coupon->subscriptions && !in_array($subscription_id, explode(',', $coupon->subscriptions))) { $step1 = false; } $step2 = $coupon->usergroups ? false : true; for ($j = 0; $j < count($groups_id); $j++) { $group_id = $groups_id[$j]; if ($coupon->usergroups && in_array($group_id, explode(',', $coupon->usergroups))) { $step2 = true; } } if ($coupon->users && !in_array($my->id, explode(',', $coupon->users))) { $step3 = false; } if ($step1 && $step2 && $step3) { return $coupon->value; } else { return 0; } } return 0; }