Location: PHPKode > projects > QuickTicket > quickticket/qti_adm_site.php
<?php

/**
* PHP versions 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    QuickTicket
* @author     Philippe Vandenberghe <hide@address.com>
* @copyright  2008-2012 The PHP Group
* @version    2.5 build:20101222
*/

session_start();
require_once('bin/qti_init.php');
include(Translate('qti_adm.php'));

if ( $oVIP->role!='A' ) die(Error(13));

// INITIALISE

$oVIP->selfurl = 'qti_adm_site.php';
$oVIP->selfname = '<span class="upper">'.$L['Adm_info'].'</span><br />'.$L['Adm_general'];

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

if ( isset($_POST['ok']) )
{
  // check sitename
  $str = $_POST['sitename']; if ( get_magic_quotes_gpc() ) $str = stripslashes($str);
  $str = substr(QTconv($str,'3',false),0,64);
  if ( !empty($str) ) { $_SESSION[QT]['site_name'] = $str; } else { $error = $L['Site_name'].' '.$L['E_invalid']; }

  // check siteurl
  if ( empty($error) )
  {
    $str = QTconv($_POST['siteurl'],'2');
    if ( substr($str,-1,1)=='/' ) $str = substr($str,0,-1);
    if ( !empty($str) ) { $_SESSION[QT]['site_url'] = $str; } else { $error = $L['Site_url'].': '.$L['E_invalid']; }
    if ( !preg_match('/^(http:\/\/|https:\/\/)/',$str) ) $warning = $L['Site_url'].': '.$L['E_missing_http'];
  }

  // check indexname
  if ( empty($error) )
  {
    $str = $_POST['title']; if ( get_magic_quotes_gpc() ) $str = stripslashes($str);
    $str = substr(QTconv($str,'3',false),0,64);
    if ( !empty($str) ) { $_SESSION[QT]['index_name'] = $str; } else { $error = $L['Name_of_index'].' '.$L['E_invalid']; }
  }

  // check adminemail
  if ( empty($error) )
  {
    $str = trim($_POST['adminmail']);
    if ( QTismail($str) ) { $_SESSION[QT]['admin_email'] = $str; } else { $error = $L['Adm_e_mail'].' ['.$str.'] '.$L['E_invalid']; }
  }

  // check others
  if ( empty($error) )
  {
    $_SESSION[QT]['use_smtp'] = $_POST['smtp'];
    if ( $_SESSION[QT]['use_smtp']=='1' )
    {
    $_SESSION[QT]['smtp_host'] = $_POST['smtphost'];
    $_SESSION[QT]['smtp_port'] = $_POST['smtpport'];
    $_SESSION[QT]['smtp_username'] = $_POST['smtpusr'];
    $_SESSION[QT]['smtp_password'] = $_POST['smtppwd'];
    if ( empty($_SESSION[QT]['smtp_host']) ) $error = 'Smtp host '.$L['E_invalid'];
    }
  }

  // save value
  if ( empty($error) )
  {
    $oDB->Query('UPDATE '.TABSETTING.' SET setting="'.addslashes($_SESSION[QT]['site_name']).'" WHERE param="site_name"');
    $oDB->Query('UPDATE '.TABSETTING.' SET setting="'.$_SESSION[QT]['site_url'].'"WHERE param="site_url"');
    $oDB->Query('UPDATE '.TABSETTING.' SET setting="'.addslashes($_SESSION[QT]['index_name']).'" WHERE param="index_name"');
    $oDB->Query('UPDATE '.TABSETTING.' SET setting="'.$_SESSION[QT]['admin_email'].'" WHERE param="admin_email"');
    $oDB->Query('UPDATE '.TABSETTING.' SET setting="'.$_SESSION[QT]['use_smtp'].'" WHERE param="use_smtp"');
    if ( $_SESSION[QT]['smtp_host']=='1' )
    {
    $oDB->Query('DELETE FROM '.TABSETTING.' WHERE param="smtp_host" OR param="smtp_port" OR param="smtp_username" OR param="smtp_password"');
    $oDB->Query('INSERT INTO '.TABSETTING.' VALUES ("smtp_host","'.$_SESSION[QT]['smtp_host'].'","1")');
    $oDB->Query('INSERT INTO '.TABSETTING.' VALUES ("smtp_port","'.$_SESSION[QT]['smtp_port'].'","1")');
    $oDB->Query('INSERT INTO '.TABSETTING.' VALUES ("smtp_username","'.$_SESSION[QT]['smtp_username'].'","1")');
    $oDB->Query('INSERT INTO '.TABSETTING.' VALUES ("smtp_password","'.$_SESSION[QT]['smtp_password'].'","1")');
    }
    $str = trim($_POST['adminfax']); if ( get_magic_quotes_gpc() ) $str = stripslashes($str);
      $str = QTconv($str,'3',false);
      if ( strlen($str)>255 ) $str = substr($str,0,255);
      $oDB->Query('UPDATE '.TABSETTING.' SET setting="'.addslashes($str).'" WHERE param="admin_fax"');
      $_SESSION[QT]['admin_fax'] = $str;
    $str = trim($_POST['adminname']); if ( get_magic_quotes_gpc() ) $str = stripslashes($str);
      $str = QTconv($str,'3',false);
      if ( strlen($str)>255 ) $str = substr($str,0,255);
      $oDB->Query('UPDATE '.TABSETTING.' SET setting="'.addslashes($str).'" WHERE param="admin_name"');
      $_SESSION[QT]['admin_name'] = $str;
    $str = trim($_POST['adminaddr']); if ( get_magic_quotes_gpc() ) $str = stripslashes($str);
      $str = QTconv($str,'3',false);
      if ( strlen($str)>255 ) $str = substr($str,0,255);
      $oDB->Query('UPDATE '.TABSETTING.' SET setting="'.addslashes($str).'" WHERE param="admin_addr"');
      $_SESSION[QT]['admin_addr'] = $str;

    // save lang

    $oVIP->LangDel('index','i');
    foreach($_POST as $strKey=>$strTranslation)
    {
      if ( substr($strKey,0,1)=='T' )
      {
        if ( !empty($strTranslation) )
        {
        if ( get_magic_quotes_gpc() ) $strTranslation = stripslashes($strTranslation);
        $oVIP->LangAdd('index',substr($strKey,1),'i',$strTranslation);
        }
      }
    }

    // register lang

    $_SESSION['L']['index'] = cVIP::LangGet('index',GetIso());

    // exit
    if ( empty($error) ) $strInfo = $L['S_save'];
  }
}

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

