<?php
// $Id: HTML_categories.php,v 1.22 2004/02/22 08:43:35 rcastley Exp $
/**
* Category admin HTML
* @package Mambo Open Source
* @Copyright (C) 2000 - 2003 Miro International Pty Ltd
* @ All rights reserved
* @ Mambo Open Source is Free Software
* @ Released under GNU/GPL License : http://www.gnu.org/copyleft/gpl.html
* @version $Revision: 1.22 $
**/

/**
* Utility class for the display of category functions
*/
class categories_html {
	/**
	* Writes a list of the categories for a section
	* @param array An array of category objects
	* @param string The name of the category section
	*/
	function show( &$rows, $section, $section_name, $myid, $pageNav ) {
?>
<form action="index2.php" method="POST" name="adminForm">
<table cellpadding="4" cellspacing="0" border="0" width="100%">
	<tr>

      <td width="100%"><span class="sectionname"><img src="images/mos_gel.png" width="70" height="67" align="middle"><?php echo $section_name;?>
        Categories</span></td>
		<td nowrap>Display #</td>
		<td> <?php echo $pageNav->writeLimitBox(); ?> </td>
	</tr>
</table>

<table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminlist">
	<tr>
		<th width="20">#</th>
		<th width="20">
			<input type="checkbox" name="toggle" value="" onClick="checkAll(<?php echo count( $rows );?>);" />
		</th>
		<th class="title">Category Name</th>
		<th width="15%"># of&nbsp;Records</th>
		<th width="15%"># Checked&nbsp;Out</th>
		<th width="10%">Published</th>
		<th width="10%">Checked Out</th>
		<th width="10%">Access</th>
		<th colspan="2">Reorder</th>
	</tr>
<?php
		$k = 0;
		for ($i=0, $n=count( $rows ); $i < $n; $i++) {
			$row = &$rows[$i];
			$img = $row->published ? 'tick.png' : 'publish_x.png';
			$task = $row->published ? 'unpublish' : 'publish';
?>
	<tr class="<?php echo "row$k"; ?>">
		<td width="20" align="right"><?php echo $i+$pageNav->limitstart+1;?></td>
		<td width="20">
<?php		if ($row->checked_out && $row->checked_out != $myid) { ?>
						&nbsp;
<?php		} else { ?>
			<input type="checkbox" id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $row->id; ?>" onClick="isChecked(this.checked);" />
<?php		} ?>
		</td>
		<td width="35%">
			<a href="#edit" onClick="return listItemTask('cb<?php echo $i;?>','edit')">
				<?php echo "$row->name ($row->title)"; ?>
			</a>
		</td>
		<td width="15%" align="center"><?php echo $row->num; ?></td>
		<td width="15%" align="center"><?php echo $row->checked_out; ?></td>
		<td width="10%" 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="" /></a></td>
		<td width="15%" align="center"><?php echo $row->editor; ?>&nbsp;</td>
		<td width="10%" align="center"><?php echo $row->groupname;?></td>
		<td>
<?php		if ($i > 0 || ($i+$pageNav->limitstart > 0)) { ?>
			<a href="#reorder" onClick="return listItemTask('cb<?php echo $i;?>','orderup')">
				<img src="images/uparrow.png" width="12" height="12" border="0" alt="Move Up">
			</a>
<?php		} else { ?>
			&nbsp;
<?php		} ?>
		</td>
		<td>
<?php		if ($i < $n-1 || $i+$pageNav->limitstart < $pageNav->total-1) { ?>
			<a href="#reorder" onClick="return listItemTask('cb<?php echo $i;?>','orderdown')">
				<img src="images/downarrow.png" width="12" height="12" border="0" alt="Move Down">
			</a>
<?php		} else { ?>
			&nbsp;
<?php		} ?>
		</td>
<?php		$k = 1 - $k; ?>
	</tr>
<?php	} // for loop ?>

    <tr>
		<th align="center" colspan="10"> <?php echo $pageNav->writePagesLinks(); ?></th>
    </tr>
    <tr>
		<td align="center" colspan="10"> <?php echo $pageNav->writePagesCounter(); ?></td>
    </tr>
</table>

<input type="hidden" name="option" value="categories" />
<input type="hidden" name="section" value="<?php echo $section;?>" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="chosen" value="" />
<input type="hidden" name="act" value="" />
<input type="hidden" name="boxchecked" value="0" />
</form>
<?php
	}
	/**
	* Writes the edit form for new and existing categories
	*
	* A new record is defined when <var>$row</var> is passed witht the <var>id</var>
	* property set to 0.  Note that the <var>section</var> property <b>must</b> be defined
	* even for a new record.
	* @param mosCategory The category object
	* @param string The html for the image list select list
	* @param string The html for the image position select list
	* @param string The html for the ordering list
	* @param string The html for the groups select list
	*/
	function edit( &$row, $imagelist, $iposlist, $orderlist, $glist ) {
		global $mosConfig_live_site, $mosConfig_editor;
		if ($row->image == "") {
			$row->image = 'blank.png';
		}
		mosMakeHtmlSafe( $row, ENT_QUOTES, 'description' );
?>
	<script language="javascript" type="text/javascript">
	function submitbutton(pressbutton, section) {
		if (document.adminForm.name.value == ""){
			alert("Category must have a name");
		} else {
			<?php getEditorContents( 'editor1', 'description' ) ; ?>
			submitform(pressbutton);
		}
	}
	</script>

	<form action="index2.php" method="post" name="adminForm">
	<table cellpadding="4" cellspacing="0" border="0" width="100%">
	<tr>
		<td class="sectionname"><?php echo $row->id ? 'Edit' : 'Add';?> Category <?php echo $row->name; ?></td>
	</tr>
	</table>
	<table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminform">
	<tr>
		<td>Category Title:</td>
		<td colspan="2">
			<input class="inputbox" type="text" name="title" value="<?php echo $row->title; ?>" size="50" maxlength="50" title="A short name to appear in menus" />
		</td>
	</tr>
	<tr>
		<td>Category Name:</td>
		<td colspan="2">
			<input class="inputbox" type="text" name="name" value="<?php echo $row->name; ?>" size="50" maxlength="255" title="A long name to be displayed in headings" />
		</td>
	</tr>
	<tr>
		<td>Image:</td>
		<td>
			<?php echo $imagelist; ?>
		</td>
		<td rowspan="4" width="50%">
			<script language="javascript" type="text/javascript">
				if (document.forms[0].image.options.value!=''){
				  jsimg='../images/stories/' + getSelectedValue( 'adminForm', 'image' );
				} else {
				  jsimg='../images/M_images/blank.png';
				}
				document.write('<img src=' + jsimg + ' name="imagelib" width="80" height="80" border="2" alt="Preview" />');
			</script>
	  </td>
	</tr>
	<tr>
		<td>Image Position:</td>
		<td>
			<?php echo $iposlist; ?>
		</td>
	</tr>
	<tr>
		<td>Ordering:</td>
		<td>
			<?php echo $orderlist; ?>
		</td>
	</tr>
	<tr>
		<td>Access Level:</td>
		<td>
			<?php echo $glist; ?>
		</td>
	</tr>
	<tr>
		<td valign="top">Description:</td>
		<td colspan="2">
			<?php
			// parameters : areaname, content, hidden field, width, height, rows, cols
			editorArea( 'editor1',  $row->description , 'description', '500', '200', '50', '5' ) ; ?>
		</td>
	</tr>
	<input type="hidden" name="option" value="categories" />
	<input type="hidden" name="section" value="<?php echo $row->section; ?>" />
	<input type="hidden" name="oldtitle" value="<?php echo $row->title ; ?>" />
	<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
	<input type="hidden" name="task" value="" />

	</table>
	</form>
<?php }

} ?>
