<form name="edit_permissions" method="post" action="perms.php">
<input type="hidden" name="actionID" value="editform" />
<input type="hidden" name="cid" value="<?php echo $permission->getId() ?>" />
<?php Horde::pformInput() ?>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr valign="middle">
  <td class="header" align="left" width="100%" colspan="7">
    <?php Horde::pimg('perms.gif') ?>&nbsp;<b><?php echo sprintf(_("Edit permissions for '%s'"), $permission->getShortName()) ?></b>
  </td>
</tr>
<tr><td>&nbsp;</td></tr>

<!-- Default Permissions -->
<tr valign="middle">
  <td class="header" align="left" width="25%">
    <?php echo Horde::img('perms.gif') . '&nbsp;' . _("Default Permissions") ?>
  </td>
  <td class="header" align="center" width="1%"><?php echo _("Show") ?></td>
  <td class="header" align="center" width="1%"><?php echo _("Read") ?></td>
  <td class="header" align="center" width="1%"><?php echo _("Edit") ?></td>
  <td class="header" align="center" width="1%"><?php echo _("Delete") ?></td>
  <td class="header" align="right" width="70%"></td>
</tr>
<?php $perm = $permission->getDefaultPermissions(); ?>
<tr>
  <td class="light">&nbsp;</td>
  <td align="center"><input type="checkbox" name="default_show"<?php echo ($perm & _PERMS_SHOW) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="default_read"<?php echo ($perm & _PERMS_READ) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="default_edit"<?php echo ($perm & _PERMS_EDIT) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="default_delete"<?php echo ($perm & _PERMS_DELETE) ? ' checked="checked"' : '' ?> /></td>
</tr>

<!-- Spacer -->
<tr><td>&nbsp;</td></tr>

<!-- Guest Permissions -->
<tr valign="middle">
  <td class="header" align="left" width="25%">
    <?php echo Horde::img('guest.gif') . '&nbsp;' . _("Guest Permissions") ?>
  </td>
  <td class="header" align="center" width="1%"><?php echo _("Show") ?></td>
  <td class="header" align="center" width="1%"><?php echo _("Read") ?></td>
  <td class="header" align="center" width="1%"><?php echo _("Edit") ?></td>
  <td class="header" align="center" width="1%"><?php echo _("Delete") ?></td>
  <td class="header" align="right" width="70%"></td>
</tr>
<?php $perm = $permission->getGuestPermissions(); ?>
<tr>
  <td class="light">&nbsp;</td>
  <td align="center"><input type="checkbox" name="guest_show"<?php echo ($perm & _PERMS_SHOW) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="guest_read"<?php echo ($perm & _PERMS_READ) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="guest_edit"<?php echo ($perm & _PERMS_EDIT) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="guest_delete"<?php echo ($perm & _PERMS_DELETE) ? ' checked="checked"' : '' ?> /></td>
</tr>

<!-- Spacer -->
<tr><td>&nbsp;</td></tr>

<!-- Event Creator Permissions -->
<tr valign="middle">
  <td class="header" align="left" width="25%">
    <?php echo Horde::img('user.gif') . '&nbsp;' . _("Event Creator") ?>
  </td>
  <td class="header" align="center" width="1%"><?php echo _("Show") ?></td>
  <td class="header" align="center" width="1%"><?php echo _("Read") ?></td>
  <td class="header" align="center" width="1%"><?php echo _("Edit") ?></td>
  <td class="header" align="center" width="1%"><?php echo _("Delete") ?></td>
  <td class="header" align="right" width="70%"></td>
</tr>
<?php $perm = $permission->getCreatorPermissions(); ?>
<tr>
  <td class="light">&nbsp;</td>
  <td align="center"><input type="checkbox" name="creator_show"<?php echo ($perm & _PERMS_SHOW) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="creator_read"<?php echo ($perm & _PERMS_READ) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="creator_edit"<?php echo ($perm & _PERMS_EDIT) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="creator_delete"<?php echo ($perm & _PERMS_DELETE) ? ' checked="checked"' : '' ?> /></td>
</tr>

<!-- Spacer -->
<tr><td>&nbsp;</td></tr>

<!-- User Permissions -->
<tr valign="middle">
  <td class="header" align="left" width="25%">
    <?php echo Horde::img('user.gif') . '&nbsp;' . _("Users") ?>
  </td>
  <td class="header" align="center" width="1%"><?php echo _("Show") ?></td>
  <td class="header" align="center" width="1%"><?php echo _("Read") ?></td>
  <td class="header" align="center" width="1%"><?php echo _("Edit") ?></td>
  <td class="header" align="center" width="1%"><?php echo _("Delete") ?></td>
  <td class="header" align="right" width="70%"></td>
