예제 #1
0
 public function testAddDocument()
 {
     $configuration = za()->getConfig('services');
     if (!$configuration) {
         echo "No services config found\n";
         return;
     }
     $searchConfig = ifset($configuration, 'SearchService');
     if (!$searchConfig) {
         echo "SearchService config not found\n";
         return;
     }
     $path = ifset($searchConfig, 'index');
     if (!$path) {
         echo "No search path set\n";
         return;
     }
     // Delete the search path
     rmdirr($path);
     $searchService = za()->getService('SearchService');
     $example = new Task();
     $example->id = 1;
     $example->title = 'Task for testing';
     $example->description = "Task description for testing";
     try {
         $searchService->index($example);
     } catch (Exception $e) {
         print_r($e);
     }
     $results = $searchService->search("testing");
     $this->assertEqual(count($results), 1);
 }
 public function execute()
 {
     if (!$this->getUser()->getRights('shop', 'settings')) {
         throw new waRightsException(_w('Access denied'));
     }
     $cm = new waCountryModel();
     $rm = new waRegionModel();
     $country = waRequest::request('country');
     $this->saveFromPost($rm, $cm, $country);
     $countries = $cm->all();
     if (!$country || empty($countries[$country])) {
         $country = wa()->getSetting('country');
     }
     if (!$country || empty($countries[$country])) {
         // Show the first country with regions by default
         $region_countries = $rm->getCountries();
         $country = reset($region_countries);
         if (!$country || empty($countries[$country])) {
             $country = key($countries);
         }
     }
     $regions = $country ? $rm->getByCountry($country) : array();
     $this->view->assign('countries', $cm->allWithFav($countries));
     $this->view->assign('country', ifset($countries[$country], $cm->getEmptyRow()));
     $this->view->assign('regions', $regions);
 }
 public function execute()
 {
     $settings = waRequest::post('settings', array(), waRequest::TYPE_ARRAY);
     if (strlen($error = logsHelper::setPhpLogSetting(ifset($settings['php_log'], false)))) {
         $this->errors[] = $error;
     }
 }
 protected function isAuth($order, &$code)
 {
     $result = false;
     if (!$result) {
         $result = $order['id'] == wa()->getStorage()->get('shop/order_id');
     }
     if (!$result) {
         // Check that order exists and belongs to this user
         $result = $order['contact_id'] == wa()->getUser()->getId() && $order['state_id'] != 'deleted';
     }
     if (!$result && $code) {
         // Check auth code
         $opm = new shopOrderParamsModel();
         $params = $opm->get($order['id']);
         if (!empty($params['auth_pin']) && ifset($params['auth_code']) === $code) {
             $pin = wa()->getStorage()->get('shop/pin/' . $order['id']);
             if ($pin && $pin == $params['auth_pin']) {
                 $result = true;
             }
         } else {
             $code = false;
         }
     }
     return $result;
 }
