<?php
// +---------------------------------------------+
// |     Copyright 2006-2009 weenCompany |
// |     http://www.weentech.com               |
// |     This file may not be redistributed.     |
// +---------------------------------------------+

define('IN_ADMIN', true);
define('IN_WEENCOMPANY', true);

$rootpath = "./../";

include($rootpath . 'includes/core.php');


PrintHeader('基本设置', 1);

// get the value of $action
$action = isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : 'displaysettings');



// ############################## UPDATE SETTINGS ##############################

if($action == 'updatesettings')
{
  $settings    = $_POST['settings'];
  $currentlogo = $_POST['currentlogo'];
  $sitedefaultlang = $_POST['sitedefaultlang'];

  // update settings
  while(list($key, $value) = each($settings))
  {
    $DB->query("UPDATE " . TABLE_PREFIX . "mainsettings SET value = '$value' WHERE settingid = '$key'");
  }

  // update the logo
  $DB->query("UPDATE " . TABLE_PREFIX . "mainsettings SET value='$currentlogo' WHERE varname = 'currentlogo'");

  // update default language
  $DB->query("UPDATE " . TABLE_PREFIX_ALL . "_mainsettings SET value='$sitedefaultlang' WHERE varname = 'sitedefaultlang'");

    $getadmindir = $DB->query_first("SELECT value FROM " . TABLE_PREFIX . "mainsettings WHERE varname = 'admin_dir'");

	$admin_dir = iif(trim($getadmindir['value']) == '', 'admin', trim($getadmindir['value']));

	if(trim($getadmindir['value']) == '')
	{
		$DB->query("UPDATE " . TABLE_PREFIX . "mainsettings SET value = '$admin_dir' WHERE varname = 'admin_dir'");
	}

	$DB->query("UPDATE " . OLDTABLE_PREFIX . "mainsettings SET value = '$admin_dir' WHERE varname = 'admin_dir'");

  PrintRedirect('mphome.php', 1);
}



// ############################### PRINT DEFAULT ###############################

if($action == 'displaysettings')
{
  // setting groups
  $group[0] = '系统设置';
  $group[1] = '开关设置';
  $group[2] = '网站设置';
  $group[3] = 'SMTP邮件设置';
  $group[4] = '时区设置';

  echo '<form enctype="multipart/form-data" method="post" action="mainsettings.php">
        <input type="hidden" name="action" value="updatesettings">';

  // language settings
  $sitedefaultlang = $DB->query_first("SELECT * FROM " . TABLE_PREFIX_ALL . "_mainsettings WHERE varname = 'sitedefaultlang'");

  PrintSection('语言设置');
  echo '<table width="100%" border="0" cellpadding="5" cellspacing="0">
        <tr>
          <td class="tdrow1" colspan="2">' . $sitedefaultlang['title'] . '</td>
        </tr>
        <tr>
          <td class="tdrow2" width="60%">' . $sitedefaultlang['description'] . '</td>
          <td class="tdrow3" valign="top">';
		  eval("echo \"$sitedefaultlang[input]\";");
          echo '</td>
        </tr>
        </table>';
  EndSection();


  for($i = 0; $i < count($group); $i++)
  {
    $getsitesettings = $DB->query("SELECT * FROM " . TABLE_PREFIX . "mainsettings WHERE groupname = '$group[$i]'");

    PrintSection($group[$i]);
    echo '<table width="100%" border="0" cellpadding="5" cellspacing="0">';

    while($setting=$DB->fetch_array($getsitesettings))
    {
      // fixes logo spacing
      $setting['value'] = preg_replace("/&nbsp;/", " ", $setting['value']);

      echo '<tr>
              <td class="tdrow1" colspan="2">' . $setting['title'] . '</td>
            </tr>
            <tr>
              <td class="tdrow2" width="60%">' . $setting['description'] . '</td>
              <td class="tdrow3" valign="top">';

      if($setting['input']=="text")
      {
        echo '<input type="text" size="40" name="settings[' . $setting['settingid'] . ']" value="' . htmlspecialchars($setting['value']) . '">';
      }
      elseif($setting['input']=="password")
      {
        echo '<input type="password" size="40" name="settings[' . $setting['settingid'] . ']" value="' . htmlspecialchars($setting['value']) . '">';
      }
      elseif($setting['input']=="yesno")
      {
        echo "是<input type=\"radio\" name=\"settings[$setting[settingid]]\"  " . iif($setting['value'] == 1, "checked", "") . " value=\"1\">&nbsp;&nbsp;&nbsp;否<input type=\"radio\" name=\"settings[$setting[settingid]]\" ".iif($setting['value']==0,"checked","")." value=\"0\">";
      }
      elseif($setting['input']=="textarea")
      {
        echo '<textarea name="settings[' . $setting['settingid'] . ']" rows="4" cols="30">' . $setting['value'] . '</textarea>';
      }
      else
      {
        eval("echo \"$setting[input]\";");
      }

      echo '</td></tr>';
    }

    echo '</table>';
    EndSection();

  }  // end for loop


  // logo settings
  $currentlogo = $DB->query_first("SELECT value FROM " . TABLE_PREFIX . "mainsettings WHERE varname = 'currentlogo'");

  PrintSection('Logo设置');
  echo '<table width="100%" border="0" cellpadding="5" cellspacing="0">
        <tr>
          <td class="tdrow1" colspan="2">设置网站Logo';
		  
		  if($enablewysiwyg){
			echo '&nbsp&nbsp<a href="javascript:;" onclick="javascript: ween_toggleEditor(\'currentlogo\', \'tinytoggle\', \'tinytoggleimg\');return false;" id="tinytoggle" title="Hide TinyMCE"><img src="styles/advanced/images/disabletiny.gif" border="0" align="absmiddle" id="tinytoggleimg"></a>';
		  }
	echo '</td>
        </tr>
        <tr>
          <td class="tdrow2" colspan="2"><textarea id="currentlogo" name="currentlogo" rows="15" style="width: 100%;" class="mceEditor">' . $currentlogo['value'] . '</textarea>
          </td>
        </tr>
        </table>';
  EndSection();

  PrintSubmit('updatesettings', '保存设置');
  echo '</form>';

}



// ############################### PRINT FOOTER ################################

PrintFooter();

?>