public function getMessage($posts, $time, $backend_url)
 {
     $message = sprintf(_w("You have blog posts scheduled for publication on the %s blog:"), wa()->accountName()) . "<br>";
     if ($posts) {
         $message .= "<ul>";
         foreach ($posts as $post) {
             $days_left = (int) ((strtotime($post['datetime']) - $time) / 86400);
             $link = "<li><a href='" . $backend_url . "/blog/?module=post&id={$post['id']}&action=edit'" . ($days_left < 0 ? ' style="color: red; font-weight: bold;"' : '') . ">" . $post['title'] . "</a> &mdash; " . wa_date('humandate', $post['datetime']) . " (" . ($days_left == 0 ? '<b>' . _w('today') . '</b>' : _w('in %d day', 'in %d days', $days_left)) . ")" . "</li>";
             $message .= $days_left < 0 ? "<span style='color: red;'>" . $link . "</span>" : $link;
         }
         $message .= "</ul>";
     }
     return $message;
 }
 /**
  * @param waContact $user
  * @return string
  */
 public static function getAccessDisableMsg($user)
 {
     $access_disable = '';
     if ($user['is_user'] == '-1') {
         $log_model = new waLogModel();
         $log_item = $log_model->select('*')->where("subject_contact_id = i:id AND action = 'access_disable'", array('id' => $user['id']))->order('datetime DESC')->limit(1)->fetch();
         if ($log_item) {
             $contact = new waContact($log_item['contact_id']);
             $name = htmlspecialchars(waContactNameField::formatName($contact));
             $access_disable = _w("Access disabled by") . " <a href='#/contact/{$log_item['contact_id']}/'>{$name}</a>, " . wa_date("humandatetime", $log_item['datetime']);
         }
     }
     return $access_disable;
 }
Пример #3
0
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */
function smarty_modifier_wa_datetime($string, $format = 'datetime', $timezone = null, $locale = null)
{
    if ($locale === null) {
        /**
         * @var waSmarty3View
         */
        $smarty = waConfig::get('current_smarty');
        $locale = $smarty->getVars('locale');
    }
    if ($locale === null) {
        $locale = waSystem::getInstance()->getUser()->getLocale();
    }
    if (!$string) {
        return '';
    }
    return wa_date($format, $string, $timezone, $locale);
}
Пример #4
0
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */
function smarty_modifier_wa_date_add($string, $format, $timezone = null, $locale = null)
{
    if ($locale === null) {
        /**
         * @var waSmarty3View
         */
        $smarty = waConfig::get('current_smarty');
        $locale = $smarty->getVars('locale');
    }
    if ($locale === null) {
        $locale = waSystem::getInstance()->getUser()->getLocale();
    }
    $string = wa_date('date', $string, $timezone, $locale);
    if (preg_match('/(\\d+)([d])/i', $format, $match)) {
        $string = wa_date('date', date('Y-m-d', strtotime($string) + $match[1] * 60 * 60 * 24), $timezone, $locale);
    }
    return $string;
}
Пример #5
0
 /**
  * Adds various extra data to specified orders.
  *
  * @param array $orders Orders array
  * @param bool $single Whether only one order is specified; only in this case modified order data array is returned
  * @return null|array
  */
 public static function workupOrders(&$orders, $single = false)
 {
     if ($single) {
         $orders = array($orders);
     }
     $workflow = new shopWorkflow();
     $states = $workflow->getAllStates();
     foreach ($orders as &$order) {
         $order['id_str'] = self::encodeOrderId($order['id']);
         $order['total_str'] = wa_currency($order['total'], $order['currency']);
         if (!empty($order['create_datetime'])) {
             $order['create_datetime_str'] = wa_date('humandatetime', $order['create_datetime']);
         }
         $state = isset($states[$order['state_id']]) ? $states[$order['state_id']] : null;
         $icon = '';
         $style = '';
         if ($state) {
             /**
              * @var shopWorkflowState $state
              */
             $icon = $state->getOption('icon');
             $style = $state->getStyle();
         }
         $order['icon'] = $icon;
         $order['style'] = $style;
         if (isset($order['params'])) {
             // shipping_address_formatted
             $shipping_address = self::getOrderAddress($order['params'], 'shipping');
             $formatter = new waContactAddressOneLineFormatter();
             $order['shipping_address_formatted'] = $formatter->format(array('data' => $shipping_address));
             $order['shipping_address_formatted'] = $order['shipping_address_formatted']['value'];
             // Shipping and payment option names
             if (isset($order['params']['shipping_name'])) {
                 $order['shipping_name'] = htmlspecialchars($order['params']['shipping_name']);
             } else {
                 $order['shipping_name'] = '<span class="hint">' . _w('not specified') . '</span>';
             }
             if (isset($order['params']['payment_name'])) {
                 $order['payment_name'] = htmlspecialchars($order['params']['payment_name']);
             } else {
                 $order['payment_name'] = '<span class="hint">' . _w('not specified') . '</span>';
             }
         }
     }
     if ($single) {
         $orders = $orders[0];
         return $orders;
     }
 }
