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


//////////////////////////////////////////////////////////////// si se envió el formulario, cargar los errores
if ($_REQUEST[click]) {
	$errors = '';
	if ($_POST['name']=='') {$errors.= "<br>".ucfirst(_TYPE)." "._NOT_SPECIFIED."";}
	if ($_POST['title']=='') {$errors.= "<br>".ucfirst(_REFERENCE)." "._NOT_SPECIFIED."";}
	//	if ($_POST['message']=='') {$errors.= "<br>".ucfirst(_MESSAGE)." "._NOT_SPECIFIED."";}
}


if($errors=='' AND $_REQUEST[click]==""._EDIT."") {
	$_POST['message'] = base64_encode($_POST['message']);
	$query="UPDATE hd_texts SET
	name='".$_POST['name']."', 
	title='".$_POST['title']."', 
	message='".$_POST['message']."', 
	langs='".$currentlang."' 
	 WHERE id='$id'";
	if(!mysql_query($query,$db_link)){
		message(_ERROR,"DEBUG: ".$query."<br>ERROR: ".mysql_error(),'texts_admin.php',_RETURN); exit;
	}else{
		go2('texts_admin.php');
	}
}


include("head_template.php");

?>
<script language="javascript" type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
	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,imagemanager,filemanager",
	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",

	theme_advanced_buttons1 : "undo,redo,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,fontselect,fontsizeselect",
	theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,link,unlink,anchor,image,cleanup,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,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]"


});
</script>
<?php


////////////////////////////////////////////////////////////////////////////////// EDIT
if ($_REQUEST[option]=="edittext") {
	$query="SELECT * FROM hd_texts WHERE id='$_REQUEST[id]'";
	$output=mysql_query($query,$db_link);
	$row=mysql_fetch_array($output);



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


<table width="98%" class="table table-bordered">
		<tr>
		<td align="center" width="100%">
';
	echo ucfirst(_EDIT);
echo '
		</td>
		</tr>
';	
echo '
			<tr valign="top">
				<td>

';

	print(messagetopinthispage(_THIS_ITEM_WILL_BE_CREATED_ONLY_FOR_THE_CURRENT_LANGUAGE." (".langname($currentlang).")","",2));
	print errors($errors); $errors = '';
	print("
	<form method='post'>
	<table border='0' width='100%'>");

	print("<tr>");
	print("<td align='left'>");

	print("<b>".lang('_TYPE').":</b> <select name='name' class='sizeextra'>");
	print ("<option value='".$row[name]."'>".lang('_'.$row[name])."</option></select>");

	print("</td><td></td></tr>");

	print("<tr>");
	print("<td align='left'><b>".lang('_REFERENCE').":</b> <input type='text' name='title' size='50' value='".$row['title']."' ");
	print("</td><td></td></tr>");

	print("
		<tr>
		<td align='left'>
		<b>".ucfirst(_MESSAGE).":</b><br>
		<TEXTAREA cols=120 rows=20 name='message'>
		".stripslashes(base64_decode($row[message]))."
		</TEXTAREA>
	</td>
	<td>");

	if ($row[name]=="WELCOME_MESSAGE_BY_REGISTERING") {
		print("
		<fieldset><legend align='left'><font color='blue'><b>"._VARIABLES."</b></font></legend>			
			<b>%FIRSTNAME%</b> = "._FIRST_NAME."<br>
			<b>%LASTNAME%</b> = "._LAST_NAME."<br>
			<b>%EMAIL%</b> = "._EMAIL."<br>
			<b>%USER%</b> = "._USER."<br>
			<b>%PASS%</b> = "._PASSWORD."<br>
			<b>%COMPANY%</b> = "._COMPANY."<br>
		</fieldset>
	");
	}
	if ($row[name]=="DATA_ACCESS_TO_THE_ACCOUNT") {
		print("
		<fieldset><legend align='left'><font color='blue'><b>"._VARIABLES."</b></font></legend>			
		<b>%URL%</b> = ".$config[1][1]."<br>
		<b>%USER%</b> = "._USER_ID."<br>
		<b>%PASS%</b> = "._PASSWORD."
		</fieldset>
	");
	}

	print("</td>
		</tr>
	</table>
	
	
	<br>
	<input type='submit' name='click' value='"._EDIT."'><br>
	</form>
	");

echo '
		</td>
		</tr>
		</table>
</div>
</div>
';
}

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


<table width="98%" class="table table-bordered">
		<tr>
		<td align="center" width="100%">
';
echo ucfirst(_TEXTS);
echo '
		</td>
		</tr>
';

echo '
			<tr valign="top">
				<td>

';

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

echo '<table width="98%" class="table table-bordered">';
print("<tr>
	<th>".ucfirst(_TYPE)."</th>
	<th>".ucfirst(_REFERENCE)."</th>
	<th>".ucfirst(_MESSAGE)."</th>
	<th>".ucfirst(_OPTIONS)."</th>
	</tr>");

$data = query("
SELECT hd_texts.*, hd_texts_names.tip 
FROM hd_texts 
INNER JOIN hd_texts_names ON hd_texts.name = hd_texts_names.name 
WHERE hd_texts.langs LIKE '%".$currentlang."%' 
ORDER by hd_texts_names.position, hd_texts.title",0);

while($row=mysql_fetch_array($data)) {

	print("<tr><td align='left'>");
	print("".tip($row[tip])."<b>".lang('_'.$row[name])."</b></td>");

	print("<td align='left'><a href='".$serverurl."/texts_admin.php?option=edittext&id=$row[id]'>".$row[title]."</a></td>");
	print("<td align='left'>");
	if ($row[message]) {
		print(substr(strip_tags(base64_decode($row[message])),0,80)."...");
	}else{
		print("&nbsp;");
	}
	print("</td>");

	print("<td align='center'>");
	print("<a href='".$serverurl."/texts_admin.php?option=edittext&id=$row[id]'><img class='sprites edit' src='images/transparent.gif' border='0' title='"._EDIT."'></a>");
	print("</td>");
	print("</tr>");
}
print("</table>");
print("<br><table cellspacing='0' cellpadding='0' border='0'><tr>");

//graybutton('texts_admin.php?option=addtext',_ADD);

print("</tr></table>");

echo '
		</td>
		</tr>
		</table>
</div>
</div>
';

include("foot_template.php");
?>
	
