[Svn] r5182 - in trunk/roundcubemail: . SQL config program/include program/js program/localization/en_US program/steps/addressbook skins/default skins/default/images/icons skins/default/includes skins/default/templates

trac at roundcube.net trac at roundcube.net
Tue Sep 6 18:35:14 CEST 2011


Author: alec
Date: 2011-09-06 11:35:14 -0500 (Tue, 06 Sep 2011)
New Revision: 5182

Modified:
   trunk/roundcubemail/
   trunk/roundcubemail/CHANGELOG
   trunk/roundcubemail/SQL/mssql.initial.sql
   trunk/roundcubemail/SQL/mssql.upgrade.sql
   trunk/roundcubemail/SQL/mysql.initial.sql
   trunk/roundcubemail/SQL/mysql.update.sql
   trunk/roundcubemail/SQL/postgres.initial.sql
   trunk/roundcubemail/SQL/postgres.update.sql
   trunk/roundcubemail/SQL/sqlite.initial.sql
   trunk/roundcubemail/SQL/sqlite.update.sql
   trunk/roundcubemail/config/db.inc.php.dist
   trunk/roundcubemail/program/include/rcube_user.php
   trunk/roundcubemail/program/js/app.js
   trunk/roundcubemail/program/localization/en_US/labels.inc
   trunk/roundcubemail/program/localization/en_US/messages.inc
   trunk/roundcubemail/program/steps/addressbook/func.inc
   trunk/roundcubemail/program/steps/addressbook/search.inc
   trunk/roundcubemail/skins/default/addressbook.css
   trunk/roundcubemail/skins/default/images/icons/folders.gif
   trunk/roundcubemail/skins/default/images/icons/folders.png
   trunk/roundcubemail/skins/default/includes/messagetoolbar.html
   trunk/roundcubemail/skins/default/templates/addressbook.html
Log:
- Merge devel-saved_search branch (Addressbook Saved Searches)



Property changes on: trunk/roundcubemail
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/devel-addressbook:4193-4422
/branches/devel-spellcheck/roundcubemail:5133-5180
/branches/devel-threads:3067-3364
   + /branches/devel-addressbook:4193-4422
/branches/devel-saved-search/roundcubemail:5070-5181
/branches/devel-spellcheck/roundcubemail:5133-5180
/branches/devel-threads:3067-3364

Modified: trunk/roundcubemail/CHANGELOG
===================================================================
--- trunk/roundcubemail/CHANGELOG	2011-09-06 13:39:45 UTC (rev 5181)
+++ trunk/roundcubemail/CHANGELOG	2011-09-06 16:35:14 UTC (rev 5182)
@@ -1,6 +1,7 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Addressbook Saved Searches
 - Added spellchecker exceptions dictionary (shared or per-user)
 - Added possibility to ignore words containing caps, numbers, symbols (spellcheck_ignore_* options)
 

Modified: trunk/roundcubemail/SQL/mssql.initial.sql
===================================================================
--- trunk/roundcubemail/SQL/mssql.initial.sql	2011-09-06 13:39:45 UTC (rev 5181)
+++ trunk/roundcubemail/SQL/mssql.initial.sql	2011-09-06 16:35:14 UTC (rev 5182)
@@ -100,6 +100,15 @@
 ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
 GO
 
+CREATE TABLE [dbo].[searches] (
+	[search_id] [int] IDENTITY (1, 1) NOT NULL ,
+	[user_id] [int] NOT NULL ,
+	[type] [tinyint] NOT NULL ,
+	[name] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
+	[data] [text] COLLATE Latin1_General_CI_AI NOT NULL 
+) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
+GO
+
 ALTER TABLE [dbo].[cache] WITH NOCHECK ADD 
 	 PRIMARY KEY  CLUSTERED 
 	(
@@ -156,6 +165,13 @@
 	)  ON [PRIMARY] 
 GO
 
+ALTER TABLE [dbo].[searches] WITH NOCHECK ADD 
+	CONSTRAINT [PK_searches_search_id] PRIMARY KEY CLUSTERED 
+	(
+		[search_id]
+	) ON [PRIMARY] 
+GO
+
 ALTER TABLE [dbo].[cache] ADD 
 	CONSTRAINT [DF_cache_user_id] DEFAULT ('0') FOR [user_id],
 	CONSTRAINT [DF_cache_cache_key] DEFAULT ('') FOR [cache_key],
