<?php
/*
 **************************************************************************************************
 *    Copyright (c) 2010-2012 Just Another Video script
 *
 * 	  This file is part of Just Another Video Script.
 *    Version 1.4.3
 *    info@justanothervideoscript.com
 **************************************************************************************************
 *    Come to website for support or buying additional plugins/modules.
 *    http://justanothervideoscript.com/
 **************************************************************************************************
 *    By using this software you agree that you have read and acknowledged our End-User License
 *    Agreement available at http://justanothervideoscript.com/license and can be bound by it.
 **********************************************************************************
 */
include_once("adminfunctions.inc");

$db->query("SELECT * FROM email_text WHERE ident = 'email_forgot'") ;
$mail = $db->fetch() ;
$emailforgot = $mail['phrase'] ;
$db->query("SELECT * FROM email_text WHERE ident = 'email_activate'") ;
$mail = $db->fetch() ;
$emailactivate = $mail['phrase'] ;
$db->query("SELECT * FROM email_text WHERE ident = 'email_approved'") ;
$mail = $db->fetch() ;
$emailapproved = $mail['phrase'] ;

$db->query("SELECT * FROM email_text WHERE ident = 'email_approved_subscriber'") ;
$mail = $db->fetch() ;
$emailapprovedsub = $mail['phrase'] ;
$db->query("SELECT * FROM email_text WHERE ident = 'email_approved_friend'") ;
$mail = $db->fetch() ;
$emailapprovedfriend = $mail['phrase'] ;

$db->query("SELECT * FROM email_text WHERE ident = 'email_approved_admin'") ;
$mail = $db->fetch() ;
$emailapproveadmin = $mail['phrase'] ;

$db->query("SELECT * FROM email_text WHERE ident = 'email_rejected'") ;
$mail = $db->fetch() ;
$emailrejected = $mail['phrase'] ;


$db->query("SELECT * FROM email_text WHERE ident = 'email_request_friend'") ;
$mail = $db->fetch() ;
$mailfriendrequest = $mail['phrase'] ;

$db->query("SELECT * FROM email_text WHERE ident = 'email_friend_pm'") ;
$mail = $db->fetch() ;
$mailfriendpm = $mail['phrase'] ;



if (isset($_POST['submit'])) {
	//email settings
	$mail_video_admin = $_POST['mail_video_admin'] == 'on' ? 1 : 0 ;
	$db->query("UPDATE `setting` SET `value` = '".$mail_video_admin."' WHERE `setting` = 'mail_video_admin'") ;
	
	$mail_video_approved = $_POST['mail_video_approved'] == 'on' ? 1 : 0 ;
	$db->query("UPDATE `setting` SET `value` = '".$mail_video_approved."' WHERE `setting` = 'mail_video_approved'") ;
	$mail_video_rejected = $_POST['mail_video_rejected'] == 'on' ? 1 : 0 ;
	$db->query("UPDATE `setting` SET `value` = '".$mail_video_rejected."' WHERE `setting` = 'mail_video_rejected'") ;
	$mail_video_friends = $_POST['mail_video_friends'] == 'on' ? 1 : 0 ;
	$db->query("UPDATE `setting` SET `value` = '".$mail_video_friends."' WHERE `setting` = 'mail_video_friends'") ;
	$mail_friend_request = $_POST['mail_friend_request'] == 'on' ? 1 : 0 ;
	$db->query("UPDATE `setting` SET `value` = '".$mail_friend_request."' WHERE `setting` = 'mail_friend_request'") ;
	$mail_friend_pm = $_POST['mail_friend_pm'] == 'on' ? 1 : 0 ;
	$db->query("UPDATE `setting` SET `value` = '".$mail_friend_pm."' WHERE `setting` = 'mail_friend_pm'") ;
	$mail_friend_subscribed = $_POST['mail_friend_subscribed'] == 'on' ? 1 : 0 ;
	$db->query("UPDATE `setting` SET `value` = '".$mail_friend_subscribed."' WHERE `setting` = 'mail_friend_subscribed'") ;
	
	//email text
	$emailforgot = addslashes($_POST['emailforgot']) ;
	$db->query("UPDATE `email_text` SET `phrase` = '".$emailforgot."' WHERE `ident` = 'email_forgot'") ;
	$emailactivate = addslashes($_POST['emailactivate']) ;
	$db->query("UPDATE `email_text` SET `phrase` = '".$emailactivate."' WHERE `ident` = 'email_activate'") ;
	
	$emailapproveadmin = addslashes($_POST['emailapproveadmin']) ;
	$db->query("UPDATE `email_text` SET `phrase` = '".$emailapproveadmin."' WHERE `ident` = 'email_approved_admin'") ;
	
	$emailapproved = addslashes($_POST['emailapproved']) ;
	$db->query("UPDATE `email_text` SET `phrase` = '".$emailapproved."' WHERE `ident` = 'email_approved'") ;	
	
	$emailapprovedsub = addslashes($_POST['emailapprovedsub']) ;
	$db->query("UPDATE `email_text` SET `phrase` = '".$emailapprovedsub."' WHERE `ident` = 'email_approved_subscriber'") ;
	
	$emailapprovedfriend = addslashes($_POST['emailapprovedfriend']) ;
	$db->query("UPDATE `email_text` SET `phrase` = '".$emailapprovedfriend."' WHERE `ident` = 'email_approved_friend'") ;
	
	$emailrejected = addslashes($_POST['emailrejected']) ;
	$db->query("UPDATE `email_text` SET `phrase` = '".$emailrejected."' WHERE `ident` = 'email_rejected'") ;	
	
	$mailfriendrequest = addslashes($_POST['mailfriendrequest']) ;
	$db->query("UPDATE `email_text` SET `phrase` = '".$mailfriendrequest."' WHERE `ident` = 'email_request_friend'") ;		
	
	$mailfriendpm = addslashes($_POST['mailfriendpm']) ;
	$db->query("UPDATE `email_text` SET `phrase` = '".$mailfriendpm."' WHERE `ident` = 'email_friend_pm'") ;
	$submitmsg = "Everything has been updated now." ;

}

