<?php

/*  Alternate WebKit
(C) 2011-2015 by Alternate Tools
-----------------------------------------------------

Filename:     class_page.php
Description:  Class cPage definition,
              to load and save page files
              
*/

include "class_storagefile.php";
include "class_gallery.php";
include "class_youtubegallery.php";
include "class_linklist.php";
include "class_guestbookentrylist.php";
include "class_form.php";

if (!defined ("CLASS_PAGE"))
{
    define ("CLASS_PAGE", "defined");
    define ("PAGETYPE_PLAIN", "0");
    define ("PAGETYPE_LINK", "1");
    define ("PAGETYPE_CONTACT", "2");
    define ("PAGETYPE_YOUTUBEGALLERY", "3");
    define ("PAGETYPE_GALLERY", "4");
    define ("PAGETYPE_LINKS", "5");
    define ("PAGETYPE_GUESTBOOK", "6");
    define ("PAGETYPE_NEWS", "7");
    define ("PAGETYPE_NEWSLETTER", "8");
    define ("PAGETYPE_SITEMAP", "9");
    define ("PAGETYPE_SEARCH", "10");
    define ("PAGETYPE_FORM", "11");
    define ("PAGETYPE_CUSTOM", "100");
    
    define ("PAGEAUTHOR_NONE", "Anonymus");

    class cPage
    {
        var $m_pageId;
        var $m_pageDate;
        var $m_pageTitle;
        var $m_pageNavigationTitle;
        var $m_pageNavigationTitleNormal;
        var $m_pageNavigationTitleActive;
        var $m_pageNavigationPosition;
        var $m_pageNavigationLevel;
        var $m_pageNavigationShowLevel;
        var $m_pageNavigationImg;
        var $m_pageNavigationImgHover;
        var $m_pageContentFile;
        var $m_pageContentPosition;
        var $m_pageThemeFile;
        var $m_pageAdditionalFile;
        var $m_pageAdditionalFolder;
        var $m_pageAdditionalParameter;
        var $m_pageAdditionalParameter2;
        var $m_pageAdditionalParameter3;
        var $m_pageAdditionalColCount;
        var $m_pageAdditionalRowCount;
        var $m_pageAdditionalImgWidth;
        var $m_pageAdditionalImgHeight;
        var $m_pageAdditionalThumbWidth;
        var $m_pageAdditionalThumbHeight;
        var $m_pageAdditionalContent;
        var $m_pageAdditionalContent2;
        var $m_pageLink;
        var $m_pageType;
        var $m_pageModified;
        var $m_pageAuthor;
        var $m_pageCreatedBy;
        var $m_pageShowInNavigation;
        var $m_pageLocked;
        var $m_pageIsMainPage;
        var $m_pageDeleteProtected;
        var $m_pageViewCount;

        var $m_pageFolder;

        // For gallery pages
        var $m_cGallery;
        // For youtube gallery pages
        var $m_cYouTubeGallery;
        // For Link lists
        var $m_cLinkList;
        // For forms
        var $m_cForm;

        function cPage()  // PHP 4
        {
            $this->Init();
        }

        function __construct()
        {
            $this->Init();
        }

        function Init()
        {
            $this->m_pageId = "0";
            $this->m_pageDate = "";
            $this->m_pageTitle = "";
            $this->m_pageNavigationTitle = "";
            $this->m_pageNavigationTitleNormal = "";
            $this->m_pageNavigationTitleActive = "";
            $this->m_pageNavigationPosition = "0";
            $this->m_pageNavigationLevel = "0";
            $this->m_pageNavigationShowLevel = "";
            $this->m_pageNavigationImg = "";
            $this->m_pageNavigationImgHover = "";
            $this->m_pageContentFile = "";
            $this->m_pageContentPosition = "top";
            $this->m_pageThemeFile = "";
            $this->m_pageAdditionalFile = "";
            $this->m_pageAdditionalFolder = "";
            $this->m_pageAdditionalParameter = "";
            $this->m_pageAdditionalParameter2 = "";
            $this->m_pageAdditionalParameter3 = "";
            $this->m_pageAdditionalColCount = "";
            $this->m_pageAdditionalRowCount = "";
            $this->m_pageAdditionalImgWidth = "";
            $this->m_pageAdditionalImgHeight = "";
            $this->m_pageAdditionalThumbWidth = "";
            $this->m_pageAdditionalThumbHeight = "";
            $this->m_pageAdditionalContent = "";
            $this->m_pageAdditionalContent2 = "";
            $this->m_pageLink = "";
            $this->m_pageType = PAGETYPE_PLAIN;
            $this->m_pageModified = "";
            $this->m_pageAuthor = "";
            $this->m_pageCreatedBy = "";
            $this->m_pageShowInNavigation = "1";
            $this->m_pageLocked = "0";
            $this->m_pageIsMainPage = "0";
            $this->m_pageDeleteProtected = "0";
            $this->m_pageViewCount = "0";

            $this->m_pageFolder = "";

            $this->m_cGallery = new cGallery;
            $this->m_cYouTubeGallery = new cYouTubeGallery;
            $this->m_cLinkList = new cLinkList;
            $this->m_cForm = new cForm;
        }
        
        // Getter / setter
        function GetId()
        {
            return $this->m_pageId;
        }
        
        function GetDate()
        {
            return $this->m_pageDate;
        }
        
        function SetTitle($title)
        {
            $this->m_pageTitle = $title;
        }
        function GetTitle()
        {
            return $this->m_pageTitle;
        }
        
        function SetNavigationTitle($title)
        {
            $this->m_pageNavigationTitle = $title;
        }
        function GetNavigationTitle()
        {
            return $this->m_pageNavigationTitle;
        }
        function SetNavigationTitleNormal($titleNormal)
        {
            $this->m_pageNavigationTitleNormal = $titleNormal;
        }
        function GetNavigationTitleNormal()
        {
            return $this->m_pageNavigationTitleNormal;
        }
        function SetNavigationTitleActive($titleActive)
        {
            $this->m_pageNavigationTitleActive = $titleActive;
        }
        function GetNavigationTitleActive()
        {
            return $this->m_pageNavigationTitleActive;
        }

        function SetNavigationPosition($position)
        {
            $this->m_pageNavigationPosition = $position;
        }
        function GetNavigationPosition()
        {
            return $this->m_pageNavigationPosition;
        }

        function SetNavigationLevel($level)
        {
            $this->m_pageNavigationLevel = $level;
        }
        function GetNavigationLevel()
        {
            return $this->m_pageNavigationLevel;
        }

        function SetNavigationShowLevel($level)
        {
            $this->m_pageNavigationShowLevel = $level;
        }
        function GetNavigationShowLevel()
        {
            return $this->m_pageNavigationShowLevel;
        }

        function SetNavigationImage($image)
        {
            $this->m_pageNavigationImg = $image;
        }
        function GetNavigationImage()
        {
            return $this->m_pageNavigationImg;
        }
        function SetNavigationImageHover($image)
        {
            $this->m_pageNavigationImgHover = $image;
        }
        function GetNavigationImageHover()
        {
            return $this->m_pageNavigationImgHover;
        }

        function GetContentFile()
        {
            return $this->m_pageContentFile;
        }
        function GetContentPosition()
        {
            return $this->m_pageContentPosition;
        }
        function SetContentPosition($position)
        {
            $this->m_pageContentPosition = $position;
        }

        function GetThemeFile()
        {
            return $this->m_pageThemeFile;
        }
        function SetThemeFile($themeFile)
        {
            $this->m_pageThemeFile = $themeFile;
        }
        
        function GetAdditionalFile()
        {
            return $this->m_pageAdditionalFile;
        }
        function SetAdditionalFile($addFile)
        {
            $this->m_pageAdditionalFile = $addFile;
        }

        function GetAdditionalFolder()
        {
            return $this->m_pageAdditionalFolder;
        }
        function SetAdditionalFolder($addFolder)
        {
            $this->m_pageAdditionalFolder = $addFolder;
        }

        function GetAdditionalParameter()
        {
            return $this->m_pageAdditionalParameter;
        }
        function SetAdditionalParameter($addParameter)
        {
            $this->m_pageAdditionalParameter = $addParameter;
        }

        function GetAdditionalParameter2()
        {
            return $this->m_pageAdditionalParameter2;
        }
        function SetAdditionalParameter2($addParameter2)
        {
            $this->m_pageAdditionalParameter2 = $addParameter2;
        }

        function GetAdditionalParameter3()
        {
            return $this->m_pageAdditionalParameter3;
        }
        function SetAdditionalParameter3($addParameter3)
        {
            $this->m_pageAdditionalParameter3 = $addParameter3;
        }

        function GetAdditionalColCount()
        {
            return $this->m_pageAdditionalColCount;
        }
        function SetAdditionalColCount($colCount)
        {
            $this->m_pageAdditionalColCount = $colCount;
        }

        function GetAdditionalRowCount()
        {
            return $this->m_pageAdditionalRowCount;
        }
        function SetAdditionalRowCount($rowCount)
        {
            $this->m_pageAdditionalRowCount = $rowCount;
        }

        function GetAdditionalImgWidth()
        {
            return $this->m_pageAdditionalImgWidth;
        }
        function SetAdditionalImgWidth($imgWidth)
        {
            $this->m_pageAdditionalImgWidth = $imgWidth;
        }

        function GetAdditionalImgHeight()
        {
            return $this->m_pageAdditionalImgHeight;
        }
        function SetAdditionalImgHeight($imgHeight)
        {
            $this->m_pageAdditionalImgHeight = $imgHeight;
        }

        function GetAdditionalThumbWidth()
        {
            return $this->m_pageAdditionalThumbWidth;
        }
        function SetAdditionalThumbWidth($thumbWidth)
        {
            $this->m_pageAdditionalThumbWidth = $thumbWidth;
        }

        function GetAdditionalThumbHeight()
        {
            return $this->m_pageAdditionalThumbHeight;
        }
        function SetAdditionalThumbHeight($thumbHeight)
        {
            $this->m_pageAdditionalThumbHeight = $thumbHeight;
        }

        function GetAdditionalContent()
        {
            return $this->m_pageAdditionalContent;
        }
        function SetAdditionalContent($addContent)
        {
            $this->m_pageAdditionalContent = $addContent;
        }
        function GetAdditionalContent2()
        {
            return $this->m_pageAdditionalContent2;
        }
        function SetAdditionalContent2($addContent2)
        {
            $this->m_pageAdditionalContent2 = $addContent2;
        }

        function GetLink()
        {
            return $this->m_pageLink;
        }
        function SetLink($link)
        {
            $this->m_pageLink = $link;
        }

        function GetType()
        {
            return $this->m_pageType;
        }
        function SetType($type)
        {
            if ($type < PAGETYPE_PLAIN || $type > PAGETYPE_CUSTOM)
                $this->m_pageType = PAGETYPE_PLAIN;
            else
                $this->m_pageType = $type;
        }

        function GetAuthor()
        {
            return $this->m_pageAuthor;
        }

        function GetModified()
        {
            return $this->m_pageModified;
        }

        function GetCreatedBy()
        {
            return $this->m_pageCreatedBy;
        }

        function ShowInNavigation()
        {
            return ($this->m_pageShowInNavigation == "1");
        }

        function SetShowInNavigation($bShow)
        {
            $this->m_pageShowInNavigation = "0";
            if ($bShow == true)
                $this->m_pageShowInNavigation = "1";
        }

        function IsLocked()
        {
            return ($this->m_pageLocked == "1");
        }

        function SetLocked($bLock, $author = PAGEAUTHOR_NONE)
        {
            $this->m_pageLocked = "0";
            if ($bLock == true)
                $this->m_pageLocked = "1";
            return $this->SavePage($author);
        }

        function IsMainPage()
        {
            return ($this->m_pageIsMainPage == "1");
        }

        function SetMainPage($bMainPage)
        {
            $this->m_pageIsMainPage = "0";
            if ($bMainPage == true)
                $this->m_pageIsMainPage = "1";
        }

        function IsDeleteProtected()
        {
            return ($this->m_pageDeleteProtected == "1");
        }

        function SetDeleteProtected($bProtect)
        {
            $this->m_pageDeleteProtected = "0";
            if ($bProtect == true)
                $this->m_pageDeleteProtected = "1";
        }
        function GetViewCount()
        {
            return $this->m_pageViewCount;
        }
        function IncreaseViewCount()
        {
            $this->m_pageViewCount ++;
            return $this->SavePage(PAGEAUTHOR_NONE, true);   // Leave modifications
        }
        function ResetViewCount()
        {
            $this->m_pageViewCount = "0";
            return $this->SavePage(PAGEAUTHOR_NONE, true);   // Leave modifications
        }


        function SetFolder($folder)
        {
            $this->m_pageFolder = $folder;
        }

        // Main methods
        function CreatePage($author = PAGEAUTHOR_NONE, $pageType = PAGETYPE_PLAIN)
        {
//            $this->Init();
            $uId = uniqid("", FALSE);
            $this->m_pageId = "pag" . $uId;
            $this->m_pageDate = date("Y-m-d H:i:s");
            $this->m_pageModified = $this->m_pageDate;
            $this->m_pageAuthor = $author;
            $this->m_pageCreatedBy = $author;
            // Create the content file
            $this->m_pageContentFile = $this->m_pageFolder . $this->m_pageId . ".pgc";
            if (file_exists($this->m_pageContentFile) == false)
            {
                $fp = fopen($this->m_pageContentFile, "w");
                if ($fp == false)
                    return false;
                fclose($fp);
            }
            $this->m_pageType = $pageType;
            return true;
        }

        function AssignGallery($galFolder)
        {
            // Create gallery file?
            if ($this->m_pageType == PAGETYPE_GALLERY)
            {
                $this->m_cGallery->CreateGalleryById("gal" . substr($this->m_pageId, 3));
                $this->m_cGallery->SetFolder($galFolder);
                $this->SetAdditionalFolder($galFolder);
                $this->m_pageAdditionalFile = $this->m_cGallery->GetId();
            }
            // Create youtube gallery file?
            if ($this->m_pageType == PAGETYPE_YOUTUBEGALLERY)
            {
                $this->m_cYouTubeGallery->CreateYouTubeGalleryById("yol" . substr($this->m_pageId, 3));
                $this->m_cYouTubeGallery->SetFolder($galFolder);
                $this->SetAdditionalFolder($galFolder);
                $this->m_pageAdditionalFile = $this->m_cYouTubeGallery->GetId();
            }
            // Create link list file?
            if ($this->m_pageType == PAGETYPE_LINKS)
            {
                $this->m_cLinkList->CreateLinkListById("lil" . substr($this->m_pageId, 3));
                $this->m_cLinkList->SetFolder($galFolder);
                $this->SetAdditionalFolder($galFolder);
                $this->m_pageAdditionalFile = $this->m_cLinkList->GetId();
            }
            // Create form file?
            if ($this->m_pageType == PAGETYPE_FORM)
            {
                $this->m_cForm->CreateFormById("frm" . substr($this->m_pageId, 3));
                $this->m_cForm->SetFolder($galFolder);
                $this->SetAdditionalFolder($galFolder);
                $this->m_pageAdditionalFile = $this->m_cForm->GetId();
            }
        }

        function DeletePageFinal()
        {
            // Check for protection
            if ($this->IsDeleteProtected() == true)
                return false;

            // Delete content file
            if (file_exists($this->m_pageContentFile) == true && unlink($this->m_pageContentFile) == false)
                return false;
            // Delete additional file
            if (file_exists($this->m_pageAdditionalFile) == true && unlink($this->m_pageAdditionalFile) == false)
                return false;
            // Delete navigation images (if existing)
            if (file_exists($this->m_pageNavigationImg) == true && unlink($this->m_pageNavigationImg) == false)
                return false;
            if (file_exists($this->m_pageNavigationImgHover) == true && unlink($this->m_pageNavigationImgHover) == false)
                return false;
            // Gallery?
            if ($this->m_pageType == PAGETYPE_GALLERY)
            {
                $this->m_cGallery->DeleteGalleryFinal();
            }
            // YouTube gallery?
            if ($this->m_pageType == PAGETYPE_YOUTUBEGALLERY)
            {
                $this->m_cYouTubeGallery->DeleteYouTubeGalleryFinal();
            }
            // Link list?
            if ($this->m_pageType == PAGETYPE_LINKS)
            {
                $this->m_cLinkList->DeleteLinkListFinal();
            }
            // Form?
            if ($this->m_pageType == PAGETYPE_FORM)
            {
                $this->m_cForm->DeleteFormFinal();
            }
            // Guestbook?
            if ($this->m_pageType == PAGETYPE_GUESTBOOK)
            {
                $guestList = new cGuestbookEntryList;
                $guestList->SetFolder($this->GetAdditionalFolder());
                $guestList->DeleteAllEntriesForPage($this->GetId());
            }
            
            // TBD... files images other types
            // ...

            // Finally main file
            return unlink($this->m_pageFolder . $this->m_pageId . ".pag");
        }

        function DeletePageFinalFromId($pageId)
        {
            $this->m_pageId = $pageId;
            return DeletePageFinal();
        }


        function LoadPageFromId($pageId)
        {
            $this->m_pageId = $pageId;
            return $this->LoadPage();
        }

        function LoadPage()
        {
            $fileName = $this->m_pageFolder . $this->m_pageId  . ".pag";
            //echo  $fileName;

            if ($this->m_pageId == "0" || $this->m_pageFolder == "")
                return false;

            if (file_exists($fileName) == false)
                return false;

            $cStorage = new cStorageFile;
            if ($cStorage->LoadStorageFromFile($fileName) == false)
                return false;

            if ($cStorage->GetData("Id") == "")
                return false;

            $this->m_pageId = $cStorage->GetData("Id");
            $this->m_pageDate = $cStorage->GetData("Date");
            $this->m_pageTitle = $cStorage->GetData("Title");
            $this->m_pageNavigationTitle = $cStorage->GetData("NavigationTitle");
            $this->m_pageNavigationTitleNormal = $cStorage->GetData("NavigationTitleNormal");
            $this->m_pageNavigationTitleActive = $cStorage->GetData("NavigationTitleActive");
            $this->m_pageNavigationPosition = $cStorage->GetData("NavigationPosition");
            $this->m_pageNavigationLevel = $cStorage->GetData("NavigationLevel");
            $this->m_pageNavigationShowLevel = $cStorage->GetData("NavigationShowLevel");
            $this->m_pageNavigationImg = $cStorage->GetData("NavigationImg");
            $this->m_pageNavigationImgHover = $cStorage->GetData("NavigationImgHover");
            $this->m_pageContentFile = $cStorage->GetData("ContentFile");
            $this->m_pageContentPosition = $cStorage->GetData("ContentPosition");
            $this->m_pageThemeFile = $cStorage->GetData("ThemeFile");
            $this->m_pageAdditionalFile = $cStorage->GetData("AdditionalFile");
            $this->m_pageAdditionalFolder = $cStorage->GetData("AdditionalFolder");
            $this->m_pageAdditionalParameter = $cStorage->GetData("AdditionalParameter");
            $this->m_pageAdditionalParameter2 = $cStorage->GetData("AdditionalParameter2");
            $this->m_pageAdditionalParameter3 = $cStorage->GetData("AdditionalParameter3");
            $this->m_pageAdditionalColCount = $cStorage->GetData("AdditionalColCount");
            $this->m_pageAdditionalRowCount = $cStorage->GetData("AdditionalRowCount");
            $this->m_pageAdditionalImgWidth = $cStorage->GetData("AdditionalImgWidth");
            $this->m_pageAdditionalImgHeight = $cStorage->GetData("AdditionalImgHeight");
            $this->m_pageAdditionalThumbWidth = $cStorage->GetData("AdditionalThumbWidth");
            $this->m_pageAdditionalThumbHeight = $cStorage->GetData("AdditionalThumbHeight");
            $this->m_pageAdditionalContent = $cStorage->GetData("AdditionalContent");
            $this->m_pageAdditionalContent2 = $cStorage->GetData("AdditionalContent2");
            $this->m_pageLink = $cStorage->GetData("Link");
            $this->m_pageType = $cStorage->GetData("Type");
            $this->m_pageModified = $cStorage->GetData("Modified");
            $this->m_pageAuthor = $cStorage->GetData("Author");
            $this->m_pageCreatedBy = $cStorage->GetData("CreatedBy");
            $this->m_pageShowInNavigation = $cStorage->GetData("ShowInNavigation");
            $this->m_pageLocked = $cStorage->GetData("Locked");
            $this->m_pageIsMainPage = $cStorage->GetData("IsMainPage");
            $this->m_pageDeleteProtected = $cStorage->GetData("DeleteProtected");
            $this->m_pageViewCount = $cStorage->GetData("ViewCount");

            // Load Gallery?
            if ($this->m_pageType == PAGETYPE_GALLERY)
            {
                $this->m_cGallery->SetFolder($this->CheckAdditionalFolder());  // only on load, save only in admin area!!
                $this->m_cGallery->LoadGalleryFromId($this->m_pageAdditionalFile);
            }
            // Load YouTubeGallery?
            if ($this->m_pageType == PAGETYPE_YOUTUBEGALLERY)
            {
                $this->m_cYouTubeGallery->SetFolder($this->CheckAdditionalFolder());  // only on load, save only in admin area!!
                $this->m_cYouTubeGallery->LoadYouTubeGalleryFromId($this->m_pageAdditionalFile);
            }
            // Load LinkList?
            if ($this->m_pageType == PAGETYPE_LINKS)
            {
                $this->m_cLinkList->SetFolder($this->CheckAdditionalFolder());  // only on load, save only in admin area!!
                $this->m_cLinkList->LoadLinkListFromId($this->m_pageAdditionalFile);
            }
            // Load form?
            if ($this->m_pageType == PAGETYPE_FORM)
            {
                $this->m_cForm->SetFolder($this->CheckAdditionalFolder());  // only on load, save only in admin area!!
                $this->m_cForm->LoadFormFromId($this->m_pageAdditionalFile);
            }

            return true;

        }

        function SavePage($author = PAGEAUTHOR_NONE, $leaveModification = false)
        {
            $newRow = "\r\n";
            $fileName = $this->m_pageFolder . $this->m_pageId  . ".pag";
            // echo $fileName;

            if ($this->m_pageId == "0" || $this->m_pageFolder == "")
                return false;

            $cStorage = new cStorageFile;
            $cStorage->SetType("page");
            $cStorage->SetVersion("1.000");
            
            $cStorage->AddData("Id", $this->m_pageId);
            $cStorage->AddData("Date", $this->m_pageDate);
            $cStorage->AddData("Title", $this->m_pageTitle);
            $cStorage->AddData("NavigationTitle", $this->m_pageNavigationTitle);
            $cStorage->AddData("NavigationTitleNormal", $this->m_pageNavigationTitleNormal);
            $cStorage->AddData("NavigationTitleActive", $this->m_pageNavigationTitleActive);
            $cStorage->AddData("NavigationPosition", $this->m_pageNavigationPosition);
            $cStorage->AddData("NavigationLevel", $this->m_pageNavigationLevel);
            $cStorage->AddData("NavigationShowLevel", $this->m_pageNavigationShowLevel);
            $cStorage->AddData("NavigationImg", $this->m_pageNavigationImg);
            $cStorage->AddData("NavigationImgHover", $this->m_pageNavigationImgHover);
            $cStorage->AddData("ContentFile", $this->m_pageContentFile);
            $cStorage->AddData("ContentPosition", $this->m_pageContentPosition);
            $cStorage->AddData("ThemeFile", $this->m_pageThemeFile);
            $cStorage->AddData("AdditionalFile", $this->m_pageAdditionalFile);
            $cStorage->AddData("AdditionalFolder", $this->m_pageAdditionalFolder);
            $cStorage->AddData("AdditionalParameter", $this->m_pageAdditionalParameter);
            $cStorage->AddData("AdditionalParameter2", $this->m_pageAdditionalParameter2);
            $cStorage->AddData("AdditionalParameter3", $this->m_pageAdditionalParameter3);
            $cStorage->AddData("AdditionalColCount", $this->m_pageAdditionalColCount);
            $cStorage->AddData("AdditionalRowCount", $this->m_pageAdditionalRowCount);
            $cStorage->AddData("AdditionalImgWidth", $this->m_pageAdditionalImgWidth);
            $cStorage->AddData("AdditionalImgHeight", $this->m_pageAdditionalImgHeight);
            $cStorage->AddData("AdditionalThumbWidth", $this->m_pageAdditionalThumbWidth);
            $cStorage->AddData("AdditionalThumbHeight", $this->m_pageAdditionalThumbHeight);
            $cStorage->AddData("AdditionalContent", $this->m_pageAdditionalContent);
            $cStorage->AddData("AdditionalContent2", $this->m_pageAdditionalContent2);
            $cStorage->AddData("Link", $this->m_pageLink);
            $cStorage->AddData("Type", $this->m_pageType);
            if ($leaveModification == false)
            {
                $cStorage->AddData("Modified", date("Y-m-d H:i:s"));
                $cStorage->AddData("Author", $author);
            }
            else
            {
                $cStorage->AddData("Modified", $this->m_pageModified);
                $cStorage->AddData("Author", $this->m_pageAuthor);
            }
            $cStorage->AddData("CreatedBy", $this->m_pageCreatedBy);
            $cStorage->AddData("ShowInNavigation", $this->m_pageShowInNavigation, false);
            $cStorage->AddData("Locked", $this->m_pageLocked, false);
            $cStorage->AddData("IsMainPage", $this->m_pageIsMainPage, false);
            $cStorage->AddData("DeleteProtected", $this->m_pageDeleteProtected, false);
            $cStorage->AddData("ViewCount", $this->m_pageViewCount, false);

            if ($leaveModification == false)  // No changes on depending files!!
            {
                // Save Gallery?
                if ($this->m_pageType == PAGETYPE_GALLERY)
                {
                    $this->m_cGallery->SetFolder($this->m_pageAdditionalFolder);
                    $this->m_cGallery->SaveGallery();
                }
                // Save YouTube Gallery?
                if ($this->m_pageType == PAGETYPE_YOUTUBEGALLERY)
                {
                    $this->m_cYouTubeGallery->SetFolder($this->m_pageAdditionalFolder);
                    $this->m_cYouTubeGallery->SaveYouTubeGallery();
                }
                // Save Link List?
                if ($this->m_pageType == PAGETYPE_LINKS)
                {
                    $this->m_cLinkList->SetFolder($this->m_pageAdditionalFolder);
                    $this->m_cLinkList->SaveLinkList();
                }
                // Save form?
                if ($this->m_pageType == PAGETYPE_FORM)
                {
                    $this->m_cForm->SetFolder($this->m_pageAdditionalFolder);
                    $this->m_cForm->SaveForm();
                }
            }
            return $cStorage->SaveStorageToFile($fileName);
        }

        function NoMagic($string)
        {
            if (get_magic_quotes_gpc())  // Magic quotes??
                return stripslashes($string);
            return $string;
        }
        
        function CheckAdditionalFolder()
        {
            if (substr($this->m_pageFolder, 0, 3) != "../")  // absolute path?
                return substr($this->m_pageAdditionalFolder, 3);  // set additional folder the same
                
            return $this->m_pageAdditionalFolder;  // normal path
        }
    }
}