public function execute()
 {
     $contact_model = new waContactModel();
     if ($contact_model->countAll()) {
         $this->redirect($this->getConfig()->getBackendUrl(true));
     }
     if (($locale = waRequest::get('lang')) && waLocale::getInfo($locale)) {
         // set locale
         wa()->setLocale($locale);
         // save to database default locale
         $app_settings_model = new waAppSettingsModel();
         $app_settings_model->set('webasyst', 'locale', $locale);
     }
     if (file_exists($this->getConfig()->getRootPath() . '/install.php')) {
         @unlink($this->getConfig()->getRootPath() . '/install.php');
     }
     if (waRequest::getMethod() == 'post') {
         $errors = array();
         $login = waRequest::post('login');
         $validator = new waLoginValidator();
         if (!$validator->isValid($login)) {
             $errors['login'] = implode("<br />", $validator->getErrors());
         }
         $password = waRequest::post('password');
         $password_confirm = waRequest::post('password_confirm');
         if ($password !== $password_confirm) {
             $errors['password'] = _w('Passwords do not match');
         }
         $email = waRequest::post('email');
         $validator = new waEmailValidator();
         if (!$validator->isValid($email)) {
             $errors['email'] = implode("<br />", $validator->getErrors());
         }
         if ($errors) {
             $this->view->assign('errors', $errors);
         } else {
             // save account name
             $app_settings_model = new waAppSettingsModel();
             $app_settings_model->set('webasyst', 'name', waRequest::post('account_name'));
             if ($email) {
                 $app_settings_model->set('webasyst', 'email', $email);
                 $app_settings_model->set('webasyst', 'sender', $email);
             }
             // create user
             $user = new waUser();
             $firstname = waRequest::post('firstname');
             $user['firstname'] = $firstname ? $firstname : $login;
             $user['lastname'] = waRequest::post('lastname');
             $user['is_user'] = 1;
             $user['login'] = $login;
             $user['password'] = $password;
             $user['email'] = $email;
             $user['locale'] = wa()->getLocale();
             $user['create_method'] = 'install';
             if ($errors = $user->save()) {
                 $result = array();
                 foreach ($errors as $k => $v) {
                     $result['all'][] = $k . ": " . (is_array($v) ? implode(', ', $v) : $v);
                 }
                 $result['all'] = implode("\r\n", $result['all']);
                 $this->view->assign('errors', $result);
             } else {
                 $user->setRight('webasyst', 'backend', 1);
                 waSystem::getInstance()->getAuth()->auth(array('login' => $login, 'password' => $password));
                 $path = $this->getConfig()->getPath('config');
                 // check routing.php
                 if (!file_exists($path . '/routing.php')) {
                     $apps = wa()->getApps();
                     $data = array();
                     $domain = $this->getConfig()->getDomain();
                     $site = false;
                     foreach ($apps as $app_id => $app) {
                         if ($app_id == 'site') {
                             $site = true;
                         } elseif (!empty($app['frontend'])) {
                             $routing = array('url' => $app_id . '/*', 'app' => $app_id);
                             if (!empty($app['routing_params']) && is_array($app['routing_params'])) {
                                 $routing = array_merge($routing, $app['routing_params']);
                             }
                             $data[$domain][] = $routing;
                         }
                     }
                     if ($site) {
                         $data[$domain][] = array('url' => '*', 'app' => 'site');
                     }
                     waUtils::varExportToFile($data, $path . '/routing.php');
                 }
                 // redirect to backend
                 $this->redirect($this->getConfig()->getBackendUrl(true));
             }
         }
     }
 }
 public function format($data)
 {
     $info = waLocale::getInfo($data);
     return ifset($info['name'], $data);
 }
