<?php
// initialize row alternating var
$_i = 0;
?>
<form action="<?php echo ($event->isInitialized() ? 'editeventaction.php' : 'addeventaction.php') ?>" method="post" name="event">
<?php Util::pformInput() ?>
<input type="hidden" name="year" value="<?php if (isset($year)) echo $year ?>" />
<input type="hidden" name="month" value="<?php if (isset($month)) echo $month ?>" />
<input type="hidden" name="mday" value="<?php if (isset($day)) echo $day ?>" />
<input type="hidden" name="timestamp" value="<?php if (isset($timestamp)) echo $timestamp ?>" />
<input type="hidden" name="new_category" value="" />
<?php if (isset($url)): ?>
<input type="hidden" name="url" value="<?php echo $url ?>" />
<?php endif; ?>
<?php if ($event->isInitialized()): ?>
<input type="hidden" name="eventID" value="<?php echo $event->getID() ?>" />
<?php endif; ?>
<?php if ($event->isInitialized()): ?>
<input type="hidden" name="existingcalendar" value="<?php echo $event->getCalendar() ?>" />
<?php endif; ?>
<table cellspacing="0" cellpdding="4">

<!-- header -->
<tr>
 <td align="left" colspan="5" class="header"><b><?php echo $event->isInitialized() ? sprintf(_("Edit %s"), htmlspecialchars($event->getTitle())) : _("Add Event") ?></b></td>
</tr>

<!-- buttons -->
<tr>
 <td align="right" colspan="5">
  <?php echo implode("\n", $buttons); ?>
  <input type="submit" name="cancel" class="button" value="<?php echo _("Cancel") ?>" onclick="self.location = '<?php echo $cancelurl; ?>'; return false;" />
  <input type="button" name="resetButton" class="button" value="<?php echo _("Reset to Defaults") ?>" onclick="document.event.reset(); updateWday('start_wday'); updateWday('end_wday');" />
 </td>
</tr>

<!-- title -->
<tr>
 <td align="right" class="light"><b><?php echo Horde::label('title', _("Tit_le")) ?>&nbsp;&nbsp;</b></td>
 <td align="left" class="item<?php echo($_i++ % 2)?>" colspan="4">
  <input type="text" name="title" id="title" value="<?php echo htmlspecialchars($event->getTitle()) ?>" size="40" maxlength="255" />
 </td>
</tr>

<!-- calendar -->
<?php if (!$prefs->isLocked('default_share') && count($calendars) > 1): ?>
<tr>
 <td align="right" class="light"><b><?php echo Horde::label('targetcalendar', _("Cal_endar")) ?>&nbsp;&nbsp;</b></td>
 <td align="left" class="item<?php echo($_i++ % 2)?>" colspan="4">
    <select id="targetcalendar" name="targetcalendar">
    <?php
    foreach ($calendars as $id => $cal) {
        $sel = ($id == $calendar_id) ? ' selected="selected"' : '';
        echo sprintf('<option value="%s"%s>%s</option>',
                     $id, $sel, $cal->get('name')) . "\n";
    } ?>
    </select>

 </td>
</tr>
<?php else: ?>
<input type="hidden" name="targetcalendar" value="<?php echo htmlspecialchars($calendar_id) ?>" />
<?php endif; ?>

<!-- category -->
<tr>
 <td align="right" class="light">
    <b><?php echo Horde::label('category', _("Categor_y")) ?>&nbsp;&nbsp;</b>
 </td>
 <td align="left" class="item<?php echo($_i++ % 2)?>" colspan="4"><?php echo $cManager->getSelect('category', $event->getCategory()) ?></td>
</tr>

<!-- location -->
<tr>
 <td align="right" class="light"><b><?php echo Horde::label('location', _("Lo_cation")) ?>&nbsp;&nbsp;</b></td>
 <td align="left" class="item<?php echo($_i++ % 2)?>" colspan="4">
  <input type="text" name="location" id="location" value="<?php echo htmlspecialchars($event->getLocation()) ?>" size="40" maxlength="255" />
 </td>
</tr>

