public function getLocale()
 {
     $locale = $this->factory->getStoredOptions('locale');
     if (!$locale) {
         return I2CE_Locales::getPreferredLocale();
     } else {
         return $locale;
     }
 }
 public function __construct()
 {
     parent::__construct();
     $this->date_pickers = array();
     if (class_exists('IntlDateFormatter')) {
         $locale = I2CE_Locales::getPreferredLocale();
         $config = I2CE::getConfig()->modules->DatePicker;
         $intl_setup = false;
         $config->setIfIsSet($intl_setup, "intl_setup/{$locale}");
         if (!$intl_setup) {
             $formatter = array('months' => new IntlDateFormatter($locale, null, null, 'UTC', null, 'MMMM'), 'days' => new IntlDateFormatter($locale, null, null, 'UTC', null, 'EEEE'));
             foreach (self::$intl_times as $type => $times) {
                 foreach ($times as $idx => $time) {
                     if (!$config->is_translated($locale, "options/{$type}/{$idx}")) {
                         $config->setTranslatable("options/{$type}/{$idx}");
                         $config->setTranslation($locale, $formatter[$type]->format($time), "options/{$type}/{$idx}");
                     }
                 }
             }
         }
         $config->intl_setup->{$locale} = 1;
     }
 }
Esempio n. 3
0
 /**
  * Displays the date in a readable format.
  */
 public function displayDate()
 {
     if (!$this->isValid()) {
         return "";
     }
     $dateTimeObj = $this->getDateTimeObj();
     if ($dateTimeObj === false) {
         return "";
     }
     $formatter = self::getIntlFormatter(I2CE_Locales::getPreferredLocale(), $this->type);
     if ($formatter !== null) {
         return $formatter->format($dateTimeObj->getTimestamp());
     } else {
         $format = self::$date_formats[$this->type];
         I2CE::getConfig()->setIfIsSet($format, "/I2CE/date/format/" . $this->type);
         return $dateTimeObj->format($format);
     }
     /*
     switch( $this->type ) {
     case self::YEAR_ONLY :
         return $this->year;
         break;
     case self::MONTH_DAY :
         if ( (int)$this->month == 0 ) {
             return "";
         } else {
             return sprintf( "%d %s", $this->day, self::$months[ (int)$this->month ] );
         }
         break;
     case self::DATE_TIME :
         if ( (int)$this->month == 0 ) {
             return "";
         } else { 
             return sprintf( "%d %s %d %d:%02d:%02d", $this->day, self::$months[ (int)$this->month ], $this->year, $this->hour, $this->minute, $this->second );
         }
         break;
     case self::TIME_ONLY :
     
         return sprintf( "%d:%02d:%02d", $this->hour, $this->minute, $this->second );                
         break;
     case self::DATE :
         if ( (int)$this->month == 0 ) {
             return "";
         } else { 
             return sprintf( "%d %s %d", $this->day, self::$months[ (int)$this->month ], $this->year );
         }
         break;
     default :
         I2CE::raiseError( "An invalid date type was used for I2CE_Date::displayDate.", E_USER_WARNING );
         return "";
     }
     */
 }
 protected function localeMenu($node, $template, $locales, $update_link_base, $selected = null)
 {
     $iconConfig = I2CE::getConfig()->traverse("/locales/icons", true, false);
     if (!$iconConfig instanceof I2CE_MagicDataNode) {
         return false;
     }
     if ($selected === null) {
         $selected = I2CE_Locales::getPreferredLocale();
     }
     if (($pos = strpos($selected, '_')) !== false) {
         $selected_lang = substr($selected, 0, $pos);
     } else {
         $selected_lang = $selected;
     }
     foreach ($locales as $locale) {
         $name = $this->getLocaleName($locale);
         if (($pos = strpos($locale, '_')) !== false) {
             $lang = substr($locale, 0, $pos);
             $region = strtolower(substr($locale, $pos + 1));
         } else {
             $lang = $locale;
             $region = $locale;
         }
         $icon = false;
         foreach (array($locale, $region) as $key) {
             if ($iconConfig->setIfIsSet($icon, $key)) {
                 break;
             }
         }
         if (is_string($icon) && strlen(trim($icon)) > 0) {
             $icon = array('src' => 'file/' . trim($icon), 'alt_text' => $name);
         } else {
             $icon = false;
         }
         if ($icon) {
             $choice_file = 'language_choice_icon.html';
         } else {
             $choice_file = 'language_choice.html';
         }
         $choiceNode = $template->appendFileByNode($choice_file, '//body/*', $node);
         if (!$choiceNode instanceof DOMNode) {
             continue;
         }
         if ($selected == $locale) {
             $name = '[' . $name . ']';
         }
         $template->setDisplayDataImmediate('language_choice_text', $name, $choiceNode);
         $template->setDisplayDataImmediate('language_choice_link', $update_link_base . $locale, $choiceNode);
         if ($icon) {
             $template->setDisplayDataImmediate('language_choice_icon', $icon, $choiceNode);
         }
     }
 }
