theme.php

File Type: php File Location: monofiles/ File name: theme.php
<?php

    
// MonoCMS Theme Editor
    //
    // Select a style for your webpage
    // Save in settings file


    //Login and user rights
    
include_once 'data_connect.php';
    include 
'log.php';

    
    if (
get_account($_SESSION['userID'])['rights'] != 'administrator') {
        
header('Location:panel.php');
        exit();
    }

    
    if (
simplexml_load_file('filesinfo/theme.xml') === false)
            exit(
'Error: The theme file is corrupt');

    
$themexml = new SimpleXMLElement('filesinfo/theme.xml',null,true);
    
    
// Load theme settings (xml)
    
if (isset($_POST['themesubmitted'])) {
        
                
        
// Theme
        // All layouts have style.css as main stylesheet.
        // In addition, each layout option comes with its own css file.
        
        
        
$layouts = array('layouthead','layoutbody','layoutfoot');
        
        foreach (
$layouts as $checked)
            
$themexml->theme->$checked $_POST[$checked];
        
        
        
        
        
        
// ON/OFF values
        
$on_off_values = array('navigation','fixedmenu','centered','background','titleshow','descriptionshow','exchange','darktheme','pagecentered');

        foreach(
$on_off_values as $onoff) {

            
            if (
$onoff == 'exchange') {
                
                
$excval $_POST['exchange'];
                
                
                
                if (
$excval == 'on') {
                    
                    
$def 'description';
                    
$cha 'title';
                }
                
                else {
                    
                    
$def 'title';
                    
$cha 'description';
                }
                
                
                
$themexml->theme->defaulttitle $def;
                
$themexml->theme->defaultdescription $cha;

                continue;
            }
            
            
$val $_POST[$onoff];
            
            if (
$val != 'on')
                
$val 'off';
            
            elseif(
$onoff == 'fixedmenu'){
                if (
$_POST['navigation'] != 'on')
                    continue;
            }
            elseif (
$onoff == 'centered')
                if (
$_POST['background'] != 'on')
                    continue;
            
            
$themexml->theme->$onoff $val;
        
        }
        
        
        
// The same with the background image . Background is the radio buttons of background img.
        
if ((isset($_SESSION['backgroundicon'])) && ($_POST['background'] == 'on'))
            
$themexml->theme->monoback basename($_SESSION['backgroundicon']);


        
// if an image file is missing
        
if ((isset($_SESSION['backgroundicon'])) && (!file_exists($_SESSION['backgroundicon']))) {
            
$_SESSION['themeset'] = '<div id="error-confirm"><span>An image file is missing. Please try again.</span></div>';
            
header('Location:theme.php');
            exit();
        }
        
        
        
        
// Save theme options in settings
        
$themexml->asXML('filesinfo/theme.xml');
        
        
        
$_SESSION['themeset'] = '<div id="action-confirm"><span>Theme saved</span></div>';
        
header('Location:theme.php');
        exit();

    }

    
$sess = array('usericon','backgroundicon');
    foreach(
$sess as $sv)
        if(isset(
$_SESSION[$sv]))
            unset(
$_SESSION[$sv])

?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Theme edit</title>
<link rel="stylesheet" type="text/css" href="cmstyle.css">
<?php include 'csstheme.php' ?>
<script type="text/javascript">

    function backform(){
        mon4 = document.getElementById('styl4');
        mon5 = document.getElementById('styl5');
        mon6 = document.getElementById('styl6');
        mon9 = document.getElementById('styl9');
        mon91 = document.getElementById('styl91');
        mon115 = document.getElementById('open-folderbg');
        formcon = document.getElementById('bgformcon');
        bgimage = document.getElementById('bgimage');
        

        
        if ( mon4.checked) {
            mon9.removeAttribute('disabled');
            mon91.removeAttribute('disabled');
            bgimage.removeAttribute('style');
            mon115.removeAttribute('style');
        }
        
        


        if (mon5.checked){
            bgimage.setAttribute('style','display:none');
            mon115.setAttribute('style','display:none');
            mon9.setAttribute('disabled','true');
            mon91.setAttribute('disabled','true');
        }

    }
    
    function stylemenu(){
            
            mon7 = document.getElementById('styl7');
            mon8 = document.getElementById('styl8');
            
            if (mon7.checked == false)
                mon8.setAttribute('disabled','true');

            if (mon7.checked == true)
                mon8.removeAttribute('disabled');

    }
    
    function rangef(){
            
            mon10 = document.getElementById('pagewidth');
            mon11 = document.getElementById('range-opt');
            
            if (mon10.checked == true)
                mon11.setAttribute('style','display:block');

            if (mon10.checked == false)
                mon11.removeAttribute('style');

    }

