<?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
 -  
 -  
-->
<html>
<head>
    <link rel="stylesheet" type="text/css" href="../demo.css"/>
</head>
<body>
<v:page name="pagecal1" xmlns:v="http://www.openlinksw.com/vspx/">
<v:variable name="tdate" type="date" default="NULL"/>
<v:variable name="newpost" type="int" default="1"/>
<v:variable name="postid" type="varchar" default="null"/>
<v:variable name="blogid" type="varchar" default="'home'" persist="1"/>
<v:variable name="uid" type="varchar" default="'dav'" persist="1"/>
<v:variable name="nuid" type="varchar" default="2" persist="1"/>
<v:variable name="uname" type="varchar" default="'Anonimous'"/>
      <v:variable name="adays" type="any" default="null"/>

<v:on-init>
  self.tdate := now ();
  if (get_keyword ('tdate', params) &lt;&gt; '')
    {
      declare cal vspx_calendar;
      self.tdate := stringdate (get_keyword ('tdate', params));
      cal := self.vc_find_descendant_control ('cal1');
      cal.cal_date := self.tdate;
    }
</v:on-init>

    <!-- LOGIN -->
    <v:login name="login1" realm="blog" mode="url"
	     user-password-check="BLOG..blog_user_password_check">
      <v:template type="if-no-login" redirect="login.vspx" />
      <v:template type="if-login" />
      <v:after-data-bind>
      <![CDATA[
	if (self.vc_authenticated)
	  {
	    self.uid := connection_get ('vspx_user');
	    self.blogid := (select top 1 BI_BLOG_ID from BLOG..SYS_BLOG_INFO, SYS_USERS where BI_OWNER = U_ID and U_NAME = self.uid order by 1);
	    self.nuid := atoi (self.blogid);
	  }
	connection_set ('blogid', self.blogid);
	connection_set ('uid', self.uid);
	self.uname := coalesce ((select U_FULL_NAME from SYS_USERS where U_NAME = self.uid), self.uname);
       ]]>
      </v:after-data-bind>
    </v:login>
    <!-- END LOGIN -->

