瀏覽代碼

Fixed rw access to database

seavenois 10 年之前
父節點
當前提交
385bf4cee1

二進制
www-admin/.functions.php.kate-swp


+ 2 - 0
www-admin/actividades/add/add.php

@@ -154,6 +154,8 @@
 			$file_idx ++;
 		}
 		
+		version();
+		
 		//Edit schedule if requires, return if not
 		if ($schedule == 'on')
 			header("Location: /actividades/add/itinerary.php?id=$id");

+ 1 - 0
www-admin/actividades/add/additinerary.php

@@ -98,6 +98,7 @@
 		if ($insert == true){
 			$query = $fields . $values;
 			mysqli_query($con, $query); //TODO further test
+			version();
 		}
 		
 		//Redirect

+ 2 - 0
www-admin/blog/add/add.php

@@ -124,6 +124,8 @@
 			$file_idx ++;
 		}
 		
+		version();
+		
 		header("Location: /blog/");
 	}
 ?>

+ 1 - 0
www-admin/blog/delete/delete.php

@@ -11,4 +11,5 @@
 		mysqli_query($con, "DELETE FROM post_comment WHERE post = $id;");
 		mysqli_query($con, "DELETE FROM post_image WHERE post = $id;");
 		mysqli_query($con, "DELETE FROM post WHERE id = $id;");
+		version();
 	}

+ 2 - 0
www-admin/blog/edit/edit.php

@@ -126,5 +126,7 @@
 			}
 			$file_idx ++;
 		}
+		
+		version();
 	}
 ?>

+ 1 - 0
www-admin/blog/translate/apply.php

@@ -31,6 +31,7 @@
 		if (strlen($text_eu) > 0 && $text_eu != $r['text_eu']){
 			mysqli_query($con, "UPDATE post SET text_eu = '$text_eu' WHERE id = $id;");
 		}
+		version();
 	}
 	
 	header("Location: /blog/translate/index.php");	

+ 1 - 4
www-admin/blog/translate/save.php

@@ -25,16 +25,13 @@
 		else{
 			if ($title_en != "" && $title_en != $r['title_en'])
 				mysqli_query($con, "UPDATE post SET title_en = '$title_en' WHERE id = $id;");
-				//echo "UPDATE post SET title_en = '$title_en' WHERE id = $id;\n";
 			if ($title_eu != "" && $title_eu != $r['title_eu'])
 				mysqli_query($con, "UPDATE post SET title_eu = '$title_eu' WHERE id = $id;");
-				//echo "UPDATE post SET title_eu = '$title_eu' WHERE id = $id;\n";
 			if ($text_en != "" && $text_en != $r['text_en'])
 				mysqli_query($con, "UPDATE post SET text_en = '$text_en' WHERE id = $id;");
-				//echo "UPDATE post SET text_en = '$text_en' WHERE id = $id;\n";
 			if ($text_eu != "" && $text_eu != $r['text_eu'])
 				mysqli_query($con, "UPDATE post SET text_eu = '$text_eu' WHERE id = $id;");
-				//echo "UPDATE post SET text_eu = '$text_eu' WHERE id = $id;\n";
+			version();
 		}
 		
 	}

+ 12 - 1
www-admin/functions.php

@@ -241,6 +241,17 @@
 			return true;
 		else
 			return false;
-}
+	}
+	
+	/****************************************************
+	* Increases version value in table settings by one. *
+	* Helpfull for the app to know when to perform a    * 
+	* full sync. Must be called after every INSERT or   *
+	* UPDATE query to the database.                     *
+ 	****************************************************/
+	function version(){
+		$con = startdb('rw');
+		mysqli_query($con, 'UPDATE settings SET value = value + 1 WHERE name = "version";');
+	}
 ?>
 	

+ 1 - 0
www-admin/galeria/translate/apply.php

@@ -45,6 +45,7 @@
 		if (strlen($desc_eu) > 0 && $desc_eu != $r['description_eu']){
 			mysqli_query($con, "UPDATE album SET description_eu = '$desc_eu' WHERE id = $id;");
 		}
+		version();
 	}
 	
 	//Update photo entries

+ 3 - 2
www-admin/lablanca/execute.php

@@ -26,16 +26,17 @@
 		switch ($action){
 			case "delete":
 				mysqli_query($con, "DELETE FROM $table WHERE id = $id;");
+				version();
 				break;
 			case "update":
 				switch($type){
 					case "text":
 						mysqli_query($con, "UPDATE $table SET $field = '$value' WHERE id = $id;");
-						error_log("UPDATE $table SET $field = '$value' WHERE id = $id;");
+						version();
 						break;
 					case "number":
 						mysqli_query($con, "UPDATE $table SET $field = $value WHERE id = $id;");
-						error_log("UPDATE $table SET $field = $value WHERE id = $id;");
+						version();
 						break;
 					//TODO: add a case for dates
 				}

+ 2 - 0
www-admin/lablanca/insertoffer.php

@@ -55,5 +55,7 @@
 		
 		//Insert into database
 		mysqli_query($con, "INSERT INTO festival_offer (year, name_es, name_en, name_eu, description_es, description_en, description_eu, days, price) VALUES ($year, '$name_es', '$name_en', '$name_eu', '$text_es', '$text_en', '$text_eu', $days, $price);");
+		
+		version();
 	}
 ?>

