/**
     * Add javascript logout to the page if a timeout is set for the site.
     * @param I2CE_Page $page
     */
    public function javascriptTimeout($page)
    {
        if (!$page->getUser()->logged_in()) {
            return;
        }
        $timeout = 0;
        I2CE::getConfig()->setIfIsSet($timeout, "/config/site/user_timeout");
        I2CE::getConfig()->setIfIsSet($timeout, "/user_prefs/timeout/user_timeout");
        if ($timeout && is_numeric($timeout) && $timeout > 0) {
            $timeout = $timeout * 1000;
            $message = "You have been logged out due to inactivity.";
            I2CE::getConfig()->setIfIsSet($message, "/config/site/user_timeout_message");
            I2CE::getConfig()->setIfIsSet($message, "/user_prefs/timeout/user_timeout_message");
            $logout = $page->getAccessedBaseURL() . "logout?message=" . urlencode($message);
            $js = <<<EOJS
var auto_logout_timeout_id = 0;
window.addEvent('domready', function() { 
        autoLogoutResetTimeout(); 
        document.addEvent('keypress', function(event) { autoLogoutResetTimeout(); } );
        document.addEvent('mousemove', function(event) { autoLogoutResetTimeout(); } );
        } );
function autoLogoutResetTimeout() {
    if ( auto_logout_timeout_id > 0 ) {
        clearTimeout( auto_logout_timeout_id );
    }
    auto_logout_timeout_id = setTimeout( function() { window.location = "{$logout}"; }, {$timeout} );
}
EOJS;
            $template = $page->getTemplate();
            $template->addHeaderLink("mootools-core.js");
            $template->addHeaderText($js, "script", true);
        }
    }
Exemple #2
0
 public function ajaxTest($page)
 {
     if (!isset($_SESSION['stub_ajax_test'])) {
         $_SESSION['stub_ajax_test'] = 'unknown0';
     }
     if (is_bool($_SESSION['stub_ajax_test'])) {
         return;
     }
     if (preg_match('/^unknown(\\d*)/', $_SESSION['stub_ajax_test'], $matches)) {
         if ($matches[1] > 5) {
             $_SESSION['stub_ajax_test'] = false;
             //assume after 5 page request we never got a response
         } else {
             $matches[1]++;
             $_SESSION['stub_ajax_test'] = 'unknown' . $matches[1];
         }
     } else {
         $_SESSION['stub_ajax_test'] = 'unknown0';
     }
     $stub_url = I2CE_Page::getAccessedBaseURL() . "/stub-ajax";
     $startJS = "\nvar Stub_Ajax_Test = {\n   start: function(){   \n        new Request.HTML({url:'{$stub_url}'}).get();\n   }\n};\nwindow.addEvent('load',Stub_Ajax_Test.start);\n";
     $template = $page->getTemplate();
     $template->addHeaderLink('mootools-core.js');
     $template->addHeaderText($startJS, 'script', "stub_ajax_test");
 }
 public function displayValues($content_node, $transient_options, $action)
 {
     if (!($mainNode = $this->template->appendFileByNode('swiss_svs_lists.html', 'div', $content_node)) instanceof DOMNode || !($listNode = $this->template->getElementByName('lists', 0, $mainNode)) instanceof DOMNode) {
         return false;
     }
     $publish_text = 'Publish a new version';
     $retrieve_text = 'Retrieve the most recent version';
     $edit_text = 'Edit %s configuration';
     $other_text = 'Other Versions:';
     $based_on_form_text = 'Based on the list %s';
     I2CE::getConfig()->setIfIsSet($publish_text, "/modules/SVS/messages/publish");
     I2CE::getConfig()->setIfIsSet($retrieve_text, "/modules/SVS/messages/retrieve");
     I2CE::getConfig()->setIfIsSet($edit_text, "/modules/SVS/messages/edit");
     I2CE::getConfig()->setIfIsSet($other_text, "/modules/SVS/messages/other");
     I2CE::getConfig()->setIfIsSet($based_on_form_text, "/modules/SVS/messages/basd_on_form_style");
     foreach ($this->storage->getKeys() as $oid) {
         if (!($swissChild = $this->getChild($oid)) instanceof I2CE_Swiss_SVS) {
             continue;
         }
         $form = $swissChild->getField('list');
         $id = 'list_' . $oid;
         $listNode->appendChild($liNode = $this->template->createElement('li'));
         $liNode->appendChild($spanNode = $this->template->createElement('span', array('id' => $id)));
         $spanNode->appendChild($aNode = $this->template->createElement('a', array('id' => $id . '_link')));
         $aNode->appendChild($this->template->createElement('h3', array(), sprintf($edit_text, $oid)));
         if ($form) {
             $spanNode->appendChild($pNode = $this->template->createElement('p', array(), sprintf($based_on_form_text, $form)));
         }
         $spanNode->appendChild($divNode = $this->template->createElement('div', array('id' => $id . '_ajax', 'class' => 'indented')));
         $spanNode->appendChild($linkDivNode = $this->template->createElement('div', array('class' => 'indented')));
         $publish = I2CE_Page::getAccessedBaseURL() . '/SVS/publish?id=' . $oid;
         $retrieve = I2CE_Page::getAccessedBaseURL() . '/SVS/RetrieveValueSet?id=' . $oid;
         $linkDivNode->appendChild($this->template->createElement('a', array('href' => $publish), $publish_text));
         $linkDivNode->appendChild($this->template->createElement('br'));
         $versions = iHRIS_SVS::getVersions($oid);
         if (count($versions) > 0) {
             $linkDivNode->appendChild($this->template->createElement('a', array('href' => $retrieve), $retrieve_text));
             $linkDivNode->appendChild($this->template->createElement('br'));
             $linkDivNode->appendChild($this->template->createTextNode($other_text));
             sort($versions);
             foreach ($versions as $i => $version) {
                 if ($i != 0) {
                     $linkDivNode->appendChild($this->template->createTextNode(','));
                 }
                 $linkDivNode->appendChild($this->template->createElement('a', array('href' => $retrieve . '&version=' . $version), " {$version} "));
             }
         }
         $linkDivNode->appendChild($this->template->createElement('pre', array(), $retrieve));
         $swissChild->addAjaxLink($id . '_link', 'contents', $id . '_ajax', $spanNode, $action, $transient_options);
     }
     return true;
 }
