<?php
include("postget.php");
include_once("common.php");
$pagetitle = _ANNOUNCEMENTS;
checklevel(2,$_REQUEST['clientid']);


if ($o == 'inmainpage') {
	if ($w == 'on2off') {
		$query="UPDATE hd_announcements SET in_mainpage='0' WHERE id='$id'";
		if(!mysql_query($query,$db_link)){
			messagetop(_ERROR,"DEBUG: ".$query."<br>ERROR: ".mysql_error(),'announcements_admin.php',0); 
		}
	}

	if ($w == 'off2on') {
		$query="UPDATE hd_announcements SET in_mainpage='0' WHERE in_mainpage='1' AND langs LIKE '%".$currentlang."%'";
		if(!mysql_query($query,$db_link)){
			messagetop(_ERROR,"DEBUG: ".$query."<br>ERROR: ".mysql_error(),'announcements_admin.php',0); 
		}

		$query="UPDATE hd_announcements SET in_mainpage='1' WHERE id='$id' AND langs LIKE '%".$currentlang."%'";
		if(!mysql_query($query,$db_link)){
			messagetop(_ERROR,"DEBUG: ".$query."<br>ERROR: ".mysql_error(),'announcements_admin.php',0); 
		}
	}
}


if ($_REQUEST[click]==""._ADD_ANNOUNCEMENT."") {
	$errors = '';
	if ($_POST['announcement']=='') {$errors.= "<br>".ucfirst(_ANNOUNCEMENT)." "._NOT_SPECIFIED."";}
}

if($errors=='' AND $_REQUEST[click]==""._ADD_ANNOUNCEMENT."") {

	$now=time()+$config[31][1]*3600;

	if($onlyclients=="on"){$onlyclients=1;}else{$onlyclients=0;}


	$query="INSERT INTO hd_announcements (comment,status,priority,date,in_mainpage,onlyclients,langs)
	VALUES ('$announcement','$status','$priority','$now','0','$onlyclients','$currentlang')";


	if(!mysql_query($query,$db_link)){
		messagetop("ERROR","DEBUG: ".$query."<br>MYSQL ERROR: ".mysql_error(),'announcements_admin.php',0); 
	}else{
		go2('announcements_admin.php');
	}
}

include("head_template.php");


?>
<script language="javascript" type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({




	// General options
	mode : "textareas",
	theme : "advanced",
	plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

	// produce BR en lugar de P
	//	forced_root_block : false,
	//	force_br_newlines : true,
	//	force_p_newlines : false,



	// Theme options
	theme_advanced_buttons1 : "undo,redo,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
	theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,|,forecolor,backcolor",
	theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
	theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
	theme_advanced_resizing : true,

	//	extended_valid_elements : "input[id|name|type|size|value],textarea[cols|rows]",
	extended_valid_elements : "input[id|name|type|size|value]",


	// Example content CSS (should be your site CSS)
	//	content_css : "css/example.css",

	// Drop lists for link/image/media/template dialogs
	//	template_external_list_url : "js/template_list.js",
	external_link_list_url : "<?php echo $config[1][1]?>/website_linkslist.php",
	external_image_list_url : "<?php echo $config[1][1]?>/website_imagelist.php",
	//	media_external_list_url : "js/media_list.js",

	relative_urls : false,
	remove_script_host : true,
	document_base_url : "<?php echo $config[1][1]?>/website/"

	// Replace values for the template plugin
	//	template_replace_values : {
	//		username : "Some User",
	//		staffid : "991234"
	//	}
});
</script>
<?