<P>&amp;nbsp;</P> <!-- place to put a logo -->
<div align="center">
<div align="left" style="margin-left: 100px;"><H2><?V self.uname ?>'s Weblog</H2></div>
<v:form name="form1" type="simple" action="blog.vspx" >
<table border="0" cellpadding="0" cellspacing="0" width="80%">
<tr>
  <td valign="top">
  <table border="0" cellpadding="0" cellspacing="0" width="70%">
    <tr>
      <td>
	   <table width="80%" border="0" cellspacing="0" cellpadding="4" class="tableentry">
	      <tr>
		<td valign="top">
                   <v:textarea name="msg" xhtml_rows="10" xhtml_cols="70">
		     <v:after-data-bind>
		       if ({?'pid'} is not null)
		         {
			   declare exit handler for sqlstate '*' { goto endb;  };
			   control.ufl_value := (select B_CONTENT from BLOG..SYS_BLOGS where B_BLOG_ID = self.blogid and B_POST_ID = {?'pid'});
			   self.newpost := 0;
			   self.postid := {?'pid'};
			endb:;
			 }
		     </v:after-data-bind>
		   </v:textarea>
		   <p style="color: red;"><v:error-summary /></p>
		</td>
	      </tr>
	      <tr>
		<td valign="top">
                   <v:button name="save" action="simple" value="Post to Weblog" >
		     <v:on-post>
		     declare msg vspx_textarea;
                     msg := self.msg;
		     if (msg.ufl_value &lt;&gt; '')
		       {
			 if (self.newpost)
			   {
			     insert into BLOG..SYS_BLOGS (B_APPKEY, B_POST_ID, B_BLOG_ID, B_TS, B_CONTENT, B_USER_ID)
				 values ('appKey', cast (sequence_next ('blogger.postid') as varchar),
				     self.blogid, now (), msg.ufl_value, self.nuid);
			   }
			 else
			   {
			     update BLOG..SYS_BLOGS set B_CONTENT = msg.ufl_value where B_POST_ID = self.postid and B_BLOG_ID = self.blogid;
			   }
		       }
                     else
		       {
			 self.vc_is_valid := 0;
			 msg.vc_error_message := 'Can not post to weblog an empty message';
			 return;
		       }
		     self.newpost := 1;
		     {
		       self.ds.vc_data_bind (e);
		     }
 		     msg.ufl_value := '';
		     </v:on-post>
		   </v:button>
		</td>
	      </tr>
           </table>
      </td>
    </tr>
    <tr>
      <td>
      &amp;nbsp;
      </td>
    </tr>
    <tr>
      <td>
       <!-- DATASET -->
      <table cellspacing="0" cellpadding="0">
       <tr bgcolor="DCDCDC">
         <td>
      <v:data-set name="ds"
      	sql='select B_CONTENT, B_TS, B_POST_ID from BLOG..SYS_BLOGS where B_BLOG_ID = :blogid
		and year(B_TS) = year(:dt) and month(B_TS) = month(:dt) and dayofmonth(B_TS) = dayofmonth(:dt)
		order by B_TS desc'
      	nrows="10" scrollable="0">
        <v:param name="blogid" value="--self.blogid"/>
        <v:param name="dt" value="--self.tdate"/>
        <v:template name="template1" type="simple" name-to-remove="table" set-to-remove="bottom">
          <table border="0" cellspacing="1" cellpadding="5" class="tableresult">
	    <tr><td colspan="4" align="center">
	         <v:label name="label03" value="--b_tit_fmt (self.tdate)" format="%s"/>
	        </td>
  	    </tr>
          </table>
        </v:template>
        <v:template name="template2" type="repeat" name-to-remove="" set-to-remove="">
          <v:template name="template7" type="if-not-exists" name-to-remove="table" set-to-remove="both">
            <table>
              <tr bgcolor="FFFFFF">
                <td align="center" colspan="4">
                  <b>No postings</b>
                </td>
              </tr>
            </table>
          </v:template>
          <v:template name="template4" type="browse" name-to-remove="table" set-to-remove="both">
            <table>
              <tr bgcolor="FFFFFF">
	        <td>
		  <v:check-box name="cb1" value="--cal_icell (control, 2)" group-name="cb1">
		    <v:after-data-bind>
		      control.ufl_selected := 0;
		    </v:after-data-bind>
		  </v:check-box>
		</td>
                <td align="left" >
                  <v:label name="label5" value="--cal_icell (control, 0)" format="%s"/>
                </td>
                <td align="left" nowrap="1" colspan="1">
                  <v:label name="label6" value="--cal_icell (control, 1)" format="%s" fmt-function="b_date_fmt"/>
                </td>
                <td nowrap="1">
		<v:url name="edit" value="EDIT" url="--concat ('blog.vspx?pid=', cal_icell (control, 2), '&amp;tdate=', datestring(coalesce(self.tdate, now())))" />
                </td>
              </tr>
            </table>
          </v:template>
        </v:template>
        <v:template name="template8" type="simple" name-to-remove="table" set-to-remove="top">
            <table>
            </table>
        </v:template>
      </v:data-set>
        </td>
	</tr>
	<tr><td>&amp;nbsp;</td></tr>
	<tr><td>
	  <v:button action="simple" name="delete" value="Delete">
	    <v:on-post>
	      declare i, deleted int;
              i := 0; deleted := 0;
	      while (1)
                {
                  i := position ('cb1', params, i);
		  if (i = 0)
		    goto endp;
                  deleted := deleted + 1;
                  delete from BLOG..SYS_BLOGS where B_BLOG_ID = self.blogid and B_POST_ID = params[i];
                  i := i + 1;
		}
             endp:

	      if (deleted &gt; 0)
	        {
                  self.ds.vc_data_bind (e);
	        }
	    </v:on-post>
	  </v:button>
	</td></tr>
	</table>
       <!-- END DATASET -->
      </td>
    </tr>
  </table>
  </td>
  <td valign="top" width="130">
    <div>
    <v:calendar name="cal1" initial-date="--coalesce (self.tdate, now())">
                  <v:before-data-bind><![CDATA[
	    set isolation = 'committed';
	    declare adays any;
	    declare m, y int;
	    declare dt date;


	    dt := coalesce (control.cal_date, self.fordate);
	    m := month (dt);
	    y := year (dt);

	    adays := vector ();
	    for select distinct dayofmonth (B_TS) DDAY from BLOG..SYS_BLOGS
	      where B_BLOG_ID = self.blogid and year (B_TS) = y and month (B_TS) = m do
	      {
	        adays := vector_concat (adays, vector (cast (DDAY as varchar)));
	      }
	    self.adays := adays;]]></v:before-data-bind>
      <v:after-data-bind>
       self.tdate := control.cal_date;
      </v:after-data-bind>
      <v:template type="simple" name="chead1" name-to-remove="table" set-to-remove="bottom">
      <table border="0" cellpadding="1" cellspacing="0" id="calendar">
        <tr>
         <td align="center">
	  <v:button name="pmon" value="&amp;lt;" action="simple" style="url">
	    <v:on-post>
	    declare cal vspx_calendar;
	    declare ctrl vspx_control;
	    cal := control.vc_parent.vc_parent;
	    cal.cal_date := dateadd ('month', -1, cal.cal_date);
	    ctrl := cal;
	    ctrl.vc_data_bind (e);
            ctrl := self.vc_find_descendant_control ('ds');
	    ctrl.vc_data_bind (e);
	    </v:on-post>
	  </v:button>
	 </td>
 	 <td colspan="5" align="center"><B>
           <?V monthname((control.vc_parent as vspx_calendar).cal_date) ?>
	   <?V year((control.vc_parent as vspx_calendar).cal_date) ?>
	   </B>
	 </td>
         <td align="center">
	  <v:button name="nmon" value="&amp;gt;" action="simple" style="url">
	    <v:on-post>
	    declare cal vspx_calendar;
	    declare ctrl vspx_control;
	    cal := control.vc_parent.vc_parent;
	    cal.cal_date := dateadd ('month', 1, cal.cal_date);
	    ctrl := cal;
	    ctrl.vc_data_bind (e);
            ctrl := self.vc_find_descendant_control ('ds');
	    ctrl.vc_data_bind (e);
	    </v:on-post>
	  </v:button>
	 </td>
	 </tr>
        <tr><td class="realsmall">Sun</td><td class="realsmall">Mon</td><td class="realsmall">Tue</td><td class="realsmall">Wed</td><td class="realsmall">Thu</td><td class="realsmall">Fri</td><td class="realsmall">Sat</td></tr>
      </table>
      </v:template>
      <v:template type="repeat" name="cbody1" name-to-remove="" set-to-remove="">
      <v:template type="browse" name="crow1" name-to-remove="table" set-to-remove="both">
      <table>
                        <tr>
                          <td class="&lt;?V cell_fmt((control as vspx_row_template).te_rowset[0], self.adays) ?>">
                            <v:button style="url" action="simple" name="b1" value="--cal_icell(control, 0)" active="--position(control.ufl_value, self.adays)"/>
                          </td>
                          <td class="&lt;?V cell_fmt((control as vspx_row_template).te_rowset[1], self.adays) ?>">
                            <v:button style="url" action="simple" name="b2" value="--cal_icell(control, 1)" active="--position(control.ufl_value, self.adays)"/>
                          </td>
                          <td class="&lt;?V cell_fmt((control as vspx_row_template).te_rowset[2], self.adays) ?>">
                            <v:button style="url" action="simple" name="b3" value="--cal_icell(control, 2)" active="--position(control.ufl_value, self.adays)"/>
                          </td>
                          <td class="&lt;?V cell_fmt((control as vspx_row_template).te_rowset[3], self.adays) ?>">
                            <v:button style="url" action="simple" name="b4" value="--cal_icell(control, 3)" active="--position(control.ufl_value, self.adays)"/>
                          </td>
                          <td class="&lt;?V cell_fmt((control as vspx_row_template).te_rowset[4], self.adays) ?>">
                            <v:button style="url" action="simple" name="b5" value="--cal_icell(control, 4)" active="--position(control.ufl_value, self.adays)"/>
                          </td>
                          <td class="&lt;?V cell_fmt((control as vspx_row_template).te_rowset[5], self.adays) ?>">
                            <v:button style="url" action="simple" name="b6" value="--cal_icell(control, 5)" active="--position(control.ufl_value, self.adays)"/>
                          </td>
                          <td class="&lt;?V cell_fmt((control as vspx_row_template).te_rowset[6], self.adays) ?>">
                            <v:button style="url" action="simple" name="b7" value="--cal_icell(control, 6)" active="--position(control.ufl_value, self.adays)"/>
                          </td>
                        </tr>
      </table>
      </v:template>
      </v:template>
      <v:template type="simple" name="cbott1" name-to-remove="table" set-to-remove="top">
      <table>
      </table>
      </v:template>
    </v:calendar>
   </div>
   <div align="center">
   <v:url name="work" url="bridge.vspx" value="Blogger Bridge" />
   </div>
  </td>
</tr>
</table>
      <v:on-post>
      declare cal vspx_calendar;
      cal := control.vc_find_control ('cal1');
      if (cal.vc_focus and cal.cal_selected is not null)
       {
         declare ctrl vspx_control;
	 self.tdate := cal.cal_selected;
         ctrl := control.vc_find_control ('ds');
         ctrl.vc_data_bind (e);
       }
      </v:on-post>
</v:form>
</div>

</v:page>
</body>
</html>

