<?xml version="1.0"?>
<!--
 -
 -  $Id$
 -
 -  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 -  project.
 -
 -  Copyright (C) 1998-2018 OpenLink Software
 -
 -  This project is free software; you can redistribute it and/or modify it
 -  under the terms of the GNU General Public License as published by the
 -  Free Software Foundation; only version 2 of the License, dated June 1991.
 -
 -  This program is distributed in the hope that it will be useful, but
 -  WITHOUT ANY WARRANTY; without even the implied warranty of
 -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 -  General Public License for more details.
 -
 -  You should have received a copy of the GNU General Public License along
 -  with this program; if not, write to the Free Software Foundation, Inc.,
 -  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 -
-->
<v:page name="attendee" decor="template/popup.vspx" style="template/template.xsl" fast-render="1" xmlns:v="http://www.openlinksw.com/vspx/" xmlns:vm="http://www.openlinksw.com/vspx/macro" doctype="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  <v:method name="priorityLabel" arglist="in priority integer">
    <![CDATA[
     if (priority = 1)
       return 'Highest';
     if (priority = 2)
       return 'High';
     if (priority = 4)
       return 'Low';
     if (priority = 5)
       return 'Lowest';
     return 'Normal';
    ]]>
  </v:method>

  <v:method name="viewField" arglist="inout fValue any">
    <![CDATA[
      if (is_empty_or_null (fValue))
      {
       http ('&nbsp;');
      } else {
       if (internal_type (fValue) = 211) {
         http (CAL.WA.dt_datestring (fValue, self.cDateFormat));
       } else {
         http (CAL.WA.utf2wide (cast (fValue as varchar)));
       }
      }
    ]]>
  </v:method>

  <v:method name="viewDescription" arglist="inout fValue any">
    <![CDATA[
      if (is_empty_or_null (fValue))
      {
        http ('&nbsp;');
      } else {
        if (internal_type (fValue) = 211)
        {
          http (CAL.WA.dt_datestring (fValue, self.cDateFormat));
        } else {
          http ('<pre>');
          http (CAL.WA.utf2wide (cast (fValue as varchar)));
          http ('</pre>');
        }
      }
    ]]>
  </v:method>

  <v:method name="arrays4Reminder" arglist="inout x any, inout y any">
    <![CDATA[
      x := make_array (14, 'any');
      x[0] := 'No reminder';
      x[1] := '5 minutes';
      x[2] := '10 minutes';
      x[3] := '15 minutes';
      x[4] := '20 minutes';
      x[5] := '25 minutes';
      x[6] := '30 minutes';
      x[7] := '45 minutes';
      x[8] := '1 hour';
      x[9] := '2 hours';
      x[10]:= '3 hours';
      x[11]:= '1 day';
      x[12]:= '2 days';
      x[13]:= '1 week';
      y:= make_array (14, 'any');
      y[0] := '-1';
      y[1] := '300';
      y[2] := '600';
      y[3] := '900';
      y[4] := '1200';
      y[5] := '1500';
      y[6] := '1800';
      y[7] := '2700';
      y[8] := '3600';
      y[9] := '7200';
      y[10]:= '10800';
      y[11]:= '86400';
      y[12]:= '172800';
      y[13]:= '604800';
    ]]>
  </v:method>

  <vm:pagetitle>Attendees page</vm:pagetitle>

  <vm:popup_page_wrapper close="yes" ods-bar="no">

    <vm:variables>
      <v:variable name="v_mode" type="varchar" default="null" />

      <v:variable name="v_uid" param-name="uid" type="varchar" default="null" />
      <v:variable name="v_action" param-name="a" type="varchar" default="null" />
      <v:variable name="v_id" param-name="id" type="integer" default="null" />

      <v:variable name="v_subject" type="varchar" default="''" />
      <v:variable name="v_description" type="varchar" default="''" />
      <v:variable name="v_location" type="varchar" default="''" />
      <v:variable name="v_event" type="integer" default="0" />
      <v:variable name="v_eventStart" type="datetime" default="null" />
      <v:variable name="v_eventEnd" type="datetime" default="null" />
      <v:variable name="v_completed" type="datetime" default="null" />
      <v:variable name="v_privacy" type="integer" default="0" />
      <v:variable name="v_attendees" type="varchar" default="''" />
      <v:variable name="v_tags" type="varchar" default="''" />
      <v:variable name="v_repeat" type="varchar" default="''" />
      <v:variable name="v_repeatParam1" type="integer" default="0" />
      <v:variable name="v_repeatParam2" type="integer" default="0" />
      <v:variable name="v_repeatParam3" type="integer" default="0" />
      <v:variable name="v_repeatUntil" type="date" default="null" />
      <v:variable name="v_reminder" type="integer" default="600" />

      <v:variable name="v_priority" type="integer" default="3" />
      <v:variable name="v_complete" type="integer" default="0" />
      <v:variable name="v_status" type="varchar" default="''" />
      <v:variable name="v_notes" type="varchar" default="''" />
    </vm:variables>

    <vm:pagebody>
      <v:before-data-bind>
        <![CDATA[
          if (not isnull (self.v_uid))
          {
            self.v_id := (select AT_EVENT_ID from CAL.WA.ATTENDEES where AT_UID = self.v_uid);
          }
          else if (not CAL.WA.access_is_write (self.account_rights))
          {
            return;
          }
          self.v_mode := case when (select E_KIND from CAL.WA.EVENTS where E_ID = self.v_id) = 0 then 'event' else 'task' end;
          if (self.v_action in ('A', 'D', 'T'))
            CAL.WA.attendees_update_status (self.v_uid, self.v_action);
        ]]>
      </v:before-data-bind>

      <div id="app_area" style="clear: right;">
        <div style="background-color: #fff;">
          <img src="image/calendarbanner_sml.jpg" border="0" alt="Calendar Home" />
        </div>
      </div>
      <div class="form-header">
        Attendees
      </div>

      <div class="new-form-body">
        <v:template type="simple" enabled="--case when self.v_mode <> '' then 1 else 0 end">
          <table>
            <v:template type="simple" enabled="--case when isnull (self.v_uid) then 0 else 1 end">
              <tr>
                <td colspan="2" align="center">
                  <v:button action="simple" value="Accept" name="a_accept" xhtml_class="form-button">
                    <v:on-post>
                      <![CDATA[
                        CAL.WA.attendees_update_status (self.v_uid, 'A');
                        self.vc_data_bind (e);
                      ]]>
                    </v:on-post>
                  </v:button>
                  <v:button action="simple" value="Decline" name="a_decline" xhtml_class="form-button">
                    <v:on-post>
                      <![CDATA[
                        CAL.WA.attendees_update_status (self.v_uid, 'D');
                        self.vc_data_bind (e);
                      ]]>
                    </v:on-post>
                  </v:button>
                  <v:button action="simple" value="Tentative" name="a_tentative" xhtml_class="form-button">
                    <v:on-post>
                      <![CDATA[
                        CAL.WA.attendees_update_status (self.v_uid, 'T');
                        self.vc_data_bind (e);
                      ]]>
                    </v:on-post>
                  </v:button>
                </td>
              </tr>
            </v:template>
            <tr>
              <td width="50%" valign="top">
                <v:before-data-bind>
                  <![CDATA[
                    --declare exit handler for not found goto _end;

                    if (self.v_mode = 'event')
                    {
                      select E_SUBJECT,
                             E_DESCRIPTION,
                             E_LOCATION,
                             E_PRIVACY,
                             E_TAGS,
                             E_EVENT,
                             CAL.WA.event_gmt2user (E_EVENT_START, self.cTimezone),
                             CAL.WA.event_gmt2user (E_EVENT_END, self.cTimezone),
                             E_REPEAT,
                             E_REPEAT_PARAM1,
                             E_REPEAT_PARAM2,
                             E_REPEAT_PARAM3,
                             E_REPEAT_UNTIL,
                             E_REMINDER,
                             E_TAGS,
                             blob_to_string (E_NOTES)
                        into self.v_subject,
                             self.v_description,
                             self.v_location,
                             self.v_privacy,
                             self.v_tags,
                             self.v_event,
                             self.v_eventStart,
                             self.v_eventEnd,
                             self.v_repeat,
                             self.v_repeatParam1,
                             self.v_repeatParam2,
                             self.v_repeatParam3,
                             self.v_repeatUntil,
                             self.v_reminder,
                             self.v_tags,
                             self.v_notes
                        from CAL.WA.EVENTS
                       where E_ID = self.v_id;
                    }
                    else if (self.v_mode = 'task')
                    {
                      select E_SUBJECT,
                             E_DESCRIPTION,
                             E_TAGS,
                             CAL.WA.event_gmt2user (E_EVENT_START, self.cTimezone),
                             CAL.WA.event_gmt2user (E_EVENT_END, self.cTimezone),
                             CAL.WA.event_gmt2user (E_COMPLETED, self.cTimezone),
                             E_PRIORITY,
                             E_STATUS,
                             E_COMPLETE,
                             blob_to_string (E_NOTES)
                        into self.v_subject,
                             self.v_description,
                             self.v_tags,
                             self.v_eventStart,
                             self.v_eventEnd,
                             self.v_completed,
                             self.v_priority,
                             self.v_status,
                             self.v_complete,
                             self.v_notes
                        from CAL.WA.EVENTS
                       where E_ID = self.v_id;
                     }
                   _end:;
                  ]]>
                </v:before-data-bind>

                <div class="new-form-body">
                  <table cellspacing="0">
                    <v:template type="simple" enabled="--case when self.v_mode = 'event' then 1 else 0 end">
                      <tr>
                        <th width="25%">
                          Name
                        </th>
                        <td>
                          <?vsp self.viewField (self.v_subject); ?>
                        </td>
                      </tr>
                      <tr>
                        <th>
                          Duration
                        </th>
                        <td>
                          <?vsp
                            if (self.v_event = 0) {
                              self.viewField (sprintf ('%s - %s', CAL.WA.dt_datetimestring (self.v_eventStart, self.cDateFormat, self.cTimeFormat), CAL.WA.dt_datetimestring (self.v_eventEnd, self.cDateFormat, self.cTimeFormat)));
                            } else {
                              self.viewField (sprintf ('%s - %s', CAL.WA.dt_datestring (self.v_eventStart, self.cDateFormat), CAL.WA.dt_datestring (self.v_eventEnd, self.cDateFormat)));
                            }
                          ?>
                        </td>
                      </tr>
                      <tr>
                        <th valign="top">
                          Description
                        </th>
                        <td>
                          <?vsp self.viewDescription (self.v_description); ?>
                        </td>
                      </tr>
                      <tr>
                        <th>
                          Location
                        </th>
                        <td>
                          <?vsp self.viewField (self.v_location); ?>
                        </td>
                      </tr>
                      <tr>
                        <th>
                          Reminder
                        </th>
                        <td>
                          <?vsp
                            declare N integer;
                            declare x, y any;

                            self.arrays4Reminder (x, y);
                            N := CAL.WA.vector_indexOf (y, cast (self.v_reminder as varchar), 0);
                            self.viewField (x [N]);
                          ?>
                        </td>
                      </tr>
                      <tr>
                        <th>
                          Tags
                        </th>
                        <td>
                          <?vsp self.viewField (self.v_tags); ?>
                        </td>
                      </tr>
                      <tr>
                        <th>
                          Repeats
                        </th>
                        <td>
                          <?vsp
                            self.viewField (CAL.WA.vcal_recurrence2str (self.v_repeat,
                                                                        self.v_RepeatParam1,
                                                                        self.v_RepeatParam2,
                                                                        self.v_RepeatParam3,
                                                                        self.v_repeatUntil
                                                                       )
                                           );
                          ?>
                        </td>
                      </tr>
                      <tr>
                        <th>
                          Repeats range
                        </th>
                        <td>
                          <?vsp
                            self.viewField (self.v_repeatUntil);
                          ?>
                        </td>
                      </tr>
                      <tr>
                        <th valign="top">
                          Notes
                        </th>
                        <td>
                          <?vsp self.viewField (self.v_notes); ?>
                        </td>
                      </tr>
                    </v:template>
                    <v:template type="simple" enabled="--case when self.v_mode = 'task' then 1 else 0 end">
                      <tr>
                        <th width="25%">
                          Name
                        </th>
                        <td>
                          <?vsp self.viewField (self.v_subject); ?>
                        </td>
                      </tr>
                      <tr>
                        <th>
                          Start Date
                        </th>
                        <td>
                          <?vsp self.viewField (self.v_eventStart); ?>
                        </td>
                      </tr>
                      <tr>
                        <th>
                          Due Date
                        </th>
                        <td>
                          <?vsp self.viewField (self.v_eventEnd); ?>
                        </td>
                      </tr>
                      <tr>
                        <th>
                          Completed
                        </th>
                        <td>
                          <?vsp self.viewField (self.v_completed); ?>
                        </td>
                      </tr>
                      <tr>
                        <th>
                          Priority
                        </th>
                        <td>
                          <?vsp self.viewField (self.priorityLabel (self.v_priority)); ?>
                        </td>
                      </tr>
                      <tr>
                        <th>
                          Status
                        </th>
                        <td>
                          <?vsp self.viewField (self.v_status); ?>
                        </td>
                      </tr>
                      <tr>
                        <th>
                          Complete
                        </th>
                        <td>
                          <?vsp self.viewField (self.v_complete); ?>
                        </td>
                      </tr>
                      <tr>
                        <th valign="top">
                          Description
                        </th>
                        <td>
                          <?vsp self.viewDescription (self.v_description); ?>
                        </td>
                      </tr>
                      <tr>
                        <th>
                          Tags
                        </th>
                        <td>
                          <?vsp self.viewField (self.v_tags); ?>
                        </td>
                      </tr>
                      <tr>
                        <th valign="top">
                          Notes
                        </th>
                        <td>
                          <?vsp self.viewField (self.v_notes); ?>
                        </td>
                      </tr>
                    </v:template>
                  </table>
                </div>
              </td>
              <td valign="top">
                <?vsp
                  declare N, M integer;
                  declare V, X any;

                  X := vector ('A', 'Accepted', 'D', 'Declined', 'T', 'Tentative', 'N', 'Not responded');
                  for (M := 0; M < length (X); M := M + 2)
                  {
                    V := CAL.WA.attendees_select (self.v_id, X[M]);
                    http (sprintf ('<div class="form-header">%s (%d)</div>', X[M+1], length (V)));
                    for (N := 0; N < length (V); N := N + 1)
                    {
                      http (sprintf ('<div style="padding-left: 12px;"><a href="mailto: %s">%V</a> (%s)</div>', V[N][2], CAL.WA.mail2string (V[N][1], V[N][2]), CAL.WA.dt_datetimestring (V[N][4], self.cDateFormat, self.cTimeFormat)));
                    }
                    http ('<br />');
                  }
                ?>
              </td>
            </tr>
          </table>
        </v:template>
        <v:template type="simple" enabled="--case when self.v_mode <> '' then 0 else 1 end">
          No access rights to view this page!
        </v:template>
      </div>
    </vm:pagebody>
  </vm:popup_page_wrapper>
</v:page>
