示例#1
0
 /**
  * Creates the permission menu template
  */
 public static function permissionMenu(Key $key, $popbox = FALSE)
 {
     $edit_groups = Users_Permission::getRestrictedGroups($key, TRUE);
     if (PHPWS_Error::isError($edit_groups)) {
         PHPWS_Error::log($edit_groups);
         $tpl['MESSAGE'] = $edit_groups->getMessage();
         return $tpl;
     }
     $view_groups = User_Form::_getNonUserGroups();
     $view_matches = $key->getViewGroups();
     $edit_matches = $key->getEditGroups();
     if (!empty($edit_groups)) {
         $edit_select = User_Form::_createMultiple($edit_groups['restricted']['all'], 'edit_groups', $edit_matches);
     } else {
         $edit_select = null;
     }
     if (!empty($view_groups)) {
         $view_select = User_Form::_createMultiple($view_groups, 'view_groups', $view_matches);
     } else {
         $view_select = null;
     }
     $form = new PHPWS_Form('choose_permissions');
     $form->addHidden('module', 'users');
     $form->addHidden('action', 'permission');
     $form->addHidden('key_id', $key->id);
     $form->addRadio('view_permission', array(0, 1, 2));
     $form->setExtra('view_permission', 'onclick="hideSelect(this.value)"');
     $form->setLabel('view_permission', array(dgettext('users', 'All visitors'), dgettext('users', 'Logged visitors'), dgettext('users', 'Specific group(s)')));
     $form->setMatch('view_permission', $key->restricted);
     $form->addSubmit(dgettext('users', 'Save permissions'));
     if ($popbox) {
         $form->addHidden('popbox', 1);
     }
     $tpl = $form->getTemplate();
     $tpl['TITLE'] = dgettext('users', 'Permissions');
     $tpl['EDIT_SELECT_LABEL'] = dgettext('users', 'Edit restrictions');
     $tpl['VIEW_SELECT_LABEL'] = dgettext('users', 'View restrictions');
     if ($edit_select) {
         $tpl['EDIT_SELECT'] = $edit_select;
     } else {
         $tpl['EDIT_SELECT'] = dgettext('users', 'No restricted edit groups found.');
     }
     if ($view_select) {
         $tpl['VIEW_SELECT'] = $view_select;
     } else {
         $tpl['VIEW_SELECT'] = dgettext('users', 'No view groups found.');
     }
     if ($popbox) {
         $tpl['CANCEL'] = sprintf('<input type="button" value="%s" onclick="window.close()" />', dgettext('users', 'Cancel'));
     }
     if (isset($_SESSION['Permission_Message'])) {
         $tpl['MESSAGE'] = $_SESSION['Permission_Message'];
         unset($_SESSION['Permission_Message']);
     }
     return $tpl;
 }