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
24 * Undocumented class - fixme
25 * @package squirrelmail
27 class abook_global_file
extends addressbook_backend
{
29 var $bname = 'global_file';
33 /* ========================== Private ======================= */
36 function abook_global_file() {
37 global $address_book_global_filename;
38 $this->global_filename
= $address_book_global_filename;
40 $this->sname
= _("Global address book");
45 /* Open the addressbook file and store the file pointer.
46 * Use $file as the file to open, or the class' own
47 * filename property. If $param is empty and file is
48 * open, do nothing. */
49 function open($new = false) {
52 /* Return true is file is open and $new is unset */
53 if($this->filehandle
&& !$new) {
57 /* Check that new file exists */
58 if (! file_exists($this->global_filename
) ||
59 ! is_readable($this->global_filename
)) {
60 return $this->set_error($this->global_filename
. ': ' .
61 _("No such file or directory"));
64 /* Close old file, if any */
65 if ($this->filehandle
) {
69 /* Open file, read only. */
70 $fh = @fopen
($this->global_filename
, 'r');
71 $this->writeable
= false;
73 return $this->set_error($this->global_filename
. ': ' .
77 $this->filehandle
= &$fh;
81 /* Close the file and forget the filehandle */
83 @fclose
($this->filehandle
);
84 $this->filehandle
= 0;
85 $this->global_filename
= '';
86 $this->writable
= false;
89 /* ========================== Public ======================== */
92 function search($expr) {
94 /* To be replaced by advanded search expression parsing */
99 /* Make regexp from glob'ed expression
100 * May want to quote other special characters like (, ), -, [, ], etc. */
101 $expr = str_replace('?', '.', $expr);
102 $expr = str_replace('*', '.*', $expr);
109 @rewind
($this->filehandle
);
111 while ($row = @fgetcsv
($this->filehandle
, 2048, '|')) {
112 $line = join(' ', $row);
113 if (eregi($expr, $line)) {
114 $res[] = array('nickname' => $row[0],
115 'name' => $row[1] . ' ' . $row[2],
116 'firstname' => $row[1],
117 'lastname' => $row[2],
120 'backend' => $this->bnum
,
121 'source' => &$this->sname
);
129 function lookup($alias) {
134 $alias = strtolower($alias);
137 @rewind
($this->filehandle
);
139 while ($row = @fgetcsv
($this->filehandle
, 2048, '|')) {
140 if (strtolower($row[0]) == $alias) {
141 return array('nickname' => $row[0],
142 'name' => $row[1] . ' ' . $row[2],
143 'firstname' => $row[1],
144 'lastname' => $row[2],
147 'backend' => $this->bnum
,
148 'source' => &$this->sname
);
155 /* List all addresses */
156 function list_addr() {
159 @rewind
($this->filehandle
);
161 while ($row = @fgetcsv
($this->filehandle
, 2048, '|')) {
162 $res[] = array('nickname' => $row[0],
163 'name' => $row[1] . ' ' . $row[2],
164 'firstname' => $row[1],
165 'lastname' => $row[2],
168 'backend' => $this->bnum
,
169 'source' => &$this->sname
);
175 function add($userdata) {
176 $this->set_error(_("Can not modify global address book"));
181 function remove($alias) {
182 $this->set_error(_("Can not modify global address book"));
187 function modify($alias, $userdata) {
188 $this->set_error(_("Can not modify global address book"));
192 } /* End of class abook_local_file */