<?
!defined('M_COM') && exit('No Permission');
include_once M_ROOT.'./include/parse.fun.php';
load_cache('clangs,nclangs,cmsgs');
function message($message,$url_forward = '',$dtime = 0){
	global $msgforwordtime,$mcharset,$sptpls;
	$dtime = $dtime ? $dtime : ($msgforwordtime ? $msgforwordtime : 1250);
	$message .= '<br><br><br>';
	if($url_forward) {
		if(strpos($message,lang('goback')) === false){
			$message .= "<a href=\"$url_forward\">[".lang('rightnowjump')."]</a><script>setTimeout(\"window.location.replace('$url_forward');\", ".$dtime.");</script>&nbsp; ";
		}else $message .= "<a href=\"javascript:history.go(-1);\" class=\"mediumtxt\">[ ".lang('rightnowgoback')."]</a>&nbsp; ";
	}
	$message .= "<a href=\"javascript:window.close();\">[".lang('closewindow')."]</a>";
	$message = "<br><br>$message<br><br>";
	$temparr['message'] = $message;
	if(!empty($sptpls['message'])){
		mexit(template('message',$temparr));
	}else{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=<?=$mcharset?>"></head><body>
<table width="98%" border="0" cellpadding="0" cellspacing="0"><tr><td align="center"><?=$message?></td></tr></table>
</body></html>
<?	
		mexit();
	}
}
function message($key,$url_forward = ''){
	global $cmsgs,$msgforwordtime,$mcharset,$sptpls;
	$dtime = $msgforwordtime ? $msgforwordtime : 1250;
	$str = @$cmsgs[$key] ? $cmsgs[$key] : $key;
	if(($num = func_num_args())>2){
		$ars = func_get_args();
		$str = explode('%s',$str,$num-1);
		$num = count($str);
		$i = 0;
		while(++$i < $num)$str[0] .= $ars[$i+1] . $str[$i];
		$str = $str[0];
	}
	$str .= '<br><br><br>';
	if($url_forward) {
		if(strpos($str,lang('goback')) === false){
			$str .= "<a href=\"$url_forward\">[".lang('rightnowjump')."]</a><script>setTimeout(\"window.location.replace('$url_forward');\", ".$dtime.");</script>&nbsp; ";
		}else $str .= "<a href=\"javascript:history.go(-1);\" class=\"mediumtxt\">[ ".lang('rightnowgoback')."]</a>&nbsp; ";
	}
	$str .= "<a href=\"javascript:window.close();\">[".lang('closewindow')."]</a>";
	$str = "<br><br>$str<br><br>";
	$temparr['message'] = $str;
	if(!empty($sptpls['message'])){
		mexit(template('message',$temparr));
	}else{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=<?=$mcharset?>"></head><body>
<table width="98%" border="0" cellpadding="0" cellspacing="0"><tr><td align="center"><?=$str?></td></tr></table>
</body></html>
<?	
		mexit();
	}
}
function if_siteclosed($sid){
	global $cmsclosed,$subsites,$cmsclosedreason;
	$closed = empty($sid) ? $cmsclosed : $subsites[$sid]['closed'];
	if($closed) message(empty($cmsclosedreason) ? lang('defaultclosedreason') : mnl2br($cmsclosedreason));
}
function ajax_info($str){
	global $mcharset;
	@header("Expires: -1");
	@header("Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0", FALSE);
	@header("Pragma: no-cache");
	header("Content-type: application/xml");
	echo "<?xml version=\"1.0\" encoding=\"$mcharset\"?>\n<root><![CDATA[";
	echo $str;
	echo ']]></root>';
	die();
}
function cumessage($msg = '',$forward=''){
	global $inajax;
	if(empty($inajax)){
		message($msg,!$forward ? M_REFERER : $forward);
	}else ajax_info($msg);
}

function lang($str=''){
	global $clangs;
	$result = '';
	$arr = explode(' ',$str);
	if(empty($arr)) return '';
	foreach($arr as $var){
		$var = trim($var);
		$result .= isset($clangs[$var]) ? $clangs[$var] : $var;
	}
	return $result;
}

function lang($str=''){
	global $nclangs;
	$str = @$nclangs[$str] ? $nclangs[$str] : $str;
	if(($num = func_num_args())>1){
		$ars = func_get_args();
		$str = explode('%s',$str,$num);
		$num = count($str);
		$i = 0;
		while(++$i < $num)$str[0] .= $ars[$i] . $str[$i];
		return $str[0];
	}
	return $str;
}

function template($spname='',$temparr=array()){
	global $sptpls;
	if(!($tplname = @$sptpls[$spname]) || !($template = load_tpl($tplname))) return '';
	foreach(array('c','u','b') as $var) nreplace($template,$var,$temparr);
	code_parse($template);
	return $template;
}
function pcaidsarr($caid,$self=1){
	global $acatalogs;
	$caid0 = $caid;
	$pcaidsarr = array();
	$level = $acatalogs[$caid]['level'];
	for($i = $level; $i > 0; $i--){
		$caid = $acatalogs[$caid]['pid'];
		$pcaidsarr[] = $caid;
	}
	if(count($pcaidsarr)>1) $pcaidsarr = array_reverse($pcaidsarr);
	if($self == 1) $pcaidsarr[] = $caid0;
	return $pcaidsarr;
}
function pccidsarr($ccid,$coid,$self=1){
	global $cotypes,${'coclasses'.$coid};
	$ccid0 = $ccid;
	$coclasses = read_cache('coclasses',$coid);
	$pccidsarr = array();
	$level = $coclasses[$ccid]['level'];
	for($i = $level; $i > 0; $i--){
		$ccid = $coclasses[$ccid]['pid'];
		$pccidsarr[] = $ccid;
	}
	if(count($pccidsarr)>1) $pccidsarr = array_reverse($pccidsarr);
	unset($coclasses);
	if($self == 1) $pccidsarr[] = $ccid0;
	return $pccidsarr;
}

?>
