summaryrefslogtreecommitdiffstats
path: root/apps/user_migrate
diff options
context:
space:
mode:
authorTom Needham <needham.thomas@gmail.com>2012-03-31 22:41:43 +0000
committerTom Needham <needham.thomas@gmail.com>2012-03-31 22:41:43 +0000
commitd20eea9761238e0569f538c6f8b1bb553068bf7b (patch)
treeaf397e1ca89dadd7d75a684f405f173d625d826e /apps/user_migrate
parent73eca66a892ade0894e35fb4b57d7b45a5e1c872 (diff)
downloadnextcloud-server-d20eea9761238e0569f538c6f8b1bb553068bf7b.tar.gz
nextcloud-server-d20eea9761238e0569f538c6f8b1bb553068bf7b.zip
Use ajax to download file, OC_Dialogs for errors
Diffstat (limited to 'apps/user_migrate')
-rw-r--r--apps/user_migrate/ajax/export.php63
-rw-r--r--apps/user_migrate/appinfo/app.php1
-rw-r--r--apps/user_migrate/js/export.js27
-rw-r--r--apps/user_migrate/settings.php22
-rw-r--r--apps/user_migrate/templates/settings.php14
5 files changed, 100 insertions, 27 deletions
diff --git a/apps/user_migrate/ajax/export.php b/apps/user_migrate/ajax/export.php
new file mode 100644
index 00000000000..ef947c610f2
--- /dev/null
+++ b/apps/user_migrate/ajax/export.php
@@ -0,0 +1,63 @@
+<?php
+
+/**
+ * ownCloud - user_migrate
+ *
+ * @author Tom Needham
+ * @copyright 2012 Tom Needham tom@owncloud.com
+ *
+ * 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_Util::checkAppEnabled('user_migrate');
+ OC_JSON::error();
+ die();
+// Which operation
+if( $_GET['operation']=='create' ){
+$uid = !empty( $_POST['uid'] ) ? $_POST['uid'] : OC_User::getUser();
+if( $uid != OC_User::getUser() ){
+ // Needs to be admin to export someone elses account
+ OC_JSON::error();
+ die();
+}
+// Create the export zip
+if( !$path = OC_Migrate::export( $uid ) ){
+ // Error
+ OC_JSON::error();
+ die();
+} else {
+ // Save path in session
+ $_SESSION['ocuserexportpath'] = $path;
+}
+OC_JSON::success();
+die();
+} else if( $_GET['operation']=='download' ){
+ // Download the export
+ $path = isset( $_SESSION['ocuserexportpath'] ) ? $_SESSION['ocuserexportpath'] : false;
+ if( !$path ){
+ die();
+ }
+ header("Content-Type: application/zip");
+ header("Content-Disposition: attachment; filename=" . basename($path));
+ header("Content-Length: " . filesize($path));
+ @ob_end_clean();
+ readfile($path);
+ unlink( $path );
+ $_SESSION['ocuserexportpath'] = '';
+}
diff --git a/apps/user_migrate/appinfo/app.php b/apps/user_migrate/appinfo/app.php
index 18ea8f52b2a..a59b6dd705c 100644
--- a/apps/user_migrate/appinfo/app.php
+++ b/apps/user_migrate/appinfo/app.php
@@ -23,6 +23,7 @@
OC_APP::registerPersonal( 'user_migrate', 'settings' );
OC_APP::registerAdmin( 'user_migrate', 'admin' );
+OC_Util::addScript( 'user_migrate', 'export');
// add settings page to navigation
$entry = array(
diff --git a/apps/user_migrate/js/export.js b/apps/user_migrate/js/export.js
new file mode 100644
index 00000000000..0e1e396f65d
--- /dev/null
+++ b/apps/user_migrate/js/export.js
@@ -0,0 +1,27 @@
+$(document).ready(function(){
+ // Do the export
+ $('#exportbtn').click(function(){
+ // Show loader
+ $('.loading').show();
+ $.getJSON(
+ OC.filePath('user_migrate','ajax','export.php'),
+ {operation:'create'},
+ function(result){
+ if(result.status == 'success'){
+ // Download the file
+ window.location = OC.filePath('user_migrate','ajax','export.php?operation=download') ;
+ $('.loading').hide();
+ $('#exportbtn').val(t('user_migrate', 'Export'));
+ } else {
+ // Cancel loading
+ $('#exportbtn').html('Failed');
+ // Show Dialog
+ OC.dialogs.alert(t('user_migrate', 'Something went wrong while the export file was being generated'), t('user_migrate', 'An error has occurred'), function(){
+ $('#exportbtn').html(t('user_migrate', 'Export')+'<img style="display: none;" class="loading" src="'+OC.filePath('core','img','loading.git')+'" />');
+ });
+ }
+ }
+ // End ajax
+ );
+ });
+}); \ No newline at end of file
diff --git a/apps/user_migrate/settings.php b/apps/user_migrate/settings.php
index 38eee990b46..62f347b3557 100644
--- a/apps/user_migrate/settings.php
+++ b/apps/user_migrate/settings.php
@@ -24,22 +24,6 @@
*/
OC_Util::checkAppEnabled('user_migrate');
-if (isset($_POST['user_export'])) {
- // Create the export zip
- if( !$path = OC_Migrate::export() ){
- // Error
- die('error');
- } else {
- // Download it
- header("Content-Type: application/zip");
- header("Content-Disposition: attachment; filename=" . basename($path));
- header("Content-Length: " . filesize($path));
- @ob_end_clean();
- readfile($path);
- unlink( $path );
- }
-} else {
- // fill template
- $tmpl = new OC_Template('user_migrate', 'settings');
- return $tmpl->fetchPage();
-} \ No newline at end of file
+// fill template
+$tmpl = new OC_Template('user_migrate', 'settings');
+return $tmpl->fetchPage(); \ No newline at end of file
diff --git a/apps/user_migrate/templates/settings.php b/apps/user_migrate/templates/settings.php
index 389de563a6f..5f4857de5fa 100644
--- a/apps/user_migrate/templates/settings.php
+++ b/apps/user_migrate/templates/settings.php
@@ -1,8 +1,6 @@
-<form id="export" action="#" method="post">
- <fieldset class="personalblock">
- <legend><strong><?php echo $l->t('Export your user account');?></strong></legend>
- <p><?php echo $l->t('This will create a compressed file that contains your ownCloud account.');?>
- </p>
- <input type="submit" name="user_export" value="Export" />
- </fieldset>
-</form> \ No newline at end of file
+<fieldset class="personalblock">
+ <legend><strong><?php echo $l->t('Export your user account');?></strong></legend>
+ <p><?php echo $l->t('This will create a compressed file that contains your ownCloud account.');?>
+ </p>
+ <button id="exportbtn">Export<img style="display: none;" class="loading" src="<?php echo OC_Helper::linkTo('core', 'img/loading.gif'); ?>" /></button>
+</fieldset>