From 5375a5e6b9b767abe7db12c918f05a9b616b6e8b Mon Sep 17 00:00:00 2001
From: Jaime Perez Crespo <jaime.perez@uninett.no>
Date: Mon, 2 Nov 2015 16:37:21 +0100
Subject: [PATCH] Reformat the login page template and enhance it.

---
 modules/core/templates/loginuserpass.php | 260 +++++++++++------------
 www/resources/default.css                |  11 +-
 2 files changed, 139 insertions(+), 132 deletions(-)

diff --git a/modules/core/templates/loginuserpass.php b/modules/core/templates/loginuserpass.php
index 8983d1a26..389a11182 100644
--- a/modules/core/templates/loginuserpass.php
+++ b/modules/core/templates/loginuserpass.php
@@ -2,150 +2,148 @@
 $this->data['header'] = $this->t('{login:user_pass_header}');
 
 if (strlen($this->data['username']) > 0) {
-	$this->data['autofocus'] = 'password';
+    $this->data['autofocus'] = 'password';
 } else {
-	$this->data['autofocus'] = 'username';
+    $this->data['autofocus'] = 'username';
 }
 $this->includeAtTemplateBase('includes/header.php');
 
 ?>
 
 <?php
-if ($this->data['errorcode'] !== NULL) {
-?>
-	<div style="border-left: 1px solid #e8e8e8; border-bottom: 1px solid #e8e8e8; background: #f5f5f5">
-		<img src="/<?php echo $this->data['baseurlpath']; ?>resources/icons/experience/gtk-dialog-error.48x48.png" class="float-l erroricon" style="margin: 15px" alt="" />
-		<h2><?php echo $this->t('{login:error_header}'); ?></h2>
-		<p><b><?php echo htmlspecialchars($this->t('{errors:title_' . $this->data['errorcode'] . '}', $this->data['errorparams'])); ?></b></p>
-		<p><?php echo htmlspecialchars($this->t('{errors:descr_' . $this->data['errorcode'] . '}', $this->data['errorparams'])); ?></p>
-	</div>
+if ($this->data['errorcode'] !== null) {
+    ?>
+    <div style="border-left: 1px solid #e8e8e8; border-bottom: 1px solid #e8e8e8; background: #f5f5f5">
+        <img src="/<?php echo $this->data['baseurlpath']; ?>resources/icons/experience/gtk-dialog-error.48x48.png"
+             class="float-l erroricon" style="margin: 15px" alt=""/>
+
+        <h2><?php echo $this->t('{login:error_header}'); ?></h2>
+
+        <p><strong><?php
+                echo htmlspecialchars($this->t(
+                    '{errors:title_'.$this->data['errorcode'].'}',
+                    $this->data['errorparams']
+                )); ?></strong></p>
+
+        <p><?php
+            echo htmlspecialchars($this->t(
+                '{errors:descr_'.$this->data['errorcode'].'}',
+                $this->data['errorparams']
+            )); ?></p>
+    </div>
 <?php
 }
-?>
-	<h2 style="break: both"><?php echo $this->t('{login:user_pass_header}'); ?></h2>
-
-	<p class="logintext"><?php echo $this->t('{login:user_pass_text}'); ?></p>
 
-	<form action="?" method="post" name="f">
-	<table>
-		<tr>
-			<td rowspan="3"><img src="/<?php echo $this->data['baseurlpath']; ?>resources/icons/experience/gtk-dialog-authentication.48x48.png" id="loginicon" alt="" /></td>
-			<td style="padding: .3em;"><?php echo $this->t('{login:username}'); ?></td>
-			<td>
-<?php
-if ($this->data['forceUsername']) {
-	echo '<strong style="font-size: medium">' . htmlspecialchars($this->data['username']) . '</strong>';
-} else {
-	echo '<input type="text" id="username" tabindex="1" name="username" value="' . htmlspecialchars($this->data['username']) . '" />';
-}
 ?>
-			</td>
+    <h2 style="break: both"><?php echo $this->t('{login:user_pass_header}'); ?></h2>
+
+    <p class="logintext"><?php echo $this->t('{login:user_pass_text}'); ?></p>
+
+    <form action="?" method="post" name="f">
+        <table>
+            <tr>
+                <td rowspan="2">
+                    <img id="loginicon" alt=""
+                        src="/<?php echo $this->data['baseurlpath']; ?>resources/icons/experience/gtk-dialog-authentication.48x48.png" />
+                </td>
+                <td><label for="username"><?php echo $this->t('{login:username}'); ?></label></td>
+                <td>
+                    <input id="username" <?php echo ($this->data['forceUsername']) ? 'disabled="disabled"' : ''; ?>
+                           type="text" name="username"
+<?php if (!$this->data['forceUsername']) {
+    echo 'tabindex="1"';
+} ?> value="<?php echo htmlspecialchars($this->data['username']); ?>"/>
+                </td>
+            <?php
+            if ($this->data['rememberUsernameEnabled'] && !$this->data['forcedUsername']) {
+                // display the "remember my username" checkbox
+            ?>
+                <td>
+                    <input type="checkbox" id="remember_username" tabindex="4"
+                           <?php echo ($this->data['rememberUsernameChecked']) ? 'checked="checked"' : ''; ?>
+                           name="remember_username" value="Yes"/>
+                    <small><?php echo $this->t('{login:remember_username}'); ?></small>
+                </td>
+            </tr>
+            <?php
+            }
+            ?>
+            <tr>
+                <td><label for="password"><?php echo $this->t('{login:password}'); ?></label></td>
+                <td>
+                    <input id="password" type="password" tabindex="2" name="password"/>
+                </td>
+            <?php
+            if ($this->data['rememberMeEnabled']) {
+                // display the remember me checkbox (keep me logged in)
+            ?>
+                <td>
+                    <input type="checkbox" id="remember_me" tabindex="5"
+                        <?php echo ($this->data['rememberMeChecked']) ? 'checked="checked"' : ''; ?>
+                           name="remember_me" value="Yes"/>
+                    <small><?php echo $this->t('{login:remember_me}'); ?></small>
+                </td>
+            </tr>
+            <?php
+            }
+            if (array_key_exists('organizations', $this->data)) {
+                ?>
+                <tr>
+                    <td></td>
+                    <td><label for="organization"><?php echo $this->t('{login:organization}'); ?></label></td>
+                    <td><select name="organization" tabindex="3">
+                            <?php
+                            if (array_key_exists('selectedOrg', $this->data)) {
+                                $selectedOrg = $this->data['selectedOrg'];
+                            } else {
+                                $selectedOrg = null;
+                            }
+
+                            foreach ($this->data['organizations'] as $orgId => $orgDesc) {
+                                if (is_array($orgDesc)) {
+                                    $orgDesc = $this->t($orgDesc);
+                                }
+
+                                if ($orgId === $selectedOrg) {
+                                    $selected = 'selected="selected" ';
+                                } else {
+                                    $selected = '';
+                                }
+
+                                echo '<option '.$selected.'value="'.htmlspecialchars($orgId).'">'.htmlspecialchars($orgDesc).'</option>';
+                            }
+                            ?>
+                        </select></td>
+                </tr>
+                <?php
+            }
+            ?>
+            <tr>
+                <td></td><td></td>
+                <td>
+                    <button id="regularsubmit" class="btn"
+                            onclick="this.value='<?php echo $this->t('{login:processing'); ?>';
+                                this.disabled=true; this.form.submit(); return true;" tabindex="6">
+                        <?php echo $this->t('{login:login_button}'); ?>
+                    </button>
+                </td>
+            </tr>
+        </table>
+        <?php
+        foreach ($this->data['stateparams'] as $name => $value) {
+            echo('<input type="hidden" name="'.htmlspecialchars($name).'" value="'.htmlspecialchars($value).'" />');
+        }
+        ?>
+    </form>
 <?php
-if ($this->data['rememberUsernameEnabled'] || $this->data['rememberMeEnabled']) {
-	$rowspan = 1;
-} elseif (array_key_exists('organizations', $this->data)) {
-	$rowspan = 3;
-} else {
-	$rowspan = 2;
-}
-?>
-			<td style="padding: .4em;" rowspan="<?php echo $rowspan; ?>">
-<?php
-if ($this->data['rememberUsernameEnabled'] || $this->data['rememberMeEnabled']) {
-    if ($this->data['rememberUsernameEnabled']) {
-        echo str_repeat("\t", 4);
-        echo '<input type="checkbox" id="remember_username" tabindex="4" name="remember_username" value="Yes" ';
-        echo ($this->data['rememberUsernameChecked'] ? 'checked="Yes" /> ' : '/> ');
-        echo $this->t('{login:remember_username}');
-    }
-    if ($this->data['rememberMeEnabled']) {
-        echo str_repeat("\t", 4);
-        echo '<input type="checkbox" id="remember_me" tabindex="4" name="remember_me" value="Yes" ';
-        echo $this->data['rememberMeChecked'] ? 'checked="Yes" /> ' : '/> ';
-        echo $this->t('{login:remember_me}');
+if (!empty($this->data['links'])) {
+    echo '<ul class="links" style="margin-top: 2em">';
+    foreach ($this->data['links'] as $l) {
+        echo '<li><a href="'.htmlspecialchars($l['href']).'">'.htmlspecialchars($this->t($l['text'])).'</a></li>';
     }
-} else {
-	$text = $this->t('{login:login_button}');
-	echo str_repeat("\t", 4);
-	echo "<input onclick=\"this.value='" . $this->t('{login:processing}') . "';this.disabled=true;this.form.submit();return true;\" type=\"submit\" tabindex=\"4\" id=\"regularsubmit\" value=\"{$text}\" />";
-}
-?>
-			</td>
-		</tr>
-		<tr>
-			<td style="padding: .3em;"><?php echo $this->t('{login:password}'); ?></td>
-			<td><input id="password" type="password" tabindex="2" name="password" /></td>
-<?php
-// Move submit button to next row if remember checkbox enabled
-if ($this->data['rememberUsernameEnabled'] || $this->data['rememberMeEnabled']) {
-	$rowspan = (array_key_exists('organizations', $this->data) ? 2 : 1);
-?>
-			<td style="padding: .4em;" rowspan="<?php echo $rowspan; ?>">
-				<input onclick="this.value='<?php echo $this->t('{login:processing}'); ?>';this.disabled=true;this.form.submit();return true;" type="submit" tabindex="5" id="regularsubmit" value="<?php echo $this->t('{login:login_button}'); ?>" />
-			</td>
-<?php
-}
-?>
-		</tr>
-
-<?php
-if (array_key_exists('organizations', $this->data)) {
-?>
-		<tr>
-			<td style="padding: .3em;"><?php echo $this->t('{login:organization}'); ?></td>
-			<td><select name="organization" tabindex="3">
-<?php
-if (array_key_exists('selectedOrg', $this->data)) {
-	$selectedOrg = $this->data['selectedOrg'];
-} else {
-	$selectedOrg = NULL;
-}
-
-foreach ($this->data['organizations'] as $orgId => $orgDesc) {
-	if (is_array($orgDesc)) {
-		$orgDesc = $this->t($orgDesc);
-	}
-
-	if ($orgId === $selectedOrg) {
-		$selected = 'selected="selected" ';
-	} else {
-		$selected = '';
-	}
-
-	echo '<option ' . $selected . 'value="' . htmlspecialchars($orgId) . '">' . htmlspecialchars($orgDesc) . '</option>';
-}
-?>
-			</select></td>
-		</tr>
-<?php
-}
-?>
-	<tr><td></td><td>
-	<input onclick="this.value='<?php echo $this->t('{login:processing}'); ?>';this.disabled=true;this.form.submit();return true;" type="submit" tabindex="5" id="mobilesubmit" value="<?php echo $this->t('{login:login_button}'); ?>" />
-	</td></tr>
-	</table>
-<?php
-foreach ($this->data['stateparams'] as $name => $value) {
-	echo('<input type="hidden" name="' . htmlspecialchars($name) . '" value="' . htmlspecialchars($value) . '" />');
+    echo '</ul>';
 }
-?>
-
-	</form>
-
-<?php
-
-if(!empty($this->data['links'])) {
-	echo '<ul class="links" style="margin-top: 2em">';
-	foreach($this->data['links'] AS $l) {
-		echo '<li><a href="' . htmlspecialchars($l['href']) . '">' . htmlspecialchars($this->t($l['text'])) . '</a></li>';
-	}
-	echo '</ul>';
-}
-
-
-
-
-echo('<h2 class="logintext">' . $this->t('{login:help_header}') . '</h2>');
-echo('<p class="logintext">' . $this->t('{login:help_text}') . '</p>');
+echo('<h2 class="logintext">'.$this->t('{login:help_header}').'</h2>');
+echo('<p class="logintext">'.$this->t('{login:help_text}').'</p>');
 
 $this->includeAtTemplateBase('includes/footer.php');
diff --git a/www/resources/default.css b/www/resources/default.css
index afe584df9..eb63ede29 100644
--- a/www/resources/default.css
+++ b/www/resources/default.css
@@ -170,6 +170,13 @@ h6 {
 	font-size: 96%;
 }
 
+input {
+	border: 1px solid #ddd;
+	border-radius: 3px;
+	padding: 5px;
+	line-height: 1.5em;
+}
+
 h1 a {
 	text-decoration: none;
 	border: none ! important;
@@ -402,19 +409,21 @@ caption {
 	background-color: #eee;
 	background-image: linear-gradient(#fcfcfc, #eee);
 	text-align: center;
+	padding: 5px;
+	cursor: hand;
 }
 
 .btn:hover, .btnaddonright:hover {
 	border-color: #ccc;
 	background-color: #ddd;
 	background-image: linear-gradient(#eee, #ddd);
+
 }
 
 .btn img,
 .btnaddonright img {
 	max-height: 15px;
 	max-width: 15px;
-	margin: 5px;
 }
 
 .topright {
-- 
GitLab