예제 #5
0
function listplug_select($template, $type)
{
    switch ($type) {
        case 'HEAD':
            echo '<select name="' . ifset($template['name']) . '" tabindex="' . ifset($template['tabindex']) . '" ' . ifset($template['javascript']) . '>';
            // add extra row if needed
            if (ifset($template['extra'])) {
                echo '<option value="', ifset($template['extraval']), '">', $template['extra'], '</option>';
            }
            break;
        case 'BODY':
            $current = $template['current'];
            echo '<option value="' . htmlspecialchars($current->value) . '"';
            if ($template['selected'] == $current->value) {
                echo ' selected="selected" ';
            }
            if (isset($template['shorten']) && $template['shorten'] > 0) {
                echo ' title="' . htmlspecialchars($current->text) . '"';
                $current->text = shorten($current->text, $template['shorten'], $template['shortenel']);
            }
            echo '>' . htmlspecialchars($current->text) . '</option>';
            break;
        case 'FOOT':
            echo '</select>';
            break;
    }
}
 public function execute()
 {
     $id = waRequest::get('id');
     $model = new shopNotificationModel();
     $n = $model->getById($id);
     $params_model = new shopNotificationParamsModel();
     $params = $params_model->getParams($id);
     // Orders used as sample data for testing
     $om = new shopOrderModel();
     $test_orders = $om->where("paid_date IS NOT NULL AND state_id <> 'deleted'")->order('id DESC')->limit(10)->fetchAll('id');
     shopHelper::workupOrders($test_orders);
     $im = new shopOrderItemsModel();
     foreach ($im->getByField('order_id', array_keys($test_orders), true) as $i) {
         $test_orders[$i['order_id']]['items'][] = $i;
     }
     foreach ($test_orders as &$o) {
         $o['items'] = ifset($o['items'], array());
         $o['total_formatted'] = waCurrency::format('%{s}', $o['total'], $o['currency']);
     }
     $this->view->assign('n', $n);
     $this->view->assign('params', $params);
     $this->view->assign('transports', self::getTransports());
     $this->view->assign('events', $this->getEvents());
     $this->view->assign('test_orders', $test_orders);
     $this->view->assign('default_email_from', $this->getConfig()->getGeneralSettings('email'));
     $this->view->assign('sms_from', $this->getSmsFrom());
     $this->view->assign('routes', wa()->getRouting()->getByApp('shop'));
 }
 protected function parseValue($value, $type)
 {
     $code = null;
     $suggest = false;
     if (is_array($value)) {
         $code = ifset($value['code']);
         $value = trim(ifset($value['value']));
         //rgb(r,g,b) #ABC #AABBCC;
         if ($code === '') {
             $code = shopColorValue::getCode($value);
         } elseif (preg_match('@^#?([0-9A-F]{3}|[0-9A-F]{6})@ui', $code)) {
             if (strpos($code, '#') === 0) {
                 $code = substr($code, 1);
             }
             if ($parsed = sscanf(strtoupper($code), '%03X%03X')) {
                 if ($parsed[1] === null) {
                     $code = (0xf00 & $parsed[0]) << 12;
                     $code |= (0xff0 & $parsed[0]) << 8;
                     $code |= (0xff & $parsed[0]) << 4;
                     $code |= 0xf & $parsed[0];
                 } else {
                     $code = $parsed[0] << 12 | $parsed[1];
                 }
             } else {
                 $code = null;
             }
         } elseif (strpos('rgb', $code) === 0) {
             //TODO
         } else {
             $code = intval($code);
         }
         if ($value === '' && $code !== null) {
             $suggest = true;
             $value = shopColorValue::getName($code);
         }
     } else {
         $value = trim($value);
         if (preg_match('@^#?(([0-9A-F]{3})|([0-9A-F]{6}))$@ui', $value, $matches)) {
             if ($matches[2]) {
                 $value = sscanf(strtoupper($matches[2]), '%03X');
                 $code = reset($value);
             } elseif ($matches[3]) {
                 $value = sscanf(strtoupper($matches[3]), '%06X');
                 $code = reset($value);
             } else {
                 $code = 0;
             }
             $value = shopColorValue::getName($code);
         } else {
             $suggest = true;
             $code = shopColorValue::getCode($value);
         }
     }
     $data = array('value' => $value, 'search_value' => $value, 'suggest' => $suggest);
     if ($code !== null) {
         $data['code'] = $code;
     }
     return $data;
 }
예제 #8
0
 public function indexAction()
 {
     $this->view->pagerName = "contact-page";
     $this->view->letters = $this->clientService->getContactLetters();
     $currentLetter = ifset($this->_getAllParams(), $this->view->pagerName, ifset($this->view->letters, 0, 'A'));
     $this->view->contacts = $this->clientService->getContacts(null, array('firstname like ' => $currentLetter . '%'), 'firstname asc');
     $this->renderView('contact/index.php');
 }
