<?php
//zOOm Gallery//
/** 
-----------------------------------------------------------------------
|  zOOm Media Gallery! by Mike de Boer - a multi-gallery component    |
-----------------------------------------------------------------------

-----------------------------------------------------------------------
|                                                                     |
| Date: October, 2004                                                 |
| Author: Mike de Boer, <http://www.mikedeboer.nl>                    |
| Copyright: copyright (C) 2004 by Mike de Boer                       |
| Description: zOOm Image Gallery, a multi-gallery component for      |
|              Mambo based on RSGallery by Ronald Smit. It's the most |
|              feature-rich gallery component for Mambo!              |
| Filename: catsmgr.php                                               |
| Version: 2.1.4                                                      |
|                                                                     |
-----------------------------------------------------------------------
**/
// MOS Intruder Alerts
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
if(array_key_exists('task', $_REQUEST))
	$task = $_REQUEST['task'];
if($task == 'edit'){
    if(array_key_exists('catid', $_REQUEST)){
        $catid = $_REQUEST['catid'];
        if(is_array($catid))
          $catid = $catid[0];
        $zoom->setGallery($catid);
        include($mosConfig_absolute_path.'/components/com_zoom/admin/editcat.php');
    }else{
		//Back to new gallery page
		?>
		<script language="javascript" type="text/javascript">
			<!--
			alert("<?php echo html_entity_decode(_ZOOM_ALERT_NOCAT);?>");
			location = "index<?php echo ($zoom->_isBackend) ? "2" : "";?>.php?option=com_zoom&Itemid=<?php echo $Itemid;?>&page=catsmgr";
			//-->
		</SCRIPT>
		<?
	}
}elseif($task == 'move'){
	// not implemented yet...
}elseif($task == 'delete'){
	if(array_key_exists('catid', $_REQUEST)){
		$catid = $_REQUEST['catid'];
		foreach($catid as $cid){
			//Fetch directoryname
			$database->setQuery("SELECT catname, catdir FROM #__zoom WHERE catid=".$cid);
			$result = $database->query();
			$row = mysql_fetch_object($result);
			$dir = $row->catdir;
			$gallery = $row->catname;
			$dir = $mosConfig_absolute_path."/".$zoom->_CONFIG['imagepath'].$dir;
			if(fs_is_dir($dir)){
				//Delete comments from database
				$database->setQuery("SELECT * FROM #__zoomfiles WHERE catid=".$cid);
				$result1 = $database->query();
				while ($row1 = mysql_fetch_object($result1)){
					$database->setQuery("DELETE FROM #__zoom_comments WHERE imgid=".$row1->imgid);
					$database->query();
				}
				//Delete files from database
				$database->setQuery("DELETE FROM #__zoomfiles WHERE catid=".$cid);
				$database->query();
				//Finally, delete category from database
				$database->setQuery("DELETE FROM #__zoom WHERE catid=".$cid);
				$database->query();
				//Empty and delete directory
				$zoom->deldir($dir);
			}
		}
		?>
		<script language="javascript" type="text/javascript">
			<!--
			alert("<?echo html_entity_decode(_ZOOM_ALERT_DEL);?>");
			location = "index<?php echo ($zoom->_isBackend) ? "2" : "";?>.php?option=com_zoom&Itemid=<?php echo $Itemid;?>&page=catsmgr";
			//-->
		</SCRIPT>
		<?php
	}else{
		?>
		<script language="javascript" type="text/javascript">
			<!--
			alert("<?echo html_entity_decode(_ZOOM_ALERT_NOCAT);?>");
			location = "index<?php echo ($zoom->_isBackend) ? "2" : "";?>.php?option=com_zoom&Itemid=<?php echo $Itemid;?>&page=catsmgr";
		</SCRIPT>
		<?php
	}
}else{
	// show list of categories...
	$zoom->createCheckAllScript();
	?>
	<script language="Javasript" type="text/javascript">
      <!--
      function submitForm(theTask){
        document.catsmgr.elements['task'].value = theTask;
        document.catsmgr.submit();
        return false;
      }
      //-->
    </script>
	<table border="0" cellspacing="0" cellpadding="0" width="100%">
	<tr>
		<td align="center" width="100%"><a href="index<?php echo ($zoom->_isBackend) ? "2" : "";?>.php?option=com_zoom&page=admin&Itemid=<?php echo $Itemid ?>">
		<img src="<?php echo $mosConfig_live_site;?>/components/com_zoom/images/home.gif" alt="<?echo _ZOOM_MAINSCREEN;?>" border="0">&nbsp;&nbsp;<?echo _ZOOM_MAINSCREEN;?></a>&nbsp; | &nbsp;
		</td>
	</tr>
	<tr>
		<td align="left"><img src="<?php echo $mosConfig_live_site;?>/components/com_zoom/images/admin/catsmgr_f2.png" border="0" alt="<?php echo _ZOOM_CATSMGR;?>">&nbsp;<b><font size="4"><?php echo _ZOOM_CATSMGR;?></font></b></td>
	</tr>
	</table>
	<br />
	<center>
	<table width="80%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td align="right">
			<div align="right">
			<?php if($zoom->_isAdmin || $zoom->_CONFIG['allowUserCreate']){ ?>
			  <a href="index<?php echo ($zoom->_isBackend) ? "2" : "";?>.php?option=com_zoom&Itemid=<?php echo $Itemid ?>&page=new" onmouseover="return overlib('<?php echo _ZOOM_NEW;?>');" onmouseout="return nd();"><img src="<?php echo $mosConfig_live_site;?>/components/com_zoom/images/admin/new.png" border="0" onmouseover="MM_swapImage('new','','<?php echo $mosConfig_live_site;?>/components/com_zoom/images/admin/new_f2.png',1);" onmouseout="MM_swapImgRestore();" name="new"></a>
			<?php } ?>
			<?php if($zoom->_isAdmin || $zoom->_CONFIG['allowUserEdit']){ ?>
              <a href="javascript:submitForm('edit');" onmouseover="return overlib('<?php  echo _ZOOM_EDIT;?>');" onmouseout="return nd();"><img src="<?php echo $mosConfig_live_site;?>/components/com_zoom/images/admin/edit.png" border="0" onmouseover="MM_swapImage('edit','','<?php echo $mosConfig_live_site;?>/components/com_zoom/images/admin/edit_f2.png',1);" onmouseout="MM_swapImgRestore();" name="edit"></a>
            <?php } if($zoom->_isAdmin || $zoom->_CONFIG['allowUserDel']){ ?>
              <a href="javascript:submitForm('delete');" onmouseover="return overlib('<?php echo _ZOOM_DEL;?>');" onmouseout="return nd();" onClick="return confirm('<?php echo _ZOOM_CONFIRM_DEL;?>');"><img src="<?php echo $mosConfig_live_site;?>/components/com_zoom/images/admin/delete.png" border="0" onmouseover="MM_swapImage('delete','','<?php echo $mosConfig_live_site;?>/components/com_zoom/images/admin/delete_f2.png',1);" onmouseout="MM_swapImgRestore();" name="delete"></a>
            <?php } ?>
            </div>
		</td>
	</tr>
	</table>
	<form  name="catsmgr" action="index<?php echo ($zoom->_isBackend) ? "2" : "";?>.php?option=com_zoom&Itemid=<?php echo $Itemid;?>&page=catsmgr" method="POST">
    <input type="hidden" name="task" value="" />
	<table width="80% border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td  height="20" width="50" class="sectiontableheader"><?echo _ZOOM_HD_CHECK;?></td>
		<td class="sectiontableheader"><?echo _ZOOM_HD_NAME;?></td>
	</tr>
	<?php echo $zoom->createCatDeleteForm(); ?>
	<tr>
		<td height="20" class="sectiontableheader"><input type="checkbox" name="checkall" onclick="checkUncheckAll(this, 'catid[]');"></td>
		<td height="20" class="sectiontableheader"><strong><?php echo _ZOOM_HD_CHECKALL;?></strong></td>
	</tr>
	</table>
	</form>
	</center>
	<?php
}
?>
