<?php
//+-----------------------------------------------------+//
//+ Copyright Floopo.com
//+ helper.settings.php
//+ Settings 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_language_editor.htm';


//____Check for any Post_____________________
if(isset($_POST['updatex'])) {


    $process = new FormProcessor();
    if(!$process->RequiredFields('all')) {

        $notification = $lang['fill_in_all'];

    } else {

        //iterate to create cleaned vars
        foreach($_POST as $key => $value) {

            $value = str_replace('\'', '', $value);
            $value = Sanatize(@mysql_real_escape_string($value));

            if($key == 'updatex' || $key == 'type' || $key == 'page') { //some some form fields sent by the html form
                //skip
            } else {
                //__upate the db
                $dbase->UpdateRecord("UPDATE lang_mine
                      		SET
					  		lang_words= '$value'
					  		WHERE lang_title = '$key'");

            }
        }
        //________write to language file______________________
        include_once (BASEPATH.'/com/com_admin/languagebuilder.php');
        $myFile = BASEPATH.'/lang/my_language.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 current settings_____________________
$current_page = (($_GET['page']) ? $_GET['page'] : $_POST['page']);
$paginate = array(30,Sanatize($current_page),' >>','<< '); //(limit, current page, next, previous)
$pagi_addurl_pre = $base_url."/index.php?option=com_admin&type=language&"; //Optional - added in paginated list e.g. 'http://xyz.com?option=asa&'
$results = $dbase->PaginatedRecordLoop("SELECT *
                                    	FROM lang_mine
								    	WHERE my_lang = 1");
$pagination = $dbase->pagination_html;


//___Set live data________________________________
$results = ((isset($_POST['updatex'])) ? $_POST : $results);

if(isset($_POST['updatex'])) {
    $results_temp = array();
    foreach($results as $key => $value) {

        if($key == 'page' || $key == 'updatex') { //skip some form generic data

            //skip
        } else {
            $value = str_replace('\'', '', $value);
            $results_temp[] = array('lang_title' => $key,'lang_words' => $value);
        }
    }
    $results = $results_temp;
}

$page = (($page =='')?1:$page); //bug fix
?>