// WARNINGS

if ( !preg_match('/^(http:\/\/|https:\/\/)/',$_SESSION[QT]['site_url']) ) $warning = $L['Site_url'].': '.$L['E_missing_http'];

include('qti_adm_p_header.php');

// FORM

echo '
<script type="text/javascript">
<!--
function smtpdisabled(str)
{
  if (str=="0")
  {
  document.getElementById("smtphost").disabled=true;
  document.getElementById("smtpport").disabled=true;
  document.getElementById("smtpusr").disabled=true;
  document.getElementById("smtppwd").disabled=true;
  }
  else
  {
  document.getElementById("smtphost").disabled=false;
  document.getElementById("smtpport").disabled=false;
  document.getElementById("smtpusr").disabled=false;
  document.getElementById("smtppwd").disabled=false;
  }
  return null;
}
function PassInLink()
{
  strHost = document.getElementById("smtphost").value;
  strPort = document.getElementById("smtpport").value;
  strUser = document.getElementById("smtpusr").value;
  strPass = document.getElementById("smtppwd").value;
  document.getElementById("smtplink").href="qti_ext_smtp.php?h=" + strHost + "&p=" + strPort + "&u=" + strUser + "&w=" + strPass;
  document.getElementById("smtplink").target="_blank";
  return null;
}
function ValidateForm(theForm)
{
  if (theForm.sitename.value.length<1) { alert(qtHtmldecode("',$L['Missing'],': ',$L['Site_name'],'")); return false; }
  if (theForm.siteurl.value.length<1) { alert(qtHtmldecode("',$L['Missing'],': ',$L['Site_url'],'")); return false; }
  if (theForm.siteurl.value.substr(0,4)!="http") { alert(qtHtmldecode("http:// or https:// required in ',$L['Site_url'],'")); return false; }
  if (theForm.title.value.length<1) { alert(qtHtmldecode("',$L['Missing'],': ',$L['Name_of_index'],'")); return false; }
  if (theForm.adminmail.value.length<1) { alert(qtHtmldecode("',$L['Missing'],': ',$L['Adm_e_mail'],'")); return false; }
  return null;
}
-->
</script>
';