<!-- status -->
<tr>
 <td align="right" class="light">
    <b><?php echo Horde::label('status', _("Stat_us")) ?>&nbsp;&nbsp;</b>
 </td>
 <td align="left" class="item<?php echo($_i++ % 2)?>" colspan="4">
  <?php echo Kronolith::buildStatusWidget('status', $event->getStatus()) ?>
 </td>
</tr>

<?php require KRONOLITH_TEMPLATES . '/edit/edit_timespan.inc'; ?>

<!-- alarm -->
<tr>
 <td align="right" class="light">
    <b><?php $ak = Horde::getAccessKey(_("Alarm")); echo Horde::highlightAccessKey(_("Alarm"), $ak); ?>&nbsp;&nbsp;</b>
  </td>
 <td class="item<?php echo($_i++ % 2)?>" align="left" valign="top" colspan="4">
  <?php
  if ($event->isInitialized() && $event->alarm > 0) {
      $alarm_set = true;
      if ($event->alarm % 10080 == 0) {
          $alarm_value = $event->alarm / 10080;
          $alarm_unit = 'week';
      } elseif ($event->alarm % 1440 == 0) {
          $alarm_value = $event->alarm / 1440;
          $alarm_unit = 'day';
      } elseif ($event->alarm % 60 == 0) {
          $alarm_value = $event->alarm / 60;
          $alarm_unit = 'hour';
      } else {
          $alarm_value = $event->alarm;
          $alarm_unit = 'min';
      }
  } else {
      $alarm_value = 15;
      $alarm_unit = 'min';
      $alarm_set = false;
  }
  ?>
  <input id="noalarm" name="alarm" type="radio" value="0"<?php if (!$alarm_set) echo ' checked="checked"' ?> /><label for="noalarm" accesskey="<?php echo $ak ?>"> <?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.event.alarm[1].checked=true" />&nbsp;
  <select name="alarm_unit" onchange="document.event.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>
  <?php echo _("before the event starts") ?>
 </td>
</tr>

<!-- description -->
<tr>
 <td align="left" colspan="5" class="header">
  <span class="smallheader"><?php echo Horde::label('description', _("<b>Descri_ption</b> (optional)")) ?></span>
</td>
</tr>
<tr>
 <td>&nbsp;</td>
 <td class="item<?php echo($_i++ % 2)?>" colspan="4" align="left">
  <textarea wrap="hard" id="description" name="description" cols="40" rows="4"><?php echo htmlspecialchars($event->getDescription()) ?></textarea>
 </td>
</tr>

<!-- attendees -->
<?php
$attendees_url = Util::addParameter('', 'timestamp', $timestamp);
if ($browser->hasFeature('javascript')) {
    Horde::addScriptFile('open_attendees_win.js');
    $attendees_link = 'javascript:open_attendees_win(\'' . $browser->escapeJSCode(substr($attendees_url, 1)) . '\');';
} else {
    $attendees_link = Horde::applicationUrl('attendees.php' . $attendees_url);
}
?>
<tr>
 <td align="left" colspan="5" class="header">
  <span class="smallheader"><?php echo Horde::label('attendees', _("<b>Attendees</b> (optional)")) ?></span>
 </td>
</tr>

<tr>
 <td>&nbsp;</td>
 <td class="item<?php echo($_i++ % 2)?>" colspan="4" align="left">
  <input id="sendupdates" type="checkbox" name="sendupdates" checked="checked" /><label for="sendupdates"> <?php echo _("Send updates/invitations to all attendees when saving this event") ?></label><br />
 </td>
</tr>
<tr>
 <td>&nbsp;</td>
 <td class="item<?php echo($_i++ % 2)?>" align="right" colspan="4">
  <input type="button" name="editattendees" class="button" value="<?php echo _("Edit Attendees") ?>" onclick="<?php echo $attendees_link ?>" />
 </td>
</tr>

<!-- recurrence -->
<tr>
 <td align="left" colspan="5" class="header">
  <span class="smallheader"><?php echo _("<b>Recurrence</b> (optional)") ?></span>
 </td>