Esempio n. 5
0
 /**
  * Gets the prefered locales for the user
  * @returns $string
  */
 public function getPreferredLocale()
 {
     if (is_string($this->locale) && strlen($this->locale) > 0) {
         return $this->locale;
     }
     if (array_key_exists('locale', $this->details) && strlen(trim($this->details['locale'])) > 0) {
         $this->locale = $this->details['locale'];
     }
     if (!$this->username || !I2CE::getConfig()->setIfIsSet($this->locale, "/user_prefs/users/{$this->username}/preferred_locale")) {
         $this->locale = I2CE_Locales::getPreferredLocale();
     }
     $this->locale = I2CE_Locales::ensureSelectableLocale($this->locale);
     return $this->locale;
 }
 protected function actionTasksSave()
 {
     if (count($this->request_remainder) == 0) {
         //adding new task
         if (!$this->post_exists('task_short_name')) {
             $this->userMessage("No task short name set", 'notice', false);
             return;
         }
         $task = $this->post('task_short_name');
         if (!$task || !I2CE_MagicDataNode::checkKey($task) || I2CE::getConfig()->__isset("/I2CE/tasks/task_description/{$task}") || I2CE::getConfig()->__isset("/I2CE/tasks/task_trickle_down/{$task}")) {
             $this->userMessage("Bad task short name", 'notice', false);
             return;
         }
         if (!$this->post_exists('task_description') || !$this->post('task_description')) {
             $this->userMessage("No task description set", 'notice', false);
             return;
         }
         //we are good to go.
         I2CE::getConfig()->I2CE->tasks->task_description->{$task} = $this->post('task_description');
     } else {
         if (count($this->request_remainder) == 1) {
             $task = $this->request_remainder[0];
             $taskConfig = I2CE::getConfig()->traverse("/I2CE/tasks");
             if (!$taskConfig->__isset("task_description/{$task}")) {
                 $this->userMessage("Invalid Task {$task} specified", 'notice', false);
                 return;
             }
             $post = $this->post();
             if (!array_key_exists('task_description', $post) || !$post['task_description']) {
                 $this->userMessage("No task description set", 'notice', false);
                 return;
             }
             if ($taskConfig->is_translatable("task_description/{$task}")) {
                 $locale = I2CE_Locales::getPreferredLocale();
                 $taskConfig->task_description->setTranslation($locale, $post['task_description'], $task);
                 if ($locale == I2CE_Locales::DEFAULT_LOCALE) {
                     $taskConfig->task_description->{$task} = $post['task_description'];
                 }
             } else {
                 $taskConfig->task_description->{$task} = $post['task_description'];
             }
             if (array_key_exists('task_tasks', $post) && is_array($post['task_tasks'])) {
                 //make sure the tasks are valid.
                 $tasks = $post['task_tasks'];
                 foreach ($tasks as $i => $r) {
                     if (!$taskConfig->__isset("task_description/{$r}")) {
                         unset($tasks[$i]);
                     }
                 }
                 $taskConfig->task_trickle_down->{$task}->erase();
                 $taskConfig->traverse("task_trickle_down/{$task}", true, false);
                 //recreate what we just erased
                 $taskConfig->task_trickle_down->{$task} = $tasks;
             }
         }
     }
     $this->setRedirect('tasks-roles/tasks');
 }
