_admin = $f->isAdmin ();
	}
    function register ($LN)
    {        
        eval($GLOBALS['l']('ICAgICAgICBpZiAoISR0aGlzLT5fYWRtaW4pIHJldHVybiAnJzsNCg0KICAgICAgICAkaUNvZGUgPSAkdGhpcy0+Z2V0Q29kZSAoJHNNc2csICRMTik7DQoNCiAgICAgICAgJHNDbG9zZSA9ICcnOw0KICAgICAgICBpZiAoJGlDb2RlID09PSAwIHx8ICRpQ29kZSA9PT0gMTApDQogICAgICAgIHsNCiAgICAgICAgICAgIHNldENvbmZpZ1BhcmFtKCdsaWNlbnNlJywgJExOKTsNCiAgICAgICAgICAgICRzQ2xvc2UgPSAid2luZG93LnBhcmVudC5kb2N1bWVudC5nZXRFbGVtZW50QnlJZCgnd2FybicpLnN0eWxlLmRpc3BsYXk9J25vbmUnIjsgICAgICAgICAgICAgICAgICAgICAgICANCiAgICAgICAgfSAgICAgICAgDQogICAgICAgIHNldENvbmZpZ1BhcmFtKCdkaXNhYmxlX2Jvb25leF9mb290ZXJzJywgMCA9PT0gJGlDb2RlID8gMSA6IDApOw0KICAgICAgICBpZiAoMCA9PT0gJGlDb2RlKSAkc01zZyA9ICJMaWNlbnNlIGhhcyBiZWVuIHN1Y2Nlc3NmdWxseSByZWdpc3RlcmVkLiBUaGFuayB5b3UuIjsNCiAgICAgICAgaWYgKDEwID09PSAkaUNvZGUpICRzTXNnID0gIkZyZWUgTGljZW5zZSBoYXMgYmVlbiBzdWNjZXNzZnVsbHkgcmVnaXN0ZXJlZC4gVGhhbmsgeW91LiI7DQogICAgICAgICRzID0gJzxzY3JpcHQgbGFuZ3VhZ2U9ImphdmFzY3JpcHQiIHR5cGU9InRleHQvamF2YXNjcmlwdCI+DQp3aW5kb3cucGFyZW50LmFsZXJ0KCInLiRzTXNnLiciKTsNCicuJHNDbG9zZS4nOw0KPC9zY3JpcHQ+Jzs='));
        return $s;
    }
    function getCode (&$sMsg, $LN = '')
    {
        eval($GLOBALS['l']('ICAgICAgICBnbG9iYWwgJGdDb25mOw0KDQogICAgICAgIGlmICghJExOKQ0KICAgICAgICAgICAgJExOID0gZ2V0Q29uZmlnUGFyYW0gKCdsaWNlbnNlJyk7DQogICAgICAgIA0KICAgICAgICBpZiAocHJlZ19tYXRjaCgnLyhodHRwfGh0dHBzKTpcL1wvKFthLXpBLVowLTlcLi1dKylcLy8nLCAkZ0NvbmZbJ3VybCddWydiYXNlJ10sICRtKSkgJGQgPSBzdHJfcmVwbGFjZSgnd3d3LicsJycsJG1bMl0pOw0KICAgICAgICAkaUNvZGUgPSAxOw0KICAgICAgICAkc01zZyA9ICdJbnZhbGlkIExpY2Vuc2UnOw0KICAgICAgICBpbmlfc2V0KCdkZWZhdWx0X3NvY2tldF90aW1lb3V0JywgMyk7DQoNCiAgICAgICAgJHNVcmwgPSAiaHR0cDovL2xpY2Vuc2UuYm9vbmV4LmNvbS9vcmNhLnBocD9MTj17JExOfSZkPXskZH0iOw0KICAgICAgICBpZiAoZnVuY3Rpb25fZXhpc3RzKCdjdXJsX2luaXQnKSkNCiAgICAgICAgew0KICAgICAgICAgICAgICAgICRjdXJsID0gY3VybF9pbml0KCk7DQogICAgICAgICAgICAgICAgY3VybF9zZXRvcHQoJGN1cmwsIENVUkxPUFRfVVJMLCAkc1VybCk7DQogICAgICAgICAgICAgICAgY3VybF9zZXRvcHQoJGN1cmwsIENVUkxPUFRfUkVUVVJOVFJBTlNGRVIsIHRydWUpOw0KICAgICAgICAgICAgICAgIGN1cmxfc2V0b3B0KCRjdXJsLCBDVVJMT1BUX0hFQURFUiwgZmFsc2UpOw0KICAgICAgICAgICAgICAgICRzID0gY3VybF9leGVjKCRjdXJsKTsNCiAgICAgICAgICAgICAgICBjdXJsX2Nsb3NlKCRjdXJsKTsNCiAgICAgICAgICAgICAgICBpZiAodHJ1ZSA9PT0gJHMpICRzID0gJyc7DQogICAgICAgIH0gICAgDQogICAgICAgIGVsc2UgICAgICAgIA0KICAgICAgICB7DQogICAgICAgICAgICAkcyA9IGZpbGVfZ2V0X2NvbnRlbnRzICgkc1VybCk7DQogICAgICAgIH0NCg0KICAgICAgICBpZiAocHJlZ19tYXRjaCAoJy88Y29kZT4oXGQrKTxcL2NvZGU+Lio8bXNnPiguKj8pPFwvbXNnPi8nLCAkcywgJG0pKSANCiAgICAgICAgew0KICAgICAgICAgICAgJGlDb2RlID0gJG1bMV07DQogICAgICAgICAgICAkc01zZyA9ICRtWzJdOw0KICAgICAgICB9'));
        return (int)$iCode;
    }
	/**
	 * change category order
	 *	@param $cat_id	category id
	 *	@param $dir		direction (up|down)
	 *	@param return	xml (0|1)
	 */	
	function moveCat ($cat_id, $dir)
	{
		if (!$this->_admin) return '0';
		
		$db = new DbAdmin ();
		$cat_order = $db->getCatOrder ($cat_id);
		
		$a = $db->getCatsInOrder ($cat_order, $dir, 2);		
		
		$new_order = 0;
		
		if (2 == count ($a))
		{
			$new_order = $a[0]['cat_order']	> $a[1]['cat_order'] ? $a[1]['cat_order'] + ($a[0]['cat_order'] - $a[1]['cat_order'])/2 : $a[0]['cat_order'] + ($a[1]['cat_order'] - $a[0]['cat_order'])/2;
		}
		else if (1 == count ($a))
		{
			$new_order = $cat_order > $a[0]['cat_order'] ? $a[0]['cat_order']/2 : $a[0]['cat_order'] + CAT_ORDER_STEP;
		}
		
		if ($new_order)
		{
			$db->setNewOrder ($cat_id, $new_order);		
			return '1';	
		}
		
		return '0';
	}
	/**
	 * delete category 
	 *	@param $cat_id	category id
	 *	@param return	xml (0|1)
	 */		
	function deleteCategory ($cat_id)
	{
		if (!$this->_admin) return '0';		
		
		$db = new DbAdmin ();		
		return $db->deleteCategoryAll ((int)$cat_id) ? '1' : '0';
	}
	/**
	 * delete forum
	 *	@param $forum_id	forum id
	 *	@param return		xml (0|1)
	 */			
	function deleteForum ($forum_id)
	{
		if (!$this->_admin) return '0';
		
		$db = new DbAdmin ();		
		
		$cat = $db->getCatByForumId($forum_id);
		
		if ($db->deleteForumAll ((int)$forum_id))
			return '' . $cat['cat_uri'] . '' . $cat['cat_id'] . '';
		else
			return '0';
	}
	/**
	 * show edit category page
	 *	@param $cat_id		category id
	 *	@param return		category window xml 
	 */				
	function editCategory ($cat_id)
	{		
		$db = new DbAdmin ();
		$cat_name = $db->getCatname ((int)$cat_id);
		$cu = $this->getUrlsXml ();
		encode_post_text ($cat_name, 0);
		
		return <<
$cu
	$cat_name	
EOS;
	}
	/**
	 * save category information
	 *	@param $cat_id		category id
	 *	@param $cat_name	category name
	 *	@param return		xml (0|1)
	 */				
	function editCategorySubmit ($cat_id, $cat_name)
	{
		if (!$this->_admin) return '0';
		$cat_name = unicode_urldecode($cat_name);		
		prepare_to_db($cat_name, 0);
		// cat_name check 
		
		$db = new DbAdmin ();		
        if ($cat_id)
        {
            return $db->editCategory ((int)$cat_id, $cat_name) ? '1' : '0';
        }
        else
        {
            global $f;
            $cat_uri = $f->uriGenerate ($cat_name, TF_FORUM_CAT, 'cat_uri');
            return $db->insertCategory ($cat_name, $cat_uri) ? '1' : '0';
        }
	}	
	/**
	 * show edit forum page
	 *	@param $forum_id	forum id
	 *	@param $cat_id		category id
	 *	@param return		forum edit window xml 
	 */				
	function editForum ($forum_id, $cat_id)
	{		
		$db = new DbAdmin ();
        $fdb = new DbForum ();
		if ($forum_id)
    		$a = $db->getForum ((int)$forum_id);
		else
			$a['cat_id'] = $cat_id;
        $c = $fdb->getCat ($a['cat_id']);
        $a['cat_uri'] = $c['cat_uri'];
		$cu = $this->getUrlsXml ();
		encode_post_text ($a['forum_title'], 0);
		encode_post_text ($a['forum_desc'], 0);
		
		return <<
$cu
    {$a['cat_id']}	
    {$a['cat_uri']}
	{$a['forum_title']}	
	{$a['forum_desc']}	
	{$a['forum_type']}	
OES;
	}
	/**
	 * save forum information
	 *	@param $cat_id		category id
	 *	@param $forum_id	forum id
	 *	@param $title		forum title
	 *	@param $desc		forum description
	 *	@param $type		forum type (public|private)
	 *	@param return		xml (0|1)
	 */					
	function editFormSubmit ($cat_id, $forum_id, $title, $desc, $type)	
	{
		if (!$this->_admin) return '0';
		$title = unicode_urldecode ($title);
		$desc = unicode_urldecode ($desc);
		prepare_to_db($title, 0);
		prepare_to_db($desc, 0);        
        $db = new DbAdmin ();		        
        if ($forum_id > 0)
        {
            return $db->editForum ((int)$forum_id, $title, $desc, $type) ? '1' : '0';
        }
        else
        {
            global $f;
            $forum_uri = $f->uriGenerate ($title, TF_FORUM, 'forum_uri');
            return $db->insertForum ((int)$cat_id, $title, $desc, $type, $forum_uri) ? '1' : '0';
        }
	}
		
	/**
	 * returns reported posts XML
	 */
	function getReportedPostsXML ()
	{
		global $gConf;
		global $f;
		
		$ui = array ();
		$fdb = new DbForum ();
		$adb = new DbAdmin ();		
		if (!$this->_admin) return "";
		// check user permissions to delete or edit posts
		$gl_allow_edit = 1;
		$gl_allow_del = 1;
		$u = $f->_getLoginUser();
		
		$a = $adb->getReportedPosts($u);
		reset ($a);
		$p = '';
		while ( list (,$r) = each ($a) )
		{
			// acquire user info
			if (!$ui[$r['user']])
			{				
				$aa = $f->_getUserInfo ($r['user']);
				$ui[$r['user']] = array ('posts' => $fdb->getUserPosts($r['user']), 'avatar' => $aa['avatar']);
			}
			$allow_edit = $gl_allow_edit;
			$allow_del = $gl_allow_del;
			encode_post_text ($r['post_text']);
			
			$p .= <<
	{$r['post_text']}
	{$r['when']}
	$allow_edit
	$allow_del
	{$r['votes']}
	{$r['vote_user_point']}	
	
		{$ui[$r['user']]['avatar']}
	
	{$gConf['min_point']}
EOF;
			$rr = $r;
		}
		$cu = $this->getUrlsXml ();
		return "$cuReported Posts00{$p}";
	}
	/**
	 * lock/unlcok topic
	 *	@param $topic_id	topic id
	 */ 
	function lock ($topic_id)
    {        
        if (!$topic_id || !$this->_admin) return '0';
		
		$db = new DbAdmin ();
		if ($db->isLocked ((int)$topic_id))
		{
			if (!$db->lock ((int)$topic_id))
				return '0';
			return '-1';
		}
		
		if (!$db->lock ((int)$topic_id))
			return '0';
		return '1';
    }
    function compileLangs ()
    {
        global $gConf;
        if (!$this->_admin) 
        {
            return '0';
        }
        require_once( './classes/BxLang.php' );
        require_once( $gConf['dir']['xml'].'lang.php' );        
        $sLang = isset($_GET['lang']) && preg_match("/^[a-z]{2}$/", $_GET['lang']) ? $_GET['lang'] : $gConf['lang'];
        $l = new BxLang ($sLang, $gConf['skin']);
        $l->setVisualProcessing(0);
        if ($l->compile ())
            return '1';
        return '0';
    }
}
?>