diff --git a/3rdparty/MDB2/Driver/Manager/pgsql.php b/3rdparty/MDB2/Driver/Manager/pgsql.php index 490f697aa5..7542e9e832 100644 --- a/3rdparty/MDB2/Driver/Manager/pgsql.php +++ b/3rdparty/MDB2/Driver/Manager/pgsql.php @@ -499,7 +499,7 @@ class MDB2_Driver_Manager_pgsql extends MDB2_Driver_Manager_Common * @return mixed array of view names on success, a MDB2 error on failure * @access public */ - function listViews() + function listViews($database = null) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { @@ -631,7 +631,7 @@ class MDB2_Driver_Manager_pgsql extends MDB2_Driver_Manager_Common * @return mixed array of table names on success, a MDB2 error on failure * @access public */ - function listTables() + function listTables($database = null) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { @@ -922,7 +922,7 @@ class MDB2_Driver_Manager_pgsql extends MDB2_Driver_Manager_Common * @return mixed array of sequence names on success, a MDB2 error on failure * @access public */ - function listSequences() + function listSequences($database = null) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { diff --git a/3rdparty/MDB2/Driver/pgsql.php b/3rdparty/MDB2/Driver/pgsql.php index 6108f18dec..13fea69068 100644 --- a/3rdparty/MDB2/Driver/pgsql.php +++ b/3rdparty/MDB2/Driver/pgsql.php @@ -1193,7 +1193,7 @@ class MDB2_Result_pgsql extends MDB2_Result_Common if ($object_class == 'stdClass') { $row = (object) $row; } else { - $row = &new $object_class($row); + $row = new $object_class($row); } } ++$this->rownum; diff --git a/apps/calendar/ajax/importdialog.php b/apps/calendar/ajax/importdialog.php index 983a3d95a8..f6b8453fc2 100644 --- a/apps/calendar/ajax/importdialog.php +++ b/apps/calendar/ajax/importdialog.php @@ -1,20 +1,17 @@ + * Copyright (c) 2012 Georg Ehrke * 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('calendar'); $l10n = new OC_L10N('calendar'); - -if(!OC_USER::isLoggedIn()) { - die(''); -} -OC_JSON::checkAppEnabled('calendar'); - $tmpl = new OC_Template('calendar', 'part.import'); +$tmpl->assign('path', $_POST['path']); +$tmpl->assign('filename', $_POST['filename']); $tmpl->printpage(); ?> diff --git a/apps/calendar/import.php b/apps/calendar/import.php index 759726b8d1..d1186e691e 100644 --- a/apps/calendar/import.php +++ b/apps/calendar/import.php @@ -1,46 +1,122 @@ + * Copyright (c) 2012 Georg Ehrke * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ - +//check for calendar rights or create new one +ob_start(); require_once ('../../lib/base.php'); OC_JSON::checkLoggedIn(); OC_Util::checkAppEnabled('calendar'); - -if($_GET["import"] == "existing"){ - $calid = $_GET["calid"]; - $calendar = OC_Calendar_App::getCalendar($calid); - if($_GET["path"] != ""){ - $filename = $_GET["path"] . "/" . $_GET["file"]; - }else{ - $filename = "/" . $_GET["file"]; - } -}else{ +$progressfile = 'import_tmp/' . md5(session_id()) . '.txt'; +if(is_writable('import_tmp/')){ + $progressfopen = fopen($progressfile, 'w'); + fwrite($progressfopen, '10'); + fclose($progressfopen); +} +$file = OC_Filesystem::file_get_contents($_POST['path'] . '/' . $_POST['file']); +if($_POST['method'] == 'new'){ $id = OC_Calendar_Calendar::addCalendar(OC_User::getUser(), $_POST['calname']); OC_Calendar_Calendar::setCalendarActive($id, 1); - $calid = $id; - if($_POST["path"] != ""){ - $filename = $_POST["path"] . "/" . $_POST["file"]; +}else{ + $calendar = OC_Calendar_App::getCalendar($_POST['id']); + if($calendar['userid'] != OC_USER::getUser()){ + OC_JSON::error(); + exit(); + } + $id = $_POST['id']; +} +//analyse the calendar file +if(is_writable('import_tmp/')){ + $progressfopen = fopen($progressfile, 'w'); + fwrite($progressfopen, '20'); + fclose($progressfopen); +} +$searchfor = array('VEVENT', 'VTODO', 'VJOURNAL'); +$parts = $searchfor; +$filearr = explode(' +', $file); +$inelement = false; +$parts = array(); +$i = 0; +foreach($filearr as $line){ + foreach($searchfor as $search){ + if(substr_count($line, $search) == 1){ + list($attr, $val) = explode(':', $line); + if($attr == 'BEGIN'){ + $parts[]['begin'] = $i; + $inelement = true; + } + if($attr == 'END'){ + $parts[count($parts) - 1]['end'] = $i; + $inelement = false; + } + } + } + $i++; +} +//import the calendar +if(is_writable('import_tmp/')){ + $progressfopen = fopen($progressfile, 'w'); + fwrite($progressfopen, '40'); + fclose($progressfopen); +} +$start = ''; +$nl = ' +'; +for ($i = 0; $i < $parts[0]['begin']; $i++) { + if($i == 0){ + $start = $filearr[0]; }else{ - $filename = "/" . $_POST["file"]; + $start .= $nl . $filearr[$i]; } } -$vcalendar = OC_Filesystem::file_get_contents($filename); -$vcalendar = explode("BEGIN:VEVENT", $vcalendar); -for($i = 1;$i < count($vcalendar);$i++){ - $vcalendar[$i] = "BEGIN:VEVENT" . $vcalendar[$i]; +$end = ''; +for($i = $parts[count($parts) - 1]['end'] + 1;$i <= count($filearr) - 1; $i++){ + if($i == $parts[count($parts) - 1]['end'] + 1){ + $end = $filearr[$parts[count($parts) - 1]['end'] + 1]; + }else{ + $end .= $nl . $filearr[$i]; + } } -for($i = 1;$i < count($vcalendar) - 1;$i++){ - $vcalendar[$i] = $vcalendar[$i] . "END:VCALENDAR"; +if(is_writable('import_tmp/')){ + $progressfopen = fopen($progressfile, 'w'); + fwrite($progressfopen, '50'); + fclose($progressfopen); } -for($i = 1;$i < count($vcalendar);$i++){ - $vcalendar[$i] = $vcalendar[0] . $vcalendar[$i]; +$importready = array(); +foreach($parts as $part){ + for($i = $part['begin']; $i <= $part['end'];$i++){ + if($i == $part['begin']){ + $content = $filearr[$i]; + }else{ + $content .= $nl . $filearr[$i]; + } + } + $importready[] = $start . $nl . $content . $nl . $end; } -for($i = 1;$i < count($vcalendar);$i++){ - OC_Calendar_Object::add($calid, $vcalendar[$i]); +if(is_writable('import_tmp/')){ + $progressfopen = fopen($progressfile, 'w'); + fwrite($progressfopen, '70'); + fclose($progressfopen); } -OC_JSON::success(); -?> +if(count($parts) == 1){ + OC_Calendar_Object::add($id, $file); +}else{ + foreach($importready as $import){ + OC_Calendar_Object::add($id, $import); + } +} +//done the import +if(is_writable('import_tmp/')){ + $progressfopen = fopen($progressfile, 'w'); + fwrite($progressfopen, '100'); + fclose($progressfopen); +} +sleep(3); +if(is_writable('import_tmp/')){ + unlink($progressfile); +} +OC_JSON::success(); \ No newline at end of file diff --git a/apps/calendar/import_tmp/Info b/apps/calendar/import_tmp/Info new file mode 100644 index 0000000000..abafbce435 --- /dev/null +++ b/apps/calendar/import_tmp/Info @@ -0,0 +1,2 @@ +This folder contains static files with the percentage of the import. +Requires write permission diff --git a/apps/calendar/js/loader.js b/apps/calendar/js/loader.js index c21c20275e..4e483f9864 100644 --- a/apps/calendar/js/loader.js +++ b/apps/calendar/js/loader.js @@ -1,14 +1,76 @@ +/** + * Copyright (c) 2012 Georg Ehrke + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ Calendar_Import={ importdialog: function(filename){ var path = $('#dir').val(); $('body').append('
'); - $('#calendar_import').load(OC.filePath('calendar', 'ajax', 'importdialog.php'), {filename:filename, path:path}, Calendar_Import.initdialog()); + $('#calendar_import').load(OC.filePath('calendar', 'ajax', 'importdialog.php'), {filename:filename, path:path}, function(){Calendar_Import.initdialog(filename);}); }, - initdialog: function(){ - + initdialog: function(filename){ + $('#calendar_import_dialog').dialog({ + width : 500, + close : function() { + $(this).dialog('destroy').remove(); + $('#calendar_import').remove(); + } + }); + $('#import_done_button').click(function(){ + $('#calendar_import_dialog').dialog('destroy').remove(); + $('#calendar_import').remove(); + }); + $('#progressbar').progressbar({value: 0}); + $('#startimport').click(function(){ + var filename = $('#filename').val(); + var path = $('#path').val(); + var calid = $('#calendar option:selected').val(); + if($('#calendar option:selected').val() == 'newcal'){ + var method = 'new'; + var calname = $('#newcalendar').val(); + var calname = $.trim(calname); + if(calname == ''){ + $('#newcalendar').css('background-color', '#FF2626'); + $('#newcalendar').focus(function(){ + $('#newcalendar').css('background-color', '#F8F8F8'); + }); + return false; + } + }else{ + var method = 'old'; + } + $('#newcalendar').attr('readonly', 'readonly'); + $('#calendar').attr('disabled', 'disabled'); + var progressfile = $('#progressfile').val(); + $.post(OC.filePath('calendar', '', 'import.php'), {method: String (method), calname: String (calname), path: String (path), file: String (filename), id: String (calid)}, function(data){ + if(data.status == 'success'){ + $('#progressbar').progressbar('option', 'value', 100); + $('#import_done').css('display', 'block'); + } + }); + $('#form_container').css('display', 'none'); + $('#progressbar_container').css('display', 'block'); + window.setTimeout('Calendar_Import.getimportstatus(\'' + progressfile + '\')', 500); + }); + $('#calendar').change(function(){ + if($('#calendar option:selected').val() == 'newcal'){ + $('#newcalform').slideDown('slow'); + }else{ + $('#newcalform').slideUp('slow'); + } + }); }, - getimportstatus: function(){ - + getimportstatus: function(progressfile){ + $.get(OC.filePath('calendar', 'import_tmp', progressfile), function(percent){ + $('#progressbar').progressbar('option', 'value', parseInt(percent)); + if(percent < 100){ + window.setTimeout('Calendar_Import.getimportstatus(\'' + progressfile + '\')', 500); + }else{ + $('#import_done').css('display', 'block'); + } + }); } } $(document).ready(function(){ diff --git a/apps/calendar/templates/part.import.php b/apps/calendar/templates/part.import.php index b8805e6b6e..8f46484b42 100644 --- a/apps/calendar/templates/part.import.php +++ b/apps/calendar/templates/part.import.php @@ -1,69 +1,27 @@ -
"> -"> -"> -
t("How to import the new calendar?");?> -

-" onclick="$('#first').css('display', 'none');$('#existingcal').css('display', 'block');"> -" onclick="$('#first').css('display', 'none');$('#newcal').css('display', 'block');"> -
-