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

taxplaner.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 require_once( './general.php' );
00019 require_once( './lib/taxplaner.php' );
00020 
00021 //Lese Html-Styles
00022 $oStyle->setTemplate( 'taxplaner.html' );
00023 
00024 // delete a town
00025 if( isset( $_GET['delete'] ) )
00026 {
00027     $strTown = urldecode( $_GET['delete'] );
00028     if( isset( $_COOKIE[$strCookiePrefix]['towns'][$strTown] ) )
00029     {
00030         setcookie( $strCookiePrefix . '[towns]['.$strTown.']', '', -2 );
00031         // $_COOKIE will be updated in the next call... -> unset it NOW
00032         unset( $_COOKIE[$strCookiePrefix]['towns'][$strTown] );
00033     }
00034 }
00035 
00036 $intNewSlots   = 0;
00037 $intNewWorker  = 0;
00038 $intNewInflTax = 0;
00039 $intNewGrowth  = 0;
00040 $intNewFood    = 0;
00041 $intNewGold    = 0;
00042 
00043 if( isset( $_POST['submit'] ) )
00044 {
00045     // replace spaces in the town name
00046     $strTown     = str_replace( ' ', '', $_POST['town'] );
00047     $intGrowth   = intval( $_POST['tp_infl_growth'] );
00048     $intInflTax  = intval( $_POST['tp_infl_tax'] );
00049     $intTax      = intval( $_POST['tp_tax'] );
00050     $intWorker   = intval( $_POST['tp_worker'] );
00051     $intFood     = intval( $_POST['tp_food'] );
00052     $intFoodBase = intval( $_POST['tp_food_base'] );
00053     $intUnit     = intval( $_POST['tp_unit'] );
00054     $intBuild    = intval( $_POST['tp_build'] );
00055     $intGold     = intval( $_POST['tp_gold'] );
00056 
00057     $intNewSlots   = intval( $_POST['new_slots'] );
00058     $intNewWorker  = intval( $_POST['new_worker'] );
00059     $intNewInflTax = intval( $_POST['new_infltax'] );
00060     $intNewGrowth  = intval( $_POST['new_inflgrowth'] );
00061     $intNewFood    = intval( $_POST['new_food'] );
00062     $intNewGold    = intval( $_POST['new_gold'] );
00063 
00064     $booNewBuilding = ( abs( $intNewSlots ) + abs( $intNewWorker ) + abs( $intNewInflTax ) + abs( $intNewGrowth ) + abs( $intNewFood ) + abs( $intNewGold ) ) > 0;
00065 
00066     if( !empty( $strTown ) )
00067     {
00068         $intExpire = time() + 7*60*24*60;
00069         $strCookieinfo = "$intGrowth,$intInflTax,$intTax,$intWorker,$intFood,$intFoodBase,$intUnit,$intBuild,$intGold";
00070         setcookie( $strCookiePrefix . '[towns]['.$strTown.']', $strCookieinfo, $intExpire );
00071         // $_COOKIE will be updated in the next call... -> update it NOW
00072         $_COOKIE[$strCookiePrefix]['towns'][$strTown] = $strCookieinfo;
00073     }
00074 }
00075 elseif( isset( $_GET['town'] ) )
00076 {
00077     $strTown = urldecode( $_GET['town'] );
00078     $aData   = explode( ',', $_COOKIE[$strCookiePrefix]['towns'][$strTown] );
00079     $intGrowth   = $aData[0];
00080     $intInflTax  = $aData[1];
00081     $intTax      = $aData[2];
00082     $intWorker   = $aData[3];
00083     $intFood     = $aData[4];
00084     $intFoodBase = $aData[5];
00085     $intUnit     = $aData[6];
00086     $intBuild    = $aData[7];
00087     $intGold     = $aData[8];
00088 }
00089 else
00090 {
00091     $strTown     = '';
00092     $intGrowth   = 0;
00093     $intInflTax  = 0;
00094     $intTax      = 0;
00095     $intWorker   = 0;
00096     $intFood     = 0;
00097     $intFoodBase = 20;
00098     $intUnit     = 0;
00099     $intBuild    = 0;
00100     $intGold     = 0;
00101 }
00102 
00103 $oStyle->addReplacements( array( 'TAXRATE' => $intTax,
00104                                  'PROD_FOOD' => $intFood,
00105                                  'FOOD_BASE' => $intFoodBase,
00106                                  'PROD_GOLD' => $intGold,
00107                                  'BUILDSLOTS' => $intBuild,
00108                                  'UNITSLOTS' => $intUnit,
00109                                  'WORKERS' => $intWorker,
00110                                  'INFL_TAX' => $intInflTax,
00111                                  'INFL_GROWTH' => $intGrowth,
00112                                  'NEW_SLOTS' => $intNewSlots,
00113                                  'NEW_WORKERS' => $intNewWorker,
00114                                  'NEW_INFL_TAX' => $intNewInflTax,
00115                                  'NEW_INFL_GROWTH' => $intNewGrowth,
00116                                  'NEW_PROD_FOOD' => $intNewFood,
00117                                  'NEW_PROD_GOLD' => $intNewGold,
00118                                  'TOWNNAME' => $strTown ) );
00119 
00120 $strTowns = '';
00121 if( isset( $_COOKIE[$strCookiePrefix]['towns'] ) && is_array( $_COOKIE[$strCookiePrefix]['towns'] ) )
00122 {
00123     foreach( $_COOKIE[$strCookiePrefix]['towns'] AS $strTownName => $strData )
00124     {
00125         $strTowns .= ' <a href="taxplaner.php?town='.urlencode( $strTownName ).'">'.$strTownName.'</a> (<a href="javascript:confirmURL(\'taxplaner.php?delete='.urlencode( $strTownName ).'\', \'Stadt '.$strTownName.' wirklich löschen?\')">del</a>) |';
00126     }
00127 }
00128 
00129 $strRight = '';
00130 $strNewBuilding = '';
00131 if( isset( $_POST['submit'] ) )
00132 {
00133     $oPlaner = new Taxplaner();
00134     $oPlaner->set( $intGrowth, $intInflTax, $intTax, $intWorker, $intFood, $intFoodBase, $intUnit, $intBuild, $intGold );
00135 
00136     if( $booNewBuilding )
00137     {
00138         $oPlanerNew = new Taxplaner();
00139         $oPlanerNew->set( $intGrowth+$intNewGrowth, $intInflTax+$intNewInflTax, $intTax, $intWorker+$intNewWorker, $intFood+$intNewFood, $intFoodBase, $intUnit, $intBuild+$intNewSlots, $intGold+$intNewGold );
00140     }
00141 
00142     $strTaxRows = '';
00143 
00144     $aTaxDetails = $oPlaner->taxCalc( $intTax-10, $intTax+10 );
00145     foreach( $aTaxDetails AS $intTaxRate => $aData )
00146     {
00147         $intFood = $aData['food'];
00148         $intGold = $aData['gold'];
00149         if( $intFood < 0 )
00150         {
00151             $intFood = '<span class="red">'.$intFood.'</span>';
00152         }
00153         if( $intGold < 0 )
00154         {
00155             $intGold = '<span class="red">'.$intGold.'</span>';
00156         }
00157         $oStyle->addReplacements( array( 'TAX' => $intTaxRate,
00158                                          'FOOD' => $intFood,
00159                                          'GOLD' => $intGold ) );
00160         $strTaxRows .= $oStyle->get_area( 'TaxRow' );
00161         $intTaxRate++;
00162     }
00163 
00164     $aTaxDetails = $oPlaner->getTaxDetails();
00165     $oStyle->addReplacements( array( 'TP_WORKER' => $aTaxDetails['workers_sum'],
00166                                      'TP_FREE_WORKER' => $aTaxDetails['workers_free'],
00167                                      'TP_TAX' => $aTaxDetails['tax_income'],
00168                                      'TP_FOOD' => $aTaxDetails['food_production'],
00169                                      'TP_FOOD_NEEDED' => $aTaxDetails['food_needed'],
00170                                      'TP_FOOD_FREE' => $aTaxDetails['food']>0 ? $aTaxDetails['food'] : '<span class="red">'.$aTaxDetails['food'].'</span>',
00171                                      'TP_GOLD_FREE' => $aTaxDetails['gold']>0 ? $aTaxDetails['gold'] : '<span class="red">'.$aTaxDetails['gold'].'</span>',
00172                                      'CALC_INFO' => '<b>Berechnung aktuell</b>',
00173                                      'TAX_ROWS' => $strTaxRows ) );
00174     $strRight = $oStyle->get_area( 'TaxPlanerCalc' );
00175 
00176     // and another taxplaner for calculating with new building
00177     if( $booNewBuilding )
00178     {
00179         $strTaxRows = '';
00180 
00181         $aTaxDetails = $oPlanerNew->taxCalc( $intTax-10, $intTax+10 );
00182         foreach( $aTaxDetails AS $intTaxRate => $aData )
00183         {
00184             $intFood = $aData['food'];
00185             $intGold = $aData['gold'];
00186             if( $intFood < 0 )
00187             {
00188                 $intFood = '<span class="red">'.$intFood.'</span>';
00189             }
00190             if( $intGold < 0 )
00191             {
00192                 $intGold = '<span class="red">'.$intGold.'</span>';
00193             }
00194             $oStyle->addReplacements( array( 'TAX' => $intTaxRate,
00195                                              'FOOD' => $intFood,
00196                                              'GOLD' => $intGold ) );
00197             $strTaxRows .= $oStyle->get_area( 'TaxRow' );
00198             $intTaxRate++;
00199         }
00200 
00201         $aTaxDetails = $oPlanerNew->getTaxDetails();
00202         $oStyle->addReplacements( array( 'TP_WORKER' => $aTaxDetails['workers_sum'],
00203                                          'TP_FREE_WORKER' => $aTaxDetails['workers_free'],
00204                                          'TP_TAX' => $aTaxDetails['tax_income'],
00205                                          'TP_FOOD' => $aTaxDetails['food_production'],
00206                                          'TP_FOOD_NEEDED' => $aTaxDetails['food_needed'],
00207                                          'TP_FOOD_FREE' => $aTaxDetails['food']>0 ? $aTaxDetails['food'] : '<span class="red">'.$aTaxDetails['food'].'</span>',
00208                                          'TP_GOLD_FREE' => $aTaxDetails['gold']>0 ? $aTaxDetails['gold'] : '<span class="red">'.$aTaxDetails['gold'].'</span>',
00209                                          'CALC_INFO' => '<b>Berechnung mit neuem Geb&auml;ude</b>',
00210                                          'TAX_ROWS' => $strTaxRows ) );
00211         $strNewBuilding = $oStyle->get_area( 'TaxPlanerCalc' );
00212     }
00213 }
00214 
00215 $oStyle->addReplacements( array( 'TOWNS' => $strTowns,
00216                                  'CALC' => $strRight,
00217                                  'CALC2' => $strNewBuilding ) );
00218 
00219 $strTmpl_inhalt = $oStyle->get_area( 'TaxPlaner' );
00220 output();

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