<?php
/**
* @version 2.6.3
* @package Joomla 1.5
* @subpackage DT Register
* @copyright Copyright (C) 2006 DTH Development
* @copyright contact dthdev@dthdevelopment.com
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/
?>
<?php

global $custom_field_types ;

?>
		<form action="index2.php" method="post" name="adminForm">

    <p><?php echo JText::_( 'DT_CUSTOM_FIELD_INSTRUCTIONS' ); ?></p>

		<table class="adminheading">

		<tr>

			<th><?php echo JText::_( 'DT_CUSTOM_FIELDS' );?>&nbsp;&nbsp;&nbsp;</th>

			<td><?php echo JText::_( 'DT_FILTER' );?></td>

			<td>

			<input type="text" name="search" value="<?php echo htmlspecialchars( $search );?>" class="text_area" onChange="document.adminForm.submit();" />

			</td>

		</tr>

		</table>

		<table class="adminlist">

		<tr>

			<th width="10">#</th>

			<th width="20">

			<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $rows ); ?>);" />

			</th>
            
			<th><?php echo JText::_( 'DT_NAME' );?></th>
            <th><?php echo JText::_( 'DT_FIELD_TYPE' );?></th>
            <th><?php echo JText::_( 'DT_EMAIL_TAG' );?></th>
			<th><?php echo JText::_( 'DT_SIZE' );?></th>

			<th><?php echo JText::_( 'DT_LABEL' );?></th>

			<th colspan="2" width="5%"><?php echo JText::_( 'DT_REORDER' );?></th>

			<th width="2%"><?php echo JText::_( 'DT_ORDER' );?></th>

			<th width="1%">

			<a href="javascript: saveOrderCustom( <?php echo count( $rows )-1; ?>,'saveorder_customfield')"><img src="images/filesave.png" border="0" width="16" height="16" alt="<?php echo JText::_( 'DT_SAVE_ORDER' ); ?>" /></a>

			</th>

			<th width="20%"><?php echo JText::_( 'DT_PUBLISHED' );?></th>

		</tr>

		<?php

		$k = 0;

		for ($i=0, $n=count( $rows ); $i < $n; $i++) {

			$row = &$rows[$i];

			$link 	= 'index2.php?option='.$option.'&task=editA_customfield&hidemainmenu=1&id='. $row->id;

			$task 	= $row->published ? 'unpublish_customfield' : 'publish_customfield';

			$img 	= $row->published ? 'publish_g.png' : 'publish_x.png';

			$alt 	= $row->published ? JText::_( 'DT_PUBLISHED' ) : JText::_( 'DT_UNPUBLISHED' );

			$row->checked_out = false;

			$checked 	= JHTML::_('grid.checkedout',   $row, $i );

			?>

			<tr class="<?php echo "row$k"; ?>">

				<td>

				<?php  echo $pageNav->getRowOffset( $i ); ?>

				</td>

				<td>

				<?php echo $checked; ?>

				</td>
               
				<td align= "center">

					<a href="<?php echo $link; ?>" title="Edit Customfield">

						<?php echo $row->name; ?>

					</a>

				</td>
                 <td align="center">

						<?php echo $custom_field_types[$row->type]; ?>

				</td>
                <td align="center">

						<?php echo "[FIELD".$row->id."]"; ?>

				</td>
				<td align="center">

					<?php echo $row->field_size?>

				</td>

				<td align="center">

				<?php echo $row->label?>

				</td>

				<td>

				<?php echo $pageNav->orderUpIcon( $i, true,'orderup_customfield' ); ?>

				</td>

	  		<td>

				<?php echo $pageNav->orderDownIcon( $i, $n, true,'orderdown_customfield' ); ?>

				</td>

				<td align="center" colspan="2">

				<input type="text" name="order[]" size="5" value="<?php echo $row->ordering; ?>" class="text_area" style="text-align: center" />

				</td>

				<td align="center">

				<a href="javascript: void(0);" onclick="return listItemTask('cb<?php echo $i;?>','<?php echo $task;?>')">

				<img src="images/<?php echo $img;?>" width="12" height="12" border="0" alt="<?php echo $alt; ?>" />

				</a>

				</td>

			</tr>

			<?php	$k = 1 - $k; } ?>

		</table>

		<?php echo $pageNav->getListFooter(); ?>

		<input type="hidden" name="option" value="<?php echo $option;?>" />

		<input type="hidden" name="task" value="custom_fields" />

		<input type="hidden" name="boxchecked" value="0" />

		<input type="hidden" name="hidemainmenu" value="0">

		</form>

		<script language="javascript">

			function saveOrderCustom(n,task)

			{

				for ( var j = 0; j <= n; j++ )

				{

					box = eval( "document.adminForm.cb" + j );

					if ( box ) {

						if ( box.checked == false ) {

							box.checked = true;

						}

					} else {

						alert("You cannot change the order of items, as an item in the list is `Checked Out`");

						return;

					}

				}

				submitform(task);

			}

		</script>	