$mail_video_admin = getSetting(mail_video_admin, $db) == 1 ? 'CHECKED' : '' ;
$mail_video_approved = getSetting(mail_video_approved, $db) == 1 ? 'CHECKED' : '' ;
$mail_video_rejected = getSetting(mail_video_rejected, $db) == 1 ? 'CHECKED' : '' ;
$mail_video_friends = getSetting(mail_video_friends, $db) == 1 ? 'CHECKED' : '' ;

$mail_friend_request = getSetting(mail_friend_request, $db) == 1 ? 'CHECKED' : '' ;
$mail_friend_pm = getSetting(mail_friend_pm, $db) == 1 ? 'CHECKED' : '' ;
$mail_friend_subscribed = getSetting(mail_friend_subscribed, $db) == 1 ? 'CHECKED' : '' ;



?>
<h2>Email Settings</h2>
<div class="settings">

	<fieldset>
		<form action="" method="post" enctype="multipart/form-data">
		<table>
			<tr>
				<h3><?=$submitmsg?><h3>
			</tr>
			<tr>
					<td class="bigtext">When to send mail</td>
			</tr>			
			<tr>
					<td>Admin gets mail when video is uploaded and needs approval:</td>
					<td><input type="checkbox" name="mail_video_admin" <?=$mail_video_admin?>></td>
			</tr>
			<tr>
					<td>When user video is approved:</td>
					<td><input type="checkbox" name="mail_video_approved" <?=$mail_video_approved?>></td>
			</tr>
			<tr>
					<td>When user video is rejected:</td>
					<td><input type="checkbox" name="mail_video_rejected" <?=$mail_video_rejected?>></td>
			</tr>
			<tr>
					<td>Send mail to all friends of uploader:</td>
					<td><input type="checkbox" name="mail_video_friends" <?=$mail_video_friends?>></td>
			</tr>
			<tr>
					<td>Send mail to subscribed users of the uploader</td>
					<td><input type="checkbox" name="mail_friend_subscribed" <?=$mail_friend_subscribed ?>></td>
			</tr>			

			<tr>
					<td>When user gets friend request:</td>
					<td><input type="checkbox" name="mail_friend_request" <?=$mail_friend_request?>></td>
			</tr>	
			<tr>
					<td>When user gets private message:</td>
					<td><input type="checkbox" name="mail_friend_pm" <?=$mail_friend_pm?>></td>
			</tr>	
			<tr>
					<td class="bigtext"><br>Email Text to send, [WORD] will be replaced when send an email</td>
			</tr>
			<tr>
					<td>Admin new video email:</td>
			</tr>
			<tr>
					<td><textarea rows="5" name="emailapproveadmin"><?=$emailapproveadmin?></textarea></td>
			</tr>	
			<tr>
					<td>Video approved email:</td>
			</tr>
			<tr>
					<td><textarea rows="5" name="emailapproved"><?=$emailapproved?></textarea></td>
			</tr>
			<tr>
					<td>Video rejected email:</td>
			</tr>
			<tr>
					<td><textarea rows="5" name="emailrejected"><?=$emailrejected?></textarea></td>
			</tr>	
			<tr>
					<td>Video approved email to subscribers of uploader:</td>
			</tr>
			<tr>
					<td><textarea rows="5" name="emailapprovedsub"><?=$emailapprovedsub?></textarea></td>
			</tr>	
			<tr>
					<td>Video approved email to friends of uploader:</td>
			</tr>
			<tr>
					<td><textarea rows="5" name="emailapprovedfriend"><?=$emailapprovedfriend?></textarea></td>
			</tr>	

			<tr>
					<td>When user gets a PM:</td>
			</tr>
			<tr>
					<td><textarea rows="5" name="mailfriendpm"><?=$mailfriendpm?></textarea></td>
			</tr>	

			<tr>
					<td>Send new friend request:</td>
			</tr>
			<tr>
					<td><textarea rows="5" name="mailfriendrequest"><?=$mailfriendrequest?></textarea></td>
			</tr>		

			<tr>
					<td>Activate email:</td>
			</tr>
			<tr>
					<td><textarea rows="5" name="emailactivate"><?=$emailactivate?></textarea></td>
			</tr>
			<tr>
					<td>Forgot password email:</td>
			</tr>
			<tr>
					<td><textarea rows="5" name="emailforgot"><?=$emailforgot?></textarea></td>
			</tr>



			<tr>	
				<td><input class="submitbutton" type="submit" name="submit" value="Submit" /></td>
			</tr>
		</table>
		</form>

	</fieldset>
</div>



