<form name="edit_permissions" method="post" action="edit.php">
<input type="hidden" name="actionID" value="editform" />
<input type="hidden" name="cid" value="<?php echo $share->getId() ?>" />
<input type="hidden" name="app" value="<?php echo $app ?>" />
<?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'"), $share->getShareName()) ?></b>
  </td>
</tr>
<tr><td>&nbsp;</td></tr>

<?php $owner = $share->getOwner(); ?>
<?php $userperms = $perm->getUserPermissions(); ?>

<!-- Ownership -->
<?php if (array_key_exists($owner, $userperms)) {
          $operm = $userperms[$owner];
      } else {
          $operm = _PERMS_SHOW & _PERMS_READ & _PERMS_EDIT & _PERMS_DELETE;
      }
?>
<tr valign="middle">
  <td class="header" align="left" width="25%">
    <?php echo Horde::img('perms.gif') . '&nbsp;' . _("Owner 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>
<tr>
<?php if ($auth->hasCapability('list')): ?>
  <td class="light">
    <select name="owner">
      <option value=""><?php echo _("Select a new owner") . ':'; ?></option>
      <option value="<?php echo $owner ?>" selected="selected"><?php echo Auth::removeHook($owner) ?></option>
    <?php foreach ($userList as $user) { if ($user != $owner) { ?>
      <option value="<?php echo $user ?>"><?php echo Auth::removeHook($user) ?></option>
    <?php } } ?>
    </select>
  </td>
<?php else: ?>
  <td class="light"><input type="text" name="owner" value="<?php echo ($owner) ?>" /></td>
<?php endif; ?>
  <td align="center"><input type="checkbox" name="owner_show"<?php echo ($operm & _PERMS_SHOW) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="owner_read"<?php echo ($operm & _PERMS_READ) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="owner_edit"<?php echo ($operm & _PERMS_EDIT) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="owner_delete"<?php echo ($operm & _PERMS_DELETE) ? ' checked="checked"' : '' ?> /></td>
</tr>

<!-- Spacer -->
<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 $dperm = $perm->getDefaultPermissions(); ?>
<tr>
  <td class="light">&nbsp;</td>
  <td align="center"><input type="checkbox" name="default_show"<?php echo ($dperm & _PERMS_SHOW) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="default_read"<?php echo ($dperm & _PERMS_READ) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="default_edit"<?php echo ($dperm & _PERMS_EDIT) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="default_delete"<?php echo ($dperm & _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 $gperm = $perm->getGuestPermissions(); ?>
<tr>
  <td class="light">&nbsp;</td>
  <td align="center"><input type="checkbox" name="guest_show"<?php echo ($gperm & _PERMS_SHOW) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="guest_read"<?php echo ($gperm & _PERMS_READ) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="guest_edit"<?php echo ($gperm & _PERMS_EDIT) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="guest_delete"<?php echo ($gperm & _PERMS_DELETE) ? ' checked="checked"' : '' ?> /></td>
</tr>

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

<!-- Creator Permissions -->
<tr valign="middle">
  <td class="header" align="left" width="25%">
    <?php echo Horde::img('user.gif') . '&nbsp;' . _("Object 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 $cperm = $perm->getCreatorPermissions(); ?>
<tr>
  <td class="light">&nbsp;</td>
  <td align="center"><input type="checkbox" name="creator_show"<?php echo ($cperm & _PERMS_SHOW) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="creator_read"<?php echo ($cperm & _PERMS_READ) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="creator_edit"<?php echo ($cperm & _PERMS_EDIT) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="creator_delete"<?php echo ($cperm & _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 foreach ($userperms as $user => $uperm) { if ($user != $owner) { ?>
<tr>
  <td class="light"><?php echo Auth::removeHook($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 ($uperm & _PERMS_SHOW) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="u_read[<?php echo $user ?>]"<?php echo ($uperm & _PERMS_READ) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="u_edit[<?php echo $user ?>]"<?php echo ($uperm & _PERMS_EDIT) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="u_delete[<?php echo $user ?>]"<?php echo ($uperm & _PERMS_DELETE) ? ' checked="checked"' : '' ?> /></td>
</tr>
<?php } } ?>
<!-- New user row -->
<tr>
<?php if ($auth->hasCapability('list')): ?>
  <td class="light">
    <select name="u_names[||new]">
      <option value=""><?php echo _("Select a user to add") . ':'; ?></option>
    <?php foreach ($userList as $user) { if (!array_key_exists($user, $userperms)) { ?>
      <option value="<?php echo $user ?>"><?php echo Auth::removeHook($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 = $perm->getGroupPermissions(); foreach ($groupperms as $group => $gperm): ?>
<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 ($gperm & _PERMS_SHOW) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="g_read[<?php echo $group ?>]"<?php echo ($gperm & _PERMS_READ) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="g_edit[<?php echo $group ?>]"<?php echo ($gperm & _PERMS_EDIT) ? ' checked="checked"' : '' ?> /></td>
  <td align="center"><input type="checkbox" name="g_delete[<?php echo $group ?>]"<?php echo ($gperm & _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 a group to add") . ':'; ?></option>
    <?php foreach ($groupList as $gid => $group) { if (!array_key_exists($gid, $groupperms)) { ?>
      <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'"), $share->getShareName()) ?>" /></td>
</tr>

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