diff options
author | Georg Ehrke <georg.stefan.germany@googlemail.com> | 2011-10-03 22:50:10 +0200 |
---|---|---|
committer | Georg Ehrke <georg.stefan.germany@googlemail.com> | 2011-10-03 22:50:10 +0200 |
commit | c40a1fcedebb238ba369a4cc30000e348bfbdd8a (patch) | |
tree | b646a490aa19fe7976fe799b899f1619528de7d7 /apps/calendar | |
parent | e8c6252a4ce1151b11f1faa8e602c06aae4294d8 (diff) | |
download | nextcloud-server-c40a1fcedebb238ba369a4cc30000e348bfbdd8a.tar.gz nextcloud-server-c40a1fcedebb238ba369a4cc30000e348bfbdd8a.zip |
added import function as filehandler
Diffstat (limited to 'apps/calendar')
-rw-r--r-- | apps/calendar/ajax/importdialog.php | 20 | ||||
-rw-r--r-- | apps/calendar/appinfo/app.php | 2 | ||||
-rw-r--r-- | apps/calendar/import.php | 50 | ||||
-rw-r--r-- | apps/calendar/js/loader.js | 16 | ||||
-rw-r--r-- | apps/calendar/templates/part.eventinfo.php | 87 | ||||
-rw-r--r-- | apps/calendar/templates/part.import.php | 70 |
6 files changed, 158 insertions, 87 deletions
diff --git a/apps/calendar/ajax/importdialog.php b/apps/calendar/ajax/importdialog.php new file mode 100644 index 00000000000..232b4ba5807 --- /dev/null +++ b/apps/calendar/ajax/importdialog.php @@ -0,0 +1,20 @@ +<?php +/** + * Copyright (c) 2011 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'); + +$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->printpage(); +?> diff --git a/apps/calendar/appinfo/app.php b/apps/calendar/appinfo/app.php index 837c6d6b124..2dc01eab0f6 100644 --- a/apps/calendar/appinfo/app.php +++ b/apps/calendar/appinfo/app.php @@ -6,6 +6,8 @@ OC::$CLASSPATH['OC_Calendar_Hooks'] = 'apps/calendar/lib/hooks.php'; OC::$CLASSPATH['OC_Connector_Sabre_CalDAV'] = 'apps/calendar/lib/connector_sabre.php'; OC_HOOK::connect('OC_User', 'post_createUser', 'OC_Calendar_Hooks', 'deleteUser'); +OC_Util::addScript('calendar','loader'); + OC_App::register( array( 'order' => 10, 'id' => 'calendar', diff --git a/apps/calendar/import.php b/apps/calendar/import.php new file mode 100644 index 00000000000..e31d8bbdc6f --- /dev/null +++ b/apps/calendar/import.php @@ -0,0 +1,50 @@ +<?php +/** + * Copyright (c) 2011 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('calendar'); + +if($_GET["import"] == "existing"){ + $calid = $_GET["calid"]; + $calendar = OC_Calendar_Calendar::findCalendar($calid); + if($calendar['userid'] != OC_User::getUser()){ + OC_JSON::error(); + exit; + } + if($_GET["path"] != ""){ + $filename = $_GET["path"] . "/" . $_GET["file"]; + }else{ + $filename = "/" . $_GET["file"]; + } +}else{ + $id = OC_Calendar_Calendar::addCalendar(OC_User::getUser(), $_POST['calname'], $_POST['description']); + OC_Calendar_Calendar::setCalendarActive($id, 1); + $calid = $id; + if($_POST["path"] != ""){ + $filename = $_POST["path"] . "/" . $_POST["file"]; + }else{ + $filename = "/" . $_POST["file"]; + } +} +$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]; +} +for($i = 1;$i < count($vcalendar) - 1;$i++){ + $vcalendar[$i] = $vcalendar[$i] . "END:VCALENDAR"; +} +for($i = 1;$i < count($vcalendar);$i++){ + $vcalendar[$i] = $vcalendar[0] . $vcalendar[$i]; +} +for($i = 1;$i < count($vcalendar);$i++){ + OC_Calendar_Object::add($calid, $vcalendar[$i]); +} +OC_JSON::success(); +?>
\ No newline at end of file diff --git a/apps/calendar/js/loader.js b/apps/calendar/js/loader.js new file mode 100644 index 00000000000..6eafec8b10d --- /dev/null +++ b/apps/calendar/js/loader.js @@ -0,0 +1,16 @@ +function importdialog(directory, filename){ + $("body").append("<div id=\"importdialogholder\"></div>"); + $("#importdialogholder").load(OC.filePath('calendar', 'ajax', 'importdialog.php?filename=' + filename + '&path=' + directory)); +} + +$(document).ready(function(){ + $('tr[data-file$=".ics"]').attr("data-mime", "text/calendar"); + $('tr[data-file$=".vcs"]').attr("data-mime", "text/calendar"); + $('tr[data-file$=".ical"]').attr("data-mime", "text/calendar"); + if(typeof FileActions!=='undefined'){ + FileActions.register('text/calendar','Import to Calendar','',function(filename){ + importdialog($('#dir').val(),filename); + }); + FileActions.setDefault('text/calendar','Import to Calendar'); + } +});
\ No newline at end of file diff --git a/apps/calendar/templates/part.eventinfo.php b/apps/calendar/templates/part.eventinfo.php deleted file mode 100644 index edccaaa2227..00000000000 --- a/apps/calendar/templates/part.eventinfo.php +++ /dev/null @@ -1,87 +0,0 @@ - <div id="eventinfo" title="<?php echo $l -> t("Edit an event");?>"> - <table id="eventinfo_table" width="100%"> - <tr> - <td width="75px"><?php echo $l -> t("Title");?>:</td> - <td> - </td> - </tr> - <tr> - <td width="75px"><?php echo $l -> t("Location");?>:</td> - <td> - </td> - </tr> - </table> - <table> - <tr> - <td width="75px"><?php echo $l -> t("Category");?>:</td> - <td></td> - <td width="75px"> <?php echo $l -> t("Calendar");?>:</td> - <td></td> - </tr> - </table> - <hr> - <table> - <tr> - <td width="75px"></td> - <td> - <input type="checkbox" id="newcalendar_allday_checkbox" disabled="true"> - <label for="newcalendar_allday_checkbox"><?php echo $l -> t("All Day Event");?></label></td> - </tr> - <tr> - <td width="75px"><?php echo $l -> t("From");?>:</td> - <td> - - </td><!--use jquery--> - </tr> - <tr> - - <td width="75px"><?php echo $l -> t("To");?>:</td> - <td> - - </td><!--use jquery--> - </tr> - <tr> - <td width="75px"><?php echo $l -> t("Repeat");?>:</td> - <td></td> - </tr> - </table> - <hr> - <table> - <tr> - <td width="75px"><?php echo $l -> t("Attendees");?>:</td> - <td style="height: 50px;"></td> - </tr> - </table> - <hr> - <table> - <tr> - <td width="75px" style="vertical-align: top;"><?php echo $l -> t("Description");?>:</td> - <td></td> - </tr> - </table> - <span id="editevent_actions"> - <input type="button" style="float: left;" value="<?php echo $l -> t("Close");?>"> - <input type="button" style="float: right;" value="<?php echo $l -> t("Edit");?>"> - </span> -</div> -<script type="text/javascript"> - $( "#eventinfo" ).dialog({ - width : 500, - close : function() { - oc_cal_opendialog = 0; - var lastchild = document.getElementById("body-user").lastChild - while(lastchild.id != "lightbox"){ - document.getElementById("body-user").removeChild(lastchild); - lastchild = document.getElementById("body-user").lastChild; - } - }, - open : function(){alert("Doesn't work yet.");} - }); - $( "#from" ).datepicker({ - dateFormat : 'dd-mm-yy' - }); - $( "#to" ).datepicker({ - dateFormat : 'dd-mm-yy' - }); - } -</script>
\ No newline at end of file diff --git a/apps/calendar/templates/part.import.php b/apps/calendar/templates/part.import.php new file mode 100644 index 00000000000..c1beb49a7f7 --- /dev/null +++ b/apps/calendar/templates/part.import.php @@ -0,0 +1,70 @@ +<div id="importdialog" title="<?php echo $l->t("Import Ical File"); ?>"> +<input type="hidden" id="filename" value="<?php echo $_GET["filename"];?>"> +<input type="hidden" id="path" value="<?php echo $_GET["path"];?>"> +<div id="first"><strong style="text-align: center;margin: 0 auto;"><?php echo $l->t("How to import the new calendar?");?></strong> +<br><br> +<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');"> +<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');"> +</div> +<div id="existingcal" style="display: none;"> +<strong><?php echo $l->t("Please choose the calendar"); ?></strong><br><br> +<form id="inputradioform"> +<?php +$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser()); +foreach($calendars as $calendar){ + echo '<input type="radio" style="width: 20px;" name="calendar" id="radio_' . $calendar["id"] . '" value="' . $calendar["id"] . '">' . $calendar["displayname"] . '<br>'; +} +?> +</form> +<br><br> +<input type="button" value="<?php echo $l->t("Import");?>!" onclick="importcal('existing');"> +<br><br> +<input type="button" value="<?php echo $l->t("Back");?>" onclick="$('#existingcal').css('display', 'none');$('#first').css('display', 'block');"> +</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> +<th><?php echo $l->t('Description') ?></th> +<td> +<textarea id="description"></textarea> +</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> +<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); + } + if(importtype == "new"){ + var calname = $("#displayname").val(); + var description = $("#description").val(); + $.post(OC.filePath('calendar', '', 'import.php'), {'import':'new', 'calname':calname, 'description':description, 'path':path, 'file':file}); + } + window.location = oc_webroot + "/apps/calendar/"; +} +</script>
\ No newline at end of file |