////
//// Get functions /////
////
function getresult($table,$option,$field="*",$link="")
{
if ($link == "")
global $link;
return mysql_query("SELECT $field FROM $table $option", $link);
}
// echo the query
function getresult2($table,$option,$field="*",$link="")
{
if ($link == "")
global $link;
echo "SELECT $field FROM $table $option ";
return getresult($table,$option,$field,$link);
}
function getrow($table,$option,$field="*",$link="")
{
if ($link == "")
global $link;
$result = mysql_query("SELECT $field FROM $table $option limit 1", $link);
return mysql_fetch_array($result);
}
// echo the query
function getrow2($table,$option,$field="*",$link="")
{
if ($link == "")
global $link;
echo "SELECT $field FROM $table $option limit 1 ";
return getrow($table,$option,$field,$link);
}
function getfield ($field,$table,$option,$link="")
{
if ($link == "")
global $link;
$result = mysql_query("SELECT $field FROM $table $option limit 1", $link);
//echo "SELECT $field FROM $table $option limit 1 ";
$row = mysql_fetch_array($result);
return $row[$field];
}
// echo the query
function getfield2($field,$table,$option,$link="")
{
if ($link == "")
global $link;
echo "SELECT $field FROM $table $option limit 1 ";
return getfield ($field,$table,$option,$link);
}
function xstr2time($strStr, $strPattern = null)
{
// an array of the valide date characters, see: http://php.net/date#AEN21898
$arrCharacters = array(
'd', // day
'm', // month
'y', // year, 2 digits
'Y', // year, 4 digits
'H', // hours
'i', // minutes
's' // seconds
);
// transform the characters array to a string
$strCharacters = implode('', $arrCharacters);
// splits up the pattern by the date characters to get an array of the delimiters between the date characters
$arrDelimiters = preg_split('~['.$strCharacters.']~', $strPattern);
// transform the delimiters array to a string
$strDelimiters = quotemeta(implode('', array_unique($arrDelimiters)));
// splits up the date by the delimiters to get an array of the declaration
$arrStr = preg_split('~['.$strDelimiters.']~', $strStr);
// splits up the pattern by the delimiters to get an array of the used characters
$arrPattern = preg_split('~['.$strDelimiters.']~', $strPattern);
// if the numbers of the two array are not the same, return false, because the cannot belong together
if (count($arrStr) !== count($arrPattern)) {
return false;
}
// creates a new array which has the keys from the $arrPattern array and the values from the $arrStr array
$arrTime = array();
for ($i = 0;$i < count($arrStr);$i++) {
$arrTime[$arrPattern[$i]] = $arrStr[$i];
}
// gernerates a 4 digit year declaration of a 2 digit one by using the current year
if (isset($arrTime['y']) && !isset($arrTime['Y'])) {
$arrTime['Y'] = substr(date('Y'), 0, 2) . $arrTime['y'];
}
// if a declaration is empty, it will be filled with the current date declaration
foreach ($arrCharacters as $strCharacter) {
if (empty($arrTime[$strCharacter])) {
$arrTime[$strCharacter] = date($strCharacter);
}
}
// checks if the date is a valide date
if (!checkdate($arrTime['m'], $arrTime['d'], $arrTime['Y'])) {
return false;
}
// generates the timestamp
$intTime = mktime($arrTime['H'], $arrTime['i'], $arrTime['s'], $arrTime['m'], $arrTime['d'], $arrTime['Y']);
// returns the timestamp
return $intTime;
}
function getaddress()
{
$temp = split("/", $_SERVER['PHP_SELF']);
foreach ($_GET as $key => $value)
{
$myval .= "$theand".$key."=".$value;
$theand = "&";
}
return $temp[count($temp)-1]."?".$myval;
}
// resize image function //
function imageResize($width, $height, $targetw, $targeth)
{
$percentage = 1;
if (($width > $targetw) || ($height > $targeth))
{
$width_diff = $width - $targetw;
$height_diff = $height - $targeth;
if ($width_diff >= $height_diff)
{
$percentage = ($targetw / $width);
}
else
{
$percentage = ($targeth / $height);
}
}
$width = round($width * $percentage);
$height = round($height * $percentage);
$percentage = 1;
//gets the new value and applies the percentage, then rounds the value
if (($width > $targetw) || ($height > $targeth))
{
$width_diff = $width - $targetw;
$height_diff = $height - $targeth;
if ($width_diff >= $height_diff)
{
$percentage = ($targetw / $width);
}
else
{
$percentage = ($targeth / $height);
}
}
$width = round($width * $percentage);
$height = round($height * $percentage);
return "width='$width' height='$height'";
}
//$image_size = getimagesize("upload/$row[photo1]");
//$size = imageResize($image_size[0], $image_size[1], 250,250);
function imageResize2($width, $height, $targetw, $targeth)
{
$percentage = 1;
if (($width > $targetw) || ($height > $targeth))
{
$width_diff = $width - $targetw;
$height_diff = $height - $targeth;
if ($width_diff >= $height_diff)
{
$percentage = ($targetw / $width);
}
else
{
$percentage = ($targeth / $height);
}
}
//gets the new value and applies the percentage, then rounds the value
$width = round($width * $percentage);
$height = round($height * $percentage);
$resize[0] = $width;
$resize[1] = $height;
return $resize;
}
// resize image function //
function newimageResize($width, $height, $targetw, $targeth)
{
$percentage = 1;
if (($width > $targetw) || ($height > $targeth))
{
$width_diff = $width - $targetw;
$height_diff = $height - $targeth;
if ($width_diff >= $height_diff)
{
$percentage = ($targetw / $width);
}
else
{
$percentage = ($targeth / $height);
}
}
$width = round($width * $percentage);
$height = round($height * $percentage);
$percentage = 1;
//gets the new value and applies the percentage, then rounds the value
if (($width > $targetw) || ($height > $targeth))
{
$width_diff = $width - $targetw;
$height_diff = $height - $targeth;
if ($width_diff >= $height_diff)
{
$percentage = ($targetw / $width);
}
else
{
$percentage = ($targeth / $height);
}
}
$width = round($width * $percentage);
$height = round($height * $percentage);
return "width='$width' height='$height'";
}
//$image_size = newimageResize("upload/$row[photo1]");
//$size = imageResize($image_size[0], $image_size[1], 250,250);
// Generate a select field's options
function genOption($dbname, $selectedValue, $name="name",$value="id",$orderby="sorting", $link="")
{
if ($link == "")
global $link;
$options = getresult($dbname," order by ".$orderby,$link);
while ($op = mysql_fetch_array($options))
{
if ($selectedValue != "" && $selectedValue == $op[$value])
$selected = "selected";
else
$selected = "";
$printOptions .= "";
}
return $printOptions;
}
?>