summaryrefslogtreecommitdiffstats
path: root/apps/contacts/ajax
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2012-07-15 04:15:57 +0200
committerThomas Tanghus <thomas@tanghus.net>2012-07-15 04:17:30 +0200
commiteba4f080159f0a97f82c79f8b57b6ce45ef127b5 (patch)
tree0165b3ac9e77d4ddf36fff25521c1657c742bcd3 /apps/contacts/ajax
parent87912a8c6595e90b3248bc84dce6e0693253b81d (diff)
downloadnextcloud-server-eba4f080159f0a97f82c79f8b57b6ce45ef127b5.tar.gz
nextcloud-server-eba4f080159f0a97f82c79f8b57b6ce45ef127b5.zip
Refactored contacts import.
Diffstat (limited to 'apps/contacts/ajax')
-rw-r--r--apps/contacts/ajax/addaddressbook.php35
-rw-r--r--apps/contacts/ajax/importaddressbook.php23
-rw-r--r--apps/contacts/ajax/selectaddressbook.php16
-rw-r--r--apps/contacts/ajax/uploadimport.php12
4 files changed, 58 insertions, 28 deletions
diff --git a/apps/contacts/ajax/addaddressbook.php b/apps/contacts/ajax/addaddressbook.php
new file mode 100644
index 00000000000..3d7885fe468
--- /dev/null
+++ b/apps/contacts/ajax/addaddressbook.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * Copyright (c) 2011-2012 Thomas Tanghus <thomas@tanghus.net>
+ * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
+ * 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('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' => $addressbook));
diff --git a/apps/contacts/ajax/importaddressbook.php b/apps/contacts/ajax/importaddressbook.php
deleted file mode 100644
index 6b5b06681ce..00000000000
--- a/apps/contacts/ajax/importaddressbook.php
+++ /dev/null
@@ -1,23 +0,0 @@
-<?php
-/**
- * Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-OCP\JSON::checkLoggedIn();
-OCP\App::checkAppEnabled('contacts');
-$upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize'));
-$post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size'));
-$maxUploadFilesize = min($upload_max_filesize, $post_max_size);
-
-$freeSpace=OC_Filesystem::free_space('/');
-$freeSpace=max($freeSpace,0);
-$maxUploadFilesize = min($maxUploadFilesize ,$freeSpace);
-
-$tmpl = new OCP\Template('contacts', 'part.importaddressbook');
-$tmpl->assign('uploadMaxFilesize', $maxUploadFilesize);
-$tmpl->assign('requesttoken', $_SERVER['HTTP_REQUESTTOKEN']);
-$tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
-$tmpl->printpage();
diff --git a/apps/contacts/ajax/selectaddressbook.php b/apps/contacts/ajax/selectaddressbook.php
new file mode 100644
index 00000000000..6c35d08c829
--- /dev/null
+++ b/apps/contacts/ajax/selectaddressbook.php
@@ -0,0 +1,16 @@
+<?php
+/**
+ * Copyright (c) 2011 Thomas Tanghus <thomas@tanghus.net>
+ * 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');
+
+$addressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser());
+$tmpl = new OCP\Template("contacts", "part.selectaddressbook");
+$tmpl->assign('addressbooks', $addressbooks);
+$page = $tmpl->fetchPage();
+OCP\JSON::success(array('data' => array('page' => $page )));
diff --git a/apps/contacts/ajax/uploadimport.php b/apps/contacts/ajax/uploadimport.php
index 80b282f38a3..3c5a2d750ed 100644
--- a/apps/contacts/ajax/uploadimport.php
+++ b/apps/contacts/ajax/uploadimport.php
@@ -27,13 +27,16 @@ OCP\JSON::callCheck();
require_once('loghandler.php');
$view = OCP\Files::getStorage('contacts');
+if(!$view->file_exists('imports')) {
+ $view->mkdir('imports');
+}
$tmpfile = md5(rand());
// If it is a Drag'n'Drop transfer it's handled here.
$fn = (isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : false);
if($fn) {
- if($view->file_put_contents('/'.$tmpfile, file_get_contents('php://input'))) {
- OCP\JSON::success(array('data' => array('path'=>'', 'file'=>$tmpfile)));
+ if($view->file_put_contents('/imports/'.$fn, file_get_contents('php://input'))) {
+ OCP\JSON::success(array('data' => array('file'=>$tmpfile, 'name'=>$fn)));
exit();
} else {
bailOut(OC_Contacts_App::$l10n->t('Error uploading contacts to storage.'));
@@ -60,10 +63,9 @@ if($error !== UPLOAD_ERR_OK) {
}
$file=$_FILES['importfile'];
-$tmpfname = tempnam(get_temp_dir(), "occOrig");
if(file_exists($file['tmp_name'])) {
- if($view->file_put_contents('/'.$tmpfile, file_get_contents($file['tmp_name']))) {
- OCP\JSON::success(array('data' => array('path'=>'', 'file'=>$tmpfile)));
+ if($view->file_put_contents('/imports/'.$file['name'], file_get_contents($file['tmp_name']))) {
+ OCP\JSON::success(array('data' => array('file'=>$file['name'], 'name'=>$file['name'])));
} else {
bailOut(OC_Contacts_App::$l10n->t('Error uploading contacts to storage.'));
}