Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
fmbiete committed Aug 28, 2014
1 parent 7c41a8e commit 0bd94c0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 48 deletions.
22 changes: 8 additions & 14 deletions carddav.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)."
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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
(?, ?, ?, ?, ?, ?, ?)
";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
54 changes: 20 additions & 34 deletions carddav_addressbook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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);
}

/**
Expand All @@ -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];
}

/**
Expand Down Expand Up @@ -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
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
";
Expand Down Expand Up @@ -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 = ?,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'));
}
}

Expand Down Expand Up @@ -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()."
Expand All @@ -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;
Expand Down

0 comments on commit 0bd94c0

Please sign in to comment.