Location: PHPKode > projects > Quick Guestbook > quicktalk/qtg_adm_conf.php
<?php

/**
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license.  If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to hide@address.com so we can mail you a copy immediately.
*
* @package    QuickTalk Guestbook
* @author     Philippe Vandenberghe <hide@address.com>
* @copyright  2009-2012 The PHP Group
* @version    2.5 build:20100731
*/

session_start();
require_once('bin/qtg_init.php');
if ( !isset($_SESSION['qtgAuth']) ) HtmlRedirect('qtg_login.php'); // CHECK LOGIN
if ( $_SESSION['qtgAuth']!='yes' )  HtmlRedirect('qtg_login.php');

// INITIALISE

include('bin/qtg_lang.php'); $arrLangDir = QTarrget($arrLang,2); // this creates an array with only the [iso]directories
include(GetLang().'qtg_adm.php');
$gui_skin = $qtg_skin; //conserve the skin setting
$qtg_skin = 'admin';   //override the skin in this page

$pg_name=$L['Configuration'];
$pg_url='qtg_adm_conf.php';

$arrYN = array($L['No'],$L['Yes']);

// --------
// SUBMITTED
// --------

if ( isset($_POST['ok']) )
{
  // Check values.
  if ( isset($_POST['Fld'][0]) ) { $qtg_use_age=true; } else { $qtg_use_age=false; }
  if ( isset($_POST['Fld'][1]) ) { $qtg_use_email=true; } else { $qtg_use_email=false; }
  if ( isset($_POST['Fld'][2]) ) { $qtg_use_from=true; } else { $qtg_use_from=false; }
  if ( isset($_POST['Bbc'][0]) ) { $qtg_bbc_bold=true; } else { $qtg_bbc_bold=false; }
  if ( isset($_POST['Bbc'][1]) ) { $qtg_bbc_italic=true; } else { $qtg_bbc_italic=false; } 
  if ( isset($_POST['Bbc'][2]) ) { $qtg_bbc_underline=true; } else { $qtg_bbc_underline=false; }
  if ( isset($_POST['Bbc'][3]) ) { $qtg_bbc_url=true; } else { $qtg_bbc_url=false; }
  if ( isset($_POST['Bbc'][4]) ) { $qtg_bbc_smiley=true; } else { $qtg_bbc_smiley=false; }  
  if ( empty($_POST['skin']) ) { $skin='default'; } else { $skin=$_POST['skin']; }
  if ( empty($_POST['formattime']) ) { $qtg_formattime=''; } else { $qtg_formattime=stripslashes(trim($_POST['formattime'])); }
  if ( $_POST['menulang']=='1' ) { $qtg_menulang=true; } else { $qtg_menulang=false; }
  if ( $_POST['coldefault']=='1' ) { $qtg_column_default=true; } else { $qtg_column_default=false; }
  if ( $_POST['colchange']=='1' ) { $qtg_column_change=true; } else { $qtg_column_change=false; }
  if ( $_POST['banner']=='1' ) { $qtg_banner=true; } else { $qtg_banner=false; }
  if ( $_POST['separateform']=='1' ) { $qtg_separateform=true; } else { $qtg_separateform=false; }
  $qtg_use_from_type = intval($_POST['fromtype']);
  $qtg_page_size = intval($_POST['page_size']);
  $qtg_type = $_POST['site_type'];
  
  // mandatory when map is active
  if ( !empty($qtg_gkey) ) $qtg_separateform=true;

  // check sitename
  $str = trim($_POST['title']); if ( get_magic_quotes_gpc() ) $str = stripslashes($str);
  $str = substr(QTconv($str,'3',false),0,255);
  if ( !empty($str) ) { $qtg_title = $str; } else { $error=$L['Site_name'].' '.$L['E_invalid']; }
  
  // check siteurl (can be empty)
  if ( empty($error) )
  {
    $str = trim($_POST['home']);
    if ( empty($str) )
    {
      $qtg_home='';
    }
    else
    {
      if ( substr($str,-1,1)=='/' ) $str=substr($str,0,-1);
      if ( !preg_match('/^(http:\/\/|https:\/\/)/',$str) ) $error=$L['Home_page'].' ['.$str.'] '.$L['E_invalid'].' (http://, https://)';
      if ( empty($error) ) $qtg_home=$str;
    }
  }
  
  // check admin email
  if ( empty($error) )
  {
    $str = trim($_POST['email']); if ( get_magic_quotes_gpc() ) $str = stripslashes($str);
    if ( QTismail($str) ) { $qtg_email=$str; } else { $error=$L['Home_email'].' ['.$str.'] '.$L['E_invalid']; }
  }

  // check dateformat
  if ( empty($error) )
  {
    $str = trim($_POST['formatdate']); if ( get_magic_quotes_gpc() ) $str = stripslashes($str);
    if ( empty($str) ) { $error='Date format cannot be empty...'; $qtg_formatdate='j-M-Y'; }
    if ( empty($error) ) $qtg_formatdate=$str;
  }

  // check pagewidth
  if ( empty($error) )
  {
    $str = strip_tags(trim($_POST['width']));
    if ( substr($str,-1,1)=='%' ) { $percent = '%'; } else { $percent = ''; }
    $str = str_replace('%','',$str);
    if ( !is_numeric($str) )
    {
      $error=$L['Site_width'].' ['.$str.'] '.$L['E_invalid'].' (500-1024, 50%-100%)';
    }
    else
    {
      if ( $percent=='%' )
      {
      if ( !QTisbetween($str,50,100) ) { $error=$L['Site_width'].' ['.$str.'] '.$L['E_invalid'].' (500-1024, 50%-100%)'; }
      }
      else
      {
      if ( !QTisbetween($str,500,1024) ) { $error=$L['Site_width'].' ['.$str.'] '.$L['E_invalid'].' (500-1024, 50%-100%)'; }
      }
    }
    if ( empty($error) ) $qtg_pagewidth=$str.$percent;
  }

  // show_size
  if ( empty($error) )
  {
    $str = trim($_POST['show_size']);
    if ( !is_numeric($str) )
    {
      $error=$L['Show_max'].' ['.$str.'] '.$L['E_invalid'].' (50-5000)';
    }
    else
    {
      if ( !QTisbetween($str,50,5000) ) $error=$L['Show_max'].' ['.$str.'] '.$L['E_invalid'].' (50-5000)';
    }
    if ( empty($error) ) $qtg_show_size=intval($str);
  }
  
  $qtg_language = $arrLangDir[$_POST['language']];
  if ( !file_exists('language/'.$qtg_language.'/qtg_main.php') )
  {
  $error = 'Problem to find the file language/'.$qtg_language.'/qtg_main.php. Settings cannot be saved.';
  $qtg_language = 'english';
  }
  if ( !file_exists('language/'.$qtg_language.'/qtg_adm.php') )
  {
  $error = 'Problem to find the file language/'.$qtg_language.'/qtg_adm.php. Settings cannot be saved.';
  $qtg_language = 'english';
  }
  
  if ( empty($error) )
  { 
    // check string variables to remove quotes
    foreach (array('qtg_language','skin','qtg_formatdate','qtg_formattime','qtg_title','qtg_home','qtg_email','qtg_pagewidth','qtg_welcome') as $strVar)
    {
      if ( isset($$strVar) ) {
      if ( strstr($$strVar,"'") ) {
        $$strVar = str_replace("'",'&#039;',$$strVar);
      }}
    }
    
$strTxt = '<?php
$qtg_language = "'.$qtg_language.'";
$qtg_menulang = '.($qtg_menulang ? 'true' : 'false').';
$qtg_skin = "'.$skin.'";
$qtg_formatdate = "'.$qtg_formatdate.'";
$qtg_formattime = "'.$qtg_formattime.'";
$qtg_banner = '.($qtg_banner ? 'true' : 'false').';
$qtg_title = "'.$qtg_title.'";
$qtg_home = "'.$qtg_home.'";
$qtg_email = "'.$qtg_email.'";
$qtg_pagewidth = "'.$qtg_pagewidth.'";
$qtg_show_size = '.$qtg_show_size.';
$qtg_page_size = '.$qtg_page_size.';
$qtg_use_age = '.($qtg_use_age ? 'true' : 'false').';
$qtg_use_email = '.($qtg_use_email ? 'true' : 'false').';
$qtg_use_from = '.($qtg_use_from ? 'true' : 'false').';
$qtg_use_from_type = '.$qtg_use_from_type.';
$qtg_column_default = '.($qtg_column_default ? 'true' : 'false').';
$qtg_column_change = '.($qtg_column_change ? 'true' : 'false').';
$qtg_separateform = '.($qtg_separateform ? 'true' : 'false').';  
$qtg_bbc_bold = '.($qtg_bbc_bold ? 'true' : 'false').';
$qtg_bbc_italic = '.($qtg_bbc_italic ? 'true' : 'false').';
$qtg_bbc_underline = '.($qtg_bbc_underline ? 'true' : 'false').';
$qtg_bbc_url = '.($qtg_bbc_url ? 'true' : 'false').';
$qtg_bbc_smiley = '.($qtg_bbc_smiley ? 'true' : 'false').';
$qtg_type = "'.$qtg_type.'";
 ?>';
    
    if (!is_writable('bin/config_display.php')) $error='Impossible to write into the file [bin/config_display.php].';
    
    if ( empty($error) )
    {
       if (!$handle = fopen('bin/config_display.php', 'w')) $error='Impossible to open the file [bin/config_display.php].';
    }
    if ( empty($error) )
    {
       if (fwrite($handle, $strTxt) === FALSE)
       {
         $error = 'Impossible to write into the file [bin/config_display.php].';
       }
       else
       {
         include('language/'.$qtg_language.'/qtg_adm.php');
         $strInfo = $L['Save_successfull'];
         fclose($handle);
       }
    }
  }
}

