<?php
$sumfingIncl=true;
// Admin data posted
if(isset($_POST['check-source'])) {      
	include '../config.thing.php';
	
	$pdata = '';
	$user = '';
	
	$pdata = explode("_",$_POST['check-source']);
	$user = is_user_fakeid($pdata[0]);
	
	if($user->isadmin == 1) {
		save_admi_settings($_POST);
	}
	die;
}
// Security form posted
if(isset ($_POST['sec_data_form'])) {
	include '../config.thing.php';
	$added = 0;
	$user = is_user_fakeid($_POST['sec_data_form']);
	$fake_id = $_POST['sec_data_form'];
	if(isset($user->id)) {
		unset($_POST['sec_data_form']);
		
		$err=array();
		$vals=array();
		foreach($_POST as $name=>$value) {
			$mand = explode("_",$name);
			if(($mand[1] == "mandatory") && ($value == "")) {
				$err[str_replace("++"," ",$mand[0])] = 1;
			}else {
				$vals[str_replace("++"," ",$mand[0])] =  $value;
				$err[str_replace("++"," ",$mand[0])] = 0;
			}
		}
		
		if(in_array(1,$err)) {
			// return 0 = mandatory field missing
			foreach($err as $k=>$v) {
				if($v == 1) {
					echo 1;
					die;
				}
			}
			die;
		} else {
			// Get data from sec_data table
			$sec_data = get_sec_data();
			
			// If some exists, say that
			if(!empty($sec_data)) {
				foreach($vals as $k=>$v) {
					if(in_array($v, $sec_data)) {
						if(trim($v) != '') {
							echo $k . " " .$v;	// value exists
							die;
						}
					} else {
						//echo $k . " " . $v;	// no value found, add
						$canadd = true;
					}
				}
				if($canadd) {
					if(update_verified_user('yes', $fake_id)) {
						$added = add_sec_data($fake_id, $vals);
						echo $added;
					}
				}
				
			} else {
				// Not data in table yet, add data
				if(update_verified_user('yes', $fake_id)) {
					$added = add_sec_data($fake_id, $vals);
					echo $added;
				}
			}
			
		}
		
	} // user exists
}
?>