3 commits - lib/api lib/client lib/locale

Aleksander Machniak machniak at kolabsys.com
Wed Mar 14 13:26:19 CET 2012


 lib/api/kolab_api_service_form_value.php |    3 
 lib/client/kolab_client_task_user.php    |  165 +++++++++++++++++++++----------
 lib/locale/en_US.php                     |   12 +-
 3 files changed, 126 insertions(+), 54 deletions(-)

New commits:
commit a38db93d5516f75d77a0f5cb432fdff148c64ce3
Merge: 36b2950 6693dda
Author: Aleksander Machniak <alec at alec.pl>
Date:   Wed Mar 14 13:25:54 2012 +0100

    Merge branch 'master' of ssh://git.kolab.org/git/kolab-wap
    
    Conflicts:
    	lib/client/kolab_client_task_user.php

diff --cc lib/client/kolab_client_task_user.php
index c8a6c2a,0013d34..9fbffa4
--- a/lib/client/kolab_client_task_user.php
+++ b/lib/client/kolab_client_task_user.php
@@@ -198,10 -198,58 +198,58 @@@ class kolab_client_task_user extends ko
          $add_mode  = empty($data['user']);
          $accttypes = array();
  
+         $result = Array();
+         $current_user_type_score = -1;
+ 
+         for ($i=0; $i < count($data['objectclass']); $i++) {
+             $data['objectclass'][$i] = strtolower($data['objectclass'][$i]);
+         }
+ 
+         $data_ocs = $data['objectclass'];
+ 
+         console("Data objectclasses (i.e. \$data_ocs): " . implode(", ", $data_ocs));
+ 
          foreach ($utypes as $idx => $elem) {
+ 
              $accttypes[$idx] = array('value' => $idx, 'content' => $elem['name']);
+ 
+             // Unless we're in add mode, detect the user type.
+             if (!$add_mode) {
+ 
+                 $ref_ocs = $elem['attributes']['fields']['objectclass'];
+ 
+                 console("Reference objectclasses (\$ref_ocs for " . $elem['key'] . "): " . implode(", ", $ref_ocs));
+ 
+                 // Eliminate the duplicates between the $data_ocs and $ref_ocs
+                 $_data_ocs = array_diff($data_ocs, $ref_ocs);
+                 $_ref_ocs = array_diff($ref_ocs, $data_ocs);
+ 
+                 console("\$data_ocs not in \$ref_ocs (" . $elem['key'] . "): " . implode(", ", $_data_ocs));
+                 console("\$ref_ocs not in \$data_ocs (" . $elem['key'] . "): " . implode(", ", $_ref_ocs));
+ 
+                 $differences = count($_data_ocs) + count($_ref_ocs);
+                 $commonalities = count($data_ocs) - $differences;
+ 
+                 console("Commonalities/differences (" . $elem['key'] . "): " . $commonalities . " / " . $differences);
+ 
+                 if ($differences > 0) {
+                     $user_type_score = ($commonalities / $differences);
+                 } else {
+                     $user_type_score = $commonalities;
+                 }
+ 
+                 console("Score for user type " . $elem['name'] . ": " . $user_type_score);
+ 
+                 if ($user_type_score > $current_user_type_score) {
+                     console("Score for user type " . $elem['name'] . " is greater than score for user type " . $current_user_type['name']);
+                     $current_user_type = $elem;
+                     $current_user_type_score = $user_type_score;
+                 }
+             }
          }
