Example #1
0
 public static function getBirthdayEvents($parameters)
 {
     $name = $parameters['calendar_id'];
     if (strpos('birthday_', $name) != 0) {
         return;
     }
     $info = explode('_', $name);
     $aid = $info[1];
     OC_Contacts_App::getAddressbook($aid);
     foreach (OC_Contacts_VCard::all($aid) as $card) {
         $vcard = OC_VObject::parse($card['carddata']);
         if (!$vcard) {
             continue;
         }
         $birthday = $vcard->BDAY;
         if ($birthday) {
             $date = new DateTime($birthday);
             $vevent = new OC_VObject('VEVENT');
             $vevent->setDateTime('LAST-MODIFIED', new DateTime($vcard->REV));
             $vevent->setDateTime('DTSTART', $date, Sabre_VObject_Element_DateTime::DATE);
             $vevent->setString('DURATION', 'P1D');
             // DESCRIPTION?
             $vevent->setString('RRULE', 'FREQ=YEARLY');
             $title = str_replace('{name}', $vcard->getAsString('FN'), OC_Contacts_App::$l10n->t('{name}\'s Birthday'));
             $parameters['events'][] = array('id' => 0, 'vevent' => $vevent, 'repeating' => true, 'summary' => $title);
         }
     }
 }
Example #2
0
 public static function getBirthdayEvents($parameters)
 {
     $name = $parameters['calendar_id'];
     if (strpos($name, 'birthday_') != 0) {
         return;
     }
     $info = explode('_', $name);
     $aid = $info[1];
     OC_Contacts_App::getAddressbook($aid);
     foreach (OC_Contacts_VCard::all($aid) as $card) {
         $vcard = OC_VObject::parse($card['carddata']);
         if (!$vcard) {
             continue;
         }
         $birthday = $vcard->BDAY;
         if ($birthday) {
             $date = new DateTime($birthday);
             $vevent = new OC_VObject('VEVENT');
             //$vevent->setDateTime('LAST-MODIFIED', new DateTime($vcard->REV));
             $vevent->setDateTime('DTSTART', $date, Sabre_VObject_Element_DateTime::DATE);
             $vevent->setString('DURATION', 'P1D');
             $vevent->setString('UID', substr(md5(rand() . time()), 0, 10));
             // DESCRIPTION?
             $vevent->setString('RRULE', 'FREQ=YEARLY');
             $title = str_replace('{name}', $vcard->getAsString('FN'), OC_Contacts_App::$l10n->t('{name}\'s Birthday'));
             $parameters['events'][] = array('id' => 0, 'vevent' => $vevent, 'repeating' => true, 'summary' => $title, 'calendardata' => "BEGIN:VCALENDAR\nVERSION:2.0\n" . "PRODID:ownCloud Contacts " . OCP\App::getAppVersion('contacts') . "\n" . $vevent->serialize() . "END:VCALENDAR");
         }
     }
 }
 function search($query)
 {
     $addressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser(), 1);
     // 		if(count($calendars)==0 || !OCP\App::isEnabled('contacts')){
     // 			//return false;
     // 		}
     // NOTE: Does the following do anything
     $results = array();
     $searchquery = array();
     if (substr_count($query, ' ') > 0) {
         $searchquery = explode(' ', $query);
     } else {
         $searchquery[] = $query;
     }
     $l = new OC_l10n('contacts');
     foreach ($addressbooks as $addressbook) {
         $vcards = OC_Contacts_VCard::all($addressbook['id']);
         foreach ($vcards as $vcard) {
             if (substr_count(strtolower($vcard['fullname']), strtolower($query)) > 0) {
                 $link = OCP\Util::linkTo('contacts', 'index.php') . '?id=' . urlencode($vcard['id']);
                 $results[] = new OC_Search_Result($vcard['fullname'], '', $link, $l->t('Contact'));
                 //$name,$text,$link,$type
             }
         }
     }
     return $results;
 }
Example #4
0
 public function formatItems($items, $format, $parameters = null)
 {
     $contacts = array();
     if ($format == self::FORMAT_CONTACT) {
         foreach ($items as $item) {
             $contact = OC_Contacts_VCard::find($item['item_source']);
             $contact['fullname'] = $item['item_target'];
             $contacts[] = $contact;
         }
     }
     return $contacts;
 }
