<?php
/**
* Most commonly used functions
*
* @author Roosevelt Purification
* @package RGameScriptPro1.1
*/
/*===========================================================================*\
|| ######################################################################### ||
|| # RGameScript Pro Version 1.1
|| # --------------------------------------------------------------------- # ||
|| # Copyright ©2005-2006 Roosevelt Purification. All Rights Reserved. # ||
|| # RGameScript Pro is a free software released under GNU/GPL License # ||
|| # Website URL: http://www.photoshopcity.com/ # ||
|| ######################################################################### ||
\*===========================================================================*/
$default = $_SERVER[''];
/**
* Function generate a custom input field
*
* @param string $formname The name of the form
* @param string $type The type of input field
* @param string $name The name of the field
* @param string $value The default value of this field
* @param integer $size The size by width of this field
* @param integer $limit The maximum limit of values this field can store
* @return unknown
*/
function FieldMaker($formname, $type = 1, $name, $value = NULL, $size = 30, $limit = 60)
{
switch ($type)
{
case 1:
$type = "text";
return "<input name='".$name."' type='".$type."' value='".$value."' size='".$size."' maxlength='".$limit."'>\n
<script>displaylimit(\"document.$formname.$name\",\"\",".$limit.")</script>\n";
break;
case 2:
$type = "password";
return "<input name='".$name."' type='".$type."' value='".$value."' size='".$size."' maxlength='".$limit."'>\n";
break;
case 3:
return "
<textarea name='".$name."' cols='23' rows='5' onKeyDown=\"textCounter(this,'progressbar1',200)\" onKeyUp=\"textCounter(this,'progressbar1',200)\" onFocus=\"textCounter(this,'progressbar1',200)\">\n"
.$value.
"</textarea>\n<script>displaylimit(\"document.$formname.$name\",\"\",200)</script>\n
<div id=\"progressbar1\" class=\"progress\"></div>\n
<script>textCounter(document.getElementById(\"maxcharfield\"),\"progressbar1\", 200)</script>\n
";
break;
case 4:
$type = "checkbox";
if ($value == 1)
{
$checked = " checked";
}
return "<input name='".$name."' type='".$type."' value='".$value."'$checked>\n";
break;
case 5:
$type = "file";
return "<input name='".$name."' type='".$type."' value='".$value."' size='".$size."' maxlength='".$limit."'>\n";
break;
}
}
/**
* Function to generate a form with two column table
*
* @param string $legend The name of legend fieldset
* @param string $formname The name of the form
* @param string $formaction The action url of the form
* @param array $fieldvalues An array of form inputs and left column messages
* @param string $submitname Name of the submit form
* @param string $submitvalue The value to display on the submit button
* @param string $type The type of form it is, 1 for application and 2 for multipart
* @param string $method How the form will be sent, 1 for POST and 2 for GET
* @param string $fieldguide The extra guide displayed after the table
* @return unknown
*/
function FormGenerator($legend, $formname, $formaction, $fieldvalues, $submitname, $submitvalue, $type = 1, $method = 1, $fieldguide = NULL)
{
if ($type == 1)
{
$type = "application/x-www-form-urlencoded";
}
else
{
$type = "multipart/form-data";
}
if ($method == 1)
{
$method = "post";
}
else
{
$method = "get";
}
$form =
"
<form action='".$formaction."' method='".$method."' enctype='".$type."' name='".$formname."' id='".$formname."' onsubmit=\"return formCheck(this);\">\n
<fieldset><legend><strong>$legend</strong></legend>\n
<table width='100%' align='center' cellpadding='5' cellspacing='6'>\n
";
foreach ($fieldvalues as $key => $value)
{
$form .=
"
<tr>\n
<td>$key</td>\n
<td>$value</td>\n
</tr>\n
";
}
$form .= "</table>\n</fieldset>\n
<div align='center'>\n
<input name='".$submitname."' type='submit' value='".$submitvalue."'>\n
</div>\n
</form>\n";
if (!empty($fieldguide))
{
$form .= "<p>".$fieldguide."</p>";
}
return $form;
}
/**
* Function make a link
*
* @param string $urlThe destination address
* @param string $urltextThe full text url
* @param string $tooltipThe tool tip
* @return stringThe new url
*/
function LinkMaker($url, $urltext = NULL, $tooltip = NULL)
{
if ($_SESSION['rgamesconf']['EnableSEO'] == 1)
{
$url = ereg_replace("\?", "/", $url);
$url = ereg_replace("=", "/", $url);
$url = ereg_replace("&", "/", $url);
}
if (empty($urltext) && !empty($tooltip))
{
$url = "<a href='".$url."' onMouseover=\"ddrivetip('".$tooltip."')\" onMouseout='hideddrivetip()'>$url</a>\n";
return $url;
}
elseif (!empty($urltext) && !empty($tooltip))
{
//Make link withtext and tip
$url = "<a href='".$url."' onMouseover=\"ddrivetip('".$tooltip."')\" onMouseout='hideddrivetip()'>$urltext</a>\n";
return $url;
}
elseif (empty($urltext) && empty($tooltip))
{
//Make link with just just url
$url = "<a href='".$url."'>$url</a>\n";
return $url;
}
elseif (empty($tooltip))
{
//Make normal link
$url = "<a href='".$url."'>$urltext</a>\n";
return $url;
}
}
/**
* Function to generate files under a directory
*
* @param string $name
* @param string $currentstyle
* @return unknown
*/
function GenerateDirectories($dir, $name, $currentstyle = NULL)
{
// Open a known directory, and proceed to read its contents
if ($handle = opendir($dir))
{
$var = "<select name='".$name."'>\n<option></option>\n";
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != ".." && $file != "index.html")
{
if ($currentstyle == $file)
{
$var .= "<option value='"."$file"."' selected>$file</option>\n";
}
else
{
$var .= "<option value='"."$file"."'>$file</option>\n";
}
}
}
$var .= "</select>";
closedir($handle);
}
return $var;
}
/**
* Function to start javascript code
*
*/
function JscriptStart()
{
echo "<script language=\"javascript\" type=\"text/javascript\">\n";
}
/**
* Function to end javascript code
*
*/
function JscriptEnd()
{
echo "</script>\n";
}
/**
* Function to display a message
*
* @param string $message The message you want to display
* @param integer $bold Choose 1 if you want to make the text bold, else use 0
* @param integer $redirect Choose 1 if the user will be redirected
*/
function DisplayMessage($message, $bold, $redirect, $redirecturl = NULL, $dir = NULL)
{
if ($bold == 1)
{
$message = "<strong>$message</strong>\n";
}
$headpart =
"
<table id='Table_01' width='98%' border='0' cellpadding='0' cellspacing='0' align='center'>\n
<tr>\n
<td>\n
<div align='left'><img id='message_01' src='$dir"."rimages/message_01.gif' width='12' height='29' alt='' /></div></td>\n
<td height='29' class='message_top'> </td>\n
<td class='message_top'>\n
<div align='center'><img id='message_03' src='$dir"."rimages/message_03.gif' width='183' height='29' alt='' /></div></td>\n
<td height='29' class='message_top'> </td>\n
<td>\n
<div align='right'><img id='message_05' src='$dir"."rimages/message_05.gif' width='12' height='29' alt='' /></div></td>\n
</tr>\n
<tr>\n
<td width='12' class='message_left'> </td>\n
<td colspan='3' valign='top' bgcolor='#E8EFF5'>\n
";
$footerpart =
"
</td>\n
<td width='12' class='message_right'> </td>\n
</tr>\n
<tr>\n
<td valign='top'>\n
<div align='left'><img id='message_09' src='$dir"."rimages/message_09.gif' width='12' height='14' alt='' /></div></td>\n
<td height='14' colspan='3' valign='top' class='message_bottom'> </td>\n
<td valign='top'>\n
<div align='right'><img id='message_11' src='$dir"."rimages/message_11.gif' width='12' height='14' alt='' /></div></td>\n
</tr>\n
</table>\n
";
if ($redirect == 1)
{
echo $headpart."<div align='center'>".$message.
"<br /><script type=\"text/javascript\">\n
var bar1= createBar(300,15,'white',1,'#CBDAEF','#3D579F',85,7,3,'');
</script>\n
</div>\n
"
.RJavaRedirect($redirecturl, 2)
.$footerpart;
}
else
{
echo $headpart."<div align='center'>".$message."</div>".$footerpart;
}
}
/**
* Function to open an game/image in a pop-up window
*
* @param string $linkname Name of the link
* @param string $filelink The file link
* @param integer $height The height of the window in pixels
* @param integer $width The width of the window in pixels
* @param boolean $fscreen Toggles if the popup will be in a full screen or not
*/
function JavaScriptPopUp($linkname, $filelink, $height, $width, $fscreen = 0)
{
$link = "<a href=\"$filelink\" onclick=\"return popitup('".$filelink."')\" />$linkname</a>\n";
if ($fscreen == 1)
{
$fscreen = "newwindow=window.open(url,'name','type=fullWindow,fullscreen');";
}
else
{
$fscreen = "newwindow=window.open(url,'name','height=".$height.", width=".$width."');";
}
JscriptStart();
echo "
function popitup(url)
{
$fscreen
if (window.focus) {newwindow.focus()}
return false;
}
";
JscriptEnd();
return $link;
}
/**
* Function to redirect the browser to a specific url
*
* @param string $url The url where the browser will be redirected
* @param integer $timeout Amount of seconds an user have to wait before the browser is redirected
*/
function RJavaRedirect($url, $timeout = 0, $message = '')
{
JscriptStart();
$url = str_replace('&', '&', $url);
if ($timeout == 0)
{
echo "window.location=\"$url\";";
}
else
{
echo "myvar = \"\"; timeout = " . ($timeout*10) . ";
function exec_refresh()
{
window.status=\"" . $message."\"+myvar; myvar = myvar + \" .\";
timerID = setTimeout(\"exec_refresh();\", 100);
if (timeout > 0)
{ timeout -= 1; }
else { clearTimeout(timerID); window.status=\"\"; window.location=\"$url\"; }
}
exec_refresh();";
}
JscriptEnd();
}
?>