+ 
+         console("A little bird tells me we need to use user_type_name " . $current_user_type['name']);
 -
 +/*
          $fields = array(
              'personal' => array(
                  'label' => 'user.personal',


commit 36b29501c9c6a0bda7e607d99b89ab54bc812b76
Author: Aleksander Machniak <alec at alec.pl>
Date:   Wed Mar 14 13:20:18 2012 +0100

    Hide all attribute fields that are not listed in 'form_fields' or 'auto_form_fields'

diff --git a/lib/client/kolab_client_task_user.php b/lib/client/kolab_client_task_user.php
index 3fdbb66..c8a6c2a 100644
--- a/lib/client/kolab_client_task_user.php
+++ b/lib/client/kolab_client_task_user.php
@@ -201,7 +201,7 @@ class kolab_client_task_user extends kolab_client_task
         foreach ($utypes as $idx => $elem) {
             $accttypes[$idx] = array('value' => $idx, 'content' => $elem['name']);
         }
-
+/*
         $fields = array(
             'personal' => array(
                 'label' => 'user.personal',
@@ -394,10 +394,50 @@ class kolab_client_task_user extends kolab_client_task
                 ),
             ),
         );
+*/
+        // Form sections
+        $sections = array(
+            'personal' => 'user.personal',
+            'system'   => 'user.system',
+            'config'   => 'user.config',
+            'other'    => 'user.other',
+        );
+
+        // field-to-section map and fields order
+        $fields = array(
+            'givenname'     => 'personal',
+            'sn'            => 'personal',
+            'displayname'   => 'personal',
+            'cn'            => 'personal',
+            'initials'      => 'personal',
+            'title'         => 'personal',
+            'telephonenumber' => 'personal',
+            'facsimiletelephonenumber' => 'personal',
+            'o'             => 'personal',
+            'ou'            => 'personal',
+            'roomnumber'    => 'personal',
+            'street'        => 'personal',
+            'l'             => 'personal',
+            'postofficebox' => 'personal',
+            'postalcode'    => 'personal',
+            'c'             => 'personal',
+            'mail'          => 'system',
+            'uid'           => 'system',
+            'userpassword'  => 'system',
+            'userpassword2' => 'system',
+            'kolabhomeserver' => 'system',
+            'cyrususerquota' =>  'config',
+            'kolabfreebusyfuture' =>  'config',
+            'kolabinvitationpolicy' =>  'config',
+            'alias'         =>  'config',
+            'kolabdelegate' =>  'config',
+            'kolaballowsmtprecipient' => 'config',
+        );
 
         $event_fields = array();
         $auto_fields  = array();
         $form_fields  = array();
+        $_fields      = array();
 
         // Selected account type
         if (!empty($data['user_type_id'])) {
@@ -414,53 +454,65 @@ class kolab_client_task_user extends kolab_client_task
         }
 
         // Mark automatically generated fields as read-only, etc.
