<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
$user=&JFactory::getUser();
if ($user->usertype=='Manager')
{JError::raiseError( 403, JText::_("ALERTNOTAUTH") );
};
$id = JArrayHelper::getValue($_REQUEST,'cid',0);
switch($task){
case("edit"):edit($id);break;
case("save"):save();break;
default:view();break;
}
function view()
{global $mainframe;
$lim = $mainframe->getUserStateFromRequest("$option.limit", 'limit', 14, 'int');
$lim0 = JRequest::getVar('limitstart', 0, '', 'int');
$query = 'SELECT COUNT(jos_sections.id) FROM jos_sections';
$db =& JFactory::getDBO();
$db->setQuery($query);
$total = $db->loadResult();
jimport('joomla.html.pagination');
$pageNav = new JPagination( $db->loadResult(), $lim0, $lim );
JToolBarHelper::title( 'Пользователи разделов', 'generic.png' );
echo '<form action="'.JRoute::_('index.php?option=com_usersections'). '" method="post" id="adminForm" name="adminForm">';
echo '<table ><tr><td width="200"></td><td>';
$query = 'SELECT jos_sections.id, jos_sections.title, jos_users.username FROM jos_sections LEFT JOIN jos_users ON jos_sections.iduser = jos_users.id ORDER BY jos_sections.title';
$db =& JFactory::getDBO();
$db->setQuery($query,$lim0, $lim);
$list = $db->loadObjectList();
echo '<table class = "adminlist"><tr><th width="10" align="center"> № </th><th align="center" width="200" >Название раздела</th><th align="center" width="200">Имя пользователя</th></tr>';
$n=1;
foreach($list as $section)
{echo '<tr><td align="center">'.$n++.'</td><td><span class="editlinktip hasTip"><a href="index.php?option=com_usersections&task=edit&cid='.$section->id.'">'.$section->title.'</a></span></td><td><span class="editlinktip hasTip"><a href="index.php?option=com_usersections&task=edit&cid='.$section->id.'">'.$section->username.'</a></span></td></tr>';
}
echo '</table>';
echo '</td></tr></table>';
echo '<table class = "adminlist"><tr width="610"><td >'.$pageNav->getListFooter( ).'</td></tr></table>';
echo '</form>';
}
function edit($id)
{JToolBarHelper::title( 'Пользователи разделов : <small><small>[редактирование]</small></small>', 'generic.png' );
JToolBarHelper::save('save');
JToolBarHelper::cancel( 'cancel', 'Close' );
echo '<form action="'.JRoute::_('index.php?option=com_usersections'). '" method="post" id="adminForm" name="adminForm">';
echo '<input type="hidden" name="task" value="" />';
echo '<input type="hidden" name="cid" value="'.$id.'" />';
echo '<table><tr><td width="200"></td><td>';
echo '<table class="adminlist">';
echo '<tr><th align="center" width="250" >Название раздела</th><th align="center" width="200" >Имя пользователя</th></tr>';
$query = 'SELECT jos_sections.title FROM jos_sections WHERE jos_sections.id='.$id;
$db =& JFactory::getDBO();
$db->setQuery($query);
$list = $db->loadResult();
$query = "SELECT id AS value, username AS text FROM #__users WHERE id <> 62 ORDER BY id";
$db->setQuery($query);
$users = $db->loadObjectList();
$query = 'SELECT jos_sections.iduser FROM jos_sections WHERE jos_sections.id='.$id;
$db =& JFactory::getDBO();
$db->setQuery($query);
$idu = $db->loadResult();
$selected = $idu;
$ulist = JHTML::_('select.genericlist',$users, 'user', 'class="inputbox" style="width:180px;"', 'value', 'text', $selected );
echo '<tr><td align="center" >'.$list.'</td><td align="center" >'.$ulist.'</td></tr>';
echo '</table>';
echo '</td></tr></table>';
echo '</form>';
}
function save()
{global $mainframe;
$uid = JArrayHelper::getValue($_POST,'user',"");
$id = JArrayHelper::getValue($_POST,'cid',"");
echo 'id='.$id.'uid='.$uid;
$query = "UPDATE `#__sections` SET `iduser` = ".$uid." WHERE id=".$id;
$db =& JFactory::getDBO();
$db->setQuery($query);
$db->Query();
if($db->_errorNum == 0) $mainframe->redirect( 'index.php?option=com_usersections', 'Успешно сохранено!');
else $mainframe->redirect( 'index.php?option=com_usersections', 'Произошла ошибка при сохранениее', 'error' );
}
?>