<?php
require_once "../includes/common.inc.php";
require_once MODEPATH.'./'.$adminpath.'/global.func.php';
if($action == 'logout'){

	clearcookies();
	$groupid = 5;
	$mm_mid = 0;
	$mm_user = $mm_pw = '';


	cpmsg('logout', mreferer());
}elseif($action == 'loggin'){

	if(cpchecksubmit('logsubmit',1,$useseccode)){
		$mm_mid = 0;
		$mm_user = $mm_pw = $mm_secques = $md5_password = '';
		$member = array();
		$md5_password = md5($password);
		$member = $db->queryarray("SELECT m.mid AS mm_mid, m.username AS mm_user, m.password AS mm_pw, m.adminid, m.groupid, m.lastvisit FROM {$tablepre}members m LEFT JOIN {$tablepre}usergroups u USING (groupid)
					WHERE m.username='$username'");
		if($member['mm_mid'] && $member['mm_pw'] == $md5_password) {
				extract($member);
				$mm_userss = $mm_user;
				$mm_user = addslashes($mm_user);		
			
				$cookietime = intval(isset($_POST['cookietime']) ? $_POST['cookietime'] :
						($_DCOOKIE['cookietime'] ? $_DCOOKIE['cookietime'] : 0));

				dsetcookie('cookietime', $cookietime, 31536000);
				dsetcookie('auth', authcode("$mm_pw\t$mm_mid", 'ENCODE'), $cookietime);

				$sessionexists = 0;

				if($groupid == 6) {
					cpmsg('login_succeed_inactive_member', '/index.html');
				} else {
					cpmsg('login_succeed', mreferer());
				}
		}
		cpmsg('admin_login_noneuser', NULL, 'HALTED');
	}else{
		$referer = mreferer();
		if($useseccode) {
			$seccode = random(4, 1);
		}
		$_DCOOKIE['cookietime'] = isset($_DCOOKIE['cookietime']) ? $_DCOOKIE['cookietime'] : 2592000;
		$cookietimecheck = array((isset($_DCOOKIE['cookietime']) ? intval($_DCOOKIE['cookietime']) : 2592000) => 'checked');		
		include theme('loggin', 'themes/admin','admin');
	}
}

?>