Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

general.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  This program is free software; you can redistribute it and/or
00004  modify it under the terms of the GNU General Public License
00005  as published by the Free Software Foundation; either version 2
00006  of the License, or (at your option) any later version.
00007 
00008  This program is distributed in the hope that it will be useful,
00009  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  GNU General Public License for more details.
00012 
00013  You should have received a copy of the GNU General Public License
00014  along with this program; if not, write to the Free Software
00015  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00016  ***************************************************************************/
00017 
00018 ini_set('display_errors', 1);
00019 error_reporting(E_ALL);
00020 
00021 // for php < 4.3
00022 if( !function_exists( 'file_get_contents' ) )
00023 {
00024     function file_get_contents( $file, $var )
00025     {
00026         $aFile = @file( $file );
00027         if( $aFile === false ) return false;
00028         return implode( '', $aFile );
00029     }
00030 }
00031 
00032 // for php < 4.1.0
00033 if( !is_array( $_POST ) && is_array( $HTTP_POST_VARS ) )
00034 {
00035     $_POST =& $HTTP_POST_VARS;
00036 }
00037 if( !is_array( $_GET ) && is_array( $HTTP_GET_VARS ) )
00038 {
00039     $_GET =& $HTTP_GET_VARS;
00040 }
00041 if( !is_array( $_COOKIE ) && is_array( $HTTP_COOKIE_VARS ) )
00042 {
00043     $_COOKIE =& $HTTP_COOKIE_VARS;
00044 }
00045 
00046 // if magic_quotes are off, do it yourself
00047 if( !get_magic_quotes_gpc() )
00048 {
00049 
00050     function addslashes_array( &$array )
00051     {
00052         reset( $array );
00053         while( list( $key, $val ) = each( $array ) )
00054         {
00055             if( is_string( $val ) ) $array[$key] = addslashes( $val );
00056             elseif( is_array( $val ) ) $array[$key] = addslashes_array( $val );
00057         }
00058         return $array;
00059     }
00060 
00061     $_REQUEST = addslashes_array( $_REQUEST );
00062     $_POST = addslashes_array( $_POST );
00063     $_GET = addslashes_array( $_GET );
00064     $_COOKIE = addslashes_array( $_COOKIE );
00065 }
00066 
00070 function output()
00071 {
00072     global $oStyle, $oUser, $strTmpl_inhalt, $x, $y, $booMapUseLastPos;
00073 
00074     // create navi
00075 
00076     // user is logged in
00077     if( $oUser->booLoggedIn )
00078     {
00079         $intMap_x = $oUser->intLastX;
00080         $intMap_y = $oUser->intLastY;
00081         $strMap_url  = "?x=$intMap_x&amp;y=$intMap_y";
00082         $strHome_url = "?x=".$oUser->intHomeX."&amp;y=".$oUser->intHomeY;
00083     }
00084     else
00085     {
00086         $strMap_url  = '';
00087         $strHome_url = '';
00088     }
00089 
00090     $oStyle->setTemplate( 'navigation.html' );
00091 
00092     $strMenuExtra = '';
00093 
00094     if( $oUser->isAdmin( 'search' ) )
00095     {
00096         $strMenuExtra .=  $oStyle->get_area( 'SearchNav' );
00097     }
00098     if( !empty( $booMapUseLastPos ) && $oUser->booLoggedIn )
00099     {
00100         $oStyle->addReplacements( array( 'MAP_URL' => $strHome_url ) );
00101         $strHome = $oStyle->get_area( 'HomeNav' );
00102     }
00103     if( $oUser->isAdmin( 'admin_menu' ) )
00104     {
00105         $strMenuExtra .=  $oStyle->get_area( 'AdminNav' );
00106     }
00107 
00108     if( !empty ( $booMapUseLastPos ) )
00109     {
00110         $oStyle->addReplacements( array( 'MAP_URL' => $strHome_url,
00111                                          'HOME_URL' => $strMap_url,
00112                                          'MENU_EXTRA' => $strMenuExtra,
00113                                          'HOME' => $strHome,
00114                                          'X' => $x,
00115                                          'Y' => $y ));
00116     }
00117     else
00118     {
00119         $oStyle->addReplacements( array( 'MAP_URL' => $strMap_url,
00120                                          'HOME_URL' => $strHome_url,
00121                                          'MENU_EXTRA' => $strMenuExtra,
00122                                          'X' => $x,
00123                                          'Y' => $y ));
00124     }
00125 
00126     $strTmplNav = $oStyle->get_area( 'Navigation' );
00127 
00128     if( empty( $GLOBALS['booMap'] ) )
00129     {
00130         $oStyle->setTemplate( 'main.html' );
00131         $oStyle->addReplacements( array( 'TMPL_NAV' => $strTmplNav, 'TMPL_MAIN' => $strTmpl_inhalt ));
00132         $oStyle->addReplacements( array( 'MAIN_TABLE' => $oStyle->get_area( 'MainTable' ) ) );
00133     }
00134     else
00135     {
00136         $oStyle->setTemplate( 'main.html' );
00137         $oStyle->addReplacements( array( 'TMPL_NAV' => $strTmplNav, 'MAIN_TABLE' => $strTmpl_inhalt ));
00138     }
00139     echo trim( $oStyle->get_area( 'Main' ) );
00140     /*
00141     $debug = debug_backtrace();
00142     echo '<pre>';
00143     echo $oMysql->intQueryCount.' Queries<br>';
00144     print_r($oStyle->getReplacements());
00145     print_r(get_included_files());
00146     */
00147     die();
00148 }
00149 
00150 // load configs and needed classes
00151 require_once( './conf/config.php' );
00152 require_once( './conf/adminconfig.php' );
00153 require_once( './lib/mysql.php' );
00154 require_once( './lib/user.php' );
00155 require_once( './lib/template.php' );
00156 require_once( './lib/logdb.php' );
00157 
00158 $oStyle = new Template( $strTmplPath );
00159 $oStyle->addReplacements( array( 'TITLE' => $strTmplTitle,
00160                                  'REFRESH' => $intTmplRefresh,
00161                                  'PHPSELF' => $_SERVER['PHP_SELF'],
00162                                  'LOGIN_URL' => $_SERVER['PHP_SELF'].'?action=login',
00163                                  'LOGOUT_URL' => $_SERVER['PHP_SELF'].'?action=logout',
00164                                  'SERVER_CHANGE' => $_SERVER['PHP_SELF'].'?action=server',
00165                                  'SERVERNAME' => $strServerName,
00166                                  'SERVERID' => $intServerId,
00167                                  'TEMPLATES' => $oStyle->getPath(),
00168                                  'STYLE' => &$strStyle,
00169                                  'VERSION' => $strPhpMapVersion
00170                                 ) );
00171 
00172 // Read Login Design & Style
00173 $oStyle->setTemplate( 'login.html' );
00174 // split default areas, which are used by other scripts
00175 $oStyle->split_area( 'Refresh' );
00176 $oStyle->split_area( 'Message' );
00177 $oStyle->split_area( 'Errortext' );
00178 $oStyle->split_area( 'Option' );
00179 $oStyle->split_area( 'Select' );
00180 $oStyle->split_area( 'NoDbMsg' );
00181 
00182 $oMysql = new Mysql( $strMysqlHost, $strMysqlUser, $strMysqlPwd, $strMysqlDb );
00183 $oMysql->setPrefix( $strMysqlPrefix );
00184 unset( $strMysqlHost, $strMysqlUser, $strMysqlPwd, $strMysqlDb, $strMysqlPrefix ); // aren't used anymore
00185 
00186 // Diplo Color Replacements
00187 $aReplacements = array();
00188 foreach( $aDiploFgColor AS $intKey => $strColor )
00189 {
00190     $aReplacements['DIPLO_FG_'.$intKey] = $strColor;
00191 }
00192 foreach( $aDiploBgColor AS $intKey => $strColor )
00193 {
00194     $aReplacements['DIPLO_BG_'.$intKey] = $strColor;
00195 }
00196 $oStyle->addReplacements( $aReplacements );
00197 
00198 // user object
00199 $oUser = new User( $oMysql, $oLog, $aAdmin, $aAdminArrays, $strCookiePrefix );
00200 
00201 // logfile object
00202 $oLog = new LogDB( $oMysql, $oUser );
00203 
00204 // check if cookies are set
00205 $strArea = $oUser->checklogin() ? 'UserPanel' : 'LoginForm';
00206 
00207 // Login
00208 if( isset( $_GET['action'] ) && $_GET['action']=='login' )
00209 {
00210     if( $oUser->login( $_POST['f_name'], $_POST['f_pass'] ) )
00211     {
00212         $strTmplMessage = 'Sie sind jetzt Angemeldet!';
00213     $oLog->write( 'Login ok', 3 );
00214         $strArea = 'Refresh';
00215     }
00216     else
00217     {
00218         $strTmplMessage = 'User existiert nicht oder falsches Passwort!';
00219     $oLog->write( 'Login failed for: "'.$_POST['f_name'].'"', 3 );
00220         $strArea = 'Refresh';
00221     }
00222 }
00223 // Logout
00224 elseif( isset( $_GET['action'] ) && $_GET['action']=='logout' )
00225 {
00226     $oUser->logout();
00227     $strTmplMessage = 'Sie sind jetzt Abgemeldet!';
00228     $strArea = 'Refresh';
00229 }
00230 
00231 if( $strArea == 'Refresh' )
00232 {
00233     $oStyle->addReplacements( array( 'REFRESH_URL' => $_SERVER['PHP_SELF'], 'REFRESH_MSG' => $strTmplMessage ) );
00234     echo trim( $oStyle->get_area( 'Refresh' ) );
00235     die();
00236 }
00237 
00238 $oStyle->addReplacements( array( 'USERNAME' => $oUser->strUser ) );
00239 $strLoginArea = $oStyle->get_area( $strArea );
00240 $oStyle->addReplacements( array( 'LOGIN' => $strLoginArea ) );
00241 
00242 // settings
00243 if( isset( $_GET['x'] ) && is_numeric( $_GET['x'] ) && isset( $_GET['y'] ) && is_numeric( $_GET['y'] ) )
00244 {
00245     // no negative values, no values bigger than the map
00246     $x = max( 1, min( $_GET['x'], $intMapSize ) );
00247     $y = max( 1, min( $_GET['y'], $intMapSize ) );
00248     // write back for other classes
00249     $_GET['x'] = $x;
00250     $_GET['y'] = $y;
00251 
00252     // save current position as last used
00253     $booUpdate = true;
00254 }
00255 else
00256 {
00257     $x = $oUser->intLastX;
00258     $y = $oUser->intLastY;
00259     $booUpdate = false;
00260 }
00261 
00262 $intZoom = ( isset( $_GET['zoom'] ) && is_numeric( $_GET['zoom'] ) ) ? $_GET['zoom'] : $oUser->intZoom;
00263 
00264 if( $booUpdate && $oUser->booLoggedIn )
00265 {
00266     $oMysql->query( "UPDATE ".$oMysql->tblUser." SET last_x=$x, last_y=$y, zoom_last=$intZoom WHERE user_id='".$oUser->intUserID."';" );
00267     $oUser->intLastX = $x;
00268     $oUser->intLastY = $y;
00269     $oUser->intZoom = $intZoom;
00270 }
00271 
00272 
00273 if( $oUser->isAdmin( 'banned' ) )
00274 {
00275     // user is banned
00276     $strTmpl_inhalt = '<br /><b>Der Account ist gesperrt.</b>';
00277     output();
00278 }
00279 
00280 if( !$oUser->booLoggedIn )
00281 {
00282     $strTmpl_inhalt = '<br><div align="center">Bitte logge dich erst mal ein :-)</div>';
00283     output();
00284 }
00285 
00286 // get some variables
00287 if(isset($_POST['p_start']))     $intPagerStart = intval( $_POST['p_start'] );
00288 elseif(isset($_GET['p_start']))  $intPagerStart = intval( $_GET['p_start'] );
00289 else $intPagerStart = 0;
00290 
00291 if(isset($_POST['p_count']))     $intPagerCount = intval( $_POST['p_count'] );
00292 elseif(isset($_GET['p_count']))  $intPagerCount = intval( $_GET['p_count'] );
00293 else $intPagerCount = 25;
00294 
00295 
00296 // Update string for DB fields
00297 // if a user wants a smaller Database, he can set these to empty strings and delete the fields in the db
00298 $strUpdateString  = ", `last_update`='".time()."', `last_update_by`='".$oUser->intUserID."'";
00299 $strCreatedString = ", `created`='".time()."', `created_by`='".$oUser->intUserID."'";
00300 $strUpdateFields  = ',last_update,last_update_by';
00301 $strUpdateValues  = ','.time().','.$oUser->intUserID;

Generated on Sun May 8 19:29:45 2005 for PhpMap by  doxygen 1.4.2