PhpRiot
Recent Code Pastes

Listing 1528

Submitted by ami, 22 August 2008
<?    
  /*
   * Copyright (c) 2006
   *
   * Florian Schreier. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modification,
   * are permitted provided that the following conditions are met:
   * 
   * 1. Redistributions of source code must retain the above copyright notice,
   * this list of conditions and the following disclaimer.
   * 2. Redistributions in binary form must reproduce the above copyright notice,
   * this list of conditions and the following disclaimer in the documentation
   * and/or other materials provided with the distribution.
   * 3. The names of its contributors may never be used to endorse or promote
   * products derived from this software without specific prior written permission.
   * 
   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   */
  include "config.php";
  
  security();
  
  if ($_POST['edit'] == 0) {
    //--neue Truppen eintragen
      //wenn Eingabefeld für automatische Eingabe ausgefüllt wurde, AUTO-Machanismus in Gang setzen
      if (!empty($_POST['truppen_regex'])) {
          //Regex (sucht die Zahlen aus der Datei heraus)
          $regex = '/(\s\d+){10}/';
          if (preg_match($regex, $_POST['truppen_regex'], $truppen)) {
              //entpacken der Truppen und Übertragung auf Variabeln
              if (ereg("MSIE",$HTTP_USER_AGENT)) { // -- IE
                  $truppen=explode(" ", $truppen[0]);
              } else {                             // -- andere Browser
                  $truppen=explode("\t", $truppen[0]);
              }
              for ($i=1; $i<=10; $i++) {
                  $_POST['t'.$i] = $truppen[$i];
              }
          } else {
              //Fehlermeldung ausgeben, wenn nicht geklappt
              echo "Regex-Fehler!";
          }
      }
      
      //MySQL-Query
    $sql="INSERT INTO ".PREFIX."truppen
            (sid,
             datum,
             volk,
             x1, y1,
             herkunft,
             x2, y2,
             standort,
             t1, t2, t3, t4, t5, t6, t7, t8, t9, t10,
             g1, g2, g3, g4, g5, g6, g7, g8, g9, g10, g11, g12, g13, g14, g15,
gt1, gt2, gt3, gt4, gt5, gt6, gt7, gt8, gt9, gt10, gt11, gt12, gt13, gt14, gt15)
          VALUES
            ('".(int) $sid."',
             now(),
             '".substr($volk, 0, 3)."',
             '".(int) $_POST['x1']."', '".(int) $_POST['y1']."',
             '".stripslashes(mysql_real_escape_string($_POST['her']))."',
             '".(int) $_POST['x2']."', '".(int) $_POST['y2']."',
             '".stripslashes(mysql_real_escape_string($_POST['sta']))."',
             '".(int) $_POST['t1']."', '".(int) $_POST['t2']."', '".(int) $_POST['t3']."', '".(int) $_POST['t4']."', '".(int) $_POST['t5']."',
             '".(int) $_POST['t6']."', '".(int) $_POST['t7']."', '".(int) $_POST['t8']."', '".(int) $_POST['t9']."', '".(int) $_POST['t10']."',
             '".(int) $_POST['g1']."', '".(int) $_POST['g2']."', '".(int) $_POST['g3']."', '".(int) $_POST['g4']."', '".(int) $_POST['g5']."',
             '".(int) $_POST['g6']."', '".(int) $_POST['g7']."', '".(int) $_POST['g8']."', '".(int) $_POST['g9']."', '".(int) $_POST['g10']."',             
             '".(int) $_POST['g11']."', '".(int) $_POST['g12']."', '".(int) $_POST['g13']."', '".(int) $_POST['g14']."', '".(int) $_POST['g15']."',             
             '".(int) $_POST['gt1']."', '".(int) $_POST['gt2']."', '".(int) $_POST['gt3']."', '".(int) $_POST['gt4']."', '".(int) $_POST['gt5']."',
             '".(int) $_POST['gt6']."', '".(int) $_POST['gt7']."', '".(int) $_POST['gt8']."', '".(int) $_POST['gt9']."', '".(int) $_POST['gt10']."',             
             '".(int) $_POST['gt11']."', '".(int) $_POST['gt12']."', '".(int) $_POST['gt13']."', '".(int) $_POST['gt14']."', '".(int) $_POST['gt15']."')";
  } else {
      //--eingetragene Truppen bearbeiten
      //Überprüfung, ob Truppen dem Spieler gehören
    $sql="SELECT
            sid
          FROM
            ".PREFIX."truppen
          WHERE
            tid='".(int) $_POST['edit']."'";
    $result = mysql_query($sql) OR die(mysql_error());
    $row = mysql_fetch_assoc($result);
    
    if ($row['sid'] == $sid) {
        //MySQL-Query
        $sql="UPDATE
                ".PREFIX."truppen
              SET
                datum = now(),
                x1 = '".(int) $_POST['x1']."', y1 = '".(int) $_POST['y1']."',
                herkunft = '".$_POST['her']."',
                x2 = '".(int) $_POST['x2']."', y2 = '".(int) $_POST['y2']."',
                standort = '".$_POST['sta']."',
                t1 = '".(int) $_POST['t1']."', t2 = '".(int) $_POST['t2']."', t3 = '".(int) $_POST['t3']."', t4 = '".(int) $_POST['t4']."', t5 = '".(int) $_POST['t5']."',
                t6 = '".(int) $_POST['t6']."', t7 = '".(int) $_POST['t7']."', t8 = '".(int) $_POST['t8']."', t9 = '".(int) $_POST['t9']."', t10 = '".(int) $_POST['t10']."'
                g1 = '".(int) $_POST['g1']."', g2 = '".(int) $_POST['g2']."', g3 = '".(int) $_POST['g3']."', g4 = '".(int) $_POST['g4']."', g5 = '".(int) $_POST['g5']."',
                g6 = '".(int) $_POST['g6']."', g7 = '".(int) $_POST['g7']."', g8 = '".(int) $_POST['g8']."', g9 = '".(int) $_POST['g9']."', g10 = '".(int) $_POST['g10']."',
                g11 = '".(int) $_POST['g11']."', g12 = '".(int) $_POST['g12']."', g13 = '".(int) $_POST['g13']."', g14 = '".(int) $_POST['g14']."', g15 = '".(int) $_POST['g15']."',
                gt1 = '".(int) $_POST['gt1']."', gt2 = '".(int) $_POST['gt2']."', gt3 = '".(int) $_POST['gt3']."', gt4 = '".(int) $_POST['gt4']."', gt5 = '".(int) $_POST['gt5']."',
                gt6 = '".(int) $_POST['gt6']."', gt7 = '".(int) $_POST['gt7']."', gt8 = '".(int) $_POST['gt8']."', gt9 = '".(int) $_POST['gt9']."', gt10 = '".(int) $_POST['gt10']."',
                gt11 = '".(int) $_POST['gt11']."', gt12 = '".(int) $_POST['gt12']."', gt13 = '".(int) $_POST['gt13']."', gt14 = '".(int) $_POST['gt14']."', gt15 = '".(int) $_POST['gt15']."'                
 
              WHERE
                tid = '".(int) $_POST['edit']."'";
    } else {
        die("Sie haben keine Berechtigung diese Daten zu bearbeiten.");
    }
  }
          
  
  
  //Query absenden
  mysql_query($sql) OR die(mysql_error());
  
  //Ändern des Änderungsdatums
  $sql="UPDATE
          ".PREFIX."spieler
        SET
          lastchange=NOW()
        WHERE
          sid='".(int) $sid."'";
  mysql_query($sql) OR die(mysql_error());
?>
Submit a Follow Up