+ // Delete address
+ function remove($alias) {
+ if(!$this->writeable)
+ return $this->set_error(_("Addressbook is read-only"));
+
+ // Lock the file to make sure we're the only process working
+ // on it.
+ if(!$this->lock())
+ return $this->set_error(_("Could not lock datafile"));
+
+ // Read file into memory, ignoring nicknames to delete
+ $this->open();
+ @rewind($this->filehandle);
+ $i = 0;
+ $rows = array();
+ while($row = @fgetcsv($this->filehandle, 2048, "|")) {
+ if(!in_array($row[0], $alias))
+ $rows[$i++] = $row;
+ }
+
+ // Write data back
+ if(!$this->overwrite(&$rows)) {
+ $this->unlock();
+ return false;
+ }
+
+ $this->unlock();
+ return true;
+ }
+
+ // Modify address
+ function modify($alias, $userdata) {
+ if(!$this->writeable)
+ return $this->set_error(_("Addressbook is read-only"));
+
+ // See if user exist
+ $ret = $this->lookup($alias);
+ if(empty($ret))
+ return $this->set_error(sprintf(_("User '%s' does not exist"),
+ $alias));
+
+ // Lock the file to make sure we're the only process working
+ // on it.
+ if(!$this->lock())
+ return $this->set_error(_("Could not lock datafile"));
+
+ // Read file into memory, modifying the data for the
+ // user identifyed by $alias
+ $this->open();
+ @rewind($this->filehandle);
+ $i = 0;
+ $rows = array();
+ while($row = @fgetcsv($this->filehandle, 2048, "|")) {
+ if(strtolower($row[0]) != strtolower($alias)) {
+ $rows[$i++] = $row;
+ } else {
+ $rows[$i++] = array(0 => $userdata["nickname"],
+ 1 => $userdata["firstname"],
+ 2 => $userdata["lastname"],
+ 3 => $userdata["email"],
+ 4 => $userdata["label"]);
+ }
+ }
+
+ // Write data back
+ if(!$this->overwrite(&$rows)) {
+ $this->unlock();
+ return false;
+ }
+
+ $this->unlock();
+ return true;
+ }
+
+ } // End of class abook_local_file