File: MailmanListDao.class.php

package info (click to toggle)
fusionforge 5.3.2%2B20141104-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 60,472 kB
  • sloc: php: 271,846; sql: 36,817; python: 14,575; perl: 6,406; sh: 5,980; xml: 4,294; pascal: 1,411; makefile: 911; cpp: 52; awk: 27
file content (161 lines) | stat: -rw-r--r-- 6,118 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
/**
 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
 *
 * This file is a part of Codendi.
 *
 * Codendi is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Codendi is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Codendi. If not, see <http://www.gnu.org/licenses/>.
 *
 * Portions Copyright 2010 (c) Mélanie Le Bail
 */

require_once 'common/dao/include/DataAccessObject.class.php';

/**
 *  Data Access Object for mailing lists
 */
class MailmanListDao extends DataAccessObject {

	public function __construct($da) {
		parent::__construct($da);
	}

	/**
	 * Search active (=not deteted) mailing lists
	 * return all active lists
	 * @return DataAccessResult
	 */
	function & searchAllActiveML() {
		$sql = "SELECT *
			FROM mail_group_list
			WHERE is_public IN (0,1)";
		return $this->retrieve($sql,array());
	}

	/**
	 * Searches by group_list_id
	 * @return DataAccessResult
	 */
	function & searchByGroupListId($group_list_id) {
		$group_list_id = $this->da->quoteSmart($group_list_id);
		$sql = "SELECT * FROM mail_group_list
			WHERE group_list_id = $1";
		return $this->retrieve($sql,array($group_list_id));
	}
	/**
	 * Searches by list_name
	 * @return DataAccessResult
	 */
	function & searchByName($realListName) {
		$realListName = $this->da->quoteSmart($realListName);
		$sql = 'SELECT 1 FROM mail_group_list WHERE lower(list_name)=$1';
		return $this->retrieve($sql,array($realListName));
	}
	/**
	 * Searches by group_id
	 * @return DataAccessResult
	 */
	function & searchByGroupId($group_id) {
		$group_id = $this->da->quoteSmart($group_id);
		$sql = "SELECT * FROM mail_group_list
			WHERE group_id = $1 ORDER BY group_list_id";
		return $this->retrieve($sql,array($group_id));
	}
	/**
	 * Searches data with group_list_id and group_id
	 * @return DataAccessResult
	 */
	function & searchListFromGroup($group_list_id,$group_id) {
		$group_id = $this->da->quoteSmart($group_id);
		$group_list_id = $this->da->quoteSmart($group_list_id);
		$sql = "SELECT * FROM mail_group_list
			WHERE group_id = $1 AND group_list_id=$2";
		return $this->retrieve($sql,array($group_id,$group_list_id));
	}

	function & insertNewList($group_id, $realListName,$isPublic,$listPassword,$creator_id,$requested,$description) {
		$group_id = $this->da->quoteSmart($group_id);
		$realListName = $this->da->quoteSmart($realListName);
		$isPublic = $this->da->quoteSmart($isPublic);
		$creator_id = $this->da->quoteSmart($creator_id);
		$requested = $this->da->quoteSmart($requested);
		$listPassword = $this->da->quoteSmart($listPassword);
		$description = $this->da->quoteSmart($description);
		$sql = "INSERT INTO mail_group_list (group_id, list_name, is_public, password, list_admin, status, description) VALUES ($1,$2,$3,$4,$5,$6,$7);";
		return db_insertid($this->update($sql,array($group_id, $realListName,$isPublic,$listPassword,$creator_id,$requested,$description)),'mail_group_list','group_list_id');
	}
	function  deleteList($group_id, $list_id) {
		return $this->updateList($list_id,$group_id,"deleted",9,1);
	}

	function  updateList($group_list_id,$group_id, $description, $isPublic,$status) {
		$group_id = $this->da->quoteSmart($group_id);
		$group_list_id = $this->da->quoteSmart($group_list_id);
		$isPublic = $this->da->quoteSmart($isPublic);
		$status = $this->da->quoteSmart($status);
		$description = $this->da->quoteSmart($description);
		$sql = "UPDATE mail_group_list SET is_public=$1, description=$2," .
			"status=$3 WHERE group_list_id=$4 AND group_id=$5;";
		return $this->update($sql,array($isPublic,$description,$status,$group_list_id,$group_id));

	}

	function  newSubscriber($usermail, $username, $userpasswd, $listname) {
		$usermail = $this->da->quoteSmart($usermail);
		$username = $this->da->quoteSmart($username);
		$userpasswd = $this->da->quoteSmart($userpasswd);
		$listname = $this->da->quoteSmart($listname);
		$sql="INSERT INTO plugin_mailman (address,password,name,listname) VALUES ($1,$2,$3,$4);";
		return $this->update($sql,array($usermail,$userpasswd,$username,$listname));
	}

	function  deleteSubscriber($usermail, $listname) {
		$usermail = $this->da->quoteSmart($usermail);
		$listname = $this->da->quoteSmart($listname);
		$sql="DELETE FROM  plugin_mailman WHERE listname=$1 AND address=$2;";
		return $this->update($sql,array($listname,$usermail));
	}
	function & userIsMonitoring($usermail,$listname) {
		$usermail = $this->da->quoteSmart($usermail);
		$listname = $this->da->quoteSmart($listname);
		$sql="SELECT count(*) AS count FROM plugin_mailman WHERE address=$1 AND listname=$2;";
		return $this->retrieve($sql,array($usermail,$listname));
	}

	function & listsMonitoredByUser($usermail) {
		$usermail = $this->da->quoteSmart($usermail);
		$sql="SELECT groups.group_name,groups.group_id,mail_group_list.group_list_id,mail_group_list.list_name ".
		     "FROM groups,mail_group_list,plugin_mailman ".
		     "WHERE groups.group_id=mail_group_list.group_id AND groups.status ='A' ".
		     "AND mail_group_list.list_name=plugin_mailman.listname ".
		     "AND plugin_mailman.address=$1 ORDER BY group_name DESC";

		return $this->retrieve($sql,array($usermail));
	}

	function & compareInfos($mail) {
		$mail = $this->da->quoteSmart($mail);
		$sql="SELECT password, name FROM  plugin_mailman WHERE address=$1;";
		return $this->retrieve($sql,array($mail));

	}
	function updateInfos($mail,$passwd,$name) {
		$mail = $this->da->quoteSmart($mail);
		$passwd = $this->da->quoteSmart($passwd);
		$name = $this->da->quoteSmart($name);
		$sql="UPDATE plugin_mailman SET password=$1, name=$2 WHERE address=$3;";
		return $this->update($sql,array($passwd,$name,$mail));

	}
}