<?php
// $Id: HTML_content.php,v 1.67 2004/02/21 18:53:50 rcastley Exp $
/**
* Content 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.67 $
**/

define( 'MASK_HIDE_TITLE', 0x0001 );
define( 'MASK_HIDE_INTRO', 0x0002 );

class HTML_content {
	/**
	* Writes a list of the content items
	* @param array An array of content objects
	*/
	function showContent( &$rows, $section, &$lists, $search, $pageNav, $option ) {
		global $my;
?>
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
<script language="Javascript" src="../includes/js/overlib_mini.js"></script>
<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->title; ?></span></td>
      <td 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 $lists['catid'];?> </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%">Title</th>
      <th width="10%" align="left">Category</th>
      <th width="10%">Published</th>
      <th width="10%">Checked Out</th>
      <th width="10%">Access</th>
      <th width="10%" nowrap="nowrap">Front Page</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> <a href="#edit" onClick="return listItemTask('cb<?php echo $i;?>','edit')">
        <?php echo $row->title; ?> </a> </td>
      <td><?php echo $row->name; ?></td>
     <?php
			$now = date( "Y-m-d h:i:s" );
			if ($now <= $row->publish_up && $row->state == "1") {
				$img = 'publish_y.png';
			} else if (($now <= $row->publish_down || $row->publish_down == "0000-00-00 00:00:00") && $row->state == "1") {
				$img = 'publish_g.png';
			} else if ($now > $row->publish_down && $row->state == "1") {
				$img = 'publish_r.png';
			} elseif ($row->state == "0") {
				$img = "publish_x.png";
			}
			$times = '';
			if (isset($row->publish_up)) {
				if ($row->publish_up == '0000-00-00 00:00:00') {
					$times .= "<tr><td>Start: Always</td></tr>";
				} else {
					$times .= "<tr><td>Start: $row->publish_up</td></tr>";
				}
			}
			if (isset($row->publish_down)) {
				if ($row->publish_down == '0000-00-00 00:00:00') {
					$times .= "<tr><td>Finish: No Expiry</td></tr>";
				} else {
					$times .= "<tr><td>Finish: $row->publish_down</td></tr>";
				}
			}
			if ($times) {
?>
        <td align="center"><a href="javascript: void(0);" onMouseOver="return overlib('<table border=0 width=100% height=100%><?php echo $times; ?></table>', CAPTION, 'Publish Information', BELOW, RIGHT);" onMouseOut="return nd();" onClick="return listItemTask('cb<?php echo $i;?>','<?php echo $row->state ? "unpublish" : "publish";?>')"><img src="images/<?php echo $img;?>" width="12" height="12" border="0" alt="" /></a>
        <?php
			}
	  ?>
      </td>
      <?php
			if ($row->checked_out) { ?>
      <td align="center"><?php echo $row->editor; ?></td>
      <?php		} else { ?>
      <td align="center">&nbsp;</td>
      <?php		} ?>
      <td align="center"><?php echo $row->groupname;?></td>
      <td align="center"><a href="javascript: void(0);" onClick="return listItemTask('cb<?php echo $i;?>','toggle_frontpage')"><img src="images/<?php echo ($row->frontpage) ? 'tick.png' : 'publish_x.png';?>" width="12" height="12" border="0" alt="" /></td>
      <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>
    </tr>
    <?php		$k = 1 - $k; } ?>
    <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="sectionid" value="<?php echo $section->id;?>" />
  <input type="hidden" name="task" value="" />
  <input type="hidden" name="boxchecked" value="0" />
</form>
<br />
<table cellspacing="0" cellpadding="4" border="0" align="center">
  <tr align="center">
    <td> <img src="images/publish_y.png" width="12" height="12" border=0 alt="Pending" />
    </td>
    <td> Published, but is <u>Pending</u> |</td>
    <td> <img src="images/publish_g.png" width="12" height="12" border=0 alt="Visible" />
    </td>
    <td> Published and is <u>Current</u> |</td>
    <td> <img src="images/publish_r.png" width="12" height="12" border=0 alt="Finished" />
    </td>
    <td> Published, but has <u>Expired</u> |</td>
    <td> <img src="images/publish_x.png" width="12" height="12" border=0 alt="Finished" />
    </td>
    <td> Not Published </td>
  </tr>
  <tr>
	<td colspan="8" align="center">Click on icon to toggle state.</td>
  </tr>
</table>
<?php
	}

	/**
	* Writes a list of the content items
	* @param array An array of content objects
	*/
	function showArchive( &$rows, $section, &$lists, $search, $pageNav, $option ) {
		global $my;
?>
<form action="index2.php" method="post" name="adminForm">
  <table cellpadding="4" cellspacing="0" border="0" width="100%">
    <tr>
      <td width="100%"><span class="sectionname"><?php echo $section->title; ?></span></td>
      <td 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 $lists['catid'];?> </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="50%">Title</th>
      <th width="15%" align="left">Category</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"> <input type="checkbox" id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $row->id; ?>" onClick="isChecked(this.checked);" />
      </td>
      <td width="85%"> <?php echo $row->title; ?> </td>
      <td width="15%"><?php echo $row->name; ?></td>
    </tr>
    <?php		$k = 1 - $k; } ?>
    <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="sectionid" value="<?php echo $section->id;?>" />
  <input type="hidden" name="task" value="showarchive" />
  <input type="hidden" name="boxchecked" value="0" />
