Ejemplo n.º 1
0
 public static function SaveAccount($data)
 {
     $query = 'UPDATE account SET ';
     foreach ($data as $key_ => $value_) {
         $key = mysql_real_escape_string($key_, DB::$handler);
         $value = mysql_real_escape_string($value_, DB::$handler);
         if ($key != 'id') {
             if ($value == null) {
                 $query .= "{$key}=NULL, ";
             } else {
                 $query .= "{$key}='{$value}', ";
             }
         }
     }
     $id = mysql_real_escape_string($data['id'], DB::$handler);
     $query = substr($query, 0, strlen($query) - 2) . ' WHERE id=' . $id;
     mysql_query($query, DB::$handler) or DB::DBdie('Error updating account data: ' . mysql_error() . "\n");
     DB::Commit();
     return true;
 }
Ejemplo n.º 2
0
 public function save()
 {
     if ($this->isPersistent) {
         return true;
     }
     //TODO: add validation
     // Begin database transaction
     DB::BeginTransaction();
     $success = true;
     if ($this->att('objid')) {
         // we are in UPDATE modus
         if (!$this->_deactivate()) {
             $success = false;
         }
     }
     // insert new version of the object...
     $sql = 'INSERT INTO ' . $this->tableName() . "(objid, isActive, created, createdby, modified, modifiedby, IPv4";
     foreach ($this->attributes as $att) {
         if (!in_array($att->name, $this->metaattributes)) {
             $sql .= ", " . $att->name;
         }
     }
     $sql .= ") VALUES (";
     // objid
     if (!$this->att("objid")) {
         $minimumID = date("Ymd") * 100000 + rand(0, 50000);
         $minimumID = 1;
         $sql .= "ifnull((SELECT newID FROM (SELECT MAX(objID) + 1 as 'newID' FROM " . $this->tableName() . " WHERE objID >= " . $minimumID . ") as x), " . $minimumID . ")";
         $this->att("created", time());
         $this->att("createdby", 1);
         // TODO: effectieve gebruiker invullen!
         $this->att("modified", $this->att("created"));
         $this->att("modifiedBy", 1);
         // TODO: effectieve gebruiker invullen!
     } else {
         $sql .= DB::qstr($this->att("objid"));
         $this->att("modified", time());
         $this->att("modifiedBy", 1);
         // TODO: effectieve gebruiker invullen!
         if (!$this->att("created")) {
             $this->att("created", time());
         }
     }
     // isActive
     $sql .= ", 1";
     // created
     $sql .= ', FROM_UNIXTIME(' . $this->att('created') . ')';
     // createdby
     $sql .= ', ' . DB::qstr($this->att('createdby'));
     // modified
     $sql .= ", NOW()";
     // modifiedBy
     $sql .= ", " . DB::qstr($this->att("modifiedby"));
     // IPvq adres van de modification
     $sql .= ", " . DB::qstr($_SERVER["REMOTE_ADDR"]);
     // loop over the attributes here...
     foreach ($this->attributes as $att) {
         if (!in_array($att->name, $this->metaattributes)) {
             switch ($att->type) {
                 case "datetime":
                 case "date":
                 case "time":
                     if ($this->att($att->name) == null) {
                         $sql .= ", NULL";
                         break;
                     } else {
                         // timestamps are in unixtimestamp in php
                         $sql .= ", FROM_UNIXTIME(" . $this->att($att->name) . ")";
                         break;
                     }
                 case "varchar":
                 case "bigint":
                 case "int":
                 case "tinyint":
                 case "text":
                 case "decimal":
                     $sql .= ", " . DB::qstr($this->att($att->name));
                     break;
                 default:
                     throw new Exception("Datatype " . $att->type . " not supported for " . get_class($this) . "." . $att->name);
             }
         }
     }
     $sql .= ")";
     // end of values
     try {
         DB::Execute($sql);
     } catch (Exception $e) {
         // catching exception and returning false...
         echo $e->getMessage();
         $success = false;
     }
     if ($success && !$this->att("objID")) {
         // we have a new object id...
         // let's get it from the database
         $sql = "SELECT objId as id FROM " . $this->tableName() . " WHERE seqid = " . DB::Insert_ID();
         $rs = DB::Execute($sql);
         $this->att("objID", $rs->fields["id"]);
     }
     DB::Commit($success);
     return $success;
 }
Ejemplo n.º 3
0
 public static function SaveData()
 {
     static $numsaves = 0;
     //      echo "*** Starting data save ...\n";
     DB::StartTransaction();
     Accounts::Save();
     Factions::Save();
     Houses::Save();
     DB::Commit();
     //      echo "*** Data saved sucessfully!\n";
     $numsaves++;
     if ($numsaves == 12) {
         //        echo "*** Doing manteinance...\n";
         /* Make manteinance */
         Factions::UpdateMembercount();
         $numsaves = 0;
         //        echo "*** Manteinance complete!\n";
     }
 }
Ejemplo n.º 4
0
function dosavedata(Player $player, $numparams, $params)
{
    Accounts::Save();
    DB::Commit();
    return COMMAND_OK;
}