<!--
 -
 -  $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="ods-app-my-insts-page"
  xmlns:vm="http://www.openlinksw.com/vspx/ods/"
  xmlns:v="http://www.openlinksw.com/vspx/"
  style="index.xsl"
  doctype="-//W3C//DTD XHTML 1.0 Transitional//EN"
  doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<vm:page>
  <vm:header>
    <vm:title>Applications</vm:title>
    <vm:disco-sioc-app-link />
  </vm:header>
  <vm:pagewrapper>
    <v:variable name="ufid" type="integer" default="-1"/>
    <vm:rawheader caption="<?V wa_utf8_to_wide (coalesce (self.f_full_name, self.u_full_name)) ?><?V case when length (self.fname) or length (self.sid) then '\'s' else '' end ?> <?V WA_GET_APP_NAME (self.app_type) ?>"/>
    <vm:body>
      <v:local-variable name="lvsn">
      <v:before-data-bind>
	<![CDATA[

    if ( not length(self.sid)
         and (self.app_type='oMail' or self.app_type='oDrive')
       )
    {
      signal ('22023', sprintf ('You are not allowed to view personal information when not signed in.', self.fname));
    };


	 if (not length (self.fname) and length (self.sid))
	   self.fname := self.u_name;

	 if (length (self.fname))
	   {
      declare exit handler for not found
	    {
	     signal ('22023', sprintf ('User "%s" does not exist.', self.fname));
	    };

	    select U_ID into self.ufid from SYS_USERS where U_NAME = self.fname;
	   }
	]]>
      </v:before-data-bind>
      </v:local-variable>
      <vm:login redirect="app_my_inst.vspx"/>
      <div id="LT_SB">
        <ul class="sb app_cmds_sb">
          <vm:if test="length (self.sid)">
            <li>
              <v:url xhtml_class="ods_side_button"
                     url="services.vspx"
                     name="my_app"
                     value='<img src="images/icons/apps_16.png" border="0" /> Manage Applications' />
            </li>
          </vm:if>
        </ul>
      <vm:if test="self.app_type<>'nntpf' and self.app_type<>'discussion'">
        <ul class="sb app_cmds_sb">
<?vsp

          declare usr_instnum,apptype_instnum int;

          declare exit handler for not found {
              apptype_instnum:=0;
          };

          select WAT_MAXINST
            into apptype_instnum
            from WA_TYPES
            where WAT_NAME = self.app_type;

          if (apptype_instnum is null)
            apptype_instnum := 999999; -- XXX Magic number???

          declare exit handler for not found
            {
              usr_instnum := 0;
            };

          select WMIC_INSTCOUNT
            into usr_instnum
            from WA_MEMBER_INSTCOUNT
            where WMIC_TYPE_NAME = self.app_type and
                  WMIC_UID=self.u_id;

          if (
               (
                 (length (self.sid) and (self.u_name = self.fname or 0 = length (self.fname)))
                 or
                 (length (self.sid) = 0 and 0 = length (self.fname))
               )
               and
               apptype_instnum<>0
               and
               apptype_instnum>usr_instnum
             )
          {
?>
              <li>
                <a class="ods_side_button" href="<?V 'index_inst.vspx?wa_name=' || self.app_type || self.login_pars || case when self.topmenu_level='1' then '&l=1' else '' end ?>">
                  <img src="images/icons/new_16.png" border="0" /> Create New</a>
              </li>
<?vsp
            }

?>

        </ul> <!-- app_cmds_sb -->
        <ul class="sb app_insts_sb">

<?vsp

    declare i int;

	  for select * from WA_USER_APP_INSTANCES_DATASPACE sub
                where user_id = self.u_id and
                      app_type = self.app_type and
                      fname = self.fname do
	    {
        declare dataspace_url varchar;


        dataspace_url:=sprintf('%s%U/%s/%s', self.odsbar_dataspace_path, INST_OWNER, self.odsbar_app_dataspace, replace (sprintf('%U', wa_utf8_to_wide (INST_NAME)), '/', '%2f'));
--        dataspace_url:=INST_DATASPACE;
?>
	      <li>
                <a class="ods_side_button" href="<?vsp http(wa_expand_url (dataspace_url, self.login_pars)); ?>">
                  <img src="images/icons/go_16.png" border="0"/> <?V wa_utf8_to_wide (INST_NAME) ?>
                </a>
              </li>
<?vsp
	    i := i + 1;
	    if (i>=10)
	    {
?>
    <li>
     <a class="ods_side_button" href="<?vsp http(wa_expand_url (self.odsbar_ods_gpath || 'search.vspx?apps=apps&q=' || WA_GET_APP_NAME(self.app_type), self.odsbar_loginparams));?>">more...</a>
    </li>

<?vsp
        goto end_for;
	    }
	  }
end_for:
	?>
        </ul>
      </vm:if>
      <vm:if test="self.app_type='nntpf' or self.app_type='discussion'">
      <div>
          <ul class="sb app_cmds_sb"><li><a href="<?Vwa_expand_url ('/dataspace/discussion', self.login_pars)?>"><img src="images/icons/go_16.png" border="0"/> Discussions </a></li></ul>
      </div>
      </vm:if>
      </div> <!-- LT_SB -->
      <div id="RT">
<?vsp
  if (self.u_id = self.ufid)
    {
      if (self.app_type = 'WEBLOG2')
	    {
?>
        <vm:dash-blog-summary/>
<?vsp
      }
      else if (self.app_type = 'eNews2')
	    {
?>
	      <vm:dash-enews-summary/>
<?vsp
	    }
	    else if (self.app_type = 'oMail')
	    {
?>
	      <vm:dash-omail-summary/>
<?vsp
	    }
	    else if (self.app_type = 'oWiki')
	    {
?>
        <vm:dash-wiki-summary/>
<?vsp
	    }
	    else if (self.app_type = 'Bookmark')
	    {
?>
	      <vm:dash-bookmark-summary/>
<?vsp
	    }
	    else if (self.app_type = 'oDrive')
	    {
?>
	      <vm:dash-odrive-summary/>
<?vsp
	    }
      else if (self.app_type = 'oGallery')
      {
?>
        <vm:dash-ogallery-summary/>
<?vsp
      }
      else if (self.app_type = 'Polls')
      {
?>
        <vm:dash-polls-summary/>
<?vsp
      }
      else if (self.app_type = 'AddressBook')
      {
?>
        <vm:dash-addressbook-summary/>
<?vsp
      }
      else if (self.app_type = 'Calendar')
      {
?>
        <vm:dash-calendar-summary/>
<?vsp
      }
      else if (self.app_type = 'IM')
      {
?>
        <vm:dash-im-summary/>
<?vsp
      }
      else if (self.app_type = 'nntpf')
      {
?>
        <vm:dash-discussions-summary/>
<?vsp
      }
	}
?>
      </div> <!-- RT -->
    </vm:body>
  </vm:pagewrapper>
</vm:page>
</v:page>