</form>
<?php
	}


	/**
	* Writes the edit form for new and existing content item
	*
	* A new record is defined when <var>$row</var> is passed witht the <var>id</var>
	* property set to 0.
	* @param mosContent The category object
	* @param string The html for the groups select list
	*/
	function editContent( &$row, $section, &$lists, &$images,
		$myid, $mosConfig_editor, $option ) {

		if ($section!='') {
			$section = "in ".$section." section";
		} else {
			$section = "";
		}

		mosMakeHtmlSafe( $row );

		$mod_date = null;
		$create_date = null;
		if (intval( $row->modified ) <> 0) {
			$mod_date = mosFormatDate( $row->modified );
		}
		if (intval( $row->created ) <> 0) {
			$create_date = mosFormatDate( $row->created );
		}
?>
<link rel="stylesheet" type="text/css" media="all" href="../includes/js/calendar/calendar-mos.css" title="green" />
<!-- import the calendar script -->
<script type="text/javascript" src="../includes/js/calendar/calendar.js"></script>
<!-- import the language module -->
<script type="text/javascript" src="../includes/js/calendar/lang/calendar-en.js"></script>
<script language="javascript" src="js/dhtml.js"></script>
<table cellpadding="4" cellspacing="0" border="0" width="100%">
  <tr>
    <td class="sectionname"><?php echo $row->id ? 'Editing' : 'Adding';?> content
      <?php echo $section;?></td>
  </tr>
</table>
<table cellspacing="0" cellpadding="4" border="0" width="100%">
  <tr>
    <td width="" class="tabpadding">&nbsp;</td>
    <td id="tab1" class="offtab" onClick="dhtml.cycleTab(this.id)">Content</td>
    <td id="tab2" class="offtab" onClick="dhtml.cycleTab(this.id)">Images</td>
    <td id="tab3" class="offtab" onClick="dhtml.cycleTab(this.id)">Publishing</td>
    <td id="tab4" class="offtab" onClick="dhtml.cycleTab(this.id)">Metadata</td>
    <td width="90%" class="tabpadding">&nbsp;</td>
  </tr>
</table>
<script language="javascript" type="text/javascript">
	var folderimages = new Array;
<?php	$i = 0;
foreach ($images as $k=>$items) {
	foreach ($items as $v) {
		echo "\n	folderimages[".$i++."] = new Array( '$k','$v->value','$v->text' );";
	}
}
?>

	function submitbutton(pressbutton) {
		var form = document.adminForm;
		if (pressbutton == 'cancel') {
			submitform( pressbutton );
			return;
		}
		// assemble the images back into one field
		var temp = new Array;
		for (var i=0, n=form.imagelist.options.length; i < n; i++) {
			temp[i] = form.imagelist.options[i].value;
		}
		form.images.value = temp.join( '\n' );

		// do field validation
		if (form.title.value == ""){
			alert( "Content item must have a title" );
		} else if (form.catid.value == "0"){
			alert( "You must select a category." );
		} else {
			<?php getEditorContents( 'editor1', 'introtext' ) ; ?>
			<?php getEditorContents( 'editor2', 'fulltext' ) ; ?>
			submitform( pressbutton );
		}
	}
</script>

<form action="index2.php" method="POST" name="adminForm">
  <input type="hidden" name="images" value="" />
  <div id="page1" class="pagetext">
    <table cellpadding="5" cellspacing="0" border="0" width="100%" class="adminform">
        <tr>
          <td align="right">Title:</td>
          <td><input class="inputbox" type="text" name="title" size="50" maxlength="100" value="<?php echo $row->title; ?>" /></td>
          <td width="30%" rowspan="6" align="middle" valign="top">
		    <table cellpadding="3" cellspacing="0" border="0" width="180" class="adminform">
              <tr>
                <th colspan="2">Item Status</th>
              </tr>
              <tr>
                <td width="34%"><strong>State</strong></td>
                <td width="50%"><?php echo $row->state > 0 ? 'Published' : ($row->state < 0 ? 'Archived' : 'Draft Unpublished');?></td>
              </tr>
              <tr>
                <td><strong>Hits</strong></td>
                <td><?php echo "$row->hits";?></td>
              </tr>
              <tr>
                <th colspan="2">Options</th>
              </tr>
              <tr>
                <td><strong>Show on Frontpage?</strong></td>
                <td>
                  <input type="checkbox" name="frontpage" value="1" <?php echo $row->frontpage ? 'checked="checked"' : ''; ?> />
                </td>
              </tr>
              <tr>
                <td><strong>Hide Title?</strong></td>
                <td>
                  <input type="checkbox" name="mask_hide_title" value="<?php echo MASK_HIDE_TITLE;?>" <?php echo $row->mask&MASK_HIDE_TITLE ? 'checked="checked"' : ''; ?> />
                </td>
              </tr>
              <tr>
                <th colspan="2">Item Info</th>
              </tr>
              <tr>
                <td><strong>Version</strong></td>
                <td><?php echo "$row->version";?></td>
              </tr>
              <tr>
                <td><strong>Created</strong></td>
                <td> <?php echo $row->created ? "$create_date</td></tr><tr><td><strong>By</strong></td><td>$row->creator" : "New document";?></td>
              </tr>
              <tr>
                <td><strong>Last Modified</strong></td>
                <td><?php echo $row->modified ? "$mod_date</td></tr><tr><td><strong>By</strong></td><td>$row->modifier" : "Not modified";?></td>
              </tr>
			  <?php if (file_exists("../components/com_vb/vb.php")) { ?>
			  <tr>
                <td><strong>Create Thread</strong></td>
                <td><input type="checkbox" name="createforum" value="1"></td>
              </tr>
			  <?php }?>
            </table>
		  </td>
        </tr>
      <tr>
        <td width="10%" align="right">Title Alias: </td>
        <td width="60%"><input name="title_alias" type="text" class="inputbox" id="title_alias" value="<?php echo $row->title_alias; ?>" size="50" maxlength="100" />
          </td>
      </tr>
      <tr>
        <td valign="top" align="right">Category:</td>
        <td> <?php echo $lists['catid']; ?> </td>
      </tr>
      <tr>
        <td valign="top" align="right"> Intro Text:<br />
          (required) </td>
        <td valign="top">
				<?php 
			// parameters : areaname, content, hidden field, width, height, rows, cols
			editorArea( 'editor1',  $row->introtext , 'introtext', 500, 200, '70', '15' ) ; ?>
        </td>
      </tr>
      <tr>
        <td valign="top" align="right"> Main Text:<br />
          (optional) </td>
        <td> 
				<?php 
			// parameters : areaname, content, hidden field, width, height, rows, cols
			editorArea( 'editor2',  $row->fulltext , 'fulltext', 500, 150, '70', '15' ) ; ?>
        </td>
      </tr>
    </table>
  </div>
  <div id="page2" class="pagetext">
    <table cellpadding="5" cellspacing="0" border="0" width="100%" class="adminform">
	<tr>
		<td colspan="6">Sub-folder :: <?php echo $lists['folders'];?></td>
	</tr>
      <tr>
        <td> Gallery Images <br /> <?php echo $lists['imagefiles'];?> <br /> <input class="button" type="button" value="Insert &gt;" onClick="addSelectedToList('adminForm','imagefiles','imagelist')" />
        </td>
        <td> Content Images: <br /> <?php echo $lists['imagelist'];?> <br /> <input class="button" type="button" value="up" onClick="moveInList('adminForm','imagelist',adminForm.imagelist.selectedIndex,-1)" />
          <input class="button" type="button" value="down" onClick="moveInList('adminForm','imagelist',adminForm.imagelist.selectedIndex,+1)" />
          <input class="button" type="button" value="remove" onClick="delSelectedFromList('adminForm','imagelist')" />
        </td>
        <td> Edit the image selected:
          <table>
            <tr>
              <td align="right">Source</td>
              <td> <input type="text" name= "_source" value="" /> </td>
            </tr>
            <tr>
              <td align="right">Align</td>
              <td> <?php echo $lists['_align']; ?> </td>
            </tr>
            <tr>
              <td align="right">Alt Text</td>
              <td> <input type="text" name="_alt" value="" /> </td>
            </tr>
            <tr>
              <td align="right">Border</td>
              <td> <input type="text" name="_border" value="" size="3" maxlength="1" />
              </td>
            </tr>
            <tr>
              <td align="right"></td>
              <td> <input class="button" type="button" value="Apply" onClick="applyImageProps()" />
              </td>
            </tr>
          </table></td>
      </tr>
      <tr>
        <td> <img name="view_imagefiles" src="../images/M_images/blank.png" width="100">
        </td>
        <td> <img name="view_imagelist" src="../images/M_images/blank.png" width="100">
        </td>
      </tr>
    </table>
  </div>
  <div id="page3" class="pagetext">
    <table cellpadding="5" cellspacing="0" border="0" width="100%" class="adminform">
      <tr>
        <td valign="top" align="right">Access Level:</td>
        <td> <?php echo $lists['access']; ?> </td>
      </tr>
      <tr>
        <td align="right">Author Alias:</td>
        <td> <input type="text" name="created_by_alias" size="50" maxlength="100" value="<?php echo $row->created_by_alias; ?>" class="inputbox" />
        </td>
      </tr>
         <tr>
        <td valign="top" align="right">Change Creator:</td>
        <td> <?php echo $lists['created_by']; ?> </td>
      </tr>
      <tr>
        <td valign="top" align="right">Ordering:</td>
        <td> <?php echo $lists['ordering']; ?> </td>
      </tr>
	        <tr>
        <td valign="top" align="right">Override Created Date </td>
        <td><input class="inputbox" type="text" name="created" id="created" size="25" maxlength="19" value="<?php echo $row->created; ?>" />
          <input name="reset" type="reset" class="button" onClick="return showCalendar('created', 'y-mm-dd');" value="..."></td>
      </tr>
      <tr>
        <td width="20%" align="right">Start Publishing:</td>
        <td width="80%"> <input class="inputbox" type="text" name="publish_up" id="publish_up" size="25" maxlength="19" value="<?php echo $row->publish_up; ?>" />
          <input type="reset" class="button" value="..." onClick="return showCalendar('publish_up', 'y-mm-dd');">
        </td>
      </tr>
      <tr>
        <td width="20%" align="right">Finish Publishing:</td>
        <td width="80%"> <input class="inputbox" type="text" name="publish_down" id="publish_down" size="25" maxlength="19" value="<?php echo $row->publish_down; ?>" />
          <input type="reset" class="button" value="..." onClick="return showCalendar('publish_down', 'y-mm-dd');">
        </td>
      </tr>
    </table>
  </div>
  <div id="page4" class="pagetext">
    <table cellpadding="5" cellspacing="0" border="0" width="100%" class="adminform">
      <tr>
        <td width="20%" valign="top" align="right">Description:</td>
        <td width="80%"> <textarea class="inputbox" cols="70" rows="4" name="metadesc" style="width:500px" width="500"><?php echo str_replace('&','&amp;',$row->metadesc); ?></textarea></td>
      </tr>
      <tr>
        <td valign="top" align="right">Keywords:</td>
        <td > <textarea class="inputbox" cols="70" rows="4" name="metakey" style="width:500px" width="500"><?php echo str_replace('&','&amp;',$row->metakey); ?></textarea></td>
      </tr>
      <tr>
        <td align="right">&nbsp;</td>
        <td> <input type="button" class="button" value="Add Sect/Cat/Title" onClick="f=document.adminForm;f.metakey.value='<?php echo $section;?>, '+getSelectedText('adminForm','catid')+', '+f.title.value+', '+f.metakey.value;" />
        </td>
      </tr>
    </table>
  </div>
  <input type="hidden" name="id" value="<?php echo $row->id; ?>" />
  <input type="hidden" name="version" value="<?php echo $row->version; ?>" />
  <input type="hidden" name="sectionid" value="<?php echo $row->sectionid; ?>" />
  <input type="hidden" name="mask" value="0" />
  <input type="hidden" name="option" value="<?php echo $option;?>" />
  <input type="hidden" name="task" value="" />
</form>
<script language="javascript" type="text/javascript">
		dhtml.cycleTab('tab1');
		</script>
<?php
	}

	/**
	* Form to select Section/Category to move item(s) to
	* @param array An array of selected objects
	* @param int The current section we are looking at
	* @param array The list of sections and categories to move to
	*/
	function moveSection( &$cid, &$sectCatList, $option, $sectionid  ) {
?>
<script language="javascript" type="text/javascript">
	function submitbutton(pressbutton) {
		var form = document.adminForm;
		if (pressbutton == 'cancel') {
			submitform( pressbutton );
			return;
		}

		// do field validation
		if (!getSelectedValue( 'adminForm', 'sectcat' )) {
			alert( "Please select something" );
		} else {
			submitform( pressbutton );
		}
	}
</script>

<form action="index2.php" method="post" name="adminForm">
<table cellpadding="4" cellspacing="0" border="0" width="100%">
	<tr>
		<td width="100%"><span class="sectionname">Move Content Items to New Section</span></td>
	</tr>
</table>

<table cellpadding="5" cellspacing="0" border="0" width="100%" class="adminform">
	<tr>
		<td width="20%" align="right">Number of Items:</td>
		<td><?php echo count( $cid );?></td>
	</tr>
	<tr>
		<td align="right" valign="top">New Section/Category:</td>
		<td><?php echo $sectCatList;?></td>
	</tr>
</table>

<input type="hidden" name="option" value="<?php echo $option;?>" />
<input type="hidden" name="sectionid" value="<?php echo $sectionid; ?>" />
<input type="hidden" name="task" value="" />
<?php
		foreach ($cid as $id) {
			echo "\n<input type=\"hidden\" name=\"cid[]\" value=\"$id\" />";
		}
?>
</form>

<?php
	}
}
?>
