{* Error and confirmation messages *}
{include file="messages.tpl"}

{strip}
{if (isset($error) and $error gt 0) or !empty($sql_error)}
   <div class="error block">
      <h2>{l}Error{/l}</h2>
      <p>{l}An error occured while saving.{/l}</p>
      {if !empty($errorMsg)}
         <p>{$errorMsg|escape}</p>
      {/if}
      {if !empty($sql_error)}
         <p>{l}The database server returned the following message:{/l}</p>
         <p>{$sql_error|escape}</p>
      {/if}
   </div>
{/if}

{if not $id}
   {if $posted}
      <div class="success block">
         {l}Category saved.{/l}
      </div>
   {elseif isset($quickAdded) and $quickAdded gt 0}
      <div class="success block">{$quickAdded} {l}subcategories saved{/l}!</div>
   {/if}

<div class="block">
   <form method="post" action="">
   <table class="formPage">

   {if isset($action) and ($action eq 'N' or $action eq 'E' or $action eq 'M')}
   <thead>
      <tr>
         <th colspan="2">
            {if $action eq 'N'}
               {if $symbolic eq 1}
                  {l}Create new symbolic category{/l}
               {else}
                  {l}Create new{/l}{if $symbolic eq 1}{l} symbolic{/l}{/if}{l} category{/l}
               {/if}
            {elseif $action eq 'E'}
               {l}Edit Category{/l}
            {elseif $action eq 'M'}
               {l}Add Subcategories to{/l}: {$currentCategory.TITLE|escape|trim}
            {/if}
         </th>
      </tr>
   </thead>
   {/if}

   <tbody>
      {if $action eq 'M'}
      <tr>
         <td class="label"><label for="multicategs">{l}Title{/l}:</label></td>
         <td class="smallDesc">
            <textarea name="multicategs" id="multicategs" rows="10" cols="50" class="text">{$multicategs|trim|escape}</textarea>
            <p class="info">{l}Place a line break between each category title{/l}.</p>
            <p class="info">{l}Duplicate entries are auto skipped{/l}.</p>
         </td>
      </tr>
      {else}
      <tr>
         <td class="label{if $symbolic ne 1} required{/if}"><label for="TITLE">{l}Title{/l}:</label></td>
         <td class="smallDesc">
            <input type="text" id="TITLE" name="TITLE" value="{$TITLE|escape|trim}" maxlength="{$smarty.const.CAT_TITLE_MAX_LENGTH}" class="text" />
            {if $symbolic eq 1}
               <p class="notice msg">{l}Leave blank to follow the title of the category that you're creating a symbolic link for{/l}.</p>
            {else}
               {validate form="dir_categs_edit" id="v_TITLE" message=$smarty.capture.field_char_required}
               {validate form="dir_categs_edit" id="v_TITLE_LENGTH" message=$smarty.capture.invalid_length|replace:'#MIN#':$smarty.const.CAT_TITLE_MIN_LENGTH|replace:'#MAX#':$smarty.const.CAT_TITLE_MAX_LENGTH}
               {validate form="dir_categs_edit" id="v_TITLE_U" message=$smarty.capture.title_not_unique}
            {/if}
         </td>
      </tr>

      {if $ENABLE_REWRITE and $symbolic ne 1}
      <tr>
         <td class="label required"><label for="TITLE_URL">{l}URL Title{/l}:</label></td>
         <td class="smallDesc">
            <input type="text" id="TITLE_URL" name="TITLE_URL" value="{$TITLE_URL|escape|trim}" maxlength="255" class="text" />
            {validate form="dir_categs_edit" id="v_TITLE_URL"  message=$smarty.capture.invalid_url_path}
            {validate form="dir_categs_edit" id="v_TITLE_URL_U" message=$smarty.capture.url_title_not_unique}
         </td>
      </tr>
      {/if}

      {if $symbolic ne 1}
      <tr>
         <td class="label"><label for="DESCRIPTION">{l}Description{/l}:</label></td>
         <td class="smallDesc">
            <textarea name="DESCRIPTION" id="DESCRIPTION" rows="6" cols="50" class="text" {formtool_count_chars name="DESCRIPTION" limit=$smarty.const.CAT_DESCRIPTION_MAX_LENGTH alert=true}>{$DESCRIPTION|trim|escape}</textarea>
            <p class="limitDesc">{l}Limit{/l}: <input type="text" name="DESCRIPTION_limit" class="limit_field" readonly="readonly" value="{$DescriptionLimit}" /></p>
            {validate form="dir_categs_edit" id="v_DESCRIPTION_LENGTH" message=$smarty.capture.invalid_length|replace:'#MIN#':$smarty.const.CAT_DESCRIPTION_MIN_LENGTH|replace:'#MAX#':$smarty.const.CAT_DESCRIPTION_MAX_LENGTH}
         </td>
      </tr>
      {/if}

      <tr>
         <td class="label required"><label for="PARENT_ID">{l}Parent{/l}:</label></td>
         <td class="smallDesc">
            {* Load category selection *}
            {include file=$smarty.const.ADMIN_TEMPLATE|cat:"/admin_category_select.tpl" parent="1"}
         </td>
      </tr>
      <tr>
         <td class="label required"><label for="SORT_ORDER">{l}Sort Order{/l}:</label></td>
         <td class="smallDesc">
            <input type="text" id="SORT_ORDER" name="SORT_ORDER" value="{$SORT_ORDER|escape|trim}" maxlength="255" class="text" />
         </td>
      </tr>
      
      <tr>
      	<td class="label"><label for="RSS_URL">{l}RSS feed:{/l}</label></td>
      	<td class="smallDesc">
      		<input type="text" id="RSS_URL" name="RSS_URL" value="{$RSS_URL|escape|trim}" maxlength="255" class="text" />
      		<p class="limitDesc">{l}For an automatic update from the RSS feed set {/l}<strong>rss_import_feeds.php</strong>{l} to run as a cron job.{/l}</p>
      	</td>
      </tr>

      {if $symbolic eq 1}
      <tr>
         <td class="label required"><label for="SYMBOLIC_ID">{l}Symbolic category for{/l}:</label></td>
         <td class="smallDesc">
            {*html_options options=$categs selected=$SYMBOLIC_ID name="SYMBOLIC_ID" id="SYMBOLIC_ID"*}
            {include file=$smarty.const.ADMIN_TEMPLATE|cat:"/admin_category_select_symbolic.tpl" parent="1"}
            {validate form="dir_categs_edit" id="v_SYMBOLIC_ID" message=$smarty.capture.no_url_in_top}
            {validate form="dir_categs_edit" id="v_SYMBOLIC_ID_E" message=$smarty.capture.invalid_symbolic_category}
            {validate form="dir_categs_edit" id="v_SYMBOLIC_ID_U" message=$smarty.capture.symbolic_category_exist}
            {validate form="dir_categs_edit" id="v_SYMBOLIC_ID_P" message=$smarty.capture.invalid_symbolic_parent}
         </td>
      </tr>
      {/if}

      <tr>
         <td class="label required"><label for="STATUS">{l}Status{/l}:</label></td>
         <td class="smallDesc">
            {html_options options=$stats selected=$STATUS name="STATUS" id="STATUS"}
         </td>
      </tr>

      {if $symbolic ne 1 and $smarty.const.ENABLE_META_TAGS eq 1}
      <tr class="thead">
         <th colspan="2">{l}META tags{/l}</th>
      </tr>
      <tr>
         <th class="msg notice info" colspan="2">{l}Define custom META tags. Leave blank to use default tags defined for your directory.{/l}</th>
      </tr>

      <tr>
         <td class="label"><label for="META_KEYWORDS">{l}META Keywords{/l}:</label></td>
         <td class="smallDesc">
            <input type="text" id="META_KEYWORDS" name="META_KEYWORDS" value="{$META_KEYWORDS|escape|trim}" class="text" />
            <p class="msg notice info">{l}Separate keywords by comma.{/l}</p>
         </td>
      </tr>
      <tr>
         <td class="label"><label for="META_DESCRIPTION">{l}META Description{/l}:</label></td>
         <td class="smallDesc">
            <textarea name="META_DESCRIPTION" id="META_DESCRIPTION" rows="3" cols="30" class="text" {formtool_count_chars name="META_DESCRIPTION" limit=$smarty.const.META_DESCRIPTION_MAX_LENGTH alert=true}>{$META_DESCRIPTION|trim|escape}</textarea>
            <p class="limitDesc">{l}Limit{/l}: <input type="text" name="META_DESCRIPTION_limit" class="limit_field" readonly="readonly" value="{$MetaDescriptionLimit}" /></p>
            {validate form="dir_categs_edit" id="v_META_DESCRIPTION_LENGTH" message=$smarty.capture.invalid_length|replace:'#MIN#':$smarty.const.META_DESCRIPTION_MIN_LENGTH|replace:'#MAX#':$smarty.const.META_DESCRIPTION_MAX_LENGTH}
         </td>
      </tr>
      {/if}
 
   {if $symbolic ne 1}