Example #5
0
 function search($query)
 {
     $addressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser(), 1);
     if (count($addressbooks) == 0 || !OCP\App::isEnabled('contacts')) {
         return array();
     }
     $results = array();
     $l = new OC_l10n('contacts');
     foreach ($addressbooks as $addressbook) {
         $vcards = OC_Contacts_VCard::all($addressbook['id']);
         foreach ($vcards as $vcard) {
             if (substr_count(strtolower($vcard['fullname']), strtolower($query)) > 0) {
                 $link = OCP\Util::linkTo('contacts', 'index.php') . '&id=' . urlencode($vcard['id']);
                 $results[] = new OC_Search_Result($vcard['fullname'], '', $link, (string) $l->t('Contact'));
                 //$name,$text,$link,$type
             }
         }
     }
     return $results;
 }
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
// 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;
}
OC_Contacts_VCard::delete($id);
OC_JSON::success(array('data' => array('id' => $id)));
Example #7
0
        if (!$view->unlink('/imports/' . $_POST['file'])) {
            OCP\Util::writeLog('contacts', 'Import: Error unlinking OC_FilesystemView ' . '/' . $_POST['file'], OCP\Util::ERROR);
        }
    }
    exit;
}
foreach ($parts as $part) {
    $card = OC_VObject::parse($part);
    if (!$card) {
        $failed += 1;
        OCP\Util::writeLog('contacts', 'Import: skipping card. Error parsing VCard: ' . $part, OCP\Util::ERROR);
        continue;
        // Ditch cards that can't be parsed by Sabre.
    }
    try {
        OC_Contacts_VCard::add($id, $card);
        $imported += 1;
    } catch (Exception $e) {
        OCP\Util::writeLog('contacts', 'Error importing vcard: ' . $e->getMessage() . $nl . $card, OCP\Util::ERROR);
        $failed += 1;
    }
}
//done the import
writeProgress('100');
sleep(3);
OC_Cache::remove($progresskey);
if (isset($_POST['fstype']) && $_POST['fstype'] == 'OC_FilesystemView') {
    if (!$view->unlink('/imports/' . $_POST['file'])) {
        OCP\Util::writeLog('contacts', 'Import: Error unlinking OC_FilesystemView ' . '/' . $_POST['file'], OCP\Util::ERROR);
    }
}
Example #8
0
 /**
  * Deletes a card
  *
  * @param mixed $addressbookid
  * @param string $carduri
  * @return bool
  */
 public function deleteCard($addressbookid, $carduri)
 {
     return OC_Contacts_VCard::deleteFromDAVData($addressbookid, $carduri);
 }
OCP\JSON::checkAppEnabled('contacts');
function bailOut($msg)
{
    OCP\JSON::error(array('data' => array('message' => $msg)));
    OCP\Util::writeLog('contacts', 'ajax/editname.php: ' . $msg, OCP\Util::DEBUG);
    exit;
}
function debug($msg)
{
    OCP\Util::writeLog('contacts', 'ajax/editname.php: ' . $msg, OCP\Util::DEBUG);
}
$tmpl = new OCP\Template("contacts", "part.edit_name_dialog");
$id = isset($_GET['id']) ? $_GET['id'] : '';
debug('id: ' . $id);
if ($id) {
    $vcard = OC_Contacts_App::getContactVCard($id);
    $name = array('', '', '', '', '');
    if ($vcard->__isset('N')) {
        $property = $vcard->__get('N');
        if ($property) {
            $name = OC_Contacts_VCard::structureProperty($property);
        }
    }
    $tmpl->assign('name', $name);
    $tmpl->assign('id', $id);
} else {
    bailOut(OC_Contacts_App::$l10n->t('Contact ID is missing.'));
    //$addressbooks = OC_Contacts_Addressbook::active(OCP\USER::getUser());
    //$tmpl->assign('addressbooks', $addressbooks);
}
$tmpl->printpage();
Example #10
0
            debug('Setting string:' . $name . ' ' . $value);
            $vcard->children[$line]->setValue($value);
            break;
        case 'EMAIL':
        case 'TEL':
        case 'ADR':
            // should I delete the property if empty or throw an error?
            debug('Setting element: (EMAIL/TEL/ADR)' . $element);
            $vcard->children[$line]->setValue($value);
            $vcard->children[$line]->parameters = array();
            if (!is_null($parameters)) {
                debug('Setting parameters: ' . $parameters);
                foreach ($parameters as $key => $parameter) {
                    debug('Adding parameter: ' . $key);
                    foreach ($parameter as $val) {
                        debug('Adding parameter: ' . $key . '=>' . $val);
                        $vcard->children[$line]->add(new Sabre_VObject_Parameter($key, strtoupper(strip_tags($val))));
                    }
                }
            }
            break;
    }
    // Do checksum and be happy
    $checksum = md5($vcard->children[$line]->serialize());
}
//debug('New checksum: '.$checksum);
if (!OC_Contacts_VCard::edit($id, $vcard)) {
    bailOut(OC_Contacts_App::$l10n->t('Error updating contact property.'));
    exit;
}
OCP\JSON::success(array('data' => array('line' => $line, 'checksum' => $checksum, 'oldchecksum' => $_POST['checksum'])));
 *
 */
