<?php
	
	/**
	* @copyright		(C)2013 DM Digital S.r.l
	* @author 			DM Digital <support@dmjoomlaextensions.com>
	* @link				http://www.dmjoomlaextensions.com
	* @license 			GNU/LGPL http://www.gnu.org/copyleft/gpl.html
	**/

	defined('_JEXEC') or die('Restricted access');
	
	class DMControllerUserManager extends DMController {
		
		public function display($cachable = false, $urlparams = array()) {

			parent::display();
		}
		
		public function editUser() {

            DMFUMFrontendHelper::checkSession();

            $params['userId'] = JRequest::getString('userId', -1);
            $params['name'] = JRequest::getString('name', '');
            $params['username'] = JRequest::getString('username', '');
            $params['email'] = JRequest::getString('email', '');
            $params['name'] = JRequest::getString('name', '');
            $params['password'] = JRequest::getString('password', '');
            $params['groups'] = JRequest::getVar('groups', '');
            $params['infoemail'] = JRequest::getInt('infoemail', 0);
            $params['blockuser'] = JRequest::getInt('blockuser', 0);

            $result = DMFUMFrontendHelper::editUser($params);

            if ($result == 'OK')
                DMFUMHHtml::reqOtput('OK');
            else
                DMFUMHHtml::reqOtput('ERROR', '', $result);
            exit;

		}
		
		public function deleteUser() {

            DMFUMFrontendHelper::checkSession();

            $userId = JRequest::getVar('userId', '-1');
            $result = DMFUMFrontendHelper::deleteUser($userId);

            if ($result == 'OK')
                DMFUMHHtml::reqOtput('OK');
            else
                DMFUMHHtml::reqOtput('ERROR', '', $result);
            exit;

		}

        public function getUserInfo() {

            DMFUMFrontendHelper::checkSession();

            $userId = JRequest::getVar('userId', 'new');
            $outhtml = DMFUMFrontendHelper::getUserInfo($userId);
            echo json_encode($outhtml);
            exit;

        }

        public function getUsers() {

            DMFUMFrontendHelper::checkSession();

            $filterGroup = JRequest::getVar('filterGroup', '');
            $filterSearch = JRequest::getVar('filterSearch', '');
            $orderBy = JRequest::getString('orderBy', '');

            $users = DMFUMFrontendHelper::getUsers($filterSearch, $filterGroup, $orderBy);
            if (count($users) > 0) {
                $outhtml = DMFUMHHtml::getUserListHtml($users);
                DMFUMHHtml::reqOtput('OK', $outhtml);
            } else {
                DMFUMHHtml::reqOtput('ERROR', '', 'There are no visible users. ');
            }
            exit;

        }
	}
	
?>