// --------
// HTML START
// --------

include('qtg_p_header.php');
include('qtg_adm_menu.php');

// Current language

$strCurrent = 'en';
  $str = $qtg_language;
  $arr = array_flip($arrLangDir);
  if ( isset($arr[$str]) ) $strCurrent = $arr[$str];

echo '
<form method="post" action="',Href('qtg_adm_conf.php'),'">
<h2>',$L['Site_settings'],'</h2>
<table width="100%" border="0" cellspacing="0" class="admin">
<tr>
<td class="admin_top" style="width:180px;"><span class="texthead"><label for="title">',$L['Site_title'],'</label></span></td>
<td class="admin" style="width:220px;"><input id="title" name="title" size="30" maxlength="255" value="',$qtg_title,'" onchange="bEdited=true;"/></td>
<td class="admin_help">',$L['HSite_title'],'</td>
</tr>
<tr>
<td class="admin_top" style="width:180px;"><span class="texthead"><label for="site_type">',$L['Site_type'],'</label></span></td>
<td class="admin" style="width:220px;">
<select id="site_type" name="site_type" onchange="bEdited=true;">
<option value="1"',($qtg_type==1 ? QSEL : ''),'>',$L['Site_type_1'],'</option>
<option value="2"',($qtg_type==2 ? QSEL : ''),'>',$L['Site_type_2'],'</option>
<option value="3"',($qtg_type==3 ? QSEL : ''),'>',$L['Site_type_3'],'</option>
</select></td>
<td class="admin_help">',$L['HSite_type'],'</td>
</tr>
<tr>
<td class="admin_top"><span class="texthead"><label for="home">',$L['Home_page'],'</label></span></td>
<td class="admin"><input id="home" name="home" size="30" maxlength="100" value="',(empty($qtg_home) ? 'http://' : $qtg_home),'" onchange="bEdited=true;"/></td>
<td class="admin_help">',$L['HHome_page'],'</td>
</tr>
<tr>
<td class="admin_top"><span class="texthead"><label for="email">',$L['Home_email'],'</label></span></td>
<td class="admin"><input id="email" name="email" size="30" maxlength="100" value="',$qtg_email,'" onchange="bEdited=true;"/></td>
<td class="admin_help">',$L['HHome_email'],'</td>
</tr>
</table>
';