if ($_REQUEST[option]=="addannouncement") {
	echo '
<div class="container">
	<div class="row">
';
	

	print(messagetopinthispage(_THIS_ITEM_WILL_BE_CREATED_ONLY_FOR_THE_CURRENT_LANGUAGE." (".langname($currentlang).")","",2));
	print errors($errors); $errors = '';
	print("
	<form method='post'>
	<table class='table'>
		<tr>
			<td rowspan='3' align='center'>
			<b>".ucfirst(_ANNOUNCEMENT).":</b><br>
			<TEXTAREA cols=150 rows=10 name='announcement'>
			".$_POST[announcement]."
			</TEXTAREA>
			</td>
			<td>
			<b>".ucfirst(_STATUS)."</b>
			<select name='status'>
			<option value='1' selected>".ucfirst(_ACTIVE)."</option>
			<option value='2'>".ucfirst(_INACTIVE)."</option>
			</select>
			</td>
		</tr>
		<tr>
			<td>
			<b>".ucfirst(_PRIORITY)."</b>
			<select name='priority'>
			<option value='low' ".sele($_POST['priority'],'low').">".ucfirst(_LOW)."</option>
			<option value='medium' ".sele($_POST['priority'],'medium').">".ucfirst(_MEDIUM)."</option>
			<option value='high' ".sele($_POST['priority'],'high').">".ucfirst(_HIGH)."</option>
			</select>
			</td>
		</tr>
		<tr>
			<td>
			<input type='checkbox' name='onlyclients'");
	if($_REQUEST[id]){if ($row[onlyclients]==1){print(" checked");};}
	print("><b>".ucfirst(_VISIBLE_ONLY_TO_REGISTERED_CLIENTS)."</b>
			</td>
		</tr>
	
	</table>
	
	
	<br>
	<input type='submit' name='click' value='"._ADD_ANNOUNCEMENT."'><br>
	</form>
	");



echo '
</div>
</div>
';
}





echo '
<div class="container">
	<div class="row">
';


print(messagetopinthispage(_ONLY_ARE_DISPLAYED_THE_ITEMS_RELATED_TO_THE_CURRENT_LANGUAGE." (".langname($currentlang).")","",2));

echo '<table class="table table-striped">';
print("<thead><tr>
	<th>".ucfirst(_ID)."</th>
	<th>".ucfirst(_ANNOUNCEMENT)."</th> 
	<th>".ucfirst(_STATUS)."</th> 
	<th>".ucfirst(_PRIORITY)."</th> 
	<th>".ucfirst(_DATE)."</th> 
	<th>".ucfirst(_ONLY_CLIENTS)."</th>
	<th>".ucfirst(_OPTIONS)."</th> 
	</tr></thead><tbody>");

$data = query("SELECT * FROM hd_announcements WHERE langs LIKE '%".$currentlang."%' ORDER by date DESC",0);

while($row=mysql_fetch_array($data)) {
	print("<tr><td align='center'>".$row[id]."</td>");
	print("<td align='left'>".$row[comment]."</td>");
	if ($row[status]=='1') {
		print("<td><b><font color='green'>".strtoupper(_ACTIVE)."</font></b></td>");
	}elseif ($row[status]=='2') {
		print("<td><b><font color='red'>".strtoupper(_INACTIVE)."</font></b></td>");
	}

	print("<td align='left' nowrap>");
	switch ($row[priority]) {
		case 'low':
		print("<img class='sprites tkt_blue' src='images/transparent.gif' title='".constant('_'.strtoupper($row[priority]))."'>");
		break;

		case 'medium':
		print("<img class='sprites tkt_orange' src='images/transparent.gif' title='".constant('_'.strtoupper($row[priority]))."'>");
		break;

		case 'high':
		print("<img class='sprites tkt_red' src='images/transparent.gif' title='".constant('_'.strtoupper($row[priority]))."'>");
		break;
	}
	print(" ".constant('_'.strtoupper($row[priority]))."");
	print("</td>");

	print("<td align='center'>");
	if ($row[date]>0) {
		print(date($df,$row[date]));
		print("<br>(".TimeAgo($row[date],time())." "._AGO.")");
	}
	print("</td>");

	print("<td align='center'>"); if ($row[onlyclients]==1) {print("<img class='sprites green_status' src='images/transparent.gif' border='0'>");}
	print("&nbsp;</td>");

	print("<td align='center'>");
	print("<a href='".$serverurl."/announcements_edit.php?id=$row[id]'><img class='sprites edit' src='images/transparent.gif' border='0' title='"._EDIT."'></a>");
	print("<a href='".$serverurl."/announcements_delete.php?id=$row[id]&text=".substr(strip_tags($row[comment]),0,20)."...'><img class='sprites del' src='images/transparent.gif' border='0' title='"._DELETE."'></a>");
	print("</td>");
	print("</tr>");
}
print("</table>");

graybutton('announcements_admin.php?option=addannouncement',_ADD_ANNOUNCEMENT);


echo '
</div>
</div>
';

include("foot_template.php");
?>
	
