= '5.0.0')
include('DUPDATE_XML_PHP5.PHP');
else
include('DUPDATE_XML_PHP4.PHP');
if (checkPHPVersion() == FALSE)
exit;
if (checkRightsByIP($ip) == FALSE)
exit;
if (($root = getXMLRoot()) == FALSE)
exit;
if (getConnection($conn, $host, $uid, $pw, $db) == FALSE)
exit;
if (checkRightsByKey($connPw, $keySeed, $root->getAttribute("KEY")) == FALSE)
exit;
$root->setAttribute("LANG", $lang);
$root->setAttribute("FILEPATH", $filePath);
$root->setAttribute("TOPTARGET", $topTarget);
$root->setAttribute("CONN", $conn);
include("DUPDATE_" . $type . "_" . $root->getAttribute("APPLICATION") . ".PHP");
switch ($root->getAttribute("ACTION"))
{
case 'test':
test($root);
break;
case 'start_update':
start_update();
break;
case 'finish_update':
finish_update();
break;
case 'old_items':
countOldItems($root);
break;
case 'meeting_handlers':
updateTelimet($root);
break;
case 'meeting':
updateMeeting($root);
break;
case 'meetingitem':
updateMeetingitem($root);
break;
case 'meetingitem_attachements':
updateAttachements($root);
break;
case 'delete_meeting':
deleteMeeting($root);
break;
case 'official_handlers':
updateVhaltijat($root);
break;
case 'official_decision':
updateOffDecision($root);
break;
case 'official_decision_attachements':
updateAttachements($root);
break;
case 'delete_official_decision':
deleteOffDecision($root);
break;
case 'document_folders':
updateFolders($root);
break;
case 'document':
updateDocument($root);
break;
case 'document_attachements':
updateAttachements($root);
break;
case 'delete_document':
deleteDocuments($root);
break;
//case 'folder_in_use':
// folderInUse($root);
// break;
default:
break;
}
//***************************************************************************
function checkPHPVersion()
{
$retVal = FALSE;
if (phpversion() >= '4.3.0')
$retVal = TRUE;
else
sendError(001, "PHP:n versio liian vanha, vaaditaan vähintään PHP versio 5.");
return $retVal;
}
//***************************************************************************
function checkRightsByKey($pw, $seed, $pw2)
{
$retVal = FALSE;
if (cryptPassword($pw, $seed) == $pw2)
$retVal = TRUE;
else
sendError(101, "Ei oikeutta yllapitoon.");
return $retVal;
}
//***************************************************************************
function sendSuccess($s)
{
global $keySeed;
print sprintf('', $keySeed, $s);
}
//***************************************************************************
//1XX = Oikeudet, 2XX = db-yhteys, 3XX = XML-data, 4XX = Tiedosto
function sendError($i, $s)
{
global $showErrors;
if ($showErrors != "yes")
$s = "";
print ('');
}
//***************************************************************************
function writeToFile($filePath, $filename, $mode, $txt)
{
$retVal = TRUE;
$fullfilename = $filePath . $filename;
if (!$handle = fopen ($fullfilename, $mode))
{
sendError(400, "Tiedoston avaaminen ei onnistu: " . $filename);
$retVal = FALSE;
}
else
{
if (!fwrite($handle, $txt))
{
sendError(401, "Tiedostoon kirjoitus ei onnistu: " . $filename);
$retVal = FALSE;
}
fclose($handle);
}
return $retVal;
}
//***************************************************************************
function replaceScandit($txt)
{
$txt = str_replace (chr(195) . chr(132), "Ä", $txt);
$txt = str_replace (chr(195) . chr(150), "Ö", $txt);
$txt = str_replace (chr(195) . chr(133), "Å", $txt);
$txt = str_replace (chr(195) . chr(164), "ä", $txt);
$txt = str_replace (chr(195) . chr(182), "ö", $txt);
$txt = str_replace (chr(195) . chr(165), "å", $txt);
return $txt;
}
//***************************************************************************
function replaceIntScanditWithEntity($txt)
{
$txt = str_replace (chr(195) . chr(132), "Ä", $txt);
$txt = str_replace (chr(195) . chr(150), "Ö", $txt);
$txt = str_replace (chr(195) . chr(133), "Å", $txt);
$txt = str_replace (chr(195) . chr(164), "ä", $txt);
$txt = str_replace (chr(195) . chr(182), "ö", $txt);
$txt = str_replace (chr(195) . chr(165), "å", $txt);
return $txt;
}
//***************************************************************************
function deleteFile($filename)
{
$retVal = TRUE;
if (file_exists($filename) == TRUE)
if (unlink($filename) == FALSE)
{
sendError(410, "Tiedoston poisto ei onnistu.");
$retVal = FALSE;
}
return $retVal;
}
//***************************************************************************
function start_update()
{
sendSuccess('');
}
//***************************************************************************
function finish_update()
{
sendSuccess('');
}
//***************************************************************************
function checkRightsByIP($ip)
{
$retVal = FALSE;
$ip = str_replace (".*", "", $ip);
$ip = str_replace ("*", "", $ip);
if ($ip == "")
$retVal = TRUE;
else
{
$ip = $ip . ".";
if (strncmp($_SERVER ['REMOTE_ADDR'] . ".", $ip, strlen($ip)) != 0)
sendError(100, "Ei oikeutta yllapitoon.");
else
$retVal = TRUE;
}
return $retVal;
}
//***************************************************************************
function getXMLRoot()
{
return new domXMLDoc;
}
//***************************************************************************
function cryptPassword($pw, $seed)
{
$pwCrypt = "";
for ($i=0; $igetAttribute("FILEPATH");
$conn = $root->getAttribute("CONN");
$round = $root->getAttribute("ROUND");
//TESTAA HAKEMISTORAKENNE
if (checkPath($filePath, "kokous") == FALSE)
return;
if (checkPath($filePath, "aski") == FALSE)
return;
if (checkPath($filePath, "vhp") == FALSE)
return;
if (checkPath($filePath, "cgi") == FALSE)
return;
if (checkPath($filePath, "css") == FALSE)
return;
if (checkPath($filePath, "kuvat") == FALSE)
return;
if (checkPath($filePath, "script") == FALSE)
return;
if (checkPath($filePath, "pohjat") == FALSE)
return;
$fileName = "DYNASTY.CHK";
switch ($round)
{
case "0":
$filePath = $filePath . "kokous";
break;
case "1":
$filePath = $filePath . "vhp";
break;
case "2":
$filePath = $filePath . "aski";
break;
}
//LUO TIEDOSTO
if (writeToFile ($filePath, $fileName, "wt", "Testi") == FALSE)
return;
//POISTA TIEDOSTO
if (unlink ($filePath . $fileName) == FALSE)
return;
//TESTAA KANTA
if ($conn != "")
{
$result = @mysql_query ("DELETE FROM WEB_ASIAKIRJAT WHERE LAJI=0");
$result = mysql_query ("INSERT INTO WEB_ASIAKIRJAT VALUES (0,'Testi','9999-99-99','Testi','Testi','Testi')");
if($result == FALSE)
{
sendError("210: ", mysql_error());
return;
}
$result = @mysql_query ("DELETE FROM WEB_ASIAKIRJAT WHERE LAJI=0");
if($result == FALSE)
{
sendError("211: ", mysql_error());
return;
}
}
sendSuccess('');
}
//***************************************************************************
function checkPath($rootPath, $appPath)
{
$retVal = FALSE;
if (is_dir($rootPath . $appPath) == FALSE)
sendError("450: ", "Vaadittava hakemisto puuttuu: " . $rootPath . $appPath);
else
$retVal = TRUE;
return $retVal;
}
?>