echo '
<h2>',$L['Skin'],' ',$L['and'],' ',$L['Regional_settings'],'</h2>
<table cellspacing="0" class="admin">
';

// Read directory in skin
$handle = opendir('skin');
$arrFiles = array();
while(false!==($strFile=readdir($handle)))
{
  if ( $strFile!='.' && $strFile!='..' ) {
  if ( is_dir('skin/'.$strFile) ) {
    $arrFiles[$strFile] = ucfirst($strFile);
  }}
}
closedir($handle);
asort($arrFiles);

$sel = '';
foreach($arrFiles as $key=>$val)
{
  $sel .= '<option value="'.$key.'"'.($gui_skin=='skin/'.$key ? QSEL : '').'>'.$val.'</option>';
}

echo '<tr>
<td class="admin_top"><span class="texthead"><label for="skin">',$L['Skin'],'</label></span></td>
<td class="admin"><select id="skin" name="skin" onchange="bEdited=true;">',$sel,'</select></td>
<td class="admin_help">',$L['HSkin'],'</td>
</tr>
';
echo '<tr>
<td class="admin_top" style="width:180px;"><span class="texthead"><label for="width">',$L['Site_width'],'</label></span></td>
<td class="admin" style="width:220px;"><input id="width" name="width" size="4" maxlength="4" value="',$qtg_pagewidth,'" onchange="bEdited=true;"/></td>
<td class="admin_help">',$L['HSite_width'],'</td>
</tr>
';
echo '<tr>
<td class="admin_top" style="width:180px;"><span class="texthead"><label for="dateformat">',$L['Date_format'],'</label></span></td>
<td class="admin" style="width:220px;">
<input id="formatdate" name="formatdate" size="10" maxlength="24" value="',$qtg_formatdate,'" onchange="bEdited=true;"/>&nbsp;
<input id="formattime" name="formattime" size="6" maxlength="24" value="',$qtg_formattime,'" onchange="bEdited=true;"/>
</td>
<td class="admin_help">',$L['HDate_format'],'</td>
</tr>
';