<tr>
<td class="label"><label for="TDESCRIPTION">{l}Page Title{/l}:</label></td>
<td class="smallDesc">
<textarea name="TDESCRIPTION" id="TDESCRIPTION" rows="6" cols="50" class="text" >{$TDESCRIPTION|trim|escape}</textarea>
</td>
</tr>
{/if}
   {if $symbolic ne 1}
<tr>
<td class="label"><label for="CATCONTENT">{l}Main area Content for the Category{/l}:</label></td>
<td class="smallDesc">
{if isset ($useRTE) and $useRTE eq 1}
{literal}
<script type="text/javascript">
	tinyMCE.init({
		// General options
		mode : "exact",
		elements: "CATCONTENT",
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

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

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css"
	});
</script>
{/literal}
<textarea id="CATCONTENT" name="CATCONTENT"  rows="15" cols="80" style="width: 100%">{$CATCONTENT}
</textarea>
            {else}   
<textarea name="CATCONTENT" id="CATCONTENT" rows="6" cols="50" class="text" >{$CATCONTENT}</textarea>{/if}
</td>
</tr>
{/if}
  {/if}
   </tbody>

   <tfoot>
      <tr>
         <td><input type="reset" id="reset-categ-submit" name="reset" value="{l}Reset{/l}" alt="{l}Reset form{/l}" title="{l}Reset form{/l}" class="button" /></td>
         <td><input type="submit" id="send-categ-submit" name="submit" value="{l}Save{/l}" alt="{l}Save form{/l}" title="{l}Save category{/l}" class="button" /></td>
      </tr>
   </tfoot>
   </table>
