<?php
function magic_quote_alter($value,$quote='') {
if ($quote = '"') {
$value = str_replace('"','\"',$value);
} elseif ($quote= "'") {
$value = str_replace("'","\'",$value);
}
if (!get_magic_quotes_gpc()) {
return addslashes($value);
} else {
return $value;
}
}
function ternary($current,$item1,$item2) {
if ($current == $item1) {
return $item2;
} else {
return $item1;
}
}
function getResultDiv($value,$type='error') {
// Formats successful or error results whether they are in an array or a snippet.
if ($type == 'success') {
$class = 'success-div';
} elseif ($type == 'test') {
$class = 'test-div';
} else {
$class = 'error-div';
}
if (is_array($value)) {
for ($i = 0; $value[$i] != ''; $i++) {
$result_div .= '<li>' . $value[$i] . '</li>';
}
if ($result_div != '') {
$result_div = '<div class="' . $class . '"><ul>' . $result_div . '</ul></div>';
}
} else {
if ($value != '') {
$result_div = '<div class="' . $class . '">' . $value . '</div>';
}
}
return $result_div;
}
function showSelected($value,$to_match) {
if ($value == $to_match) {
return ' selected ';
} else {
return '';
}
}
function listArray($array) {
while ($var = each($array)) {
printf ("Key <b>%s</b> has the value of: <b>%s</b><br>", $var['key'], $var['value']);
}
}
if(!function_exists('str_split')){
function str_split($str,$length=1){
$cnt = strlen($str);
for ($i=0; $i<$cnt; $i+=$length) {
$array[]= substr($str,$i,$length);
}
return $array;
}
}
function checkValidChars($string,$valid_chars) {
$string_array = str_split($string);
$valid_chars_array = str_split($valid_chars);
$i = 0;
while ($string_array[$i] != '') {
if (!in_array($string_array[$i],$valid_chars_array)) {
return false;
}
$i++;
}
return true;
}
function removeInvalidChars($string,$valid_chars) {
$string_array = str_split($string);
$valid_chars_array = str_split($valid_chars);
$i = 0;
while ($string_array[$i] != '') {
if (in_array($string_array[$i],$valid_chars_array)) {
$new_string .= $string_array[$i];
}
$i++;
}
return $new_string;
}
function checkLogin($username,$password) {
$result = mysql_query('
SELECT *
FROM weight_loss_tracker_users
WHERE user_username = "' . $username . '" and
user_password = "' . $password . '"');
if (mysql_num_rows($result) > 0) {
return true;
} else {
return false;
}
}
function checkAdminLogin($username,$password) {
$result = mysql_query('
SELECT *
FROM weight_loss_tracker_administrators
WHERE administrators_username = "' . $username . '" and
administrators_pass = "' . $password . '"');
if (mysql_num_rows($result) > 0) {
return true;
} else {
return false;
}
}
function startOptionDiv($unique_id,$title) {
global $weight_loss_tracker_absolute_url;
return '<div class="option-main-div">
<a onclick="switchImage (\'' . $weight_loss_tracker_absolute_url . '/weightlosstracker/images/white-arrow-over.gif\',\'' . $weight_loss_tracker_absolute_url . '/weightlosstracker/images/white-arrow-down.gif\',\'' . $unique_id . '_image\')" href="javascript:toggleLayer(\'manage_' . $unique_id . '\');"><img src="' . $weight_loss_tracker_absolute_url . '/weightlosstracker/images/white-arrow-over.gif" id="' . $unique_id . '_image" name="' . $unique_id . '_image" alt="Click to expand" title="Click to expand"><p> ' . $title . '</p></a>
</div>
<div class="option-block-div" id="manage_' . $unique_id . '">
<div class="highlighted-border">';
}
function endOptionDiv() {
return '</div>
</div>';
}
?>