예제 #9
0
 private function getStaticImg($address, $options = array())
 {
     $zoom = ifset($options['zoom'], 10);
     $width = ifset($options['width'], '600');
     $height = ifset($options['height'], '400');
     $size = (int) $width . 'x' . (int) $height;
     return '<img src="//maps.googleapis.com/maps/api/staticmap?center=' . urlencode($address) . '.&zoom=' . $zoom . '&size=' . $size . '&markers=color:red%7Clabel:A%7C' . urlencode($address) . '&sensor=false" />';
 }
 public function execute()
 {
     $code = waRequest::param('code');
     $encoded_order_id = waRequest::param('id');
     $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);
     }
     if (!$order_id || $order_id != substr($code, 16, -16)) {
         throw new waException(_w('Order not found'), 404);
     }
     // When user is authorized, check if order belongs to him.
     // When it does, redirect to plain order page.
     if (wa()->getUser()->isAuth()) {
         $om = new shopOrderModel();
         $order = $om->getOrder($order_id);
         if (!$order) {
             throw new waException(_w('Order not found'), 404);
         }
         if ($order['contact_id'] == wa()->getUser()->getId()) {
             $this->redirect(wa()->getRouteUrl('/frontend/myOrder', array('id' => $order_id)));
         }
     }
     // Check auth code
     $opm = new shopOrderParamsModel();
     $params = $opm->get($order_id);
     if (ifset($params['auth_code']) !== $code || empty($params['auth_pin'])) {
         throw new waException(_w('Order not found'), 404);
     }
     // Check auth pin and show order page if pin is correct
     $pin = waRequest::request('pin', wa()->getStorage()->get('shop/pin/' . $order_id));
     if ($pin && $pin == $params['auth_pin']) {
         wa()->getStorage()->set('shop/pin/' . $order_id, $pin);
         parent::execute();
         if (!waRequest::isXMLHttpRequest()) {
             $this->layout->assign('breadcrumbs', self::getBreadcrumbs());
         }
         return;
     }
     //
     // No pin or pin is incorrect: show form to enter pin
     //
     $this->view->assign('wrong_pin', !!$pin);
     $this->view->assign('pin_required', true);
     $this->view->assign('encoded_order_id', $encoded_order_id);
     $this->view->assign('my_nav_selected', 'orders');
     // Set up layout and template from theme
     $this->setThemeTemplate('my.order.html');
     if (!waRequest::isXMLHttpRequest()) {
         $this->setLayout(new shopFrontendLayout());
         $this->getResponse()->setTitle(_w('Order') . ' ' . $encoded_order_id);
         $this->view->assign('breadcrumbs', self::getBreadcrumbs());
         $this->layout->assign('nofollow', true);
     }
 }
예제 #11
0
 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);
 }
예제 #12
0
 public function configure($config)
 {
     $this->fileRoot = APP_DIR . ifset($config, 'root', '/data/files');
     if (!is_dir($this->fileRoot)) {
         // failure!
         if (!mkdirr($this->fileRoot, 0775)) {
             throw new Exception("Could not find file root at {$this->fileRoot}");
         }
     }
 }
 public function execute()
 {
     $data = waRequest::post('settings');
     unset($data['search_name']);
     if (isset($data['data_contact']) && is_array($data['data_contact'])) {
         if ($data['config_name'] != '') {
             if ($data['from'] != '') {
                 $info = $data;
                 $modelNotifierRule = new shopNotifierRuleModel();
                 $data_contact = json_encode($info['data_contact']);
                 unset($info['data_contact']);
                 $info['data_contact'] = $data_contact;
                 $state_name = json_encode($info['state_name']);
                 unset($info['state_name']);
                 $info['state_name'] = $state_name;
                 $info['group_senders'] = ifset($info['group_senders'], 0);
                 $info['save_to_order_log'] = ifset($info['save_to_order_log'], 0);
                 $result = $modelNotifierRule->getByField('config_name', $data['config_name']);
                 $val_update = '';
                 $column_insert = '';
                 $value_insert = '';
                 $len = count($info);
                 $i = 0;
                 foreach ($info as $key => $value) {
                     $i++;
                     if ($len == $i) {
                         $value_insert .= "'" . $value . "'";
                         $column_insert .= $key;
                         $val_update .= $key . "='" . $value . "'";
                     } else {
                         $value_insert .= "'" . $value . "', ";
                         $column_insert .= $key . ', ';
                         $val_update .= $key . "='" . $value . "',";
                     }
                 }
                 if ($result) {
                     $modelNotifierRule->updateById($result['id'], $info);
                     //                        query("UPDATE shop_notifier_rule SET ".$val_update." WHERE id = '".$result['id']."'");
                     $data['id'] = $result['id'];
                 } else {
                     $data['id'] = $modelNotifierRule->insert($info);
                     //query("INSERT INTO shop_notifier_rule (".$column_insert.") VALUES (".$value_insert.")");
                 }
                 $this->response['data'] = $data;
                 $this->response['message'] = 'ok';
             } else {
                 $this->response['message'] = 'fail_send_email';
             }
         } else {
             $this->response['message'] = 'fail_config_name_null';
         }
     } else {
         $this->response['message'] = 'fail_data_contact';
     }
 }
