{* 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 $posted}
   <div class="success block">
      {l}Link saved.{/l}
   </div>
{/if}

{if isset($AllowedFeat) and $AllowedFeat ne 1}
   <div class="error block">
      <p>{l}Maximum number of featured links for this category exceeded!{/l}</p>
      <p>{l}Please review link preferences.{/l}</p>
   </div>
{/if}

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

   {if isset($action) and ($action eq 'N' or $action eq 'E')}
   <thead>
      <tr>
         <th colspan="2">
            {if $action eq 'N'}
               {l}Create new link{/l}
            {elseif $action eq 'E'}
               {l}Edit link{/l}
            {/if}
         </th>
      </tr>
  </thead>
  {/if}

   <tbody>
      <tr>
         <td class="label required"><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.TITLE_MAX_LENGTH}" class="text" />
            {validate form="dir_links_edit" id="v_TITLE" message=$smarty.capture.field_char_required}
            {validate form="dir_links_edit" id="v_TITLE_U" message=$smarty.capture.title_not_unique}
            {validate form="dir_links_edit" id="v_TITLE_LENGTH" message=$smarty.capture.invalid_length|replace:'#MIN#':$smarty.const.TITLE_MIN_LENGTH|replace:'#MAX#':$smarty.const.TITLE_MAX_LENGTH}
            {if $SEO_URL != ''}
            <a class="admin_action" href="{if !$smarty.const.ENABLE_REWRITE}
                                                {$smarty.const.DOC_ROOT}/detail.php?id={$ID}
                                             {else}
                                                {$smarty.const.DOC_ROOT}/{$SEO_URL}{/if}" title="{l}Preview Link on the Front End{/l}" target="_blank">
            	<img src="{$smarty.const.TEMPLATE_ROOT}/images/outbox.png"/>
            </a>
            {/if}
         </td>
      </tr>
      <tr>
         <td class="label {if $smarty.const.REQUIRE_URL}required{/if}"><label for="URL">{l}URL{/l}:</label></td>
         <td class="smallDesc">
            <input type="text" id="URL" name="URL" value="{$URL|escape|trim}" class="text"/>
            {if $smarty.const.REQUIRE_URL}
	    {validate form="dir_links_edit" id="v_URL" message=$smarty.capture.invalid_url}
            {validate form="dir_links_edit" id="v_URL_U" message=$smarty.capture.url_not_unique}
	    {/if}
         </td>
      </tr>
      <tr>
         <td class="label"><label for="DESCRIPTION">{l}Description{/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: "DESCRIPTION",
		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="DESCRIPTION" name="DESCRIPTION" rows="20" cols="80" style="width: 100%">{$DESCRIPTION}
</textarea>	
            {else}
               <textarea name="DESCRIPTION" id="DESCRIPTION" rows="6" cols="50" class="text">{$DESCRIPTION|trim|escape}</textarea>
            {/if}
            <p class="limitDesc">{l}Limit{/l}: <input type="text" name="DESCRIPTION_limit" class="limit_field" readonly="readonly" value="{$DescriptionLimit}" /></p>
            {validate form="dir_links_edit" id="v_DESCRIPTION_LENGTH" message=$smarty.capture.invalid_length|replace:'#MIN#':$smarty.const.DESCRIPTION_MIN_LENGTH|replace:'#MAX#':$smarty.const.DESCRIPTION_MAX_LENGTH}
         </td>
      </tr>
       {if $smarty.const.GMAP_ENABLE}
<tr>
         <td class="label"><label for="ADDRESS">{l}Address{/l}:</label></td>
         <td class="smallDesc">
            <input type="text" id="ADDRESS" name="ADDRESS" value="{$ADDRESS|escape|trim}"  class="text" />
         </td>
      </tr>
      <tr>
         <td class="label"><label for="CITY">{l}City{/l}:</label></td>
         <td class="smallDesc">
            <input type="text" id="CITY" name="CITY" value="{$CITY|escape|trim}"  class="text" />
         </td>
      </tr>
      <tr>
         <td class="label"><label for="STATE">{l}State/Province{/l}:</label></td>
         <td class="smallDesc">
            <input type="text" id="STATE" name="STATE" value="{$STATE|escape|trim}"  class="text" />
         </td>
      </tr>
      <tr>
         <td class="label"><label for="ZIP">{l}Zip/Postal Code{/l}:</label></td>
         <td class="smallDesc">
            <input type="text" id="ZIP" name="ZIP" value="{$ZIP|escape|trim}"  class="text" />
         </td>
      </tr>
       <tr>
         <td class="label"><label for="PHONE_NUMBER">{l}Phone Number{/l}:</label></td>
         <td class="smallDesc">
            <input type="text" id="PHONE_NUMBER" name="PHONE_NUMBER" value="{$PHONE_NUMBER|escape|trim}"  class="text" />
         </td>
      </tr>
       {/if}
      {if $smarty.const.REQUIRE_REGISTERED_USER}
      <tr>
         <td class="label"><label for="OWNER_ID">{l}Assign Owner{/l}:</label></td>
         <td class="smallDesc">
            {html_options options=$ActiveUsersList selected=$OWNER_ID name="OWNER_ID" id="OWNER_ID"}
            <p class="msg notice info">{l}Use with care!! Selected user details will overwrite link owner name, email address and id!!{/l}</p>
            {validate form="dir_links_edit" id="v_OWNER_ID" message=$smarty.capture.field_required}
         </td>
      </tr>
      {/if}
      <tr>
         <td class="label"><label for="OWNER_NAME">{l}Owner Name{/l}:</label></td>
         <td class="smallDesc">
            <input type="text" id="OWNER_NAME" name="OWNER_NAME" value="{$OWNER_NAME|escape|trim}" maxlength="{$smarty.const.USER_NAME_MAX_LENGTH}" class="text" />
            {validate form="dir_links_edit" id="v_OWNER_NAME_LENGTH" message=$smarty.capture.invalid_length|replace:'#MIN#':$smarty.const.USER_NAME_MIN_LENGTH|replace:'#MAX#':$smarty.const.USER_NAME_MAX_LENGTH}
         </td>
      </tr>
      <tr>
         <td class="label"><label for="OWNER_EMAIL">{l}Owner Email{/l}:</label></td>
         <td class="smallDesc">
            <input type="text" id="OWNER_EMAIL" name="OWNER_EMAIL" value="{$OWNER_EMAIL|escape|trim}" maxlength="255" class="text" />
            {validate form="dir_links_edit" id="v_OWNER_EMAIL" message=$smarty.capture.invalid_email}
         </td>
      </tr>
<tr>
         <td class="label required"><label for="OWNER_EMAIL_CONFIRMED">{l}Owner Email Confirmed{/l}:</label></td>
         <td class="smallDesc">
        {html_options options=$econfirm selected=$OWNER_EMAIL_CONFIRMED name="OWNER_EMAIL_CONFIRMED" id="OWNER_EMAIL_CONFIRMED"}
         </td>
      </tr>

      <tr>
         <td class="label required"><label for="CATEGORY_ID">{l}Category{/l}:</label></td>
         <td class="smallDesc">
            {* Load category selection *}
            {include file=$smarty.const.ADMIN_TEMPLATE|cat:"/admin_category_select.tpl"}
            {validate form="dir_links_edit" id="v_CATEGORY_ID" message=$smarty.capture.no_url_in_top}
         </td>
      </tr>
      <tr>
<td class="label required"><label for="semail">{l}Send Email On Edit{/l}:</label></td>
<td class="smallDesc">
<input type="checkbox" id="semail" name="semail" value="1" {if $semail}checked="checked"{/if} />
 <p class="msg notice info">{l}Check this to send an email to the link owner to let them know you have edited the link.{/l}</p>        
</td>
</tr>

      {if $smarty.const.FTR_ENABLE}
      <tr>
         <td class="label required"><label for="FEATURED">{l}Featured{/l}:</label></td>
         <td class="smallDesc">
            <input type="checkbox" id="FEATURED" name="FEATURED" value="1" {if $FEATURED}checked="checked"{/if} />
         </td>
      </tr>
      {/if}
      <tr>
<td class="label"><label for="LINK_TYPE">{l}Link Type{/l}:</label></td>
<td class="smallDesc">
 {html_options options=$link_type_str selected=$LINK_TYPE name="LINK_TYPE" id="LINK_TYPE"}
</td>
</tr>
<tr>
      <tr>
         <td class="label required"><label for="NOFOLLOW">{l}NoFollow{/l}:</label></td>
         <td class="smallDesc">
            <input type="checkbox" id="NOFOLLOW" name="NOFOLLOW" value="1"{if $NOFOLLOW} checked="checked"{/if} />
         </td>
      </tr>
      <tr>
         <td class="label required"><label for="RECPR_REQUIRED">{l}Require Reciprocal Link{/l}:</label></td>
         <td class="smallDesc">
            <input type="checkbox" id="RECPR_REQUIRED" name="RECPR_REQUIRED" value="1"{if $RECPR_REQUIRED} checked="checked"{/if} />
         </td>
      </tr>
      <tr>
         <td class="label"><label for="RECPR_URL">{l}Reciprocal Link URL{/l}:</label></td>
         <td class="smallDesc">
            <input type="text" id="RECPR_URL" name="RECPR_URL" value="{$RECPR_URL|escape|trim}" class="text" />
            {validate form="dir_links_edit" id="v_RECPR_URL" message=$smarty.capture.invalid_url}
            {if !empty ($RECPR_URL)}
               <a href="{$RECPR_URL|escape|trim}" title="{l}Visit{/l}: {$RECPR_URL|escape|trim}" class="button" target="_blank">{l}Visit reciprocal page{/l}</a>
            {/if}
         </td>
      </tr>
      <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>
      <tr>
         <td class="label"><label for="EXPIRY_DATE">{l}Link Expires{/l}:</label></td>
         <td class="smallDesc">
            <input type="text" id="EXPIRY_DATE" name="EXPIRY_DATE" value="{$EXPIRY_DATE}" maxlength="40" class="text" />
            {validate form="dir_links_edit" id="v_EXPIRY_DATE" message=$smarty.capture.invalid_date}
         </td>
      </tr>
      {if $smarty.const.ENABLE_PAGERANK}
      <tr>
         <td class="label"><label for="PAGERANK">{l}Pagerank{/l}:</label></td>
         <td class="smallDesc">
            <input type="text" id="PAGERANK" name="PAGERANK" value="{$PAGERANK}" maxlength="2" class="text" />
            <p class="msg notice info">{l}Leave the field blank for automatic Google Pagerank calculation or give value of "-1" for no Pagerank.{/l}</p>
            {validate form="dir_links_edit" id="v_PAGERANK" message=$smarty.capture.field_integer_required}
         </td>
      </tr>
      {/if}
      <tr>
         <td class="label"><label for="HITS">{l}Hits{/l}:</label></td>
         <td class="smallDesc">
            <input type="text" id="HITS" name="HITS" value="{$HITS}" maxlength="15" class="text" />
            {validate form="dir_links_edit" id="v_HITS" message=$smarty.capture.field_integer_required}
         </td>
      </tr>

      {if $smarty.const.ENABLE_META_TAGS eq 1}
      <tr class="thead">
         <th colspan="2">{l}META tags{/l}</th>
      </tr>
      <tr class="thead">
         <td colspan="2" class="info notice">{l}Define custom META tags for detail pages. Leave blank to use default tags defined for your directory.{/l}</td>
      </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 id="META_DESCRIPTION" name="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_links_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}
   </tbody>

   <tfoot>
      <tr>
         <td><input type="reset" id="reset-link-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-link-submit" name="submit" value="{l}Save{/l}" alt="{l}Save form{/l}" title="{l}Save link{/l}" class="button" /></td>
      </tr>
   </tfoot>
   </table>
   </form>
</div>
{/strip}