forked from christian-putzke/Roundcube-CardDAV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
carddav_addressbook.php
1074 lines (943 loc) · 25.2 KB
/
carddav_addressbook.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Roundcube CardDAV addressbook extension
*
* @author Christian Putzke <[email protected]>
* @copyright Christian Putzke @ Graviox Studios
* @since 12.09.2011
* @link http://www.graviox.de/
* @link https://twitter.com/graviox/
* @version 0.5.1
* @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
*/
class carddav_addressbook extends rcube_addressbook
{
/**
* Database primary key
*
* @var string
*/
public $primary_key = 'carddav_contact_id';
/**
* Sets addressbook readonly (true) or not (false)
*
* @var boolean
*/
public $readonly = false;
/**
* Allow addressbook groups (true) or not (false)
*
* @var boolean
*/
public $groups = false;
/**
* Internal addressbook group id
*
* @var string
*/
public $group_id;
/**
* Search filters
*
* @var array
*/
private $filter;
/**
* Result set
*
* @var rcube_result_set
*/
private $result;
/**
* Translated addressbook name
*
* @var string
*/
private $name;
/**
* CardDAV server id
*
* @var integer
*/
private $carddav_server_id = false;
/**
* Single and searchable database table columns
*
* @var array
*/
private $table_cols = array('name', 'firstname', 'surname', 'email');
/**
* vCard fields used for the fulltext search (database column: words)
*
* @var array
*/
private $fulltext_cols = array('name', 'firstname', 'surname', 'middlename', 'nickname',
'jobtitle', 'organization', 'department', 'maidenname', 'email', 'phone',
'address', 'street', 'locality', 'zipcode', 'region', 'country', 'website', 'im', 'notes');
/**
* vCard fields that will be displayed in the addressbook
*
* @var array
*/
public $coltypes = array('name', 'firstname', 'surname', 'middlename', 'prefix', 'suffix', 'nickname',
'jobtitle', 'organization', 'department', 'assistant', 'manager',
'gender', 'maidenname', 'spouse', 'email', 'phone', 'address',
'birthday', 'anniversary', 'website', 'im', 'notes', 'photo');
/**
* Id list separator
*
* @constant string
*/
const SEPARATOR = ',';
/**
* Init CardDAV addressbook
*
* @param string $carddav_server_id Translated addressbook name
* @param integer $name CardDAV server id
* @return void
*/
public function __construct($carddav_server_id, $name, $readonly)
{
$this->ready = true;
$this->name = $name;
$this->carddav_server_id = $carddav_server_id;
$this->readonly = $readonly;
}
/**
* Get translated addressbook name
*
* @return string $this->name Translated addressbook name
*/
public function get_name()
{
return $this->name;
}
/**
* Get all CardDAV adressbook contacts
*
* @param array $limit Limits (limit, offset)
* @return array CardDAV adressbook contacts
*/
private function get_carddav_addressbook_contacts($limit = array())
{
$rcmail = rcmail::get_instance();
$carddav_addressbook_contacts = array();
$query = "
SELECT
*
FROM
".get_table_name('carddav_contacts')."
WHERE
user_id = ?
AND
carddav_server_id = ?
".$this->get_search_set()."
ORDER BY
name ASC
";
if (empty($limit))
{
$result = $rcmail->db->query($query, $rcmail->user->data['user_id'], $this->carddav_server_id);
}
else
{
$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))
{
$carddav_addressbook_contacts[$contact['vcard_id']] = $contact;
}
}
return $carddav_addressbook_contacts;
}
/**
* Get one CardDAV adressbook contact
*
* @param integer $carddav_contact_id CardDAV contact id
* @return array CardDAV adressbook contact
*/
private function get_carddav_addressbook_contact($carddav_contact_id)
{
$rcmail = rcmail::get_instance();
$query = "
SELECT
*
FROM
".get_table_name('carddav_contacts')."
WHERE
user_id = ?
AND
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;
}
/**
* Get count of CardDAV contacts specified CardDAV addressbook
*
* @return integer Count of the CardDAV contacts
*/
private function get_carddav_addressbook_contacts_count()
{
$rcmail = rcmail::get_instance();
$query = "
SELECT
*
FROM
".get_table_name('carddav_contacts')."
WHERE
user_id = ?
AND
carddav_server_id = ?
".$this->get_search_set()."
ORDER BY
name ASC
";
$result = $rcmail->db->query($query, $rcmail->user->data['user_id'], $this->carddav_server_id);
return $rcmail->db->num_rows($result);
}
/**
* Get result set
*
* @return $this->result rcube_result_set Roundcube result set
*/
public function get_result()
{
return $this->result;
}
/**
*
*
* @param integer $carddav_contact_id CardDAV contact id
* @param boolean $assoc Define if result should be an assoc array or rcube_result_set
* @return mixed Returns contact as an assoc array or rcube_result_set
*/
public function get_record($carddav_contact_id, $assoc = false)
{
$contact = $this->get_carddav_addressbook_contact($carddav_contact_id);
$contact['ID'] = $contact[$this->primary_key];
unset($contact['email']);
$vcard = new rcube_vcard($contact['vcard']);
$contact += $vcard->get_assoc();
$this->result = new rcube_result_set(1);
$this->result->add($contact);
if ($assoc === true)
{
return $contact;
}
else
{
return $this->result;
}
}
/**
* Getter for saved search properties
*
* @return $this->filter array Search properties
*/
public function get_search_set()
{
return $this->filter;
}
/**
* Save a search string for future listings
*
* @param string $filter SQL params to use in listing method
* @return void
*/
public function set_search_set($filter)
{
$this->filter = $filter;
}
/**
* Set database search filter
*
* @param mixed $fields Database field names
* @param string $value Searched value
* @return void
*/
public function set_filter($fields, $value)
{
$rcmail = rcmail::get_instance();
$filter = null;
if (is_array($fields))
{
$filter = "AND (";
foreach ($fields as $field)
{
if (in_array($field, $this->table_cols) || $fields == $this->primary_key)
{
$filter .= $rcmail->db->ilike($field, '%'.$value.'%')." OR ";
}
}
$filter = substr($filter, 0, -4);
$filter .= ")";
}
else
{
if (in_array($fields, $this->table_cols) || $fields == $this->primary_key)
{
$filter = " AND ".$rcmail->db->ilike($fields, '%'.$value.'%');
}
else if ($fields == '*')
{
$filter = " AND ".$rcmail->db->ilike('words', '%'.$value.'%');
}
}
$this->set_search_set($filter);
}
/**
* Sets internal addressbook group id
*
* @param string $group_id Internal addressbook group id
* @return void
*/
public function set_group($group_id)
{
$this->group_id = $group_id;
}
/**
* Reset cached filters and results
*
* @return void
*/
public function reset()
{
$this->result = null;
$this->filter = null;
}
/**
* Synchronize CardDAV-Addressbook
*
* @param array $server CardDAV server array
* @param integer $carddav_contact_id CardDAV contact id
* @param string $vcard_id vCard id
* @return boolean if no error occurred "true" else "false"
*/
public function carddav_addressbook_sync($server, $carddav_contact_id = null, $vcard_id = null)
{
$any_data_synced = false;
self::write_log('Starting CardDAV-Addressbook synchronization');
if (false !== ($carddav_backend = $this->get_backend($server)))
{
self::write_log('Connected to the CardDAV-Server ' . $server['url']);
if ($vcard_id !== null)
{
$elements = $carddav_backend->get_xml_vcard($vcard_id);
if ($carddav_contact_id !== null)
{
$carddav_addressbook_contact = $this->get_carddav_addressbook_contact($carddav_contact_id);
$carddav_addressbook_contacts = array(
$carddav_addressbook_contact['vcard_id'] => $carddav_addressbook_contact
);
}
}
else
{
$elements = $carddav_backend->get(false);
$carddav_addressbook_contacts = $this->get_carddav_addressbook_contacts();
}
try
{
$xml = new SimpleXMLElement($elements);
if (!empty($xml->element))
{
foreach ($xml->element as $element)
{
$element_id = (string) $element->id;
$element_etag = (string) $element->etag;
$element_last_modified = (string) $element->last_modified;
if (isset($carddav_addressbook_contacts[$element_id]))
{
if ($carddav_addressbook_contacts[$element_id]['etag'] != $element_etag ||
$carddav_addressbook_contacts[$element_id]['last_modified'] != $element_last_modified)
{
$carddav_content = array(
'vcard' => $carddav_backend->get_vcard($element_id),
'vcard_id' => $element_id,
'etag' => $element_etag,
'last_modified' => $element_last_modified
);
if ($this->carddav_addressbook_update($carddav_content))
{
$any_data_synced = true;
}
}
}
else
{
$carddav_content = array(
'vcard' => $carddav_backend->get_vcard($element_id),
'vcard_id' => $element_id,
'etag' => $element_etag,
'last_modified' => $element_last_modified
);
if (!empty($carddav_content['vcard']))
{
if ($this->carddav_addressbook_add($carddav_content))
{
$any_data_synced = true;
}
}
}
unset($carddav_addressbook_contacts[$element_id]);
}
}
else
{
$logging_message = 'No CardDAV XML-Element found!';
if ($carddav_contact_id !== null && $vcard_id !== null)
{
self::write_log($logging_message . ' The CardDAV-Server does not have a contact with the vCard id ' . $vcard_id);
}
else
{
self::write_log($logging_message . ' The CardDAV-Server seems to have no contacts');
}
}
if (!empty($carddav_addressbook_contacts))
{
foreach ($carddav_addressbook_contacts as $vcard_id => $etag)
{
if ($this->carddav_addressbook_delete($vcard_id))
{
$any_data_synced = true;
}
}
}
if ($any_data_synced === false)
{
self::write_log('all CardDAV-Data are synchronous, nothing todo!');
}
self::write_log('Syncronization complete!');
}
catch (Exception $e)
{
self::write_log('CardDAV-Server XML-Response is malformed. Synchronization aborted!');
return false;
}
}
else
{
self::write_log('Couldn\'t connect to the CardDAV-Server ' . $server['url']);
return false;
}
return true;
}
/**
* Adds a vCard to the CardDAV addressbook
*
* @param array $carddav_content CardDAV contents (vCard id, etag, last modified, etc.)
* @return boolean
*/
private function carddav_addressbook_add($carddav_content)
{
$rcmail = rcmail::get_instance();
$vcard = new rcube_vcard($carddav_content['vcard']);
$query = "
INSERT INTO
".get_table_name('carddav_contacts')." (carddav_server_id, user_id, etag, last_modified, vcard_id, vcard, words, firstname, surname, name, email)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
";
$database_column_contents = $this->get_database_column_contents($vcard->get_assoc());
$result = $rcmail->db->query(
$query,
$this->carddav_server_id,
$rcmail->user->data['user_id'],
$carddav_content['etag'],
$carddav_content['last_modified'],
$carddav_content['vcard_id'],
$carddav_content['vcard'],
$database_column_contents['words'],
$database_column_contents['firstname'],
$database_column_contents['surname'],
$database_column_contents['name'],
$database_column_contents['email']
);
if ($rcmail->db->affected_rows($result))
{
self::write_log('Added CardDAV-Contact to the local database with the vCard id ' . $carddav_content['vcard_id']);
return true;
}
else
{
self::write_log('Couldn\'t add CardDAV-Contact to the local database with the vCard id ' . $carddav_content['vcard_id']);
return false;
}
}
/**
* Updates a vCard in the CardDAV-Addressbook
*
* @param array $carddav_content CardDAV contents (vCard id, etag, last modified, etc.)
* @return boolean
*/
private function carddav_addressbook_update($carddav_content)
{
$rcmail = rcmail::get_instance();
$vcard = new rcube_vcard($carddav_content['vcard']);
$database_column_contents = $this->get_database_column_contents($vcard->get_assoc());
$query = "
UPDATE
".get_table_name('carddav_contacts')."
SET
etag = ?,
last_modified = ?,
vcard = ?,
words = ?,
firstname = ?,
surname = ?,
name = ?,
email = ?
WHERE
vcard_id = ?
AND
carddav_server_id = ?
AND
user_id = ?
";
$result = $rcmail->db->query(
$query,
$carddav_content['etag'],
$carddav_content['last_modified'],
$carddav_content['vcard'],
$database_column_contents['words'],
$database_column_contents['firstname'],
$database_column_contents['surname'],
$database_column_contents['name'],
$database_column_contents['email'],
$carddav_content['vcard_id'],
$this->carddav_server_id,
$rcmail->user->data['user_id']
);
if ($rcmail->db->affected_rows($result))
{
self::write_log('CardDAV-Contact updated in the local database with the vCard id ' . $carddav_content['vcard_id']);
return true;
}
else
{
self::write_log('Couldn\'t update CardDAV-Contact in the local database with the vCard id ' . $carddav_content['vcard_id']);
return false;
}
}
/**
* Deletes a vCard from the CardDAV addressbook
*
* @param string $vcard_id vCard id
* @return boolean
*/
private function carddav_addressbook_delete($vcard_id)
{
$rcmail = rcmail::get_instance();
$query = "
DELETE FROM
".get_table_name('carddav_contacts')."
WHERE
vcard_id = ?
AND
carddav_server_id = ?
AND
user_id = ?
";
$result = $rcmail->db->query($query, $vcard_id, $this->carddav_server_id, $rcmail->user->data['user_id']);
if ($rcmail->db->affected_rows($result))
{
self::write_log('CardDAV-Contact deleted from the local database with the vCard id ' . $vcard_id);
return true;
}
else
{
self::write_log('Couldn\'t delete CardDAV-Contact from the local database with the vCard id ' . $vcard_id);
return false;
}
}
/**
* Adds a CardDAV server contact
*
* @param string $vcard vCard
* @return boolean
*/
private function carddav_add($vcard)
{
$rcmail = rcmail::get_instance();
$server = current(carddav::get_carddav_server($this->carddav_server_id));
if (false !== ($carddav_backend = $this->get_backend($server)))
{
$vcard_id = $carddav_backend->add($vcard);
$this->carddav_addressbook_sync($server, false, $vcard_id);
return $rcmail->db->insert_id(get_table_name('carddav_contacts'));
}
return false;
}
/**
* Updates a CardDAV server contact
*
* @param integer $carddav_contact_id CardDAV contact id
* @param string $vcard The new vCard
* @return boolean
*/
private function carddav_update($carddav_contact_id, $vcard)
{
$rcmail = rcmail::get_instance();
$contact = $this->get_carddav_addressbook_contact($carddav_contact_id);
$server = current(carddav::get_carddav_server($this->carddav_server_id));
if (false !== ($carddav_backend = $this->get_backend($server)))
{
$carddav_backend->update($vcard, $contact['vcard_id']);
$this->carddav_addressbook_sync($server, $carddav_contact_id, $contact['vcard_id']);
return true;
}
return false;
}
/**
* Deletes the CardDAV server contact
*
* @param array $carddav_contact_ids CardDAV contact ids
* @return mixed affected CardDAV contacts or false
*/
private function carddav_delete($carddav_contact_ids)
{
$rcmail = rcmail::get_instance();
$server = current(carddav::get_carddav_server($this->carddav_server_id));
if (false !== ($carddav_backend = $this->get_backend($server)))
{
foreach ($carddav_contact_ids as $carddav_contact_id)
{
$contact = $this->get_carddav_addressbook_contact($carddav_contact_id);
$carddav_backend->delete($contact['vcard_id']);
$this->carddav_addressbook_sync($server, $carddav_contact_id, $contact['vcard_id']);
}
return count($carddav_contact_ids);
}
return false;
}
/**
* Get CardDAV_Backend for the given server
*
* @param array server connection parameters
* @return mixed either a CardDAV_Backend or FALSE if the connection fails
*/
private function get_backend($server) {
$rcmail = rcmail::get_instance();
$this->interpolate_settings($server);
$carddav_backend = new carddav_backend($server['url']);
$carddav_backend->set_auth($server['username'], $rcmail->decrypt($server['password']));
if ($carddav_backend->check_connection())
{
return $carddav_backend;
}
else
{
return false;
}
}
/**
* When 'default_server' is not set to 0, this will replace macros
* used in server settings.
*
* @param array $server CarDAV server array
*/
private function interpolate_settings(&$server)
{
if ($server['default_server'] == 0) {
return;
}
$rcmail = rcmail::get_instance();
$server['username'] = str_replace('%u', $_SESSION['username'], $server['username']);
$server['username'] = str_replace('%l', $rcmail->user->get_username('local'), $server['username']);
$server['username'] = str_replace('%d', $rcmail->user->get_username('domain'), $server['username']);
$server['password'] = str_replace('%p', $_SESSION['password'], $server['password']);
$server['url'] = str_replace('%u', $_SESSION['username'], $server['url']);
$server['url'] = str_replace('%l', $_SESSION['username'], $server['url']);
$server['url'] = str_replace('%d', $_SESSION['username'], $server['url']);
}
/**
* @see rcube_addressbook::list_groups()
* @param string $search
* @return boolean
*/
public function list_groups($search = null)
{
return false;
}
/**
* Returns a list of CardDAV adressbook contacts
*
* @param string $columns Database columns
* @param integer $subset Subset for result limits
* @return rcube_result_set $this->result List of CardDAV adressbook contacts
*/
public function list_records($columns = null, $subset = 0)
{
$this->result = $this->count();
$limit = array(
'start' => ($subset < 0 ? $this->result->first + $this->page_size + $subset : $this->result->first),
'length' => ($subset != 0 ? abs($subset) : $this->page_size)
);
$contacts = $this->get_carddav_addressbook_contacts($limit);
if (!empty($contacts))
{
foreach ($contacts as $contact)
{
$record = array();
$record['ID'] = $contact[$this->primary_key];
if ($columns === null)
{
$vcard = new rcube_vcard($contact['vcard']);
$record += $vcard->get_assoc();
}
else
{
$record['name'] = $contact['name'];
$record['email'] = explode(', ', $contact['email']);
}
$this->result->add($record);
}
}
return $this->result;
}
/**
* Search and autocomplete contacts in the mail view
*
* @return rcube_result_set $this->result List of searched CardDAV adressbook contacts
*/
private function search_carddav_addressbook_contacts()
{
$rcmail = rcmail::get_instance();
$this->result = $this->count();
$query = "
SELECT
*
FROM
".get_table_name('carddav_contacts')."
WHERE
user_id = ?
".$this->get_search_set()."
ORDER BY
name ASC
";
$result = $rcmail->db->query($query, $rcmail->user->data['user_id']);
if ($rcmail->db->num_rows($result))
{
while ($contact = $rcmail->db->fetch_assoc($result))
{
$record['name'] = $contact['name'];
$record['email'] = explode(', ', $contact['email']);
$this->result->add($record);
}
}
return $this->result;
}
/**
* Search method (autocomplete, addressbook)
*
* @param array $fields Search in these fields
* @param string $value Search value
* @param boolean $strict
* @param boolean $select
* @param boolean $nocount
* @param array $required
* @return rcube_result_set List of searched CardDAV-Adressbook contacts
*/
public function search($fields, $value, $strict = false, $select = true, $nocount = false, $required = array())
{
$this->set_filter($fields, $value);
return $this->search_carddav_addressbook_contacts();
}
/**
* Count CardDAV contacts for a specified CardDAV addressbook and return the result set
*
* @return rcube_result_set
*/
public function count()
{
$count = $this->get_carddav_addressbook_contacts_count();
return new rcube_result_set($count, ($this->list_page - 1) * $this->page_size);
}
/**
* @see rcube_addressbook::get_record_groups()
* @param integer $id
* @return boolean
*/
public function get_record_groups($id)
{
return false;
}
/**
* @see rcube_addressbook::create_group()
* @param string $name
* @return boolean
*/
public function create_group($name)
{
return false;
}
/**
* @see rcube_addressbook::delete_group()
* @param integer $gid
* @return boolean
*/
public function delete_group($gid)
{
return false;
}
/**
* @see rcube_addressbook::rename_group()
* @param integer $gid
* @param string $newname
* @return boolean
*/
public function rename_group($gid, $newname)
{
return false;
}
/**
* @see rcube_addressbook::add_to_group()
* @param integer $group_id
* @param array $ids
* @return boolean
*/
public function add_to_group($group_id, $ids)
{
return false;
}
/**
* @see rcube_addressbook::remove_from_group()
* @param integer $group_id
* @param array $ids
* @return boolean
*/
public function remove_from_group($group_id, $ids)
{
return false;
}
/**
* Creates a new CardDAV addressbook contact
*
* @param array $save_data Associative array with save data
* @param boolean $check Check if the e-mail address already exists
* @return mixed The created record ID on success or false on error
*/
function insert($save_data, $check = false)
{
$rcmail = rcmail::get_instance();
if (!is_array($save_data))
{
return false;
}
if ($check !== false)
{
foreach ($save_data as $col => $values)
{
if (strpos($col, 'email') === 0)
{
foreach ((array)$values as $email)
{
if ($existing = $this->search('email', $email, false, false))
{
break 2;
}
}
}
}
}
$database_column_contents = $this->get_database_column_contents($save_data);
return $this->carddav_add($database_column_contents['vcard']);
}
/**
* Updates a CardDAV addressbook contact
*
* @param integer $carddav_contact_id CardDAV contact id
* @param array $save_data vCard parameters
* @return boolean
*/
public function update($carddav_contact_id, $save_data)
{
$record = $this->get_record($carddav_contact_id, true);
$database_column_contents = $this->get_database_column_contents($save_data, $record);
return $this->carddav_update($carddav_contact_id, $database_column_contents['vcard']);
}
/**
* Deletes one or more CardDAV addressbook contacts
*
* @param array $carddav_contact_ids Record identifiers
* @param boolean $force
* @return boolean
*/
public function delete($carddav_contact_ids, $force = true)
{
if (!is_array($carddav_contact_ids))
{
$carddav_contact_ids = explode(self::SEPARATOR, $carddav_contact_ids);
}