/[drupal]/contributions/modules/mailserver/mailserver.mysql.inc
ViewVC logotype

Contents of /contributions/modules/mailserver/mailserver.mysql.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Wed Apr 9 19:52:22 2008 UTC (19 months, 2 weeks ago) by tbarregren
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +3 -3 lines
File MIME type: text/x-php
Minor improvements. No bugfixes.
1 <?php
2
3 /* $Id: mailserver.mysql.inc,v 1.1.2.1 2008/02/04 12:58:28 tbarregren Exp $
4 *
5 * Copyright (C) 2008 Thomas Barregren.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22
23 /**
24 * @file
25 * MySQL queries for MailServer – a Drupal module that automatically creates,
26 * updates and removes e-mail accounts for users with an e-mail domain that the
27 * module is configured to manage.
28 *
29 * Each function below must return a string that can be passed into db_query()
30 * as the query argument. The additional arguments that will be passed into
31 * db_query() are passed in an array to the function. The function may use
32 * these arguments to build the query, or alter them.
33 *
34 * Author:
35 * Thomas Barregren <http://drupal.org/user/16678>.
36 */
37
38
39 /******************************************************************************
40 * MYSQL QUERIES
41 ******************************************************************************/
42
43 function _mailserver_db_get_domains_query() {
44 return <<<SQL
45 SELECT id, name FROM {mailserver_virtual_domains}
46 SQL;
47 }
48
49 function _mailserver_db_get_domain_id_query() {
50 return <<<SQL
51 SELECT id FROM {mailserver_virtual_domains} WHERE name = '%s'
52 SQL;
53 }
54
55 function _mailserver_db_insert_domains_query(&$args) {
56 $str = mailserver_token_string(count($args), "('%s')", ',');
57 return <<<SQL
58 INSERT INTO {mailserver_virtual_domains} (name) VALUES $str
59 SQL;
60 }
61
62 function _mailserver_db_delete_domains_query(&$args) {
63 $str = mailserver_token_string(count($args), "'%s'", ',');
64 return <<<SQL
65 DELETE FROM {mailserver_virtual_domains} WHERE name IN ($str)
66 SQL;
67 }
68
69 function _mailserver_db_insert_users_query($args) {
70 $str = mailserver_token_string(count($args), '%s', '|');
71 return <<<SQL
72 INSERT INTO mailserver_virtual_users (id, domain_id, user, password)
73 SELECT u.uid, d.id, SUBSTRING_INDEX(mail,'@',1), u.pass
74 FROM users AS u
75 INNER JOIN mailserver_virtual_domains AS d
76 ON SUBSTRING_INDEX(u.mail,'@',-1) = d.name
77 WHERE mail REGEXP '.+@($str)'
78 SQL;
79 }
80
81 function _mailserver_db_insert_user_query() {
82 return <<<SQL
83 INSERT INTO {mailserver_virtual_users} (id, domain_id, user, password) VALUES (%d, %d, '%s', MD5('%s'))
84 SQL;
85 }
86
87 function _mailserver_db_delete_user_query() {
88 return <<<SQL
89 DELETE FROM {mailserver_virtual_users} WHERE id = %d
90 SQL;
91 }
92
93 function _mailserver_db_update_user_query() {
94 return <<<SQL
95 UPDATE {mailserver_virtual_users} SET password = MD5('%s') WHERE id = %d
96 SQL;
97 }
98

  ViewVC Help
Powered by ViewVC 1.1.2