Enhancements to User CP - handle attribute deletion/mod more gracefully
authorDan Fuhry <dan@fuhry.us>
Sat, 16 Feb 2013 20:47:45 -0500
changeset 7 faf6f7941e8f
parent 6 3ac4e03f28b2
child 9 f4bf6556fb9f
Enhancements to User CP - handle attribute deletion/mod more gracefully
packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/includes/templates/header.tpl
packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/includes/templates/my-account.tpl
packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/index.php
packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/res/tablesorter/themes/bootstrap/asc.gif
packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/res/tablesorter/themes/bootstrap/bg.gif
packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/res/tablesorter/themes/bootstrap/desc.gif
packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/res/tablesorter/themes/bootstrap/style.css
--- a/packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/includes/templates/header.tpl	Sat Feb 16 19:02:51 2013 -0500
+++ b/packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/includes/templates/header.tpl	Sat Feb 16 20:47:45 2013 -0500
@@ -5,7 +5,7 @@
 		<title>{$title} &bull; SSO-in-a-Box Control Panel</title>
 		<link rel="stylesheet" type="text/css" href="/res/bootstrap/css/bootstrap.min.css" />
 		<link rel="stylesheet" type="text/css" href="/res/ssoinabox.css" />
-		<link rel="stylesheet" type="text/css" href="/res/tablesorter/themes/blue/style.css" />
+		<link rel="stylesheet" type="text/css" href="/res/tablesorter/themes/bootstrap/style.css" />
 		<script type="text/javascript" src="/res/jquery.min.js"></script>
 		<script type="text/javascript" src="/res/bootstrap/js/bootstrap.min.js"></script>
 		<script type="text/javascript" src="/res/tablesorter/jquery.tablesorter.js"></script>
--- a/packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/includes/templates/my-account.tpl	Sat Feb 16 19:02:51 2013 -0500
+++ b/packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/includes/templates/my-account.tpl	Sat Feb 16 20:47:45 2013 -0500
@@ -26,7 +26,7 @@
 	<div class="control-group">
 		<label class="control-label">E-mail address:</label>
 		<div class="controls">
-			<input type="text" name="mail" value="{if isset($userinfo['mail'])}{$userinfo['mail']|escape:'html'}{/if}" />
+			<input type="text" name="mail" value="{if isset($userinfo['mail'])}{$userinfo['mail'][0]|escape:'html'}{/if}" />
 			<p>Enter an e-mail address if you want to be able to use password recovery.</p>
 		</div>
 	</div>
--- a/packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/index.php	Sat Feb 16 19:02:51 2013 -0500
+++ b/packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/index.php	Sat Feb 16 20:47:45 2013 -0500
@@ -42,10 +42,36 @@
 		break;
 	case 'profile-update':
 		// header('Content-type: text/plain'); print_r(!empty($_POST['sshPublicKey']) ? $_POST['sshPublicKey'] : array()); exit;
-		$result = ldap_mod_replace($_ldapconn, ldap_make_user_dn($_SERVER['REMOTE_USER']), array(
-				'mail' => array($_POST['mail'])
-				, 'sshPublicKey' => !empty($_POST['sshPublicKey']) ? array_unique($_POST['sshPublicKey']) : array()
-			));
+		$ui = ldap_get_user($_SERVER['REMOTE_USER']);
+		
+		foreach ( array('mail', 'sshPublicKey') as $field )
+		{
+			if ( empty($_POST[$field]) && empty($ui[$field]) )
+			{
+				// both empty, do nothing
+			}
+			else if ( empty($_POST[$field]) && !empty($ui[$field]) )
+			{
+				// POST empty, database not. Delete attr.
+				$result = ldap_mod_del($_ldapconn, ldap_make_user_dn($_SERVER['REMOTE_USER']), array(
+						$field => array()
+					));
+			}
+			else if ( !empty($_POST[$field]) && empty($ui[$field]) )
+			{
+				// POST filled, database empty. Add attr.
+				$result = ldap_mod_add($_ldapconn, ldap_make_user_dn($_SERVER['REMOTE_USER']), array(
+						$field => is_array($_POST[$field]) ? array_unique($_POST[$field]) : array($_POST[$field])
+					));
+			}
+			else if ( !empty($_POST[$field]) && !empty($ui[$field]) )
+			{
+				// POST and database filled. Replace attr.
+				$result = ldap_mod_replace($_ldapconn, ldap_make_user_dn($_SERVER['REMOTE_USER']), array(
+						$field => is_array($_POST[$field]) ? array_unique($_POST[$field]) : array($_POST[$field])
+					));
+			}
+		}
 		
 		if ( $result || ldap_error($_ldapconn) === 'Success' )
 		{
Binary file packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/res/tablesorter/themes/bootstrap/asc.gif has changed
Binary file packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/res/tablesorter/themes/bootstrap/bg.gif has changed
Binary file packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/res/tablesorter/themes/bootstrap/desc.gif has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/res/tablesorter/themes/bootstrap/style.css	Sat Feb 16 20:47:45 2013 -0500
@@ -0,0 +1,14 @@
+/* tables */
+
+table.tablesorter thead tr .header {
+	background-image: url(bg.gif);
+	background-repeat: no-repeat;
+	background-position: center right;
+	cursor: pointer;
+}
+table.tablesorter thead tr .headerSortUp {
+	background-image: url(asc.gif);
+}
+table.tablesorter thead tr .headerSortDown {
+	background-image: url(desc.gif);
+}