Contacts: In app import. Cleanup still needed.
This commit is contained in:
parent
0cd9570277
commit
dfc94cbe84
|
@ -0,0 +1,24 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
require_once('../../../lib/base.php');
|
||||
OC_JSON::checkLoggedIn();
|
||||
OC_Util::checkAppEnabled('contacts');
|
||||
$upload_max_filesize = OC_Helper::computerFileSize(ini_get('upload_max_filesize'));
|
||||
$post_max_size = OC_Helper::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 OC_Template('contacts', 'part.importaddressbook');
|
||||
$tmpl->assign('uploadMaxFilesize', $maxUploadFilesize);
|
||||
$tmpl->assign('uploadMaxHumanFilesize', OC_Helper::humanFileSize($maxUploadFilesize));
|
||||
$tmpl->printpage();
|
||||
?>
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
/**
|
||||
* ownCloud - Addressbook
|
||||
*
|
||||
* @author Thomas Tanghus
|
||||
* @copyright 2012 Thomas Tanghus <thomas@tanghus.net>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* 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');
|
||||
|
||||
// Check if we are a user
|
||||
OC_JSON::checkLoggedIn();
|
||||
OC_JSON::checkAppEnabled('contacts');
|
||||
function bailOut($msg) {
|
||||
OC_JSON::error(array('data' => array('message' => $msg)));
|
||||
OC_Log::write('contacts','ajax/uploadimport.php: '.$msg, OC_Log::ERROR);
|
||||
exit();
|
||||
}
|
||||
function debug($msg) {
|
||||
OC_Log::write('contacts','ajax/uploadimport.php: '.$msg, OC_Log::DEBUG);
|
||||
}
|
||||
|
||||
// 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) {
|
||||
/*$dir = OC_App::getStorage('contacts');
|
||||
$handle = $dir->touch(''.$fn);
|
||||
if(!$handle) {
|
||||
bailOut('Bugger!');
|
||||
} else {
|
||||
bailOut('Yippie!');
|
||||
}
|
||||
debug('Internal path: '.$dir->getInternalPath());*/
|
||||
$tmpfile = md5(rand());
|
||||
if(OC_Filesystem::file_put_contents('/'.$tmpfile, file_get_contents('php://input'))) {
|
||||
debug($fn.' uploaded');
|
||||
OC_JSON::success(array('data' => array('path'=>'', 'file'=>$tmpfile)));
|
||||
} else {
|
||||
bailOut(OC_Contacts_App::$l10n->t('Error uploading contacts to storage.'));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -33,7 +33,8 @@ dl.form { width: 100%; float: left; clear: right; margin: 0; padding: 0; }
|
|||
.form dd { display: table-cell; clear: right; float: left; margin: 0; padding: 0px; white-space: nowrap; vertical-align: text-bottom; }
|
||||
#address.form dt { min-width: 5em; }
|
||||
#address.form dl { min-width: 10em; }
|
||||
|
||||
.droptarget { margin: 0.5em; padding: 0.5em; border: thin solid #ccc; -moz-border-radius:.3em; -webkit-border-radius:.3em; border-radius:.3em; }
|
||||
.droppable { margin: 0.5em; padding: 0.5em; border: thin dashed #333; -moz-border-radius:.3em; -webkit-border-radius:.3em; border-radius:.3em; }
|
||||
.loading { background: url('../../../core/img/loading.gif') no-repeat center !important; /*cursor: progress; */ cursor: wait; }
|
||||
.ui-autocomplete-loading { background: url('../../../core/img/loading.gif') right center no-repeat; }
|
||||
.float { float: left; }
|
||||
|
|
|
@ -99,12 +99,16 @@ if(is_writable('import_tmp/')){
|
|||
if(count($parts) == 1){
|
||||
$importready = array($file);
|
||||
}
|
||||
$imported = 0;
|
||||
$failed = 0;
|
||||
foreach($importready as $import){
|
||||
$card = OC_VObject::parse($import);
|
||||
if (!$card) {
|
||||
$failed += 1;
|
||||
OC_Log::write('contacts','Import: skipping card. Error parsing VCard: '.$import, OC_Log::ERROR);
|
||||
continue; // Ditch cards that can't be parsed by Sabre.
|
||||
}
|
||||
$imported += 1;
|
||||
OC_Contacts_VCard::add($id, $card);
|
||||
}
|
||||
//done the import
|
||||
|
@ -117,4 +121,10 @@ sleep(3);
|
|||
if(is_writable('import_tmp/')){
|
||||
unlink($progressfile);
|
||||
}
|
||||
OC_JSON::success();
|
||||
if(isset($_POST['istmpfile'])) {
|
||||
OC_Log::write('contacts','Import: Unlinking '.$_POST['path'] . '/' . $_POST['file'], OC_Log::ERROR);
|
||||
if(!OC_Filesystem::unlink($_POST['path'] . '/' . $_POST['file'])) {
|
||||
OC_Log::write('contacts','Import: Error unlinking '.$_POST['path'] . '/' . $_POST['file'], OC_Log::ERROR);
|
||||
}
|
||||
}
|
||||
OC_JSON::success(array('data' => array('imported'=>$imported, 'failed'=>$failed)));
|
||||
|
|
|
@ -1263,7 +1263,8 @@ Contacts={
|
|||
for(ptype in this.data.TEL[phone]['parameters'][param]) {
|
||||
var pt = this.data.TEL[phone]['parameters'][param][ptype];
|
||||
$('#phonelist li:last-child').find('select option').each(function(){
|
||||
if ($(this).val().toUpperCase() == pt.toUpperCase()) {
|
||||
//if ($(this).val().toUpperCase() == pt.toUpperCase()) {
|
||||
if ($.inArray($(this).val().toUpperCase(), pt.toUpperCase().split(',')) > -1) {
|
||||
$(this).attr('selected', 'selected');
|
||||
}
|
||||
});
|
||||
|
@ -1285,6 +1286,7 @@ Contacts={
|
|||
},
|
||||
},
|
||||
Addressbooks:{
|
||||
droptarget:undefined,
|
||||
overview:function(){
|
||||
if($('#chooseaddressbook_dialog').dialog('isOpen') == true){
|
||||
$('#chooseaddressbook_dialog').dialog('moveToTop');
|
||||
|
@ -1317,14 +1319,13 @@ Contacts={
|
|||
var tr = $(document.createElement('tr'))
|
||||
.load(OC.filePath('contacts', 'ajax', 'addbook.php'));
|
||||
$(object).closest('tr').after(tr).hide();
|
||||
/* TODO: Shouldn't there be some kinda error checking here? */
|
||||
},
|
||||
editAddressbook:function(object, bookid){
|
||||
var tr = $(document.createElement('tr'))
|
||||
.load(OC.filePath('contacts', 'ajax', 'editaddressbook.php') + "?bookid="+bookid);
|
||||
$(object).closest('tr').after(tr).hide();
|
||||
},
|
||||
deleteAddressbook:function(bookid){
|
||||
deleteAddressbook:function(obj, bookid){
|
||||
var check = confirm("Do you really want to delete this address book?");
|
||||
if(check == false){
|
||||
return false;
|
||||
|
@ -1332,9 +1333,10 @@ Contacts={
|
|||
$.post(OC.filePath('contacts', 'ajax', 'deletebook.php'), { id: bookid},
|
||||
function(jsondata) {
|
||||
if (jsondata.status == 'success'){
|
||||
$('#chooseaddressbook_dialog').dialog('destroy').remove();
|
||||
$(obj).closest('tr').remove();
|
||||
//$('#chooseaddressbook_dialog').dialog('destroy').remove();
|
||||
Contacts.UI.Contacts.update();
|
||||
Contacts.UI.Addressbooks.overview();
|
||||
//Contacts.UI.Addressbooks.overview();
|
||||
} else {
|
||||
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
|
||||
//alert('Error: ' + data.message);
|
||||
|
@ -1342,8 +1344,99 @@ Contacts={
|
|||
});
|
||||
}
|
||||
},
|
||||
doImport:function(){
|
||||
Contacts.UI.notImplemented();
|
||||
loadImportHandlers:function() {
|
||||
this.droptarget = $('#import_drop_target');
|
||||
console.log($('#import_drop_target').html());
|
||||
$(this.droptarget).bind('dragover',function(event){
|
||||
//console.log('dragover');
|
||||
$(event.target).addClass('droppable');
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
});
|
||||
$(this.droptarget).bind('dragleave',function(event){
|
||||
//console.log('dragleave');
|
||||
$(event.target).removeClass('droppable');
|
||||
//event.stopPropagation();
|
||||
//event.preventDefault();
|
||||
});
|
||||
$(this.droptarget).bind('drop',function(event){
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
console.log('drop');
|
||||
$(event.target).removeClass('droppable');
|
||||
$(event.target).html(t('contacts', 'Uploading...'));
|
||||
Contacts.UI.loading(event.target, true);
|
||||
$.fileUpload(event.originalEvent.dataTransfer.files);
|
||||
});
|
||||
|
||||
$.fileUpload = function(files){
|
||||
console.log(files + ', ' + files.length);
|
||||
var file = files[0];
|
||||
console.log('size: '+file.size+', type: '+file.type);
|
||||
if(file.size > $('#max_upload').val()){
|
||||
OC.dialogs.alert(t('contacts','The file you are trying to upload exceed the maximum size for file uploads on this server.'), t('contacts','Upload too large'));
|
||||
$(Contacts.UI.Addressbooks.droptarget).html(t('contacts', 'Drop a VCF file to import contacts.'));
|
||||
Contacts.UI.loading(Contacts.UI.Addressbooks.droptarget, false);
|
||||
return;
|
||||
}
|
||||
if(file.type.indexOf('text') != 0) {
|
||||
OC.dialogs.alert(t('contacts','You have dropped a file type that cannot be imported: ') + file.type, t('contacts','Wrong file type'));
|
||||
$(Contacts.UI.Addressbooks.droptarget).html(t('contacts', 'Drop a VCF file to import contacts.'));
|
||||
Contacts.UI.loading(Contacts.UI.Addressbooks.droptarget, false);
|
||||
return;
|
||||
}
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
if (!xhr.upload) {
|
||||
OC.dialogs.alert(t('contacts', 'Your browser doesn\'t support AJAX upload. Please upload the contacts file to ownCloud and import that way.'), t('contacts', 'Error'))
|
||||
}
|
||||
fileUpload = xhr.upload,
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState == 4){
|
||||
response = $.parseJSON(xhr.responseText);
|
||||
if(response.status == 'success') {
|
||||
if(xhr.status == 200) {
|
||||
$(Contacts.UI.Addressbooks.droptarget).html(t('contacts', 'Importing...'));
|
||||
Contacts.UI.Addressbooks.doImport(response.data.path, response.data.file);
|
||||
} else {
|
||||
$(Contacts.UI.Addressbooks.droptarget).html(t('contacts', 'Drop a VCF file to import contacts.'));
|
||||
Contacts.UI.loading(Contacts.UI.Addressbooks.droptarget, false);
|
||||
OC.dialogs.alert(xhr.status + ': ' + xhr.responseText, t('contacts', 'Error'));
|
||||
}
|
||||
} else {
|
||||
OC.dialogs.alert(response.data.message, t('contacts', 'Error'));
|
||||
}
|
||||
}
|
||||
};
|
||||
xhr.open("POST", 'ajax/uploadimport.php?file='+encodeURIComponent(file.name), true);
|
||||
xhr.setRequestHeader('Cache-Control', 'no-cache');
|
||||
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
xhr.setRequestHeader('X_FILE_NAME', encodeURIComponent(file.name));
|
||||
xhr.setRequestHeader('X-File-Size', file.size);
|
||||
xhr.setRequestHeader('Content-Type', file.type);
|
||||
xhr.send(file);
|
||||
}
|
||||
},
|
||||
importAddressbook:function(object){
|
||||
var tr = $(document.createElement('tr'))
|
||||
.load(OC.filePath('contacts', 'ajax', 'importaddressbook.php'));
|
||||
$(object).closest('tr').after(tr).hide();
|
||||
//this.loadImportHandlers();
|
||||
},
|
||||
doImport:function(path, file){
|
||||
var id = $('#importaddressbook_dialog').find('#book').val();
|
||||
console.log('Selected book: ' + id);
|
||||
$.post(OC.filePath('contacts', '', 'import.php'), { id: id, path: path, file: file, istmpfile: true },
|
||||
function(jsondata){
|
||||
if(jsondata.status == 'success'){
|
||||
Contacts.UI.Addressbooks.droptarget.html(t('contacts', 'Import done. Success/Failure: ')+jsondata.data.imported+'/'+jsondata.data.failed);
|
||||
$('#chooseaddressbook_dialog').find('#close_button').val(t('contacts', 'OK'));
|
||||
Contacts.UI.Contacts.update();
|
||||
} else {
|
||||
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
|
||||
}
|
||||
});
|
||||
Contacts.UI.loading(Contacts.UI.Addressbooks.droptarget, false);
|
||||
},
|
||||
submit:function(button, bookid){
|
||||
var displayname = $("#displayname_"+bookid).val().trim();
|
||||
|
@ -1507,13 +1600,13 @@ $(document).ready(function(){
|
|||
});
|
||||
$('#contacts_details_photo_wrapper').bind('dragover',function(event){
|
||||
console.log('dragover');
|
||||
$(event.target).css('background-color','red');
|
||||
$(event.target).addClass('droppable');
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
});
|
||||
$('#contacts_details_photo_wrapper').bind('dragleave',function(event){
|
||||
console.log('dragleave');
|
||||
$(event.target).css('background-color','white');
|
||||
$(event.target).removeClass('droppable');
|
||||
//event.stopPropagation();
|
||||
//event.preventDefault();
|
||||
});
|
||||
|
@ -1521,7 +1614,7 @@ $(document).ready(function(){
|
|||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
console.log('drop');
|
||||
$(event.target).css('background-color','white')
|
||||
$(event.target).removeClass('droppable');
|
||||
$.fileUpload(event.originalEvent.dataTransfer.files);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<div id="chooseaddressbook_dialog" title="<?php echo $l->t("Choose active Address Books"); ?>">
|
||||
<div id="chooseaddressbook_dialog" title="<?php echo $l->t("Configure Address Books"); ?>">
|
||||
<table width="100%" style="border: 0;">
|
||||
<?php
|
||||
$option_addressbooks = OC_Contacts_Addressbook::all(OC_User::getUser());
|
||||
|
@ -14,6 +14,7 @@ for($i = 0; $i < count($option_addressbooks); $i++){
|
|||
<tr>
|
||||
<td colspan="5" style="padding: 0.5em;">
|
||||
<a class="button" href="#" onclick="Contacts.UI.Addressbooks.newAddressbook(this);"><?php echo $l->t('New Address Book') ?></a>
|
||||
<a class="button" href="#" onclick="Contacts.UI.Addressbooks.importAddressbook(this);"><?php echo $l->t('Import from VCF') ?></a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
// FIXME: Make this readable.
|
||||
echo "<td width=\"20px\"><input id=\"active_" . $_['addressbook']["id"] . "\" type=\"checkbox\" onClick=\"Contacts.UI.Addressbooks.activation(this, " . $_['addressbook']["id"] . ")\"" . (OC_Contacts_Addressbook::isActive($_['addressbook']["id"]) ? ' checked="checked"' : '') . "></td>";
|
||||
echo "<td><label for=\"active_" . $_['addressbook']["id"] . "\">" . htmlspecialchars($_['addressbook']["displayname"]) . "</label></td>";
|
||||
echo "<td width=\"20px\"><a href=\"#\" onclick=\"Contacts.UI.showCardDAVUrl('" . OC_User::getUser() . "', '" . rawurlencode($_['addressbook']["uri"]) . "');\" title=\"" . $l->t("CardDav Link") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/public.svg\"></a></td><td width=\"20px\"><a href=\"export.php?bookid=" . $_['addressbook']["id"] . "\" title=\"" . $l->t("Download") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/download.svg\"></a></td><td width=\"20px\"><a href=\"#\" title=\"" . $l->t("Edit") . "\" class=\"action\" onclick=\"Contacts.UI.Addressbooks.editAddressbook(this, " . $_['addressbook']["id"] . ");\"><img class=\"svg action\" src=\"../../core/img/actions/rename.svg\"></a></td><td width=\"20px\"><a href=\"#\" onclick=\"Contacts.UI.Addressbooks.deleteAddressbook('" . $_['addressbook']["id"] . "');\" title=\"" . $l->t("Delete") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/delete.svg\"></a></td>";
|
||||
echo "<td width=\"20px\"><a href=\"#\" onclick=\"Contacts.UI.showCardDAVUrl('" . OC_User::getUser() . "', '" . rawurlencode($_['addressbook']["uri"]) . "');\" title=\"" . $l->t("CardDav Link") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/public.svg\"></a></td><td width=\"20px\"><a href=\"export.php?bookid=" . $_['addressbook']["id"] . "\" title=\"" . $l->t("Download") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/download.svg\"></a></td><td width=\"20px\"><a href=\"#\" title=\"" . $l->t("Edit") . "\" class=\"action\" onclick=\"Contacts.UI.Addressbooks.editAddressbook(this, " . $_['addressbook']["id"] . ");\"><img class=\"svg action\" src=\"../../core/img/actions/rename.svg\"></a></td><td width=\"20px\"><a href=\"#\" onclick=\"Contacts.UI.Addressbooks.deleteAddressbook(this, '" . $_['addressbook']["id"] . "');\" title=\"" . $l->t("Delete") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/delete.svg\"></a></td>";
|
||||
|
|
Loading…
Reference in New Issue