<?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>
  <script language="JavaScript">
  function selectRow (frm_name, __filename)
    {
       if (opener == null)
         return;

       this.<?V self.retname ?> = opener.<?V self.retname ?>;
       if (<?V self.retname ?> != null &amp;&amp; frm_name != '')
         <?V self.retname ?>.value = document.forms[frm_name].item_name.value;

       opener.focus ();
       close ();
    }
  </script>
  <link rel="alternate"
        type="application/rss+xml"
        title="Virtuoso Screencast Demos"
        href="http://support.openlinksw.com/viewlets/virtuoso_viewlets_rss.vsp" />
  <link rel="alternate"
        type="application/rss+xml"
        title="Virtuoso Tutorials"
        href="http://demo.openlinksw.com/tutorial/rss.vsp" />
  <link rel="alternate"
        type="application/rss+xml"
        title="Virtuoso Product Blog (RSS 2.0)"
        href="http://www.openlinksw.com/weblogs/virtuoso/gems/rss.xml" />
  <link rel="alternate"
        type="application/atom+xml"
        title="Virtuoso Product Blog (Atom)"
        href="http://www.openlinksw.com/weblogs/virtuoso/gems/atom.xml" />
  <link rel="stylesheet" href="yacutia_vdir_style.css" type="text/css"/>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
  <title><?V self.caption ?></title>
