示例#1
0
 function import()
 {
     switch ($this->appinfo->version) {
         default:
             // All versions of the app have had the same db structure, so all can use the same import function
             $query = $this->content->prepare('SELECT * FROM `contacts_addressbooks` WHERE `userid` LIKE ?');
             $results = $query->execute(array($this->olduid));
             $idmap = array();
             while ($row = $results->fetchRow()) {
                 // Import each addressbook
                 $addressbookquery = OCP\DB::prepare('INSERT INTO `*PREFIX*contacts_addressbooks` (`userid`, `displayname`, `uri`, `description`, `ctag`) VALUES (?, ?, ?, ?, ?)');
                 $addressbookquery->execute(array($this->uid, $row['displayname'], $row['uri'], $row['description'], $row['ctag']));
                 // Map the id
                 $idmap[$row['id']] = OCP\DB::insertid('*PREFIX*contacts_addressbooks');
                 // Make the addressbook active
                 OC_Contacts_Addressbook::setActive($idmap[$row['id']], true);
             }
             // Now tags
             foreach ($idmap as $oldid => $newid) {
                 $query = $this->content->prepare('SELECT * FROM `contacts_cards` WHERE `addressbookid` LIKE ?');
                 $results = $query->execute(array($oldid));
                 while ($row = $results->fetchRow()) {
                     // Import the contacts
                     $contactquery = OCP\DB::prepare('INSERT INTO `*PREFIX*contacts_cards` (`addressbookid`, `fullname`, `carddata`, `uri`, `lastmodified`) VALUES (?, ?, ?, ?, ?)');
                     $contactquery->execute(array($newid, $row['fullname'], $row['carddata'], $row['uri'], $row['lastmodified']));
                 }
             }
             // All done!
             break;
     }
     return true;
 }
示例#2
0
<?php

/**
 * Copyright (c) 2011 Thomas Tanghus <*****@*****.**>
 * Copyright (c) 2011 Bart Visscher <*****@*****.**>
 * 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();
$bookid = $_POST['bookid'];
$book = OC_Contacts_App::getAddressbook($bookid);
// is owner access check
if (!OC_Contacts_Addressbook::setActive($bookid, $_POST['active'])) {
    OCP\Util::writeLog('contacts', 'ajax/activation.php: Error activating addressbook: ' . $bookid, OCP\Util::ERROR);
    OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error (de)activating addressbook.'))));
    exit;
}
OCP\JSON::success(array('active' => OC_Contacts_Addressbook::isActive($bookid), 'bookid' => $bookid, 'book' => $book));
 * Copyright (c) 2011-2012 Thomas Tanghus <*****@*****.**>
 * Copyright (c) 2011 Bart Visscher <*****@*****.**>
 * 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\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
$userid = OCP\USER::getUser();
$name = trim(strip_tags($_POST['name']));
if (!$name) {
    OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Cannot add addressbook with an empty name.'))));
    OCP\Util::writeLog('contacts', 'ajax/createaddressbook.php: Cannot add addressbook with an empty name: ' . strip_tags($_POST['name']), OCP\Util::ERROR);
    exit;
}
$bookid = OC_Contacts_Addressbook::add($userid, $name, null);
if (!$bookid) {
    OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error adding addressbook.'))));
    OCP\Util::writeLog('contacts', 'ajax/createaddressbook.php: Error adding addressbook: ' . $_POST['name'], OCP\Util::ERROR);
    exit;
}
if (!OC_Contacts_Addressbook::setActive($bookid, 1)) {
    OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error activating addressbook.'))));
    OCP\Util::writeLog('contacts', 'ajax/createaddressbook.php: Error activating addressbook: ' . $bookid, OCP\Util::ERROR);
    //exit();
}
$addressbook = OC_Contacts_App::getAddressbook($bookid);
$tmpl = new OCP\Template('contacts', 'part.chooseaddressbook.rowfields');
$tmpl->assign('addressbook', $addressbook);
OCP\JSON::success(array('page' => $tmpl->fetchPage(), 'addressbook' => $addressbook));
示例#4
0
    $view = OCP\Files::getStorage('contacts');
    $file = $view->file_get_contents('/imports/' . $_POST['file']);
} else {
    $file = OC_Filesystem::file_get_contents($_POST['path'] . '/' . $_POST['file']);
}
if (!$file) {
    OCP\JSON::error(array('data' => array('message' => 'Import file was empty.')));
    exit;
}
if (isset($_POST['method']) && $_POST['method'] == 'new') {
    $id = OC_Contacts_Addressbook::add(OCP\USER::getUser(), $_POST['addressbookname']);
    if (!$id) {
        OCP\JSON::error(array('data' => array('message' => 'Error creating address book.')));
        exit;
    }
    OC_Contacts_Addressbook::setActive($id, 1);
} else {
    $id = $_POST['id'];
    if (!$id) {
        OCP\JSON::error(array('data' => array('message' => 'Error getting the ID of the address book.', 'file' => $_POST['file'])));
        exit;
    }
    OC_Contacts_App::getAddressbook($id);
    // is owner access check
}
//analyse the contacts file
writeProgress('40');
$file = str_replace(array("\r", "\n\n"), array("\n", "\n"), $file);
$lines = explode($nl, $file);
$inelement = false;
$parts = array();