<?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');
if ( !$oVIP->CanView('U') ) die(Error(11));
// --------
// INITIALISE
// --------
$id = -1;
if (isset($_GET['id'])) $id = intval(strip_tags($_GET['id']));
if (isset($_POST['id'])) $id = intval(strip_tags($_POST['id']));
if ($id<0) die('Missing parameters');
include('bin/qt_lib_smtp.php');
include(Translate('qti_reg.php'));
$oVIP->selfurl = 'qti_user_rename.php';
$oVIP->selfname = $L['Change_name'];
$oVIP->exiturl = 'qti_user.php?id='.$id;
$oVIP->exitname = '« '.$L['Profile'];
// --------
// SUBMITTED
// --------
if ( isset($_POST['ok']) )
{
// check name
if ( empty($error) )
{
$strName = trim(strip_tags($_POST['title'])); if ( get_magic_quotes_gpc() ) $strName = stripslashes($strName);
if ( !QTislogin($strName) ) $error = $L['E_invalid'];
if ( empty($error) )
{
$oDB->Query('SELECT count(*) as countid FROM '.TABUSER.' WHERE name="'.$strName.'"');
$row = $oDB->Getrow();
if ( $row['countid']!=0 ) $error = $L['E_already_used'];
}
}
// execute and exit
if ( empty($error) )
{
$oDB->Query('UPDATE '.TABUSER.' SET name="'.$strName.'" WHERE id='.$id);
// Post
$oDB->query('UPDATE '.TABPOST.' SET username="'.$strName.'" WHERE userid='.$id);
$oDB->query('UPDATE '.TABPOST.' SET modifname="'.$strName.'" WHERE modifuser='.$id);
$oDB->query('UPDATE '.TABTOPIC.' SET firstpostname="'.$strName.'" WHERE firstpostuser='.$id);
$oDB->query('UPDATE '.TABTOPIC.' SET lastpostname="'.$strName.'" WHERE lastpostuser='.$id);
$oDB->query('UPDATE '.TABSECTION.' SET moderatorname="'.$strName.'" WHERE moderator='.$id);
$oVIP->exiturl = 'qti_login.php?dfltname='.$strName;
$oVIP->exitname = '« '.$L['Login'];
$oVIP->EndMessage(NULL,$L['S_update'],$_SESSION[QT]['skin_dir'],2);
}
}
// --------
// HTML START
// --------
$oDB->Query('SELECT * FROM '.TABUSER.' WHERE id='.$id);
$row = $oDB->Getrow();
$strHeadScript = '
<script type="text/javascript" src="bin/qt_jquery.js"></script>
<script type="text/javascript">
<!--
function ValidateForm(theForm)
{
if (theForm.title.value.length==0) { alert(html_entity_decode("'.$L['Missing'].': '.$L['Username'].'")); return false; }
return null;
}
$(function() {
$("#title").blur(function() {
$.post("qti_j_exists.php",
{f:"name",v:$("#title").val(),e1:"'.$L['E_min_4_char'].'",e2:"'.$L['E_already_used'].'"},
function(data) { if ( data.length>0 ) document.getElementById("title_err").innerHTML=data; });
});
});
-->
</script>
';
include('qti_p_header.php');
if ( !empty($error) ) echo '<p id="infomessage" class="error">',$error,'</p>';
echo '
<table class="hidden" cellspacing="0">
<tr class="hidden">
<td class="hidden" style="width:175px;"><br />',AsImgBox(AsImg(AsAvatarScr($row['photo']),'',$row['name']),'picbox','',$row['name']),'</td>
<td class="hidden">
';
$oHtml->Msgbox($oVIP->selfname);
echo '<form method="post" action="',$oVIP->selfurl,'" onsubmit="return ValidateForm(this);">
<input type="hidden" name="id" value="',$id,'" />
<h2>',$row['name'],'</h2>
<p>',$L['Choose_name'],'</p>
<p><input type="text" id="title" name="title" size="20" maxlength="32" onfocus="document.getElementById(\'title_err\').innerHTML=\'\';" /> <input type="submit" name="ok" value="',$L['Save'],'" /> <span id="title_err" class="error"></span></p>
</form>
<p><a href="',$oVIP->exiturl,'">',$oVIP->exitname,'</a></p>
';
$oHtml->Msgbox();
echo '
</td>
</tr>
</table>
';
// --------
// HTML END
// --------
include('qti_p_footer.php');
?>