<?php
// $Id: HTML_modules.php,v 1.24 2004/02/26 05:02:59 eddieajau Exp $
/**
* Module 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.24 $
**/

/**
* Utility class for the display of module functions
*/
class HTML_modules {
	/**
	* Writes a list of the defined modules
	* @param array An array of category objects
	*/
	function showModules( &$rows, $myid, &$pageNav, $option ) {
?>
<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">Module Manager</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>#</th>
		<th>
			<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $rows );?>);" />
		</th>
		<th class="title">Module Name</th>
		<th nowrap="nowrap">Type</th>
		<th nowrap="nowrap">Position</th>
		<th nowrap="nowrap">Published</th>
		<th nowrap="nowrap">Checked Out</th>
		<th nowrap="nowrap">Access</th>
		<th colspan="2" nowrap="nowrap">Reorder</th>
	</tr>
<?php
		$k = 0;
		for ($i=0, $n=count( $rows ); $i < $n; $i++) {
			$row = &$rows[$i];
			$img = $row->published ? 'publish_g.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="50%"><a href="#edit" onclick="return listItemTask('cb<?php echo $i;?>','edit')"><?php echo $row->title; ?></a></td>
		<td width="10%" align="center"><?php echo $row->module ? "Mambo" : "User";?></td>
		<td width="10%" align="center"><?php echo $row->position; ?></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;?>" 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 align="center">
<?php		if (($i > 0 || ($i+$pageNav->limitstart > 0)) && $row->position == @$rows[$i-1]->position) { ?>
			<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->position == @$rows[$i+1]->position) { ?>
			<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="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="<?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 module
	*
	* A new record is defined when <var>$row</var> is passed witht the <var>id</var>
	* property set to 0.
	* @param mosCategory The category object
	* @param array <p>The modules of the left side.  The array elements are in the form
	* <var>$leftorder[<i>order</i>] = <i>label</i></var>
	* where <i>order</i> is the module order from the db table and <i>label</i> is a
	* text label associciated with the order.</p>
	* @param array See notes for leftorder
	* @param string The html for the groups select list
	* @param string The html for the page content select list
	* @param string The html position select list
	*/
	function editModule( &$row, &$orders2, &$glist, &$menulist, &$poslist, &$titlelist, &$publishlist, $option ) {
		$limit = intval( mosGetParam( $_REQUEST, 'limit', 10 ) );
		$limitstart = intval( mosGetParam( $_REQUEST, 'limitstart', 0 ) );
?>
		<script language="javascript" type="text/javascript">
		function submitbutton(pressbutton) {
			if (document.adminForm.title.value == ""){
				alert("Module must have a title");
			} else {
				<?php if ($row->module == "") {
					getEditorContents( 'editor1', 'content' );
				}?>
				submitform(pressbutton);
			}
		}
		</script>

		<script language="javascript" text="text/javascript">
		<!--
			var originalOrder = '<?php echo $row->ordering;?>';
			var originalPos = '<?php echo $row->position;?>';
			var orders = new Array();	// array in the format [key,value,text]
<?php	$i = 0;
foreach ($orders2 as $k=>$items) {
	foreach ($items as $v) {
		echo "\n	orders[".$i++."] = new Array( '$k','$v->value','$v->text' );";
	}
}
?>
		//-->
		</script>

		<table cellpadding="4" cellspacing="1" border="0" width="100%">
			<tr>
				<td width="100%" class="sectionname" ><img src="images/mos_gel.png" align="middle" alt="Module Manager"><?php echo $row->id ? 'Edit' : 'Add';?> Module -> <?php echo $row->title; ?></td>
			</tr>
		</table>
		<table cellpadding="4" cellspacing="1" border="0" width="100%" class="adminform">
		<form action="index2.php" method="POST" name="adminForm">
			<tr>
				<td width="100" align="left">Title:</td>
				<td>
					<input class="inputbox" type="text" name="title" size="50" value="<?php echo $row->title; ?>" />
				</td>
			</tr>
			<tr>
				<td width="100" align="left">Show title:</td>
				<td>
					<?php echo $titlelist; ?>
				</td>
			</tr>
			<!-- START selectable pages -->
			<tr>
				<td valign="top" align="left">Page(s):</td>
				<td>
					<?php echo $menulist; ?>
				</td>
			</tr>
			<!-- END selectable pages -->

			<?php if ($row->module == "")
			{ ?>
				<tr>
					<td valign="top" align="left">Content:</td>
					<td>
						<?php 
						// parameters : areaname, content, hidden field, width, height, rows, cols
						editorArea( 'editor1',  $row->content , 'content', '500', '400', '70', '15' ) ; ?>
					</td>
				</tr>
		 	<?php		
			} ?>
			<tr>
				<td valign="top" align="left">Position:</td>
				<td>
					<?php echo $poslist; ?>
				</td>
			</tr>
			<tr>
				<td valign="top" align="left">Module Order:</td>
				<td>
					<script language="javascript" type="text/javascript">
					<!--
						writeDynaList( 'class="inputbox" name="ordering" size="1"',
							orders, originalPos, originalPos, originalOrder );
					//-->
					</script>
				</td>
			</tr>
			<tr>
				<td valign="top" align="left">Access Level:</td>
				<td>
					<?php echo $glist; ?>
				</td>
			</tr>
			<tr>
				<td valign="top" align="left">Parameters:</td>
				<td>
					<textarea name="params" cols="50" rows="5" class="inputbox"><?php echo $row->params; ?></textarea>
				</td>
			</tr>
			<tr>
				<td valign="top">Published:</td>
				<td><?php echo $publishlist; ?></td>
			</tr>
			<tr>
				<td colspan="2">&nbsp;</td>
			</tr>
		</table>

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