* 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));
Example #2
0
    OC_Cache::set($progresskey, $pct, 300);
}
writeProgress('10');
$view = $file = null;
if (isset($_POST['fstype']) && $_POST['fstype'] == 'OC_FilesystemView') {
    $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
Example #3
0
 /**
  * @brief Add default Addressbook for a certain user
  * @param paramters parameters from postCreateUser-Hook
  * @return array
  */
 public static function createUser($parameters)
 {
     OC_Contacts_Addressbook::add($parameters['uid'], 'default', 'Default Address Book');
     return true;
 }
 /**
  * @brief Get active addressbooks for a user.
  * @param integer $uid User id. If null current user will be used.
  * @return array
  */
 public static function activeIds($uid = null)
 {
     if (is_null($uid)) {
         $uid = OCP\USER::getUser();
     }
     $prefbooks = OCP\Config::getUserValue($uid, 'contacts', 'openaddressbooks', null);
     if (!$prefbooks) {
         $addressbooks = OC_Contacts_Addressbook::all($uid);
         if (count($addressbooks) == 0) {
             OC_Contacts_Addressbook::add($uid, 'default', 'Default Address Book');
             $addressbooks = OC_Contacts_Addressbook::all($uid);
         }
         $prefbooks = $addressbooks[0]['id'];
         OCP\Config::setUserValue($uid, 'contacts', 'openaddressbooks', $prefbooks);
     }
     return explode(';', $prefbooks);
 }
Example #5
0
<?php

/**
 * 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');
OCP\JSON::callCheck();
require_once __DIR__ . '/../loghandler.php';
debug('name: ' . $_POST['name']);
$userid = OCP\USER::getUser();
$name = isset($_POST['name']) ? trim(strip_tags($_POST['name'])) : null;
$description = isset($_POST['description']) ? trim(strip_tags($_POST['description'])) : null;
if (is_null($name)) {
    bailOut('Cannot add addressbook with an empty name.');
}
$bookid = OC_Contacts_Addressbook::add($userid, $name, $description);
if (!$bookid) {
    bailOut('Error adding addressbook: ' . $name);
}
if (!OC_Contacts_Addressbook::setActive($bookid, 1)) {
    bailOut('Error activating addressbook.');
}
$addressbook = OC_Contacts_App::getAddressbook($bookid);
OCP\JSON::success(array('data' => array('addressbook' => $addressbook)));
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
function contacts_namesort($a, $b)
{
    return strcmp($a['name'], $b['name']);
}
// Init owncloud
require_once '../../lib/base.php';
// Check if we are a user
OC_Util::checkLoggedIn();
OC_Util::checkAppEnabled('contacts');
// Check if the user has an addressbook
$addressbooks = OC_Contacts_Addressbook::all(OC_User::getUser());
if (count($addressbooks) == 0) {
    OC_Contacts_Addressbook::add(OC_User::getUser(), 'default', 'Default Address Book');
    $addressbooks = OC_Contacts_Addressbook::all(OC_User::getUser());
}
$prefbooks = OC_Preferences::getValue(OC_User::getUser(), 'contacts', 'openaddressbooks', null);
if (is_null($prefbooks)) {
    $prefbooks = $addressbooks[0]['id'];
    OC_Preferences::setValue(OC_User::getUser(), 'contacts', 'openaddressbooks', $prefbooks);
}
// Load the files we need
OC_App::setActiveNavigationEntry('contacts_index');
// Load a specific user?
$id = isset($_GET['id']) ? $_GET['id'] : null;
// sort addressbooks  (use contactsort)
usort($addressbooks, 'contacts_namesort');
// Addressbooks to load
$openaddressbooks = explode(';', $prefbooks);