// 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;
}
$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;
}
$details = OC_Contacts_VCard::structureContact($vcard);
$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, 'page' => $page)));
Example #12
0
<?php

/**
 * Copyright (c) 2012 Thomas Tanghus <*****@*****.**>
 * Copyright (c) 2011 Jakob Sack mail@jakobsack.de
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
// Check if we are a user
OCP\User::checkLoggedIn();
OCP\App::checkAppEnabled('contacts');
// Get active address books. This creates a default one if none exists.
$ids = OC_Contacts_Addressbook::activeIds(OCP\USER::getUser());
$has_contacts = count(OC_Contacts_VCard::all($ids, 0, 1)) > 0 ? true : false;
// just to check if there are any contacts.
if ($has_contacts === false) {
    OCP\Util::writeLog('contacts', 'index.html: No contacts found.', OCP\Util::DEBUG);
}
// Load the files we need
OCP\App::setActiveNavigationEntry('contacts_index');
// Load a specific user?
$id = isset($_GET['id']) ? $_GET['id'] : null;
$impp_types = OC_Contacts_App::getTypesOfProperty('IMPP');
$phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
$email_types = OC_Contacts_App::getTypesOfProperty('EMAIL');
$ims = OC_Contacts_App::getIMOptions();
$im_protocols = array();
foreach ($ims as $name => $values) {
    $im_protocols[$name] = $values['displayname'];
}
Example #13
0
<?php

/**
 * Copyright (c) 2011-2012 Thomas Tanghus <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
OCP\User::checkLoggedIn();
OCP\App::checkAppEnabled('contacts');
$bookid = isset($_GET['bookid']) ? $_GET['bookid'] : NULL;
$contactid = isset($_GET['contactid']) ? $_GET['contactid'] : NULL;
$nl = "\n";
if (isset($bookid)) {
    $addressbook = OC_Contacts_App::getAddressbook($bookid);
    $cardobjects = OC_Contacts_VCard::all($bookid);
    header('Content-Type: text/directory');
    header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $addressbook['displayname']) . '.vcf');
    foreach ($cardobjects as $card) {
        echo $card['carddata'] . $nl;
    }
} elseif (isset($contactid)) {
    $data = OC_Contacts_App::getContactObject($contactid);
    header('Content-Type: text/directory');
    header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $data['fullname']) . '.vcf');
    echo $data['carddata'];
}
 /**
  * @brief removes an address book
  * @param integer $id
  * @return boolean
  */
 public static function delete($id)
 {
     $stmt = OC_DB::prepare('DELETE FROM *PREFIX*contacts_addressbooks WHERE id = ?');
     $stmt->execute(array($id));
     $cards = OC_Contacts_VCard::all($id);
     foreach ($cards as $card) {
         OC_Contacts_VCard::delete($card['id']);
     }
     return true;
 }
Example #15
0
 /**
  * @brief removes an address book
  * @param integer $id
  * @return boolean
  */
 public static function delete($id)
 {
     // FIXME: There's no error checking at all.
     self::setActive($id, false);
     $stmt = OCP\DB::prepare('DELETE FROM *PREFIX*contacts_addressbooks WHERE id = ?');
     $stmt->execute(array($id));
     $cards = OC_Contacts_VCard::all($id);
     foreach ($cards as $card) {
         OC_Contacts_VCard::delete($card['id']);
     }
     return true;
 }
