<?php
/**
* Class : setting_manager
* Purpose : All setting coding done here.
*/
class setting_manager extends mod_manager {
#######################################################################################################
### Function Name : setting_manager ###
### Description : This is a constructor ###
### Input : Reference of smarty,input and output parameters ###
### Output : Initiates mod manager and initialize object and business class for user manager ###
#######################################################################################################
function setting_manager (& $smarty, & $_output, & $_input) {
if($_REQUEST['ce']!='0'){
check_session();
}else{
if(!$_SESSION['id_user']){
exit("<span class='fcolor'>".getmessage('COM_NO_SESSION')."Please <a href='javascript:void(0);' onclick=check_JSsession('nosession',0); style='text-decoration : underline;'>click</a> here to log in again</span>");
}
}
$this->mod_manager($smarty, $_output, $_input, 'setting');
$this->obj_setting = new setting;
$this->setting_bl = new setting_bl;
}
####################################################################################################
### Function Name : get_module_name(Predefined Function) ####
####################################################################################################
function get_module_name() {
return 'setting';
}
####################################################################################################
### Function Name : get_manager_name(Predefined Function) ###
####################################################################################################
function get_manager_name() {
return 'setting';
}
######################################################################################################
### Function Name : default(Predefined Function) ###
### Description : Handle default request(if no choice specified) ###
######################################################################################################
function _default() {
return true;
}
####################################################################################################
### Function Name : _listing ###
### Description : Function to show setting listing ###
### Input : No input ###
### Ouput : listing template ###
####################################################################################################
function _listing(){
check_session();
if(!$_SESSION['id_developer']){
$cond=" is_editable=1 ";
$this->_output['tpl']='setting/listing';
}else{
redirect(LBL_SITE_URL);
}
$sql = get_search_sql("config",$cond." ORDER BY name,id_seq ");
$this->_output['res']=getrows($sql,$err);
}
####################################################################################################
### Function Name : _add ###
### Description : Function to show editable language template with add option in fancybox ###
### Input : No input ###
### Ouput : dev_add template ###
####################################################################################################
function _add(){
check_session();
global $link;
$sql.=get_search_sql('config','');
if($this->_input['id_config']) {
$sql.= " WHERE id_config = '".$this->_input['id_config']."' LIMIT 1";
$this->_output['section'] = getsingleindexrow($sql);
$this->_output['add_section'] = 1;
}else {
$sql.=" GROUP BY name";
$this->_output['section']=getindexrows($sql,'name','name');
}
$this->_output['f_type']=array("text" => "Text","radio" => "Radio","checkbox" => "Checkbox","dropdown" => "Drop Down");
$this->_output['tpl']='setting/dev_add';
}
####################################################################################################
### Function Name : _edit ###
### Description : Function to show editable setting options ###
### Input : No input ###
### Ouput : dev_add template ###
####################################################################################################
function _edit(){
check_session();
$sql=get_search_sql("config"," GROUP BY name");
$this->_output['section']=getindexrows($sql,'name','name');
$sql_config = get_search_sql('config',"id_config = '".$this->_input['id_config']."' LIMIT 1");
$res = getrows($sql_config,$err);
$this->_output['res'] = $res[0];
$this->_output['f_type']=array("text" => "Text","radio" => "Radio","checkbox" => "Checkbox","dropdown" => "Drop Down");
$this->_output['tpl']='setting/dev_add';
}
#####################################################################################################
### Function Name : _update_config ###
### Description : Function to update config ###
### Input : No input ###
### Ouput : Redirect to _write_config() function ###
#####################################################################################################
function _update_config(){
check_session();
global $link;
$sectype=$this->_input['sectype'];
foreach($this->_input[$sectype] as $key=>$value){
if($_SESSION['id_developer']) {
if(is_array($this->_input[$sectype][$key][$key])) {
$this->_input[$sectype][$key][$key] = implode(",",$this->_input[$sectype][$key][$key]);
}
$usql ="UPDATE ".TABLE_PREFIX."config SET value='".$this->_input[$sectype][$key][$key]."',comment='".$this->_input[$sectype][$key]['comment']."' WHERE id_config=".$key;
}else {
if(is_array($value)) {
$value=implode(",",$value);
}
$usql ="UPDATE ".TABLE_PREFIX."config SET value='".$value."' WHERE id_config=".$key;
}
$link->query($usql);
$_SESSION['raise_message']['global']=getmessage('COM_UPD_SUCC');
}
$this->write_config('ajax');
ob_clean();
$this->_listing();
}
#####################################################################################################
### Function Name : _delete_config ###
### Description : Function to update config ###
### Input : No input ###
### Ouput : Redirect to _language() function ###
#####################################################################################################
function _delete_config(){
check_session();
global $link;
ob_clean();
$keys=stripslashes($this->_input['keys']);
$keys=trim($keys,',');
$dsql="DELETE FROM ".TABLE_PREFIX."config WHERE id_config IN(".$keys.")";
$link->query($dsql);
$_SESSION['raise_message']['global']=getmessage('COM_DEL_SUCC');
$this->write_config('ajax');
exit;
}
#####################################################################################################
### Function Name : _set_config ###
### Description : Function to Insert config ###
### Input : No input ###
### Ouput : Redirect to _write_config() function ###
#####################################################################################################
function _set_config(){
ob_clean();
global $link;
$cond=" ckey='".$this->_input['sec']['ckey']."' LIMIT 1";
$csql=get_search_sql('config',$cond);
$cres=getsingleindexrow($csql);
if($cres['name']==$this->_input['sec']['name']){
print "no";exit;
}else{
$this->_input['sec']['name']=str_replace(" ", "_", trim($this->_input['sec']['name']));
$this->_input['sec']['name']=strtoupper($this->_input['sec']['name']);
$this->obj_setting->insert($this->_input['sec']);
$_SESSION['raise_message']['global']=getmessage('COM_INS_SUCC');
$this->write_config('ajax');
exit;
}
}
####################################################################################################
### Function Name : _edit_config ###
### Description : Function to show editable config options ###
### Input : No input ###
### Ouput : Redirect to _write_config() function ###
####################################################################################################
function _edit_config(){
ob_clean();
global $link;
$cond=" ckey='".$this->_input['sec']['ckey']."' AND id_config != '".$this->_input['id_config']."' LIMIT 1";
$csql=get_search_sql('config',$cond);
$cres=getsingleindexrow($csql);
if($cres['name']==$this->_input['sec']['name']){
print "no";exit;
}else{
$this->_input['sec']['name']=strtoupper($this->_input['sec']['name']);
$this->obj_setting->edit_config($this->_input['sec'],$this->_input['id_config']);
$this->write_config('ajax');
}
}
####################################################################################################
### Function Name : write_config ###
### Description : Function to fetch one by one record and write ###
### Input : No input ###
### Ouput : Redirect to listing function ###
####################################################################################################
function write_config($p=''){
global $link;
$sql = "SELECT * FROM ".TABLE_PREFIX."config ORDER BY name,id_config";
$sth = execute($sql,$err);
if ($sth) {
do {
if ($result = $link->store_result()) {
while($res1 = $result->fetch_assoc()){
$sampleData[$res1['name']][$res1['ckey']]=$res1['value'];
}
$result->close();
}
} while ($link->next_result());
$f=$this->write_ini_file($sampleData, APP_ROOT.'flexycms/configs/'.SITE_USED.'/config.ini.php');
if($p){
print LBL_SITE_URL."index.php/page-setting-choice-listing";
}else{
redirect(LBL_SITE_URL."index.php/page-setting-choice-listing");
}
} else {
printf("<br />First Error: %s\n", $link->error);
exit;
}
}
####################################################################################################
### Function Name : write_ini_file ###
### Description : write on config.ini.php file ###
### Input : No input ###
### Ouput : No output ###
####################################################################################################
function write_ini_file($assoc_arr, $path, $has_sections=TRUE) {
$content = "";
if ($has_sections) {
foreach ($assoc_arr as $key=>$elem) {
if($content)
$content .= "\n";
$content .= "[".$key."]\n";
foreach ($elem as $key2=>$elem2) {
if(is_array($elem2)) {
for($i=0;$i<count($elem2);$i++) {
$content .= $key2."[] = \"".$elem2[$i]."\"\n";
}
}
else if($elem2=="") $content .= $key2." = \n";
else $content .= $key2." = \"".$elem2."\"\n";
}
}
}else {
foreach ($assoc_arr as $key=>$elem) {
if(is_array($elem)) {
for($i=0;$i<count($elem);$i++) {
$content .= $key2."[] = \"".$elem[$i]."\"\n";
}
}
else if($elem=="") $content .= $key2." = \n";
else $content .= $key2." = \"".$elem."\"\n";
}
}
if (!$handle = fopen($path, 'w')) {
return false;
}
if (!fwrite($handle, $content)) {
return false;
}
fclose($handle);
return true;
}
####################################################################################################
### Function Name : _reorder ###
### Description : update the ordering of general setting page rows ###
### Input : No input ###
### Ouput : No output ###
####################################################################################################
function _reorder() {
$ordered = explode(',',$this->_input['tab']);
$cnt=count($ordered);
for($i=0;$i<$cnt;$i++){
$j = $i+1;
$sql = "UPDATE ".TABLE_PREFIX."config SET id_seq = ".$j." WHERE id_config = ".$ordered[$i];
execute($sql,$err);
}
}
}//end of class