<?php
define('THIS_SCRIPT', 'upuserface');
include_once 'global.php';
$lang = load_lang($lang, 'upuserface' );
checklogin();
header("content-Type: text/html; charset=".$charset);
head();
if ( strpos($sysinfo['flag'],'34,') === false ){
	show_msg($lang['readme_tit'],$lang['error.str1'],0,'','','','');
	exit;
}
PageLoad();
footer();
function Pageload(){
	global $dv,$db,$lang,$file_list,$filename,$action,$allid;
	global $pre,$page_size,$page,$total,$page_count,$offset,$p,$start,$next,$ten_page,$facesdir,$facesurl;
	$facesdir=faces_dir();
	$facesurl= "../".$facesdir.'faces/';
	$facesdir=realpath("../".$facesdir).$lang['dir'];
	if($action=="del"){
		 del_head_portrait($filename);
	 }
	 elseif($action=="clear" and $allid=='Y'){
		delall_head_portrait();
	 }
	 else{
		head_portrait();
	}
include printout('upuserface');
}
function faces_dir() {
	global $dv,$db;
	$forum_setting=$db->scalar("select forum_setting from {$dv}setup");
	$forum_settings=explode(",",$forum_setting);
	return $forum_settings[90];
}
function head_portrait(){
	global $dv,$lang,$db,$file_list,$facesdir,$facesurl;
	global $pre,$page_size,$page,$total,$page_count,$offset,$p,$start,$next,$ten_page,$file_total;
	$file_list=array();
	if (is_dir($facesdir)) {
		if ($dir_hand = opendir($facesdir)) {
			while (($file = readdir($dir_hand)) !== false) {
				if($file=="." or $file==".."){
					continue;
				}
				else{
					$file_list[]=$dir.$file;
					$file_total+=1;
				}
			}
			$page_size=20;
			$page_count=ceil($file_total/$page_size);
			$total=$file_total;
			closedir($dir_hand);
		}
	}
	else{
		show_msg($lang['sys.info'],$lang['tmp.info13'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
}
function del_head_portrait($filename){
	global $lang,$facesdir,$facesurl;
	if($filename!=""){
		if(unlink($filename)){
			show_msg($lang['sys.info'],$lang['tmp.info14'],1,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
		else{
			show_msg($lang['sys.info'],$lang['tmp.info15'],0,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
	}
	else{
		show_msg($lang['sys.info'],$lang['tmp.info16'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
}
function delall_head_portrait(){
	global $lang,$facesdir,$facesurl;
	if(is_dir($facesdir)){
		if($dir_fp=opendir($facesdir)){
			while(($filename=readdir($dir_fp))!==false){
				if($filename=="." or $filename==".."){
					continue;
				}
				else{
					unlink($facesdir.$filename);
				}
			}
			show_msg($lang['sys.info'],$lang['tmp.info14'],1,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
		else{
			show_msg($lang['sys.info'],$lang['tmp.info15'],0,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
	}
	else{
		show_msg($lang['sys.info'],$lang['tmp.info10'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
}
?>