public function __construct($options = array()) { parent::__construct($options); // @todo: check required options $this->app_id = ifempty($this->options['app_id']); $this->app_secret = ifempty($this->options['app_secret']); }
protected function callbackHandler($request) { if (!$this->order_id || !$this->app_id || !$this->merchant_id) { throw new waPaymentException('invalid order number', 404); } if (!$this->verifySign($request)) { throw new waPaymentException('invalid signature', 404); } $result = array(); $transaction_data = $this->formalizeData($request); if (!empty($request['customer'])) { switch (ifempty($transaction_data['state'])) { case self::STATE_CAPTURED: $result['redirect'] = $this->getAdapter()->getBackUrl(waAppPayment::URL_SUCCESS, $transaction_data); break; case self::STATE_DECLINED: $result['redirect'] = $this->getAdapter()->getBackUrl(waAppPayment::URL_FAIL, $transaction_data); } } if (ifempty($transaction_data['state']) == self::STATE_CAPTURED) { $transaction_data = $this->saveTransaction($transaction_data, $request); $this->execAppCallback(self::CALLBACK_PAYMENT, $transaction_data); } return $result; }
function get_edit_announcement_input_form($announcement_r, $HTTP_VARS = NULL) { global $PHP_SELF; $buffer .= "<form action=\"{$PHP_SELF}\" method=\"POST\">"; $buffer .= "\n<input type=\"hidden\" name=\"type\" value=\"announcements\">"; if (is_array($announcement_r)) { $buffer .= "\n<input type=\"hidden\" name=\"op\" value=\"update\">" . "\n<input type=\"hidden\" name=\"announcement_id\" value=\"" . $announcement_r['announcement_id'] . "\">"; } else { $buffer .= "\n<input type=\"hidden\" name=\"op\" value=\"insert\">"; } $buffer .= "<table>"; $buffer .= get_input_field("title", NULL, 'Title', "text(50,500)", "Y", ifempty($announcement_r['title'], $HTTP_VARS['title']), TRUE); $buffer .= get_input_field("content", NULL, 'Announcement', "htmlarea(60,15)", "Y", ifempty($announcement_r['content'], $HTTP_VARS['content']), TRUE); $buffer .= get_input_field("display_days", NULL, 'Display Days', "number(10,10)", "Y", ifempty($announcement_r['display_days'], $HTTP_VARS['display_days']), TRUE); if (is_array($announcement_r)) { $buffer .= get_input_field("closed_ind", NULL, 'Closed', "checkbox(Y,N)", "N", ifempty($announcement_r['closed_ind'], $HTTP_VARS['closed_ind']), TRUE); } $buffer .= "</table>"; $help_r[] = array('img' => 'compulsory.gif', 'text' => get_opendb_lang_var('compulsory_field'), id => 'compulsory'); $help_r[] = array('text' => 'A zero in Display Days indicates the announcment will never expire.'); $help_r[] = array('text' => 'No validation is performed on HTML entered in the Announcement text field.'); $buffer .= format_help_block($help_r); if (get_opendb_config_var('widgets', 'enable_javascript_validation') !== FALSE) { $onclick_event = "if(!checkForm(this.form)){return false;}else{this.form.submit();}"; } else { $onclick_event = "this.form.submit();"; } $buffer .= "<input type=\"button\" class=\"button\" onclick=\"{$onclick_event}\" value=\"Save\">"; $buffer .= "\n</form>"; return $buffer; }
public function widgetAddAction() { $data = waRequest::post(); if (isset($data['new_block'])) { $new_block = $data['new_block']; unset($data['new_block']); } else { $new_block = false; } $dashboard_id = waRequest::request('dashboard_id', null, 'int'); if ($dashboard_id && !wa()->getUser()->isAdmin('webasyst')) { throw new waException('Access denied', 403); } $widgets = wa($data['app_id'])->getConfig()->getWidgets(); $data['name'] = $widgets[$data['widget']]['name']; $id = $this->getWidgetModel()->add($data, $new_block, ifempty($dashboard_id, null)); $w = wa()->getWidget($id)->getInfo(); $w['size'] = explode('x', $w['size']); $w['sizes'] = $widgets[$data['widget']]['sizes']; foreach ($w['sizes'] as $s) { if ($s == array(1, 1)) { $w['has_sizes']['small'] = true; } elseif ($s == array(2, 1)) { $w['has_sizes']['medium'] = true; } elseif ($s == array(2, 2)) { $w['has_sizes']['big'] = true; } } $w['has_settings'] = $widgets[$data['widget']]['has_settings']; $this->displayJson(array('id' => $id, 'html' => $this->display(array('w' => $w), $this->getPluginRoot() . 'templates/actions/dashboard/DashboardWidget.html', true))); }
public function getAllSettings() { $this->enable = $this->getSettings('enable') ? 1 : 0; $this->where = $this->getSettings('where'); $this->phone_mask = $this->getSettings('phone_mask'); $this->phone_placeholder = $this->getSettings('phone_placeholder'); $this->error_msg = $this->getSettings('error_msg'); $this->error_msg = ifempty($this->error_msg, 'Неверный формат'); $this->validate = $this->getSettings('validate') ? 1 : 0; $this->phone_input_names = $this->getSettings('phone_input_names'); if (empty($this->phone_input_names)) { $this->phone_input_names = 'phone'; } $this->view = wa()->getView(); if (!empty($this->phone_input_names)) { $this->phone_input_names = explode(',', $this->getSettings('phone_input_names')); foreach ($this->phone_input_names as $i => $phone) { $this->phone_input_names[$i] = '[name*="[' . trim($phone) . ']"]'; } $this->view->assign('phone_input_names', join(', ', $this->phone_input_names)); } else { $this->phone_input_names = false; } $this->view->assign('where', $this->where); $this->view->assign('error_msg', $this->error_msg); $this->view->assign('phone_mask', $this->phone_mask); $this->view->assign('phone_placeholder', $this->phone_placeholder); $this->view->assign('validate', $this->validate); }
protected function create($params = array()) { $config = array('name' => empty($params['name']) ? ucfirst($this->plugin_id) : $params['name'], 'icon' => 'img/' . $this->plugin_id . '.gif', 'version' => ifempty($params['version'], $this->getDefaults('version')), 'vendor' => ifempty($params['vendor'], $this->getDefaults('vendor')), 'handlers' => array()); $paths = array('css/' . $this->plugin_id . '.css', 'js/' . $this->plugin_id . '.js', 'img/', 'lib/', 'lib/actions/backend/', 'lib/classes/', 'lib/config/', 'lib/' . $this->app_id . ucfirst($this->plugin_id) . 'Plugin.class.php' => $this->getPluginClassCode(), 'lib/vendors/'); if (isset($params['db'])) { array_push($paths, array('lib/models/')); } if (isset($params['locale'])) { array_push($paths, array('locale/')); } if (isset($params['frontend'])) { $config['frontend'] = true; array_push($paths, array('lib/actions/frontend/', 'templates/actions/frontend/')); $paths['lib/config/routing.php'] = array('*' => 'frontend'); } if (isset($params['settings'])) { $paths['lib/config/settings.php'] = array(); } $paths['lib/config/plugin.php'] = $config; $protected_paths = array('lib/', 'templates/'); if (isset($params['locale'])) { array_push($protected_paths, array('locale/')); } $this->createStructure($paths); $this->protect($protected_paths); if (!isset($params['disable'])) { $this->installPlugin(); $errors = $this->flushCache(); if ($errors) { print "Error during delete cache files:\n\t" . implode("\n\t", $errors) . "\n"; } } return $config; }
/** * Enter description here... * * @param unknown_type $override_title * @return unknown */ function get_opendb_title($override_default_title = TRUE) { if ($override_default_title) { return ifempty(get_opendb_config_var('site', 'title'), __OPENDB_TITLE__); } else { return __OPENDB_TITLE__; } }
public function defaultAction() { $settings = $this->getSettings(); $rss_url = ifempty($settings['rss_feed']); if ($rss_url == 'custom') { $rss_url = ifempty($settings['custom_rss_feed']); } $this->display(array('rss_url' => $rss_url, 'uniqid' => 'n' . uniqid(true)), $this->getTemplatePath('Default.html')); }
public function getHTML($params = array(), $attrs = '') { $value = isset($params['value']) ? $params['value'] : ''; $disabled = ''; if (wa()->getEnv() === 'frontend' && isset($params['my_profile']) && $params['my_profile'] == '1') { $disabled = 'disabled="disabled"'; } return '<input type="hidden" ' . $disabled . ' name="' . $this->getHTMLName($params) . '" value=""><input type="checkbox"' . ($value ? ' checked="checked"' : '') . ' name="' . $this->getHTMLName($params) . '" value="' . ifempty($value, '1') . '" ' . $attrs . '>'; }
function doTree($group = false) { global $misc; $servers = $misc->getServers(true, $group); $reqvars = $misc->getRequestVars('server'); $attrs = array('text' => field('desc'), 'icon' => ifempty(field('username'), 'DisconnectedServer', 'Server'), 'toolTip' => field('id'), 'action' => url('redirect.php', $reqvars, array('server' => field('id'))), 'branch' => ifempty(field('username'), false, url('all_db.php', $reqvars, array('action' => 'tree', 'server' => field('id'))))); $misc->printTreeXML($servers, $attrs); exit; }
public function execute() { list($start_date, $end_date, $group_by) = shopReportsSalesAction::getTimeframeParams(); // Init by-day arrays with zeroes. $by_day = array(); // Data for main graph: 'yyyy-mm-dd' => array(...) $sales_by_day = array(); // Total sales data $om = new shopOrderModel(); foreach ($om->getSales($start_date, $end_date, $group_by) as $date => $row) { $sales_by_day[$date] = $row['total']; $by_day[$date] = array('date' => $date, 'total_percent' => 0, 'total' => 0); } // Max profit in a single day $max_day_profit = 0; // Totals for period, in default currency $total = array('profit' => 0, 'purchase' => 0, 'shipping' => 0, 'sales' => 0, 'tax' => 0); // Loop over all days of a period that had at least one order paid, // and gather data into vars listed above. foreach ($om->getProfit($start_date, $end_date, $group_by) as $row) { $sales = ifset($sales_by_day[$row['date']], 0); $profit = $sales - $row['purchase'] - $row['shipping'] - $row['tax']; $max_day_profit = max($max_day_profit, $profit); $by_day[$row['date']]['total'] = $profit; $total['sales'] += $sales; $total['profit'] += $profit; $total['purchase'] += $row['purchase']; $total['shipping'] += $row['shipping']; $total['tax'] += $row['tax']; } // Data for main chart $profit_data = array(); foreach ($by_day as &$d) { $d['total_percent'] = $max_day_profit ? $d['total'] * 100 / ifempty($max_day_profit, 1) : 0; $profit_data[] = array($d['date'], $d['total']); } unset($d); // Data for pie chart $pie_data = array(); $pie_total = $total['shipping'] + $total['profit'] + $total['purchase'] + $total['tax']; if ($pie_total) { $pie_data[] = array(_w('Shipping') . ' (' . round($total['shipping'] * 100 / ifempty($pie_total, 1), 1) . '%)', (double) $total['shipping']); $pie_data[] = array(_w('Profit') . ' (' . round($total['profit'] * 100 / ifempty($pie_total, 1), 1) . '%)', (double) $total['profit']); $pie_data[] = array(_w('Product purchases') . ' (' . round($total['purchase'] * 100 / ifempty($pie_total, 1), 1) . '%)', (double) $total['purchase']); $pie_data[] = array(_w('Tax') . ' (' . round($total['tax'] * 100 / ifempty($pie_total, 1), 1) . '%)', (double) $total['tax']); $pie_data = array($pie_data); } $def_cur = wa()->getConfig()->getCurrency(); $this->view->assign('total', $total); $this->view->assign('by_day', $by_day); $this->view->assign('def_cur', $def_cur); $this->view->assign('group_by', $group_by); $this->view->assign('pie_data', $pie_data); $this->view->assign('profit_data', $profit_data); $this->view->assign('avg_profit', $by_day ? round($total['profit'] / count($by_day), 2) : 0); }
function generate_language_sql($language, $options = NULL) { $CRLF = get_user_browser_crlf(); $sqlscript = ''; //language, description, default_ind $language_r = fetch_language_r($language); if (is_not_empty_array($language_r)) { $sqlscript = '#########################################################' . $CRLF . '# OpenDb ' . get_opendb_version() . ' \'' . $language . '\' Language Pack' . $CRLF . '#########################################################' . $CRLF . $CRLF; $sqlscript .= "INSERT INTO s_language (language, description, default_ind) " . "VALUES ('" . $language_r['language'] . "', '" . addslashes($language_r['description']) . "', '" . $language_r['default_ind'] . "'); " . $CRLF; $results = fetch_language_langvar_rs($language, $options); if ($results) { $sqlscript .= $CRLF . '#' . $CRLF . '# System Language Variables' . $CRLF . '#' . $CRLF; while ($lang_var_r = db_fetch_assoc($results)) { if ($language_r['default_ind'] != 'Y') { $value = ifempty($lang_var_r['value'], $lang_var_r['default_value']); } else { $value = $lang_var_r['value']; } $sqlscript .= "INSERT INTO s_language_var (language, varname, value) " . "VALUES ('" . $language_r['language'] . "', '" . $lang_var_r['varname'] . "', '" . addslashes($value) . "'); " . $CRLF; } db_free_result($results); } if ($language_r['default_ind'] != 'Y') { $table_r = get_system_table_r(); if (is_array($table_r)) { $sqlscript .= $CRLF . '#' . $CRLF . '# System Table Language Variables' . $CRLF . '#' . $CRLF; reset($table_r); while (list(, $table) = each($table_r)) { $tableconf_r = get_system_table_config($table); // key, column if (is_array($tableconf_r) && is_array($tableconf_r['columns'])) { reset($tableconf_r['columns']); while (list(, $column) = each($tableconf_r['columns'])) { $results = fetch_system_table_column_langvar_rs($language, $table, $column, $options); if ($results) { while ($lang_var_r = db_fetch_assoc($results)) { if ($language_r['default_ind'] != 'Y') { $value = ifempty($lang_var_r['value'], $lang_var_r[$column]); } else { $value = $lang_var_r['value']; } if (strlen($value)) { $sqlscript .= "INSERT INTO s_table_language_var (language, tablename, columnname, key1, key2, key3, value) " . "VALUES ('" . $language_r['language'] . "', '" . $table . "', '" . $column . "', '" . $lang_var_r['key1'] . "', " . (strlen($lang_var_r['key2']) > 0 ? "'" . $lang_var_r['key2'] . "'" : "''") . ", " . (strlen($lang_var_r['key3']) > 0 ? "'" . $lang_var_r['key3'] . "'" : "''") . ", '" . addslashes($value) . "'); " . $CRLF; } } db_free_result($results); } } } } } } } return $sqlscript; }
public function unserialize($serialized) { $data = unserialize($serialized); $this->file = ifset($data['file']); $this->delimiter = ifempty($data['delimiter'], ';'); $this->encoding = ifempty($data['encoding'], 'utf-8'); $this->method = ifempty($data['method'], 'iconv'); $this->data_mapping = ifset($data['data_mapping']); $this->offset = ifset($data['offset'], 0); $this->restore(); }
public function __construct($coupon = array()) { waLocale::loadByDomain(array('shop', 'coupon')); waSystem::pushActivePlugin('coupon', 'shop'); $this->data['code'] = ifempty($coupon['code'], ''); $this->data['expire'] = ifempty($coupon['expire_datetime']); $curm = new shopCurrencyModel(); $currencies = $curm->getAll('code'); $this->data['discount'] = shopCouponPlugin::formatValue($coupon, $currencies); waSystem::popActivePlugin(); }
public function frontendCheckout($info) { $step = ifempty($info['step'], ''); if ($step == 'success') { return ''; } $cart = new shopCart(); $m = new shopCartsreportPluginCartModel(); $m->insert(array('code' => $cart->getCode(), 'checkout.' . $step => 1, 'edit_datetime' => date('Y-m-d H:i:s')), 1); return ''; }
public function execute() { $om = new shopOrderModel(); $encoded_order_id = waRequest::param('id'); $code = waRequest::param('code'); $order_id = shopHelper::decodeOrderId($encoded_order_id); if (!$order_id) { // fall back to non-encoded id $order_id = $encoded_order_id; $encoded_order_id = shopHelper::encodeOrderId($order_id); } $order = $om->getOrder($order_id); if (!$order) { throw new waException(_w('Order not found'), 404); } elseif (!$this->isAuth($order, $code)) { if ($code && $order_id != substr($code, 16, -16)) { throw new waException(_w('Order not found'), 404); } else { $redirect = array('id' => $order_id); if (!empty($code)) { $redirect['code'] = $code; } $url = $code ? '/frontend/myOrderByCode' : '/frontend/myOrder'; $this->redirect(wa()->getRouteUrl($url, $redirect)); } } elseif ($code && $order['contact_id'] == wa()->getUser()->getId()) { $redirect = array('id' => $order_id, 'form_type' => waRequest::param('form_type'), 'form_id' => waRequest::param('form_id')); $this->redirect(wa()->getRouteUrl('/frontend/myOrderPrintform', $redirect)); } $order_params_model = new shopOrderParamsModel(); $order['params'] = $order_params_model->get($order['id']); $order['id_str'] = $encoded_order_id; switch (waRequest::param('form_type')) { case 'payment': if (empty($order['params']['payment_id']) || !($payment = shopPayment::getPlugin(null, $order['params']['payment_id']))) { throw new waException(_w('Printform not found'), 404); } $form_id = waRequest::param('form_id'); $params = null; if (strpos($form_id, '.')) { $form = explode('.', $form_id, 2); $form_id = array_shift($form); $params = array_shift($form); } print $payment->displayPrintForm(ifempty($form_id, $payment->getId()), shopPayment::getOrderData($order, $payment), intval($params)); exit; break; default: throw new waException(_w('Printform not found'), 404); break; } }
public static function getAvailableLanguages() { static $options; if ($options !== null) { return $options; } $langs = waLocale::getAll('info'); $options = array(); foreach ($langs as $code => $lang) { $code = substr($code, 0, 2); $options[$code] = ifempty($lang['name'], '') . ' (' . $code . ')'; } return $options; }
/** * @return array|bool|null * @throws waException */ public function isAuth() { $info = waSystem::getInstance()->getStorage()->read('auth_user'); if (!$info) { $info = $this->_authByCookie(); if ($info) { waSystem::getInstance()->getStorage()->write('auth_user', $info); } } // check options if ($info && $info['id'] && (!$this->getOption('is_user') || ifempty($info['is_user']) > 0)) { return $info; } return false; }
public function __get($field) { switch ($field) { case self::HSV: case self::RGB: case self::CMYK: if (!isset($this->_data[$field])) { $this->_data[$field] = $this->convert($field, $this->code); } return $this->_data[$field]; case 'style': $style = ""; if ($this->code !== null) { $d = !!(0xff & $this->code < 0x7f) + !!(0xff & $this->code >> 8 < 0x7f) + 2 * !!(0xff & $this->code >> 16 < 0x7f); if ($d > 2) { $color = 0xffffff; } else { $color = 0x0; } $style .= "color:{$this->convert(self::HEX, $color)};"; $style .= "background-color:{$this->hex};"; } return $style; break; case 'html': $name = htmlentities(ifempty($this->value, $this->hex), ENT_QUOTES, 'utf-8'); return <<<HTML <span style="white-space: nowrap;">{$this->icon}{$name}</span> HTML; break; case 'icon': if ($this->code === null) { return null; } else { return <<<HTML <i class="icon16 color" style="background:{$this->hex};"></i> HTML; } break; case 'compare': return trim($this->value); break; default: return isset($this->{$field}) ? $this->{$field} : $this->convert($field); break; } }
/** * @param int $tax_id * @param array $address * @return float */ public function getByTaxAddress($tax_id, $address) { $result = false; $country = ifempty($address['country'], wa('shop')->getConfig()->getGeneralSettings('country')); if ($country) { $data = array('id' => $tax_id, 'country' => $country); if (empty($address['region'])) { $region_sql = " AND region_code IS NULL "; } else { $data['region'] = $address['region']; $region_sql = " AND (region_code IS NULL OR region_code=:region) "; } $sql = "SELECT tax_value\n FROM {$this->table}\n WHERE tax_id=:id\n AND country_iso3=:country\n {$region_sql}\n ORDER BY region_code IS NOT NULL\n LIMIT 1"; $result = $this->query($sql, $data)->fetchField(); } if ($result === false) { static $all_rates = null, $eu_rates = null, $rest_rates = null; if ($rest_rates === null) { $all_rates = $eu_rates = $rest_rates = array(); $sql = "SELECT * FROM {$this->table} WHERE country_iso3 IN ('%AL', '%EU', '%RW') AND region_code iS NULL"; foreach ($this->query($sql) as $row) { switch ($row['country_iso3']) { case '%AL': $all_rates[$row['tax_id']] = $row['tax_value']; break; case '%EU': $eu_rates[$row['tax_id']] = $row['tax_value']; break; case '%RW': $rest_rates[$row['tax_id']] = $row['tax_value']; break; } } } if (isset($all_rates[$tax_id])) { $result = $all_rates[$tax_id]; } if (isset($rest_rates[$tax_id])) { $result = $rest_rates[$tax_id]; } if ($country && self::isEuropean($country)) { $result = ifset($eu_rates[$tax_id]); } } return (double) $result; }
protected function create($params = array()) { $config = array('name' => ifempty($params['name'], $this->widget_id), 'size' => array('2x2', '2x1', '1x1'), 'img' => "img/{$this->widget_id}.png", 'version' => ifempty($params['version'], $this->getDefaults('version')), 'vendor' => ifempty($params['vendor'], $this->getDefaults('vendor'))); if ($this->app_id == 'webasyst') { $name = $this->widget_id; } else { $name = $this->app_id . ucfirst($this->widget_id); } $paths = array("img/{$this->widget_id}.png", 'lib/config/widget.php' => $config, "lib/{$name}.widget.php" => $this->getWidgetCode($name), 'templates/Default.html' => $this->getTemplateCode()); if (isset($params['settings'])) { $paths = array_merge($paths, array('lib/config/settings.php' => array())); } $this->createStructure($paths); $protected_paths = array('lib/', 'templates/'); $this->protect($protected_paths); return $config; }
protected function saveFromPost($rm, $cm, $country) { if (!$country || !waRequest::post()) { return; } if (waRequest::post('fav')) { $region = waRequest::post('region'); $fav_sort = waRequest::post('fav_sort'); if ($fav_sort === '') { $fav_sort = null; } if ($region) { $rm->updateByField(array('country_iso3' => $country, 'code' => $region), array('fav_sort' => $fav_sort)); } else { $cm->updateByField('iso3letter', $country, array('fav_sort' => $fav_sort)); } echo json_encode(array('status' => 'ok', 'data' => 'ok')); exit; } $region_codes = waRequest::post('region_codes'); if (!$region_codes || !is_array($region_codes)) { $region_codes = array(); } $region_names = waRequest::post('region_names'); if (!$region_names || !is_array($region_names)) { $region_names = array(); } $region_favs = waRequest::post('region_favs'); if (!$region_favs || !is_array($region_favs)) { $region_favs = array(); } $regions = array(); foreach ($region_codes as $i => $code) { $code = trim($code); $name = trim(ifempty($region_names[$i], '')); $fav = trim(ifempty($region_favs[$i], '')); if (!$name || !$code) { continue; } $regions[$code] = empty($fav) ? $name : array('name' => $name, 'fav_sort' => $fav); } $rm->saveForCountry($country, $regions); $country_fav = waRequest::post('country_fav', null, 'int'); $cm->updateByField('iso3letter', $country, array('fav_sort' => ifempty($country_fav))); }
function getItemsPerPageControl($PHP_SELF, $HTTP_VARS) { $buffer = ''; $items_per_page_options_r = get_opendb_config_var('listings', 'items_per_page_options'); if (is_not_empty_array($items_per_page_options_r)) { $items_per_page_rs = array(); while (list(, $items_per_page) = each($items_per_page_options_r)) { if ($items_per_page == '0') { $display = get_opendb_lang_var('all'); } else { $display = $items_per_page; } $items_per_page_rs[] = array('value' => $items_per_page, 'display' => $display); } $buffer .= "<form class=\"itemsPerPageControl\" id=\"form-items_per_page\" action=\"" . $PHP_SELF . "\" method=\"GET\">" . get_url_fields($HTTP_VARS) . "<label for=\"select-items_per_page\">" . get_opendb_lang_var('items_per_page') . '</label>' . "<select id=\"select-items_per_page\" name=\"items_per_page\" class=\"footer\" onChange=\"this.form.submit()\">" . custom_select('items_per_page', $items_per_page_rs, '%display%', 'NA', ifempty($HTTP_VARS['items_per_page'], get_opendb_config_var('listings', 'items_per_page')), 'value') . "\n</select></form>"; } return $buffer; }
public function execute(&$params) { $master_id = $params['id']; $merge_ids = $params['contacts']; $all_ids = array_merge($merge_ids, array($master_id)); $m = new waModel(); // // All the simple cases: update contact_id in tables // foreach (array(array('shop_cart_items', 'contact_id'), array('shop_checkout_flow', 'contact_id'), array('shop_order', 'contact_id'), array('shop_order_log', 'contact_id'), array('shop_product', 'contact_id'), array('shop_product_reviews', 'contact_id'), array('shop_affiliate_transaction', 'contact_id')) as $pair) { list($table, $field) = $pair; $sql = "UPDATE {$table} SET {$field} = :master WHERE {$field} in (:ids)"; $m->exec($sql, array('master' => $master_id, 'ids' => $merge_ids)); } // // shop_affiliate_transaction // $balance = 0.0; $sql = "SELECT * FROM shop_affiliate_transaction WHERE contact_id=? ORDER BY id"; foreach ($m->query($sql, $master_id) as $row) { $balance += $row['amount']; if ($row['balance'] != $balance) { $m->exec("UPDATE shop_affiliate_transaction SET balance=? WHERE id=?", $balance, $row['id']); } } $affiliate_bonus = $balance; // // shop_customer // // Make sure it exists $cm = new shopCustomerModel(); $cm->createFromContact($master_id); $sql = "SELECT SUM(number_of_orders) FROM shop_customer WHERE contact_id IN (:ids)"; $number_of_orders = $m->query($sql, array('ids' => $all_ids))->fetchField(); $sql = "SELECT MAX(last_order_id) FROM shop_customer WHERE contact_id IN (:ids)"; $last_order_id = $m->query($sql, array('ids' => $all_ids))->fetchField(); $sql = "UPDATE shop_customer SET number_of_orders=?, last_order_id=?, affiliate_bonus=? WHERE contact_id=?"; $m->exec($sql, ifempty($number_of_orders, 0), ifempty($last_order_id, null), ifempty($affiliate_bonus, 0), $master_id); if ($number_of_orders) { shopCustomers::recalculateTotalSpent($master_id); } wa('shop')->event('customers_merge', $params); return null; }
public function execute() { $contact_id = waRequest::post('contact_id', 0, 'int'); $amount = (double) str_replace(',', '.', waRequest::post('amount', '0')); $comment = trim(waRequest::post('comment', '')); if (!$contact_id || !$amount) { return; } if (!$comment) { if ($amount < 0) { $comment = _w('Bonus pay out'); $this->logAction('affiliate_payout', -$amount, $contact_id); } else { $comment = _w('Bonus credit'); $this->logAction('affiliate_credit', $amount, $contact_id); } } $atm = new shopAffiliateTransactionModel(); $atm->applyBonus($contact_id, $amount, null, ifempty($comment), $amount > 0 ? shopAffiliateTransactionModel::TYPE_DEPOSIT : shopAffiliateTransactionModel::TYPE_WITHDRAWAL); }
public function frontendSidebar($params) { $output = array(); $config = (include $this->path . '/lib/config/config.php'); $tag_model = new blogTagPluginModel(); if ($tags = $tag_model->getAllTags($config)) { $output['sidebar'] = '<div class="tags cloud">'; $wa = wa(); foreach ($tags as $tag) { $tag['link'] = $wa->getRouteUrl('blog/frontend', array('tag' => urlencode($tag['name'])), true); $tag['name'] = htmlentities($tag['name'], ENT_QUOTES, 'utf-8'); $output['sidebar'] .= <<<HTML <a href="{$tag['link']}" style="font-size: {$tag['size']}%; opacity: {$tag['opacity']};">{$tag['name']}</a> HTML; } $output['sidebar'] .= '</div>'; } return ifempty($output, null); }
public function catalogAction() { /** * @var shopYandexmarketPlugin $plugin */ $plugin = wa()->getPlugin('yandexmarket'); $profile_helper = new shopImportexportHelper('yandexmarket'); list($path, $profile_id) = $plugin->getInfoByHash(waRequest::param('hash')); if ($profile_id) { $profile = $profile_helper->getConfig($profile_id); if (!$profile) { throw new waException('Profile not found', 404); } $lifetime = ifset($profile['config']['lifetime'], 0); if ($lifetime && (!file_exists($path) || time() - filemtime($path) > $lifetime)) { waRequest::setParam('profile_id', $profile_id); $runner = new shopYandexmarketPluginRunController(); $_POST['processId'] = null; $moved = false; $ready = false; do { ob_start(); if (empty($_POST['processId'])) { $_POST['processId'] = $runner->processId; } else { sleep(1); } if ($ready) { $_POST['cleanup'] = true; $moved = true; } $runner->execute(); $out = ob_get_clean(); $result = json_decode($out, true); $ready = !empty($result) && is_array($result) && ifempty($result['ready']); } while (!$ready || !$moved); //TODO check errors } } waFiles::readFile($path, waRequest::get('download') ? 'yandexmarket.xml' : null); }
public function execute() { /** * Backend discount settings * * Allows to add custom discount types to discount settings page. * * Plugins are expected to return one item or a list of items to to add to discounts menu. * Each item is represented by an array: * array( * 'id' => string, // Optional discount type ID. Defaults to plugin_id. * 'name' => string, // Required. Human-readable name of dicount type. * 'url' => string, // Required (unless you hack into JS using 'html' parameter). Content for settings page is fetched from this URL. * 'status' => bool, // Optional. Whether this discount type is active. Defaults to false (disabled). * 'html' => string, // Optional. Custom HTML to append to discounts settings page. E.g. for custom JS purposes. * ) * * @event backend_settings_discounts */ $plugin_types = wa()->event('backend_settings_discounts'); $all_types = array(); foreach ($plugin_types + array('shop' => self::getCoreTypes()) as $plugin_id => $types) { if (isset($types['name'])) { $types['id'] = $plugin_id; $types = array($types); } foreach ($types as $i => $type) { if (empty($type['name'])) { continue; } if (empty($type['id'])) { $type['id'] = $plugin_id . '_' . $i; } $type['status'] = ifempty($type['status'], false); $all_types[$type['id']] = $type; } } $this->view->assign('types', $all_types); $this->view->assign('combiner', wa()->getSetting('discounts_combine', 'max')); }
public static function savePlugin($plugin) { $default = array('status' => 0); $plugin = array_merge($default, $plugin); if (!intval(ifempty($plugin['id'])) && isset($plugin['settings'])) { $instance = waShipping::factory($plugin['plugin'], null, self::getInstance()); $instance->saveSettings($plugin['settings']); } $model = new shopPluginModel(); if (!empty($plugin['id']) && ($id = max(0, intval($plugin['id']))) && ($row = $model->getByField(array('id' => $id, 'type' => shopPluginModel::TYPE_SHIPPING)))) { $plugin['plugin'] = $row['plugin']; $model->updateById($plugin['id'], $plugin); } elseif (!empty($plugin['plugin'])) { $plugin['type'] = shopPluginModel::TYPE_SHIPPING; $plugin['id'] = $model->insert($plugin); } if (!empty($plugin['id']) && isset($plugin['settings'])) { $instance = waShipping::factory($plugin['plugin'], $plugin['id'], self::getInstance()); $instance->saveSettings($plugin['settings']); } return $plugin; }
function queryListing($page_no, $items_per_page, $offset, $s_item_type, $search_vars_r) { if (!$this->isConfigured) { return FALSE; } if (strlen($search_vars_r[$this->siteAttributeType]) > 0) { $context_search_vars[$this->siteAttributeType] = $search_vars_r[$this->siteAttributeType]; $this->addListingRow(NULL, NULL, NULL, $context_search_vars); return TRUE; } else { $index_type = ifempty($this->getConfigValue('item_type_to_index_map', $s_item_type), strtolower($s_item_type)); $response = $this->client->category($index_type)->responseGroup("Small,Images")->page($page_no)->search($search_vars_r['title']); if (is_array($response['Items']) && is_array($response['Items']['Request']) && $response['Items']['Request']['IsValid'] == 'True') { $this->setTotalCount($response['Items']['TotalResults']); while (list(, $item_r) = each($response['Items']['Item'])) { $this->addListingRow($item_r['ItemAttributes']['Title'], $item_r['SmallImage']['URL'], NULL, array($this->siteAttributeType => $item_r['ASIN'], 'search.title' => $search_vars_r['title'])); } return TRUE; } else { return FALSE; } } }