<script language="JavaScript" type="text/javascript">
<!--
function checkCategory() {
    if (document.task.task_category.value == '*new*') {
        var newCategory = window.prompt('<?php echo addslashes(_("You are creating a new category.")) . '\n' . addslashes(_("Please enter a name for the new category:")) ?>\n', '');
        if (newCategory != null && newCategory != '') {
            document.task.new_category.value = newCategory;
        } else {
            window.alert('<?php echo addslashes(_("You must choose a category.")) ?>');
            return false;
        }
    } else if (document.task.task_category.value == '') {
        window.alert('<?php echo addslashes(_("You must choose a category.")) ?>');
        return false;
    }
    return true;
}
//-->
</script>
<form method="post" name="task" enctype="multipart/form-data" action="<?php echo Horde::selfURL() ?>">
<?php Horde::pformInput() ?>
<input type="hidden" name="actionID" value="<?php echo NAG_SAVE_TASK ?>" />
<input type="hidden" name="task" value="<?php echo $task_id ?>" />
<input type="hidden" name="tasklist_original" value="<?php echo $tasklist_id ?>" />
<input type="hidden" name="new_category" value="" />
<table border="0" cellpadding="2" cellspacing="0" width="100%">
<tr><td align="left" class="header"><b><?php echo $title ?></b></td></tr>
</table>

<table border="0" cellpadding="2" cellspacing="0" width="100%">
<tr>
  <td class="item" align="right" valign="top"><b><?php echo Horde::label('task_name', _("Name")) ?></b>&nbsp;</td>
  <td class="item" width="100%">
    <input id="task_name" name="task_name" type="text" value="<?php echo htmlspecialchars($task_name) ?>" size="50" maxlength="100" />
  </td>
</tr>

<?php if (!$prefs->isLocked('default_tasklist') && count($tasklists = Nag::listTasklists())): ?>
<tr>
  <td class="item" align="right" valign="top"><b><?php echo Horde::label('tasklist_target', _("Task List")) ?></b>&nbsp;</td>
  <td class="item" width="100%">

  <select id="tasklist_target" name="tasklist_target">
  <?php
  foreach ($tasklists as $id => $tasklist) {
    if ($tasklist->hasPermission(Auth::getAuth(), _PERMS_EDIT)) {
      $sel = ($id == $tasklist_id) ? ' selected="selected"' : '';
      echo sprintf('<option value="%s"%s>%s</option>',
        $id, $sel, $tasklist->getShareName()) . "\n";
    }
  } ?>
  </select>

  </td>
</tr>
<?php else: ?>
<input type="hidden" name="tasklist_target" value="<?php echo htmlspecialchars(Auth::getAuth()) ?>" />
<?php endif; ?>

<tr>
  <td class="item" align="right" valign="top"><b><?php echo Horde::label('task_category', _("Category")) ?></b>&nbsp;</td>
  <td class="item" width="100%">
    <?php echo Nag::buildCategoryWidget('task_category', $task_category, true) ?>
  </td>
</tr>
<tr>
  <td class="item" align="right" valign="top" nowrap="nowrap"><b><?php echo Horde::label('due_type_none', _("Due By")) ?></b>&nbsp;</td>
  <td class="item" width="100%">
    <input id="due_type_none" name="due_type" type="radio" value="none" <?php echo $none_checked ?> />
    <label for="due_type_none"><?php echo _("No due date.") ?></label><br />

    <table border="0" cellspacing="0" cellpadding="0">
    <tr><td rowspan="2" valign="top">
      <input name="due_type" type="radio" value="specified" <?php echo $specified_checked ?>/>
    </td>
    <td>
      <?php echo $day_widget . ' ' . $month_widget . ' ' . $year_widget ?>
      <?php if ($GLOBALS['browser']->hasFeature('javascript')) {
                Horde::addScriptFile('open_calendar.js', 'horde');
                echo '<div id="goto" class="control" style="position:absolute;visibility:hidden;padding:1px"></div>';
                echo Horde::link('', _("Select a date"), '', '', 'openCalendar(\'dueimg\', \'due\'); return false;') . Horde::img('calendar.gif', _("Calendar"), 'align="top" id="dueimg"', $GLOBALS['registry']->getParam('graphics', 'horde')) . '</a>';
            } ?>
    </td></tr>
    <tr><td>
      <?php echo $hour_widget . ' ' . $minute_widget ?>
    </td></tr></table>
  </td>
</tr>

<!-- alarm -->
<tr>
 <td align="right" class="item"><b><?php echo Horde::label('noalarm', _("Alarm")) ?>&nbsp;&nbsp;</b></td>
 <td class="item" align="left" valign="top" colspan="3">
  <input id="noalarm" name="alarm" type="radio" value="0"<?php if (!$alarm_set) echo ' checked="checked"' ?>/>
  <label for="noalarm"><?php echo _("None") ?></label><br />
  <input name="alarm" type="radio" value="1"<?php if ($alarm_set) echo ' checked="checked"' ?> />
  <input type="text" size="2" name="alarm_value" value="<?php echo $alarm_value ?>" onchange="document.task.alarm[1].checked=true" />&nbsp;
  <select name="alarm_unit" onchange="document.task.alarm[1].checked=true">
   <option value="1"<?php echo ($alarm_unit == 'min') ? ' selected="selected"' : '' ?>><?php echo _("Minute(s)") ?></option>
   <option value="60"<?php echo ($alarm_unit == 'hour') ? ' selected="selected"' : '' ?>><?php echo _("Hour(s)") ?></option>
   <option value="1440"<?php echo ($alarm_unit == 'day') ? ' selected="selected"' : '' ?>><?php echo _("Day(s)") ?></option>
   <option value="10080"<?php echo ($alarm_unit == 'week') ? ' selected="selected"' : '' ?>><?php echo _("Week(s)") ?></option>
  </select>
 </td>
</tr>
<tr>
  <td class="item" align="right" valign="top"><b><?php echo Horde::label('task_priority', _("Priority")) ?></b>&nbsp;</td>
  <td class="item" width="100%">
    <?php echo Nag::buildPriorityWidget('task_priority', $task_priority) ?>
  </td>
</tr>
<tr>
  <td class="item" align="right" valign="top" nowrap="nowrap"><b><?php echo Horde::label('task_completed', _("Completed?")) ?></b>&nbsp;</td>
  <td class="item" width="100%">
    <?php echo Nag::buildCompletionWidget('task_completed', $task_completed) ?>
  </td>
</tr>
<tr>
  <td class="item" align="right" valign="top"><b><?php echo Horde::label('task_desc', _("Description")) ?></b>&nbsp;</td>
  <td class="item" width="100%">
    <textarea id="task_desc" name="task_desc" cols="50" rows="5"><?php echo htmlspecialchars($task_desc) ?></textarea>
  </td>
</tr>
</table>

<br />
<table border="0" align="center" width="100%" cellspacing="0" cellpadding="0">
<tr>
  <td>
    <input type="submit" class="button" value="<?php echo _("Save Task") ?>" onclick="return checkCategory();" />&nbsp;
    <input type="reset" class="button" value="<?php echo _("Undo Changes") ?>" />
  </td>
</tr>
</table>
</form>
