Esempio n. 1
0
 /**
  * Sets the prefered locales for the user
  * @param string $locale
  * @param boolean $save.   Defaults to true.
  * @returns string $locales.  false on failure  string or array of strings, the locales on success
  */
 public function setPreferredLocale($locale, $save = true)
 {
     $locale = I2CE_Locales::ensureSelectableLocale($locale);
     I2CE_Locales::setPreferredLocale($locale);
     if (!$this->username == 'i2ce_admin') {
         if ($this->id <= 0 || !$this->username) {
             //I2CE::raiseError("Could not save locales for user no id or username ({$this->id}/{$this->username})");
             return $locale;
         }
         if (self::hasDetail('locale')) {
             $this->details['locale'] = $locale;
             if ($save && !$this->save()) {
                 I2CE::raiseError("Cannot save preferred locale");
             }
         }
     }
     $userPrefs = I2CE::getConfig()->traverse("/user_prefs/users/{$this->username}", true);
     if (!$userPrefs instanceof I2CE_MagicDataNode) {
         I2CE::raiseError("Error in accessing user prefs for {$this->username}");
         return $locales;
     }
     $userPrefs->preferred_locale = $locale;
     return $locale;
 }
Esempio n. 2
0
 public function generateListData($lang = 'en-US')
 {
     I2CE_Locales::setPreferredLocale(strtr($lang, '-', '_'));
     $display_style = 'default';
     I2CE::getConfig()->setIfIsSet($display_style, "/modules/SVS/lists/" . $this->oid . "/meta/display_style");
     $code_style = 'code';
     I2CE::getConfig()->setIfIsSet($code_style, "/modules/SVS/lists/" . $this->oid . "/meta/code_style");
     $code_system_style = false;
     I2CE::getConfig()->setIfIsSet($code_system_style, "/modules/SVS/lists/" . $this->oid . "/meta/code_system_style");
     $meta = $this->getMeta();
     $code_system = $meta['Source'];
     I2CE::getConfig()->setIfIsSet($code_system, "/modules/SVS/lists/" . $this->oid . "/meta/code_system");
     $where = I2CE::getConfig()->getAsArray("/modules/SVS/lists/" . $this->oid . "/where");
     if (!is_array($where)) {
         $where = array();
     }
     $inc_hidden = false;
     I2CE::getConfig()->setIfIsSet($inc_hidden, "/modules/SVS/lists/" . $this->oid . "/hidden");
     //include hidden
     if (!$inc_hidden) {
         $nohidden = array('operator' => 'OR', 'operand' => array(array('operator' => 'FIELD_LIMIT', 'field' => 'i2ce_hidden', 'style' => 'no', 'data' => array()), array('operator' => 'FIELD_LIMIT', 'field' => 'i2ce_hidden', 'style' => 'null', 'data' => array())));
         if (count($where) > 0) {
             $where = array('operator' => 'AND', 'operand' => array(0 => $where, 1 => $nohidden));
         } else {
             $where = $nohidden;
         }
     }
     $styles = array('displayName' => $display_style, 'code' => $code_style);
     if ($code_system_style) {
         $styles['codeSystem'] = $code_system_style;
     }
     $all_fields = array();
     $disp_strings = array();
     $disp_fields = array();
     foreach ($styles as $out => $style) {
         if ($style == 'id') {
             continue;
         }
         $disp_strings[$out] = I2CE_List::getDisplayString($this->list, $style);
         $disp_fields[$out] = I2CE_List::getDisplayFields($this->list, $style);
         ksort($disp_fields[$out]);
         $all_fields = array_merge($all_fields, $disp_fields[$out]);
     }
     $all_fields = array_unique($all_fields);
     $field_data = I2CE_FormStorage::listDisplayFields($this->list, $all_fields, false, $where, array());
     $data = array();
     foreach ($field_data as $id => $fields) {
         $data[$id] = array();
         foreach ($styles as $out => $style) {
             if ($style == 'id') {
                 $data[$id][$out] = $id;
             } else {
                 $values = array();
                 foreach ($disp_fields[$out] as $field) {
                     if (array_key_exists($field, $fields)) {
                         $val = $fields[$field];
                     } else {
                         $val = '';
                     }
                     $values[] = $val;
                 }
                 $data[$id][$out] = @vsprintf($disp_strings[$out], $values);
             }
         }
         if (!in_array('codeSystem', $styles)) {
             $data[$id]['codeSystem'] = $code_system;
         }
     }
     return $data;
 }