$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;
}
$name = $_POST['name'];
$value = $_POST['value'];
$parameters = isset($_POST['parameteres']) ? $_POST['parameters'] : array();
$property = OC_Contacts_VCard::addVCardProperty($vcard, $name, $value, $parameters);
$line = count($vcard->children) - 1;
$checksum = md5($property->serialize());
OC_Contacts_VCard::edit($id, $vcard->serialize());
$tmpl = new OC_Template('contacts', 'part.property');
$tmpl->assign('property', OC_Contacts_VCard::structureProperty($property, $line));
$page = $tmpl->fetchPage();
OC_JSON::success(array('data' => array('page' => $page)));
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;
}
$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;
}
$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]));
$page = $tmpl->fetchPage();
OC_JSON::success(array('data' => array('page' => $page)));
Example #18
0
 * Copyright (c) 2011 Thomas Tanghus <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
$id = $_GET['id'];
$checksum = isset($_GET['checksum']) ? $_GET['checksum'] : '';
$vcard = OC_Contacts_App::getContactVCard($id);
$adr_types = OC_Contacts_App::getTypesOfProperty('ADR');
$tmpl = new OCP\Template("contacts", "part.edit_address_dialog");
if ($checksum) {
    $line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum);
    $element = $vcard->children[$line];
    $adr = OC_Contacts_VCard::structureProperty($element);
    $types = array();
    if (isset($adr['parameters']['TYPE'])) {
        if (is_array($adr['parameters']['TYPE'])) {
            $types = array_map('htmlspecialchars', $adr['parameters']['TYPE']);
            $types = array_map('strtoupper', $types);
        } else {
            $types = array(strtoupper(htmlspecialchars($adr['parameters']['TYPE'])));
        }
    }
    $tmpl->assign('types', $types, false);
    $adr = array_map('htmlspecialchars', $adr['value']);
    $tmpl->assign('adr', $adr, false);
}
$tmpl->assign('id', $id);
$tmpl->assign('adr_types', $adr_types);
Example #19
0
/**
 * Copyright (c) 2011-2012 Thomas Tanghus <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
OCP\User::checkLoggedIn();
OCP\App::checkAppEnabled('contacts');
$bookid = isset($_GET['bookid']) ? $_GET['bookid'] : null;
$contactid = isset($_GET['contactid']) ? $_GET['contactid'] : null;
$nl = "\n";
if (isset($bookid)) {
    $addressbook = OC_Contacts_App::getAddressbook($bookid);
    //$cardobjects = OC_Contacts_VCard::all($bookid);
    header('Content-Type: text/directory');
    header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $addressbook['displayname']) . '.vcf');
    $start = 0;
    $batchsize = OCP\Config::getUserValue(OCP\User::getUser(), 'contacts', 'export_batch_size', 20);
    while ($cardobjects = OC_Contacts_VCard::all($bookid, $start, $batchsize)) {
        foreach ($cardobjects as $card) {
            echo $card['carddata'] . $nl;
        }
        $start += $batchsize;
    }
} elseif (isset($contactid)) {
    $data = OC_Contacts_App::getContactObject($contactid);
    header('Content-Type: text/vcard');
    header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $data['fullname']) . '.vcf');
    echo $data['carddata'];
}
Example #20
0
<?php

/**
* @author  Victor Dubiniuk
* Copyright (c) 2012 Victor Dubiniuk <*****@*****.**>
* Copyright (c) 2012 Thomas Tanghus <*****@*****.**>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
$id = intval($_POST['id']);
$aid = intval($_POST['aid']);
$isaddressbook = isset($_POST['isaddressbook']) ? true : false;
// Ownership checking
OC_Contacts_App::getAddressbook($aid);
try {
    OC_Contacts_VCard::moveToAddressBook($aid, $id, $isaddressbook);
} catch (Exception $e) {
    $msg = $e->getMessage();
    OCP\Util::writeLog('contacts', 'Error moving contacts "' . implode(',', $id) . '" to addressbook "' . $aid . '"' . $msg, OCP\Util::ERROR);
    OC_JSON::error(array('data' => array('message' => $msg)));
}
OC_JSON::success(array('data' => array('ids' => $id)));
Example #21
0
function bailOut($msg)
{
    OCP\JSON::error(array('data' => array('message' => $msg)));
    OCP\Util::writeLog('contacts', 'ajax/addcontact.php: ' . $msg, OCP\Util::DEBUG);
    exit;
}
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
$aid = isset($_POST['aid']) ? $_POST['aid'] : null;
if (!$aid) {
    $aid = min(OC_Contacts_Addressbook::activeIds());
    // first active addressbook.
}
OC_Contacts_App::getAddressbook($aid);
// is owner access check
$isnew = isset($_POST['isnew']) ? $_POST['isnew'] : false;
$fn = trim($_POST['fn']);
$n = trim($_POST['n']);
$vcard = new OC_VObject('VCARD');
$vcard->setUID();
$vcard->setString('FN', $fn);
$vcard->setString('N', $n);
$id = OC_Contacts_VCard::add($aid, $vcard, null, $isnew);
if (!$id) {
    OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('There was an error adding the contact.'))));
    OCP\Util::writeLog('contacts', 'ajax/addcontact.php: Recieved non-positive ID on adding card: ' . $id, OCP\Util::ERROR);
    exit;
}
OCP\JSON::success(array('data' => array('id' => $id)));
Example #22
0
 */
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
foreach ($_POST as $key => $element) {
    debug('_POST: ' . $key . '=>' . print_r($element, true));
}
function bailOut($msg)
{
    OCP\JSON::error(array('data' => array('message' => $msg)));
    OCP\Util::writeLog('contacts', 'ajax/categories/rescan.php: ' . $msg, OCP\Util::DEBUG);
    exit;
}
function debug($msg)
{
    OCP\Util::writeLog('contacts', 'ajax/categories/rescan.php: ' . $msg, OCP\Util::DEBUG);
}
$addressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser());
if (count($addressbooks) == 0) {
    bailOut(OC_Contacts_App::$l10n->t('No address books found.'));
}
$addressbookids = array();
foreach ($addressbooks as $addressbook) {
    $addressbookids[] = $addressbook['id'];
}
$contacts = OC_Contacts_VCard::all($addressbookids);
if (count($contacts) == 0) {
    bailOut(OC_Contacts_App::$l10n->t('No contacts found.'));
}
OC_Contacts_App::scanCategories($contacts);
$categories = OC_Contacts_App::getCategories();
OCP\JSON::success(array('data' => array('categories' => $categories)));
Example #23
0
<?php