</tr>
<tr>
 <td class="light" align="right" valign="top"><b><br /><?php echo Horde::label('recurnone', _("Pattern")) ?>&nbsp;&nbsp;</b></td>
 <td class="item<?php echo($_i++ % 2)?>" align="left" valign="top" colspan="4">
  <?php $_j = $_i ?>
  <table cellpadding="0" cellspacing="0" width="100%">
   <tr>
    <td nowrap="nowrap" class="item<?php echo($_j++ % 2)?>">
     <input id="recurnone" type="radio" name="recur" onclick="clearFields(0);" value="<?php echo KRONOLITH_RECUR_NONE ?>"<?php if ($event->hasRecurType(KRONOLITH_RECUR_NONE)) echo ' checked="checked"' ?> /><label for="recurnone"> <?php echo _("None") ?></label>
    </td>
   </tr>
   <tr>
    <td nowrap="nowrap" class="item<?php echo($_j++ % 2)?>">
     <input id="recurdaily" type="radio" name="recur" onclick="setInterval('recur_daily_interval');" value="<?php echo KRONOLITH_RECUR_DAILY ?>"<?php if ($event->hasRecurType(KRONOLITH_RECUR_DAILY)) echo ' checked="checked"' ?> /><label for="recurdaily"> <?php echo _("Daily: Recurs every") ?>&nbsp;</label>
     <input type="text" name="recur_daily_interval" size="2" onkeypress="setRecur(1);" onchange="setRecur(1);" value="<?php echo $event->hasRecurType(KRONOLITH_RECUR_DAILY) ? $event->getRecurInterval() : '' ?>" />&nbsp;<?php echo _("day(s)") ?>
    </td>
   </tr>
   <tr>
    <td nowrap="nowrap" class="item<?php echo($_j++ % 2)?>">
     <input id="recurweekly" type="radio" name="recur" onclick="setInterval('recur_weekly_interval');" value="<?php echo KRONOLITH_RECUR_WEEKLY ?>"<?php if ($event->hasRecurType(KRONOLITH_RECUR_WEEKLY)) echo ' checked="checked"' ?> /><label for="recurweekly"> <?php echo _("Weekly: Recurs every") ?>&nbsp;</label>
     <input type="text" name="recur_weekly_interval" size="2" onkeypress="setRecur(2);" onchange="setRecur(2);" value="<?php echo $event->hasRecurType(KRONOLITH_RECUR_WEEKLY) ? $event->getRecurInterval() : '' ?>" />&nbsp;
     <?php echo _("week(s) on:") ?><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     <label for="mo"><?php echo _("Mo") ?></label><input id="mo" type="checkbox" name="weekly[]" onclick="setInterval('recur_weekly_interval');setRecur(2);" value="<?php echo HORDE_DATE_MASK_MONDAY ?>"<?php if ($event->recurOnDay(HORDE_DATE_MASK_MONDAY)) echo ' checked="checked"' ?> />&nbsp;
     <label for="tu"><?php echo _("Tu") ?></label><input id="tu" type="checkbox" name="weekly[]" onclick="setInterval('recur_weekly_interval');setRecur(2);" value="<?php echo HORDE_DATE_MASK_TUESDAY ?>"<?php if ($event->recurOnDay(HORDE_DATE_MASK_TUESDAY)) echo ' checked="checked"' ?> />&nbsp;
     <label for="we"><?php echo _("We") ?></label><input id="we" type="checkbox" name="weekly[]" onclick="setInterval('recur_weekly_interval');setRecur(2);" value="<?php echo HORDE_DATE_MASK_WEDNESDAY ?>"<?php if ($event->recurOnDay(HORDE_DATE_MASK_WEDNESDAY)) echo ' checked="checked"' ?> />&nbsp;
     <label for="th"><?php echo _("Th") ?></label><input id="th" type="checkbox" name="weekly[]" onclick="setInterval('recur_weekly_interval');setRecur(2);" value="<?php echo HORDE_DATE_MASK_THURSDAY ?>"<?php if ($event->recurOnDay(HORDE_DATE_MASK_THURSDAY)) echo ' checked="checked"' ?> />&nbsp;
     <label for="fr"><?php echo _("Fr") ?></label><input id="fr" type="checkbox" name="weekly[]" onclick="setInterval('recur_weekly_interval');setRecur(2);" value="<?php echo HORDE_DATE_MASK_FRIDAY ?>"<?php if ($event->recurOnDay(HORDE_DATE_MASK_FRIDAY)) echo ' checked="checked"' ?> />&nbsp;
     <label for="sa"><?php echo _("Sa") ?></label><input id="sa" type="checkbox" name="weekly[]" onclick="setInterval('recur_weekly_interval');setRecur(2);" value="<?php echo HORDE_DATE_MASK_SATURDAY ?>"<?php if ($event->recurOnDay(HORDE_DATE_MASK_SATURDAY)) echo ' checked="checked"' ?> />&nbsp;
     <label for="su"><?php echo _("Su") ?></label><input id="su" type="checkbox" name="weekly[]" onclick="setInterval('recur_weekly_interval');setRecur(2);" value="<?php echo HORDE_DATE_MASK_SUNDAY ?>"<?php if ($event->recurOnDay(HORDE_DATE_MASK_SUNDAY)) echo ' checked="checked"' ?> />&nbsp;
    </td>
   </tr>
   <tr>
    <td nowrap="nowrap" class="item<?php echo($_j++ % 2)?>">
     <input id="recurmonthday" type="radio" name="recur" onclick="setInterval('recur_day_of_month_interval');" value="<?php echo KRONOLITH_RECUR_DAY_OF_MONTH ?>"<?php if ($event->hasRecurType(KRONOLITH_RECUR_DAY_OF_MONTH)) echo ' checked="checked"' ?> /><label for="recurmonthday"> <?php echo _("Monthly: Recurs every") ?>&nbsp;</label>
     <input type="text" name="recur_day_of_month_interval" size="2" onkeypress="setRecur(3);" onchange="setRecur(3);" value="<?php echo $event->hasRecurType(KRONOLITH_RECUR_DAY_OF_MONTH) ? $event->getRecurInterval() : '' ?>" />&nbsp;<?php echo _("month(s)") . ' ' . _("on the same date") ?>
    </td>
   </tr>
   <tr>
    <td nowrap="nowrap" class="item<?php echo($_j++ % 2)?>">
     <input id="recurmonthweek" type="radio" name="recur" onclick="setInterval('recur_week_of_month_interval');" value="<?php echo KRONOLITH_RECUR_WEEK_OF_MONTH ?>"<?php if ($event->hasRecurType(KRONOLITH_RECUR_WEEK_OF_MONTH)) echo ' checked="checked"' ?> /><label for="recurmonthweek"> <?php echo _("Monthly: Recurs every") ?>&nbsp;</label>
     <input type="text" name="recur_week_of_month_interval" size="2" onkeypress="setRecur(4);" onchange="setRecur(4);" value="<?php echo $event->hasRecurType(KRONOLITH_RECUR_WEEK_OF_MONTH) ? $event->getRecurInterval() : '' ?>" />&nbsp;<?php echo _("month(s)") . ' ' . _("on the same weekday") ?>
    </td>
   </tr>
   <tr>
    <td nowrap="nowrap" class="item<?php echo($_j++ % 2)?>">
     <input id="recuryear" type="radio" name="recur" onclick="setInterval('recur_yearly_interval');" value="<?php echo KRONOLITH_RECUR_YEARLY ?>"<?php if ($event->hasRecurType(KRONOLITH_RECUR_YEARLY)) echo ' checked="checked"' ?> /><label for="recuryear"> <?php echo _("Yearly: Recurs every") ?>&nbsp;</label>
     <input type="text" name="recur_yearly_interval" size="2" onkeypress="setRecur(5);" onchange="setRecur(5);" value="<?php echo $event->hasRecurType(KRONOLITH_RECUR_YEARLY) ? $event->getRecurInterval() : '' ?>" />&nbsp;<?php echo _("year(s)") ?>
    </td>
   </tr>
  </table>
 </td>
