<?php
// =====================================================
//
// s-p-e - Content management system.
// Copyright (C) 2004, 2005, 2006, 2010, 2011 Vladimir B. Tsarkov
//
// This file is part of s-p-e.
//
// s-p-e is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// s-p-e is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with s-p-e. If not, see <http://www.gnu.org/licenses/>.
//
// ------
//
// You can contact me via e-mail: lipetsk-gnu-lug at bk period ru
//
// functions.php
//
// Abstract: Functions.
//
// Revision History:
//
// 1 2004-03-27 - 2005-07-02 vbt
// 2 2005-07-22 vbt
// 3 2006-02-24 vbt
// 4 2010-06-24 vbt
// 5 2011-01-22 vbt
//
// =====================================================
function auth($connector, $sid, $type, $prefix)
{
$result = mysql_query("select login
from ".($prefix)."session
where sid='$sid'
and type='$type'", $connector)
or die("error #102-f1");
if(mysql_num_rows($result) == 0)
{
return false;
}
if($row = mysql_fetch_array($result))
{
return $row["login"];
}
mysql_free_result($result);
mysql_close($connector);
}
function cache()
{
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
session_cache_limiter("nocache");
}
function comments($id, $rid, $host, $user, $password, $database, $prefix)
{
$connector = mysql_connect("$host", "$user", "$password") or die("error #103-f1");
mysql_select_db("$database", $connector) or die("error #104-f1");
$result = mysql_query("select uname, date, timer
from ".($prefix)."comment
where partid='$id'
and recid='$rid'
order by date desc, timer desc", $connector)
or die("error #102-f2");
$number = mysql_num_rows($result);
mysql_free_result($result);
mysql_close($connector);
echo $number;
}
function connect($host, $user, $password, $database, &$connector)
{
$connector = mysql_connect("$host", "$user", "$password") or die("error #103-f2");
mysql_select_db("$database", $connector) or die("error #104-f2");
}
function langch($lng)
{
if($lng == "ru")
{
return $language = "russian";
}
else if($lng == "en")
{
return $language = "english";
}
else
{
return $language = $cfg["deflangvisitor"];
}
}
function language($language)
{
// Here we can add the support of different languages.
if($language == "russian")
{
putenv("LC_ALL=ru_RU");
setlocale(LC_ALL, "ru_RU.utf8");
$domain = "messages";
if(ereg("\/data$", dirname($_SERVER['PHP_SELF'])) == true)
{
bindtextdomain($domain, "../locale");
}
else
{
bindtextdomain($domain, "locale");
}
textdomain($domain);
}
}
function line()
{
echo "<hr width='99%' color='black'>";
}
function publicform($type,
$tabheader,
$partname,
$theme,
$intro,
$full,
$date,
$num,
$time,
$update)
{
echo "<form action='addnews.php' method='post'>
<table border='1' class='admin-table'>
<tr>
<td>
<font class='s-normal' id='w-bold'>$tabheader</font>
</td>
</tr>
<tr>
<td>
<table border='0'><br>
<tr>
<td>
<font class='s-normal' id='w-normal'>".(_("Section")).":</font>
</td>
<td>
<font class='s-normal' id='w-normal'>$partname</font>
</td>
</tr>";
if($date.$time != "nn")
{
echo "<input type='hidden' name='date' value='".(base64_encode($date))."'>";
}
echo "<input type='hidden' name='num' value='".(base64_encode($num))."'>
<input type='hidden' name='type' value='".(base64_encode($type))."'>
<input type='hidden' name='partname' value='".(base64_encode($partname))."'>
<tr>
<td>
<font class='s-normal' id='w-normal'>".(_("Theme")).": </font></td>";
if($update == "y")
{
echo "<td>
<font class='s-normal' id='w-normal'>$theme</font>
</td>";
}
else
{
echo "<td>
<INPUT class='admin-text'
type='text'
name='newtheme'
size='80'
maxlength='100'
value='".eregi_replace("'", "'",$theme)."'>
</td>";
}
echo "</tr>
<tr>";
if($date.$time != "nn")
{
echo "<td>
<font class='s-normal' id='w-normal'>
".(_("Date")).":
</font>
</td>
<td>
<font class='s-normal' id='w-normal'>
$date ".(_("Time")).": $time
</font>
</td>";
}
echo "</tr>
</table>
<br>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td align='left'>
<font class='s-normal' id='w-normal'>".(_("Introduction")).":</font>
</td>
<td>
<textarea cols='42' rows='6' name='newintro'>".trim((str_replace("<br>", "\n", $intro)))."</textarea>
</td>
</tr>
<tr>
<td>
<font class='s-normal' id='w-normal'>".(_("Full text")).":</font>
</td>
<td>
<textarea cols='42' rows='15' name='newtext'>".(str_replace("<br>", "\n", $full))."</textarea>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<div align='right'>
<table>
<tr>";
if($update == "n")
{
echo "<td>
<INPUT class='admin-button' type='submit' name='update' value='".(_("Update"))." »'>
</td>
<td>
<INPUT class='admin-button' type='submit' name='save' value='".(_("Save"))." »'>
</td>";
}
if($update == "y")
{
echo "<td>
<INPUT class='admin-button' type='submit' name='update' value='".(_("Update"))." »'>
</td>";
}
echo "</tr>
</table>
</div>
</td>
</tr>
</table>
</form>";
}
function pwdlength($newpwd)
{
if(strlen($newpwd)<8)
{
return 0;
}
else
{
return 1;
}
}
function redirect($value)
{
if($value == false)
{
if(headers_sent() == false)
{
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: auth.php");
exit;
}
else
{
echo "Error: Headers already sent!";
}
}
}
function search_pager($pageline, $page, $addrline, $pageq)
{
if(isset($pageline) && $page > 1)
{
$prevappend = "<a href='$addrline".($page - 1)."'>".(_("Previous"))."</a> ";
}
else
{
$nextappend = "<a href='$addrline".($page + 1)."'>".(_("Next"))."</a>";
}
if(isset($pageline) && $page > 1 && $pageq > $page)
{
$prevappend = "<a href='$addrline".($page - 1)."'>".(_("Previous"))."</a> ";
$nextappend = "<a href='$addrline".($page + 1)."'>".(_("Next"))."</a>";
}
if(isset($pageline) && isset($prevappend) && isset($nextappend) == false)
{
$string = "<font class='s-normal' id='w-normal'>$prevappend"."$pageline</font>";
}
if(isset($pageline) && isset($prevappend) == false && isset($nextappend))
{
$string = "<font class='s-normal' id='w-normal'>$pageline"."$nextappend</font>";
}
if(isset($pageline) && isset($nextappend) && isset($prevappend))
{
$string = "<font class='s-normal' id='w-normal'>$prevappend"."$pageline"."$nextappend</font>";
}
if(isset($string))
{
return $string;
}
}
function search_parser($array, $type)
{
if($type == "any")
{
$symbol = "|";
}
for($i = 0; isset($array[$i]); $i++)
{
if($i == 0)
{
if(sizeof($array) == 1)
{
$array[$i] = eregi_replace("^(\.)*$", "\.", $array[$i]);
$string = "$array[$i]";
}
else
{
$array[$i] = eregi_replace("^(\.)*$", "\.", $array[$i]);
$string = "$array[$i]".$symbol;
}
}
else
{
if(sizeof($array) == ($i + 1))
{
$array[$i] = eregi_replace("^(\.)*$", "\.", $array[$i]);
$string = $string."$array[$i]";
}
else
{
$array[$i] = eregi_replace("^(\.)*$", "\.", $array[$i]);
$string = $string."$array[$i]".$symbol;
}
}
}
return $string;
}
// Implementation of session-handling functions
// used to store information using MySQL DBMS
function open()
{
global $cfg;
require_once("configure/specfg.php");
connect($cfg["host"], $cfg["user"], $cfg["password"], $cfg["database"], $connector);
return $connector;
}
function close()
{
return true;
}
function read($value)
{
global $cfg;
$result = mysql_query("SELECT type
FROM ".($cfg["prefix"])."session
WHERE sid = '$value'
AND expiration >".(time())."")
or die("error #102-f3");
if($row = mysql_fetch_array($result))
{
return $row["type"];
}
return false;
}
function write($info, $value)
{
global $cfg;
$expiration = time() + 1200;
if(($info[0] == true) && ($info[1] == true) && ($value == true))
{
mysql_query("INSERT INTO ".($cfg["prefix"])."session
(login, type, sid, expiration)
VALUES ('".($info[0])."', '".($info[1])."', '$value', '$expiration')")
or die("error #102-f4");
}
}
function destroy($value)
{
global $cfg;
$result = mysql_query("DELETE FROM ".($cfg["prefix"])."session WHERE sid = '$value'") or die("error #102-f5");
return $result;
}
function gc()
{
global $cfg;
// require_once("configure/specfg.php");
$result = mysql_query("DELETE FROM ".($cfg["prefix"])."session WHERE expiration < ".(time())."")
or die("error #102-f6");
return mysql_affected_rows();
}
// End of implementation of session-handling
// functions used to store information using MySQL DBMS
?>