+ 1 - 16
www-admin/lablanca/uploadimage.php

@@ -65,25 +65,10 @@
 					$thumb->clear();
 					$thumb->destroy(); 
 					
-					//Create preview
-					//$thumb = new Imagick();
-					//$thumb->readImage("../../www/img/fiestas/tmp.$r[id].png");    
-					//$thumb->resizeImage($p_w, $p_h, Imagick::FILTER_LANCZOS, 1);
-					//$thumb->writeImage("../../www/img/fiestas/preview/$r[year].png");
-					//$thumb->clear();
-					//$thumb->destroy(); 
-					
-					//Create miniature
-					//$thumb = new Imagick();
-					//$thumb->readImage("../../www/img/fiestas/tmp.$r[id].png");    
-					//$thumb->resizeImage($m_w, $m_h, Imagick::FILTER_LANCZOS, 1);
-					//$thumb->writeImage("../../www/img/fiestas/miniature/$r[year].png");
-					//$thumb->clear();
-					//$thumb->destroy();
-					
 					//Update database
 					if (strlen($r['img']) == 0){
 						mysqli_query($con, "UPDATE festival SET img = '$r[year].png' WHERE id = $id;");
+						version();
 					}
 				}
 				break;

+ 1 - 1
www/app/sync.php

@@ -1,5 +1,5 @@
 <?php
-	include('../php_functions.php');
+	include('../functions.php');
 	$con = startdb();
 	
 	//Get client version

+ 1 - 0
www/blog/comment.php

@@ -36,6 +36,7 @@
 		
 	//Insert row
 	mysqli_query($con, "INSERT INTO post_comment (post, text, username, lang) VALUES ($post, '$text', '$user', '$lang');");
+	version();
 	
 	//Prepare the page to update the comment section
 	//WARNING: If changes are done here, do the same in post.php

+ 13 - 1
www/functions.php

@@ -32,8 +32,9 @@
 		//Connect to to database
 		if ($mode == 'ro')
 			$con = mysqli_connect($host, $username_ro, $pass_ro, $db_name);
-		else if ($mode == 'rw')
+		else if ($mode == 'rw'){
 			$con = mysqli_connect($host, $username_rw, $pass_rw, $db_name);
+		}
 			
 		// Check connection
 		if (mysqli_connect_errno()){
@@ -273,5 +274,16 @@
 		}
 		return $cut;
 	}
+	
+	/****************************************************
+	* Increases version value in table settings by one. *
+	* Helpfull for the app to know when to perform a    * 
+	* full sync. Must be called after every INSERT,     *
+	* UPDATE or DELETE query to the database.           *
+ 	****************************************************/
+	function version(){
+		$con = startdb('rw');
+		mysqli_query($con, 'UPDATE settings SET value = value + 1 WHERE name = "version";');
+	}
 ?>
 	

+ 1 - 0
www/galeria/comment.php

@@ -35,6 +35,7 @@
 		
 	//Insert row
 	mysqli_query($con, "INSERT INTO photo_comment (photo, text, username, lang) VALUES ($photo, '$text', '$user', '$lang');");
+	version();
 	
 	//Prepare the page to update the comment section
 	//WARNING: If changes are done here, do the same in album.php

+ 1 - 1
www/galeria/save.php

@@ -82,8 +82,8 @@
 		$h = getimagesize("../img/galeria/$fname.jpg")[1];
 		//Entry in database
 		mysqli_query($con, "INSERT INTO photo (id, file, permalink, title_es, title_en, title_eu, description_es, description_en, description_eu, width, height, size, approved, username) VALUES ($id, '$fname.jpg', '$fname', '$titles[$i]', '$titles[$i]', '$titles[$i]', '$descriptions[$i]', '$descriptions[$i]', '$descriptions[$i]', $w, $h, $s, 0, '$username')");
-		error_log("INSERT INTO photo (id, file, permalink, title_es, title_en, title_eu, description_es, description_en, description_eu, width, height, size, approved, username) VALUES ($id, '$fname.jpg', '$fname', '$titles[$i]', '$titles[$i]', '$titles[$i]', '$descriptions[$i]', '$descriptions[$i]', '$descriptions[$i]', $w, $h, $s, 0, '$username')");
 		mysqli_query($con, "INSERT INTO photo_album VALUES ($id, $album);");
+		version();
 		$id ++;
 	}