</script>
</head>
<body>
<?php

include 'mypanel.php';

if (isset(
$_SESSION['themeset'])) {
        print 
$_SESSION['themeset'];
        unset(
$_SESSION['themeset']);
    }
?>
    <div class="main">
        <h1 id="edpage" class="inbl ind">Theme</h1>
        <div class="center-container">
            <?php
            
// Layout, background and footer
            
$thhead $themexml->theme->layouthead;
            
$thbody $themexml->theme->layoutbody;
            
$thfoot $themexml->theme->layoutfoot;
            
$mainbg $themexml->theme->background;
            
$center $themexml->theme->centered;
            
$navon $themexml->theme->navigation;
            
$fixed $themexml->theme->fixedmenu;
            
$tit $themexml->theme->titleshow;
            
$des $themexml->theme->descriptionshow;
            
$exc $themexml->theme->defaulttitle;
            
$fullpagebg $themexml->theme->fullpagebg;
            
$darktheme $themexml->theme->darktheme;
            
$pagewidth $themexml->theme->pagecentered
                
            ?>
            
            
            <form enctype="multipart/form-data" action="theme.php" id="themeform" method="POST">
        
        
                <!-- Layout -->
                <div class="layout">
                
                    <h3>Choose layout</h3>
                    
                    
                    <!-- Header -->
                    
                    <h4>Header</h4>
                    
                    <div class="laycon">
                        <input name="layouthead" class="layradio" id="styl2" type="radio" value="head1"<?php if ($thhead == 'head1') print ' checked' ?>>
                        <label for="styl2" style="background:url('images/layh1.png') no-repeat"><span>Standard</span></label>
                    </div>
                    
                    <div class="laycon">
                        <input name="layouthead" class="layradio" id="styl3" type="radio" value="head2"<?php if ($thhead == 'head2') print ' checked' ?>>
                        <label for="styl3" style="background:url('images/layh2.png') no-repeat"><span>Centered</span></label>
                    </div>
                    


                    <!-- Title description exchange positions -->

                    <input name="exchange" type="checkbox" id="ex-pos" class="gencheck" value="on"<?php if ($exc == 'description') print ' checked' ?>>
                    <label for="ex-pos" style="margin-top:29px">Description first</label>
                    <div class="clear"></div>

                    <!-- END


                    
                            
                    Body -->
                                    
                    <h4>Main body</h4>
                    
                    <div class="laycon">
                        <input name="layoutbody" class="layradio" id="styl23" type="radio" value="body1"<?php if ($thbody == 'body1') print ' checked' ?>>
                        <label for="styl23" style="background:url('images/body1.png') no-repeat"><span>Full width</span></label>
                    </div>
                    
                    <div class="laycon">
                        <input name="layoutbody" class="layradio" id="styl24" type="radio" value="body2"<?php if ($thbody == 'body2') print ' checked' ?>>
                        <label for="styl24" style="background:url('images/body2.png') no-repeat"><span>Right sidebar</span></label>
                    </div>
                    
                    <div class="laycon">
                        <input name="layoutbody" class="layradio" id="styl25" type="radio" value="body3"<?php if ($thbody == 'body3') print ' checked' ?>>
                        <label for="styl25" style="background:url('images/body3.png') no-repeat"><span>Left sidebar</span></label>
                    </div>
                    
                    <div class="laycon">
                        <input name="layoutbody" class="layradio" id="styl26" type="radio" value="body4"<?php if ($thbody == 'body4') print ' checked' ?>>
                        <label for="styl26" style="background:url('images/body4.png') no-repeat"><span>Double sidebar</span></label>
                    </div>
                    <div class="clear"></div>
                    
                    <!-- END
                    
                    
                    
                    
                    Footer -->
        
                    <h4>Footer</h4>
                    
                    <div class="laycon">
                        <input name="layoutfoot" class="layradio" id="styl27" type="radio" value="foot1"<?php if ($thfoot == 'foot1') print ' checked' ?>>
                        <label for="styl27" style="background:url('images/foot1.png') no-repeat"><span>Single box</span></label>
                    </div>
                    
                    <div class="laycon">
                        <input name="layoutfoot" class="layradio" id="styl28" type="radio" value="foot2"<?php if ($thfoot == 'foot2') print ' checked' ?>>
                        <label for="styl28" style="background:url('images/foot2.png') no-repeat"><span>Double box</span></label>
                    </div>
                    <div class="laycon">
                        <input name="layoutfoot" class="layradio" id="styl29" type="radio" value="foot3"<?php if ($thfoot == 'foot3') print ' checked' ?>>
                        <label for="styl29" style="background:url('images/foot3.png') no-repeat"><span>Triple box</span></label>
                    </div>
                    <div class="clear"></div>
                    
                
                <!-- END -->
                
                
                
                
                    <div class="clear"></div>
                    
                    <!-- Page width 
                    
                    <input type="checkbox" class="gencheck" onchange="rangef();" name="pagecentered" id="pagewidth" value="on"<?php 
                        
                        
