<?php

/**
 * @version         1.9.7
 * @package        Joomla
 * @subpackage     EDocman
 * @author         Tuan Pham Ngoc
 * @copyright      Copyright (C) 2011 - 2024 Ossolution Team
 * @license        GNU/GPL, see LICENSE.php
 */

// No direct access.
defined('_JEXEC') or die; 
use Joomla\CMS\Language\Text;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Toolbar\ToolbarHelper;

ToolbarHelper::title(   Text::_( 'EDOCMAN_MOVING_ADDITIONAL_CATEGORY' ), 'move' );
ToolbarHelper::save('document.movingcategory1');
ToolbarHelper::cancel('document.documentlist');
$bootstrapHelper = $this->bootstrapHelper;
$rowFluidClass	 = $bootstrapHelper->getClassMapping('row-fluid');
$span12Class	 = $bootstrapHelper->getClassMapping('span12');


$db = Factory::getContainer()->get('db');
$query = $db->getQuery(true);
$query->select('id, title, parent_id');
$query->from('#__edocman_categories');
$query->where('published=1');
$db->setQuery($query);
$rows     = $db->loadObjectList();
$children = array();
// first pass - collect children
if (count($rows))
{
	foreach ($rows as $v)
	{
		$pt   = $v->parent_id;
		$list = @$children[$pt] ? $children[$pt] : array();
		array_push($list, $v);
		$children[$pt] = $list;
	}
}

$list      = HTMLHelper::_('menu.treerecurse', 0, '', array(), $children, 9999);
$options   = array();
$options[] = HTMLHelper::_('select.option', 0, Text::_('EDOCMAN_SELECT_CATEGORY'));
if (count($list))
{
	foreach ($list as $row)
	{
		$options[] = HTMLHelper::_('select.option', $row->id, $row->treename);
	}
}

?>
<form action="<?php echo Route::_('index.php?option=com_edocman'); ?>" method="post" name="adminForm" id="adminForm">
<div class="<?php echo $rowFluidClass; ?>" id="modal-movingcategory">
	<div class="<?php echo $span12Class; ?>">
		<?php echo Text::_('EDOCMAN_PLEASE_SELECT_ADDITIONAL_CATEGORY_THAT_YOU_WANT_TO_MOVE_DOCUMENTS_TO');?>
		<?php 
		echo HTMLHelper::_('select.genericlist', $options, 'moving_category_id1',
				array(
					'option.text.toHtml' => false,
					'list.attr'          => 'class="input-xxlarge form-select ilarge" style="display:inline;"',
					'option.text'        => 'text',
					'option.key'         => 'value',
					'list.select'        => 0)); 
		?>
	</div>
</div>
<?php
$cid = $this->input->get('cid', array(), 'array');
?>
<select name='cid[]' multiple style='display:none;'>
<?php
foreach($cid as $documentId)
{
	?>
		<option value = '<?php echo $documentId?>' selected><?php echo $documentId?></option>
	<?php
}
?>
</select>
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<?php echo HTMLHelper::_('form.token'); ?>
</form>
