<?

//CHANGES TIMEZONE
function timezone($time) {

global $admin_info;
$time = $time-(date("Z")-(date("I")*3600));

if($admin_info[timezone] == -12) { $new_time = $time - 43200; }
if($admin_info[timezone] == -11) { $new_time = $time - 39600; }
if($admin_info[timezone] == -10) { $new_time = $time - 33000; }
if($admin_info[timezone] == -9) { $new_time = $time - 32400; }
if($admin_info[timezone] == -8) { $new_time = $time - 28800; }
if($admin_info[timezone] == -7) { $new_time = $time - 25200; }
if($admin_info[timezone] == -6) { $new_time = $time - 21600; }
if($admin_info[timezone] == -5) { $new_time = $time - 18000; }
if($admin_info[timezone] == -4) { $new_time = $time - 14400; }
if($admin_info[timezone] == -3.3) { $new_time = $time - 11880; }
if($admin_info[timezone] == -3) { $new_time = $time - 10800; }
if($admin_info[timezone] == -2) { $new_time = $time - 7200; }
if($admin_info[timezone] == -1) { $new_time = $time - 3600; }
if($admin_info[timezone] == 0) { $new_time = $time; }
if($admin_info[timezone] == 1) { $new_time = $time + 3600; }
if($admin_info[timezone] == 2) { $new_time = $time + 7200; }
if($admin_info[timezone] == 3) { $new_time = $time + 10800; }
if($admin_info[timezone] == 3.3) { $new_time = $time + 11880; }
if($admin_info[timezone] == 4) { $new_time = $time + 14400; }
if($admin_info[timezone] == 4.3) { $new_time = $time + 15480; }
if($admin_info[timezone] == 5) { $new_time = $time + 18000; }
if($admin_info[timezone] == 5.5) { $new_time = $time + 19800; }
if($admin_info[timezone] == 6) { $new_time = $time + 21600; }
if($admin_info[timezone] == 7) { $new_time = $time + 25200; }
if($admin_info[timezone] == 8) { $new_time = $time + 28800; }
if($admin_info[timezone] == 9) { $new_time = $time + 32400; }
if($admin_info[timezone] == 9.3) { $new_time = $time + 33480; }
if($admin_info[timezone] == 10) { $new_time = $time + 33000; }
if($admin_info[timezone] == 11) { $new_time = $time + 39600; }
if($admin_info[timezone] == 12) { $new_time = $time + 43200; }

return $new_time;

}

// ROUNDING
function rounder($in) {
  $in = round($in,2);
  if (substr($in,-3,1)=="." | $in == 0) {$out=$in;} else {
     if (!strstr($in,".")) $out = $in.".00";
     if (strstr($in,".")) $out = $in."0";}
  return $out;
}



// DELETES A DIRECTORY
function deleteuse($del_dir) {
  if(str_replace(" ", "", $del_dir) != "./u/" | str_replace(" ", "", $del_dir) != "../u/") {
    @chmod($del_dir, 0777);
    if (is_dir($del_dir)) {
      $handle = opendir($del_dir); 
      while($filename = readdir($handle)) {
        if ($filename != "." && $filename !="..") {
          deleteuse($del_dir."/".$filename);
        }
      }
      closedir($handle);
      rmdir($del_dir);
    } else {
      unlink($del_dir);
    }
  }
} // END deleteuse() function



// ENCRYPTION FUNCTION
function encrypt($password) {

$key = "asdfoiuyqwerlkjqertvywvkhjgqweruiytxcvyotxcyutquweyrgqwejrhgkqiweuryoiutyoweirutyqwlehjbzjxhcvgzxcvgysdfgqgwerhlpoiuyiusgdfkjhasdzzxcnadjaerhetqsdhowuerqpziugalkwjernvbzvoiausiruoqwierjlzvbalsdruqwoiruro";
$crypt = "";
for($i=0;$i<strlen($password);$i++) {
$i_key = ord(substr($key, $i, 1));
$i_pass = ord(substr($password, $i, 1));
$n_key = ord(substr($key, $i+1, 1));
$i_crypt = $i_pass + $i_key;
$i_crypt = $i_crypt - $n_key;
if($i_crypt == 92) {
$i_crypt = 251;
}
$crypt .= chr($i_crypt);
}
return $crypt;
} //END encrypt() function



