<?php
//  ------------------------------------------------------------------------ //
// 本模組由 tad 製作
// 製作日期：2010-11-16
// $Id: $
// ------------------------------------------------------------------------- //

/*-----------引入檔案區--------------*/
include "../../../include/cp_header.php";
include_once "../tad_function.php";
$xoopsOption['template_main'] = "tadtools_adm_index_tpl.html";
xoops_cp_header();

/*-----------function區--------------*/
function tadtools_setup(){
  global $xoopsModule,$xoopsConfig,$xoopsTpl;
  $version=_MA_TT_VERSION.$xoopsModule->getVar("version");

  $i=0;
  $themes="";
  foreach($xoopsConfig['theme_set_allowed'] as $theme){
    $color=$xoopsConfig['theme_set']==$theme?"style='background-color:#990000'":"";

    $themes[$i]['color']=$color;
    $themes[$i]['theme_name']=$theme;
    $themes[$i]['use_bootstrap_setup']=use_bootstrap_setup($theme);
    $i++;
  }

  $xoopsTpl->assign( "themes" , $themes) ;
  $xoopsTpl->assign( "version" , $version) ;
}

function use_bootstrap_setup($def_theme=""){
  global $xoopsDB;
  $sql="select `tt_use_bootstrap` from `".$xoopsDB->prefix("tadtools_setup")."`  where `tt_theme`='$def_theme'";
  $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error());
  list($tt_use_bootstrap)=$xoopsDB->fetchRow($result);
  
  $main="
  <select name='tt_use_bootstrap[$def_theme]'>
  <option value='' ".chk($tt_use_bootstrap,'',1,'selected').">"._MA_TT_EMPTY_CONFIG."</option>
  <option value='1' ".chk($tt_use_bootstrap,'1',0,'selected').">"._MA_TT_EMPTY_NEED_BOOTSTRAP."</option>
  <option value='0' ".chk($tt_use_bootstrap,'0',0,'selected').">"._MA_TT_EMPTY_NO_NEED_BOOTSTRAP."</option>
  </select>";
  return $main;
}


function save(){
  global $xoopsDB;
  foreach($_POST['tt_use_bootstrap'] as $tt_theme=>$tt_use_bootstrap){
    $sql = "INSERT INTO `".$xoopsDB->prefix("tadtools_setup")."` (`tt_theme` , `tt_use_bootstrap`) values('{$tt_theme}', '{$tt_use_bootstrap}' ) ON DUPLICATE KEY UPDATE `tt_use_bootstrap` = '{$tt_use_bootstrap}'";

    $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error());
  }
}
/*-----------執行動作判斷區----------*/
$op=empty($_REQUEST['op'])?"":$_REQUEST['op'];

switch($op){

  case "save":
  save();
  header("location:{$_SERVER['PHP_SELF']}");
	break;


	default:
	tadtools_setup();
	break;
}


/*-----------秀出結果區--------------*/
admin_toolbar(0);

xoops_cp_footer();

?>