</tr>
<?php $userperms = $permission->getUserPermissions(); foreach ($userperms as $user => $perm): ?>
<tr>
  <td class="light"><?php echo $user ?><input type="hidden" name="u_names[<?php echo $user ?>]" value="<?php echo $user ?>" /></td>
  <td align="center"><input type="checkbox" name="u_show[<?php echo $user ?>]"<?php echo ($perm & _PERMS_SHOW) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="u_read[<?php echo $user ?>]"<?php echo ($perm & _PERMS_READ) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="u_edit[<?php echo $user ?>]"<?php echo ($perm & _PERMS_EDIT) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="u_delete[<?php echo $user ?>]"<?php echo ($perm & _PERMS_DELETE) ? ' checked="checked"' : '' ?> /></td>
</tr>
<?php endforeach; ?>
<!-- New user row -->
<tr>
<?php if ($auth->hasCapability('list')): ?>
  <td class="light">
    <select name="u_names[||new]">
      <option value=""><?php echo _("Select") . ':'; ?></option>
    <?php foreach ($auth->listUsers() as $user) { if (!isset($userperms[$user])) { ?>
      <option value="<?php echo $user ?>"><?php echo $user ?></option>
    <?php } } ?>
    </select>
  </td>
<?php else: ?>
  <td class="light"><input type="text" name="u_names[||new]" /></td>
<?php endif; ?>
  <td align="center"><input type="checkbox" name="u_show[||new]" /></td>
  <td align="center"><input type="checkbox" name="u_read[||new]" /></td>
  <td align="center"><input type="checkbox" name="u_edit[||new]" /></td>
  <td align="center"><input type="checkbox" name="u_delete[||new]" /></td>
</tr>

<!-- Spacer -->
<tr><td>&nbsp;</td></tr>

<!-- Group Permissions -->
<tr valign="middle">
  <td class="header" align="left" width="25%">
    <?php echo Horde::img('group.gif') . '&nbsp;' . _("Groups") ?>
  </td>
  <td class="header" align="center" width="1%"><?php echo _("Show") ?></td>
  <td class="header" align="center" width="1%"><?php echo _("Read") ?></td>
  <td class="header" align="center" width="1%"><?php echo _("Edit") ?></td>
  <td class="header" align="center" width="1%"><?php echo _("Delete") ?></td>
  <td class="header" align="right" width="70%"></td>
</tr>
<?php $groupperms = $permission->getGroupPermissions(); foreach ($groupperms as $group => $perm): ?>
<tr>
  <td class="light"><?php echo $groups->getGroupName($group) ?><input type="hidden" name="g_names[<?php echo $group ?>]" value="<?php echo $group ?>" /></td>
  <td align="center"><input type="checkbox" name="g_show[<?php echo $group ?>]"<?php echo ($perm & _PERMS_SHOW) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="g_read[<?php echo $group ?>]"<?php echo ($perm & _PERMS_READ) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="g_edit[<?php echo $group ?>]"<?php echo ($perm & _PERMS_EDIT) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="g_delete[<?php echo $group ?>]"<?php echo ($perm & _PERMS_DELETE) ? ' checked="checked"' : '' ?> /></td>
</tr>
<?php endforeach; ?>
<!-- New group row -->
<tr>
  <td class="light">
    <select name="g_names[||new]">
      <option value=""><?php echo _("Select") . ':'; ?></option>
    <?php $groupList = $groups->listGroups(); foreach ($groupList as $gid => $group) { if (!isset($groupperms[$gid])) { ?>
      <option value="<?php echo htmlspecialchars($gid) ?>"><?php echo htmlspecialchars($group) ?></option>
    <?php } } ?>
    </select>
  </td>
  <td align="center"><input type="checkbox" name="g_show[||new]" /></td>
  <td align="center"><input type="checkbox" name="g_read[||new]" /></td>
  <td align="center"><input type="checkbox" name="g_edit[||new]" /></td>
  <td align="center"><input type="checkbox" name="g_delete[||new]" /></td>
</tr>

<tr>
  <td><input type="submit" class="button" value="<?php printf(_("Save '%s'"), $permission->getShortName()) ?>" /></td>
</tr>

</table>
</form>
<br />