/**
 * Copyright (c) 2011 Thomas Tanghus <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
$ids = OC_Contacts_Addressbook::activeIds(OCP\USER::getUser());
$allcontacts = OC_Contacts_VCard::all($ids);
$contacts = array();
foreach ($allcontacts as $contact) {
    // try to conserve some memory
    $contacts[] = array('id' => $contact['id'], 'addressbookid' => $contact['addressbookid'], 'fullname' => $contact['fullname']);
}
unset($allcontacts);
$addressbooks = OC_Contacts_Addressbook::active(OCP\USER::getUser());
$tmpl = new OCP\Template("contacts", "part.contacts");
$tmpl->assign('contacts', $contacts);
$page = $tmpl->fetchPage();
OCP\JSON::success(array('data' => array('page' => $page)));
 /**
  * @brief Add property to vcard object
  * @param object $vcard
  * @param object $name of property
  * @param object $value of property
  * @param object $paramerters of property
  */
 public static function addVCardProperty($vcard, $name, $value, $parameters = array())
 {
     if (is_array($value)) {
         $value = OC_Contacts_VCard::escapeSemicolons($value);
     }
     $property = new Sabre_VObject_Property($name, $value);
     $parameternames = array_keys($parameters);
     foreach ($parameternames as $i) {
         $property->parameters[] = new Sabre_VObject_Parameter($i, $parameters[$i]);
     }
     $vcard->add($property);
     return $property;
 }
