<?php
$sumfingIncl=true;
if(isset ($_POST['username']) && isset($_POST['email']) && isset($_POST['uid'])) {      
	include '../../config.thing.php';
	
	// Get options
	$set = get_adm_opts();
	include '../../incl/translate.php';
	
	// Get datavar if not empty
	if($_POST['datav'] != '') {
		$datavar = '_' . $_POST['datav'];
	} else {
		$datavar = '';
	}
	
	// Make link
	$linkhash = sha1($_POST['username'] . ':;:' . $_POST['uid']);
	$link = MY_APP_URL . '?app_data=3_' . $linkhash . $datavar;
	
	// Insert into database
	if(insert_mobile_link($_POST['uid'],$linkhash,$datavar)) {
		$sendemail = true;
	} else {
		error_log(_("Link saving from mobile page failed!"));
	}
	
	// Send message to user
	$subject = str_replace('[NAME]',$_POST['username'],$set->mob_email_subject);
	$message = str_replace('[NAME]',$_POST['username'],$set->mob_email_message);
	$message = str_replace('[LINK]','<a href="'.$link.'">' . $link . '</a>',$message);
	$message = nl2br($message);
	if($sendemail) {
		if(!mobile_email($set->admin_email,$_POST['email'],$subject,$message)) {
			error_log(_("Email to mobile user failed!"));
		} else {
			echo 1;	
		}
	}
}

?>