0777, 'timeFormat' => '%d.%m.%Y %H:%M:%S');
$dsLog = &Log::singleton('file', DALEN_PATH_LOG . 'ds.log', 'DS', $conf);
$dsLog->log('-->');
}
$db = DB::connect("mysql://" . DB_USER .
":" . DB_PASSWORD .
"@" . DB_SERVER .
"/" . DALEN_SITE);
if (DB::isError($db) || '' == DALEN_SITE) {
die("472 Nemohu se pripojit do db");
}
// proměnné už nejsou potřeba
$c['mysql'] = array();
$db->setFetchMode(DB_FETCHMODE_ASSOC);
// připojení souborů na Menu
//require_once(DALEN_PATHU . 's/TreeMenu/TreeMenu.php');
// Připojení dalších souborů
require_once(DALEN_PATHS.'FckEditor/fckeditor.php');
require_once(DALEN_PATHS.'Excel/Writer.php');
require_once(DALEN_PATHS.'Excel/Reader.php');
///////// Inicalizace session a pøípadné pøihlášení
$session = new Session(); // Provede session_start() a inicializaci
$res = $session->login($u);
if(isErr($res)) {
$u = new DefUser($_SESSION['userID'], $_SESSION['userPassword']);
}
if(isset($_GET['logout']))
{
$session->logout();
$p['presmerovani'] = DALEN_ROOTPAGE;
header("HTTP/1.1 301 Moved Permanently");
header("Location: $p[presmerovani]");
header("Connection: close");
exit;
}
///////// redirect if URL not end with /
ereg("^([^\?]+)(\??[^\?]*)$", $scriptUrl, $redirTmp);
if(!ereg("^.*\/$", $redirTmp[1]))
{ //// přidáváme lomítko nakonec
$t['redir'] = $redirTmp[1]."/".$redirTmp[2];
header("HTTP/1.1 301 Moved Permanently");
header("Location: ". $t['redir']);
header("Connection: close");
exit;
}
if(DALEN_REWRITE) {
$cesta = substr($scriptUrl, strlen(DALEN_URLROOT)-1);
} else {
$_GET['dalen_url'] ? $cesta = "/".$_GET['dalen_url'] : $cesta = "/";
}
function getPathToArray($way) {
ereg("\/([^\?\/]*)(.*)(\??.*)", $way, $tmp);
$return = array();
if(''!=$tmp[1])
$return[] = $tmp[1];
if(ereg("\/", $tmp[2]))
$return = array_merge($return, getPathToArray($tmp[2]));
return $return;
}
$i['path'] = getPathToArray($cesta);
if(!is_array($i['path']))
$i['path'] = array();
array_unshift($i['path'], 'dalen_rootpage');
/////////// parse id_record
unset($erg);
if(DALEN_REWRITE) {
eregi(substr(DALEN_URLROOT,0,-1).".*/([a-z0-9_-]+)/(\?.*)?$", $scriptUrl, $erg);
$erg[1]?$i['id']=$erg[1]:$i['id'] = DALEN_ROOTPAGE;
} else {
$_GET['dalen_url'] ? '' : $_GET['dalen_url'] = '';
ereg(".*/([a-z0-9_-]+)/(\?.*)?$", "/".$_GET['dalen_url'], $erg);
$erg[1]?$i['id']=$erg[1]:$i['id'] = DALEN_ROOTPAGE;
}
if(!idExists($i['id'])) {
header ("HTTP/1.0 404 Not Found");
$i['id'] = DALEN_ERRORPAGE404;
} else {
$dalenUserPrivilege = new RealPrivilegeCache($u->userID);
$dalenUserPrivilege->get($i['id'], RECORD_PRIVILEGE, false);
if(0==$dalenUserPrivilege->canRead || 2==$dalenUserPrivilege->canRead) {
header ("HTTP/1.0 401 Unauthorized");
$i['id'] = DALEN_ERRORPAGE401;
}
}
///////// select Page
$select = "SELECT Record.recordID, Record.versionUserID, Record.recordName,
Record.parentRecordID, Record.parentVersionUserID,
RecordLink.linkedID templateRecordID, RecordLink.linkedUserID templateVersionUserID,
Record.recordLastModified
FROM Record, RecordLink
WHERE Record.recordID=RecordLink.recordID
AND Record.versionUserID=RecordLink.versionUserID
AND Record.recordID = '".$i['id']."'
AND RecordLink.linkType = 'template'
";
$result = $db->query($select);
if (DB::isError($result)) {
die($result->message);
} else {
$d = $result->fetchRow();
}
if($temp = propertyValue($i['id']))
{
////// select PropertyValues for Page
foreach($temp as $key => $val)
{
$propertyValue[$key] = $property[$key] = $val;
}
}
$sql = "SELECT p.propertyID, p.propertyName
FROM `Property` AS p
RIGHT JOIN `Record` AS r ON recordID = '". $i['id'] ."'
WHERE r.typeID = p.typeID";
$res = $db->query($sql);
while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
{
$propertyName[$row['propertyID']] = $row['propertyName'];
}
////// select current template
$t = array();
$sql = "
SELECT p.propertyID, p.typeID
FROM `Property` AS p
RIGHT JOIN `Record` AS r ON r.typeID = p.typeID
WHERE r.recordID = '".$d['templateRecordID']."'
ORDER BY p.propertyOrder
";
$res = $db->query($sql);
$tmp = '';
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
$tmp[] = $row->propertyID;
if(!isset($typeID))
$typeID = $row->typeID;
}
$prop = '';
foreach($tmp as $key)
$prop .= ", t.".$key;
$select = "
SELECT t.recordID". $prop .", r.parentRecordID
FROM `_". $typeID ."` AS t, Record AS r
WHERE t.recordID = r.recordID
AND r.recordID = '".$d['templateRecordID']."'
LIMIT 1
";
$rTemplate = $db->getRow($select);
$temps = '';
unset($rTemplate['recordID']);
foreach($rTemplate as $key => $val)
{
if('parentRecordID' != $key) {
if('' == $val) {
$temps .= " , t.".$key;
} else {
$t[$key] = $val;
}
}
}
if(''!=$temps) {
if(isset($t) AND is_array($t)) {
$ttt = inheritTemplate($temps, $rTemplate['parentRecordID']);
if(null!=$ttt)
$t = array_merge($ttt, $t);
}
else
$t = inheritTemplate($temps, $rTemplate['parentRecordID']);
}
unset($temps);
function inheritTemplate($properties, $parentRecordID)
{
global $xx,$db;
$t = array();
$temp = '';
if(DALEN_ROOTRECORD == $parentRecordID)
return '';
$sql = " SELECT typeID " .
" FROM `Record` " .
" WHERE recordID = ".sr($parentRecordID).
" LIMIT 1";
$row = $db->getRow($sql);
$select = "
SELECT r.parentRecordID". $properties ."
FROM `_".$row['typeID']."` AS t, Record AS r
WHERE t.recordID = r.recordID
AND r.recordID = '". $parentRecordID ."'
LIMIT 1
";
$rTemplate = $db->getRow($select);
foreach($rTemplate as $key => $val)
{
if('parentRecordID' != $key) {
if('' == $val) {
$temp .= " , t.".$key;
} else {
$t[$key] = $val;
}
}
}
if(''!=$temp) {
if(isset($t) AND is_array($t)) {
$ttt = inheritTemplate($temp, $rTemplate['parentRecordID']);
if(is_array($ttt))
$t = array_merge($ttt, $t);
}
else {
$t = inheritTemplate($temp, $rTemplate['parentRecordID']);
}
}
return $t;
}
$tt['template'] = '';
foreach($tmp as $key) {
$tt['template'] .= $t[$key];
}
unset($t);
/// nastavuje http hlavičku na recordLastModified a převádí do RFC formátu
//ereg("^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$",$d['recordLastModified'],$ergtime);
//Header("Last-Modified: ".date("r",mktime($ergtime[4],$ergtime[5],$ergtime[6],$ergtime[2],$ergtime[3],$ergtime[1])));
// nastavuje http hlavičku Last-Modified na aktuální čas
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
$query = $db->_queryCount;
$tTime = timer();
// Execute TEMPLATE
eval($tt['template']);
$query = 'SQL counter: ' . ($db->_queryCount - $query) . ' / ' . $db->_queryCount;
$time = 'Execution time: ' . timer($tTime) . ' / ' . timer($time) . ' s';
// Verbose mode
if (isset($xx['verbose']))
{
if ($xx['verbose']>4)
{
print '
';
print $query;
print '
';
print $time;
}
}
// Debug Log
if (defined('DALEN_LOG_DS') && DALEN_LOG_DS) {
$dsLog->log($query);
$dsLog->log($time);
$dsLog->log('<--');
}
?>