@@ -274,6 +290,14 @@
 CREATE  UNIQUE INDEX [IX_dictionary_user_language] ON [dbo].[dictionary]([user_id],[language]) ON [PRIMARY]
 GO
 
+ALTER TABLE [dbo].[searches] ADD 
+	CONSTRAINT [DF_searches_user] DEFAULT (0) FOR [user_id],
+	CONSTRAINT [DF_searches_type] DEFAULT (0) FOR [type],
+GO
+
+CREATE UNIQUE INDEX [IX_searches_user_type_name] ON [dbo].[searches]([user_id],[type],[name]) ON [PRIMARY]
+GO
+
 ALTER TABLE [dbo].[identities] ADD CONSTRAINT [FK_identities_user_id] 
     FOREIGN KEY ([user_id]) REFERENCES [dbo].[users] ([user_id])
     ON DELETE CASCADE ON UPDATE CASCADE
@@ -304,6 +328,11 @@
     ON DELETE CASCADE ON UPDATE CASCADE
 GO
 
+ALTER TABLE [dbo].[searches] ADD CONSTRAINT [FK_searches_user_id]
+    FOREIGN KEY ([user_id]) REFERENCES [dbo].[users] ([user_id])
+    ON DELETE CASCADE ON UPDATE CASCADE
+GO
+
 -- Use trigger instead of foreign key (#1487112)
 -- "Introducing FOREIGN KEY constraint ... may cause cycles or multiple cascade paths."
 CREATE TRIGGER [contact_delete_member] ON [dbo].[contacts]

Modified: trunk/roundcubemail/SQL/mssql.upgrade.sql
===================================================================
--- trunk/roundcubemail/SQL/mssql.upgrade.sql	2011-09-06 13:39:45 UTC (rev 5181)
+++ trunk/roundcubemail/SQL/mssql.upgrade.sql	2011-09-06 16:35:14 UTC (rev 5182)
@@ -121,3 +121,33 @@
 GO
 CREATE  UNIQUE INDEX [IX_dictionary_user_language] ON [dbo].[dictionary]([user_id],[language]) ON [PRIMARY]
 GO
+
+CREATE TABLE [dbo].[searches] (
+	[search_id] [int] IDENTITY (1, 1) NOT NULL ,
+	[user_id] [int] NOT NULL ,
+	[type] [tinyint] NOT NULL ,
+	[name] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
+	[data] [text] COLLATE Latin1_General_CI_AI NOT NULL 
+) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
+GO
+
+ALTER TABLE [dbo].[searches] WITH NOCHECK ADD 
+	CONSTRAINT [PK_searches_search_id] PRIMARY KEY CLUSTERED 
+	(
+		[search_id]
+	) ON [PRIMARY] 
+GO
+
+ALTER TABLE [dbo].[searches] ADD 
+	CONSTRAINT [DF_searches_user] DEFAULT (0) FOR [user_id],
+	CONSTRAINT [DF_searches_type] DEFAULT (0) FOR [type],
+GO
+
+CREATE UNIQUE INDEX [IX_searches_user_type_name] ON [dbo].[searches]([user_id],[type],[name]) ON [PRIMARY]
+GO
+
+ALTER TABLE [dbo].[searches] ADD CONSTRAINT [FK_searches_user_id]
+    FOREIGN KEY ([user_id]) REFERENCES [dbo].[users] ([user_id])
+    ON DELETE CASCADE ON UPDATE CASCADE
+GO
+

Modified: trunk/roundcubemail/SQL/mysql.initial.sql
===================================================================
--- trunk/roundcubemail/SQL/mysql.initial.sql	2011-09-06 13:39:45 UTC (rev 5181)
+++ trunk/roundcubemail/SQL/mysql.initial.sql	2011-09-06 16:35:14 UTC (rev 5182)
@@ -155,4 +155,20 @@
   UNIQUE `uniqueness` (`user_id`, `language`)
 ) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
 
