<?php
// $Id: admin.weblinks.html.php,v 1.13 2004/01/16 12:15:08 rcastley Exp $
/**
* Weblink 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.13 $
**/

// ensure this file is being included by a parent file
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

class HTML_weblinks {

	function showWeblinks( $option, &$rows, &$clist, &$search, &$pageNav ) {
		global $my;
?>
		<form action="index2.php" method="post" name="adminForm">
		<table cellpadding="4" cellspacing="0" border="0" width="100%">
		<tr>
			<td width="100%" class="sectionname"><img src="images/mos_gel.png" width="70" height="67" align="middle" />Weblink Manager
			</td>
			<td nowrap="nowrap">Display #</td>
			<td>
				<?php echo $pageNav->writeLimitBox(); ?>
			</td>
			<td>Search:</td>
			<td>
				<input type="text" name="search" value="<?php echo $search;?>" class="inputbox" onChange="document.adminForm.submit();" />
			</td>
			<td width="right">
				<?php echo $clist;?>
			</td>
		</tr>
		</table>

		<table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminlist">
			<tr>
				<th width="20">
					<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $rows ); ?>);" />
				</th>
				<th class="title" width="40%" nowrap="nowrap">Title</th>
				<th width="25%" align="left" nowrap="nowrap">Category</th>
				<th width="10%" align="left" nowrap="nowrap">Hits</th>
				<th width="10%" nowrap="nowrap">Published</th>
				<th width="10%" nowrap="nowrap">Checked Out</th>
				<th width="10%" nowrap="nowrap">Approved</th>
				<th colspan="2">Reorder</th>
			</tr>
<?php
		$k = 0;
		for ($i=0, $n=count( $rows ); $i < $n; $i++) {
			$row = &$rows[$i];
?>
			<tr class="<?php echo "row$k"; ?>">
				<td width="20">
<?php		if ($row->checked_out && $row->checked_out != $my->id) { ?>
						&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="50%">
					<a href="#edit" onclick="return listItemTask('cb<?php echo $i;?>','edit')">
						<?php echo $row->title; ?>
					</a>
				</td>
				<td width="25%"><?php echo $row->category; ?></td>
				<td width="10%"><?php echo $row->hits; ?></td>
<?php
			$task = $row->published ? 'unpublish' : 'publish';
			$img = $row->published ? 'publish_g.png' : 'publish_x.png';
?>
			  <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>
<?php
			if ($row->checked_out) { ?>
				<td width="10%" align="center"><?php echo $row->editor; ?></td>
<?php		} else { ?>
				<td width="10%" align="center">&nbsp;</td>
<?php		} //Access ?>

<?php		if ($row->approved) {?>
				<td width="10%" align="center"><img src="images/tick.png"></td>
<?php
			} else { ?>
				<td width="10%" align="center">&nbsp;</td>
<?php		} ?>
<td>
<?php		if (($i > 0 || ($i+$pageNav->limitstart > 0)) && $row->catid == @$rows[$i-1]->catid) { ?>
        <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 { echo "&nbsp;"; } ?>
      </td>
      <td>
<?php		if (($i < $n-1 || $i+$pageNav->limitstart < $pageNav->total-1) && $row->catid == @$rows[$i+1]->catid) { ?>
        <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 { echo "&nbsp;"; } ?>
      </td>
<?php		$k = 1 - $k; } ?>
			</tr>
			<tr>
				<th align="center" colspan="9">
					<?php echo $pageNav->writePagesLinks(); ?></th>
			</tr>
			<tr>
				<td align="center" colspan="9">
					<?php echo $pageNav->writePagesCounter(); ?></td>
			</tr>
		</table>
		<input type="hidden" name="option" value="<?php echo $option;?>" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		</form>
<?php
	}

/**
* Writes the edit form for new and existing record
*
* A new record is defined when <var>$row</var> is passed witht the <var>id</var>
* property set to 0.
* @param mosWeblink The weblink object
* @param string The html for the categories select list
* @param string The html for the ordering select list
*/
	function editWeblink( $option, &$row, &$clist, &$olist, &$applist ) {
		mosMakeHtmlSafe( $row, ENT_QUOTES, 'description' );
?>
		<script language="javascript" type="text/javascript">
		function submitbutton(pressbutton) {
			var form = document.adminForm;
			if (pressbutton == 'cancel') {
				submitform( pressbutton );
				return;
			}

			// do field validation
			if (form.title.value == ""){
				alert( "Weblink item must have a title" );
			} else if (form.catid.value == "0"){
				alert( "You must select a category." );
			} else if (form.url.value == ""){
				alert( "You must have a url." );
			} else {
				submitform( pressbutton );
			}
		}
		</script>
		<table cellpadding="4" cellspacing="0" border="0" width="100%">
    <tr>
      <td width="100%"><span class="sectionname"><?php echo $row->id ? 'Edit' : 'Add';?> Weblink</span></td>
    </tr>
  </table>
		<table cellpadding="4" cellspacing="1" border="0" width="100%" class="adminform">
		<form action="index2.php" method="post" name="adminForm" id="adminForm">
			<tr>
				<td width="20%" align="right">Name:</td>
				<td width="80%">
					<input class="inputbox" type="text" name="title" size="50" maxlength="250" value="<?php echo $row->title;?>" />
				</td>
			</tr>

			<tr>
				<td valign="top" align="right">Category:</td>
				<td>
					<?php echo $clist; ?>
				</td>
			</tr>

			<tr>
				<td valign="top" align="right">URL:</td>
				<td>
					<input class="inputbox" type="text" name="url" value="<?php echo $row->url; ?>" size="50" maxlength="250" />
				</td>
			</tr>

			<tr>
				<td valign="top" align="right">Description:</td>
				<td>
					<textarea class="inputbox" cols="50" rows="5" name="description" style="width:500px" width="500"><?php echo $row->description;?></textarea>
				</td>
			</tr>

			<tr>
				<td valign="top" align="right">Ordering:</td>
				<td>
					<?php echo $olist; ?>
				</td>
			</tr>


			<tr>
				<td valign="top" align="right">Approved:</td>
				<td>
					<?php echo $applist; ?>
				</td>
			</tr>

		</table>

		<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
		<input type="hidden" name="option" value="<?php echo $option;?>" />
		<input type="hidden" name="task" value="" />
		</form>
<?php
	}
}
?>