</tr>

<!-- recur end date -->
<tr>
 <td align="right" class="light">
    <b><?php echo Horde::label('recur_enddate[year]', _("Recur Until")) ?>&nbsp;&nbsp;</b>
 </td>
 <td align="left" class="item<?php echo($_i % 2)?>" colspan="3">
  <input id="recurnoend" type="radio" name="recur_enddate_type" value="none"<?php echo ($event->hasRecurEnd() ? '' : ' checked="checked"') ?> /><label for="recurnoend"> <?php echo _("No end date") ?></label><br />
  <input type="radio" name="recur_enddate_type" value="date"<?php echo ($event->hasRecurEnd() ? ' checked="checked"' : '') ?> />
  <?php echo $event->html('recur_enddate[year]') ?> - <?php echo $event->html('recur_enddate[month]') ?> - <?php echo $event->html('recur_enddate[day]') ?>
<?php if (($browser->isBrowser('msie') && $browser->getMajor() >= 4) ||
          ($browser->isBrowser('mozilla') && $browser->getMajor() >= 5)): ?>
   <span id="recur_end_wday"></span>
   <script language="JavaScript" type="text/javascript">
    updateWday("recur_end_wday");
   </script>
<?php endif; ?>
<?php if ($GLOBALS['browser']->hasFeature('dom')) {
    echo '</td><td align="right" class="item' . ($_i++ % 2) . '">';
    Horde::addScriptFile('open_calendar.js', 'horde');
    echo Horde::link('', _("Select a date"), '', '', 'openCalendar(\'recur_enddateimg\', \'recur_enddate\', \'' . addslashes($event->js('recur_enddate')) . '\'); return false;') . Horde::img('calendar.png', _("Set recurrence end date"), 'align="top" id="recur_enddateimg"', $GLOBALS['registry']->getImageDir('horde')) . '</a>';
} ?>
 </td>