echo '<form method="post" action="',$oVIP->selfurl,'" onsubmit="return ValidateForm(this);">
<table class="data_o" cellspacing="0">
<tr class="data_o">
<td class="colhd colhdgroup" colspan="2">',$L['General_site'],'</td>
</tr>
';
if ( empty($_SESSION[QT]['site_name']) ) $_SESSION[QT]['site_name']='';
$str = QTconv($_SESSION[QT]['site_name'],'I');
echo '<tr class="data_o" title="',$L['H_Site_name'],'">
<td class="colhd colhdfirst" style="width:200px;"><label for="sitename">',$L['Site_name'],'</label></td>
<td class="colct"><input type="text" id="sitename" name="sitename" size="50" maxlength="64" value="',$str,'" onchange="bEdited=true;" />',(strstr($str,'&amp;') ?  ' <span class="small">'.$_SESSION[QT]['site_name'].'</span>' : ''),'</td>
</tr>
';
echo '<tr class="data_o" title="',$L['H_Site_url'],'">
<td class="colhd colhdfirst"><label for="siteurl">',$L['Site_url'],'</label></td>
<td class="colct"><input type="text" id="siteurl" name="siteurl" size="50" maxlength="255" value="',$_SESSION[QT]['site_url'],'" onchange="bEdited=true;" /></td>
</tr>
';
if ( empty($_SESSION[QT]['index_name']) ) $_SESSION[QT]['index_name']='';
$str = QTconv($_SESSION[QT]['index_name'],'I');
echo '<tr class="data_o" title="',$L['H_Name_of_index'],'">
<td class="colhd colhdfirst"><label for="title">',$L['Name_of_index'],'</label></td>
<td class="colct">
<input type="text" id="title" name="title" size="50" maxlength="64" value="',$str,'" style="background-color:#FFFF99" onchange="bEdited=true;" />',(strstr($str,'&amp;') ?  ' <span class="small">'.$_SESSION[QT]['index_name'].'</span>' : ''),'</td>
</tr>
';
echo '<tr class="data_o">
<td class="colhd colhdgroup" colspan="2">',$L['Site_contact'],'</td>
</tr>
';
echo '<tr class="data_o" title="',$L['H_Admin_e_mail'],'">
<td class="colhd colhdfirst"><label for="adminmail">',$L['Adm_e_mail'],'</label></td>
<td class="colct"><input type="text" id="adminmail" name="adminmail" size="50" maxlength="255" value="',$_SESSION[QT]['admin_email'],'" onchange="bEdited=true;" /></td>
</tr>
';
if ( empty($_SESSION[QT]['admin_fax']) ) $_SESSION[QT]['admin_fax']='';
$str = QTconv($_SESSION[QT]['admin_fax'],'I');
echo '<tr class="data_o" title="',$L['H_Admin_fax'],'">
<td class="colhd colhdfirst"><label for="adminfax">',$L['Adm_fax'],'</label></td>
<td class="colct"><input type="text" id="adminfax" name="adminfax" size="50" maxlength="255" value="',$str,'" onchange="bEdited=true;" />',(strstr($str,'&amp;') ?  ' <span class="small">'.$_SESSION[QT]['admin_fax'].'</span>' : ''),'</td>
</tr>
';
if ( empty($_SESSION[QT]['admin_name']) ) $_SESSION[QT]['admin_name']='';
$str = QTconv($_SESSION[QT]['admin_name'],'I');
echo '<tr class="data_o" title="',$L['Adm_name'],'">
<td class="colhd colhdfirst"><label for="adminname">',$L['Adm_name'],'</label></td>
<td class="colct"><input type="text" id="adminname" name="adminname" size="50" maxlength="255" value="',$str,'" onchange="bEdited=true;" />',(strstr($str,'&amp;') ?  ' <span class="small">'.$_SESSION[QT]['admin_name'].'</span>' : ''),'</td>
</tr>
';
if ( empty($_SESSION[QT]['admin_addr']) ) $_SESSION[QT]['admin_addr']='';
$str = QTconv($_SESSION[QT]['admin_addr'],'I');
echo '<tr class="data_o" title="',$L['Adm_addr'],'">
<td class="colhd colhdfirst"><label for="adminaddr">',$L['Adm_addr'],'</label></td>
<td class="colct"><input type="text" id="adminaddr" name="adminaddr" size="50" maxlength="255" value="',$str,'" onchange="bEdited=true;" />',(strstr($str,'&amp;') ?  ' <span class="small">'.$_SESSION[QT]['admin_addr'].'</span>' : ''),'</td>
</tr>
';
echo '<tr class="data_o">
<td class="colhd colhdgroup" colspan="2">',$L['Email_settings'],'</td>
</tr>
';
echo '<tr class="data_o" title="',$L['H_Use_smtp'],'">
<td class="colhd colhdfirst"><label for="smtp">',$L['Use_smtp'],'</label></td>
<td class="colct">
<select id="smtp" name="smtp" onchange="smtpdisabled(this.value); bEdited=true;">
<option value="0"',($_SESSION[QT]['use_smtp']=='0' ? QSEL : ''),'>',$L['N'],'</option>
<option value="1"',($_SESSION[QT]['use_smtp']=='1' ? QSEL : ''),'>',$L['Y'],'</option>
</select></td>
</tr>
';
echo '<tr class="data_o" title="',$L['H_Use_smtp'],'">
<td class="colhd colhdfirst"><label for="smtphost">Smtp host</label></td>
<td class="colct">
<input type="text" id="smtphost" name="smtphost" size="28" maxlength="64" value="',$_SESSION[QT]['smtp_host'],'"'.($_SESSION[QT]['use_smtp']=='0' ? QDIS : '').' onchange="bEdited=true;" />
 port <input type="text" id="smtpport" name="smtpport" size="4" maxlength="6" value="',(isset($_SESSION[QT]['smtp_port']) ? $_SESSION[QT]['smtp_port'] : '25'),'"'.($_SESSION[QT]['use_smtp']=='0' ? QDIS : '').' onchange="bEdited=true;" />
