<?php 
/*    
 *    Copyright (c) 2010 VidiScript
 *
 *    This file is part of VidiScript.
 *
 *    VidiScript is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    VidiScript is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with VidiScript.  If not, see <http://www.gnu.org/licenses/>.
 *
 *    File Name: emailmanager.inc
 *    Description: Admin options for email management
 *    $Date: 2010-02-21 23:16:57 +0000 (Sun, 21 Feb 2010) $
 *    $Revision: 12 $
 */
if (isset($_POST['delete'])) {
	$stopMessage = "<p>Are you sure you wish to delete ".$_POST['ident']."? <a href='?id=".$_GET['id']."&del=".$_POST['ident']."'>Yes</a> <a href='?id=".$_GET['id']."'>No</a> </p>" ;
}
elseif (!isset($_POST['submit'])) {
	if (isset($_GET['del'])) {
		$db->query("DELETE FROM `email_text` WHERE ident = '".quote_smart($_GET['del'])."'") ;
		$stopMesage = "<p>Email text deleted. <a href='?id=".$_GET['id']."'>back</a></p>" ;
	}
	$db->query("SELECT ident FROM `email_text` ORDER BY ident") ;
	$res = $db->fetchAll() ;
	$identOptions = "" ;
	foreach ($res as $row) {
		$identOptions .= "<option>".$row['ident']."</option>" ;
	}
}
else {
	if (isset($_POST['eident'])) {
		$editIdent = $_POST['eident'] ;
		if (strlen($_POST['newident']) > 0) {
			$db->query("SELECT phrase FROM `email_text` WHERE ident = '".quote_smart($_POST['newident'])."'") ;
			if ($db->numRows() != 0) {
				$stopMessage = "<p>Email text already exists! <a href='?id=".$_GET['id']."'>back</a></p>" ;
			}
			else {
				$db->query("INSERT INTO `email_text` (ident) VALUES ('".quote_smart($_POST['newident'])."')") ;
				$editIdent = $_POST['newident'] ;
			}
		}
		echo "<p>To use this email text use the following syntax:<br/>&lt?=getEmail(\"$editIdent\")?&gt</p>" ;
		if (!isset($stopMessage)) {
			$db->query("SELECT phrase FROM `email_text` WHERE ident = '$editIdent'") ;
			$res = $db->fetch() ;
			$editEmail = $res['phrase'] ;
		}
	}
	else {
		$db->query("UPDATE `email_text` SET phrase = '".quote_smart($_POST['phrase'])."' WHERE ident = '".quote_smart($_POST['ident'])."'") ;
		$stopMessage = "<p>Email text updated. <a href='?id=".$_GET['id']."'>back</a></p>" ;
	}
}
?>
