diff --git a/3rdparty/MDB2/Driver/Manager/pgsql.php b/3rdparty/MDB2/Driver/Manager/pgsql.php
index 490f697aa5be715a55bcecdad0f6207811f13d06..7542e9e8329966bb2e9ae8ec23a75c8633d1dd83 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 6108f18dec16e69c4173531d90c6b357dc3e3d54..13fea6906806f2b3f41b85b204181ce67a75eae4 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 983a3d95a8400de43bce6d91cdb8c9b0c3259f53..f6b8453fc22593ba6bb47e1f876b03e0fd764728 100644
--- a/apps/calendar/ajax/importdialog.php
+++ b/apps/calendar/ajax/importdialog.php
@@ -1,20 +1,17 @@
 <?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
  * 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('<script type="text/javascript">document.location = oc_webroot;</script>');
-}
-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 759726b8d10172eea6faffd770b55b2ad73dfe49..d1186e691e516f7053a0671489453224272ebc72 100644
--- a/apps/calendar/import.php
+++ b/apps/calendar/import.php
@@ -1,46 +1,122 @@
 <?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
  * 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);
+}
+$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;
+}
+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);$i++){
-	$vcalendar[$i] = $vcalendar[0] . $vcalendar[$i];
+//done the import
+if(is_writable('import_tmp/')){
+	$progressfopen = fopen($progressfile, 'w');
+	fwrite($progressfopen, '100');
+	fclose($progressfopen);
 }
-for($i = 1;$i < count($vcalendar);$i++){
-	OC_Calendar_Object::add($calid, $vcalendar[$i]);
+sleep(3);
+if(is_writable('import_tmp/')){
+	unlink($progressfile);
 }
-OC_JSON::success();
-?>
+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 0000000000000000000000000000000000000000..abafbce435c705366fc97ba2b15b1e2fe962d1eb
--- /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 c21c20275e239419227d5ff3f73895df3b8d05ac..4e483f9864e92cb073e9ef6277c2c3ca71e54acb 100644
--- a/apps/calendar/js/loader.js
+++ b/apps/calendar/js/loader.js
@@ -1,14 +1,76 @@
+/**
+ * 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={
 	importdialog: function(filename){
 		var path = $('#dir').val();
 		$('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(){
diff --git a/apps/calendar/templates/part.import.php b/apps/calendar/templates/part.import.php
index b8805e6b6ef3fd8cb10c4ad8e89074d8de9f8e78..8f46484b42b67fa38f2ab0f052cab0238b291cc3 100644
--- a/apps/calendar/templates/part.import.php
+++ b/apps/calendar/templates/part.import.php
@@ -1,69 +1,27 @@
-<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">
+<div id="calendar_import_dialog" title="<?php echo $l->t("Import a calendar file"); ?>">
+<div id="form_container">
+<input type="hidden" id="filename" value="<?php echo $_['filename'];?>">
+<input type="hidden" id="path" value="<?php echo $_['path'];?>">
+<input type="hidden" id="progressfile" value="<?php echo md5(session_id()) . '.txt';?>">
+<p style="text-align:center;"><b><?php echo $l->t('Please choose the calendar'); ?></b>
+<select style="width:100%;" id="calendar" name="calendar">
 <?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>';
-}
+$calendar_options = OC_Calendar_Calendar::allCalendars(OC_User::getUser());
+$calendar_options[] = array('id'=>'newcal', 'displayname'=>$l->t('create a new calendar'));
+echo html_select_options($calendar_options, $calendar_options[0]['id'], array('value'=>'id', 'label'=>'displayname'));
 ?>
-</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');">
+</select>
+<div id="newcalform" style="display: none;">
+	<input type="text" style="width: 97%;" placeholder="<?php echo $l->t('Name of new calendar'); ?>" id="newcalendar" name="newcalendar">
+</div>
+<input type="button" value="<?php echo $l->t("Import");?>!" id="startimport">
 </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 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>
-<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
+</div>
\ No newline at end of file
diff --git a/apps/gallery/ajax/galleryOp.php b/apps/gallery/ajax/galleryOp.php
index 0224977e633a8128e5b4b983b97f5e0095c02b47..a62f0fe3f5bae7d71fd21b03c4abf9adbb7c80a4 100644
--- a/apps/gallery/ajax/galleryOp.php
+++ b/apps/gallery/ajax/galleryOp.php
@@ -29,6 +29,7 @@ OC_JSON::checkAppEnabled('gallery');
 function handleRename($oldname, $newname) {
   OC_JSON::checkLoggedIn();
   OC_Gallery_Album::rename($oldname, $newname, OC_User::getUser());
+  OC_Gallery_Album::changeThumbnailPath($oldname, $newname);
 }
 
 function handleRemove($name) {
diff --git a/apps/gallery/css/styles.css b/apps/gallery/css/styles.css
index 6bfd756e5f1462e2eacf2bcc09ad08a4719e406c..4ada23b0b062aae8ebce749d49cff56f4c306f36 100644
--- a/apps/gallery/css/styles.css
+++ b/apps/gallery/css/styles.css
@@ -1,5 +1,5 @@
 div#gallery_list { margin: 90pt 20pt; }
-div#gallery_list.leftcontent { padding-top: 15pt; margin: 0; height: 80%; text-align: center; overflow: scroll; }
+div#gallery_list.leftcontent { padding-top: 15pt; margin: 0; position: absolute; bottom:0px; text-align: center; overflow: scroll; }
 div#gallery_album_box { width: 200px; text-align: center; border: 0; display: inline-block; margin: 5pt; vertical-align: top; padding: 10px; position: relative; overflow: hidden; color: #999; }
 div#gallery_album_box:hover { color: black; }
 .leftcontent div#gallery_album_box { margin: 5px; }
@@ -7,5 +7,5 @@ div#gallery_album_box h1 { font-size: 9pt; font-family: Verdana; }
 div#gallery_album_cover { width: 199px; height: 199px; border: solid 1pt #999; padding: 0; }
 div#gallery_control_overlay { border: 0; position:absolute; right: 10pt; background-color: #333; opacity: 0.5; visibility:hidden; padding: 0 5pt; }
 div#gallery_control_overlay a { color:white; }
-#gallery_images { padding:10px 5px; }
+#gallery_images.rightcontent { padding:10px 5px; position:absolute; bottom: 0px; overflow: scroll; }
 
diff --git a/apps/gallery/js/album_cover.js b/apps/gallery/js/album_cover.js
index 84a89c5a91f69c5b8b508781751dd5ef73986acc..0009eb04e4f19bf14a4f301fe73aef0d1b7e411e 100644
--- a/apps/gallery/js/album_cover.js
+++ b/apps/gallery/js/album_cover.js
@@ -58,7 +58,7 @@ function galleryRemove(albumName) {
 }
 
 function galleryRename(name) {
-  var result = window.prompt("Input new gallery name", "");
+  var result = window.prompt("Input new gallery name", name);
   if (result) {
 	if (Albums.find(result)) {
 	  alert("Album named '" + result + "' already exists");
diff --git a/apps/gallery/lib/album.php b/apps/gallery/lib/album.php
index a94eff3acd7864abf4907883cd6a2b94672e7616..6adff196071742a83f981bfc73e3b041ad3bd8c1 100644
--- a/apps/gallery/lib/album.php
+++ b/apps/gallery/lib/album.php
@@ -42,6 +42,13 @@ class OC_Gallery_Album {
 		$stmt = OC_DB::prepare($sql);
 		return $stmt->execute($args);
 	}
+
+  public static function removeByPath($path, $owner) {
+    $album = self::find($owner, null, $path);
+    $album = $album->fetchRow();
+    self::remove($owner, $album['album_name']);
+    OC_Gallery_Photo::removeByAlbumId($album['album_id']);
+  }
 	
   public static function find($owner, $name=null, $path=null){
 		$sql = 'SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner = ?';
@@ -58,6 +65,17 @@ class OC_Gallery_Album {
 		return $stmt->execute($args);
 	}
 
+  public static function changePath($oldname, $newname, $owner) {
+    $stmt = OC_DB::prepare('UPDATE OR IGNORE *PREFIX*gallery_albums SET album_path=? WHERE uid_owner=? AND album_path=?');
+    $stmt->execute(array($newname, $owner, $oldname));
+  }
+
+  public static function changeThumbnailPath($oldname, $newname) {
+    require_once('../../../lib/base.php');
+    $thumbpath = OC::$CONFIG_DATADIRECTORY.'/../gallery/';
+    rename($thumbpath.$oldname.'.png', $thumbpath.$newname.'.png');
+  }
+
 }
 
 ?>
diff --git a/apps/gallery/lib/hooks_handlers.php b/apps/gallery/lib/hooks_handlers.php
index 65f3faaeeaf3f57559289a9797c2d1e46b0b0e1c..534f76896d788cb2835f1b6b7869a2f7a76922ed 100644
--- a/apps/gallery/lib/hooks_handlers.php
+++ b/apps/gallery/lib/hooks_handlers.php
@@ -34,8 +34,19 @@ class OC_Gallery_Hooks_Handlers {
   private static function isPhoto($filename) {
     OC_Log::write(self::$APP_TAG, "Checking file ".$filename." with mimetype ".OC_Filesystem::getMimeType($filename), OC_Log::DEBUG);
     if (substr(OC_Filesystem::getMimeType($filename), 0, 6) == "image/")
-      return 1;
-    return 0;
+      return true;
+    return false;
+  }
+
+  private static function directoryContainsPhotos($dirpath) {
+    $dirhandle = opendir(OC::$CONFIG_DATADIRECTORY.$dirpath);
+    if ($dirhandle != FALSE) {
+      while (($filename = readdir($dirhandle)) != FALSE) {
+        if ($filename[0] == '.') continue;
+        if (self::isPhoto($dirpath.'/'.$filename)) return true;
+      }
+    }
+    return false;
   }
 
   private static function createAlbum($path) {
@@ -72,46 +83,53 @@ class OC_Gallery_Hooks_Handlers {
 
   public static function removePhoto($params) {
     $path = $params['path'];
-    if (!self::isPhoto($path)) return;
-    OC_Gallery_Photo::removeByPath($path);
+    if (OC_Filesystem::is_dir($path) && self::directoryContainsPhotos($path)) {
+      OC_Gallery_Album::removeByPath($path, OC_User::getUser());
+    } elseif (self::isPhoto($path)) {
+      OC_Gallery_Photo::removeByPath($path);
+    }
   }
 
   public static function renamePhoto($params) {
-    $olddir = substr($params['oldpath'], 0, strrpos($params['oldpath'], '/'));
-    $newdir = substr($params['newpath'], 0, strrpos($params['newpath'], '/'));
-    if ($olddir == '') $olddir = '/';
-    if ($newdir == '') $newdir = '/';
-    if (!self::isPhoto($params['newpath'])) return;
-    OC_Log::write(self::$APP_TAG, 'Moving photo from '.$params['oldpath'].' to '.$params['newpath'], OC_Log::DEBUG);
-    $album;
-    $newAlbumId;
-    $oldAlbumId;
-    if ($olddir == $newdir) {
-      // album changing is not needed
-      $album = OC_Gallery_Album::find(OC_User::getUser(), null, $olddir);
-      if ($album->numRows() == 0) {
-        $album = self::createAlbum($newdir);
-      }
-      $album = $album->fetchRow();
-      $newAlbumId = $oldAlbumId = $album['album_id'];
-    } else {
-      $newalbum = OC_Gallery_Album::find(OC_User::getUser(), null, $newdir);
-      $oldalbum = OC_Gallery_Album::find(OC_User::getUser(), null, $olddir);
-
-      if ($newalbum->numRows() == 0) {
-        $newalbum = self::createAlbum($newdir);
-      }
-      $newalbum = $newalbum->fetchRow();
-      if ($oldalbum->numRows() == 0) {
-        OC_Gallery_Photo::create($newalbum['album_id'], $params['newpath']);
-        return;
-      }
-      $oldalbum = $oldalbum->fetchRow();
-      $newAlbumId = $newalbum['album_id'];
-      $oldAlbumId = $oldalbum['album_id'];
+    if (OC_Filesystem::is_dir($params['newpath']) && self::directoryContainsPhotos($params['newpath'])) {
+      OC_Gallery_Album::changePath($params['oldpath'], $params['newpath'], OC_User::getUser());
+    } elseif (!self::isPhoto($params['newpath'])) {
+      $olddir = substr($params['oldpath'], 0, strrpos($params['oldpath'], '/'));
+      $newdir = substr($params['newpath'], 0, strrpos($params['newpath'], '/'));
+      if ($olddir == '') $olddir = '/';
+      if ($newdir == '') $newdir = '/';
+      if (!self::isPhoto($params['newpath'])) return;
+      OC_Log::write(self::$APP_TAG, 'Moving photo from '.$params['oldpath'].' to '.$params['newpath'], OC_Log::DEBUG);
+      $album;
+      $newAlbumId;
+      $oldAlbumId;
+      if ($olddir == $newdir) {
+        // album changing is not needed
+        $album = OC_Gallery_Album::find(OC_User::getUser(), null, $olddir);
+        if ($album->numRows() == 0) {
+          $album = self::createAlbum($newdir);
+        }
+        $album = $album->fetchRow();
+        $newAlbumId = $oldAlbumId = $album['album_id'];
+      } else {
+        $newalbum = OC_Gallery_Album::find(OC_User::getUser(), null, $newdir);
+        $oldalbum = OC_Gallery_Album::find(OC_User::getUser(), null, $olddir);
+
+        if ($newalbum->numRows() == 0) {
+          $newalbum = self::createAlbum($newdir);
+        }
+        $newalbum = $newalbum->fetchRow();
+        if ($oldalbum->numRows() == 0) {
+          OC_Gallery_Photo::create($newalbum['album_id'], $params['newpath']);
+          return;
+        }
+        $oldalbum = $oldalbum->fetchRow();
+        $newAlbumId = $newalbum['album_id'];
+        $oldAlbumId = $oldalbum['album_id'];
 
+      }
+      OC_Gallery_Photo::changePath($oldAlbumId, $newAlbumId, $params['oldpath'], $params['newpath']);
     }
-    OC_Gallery_Photo::changePath($oldAlbumId, $newAlbumId, $params['oldpath'], $params['newpath']);
   }
 }
 
diff --git a/apps/gallery/lib/photo.php b/apps/gallery/lib/photo.php
index 23887098e0fe87c5d2b27dc43cf933634550c0d8..14b0c4b2a070ffd22be4e07ba8b70dc8d85d62a0 100644
--- a/apps/gallery/lib/photo.php
+++ b/apps/gallery/lib/photo.php
@@ -56,6 +56,11 @@ class OC_Gallery_Photo{
     $stmt->execute(array($id));
   }
 
+  public static function removeByAlbumId($albumid) {
+    $stmt = OC_DB::prepare('DELETE FROM *PREFIX*gallery_photos WHERE album_id = ?');
+    $stmt->execute(array($albumid));
+  }
+
   public static function changePath($oldAlbumId, $newAlbumId, $oldpath, $newpath) {
     $stmt = OC_DB::prepare("UPDATE *PREFIX*gallery_photos SET file_path = ?, album_id = ? WHERE album_id = ? and file_path = ?");
     $stmt->execute(array($newpath, $newAlbumId, $oldAlbumId, $oldpath));
diff --git a/lib/base.php b/lib/base.php
index e0f14b703dc81c2cffb90da7e99b7912a514bedf..9531f7ed74f1b3e95faa00191d9baa42156b27ce 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -156,7 +156,7 @@ class OC{
 			$installedVersion=OC_Config::getValue('version','0.0.0');
 			$currentVersion=implode('.',OC_Util::getVersion());
 			if (version_compare($currentVersion, $installedVersion, '>')) {
-				OC_DB::updateDbFromStructure('../db_structure.xml');
+				OC_DB::updateDbFromStructure(OC::$SERVERROOT.'/db_structure.xml');
 				OC_Config::setValue('version',implode('.',OC_Util::getVersion()));
 			}
 
diff --git a/lib/db.php b/lib/db.php
index b901cc8b513bedd4980cf02a02a5c2a9c6cd82b3..f6eddf7825cb4d4e7007a8f97e9e71d3fa554d7d 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -371,6 +371,10 @@ class OC_DB {
 		}
 		file_put_contents( $file2, $content );
 		$op = self::$schema->updateDatabase($file2, $previousSchema, array(), false);
+		
+		// Delete our temporary file
+		unlink( $file2 );
+		
 		if (PEAR::isError($op)) {
 		    $error = $op->getMessage();
 		    OC_Log::write('core','Failed to update database structure ('.$error.')',OC_Log::FATAL);
diff --git a/settings/personal.php b/settings/personal.php
old mode 100644
new mode 100755
index c27ca0aed63131b3e35c5ac93393be87b3ce72ba..7035f1b07d42c7a89035130d7f7468dc1b137637
--- a/settings/personal.php
+++ b/settings/personal.php
@@ -31,7 +31,7 @@ array_unshift($languageCodes,$lang);
 $languageNames=include 'languageCodes.php';
 $languages=array();
 foreach($languageCodes as $lang){
-	$languages[]=array('code'=>$lang,'name'=>$languageNames[$lang]);
+	$languages[]=array('code'=>$lang,'name'=>@$languageNames[$lang]);
 }
 
 // Return template