// Read language subdirectories
$arrFiles = array();
foreach($arrLang as $strIso=>$arr)
{
  if ( is_dir('language/'.$arr[2]) ) $arrFiles[$strIso] = ucfirst($arr[1]);
}
asort($arrFiles);

echo '<tr>
<td class="admin_top" style="width:180px;"><span class="texthead"><label for="language">',$L['Dfltlang'],'</label></span></td>
<td class="admin" style="width:220px;"><select id="language" name="language" onchange="bEdited=true;">',QTasTag($arrFiles,$strCurrent),'</select></td>
<td class="admin_help">',$L['HDfltlang'],'</td>
</tr>
';
echo '<tr>
<td class="admin_top"><span class="texthead"><label for="menulang">',$L['Menulang'],'</label></span></td>
<td class="admin">
<select id="menulang" name="menulang" onchange="bEdited=true;">',QTasTag($arrYN,$qtg_menulang),'</select>
</td>
<td class="admin_help">',$L['HMenulang'],'</td>
</tr>
</table>
';
echo '
<h2>',$L['Message_settings'],'</h2>
<table width="100%" border="0" cellspacing="0" class="admin">
<tr>
<td class="admin_top" style="width:180px;"><span class="texthead"><label for="show_size">',$L['Show_max'],'</label></span></td>
<td class="admin" style="width:220px;"><input id="show_size" name="show_size" size="5" maxlength="5" value="',$qtg_show_size,'" onchange="bEdited=true;"/>&nbsp;',$L['Characters'],'</td>
<td class="admin_help">',$L['HShow_max'],'</td>
</tr>
<tr>
<td class="admin_top"><span class="texthead"><label for="page_size">',$L['Post_per_page'],'</label></span></td>
<td class="admin"><select id="page_size" name="page_size" onchange="bEdited=true;">',QTasTag(array(10=>10,20=>20,30=>30,40=>40,50=>50,100=>100),$qtg_page_size),'</select></td>
<td class="admin_help">',$L['HPost_per_page'],'</td>
</tr>
<tr valign="top">
<td class="admin_top"><span class="texthead">',$L['Optional_fields'],'</label></span></td>
<td class="admin">
<input type="checkbox" id="Fld[0]" name="Fld[0]" value="Age"'.($qtg_use_age ? QCHE : '').' onchange="bEdited=true;"/><label for="Fld[0]"> ',$L['Use_age'],'</label><br/>
<input type="checkbox" id="Fld[1]" name="Fld[1]" value="Email"'.($qtg_use_email ? QCHE : '').' onchange="bEdited=true;"/><label for="Fld[1]"> ',$L['Use_email'],'</label>&nbsp;<br/>
<input type="checkbox" id="Fld[2]" name="Fld[2]" value="From"'.($qtg_use_from ? QCHE : '').' onchange="bEdited=true;"/><label for="Fld[2]"> ',$L['Use_from'],'</label>&nbsp;
<select id="fromtype" name="fromtype" onchange="bEdited=true;">
<option value="0"',($qtg_use_from_type==0 ? QSEL : ''),'>',$L['Use_from_0'],'</option>
<option value="1"',($qtg_use_from_type==1 ? QSEL : ''),'>',$L['Use_from_1'],'</option>
</select>
</td>
<td class="admin_help">',$L['HOptional_fields'],'</td>
</tr>
<tr valign="top">
<td class="admin_top"><span class="texthead">',$L['BBC_code'],'</label></span></td>
<td class="admin">
<input type="checkbox" id="Bbc[0]" name="Bbc[0]" value="Bold"'.($qtg_bbc_bold ? QCHE : '').' onchange="bEdited=true;"/><label for="Bbc[0]"> ',$L['Ico_bold'],'</label><br/>
<input type="checkbox" id="Bbc[1]" name="Bbc[1]" value="Italic"'.($qtg_bbc_italic ? QCHE : '').' onchange="bEdited=true;"/><label for="Bbc[1]"> ',$L['Ico_italic'],'</label><br/>
<input type="checkbox" id="Bbc[2]" name="Bbc[2]" value="Underline"'.($qtg_bbc_underline ? QCHE : '').' onchange="bEdited=true;"/><label for="Bbc[2]"> ',$L['Ico_under'],'</label><br/>
<input type="checkbox" id="Bbc[3]" name="Bbc[3]" value="Url"'.($qtg_bbc_url ? QCHE : '').' onchange="bEdited=true;"/><label for="Bbc[3]"> ',$L['Ico_url'],'</label><br/>
<input type="checkbox" id="Bbc[4]" name="Bbc[4]" value="Smiley"'.($qtg_bbc_smiley ? QCHE : '').' onchange="bEdited=true;"/><label for="Bbc[4]"> ',$L['Ico_smiley'],'</label>
</td>
<td class="admin_help">',$L['HBBC_code'],'</td>
</tr>
</table>
';
echo '
<h2>',$L['Display_options'],'</h2>
<table width="100%" border="0" cellspacing="0" class="admin">
<tr>
<td class="admin_top" style="width:180px;"><span class="texthead"><label for="coldefault">',$L['Column_default'],'</label></span></td>
<td class="admin" style="width:220px;">
<select id="coldefault" name="coldefault" onchange="bEdited=true;">',QTasTag($arrYN,$qtg_column_default),'</select>
</td>
<td class="admin_help">',$L['HColumn_default'],'</td>
</tr>
<tr>
<td class="admin_top"><span class="texthead"><label for="colchange">',$L['Column_change'],'</label></span></td>
<td class="admin">
<select id="colchange" name="colchange" onchange="bEdited=true;">',QTasTag($arrYN,$qtg_column_change),'</select>
<td class="admin_help">',$L['HColumn_change'],'</td>
</tr>
<tr>
<td class="admin_top"><span class="texthead"><label for="banner">',$L['Banner'],'</label></span></td>
<td class="admin">
<select id="banner" name="banner" onchange="bEdited=true;">',QTasTag($arrYN,$qtg_banner),'</select>
</td>
<td class="admin_help">',$L['HBanner'],'</td>
</tr>
<tr>
<td class="admin_top"><span class="texthead"><label for="separateform">',$L['Separate_form'],'</label></span></td>
';
if ( !empty($qtg_gkey) ) 
{
echo '<td class="admin">
<select id="separateform" disabled="disabled" onchange="bEdited=true;"><option value="Y">',$L['Yes'],'</option></select>
<input type="hidden" name="separateform" value="Y"/> 
</td>';
}
else
{
echo '<td class="admin">
<select id="separateform" name="separateform" onchange="bEdited=true;">',QTasTag($arrYN,$qtg_separateform),'</select>
</td>';
}
echo '
<td class="admin_help">',$L['HSeparate_form'],'</td>
</tr>
</table>

<p style="text-align:center"><input type="submit" name="ok" value="',$L['Save'],'"/></p>
</form>
';

// --------
// HTML END
// --------

include('qtg_p_footer.php');

?>
Return current item: Quick Guestbook