From 4cf42fde05ff891f6961ba60dbb1c2e4c91c39c6 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Tue, 20 Mar 2012 18:47:24 -0400
Subject: [PATCH] Add support for read-only address book records

---
 program/steps/addressbook/edit.inc   |    4 ++--
 program/include/rcube_imap.php       |    8 ++++----
 program/steps/addressbook/func.inc   |    8 ++++++--
 program/steps/addressbook/show.inc   |    1 +
 program/steps/mail/list_contacts.inc |    6 +++---
 skins/larry/addressbook.css          |    4 ++++
 program/js/app.js                    |    4 ++--
 7 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index 7038d24..bd8f351 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -1346,21 +1346,21 @@
      *
      * @return rcube_result_index  Search result (UIDs)
      */
-    public function search_once($mailbox = null, $str = 'ALL')
+    public function search_once($folder = null, $str = 'ALL')
     {
         if (!$str) {
             return 'ALL';
         }
 
-        if (!strlen($mailbox)) {
-            $mailbox = $this->mailbox;
+        if (!strlen($folder)) {
+            $folder = $this->folder;
         }
 
         if (!$this->check_connection()) {
             return new rcube_result_index();
         }
 
-        $index = $this->conn->search($mailbox, $str, true);
+        $index = $this->conn->search($folder, $str, true);
 
         return $index;
     }
diff --git a/program/js/app.js b/program/js/app.js
index 94e48a8..53a67c7 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -4229,7 +4229,7 @@
   };
 
   // add row to contacts list
-  this.add_contact_row = function(cid, cols, select)
+  this.add_contact_row = function(cid, cols, classes)
   {
     if (!this.gui_objects.contactslist)
       return false;
@@ -4238,7 +4238,7 @@
       row = document.createElement('tr');
 
     row.id = 'rcmrow'+this.html_identifier(cid);
-    row.className = 'contact';
+    row.className = 'contact ' + (classes || '');
 
     if (list.in_selection(cid))
       row.className += ' selected';
diff --git a/program/steps/addressbook/edit.inc b/program/steps/addressbook/edit.inc
index 5f8a4ec..abed2c5 100644
--- a/program/steps/addressbook/edit.inc
+++ b/program/steps/addressbook/edit.inc
@@ -36,8 +36,8 @@
         $OUTPUT->set_env('cid', $record['ID']);
     }
 
-    // adding not allowed here
-    if ($CONTACTS->readonly) {
+    // editing not allowed here
+    if ($CONTACTS->readonly || $record['readonly']) {
         $OUTPUT->show_message('sourceisreadonly');
         rcmail_overwrite_action('show');
         return;
diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc
index 5a7213c..eb8a0e5 100644
--- a/program/steps/addressbook/func.inc
+++ b/program/steps/addressbook/func.inc
@@ -5,7 +5,7 @@
  | program/steps/addressbook/func.inc                                    |
  |                                                                       |
  | This file is part of the Roundcube Webmail client                     |
- | Copyright (C) 2005-2007, The Roundcube Dev Team                       |
+ | Copyright (C) 2005-2012, The Roundcube Dev Team                       |
  |                                                                       |
  | Licensed under the GNU General Public License version 3 or            |
  | any later version with exceptions for skins & plugins.                |
@@ -339,6 +339,7 @@
 
     while ($row = $result->next()) {
         $a_row_cols = array();
+        $classes = array('person');  // org records will follow some day
 
         // build contact ID with source ID
         if (isset($row['sourceid'])) {
@@ -351,7 +352,10 @@
             $a_row_cols[$col] = Q($val);
         }
 
-        $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols);
+        if ($row['readonly'])
+            $classes[] = 'readonly';
+
+        $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols, join(' ', $classes));
     }
 }
 
diff --git a/program/steps/addressbook/show.inc b/program/steps/addressbook/show.inc
index 5086a7b..bf65beb 100644
--- a/program/steps/addressbook/show.inc
+++ b/program/steps/addressbook/show.inc
@@ -33,6 +33,7 @@
 
 // read contact record
 if ($cid && ($record = $CONTACTS->get_record($cid, true))) {
+    $OUTPUT->set_env('readonly', $CONTACTS->readonly || $record['readonly']);
     $OUTPUT->set_env('cid', $record['ID']);
 }
 
diff --git a/program/steps/mail/list_contacts.inc b/program/steps/mail/list_contacts.inc
index eb425d2..6954e11 100644
--- a/program/steps/mail/list_contacts.inc
+++ b/program/steps/mail/list_contacts.inc
@@ -45,7 +45,7 @@
                     $row_id = 'G'.$group['ID'];
                     $jsresult[$row_id] = format_email_recipient($email, $group['name']);
                     $OUTPUT->command('add_contact_row', $row_id, array(
-                        'contactgroup' => html::span(array('title' => $email), Q($group['name']))));
+                        'contactgroup' => html::span(array('title' => $email), Q($group['name']))), 'group');
                 }
             }
             // show group with count
@@ -53,7 +53,7 @@
                 $row_id = 'E'.$group['ID'];
                 $jsresult[$row_id] = $group['name'];
                 $OUTPUT->command('add_contact_row', $row_id, array(
-                    'contactgroup' => Q($group['name'] . ' (' . intval($result->count) . ')')));
+                    'contactgroup' => Q($group['name'] . ' (' . intval($result->count) . ')')), 'group');
             }
         }
     }
@@ -75,7 +75,7 @@
                 $row_id = $row['ID'].$i;
                 $jsresult[$row_id] = format_email_recipient($email, $name);
                 $OUTPUT->command('add_contact_row', $row_id, array(
-                    'contact' => html::span(array('title' => $email), Q($name ? $name : $email))));
+                    'contact' => html::span(array('title' => $email), Q($name ? $name : $email))), 'person');
             }
         }
     }
diff --git a/skins/larry/addressbook.css b/skins/larry/addressbook.css
index c754b91..4ad6d34 100644
--- a/skins/larry/addressbook.css
+++ b/skins/larry/addressbook.css
@@ -73,6 +73,10 @@
 	text-overflow: ellipsis;
 }
 
+#contacts-table .contact.readonly td {
+	font-style: italic;
+}
+
 #directorylist li.addressbook a {
 	background-position: 6px -766px;
 }

--
Gitblit v1.9.1