changes to prior commit
[openemr.git] / library / restoreSession.php
bloba72185b993586980bc3a32f089e86c28bf3cf545
1 // login.php makes sure the session ID captured here is different for each
2 // new login. We maintain it here because most browsers do not have separate
3 // cookie storage for different top-level windows. This function should be
4 // called just prior to invoking any server script that requires correct
5 // session data. onclick="top.restoreSession()" usually does the job.
6 //
7 var oemr_session_name = '<?php echo session_name(); ?>';
8 var oemr_session_id = '<?php echo session_id(); ?>';
9 var oemr_dialog_close_msg = '<?php echo (function_exists('xla')) ? xla("OK to close this other popup window?") : "OK to close this other popup window?"; ?>';
11 function restoreSession() {
12 <?php if (!empty($GLOBALS['restore_sessions'])) { ?>
13 var ca = document.cookie.split('; ');
14 for (var i = 0; i < ca.length; ++i) {
15 var c = ca[i].split('=');
16 if (c[0] == oemr_session_name && c[1] != oemr_session_id) {
17 <?php if ($GLOBALS['restore_sessions'] == 2) { ?>
18 alert('Changing session ID from\n"' + c[1] + '" to\n"' + oemr_session_id + '"');
19 <?php } ?>
20 document.cookie = oemr_session_name + '=' + oemr_session_id + '; path=<?php echo($web_root ? $web_root : '/');?>';
23 <?php } ?>
24 return true;
27 // Pages that have a Print button or link should call this to initialize it for logging.
28 // This is done at page load time in case we want to hide or disable the element.
29 // The second argument, if present, specifies a log message to be used instead of logging
30 // the entire document and will always prevent hiding of the button or link.
32 function printLogSetup(elem, logdata) {
33 if (elem == null) return;
34 var doc = elem.ownerDocument;
35 var win = doc.defaultView || doc.parentWindow;
36 if (typeof(logdata) == 'undefined') logdata = null;
37 <?php if ($GLOBALS['gbl_print_log_option'] == 1) { ?>
38 if (logdata == null) {
39 elem.style.display = 'none';
40 return;
42 <?php } ?>
43 win.printlogdata = logdata;
44 elem.onclick = function () {
45 // This is a function definition and variables here will be evaluated when the function executes.
46 top.printLogPrint(this);
50 // Pages that would otherwise call window.print() at load time should call this instead
51 // to support print logging. In this case the passed argument is normally the window,
52 // and data to log, if specified, should be in the caller's window.printlogdata.
53 // If no log data is specified and the global option to hide the print feature is set,
54 // then no printing is done and the function returns false.
56 function printLogPrint(elem) {
57 var win = elem;
58 if (elem.ownerDocument) {
59 var doc = elem.ownerDocument;
60 win = doc.defaultView || doc.parentWindow;
62 <?php if ($GLOBALS['gbl_print_log_option'] == 1) { ?>
63 // Returning false means we didn't print.
64 if (!win.printlogdata) return false;
65 <?php } ?>
66 if (win.printlog_before_print) win.printlog_before_print();
67 win.print();
68 <?php if (!empty($GLOBALS['gbl_print_log_option'])) { ?>
69 comments = win.printlogdata || win.document.body.innerHTML;
70 top.restoreSession();
71 $.post("<?php echo $GLOBALS['webroot']; ?>/library/ajax/log_print_action_ajax.php",
72 { comments: comments }
74 <?php } ?>
75 return true;