• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/Mail/classes/class.ilAddressbook.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00034 class ilAddressbook
00035 {
00041         var $ilias;
00042 
00048         var $lng;
00049 
00055         var $user_id;
00056 
00062         var $table_addr;
00063 
00069         function ilAddressbook($a_user_id = 0)
00070         {
00071                 global $ilias,$lng;
00072 
00073                 $this->ilias = &$ilias;
00074                 $this->lng = &$lng;
00075                 $this->user_id = $a_user_id;
00076 
00077                 $this->table_addr = 'addressbook';
00078         }
00085         function searchUsers($a_query_str)
00086         {
00087                 if($a_query_str)
00088                 {
00089                         $query = "SELECT * FROM $this->table_addr ".
00090                                 "WHERE (login LIKE '%".addslashes($a_query_str)."%' ".
00091                                 "OR firstname LIKE '%".addslashes($a_query_str)."%' ".
00092                                 "OR lastname LIKE '%".addslashes($a_query_str)."%' ".
00093                                 "OR email LIKE '%".addslashes($a_query_str)."%') ".
00094                                 "AND user_id = '".$this->user_id."'";
00095                 }
00096                 else
00097                 {
00098                         $query = "SELECT * FROM $this->table_addr ".
00099                                 "WHERE user_id = '".$this->user_id."'";
00100                 }
00101                 $res = $this->ilias->db->query($query);
00102                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00103                 {
00104                         $entries[] = array(
00105                                 "login"      => ($row->login),
00106                                 "firstname"  => ($row->firstname),
00107                                 "lastname"   => ($row->lastname),
00108                                 "email"      => ($row->email));
00109                 }
00110                 return $entries ? $entries : array();
00111         }
00121         function addEntry($a_login,$a_firstname,$a_lastname,$a_email)
00122         {
00123                 global $ilDB;
00124                 
00125                 $query = "INSERT INTO $this->table_addr ".
00126                         "SET user_id = ".$ilDB->quote($this->user_id).",".
00127                         "login = ".$ilDB->quote($a_login).",".
00128                         "firstname = ".$ilDB->quote($a_firstname).",".
00129                         "lastname = ".$ilDB->quote($a_lastname).",".
00130                         "email = ".$ilDB->quote($a_email)."";
00131 
00132                 $res = $this->ilias->db->query($query);
00133 
00134                 return true;
00135         }
00136 
00147         function updateEntry($a_addr_id,$a_login,$a_firstname,$a_lastname,$a_email)
00148         {
00149                 global $ilDB;
00150                 
00151                 $query = "UPDATE $this->table_addr ".
00152                         "SET login = ".$ilDB->quote($a_login).",".
00153                         "firstname = ".$ilDB->quote($a_firstname).",".
00154                         "lastname = ".$ilDB->quote($a_lastname).",".
00155                         "email = ".$ilDB->quote($a_email)." ".
00156                         "WHERE user_id = ".$ilDB->quote($this->user_id)." ".
00157                         "AND addr_id = ".$ilDB->quote($a_addr_id)."";
00158 
00159                 $res = $this->ilias->db->query($query);
00160 
00161                 return true;
00162         }
00163 
00169         function getEntries()
00170         {
00171                 global $ilDB;
00172                 
00173                 $query = "SELECT * FROM $this->table_addr ".
00174                         "WHERE user_id = ".$ilDB->quote($this->user_id)." ";
00175                 
00176                 if (trim($this->getSearchQuery()) != '')
00177                 {
00178                 $query .= " AND (login LIKE '%".addslashes(trim($this->getSearchQuery()))."%' ".
00179                                 "OR firstname LIKE '%".addslashes(trim($this->getSearchQuery()))."%' ".
00180                                 "OR lastname LIKE '%".addslashes(trim($this->getSearchQuery()))."%' ".
00181                                 "OR email LIKE '%".addslashes(trim($this->getSearchQuery()))."%') ";
00182                 }
00183                 
00184                 $query .= " ORDER BY login,lastname";
00185 
00186                 $res = $this->ilias->db->query($query);
00187                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00188                 {
00189                         $entries[] = array(
00190                                 "addr_id"    => $row->addr_id,
00191                                 "login"      => ($row->login),
00192                                 "firstname"  => ($row->firstname),
00193                                 "lastname"   => ($row->lastname),
00194                                 "email"      => ($row->email));
00195                 }
00196                 return $entries ? $entries : array();
00197         }
00204         function getEntry($a_addr_id)
00205         {
00206                 global $ilDB;
00207                 
00208                 $query = "SELECT * FROM $this->table_addr ".
00209                         "WHERE user_id = ".$ilDB->quote($this->user_id)." ".
00210                         "AND addr_id = ".$ilDB->quote($a_addr_id)." ";
00211 
00212                 $row = $this->ilias->db->getRow($query,DB_FETCHMODE_OBJECT);
00213 
00214                 return array(
00215                         "addr_id"    => $row->addr_id,
00216                         "login"      => ($row->login),
00217                         "firstname"  => ($row->firstname),
00218                         "lastname"   => ($row->lastname),
00219                         "email"      => ($row->email));
00220         }
00221 
00228         function deleteEntries($a_entries)
00229         {
00230                 if(is_array($a_entries))
00231                 {
00232                         foreach($a_entries as $entry)
00233                         {
00234                                 $this->deleteEntry($entry);
00235                         }
00236                 }
00237                 return true;
00238         }
00245         function deleteEntry($a_addr_id)
00246         {
00247                 global $ilDB;
00248                 
00249                 $query = "DELETE FROM addressbook_mailing_lists_assignments ".
00250                                  "WHERE addr_id = ".$ilDB->quote($a_addr_id)." ";
00251                 $this->ilias->db->query($query);
00252                 
00253                 $query = "DELETE FROM $this->table_addr ".
00254                         "WHERE user_id = ".$ilDB->quote($this->user_id)." ".
00255                         "AND addr_id = ".$ilDB->quote($a_addr_id)." ";
00256                 $res = $this->ilias->db->query($query);
00257 
00258                 return true;
00259         }
00260 
00267         function checkEntry($a_login)
00268         {
00269                 global $ilDB;
00270                 
00271                 if ($a_login != "")
00272                 {
00273                         $query = "SELECT addr_id FROM $this->table_addr ".
00274                                      "WHERE user_id = ".$ilDB->quote($this->user_id)." 
00275                       AND login = ".$ilDB->quote($a_login)." ";
00276                         return $this->ilias->db->getOne($query);
00277                 }
00278                 
00279                 return 0;
00280         }
00281 
00282         /* Check whether an entry with a given login name already exists */
00283         function checkEntryByLogin($a_login)
00284         {
00285                 global $ilDB;
00286                 
00287                 if ($a_login != "")
00288                 {
00289                         $query = "SELECT addr_id FROM $this->table_addr ".
00290                                 "WHERE user_id = ".$ilDB->quote($this->user_id)." ".
00291                                 "AND login = ".$ilDB->quote($a_login)." ";
00292                         return $this->ilias->db->getOne($query);
00293                 }
00294                 
00295                 return 0;
00296         }
00297         
00298         public function setSearchQuery($search_query = '')
00299         {
00300                 $this->search_query = $search_query;
00301         }
00302         public function getSearchQuery()
00303         {
00304                 return $this->search_query;
00305         }
00306 }
00307 ?>

Generated on Fri Dec 13 2013 17:56:57 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1