예제 #14
0
파일: Pager.php 프로젝트: nyeholt/relapse
 /**
  * @param int $total The total number of things being shown
  * @param int $perPage How many things per page
  * @param string $name the name of the page
  * @param array $params additional params to use
  * @param int $currentPage
  */
 public function Pager($total, $perPage, $name = 'page', $params = array(), $persistParams = false, $currentPage = 0, $prev = '&laquo;', $next = '&raquo;', $numberOfLinks = 10)
 {
     if ($total == 0 || $perPage == 0) {
         return;
     }
     if ($total <= $perPage) {
         return;
     }
     // If not set, check the request, otherwise just
     // assume first page
     if (!$currentPage) {
         $currentPage = ifset($_GET, $name, 1);
     }
     $totalPages = ceil($total / $perPage);
     // Figure out where to start printing from
     $eitherSide = floor($numberOfLinks / 2);
     $start = 1;
     $end = $numberOfLinks;
     if ($currentPage > $eitherSide) {
         $start = $currentPage - $eitherSide;
         $end = $currentPage + $eitherSide;
     }
     // Account for the extra item we get if we're
     // an even numberoflinks value
     $end--;
     if ($end > $totalPages) {
         $end = $totalPages;
     }
     $args = '';
     $ctrl = Zend_Controller_Front::getInstance();
     $oldRequest = $ctrl->getRequest()->getParams();
     if ($persistParams) {
         foreach ($oldRequest as $param => $value) {
             if ($param != 'action' && $param != 'controller' && $param != 'module' && $param != $name && !isset($params[$param])) {
                 $params[$param] = $value;
             }
         }
     }
     $args = '&amp;' . encode_params($params, '&amp;', '=');
     echo '<div class="pager-links">';
     if ($currentPage > 1) {
         echo '<a class="pager-prev-link pager-link" href="' . current_url() . '?' . $name . '=' . ($currentPage - 1) . $args . '">' . $prev . '</a>';
     }
     for ($i = $start; $i <= $end; $i++) {
         if ($i == $currentPage) {
             echo '<span class="pager-current-link pager-link">' . $i . '</span>';
         } else {
             echo '<a class="pager-link" href="' . current_url() . '?' . $name . '=' . $i . $args . '">' . $i . '</a>';
         }
     }
     if ($currentPage < $totalPages) {
         echo '<a class="pager-next-link pager-link" href="' . current_url() . '?' . $name . '=' . ($currentPage + 1) . $args . '">' . $next . '</a>';
     }
     echo '</div>';
 }
예제 #15
0
 public static function getRole($role)
 {
     if (self::$roles == null) {
         self::$roles = array();
         self::$roles[self::ROLE_READ] = self::PERM_READ;
         self::$roles[self::ROLE_WRITE] = self::PERM_READ + self::PERM_WRITE;
         self::$roles[self::ROLE_POWER] = self::$roles[self::ROLE_WRITE] + self::PERM_POWER;
         self::$roles[self::ROLE_MANAGER] = self::$roles[self::ROLE_POWER] + self::PERM_MANAGER;
         self::$roles[self::ROLE_ADMIN] = self::$roles[self::ROLE_MANAGER] + self::PERM_ADMIN;
     }
     return ifset(self::$roles, $role, 0);
 }