</tr>

<?php if ($conf['metadata']['keywords']): ?>
<!-- keywords -->
<tr class="smallheader">
 <td colspan="5" class="smallheader" align="left"><?php echo _("<b>Keywords</b> (optional)") ?></td>
</tr>
<tr>
 <td></td>
 <td class="item<?php echo($_i++ % 2) ?>" colspan="4" align="left">
  <table cellspacing="2" cellpadding="2">
   <?php include_once KRONOLITH_BASE . '/config/keywords.php'; $count = 0; $_j = $_i; ?>
   <?php foreach ($keywords as $cat => $list):
       if ($count % 3 == 0): ?>
   <tr>
   <?php endif; ?>
    <td class="item<?php echo($_j++ % 2)?>" valign="top">
     <b><?php echo $cat ?></b><br />
    <?php for ($k = 0; $k < count($list); $k++): ?>
     <input type="checkbox" id="keyword<?php echo $k ?>" name="keywords[]" value="<?php echo htmlspecialchars($list[$k]) ?>"<?php if ($event->hasKeyword($list[$k])) echo ' checked="checked"' ?> />
     <?php echo Horde::label('keyword' . $k, htmlspecialchars($list[$k])) ?><br />
    <?php endfor; ?>
    </td>
   <?php if (($count % 3 == 2) || ($count == count($keywords) - 1)): ?>
   </tr>
   <?php endif; $count++; ?>
   <?php endforeach; ?>
  </table>
 </td>
</tr>
<?php endif; ?>

<!-- buttons -->
<tr>
 <td align="right" colspan="5">
  <?php echo implode("\n", $buttons); ?>
  <input type="submit" name="cancel" class="button" value="<?php echo _("Cancel") ?>" onclick="self.location = '<?php echo $cancelurl; ?>'; return false;" />
  <input type="button" name="resetButton" class="button" value="<?php echo _("Reset to Defaults") ?>" onclick="document.event.reset(); updateWday('start_wday'); updateWday('end_wday');" />
  </td>
 </tr>
</table>
</form>

<script language="JavaScript" type="text/javascript">
<!--
document.event.title.focus();
//-->
</script>
