6 * Copyright (c) 1999-2001 The Squirrelmail Development 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!
22 /*****************************************************************/
23 /*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
24 /*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
25 /*** + Base level indent should begin at left margin, as ***/
26 /*** the first line of the class definition below. ***/
27 /*** + All identation should consist of four space blocks ***/
28 /*** + Tab characters are evil. ***/
29 /*** + all comments should use "slash-star ... star-slash" ***/
30 /*** style -- no pound characters, no slash-slash style ***/
31 /*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
32 /*** ALWAYS USE { AND } CHARACTERS!!! ***/
33 /*** + Please use ' instead of ", when possible. Note " ***/
34 /*** should always be used in _( ) function calls. ***/
35 /*** Thank you for your help making the SM code more readable. ***/
36 /*****************************************************************/
38 class abook_global_file
extends addressbook_backend
{
40 var $bname = 'global_file';
44 // ========================== Private =======================
47 function abook_global_file() {
48 global $address_book_global_filename;
49 $this->global_filename
= $address_book_global_filename;
51 $this->sname
= _("Global address book");
56 // Open the addressbook file and store the file pointer.
57 // Use $file as the file to open, or the class' own
58 // filename property. If $param is empty and file is
60 function open($new = false) {
63 // Return true is file is open and $new is unset
64 if($this->filehandle
&& !$new)
67 // Check that new file exists
68 if (! file_exists($this->global_filename
) ||
69 ! is_readable($this->global_filename
))
70 return $this->set_error($this->global_filename
. ': ' .
71 _("No such file or directory"));
73 // Close old file, if any
74 if ($this->filehandle
) $this->close();
76 // Open file, read only.
77 $fh = @fopen
($this->global_filename
, 'r');
78 $this->writeable
= false;
80 return $this->set_error($this->global_filename
. ': ' .
83 $this->filehandle
= &$fh;
87 // Close the file and forget the filehandle
89 @fclose
($this->filehandle
);
90 $this->filehandle
= 0;
91 $this->global_filename
= '';
92 $this->writable
= false;
95 // ========================== Public ========================
98 function search($expr) {
100 // To be replaced by advanded search expression parsing
101 if(is_array($expr)) return;
103 // Make regexp from glob'ed expression
104 // May want to quote other special characters like (, ), -, [, ], etc.
105 $expr = str_replace('?', '.', $expr);
106 $expr = str_replace('*', '.*', $expr);
112 @rewind
($this->filehandle
);
114 while ($row = @fgetcsv
($this->filehandle
, 2048, '|')) {
115 $line = join(' ', $row);
116 if (eregi($expr, $line)) {
117 $res[] = array('nickname' => $row[0],
118 'name' => $row[1] . ' ' . $row[2],
119 'firstname' => $row[1],
120 'lastname' => $row[2],
123 'backend' => $this->bnum
,
124 'source' => &$this->sname
);
132 function lookup($alias) {
136 $alias = strtolower($alias);
139 @rewind
($this->filehandle
);
141 while ($row = @fgetcsv
($this->filehandle
, 2048, '|')) {
142 if (strtolower($row[0]) == $alias) {
143 return array('nickname' => $row[0],
144 'name' => $row[1] . ' ' . $row[2],
145 'firstname' => $row[1],
146 'lastname' => $row[2],
149 'backend' => $this->bnum
,
150 'source' => &$this->sname
);
157 // List all addresses
158 function list_addr() {
161 @rewind
($this->filehandle
);
163 while ($row = @fgetcsv
($this->filehandle
, 2048, '|')) {
164 $res[] = array('nickname' => $row[0],
165 'name' => $row[1] . ' ' . $row[2],
166 'firstname' => $row[1],
167 'lastname' => $row[2],
170 'backend' => $this->bnum
,
171 'source' => &$this->sname
);
177 function add($userdata) {
178 $this->set_error(_("Can not modify global address book"));
183 function remove($alias) {
184 $this->set_error(_("Can not modify global address book"));
189 function modify($alias, $userdata) {
190 $this->set_error(_("Can not modify global address book"));
194 } // End of class abook_local_file