/**
  *  This function returns an associative array with checkboxgroups
  *
  * @param $id    	User id (when adding new group), Group id (when editing group)
  * @param $edit   	We are adding or editing
  *
  * @returns    YDForm object pointer         
  */
 function &_addFormDetails($id, $edit)
 {
     // init form
     $this->_form = new YDForm($this->_form_name);
     // if this group is not a root group we must get the parent group permissions to check the ones we can use
     $userobject = new YDCMUserobject();
     $groups = $userobject->getElements(array('ydcmgroup', 'ydcmuser'));
     $parent_id = $groups[$id]['parent_id'];
     // when adding a new group, parent of $id is the master group. when editing a group, parent is a user.. so the master group is the parent of the parent
     if ($edit == true) {
         $parent_id = $groups[$parent_id]['parent_id'];
     }
     // if parent of this group is root, parentgroup permissions are ALL (read: null), otherwise we must get permissions of that parent
     if ($parent_id == 1) {
         $parentgroup_perms = null;
     } else {
         $parentgroup_perms = $this->getPermissions($parent_id);
     }
     // if we are editing, we must get the current group permissions
     if ($edit == true) {
         $perms = $this->getPermissions($id);
     }
     // init form defaults array
     $form_defaults = array();
     // get all possible actions to compute checkboxgroups for each class
     foreach ($this->getRegisteredActions() as $class => $actions) {
         // get permission translations for each component
         YDLocale::addDirectory(YD_DIR_HOME_ADD . '/YDCMComponent/languages/' . $class);
         // init checkboxgroup options, disabled options and default values
         $chk_options = array();
         $chk_disable = array();
         $form_defaults['pclass_' . $class] = array();
         // cycle all actions of this class to get translations and default values
         foreach ($actions as $action) {
             // get actions labels
             $chk_options[$action] = $this->getActionTitle($class, $action);
             // if parentgroup is the root (id 1) or the parent group has the correspondent action, this action must be set based on current group db values
             if (is_null($parentgroup_perms) || isset($parentgroup_perms[$class][$action])) {
                 // if we are editing and the current group has this permission we must check it. if we are adding just uncheck it
                 if ($edit && isset($perms[$class][$action])) {
                     $form_defaults['pclass_' . $class][$action] = 1;
                 }
                 // otherwise the action must be unset and disabled (because, if the parent group cannot do something, this group cannot do too)
             } else {
                 $form_defaults['pclass_' . $class][$action] = 0;
                 $chk_disable[] = $action;
             }
         }
         // add checkboxgroup to form
         $checkboxgroup =& $this->_form->addElement('checkboxgroup', 'pclass_' . $class, $this->getClassTitle($class), array(), $chk_options);
         $checkboxgroup->addSelectAll(true, array('class' => 'ydcmpermission_checkbox_selall'));
         $checkboxgroup->setAttribute('class', 'ydcmpermission_checkbox');
         $checkboxgroup->setLabelAttribute('class', 'ydcmpermission_checkbox_label');
         // disable checkboxgroup options that are not valid for this group
         if (!empty($chk_disable)) {
             $this->_form->disable('pclass_' . $class, $chk_disable);
         }
     }
     // add submit button
     $this->_form->addElement('submit', '_cmdSubmit', t('save'));
     // set form defaults
     $this->_form->setDefaults($form_defaults);
     return $this->_form;
 }
Exemplo n.º 2
0
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
        Lesser General Public License for more details.
    You should have received a copy of the GNU Lesser General Public
        License along with this library; if not, write to the Free Software
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Check if the framework is loaded
if (!defined('YD_FW_NAME')) {
    die('Yellow Duck Framework is not loaded.');
}
// set components path
YDConfig::set('YD_DBOBJECT_PATH', YD_DIR_HOME_ADD . '/YDCMComponent', false);
// add translations directory
YDLocale::addDirectory(dirname(__FILE__) . '/languages/');
YDLocale::addDirectory(dirname(__FILE__) . '/languages/YDCMUser/');
YDConfig::set('YDCMTEMPLATES_ADMIN_EXT', '/shot.png', false);
// add YDF libs needed by this class
YDInclude('YDDatabaseObject.php');
YDInclude('YDValidateRules.php');
YDInclude('YDUtil.php');
YDInclude('YDResult.php');
// add YDCM libs
YDInclude('YDCMLanguages.php');
YDInclude('YDCMTemplates.php');
YDInclude('YDCMUserobject.php');
// user class
class YDCMUser extends YDDatabaseObject
{
    function YDCMUser()
    {