Files
oav/include/function.inc.php
2024-02-15 09:29:32 +01:00

191 lines
4.1 KiB
PHP

<?php
// Functions Kazar
//
// Test si le fichier est appellŽ "seul"
//if (preg ("function.inc.php", $_SERVER['PHP_SELF']))
//{
// header("Location: /");
// exit;
//}
function printheader($titre){
if(!strlen($titre)) {
$titre = "Homepage";
}
require("header.inc.php");
}
function getimage() {
$curdir=basename(dirname($_SERVER['SCRIPT_NAME']));
if(empty($curdir)) {
return "intro";
} else {
return $curdir;
}
}
// Captcha (cf http://www.webelix.net/trucs_et_astuces-(PHP)_Anti_Robots_Spammeurs.html)
function aff_captcha()
{
// Tableau de valeurs
$input = array(2, 35, 15, 6, 40, 4, 8, 22, 11, 5, 32, 10, 1, 12, 26, 16, 55, 17);
// Extraction aléatoire de deux valeurs du tableau
$rand_keys = array_rand($input, 2);
// Creation et calcul de la somme des deux valeurs
$question = 'Quelle est la somme de <strong>'.$input[$rand_keys[0]].' + '.$input[$rand_keys[1]].' = </strong>';
$add = md5($input[$rand_keys[0]] + $input[$rand_keys[1]]);
echo '<table cellspacing="0" cellpadding="6" style="border: 1px solid red">
<tr>
<td><strong>Anti-Spam : </strong>'. $question .'</td>
<td><input name="reponse" type="text" size="3" maxlength="3" value="" style="font-weight: bold" />
<input name="captcha" type="hidden" value="'. $add .'" /></td>
</tr>
</table>';
}
function valid_captcha()
{
// if (md5($_POST['reponse']) == $_POST['captcha'])
if (md5(get_post('reponse')) == get_post('captcha'))
return true;
else
return false;
}
//
// escape_string
// Action: Escape a string
// Call: escape_string (string string)
//
function escape_string ($string)
{
if (get_magic_quotes_gpc () == 0)
{
$search = array ("/'/", "/\"/", "/;/");
$replace = array ("\\\'", "\\\"", "\\;");
$escaped_string = preg_replace ($search, $replace, $string);
}
else
{
$escaped_string = $string;
}
return $escaped_string;
}
//
// get_post
// Action: Get a variable from POST
// Call: get_post('var');
//
function get_post ($string)
{
if (($_SERVER['REQUEST_METHOD'] == "POST") && isset($_POST[$string]))
{
return escape_string($_POST[$string]);
}
else
{
return NULL;
}
}
//
// get_get
// Action: Get a variable from GET
// Call: get_get('var');
//
function get_get ($string)
{
if (($_SERVER['REQUEST_METHOD'] == "GET") && isset($_GET[$string]))
{
return escape_string($_GET[$string]);
}
else
{
return NULL;
}
}
// Pour le menu parse_ini_file();
function searchini() {
return dirname(__FILE__)."/menu.ini";
}
function domenu() {
$menu = parse_ini_file(searchini(),true);
$topmenu = $menu['topmenu'];
$out = ""; // Out text for menu
if (count($topmenu)> 10) {
return "Error Too mutch lines in top menu (max 4)";
}
// Top menu
$out .= "<div class=\"divmenuhaut\">\n";
//$out .= "<p>&nbsp;</p><p>&nbsp;</p>\n";
$out .= "<p>&nbsp;</p>\n";
$out .= "<ul class=\"menu\">\n";
foreach ($topmenu as $line => $val) {
$out .= "<li><a class=\"";
if ($line == getimage()) {
$out .= "menuon";
} else {
$out .= "menuoff";
}
$out .= "\" href=\"/";
if ($line != "intro") {
$out .= $line."/";
}
$out .= "\" >";
if ($line == getimage()) {
$out .= "&gt; ";
}
$out .= $val."</a></li>";
}
$out .= "</ul></div>\n";
// Bottom menu
/*
$out .= "<div class=\"divmenubas\">\n";
$out .= "<ul class=\"menu\">\n";
foreach ($bottommenu as $line => $val) {
$out .= "<li><a class=\"";
if ($line == getimage()) {
$out .= "menuon";
} else {
$out .= "menuoff";
}
$out .= "\" href=\"/";
if ($line != "intro") {
$out .= $line."/";
}
$out .= "\" >";
if ($line == getimage()) {
$out .= "&gt; ";
}
$out .= $val."</a></li>";
}
$out .= "</ul></div>\n";
*/
print $out;
}
// Page
// Do the page with the right title
function page($titre) {
printheader($titre);
domenu();
print "<div class=\"textebox\">\n";
}
// finpage
// ajoute les tags en fin de page
function finpage(){
require("bottom.inc.php");
}
?>