Esempio n. 3
0
 /**
  * Returns format strings for PHP function date corresponding to formats used by Webasyst framework.
  *
  * @param string $format Time format strings used in Webasyst framework including the following options:
  *     - 'date_formats' sub-array keys specified in locale configuration file located in wa-system/locale/data/,
  *     - PHP class DateTime constants,
  *     - format strings acceptable for PHP function date, or one of the identifiers corresponding to pre-defined
  *       time formatting strings supported by method format().
  * @see self::format()
  * @param string|null $locale Locale identifier. If not specifed, current user locale is determined automatically.
  * @return string
  */
 public static function getFormat($format, $locale = null)
 {
     if (!$locale) {
         $locale = waSystem::getInstance()->getLocale();
     }
     $locale = waLocale::getInfo($locale);
     $date_formats = isset($locale['date_formats']) ? $locale['date_formats'] : array();
     $default = array('humandate' => 'd f Y', 'date' => 'Y-m-d', 'time' => 'H:i', 'fulltime' => 'H:i:s', 'datetime' => 'Y-m-d H:i', 'fulldatetime' => 'Y-m-d H:i:s', 'timestamp' => 'U');
     if (isset($date_formats[$format])) {
         return $date_formats[$format];
     } elseif (isset($default[$format])) {
         return $default[$format];
     } elseif (defined($format) && strpos($format, 'DATE_') === 0) {
         return constant($format);
     } elseif (stripos("ymdhisfjnucrzt", $format) !== false) {
         return $format;
     } else {
         trigger_error("waDateTime format '{$format}' undefined", E_USER_NOTICE);
         return "Y-m-d H:i:s";
     }
 }
 protected function getCurrencyInfo()
 {
     $currency = waCurrency::getInfo($this->getConfig()->getCurrency(false));
     $locale = waLocale::getInfo(wa()->getLocale());
     return array('code' => $currency['code'], 'sign' => $currency['sign'], 'sign_html' => !empty($currency['sign_html']) ? $currency['sign_html'] : $currency['sign'], 'sign_position' => isset($currency['sign_position']) ? $currency['sign_position'] : 1, 'sign_delim' => isset($currency['sign_delim']) ? $currency['sign_delim'] : ' ', 'decimal_point' => $locale['decimal_point'], 'frac_digits' => $locale['frac_digits'], 'thousands_sep' => $locale['thousands_sep']);
 }
 /**
  * Format amount according to currency settings and current locale settings.
  *
  * TODO: document format string specifications. For now, see unit tests for some usage clues.
  *
  * @param string $format
  * @param float $n amount to format
  * @param string $currency 3-letter iso code
  * @param string $locale
  */
 public static function format($format, $n, $currency, $locale = null)
 {
     $old_locale = waSystem::getInstance()->getLocale();
     if ($locale === null) {
         $locale = $old_locale;
     }
     $currency = waCurrency::getInfo($currency);
     if ($format == '%w' || $format == '%W') {
         if ($locale !== $old_locale) {
             wa()->setLocale($locale);
         }
         waLocale::loadByDomain('webasyst', $locale);
     }
     $locale = waLocale::getInfo($locale);
     $result = preg_replace('/%([0-9]?\\.?[0-9]?)([iw]*)({[n|f|c|s][0-9]?})?/ie', 'self::extract($n, $currency, $locale, "$1", "$2", "$3")', $format);
     if ($locale !== $old_locale) {
         wa()->setLocale($old_locale);
     }
     return $result;
 }
 /**
  * Returns formatted amount value with currency.
  *
  * @see wa_currency()
  * @see wa_currency_html()
  *
  * @param string $format Amount format. The format string must begin with % character and may contain the following
  *     optional parts in the specified order:
  *     - Precision (number of digits after decimal separator) expressed as an arbitrary integer value. If not
  *       specified, then 2 decinal digits are displayed by default.
  *     - Display type (as a number; e.g., "123456", or in words; e.g., 'one hundred and twenty-three thousand four
  *       hundred and fifty-six"). To use the numerical format, specify i; for verbal format, use w. The verbal
  *       expression of a number contains its integer part only, the decimal part is ignored. If the display type is
  *       not specified, then the numerical format is used by default.
  *     - Currency sign or name. To add it to the formatted amount value, specify one of the following identifiers in
  *       curly brackets:
  *         {n}: full cyrrency name; e.g., "dollar"
  *         {s}: brief currency name or sign; e.g., "$"
  *         {f}: name of the fractional currency unit; e.g., "cent/cents"
  *         {c}: currency code; e.g., "USD".
  * @param float $n Original number to be formatted
  * @param string $currency Currency's ISO3 code
  * @param string $locale Locale id
  * @return string E.g., 'en_US'
  */
 public static function format($format, $n, $currency, $locale = null)
 {
     $old_locale = waSystem::getInstance()->getLocale();
     if ($locale === null) {
         $locale = $old_locale;
     }
     if ($locale !== $old_locale) {
         wa()->setLocale($locale);
     }
     $currency = self::getInfo($currency);
     waLocale::loadByDomain('webasyst', $locale);
     $locale = waLocale::getInfo($locale);
     self::$format_data['n'] = $n;
     self::$format_data['locale'] = $locale;
     self::$format_data['currency'] = $currency;
     $pattern = '/%([0-9]?\\.?[0-9]?)([iw]*)({[n|f|c|s|h][0-9]?})?/i';
     $result = preg_replace_callback($pattern, array('self', 'replace_callback'), $format);
     if ($locale !== $old_locale) {
         wa()->setLocale($old_locale);
     }
     return $result;
 }
 private function overview()
 {
     $this->setLayout(new shopWelcomeLayout());
     #countries
     $cm = new waCountryModel();
     $cm->preload();
     $countries = array();
     if (!empty($this->countries)) {
         foreach ($this->countries as $iso3) {
             $countries[$iso3] = $cm->get($iso3);
         }
     }
     $locale = waLocale::getInfo(wa()->getUser()->getLocale());
     if (!isset($locale['iso3']) || !isset($countries[$locale['iso3']])) {
         if (isset($countries['usa'])) {
             $country_iso3 = 'usa';
         } else {
             reset($countries);
             $country_iso3 = key($countries);
         }
     } else {
         $country_iso3 = $locale['iso3'];
     }
     $this->view->assign('countries', $countries);
     $this->view->assign('country_iso', $country_iso3);
     $this->view->assign('translate', $this->translate);
     #product types
     $types = array();
     if (!empty($this->types)) {
         foreach ($this->types as $id => $type) {
             if ($id != 'default') {
                 $name = ifempty($type['name'], $id);
                 $types[$id] = array('name' => ifempty($this->translate[$name], $name), 'icon' => ifempty($type['icon'], ''), 'description' => '');
             }
         }
     }
     $this->view->assign('types', $types);
 }