<?php
/***************************************************************************
 *  You can find the license in the docs directory
 *
 *  Unicode Reminder メモ
 ***************************************************************************/

require_once($opt['rootpath'] . 'lib2/logic/rowEditor.class.php');

class statpic
{
	var $nUserId = 0;

	var $reUser;

	function __construct($nNewUserId)
	{
		$this->reUser = new rowEditor('user');
		$this->reUser->addPKInt('user_id', null, false, RE_INSERT_AUTOINCREMENT);
		$this->reUser->addString('statpic_text', '', false);
		$this->reUser->addString('statpic_logo', 0, false);

		$this->nUserId = $nNewUserId+0;

		$this->reUser->load($this->nUserId);
	}

	function getStyle()
	{
		return $this->reUser->getValue('statpic_logo');
	}

	function setStyle($value)
	{
		return $this->reUser->setValue('statpic_logo', $value);
	}

	function getText()
	{
		return $this->reUser->getValue('statpic_text');
	}

	function setText($value)
	{
		if ($value != '')
			if (!mb_ereg_match(REGEX_STATPIC_TEXT, $value))
				return false;

		return $this->reUser->setValue('statpic_text', $value);
	}

	function save()
	{
		$retval = $this->reUser->save();
		if ($retval)
			$this->invalidate();

		return $retval;
	}

	// force regeneration of image on next call of ocstats.php
	function invalidate()
	{
		sql("DELETE FROM `user_statpic` WHERE `user_id`='&1'", $this->nUserId);
	}
}
?>