My little Faction Manager

Dante_A - Heavens Tear
Dante_A - Heavens Tear Posts: 11 Arc User
edited August 2010 in Off-Topic Discussion
*Users who follow this guide do so at their own risk*


Well, i was using a long time the Titles to have an overview about my faction.

Like 0284 - Last seen on 2nd with lvl 84

But me and my members get pi**ed with this. So i've decided to write a little script, to handle all of this.

All you need is a webspace with mysql.

There you can simply create and update a memberlist.

Informations that can be entered:

Name, Date of joining, level joining, last seen, current level, additional information.

All protected with a simple password, so you can give this to your marshalls and executors too.

Other Members can look at the list, ofc. But need the PW to change things.

How to use?

Create a folder with a name of your choice

Create the file
db.php

put this into file:
<?php
 $MYSQL_HOST = "localhost";			//Hostname of MySQL Server, usually localhost
 $MYSQL_USER = "changeme";			//MySQL Username
 $MYSQL_PW   = "changeme";			//MySQL Password
 $MYSQL_DB   = "changeme";			//MySQL Tablename
 $password   = "changeme";			//Password for Webinterface
 $faction    = "changeme";			//Faction Name

 $conn = mysql_connect($MYSQL_HOST, $MYSQL_USER, $MYSQL_PW);
 mysql_select_db($MYSQL_DB, $conn);

?>

change the changemes to your informations

save it

create
install.php
<?php
include './db.php';

$sql = 'CREATE TABLE `manage` ('
        . ' `id` INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, '
        . ' `name` VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, '
        . ' `joined` VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, '
        . ' `jlvl` INT(3) NOT NULL, '
        . ' `seen` VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, '
        . ' `slvl` INT(3) NOT NULL, '
        . ' `info` VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL'
        . ' )'
        . ' ENGINE = myisam;';

$do_it = mysql_query($sql);

?>

save and create
index.php
<?php
include './db.php';

$state = mysql_real_escape_string(htmlspecialchars($_GET["state"]));