Esempio n. 7
0
 /**
  * Perform the main actions of the page.
  * @global array Get the home page from the global configuration
  */
 protected function action()
 {
     if ($this->request_exists('message') && $this->request('message')) {
         $this->template->userMessage($this->request('message'), 'default', false);
     }
     $i2ce_config = I2CE::getConfig()->I2CE;
     parent::action();
     $this->template->setBodyId("loginPage");
     if ($this->isPost()) {
         if ($this->post('submit') == "Login as Guest") {
             $this->post['username'] = $i2ce_config->guest->account;
             $this->post['password'] = $i2ce_config->guest->password;
         }
         $message = $this->user->login($this->post('username'), $this->post('password'));
         if (is_string($message)) {
             $this->template->setDisplayDataImmediate('error_message', $message);
         } else {
             if ($message === true) {
                 //the user was logged in
                 if (I2CE_Locales::getPreferredLocale() != I2CE_Locales::getBrowserPreferredLocale()) {
                     $this->user->setPreferredLocale(I2CE_Locales::getPreferredLocale());
                 }
             }
         }
     }
     if ($this->user->logged_in()) {
         if (array_key_exists('referal', $_SESSION) && $_SESSION['referal']) {
             $site_url = $this->getAccessedBaseURL();
             $referal = $_SESSION['referal'];
             unset($_SESSION['referal']);
             if ($site_url . $this->page == $referal) {
                 //there is an off chance that we are redirect from the login page.  this can happen if we initialize the site by accessing the login page
                 $referal = $this->getHome();
             }
             if (preg_match('/login/', $referal) || preg_match('/logout/', $referal)) {
                 $referal = $this->getHome();
             }
         } else {
             $referal = $this->getHome();
         }
         if ($this->user->username != 'i2ce_admin' && I2CE_User::userHasDefaultPassword($this->user->username)) {
             $this->userMessage("Please you must change your default password before you continue using the system!", "notice");
             $this->setRedirect('password');
         } else {
             $this->setRedirect($referal);
         }
         return true;
     }
     if ($default_password = I2CE_User::userHasPassword('administrator', 'administrator')) {
         $username = $this->template->query('//input[@name="username"]');
         if ($username->length == 1) {
             $username->item(0)->setAttribute('value', 'administrator');
         }
         $password = $this->template->query('//input[@name="password"]');
         if ($password->length == 1) {
             $password->item(0)->setAttribute('value', 'administrator');
         }
     } else {
         if (($autologinuser = I2CE_User::getAutoLoginUser()) !== false) {
             $username = $this->template->query('//input[@name="username"]');
             if ($username->length == 1) {
                 $username->item(0)->setAttribute('value', $autologinuser);
             }
         }
     }
     $this->template->addHeaderLink("welcomeText.css");
     if ($this->user->logged_in() && $this->user->username == 'administrator' && $default_password) {
         $this->userMessage("Your password is currently set to the default password, administrator.  Please change this by clicking on the \"Change Password\" link  below.", "notice");
         $this->userMessage("If you have not already done so, please create a new user with a non-administrative role for everyday use.", "notice");
     }
 }
Esempio n. 8
0
 public function __construct()
 {
     $this->command_line = !array_key_exists('HTTP_HOST', $_SERVER);
     I2CE_Locales::setPreferredLocale(I2CE_Locales::getPreferredLocale());
 }