Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed pagination in addressbook and save new contacts #77

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions carddav.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,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 @@ -353,23 +353,18 @@ 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 @@ -534,7 +529,7 @@ public function carddav_server_save()

$query = "
INSERT INTO
".get_table_name('carddav_server')." (user_id, url, username, password, label, read_only)
".$rcmail->db->table_name('carddav_server')." (user_id, url, username, password, label, read_only)
VALUES
(?, ?, ?, ?, ?, ?)
";
Expand Down Expand Up @@ -581,7 +576,7 @@ public function carddav_server_delete()

$query = "
DELETE FROM
".get_table_name('carddav_server')."
".$rcmail->db->table_name('carddav_server')."
WHERE
user_id = ?
AND
Expand Down Expand Up @@ -615,6 +610,6 @@ public function carddav_server_delete()
*/
public function write_log($message)
{
write_log('CardDAV', 'v' . self::VERSION . ' | ' . $message);
rcmail::write_log('CardDAV', 'v' . self::VERSION . ' | ' . $message);
}
}
55 changes: 20 additions & 35 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,18 @@ 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 @@ -507,7 +496,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 @@ -557,7 +546,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 @@ -614,7 +603,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 @@ -653,9 +642,9 @@ private function carddav_add($vcard)
if ($carddav_backend->check_connection())
{
$vcard_id = $carddav_backend->add($vcard);
$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'));
}

return false;
Expand Down Expand Up @@ -781,7 +770,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 @@ -791,16 +780,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