Highway to PSR2
[openemr.git] / interface / login / login.php
blob330d034580eb61292880413146f1a8f541598fbf
1 <?php
2 /**
3 * Login screen.
5 * LICENSE: This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
16 * @package OpenEMR
17 * @author Rod Roark <rod@sunsetsystems.com>
18 * @author Brady Miller <brady.g.miller@gmail.com>
19 * @author Kevin Yeh <kevin.y@integralemr.com>
20 * @author Scott Wakefield <scott.wakefield@gmail.com>
21 * @author ViCarePlus <visolve_emr@visolve.com>
22 * @author Julia Longtin <julialongtin@diasp.org>
23 * @author cfapress
24 * @author markleeds
25 * @link http://www.open-emr.org
30 use OpenEMR\Core\Header;
32 $ignoreAuth=true;
33 require_once("../globals.php");
35 // mdsupport - Add 'App' functionality for user interfaces without standard menu and frames
36 // If this script is called with app parameter, validate it without showing other apps.
38 // Build a list of valid entries
39 $emr_app = array();
40 if ($GLOBALS['new_tabs_layout']) {
41 $rs = sqlStatement(
42 "SELECT option_id, title,is_default FROM list_options
43 WHERE list_id=? and activity=1 ORDER BY seq, option_id",
44 array ('apps')
46 if (sqlNumRows($rs)) {
47 while ($app = sqlFetchArray($rs)) {
48 $app_req = explode('?', trim($app['title']));
49 if (! file_exists('../'.$app_req[0])) {
50 continue;
53 $emr_app [trim($app ['option_id'])] = trim($app ['title']);
54 if ($app ['is_default']) {
55 $emr_app_def = $app ['option_id'];
61 $div_app = '';
62 if (count($emr_app)) {
63 // Standard app must exist
64 $std_app = 'main/main_screen.php';
65 if (!in_array($std_app, $emr_app)) {
66 $emr_app['*OpenEMR'] = $std_app;
69 if (isset($_REQUEST['app']) && $emr_app[$_REQUEST['app']]) {
70 $div_app = sprintf('<input type="hidden" name="appChoice" value="%s">', attr($_REQUEST['app']));
71 } else {
72 foreach ($emr_app as $opt_disp => $opt_value) {
73 $opt_htm .= sprintf(
74 '<option value="%s" %s>%s</option>\n',
75 attr($opt_disp),
76 ($opt_disp == $opt_default ? 'selected="selected"' : ''),
77 text(xl_list_label($opt_disp))
81 $div_app = sprintf(
83 <div id="divApp" class="form-group">
84 <label for="appChoice" class="control-label text-right">%s:</label>
85 <div>
86 <select class="form-control" id="selApp" name="appChoice" size="1">%s</select>
87 </div>
88 </div>',
89 xlt('App'),
90 $opt_htm
96 <html>
97 <head>
98 <title><?php echo text($openemr_name) . " " . xlt('Login'); ?></title>
99 <meta http-equiv="X-UA-Compatible" content="IE=edge" />
101 <?php Header::setupHeader(['jquery-ui', 'jquery-ui-darkness']); ?>
103 <link rel="stylesheet" href="../themes/login.css?v=<?php echo $v_js_includes; ?>" type="text/css">
105 <link rel="shortcut icon" href="<?php echo $GLOBALS['images_static_relative']; ?>/favicon.ico" />
107 <script type="text/javascript">
108 var registrationTranslations = <?php echo json_encode(array(
109 'title' => xla('OpenEMR Product Registration'),
110 'pleaseProvideValidEmail' => xla('Please provide a valid email address'),
111 'success' => xla('Success'),
112 'registeredSuccess' => xla('Your installation of OpenEMR has been registered'),
113 'submit' => xla('Submit'),
114 'noThanks' => xla('No Thanks'),
115 'registeredEmail' => xla('Registered email'),
116 'registeredId' => xla('Registered id'),
117 'genericError' => xla('Error. Try again later'),
118 'closeTooltip' => ''
122 var registrationConstants = <?php echo json_encode(array(
123 'webroot' => $GLOBALS['webroot']
126 </script>
128 <script type="text/javascript" src="<?php echo $webroot ?>/interface/product_registration/product_registration_service.js?v=<?php echo $v_js_includes; ?>"></script>
129 <script type="text/javascript" src="<?php echo $webroot ?>/interface/product_registration/product_registration_controller.js?v=<?php echo $v_js_includes; ?>"></script>
131 <script type="text/javascript">
132 jQuery(document).ready(function() {
133 init();
135 var productRegistrationController = new ProductRegistrationController();
136 productRegistrationController.getProductRegistrationStatus(function(err, data) {
137 if (err) { return; }
139 if (data.statusAsString === 'UNREGISTERED') {
140 productRegistrationController.showProductRegistrationModal();
145 function init() {
146 $("#authUser").focus();
149 function transmit_form() {
150 document.forms[0].submit();
153 function imsubmitted() {
154 <?php if (!empty($GLOBALS['restore_sessions'])) { ?>
155 // Delete the session cookie by setting its expiration date in the past.
156 // This forces the server to create a new session ID.
157 var olddate = new Date();
158 olddate.setFullYear(olddate.getFullYear() - 1);
159 document.cookie = '<?php echo session_name() . '=' . session_id() ?>; path=<?php echo($web_root ? $web_root : '/');?>; expires=' + olddate.toGMTString();
160 <?php } ?>
161 return false; //Currently the submit action is handled by the encrypt_form().
163 </script>
165 </head>
166 <body class="login">
167 <div class="container">
168 <form method="POST" id="login_form"
169 action="../main/main_screen.php?auth=login&site=<?php echo attr($_SESSION['site_id']); ?>"
170 target="_top" name="login_form" onsubmit="return imsubmitted();">
171 <div class="row">
172 <div class="col-sm-12">
173 <div>
174 <div class="center-block" style="max-width:400px">
175 <img class="img-responsive center-block" src="<?php echo $GLOBALS['images_static_relative']; ?>/login-logo.png" />
176 </div>
178 <input type='hidden' name='new_login_session_management' value='1' />
180 <?php
181 // collect groups
182 $res = sqlStatement("select distinct name from groups");
183 for ($iter = 0; $row = sqlFetchArray($res); $iter++) {
184 $result[$iter] = $row;
187 if (count($result) == 1) {
188 $resvalue = $result[0]{"name"};
189 echo "<input type='hidden' name='authProvider' value='" . attr($resvalue) . "' />\n";
192 // collect default language id
193 $res2 = sqlStatement("select * from lang_languages where lang_description = ?", array($GLOBALS['language_default']));
194 for ($iter = 0; $row = sqlFetchArray($res2); $iter++) {
195 $result2[$iter] = $row;
198 if (count($result2) == 1) {
199 $defaultLangID = $result2[0]{"lang_id"};
200 $defaultLangName = $result2[0]{"lang_description"};
201 } else {
202 //default to english if any problems
203 $defaultLangID = 1;
204 $defaultLangName = "English";
207 // set session variable to default so login information appears in default language
208 $_SESSION['language_choice'] = $defaultLangID;
209 // collect languages if showing language menu
210 if ($GLOBALS['language_menu_login']) {
211 // sorting order of language titles depends on language translation options.
212 $mainLangID = empty($_SESSION['language_choice']) ? '1' : $_SESSION['language_choice'];
213 if ($mainLangID == '1' && !empty($GLOBALS['skip_english_translation'])) {
214 $sql = "SELECT *,lang_description as trans_lang_description FROM lang_languages ORDER BY lang_description, lang_id";
215 $res3=SqlStatement($sql);
216 } else {
217 // Use and sort by the translated language name.
218 $sql = "SELECT ll.lang_id, " .
219 "IF(LENGTH(ld.definition),ld.definition,ll.lang_description) AS trans_lang_description, " .
220 "ll.lang_description " .
221 "FROM lang_languages AS ll " .
222 "LEFT JOIN lang_constants AS lc ON lc.constant_name = ll.lang_description " .
223 "LEFT JOIN lang_definitions AS ld ON ld.cons_id = lc.cons_id AND " .
224 "ld.lang_id = ? " .
225 "ORDER BY IF(LENGTH(ld.definition),ld.definition,ll.lang_description), ll.lang_id";
226 $res3=SqlStatement($sql, array($mainLangID));
229 for ($iter = 0; $row = sqlFetchArray($res3); $iter++) {
230 $result3[$iter] = $row;
233 if (count($result3) == 1) {
234 //default to english if only return one language
235 echo "<input type='hidden' name='languageChoice' value='1' />\n";
237 } else {
238 echo "<input type='hidden' name='languageChoice' value='".attr($defaultLangID)."' />\n";
241 </div>
242 </div>
243 </div>
244 <?php if (isset($_SESSION['relogin']) && ($_SESSION['relogin'] == 1)) : // Begin relogin dialog ?>
245 <div class="row">
246 <div class="col-sm-12">
248 <strong><?php echo xlt('Password security has recently been upgraded.'); ?><br>
249 <?php echo xlt('Please login again.'); ?></strong>
250 </p>
251 <?php unset($_SESSION['relogin']); ?>
252 </div>
253 </div>
254 <?php endif; ?>
255 <?php if (isset($_SESSION['loginfailure']) && ($_SESSION['loginfailure'] == 1)) : // Begin login failure block ?>
256 <div class="row">
257 <div class="col-sm-12">
258 <div class="well well-lg login-failure">
259 <?php echo xlt('Invalid username or password'); ?>
260 </div>
261 </div>
262 </div>
263 <?php endif; // End login failure block?>
264 <div class="row">
265 <?php
266 $extraLogo = $GLOBALS['extra_logo_login'];
267 $loginFormColumnCount = ($extraLogo == 1) ? '6' : '12';
269 <?php if ($extraLogo) : ?>
270 <div class="col-sm-6">
271 <?php echo $logocode; ?>
272 </div>
273 <?php endif; ?>
274 <div class="col-sm-<?php echo $loginFormColumnCount;?>">
275 <div class="row">
276 <div class="center-block login-title-label">
277 <?php if ($GLOBALS['show_label_login']) : ?>
278 <?php echo text($openemr_name); ?>
279 <?php endif; ?>
280 </div>
281 <?php
282 // Figure out how to display the tiny logos
283 $t1 = $GLOBALS['tiny_logo_1'];
284 $t2 = $GLOBALS['tiny_logo_2'];
285 if ($t1 && !$t2) : ?>
286 <div class="col-sm-12 center-block">
287 <?php echo $tinylogocode1; ?>
288 </div>
289 <?php
290 endif;
291 if ($t2 && !$t1) : ?>
292 <div class="col-sm-12 center-block">
293 <?php echo $tinylogocode2; ?>
294 </div>
295 <?php
296 endif;
297 if ($t1 && $t2) : ?>
298 <div class="col-sm-6 center-block"><?php echo $tinylogocode1;?></div>
299 <div class="col-sm-6 center-block"><?php echo $tinylogocode2;?></div>
300 <?php
301 endif;
303 </div>
304 <?php if (count($result) > 1) : // Begin Display check for groups ?>
305 <div class="form-group">
306 <label for="group" class="control-label text-right"><?php echo xlt('Group:'); ?></label>
307 <div>
308 <select name="authProvider" class="form-control">
309 <?php
310 foreach ($result as $iter) {
311 echo "<option value='".attr($iter{"name"})."'>".text($iter{"name"})."</option>\n";
314 </select>
315 </div>
316 </div>
317 <?php endif; // End Display check for groups ?>
318 <div class="form-group">
319 <label for="authUser" class="control-label text-right"><?php echo xlt('Username:'); ?></label>
320 <input type="text" class="form-control" id="authUser" name="authUser" placeholder="<?php echo xla('Username:'); ?>">
321 </div>
322 <div class="form-group">
323 <label for="clearPass" class="control-label text-right"><?php echo xlt('Password:'); ?></label>
324 <input type="password" class="form-control" id="clearPass" name="clearPass" placeholder="<?php echo xla('Password:'); ?>">
325 </div>
326 <?php echo $div_app ?>
327 <?php if ($GLOBALS['language_menu_login'] && (count($result3) != 1)) : // Begin language menu block ?>
328 <div class="form-group">
329 <label for="language" class="control-label text-right"><?php echo xlt('Language'); ?>:</label>
330 <div>
331 <select class="form-control" name="languageChoice" size="1">
332 <?php
333 echo "<option selected='selected' value='" . attr($defaultLangID) . "'>" . xlt('Default') . " - " . xlt($defaultLangName) . "</option>\n";
334 foreach ($result3 as $iter) :
335 if ($GLOBALS['language_menu_showall']) {
336 if (!$GLOBALS['allow_debug_language'] && $iter['lang_description'] == 'dummy') {
337 continue; // skip the dummy language
340 echo "<option value='".attr($iter['lang_id'])."'>".text($iter['trans_lang_description'])."</option>\n";
341 } else {
342 if (in_array($iter['lang_description'], $GLOBALS['language_menu_show'])) {
343 if (!$GLOBALS['allow_debug_language'] && $iter['lang_description'] == 'dummy') {
344 continue; // skip the dummy language
347 echo "<option value='".attr($iter['lang_id'])."'>" . text($iter['trans_lang_description']) . "</option>\n";
350 endforeach; ?>
351 </select>
352 </div>
353 </div>
354 <?php endif; // End language menu block ?>
355 <div class="form-group pull-right">
356 <button type="submit" class="btn btn-default btn-lg" onClick="transmit_form()"><i class="fa fa-sign-in"></i>&nbsp;&nbsp;<?php echo xlt('Login');?></button>
357 </div>
358 </div>
359 <div class="col-sm-12 text-center">
360 <p class="small">
361 <a href="../../acknowledge_license_cert.html" target="main"><?php echo xlt('Acknowledgments, Licensing and Certification'); ?></a>
362 </p>
363 </div>
364 <div class="product-registration-modal" style="display: none">
365 <p class="context"><?php echo xlt("Register your installation with OEMR to receive important notifications, such as security fixes and new release announcements."); ?></p>
366 <input placeholder="<?php echo xlt('email'); ?>" type="email" class="email" style="width: 100%; color: black" />
367 <p class="message" style="font-style: italic"></p>
368 </div>
369 </div>
370 </form>
371 </div>
372 </body>
373 </html>