[Mapbender-commits] r6225 - in trunk/mapbender/http: . x_metadata

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon May 31 07:52:06 EDT 2010


Author: christoph
Date: 2010-05-31 07:52:05 -0400 (Mon, 31 May 2010)
New Revision: 6225

Added:
   trunk/mapbender/http/x_metadata/
   trunk/mapbender/http/x_metadata/mb_md_editor_search_data_server.php
Log:


Added: trunk/mapbender/http/x_metadata/mb_md_editor_search_data_server.php
===================================================================
--- trunk/mapbender/http/x_metadata/mb_md_editor_search_data_server.php	                        (rev 0)
+++ trunk/mapbender/http/x_metadata/mb_md_editor_search_data_server.php	2010-05-31 11:52:05 UTC (rev 6225)
@@ -0,0 +1,153 @@
+<?php
+/*
+ * License:
+ * Copyright (c) 2009, Open Source Geospatial Foundation
+ * This program is dual licensed under the GNU General Public License 
+ * and Simplified BSD license.  
+ * http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
+ */
+ 
+require_once dirname(__FILE__) . "/../../core/globalSettings.php";
+require_once dirname(__FILE__) . "/../classes/class_locale.php";
+require_once dirname(__FILE__) . "/../classes/class_group_registrar.php";
+
+$ajaxResponse = new AjaxResponse($_POST);
+
+switch ($ajaxResponse->getMethod()) {
+	case "autocompleteResponsibleParty" :
+		$input = $ajaxResponse->getParameter("input");
+
+		// get registrars I belong to
+		$myRegistrars = Registrar::getRegistrarsByUser(Mapbender::session()->get("mb_user_id"));
+
+		// get registrars that match the search term
+		$filter = new stdClass();
+		$filter->name = $input;
+		$matchedRegistrars = Registrar::getList($filter);
+
+		// compute and return intersection
+		$matchedRegistrars = Registrar::intersect($myRegistrars, $matchedRegistrars);		
+
+		$resultObj = array();
+		foreach ($matchedRegistrars as $reg) {
+			$resultObj[]= $reg->name;
+		}
+        $ajaxResponse->setSuccess(true);
+		$ajaxResponse->setResult(array(
+			"found" => $resultObj
+		));
+		break;
+	case "autocompleteIndividualName" :
+		$input = $ajaxResponse->getParameter("input");
+		
+		$sql = "SELECT individual_name FROM mb_metadata_data WHERE individual_name ILIKE $1";
+		$res = db_prep_query($sql, array($input . "%"), array("s"));
+		$resultObj = array();
+		while ($row = db_fetch_assoc($res)) {
+			$resultObj[]= $row["individual_name"];
+		}
+        $ajaxResponse->setSuccess(true);
+		$ajaxResponse->setResult(array(
+			"found" => $resultObj
+		));
+		break;
+	case "autocompleteMbUser" :
+		$input = $ajaxResponse->getParameter("input");
+		$sql = "SELECT DISTINCT mb_user_name FROM mb_user, mb_metadata_data WHERE mb_user_id = fkey_mb_user_id AND mb_user_name ILIKE $1";
+		$res = db_prep_query($sql, array($input . "%"), array("s"));
+		$resultObj = array();
+		while ($row = db_fetch_assoc($res)) {
+			$resultObj[]= $row["mb_user_name"];
+		}
+        $ajaxResponse->setSuccess(true);
+		$ajaxResponse->setResult(array(
+			"found" => $resultObj
+		));
+		break;
+	case "delete" :
+		$ids = $ajaxResponse->getParameter("ids");
+		if (!is_array($ids) || count($ids) === 0) {
+	        $ajaxResponse->setSuccess(false);
+	        $ajaxResponse->setMessage("Unbekannter Metadatensatz.");
+		}
+		else {
+			$parameters = array();
+			$t = array();
+			for ($i = 0; $i < count($ids); $i++) {
+				$parameters[]= "$" . ($i+1);
+				$t[]= "i";
+			}
+			$parameters = implode(", ", $parameters);
+			$sql = "DELETE FROM mb_metadata_data WHERE id IN ($parameters)";
+			$res = db_prep_query($sql, $ids, $t);
+			if ($res) {
+		        $ajaxResponse->setSuccess(true);
+		        $ajaxResponse->setMessage(_mb("Metadatensätze gelöscht."));
+			}
+			else {
+		        $ajaxResponse->setSuccess(false);
+		        $ajaxResponse->setMessage(_mb("Metadatensätze konnten nicht gelöscht werden."));
+			}
+		}
+		break;
+	case "search" :
+		$data = $ajaxResponse->getParameter("data");
+		$sql = "SELECT id, title, status, responsible_party, individual_name, date " . 
+			"FROM mb_metadata_data, mb_user WHERE fkey_mb_user_id = mb_user_id ";
+		$andConditions = array();
+		$v = array();
+		$t = array();
+		$i = 0;
+		foreach ($data as $item) {
+			if ($item->value === "") {
+				continue;
+			}
+			if ($item->name === "title") {
+				$andConditions[]= "title LIKE $" . ++$i;
+				$v[]= "%" . $item->value . "%";
+				$t[]= "s";
+			}
+			elseif ($item->name === "responsible_party" || 
+				$item->name === "individual_name" || 
+				$item->name === "status") {
+				$andConditions[]= $item->name . " = $" . ++$i;
+				$v[]= $item->value;
+				$t[]= "s";
+			}
+			elseif ($item->name === "fkey_mb_user_id") {
+				$andConditions[]= "mb_user_name = $" . ++$i;
+				$v[]= $item->value;
+				$t[]= "i";
+			}
+			elseif ($item->name === "date_min") {
+				$andConditions[]= "date >= $" . ++$i;
+				$v[]= $item->value;
+				$t[]= "s";
+			}
+			elseif ($item->name === "date_max") {
+				$andConditions[]= "date <= $" . ++$i;
+				$v[]= $item->value;
+				$t[]= "s";
+			}
+		}
+		if (count($andConditions) > 0) {
+			$sql .= " AND " . implode(" AND ", $andConditions);
+		}
+		$sql .= " ORDER BY title";
+		$res = db_prep_query($sql, $v, $t);
+		$resultObj = array();
+		while ($row = db_fetch_assoc($res)) {
+			$resultObj[]= $row;
+		}
+		
+        $ajaxResponse->setSuccess(true);
+		$ajaxResponse->setResult($resultObj);
+		break;
+	default :
+		$ajaxResponse->setSuccess(false);
+		$ajaxResponse->setMessage(_mb("An unknown error occured."));
+		break;
+}
+
+$ajaxResponse->send();
+?>
\ No newline at end of file



More information about the Mapbender_commits mailing list