<?php 
defined( '_JEXEC' ) or die( 'Restricted access' ); 
//error_reporting(E_ALL);
class jcText extends JText
{
    function _($text)
    {
        return parent::_($text);
    }
}
$GLOBALS['database'] =& JFactory::getDBO();
global $database ,$mainframe;

$document =& JFactory::getDocument();
$document->addStyleSheet(JURI::root().'/administrator/components/com_jxplorer/css/jxplorer.css');

require_once( JApplicationHelper::getPath( 'admin_html' ) );
require_once( JApplicationHelper::getPath( 'admin_functions' ) );
require_once( JPATH_COMPONENT.DS.'joomlaequipment.config.php' );
require_once( JPATH_COMPONENT.DS.'jxplorer.helpers.php' );
require_once( JPATH_COMPONENT.DS.'admin.jxplorer.xajax.php' );

if(JEConfig::get('general.homedir') === '' || !jxTestInitDir())
{
    $path = str_replace("\\", '/', JPATH_ROOT.DS);
    $database -> setQuery("UPDATE #__je_config SET `selected` = '{$path}' WHERE `name` = 'homedir' AND `section` = 'general'");
    $database -> query();
}
jimport( 'joomla.filesystem.folder' );


$task        = JRequest::getVar( 'task', '' );
$client 	   = JRequest::getVar( 'client', 'site' );
$subdir      = JRequest::getVar( 'subdir', $SUBDIR );
$directory   = JRequest::getVar( 'directory', jxInitialDirectory() );
$destination = intval(JRequest::getVar( 'destination', 0));
$cid = JRequest::getVar( 'cid', array(0), '', 'array' );
$_special    = JRequest::getVar( '_special', '' );
$search      = JRequest::getVar( 'search', '' );
if( !is_array( $cid ) ) {$cid = array(0);}


switch ($task)
{
    case "saveconfig":
        JEConfig::save();
        $task = "manage";
        break;
    case "applyconfig":
        JEConfig::save();
        jxMsg('Configuration Saved Successfully.');
        $task = "config";
    break;
}

if(!jxTestThumbPath())
{
    JError::raise(E_WARNING, '0156', JText::_('The Tumbnails directory either not exists or not writable.'));
    $task = 'config';
    JRequest::setVar('task', $task);
}
if(!jxTestUploadDir())
{
    JError::raise(E_WARNING, '0156', JText::_('The Upload directory either not exists or not writable.'));
    $task = 'config';
    JRequest::setVar('task', $task);
}
// if home directory is not correct go to Config page
if(!jxTestInitDir()) 
{
    JError::raise(E_WARNING, '0181', JText::_('The Initial Directory Either not correct or is not set or not readable.'));
    $task = 'config';
    JRequest::setVar('task', $task);
}
// If Charset is not set go to Config page
if(!jxTestCharSet()) 
{
    JError::raise(E_WARNING, '0187', JText::_('Charset is not set.'));
    $task = 'config';
    JRequest::setVar('task', $task);
}

if(jxTotalRecords() === 0 && $task != 'reindex') JError::raise(E_NOTICE, '0191', JText::_('If you do not see any files, may be you are to do Reindex.'));

if($task != 'config')
{
   progressPanel();
   $document->addScript(JURI::root().'/administrator/components/com_jxplorer/js/jxplorer.js');
}    
print '<form action="index2.php" method="post" name="adminForm" enctype="multipart/form-data">';

