mango r169 - in trunk: . www



Author: ovitters
Date: Sat May 31 22:19:59 2008
New Revision: 169
URL: http://svn.gnome.org/viewvc/mango?rev=169&view=rev

Log:
	* www/update_user.php: Kill the tabs. They just make updating a user
	more annoying as not everything is on one page, plus you cannot switch
	between 'tabs' without saving the user.
	* www/update_user.xsl: Kill tabs in the UI as well.



Modified:
   trunk/ChangeLog
   trunk/www/update_user.php
   trunk/www/update_user.xsl

Modified: trunk/www/update_user.php
==============================================================================
--- trunk/www/update_user.php	(original)
+++ trunk/www/update_user.php	Sat May 31 22:19:59 2008
@@ -35,9 +35,6 @@
         // Groups the user belongs to that we're not responsible for
         $othergroups,
 
-        // Tab being displayed
-        $tab,
-
         // An initialisation error message
         $error;
 
@@ -52,7 +49,6 @@
 
         $this->user = $user;
         $this->othergroups = array_diff($user->groups, $AFFECTEDGROUPS);
-        $this->tab = "general";
     }
         
     function main() {
@@ -89,14 +85,9 @@
         // Security check
         if(!check_permissions($dom, $pagenode, GROUP)) return;
 
-        // Check for a change of tab
-        if(isset($_GET['tab'])) {
-            $this->tab = $_GET['tab'];
-        }
-
         // Start the page off
+        $this->error = null;
         $formnode = $pagenode->appendChild($dom->createElement("updateuser"));
-        $formnode->setAttribute("tab", $this->tab);
 
         // If posting details, attempt to add the new details
         if($_SERVER['REQUEST_METHOD'] == 'POST') {
@@ -117,6 +108,7 @@
 
     function process(&$dom, &$formnode) {   
         // Check ref (in case of multiple open pages)
+        // XXX -- For security reasons, this should be moved elsewhere!
         $uidcheck = $_POST['uidcheck'];
         if($this->user->uid != $uidcheck) {
             $user = User::fetchuser($uidcheck);
@@ -129,22 +121,19 @@
 
         // Individual tab form handlers
         $result = null;
-        $inform_changes = false;
-        if($this->tab == "general")
-            $result = $this->process_general_tab($dom, $formnode);
-        elseif($this->tab == "sshkeys") {
-            $result = $this->process_sshkeys_tab($dom, $formnode);
-            $inform_changes = true;
-        }
-        elseif($this->tab == "groups") {
-            $result = $this->process_groups_tab($dom, $formnode);
-            $inform_changes = true;
+
+        $changes = false;
+        if (!empty($_POST['updateuser'])) {
+            $changes = $this->process_general_tab($dom, $formnode);
+            $changes = $changes or $this->process_sshkeys_tab($dom, $formnode);
+            $changes = $changes or $this->process_groups_tab($dom, $formnode);
         }
-        elseif($this->tab == "actions")
-            $result = $this->process_actions_tab($dom, $formnode);
+        $changes = $changes or $this->process_actions_tab($dom, $formnode);
 
-        if ($result === true) {
+        if ($changes) {
+            error_log("have changes!!");
             $formerrors = $this->user->validate();
+
             if(count($formerrors) > 0) {
                 foreach($formerrors as $error) {
                     $node = $formnode->appendChild($dom->createElement("formerror"));
@@ -178,17 +167,26 @@
         }
     }
 
-    function process_general_tab(&$dom, &$formnode) {   
-        // Read form and validate
-        $this->user->cn = $_POST['cn'];
-        $this->user->mail = $_POST['mail'];
-        $this->user->description = $_POST['description'];
+    function process_general_tab(&$dom, &$formnode) {
+        $changes = false;
 
-        return true;
+        $attrs = array('cn', 'mail', 'description');
+
+        foreach($attrs as $var) {
+            if ($this->user->$var == $_POST[$var])
+                continue;
+
+            $this->user->$var = $_POST[$var];
+            $changes = true;
+            error_log("setting changes");
+        }
+
+        return $changes;
     }
 
     function process_sshkeys_tab(&$dom, &$formnode) {   
         // Read form and validate
+        // XXX - compare arrays to check if user changed
         $this->user->authorizedKeys = array();
         if($_FILES['keyfile']['tmp_name']) {
             $keyfile = file_get_contents($_FILES['keyfile']['tmp_name']);
@@ -235,10 +233,10 @@
 
         // Was this confirmation to send?
         if(isset($_POST['confirmemail'])) {
-            $to = stripslashes($_POST['to']);
-            $cc = stripslashes($_POST['cc']);
-            $subject = stripslashes($_POST['subject']);
-            $body = stripslashes($_POST['body']);
+            $to = $_POST['to'];
+            $cc = $_POST['cc'];
+            $subject = $_POST['subject'];
+            $body = $_POST['body'];
             if($body == "") {
                 return PEAR::raiseError("No mail body supplied");
             }
@@ -269,8 +267,10 @@
             $headers = $mime->headers($headers);
             $mail = &Mail::factory('smtp');
             $error = $mail->send($recipients, $headers, $content);
-            if(PEAR::isError($error))
-                return $error;
+            if(PEAR::isError($error)) {
+                $this->error = $error;
+                return false;
+            }
 
             // Trigger an 'e-mail sent' page
             $formnode->appendChild($dom->createElement("emailsent"));
@@ -285,7 +285,7 @@
         $subject = "";
 
         // Was an RT number supplied?
-        if(isset($_POST['rt_number'])) {
+        if(!empty($_POST['rt_number'])) {
             $rt_number = $_POST['rt_number'];
             if(intval($rt_number) > 0) {
                 $cc = "Accounts RT Queue <accounts gnome org>";
@@ -304,6 +304,8 @@
             return $this->_create_email_dom($dom, $formnode, 'authtokenmail', 'authtoken_mail',
                                             $to, $cc, $subject, array('authtoken' => $authtoken));
         }
+
+        return false;
     }
 
 

Modified: trunk/www/update_user.xsl
==============================================================================
--- trunk/www/update_user.xsl	(original)
+++ trunk/www/update_user.xsl	Sat May 31 22:19:59 2008
@@ -18,63 +18,26 @@
    <xsl:if test="boolean(.//change)">
     <xsl:apply-templates select=".//change"/>
    </xsl:if>
-   <table class="formtabs">
-    <tr>
-     <td>
-      <xsl:if test="@tab='general'">
-       <xsl:attribute name="class">selected</xsl:attribute>
-      </xsl:if>
-      <a href="{$script}?tab=general">General</a>
-     </td>
-     <td>
-      <xsl:if test="@tab='sshkeys'">
-       <xsl:attribute name="class">selected</xsl:attribute>
-      </xsl:if>
-      <a href="{$script}?tab=sshkeys">SSH Keys</a>
-     </td>
-     <td>
-      <xsl:if test="@tab='groups'">
-       <xsl:attribute name="class">selected</xsl:attribute>
-      </xsl:if>
-      <a href="{$script}?tab=groups">Groups</a>
-     </td>
-     <td>
-      <xsl:if test="@tab='actions'">
-       <xsl:attribute name="class">selected</xsl:attribute>
-      </xsl:if>
-      <a href="{$script}?tab=actions">Actions</a>
-     </td>
-    </tr>
-   </table>
    <form enctype="multipart/form-data" method="POST" action="{$script}" name="form">
     <input type="hidden" name="mango_token" value="{/page/@token}"/>
     <input type="hidden" name="uidcheck" value="{uid}"/>
-    <xsl:choose>
-     <xsl:when test="@tab='general'">
-      <xsl:call-template name="updateusergeneraltab"/>
-     </xsl:when>
-     <xsl:when test="@tab='sshkeys'">
-      <xsl:call-template name="updateusersshkeystab"/>
-     </xsl:when>
-     <xsl:when test="@tab='groups'">
-      <xsl:call-template name="updateusergroupstab"/>
-     </xsl:when>
-     <xsl:when test="@tab='actions'">
-      <xsl:call-template name="updateuseractionstab"/>
-     </xsl:when>
-     <xsl:otherwise>
-      <p class="error">Unknown tab '<xsl:value-of select="@tab"/>'.</p>
-     </xsl:otherwise>
-    </xsl:choose>
+    <table class="form">
+     <xsl:call-template name="updateusergeneral"/>
+     <xsl:call-template name="updateusersshkeys"/>
+     <xsl:call-template name="updateusergroups"/>
+    </table>
     <p>
-     <input type="submit" name="update" value="Update &gt;&gt;"/>
+     <input type="submit" name="updateuser" value="Update &gt;&gt;"/>
     </p>
    </form>
+   <form enctype="multipart/form-data" method="POST" action="{$script}" name="form">
+    <input type="hidden" name="mango_token" value="{/page/@token}"/>
+    <input type="hidden" name="uidcheck" value="{uid}"/>
+    <xsl:call-template name="updateuseractions"/>
+   </form>
   </xsl:template>
 
-  <xsl:template name="updateusergeneraltab">
-    <table class="form">
-     <caption>Update user '<xsl:value-of select="uid"/>'</caption>
+  <xsl:template name="updateusergeneral">
      <tr>
       <th>
        <xsl:if test="boolean(formerror[ type='cn'])">
@@ -105,12 +68,9 @@
        <textarea name="description" rows="5" cols="40"><xsl:value-of select="description"/></textarea>
       </td>
      </tr>
-    </table>
   </xsl:template>
 
-  <xsl:template name="updateusersshkeystab">
-    <table class="form">
-     <caption>Update user '<xsl:value-of select="uid"/>'</caption>
+  <xsl:template name="updateusersshkeys">
      <tr>
       <th>
        SSH key(s)
@@ -137,12 +97,9 @@
        <textarea name="newkeys" rows="5"><xsl:apply-templates select="newkeys"/></textarea>
       </td>
      </tr>
-    </table>
   </xsl:template>
 
-  <xsl:template name="updateusergroupstab">
-    <table class="form">
-     <caption>Update user '<xsl:value-of select="uid"/>'</caption>
+  <xsl:template name="updateusergroups">
      <tr>
       <th>
        Groups/options
@@ -250,10 +207,9 @@
        </div>
       </td>
      </tr>
-    </table>
   </xsl:template>
 
-  <xsl:template name="updateuseractionstab">
+  <xsl:template name="updateuseractions">
     <xsl:choose>
      <xsl:when test="boolean(authorisemail)">
       <xsl:call-template name="authorisemail"/>
@@ -268,15 +224,15 @@
   </xsl:template>
 
   <xsl:template name="whichaction">
-    <table class="form whichaction">
+    <table class="form">
      <tr>
-      <th colspan="2">RT3 number</th>
+      <th>RT3 number</th>
       <td>
        <input type="text" name="rt_number" value="{rt_number}"/>
       </td>
      </tr>
      <tr>
-      <td>
+      <td colspan="2">
        <p>Select an action to perform:</p>
        <ul>
         <li>
@@ -289,7 +245,6 @@
   </xsl:template>
 
   <xsl:template name="authorisemail">
-    <input type="hidden" name="confirmemail" value="yes"/>
     <table class="form">
      <tr>
       <td colspan="2">
@@ -297,19 +252,19 @@
       </td>
      </tr>
      <tr>
-      <td>To</td>
+      <th>To</th>
       <td>
        <input type="text" name="to" value="{to}" size="40"/>
       </td>
      </tr>
      <tr>
-      <td>Cc</td>
+      <th>Cc</th>
       <td>
        <input type="text" name="cc" value="{cc}" size="40"/>
       </td>
      </tr>
      <tr>
-      <td>Subject</td>
+      <th>Subject</th>
       <td>
        <input type="text" name="subject" value="{subject}" size="40"/>
       </td>
@@ -319,7 +274,11 @@
        <textarea name="body" cols="80" rows="20"><xsl:value-of select="body"/></textarea>
       </td>
      </tr>
-    </table>
+   </table>
+
+    <p>
+     <input type="submit" name="confirmemail" value="Send email &gt;&gt;"/>
+    </p>
   </xsl:template>
 
   <xsl:template name="emailsent">



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]