예제 #16
0
 /**
  * Returns aggregate discount amount applicable to order.
  * 
  * @param array $order Order data array
  * @param bool $apply Whether discount-related information must be added to order parameters (where appropriate)
  * @return float Total discount value expressed in order currency
  */
 public static function calculate(&$order, $apply = false)
 {
     $currency = isset($order['currency']) ? $order['currency'] : wa('shop')->getConfig()->getCurrency(false);
     $applicable_discounts = array();
     $contact = self::getContact($order);
     // Discount by contact category applicable?
     if (self::isEnabled('category')) {
         $applicable_discounts[] = self::byCategory($order, $contact, $apply);
     }
     // Discount by coupon applicable?
     if (self::isEnabled('coupons')) {
         $applicable_discounts[] = self::byCoupons($order, $contact, $apply);
     }
     // Discount by order total applicable?
     if (self::isEnabled('order_total')) {
         $crm = new shopCurrencyModel();
         $dbsm = new shopDiscountBySumModel();
         // Order total in default currency
         $order_total = (double) $crm->convert($order['total'], $currency, wa('shop')->getConfig()->getCurrency());
         $applicable_discounts[] = max(0.0, min(100.0, (double) $dbsm->getDiscount('order_total', $order_total))) * $order['total'] / 100.0;
     }
     // Discount by customer total spent applicable?
     if (self::isEnabled('customer_total')) {
         $applicable_discounts[] = self::byCustomerTotal($order, $contact, $apply);
     }
     /**
      * @event order_calculate_discount
      * @param array $params
      * @param array[string] $params['order'] order info array('total' => '', 'items' => array(...))
      * @param array[string] $params['contact'] contact info
      * @param array[string] $params['apply'] calculate or apply discount
      * @return float discount
      */
     $event_params = array('order' => &$order, 'contact' => $contact, 'apply' => $apply);
     $plugins_discounts = wa('shop')->event('order_calculate_discount', $event_params);
     foreach ($plugins_discounts as $plugin_discount) {
         $applicable_discounts[] = $plugin_discount;
     }
     // Select max discount or sum depending on global setting.
     $discount = 0.0;
     if ($applicable_discounts = array_filter($applicable_discounts, 'is_numeric')) {
         if (wa('shop')->getSetting('discounts_combine') == 'sum') {
             $discount = (double) array_sum($applicable_discounts);
         } else {
             $discount = (double) max($applicable_discounts);
         }
     }
     // Discount based on affiliate bonus?
     if (shopAffiliate::isEnabled()) {
         $discount = $discount + (double) shopAffiliate::discount($order, $contact, $apply, $discount);
     }
     return min(max(0, $discount), ifset($order['total'], 0));
 }
 public function execute()
 {
     $term = waRequest::request('term');
     $limit = waRequest::request('limit', 30, 'int');
     if (mb_strlen($term) < 2) {
         return;
     }
     $type = waRequest::request('type', null, waRequest::TYPE_STRING_TRIM);
     $model = new waModel();
     if (strpos($term, '@') !== FALSE) {
         $contacts = new contactsCollection('/search/email*=' . $term);
     } else {
         $contacts = new contactsCollection();
         $t_a = preg_split("/\\s+/", $term);
         $cond = array();
         foreach ($t_a as $t) {
             $t = trim($t);
             if ($t) {
                 $t = $model->escape($t, 'like');
                 if ($type === 'person') {
                     $cond[] = "(c.firstname LIKE '{$t}%' OR c.middlename LIKE '{$t}%' OR c.lastname LIKE '{$t}%')";
                 } else {
                     if ($type === 'company') {
                         $cond[] = "c.name LIKE '{$t}%'";
                     } else {
                         $cond[] = "(c.firstname LIKE '{$t}%' OR c.middlename LIKE '{$t}%' OR c.lastname LIKE '{$t}%' OR c.name LIKE '{$t}%')";
                     }
                 }
             }
         }
         if ($cond) {
             $contacts->addWhere(implode(" AND ", $cond));
         }
     }
     if ($type) {
         if ($type === 'person') {
             $contacts->addWhere("is_company = 0");
         } else {
             if ($type === 'company') {
                 $contacts->addWhere("is_company = 1");
             }
         }
     }
     $this->response = array();
     $term_safe = htmlspecialchars($term);
     foreach ($contacts->getContacts('id,name,company,email', 0, $limit) as $c) {
         $name = $this->prepare($c['name'], $term_safe);
         $email = $this->prepare(ifset($c['email'][0], ''), $term_safe);
         $company = $this->prepare($c['company'], $term_safe);
         $this->response[] = array('label' => implode(', ', array_filter(array($name, $company, $email))), 'value' => $c['id'], 'name' => $c['name'], 'email' => ifset($c['email'][0], ''), 'company' => $c['company']);
     }
 }
 public function execute()
 {
     $asm = new waAppSettingsModel();
     if (waRequest::post()) {
         $conf = waRequest::post('conf');
         if ($conf && is_array($conf)) {
             $conf['affiliate_credit_rate'] = str_replace(',', '.', (double) str_replace(',', '.', ifset($conf['affiliate_credit_rate'], '0')));
             $conf['affiliate_usage_rate'] = str_replace(',', '.', (double) str_replace(',', '.', ifset($conf['affiliate_usage_rate'], '0')));
             foreach ($conf as $k => $v) {
                 $asm->set('shop', $k, $v);
             }
         }
     }
     $enabled = shopAffiliate::isEnabled();
     $def_cur = waCurrency::getInfo(wa()->getConfig()->getCurrency());
     $tm = new shopTypeModel();
     $product_types = $tm->getAll();
     $conf = $asm->get('shop');
     if (!empty($conf['affiliate_product_types'])) {
         $conf['affiliate_product_types'] = array_fill_keys(explode(',', $conf['affiliate_product_types']), true);
     } else {
         $conf['affiliate_product_types'] = array();
     }
     $this->view->assign('conf', $conf);
     $this->view->assign('enabled', $enabled);
     $this->view->assign('product_types', $product_types);
     $this->view->assign('def_cur_sym', ifset($def_cur['sign'], wa()->getConfig()->getCurrency()));
     /**
      * Backend affiliate settings
      *
      * Plugins are expected to return one item or a list of items to to add to affiliate menu.
      * Each item is represented by an array:
      * array(
      *   'id'   => string,  // Required.
      *   'name' => string,  // Required.
      *   'url'  => string,  // Required (unless you hack into JS using 'html' parameter). Content for settings page is fetched from this URL.
      * )
      *
      * @event backend_settings_discounts
      */
     $plugins = wa()->event('backend_settings_affiliate');
     $config = wa('shop')->getConfig();
     foreach ($plugins as $k => &$p) {
         if (substr($k, -7) == '-plugin') {
             $plugin_id = substr($k, 0, -7);
             $plugin_info = $config->getPluginInfo($plugin_id);
             $p['img'] = $plugin_info['img'];
         }
     }
     $this->view->assign('plugins', $plugins);
     $this->view->assign('installer', $this->getUser()->getRights('installer', 'backend'));
 }
    function parse_modal_layout($layout)
    {
        function parse_modal_layout_styles($width)
        {
            if (preg_match("/(\\d+(\\.\\d+)?)(px)/", $width)) {
                return "class=\"span\" style=\"width: {$width}; margin-left: 0;\"";
            } else {
                return "class=\"span{$width}\"";
            }
        }
        switch ($layout["type"]) {
            case "horizontal":
                $width = explode(":", $layout["width"]);
                $child_counter = 0;
                ?>
				<div class="row-fluid">
					<?php 
                foreach ($layout["sublayouts"] as $sublayout_id => $sublayout) {
                    ?>
						<div <?php 
                    echo parse_modal_layout_styles($width[$child_counter++]);
                    ?>
>
							<?php 
                    parse_modal_layout($sublayout);
                    ?>
						</div>
					<?php 
                }
                ?>
					<?php 
                foreach ($layout["properties"] as $property_id => $property) {
                    ?>
						<div <?php 
                    echo parse_modal_layout_styles($width[$child_counter++]);
                    ?>
>
							<?php 
                    echo aw_modal::parse_properties(array($property_id => $property), ifset($layout, "captionside") === "left");
                    ?>
						</div>
					<?php 
                }
                ?>
				</div>
				<?php 
                break;
            case "vertical":
                echo aw_modal::parse_properties($layout["properties"], false);
                break;
        }
    }
 public function execute()
 {
     $f = waRequest::param('f');
     $fid = waRequest::param('fid');
     $parent = waRequest::param('parent');
     $css_class = waRequest::param('css_class');
     $new_field = false;
     if (!$f instanceof waContactField) {
         $new_field = true;
         $f = new waContactStringField($fid, '', array('app_id' => 'shop'));
     }
     $prefix = 'options';
     if ($parent) {
         $prefix .= '[' . $parent . '][fields]';
     }
     static $ftypes = null;
     if ($ftypes === null) {
         $ftypes = array('NameSubfield' => _w('Text (input)'), 'Email' => _w('Text (input)'), 'Address' => _w('Address'), 'Text' => _w('Text (textarea)'), 'String' => _w('Text (input)'), 'Select' => _w('Select'), 'Phone' => _w('Text (input)'), 'IM' => _w('Text (input)'), 'Url' => _w('Text (input)'), 'Date' => _w('Date'), 'Composite' => _w('Composite field group'), 'Checkbox' => _w('Checkbox'));
     }
     $form = waContactForm::loadConfig(array('_default_value' => $f), array('namespace' => "{$prefix}[{$fid}]"));
     // Get default value
     $default_value = null;
     if (!$new_field && $f->getParameter('_disabled')) {
         $settings = wa('shop')->getConfig()->getCheckoutSettings();
         if (!isset($settings['contactinfo'])) {
             $settings = wa('shop')->getConfig()->getCheckoutSettings(true);
         }
         $fields_config = ifset($settings['contactinfo']['fields'], array());
         if ($parent) {
             if (!empty($fields_config[$parent]['fields'][$fid]['hidden'])) {
                 $default_value = ifset($fields_config[$parent]['fields'][$fid]['value']);
             }
         } else {
             if (!empty($fields_config[$fid]['hidden'])) {
                 $default_value = ifset($fields_config[$fid]['value']);
             }
         }
         if ($default_value !== null) {
             $form->setValue('_default_value', $default_value);
         }
     }
     $this->view->assign('f', $f);
     $this->view->assign('fid', $fid);
     $this->view->assign('form', $form);
     $this->view->assign('parent', $parent);
     $this->view->assign('prefix', $prefix);
     $this->view->assign('uniqid', 'f' . uniqid());
     $this->view->assign('new_field', $new_field);
     $this->view->assign('tr_classes', $css_class);
     $this->view->assign('default_value', $default_value);
     $this->view->assign('ftypes', $ftypes);
 }