//if ($pagewidth == 'on') print ' checked'
                        
                        
?>>
                    <label for="pagewidth">Page centered</label>
                    <div class="clear"></div>
                    <div id="range-opt" style="display:<?php //print ($pagewidth == 'on' ) ? 'block' : 'none' ?>">
                        <h5>Page width</h5>
                        <input type="range" min="700" max="1100" value="900" id="pwidth" name="range">
                        <div style="font-size:16px;height:30px;width:380px;border:2px solid #ddd;background:#f3f3f3">
                            <div id="width-display" style="background:#fbfbfb;height:30px;margin:0 auto;border-left:2px solid #eee;border-right:2px solid #eee"></div>
                            <br>
                            <span id="range"></span>px
                        </div>
                        <script type="text/javascript">
                        var sel = document.getElementById("pwidth");
                        var dis = document.getElementById("width-display");
                        var out = document.getElementById("range");
                        dis.style.width = sel.value/3.5 +"px";
                        out.innerHTML = sel.value;
                        sel.oninput = function() {dis.style.width = (this.value/3.5)+"px";out.innerHTML = this.value } 
                        </script>
                    </div>
                <!-- END -->
                </div>
                



                <!-- Background -->
                
                

                <!-- END
                
                
                
                General options -->

                <h3>General options</h3>
                
                
                
                <!-- Website Title on-->

                <input name="titleshow" type="checkbox" class="gencheck" id="styl82" value="on"<?php 
                        
if ($tit == 'on') print ' checked'
                    
?>>
                <label for="styl82" id="themelab32">Show Title</label>
                <div class="clear"></div>
                
                <!-- END




                Website description on-->

                <input name="descriptionshow" type="checkbox" id="des-show" class="gencheck" value="on"<?php if ($des == 'on') print ' checked' ?>>
                <label for="des-show">Show Description</label>
                <div class="clear"></div>

                <!-- END

                


                Navigation menu on-->
                
                <input type="checkbox" class="gencheck" id="styl7" onchange="stylemenu()" name="navigation" value="on"<?php if($navon=='on') print ' checked' ?>>
                <label for="styl7" id="themelab2">Navigation menu</label>
                <div class="clear"></div>
                
                <!-- END



                Fixed menu -->

                <input type="checkbox" class="gencheck" id="styl8" name="fixedmenu" value="on"<?php 
                    
                    
if ($navon == 'off') print ' disabled="true"';
                    if (
$fixed == 'on') print ' checked'
                    
                    
?>>
                <label for="styl8" id="themelab3">Fixed</label>
                <div class="clear"></div>
                
                <!-- END





                Owner icon 

                <input type="checkbox" class="gencheck" id="styl81" name="ownericon" value="on"<?php 
                        
//if ($ownericon == 'on') print ' checked'
                    
?>>
                <label for="styl81" id="themelab31">Use owner's icon as logo</label>
                <div class="clear"></div>
                
                <!-- END


                



                Dark colors -->

                <input type="checkbox" class="gencheck" id="styl35" name="darktheme" value="on"<?php 
                        
if ($darktheme == 'on') print ' checked'
                    
?>>
                <label for="styl35">Dark theme</label>
                <div class="clear"></div>
                
                <!-- END -->


                
                <div  style="clear:both;height:60px"></div>
                
                <!-- SAVE theme-->
                <input class="stylish-button" type="submit" value="Save theme" name="themesubmitted" style="float:left;margin:55px 0 85px 0">
                
                <!-- PREVIEW theme 
                <input class="stylish-button" type="submit" value="Preview" name="themepreview" style="margin:55px 0 0 12px;opacity:.7;float:left">
                -->
                
            </form>
        </div>
    </div>
</body>
</html>