static function getCountryNameOfCode($code) { $countries = array_flip(Helper_Paypal::getPaypalCountries()); $name = $code; if (isset($countries[$code])) { $name = $countries[$code]; } return $name; }
/** * Function to generate list of countries * * This function get the data from other party and generate it into list of countries as select input * * @param $params variable to assign the generated result * @param $template to associate the generated countries into the selected template * * @return void */ function smarty_function_sirclo_generate_standard_countries($params, $template) { if (isset($params['out'])) { $template->assign($params['out'], Helper_Paypal::getPaypalCountriesAssoc()); } }
static function renderFormRow($options, $lang = "en") { $_name = ""; $_sanitized_name = ""; $_label = ""; $_type = "text"; $_attribute = ""; $_value = ""; $_value_empty = ""; $_html_input = ""; $_html = ""; $_options = array(); $_selected = ""; if (!empty($options['name'])) { $_name = $options['name']; } if (!empty($options['name'])) { $_sanitized_name = preg_replace("/[^a-zA-Z0-9\\-_]+/", "", $options['name']); } if (!empty($options['label'])) { $_label = $options['label']; } if (!empty($options['type'])) { $_type = $options['type']; } if (!empty($options['attribute'])) { $_attribute = $options['attribute']; } if (!empty($options['value'])) { $_value = $options['value']; } if (!empty($options['value_empty'])) { $_value_empty = $options['value_empty']; } if (!empty($options['options'])) { $_options = $options['options']; } if (!empty($options['selected'])) { $_selected = $options['selected']; } $_required = ""; if (strpos($_attribute, 'required') !== false) { $_required .= "<span class='required'>*</span>"; } if ($_type == "text" || $_type == "email" || $_type == "tel" || $_type == "password") { $_html_input .= "<input id='input_{$_name}' type='{$_type}' name='{$_name}' {$_attribute} value='{$_value}'>"; $_html .= "\n <div id='form-row-{$_sanitized_name}' class='sirclo-form-row'>\n <div class='sirclo-form-label'>\n <label for='{$_name}'>\n {$_label}\n {$_required}\n </label>\n </div>\n <div class='sirclo-form-input'>\n {$_html_input}\n </div>\n </div>"; } else { if ($_type == "textarea") { $_html_input .= "<textarea name='{$_name}' {$_attribute}></textarea>"; $_html .= "\n <div id='form-row-{$_sanitized_name}' class='sirclo-form-row'>\n <div class='sirclo-form-label'>\n <label for='{$_name}'>\n {$_label}\n {$_required}\n </label>\n </div>\n <div class='sirclo-form-input'>\n {$_html_input}\n </div>\n </div>"; } else { if ($_type == "file") { $_html_input .= "<input id='input_{$_name}' type='file' name='{$_name}' {$_attribute}>"; $_html .= "\n <div id='form-row-{$_sanitized_name}' class='sirclo-form-row'>\n <div class='sirclo-form-label'>\n <label for='{$_name}'>\n {$_label}\n {$_required}\n </label>\n </div>\n <div class='sirclo-form-input'>\n {$_html_input}\n </div>\n </div>"; } else { if ($_type == "country") { $_countries = Helper_Paypal::getPaypalCountriesAssoc(); $_html_input_option = "<option value=\"\">-- Select Country --</option>"; foreach ($_countries as $_country_key => $_country_value) { if (!empty($_value) && $_value == $_country_key) { $_html_input_option .= "<option value='{$_country_key}' selected='selected'>{$_country_value}</option>"; } else { $_html_input_option .= "<option value='{$_country_key}'>{$_country_value}</option>"; } } $_html_input .= "<select name='{$_name}' {$_attribute}>{$_html_input_option}</select>"; $_html .= "\n <div id='form-row-{$_sanitized_name}' class='sirclo-form-row'>\n <div class='sirclo-form-label'>\n <label for='{$_name}'>\n {$_label}\n {$_required}\n </label>\n </div>\n <div class='sirclo-form-input'>\n {$_html_input}\n </div>\n </div>"; } else { if ($_type == "salutation") { if ($lang == "id") { $_salutations = array('' => '-- Harap Dipilih --', 'Mr' => 'Tuan', 'Mrs' => 'Nyonya', 'Miss' => 'Nona', 'Dr' => 'Dr'); } else { $_salutations = array('' => '-- Please Select --', 'Mr' => 'Mr', 'Mrs' => 'Mrs', 'Miss' => 'Miss', 'Ms' => 'Ms', 'Dr' => 'Dr'); } $_html_input_option = ""; foreach ($_salutations as $_salutation_key => $_salutation_value) { if (!empty($_value) && $_value == $_salutation_value) { $_html_input_option .= "<option value='{$_salutation_key}' selected='selected'>{$_salutation_value}</option>"; } else { $_html_input_option .= "<option value='{$_salutation_key}'>{$_salutation_value}</option>"; } } $_html_input .= "<select name='{$_name}' {$_attribute}>{$_html_input_option}</select>"; $_html .= "\n <div id='form-row-{$_sanitized_name}' class='sirclo-form-row'>\n <div class='sirclo-form-label'>\n <label for='{$_name}'>\n {$_label}\n {$_required}\n </label>\n </div>\n <div class='sirclo-form-input'>\n {$_html_input}\n </div>\n </div>"; } else { if ($_type == "checkbox") { $_html_input .= "<input name='{$_name}' {$_attribute} type='checkbox'>"; $_html .= "\n <div id='form-row-{$_sanitized_name}' class='sirclo-form-row'>\n <div class='sirclo-form-input checkbox'>\n {$_html_input}\n <label for='{$_name}'>\n {$_label}\n {$_required}\n </label>\n </div>\n </div>"; } else { if ($_type == "radio") { $_html_input = ""; if (!empty($_value)) { foreach ($_value as $_v) { $_html_image = ''; if (!empty($_v['image'])) { $_html_image = '<br/><img src="' . Helper_File::addSuffix($_v['image'], '_ori') . '"/>'; } if (isset($_selected) && $_v['value'] == $_selected) { $_html_input .= "<div class='radio'><input value='" . $_v['value'] . "' name='" . $_name . "' type='radio' " . $_attribute . " checked='checked'>" . $_v['title'] . $_html_image . "</div>\n"; } else { $_html_input .= "<div class='radio'><input value='" . $_v['value'] . "' name='" . $_name . "' type='radio' " . $_attribute . ">" . $_v['title'] . $_html_image . "</div>\n"; } } } else { if (!empty($_value_empty)) { $_html_input .= "<span class='value-empty'>{$_value_empty}</span>"; } } $_html .= <<<EOD <div id='form-row-{$_sanitized_name}' class='sirclo-form-row'> <div class='sirclo-form-input radio'> {$_html_input}</div> </div> EOD; } else { if ($_type == "checkbox_multiple") { $_html_input = ""; if (!empty($_value)) { foreach ($_value as $_v) { if (!empty($_selected) && in_array($_v['value'], $_selected)) { $_html_input .= "<div class='checkbox-multiple'><input value='" . $_v['value'] . "' name='" . $_name . "' type='checkbox' " . $_attribute . " checked='checked'>" . $_v['title'] . "</div>"; } else { $_html_input .= "<div class='checkbox-multiple'><input value='" . $_v['value'] . "' name='" . $_name . "' type='checkbox' " . $_attribute . ">" . $_v['title'] . "</div>"; } } } else { if (!empty($_value_empty)) { $_html_input .= "<span class='value-empty'>{$_value_empty}</span>"; } } $_html .= "\n <div id='form-row-{$_sanitized_name}' class='sirclo-form-row'>\n <div class='sirclo-form-input checkbox-multiple'>\n {$_html_input}\n </div>\n </div>"; } else { if ($_type == "subheader") { $_html .= "<h3 class='{$_sanitized_name}'>" . $_value . "</h3>"; } else { if ($_type == "hidden") { $_html .= "<input id='input_{$_sanitized_name}' type='{$_type}' name='{$_name}' {$_attribute} value='{$_value}'>"; } else { if ($_type == "div") { $_html .= "<div {$_attribute}>"; } else { if ($_type == "div_close") { $_html .= "</div>"; } else { if ($_type == "submit") { if ($lang == "id") { $_html_input .= "<div class='sirclo-form-row notice'><span class='required'>*</span> wajib diisi.</div>"; } else { $_html_input .= "<div class='sirclo-form-row notice'>Fields marked with <span class='required'>*</span> are required.</div>"; } $_html_input .= "<input type='submit' value='{$_value}' {$_attribute}>"; $_html .= "\n <div id='form-row-{$_sanitized_name}' class='sirclo-form-row'>\n {$_html_input}\n </div>"; } else { if ($_type == 'dropdown') { $_attrs = array(); if ($_required) { $_attrs['required'] = 'required'; } $_html_input .= Helper_Xml::xmlSelect($_name, $_options, $_value, $_attrs); $_html .= "\n <div id='form-row-{$_sanitized_name}' class='sirclo-form-row'>\n <div class='sirclo-form-label'>\n <label for='{$_name}'>\n {$_label}\n {$_required}\n </label>\n </div>\n <div class='sirclo-form-input'>\n {$_html_input}\n </div>\n </div>"; } else { if ($_type == "plain_text") { $_html_input .= "<p>{$_value}</p>"; $_html .= "\n <div id='form-row-{$_sanitized_name}' class='sirclo-form-row'>\n {$_html_input}\n </div>"; } } } } } } } } } } } } } } } return $_html; }
static function getInstanceFromSmartyParams($params, $template = NULL) { $renderer = new Renderer_Cart(); $messages = array(); if ($template) { $view = $template->smarty->getTemplateVars('__view'); if (isset($view['messages'])) { $messages = $view['messages']; } } $renderer->messages = $messages; $renderer->countries = Helper_Paypal::getPaypalCountries(); if (isset($params['with_product_link'])) { $renderer->withProductLink = $params['with_product_link']; } if (isset($params['with_currency_symbol'])) { $renderer->withCurrencySymbol = $params['with_currency_symbol']; } if (isset($params['with_currency_space'])) { $renderer->withCurrencySpace = $params['with_currency_space']; } if (isset($params['member'])) { $renderer->member = $params['member']; } if (isset($params['currencies'])) { $renderer->currencies = $params['currencies']; } if (isset($params['with_delivery_date'])) { $renderer->withDeliveryDate = $params['with_delivery_date']; } if (isset($params['with_discount'])) { $renderer->withDiscount = $params['with_discount']; } if (isset($params['with_points'])) { $renderer->withPoints = $params['with_points']; } if (isset($params['points_label'])) { $renderer->pointsLabel = $params['points_label']; } if (isset($params['with_item_table'])) { $renderer->withItemTable = $params['with_item_table']; } if (isset($params['with_total_rows'])) { $renderer->withTotalRows = $params['with_total_rows']; } if (isset($params['discount_label'])) { $renderer->discountLabel = $params['discount_label']; } if (isset($params['shows_discount'])) { $renderer->showsDiscount = $params['shows_discount']; } if (isset($params['always_show_shipping'])) { $renderer->alwaysShowShipping = $params['always_show_shipping']; } if (isset($params['with_shipping'])) { $renderer->withShipping = $params['with_shipping']; } if (isset($params['with_shipping_country'])) { $renderer->withShippingCountry = $params['with_shipping_country']; } if (isset($params['with_shipping_city'])) { $renderer->withShippingCity = $params['with_shipping_city']; } if (isset($params['thumbnail_suffix'])) { $renderer->thumbnailSuffix = $params['thumbnail_suffix']; } if (isset($params['with_backorder_shipping'])) { $renderer->withBackorderShipping = $params['with_backorder_shipping']; } if (isset($params['cart_table_mode'])) { $renderer->cartTableMode = $params['cart_table_mode']; } if (isset($params['with_new_line_separator'])) { $renderer->withNewLineSeparator = $params['with_new_line_separator']; } return $renderer; }
static function _cartToPaypalItemParams($controller, $cart, $member = NULL) { $items = $cart['items']; $params = self::_cartItemsToPaypalParams($controller, $items); if (isset($cart['shipping']) && isset($cart['shipping_discount']) && $cart['shipping']) { $params['shipping_1'] = self::_getConvertedPrice($controller, $cart['shipping'] + $cart['shipping_discount']); } if (isset($cart['discounts']) && $cart['discounts']) { //$discRaw = array_sum(array_map(function ($x) {return $x['value'];}, $cart['discounts'])); $discRaw = -1 * self::getDiscountAmount($cart); $itemTotal = self::getItemTotal($cart['items']); if ($discRaw >= $itemTotal) { $discRaw = max(0, $itemTotal - 0.01); } $discountAmountCart = Helper_Paypal::numberFormat($discRaw); if ($discountAmountCart) { $params['discount_amount_cart'] = self::_getConvertedPrice($controller, $discountAmountCart); } } if (isset($cart['tax']) && $cart['tax']) { $params['tax_cart'] = self::_getConvertedPrice($controller, $cart['tax']); } return $params; }
static function renderFormRow($options, $lang = "en") { $_name = ""; $_sanitized_name = ""; $_label = ""; $_type = "text"; $_attribute = ""; $_value = ""; $_value_empty = ""; $_html_input = ""; $_html = ""; $_options = array(); $_selected = ""; if (!empty($options['name'])) { $_name = $options['name']; } if (!empty($options['name'])) { $_sanitized_name = preg_replace("/[^a-zA-Z0-9\\-_]+/", "", $options['name']); } if (!empty($options['label'])) { $_label = $options['label']; } if (!empty($options['type'])) { $_type = $options['type']; } if (!empty($options['attribute'])) { $_attribute = $options['attribute']; } if (!empty($options['value'])) { $_value = $options['value']; } if (!empty($options['value_empty'])) { $_value_empty = $options['value_empty']; } if (!empty($options['options'])) { $_options = $options['options']; } if (!empty($options['selected'])) { $_selected = $options['selected']; } $_required = ""; if (strpos($_attribute, 'required') !== false) { $_required .= "<span class='required'>*</span>"; } /* <div class="form-group has-feedback"> <input type="text" class="form-control" placeholder="Email" /> <i class="fa fa-envelope s-top-less-margin form-control-feedback"></i> </div> */ if ($_type == "emailLogin") { $_html_input .= "<input id='input_{$_name}' class='form-control' type='{$_type}' name='{$_name}' {$_attribute} value='{$_value}' placeholder='Email'>\n\t\t\t\t\t\t\t <i class='fa fa-envelope s-top-less-margin form-control-feedback'></i>"; $_html .= '<div id="form-row-$_sanitized_name" class="form-group"> <div class="form-group has-feedback sirclo-form-input"> ' . $_html_input . ' </div> </div>'; } else { if ($_type == "passwordLogin") { $_html_input .= "<input id='input_{$_name}' class='form-control' type='{$_type}' name='{$_name}' {$_attribute} value='{$_value}' placeholder='Password'>\n\t\t\t\t\t\t\t <i class='fa fa-lock s-top-less-margin form-control-feedback'></i>"; $_html .= '<div id="form-row-$_sanitized_name" class="form-group"> <div class="form-group has-feedback sirclo-form-input"> ' . $_html_input . ' </div> </div>'; } else { if ($_type == "text" || $_type == "password" || $_type == "email" || $_type == "tel" || $_type == "date") { $_html_input .= "<input id='input_{$_name}' type='{$_type}' name='{$_name}' {$_attribute} value='{$_value}'>"; $_html .= "\n <div id='form-row-{$_sanitized_name}' class='form-group'>\n <div class='sirclo-form-label'>\n <label for='{$_name}'>\n {$_label}\n {$_required}\n </label>\n </div>\n <div class='sirclo-form-input'>\n {$_html_input}\n </div>\n </div>"; } else { if ($_type == "textarea") { $_html_input .= "<textarea name='{$_name}' {$_attribute}></textarea>"; $_html .= "\n <div id='form-row-{$_sanitized_name}' class='form-group'>\n <div class='sirclo-form-label'>\n <label for='{$_name}'>\n {$_label}\n {$_required}\n </label>\n </div>\n <div class='sirclo-form-input'>\n {$_html_input}\n </div>\n </div>"; } else { if ($_type == "file") { $_html_input .= "<input id='input_{$_name}' type='file' name='{$_name}' {$_attribute}>"; $_html .= "\n <div id='form-row-{$_sanitized_name}' class='form-group'>\n <div class='sirclo-form-label'>\n <label for='{$_name}'>\n {$_label}\n {$_required}\n </label>\n </div>\n <div class='sirclo-form-input'>\n {$_html_input}\n </div>\n </div>"; } else { if ($_type == "country") { $_countries = Helper_Paypal::getPaypalCountriesAssoc(); $_html_input_option = "<option value=\"\">-- Select Country --</option>"; foreach ($_countries as $_country_key => $_country_value) { if (!empty($_value) && $_value == $_country_key) { $_html_input_option .= "<option value='{$_country_key}' selected='selected'>{$_country_value}</option>"; } else { $_html_input_option .= "<option value='{$_country_key}'>{$_country_value}</option>"; } } $_html_input .= "<select name='{$_name}' {$_attribute}>{$_html_input_option}</select>"; $_html .= "\n <div id='form-row-{$_sanitized_name}' class='form-group'>\n <div class='sirclo-form-label'>\n <label for='{$_name}'>\n {$_label}\n {$_required}\n </label>\n </div>\n <div class='sirclo-form-input'>\n {$_html_input}\n </div>\n </div>"; } else { if ($_type == "salutation") { if ($lang == "id") { $_salutations = array('' => '-- Harap Dipilih --', 'Mr' => 'Tuan', 'Mrs' => 'Nyonya', 'Miss' => 'Nona', 'Dr' => 'Dr'); } else { $_salutations = array('' => '-- Please Select --', 'Mr' => 'Mr', 'Mrs' => 'Mrs', 'Miss' => 'Miss', 'Ms' => 'Ms', 'Dr' => 'Dr'); } $_html_input_option = ""; foreach ($_salutations as $_salutation_key => $_salutation_value) { if (!empty($_value) && $_value == $_salutation_value) { $_html_input_option .= "<option value='{$_salutation_key}' selected='selected'>{$_salutation_value}</option>"; } else { $_html_input_option .= "<option value='{$_salutation_key}'>{$_salutation_value}</option>"; } } $_html_input .= "<select name='{$_name}' {$_attribute}>{$_html_input_option}</select>"; $_html .= "\n <div id='form-row-{$_sanitized_name}' class='form-group'>\n <div class='sirclo-form-label'>\n <label for='{$_name}'>\n {$_label}\n {$_required}\n </label>\n </div>\n <div class='sirclo-form-input'>\n {$_html_input}\n </div>\n </div>"; } else { if ($_type == "checkbox") { $_html_input .= "<input name='{$_name}' {$_attribute} type='checkbox'>"; $_html .= "\n <div id='form-row-{$_sanitized_name}' class='form-group checkbox'>\n <label for='{$_name}'>\n <input name ='agreement' required type='checkbox'>\n {$_label}\n {$_required}\n </label>\n </div>"; } else { if ($_type == "radio") { $_html_input = ""; if (!empty($_value)) { foreach ($_value as $_v) { $_html_image = ''; if (!empty($_v['image'])) { foreach ($_v['image'] as $img) { if ($_html_image == '') { $_html_image .= '<br/>'; } $_html_image .= '<img class="s-icon-pay" src="' . $img . '"/>'; } } if (isset($_selected) && $_v['value'] == $_selected) { $_html_input .= "<label><input value='" . $_v['value'] . "' name='" . $_name . "' type='radio' " . $_attribute . " checked='checked'>" . $_v['title'] . $_html_image . "</label>\n"; } else { $_html_input .= "<label><input value='" . $_v['value'] . "' name='" . $_name . "' type='radio' " . $_attribute . ">" . $_v['title'] . $_html_image . "</label>\n"; } } } else { if (!empty($_value_empty)) { $_html_input .= "<span class='value-empty'>{$_value_empty}</span>"; } } $_html .= <<<EOD <div id='form-row-{$_sanitized_name}' class='form-group radio'> {$_html_input} </div> EOD; } else { if ($_type == "checkbox_multiple") { $_html_input = ""; if (!empty($_value)) { foreach ($_value as $_v) { if (!empty($_selected) && in_array($_v['value'], $_selected)) { $_html_input .= "<div class='checkbox-multiple'><input value='" . $_v['value'] . "' name='" . $_name . "' type='checkbox' " . $_attribute . " checked='checked'>" . $_v['title'] . "</div>"; } else { $_html_input .= "<div class='checkbox-multiple'><input value='" . $_v['value'] . "' name='" . $_name . "' type='checkbox' " . $_attribute . ">" . $_v['title'] . "</div>"; } } } else { if (!empty($_value_empty)) { $_html_input .= "<span class='value-empty'>{$_value_empty}</span>"; } } $_html .= "\n <div id='form-row-{$_sanitized_name}' class='form-group'>\n <div class='sirclo-form-input checkbox-multiple'>\n {$_html_input}\n </div>\n </div>"; } else { if ($_type == "subheader") { $_html .= "<h2 class='{$_sanitized_name}'>" . $_value . "</h2>"; } else { if ($_type == "hidden") { $_html .= "<input id='input_{$_sanitized_name}' type='{$_type}' name='{$_name}' {$_attribute} value='{$_value}'>"; } else { if ($_type == "div") { $_html .= "<div {$_attribute}>"; } else { if ($_type == "div_close") { $_html .= "</div>"; } else { if ($_type == "submit") { if ($_value == "LOGIN") { $_html_input .= '<button class="btn btn-lg blue-button s-fullwidth s-bottom-margin s-top-less-margin s-login-button">LOGIN</button>'; } else { if ($_value == "REGISTER") { $_html_input .= '<button type="submit" class="btn btn-lg blue-button"> REGISTER </button>'; } else { if ($_value == "SEND") { $_html_input .= '<button type="submit" class="btn btn-lg blue-button">SEND</button>'; } else { if ($_value == "CHANGE PASSWORD") { $_html_input .= '<button type="submit" class="btn btn-lg blue-button s-change-password-submit">CHANGE PASSWORD</button>'; } else { /* if ($lang == "id") { $_html_input .= "<div class='form-group notice'><span class='required'>*</span> wajib diisi.</div>"; } else { $_html_input .= "<div class='form-group notice'>Fields marked with <span class='required'>*</span> are required.</div>"; }*/ $_html_input .= "<input type='submit' value='{$_value}' {$_attribute}>"; } } } } $_html .= "\n <div id='form-row-{$_sanitized_name}' class='form-group'>\n {$_html_input}\n </div>"; } else { if ($_type == 'dropdown') { $_attrs = array(); if ($_required) { $_attrs['required'] = 'required'; } $_html_input .= Helper_Xml::xmlSelect($_name, $_options, $_value, $_attrs); $_html .= "\n <div id='form-row-{$_sanitized_name}' class='form-group'>\n <div class='sirclo-form-label'>\n <label for='{$_name}'>\n {$_label}\n {$_required}\n </label>\n </div>\n <div class='sirclo-form-input'>\n {$_html_input}\n </div>\n </div>"; } else { if ($_type == "plain_text") { $_html_input .= "<p>{$_value}</p>"; $_html .= "\n <div id='form-row-{$_sanitized_name}' class='form-group'>\n {$_html_input}\n </div>"; } } } } } } } } } } } } } } } } } return $_html; }