예제 #21
0
 public function configure($config)
 {
     try {
         Zend_Loader::loadFile(ifset($config, 'type_cache', self::$CACHE_FILE), 'data/cache', true);
         global $__TYPE_CACHE;
         if (isset($__TYPE_CACHE)) {
             $this->typeMap = $__TYPE_CACHE;
         } else {
             $this->typeMap = array();
         }
     } catch (Zend_Exception $e) {
     }
 }
예제 #22
0
파일: utils.php 프로젝트: nyeholt/relapse
function print_backtrace($trace, $log = true)
{
    $func = 'print';
    if ($log) {
        $func = 'error_log';
    }
    foreach ($trace as $t) {
        if ($func == 'error_log') {
            za()->log(ifset($t, 'line', 'unknown') . ':' . ifset($t, 'file', 'null'), Zend_Log::ERR);
        } else {
            $func(ifset($t, 'line', 'unknown') . ':' . ifset($t, 'file', 'null'));
        }
    }
}
 public function execute()
 {
     $album_id = waRequest::get('id', null, waRequest::TYPE_INT);
     $album_model = new photosAlbumModel();
     $albums = $album_model->getAlbums();
     $album = ifset($albums[$album_id]);
     if (!$album_id || !$album) {
         throw new waException(_w('Unknown album'));
     }
     $collection = new photosCollection('/album/' . $album_id);
     $this->view->assign('album', $album);
     $this->view->assign('photos_count', $collection->count());
     $this->view->assign('offspring', $this->getOffspringIds($albums, $album_id));
 }