-        foreach ($auto_fields as $af_idx => $af) {
-            foreach ($fields as $section_idx => $section) {
-                foreach ($section['fields'] as $idx => $field) {
-                    if ($idx == $af_idx) {
-                        if (empty($field['system'])) {
-                            $fields[$section_idx]['fields'][$idx]['readonly'] = true;
-                            $fields[$section_idx]['fields'][$idx]['disabled'] = true;
-                            $fields[$section_idx]['fields'][$idx]['required'] = false;
-                        }
+        foreach ($auto_fields as $idx => $field) {
+            $_fields[$idx] = array(
+                'readonly' => true,
+                'disabled' => true,
+                'section'  => isset($fields[$idx]) ? $fields[$idx] : 'other',
+                // assume auto-generated field is of type text
+                'type'        => kolab_form::INPUT_TEXT,
+                'maxlength'   => 50,
+            );
 
-                        if (!empty($af['data'])) {
-                            foreach ($af['data'] as $afd) {
-                                $event_fields[$afd][] = $af_idx;
-                            }
-                        }
-                        break 2;
-                    }
-                }
+            if (!empty($field['data'])) {
+                 foreach ($field['data'] as $fd) {
+                     $event_fields[$fd][] = $idx;
+                 }
             }
         }
 
-        foreach ($fields as $section_idx => $section) {
-            foreach ($section['fields'] as $idx => $field) {
-                // Disable fields not allowed for specified user type
-                if (empty($field['system']) && !array_key_exists($idx, $form_fields)) {
-                    $fields[$section_idx]['fields'][$idx]['readonly'] = true;
-                    $fields[$section_idx]['fields'][$idx]['disabled'] = true;
-                    $fields[$section_idx]['fields'][$idx]['required'] = false;
-                }
+        // Other fields
+        foreach ($form_fields as $idx => $field) {
+            $_fields[$idx] = array(
+                'section'  => isset($fields[$idx]) ? $fields[$idx] : 'other',
+                'required' => true,
+            );
 
-                // Attach on-change events to some fields, to update
-                // auto-generated field values
-                if (!empty($event_fields[$idx])) {
-                    $event = json_encode(array_unique($event_fields[$idx]));
-                    $fields[$section_idx]['fields'][$idx]['onchange'] = "kadm.form_value_change($event)";
+            switch ($field['type']) {
+            case 'select':
+                $_fields[$idx]['type'] = kolab_form::INPUT_SELECT;
+                break;
+            default:
+                $_fields[$idx]['type'] = kolab_form::INPUT_TEXT;
+                if (isset($field['maxlength'])) {
+                    $_fields[$idx]['maxlength'] = $field['maxlength'];
                 }
             }
+
+            // Attach on-change events to some fields, to update
+            // auto-generated field values
+            if (!empty($event_fields[$idx])) {
+                $event = json_encode(array_unique($event_fields[$idx]));
+                $_fields[$idx]['onchange'] = "kadm.form_value_change($event)";
+            }
         }
 
-        $this->output->set_env('auto_fields', $auto_fields);
-        $this->output->set_env('form_id', $form_id);
-        $this->output->add_translation('user.password.mismatch',
-            'user.add.success', 'user.delete.success');
+        // Add user type id selector
+        $_fields['user_type_id'] = array(
+            'section'  => 'system',
+            'type'     => kolab_form::INPUT_SELECT,
+            'options'  => $accttypes,
+            'onchange' => "kadm.user_save(true, 'system')",
+        );
+
+        // Add password confirmation
+        if (isset($_fields['userpassword'])) {
+            $_fields['userpassword2'] = $_fields['userpassword'];
+        }
 
         // Hide account type selector if there's only one type
-        if (count($accttypes) < 2) {
-            $fields['system']['fields']['user_type_id'] = array(
+        if (count($accttypes) < 2 || !$add_mode) {
+            $_fields['user_type_id'] = array(
                 'type' => kolab_form::INPUT_HIDDEN,
             );
         }
@@ -483,22 +535,34 @@ class kolab_client_task_user extends kolab_client_task
 
             // remove password
             $data['userpassword'] = '';
+        }
 
-            // Remove user type selector
-            unset($fields['system']['fields']['user_type_id']);
+        // Sort
+        foreach ($fields as $idx => $val) {
+            if (array_key_exists($idx, $_fields)) {
+                $fields[$idx] = $_fields[$idx];
+                unset($_fields[$idx]);
+            }
+            else {
+                unset($fields[$idx]);
+            }
+        }
+        if (!empty($_fields)) {
+            $fields = array_merge($fields, $_fields);
         }
 
         // Parse elements and add them to the form object
-        foreach ($fields as $section_idx => $section) {
-            if (empty($section['fields'])) {
-                continue;
-            }
+        foreach ($sections as $section_idx => $section) {
+            $form->add_section($section_idx, kolab_html::escape($this->translate($section)));
 
-            $form->add_section($section_idx, kolab_html::escape($this->translate($section['label'])));
+            foreach ($fields as $idx => $field) {
+                if ($field['section'] != $section_idx) {
+                    continue;
+                }
 
-            foreach ($section['fields'] as $idx => $field) {
+                $field['label']       = kolab_html::escape($this->translate("user.$idx"));
+                $field['description'] = "user.$idx.desc";
                 $field['section']     = $section_idx;
-                $field['label']       = kolab_html::escape($this->translate($field['label']));
 
                 if (!empty($data[$idx])) {
                     if (is_array($data[$idx])) {
@@ -509,11 +573,11 @@ class kolab_client_task_user extends kolab_client_task
                         $field['value'] = kolab_html::escape($data[$idx]);
                     }
                 }
-
+/*
                 if (!empty($field['suffix'])) {
                     $field['suffix'] = kolab_html::escape($this->translate($field['suffix']));
                 }
-
+*/
                 if (!empty($field['options'])) {
                     foreach ($field['options'] as $opt_idx => $option) {
                         if (is_array($option)) {
@@ -560,6 +624,11 @@ class kolab_client_task_user extends kolab_client_task
             $form->activate_section($data['section']);
         }
 
+        $this->output->set_env('auto_fields', $auto_fields);
+        $this->output->set_env('form_id', $form_id);
+        $this->output->add_translation('user.password.mismatch',
+            'user.add.success', 'user.delete.success');
+
         return $form->output();
     }
 
diff --git a/lib/locale/en_US.php b/lib/locale/en_US.php
index 4b44c91..9697bad 100644
--- a/lib/locale/en_US.php
+++ b/lib/locale/en_US.php
@@ -41,11 +41,13 @@ $LANG['user.norecords'] = 'No user records found!';
 $LANG['user.personal'] = 'Personal';
 $LANG['user.system'] = 'System';
 $LANG['user.config'] = 'Configuration';
+$LANG['user.other'] = 'Other';
 $LANG['user.contact'] = 'Contact';
-$LANG['user.surname'] = 'Surname';
+$LANG['user.sn'] = 'Surname';
+$LANG['user.cn'] = 'Common name';
 $LANG['user.givenname'] = 'Given name';
 $LANG['user.displayname'] = 'Display name';
-$LANG['user.email'] = 'Email';
+$LANG['user.mail'] = 'Email';
 $LANG['user.initials'] = 'Middle name';
 $LANG['user.title'] = 'Title';
 $LANG['user.country'] = 'Country';
@@ -63,7 +65,7 @@ $LANG['user.quota'] = 'Quota';
 $LANG['user.quota.desc'] = 'Leave blank for unlimited';
 $LANG['user.fbinterval'] = 'Free-Busy interval';
 $LANG['user.fbinterval.desc'] = 'Leave blank for default (60 days)';
-$LANG['user.type'] = 'Account type';
+$LANG['user.user_type_id'] = 'Account type';
 $LANG['user.alias'] = 'Email aliases';
 $LANG['user.invitation-policy'] = 'Invitation policy';
 $LANG['user.delegate'] = 'Email delegates';
@@ -71,8 +73,8 @@ $LANG['user.delegate.desc'] = 'Others allowed to send emails with a "From" addre
 $LANG['user.smtp-recipients'] = 'Allowed recipients';
 $LANG['user.smtp-recipients.desc'] = 'Restricts allowed recipients of SMTP messages';
 $LANG['user.uid'] = 'Unique identity (UID)';
-$LANG['user.password'] = 'Password';
-$LANG['user.password-confirm'] = 'Confirm password';
+$LANG['user.userpassword'] = 'Password';
+$LANG['user.userpassword2'] = 'Confirm password';
 $LANG['user.password.mismatch'] = 'Passwords do not match!';
 $LANG['user.homeserver'] = 'Mailbox home server';
 $LANG['user.add.success'] = 'User created successfully.';


commit ea6745b64f13f868ef269cfa3e38ffb2f215dc48
Author: Aleksander Machniak <alec at alec.pl>
Date:   Wed Mar 14 13:19:45 2012 +0100

    Generate correct email address when sn is empty

diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index 0e481a4..2ada7a2 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -126,7 +126,8 @@ class kolab_api_service_form_value extends kolab_api_service
             $givenname = preg_replace('/[^a-z-_]/i', '', $givenname);
             $sn        = preg_replace('/[^a-z-_]/i', '', $sn);
 
-            $mail = $givenname . "." . $sn . "@" . $_SESSION['user']->get_domain();
+            $local = trim($givenname . '.' . $sn, '.');
+            $mail  = $local . '@' . $_SESSION['user']->get_domain();
 
             $orig_mail = $mail;
 





More information about the commits mailing list