Location: PHPKode > projects > QuickTalk Forum > quicktalk/qtf_user_rename.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
 * @author     Philippe Vandenberghe <hide@address.com>
 * @copyright  2008-2012 The PHP Group
 * @version    2.5 build:20100924
 */

session_start();
require_once('bin/qtf_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('qtf_reg.php'));

$oDB->Query('SELECT * FROM '.TABUSER.' WHERE id='.$id);
$row = $oDB->Getrow();

$oVIP->selfurl = 'qtf_user_rename.php';
$oVIP->selfname = $L['Change_name'];
$oVIP->exiturl = 'qtf_user.php?id='.$id;
$oVIP->exitname = '&laquo; '.$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 = 'qtf_login.php?dfltname='.$strName;
    $oVIP->exitname = '&laquo; '.$L['Login'];
    $oVIP->EndMessage(NULL,$L['S_update'],$_SESSION[QT]['skin_dir'],2);
  }
}

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

$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['E_mandatory'].': '.$L['Username'].'")); return false; }
  return null;
}
$(function() {
  $("#title").blur(function() {
    $.post("qtf_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('qtf_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;">',AsImgBox(AsImg($row['picture'],'',$row['name']),'picbox','',$row['name']),'</td>
<td class="hidden">
';

HtmlMsg(0,'350px','',$oVIP->selfname);

echo '<form method="post" action="',$oVIP->selfurl,'" onsubmit="return ValidateForm(this);">';
echo '<input type="hidden" name="id" value="',$id,'"/>';
echo '<h2>',$row['name'],'</h2>';
echo '<p>',$L['Choose_name'],'</p>';
echo '<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>';
echo '</form>';
echo '<a href="',$oVIP->exiturl,'">',$oVIP->exitname,'</a>';
echo '</div>
';

HtmlMsg(1);

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

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

include('qtf_p_footer.php');

?>
Return current item: QuickTalk Forum