예제 #24
0
 /**
  * @param string $date_with_hour datetime in 'Y-m-d H' format
  * @param string $city
  * @param string $unit C or F
  * @return array|null
  */
 public function getWeather($date_with_hour, $city, $unit = 'C', $from_cache = true)
 {
     $cache = $this->getCacheWeather();
     if (!$from_cache && (empty($cache[$date_with_hour][$city]) || !empty($cache[$date_with_hour][$city]['message']))) {
         $weather = array();
         // Close the session to allow parallel HTTP requests during this (potentially long) operation
         wa()->getStorage()->close();
         // make maximum 3 tries for loading weather
         for ($tries = 3; $tries > 0; $tries--) {
             try {
                 $weather = $this->loadWeather($city);
             } catch (Exception $e) {
                 // Something's badly wrong (as opposed to an empty result)
                 // and we should not try again.
                 $weather = array('message' => $e->getMessage());
                 break;
             }
             if (!empty($weather) && empty($weather['message'])) {
                 // Only write to real persistemt cache if there's no error
                 $this->setCacheWeather($cache);
                 break;
             }
             $tries > 1 && sleep(4 - $tries);
         }
         $cache[$date_with_hour][$city] = $weather;
         // Open the session storage again
         wa()->getStorage()->open();
     }
     $weather = ifset($cache[$date_with_hour][$city], array());
     if ($unit === 'C') {
         foreach (array('temp', 'temp_min', 'temp_max') as $temp_key) {
             if (isset($weather['main'][$temp_key])) {
                 $temp_F = $weather['main'][$temp_key];
                 $weather['main'][$temp_key] = ($temp_F - 32) * 5 / 9;
             }
         }
     }
     foreach (array('temp', 'temp_min', 'temp_max') as $temp_key) {
         if (isset($weather['main'][$temp_key])) {
             $weather['main'][$temp_key] = (int) round($weather['main'][$temp_key], 1);
         }
     }
     if (!empty($weather['weather'])) {
         if (isset($weather['weather'][0])) {
             $weather['weather'] = $weather['weather'][0];
         }
     }
     return $weather;
 }
