Forgot since tag
[squirrelmail.git] / src / addressbook.php
index 42f5d2dd90c735acfd9a3ead024f623b5dc97924..a75a8f7eb470cf0e3a7194ce9407779daaefdbc9 100644 (file)
@@ -20,6 +20,9 @@ include('../include/init.php');
 /** SquirrelMail required files. */
 /* address book functions */
 require_once(SM_PATH . 'functions/addressbook.php');
+include_once(SM_PATH . 'templates/util_addressbook.php');
+include_once(SM_PATH . 'templates/util_global.php');
+
 /* form functions */
 require_once(SM_PATH . 'functions/forms.php');
 
@@ -109,14 +112,14 @@ if(sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'P
             $orig_sel = $sel;
             sort($sel);
 
-            /* The selected addresses are identidied by "backend:nickname". *
+            /* The selected addresses are identidied by "nickname_backend". *
              * Sort the list and process one backend at the time            */
             $prevback  = -1;
             $subsel    = array();
             $delfailed = false;
 
             for ($i = 0 ; (($i < sizeof($sel)) && !$delfailed) ; $i++) {
-                list($sbackend, $snick) = explode(':', $sel[$i]);
+                list($snick, $sbackend) = explode('_', $sel[$i]);
 
                 /* When we get to a new backend, process addresses in *
                  * previous one.                                      */
@@ -164,7 +167,7 @@ if(sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'P
                         $defselected = $sel;
                     } else {
                         $abortform = true;
-                        list($ebackend, $enick) = explode(':', current($sel));
+                        list($enick, $ebackend) = explode('_', current($sel));
                         $olddata = $abook->lookup($enick, $ebackend);
                         // Test if $olddata really contains anything and return an error message if it doesn't
                         if (!$olddata) {
@@ -186,14 +189,7 @@ if(sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'P
                     /* Handle error messages */
                     if (!$r) {
                         /* Display error */
-                        echo html_tag( 'table',
-                                html_tag( 'tr',
-                                    html_tag( 'td',
-                                        "\n". '<strong><font color="' . $color[2] .
-                                        '">' . _("ERROR") . ': ' . $abook->error . '</font></strong>' ."\n",
-                                        'center' )
-                                    ),
-                                'center', '', 'width="100%"' );
+                        plain_error_message( nl2br(htmlspecialchars($abook->error)));
 
                         /* Display the "new address" form again */
                         abook_create_form($form_url,'editaddr',_("Update address"),_("Update address"),$newdata);
@@ -245,27 +241,18 @@ while (list($k, $backend) = each ($abook->backends)) {
     $a['Addresses'] = array();
 
     $alist = $abook->list_addr($backend->bnum);
-    usort($alist,'alistcmp');
-    $start = 200;
-    $count = count($alist);
-    if ($start >= $count) $start = 0;
-    $alist = array_slice($alist,$start,15);
-   
-    while(list($undef,$row) = each($alist)) {
-        $contact = array (
-                            'FirstName'     => htmlspecialchars($row['firstname']),
-                            'LastName'      => htmlspecialchars($row['lastname']),
-                            'FullName'      => htmlspecialchars($row['name']),
-                            'NickName'      => htmlspecialchars($row['nickname']),
-                            'Email'         => htmlspecialchars($row['email']),
-                            'FullAddress'   => htmlspecialchars($abook->full_address($row)),
-                            'Info'          => htmlspecialchars($row['label']),
-                            'Extra'         => (isset($row['extra']) ? $row['extra'] : NULL),
-                         );
-        $a['Addresses'][] = $contact;
-    }
+
+    /* check return (array with data or boolean false) */
+    if (is_array($alist)) {
+        usort($alist,'alistcmp');
+
+        $a['Addresses'] = formatAddressList($alist);
   
-    $addresses[$backend->bnum] = $a;
+        $addresses[$backend->bnum] = $a;
+    } else {
+        // list_addr() returns boolean
+        plain_error_message(nl2br(htmlspecialchars($abook->error)));
+    }
 }