// DECRYPTION FUNCTION
function decrypt($password) {

$key = "asdfoiuyqwerlkjqertvywvkhjgqweruiytxcvyotxcyutquweyrgqwejrhgkqiweuryoiutyoweirutyqwlehjbzjxhcvgzxcvgysdfgqgwerhlpoiuyiusgdfkjhasdzzxcnadjaerhetqsdhowuerqpziugalkwjernvbzvoiausiruoqwierjlzvbalsdruqwoiruro";
$crypt = "";
$password = stripslashes($password);
for($i=0;$i<strlen($password);$i++) {
$i_key = ord(substr($key, $i, 1));
$i_pass = ord(substr($password, $i, 1));
if($i_pass == 251) {
$i_pass = 92;
}
$n_key = ord(substr($key, $i+1, 1));
$i_crypt = $i_pass + $n_key;
$i_crypt = $i_crypt - $i_key;
$crypt .= chr($i_crypt);
}
return $crypt;
} //END decrypt() function



//USER ENCRYPTION
function u_encrypt($password) {

$key = "asdfoiuyqwerlkjqertvywvkhjgqweruiytxcvyotxcyutquweyrgqwejrhgkqiweuryoiutyoweirutyqwlehjbzjxhcvgzxcvgysdfgqgwerhlpoiuyiusgdfkjhasdzzxcnadjaerhetqsdhowuerqpziugalkwjernvbzvoiausiruoqwierjlzvbalsdruqwoiruro";
$crypt = "";
for($i=0;$i<strlen($password);$i++) {
$i_key = ord(substr($key, $i, 1));
$i_pass = ord(substr($password, $i, 1));
$n_key = ord(substr($key, $i+1, 1));
$i_crypt = $i_pass + $i_key;
$i_crypt = $i_crypt - $n_key;
if($i_crypt == 92) {
$i_crypt = 251;
}
$crypt .= chr($i_crypt);
}

return $crypt;
}//END u_encrypt() function



//USER DECRYPTION
function u_decrypt($password) {

$key = "asdfoiuyqwerlkjqertvywvkhjgqweruiytxcvyotxcyutquweyrgqwejrhgkqiweuryoiutyoweirutyqwlehjbzjxhcvgzxcvgysdfgqgwerhlpoiuyiusgdfkjhasdzzxcnadjaerhetqsdhowuerqpziugalkwjernvbzvoiausiruoqwierjlzvbalsdruqwoiruro";
$crypt = "";
$password = stripslashes($password);
for($i=0;$i<strlen($password);$i++) {
$i_key = ord(substr($key, $i, 1));
$i_pass = ord(substr($password, $i, 1));
if($i_pass == 251) {
$i_pass = 92;
}
$n_key = ord(substr($key, $i+1, 1));
$i_crypt = $i_pass + $n_key;
$i_crypt = $i_crypt - $i_key;
$crypt .= chr($i_crypt);
}
return $crypt;
}//END u_decrypt() function



//RANDOM CODE GENERATOR FUNCTION
function randomcode($len="5") {
$code = NULL;
for($i=0;$i<$len;$i++) {
$char = chr(rand(48,122));
while(!ereg("[a-zA-Z0-9]", $char)) {
if($char == $lchar) { continue; }
$char = chr(rand(48,90));
}
$pass .= $char;
$lchar = $char;
}
return $pass;
} //END randomcode() function


