<?php
// no direct access
defined('_JEXEC') or die('Restricted access');

/* * ***********************************************************************
 * Users App for Watchful
 * Copyright (c) 2006-2013 Anything Digital & Inetis
 * ************************************************************************
 * Watchful.li is a web site monitoring and security service.
 * 
 * Although Watchful.li is a paid service, this program is free software;
 * you can redistribute it and/or modify it under the terms of the GNU 
 * General Public License as published by the Free Software Foundation; 
 * either version 2 of the License, or (at your option) any later version.
 *
 * This header must not be removed. Additional contributions/changes
 * may be added to this header as long as no information is deleted.
 * ************************************************************************
 * Get the latest version of this program at: https://watchful.li
 * *********************************************************************** */

jimport('joomla.form.formfield');
class JFormFieldUsersGroups extends JFormField
{
    protected $type = 'usersgroups';

    protected function getInput()
    {
        $options = array();
        if (!is_array($this->value))
            $this->value = array($this->value);

        $db = & JFactory::getDbo();
        $query = "SELECT id, title FROM #__usergroups WHERE id NOT IN (1)";
        $db->setQuery($query);
        if ($usersgroups = $db->loadObjectList())
        {
            foreach ($usersgroups as $usersgroup)
            {
                $checked = in_array($usersgroup->id, $this->value) ? ' checked="checked"' : ' ';
                if (version_compare(JVERSION, '3.0.0', 'lt'))
                {
                    $options[] = '<input name="' . $this->name . '[]" type="checkbox"' . $checked . 'value="' . $usersgroup->id . '"><label>' . $usersgroup->title . '</label>';
                }
                else
                {
                    $options[] = '<input name="' . $this->name . '[]" type="checkbox"' . $checked . 'value="' . $usersgroup->id . '">' . $usersgroup->title;
                }
            }
        }
        if (version_compare(JVERSION, '3.0.0', 'lt'))
        {
            return '<fieldset class="radio">' . implode('<br style="clear: left"/>', $options) . '</fieldset>';
        }
        else
        {
            return implode("<br />", $options);
        }
    }

}