Exemple #4
0
 public function getMeta()
 {
     $meta = I2CE::getConfig()->getAsArray("/modules/SVS/lists/" . $this->oid . "/meta");
     if (!is_array($meta)) {
         $meta = array();
     }
     $req_keys = array('displayName' => $this->listObj->getDisplayName(), 'Status' => 'Active', 'Source' => 'iHRIS', 'SourceURI' => I2CE_Page::getAccessedBaseURL(), 'Type' => 'Expanded');
     I2CE::getConfig()->setIfIsSet($meta['Source'], "/config/site/module");
     foreach ($req_keys as $key => $val) {
         if (!array_key_exists($key, $meta) || !$meta[$key]) {
             $meta[$key] = $val;
         }
     }
     return $meta;
 }
 protected function displayMeta($mainNode, $transient_options, $action)
 {
     if (($styleNode = $this->template->getElementByName('style', 0, $mainNode)) instanceof DOMNode) {
         $styles = I2CE::getConfig()->getKeys("/I2CE/template/page_styles");
         $selected_style = $this->getField('style');
         foreach ($styles as $style) {
             $attrs = array('value' => $style);
             if ($style == $selected_style && $selected_style != '' || $style == 'shell' && $selected_style == '') {
                 $attrs['selected'] = 'selected';
             }
             $styleNode->appendChild($this->template->createElement('option', $attrs, $style));
         }
         $this->renameInputs('style', $mainNode);
     }
     if (($descNode = $this->template->getElementByName('description', 0, $mainNode)) instanceof DOMNode) {
         $this->template->setDisplayData("page", $this->name, $descNode);
         $this->template->setDisplayData("class", $this->getField('class'), $descNode);
     }
     if (($linkNode = $this->template->getElementByName('link_name', 0, $mainNode)) instanceof DOMNode) {
         $page = $this->getName();
         $url = I2CE_Page::getAccessedBaseURL() . '/' . $page;
         $c = 0;
         $formids = $this->getSampleIDs();
         foreach ($formids as $formid) {
             $this->template->setDisplayDataImmediate("link_title_" . $c, "{$page} {$c}", $linkNode);
             $this->template->setDisplayDataImmediate("page_edit_link_" . $c, "{$url}?id={$formid}", $linkNode);
             $c++;
         }
         return true;
     }
 }
 public static function intialize_csd_cache_metadata($csd_cache, $lists = array(), $requested_oids = array(), $options = array())
 {
     if (!I2CE_MagicDataNode::checkKey($csd_cache) || !is_array($lists)) {
         I2CE::raiseError("Badness on CSD cache metadata args");
         return false;
     }
     if (!is_array($requested_oids)) {
         $requested_oids = array();
     }
     if (!is_array($options)) {
         $options = array();
     }
     $config = I2CE::getConfig();
     if (!($svs_config = $config->traverse("/modules/SVS/lists", true, false)) instanceof I2CE_MagicDataNode) {
         I2CE::raiseError("bad SVS root node");
         return false;
     }
     if (!($csd_cache_config = $config->traverse("/modules/csd_cache/" . $csd_cache . "/args", true, false)) instanceof I2CE_MagicDataNode) {
         I2CE::raiseError("bad csd_cache config node");
         return false;
     }
     $site_module = 'ihris';
     $config->setIfIsSet($site_module, '/config/site/module');
     $source_uri = "http://localhost/" . $site_module;
     if (array_key_exists('HTTP_HOST', $_SERVER)) {
         $source_uri = I2CE_Page::getAccessedBaseURL();
     }
     if (!is_array($oids = $csd_cache_config->getAsArray('svs_dependencies'))) {
         $oids = array();
     }
     foreach ($lists as $list) {
         if (array_key_exists($list, $oids)) {
             continue;
         }
         if (array_key_exists($list, $requested_oids)) {
             $oids[$list] = $oid = $requested_oids[$list];
         } else {
             $oids[$list] = $oid = iHRIS_CSDCache::generateUUIDasOID();
         }
         if (!I2CE_MagicDataNode::checkKey($oid)) {
             I2CE::raiseError("Invalid OID: {$oid}");
             return false;
         }
         if (array_key_exists($list, $options) && is_array($options[$list])) {
             $opts = $options[$list];
         } else {
             $opts = array();
         }
         $styles = iHRIS_SVS::getAvailableStyles($list);
         if (array_key_exists('code_style', $opts) && is_scalar($opts['code_style'])) {
             $code_style = $opts['code_style'];
         } else {
             $code_style = 'code';
         }
         if (!in_array($code_style, $styles)) {
             $code_style = 'id';
         }
         $definition = array('list' => $list, 'meta' => array('Source' => $site_module, 'SourceURI' => $source_uri, 'code_style' => $code_style, 'code_system' => $oid));
         if (!($svs_list_config = $svs_config->traverse($oid, true, false)) instanceof I2CE_MagicDataNode) {
             I2CE::raiseError("Could not create MD for {$oid} at " . $svs_config->getPath());
             return false;
         }
         $svs_list_config->setValue($definition);
         try {
             $svs = new iHRIS_SVS($oid);
             $svs->publishConceptList();
         } catch (Exception $e) {
             I2CE::raiseError("Could not create SVS list on OID: {$oid}");
             return false;
         }
     }
     $transform_vars = array('sourceDirectory' => $source_uri, 'rootProviderURN' => 'urn:ihris.org:' . $site_module . ':providers', 'rootFacilityURN' => 'urn:ihris.org:' . $site_module . ':facilities', 'rootOrganizationURN' => 'urn:ihris.org:' . $site_module . ':organizations', 'rootServicesURN' => 'urn:ihris.org:' . $site_module . ':services');
     foreach ($lists as $list) {
         $transform_vars[$list . 'CodingScheme'] = $oids[$list];
     }
     $csd_cache_config->svs_dependencies = $oids;
     foreach ($transform_vars as $key => $val) {
         I2CE::raiseError("Setting {$key} at " . $csd_cache_config->getPath());
         if (!$csd_cache_config->__isset("transform_vars/" . $key)) {
             $csd_cache_config->transform_vars->{$key} = $val;
         }
     }
     return true;
 }
 protected function sendVerificationEmail()
 {
     $verify_only = false;
     $msg_html = false;
     I2CE::getConfig()->setIfIsSet($verify_only, "/modules/RequestAccount-VerifyEmail/verify_only");
     if ($verify_only) {
         I2CE::getConfig()->setIfIsSet($msg, "/modules/RequestAccount-VerifyEmail/user_messages/email_message_verify_only");
         I2CE::getConfig()->setIfIsSet($msg_html, "/modules/RequestAccount-VerifyEmail/user_messages/email_message_verify_only_html");
     } else {
         I2CE::getConfig()->setIfIsSet($msg, "/modules/RequestAccount-VerifyEmail/user_messages/email_message");
         if (!I2CE::getConfig()->setIfIsSet($msg_html, "/modules/RequestAccount-VerifyEmail/user_messages/email_message_html")) {
             I2CE::raiseError("NO HTML");
         }
     }
     I2CE::getConfig()->setIfIsSet($subject, "/modules/RequestAccount-VerifyEmail/user_messages/email_subject");
     $site_link = I2CE_Page::getAccessedBaseURL() . '/' . $this->pageRoot();
     $link = $site_link . "?verify=" . $this->requested_user->getField('request_number')->getValue();
     $username = $this->requested_user->username;
     $email = $this->requested_user->email;
     $site = 'I2CE';
     I2CE::getConfig()->setIfIsSet($site, "/I2CE/template/prefix_title");
     $msg = sprintf($msg, $username, $link, $site, $site_link);
     if ($msg_html) {
         $msg_html = sprintf($msg_html, $username, $link, $site, $site_link);
     }
     $subject = sprintf($subject, $site);
     if (!$email || !$msg || !$subject) {
         I2CE::raiseError("Invalid message<{$msg}> or subject<{$subject}> or email<{$email}>");
         return false;
     }
     I2CE::raiseError("Want to send email to {$email} with subject {$subject}");
     I2CE::raiseError("Want to send email to user {$username} with message {$msg}");
     I2CE::raiseError("Want to send email to user {$username} with message  html " . $msg_html);
     if (!I2CE_Mailer::mail($email, array('Subject' => $subject), $msg, $msg_html)) {
         I2CE::raiseError("Could not mail verification message to {$username} / {$email}");
         return false;
     }
     return true;
 }
 public function displayValues($content_node, $transient_options, $action)
 {
     if (!($mainNode = $this->template->appendFileByNode('swiss_svs_meta.html', 'div', $content_node)) instanceof DOMNode) {
         I2CE::raiseError("Could not load " . $this->getTemplate());
         return false;
     }
     $avail_styles = $this->getAllowedStyles();
     $default_styles = array('code_style' => 'code', 'display_style' => 'default');
     foreach (self::$styles as $style) {
         if (!($styleNode = $this->template->getElementByName($style, 0, $mainNode)) instanceof DOMElement) {
             continue;
         }
         $sel = $this->getField($style);
         $t_avail_styles = $avail_styles;
         if ($style == 'code_style') {
             $t_avail_styles[] = 'id';
         }
         if (!$sel) {
             if (array_key_exists($style, $default_styles) && in_array($default_styles[$style], $avail_styles)) {
                 $this->setField($style, $default_styles[$style]);
                 $sel = $default_styles[$style];
             } else {
                 if ($style == 'code_style') {
                     $this->setField($style, 'id');
                     $sel = 'id';
                 }
             }
         }
         foreach ($t_avail_styles as $s) {
             $attrs = array('value' => $s);
             if ($s == $sel) {
                 $attrs['selected'] = 'selected';
             }
             $styleNode->appendChild($this->template->createElement('option', $attrs, $s));
         }
     }
     $type = $this->getField('Type');
     if (!$type) {
         $this->setField('Type', 'Expanded');
     }
     $uri = $this->getField('SourceURI');
     if (!$uri) {
         $this->setField('SourceURI', I2CE_Page::getAccessedBaseURL());
     }
     $stat = $this->getField('Status');
     if (!$stat) {
         $this->setField('Status', 'Active');
     }
     $src = $this->getField('Source');
     if (!$src) {
         $src = 'iHRIS';
         I2CE::getConfig()->setIfIsSet($src, "/config/site/module");
         $this->setField('Source', $src);
     }
     foreach (self::$fields as $field) {
         $this->template->setDisplayDataImmediate($field, $this->getField($field), $mainNode);
     }
     $this->renameInputs(self::$fields, $mainNode);
     $this->renameInputs(self::$styles, $mainNode);
     return true;
 }