예제 #25
0
 public function getRecordedTime()
 {
     $theProject = $this->projectService->getProject($this->projectid);
     $records = $this->projectService->getTimesheetReport(null, $theProject, null, -1, $this->startdate, $this->enddate);
     $userTimeMapping = array();
     foreach ($records as $record) {
         $current = ifset($userTimeMapping, $record->user, 0);
         // go through all times
         foreach ($record->days as $daytime) {
             $current += $daytime;
         }
         $userTimeMapping[$record->user] = $current;
     }
     return $userTimeMapping;
 }
 public function execute($oder_id = null)
 {
     // Restore previous state
     $log_model = new shopOrderLogModel();
     $params = array();
     $this->state_id = $log_model->getPreviousState($oder_id, $params);
     // Restore order.paid_*, customer.total_spent and customer.affiliation_bonus
     $paid_date = ifset($params['paid_date']);
     if ($paid_date) {
         $t = strtotime($paid_date);
         $result['update'] = array('paid_year' => date('Y', $t), 'paid_quarter' => floor((date('n', $t) - 1) / 3) + 1, 'paid_month' => date('n', $t), 'paid_date' => date('Y-m-d', $t));
         return $result;
     }
     return true;
 }
 /**
  *
  * Displays printable form content (HTML) by id
  * @param string $id
  * @param waOrder $order
  */
 public function displayPrintForm($id, waOrder $order, $params = array())
 {
     if ($id == $this->id) {
         $view = wa()->getView();
         $view->assign('settings', $this->getSettings(), true);
         $company = $this->cust_company ? $this->cust_company : 'company';
         $inn = $this->cust_inn ? $this->cust_inn : 'inn';
         $params = $order['params'];
         $company = array('company' => ifset($params['payment_params_' . $company], $order->contact_id ? $order->getContactField($company) : ''), 'inn' => ifset($params['payment_params_' . $inn], $order->contact_id ? $order->getContactField($inn) : ''));
         $view->assign('order', $order);
         $view->assign('company', $company);
         return $view->fetch($this->path . '/templates/form.html');
     } else {
         throw new waException('print form not found');
     }
 }
 public function defaultAction()
 {
     $city = $this->getSettings('city');
     $use_setting_city = true;
     if (!$city) {
         $use_setting_city = false;
         $addresses = wa()->getUser()->get('address');
         foreach ($addresses as $address) {
             $city = ifset($address['data']['city'], '');
             if ($city) {
                 break;
             }
         }
     }
     $this->display(array('info' => $this->getInfo(), 'city' => $city, 'use_setting_city' => $use_setting_city));
 }
예제 #29
0
 public function indexAction()
 {
     // get all the contacts for the currently logged in user's company.
     $contact = $this->clientService->getContact(za()->getUser()->contactid);
     if (!$contact) {
         return;
     }
     $client = $this->clientService->getClient($contact->clientid);
     $totalCount = $this->clientService->getContactCount(array('clientid=' => $client->id));
     $this->view->pagerName = 'pager';
     $currentPage = ifset($this->_getAllParams(), $this->view->pagerName, 1);
     $this->view->totalCount = $totalCount;
     $this->view->listSize = za()->getConfig('project_list_size');
     $this->view->contacts = $this->clientService->getContacts($client, array(), 'firstname asc', $currentPage, $this->view->listSize);
     $this->renderView('contact/index.php');
 }
예제 #30
0
    protected function getByLatLng($lat, $lng, $options = array())
    {
        $id = uniqid();
        $zoom = ifset($options['zoom'], 10);
        $center = json_encode(array($lat, $lng));
        $script = <<<HTML
ymaps.ready(function () {
    var map = new ymaps.Map('yandex-map-{$id}', {
        center: {$center},
        zoom: {$zoom},
        controls: ['smallMapDefaultSet']
    });
});
HTML;
        return $this->getBaseHTML($id, $script, $options);
    }