//BMP TO GD CONVERTER FUNCTION
function ConvertBMP2GD($src, $dest = false) {
 if(!($src_f = fopen($src, "rb"))) {
  return false;
 }
 if(!($dest_f = fopen($dest, "wb"))) {
  return false;
 }
 $header = unpack("vtype/Vsize/v2reserved/Voffset", fread($src_f,
14));
 $info = unpack("Vsize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vncolor/Vimportant",
fread($src_f, 40));
 
 extract($info);
 extract($header);

 if($type != 0x4D42) {  // signature "BM"
  return false;
 }

 $palette_size = $offset - 54;
 $ncolor = $palette_size / 4;
 $gd_header = "";
 // true-color vs. palette
 $gd_header .= ($palette_size == 0) ? "\xFF\xFE" : "\xFF\xFF"; 
 $gd_header .= pack("n2", $width, $height);
 $gd_header .= ($palette_size == 0) ? "\x01" : "\x00";
 if($palette_size) {
  $gd_header .= pack("n", $ncolor);
 }
 // no transparency
 $gd_header .= "\xFF\xFF\xFF\xFF";     

 fwrite($dest_f, $gd_header);

 if($palette_size) {
  $palette = fread($src_f, $palette_size);
  $gd_palette = "";
  $j = 0;
  while($j < $palette_size) {
   $b = $palette{$j++};
   $g = $palette{$j++};
   $r = $palette{$j++};
   $a = $palette{$j++};
   $gd_palette .= "$r$g$b$a";
  }
  $gd_palette .= str_repeat("\x00\x00\x00\x00", 256 - $ncolor);
  fwrite($dest_f, $gd_palette);
 }

 $scan_line_size = (($bits * $width) + 7) >> 3;
 $scan_line_align = ($scan_line_size & 0x03) ? 4 - ($scan_line_size &
0x03) : 0;

 for($i = 0, $l = $height - 1; $i < $height; $i++, $l--) {
  // BMP stores scan lines starting from bottom
  fseek($src_f, $offset + (($scan_line_size + $scan_line_align) *
$l));
  $scan_line = fread($src_f, $scan_line_size);
  if($bits == 24) {
   $gd_scan_line = "";
   $j = 0;
   while($j < $scan_line_size) {
    $b = $scan_line{$j++};
    $g = $scan_line{$j++};
    $r = $scan_line{$j++};
    $gd_scan_line .= "\x00$r$g$b";
   }
  }
  else if($bits == 8) {
   $gd_scan_line = $scan_line;
  }
  else if($bits == 4) {
   $gd_scan_line = "";
   $j = 0;
   while($j < $scan_line_size) {
    $byte = ord($scan_line{$j++});
    $p1 = chr($byte >> 4);
    $p2 = chr($byte & 0x0F);
    $gd_scan_line .= "$p1$p2";
   } $gd_scan_line = substr($gd_scan_line, 0, $width);
  }
  else if($bits == 1) {
   $gd_scan_line = "";
   $j = 0;
   while($j < $scan_line_size) {
    $byte = ord($scan_line{$j++});
    $p1 = chr((int) (($byte & 0x80) != 0));
    $p2 = chr((int) (($byte & 0x40) != 0));
    $p3 = chr((int) (($byte & 0x20) != 0));
    $p4 = chr((int) (($byte & 0x10) != 0));
    $p5 = chr((int) (($byte & 0x08) != 0));
    $p6 = chr((int) (($byte & 0x04) != 0));
    $p7 = chr((int) (($byte & 0x02) != 0));
    $p8 = chr((int) (($byte & 0x01) != 0));
    $gd_scan_line .= "$p1$p2$p3$p4$p5$p6$p7$p8";
   } $gd_scan_line = substr($gd_scan_line, 0, $width);
  }
    
  fwrite($dest_f, $gd_scan_line);
 }
 fclose($src_f);
 fclose($dest_f);
 return true;
} //END ConvertBMP2GD()



// CREATES IMAGE FROM BMP FUNCTION
function imagecreatefrombmp($filename) {
 $tmp_name = tempnam("/tmp", "GD");
 if(ConvertBMP2GD($filename, $tmp_name)) {
  $img = imagecreatefromgd($tmp_name);
  unlink($tmp_name);
  return $img;
 } return false;
} //END imagecreatefrombmp()

?>