Esempio n. 3
0
 public function __construct()
 {
     $this->command_line = !array_key_exists('HTTP_HOST', $_SERVER);
     I2CE_Locales::setPreferredLocale(I2CE_Locales::getPreferredLocale());
 }
Esempio n. 4
0
 /**
  * Create a new instance of a page.
  * 
  * The default constructor should be called by any pages extending this object.  It creates the
  * {@link I2CE_Template} and {@link I2CE_User} objects and sets up the basic member variables.
  * @param array $args
  * @param array $request_remainder The remainder of the request path
  */
 public function __construct($args, $request_remainder, $get = null, $post = null)
 {
     if (array_key_exists('root_url', $args) && $args['root_url']) {
         $this->root_url = $args['root_url'];
         unset($args['root_url']);
     }
     $this->setIsPost(array_key_exists('REQUEST_METHOD', $_SERVER) && $_SERVER['REQUEST_METHOD'] == "POST");
     $this->user = new I2CE_User();
     if (function_exists('apache_note')) {
         apache_note("iHRIS-username", $this->user->username == '0' ? '-' : $this->user->username);
     } elseif (array_key_exists('HTTP_HOST', $_SERVER) && !headers_sent()) {
         header('X-iHRIS-username', $this->user->username == '0' ? '-' : $this->user->username);
     }
     I2CE_Locales::setPreferredLocale($this->user->getPreferredLocale());
     $this->args = $args;
     $this->request_remainder = $request_remainder;
     $i2ce_config = I2CE::getConfig()->I2CE;
     if (!array_key_exists('access', $args)) {
         if (array_key_exists('HTTP_HOST', $_SERVER)) {
             $args['access'] = array('any');
             //default is anyone logged in.
         } else {
             $args['access'] = array('all');
         }
     }
     $this->access = $args['access'];
     $this->setupGetPost($get, $post);
     $this->template = null;
     if (!$this->initializeTemplate()) {
         I2CE::raiseError("Could not setup templates");
     }
     $this->redirect = "";
     $this->permissionParser = new I2CE_PermissionParser($this->template);
     I2CE_ModuleFactory::callHooks('page_constructor', array('page' => $this, 'args' => $args, 'request_remainder' => $request_remainder));
 }
 /**
  * The business method if this page is called from the commmand line
  * @param array $request_remainder the remainder of the request after the page specfication.  
  * @param array $args the array of unix style command line arguments 
  */
 protected function actionCommandLine($args, $request_remainder)
 {
     $config = I2CE::getConfig();
     if (!$config->is_parent("/modules/forms/forms")) {
         I2CE::raiseError("No Forms", E_USER_ERROR);
     }
     $config = I2CE::getConfig();
     $module = $config->config->site->module;
     if (!$module) {
         I2CE::raiseError("No site module");
     }
     $formConfig = $config->modules->forms->forms;
     $this->locale = I2CE::getRuntimeVariable('locale', false);
     if (!$this->locale) {
         $this->locale = I2CE_Locales::DEFAULT_LOCALE;
     }
     $this->locale = I2CE_Locales::ensureSelectableLocale($this->locale);
     I2CE_Locales::setPreferredLocale($this->locale);
     $forms = I2CE::getRuntimeVariable('forms', false);
     if ($forms) {
         $forms = explode(',', $forms);
     } else {
         $forms = $formConfig->getKeys('/modules/forms/forms');
         $cli = new I2CE_CLI();
         $forms = $cli->chooseMenuValues("Select Forms:", $forms);
     }
     if ($skipforms = I2CE::getRuntimeVariable('skipforms', false)) {
         $skipforms = explode('#', $skipforms);
         $t_forms = array();
         foreach ($forms as $form) {
             foreach ($skipforms as $skipform) {
                 if (preg_match('/' . $skipform . '/', $form)) {
                     continue 2;
                 }
             }
             $t_forms[] = $form;
         }
         $forms = $t_forms;
     }
     sort($forms, SORT_STRING);
     switch ($this->page) {
         case 'wiki':
             $this->wiki($forms);
             break;
         case 'dot':
             $this->dot($forms);
             break;
         case 'text':
         default:
             $this->text($forms);
             break;
     }
 }