</form>
</div>
{else}
<div class="block">
   <form method="post" action="" name="delete">
   <input type="hidden" name="action" class="hidden" value="D:{$id}" />
   <table class="formPage">
      <tbody>
         <tr>
            <td colspan="2">{l}The category contains {/l}{$count_categs}{l} subcategorie(s) {/l}{$count_links}{l} link(s) and {/l}{$count_articles}{l} article(s){/l}.<br />{l}Cannot proceed with delete until further action is taken{/l}:</td>
         </tr>
         <tr>
            <td class="label"><label for="do-categ-select">{l}Move all to{/l}</label> <input type="radio" id="do-categ-select" name="do" value="move"{if $do eq "move"} checked="checked"{/if} /></td>
            <td class="smallDesc">
               {* Load category selection *}
               {include file=$smarty.const.ADMIN_TEMPLATE|cat:"/admin_category_select.tpl"}

               {if $error}
                  <span class="errForm">{l}Please select another category.{/l}</span>
               {/if}
            </td>
         </tr>
         <tr>
            <td class="label" colspan="2"><label for="do-delete-all">{l}Delete all{/l}</label> <input type="radio" id="do-delete-all" name="do" value="delete"{if $do eq "delete"} checked="1"{/if} /></td>
         </tr>
      </tbody>
      <tfoot>
         <tr>
            <td>
               <input type="submit" name="delete" value="{l}Delete{/l}" onclick="return categ_rm_confirm('{l}Are you sure you want to remove this category?{/l}\n{l}Note: categories can not be restored after removal!{/l}');" title="{l}Remove Category{/l}" class="action delete button" />
            </td>
            <td>
               <input type="submit" name="cancel" value="{l}Cancel{/l}" title="{l}Cancel category removal{/l}" class="button" />
            </td>
         </tr>
      </tfoot>
   </table>
   </form>
</div>
{/if}
{/strip}