Skip to content
Snippets Groups Projects
Commit 4d1c414f authored by Georg Ehrke's avatar Georg Ehrke
Browse files

Merge branch 'calendar'

parents 06388e13 868cf462
Branches
No related tags found
No related merge requests found
<?php <?php
/** /**
* Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de> * Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de>
* This file is licensed under the Affero General Public License version 3 or * This file is licensed under the Affero General Public License version 3 or
* later. * later.
* See the COPYING-README file. * See the COPYING-README file.
*/ */
require_once('../../../lib/base.php'); require_once('../../../lib/base.php');
OC_JSON::checkLoggedIn();
OC_Util::checkAppEnabled('calendar');
$l10n = new OC_L10N('calendar'); $l10n = new OC_L10N('calendar');
if(!OC_USER::isLoggedIn()) {
die('<script type="text/javascript">document.location = oc_webroot;</script>');
}
OC_JSON::checkAppEnabled('calendar');
$tmpl = new OC_Template('calendar', 'part.import'); $tmpl = new OC_Template('calendar', 'part.import');
$tmpl->assign('path', $_POST['path']);
$tmpl->assign('filename', $_POST['filename']);
$tmpl->printpage(); $tmpl->printpage();
?> ?>
<?php <?php
/** /**
* Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de> * Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de>
* This file is licensed under the Affero General Public License version 3 or * This file is licensed under the Affero General Public License version 3 or
* later. * later.
* See the COPYING-README file. * See the COPYING-README file.
*/ */
//check for calendar rights or create new one
ob_start();
require_once ('../../lib/base.php'); require_once ('../../lib/base.php');
OC_JSON::checkLoggedIn(); OC_JSON::checkLoggedIn();
OC_Util::checkAppEnabled('calendar'); OC_Util::checkAppEnabled('calendar');
$progressfile = 'import_tmp/' . md5(session_id()) . '.txt';
if($_GET["import"] == "existing"){ if(is_writable('import_tmp/')){
$calid = $_GET["calid"]; $progressfopen = fopen($progressfile, 'w');
$calendar = OC_Calendar_App::getCalendar($calid); fwrite($progressfopen, '10');
if($_GET["path"] != ""){ fclose($progressfopen);
$filename = $_GET["path"] . "/" . $_GET["file"];
}else{
$filename = "/" . $_GET["file"];
} }
}else{ $file = OC_Filesystem::file_get_contents($_POST['path'] . '/' . $_POST['file']);
if($_POST['method'] == 'new'){
$id = OC_Calendar_Calendar::addCalendar(OC_User::getUser(), $_POST['calname']); $id = OC_Calendar_Calendar::addCalendar(OC_User::getUser(), $_POST['calname']);
OC_Calendar_Calendar::setCalendarActive($id, 1); OC_Calendar_Calendar::setCalendarActive($id, 1);
$calid = $id;
if($_POST["path"] != ""){
$filename = $_POST["path"] . "/" . $_POST["file"];
}else{ }else{
$filename = "/" . $_POST["file"]; $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{
$start .= $nl . $filearr[$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];
}
} }
if(is_writable('import_tmp/')){
$progressfopen = fopen($progressfile, 'w');
fwrite($progressfopen, '50');
fclose($progressfopen);
} }
$vcalendar = OC_Filesystem::file_get_contents($filename); $importready = array();
$vcalendar = explode("BEGIN:VEVENT", $vcalendar); foreach($parts as $part){
for($i = 1;$i < count($vcalendar);$i++){ for($i = $part['begin']; $i <= $part['end'];$i++){
$vcalendar[$i] = "BEGIN:VEVENT" . $vcalendar[$i]; if($i == $part['begin']){
$content = $filearr[$i];
}else{
$content .= $nl . $filearr[$i];
}
}
$importready[] = $start . $nl . $content . $nl . $end;
}
if(is_writable('import_tmp/')){
$progressfopen = fopen($progressfile, 'w');
fwrite($progressfopen, '70');
fclose($progressfopen);
}
if(count($parts) == 1){
OC_Calendar_Object::add($id, $file);
}else{
foreach($importready as $import){
OC_Calendar_Object::add($id, $import);
} }
for($i = 1;$i < count($vcalendar) - 1;$i++){
$vcalendar[$i] = $vcalendar[$i] . "END:VCALENDAR";
} }
for($i = 1;$i < count($vcalendar);$i++){ //done the import
$vcalendar[$i] = $vcalendar[0] . $vcalendar[$i]; if(is_writable('import_tmp/')){
$progressfopen = fopen($progressfile, 'w');
fwrite($progressfopen, '100');
fclose($progressfopen);
} }
for($i = 1;$i < count($vcalendar);$i++){ sleep(3);
OC_Calendar_Object::add($calid, $vcalendar[$i]); if(is_writable('import_tmp/')){
unlink($progressfile);
} }
OC_JSON::success(); OC_JSON::success();
\ No newline at end of file
?>
This folder contains static files with the percentage of the import.
Requires write permission
/**
* 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.
*/
Calendar_Import={ Calendar_Import={
importdialog: function(filename){ importdialog: function(filename){
var path = $('#dir').val(); var path = $('#dir').val();
$('body').append('<div id="calendar_import"></div>'); $('body').append('<div id="calendar_import"></div>');
$('#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(){ $(document).ready(function(){
......
<div id="importdialog" title="<?php echo $l->t("Import Ical File"); ?>"> <div id="calendar_import_dialog" title="<?php echo $l->t("Import a calendar file"); ?>">
<input type="hidden" id="filename" value="<?php echo $_GET["filename"];?>"> <div id="form_container">
<input type="hidden" id="path" value="<?php echo $_GET["path"];?>"> <input type="hidden" id="filename" value="<?php echo $_['filename'];?>">
<div id="first"><strong style="text-align: center;margin: 0 auto;"><?php echo $l->t("How to import the new calendar?");?></strong> <input type="hidden" id="path" value="<?php echo $_['path'];?>">
<br><br> <input type="hidden" id="progressfile" value="<?php echo md5(session_id()) . '.txt';?>">
<input style="float: left;" type="button" value="<?php echo $l->t("Import into an existing calendar"); ?>" onclick="$('#first').css('display', 'none');$('#existingcal').css('display', 'block');"> <p style="text-align:center;"><b><?php echo $l->t('Please choose the calendar'); ?></b>
<input style="float: right;" type="button" value="<?php echo $l->t("Import into a new calendar");?>" onclick="$('#first').css('display', 'none');$('#newcal').css('display', 'block');"> <select style="width:100%;" id="calendar" name="calendar">
</div>
<div id="existingcal" style="display: none;">
<strong><?php echo $l->t("Please choose the calendar"); ?></strong><br><br>
<form id="inputradioform">
<?php <?php
$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser()); $calendar_options = OC_Calendar_Calendar::allCalendars(OC_User::getUser());
foreach($calendars as $calendar){ $calendar_options[] = array('id'=>'newcal', 'displayname'=>$l->t('create a new calendar'));
echo '<input type="radio" style="width: 20px;" name="calendar" id="radio_' . $calendar["id"] . '" value="' . $calendar["id"] . '">' . $calendar["displayname"] . '<br>'; echo html_select_options($calendar_options, $calendar_options[0]['id'], array('value'=>'id', 'label'=>'displayname'));
}
?> ?>
</form> </select>
<br><br> <div id="newcalform" style="display: none;">
<input type="button" value="<?php echo $l->t("Import");?>!" onclick="importcal('existing');"> <input type="text" style="width: 97%;" placeholder="<?php echo $l->t('Name of new calendar'); ?>" id="newcalendar" name="newcalendar">
<br><br> </div>
<input type="button" value="<?php echo $l->t("Back");?>" onclick="$('#existingcal').css('display', 'none');$('#first').css('display', 'block');"> <input type="button" value="<?php echo $l->t("Import");?>!" id="startimport">
</div>
<div id="progressbar_container" style="display: none">
<p style="text-align:center;"><b><?php echo $l->t('Importing calendar'); ?></b>
<div id="progressbar"></div>
<div id="import_done" style="display: none;">
<p style="text-align:center;"><b><?php echo $l->t('Calendar imported successfully'); ?></b></p>
<input type="button" value="<?php echo $l->t('Close Dialog'); ?>" id="import_done_button">
</div> </div>
<div id="newcal" style="display: none;">
<strong><?php echo $l->t("Please fill out the form"); ?></strong>
<!-- modified part of part.editcalendar.php -->
<table width="100%" style="border: 0;">
<tr>
<th><?php echo $l->t('Displayname') ?></th>
<td>
<input id="displayname" type="text" value="">
</td>
</tr>
</table>
<!-- end of modified part -->
<br><br>
<input type="button" value="<?php echo $l->t("Import");?>!" onclick="importcal('new');">
<br><br>
<input type="button" value="<?php echo $l->t("Back");?>" onclick="$('#newcal').css('display', 'none');$('#first').css('display', 'block');">
</div> </div>
</div> </div>
\ No newline at end of file
<script type="text/javascript">
$("input:radio[name='calendar']:first").attr("checked","checked");
$("#importdialog").dialog({
width : 500,
close : function(event, ui) {
$(this).dialog('destroy').remove();
$("#importdialogholder").remove();
}
});
function importcal(importtype){
var path = $("#path").val();
var file = $("#filename").val();
if(importtype == "existing"){
var calid = $("input:radio[name='calendar']:checked").val();
$.getJSON(OC.filePath('calendar', '', 'import.php') + "?import=existing&calid=" + calid + "&path=" + path + "&file=" + file, function(){
$("#importdialog").dialog('destroy').remove();
$("#importdialogholder").remove();
});
}
if(importtype == "new"){
var calname = $("#displayname").val();
$.post(OC.filePath('calendar', '', 'import.php'), {'import':'new', 'calname':calname, 'path':path, 'file':file}, function(){
$("#importdialog").dialog('destroy').remove();
$("#importdialogholder").remove();
});
}
}
</script>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment