![]() |
|||||||||
![]() |
![]() |
||||||||
![]() |
|||||||||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|
![]() |
|||||||||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() | ![]() Photo Galleries:class DataLayer { var $link; var $errors = array(); var $debug = false; function DataLayer( ) { } function connect( $host, $name, $pass, $db ) { $link = mysql_connect( $host, $name, $pass ); if ( ! $link ) { $this->setError("Couldn't connect to database server"); return false; } if ( ! mysql_select_db( $db, $link ) ) { $this->setError("Couldn't select database."); return false; } $this->link = $link; return true; } function getError( ) { return $this->errors[count($this->errors)-1]; } function setError( $str ) { array_push( $this->errors, $str ); } function _query( $query ) { if ( ! $this->link ) { $this->setError("No active db connection"); return false; } $result = mysql_query( $query, $this->link ); if ( ! $result ) $this->setError("error: ".mysql_error()); return $result; } function setQuery( $query ) { if (! $result = $this->_query( $query ) ) return false; return mysql_affected_rows( $this->link ); } function getQuery( $query ) { if (! $result = $this->_query( $query ) ) return false; $ret = array(); while ( $row = mysql_fetch_assoc( $result ) ) $ret[] = $row; return $ret; } function getResource( ) { return $this->link; } function select( $table, $condition="", $sort="" ) { $query = "SELECT * FROM $table"; $query .= $this->_makeWhereList( $condition ); if ( $sort != "" ) $query .= " order by $sort"; $this->debug( $query ); return $this->getQuery( $query, $error ); } function insert( $table, $add_array ) { $add_array = $this->_quote_vals( $add_array ); $keys = "(".implode( array_keys( $add_array ), ", ").")"; $values = "values (".implode( array_values( $add_array ), ", ").")"; $query = "INSERT INTO $table $keys $values"; $this->debug( $query ); return $this->setQuery( $query ); } function update( $table, $update_array, $condition="" ) { $update_pairs=array(); foreach( $update_array as $field=>$val ) array_push( $update_pairs, "$field=".$this->_quote_val( $val ) ); $query = "UPDATE $table set "; $query .= implode( ", ", $update_pairs ); $query .= $this->_makeWhereList( $condition ); $this->debug( $query ); return $this->setQuery( $query ); } function delete( $table, $condition="" ) { $query = "DELETE FROM $table"; $query .= $this->_makeWhereList( $condition ); $this->debug( $query ); return $this->setQuery( $query, $error ); } function debug( $msg ) { if ( $this->debug ) print "$msg"; } function _makeWhereList( $condition ) { if ( empty( $condition ) ) return ""; $retstr = " WHERE "; if ( is_array( $condition ) ) { $cond_pairs=array(); foreach( $condition as $field=>$val ) array_push( $cond_pairs, "$field=".$this->_quote_val( $val ) ); $retstr .= implode( " and ", $cond_pairs ); } elseif ( is_string( $condition ) && ! empty( $condition ) ) $retstr .= $condition; return $retstr; } function _quote_val( $val ) { if ( is_numeric( $val ) ) return $val; return "'".mysql_real_escape_string($val)."'"; } function _quote_vals( $array ) { foreach( $array as $key=>$val ) $ret[$key]=$this->_quote_val( $val ); return $ret; } } ?> $zones[0]["name"] = "South Korea"; $zones[0]["url"] = "imageview.php"; //$zones[0]["list"] = array("Grunge Photos", "Other Photos", "Graphic Design", "Art", "Computer Art"); $zones[1]["name"] = "Japan"; $zones[1]["url"] = "imageview.php"; $zones[2]["name"] = "Thailand"; $zones[2]["url"] = "imageview.php"; $zones[3]["name"] = "Laos"; $zones[3]["url"] = "imageview.php"; $zones[4]["name"] = "Bali"; $zones[4]["url"] = "imageview.php"; $zones[5]["name"] = "Mexico"; $zones[5]["url"] = "imageview.php"; $zones[6]["name"] = "Guatemala"; $zones[6]["url"] = "imageview.php"; $zones[7]["name"] = "Religious and Sacred"; $zones[7]["url"] = "imageview.php"; $zones[8]["name"] = "Food"; $zones[8]["url"] = "imageview.php"; $zones[9]["name"] = "USA"; $zones[9]["url"] = "imageview.php"; $zones[10]["name"] = "Bali"; $zones[10]["url"] = "imageview.php"; $zones[11]["name"] = "Worldschooling Travel Tour: Mexico Oct. '08"; $zones[11]["url"] = "imageview.php"; $zones[12]["name"] = "Honduras"; $zones[12]["url"] = "imageview.php"; $zones[13]["name"] = "Nicaragua"; $zones[13]["url"] = "imageview.php"; $zones[14]["name"] = "Costa Rica"; $zones[14]["url"] = "imageview.php"; //$zones[1]["list"] = array("Grunge Photos", "Other Photos", "Graphic Design", "Art", "Computer Art"); function buildglistsections ($z=0, $sel=1) { global $zones; $i = 0; foreach($zones[$z]["list"] as $item) { $sections[] = (string)($i++ . " " . $item); } $txt = "\n"; return $txt; } function buildglistzones($sel=0) { global $zones; $i = 0; foreach($zones as $item) { $sections[] = (string)($i++ . " " . $item["name"]); } $txt = "\n"; return $txt; } function urltozone($string) { global $zones; $i = 0; $r = "negative"; foreach($zones as $item) { $i++; if($item["url"] == $string){ $r = $i; break; } } return $r; } function zonetotitle($n=0) { global $zones; return $zones[$n]["name"]; } function getzonemenu($n=0) { global $zones; return $zones[$n]["list"]; } function buildzonemenu($n=0,$t="_blank") { global $zones; $z = $zones[$n]["list"]; //$r = " "; $i = 0; foreach($z as $item) { if( $i > 0){ $r .= " | "; } $r .= ''; $r .= $item . ""; } //$r .= " "; return $r; } function returnsectionlist($n=0) { global $zones; $z = $zones[$n]["list"]; return $z; } ?> |