|
Page 3 of 8
admin.dailymessage.html.php
<?
defined(
'_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
This line makes
sure this code is being called from Joomla and not by some stray visitor.
class
HTML_joeDailyMessage{
This class is
primarily called form admin.dailymessage.php and handles the majority of the
HTML output for the administrator interface.
function
edit( $option, &$row ) {
This function
takes the name of the component (com_dailymessage) and a database row loaded
from code in admin.dailymessage.php and displays a screen where the
administrator can edit a daily message.
?>
<form
action="index2.php" method="post" name="adminForm" id="adminForm"
class="adminForm">
<table
border="0" cellpadding="3" cellspacing="0">
<tr>
<td>Message:
</td>
<td><input
type="text" size="50" maxsize="100" name="message" value="<?php echo
$row->message; ?>" /></td>
</tr>
<tr>
<td>Date:
</td>
<td><input
size="30" name="date" value="<? echo $row->date; ?>"></td>
</tr>
<tr>
<td>Published:
</td>
<td><?
echo mosHTML::yesnoSelectList( "published", "", $row->published );
?></td>
</tr>
If a database row
has been supplied, the fields of the form are populated. Noticed that the
'Published' element is handled by the mosHTML class function yesnoSelectList.
The mosHTML class is declared in classes/mambo.php and is available in
throughout Joomla. This function generates a dropdown list with the values 'no'
and 'yes'. If the value of the variable $row-published is 0, 'no' will be
selected. If the value is 1, 'yes' will be selected. This can be very helpful
for creating administrative interfaces and is handled more gracefully than a
checkbox.
</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>
<?
}
Finally, the
hidden variables containing the daily message id, the name of the component, and
the task are placed in the form and output ends. The 'task' variable is actually
set to null so that the Javascript from the toolbar can fill
it in later depending on which button is clicked.
function
listConfiguration($option, &$rows)
{
This function is
called to display the configuration panel where the administrator can format the
display of the daily messages.
?>
<form
action="index2.php" method="post" name="adminForm">
<table
cellpadding="4" cellspacing="0" border="0" width="100%"
class="adminlist">
<?
$row
= $rows[0];
?>
<tr><td>Bold</td><td><?
echo mosHTML::yesnoSelectList( "bold", "", $row->bold );
?></td></tr>
<tr><td>Italic</td><td><?
echo mosHTML::yesnoSelectList( "italic", "", $row->italic );
?></td></tr>
<tr><td>Underline</td><td><?
echo mosHTML::yesnoSelectList( "underline", "", $row->underline );
?></td></tr>
<tr><td>Show
Date</td><td><? echo mosHTML::yesnoSelectList( "showdate", "",
$row->showdate ); ?></td></tr>
</table>
This form is
populated with the data from the first row in the mos_joe_dailymessage_conf
table [there should only be one row]. The yesnoSelectList() function makes it
simple to ensure the correct values are represented on the form.
<input
type="hidden" name="option" value="<?php echo $option; ?>" />
<input
type="hidden" name="task" value="" />
<input
type="hidden" name="configid" value=<? echo $row->configid ?> />
<input
type="hidden" name="act" value="configure" />
</form>
<?
}
Finally the
option, task, configid, and act variables are hidden in the form. The 'configid' variable ensures that we update the same configuration
record, although there should only be one. The 'act' variable tells the
admin.dailymessage.php code to either save or cancel for the configuration
screen and not the message screen. This is handled by the switch statement
towards the beginning of that file.
function
listMessages( $option, &$rows ) {
?>
Finally, this
function renders the default screen the administrator sees when clicking on
'Edit Messages' on the main menu.
<form
action="index2.php" method="post" name="adminForm">
<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="25%">Message</th>
<th>Date</th>
<th width="25%">Published</th>
</tr>
This table header
labels all of the columns and provides a master checkbox that will check every
message on the form when clicked.
<?php
$k
= 0;
for($i=0;
$i < count( $rows ); $i++) {
$row
= $rows[$i];
?>
This starts a loop
that cycles through each of the database rows in the $rows array.
<tr class="<?php echo "row$k"; ?>">
Pulls the style
for the row from CSS based on whether this is row 0 or row 1. We start with row
0 and change it to row 1, back and forth, to create an alternating effect making
the table easier to read.
<td><input type="checkbox" id="cb<?php echo $i;?>" name="cid[]"
value="<?php echo $row->id; ?>" onclick="isChecked(this.checked);"
/></td>
Displays a
checkbox and provides a way of identifying it later when the form is submitted.
Each checkbox id is stored as cbX, where X is the numerical position in the list
the checkbox resides at. The name is specified as an array and the value is set
to the id for the row found in the database.
<td><a href="#edit" onclick="return listItemTask('cb<?php echo
$i;?>','edit')"><?php echo $row->message;
?></a></td>
Creates links
containing the text of the message. When clicked, the link will automatically
check the box at the beginning of the row and tell the Javascript to submit the
form with the task of 'edit.'
<td><?
echo mosFormatDate($row->date); ?></td>
Outputs the date
of the message, displayed according to the local format through the
mosFormatDate() function which is declared in classes/mambo.php.
<td align="center">
<?php
if
($row->published == "1") {
echo
"<a href="javascript: void(0);" onClick="return
listItemTask('cb$i','unpublish')"><img src="images/publish_g.png"
border="0" /></a>";
}
else {
echo
"<a href="javascript: void(0);" onClick="return
listItemTask('cb$i','publish')"><img src="images/publish_x.png" border="0"
/></a>";
}
?>
</td>
This displays
either the 'published' or 'unpublished' icon, depending on the status of the
message. If the icon is clicked, the form is submitted with the opposite status
as the task.
<?php $k = 1 - $k; ?>
Changes the
variable that determines the background color of the row. Ones become zeros and
zeros become one.
</tr>
<?php
}
?>
</table>
<input
type="hidden" name="option" value="<?php echo $option; ?>" />
<input
type="hidden" name="task" value="" />
<input
type="hidden" name="boxchecked" value="0" />
</form>
<?
}
}
Hides the
variables option, task, and boxchecked at the end of the form. Both 'boxchecked'
and 'task' are later modified by Javascript. Boxchecked is used to make sure
that items are checked before a task is executed.
?>
|