</head>
<body>
<v:page name="vdir_browser"
   xmlns:v="http://www.openlinksw.com/vspx/"
   xmlns:xhtml="http://www.w3.org/1999/xhtml"
   xmlns:vm="http://www.openlinksw.com/vspx/macro"
   >
  <!-- Parameters -->
  <v:variable name="caption" persist="0" type="varchar" default="'Select file'" />
  <v:variable name="dir_separator" persist="0" type="varchar" default="'/'" />
  <v:variable name="quote_char" persist="0" type="varchar" default="''" />
  <v:variable name="template_char" persist="0" type="varchar" default="'*'" />
  <v:variable name="crfolder_proc_name" persist="0" type="varchar" default="''" />
  <v:variable name="content_proc_name" persist="0" type="varchar" default="''" />
  <v:variable name="content_meta_proc_name" persist="0" type="varchar" default="''" />
  <v:variable name="multi_select" persist="0" type="integer" default="0" />
  <v:variable name="dir_select" persist="0" type="integer" default="0" />
  <v:variable name="retname" persist="0" type="varchar" default="''" />
  <v:variable name="filter" persist="0" type="varchar" default="''" />
  <v:variable name="crfolder_mode" persist="0" type="integer" default="0" />

  <!-- State Vars -->
  <v:variable name="rootdir" persist="0" type="varchar" default="''" />
  <v:variable name="curpath" persist="0" type="varchar" default="''" />
  <v:variable name="sel_items" persist="0" type="varchar" default="''" />

  <v:on-init>
    <v:script>
      <![CDATA[

--  dbg_printf ('nntpf_browser on-init');
    --dbg_obj_print ('params', params);

  if (get_keyword ('content-proc', params, '') <> '')
    {
--      dbg_obj_print ('init params');

      self.retname := get_keyword ('retname', params, '');
      self.caption := get_keyword ('caption', params, '');
      self.dir_separator := get_keyword ('dir-separator', params, '');
      self.quote_char := get_keyword ('quote-char', params, '');
      self.template_char := get_keyword ('filter-char', params, '');
      self.crfolder_proc_name := get_keyword ('crfolder-proc', params, '');
      self.content_proc_name := get_keyword ('content-proc', params, '');
      self.content_meta_proc_name := get_keyword ('content-meta-proc', params, '');
      self.multi_select := atoi (get_keyword ('multi-sel', params, '0'));
      self.dir_select := atoi (get_keyword ('dir-sel', params, '0'));
      self.rootdir := '';
      self.filter := get_keyword ('filter', params, '');

--      dbg_printf ('content_proc_name: %s', self.content_proc_name);
--      dbg_printf ('content_meta_proc_name: %s', self.content_meta_proc_name);

      if (get_keyword ('start-path', params, '') <> '')
        self.curpath := get_keyword ('start-path', params);
      else if (self.curpath = '')
        self.curpath := self.rootdir;

      if (self.dir_select > 0)
        {
          self.sel_items := self.curpath;
          self.multi_select := 0;
        }
    }


    if (length (self.curpath) > 1)
      self.curpath := rtrim (self.curpath, self.dir_separator);

--  dbg_printf ('nntpf_browser on-init end');

      ]]>
    </v:script>
  </v:on-init>
  <v:form name="form1" type="simple" method="POST" action="nntpf_browser.vspx">
    <table class="vdir_headertable" width="100%" border="0" cellspacing="0" cellpadding="2">
      <tr class="vdir_headertr" align="left">
        <td class="vdir_headertd">
          <label for="t_path">Contents of</label>
          <v:text name="t_path"
                  xhtml_id="t_path"
                  value="''"
                  format="%s">
            <v:before-render>
              <v:script>
                <![CDATA[

--  dbg_printf ('t_path before-render');
  control.ufl_value := self.curpath;

                ]]>
              </v:script>
            </v:before-render>
          </v:text>
          <v:button name="b_go_path" value="Go" action="simple">
            <v:on-post>
              <v:script>
                <![CDATA[

--  dbg_printf ('b_go_path on-post');
  self.curpath := self.t_path.ufl_value;

  if (length (self.curpath) > 1)
    self.curpath := rtrim (self.curpath, self.dir_separator);

    -- self.ds_items.vc_reset ();
    self.ds_items.vc_data_bind (e);

                ]]>
              </v:script>
            </v:on-post>
          </v:button>
        </td>
        <td class="vdir_headertd">
          <v:button name="b_up"
                    style="image"
                    value="--'../vspx/browser/images/16x16/folder_up.gif'"
                    xhtml_alt="Up one level"
                    action="simple">
            <v:before-render>
              <v:script>
                <![CDATA[

--  dbg_printf ('b_up before-render');
  control.ufl_active := case when length (self.curpath) > 0 then 1 else 0 end;

                ]]>
              </v:script>
            </v:before-render>
            <v:on-post>
              <v:script>
                <![CDATA[

--  dbg_printf ('b_up on-post');
  declare pos integer;
  pos := strrchr (self.curpath, self.dir_separator[0]);

  if (isnull (pos))
    pos := 0;

  self.curpath := left (self.curpath, pos);

  if (self.dir_select <> 0)
    self.sel_items := concat (self.curpath, self.dir_separator);
  -- self.ds_items.vc_reset();
  self.ds_items.vc_data_bind (e);

                ]]>
              </v:script>
            </v:on-post>
          </v:button>
        </td>
        <td class="vdir_headertd">
          <v:button name="b_create"
                    style="image"
                    value="../vspx/browser/images/16x16/folder_new.gif"
                    xhtml_alt="Create new folder"
                    action="simple">
            <v:before-render>
              <v:script>
                <![CDATA[

--  dbg_printf ('b_create before-render');
  control.ufl_active := case when length (self.crfolder_proc_name) > 0 then 1 else 0 end;

                ]]>
              </v:script>
            </v:before-render>
            <v:on-post>
              <v:script>
                <![CDATA[

--  dbg_printf ('b_create on-post');
  self.crfolder_mode := case when self.crfolder_mode <> 0 then 0 else 1 end;
                ]]>
              </v:script>
            </v:on-post>
          </v:button>
        </td>
      </tr>
      <v:template name="temp_crfold"
                  type="simple"
                  condition="self.crfolder_mode &lt;&gt; 0">
        <tr class="vdir_headertr" align="left">
          <td class="vdir_headertd" colspan="3">
            <label for="t_newfolder">New folder</label>
            <v:text name="t_newfolder"
                    xhtml_id="t_newfolder"
                    value="''"
                    format="%s"/>
            <v:button name="b_new_folder"
                      value="Create"
                      action="simple">
              <v:on-post>
                <v:script>
                  <![CDATA[

--  dbg_printf ('b_new_folder on-post');
  if (length (self.t_newfolder.ufl_value) > 0 and
      length (self.crfolder_proc_name) > 0)
    {
--      dbg_printf ('XXXXXXXXXXXXXXXXXXXOOOOOOOOOOOOOOOOaaaaaaaaa self.crfolder_proc_name: %s', self.crfolder_proc_name);
      CALL (self.crfolder_proc_name)(self.curpath, self.t_newfolder.ufl_value);
      -- self.ds_items.vc_reset ();
      self.ds_items.vc_data_bind (e);
    }

--  dbg_obj_print('crfolder', self.curpath, self.t_newfolder.ufl_value);
  self.crfolder_mode := 0;

                  ]]>
                </v:script>
              </v:on-post>
            </v:button>
          </td>
        </tr>
      </v:template>
    </table>
    <v:data-set name="ds_items"
                data="--CALL (self.content_proc_name)(curpath, filter)"
                meta="--CALL (self.content_meta_proc_name)()"
                nrows="15"
                scrollable="1"
                width="80">
      <v:param name="curpath"
               value="self.curpath" />
      <v:param name="filter"
               value="self.filter" />
      <v:template name="header1"
                  type="simple"
                  name-to-remove="table"
                  set-to-remove="bottom">
        <table class="vdir_listtable"
               width="100%"
               border="0"
               cellspacing="0"
               cellpadding="2">
          <tr class="vdir_listheader">
            <td/>
            <td>Name</td>
            <?vsp
                  declare j integer;
                  j := 3;
                  while (j < length ((control.vc_parent as vspx_data_set).ds_row_meta))
                    {
                      http ('<td>');
                      http (coalesce ((control.vc_parent as vspx_data_set).ds_row_meta[j], ''));
                      http ('</td>');
                      j := j + 1;
                    }
            ?>
          </tr>
          <?vsp if (length (self.curpath) > 0) { ?>
          <tr class="vdir_listrow">
            <td>
              <v:button name="b_up2"
                        style="image"
                        value="../vspx/browser/images/16x16/folder_up.gif"
                        xhtml_alt="Up one level"
                        action="simple">
                <v:on-post>
                  <v:script>
                    <![CDATA[

--  dbg_printf ('b_up2 on-post');
  declare pos integer;
  declare before_path varchar;

  pos := strrchr (self.curpath, self.dir_separator[0]);

  if (isnull (pos))
    pos := 0;

  before_path := self.curpath;
  self.curpath := left (self.curpath, pos);
  if (self.content_proc_name = 'nntpf_browse_proc')
    {
      declare state, msg, descs, rows any;
      state := '00000';
      exec('sys_dirlist (?, ?)', state, msg, vector (self.curpath, 0));

      if (state <> '00000')
        self.curpath := before_path;
    }

  if (self.dir_select <> 0)
    self.sel_items := concat (self.curpath, self.dir_separator);
  -- self.ds_items.vc_reset ();

  self.ds_items.vc_data_bind (e);

                    ]]>
                  </v:script>
                </v:on-post>
              </v:button>
            </td>
            <?vsp
              http (sprintf ('<td colspan="%d"/>',
                             length ((control.vc_parent as vspx_data_set).ds_row_meta)));
            ?>
          </tr>
          <?vsp } ?>
        </table>
      </v:template>
      <v:template name="rows" type="repeat">
        <v:template name="template4"
                    type="browse"
                    name-to-remove="table"
                    set-to-remove="both">
          <table>
            <tr class="vdir_listrow">
          <?vsp
  declare imgname varchar;
  declare rowset any;

  rowset := (control as vspx_row_template).te_rowset;
  if (length (rowset) > 2 and not isnull (rowset[2]))
    imgname := rowset[2];
  else if (rowset[0] <> 0)
    imgname := '../vspx/browser/images/16x16/folder.gif';
  else
    imgname := '../vspx/browser/images/16x16/generic_file.gif';
          ?>
              <td><img src="<?V imgname ?>"/></td>
              <td nowrap="1">
                <?vsp if (self.dir_select = 0 or rowset[0] <> 0) { ?>
                  <v:button name="b_item"
                            style="url"
                            action="simple"
                            value="--(control.vc_parent as vspx_row_template).te_rowset[1]"
                            format="%s">
                    <v:on-post>
                      <script>
                        <![CDATA[

--  dbg_printf ('b_item on-post');
  declare before_path varchar;

  if ((control.vc_parent as vspx_row_template).te_rowset[0] <> 0)
    {
      if (length (self.curpath) > 0)
        self.curpath := concat( self.curpath, self.dir_separator);
        before_path := self.curpath;
        self.curpath := concat (self.curpath,
                                self.quote_char,
                                (control.vc_parent as vspx_row_template).te_rowset[1],
                                self.quote_char);
      if (self.content_proc_name = 'nntpf_browse_proc')
        {
          declare state, msg, descs, rows any;
          state := '00000';
          exec ('sys_dirlist(?, ?)',
                state,
                msg,
                vector (self.curpath, 0));

          if (state <> '00000')
            self.curpath := before_path;
        }

      -- self.ds_items.vc_reset();
      self.ds_items.vc_data_bind (e);

      if (self.dir_select <> 0)
        self.sel_items := concat(self.curpath, self.dir_separator);
    }
  else if (self.dir_select = 0)
    {
      if (self.multi_select <> 0 and length (self.sel_items) > 0)
        self.sel_items := concat (self.sel_items,
                                  ',',
                                  concat (self.curpath,
                                          self.dir_separator,
                                          self.quote_char,
                                          (control.vc_parent as vspx_row_template).te_rowset[1],
                                          self.quote_char));
      else
        self.sel_items := concat (self.curpath,
                                  self.dir_separator,
                                  self.quote_char,
                                  (control.vc_parent as vspx_row_template).te_rowset[1],
                                  self.quote_char);
    }
--  dbg_printf ('b_item on-post end');

                        ]]>
                      </script>
                    </v:on-post>
                  </v:button>
                <?vsp } else {
                   http( rowset[1] );
                 } ?>
              </td>
              <?vsp
  declare j integer;
  j := 3;
  while (j < length (rowset))
    {
      http( '<td>' || coalesce (rowset[j], '') || '</td>');
      j := j + 1;
    }
              ?>
            </tr>
          </table>
        </v:template>
      </v:template>
      <v:template name="template3"
                  type="simple"
                  name-to-remove="table"
                  set-to-remove="top">
        <table></table>
        <table class="vdir_listtable"
               cellpadding="0">
          <tr class="vdir_listrow">
            <td align="right">
              <v:button name="ds_items_prev"
                        action="simple"
                        value="&lt;&lt;"
                        xhtml:size="10pt"/>
            </td>
            <td align="left">
              <v:button name="ds_items_next"
                        action="simple"
                        value="&gt;&gt;"
                        xhtml:size="10pt"/>
            </td>
          </tr>
        </table>
      </v:template>
    </v:data-set>
    <table>
      <tr>
        <td>Resource Name</td>
        <td>
          <v:text name="item_name"
                  value="--''"
                  type="simple"
                  xhtml_size="18" >
            <v:before-render>
              <script>
                <![CDATA[
--  dbg_printf ('item_name before-render');
  control.ufl_value := self.sel_items;

                ]]>
              </script>
            </v:before-render>
          </v:text>
        </td>
        <td>
          <input type="button" name="b_return" value="Select"
                 onClick="javascript:  selectRow ('form1', '(NULL)','')" />

          <!--v:button name="b_return" action="return" value="Select" xhtml_onClick="javascript: this.<?V self.retname ?> = opener.<?V self.retname ?>; if (<?V self.retname ?> != null ) <?V self.retname ?>.value = document.form1.item_name.value; opener.focus(); close();">
            <v:field name="filename" ref="item_name"/>
          </v:button-->
          <v:button name="b_cancel" action="simple" value="Cancel" xhtml_onClick="javascript: if (opener != null) opener.focus(); window.close()"/>
        </td>
      </tr>
      <tr>
        <td>Filter</td>
        <td>
          <v:text name="t_filter" value="--''" type="simple" xhtml_size="10" >
            <v:before-render>
              <v:script>
                <![CDATA[

--  dbg_printf ('t_filter before-render');
  control.ufl_value := self.filter;

                ]]>
              </v:script>
            </v:before-render>
          </v:text>
          <v:button name="b_apply" action="simple" value="Apply">
            <v:on-post>
              <v:script>
                <![CDATA[

  self.filter := self.t_filter.ufl_value;
  -- self.ds_items.vc_reset();
  self.ds_items.vc_data_bind(e);

                ]]>
              </v:script>
            </v:on-post>
          </v:button>
        </td>
        <td/>
      </tr>
    </table>
  </v:form>
</v:page>
</body>
</html>