Example #25
0
 /**
  * scan vcards for categories.
  * @param $vccontacts VCards to scan. null to check all vcards for the current user.
  */
 public static function scanCategories($vccontacts = null)
 {
     if (is_null($vccontacts)) {
         $vcaddressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser());
         if (count($vcaddressbooks) > 0) {
             $vcaddressbookids = array();
             foreach ($vcaddressbooks as $vcaddressbook) {
                 $vcaddressbookids[] = $vcaddressbook['id'];
             }
             $vccontacts = OC_Contacts_VCard::all($vcaddressbookids);
         }
     }
     if (is_array($vccontacts) && count($vccontacts) > 0) {
         $cards = array();
         foreach ($vccontacts as $vccontact) {
             $cards[] = $vccontact['carddata'];
         }
         self::$categories->rescan($cards);
     }
 }
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;
}
$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;
}
unset($vcard->children[$line]);
OC_Contacts_VCard::edit($id, $vcard->serialize());
OC_JSON::success(array('data' => array('id' => $id)));
OC_Util::checkLoggedIn();
OC_Util::checkAppEnabled('contacts');
$id = $_GET['id'];
$l10n = new OC_L10N('contacts');
$card = OC_Contacts_VCard::find($id);
if ($card === false) {
    echo $l10n->t('Contact could not be found.');
    exit;
}
$addressbook = OC_Contacts_Addressbook::find($card['addressbookid']);
if ($addressbook === false || $addressbook['userid'] != OC_USER::getUser()) {
    echo $l10n->t('This is not your contact.');
    // This is a weird error, why would it come up? (Better feedback for users?)
    exit;
}
$content = OC_Contacts_VCard::parse($card['carddata']);
// invalid vcard
if (is_null($content)) {
    echo $l10n->t('This card is not RFC compatible.');
    exit;
}
// Photo :-)
foreach ($content->children as $child) {
    if ($child->name == 'PHOTO') {
        $mime = 'image/jpeg';
        foreach ($child->parameters as $parameter) {
            if ($parameter->name == 'TYPE') {
                $mime = $parameter->value;
            }
        }
        $photo = base64_decode($child->value);
<?php

foreach ($_['contacts'] as $contact) {
    $display = trim($contact['fullname']);
    if (!$display) {
        $vcard = OC_Contacts_App::getContactVCard($contact['id']);
        if (!is_null($vcard)) {
            $struct = OC_Contacts_VCard::structureContact($vcard);
            $display = isset($struct['EMAIL'][0]) ? $struct['EMAIL'][0]['value'] : '[UNKNOWN]';
        }
    }
    ?>
	<li role="button" book-id="<?php 
    echo $contact['addressbookid'];
    ?>
" data-id="<?php 
    echo $contact['id'];
    ?>
"><a href="index.php?id=<?php 
    echo $contact['id'];
    ?>
"><?php 
    echo htmlspecialchars($display);
    ?>
</a></li>
<?php 
}
Example #29
0
function debug($msg)
{
    OCP\Util::writeLog('contacts', 'ajax/categories/delete.php: ' . $msg, OCP\Util::DEBUG);
}
$categories = isset($_POST['categories']) ? $_POST['categories'] : null;
if (is_null($categories)) {
    bailOut(OC_Contacts_App::$l10n->t('No categories selected for deletion.'));
}
debug(print_r($categories, true));
$addressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser());
if (count($addressbooks) == 0) {
    bailOut(OC_Contacts_App::$l10n->t('No address books found.'));
}
$addressbookids = array();
foreach ($addressbooks as $addressbook) {
    $addressbookids[] = $addressbook['id'];
}
$contacts = OC_Contacts_VCard::all($addressbookids);
if (count($contacts) == 0) {
    bailOut(OC_Contacts_App::$l10n->t('No contacts found.'));
}
$cards = array();
foreach ($contacts as $contact) {
    $cards[] = array($contact['id'], $contact['carddata']);
}
debug('Before delete: ' . print_r($categories, true));
$catman = new OC_VCategories('contacts');
$catman->delete($categories, $cards);
debug('After delete: ' . print_r($catman->categories(), true));
OC_Contacts_VCard::updateDataByID($cards);
OCP\JSON::success(array('data' => array('categories' => $catman->categories())));
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
// 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;
}
$tmpl = new OC_Template('contacts', 'part.addpropertyform');
$tmpl->assign('id', $id);
$page = $tmpl->fetchPage();
OC_JSON::success(array('data' => array('page' => $page)));