+
+-- Table structure for table `searches`
+
+CREATE TABLE `searches` (
+ `search_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ `user_id` int(10) UNSIGNED NOT NULL DEFAULT '0',
+ `type` int(3) NOT NULL DEFAULT '0',
+ `name` varchar(128) NOT NULL,
+ `data` text,
+ PRIMARY KEY(`search_id`),
+ CONSTRAINT `user_id_fk_searches` FOREIGN KEY (`user_id`)
+   REFERENCES `users`(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ UNIQUE `uniqueness` (`user_id`, `type`, `name`)
+) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
+
+
 /*!40014 SET FOREIGN_KEY_CHECKS=1 */;

Modified: trunk/roundcubemail/SQL/mysql.update.sql
===================================================================
--- trunk/roundcubemail/SQL/mysql.update.sql	2011-09-06 13:39:45 UTC (rev 5181)
+++ trunk/roundcubemail/SQL/mysql.update.sql	2011-09-06 16:35:14 UTC (rev 5182)
@@ -155,3 +155,15 @@
     REFERENCES `users`(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE,
   UNIQUE `uniqueness` (`user_id`, `language`)
 ) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
+
+CREATE TABLE `searches` (
+  `search_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+  `user_id` int(10) UNSIGNED NOT NULL DEFAULT '0',
+  `type` int(3) NOT NULL DEFAULT '0',
+  `name` varchar(128) NOT NULL,
+  `data` text,
+  PRIMARY KEY(`search_id`),
+  CONSTRAINT `user_id_fk_searches` FOREIGN KEY (`user_id`)
+    REFERENCES `users`(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE,
+  UNIQUE `uniqueness` (`user_id`, `type`, `name`)
+) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;

Modified: trunk/roundcubemail/SQL/postgres.initial.sql
===================================================================
--- trunk/roundcubemail/SQL/postgres.initial.sql	2011-09-06 13:39:45 UTC (rev 5181)
+++ trunk/roundcubemail/SQL/postgres.initial.sql	2011-09-06 16:35:14 UTC (rev 5182)
@@ -238,3 +238,29 @@
     data text NOT NULL,
     CONSTRAINT dictionary_user_id_language_key UNIQUE (user_id, "language")
 );
+
+--
+-- Sequence "searches_ids"
+-- Name: searches_ids; Type: SEQUENCE; Schema: public; Owner: postgres
+--
+
+CREATE SEQUENCE search_ids
+    INCREMENT BY 1
+    NO MAXVALUE
+    NO MINVALUE
+    CACHE 1;
+
+--
+-- Table "searches"
+-- Name: searches; Type: TABLE; Schema: public; Owner: postgres
+--
+
+CREATE TABLE searches (
+    search_id integer DEFAULT nextval('search_ids'::text) PRIMARY KEY,
+    user_id integer NOT NULL
+        REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
+    "type" smallint DEFAULT 0 NOT NULL,
+    name varchar(128) NOT NULL,
+    data text NOT NULL,
+    CONSTRAINT searches_user_id_key UNIQUE (user_id, "type", name)
+);

Modified: trunk/roundcubemail/SQL/postgres.update.sql
===================================================================
--- trunk/roundcubemail/SQL/postgres.update.sql	2011-09-06 13:39:45 UTC (rev 5181)
+++ trunk/roundcubemail/SQL/postgres.update.sql	2011-09-06 16:35:14 UTC (rev 5182)
@@ -110,3 +110,19 @@
     data text NOT NULL,
     CONSTRAINT dictionary_user_id_language_key UNIQUE (user_id, "language")
 );
+
+CREATE SEQUENCE search_ids
+    INCREMENT BY 1
+    NO MAXVALUE
+    NO MINVALUE
+    CACHE 1;
+
+CREATE TABLE searches (
+    search_id integer DEFAULT nextval('search_ids'::text) PRIMARY KEY,
+    user_id integer NOT NULL
+        REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
+    "type" smallint DEFAULT 0 NOT NULL,
+    name varchar(128) NOT NULL,
+    data text NOT NULL,
+    CONSTRAINT searches_user_id_key UNIQUE (user_id, "type", name)
+);

Modified: trunk/roundcubemail/SQL/sqlite.initial.sql
===================================================================
--- trunk/roundcubemail/SQL/sqlite.initial.sql	2011-09-06 13:39:45 UTC (rev 5181)
+++ trunk/roundcubemail/SQL/sqlite.initial.sql	2011-09-06 16:35:14 UTC (rev 5182)
@@ -161,3 +161,18 @@
 
 CREATE UNIQUE INDEX ix_dictionary_user_language ON dictionary (user_id, "language");
 
