<?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()) {

			if (JRequest::getVar('view',-1) == -1) {
				JRequest::setVar('view', 'permissions');
			}
			parent::display();
		}
		
		public function add() {

			JRequest::setVar('view', 'permission');
			parent::display();
		}

        public function log() {

            JRequest::setVar('view', 'log');
            parent::display();
        }
		
		public function cancel() {

			$mainframe = JFactory::getApplication();
			$mainframe->redirect('index.php?option=com_dmfrontendusermanager');
		}
		
		public function delete() {

			$gid = JRequest::getVar('cid', '');
            foreach ($gid as $groupId) {
                DMFUMHelper::deletePermissions($groupId);
            }

			$mainframe = JFactory::getApplication();
			$mainframe->redirect('index.php?option=com_dmfrontendusermanager');

		}
		
		public function save() {

            $groups = DMFUMHelper::getGroups();
            $gid = JRequest::getInt('gid', -1);
            if ($gid > 0) {
                foreach ($groups as $group) {
                    $slaveid = $group->id;
                    $view = JRequest::getInt('view_' . $slaveid,0);
                    $add = JRequest::getInt('add_' . $slaveid,0);
                    $edit = JRequest::getInt('edit_' . $slaveid,0);
                    $del = JRequest::getInt('del_' . $slaveid,0);
                    DMFUMHelper::insertPermissions($gid, $slaveid, $view, $add, $edit, $del);
                    }
            }

			$mainframe = JFactory::getApplication();
			$mainframe->redirect('index.php?option=com_dmfrontendusermanager');
		}
	}
	
?>