svn commit: r152 - trunk/mapbender/http/classes/class_administration.php
uli at osgeo.org
uli at osgeo.org
Wed Apr 26 10:06:38 EDT 2006
Author: uli
Date: 2006-04-26 14:06:38+0000
New Revision: 152
Modified:
trunk/mapbender/http/classes/class_administration.php
Log:
code cleaning in process
Modified: trunk/mapbender/http/classes/class_administration.php
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/classes/class_administration.php?view=diff&rev=152&p1=trunk/mapbender/http/classes/class_administration.php&p2=trunk/mapbender/http/classes/class_administration.php&r1=151&r2=152
==============================================================================
--- trunk/mapbender/http/classes/class_administration.php (original)
+++ trunk/mapbender/http/classes/class_administration.php 2006-04-26 14:06:38+0000
@@ -17,36 +17,23 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
require_once("../../conf/mapbender.conf");
-
-/*
- * class administration
- * Methods:
- * getGuisByOwner(id): returns an array of all guis where the user is owner
- * getGuisByPermission(id): returns an array of all guis where the user has
- * permission to read
- * getWmsByOwnGuis($array_gui_ids): returns an array of wms which are included
- * in own guis
- */
-
- require("phpmailer-1.72/class.phpmailer.php");
-
+require("phpmailer-1.72/class.phpmailer.php");
class administration{
- function adminstration(){
-
- }
- // CB - returns true if $email is a valid email
- function isValidEmail ($email) {
+ function __construct(){
+ $con = db_connect(DBSERVER,OWNER,PW);
+ db_select_db(DB,$con);
+ }
+
+ function isValidEmail($email) {
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
return true;
}
return false;
}
-
- // CB - sends email with less parameters
- function sendEmail($fromAddr, $fromName, $toAddr, $toName, $subject, $body, &$error_msg ) {
+ function sendEmail($fromAddr, $fromName, $toAddr, $toName, $subject, $body, &$error_msg ){
global $mailHost, $mailUsername, $mailPassword;
if($fromAddr == ''){
@@ -97,8 +84,7 @@
return false;
}
}
-
- // CB - generates random password with $max digits
+
function getRandomPassword() {
// password length
@@ -120,10 +106,8 @@
return $newpass;
}
- // CB - returns all owners (both from mb_user *and* mb_user from mb_group) of a gui
- function getOwnerByGui($gui_id) {
- global $DBSERVER,$DB,$OWNER,$PW;
-
+ function getOwnerByGui($gui_id){
+
$sql = "(SELECT mb_user.mb_user_name";
$sql .= "FROM mb_user ";
$sql .= "JOIN gui_mb_user ON mb_user.mb_user_id = gui_mb_user.fkey_mb_user_id ";
@@ -150,17 +134,14 @@
return $owner;
}
- //CB - returns the email address of a user identified by id
- function getEmailByUserId($userid){
- $con = db_connect(DBSERVER,OWNER,PW);
- db_select_db(DB,$con);
+ function getEmailByUserId($userid){
$sql = "SELECT mb_user_email FROM mb_user ";
$sql .= "WHERE mb_user_id = $1 GROUP by mb_user_email";
$v = array($userid);
$t = array('i');
$res = db_prep_query($sql,$v,$t);
- $count_g = 0;
- $array = array();
+ $count_g = 0;
+ $array = array();
$row = db_fetch_array($res);
if ($row) {
return $row["mb_user_email"];
@@ -168,19 +149,16 @@
else {
return false;
}
- }
+ }
- //CB - returns the user id of a user identified by username
- function getUserNameByUserId($userid){
- $con = db_connect(DBSERVER,OWNER,PW);
- db_select_db(DB,$con);
+ function getUserNameByUserId($userid){
$sql = "SELECT mb_user_name FROM mb_user ";
$sql .= "WHERE mb_user_id = $1 GROUP BY mb_user_name";
$v = array($userid);
$t = array("i");
$res = db_prep_query($sql,$v,$t);
- $count_g = 0;
- $array = array();
+ $count_g = 0;
+ $array = array();
$row = db_fetch_array($res);
if ($row) {
return $row["mb_user_name"];
@@ -188,12 +166,9 @@
else {
return false;
}
- }
+ }
- // CB - returns userId of user(s) with email address $email
function getUserIdByEmail($email){
- $con = db_connect(DBSERVER,OWNER,PW);
- db_select_db(DB,$con);
$sql = "SELECT mb_user_id FROM mb_user ";
$sql .= "WHERE mb_user_email = $1 GROUP BY mb_user_id";
$v = array($email);
@@ -213,26 +188,32 @@
}
}
- // CB - returns all owners of wms $wms_id
- function getOwnerByWms($wms_id){
- global $DBSERVER,$DB,$OWNER,$PW;
- $sql = "SELECT fkey_gui_id FROM gui_wms WHERE fkey_wms_id = ".$wms_id." GROUP BY fkey_gui_id";
- $count=0;
- $res = db_query($sql);
+ function getOwnerByWms($wms_id){
+ $sql = "SELECT fkey_gui_id FROM gui_wms WHERE fkey_wms_id = $1 GROUP BY fkey_gui_id";
+ $v = array($wms_id);
+ $t = array('i');
+ $count=0;
+ $res = db_prep_query($sql,$v,$t);
while($row = db_fetch_array($res)){
$gui[$count] = $row["fkey_gui_id"];
$count++;
}
-
+
if ($count > 0) {
if(count($gui)>0){
+ $v = array();
+ $t = array();
+ $c = 1;
$sql = "(SELECT mb_user.mb_user_name FROM mb_user JOIN gui_mb_user ";
$sql .= "ON mb_user.mb_user_id = gui_mb_user.fkey_mb_user_id ";
$sql .= " WHERE gui_mb_user.mb_user_type = 'owner'";
$sql .= " AND gui_mb_user.fkey_gui_id IN (";
for($i=0; $i<count($gui); $i++){
if($i>0){ $sql .= ",";}
- $sql .= "'".$gui[$i]."'";
+ $sql .= "$".$c;
+ $c++;
+ array_push($v, $gui[$i]);
+ array_push($t, 's');
}
$sql .= ") GROUP BY mb_user.mb_user_name";
$sql .= ") UNION (";
@@ -240,67 +221,36 @@
$sql .= "ON mb_user.mb_user_id = mb_user_mb_group.fkey_mb_user_id ";
$sql .= " WHERE gui_mb_group.mb_group_type = 'owner'";
$sql .= " AND gui_mb_group.fkey_gui_id IN (";
-
- for($i=0; $i<count($gui); $i++){
- if($i>0){ $sql .= ",";}
- $sql .= "'".$gui[$i]."'";
+
+ for($j=0; $j<count($gui); $j++){
+ if($j>0){ $sql .= ",";}
+ $sql .= "$".$c;
+ $c++;
+ array_push($v, $gui[$i]);
+ array_push($t, 's');
}
$sql .= ") GROUP BY mb_user.mb_user_name)";
-
+
$user = array();
- $res = db_query($sql);
+ $res = db_prep_query($sql,$v,$t);
}
$cnt = 0;
-
+
while($row = db_fetch_array($res)){
$user[$cnt] = $row["mb_user_name"];
$cnt++;
- }
+ }
if ($cnt>0) return $user;
else return false;
}
else return false;
- }
-
-/*
- * CB
- * these functions may be easier to use as existing functions
- * however i have now decided not included them to avoid confusion
- *
- *
- // CB (works)
- function getWmsByGuis($array_gui_ids){
- global $DBSERVER,$DB,$OWNER,$PW;
- $sql = "SELECT distinct fkey_wms_id from gui_wms WHERE gui_wms.fkey_gui_id IN(";
- for($i=0; $i<count($array_gui_ids); $i++){
- if($i>0){ $sql .= ",";}
- $sql .= "'".$array_gui_ids[$i]."'";
- }
- $sql .= ")";
- $count=0;
- $wms_id = array();
- $res = db_query($sql);
- while($row = db_fetch_array($res)){
- $wms_id[$count] = $row["fkey_wms_id"];
- $count++;
- }
- return $wms_id;
}
-
- // CB (not tested)
- function getWmsByPermGuis($user_id){
- $gui_list = $this->getGuisByPermission($user_id);
- return $this->getWmsByGuis($gui_list);
- }
- */
- //CB - returns the GML of a WMC identifies by wmc_id
function guiExists($id){
- global $DBSERVER,$DB,$OWNER,$PW;
- $con = db_connect($DBSERVER,$OWNER,$PW);
- db_select_db(DB,$con);
- $sql = "SELECT * FROM gui WHERE gui_id = '". $id."'";
- $res = db_query($sql);
+ $sql = "SELECT * FROM gui WHERE gui_id = $1 ";
+ $v = array($id);
+ $t = array('s');
+ $res = db_prep_query($sql,$v,$t);
$row = db_fetch_array($res);
if ($row) {
return true;
@@ -308,10 +258,8 @@
else {
return false;
}
- }
-
+ }
- //CB - deletes a wmc by id. $user_id has to fit db entry
function deleteWmc($wmc_id, $user_id){
global $DBSERVER,$DB,$OWNER,$PW;
$con = db_connect($DBSERVER,$OWNER,$PW);
@@ -325,30 +273,23 @@
else {
return false;
}
- }
-
+ }
- // CB - insert gui $gui_id
- function insertGui($guiId) {
- if (!$this->guiExists($guiId)) {
- global $DBSERVER,$DB,$OWNER,$PW;
- $con = db_connect($DBSERVER,$OWNER,$PW);
- db_select_db(DB,$con);
+ function insertGui($guiId) {
+ if (!$this->guiExists($guiId)) {
$sql = "INSERT INTO gui VALUES ('" . $guiId . "', '" . $guiId . "', '', '1')";
$res = db_query($sql);
-
+
if ($res) {
return true;
}
- }
+ }
return false;
- }
-
+ }
- // CB - deletes from gui_mb_user where gui_id
- function delAllUsersOfGui($guiId) {
+ function delAllUsersOfGui($guiId) {
global $DBSERVER,$DB,$OWNER,$PW;
- $con = db_connect($DBSERVER,$OWNER,$PW);
+ $con = db_connect($DBSERVER,$OWNER,$PW);
db_select_db(DB,$con);
$sql = "DELETE FROM gui_mb_user WHERE fkey_gui_id = '" . $guiId . "'";
$res = db_query($sql);
@@ -359,86 +300,64 @@
else {
return true;
}
- }
-
-
-
+ }
- // CB (works)
- function getWmsByOwner($user_id) {
+ function getWmsByOwner($user_id){
$gui_list = $this->getGuisByOwner($user_id);
return $this->getWmsByOwnGuis($gui_list);
}
- // CB -returns all users using a certain wms $wms_id
function getUserByWms($wms_id){
- global $DBSERVER,$DB,$OWNER,$PW;
- $sql = "SELECT fkey_gui_id FROM gui_wms WHERE fkey_wms_id = ".$wms_id." GROUP BY fkey_gui_id";
- $count=0;
- $res = db_query($sql);
- while($row = db_fetch_array($res)){
- $gui[$count] = $row["fkey_gui_id"];
- $count++;
- }
- if(count($gui)>0){
- $sql = "(SELECT mb_user.mb_user_name FROM mb_user JOIN gui_mb_user ";
- $sql .= "ON mb_user.mb_user_id = gui_mb_user.fkey_mb_user_id ";
- $sql .= " WHERE gui_mb_user.fkey_gui_id IN (";
- for($i=0; $i<count($gui); $i++){
- if($i>0){ $sql .= ",";}
- $sql .= "'".$gui[$i]."'";
- }
- $sql .= ") GROUP BY mb_user.mb_user_name) UNION";
- $sql .= "(SELECT mb_user.mb_user_name FROM gui_mb_group JOIN mb_user_mb_group ON mb_user_mb_group.fkey_mb_group_id = gui_mb_group.fkey_mb_group_id JOIN mb_user ";
- $sql .= "ON mb_user.mb_user_id = mb_user_mb_group.fkey_mb_user_id ";
- $sql .= " WHERE gui_mb_group.fkey_gui_id IN (";
- for($i=0; $i<count($gui); $i++){
- if($i>0){ $sql .= ",";}
- $sql .= "'".$gui[$i]."'";
- }
- $sql .= ") GROUP BY mb_user.mb_user_name )";
- $user = array();
- $res = db_query($sql);
- $cnt = 0;
- while($row = db_fetch_array($res)){
- $user[$cnt] = $row["mb_user_name"];
- $cnt++;
- }
- }
- return $user;
- }
-
- //CB - returns the title of a WMS identifies by wms_id
- function getWmsTitleByWmsId($id){
global $DBSERVER,$DB,$OWNER,$PW;
- $sql = "SELECT wms_title from wms WHERE wms_id = '". $id."' GROUP BY wms_title";
+ $sql = "SELECT fkey_gui_id FROM gui_wms WHERE fkey_wms_id = ".$wms_id." GROUP BY fkey_gui_id";
+ $count=0;
$res = db_query($sql);
- $row = db_fetch_array($res);
- if ($row) {
- return $row["wms_title"];
+ while($row = db_fetch_array($res)){
+ $gui[$count] = $row["fkey_gui_id"];
+ $count++;
}
- else {
- return false;
+ if(count($gui)>0){
+ $sql = "(SELECT mb_user.mb_user_name FROM mb_user JOIN gui_mb_user ";
+ $sql .= "ON mb_user.mb_user_id = gui_mb_user.fkey_mb_user_id ";
+ $sql .= " WHERE gui_mb_user.fkey_gui_id IN (";
+ for($i=0; $i<count($gui); $i++){
+ if($i>0){ $sql .= ",";}
+ $sql .= "'".$gui[$i]."'";
+ }
+ $sql .= ") GROUP BY mb_user.mb_user_name) UNION";
+ $sql .= "(SELECT mb_user.mb_user_name FROM gui_mb_group JOIN mb_user_mb_group ON mb_user_mb_group.fkey_mb_group_id = gui_mb_group.fkey_mb_group_id JOIN mb_user ";
+ $sql .= "ON mb_user.mb_user_id = mb_user_mb_group.fkey_mb_user_id ";
+ $sql .= " WHERE gui_mb_group.fkey_gui_id IN (";
+ for($i=0; $i<count($gui); $i++){
+ if($i>0){ $sql .= ",";}
+ $sql .= "'".$gui[$i]."'";
+ }
+ $sql .= ") GROUP BY mb_user.mb_user_name )";
+ $user = array();
+ $res = db_query($sql);
+ $cnt = 0;
+ while($row = db_fetch_array($res)){
+ $user[$cnt] = $row["mb_user_name"];
+ $cnt++;
+ }
}
+ return $user;
}
- //CB - returns the title of a GUI identifies by gui_id
- function getGuiTitleByGuiId($id){
- global $DBSERVER,$DB,$OWNER,$PW;
- $con = db_connect($DBSERVER,$OWNER,$PW);
- db_select_db(DB,$con);
- $sql = "SELECT gui_title from gui WHERE gui_id = '".$id."' GROUP BY gui_title";
- $res = db_query($sql);
+ function getWmsTitleByWmsId($id){
+ $sql = "SELECT wms_title from wms WHERE wms_id = $1 GROUP BY wms_title";
+ $v = array($id);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
$row = db_fetch_array($res);
if ($row) {
- return $row["gui_title"];
+ return $row["wms_title"];
}
else {
return false;
}
}
-
- //CB - returns the GML of a WMC identifies by wmc_id
+
function getWmcById($id){
global $DBSERVER,$DB,$OWNER,$PW;
$con = db_connect($DBSERVER,$OWNER,$PW);
@@ -454,9 +373,8 @@
}
}
- // CB
function resetLoginCount($userId) {
- global $DBSERVER,$DB,$OWNER,$PW;
+ global $DBSERVER,$DB,$OWNER,$PW;
$con = db_connect($DBSERVER,$OWNER,$PW);
db_select_db(DB,$con);
$sql = "UPDATE mb_user SET mb_user_login_count = '0' ";
@@ -469,11 +387,10 @@
else {
return true;
}
- }
-
+ }
- function getUserIdByUserName($username){
- global $DBSERVER,$DB,$OWNER,$PW;
+ function getUserIdByUserName($username){
+ global $DBSERVER,$DB,$OWNER,$PW;
$con = db_connect($DBSERVER,$OWNER,$PW);
db_select_db(DB,$con);
$sql = "SELECT mb_user_id FROM mb_user ";
@@ -491,12 +408,10 @@
else {
return false;
}
- }
-
-
- // CB - set user identified by name as owner of gui $gui_id
- function setUserAsGuiOwner($guiId, $userId) {
- global $DBSERVER,$DB,$OWNER,$PW;
+ }
+
+ function setUserAsGuiOwner($guiId, $userId) {
+ global $DBSERVER,$DB,$OWNER,$PW;
$con = db_connect($DBSERVER,$OWNER,$PW);
db_select_db(DB,$con);
$sql = "UPDATE gui_mb_user SET mb_user_type = 'owner' ";
@@ -509,12 +424,10 @@
else {
return true;
}
- }
-
+ }
- // CB - returns the guiId for a given guiTitle
- function getGuiIdByGuiName($guiTitle){
- global $DBSERVER,$DB,$OWNER,$PW;
+ function getGuiIdByGuiName($guiTitle){
+ global $DBSERVER,$DB,$OWNER,$PW;
$con = db_connect($DBSERVER,$OWNER,$PW);
db_select_db(DB,$con);
$sql = "SELECT gui_id FROM gui ";
@@ -534,7 +447,7 @@
}
}
- function getGuisByOwner($user_id){
+ function getGuisByOwner($user_id){
global $DBSERVER,$DB,$OWNER,$PW;
$connect = db_connect($DBSERVER,$OWNER,$PW);
db_select_db(DB);
@@ -552,7 +465,6 @@
return $arrayGuis;
}
- //CB - returns an array of WMC IDs
function getWmcByOwner($user_id){
global $DBSERVER,$DB,$OWNER,$PW;
$connect = db_connect($DBSERVER,$OWNER,$PW);
@@ -567,13 +479,9 @@
$count_g++;
}
return $arrayWmc;
- }
-
-
+ }
+
function getGuisByPermission($mb_user_id){
- $connect = db_connect(DBSERVER,OWNER,PW);
- db_select_db(DB);
-
$arrayGuis = array();
$mb_user_groups = array();
$sql_groups = "SELECT fkey_mb_group_id FROM mb_user_mb_group WHERE fkey_mb_user_id = $1 ";
@@ -621,8 +529,6 @@
}
function getWmsByOwnGuis($array_gui_ids){
- $connect = db_connect(DBSERVER,OWNER,PW);
- db_select_db(DB);
if(count($array_gui_ids)>0){
$v = array();
$t = array();
@@ -644,13 +550,10 @@
}
return $ownguis;
}
- #ToDo: check if empty function is merge error
- #function getWmsByPermGuis($array_gui_ids){
- #}
- function getWmsOwner($wms_id){
- global $DBSERVER,$DB,$OWNER,$PW;
- $sql = "SELECT fkey_gui_id FROM gui_wms WHERE fkey_wms_id = ".$wms_id." GROUP BY fkey_gui_id";
- $count=0;
+
+ function getWmsOwner($wms_id){
+ $sql = "SELECT fkey_gui_id FROM gui_wms WHERE fkey_wms_id = ".$wms_id." GROUP BY fkey_gui_id";
+ $count=0;
$res = db_query($sql);
while($row = db_fetch_array($res)){
$gui[$count] = $row["fkey_gui_id"];
@@ -675,11 +578,10 @@
}
}
return $wmsowner;
- }
+ }
- // CB - insert user $user_id as owner of gui $gui_id
- function insertUserAsGuiOwner($guiId, $userId) {
- global $DBSERVER,$DB,$OWNER,$PW;
+ function insertUserAsGuiOwner($guiId, $userId){
+ global $DBSERVER,$DB,$OWNER,$PW;
$con = db_connect($DBSERVER,$OWNER,$PW);
db_select_db($DB,$con);
$sql = "INSERT INTO gui_mb_user VALUES ('" . $guiId . "', '" . $userId . "', 'owner')";
@@ -721,6 +623,7 @@
return true;
}
}
+
function getWMSOWSstring($wms_id){
$sql = "SELECT wms_owsproxy FROM wms WHERE wms_id = $1 ";
$v = array($wms_id);
@@ -733,6 +636,7 @@
return false;
}
}
+
function setWMSOWSstring($wms_id, $status){
$sql = "UPDATE wms SET wms_owsproxy = $1 WHERE wms_id = $2 ";
$t = array("s","i");
@@ -745,6 +649,7 @@
}
$res = db_prep_query($sql,$v,$t);
}
+
function checkURL($url){
$pos_qm = strpos($url,"?");
if($pos_qm > 0 && $pos_qm < (strlen($url)-1) && substr($url,(strlen($url)-1)) != "&"){
@@ -759,7 +664,4 @@
}
}
}
-$n = new administration();
-$r = $n->getOwnerByGui("admin1");
-print_r($r);
?>
\ No newline at end of file
More information about the Mapbender_commits
mailing list