+-- --------------------------------------------------------
+
+--
+-- Table structure for table searches
+--
+
+CREATE TABLE searches (
+  search_id integer NOT NULL PRIMARY KEY,
+  user_id integer NOT NULL DEFAULT '0',
+  "type" smallint NOT NULL DEFAULT '0',
+  name varchar(128) NOT NULL,
+  data text NOT NULL
+);
+
+CREATE UNIQUE INDEX ix_searches_user_type_name (user_id, type, name);

Modified: trunk/roundcubemail/SQL/sqlite.update.sql
===================================================================
--- trunk/roundcubemail/SQL/sqlite.update.sql	2011-09-06 13:39:45 UTC (rev 5181)
+++ trunk/roundcubemail/SQL/sqlite.update.sql	2011-09-06 16:35:14 UTC (rev 5182)
@@ -227,6 +227,7 @@
 DELETE FROM cache;
 CREATE INDEX ix_contactgroupmembers_contact_id ON contactgroupmembers (contact_id);
 
+
 -- Updates from version 0.6-stable
 
 CREATE TABLE dictionary (
@@ -236,3 +237,13 @@
 );
 
 CREATE UNIQUE INDEX ix_dictionary_user_language ON dictionary (user_id, "language");
+
+CREATE TABLE searches (
+  search_id integer NOT NULL PRIMARY KEY,
+  user_id integer NOT NULL DEFAULT '0',
+  "type" smallint NOT NULL DEFAULT '0',
+  name varchar(128) NOT NULL,
+  data text NOT NULL
+);
+
+CREATE UNIQUE INDEX ix_searches_user_type_name (user_id, type, name);

Modified: trunk/roundcubemail/config/db.inc.php.dist
===================================================================
--- trunk/roundcubemail/config/db.inc.php.dist	2011-09-06 13:39:45 UTC (rev 5181)
+++ trunk/roundcubemail/config/db.inc.php.dist	2011-09-06 16:35:14 UTC (rev 5182)
@@ -68,6 +68,8 @@
 
 $rcmail_config['db_sequence_messages'] = 'message_ids';
 
+$rcmail_config['db_sequence_searches'] = 'search_ids';
 
+
 // end db config file
 

Modified: trunk/roundcubemail/program/include/rcube_user.php
===================================================================
--- trunk/roundcubemail/program/include/rcube_user.php	2011-09-06 13:39:45 UTC (rev 5181)
+++ trunk/roundcubemail/program/include/rcube_user.php	2011-09-06 16:35:14 UTC (rev 5182)
@@ -47,6 +47,8 @@
      */
     private $rc;
 
+    const SEARCH_ADDRESSBOOK = 1;
+    const SEARCH_MAIL = 2;
 
     /**
      * Object constructor
@@ -551,4 +553,129 @@
         return empty($plugin['email']) ? NULL : $plugin['email'];
     }
 
+
+    /**
+     * Return a list of saved searches linked with this user
+     *
+     * @param int  $type  Search type
+     *
+     * @return array List of saved searches indexed by search ID
+     */
+    function list_searches($type)
+    {
+        $plugin = $this->rc->plugins->exec_hook('saved_search_list', array('type' => $type));
+
+        if ($plugin['abort']) {
+            return (array) $plugin['result'];
+        }
+
+        $result = array();
+
+        $sql_result = $this->db->query(
+            "SELECT search_id AS id, ".$this->db->quoteIdentifier('name')
+            ." FROM ".get_table_name('searches')
+            ." WHERE user_id = ?"
+                ." AND ".$this->db->quoteIdentifier('type')." = ?"
+            ." ORDER BY ".$this->db->quoteIdentifier('name'),
+            (int) $this->ID, (int) $type);
+
+        while ($sql_arr = $this->db->fetch_assoc($sql_result)) {
+            $sql_arr['data'] = unserialize($sql_arr['data']);
+            $result[$sql_arr['id']] = $sql_arr;
+        }
+
+        return $result;
+    }
+
+
+    /**
+     * Return saved search data.
+     *
+     * @param int  $id  Row identifier
+     *
+     * @return array Data
+     */
+    function get_search($id)
+    {
+        $plugin = $this->rc->plugins->exec_hook('saved_search_get', array('id' => $id));
+
+        if ($plugin['abort']) {
+            return $plugin['result'];
+        }
+
+        $sql_result = $this->db->query(
+            "SELECT ".$this->db->quoteIdentifier('name')
+                .", ".$this->d