<?php
//+-----------------------------------------------------+//
//+ Copyright Floopo.com
//+ helper.themes.php
//+ Themes admin helper
//+-----------------------------------------------------+//

defined('BASEPATH') or die('You can not directly access this file');//check its within this framework

//____DEFAULT TEMPLATE_____________________________
$inner_template = ADMIN_TEMPLATES.'tpl_themes.htm';

//____Check for any Post_____________________

if(isset($_POST['update'])) {

    //__process the form
    $process = new FormProcessor();
    if(!$process->RequiredFields('theme')) {

        $notification = $lang['fill_in_all'];

    }
    else {

        //escape the data
            $theme = Sanatize(@mysql_real_escape_string($_POST['theme']));

        //__upate the db
        $dbase->UpdateRecord("UPDATE system_settings
                              SET
					          theme= '$theme'
					          WHERE place_holder = 'yes'");

        //________write to settings file______________________
        include_once (BASEPATH.'/com/com_admin/configbuilder.php');
        $myFile = BASEPATH.'/config/settings.php';
        //@unlink($myFile);
        $fh = @fopen($myFile,'wb');
        @fwrite($fh,$config_line) or $error = true;
        @fclose($fh);

        //writing notification
        if($error) {
            $notification = $lang['settings_writing_error'];

        }
        else {

            //general notification
            $notification = (($dbase->obj_status) ? $lang['request_completed'] : $lang['generic_error']);
        }

    }
}


//____Lets get the themes___________________________
$themesdir = @opendir(BASEPATH.'/themes/');
$results2 = array();
while(($file = @readdir($themesdir)) !== false) {
    $found_path = BASEPATH.'/themes/'.$file;
    $file_type = @filetype($found_path);//is it dir of file
    if($file != '.' && $file != '..' && $file != 'siteadmin' && $file_type == 'dir') {

        //set dbase selected theme
        $selected = (($file == $live_data['theme']) ? 'selected' : '');

        //create pull down options
        $themes_list = $themes_list.'<option value="'.$file.'" '.$selected.'>'.$file.'</option>';

        //add to array;
        $results2[] = array('theme'=>$file);
    }
}


?>