<?php
/**************************************************************************************************
|
| iDocScript - Document Sharing Script
| http://www.idocscript.com
| webmaster@idocscript.com
|
|**************************************************************************************************
|
| By using this software you agree that you have read and acknowledged our End-User License 
| Agreement available at http://www.idocscript.com/eula.html and to be bound by it.
|
| Copyright (c) 2011 iDocScript.com. All rights reserved.
|**************************************************************************************************/
include("include/config.php");
include("include/functions/import.php");

$did = intval($_REQUEST['did']);
$vshareto = cleanit($_REQUEST['vshareto']);
$vsharemessage = cleanit($_REQUEST['vsharemessage']);
$USERID = intval($_SESSION['USERID']);

if ($did > 0 && is_numeric($did))
{
	if($USERID > 0 && is_numeric($USERID))
	{
		if($vshareto != "")
		{
			$query="SELECT title FROM docs WHERE DID='".mysql_real_escape_string($did)."'";
			$executequery=$conn->execute($query);
			$cleantitle = $executequery->fields['title'];
			if($cleantitle != "")
			{
				$cleantitle = seo_clean_titles_sendmail($cleantitle);
				$sharevideolink = $config['baseurl']."/doc/".$did."/".$cleantitle;
				$vshareemails = explode(",",$vshareto);
				for($vsendloop=0; $vsendloop<count($vshareemails); $vsendloop++)
				{
					$sendtotemp=$vshareemails[$vsendloop];
					if(verify_valid_email($sendtotemp))
					{
						$query="SELECT email,username FROM members WHERE USERID='".mysql_real_escape_string($USERID)."'";
						$executequery=$conn->execute($query);
						$tempemail = $executequery->fields['email'];
						$tempusername = $executequery->fields['username'];
						$sendername = stripslashes($config['site_name']);
						$from = $config['site_email'];
						$subject = $tempemail." ".$lang['425'];
						$sendmailbody = "<html>";
						$sendmailbody .= $tempusername." ".$lang['426'].":<br>";
						$sendmailbody .= "<a href=$sharevideolink>$sharevideolink</a><br><br>";
						if ($vsharemessage != "")
						{
							$vsharemessage = str_replace("\\n", "<br>", $vsharemessage);
							$sendmailbody .= $tempusername." ".$lang['435'].":<br>";
							$sendmailbody .= $vsharemessage."<br><br>";
						}
						$sendmailbody .= $lang['436'].":<br>";
						$sendmailbody .= $sharevideolink."<br><br>";
						$sendmailbody .= $lang['437'].",<br>";
						$sendmailbody .= "$sendername";
						$sendmailbody .= "</html>";
						mailme($sendtotemp,$sendername,$from,$subject,$sendmailbody,$bcc="");
						$message = $lang['438'];
					}
					else
					{
						$error = $lang['424'];
					}
				}
			}
		}
		else
		{
			$error = $lang['439'] ;
		}
	}
}
STemplate::assign('error',$error);
STemplate::assign('message',$message);
STemplate::display('postshare.tpl');
?>