</td>
</tr>
';
echo '<tr class="data_o" title="',$L['H_Use_smtp'],'">
<td class="colhd colhdfirst"><label for="smtpusr">Smtp username</label></td>
<td class="colct"><input type="text" id="smtpusr" name="smtpusr" size="28" maxlength="64" value="',$_SESSION[QT]['smtp_username'],'"'.($_SESSION[QT]['use_smtp']=='0' ? QDIS : '').' onchange="bEdited=true;" /></td>
</tr>
';
echo '<tr class="data_o" title="',$L['H_Use_smtp'],'">
<td class="colhd colhdfirst"><label for="smtppwd">Smtp password</label></td>
<td class="colct"><input type="text" id="smtppwd" name="smtppwd" size="28" maxlength="64" value="',$_SESSION[QT]['smtp_password'],'"'.($_SESSION[QT]['use_smtp']=='0' ? QDIS : '').' onchange="bEdited=true;" /> <a id="smtplink" href="qti_ext_smtp.php" onclick="PassInLink()">test smtp</a></td>
</tr>
';
echo '<tr class="data_o">
<td class="colhd colhdgroup" colspan="2">',$L['Translations'],'</td>
</tr>
';
echo '<tr class="data_o">
<td class="colhd colhdfirst">',$L['Name_of_index'],'</td>
<td class="colct" colspan="2">
<p class="help">',sprintf($L['E_no_translation'],$_SESSION[QT]['index_name']),'</p>
<table cellspacing="0" class="hidden">';
$arrTrans = $oVIP->LangGet('index','*','i');
include('bin/qti_lang.php'); // this creates $arrLang
foreach($arrLang as $strIso=>$arr)
{
  $str = '';
  if ( isset($arrTrans[$strIso]) ) {
  if ( !empty($arrTrans[$strIso]) ) {
    $str = QTconv($arrTrans[$strIso],'I');
  }}
  echo '
  <tr class="hidden">
  <td class="hidden" style="width:30px"><label for="T',$strIso,'""><span title="',$arr[1],'">',$arr[0],'</span></label></td>
  <td class="hidden"><input class="small" title="',$L['Name_of_index'],' (',$strIso,')" type="text" id="T',$strIso,'" name="T',$strIso,'" size="45" maxlength="64" value="',$str,'" onchange="bEdited=true;" />',(strstr($str,'&amp;') ?  ' <span class="small">'.$arrTrans[$strIso].'</span>' : ''),'</td>
  </tr>
  ';
}
echo '</table>
</td>
</tr>
';
echo '<tr class="data_o">
<td class="colhd" colspan="2" style="padding:6px; text-align:center"><input type="submit" name="ok" value="',$L['Save'],'" /></td>
</tr>
';
echo '</table>
</form>
';

// HTML END

include('qti_adm_p_footer.php');

?>
Return current item: QuickTicket