?>
<html>
  <head>
    <title><?php echo $faction; ?> Faction Manager - by Dante_A, Heavens Tear</title>
    <style type="text/css">
    <!--
    input { background-color: #330000; color: #aaa; border: 1px solid #111; }
    button { background-color: #330000; color: #aaa; border: 1px solid #111; }
    -->
    </style>
  </head>
  <body bgcolor="#190000" style="color: #aaa;">
    <table>
      <tr>
        <td colspan="11">
        <center><h2>
          <?php
            if($state == 1) { echo '<font color="#880000">Access denied!</font>'; }
            if($state == 2) { echo '<font color="#880000">Error: Not all fields filled!</font>'; }
            if($state == 3) { echo '<font color="#008800">Updated Successfully!</font>'; }
            if($state == 4) { echo '<font color="#880000">Entry for this Name allready in Database!</font>'; }
          ?>
        </h2></center>
        </td>
      </tr>
      <tr>
        <td>
            Delete:
        </td>
        <td>
            *Name:
        </td>
        <td>
            *Joined:
        </td>
        <td>
            *With Level:
        </td>
        <td>
            *Last seen:
        </td>
        <td>
            *With Level:
        </td>
        <td>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </td>
        <td>
            Information:
        </td>
        <td>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </td>
        <td>
            *Password:
        </td>
        <td>
          &nbsp;
        </td>
      </tr>
      <?php
        $count = 0;
        $query = mysql_query("SELECT * FROM `manage` ORDER BY `id` ; ");
          while($row = mysql_fetch_object($query)){
            $count++;
            $id = "$row->id";
            $name = "$row->name";
            $joined = "$row->joined";
            $jlvl = "$row->jlvl";
            $seen = "$row->seen";
            $slvl = "$row->slvl";
            $info = "$row->info";
      ?>
      <tr>
        <form name="handle_<?php echo $id; ?>" action="./handle.php" method="post">
        <td>
            &nbsp;&nbsp;&nbsp;<input name="id" maxlength="10" value="<?php echo $id; ?>" style="display: none; width: 0px;" readonly /><input type="checkbox" name="delete" "value="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </td>
        <td>
            <input name="name" maxlength="32" value="<?php echo $name; ?>" />
        </td>
        <td>
            <input name="joined" maxlength="32" value="<?php echo $joined; ?>" />
        </td>
        <td>
            <input name="jlvl" maxlength="3" value="<?php echo $jlvl; ?>" />
        </td>
        <td>
            <input name="seen" maxlength="32" value="<?php echo $seen; ?>" />
        </td>
        <td>
            <input name="slvl" maxlength="3" value="<?php echo $slvl; ?>" />
        </td>
        <td>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </td>
        <td>
            <input name="info" maxlength="32" value="<?php echo $info; ?>" />
        </td>
        <td>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </td>
        <td>
            <input name="pass" maxlength="32" value="" />
        </td>
        <td>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </td>
        <td>
            <button type="submit">Submit</button>
        </td>
        </form>
      </tr>
      <?php
      if ($count == 15){
        $count = 0;
      ?>
              <tr>
        <td>
            Delete:
        </td>
        <td>
            *Name:
        </td>
        <td>
            *Joined:
        </td>
        <td>
            *With Level:
        </td>
        <td>
            *Last seen:
        </td>
        <td>
            *With Level:
        </td>
        <td>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </td>
        <td>
            Information:
        </td>
        <td>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </td>
        <td>
            *Password:
        </td>
        <td>
          &nbsp;
        </td>
      </tr>
      <?php }} ?>
      <tr>
        <td>
            Delete:
        </td>
        <td>
            *Name:
        </td>
        <td>
            *Joined:
        </td>
        <td>
            *With Level:
        </td>
        <td>
            *Last seen:
        </td>
        <td>
            *With Level:
        </td>
        <td>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </td>
        <td>
            Information:
        </td>
        <td>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </td>
        <td>
            *Password:
        </td>
        <td>
          &nbsp;
        </td>
      </tr>
      <tr>
        <form name="handler" action="./handle.php" method="post">
        <td>
            &nbsp;&nbsp;&nbsp;<input name="id" maxlength="60" value="none" style="display: none; width: 0px;" readonly />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </td>
        <td>
            <input name="name" maxlength="32" value="" />
        </td>
        <td>
            <input name="joined" maxlength="32" value="" />
        </td>
        <td>
            <input name="jlvl" maxlength="3" value="" />
        </td>
        <td>
            <input name="seen" maxlength="32" value="" />
        </td>
        <td>
            <input name="slvl" maxlength="3" value="" />
        </td>
        <td>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </td>
        <td>
            <input name="info" maxlength="32" value="" />
        </td>
        <td>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </td>
        <td>
            <input name="pass" maxlength="32" value="" />
        </td>
        <td>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </td>
        <td>
            <button type="submit">Submit</button>
        </td>
        </form>
      </tr>
    </table>
    <br><br><small>* Required</small>
  </body>
</html>

save and create
handle.php
<?php

include './db.php';

$pass = mysql_real_escape_string(htmlspecialchars($_POST["pass"]));
if ($pass != "$password") {
  header("Location: ./index.php?state=1 ");
  die();
}
$id = mysql_real_escape_string(htmlspecialchars($_POST["id"]));
$del = mysql_real_escape_string(htmlspecialchars($_POST["delete"]));
$name = mysql_real_escape_string(htmlspecialchars($_POST["name"]));
$joined = mysql_real_escape_string(htmlspecialchars($_POST["joined"]));
$jlvl = mysql_real_escape_string(htmlspecialchars($_POST["jlvl"]));
$seen = mysql_real_escape_string(htmlspecialchars($_POST["seen"]));
$slvl = mysql_real_escape_string(htmlspecialchars($_POST["slvl"]));
$info = mysql_real_escape_string(htmlspecialchars($_POST["info"]));

if( $name == "" || $joined == "" || $jlvl == "" || $seen == "" || $slvl == "" ) {
  header("Location: ./index.php?state=2 ");
  die();
}

$query = mysql_query("SELECT * FROM `manage` WHERE `name` = '$name' ; ");
  while($row = mysql_fetch_object($query)){
    $check = "$row->id";
}

if ($id != "none") {

if ($del != 1) {

  $query = "UPDATE `manage` Set name='$name' WHERE id = '$id'";
    $do_it = mysql_query($query);
  $query = "UPDATE `manage` Set joined='$joined' WHERE id = '$id'";
    $do_it = mysql_query($query);
  $query = "UPDATE `manage` Set jlvl='$jlvl' WHERE id = '$id'";
    $do_it = mysql_query($query);
  $query = "UPDATE `manage` Set seen='$seen' WHERE id = '$id'";
    $do_it = mysql_query($query);
  $query = "UPDATE `manage` Set slvl='$slvl' WHERE id = '$id'";
    $do_it = mysql_query($query);
  $query = "UPDATE `manage` Set info='$info' WHERE id = '$id'";
    $do_it = mysql_query($query);
} else {
  $query = "DELETE FROM `manage` WHERE `id` = '$id'";
    $do_it = mysql_query($query);
}

  header("Location: ./index.php?state=3 ");
  die();
} else {

if( $check != '') {
  header("Location: ./index.php?state=4 ");
  die();
}

$m_m_e = "INSERT INTO `manage` (name, joined, jlvl, seen, slvl, info)
          VALUES ('$name', '$joined', '$jlvl', '$seen', '$slvl', '$info')";
  $do_it = mysql_query($m_m_e);

  header("Location: ./index.php?state=3 ");
  die();

}

echo "Unexpected Error!<br>Please inform admin!";

?>

save and open now in browser

www.yourside.de/yourfolder/install.php

delete install.php

and open www.yourside.de/yourfolder/index.php

there you go =)

maybe someone find this usefull ^^

i just can say, my faction is happy now, since they can use the title option