<?php

if ( !defined( 'SMARTY_DIR' ) ) {
	include_once( 'init.php' );
}

include ( 'sessioninc.php' );

$mship = $_REQUEST['item_number'];

$mshipinfo =& $osDB->getRow('select activedays, name from ! where roleid = ?', array( MEMBERSHIP_TABLE, $mship ) );

$activedays = $mshipinfo['activedays'];

$userrec =& $osDB->getRow('select level, levelend from ! where id = ?', array(USER_TABLE, $_SESSION['UserId'] ) );

if ($userrec['levelend'] < time() || $userrec['level'] != $mship) { $userrec['levelend'] = time(); }

$levelend = strtotime("+$activedays day", $userrec['levelend']);

$osDB->query( 'UPDATE ! SET level = ?, levelend = ?  WHERE id = ?', array( USER_TABLE, $mship, $levelend, $_SESSION['UserId'] ) );

$t->assign('level', $mshipinfo['name']);

unset($userrec, $mshipinfo);

$t->assign('rendered_page', $t->fetch('mshipchanged.tpl') );

$t->display( 'index.tpl' );

?>