From 2fcd486ab1a2b13e09e95d1f0d485cebec37499e Mon Sep 17 00:00:00 2001 From: short <> Date: Thu, 16 Aug 2001 01:39:37 +0000 Subject: [PATCH] config.php introduced prepvar() implemented for {GET,POST} input and validation db_* implemented, currently just for content tables headers of common.php must be now called by heading() img_size() implemented for simpler XHTML image size declarations --- common.php | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- config.php | 17 ++++++++++ index.php | 85 +++++++++++++++++++++++++++++------------------- objednavka.php | 4 +-- obsah.php | 48 +++++++++++++++++++++++++++ obsah_init.pl | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 301 insertions(+), 42 deletions(-) create mode 100644 config.php create mode 100644 obsah.php create mode 100755 obsah_init.pl diff --git a/common.php b/common.php index fac6f37..94e1a70 100644 --- a/common.php +++ b/common.php @@ -2,8 +2,9 @@ error_reporting(E_ALL); - $admin_mail="short@ucw.cz"; - $viewcvs=ereg_replace("^/~short/","\\0cgi-bin/viewcvs/",$HTTP_SERVER_VARS["SCRIPT_NAME"]); + include("config.php"); + + // $viewcvs prepared by "config.php" if ($viewcvs==$HTTP_SERVER_VARS["SCRIPT_NAME"]) unset($viewcvs); $cvs_id_split=split(" ",$cvs_id); @@ -41,6 +42,84 @@ function fatal($msg="UNKNOWN") footer(); } +function prepvar($name,$regex=".",$require=true) +{ + global $HTTP_GET_VARS,$HTTP_POST_VARS; + + if (isset($HTTP_GET_VARS[$name])) + $v=$HTTP_GET_VARS[$name]; + else if (isset($HTTP_POST_VARS[$name])) + $v=$HTTP_POST_VARS[$name]; + else + unset($v); + + $name_html="Parametr ".htmlspecialchars($name).""; + + $regex="^$regex\$"; + if (isset($v) && !ereg($regex,$v)) + fatal("$name_html nevyhovuje po¾adovanému regexu ".htmlspecialchars($regex).""); + if (!isset($v) && $require) + fatal("$name_html je vy¾adován"); + + if (!isset($v)) + return(0); + + global $$name; + $$name=$v; + return($v); +} + +function db_connect() +{ + global $db_host,$db_user,$db_pwd,$db_name; + global $db_link; + + if (isset($db_link)) + return; + if (!($db_link=@mysql_connect($db_host,$db_user,$db_pwd))) + fatal("MySQL connect: ".mysql_error()); + if (!mysql_select_db($db_name,$db_link)) + fatal("MySQL database select: ".mysql_error()); +} + +function db_query($query) +{ + global $db_link; + + db_connect(); + if (!($r=mysql_query($query,$db_link))) + fatal("MySQL query \"$query\": ".mysql_error()); + return($r); +} + +function db_row($query) +{ + $q=db_query($query); + $r=mysql_fetch_row($q); + mysql_free_result($q); + return($r); +} + +function db_item($query) +{ + $row=db_row($query); + return($row[0]); +} + +function month_full($year,$month,$month_last=0) +{ + global $tb_obsah; + + if (!$month_last) + $month_last=db_item("select month_last from $tb_obsah where year='$year' and month='$month'"); + return(sprintf("%02d".($month==$month_last ? "" : "-%02d"),$month,$month_last)); +} + +function img_size($width,$height) +{ + return("style=\"border:0;width:${width}px;height:${height}px\" width=\"$width\" height=\"$height\""); +} + function footer() { // deadlock prevention: @@ -55,17 +134,21 @@ function footer()
alt="Valid XHTML 1.0!" />"> |