Пример #6
0
 public function formateDatetime($datetime)
 {
     return wa_date('date', $datetime) . ' ' . wa_date('H', $datetime) . ':' . wa_date('i', $datetime);
 }
 protected function workupProducts(&$products)
 {
     $currency = $this->getConfig()->getCurrency();
     foreach ($products as &$p) {
         if ($p['min_price'] == $p['max_price']) {
             $p['price_range'] = wa_currency($p['min_price'], $currency);
         } else {
             $p['price_range'] = wa_currency($p['min_price'], $currency) . '...' . wa_currency($p['max_price'], $currency);
         }
         if ($p['badge']) {
             $p['badge'] = shopHelper::getBadgeHtml($p['badge']);
         }
         unset($p['meta_description'], $p['meta_keywords'], $p['meta_title'], $p['description'], $p['summary']);
     }
     unset($p);
     if ($this->sort == 'count') {
         foreach ($products as &$p) {
             $p['icon'] = shopHelper::getStockCountIcon($p['count']);
         }
     } else {
         if ($this->sort == 'create_datetime') {
             foreach ($products as &$p) {
                 $p['create_datetime_str'] = wa_date('humandatetime', $p['create_datetime']);
             }
         } else {
             if ($this->sort == 'rating') {
                 foreach ($products as &$p) {
                     $p['rating_str'] = shopHelper::getRatingHtml($p['rating'], 10, true);
                 }
             } else {
                 if ($this->sort == 'total_sales') {
                     $currency = wa('shop')->getConfig()->getCurrency();
                     foreach ($products as &$p) {
                         $p['total_sales_str'] = wa_currency($p['total_sales'], $currency);
                     }
                 }
             }
         }
     }
     unset($p);
     $info = $this->collection->getInfo();
     if ($info['hash'] == 'category') {
         $product_ids = array_keys($products);
         $category_products_model = new shopCategoryProductsModel();
         $ids = $category_products_model->filterByEnteringInCategories($product_ids, $info['id']);
         $ids = array_flip($ids);
         foreach ($products as $id => &$product) {
             $product['alien'] = $info['type'] == shopCategoryModel::TYPE_STATIC && !isset($ids[$id]);
         }
         unset($product);
     }
 }
 public function execute()
 {
     $update = waRequest::post('update');
     // just update one or any field of product
     if ($update) {
         $this->update($update);
         return;
     }
     $data = waRequest::post('product');
     $id = empty($data['id']) || !intval($data['id']) ? null : $data['id'];
     if (!$id && isset($data['id'])) {
         unset($data['id']);
     }
     # edit product info - check rights
     $product_model = new shopProductModel();
     if ($id) {
         if (!$product_model->checkRights($id)) {
             throw new waRightsException(_w("Access denied"));
         }
     } else {
         if (!$product_model->checkRights($data)) {
             throw new waRightsException(_w("Access denied"));
         }
     }
     $skus = waRequest::post('skus', array());
     if (isset($data['skus'])) {
         foreach ($skus as $s_id => $s) {
             if (isset($data['skus'][$s_id])) {
                 $data['skus'][$s_id] += $s;
             } else {
                 $data['skus'][$s_id] = $s;
             }
         }
     } else {
         $data['skus'] = $skus;
     }
     if (empty($data['categories'])) {
         $data['categories'] = array();
     }
     if (empty($data['tags'])) {
         $data['tags'] = array();
     }
     if (empty($data['features_selectable'])) {
         $data['features_selectable'] = array();
     }
     # verify sku_type before save
     if ($data['type_id']) {
         $features_model = new shopFeatureModel();
         if ($features_model->isTypeMultipleSelectable($data['type_id'])) {
             if ($data['sku_type'] == shopProductModel::SKU_TYPE_SELECTABLE) {
                 if (empty($data['features_selectable'])) {
                     throw new waException(_w("Check at least one feature value"));
                 }
             }
         } else {
             $data['sku_type'] = shopProductModel::SKU_TYPE_FLAT;
         }
     } else {
         $data['sku_type'] = shopProductModel::SKU_TYPE_FLAT;
     }
     if ($data['sku_type'] == shopProductModel::SKU_TYPE_FLAT) {
         $data['features_selectable'] = array();
     }
     try {
         $product = new shopProduct($id);
         // for logging changes in stocks
         shopProductStocksLogModel::setContext(shopProductStocksLogModel::TYPE_PRODUCT);
         if ($product->save($data, true, $this->errors)) {
             $features_counts = null;
             if ($product->sku_type == shopProductModel::SKU_TYPE_SELECTABLE) {
                 $features_counts = array();
                 foreach ($product->features_selectable as $f) {
                     if (isset($f['selected'])) {
                         $features_counts[] = $f['selected'];
                     } else {
                         $features_counts[] = count($f['values']);
                     }
                 }
                 $features_total_count = array_product($features_counts);
                 $this->response['features_selectable_strings'] = array('options' => implode(' x ', $features_counts) . ' ' . _w('option', 'options', $features_total_count), 'skus' => _w('%d SKU in total', '%d SKUs in total', $features_total_count));
             }
             shopProductStocksLogModel::clearContext();
             if ($id) {
                 $this->logAction('product_edit', $id);
             } else {
                 $this->logAction('product_add', $product->getId());
             }
             $this->response['id'] = $product->getId();
             $this->response['name'] = $product->name;
             $this->response['url'] = $product->url;
             $this->response['frontend_urls'] = $this->getUrl($product);
             $this->response['raw'] = $this->workupData($product->getData());
             $sales_rate = waRequest::post('sales_rate', 0, waRequest::TYPE_STRING_TRIM);
             $sales_rate = (double) str_replace(',', '.', $sales_rate);
             $runout = $product->getRunout($sales_rate);
             if (!empty($runout['product'])) {
                 $runout['product']['date_str'] = wa_date("humandate", $runout['product']['date']);
                 $runout['product']['days_str'] = _w('%d day', '%d days', $runout['product']['days']);
                 if ($runout['product']['days'] < 3 * 365 && $runout['product']['days'] > 0) {
                     $runout['product_str'] = sprintf(_w('Based on last 30 days sales dynamic (%d items of %s sold during last 30 days), you will run out of %s in <strong>%d days</strong> (on %s)'), $sales_rate * 30, $product->name, $product->name, $runout['product']['days'], wa_date("humandate", $runout['product']['date']));
                 }
             } else {
                 $runout['product'] = new stdClass();
                 /* {} */
             }
             if (!empty($runout['sku'])) {
                 foreach ($runout['sku'] as &$sk_r) {
                     if (empty($sk_r['stock'])) {
                         $sk_r['date_str'] = wa_date("humandate", $sk_r['date']);
                         $sk_r['days_str'] = _w('%d day', '%d days', $sk_r['days']);
                     } else {
                         foreach ($sk_r['stock'] as &$st_r) {
                             $st_r['date_str'] = wa_date("humandate", $st_r['date']);
                             $st_r['days_str'] = _w('%d day', '%d days', $st_r['days']);
                         }
                     }
                 }
                 unset($sk_r, $st_r);
             } else {
                 $runout['sku'] = new stdClass();
                 /* {} */
             }
             $this->response['raw']['runout'] = $runout;
             $this->response['storefront_map'] = $product_model->getStorefrontMap($product->id);
         }
     } catch (Exception $ex) {
         $this->setError($ex->getMessage());
     }
 }