ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAddressbook.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
35 {
41  var $ilias;
42 
48  var $lng;
49 
55  var $user_id;
56 
63 
69  function ilAddressbook($a_user_id = 0)
70  {
71  global $ilias,$lng;
72 
73  $this->ilias = &$ilias;
74  $this->lng = &$lng;
75  $this->user_id = $a_user_id;
76 
77  $this->table_addr = 'addressbook';
78  }
85  function searchUsers($a_query_str)
86  {
87  if($a_query_str)
88  {
89  $query = "SELECT * FROM $this->table_addr ".
90  "WHERE (login LIKE '%".addslashes($a_query_str)."%' ".
91  "OR firstname LIKE '%".addslashes($a_query_str)."%' ".
92  "OR lastname LIKE '%".addslashes($a_query_str)."%' ".
93  "OR email LIKE '%".addslashes($a_query_str)."%') ".
94  "AND user_id = '".$this->user_id."'";
95  }
96  else
97  {
98  $query = "SELECT * FROM $this->table_addr ".
99  "WHERE user_id = '".$this->user_id."'";
100  }
101  $res = $this->ilias->db->query($query);
102  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
103  {
104  $entries[] = array(
105  "login" => ($row->login),
106  "firstname" => ($row->firstname),
107  "lastname" => ($row->lastname),
108  "email" => ($row->email));
109  }
110  return $entries ? $entries : array();
111  }
121  function addEntry($a_login,$a_firstname,$a_lastname,$a_email)
122  {
123  global $ilDB;
124 
125  $query = "INSERT INTO $this->table_addr ".
126  "SET user_id = ".$ilDB->quote($this->user_id).",".
127  "login = ".$ilDB->quote($a_login).",".
128  "firstname = ".$ilDB->quote($a_firstname).",".
129  "lastname = ".$ilDB->quote($a_lastname).",".
130  "email = ".$ilDB->quote($a_email)."";
131 
132  $res = $this->ilias->db->query($query);
133 
134  return true;
135  }
136 
147  function updateEntry($a_addr_id,$a_login,$a_firstname,$a_lastname,$a_email)
148  {
149  global $ilDB;
150 
151  $query = "UPDATE $this->table_addr ".
152  "SET login = ".$ilDB->quote($a_login).",".
153  "firstname = ".$ilDB->quote($a_firstname).",".
154  "lastname = ".$ilDB->quote($a_lastname).",".
155  "email = ".$ilDB->quote($a_email)." ".
156  "WHERE user_id = ".$ilDB->quote($this->user_id)." ".
157  "AND addr_id = ".$ilDB->quote($a_addr_id)."";
158 
159  $res = $this->ilias->db->query($query);
160 
161  return true;
162  }
163 
169  function getEntries()
170  {
171  global $ilDB;
172 
173  $query = "SELECT * FROM $this->table_addr ".
174  "WHERE user_id = ".$ilDB->quote($this->user_id)." ";
175 
176  if (trim($this->getSearchQuery()) != '')
177  {
178  $query .= " AND (login LIKE '%".addslashes(trim($this->getSearchQuery()))."%' ".
179  "OR firstname LIKE '%".addslashes(trim($this->getSearchQuery()))."%' ".
180  "OR lastname LIKE '%".addslashes(trim($this->getSearchQuery()))."%' ".
181  "OR email LIKE '%".addslashes(trim($this->getSearchQuery()))."%') ";
182  }
183 
184  $query .= " ORDER BY login,lastname";
185 
186  $res = $this->ilias->db->query($query);
187  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
188  {
189  $entries[] = array(
190  "addr_id" => $row->addr_id,
191  "login" => ($row->login),
192  "firstname" => ($row->firstname),
193  "lastname" => ($row->lastname),
194  "email" => ($row->email));
195  }
196  return $entries ? $entries : array();
197  }
204  function getEntry($a_addr_id)
205  {
206  global $ilDB;
207 
208  $query = "SELECT * FROM $this->table_addr ".
209  "WHERE user_id = ".$ilDB->quote($this->user_id)." ".
210  "AND addr_id = ".$ilDB->quote($a_addr_id)." ";
211 
212  $row = $this->ilias->db->getRow($query,DB_FETCHMODE_OBJECT);
213 
214  return array(
215  "addr_id" => $row->addr_id,
216  "login" => ($row->login),
217  "firstname" => ($row->firstname),
218  "lastname" => ($row->lastname),
219  "email" => ($row->email));
220  }
221 
228  function deleteEntries($a_entries)
229  {
230  if(is_array($a_entries))
231  {
232  foreach($a_entries as $entry)
233  {
234  $this->deleteEntry($entry);
235  }
236  }
237  return true;
238  }
245  function deleteEntry($a_addr_id)
246  {
247  global $ilDB;
248 
249  $query = "DELETE FROM addressbook_mailing_lists_assignments ".
250  "WHERE addr_id = ".$ilDB->quote($a_addr_id)." ";
251  $this->ilias->db->query($query);
252 
253  $query = "DELETE FROM $this->table_addr ".
254  "WHERE user_id = ".$ilDB->quote($this->user_id)." ".
255  "AND addr_id = ".$ilDB->quote($a_addr_id)." ";
256  $res = $this->ilias->db->query($query);
257 
258  return true;
259  }
260 
267  function checkEntry($a_login)
268  {
269  global $ilDB;
270 
271  if ($a_login != '')
272  {
273  $query = $ilDB->prepare("SELECT addr_id FROM ".$this->table_addr." WHERE user_id = ? AND login = ?",
274  array('integer', 'text'));
275 
276  $result = $ilDB->execute($query, array($this->user_id, $a_login));
277  while($record = $ilDB->fetchAssoc($result))
278  {
279  return $record['addr_id'];
280  }
281  }
282 
283  return 0;
284  }
285 
286  /* Check whether an entry with a given login name already exists */
287  function checkEntryByLogin($a_login)
288  {
289  global $ilDB;
290 
291  if ($a_login != "")
292  {
293  $query = $ilDB->prepare("SELECT addr_id FROM ".$this->table_addr." WHERE user_id = ? AND login = ?",
294  array('integer', 'text'));
295 
296  $result = $ilDB->execute($query, array($this->user_id, $a_login));
297  while($record = $ilDB->fetchAssoc($result))
298  {
299  return $record['addr_id'];
300  }
301  }
302 
303  return 0;
304  }
305 
306  public function setSearchQuery($search_query = '')
307  {
308  $this->search_query = $search_query;
309  }
310  public function getSearchQuery()
311  {
312  return $this->search_query;
313  }
314 }
315 ?>