<?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'];

  // 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'");

  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">';

  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();

?>
