summaryrefslogtreecommitdiffstats
path: root/apps/contacts/ajax
diff options
context:
space:
mode:
Diffstat (limited to 'apps/contacts/ajax')
-rw-r--r--apps/contacts/ajax/addcard.php27
-rw-r--r--apps/contacts/ajax/addproperty.php28
-rw-r--r--apps/contacts/ajax/deletebook.php11
-rw-r--r--apps/contacts/ajax/deletecard.php17
-rw-r--r--apps/contacts/ajax/deleteproperty.php38
-rw-r--r--apps/contacts/ajax/getdetails.php45
-rw-r--r--apps/contacts/ajax/setproperty.php62
-rw-r--r--apps/contacts/ajax/showaddcard.php6
-rw-r--r--apps/contacts/ajax/showaddproperty.php16
-rw-r--r--apps/contacts/ajax/showsetproperty.php39
10 files changed, 60 insertions, 229 deletions
diff --git a/apps/contacts/ajax/addcard.php b/apps/contacts/ajax/addcard.php
index 0cecd3bdc06..9d782246a0a 100644
--- a/apps/contacts/ajax/addcard.php
+++ b/apps/contacts/ajax/addcard.php
@@ -23,26 +23,20 @@
// Init owncloud
require_once('../../../lib/base.php');
-$aid = $_POST['id'];
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$addressbook = OC_Contacts_Addressbook::find( $aid );
-if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your addressbook.')))); // Same here (as with the contact error). Could this error be improved?
- exit();
-}
+$aid = $_POST['id'];
+$addressbook = OC_Contacts_App::getAddressbook( $aid );
$fn = $_POST['fn'];
$values = $_POST['value'];
$parameters = $_POST['parameters'];
-$vcard = new Sabre_VObject_Component('VCARD');
-$vcard->add(new Sabre_VObject_Property('FN',$fn));
-$vcard->add(new Sabre_VObject_Property('UID',OC_Contacts_VCard::createUID()));
+$vcard = new OC_VObject('VCARD');
+$vcard->setUID();
+$vcard->setString('FN',$fn);
// Data to add ...
$add = array('TEL', 'EMAIL', 'ORG');
@@ -64,15 +58,8 @@ foreach( $add as $propname){
else{
$prop_parameters = array();
}
- OC_Contacts_VCard::addVCardProperty($vcard, $propname, $value, $prop_parameters);
+ $vcard->addProperty($propname, $value, $prop_parameters);
}
$id = OC_Contacts_VCard::add($aid,$vcard->serialize());
-$details = OC_Contacts_VCard::structureContact($vcard);
-$name = $details['FN'][0]['value'];
-$tmpl = new OC_Template('contacts','part.details');
-$tmpl->assign('details',$details);
-$tmpl->assign('id',$id);
-$page = $tmpl->fetchPage();
-
-OC_JSON::success(array('data' => array( 'id' => $id, 'name' => $name, 'page' => $page )));
+OC_Contacts_App::renderDetails($id, $vcard);
diff --git a/apps/contacts/ajax/addproperty.php b/apps/contacts/ajax/addproperty.php
index 101cfabbe84..98877805b46 100644
--- a/apps/contacts/ajax/addproperty.php
+++ b/apps/contacts/ajax/addproperty.php
@@ -23,40 +23,20 @@
// Init owncloud
require_once('../../../lib/base.php');
-$id = $_POST['id'];
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$card = OC_Contacts_VCard::find( $id );
-if( $card === false ){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
- exit();
-}
-
-$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
-if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
- exit();
-}
-
-$vcard = OC_Contacts_VCard::parse($card['carddata']);
-// Check if the card is valid
-if(is_null($vcard)){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.'))));
- exit();
-}
+$id = $_POST['id'];
+$vcard = OC_Contacts_App::getContactVCard( $id );
$name = $_POST['name'];
$value = $_POST['value'];
-$parameters = isset($_POST['parameteres'])?$_POST['parameters']:array();
+$parameters = isset($_POST['parameters'])?$_POST['parameters']:array();
-$property = OC_Contacts_VCard::addVCardProperty($vcard, $name, $value, $parameters);
+$property = $vcard->addProperty($name, $value, $parameters);
$line = count($vcard->children) - 1;
-$checksum = md5($property->serialize());
OC_Contacts_VCard::edit($id,$vcard->serialize());
diff --git a/apps/contacts/ajax/deletebook.php b/apps/contacts/ajax/deletebook.php
index c13217ef2e2..3ede17ab886 100644
--- a/apps/contacts/ajax/deletebook.php
+++ b/apps/contacts/ajax/deletebook.php
@@ -23,19 +23,12 @@
// Init owncloud
require_once('../../../lib/base.php');
-$id = $_GET['id'];
-
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$addressbook = OC_Contacts_Addressbook::find( $id );
-if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
- exit();
-}
+$id = $_GET['id'];
+$addressbook = OC_Contacts_App::getAddressbook( $id );
OC_Contacts_Addressbook::delete($id);
OC_JSON::success(array('data' => array( 'id' => $id )));
diff --git a/apps/contacts/ajax/deletecard.php b/apps/contacts/ajax/deletecard.php
index a0a6b8c3ea8..e26dfd6ebfe 100644
--- a/apps/contacts/ajax/deletecard.php
+++ b/apps/contacts/ajax/deletecard.php
@@ -23,25 +23,12 @@
// Init owncloud
require_once('../../../lib/base.php');
-$id = $_GET['id'];
-
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$card = OC_Contacts_VCard::find( $id );
-if( $card === false ){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
- exit();
-}
-
-$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
-if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
- exit();
-}
+$id = $_GET['id'];
+$card = OC_Contacts_App::getContactObject( $id );
OC_Contacts_VCard::delete($id);
OC_JSON::success(array('data' => array( 'id' => $id )));
diff --git a/apps/contacts/ajax/deleteproperty.php b/apps/contacts/ajax/deleteproperty.php
index 0a3a3c293a0..f69735e61c6 100644
--- a/apps/contacts/ajax/deleteproperty.php
+++ b/apps/contacts/ajax/deleteproperty.php
@@ -23,45 +23,15 @@
// Init owncloud
require_once('../../../lib/base.php');
-$id = $_GET['id'];
-$checksum = $_GET['checksum'];
-
-
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$card = OC_Contacts_VCard::find( $id );
-if( $card === false ){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
- exit();
-}
-
-$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
-if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
- exit();
-}
-
-$vcard = OC_Contacts_VCard::parse($card['carddata']);
-// Check if the card is valid
-if(is_null($vcard)){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.'))));
- exit();
-}
+$id = $_GET['id'];
+$checksum = $_GET['checksum'];
-$line = null;
-for($i=0;$i<count($vcard->children);$i++){
- if(md5($vcard->children[$i]->serialize()) == $checksum ){
- $line = $i;
- }
-}
-if(is_null($line)){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('Information about vCard is incorrect. Please reload the page.'))));
- exit();
-}
+$vcard = OC_Contacts_App::getContactVCard( $id );
+$line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum);
unset($vcard->children[$line]);
diff --git a/apps/contacts/ajax/getdetails.php b/apps/contacts/ajax/getdetails.php
index 260fb53a686..8cc0f9cbb0f 100644
--- a/apps/contacts/ajax/getdetails.php
+++ b/apps/contacts/ajax/getdetails.php
@@ -23,50 +23,11 @@
// Init owncloud
require_once('../../../lib/base.php');
-$id = $_GET['id'];
-
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
+$id = $_GET['id'];
+$vcard = OC_Contacts_App::getContactVCard( $id );
-$card = OC_Contacts_VCard::find( $id );
-if( $card === false ){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
- exit();
-}
-
-$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
-if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
- exit();
-}
-
-$vcard = OC_Contacts_VCard::parse($card['carddata']);
-// Check if the card is valid
-if(is_null($vcard)){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.'))));
- exit();
-}
-
-$property_types = array(
- 'ADR' => $l10n->t('Address'),
- 'TEL' => $l10n->t('Telephone'),
- 'EMAIL' => $l10n->t('Email'),
- 'ORG' => $l10n->t('Organization'),
-);
-$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
-$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
-
-$details = OC_Contacts_VCard::structureContact($vcard);
-$tmpl = new OC_Template('contacts','part.details');
-$tmpl->assign('details',$details);
-$tmpl->assign('id',$id);
-$tmpl->assign('property_types',$property_types);
-$tmpl->assign('adr_types',$adr_types);
-$tmpl->assign('phone_types',$phone_types);
-$page = $tmpl->fetchPage();
-
-OC_JSON::success(array('data' => array( 'id' => $id, 'page' => $page )));
+OC_Contacts_App::renderDetails($id, $vcard);
diff --git a/apps/contacts/ajax/setproperty.php b/apps/contacts/ajax/setproperty.php
index 18e00872473..bcc4c161cc0 100644
--- a/apps/contacts/ajax/setproperty.php
+++ b/apps/contacts/ajax/setproperty.php
@@ -23,53 +23,28 @@
// Init owncloud
require_once('../../../lib/base.php');
-$id = $_POST['id'];
-$checksum = $_POST['checksum'];
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$card = OC_Contacts_VCard::find( $id );
-if( $card === false ){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
- exit();
-}
-
-$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
-if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
- exit();
-}
-
-$vcard = OC_Contacts_VCard::parse($card['carddata']);
-// Check if the card is valid
-if(is_null($vcard)){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.'))));
- exit();
-}
+$id = $_POST['id'];
+$checksum = $_POST['checksum'];
-$line = null;
-for($i=0;$i<count($vcard->children);$i++){
- if(md5($vcard->children[$i]->serialize()) == $checksum ){
- $line = $i;
- }
-}
-if(is_null($line)){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('Information about vCard is incorrect. Please reload the page.'))));
- exit();
-}
+$vcard = OC_Contacts_App::getContactVCard( $id );
+$line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum);
// Set the value
$value = $_POST['value'];
if(is_array($value)){
- $value = OC_Contacts_VCard::escapeSemicolons($value);
+ $value = OC_VObject::escapeSemicolons($value);
}
$vcard->children[$line]->setValue($value);
// Add parameters
$postparameters = isset($_POST['parameters'])?$_POST['parameters']:array();
+if ($vcard->children[$line]->name == 'TEL' && !array_key_exists('TYPE', $postparameters)){
+ $postparameters['TYPE']='';
+}
for($i=0;$i<count($vcard->children[$line]->parameters);$i++){
$name = $vcard->children[$line]->parameters[$i]->name;
if(array_key_exists($name,$postparameters)){
@@ -77,7 +52,14 @@ for($i=0;$i<count($vcard->children[$line]->parameters);$i++){
unset($vcard->children[$line]->parameters[$i]);
}
else{
- $vcard->children[$line]->parameters[$i]->value = $postparameters[$name];
+ unset($vcard->children[$line][$name]);
+ $values = $postparameters[$name];
+ if (!is_array($values)){
+ $values = array($values);
+ }
+ foreach($values as $value){
+ $vcard->children[$line]->add($name, $value);
+ }
}
unset($postparameters[$name]);
}
@@ -94,7 +76,17 @@ $checksum = md5($vcard->children[$line]->serialize());
OC_Contacts_VCard::edit($id,$vcard->serialize());
-$tmpl = new OC_Template('contacts','part.property');
+$adr_types = OC_Contacts_App::getTypesOfProperty('ADR');
+$phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
+
+if ($vcard->children[$line]->name == 'FN'){
+ $tmpl = new OC_Template('contacts','part.property.FN');
+}
+else{
+ $tmpl = new OC_Template('contacts','part.property');
+}
+$tmpl->assign('adr_types',$adr_types);
+$tmpl->assign('phone_types',$phone_types);
$tmpl->assign('property',OC_Contacts_VCard::structureProperty($vcard->children[$line],$line));
$page = $tmpl->fetchPage();
diff --git a/apps/contacts/ajax/showaddcard.php b/apps/contacts/ajax/showaddcard.php
index 98367758fd4..54592c89c0d 100644
--- a/apps/contacts/ajax/showaddcard.php
+++ b/apps/contacts/ajax/showaddcard.php
@@ -23,14 +23,12 @@
// Init owncloud
require_once('../../../lib/base.php');
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
-$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
+$adr_types = OC_Contacts_App::getTypesOfProperty('ADR');
+$phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
$addressbooks = OC_Contacts_Addressbook::all(OC_USER::getUser());
$tmpl = new OC_Template('contacts','part.addcardform');
diff --git a/apps/contacts/ajax/showaddproperty.php b/apps/contacts/ajax/showaddproperty.php
index f87cd05359b..30eb7634f80 100644
--- a/apps/contacts/ajax/showaddproperty.php
+++ b/apps/contacts/ajax/showaddproperty.php
@@ -23,24 +23,12 @@
// Init owncloud
require_once('../../../lib/base.php');
-$id = $_GET['id'];
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$card = OC_Contacts_VCard::find( $id );
-if( $card === false ){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
- exit();
-}
-
-$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
-if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
- exit();
-}
+$id = $_GET['id'];
+$card = OC_Contacts_App::getContactObject( $id );
$tmpl = new OC_Template('contacts','part.addpropertyform');
$tmpl->assign('id',$id);
diff --git a/apps/contacts/ajax/showsetproperty.php b/apps/contacts/ajax/showsetproperty.php
index 4ec3dd7d8e1..e23fa21c56b 100644
--- a/apps/contacts/ajax/showsetproperty.php
+++ b/apps/contacts/ajax/showsetproperty.php
@@ -23,51 +23,26 @@
// Init owncloud
require_once('../../../lib/base.php');
-$id = $_GET['id'];
-$checksum = $_GET['checksum'];
-$l10n = new OC_L10N('contacts');
-
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$card = OC_Contacts_VCard::find( $id );
-if( $card === false ){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
- exit();
-}
-
-$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
-if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
- exit();
-}
+$id = $_GET['id'];
+$checksum = $_GET['checksum'];
-$vcard = OC_Contacts_VCard::parse($card['carddata']);
-// Check if the card is valid
-if(is_null($vcard)){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.'))));
- exit();
-}
+$vcard = OC_Contacts_App::getContactVCard( $id );
-$line = null;
-for($i=0;$i<count($vcard->children);$i++){
- if(md5($vcard->children[$i]->serialize()) == $checksum ){
- $line = $i;
- }
-}
-if(is_null($line)){
- OC_JSON::error(array('data' => array( 'message' => $l10n->t('Information about vCard is incorrect. Please reload the page.'))));
- exit();
-}
+$line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum);
-$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
+$adr_types = OC_Contacts_App::getTypesOfProperty('ADR');
+$phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
$tmpl = new OC_Template('contacts','part.setpropertyform');
$tmpl->assign('id',$id);
$tmpl->assign('checksum',$checksum);
$tmpl->assign('property',OC_Contacts_VCard::structureProperty($vcard->children[$line]));
$tmpl->assign('adr_types',$adr_types);
+$tmpl->assign('phone_types',$phone_types);
$page = $tmpl->fetchPage();
OC_JSON::success(array('data' => array( 'page' => $page )));