4 * abook_global_file.php
6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * Backend for addressbook as a pipe separated file
11 * An array with the following elements must be passed to
12 * the class constructor (elements marked ? are optional):
14 * NOTE. This class should not be used directly. Use the
15 * "AddressBook" class instead.
17 * Make sure you configure this before using it!
20 * @package squirrelmail
21 * @subpackage addressbook
25 * Undocumented class - fixme
26 * @package squirrelmail
28 class abook_global_file
extends addressbook_backend
{
30 var $bname = 'global_file';
34 /* ========================== Private ======================= */
37 function abook_global_file() {
38 global $address_book_global_filename;
39 $this->global_filename
= $address_book_global_filename;
41 $this->sname
= _("Global address book");
46 /* Open the addressbook file and store the file pointer.
47 * Use $file as the file to open, or the class' own
48 * filename property. If $param is empty and file is
49 * open, do nothing. */
50 function open($new = false) {
53 /* Return true is file is open and $new is unset */
54 if($this->filehandle
&& !$new) {
58 /* Check that new file exists */
59 if (! file_exists($this->global_filename
) ||
60 ! is_readable($this->global_filename
)) {
61 return $this->set_error($this->global_filename
. ': ' .
62 _("No such file or directory"));
65 /* Close old file, if any */
66 if ($this->filehandle
) {
70 /* Open file, read only. */
71 $fh = @fopen
($this->global_filename
, 'r');
72 $this->writeable
= false;
74 return $this->set_error($this->global_filename
. ': ' .
78 $this->filehandle
= &$fh;
82 /* Close the file and forget the filehandle */
84 @fclose
($this->filehandle
);
85 $this->filehandle
= 0;
86 $this->global_filename
= '';
87 $this->writable
= false;
90 /* ========================== Public ======================== */
93 function search($expr) {
95 /* To be replaced by advanded search expression parsing */
100 /* Make regexp from glob'ed expression
101 * May want to quote other special characters like (, ), -, [, ], etc. */
102 $expr = str_replace('?', '.', $expr);
103 $expr = str_replace('*', '.*', $expr);
110 @rewind
($this->filehandle
);
112 while ($row = @fgetcsv
($this->filehandle
, 2048, '|')) {
113 $line = join(' ', $row);
114 if (eregi($expr, $line)) {
115 $res[] = array('nickname' => $row[0],
116 'name' => $row[1] . ' ' . $row[2],
117 'firstname' => $row[1],
118 'lastname' => $row[2],
121 'backend' => $this->bnum
,
122 'source' => &$this->sname
);
130 function lookup($alias) {
135 $alias = strtolower($alias);
138 @rewind
($this->filehandle
);
140 while ($row = @fgetcsv
($this->filehandle
, 2048, '|')) {
141 if (strtolower($row[0]) == $alias) {
142 return array('nickname' => $row[0],
143 'name' => $row[1] . ' ' . $row[2],
144 'firstname' => $row[1],
145 'lastname' => $row[2],
148 'backend' => $this->bnum
,
149 'source' => &$this->sname
);
156 /* List all addresses */
157 function list_addr() {
160 @rewind
($this->filehandle
);
162 while ($row = @fgetcsv
($this->filehandle
, 2048, '|')) {
163 $res[] = array('nickname' => $row[0],
164 'name' => $row[1] . ' ' . $row[2],
165 'firstname' => $row[1],
166 'lastname' => $row[2],
169 'backend' => $this->bnum
,
170 'source' => &$this->sname
);
176 function add($userdata) {
177 $this->set_error(_("Can not modify global address book"));
182 function remove($alias) {
183 $this->set_error(_("Can not modify global address book"));
188 function modify($alias, $userdata) {
189 $this->set_error(_("Can not modify global address book"));
193 } /* End of class abook_local_file */