Bravo List

Bravo List (http://www.bvlist.com/index.php)
-   Mods & Themes (http://www.bvlist.com/forumdisplay.php?f=113)
-   -   Bytes Calculator based on tbdev (http://www.bvlist.com/showthread.php?t=1832)

Edgein 18th January 2009 20:08

Bytes Calculator based on tbdev
 
Hello i'm playing with fts 1.2.3 Final

my first mod is a
a Bytes calculator
You can convert Bytes, KiloBytes, MegaBytes, GigaBytes, and TeraBytes

first the sql for the Moderator Control & Stats Panel

Code:

INSERT INTO `stafftools` (`name`, `file`, `desc`, `minclass`) VALUES
('Calculator', 'calc.php', 'You can here convert Bytes, KiloBytes, MegaBytes, GigaBytes, and TeraBytes', 4);

in functions.php

add above function ug

PHP Code:

function Convert_to_bytes($number$size$returnall=false)
{
if(
$returnall === false)
{
switch(
$size)
{
case 
"t":
return 
$number*1024*1024*1024*1024;
case 
"g":
return 
$number*1024*1024*1024;
case 
"m":
return 
$number*1024*1024;
case 
"k":
return 
$number*1024;
case 
"b":
return 
$number;
}
}
else
{
switch(
$size)
{
case 
"b":
return array(
$number$number/1024$number/1024/1024$number/1024/1024/1024$number/1024/1024/1024/1024);
break;
case 
"k":
return array(
$number*1024$number$number/1024$number/1024/1024$number/1024/1024/1024);
break;
case 
"m":
return array(
$number*1024*1024$number*1024$number$number/1024$number/1024/1024);
break;
case 
"g":
return array(
$number*1024*1024*1024$number*1024*1024$number*1024$number$number/1024);
break;
case 
"t":
return array(
$number*1024*1024*1024*1024$number*1024*1024*1024$number*1024*1024$number*1024$number);
break;
}
}


and create a new file named calc.php and put it into de admin folder

PHP Code:

<?
$rootpath 
'../';
require_once ( 
$rootpath."include/bittorrent.php" ) ;

ADMIN::check();


stdhead("Calculator");


if(
$CURUSER['class'] < UC_MODERATOR){
header("Location: 404.php");}
if(
$_SERVER['REQUEST_METHOD'] == 'POST')
{
if(isset(
$_POST['value']))
{
if(isset(
$_POST['size']))
{
$values Convert_to_bytes($_POST["value"], $_POST["size"], true);
?>


<table width="80%" border="3" cellpadding="0" cellspacing="0" cellpadding="0" align="center" >
<h2>Calculator</h2>
<tr>
<td colspan="3" align="center" nowrap ><b>Coversion Result</b></td>
</tr>
<tr>
<td align="right" nowrap ><b>Bytes</b></td>
<td align="center" nowrap width="1%">=</td>
<td align="left" nowrap ><? echo $values[0];?></td>
</tr>
<tr>
<td align="right" nowrap ><b>KiloBytes</b></td>
<td align="center" nowrap width="1%">=</td>
<td align="left" nowrap ><? echo $values[1];?></td>
</tr>

<tr>
<td align="right" nowrap ><b>MegaBytes</b></td>
<td align="center" nowrap width="1%">=</td>
<td align="left" nowrap ><? echo $values[2];?></td>
</tr>
<tr>
<td align="right" nowrap ><b>GigaBytes</b></td>

<td align="center" nowrap width="1%">=</td>
<td align="left" nowrap ><? echo $values[3];?></td>
</tr>
<tr>
<td align="right" nowrap ><b>TeraBytes</b></td>
<td align="center" nowrap width="1%">=</td>
<td align="left" nowrap ><? echo $values[4];?></td>

</tr>
</table>

<?
}
else{
stderr("Error""Missing post data");
}
}
else{
stderr("Error""Missing post data");
}

?>

<?
}
?>

<p align=center> Get the value of this in Bytes, KiloBytes, MegaBytes, GigaBytes, and TeraBytes </p>
<form method=post action=calc.php name=calc>
<input name=value type=text size=10 value="">&nbsp;<select name=size>
<option value="b">Bytes</option>
<option value="k">KiloBytes</option>
<option value="m">MegaBytes</option>
<option value="g">GigaBytes</option>
<option value="t">TeraBytes</option>
</select>

<input type=submit value='Do It' />
</form>

<?
stdfoot
();
?>


screen:
http://i86.photobucket.com/albums/k1..._2006/calc.jpg


All times are GMT +2. The time now is 20:06.

Powered by vBulletin® Version 3.8.11 Beta 3
Copyright ©2000 - 2024, vBulletin Solutions Inc.