Jump to content

PHP - Logging | CreateLog | ItemIMG


Recommended Posts

M2 Download Center

This is the hidden content, please
( Internal )

Hello, i created several functions for private server Santhia (czech private server). I hope it will useful for you. 

 

Log system function:

function CreateLog ($status,$fileName,$id,$ip,$itemID = NULL,$desc = NULL) {
   $sql = mysql_query("SELECT login from ".DB_ACC.".account WHERE id = ".mysql_escape($id)." "); 
   if(strtoupper(trim($fileName)) == 'BUY' and !is_null($itemID) )
   {$opt = ' | Item: '.$itemID; } 
   else {$opt = ''; } 
   if (!is_null($desc)){ $descr = $desc; }else{ $descr = ''; }
   $log = new Logging();
   $log->lfile('path/logs/'.$fileName.'.txt');
   $log->lwrite('STATUS: '.strtoupper(trim($status)).' | Login: '.mysql_result($sql,0,login).''.$opt.' | '.$ip.' | '.$descr );
   //e.g. CreateLog ('STATUS',NAME_OF_FILE,$_SESSION['id'],$_SERVER['REMOTE_ADDR'],''ID_ITEMU,'DESCRIPTION');
}

Log system class:

<?php
class Logging {
    private $log_file, $fp;
    
      public function lfile($path) {
          $this->log_file = $path;
      }
      
      public function lwrite($message) {
          if (!is_resource($this->fp)) {
              $this->lopen();
          }
          $time = @date('[Y.m.d H:i:s]');
          fwrite($this->fp, "$time $message" . PHP_EOL);
      }
      
      public function lclose() {
          fclose($this->fp);
      }
      
      private function lopen() {
          $log_file_default = 'path/logs/login.txt';
          $lfile = $this->log_file ? $this->log_file : $log_file_default;
          $this->fp = fopen($lfile, 'a') or exit("Can't open $lfile!");
      }
}
?>

-----------------------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------------------------

Function to display the image of Items:

function ItemImg($vnum) {
  $equip_length = strlen($vnum);
	switch($equip_length) {
	 case '1':
	   $vnum = '0000'.$vnum;
     $id = substr($vnum, 0, -1);
	     break;
	 case '2':
	   $vnum = '000'.$vnum;
     $id = substr($vnum, 0, -1);
			 break;
	 case '3':
		 $vnum = '00'.$vnum;
     $id = substr($vnum, 0, -1);
			 break;
	 case '4':
		 $vnum = '0'.$vnum;
     $id = substr($vnum, 0, -1);
			 break;
   case '5':
		 $vnum1 = $vnum;
			 break;    
  }
  if(file_exists('template/img/isIcon/ico/'.$id.'0.png')) 
  {
    return 'path/ico/'.$id.'0.png';
  } 
  elseif(file_exists('path/ico/'.$vnum1.'.png'))  
  {
    return 'path/ico/'.$vnum1.'.png';
  }
  else
  {
    return 'path/error.png'; // error image. if image is missing
  }
}

I hope it will useful for you. If you have questions feel to free and contact me.

 

Dumik 

WebDeveloper for Santhia

  • Eyes 1
  • Smile Tear 1
  • Think 2
  • Love 5
Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Here is my function to get the image of an item:

function MakeItemImage($vnum)
{
	$ItemType = mysql_result(mysql_query("SELECT type FROM player.item_proto WHERE vnum='".mysql_real_escape_string($vnum)."' LIMIT 1"),0);
	if ($vnum >= 11971 && $vnum <= 11974){return $vnum;} // Kingarmour fix
	if ($ItemType == 1 || $ItemType == 2){
		$vnum = substr($vnum,0,strlen($vnum)-1);
		$vnum .= "0";
		if (strlen($vnum) < 5){
			$Differenz = (5-strlen($vnum));
			$Nullen  = "";
			for ($i = 1; $i <= $Differenz; $i++) {
				$Nullen .= "0";
			}
			$vnum = $Nullen.$vnum;
		}
	}
	return $vnum;
}

How to use:

$vnum = 149;
if (file_exists("is_img/".MakeItemImage($vnum).".png"){
	echo '<img src="is_img/'.MakeItemImage($vnum).'.png"/>';
}
else{
	echo '<img src="is_img/fail.png/>"';
}
Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.