switch ($task)
{
    case "savefile":
      jxSaveFile($cid, $directory);
      jxActionPanel($directory);
      jxListDirectory($directory, $client, $task);
      break;
    case "applyfile":
      jxSaveFile($cid, $directory);
    case "editfile":
      jxEditForm($cid[0], $directory);
      break;
          
    case "download":
      @ob_end_clean();
      jxDownload($cid, $directory);
      ob_start(false); 
      jxActionPanel($directory);
      jxListDirectory($directory, $client, $task);
      break;

    case "uploadfiles":
      jxUploadFiles();
    case "upload":
      jxUploadForm();
      break;
    
    // configuration management
    case "config":
      JEConfig::display();
      break;

    case "chmod":
      jxChmod($cid, $subdir);
      jxActionPanel($directory);
      jxListDirectory($directory, $client, $task);
      break;

    case "restore":
      jxRestore($cid);
      $task = 'recycle';
      jxListDirectory($directory, $client, $task);
      break;

    case "delete":
      jxDelete($cid);
      $task = 'recycle';
      jxMsg('Delete Successful.');
      jxIndex($directory, false);
      jxListDirectory($directory, $client, $task);
      break;
  
    case "forever":
      jxEmptyRecycle();
      $task = 'recycle';
      jxListDirectory($directory, $client, $task);
      break;

    case "recycle":
      jxListDirectory($directory, $client, $task);
      break;

    case "archivezip":
    case "archivetar":
      jxArchive($cid, $directory, $_special, $task);
      jxActionPanel($directory);
      jxListDirectory($directory, $client, $task);
      break;

    case "trash":
      jxTrash($cid);
      jxActionPanel($directory);
      jxListDirectory($directory, $client, $task);
      break;

    case "extract":
      jxExtractArchive($cid[0], $destination);
      break;

    case "copymove":
      jxDestinationForm($cid);
      break;

    case "copy":
    case "move":
      $cid = unserialize(base64_decode(JRequest::getVar( 'cid2' )));
      jxCopyMove($cid, $destination, $task, $directory);
      jxActionPanel($directory);
      jxListDirectory($directory, $client, $task);
      break;

    case "reindex":
      jxIndex();
      $mainframe->redirect('index2.php?option=com_jxplorer&task=manage', JText::_('Reindex Done Successfully.'));
      break;

    case "refresh":
      jxIndex($directory, false);
      jxMsg('Succesfull',$task);
      jxActionPanel($directory);
      jxListDirectory($directory, $client, $task);
      break;
    
    case "up":
      $directory = jxDirectoryUp($directory);
      jxActionPanel($directory);
      jxListDirectory($directory, $client, $task);
      break;
    
    case "rename":
  
      jxRename($cid[0], $_special, $directory);  
      jxActionPanel($directory);
      jxListDirectory($directory, $client, $task);
      break;
 
    case "remove":
      jxDelete($cid, $directory);
      jxActionPanel($directory);
      jxListDirectory($directory, $client, $task);
      break;

    case "newfolder":
    case "newfile":
      jxNewFileFolder($_special, $directory, $task);
      jxActionPanel($directory);
      jxListDirectory($directory, $client, $task);
      break;
      
      
  	case 'accesspublic':
  	case 'accessregistered':
  	case 'accessspecial':
  		jxAccess( $cid, $task, $subdir);
      jxActionPanel($directory);
      jxListDirectory($directory, $client, $task);
      break;
      
  	case 'goto':
       $directory = $destination;
       jxActionPanel($directory);
       jxListDirectory($directory, $client, $task);
       break;
    case "manage":
    default:
      jxActionPanel($directory);
      jxListDirectory($directory, $client, $task, $search);

}

?>

<input type="hidden" name="option" value="com_jxplorer" />
<input type="hidden" name="directory" id="directory" value="<?php echo $directory; ?>" />
<input type="hidden" name="task" value="<?php echo $task ?>" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="client" value="<?php echo $client;?>" />
<input type="hidden" name="hidemainmenu" value="0" />

</form>
<div class="clr"></div>
<center><a href="http://joomlaequipment.com" target="_blank">
&copy; 2006 "JXplorer" by JoomlaEquipment</a> <a href="mailto:serg4172@mail.ru">Sergey Romanov</a></center>
</div></div>
<div id="border-bottom"><div><div></div></div></div>
<?php 
function jxActionPanel($directory)
{
	Global $search;
	?>
	 <div id="tablecell">	
	
	<table class="text_area" width="100%">
	<TR>
	 <TD colspan="3" align="left">
	  <?php echo JText::_('Address:').jxAddressLine($directory);?>
	 </TD>
	</TR>
	</table>
	<br>
	<table class="adminform" border="0">
	  <TR valign="top">
	    <TD nowrap="nowrap">
	      <?php  echo JText::_('Search'); ?>:&nbsp;
	      <input type="text" value="<?php echo JRequest::getVar( 'search' ) ?>" name="search" size="10" class="text_area">&nbsp;
	      <input type="button" class="button" value="<?php echo JText::_('Go'); ?>" onclick="javascript:submitbutton('search')">
	    </TD>
	
	  <TD>
	      <INPUT type="Checkbox" name="subdir" id="sd" <?php echo $subdir ? " checked='checked'" : ""?>>
	      <?php  echo JText::_('Access/Publish Including Subdirectories');  ?>
	    </TD>
	
	
	    <TD align="right" nowrap="nowrap">
	      <div style="float:right">
	      <input type="text" name="_special" class="text_area">&nbsp;
	      <input type="button" class="button" value="<?php echo JText::_('New File'); ?>" 
	             onclick="javascript:submitbutton('newfile')">
	      <input type="button" class="button" value="<?php echo JText::_('New Folder'); ?>"
	             onclick="javascript:submitbutton('newfolder')">
	      <input type="button" class="button" value="<?php echo JText::_('Rename'); ?>"
	             onclick="javascript:if(document.adminForm.boxchecked.value==0){alert('<?php echo JText::_('Please make a selection from the list to Rename'); ?>');}else{if(document.adminForm._special.value==''){alert('<?php echo JText::_('Please, enter new name')?>'); document.adminForm._special.style.borderColor='#ff0033';}else{submitbutton('rename');}}">
	      <input type="button" class="button" value="<?php echo JText::_('Tar'); ?>"
	             onclick="javascript:if(document.adminForm.boxchecked.value==0){alert('<?php echo JText::_('Please make a selection from the list to Tar archive'); ?>');}else{submitbutton('archivetar')}">
	      <input type="button" class="button" value="<?php echo JText::_('Zip'); ?>" 
	             onclick="javascript:if(document.adminForm.boxchecked.value==0){alert('<?php echo JText::_('Please make a selection from the list to Zip Archive'); ?>');}else{submitbutton('archivezip')}">
	      </div>
	    </TD>
	
	  </TR>
	</table>

<? } ?>