<script language="JavaScript" type="text/javascript">
<!--
function deleteCategory(id)
{
    document.prefs.managementActionID.value = <?php echo MNEMO_DELETE_CATEGORY ?>;
    document.prefs.category_id.value = id;
    document.prefs.submit();
}

function renameCategory(id)
{
    var name = window.prompt('<?php echo addslashes(_("Please enter a new name for this category:")) ?>\n', '');

    if (name != null && name != '') {
        document.prefs.managementActionID.value = <?php echo MNEMO_RENAME_CATEGORY ?>;
        document.prefs.category_name.value = name;
        document.prefs.category_id.value = id;
        document.prefs.submit();
    }
}

function addCategory()
{
    var name = window.prompt('<?php echo addslashes(_("Please enter a name for the new category:")) ?>\n', '');

    if (name != null && name != '') {
        document.prefs.managementActionID.value = <?php echo MNEMO_ADD_CATEGORY ?>;
        document.prefs.category_name.value = name;
        document.prefs.submit();
    }
}


//-->
</script>
<input name='managementActionID' value="" type="hidden" />
<input name='category_id' value="" type="hidden" />
<input name='category_name' value="" type="hidden" />
<table border="0">
<tr>
  <td colspan="2"><?php echo sprintf(_("Any notes in a category that is deleted will become %s."), _("Unfiled")) ?><br/><br/></td>
</tr>

<tr>
  <td></td>
  <td>
    <a href="" onclick="addCategory(); return false;"><?php echo _("Create New Category") ?></a>
  </td>
</tr>

<?php
$categories = Mnemo::listCategories();
$colors = Mnemo::categoryColors();
foreach ($categories as $key => $name):
    $color = isset($colors[$key]) ? $colors[$key] : '#ffffff';
    $url = Horde::url($registry->getParam('webroot', 'horde') . '/util/colorpicker.php');
    $url = Horde::addParameter($url, 'target', 'newColors[' . $key . ']');
    $url = Horde::addParameter($url, 'form', 'prefs');
?>
<tr>
  <td style="background-color:<?php echo $color ?>"><b><?php echo $name ?></b></td>
  <td>
    <a href="" onclick="deleteCategory('<?php echo $key ?>'); return false;"><?php echo _("Delete") ?></a>&nbsp;|&nbsp;
    <a href="" onclick="renameCategory('<?php echo $key ?>'); return false;"><?php echo _("Rename") ?></a>&nbsp;|&nbsp;
    <?php if (!$prefs->isLocked('memo_colors')): ?>
    <a href="<?php echo $url ?>" onclick="window.open('<?php echo $url ?>', 'colorpicker', 'toolbar=no,location=no,status=no,scrollbars=no,resizable=no,width=120,height=250,left=100,top=100'); return false;" onmouseout="window.status='';" onmouseover="window.status='<?php echo _('Color Picker') ?>'; return true;" class="widget" target="colorpicker">
      <?php Horde::pimg('colorpicker.gif', _('Color Picker'), 'height="16"', $registry->getParam('graphics', 'horde')) ?></a>
    <input style="background-color:<?php echo $color ?>" name="newColors[<?php echo $key ?>]" value="<?php echo $color ?>" />
    <?php endif; ?>
  </td>
</tr>
<?php endforeach; ?>

<tr>
  <td colspan="2"><br/><?php echo _("These changes can not be undone!") ?></td>
</tr>
</table>
