From 0bd94c0d608b77b58325ea85a1f2c46b3d0b6405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Miguel=20Biete=20Ba=C3=B1on?= Date: Thu, 28 Aug 2014 09:18:10 +0200 Subject: [PATCH] Merge #77 --- carddav.php | 22 ++++++----------- carddav_addressbook.php | 54 +++++++++++++++-------------------------- 2 files changed, 28 insertions(+), 48 deletions(-) diff --git a/carddav.php b/carddav.php index 904b0bd..eeee302 100644 --- a/carddav.php +++ b/carddav.php @@ -159,7 +159,7 @@ public function get_carddav_server($carddav_server_id = false) SELECT * FROM - ".get_table_name('carddav_server')." + ".$rcmail->db->table_name('carddav_server')." WHERE user_id = ? ".($carddav_server_id !== false ? " AND carddav_server_id = ?" : null)." @@ -362,23 +362,17 @@ protected function carddav_server_available() $query = " SELECT - * + count(*) FROM - ".get_table_name('carddav_server')." + ".$rcmail->db->table_name('carddav_server')." WHERE user_id = ? "; $result = $rcmail->db->query($query, $user_id); - if ($rcmail->db->num_rows($result)) - { - return true; - } - else - { - return false; - } + $count = $rcmail->db->fetch_array($result); + return ($count[0] > 0); } /** @@ -571,7 +565,7 @@ public function add_carddav_server($server) $query = " INSERT INTO - ".get_table_name('carddav_server')." (user_id, url, username, password, label, read_only, default_server) + ".$rcmail->db->table_name('carddav_server')." (user_id, url, username, password, label, read_only, default_server) VALUES (?, ?, ?, ?, ?, ?, ?) "; @@ -648,7 +642,7 @@ public function delete_carddav_server($carddav_server_id) $query = " DELETE FROM - ".get_table_name('carddav_server')." + ".$rcmail->db->table_name('carddav_server')." WHERE user_id = ? AND @@ -702,6 +696,6 @@ public function carddav_server_delete_from_settings() */ public function write_log($message) { - write_log('CardDAV', 'v' . self::VERSION . ' | ' . $message); + rcmail::write_log('CardDAV', 'v' . self::VERSION . ' | ' . $message); } } diff --git a/carddav_addressbook.php b/carddav_addressbook.php index 229216d..ce50385 100644 --- a/carddav_addressbook.php +++ b/carddav_addressbook.php @@ -143,7 +143,7 @@ private function get_carddav_addressbook_contacts($limit = array()) SELECT * FROM - ".get_table_name('carddav_contacts')." + ".$rcmail->db->table_name('carddav_contacts')." WHERE user_id = ? AND @@ -162,12 +162,9 @@ private function get_carddav_addressbook_contacts($limit = array()) $result = $rcmail->db->limitquery($query, $limit['start'], $limit['length'], $rcmail->user->data['user_id'], $this->carddav_server_id); } - if ($rcmail->db->num_rows($result)) + while ($contact = $rcmail->db->fetch_assoc($result)) { - while ($contact = $rcmail->db->fetch_assoc($result)) - { - $carddav_addressbook_contacts[$contact['vcard_id']] = $contact; - } + $carddav_addressbook_contacts[$contact['vcard_id']] = $contact; } return $carddav_addressbook_contacts; @@ -187,7 +184,7 @@ private function get_carddav_addressbook_contact($carddav_contact_id) SELECT * FROM - ".get_table_name('carddav_contacts')." + ".$rcmail->db->table_name('carddav_contacts')." WHERE user_id = ? AND @@ -196,12 +193,7 @@ private function get_carddav_addressbook_contact($carddav_contact_id) $result = $rcmail->db->query($query, $rcmail->user->data['user_id'], $carddav_contact_id); - if ($rcmail->db->num_rows($result)) - { - return $rcmail->db->fetch_assoc($result); - } - - return false; + return $rcmail->db->fetch_assoc($result); } /** @@ -215,21 +207,19 @@ private function get_carddav_addressbook_contacts_count() $query = " SELECT - * + count(*) FROM - ".get_table_name('carddav_contacts')." + ".$rcmail->db->table_name('carddav_contacts')." WHERE user_id = ? AND carddav_server_id = ? - ".$this->get_search_set()." - ORDER BY - name ASC - "; + ".$this->get_search_set(); $result = $rcmail->db->query($query, $rcmail->user->data['user_id'], $this->carddav_server_id); - return $rcmail->db->num_rows($result); + $count = $rcmail->db->fetch_array($result); + return $count[0]; } /** @@ -503,7 +493,7 @@ private function carddav_addressbook_add($carddav_content) $query = " INSERT INTO - ".get_table_name('carddav_contacts')." (carddav_server_id, user_id, etag, last_modified, vcard_id, vcard, words, firstname, surname, name, email) + ".$rcmail->db->table_name('carddav_contacts')." (carddav_server_id, user_id, etag, last_modified, vcard_id, vcard, words, firstname, surname, name, email) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) "; @@ -553,7 +543,7 @@ private function carddav_addressbook_update($carddav_content) $query = " UPDATE - ".get_table_name('carddav_contacts')." + ".$rcmail->db->table_name('carddav_contacts')." SET etag = ?, last_modified = ?, @@ -610,7 +600,7 @@ private function carddav_addressbook_delete($vcard_id) $query = " DELETE FROM - ".get_table_name('carddav_contacts')." + ".$rcmail->db->table_name('carddav_contacts')." WHERE vcard_id = ? AND @@ -649,9 +639,9 @@ private function carddav_add($vcard) $vcard_id = $carddav_backend->add($vcard); if($vcard_id !== false) { - $this->carddav_addressbook_sync($server, false, $vcard_id); + $this->carddav_addressbook_sync($server, null, $vcard_id); - return $rcmail->db->insert_id(get_table_name('carddav_contacts')); + return $rcmail->db->insert_id($rcmail->db->table_name('carddav_contacts')); } } @@ -820,7 +810,7 @@ private function search_carddav_addressbook_contacts() SELECT * FROM - ".get_table_name('carddav_contacts')." + ".$rcmail->db->table_name('carddav_contacts')." WHERE user_id = ? ".$this->get_search_set()." @@ -830,16 +820,12 @@ private function search_carddav_addressbook_contacts() $result = $rcmail->db->query($query, $rcmail->user->data['user_id']); - if ($rcmail->db->num_rows($result)) + while ($contact = $rcmail->db->fetch_assoc($result)) { - while ($contact = $rcmail->db->fetch_assoc($result)) - { - $record['name'] = $contact['name']; - $record['email'] = explode(', ', $contact['email']); - - $this->result->add($record); - } + $record['name'] = $contact['name']; + $record['email'] = explode(', ', $contact['email']); + $this->result->add($record); } return $this->result;