<?php


    # Settings for author users



    # login
    include_once 'data_connect.php';
    include_once 'log.php';
    
    
    
    # user rights - authors only
    if (get_account($_SESSION['userID'])['rights'] == 'administrator') {
        header('Location:general.php');
        exit();
    }
    
    

    function submit_settings_values() {

        $urlicon = $_POST['urlicon'];
        
        if (strlen($_POST['editorname']) > 40)
            $error = 'ERROR:editorname';

        $userrelated = array('usereditorname','urlicon');
        foreach ($userrelated as $user) {
            
            if ($user == 'urlicon')
                $_POST[$user] = trim($_POST[$user]);
                
            $_POST[$user] = (isset($_POST[$user])) ? strip_tags($_POST[$user]) : ' ';

        
        }
        
        
        # personal on off settings settings
        $personal_on_off = ['texteditor'];
        
        foreach($personal_on_off as $val)
            
            if (!isset($_POST[$val]))
                $_POST[$val] = 'off';

            
        if (!isset($error)) {
            update_account($_SESSION['userID'],'set');
            $_SESSION['settingssetuser'] = true;
        }

        else
            $_SESSION[$error] = true;
        
        
        header('Location:generaluser.php');
        exit();
        
        return true;
            
    }
    
    if (isset($_POST['submitted']))
        submit_settings_values();



    # extensions
    include 'command.php'



?>
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Settings</title>
<link rel="stylesheet" type="text/css" href="cmstyle.css">
<?php include 'csstheme.php' ?>
<link rel="stylesheet" type="text/css" href="cmsavebutton.css">
</head>
<body>
<?php

    

    # panel
    include 'mypanel.php';
    action_confirm();



    # user accout info
    $acc_info = get_account($_SESSION['userID']);
    $editorname = $acc_info['editorname'];
    $urlicon = $acc_info['urlicon'];
    $texteditor = $acc_info['texteditor']

?>
    
    <div class="main">
    <h1>Settings</h1>
    
        <div class="center-container">
        <?php
        

        if(isset($_SESSION['usericon']))
            unset($_SESSION['usericon']);
        
        ?>
            <div id="settingspage">
            
                <form action="generaluser.php" method="post" id="MONform">
                    
                    <div class="sel">
                        <label class="lab-5" style="margin-right:12px;cursor:default">Color theme</label><br>
                        <span class="des">Light theme is the standard control panel theme. Choose dark theme to decrease brightness.</span>
                    </div>
                    <div class="sel-r">
                        <input name="theme" type="radio" id="rd-1" class="monradio" value="light" title="Standard"<?php if ($user_theme == 'light') print ' checked' ?>>
                        <label for="rd-1">Light</label>


                        <input name="theme" type="radio" id="rd-3" class="monradio" value="dark" title="Dark"<?php if ($user_theme == 'cmdark') print ' checked' ?>>
                        <label for="rd-3" style="margin-left:10px">Dark</label>
                    </div>
                    <div class="clear"></div>

                    
                    
                    <div class="sel">
                        <label for="editorname" class="lab-5">Editor name</label><br>
                        <span class="des">Choose an editor name that will appear to others.</span>
                    </div>
                    <input name="usereditorname" type="text" id="editorname" class="inp-76" value="<?php print $editorname ?>">
                    <div class="clear"></div>


                    
                    <div>
                        <div>User icon<br>
                            <span class="des">Upload an icon or submit the filename of an image file.</span>
                        </div>
                        <!-- upload iframe -->
                        <iframe src="upload_icon.php" name="user-image" id="user-image"></iframe>                    
                        <p><label for="usericon">Image file</label> <a class="qmark" href="javascript:;">?<span class="details">Overrides 'upload image'</span></a></p><input id="usericon" type="text" name="urlicon" value="<?php print $urlicon ?>" class="inp-1" style="padding:0;width:400px"></div>
                    <div class="clear"></div>
                    
                    
                    <div class="sel">
                        Login password<br>
                        <span class="des">Create a new login password. This will automatically end session and ask you to login again.</span>
                    </div>
                    <a href="password_change.php" class="setlink">Change your log in password</a><br>
                    <div class="clear"></div>
                    <div class="newoptions"></div>
                    <div class="clear"></div>
                    

                    
                    <div class="sel">
                        Text/HTML editor<br>
                        <span class="des">Use the old Document.execCommand() wysiwyg editor.<i> Note: It might not work on every browser.</i></span>
                    </div>
                    <input type="checkbox" name="texteditor" value="on"  id="onoff-0" autocomplete="off" <?php if ($texteditor == 'on') print 'checked' ?>>
                    <label for="onoff-0"></label>
                    <div class="clear"></div>
                    
                    
                </form>
            </div>
        </div>
    </div>
    <?php
            


    # plugins
    include 'execute.php'



    ?>
</body>
</html>