<?xml version="1.0" encoding="UTF-8"?>
<!--
 -
 -  $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="channels" decor="template/template.vspx" style="template/template.xsl" fast-render="1" button-anchors="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="sortChange" arglist="in columnName varchar">
    <![CDATA[
      if (columnName = '')
        return;
      self.ds.vc_reset();
      if (self.c_order = columnName)
      {
        self.c_direction := either(equ(self.c_direction, 'asc'), 'desc', 'asc');
      } else {
        self.c_direction := 'asc';
      }
      self.c_order := columnName;
    ]]>
  </v:method>

  <v:method name="pshCheck" arglist="">
    <![CDATA[
      return case when ENEWS.WA.pshCheck () and not isnull (self.v_psh) then 1 else 0 end;
    ]]>
  </v:method>

  <vm:pagetitle>Feeds</vm:pagetitle>
  <vm:pagewrapper>
    <vm:header>Feeds</vm:header>
    <vm:variables>
      <v:variable name="c_order" persist="1" type="varchar" default="'EF_TITLE'" />
      <v:variable name="c_direction" persist="1" type="varchar" default="'asc'" />

      <v:variable name="v_mode" type="varchar" default="''" persist="0"/>
      <v:variable name="v_id" param-name="id" type="integer" persist="0"/>
      <v:variable name="v_feed_id" param-name="id" type="integer" persist="0"/>
      <v:variable name="v_feed_uri" type="varchar" default="''" persist="0"/>
      <v:variable name="v_title" type="varchar" default="''"/>
      <v:variable name="v_home" type="varchar" default="''"/>
      <v:variable name="v_update_period" type="varchar" default="'daily'"/>
      <v:variable name="v_update_frequency" type="integer" default="4"/>
      <v:variable name="v_store_days" type="integer" default="30"/>
      <v:variable name="v_tags" type="varchar" default="''" persist="0"/>
      <v:variable name="v_folder_name" type="varchar" default="''"/>
      <v:variable name="v_folder_id" type="varchar" default="'0'"/>
      <v:variable name="v_directory_name" type="varchar" default="''"/>
      <v:variable name="v_directory_id" type="varchar" default="'0'"/>
      <v:variable name="v_graph" type="varchar" default="''"/>
      <v:variable name="v_psh" type="varchar" default="null"/>
      <v:variable name="v_psh_enabled" type="integer" default="1"/>
      <v:variable name="v_acl" type="varchar" default="null"/>
    </vm:variables>
    <vm:pagebody>
      <v:before-render>
        <![CDATA[
          self.F1.uf_action := ENEWS.WA.utf2wide (ENEWS.WA.page_url (self.domain_id, 'channels.vspx'));
        ]]>
      </v:before-render>
      <v:template name="t1" type="simple" enabled="--either(equ(self.v_mode, ''), 1, 0)">
          <div style="padding: 0 0 0.5em 0;">
          <v:button name="btn_subscribe" action="simple" value="subscribe" xhtml_class="button" xhtml_alt="Subscribe feed">
              <v:on-post>
                <![CDATA[
                self.vc_redirect (ENEWS.WA.utf2wide (ENEWS.WA.page_url (self.domain_id, 'channels_create.vspx')));
                ]]>
              </v:on-post>
            </v:button>
          <v:button name="btn_delete" value="delete" action="simple" xhtml_onclick="javascript: return confirmAction(\'Are you sure that you want to delete selected feed(s)?\', this.form, \'cb_item\', \'No feeds were selected to be deleted.\');" xhtml_class="button" xhtml_alt="Delete selected feed(s)">
            <v:on-post>
              <![CDATA[
                declare i integer;

                for (i := 0; i < length(e.ve_params); i := i + 2)
                {
                  if (e.ve_params[i] = 'cb_item')
                  {
                    declare exit handler for sqlstate '*'
                    {
                      rollback work;
                      goto _next;
                    };
                    commit work;

                    ENEWS.WA.channel_delete (e.ve_params[i+1]);
                  }
                  _next:;
                }
                ENEWS.WA.tags_refresh(self.domain_id, self.account_id, 0);
                self.vc_data_bind(e);
              ]]>
            </v:on-post>
          </v:button>
          <v:button name="btn_refresh" value="refresh" action="simple" xhtml_onclick="javascript: return anySelected(this.form, \'cb_item\', \'No feeds were selected to be refreshed.\');" xhtml_class="button" xhtml_alt="Refresh selected feed(s)">
            <v:on-post>
              <![CDATA[
                declare i integer;

                for (i := 0; i < length(e.ve_params); i := i + 2)
                {
                  if (e.ve_params[i] = 'cb_item')
                  {
                    declare exit handler for sqlstate '*'
                    {
                      rollback work;
                      goto _next;
                    };
                    commit work;

                     ENEWS.WA.feed_refresh(e.ve_params[i+1]);
                  }
                  _next:;
                }
                self.vc_data_bind (e);
              ]]>
            </v:on-post>
          </v:button>
            <div class="menuBar" id="exportBar">
            <a class="menuButton button2" onMouseDown="return this.blur();" onclick="return menuPopup(this, 'exportMenu');" title="Export Feeds">export</a>
              <div class="menu" id="exportMenu">
                <?vsp
              http(sprintf('<a class="menuItem" href="%sOFM.ocs" target="_blank" title="%s"><img src="image/%s" border="0" alt="%s"/> %s</a>', ENEWS.WA.dav_url (self.domain_id), 'OCS Export', 'blue-icon-16.gif', 'OCS Export', 'OCS'));
              http(sprintf('<a class="menuItem" href="%sOFM.opml" target="_blank" title="%s"><img src="image/%s" border="0" alt="%s"/> %s</a>', ENEWS.WA.dav_url (self.domain_id), 'OPML Export', 'blue-icon-16.gif', 'OPML Export', 'OPML'));
              http(sprintf('<a class="menuItem" href="%sOFM.foaf" target="_blank" title="%s"><img src="image/%s" border="0" alt="%s"/> %s</a>', ENEWS.WA.dav_url (self.domain_id), 'FOAF Export', 'foaf.png', 'FOAF Export', 'FOAF'));
                ?>
              </div>
            </div>
          </div>
      <v:data-source name="dsrc" expression-type="sql" nrows="0" initial-offset="0">
        <v:before-data-bind>
          <![CDATA[
            self.sortChange(get_keyword('sortColumn', e.ve_params, ''));
            control.ds_nrows := ENEWS.WA.settings_rows (self.settings);
            control.ds_sql := sprintf('select EFD_ID, EF_ID, EF_URI, coalesce(coalesce(EFD_TITLE, EF_TITLE), \'~no title~\') EF_TITLE, cast(ENEWS.WA.channel_feeds(EF_ID) as integer) EF_COUNT from ENEWS.WA.FEED join ENEWS.WA.FEED_DOMAIN on EFD_FEED_ID = EF_ID where EFD_DOMAIN_ID = %d', self.domain_id);
            control.ds_sql := concat(control.ds_sql, ' order by ', self.c_order, ' ', self.c_direction);
          ]]>
        </v:before-data-bind>
          <v:after-data-bind>
            control.ds_make_statistic ();
          </v:after-data-bind>
      </v:data-source>
      <v:data-set name="ds" data-source="self.dsrc" scrollable="1">
          <v:template name="ds_header" type="simple" name-to-remove="table" set-to-remove="bottom">
            <table id="channels" class="ODS_grid" cellspacing="0">
              <thead>
                <tr>
                  <th class="checkbox">
                    <input type="checkbox" name="cb_all" value="Select All" onClick="selectAllCheckboxes(this.form, this, 'cb_item')" title="Select All" />
                  </th>
                  <?vsp http (DB.DBA.wa_show_column_header ('Title', 'EF_TITLE', self.c_order, self.c_direction, ' width="50%"')); ?>
                  <?vsp http (DB.DBA.wa_show_column_header ('Feed URL', 'EF_URI', self.c_order, self.c_direction, ' width="50%"')); ?>
                  <?vsp http (DB.DBA.wa_show_column_header ('Retrieved', 'EF_COUNT', self.c_order, self.c_direction)); ?>
                  <th class="action">Action</th>
                </tr>
              </thead>
            </table>
          </v:template>

          <v:template name="ds_repeat" type="repeat" name-to-remove="" set-to-remove="">

            <v:template name="ds_empty" type="if-not-exists" name-to-remove="table" set-to-remove="both">
              <table>
                <tr>
                  <td colspan="5">No feeds</td>
                </tr>
              </table>
            </v:template>

            <v:template name="ds_browse" type="browse" name-to-remove="table" set-to-remove="both">
              <table>
                <tr>
                  <td class="checkbox">
                    <?vsp
                      http (sprintf ('<input type="checkbox" name="cb_item" value="%d" title="%V" />', control.te_rowset[0], control.te_rowset[2]));
                    ?>
                  </td>
                  <td>
                    <v:label value="--(control.vc_parent as vspx_row_template).te_column_value('EF_TITLE')" format="%s"/>
                  </td>
                  <td>
                    <v:label value="--(control.vc_parent as vspx_row_template).te_column_value('EF_URI')" format="%s"/>
                  </td>
                  <td align="right">
                    <v:label value="--(control.vc_parent as vspx_row_template).te_column_value('EF_COUNT')" format="%d"/>
                  </td>
                  <td class="action">
                    <v:button name="btn_edit" value="edit" action="simple" xhtml_class="button" xhtml_alt="edit feed">
                      <v:on-post>
                        <![CDATA[
                          self.v_id := (control.vc_parent as vspx_row_template).te_column_value('EFD_ID');
                          self.v_mode := 'update';
                          self.vc_data_bind (e);
                        ]]>
                      </v:on-post>
                    </v:button>
                  </td>
                </tr>
              </table>
            </v:template>

          </v:template>

          <v:template name="ds_footer" type="simple" name-to-remove="table" set-to-remove="top">
            <table>
              <tfoot>
                <tr align="right" >
                  <td colspan="5">
                  <vm:ds-navigation data-set="ds"/>
                </td>
              </tr>
              </tfoot>
            </table>
          </v:template>

        </v:data-set>
        <script type="text/javascript">
          <![CDATA[
            coloriseTable('channels');
          ]]>
        </script>
      </v:template>
      <v:template name="t3" type="simple" enabled="--either(equ(self.v_mode, 'update'), 1, 0)">
        <v:before-data-bind>
          <![CDATA[
            declare exit handler for not found goto _end;
            declare params any;

            params := self.vc_page.vc_event.ve_params;
            if (isnull(get_keyword('f_title', params)))
            {
               select b.EF_ID,
                      b.EF_URI,
                      b.EF_HOME_URI,
                      b.EF_UPDATE_PERIOD,
                      b.EF_UPDATE_FREQ,
                      b.EF_STORE_DAYS,
                      b.EF_PSH_SERVER,
                      b.EF_PSH_ENABLED,
                      a.EFD_TITLE,
                      a.EFD_GRAPH,
                      a.EFD_TAGS,
                      a.EFD_FOLDER_ID,
                      c.EFD_DIRECTORY_ID,
                      a.EFD_ACL
                 into self.v_feed_id,
                      self.v_feed_uri,
                      self.v_home,
                      self.v_update_period,
                      self.v_update_frequency,
                      self.v_store_days,
                      self.v_psh,
                      self.v_psh_enabled,
                      self.v_title,
                      self.v_graph,
                      self.v_tags,
                      self.v_folder_id,
                      self.v_directory_id,
                      self.v_acl
                from ENEWS.WA.FEED_DOMAIN a
                       join ENEWS.WA.FEED b on b.EF_ID = a.EFD_FEED_ID
                          left join ENEWS.WA.FEED_DIRECTORY c on c.EFD_FEED_ID = a.EFD_FEED_ID
                where a.EFD_ID = self.v_id;

              self.rdf_iri := SIOC..feed_iri (self.v_feed_id);
              return;
            }

          _end:
            self.v_title := get_keyword('f_title', params, '');
            self.v_home := get_keyword('f_home', params, '');
            self.v_update_period := get_keyword('f_update_period', params, 'daily');
            self.v_update_frequency := get_keyword('f_update_frequency', params, '4');
            self.v_store_days := get_keyword('f_store_days', params, '');
            self.v_psh_enabled := get_keyword('f_psh_enabled', params, '0');
            self.v_tags := get_keyword('f_tags', params, '');
            self.v_folder_id := get_keyword('f_folder_id', params, '');
            self.v_folder_name := get_keyword('f_folder_name', params, '');
            self.v_directory_id := get_keyword('f_directory_id', params, '');
            self.v_directory_name := get_keyword('f_directory_name', params, '');
            self.v_acl := null;
          ]]>
        </v:before-data-bind>
        <div class="form-header">
          Feed
        </div>
        <div id="p" class="c1">
          <div class="tabs">
            &nbsp;<vm:tabCaption tab="p" tabsCount="2" tabNo="0" caption="Main" />
            &nbsp;<vm:tabCaption tab="p" tabsCount="2" tabNo="1" caption="Sharing" />
          </div>
          <div class="contents">
            <div id="p_content_0" class="tabContent">
              <table class="form-body" cellspacing="0">
            <tr>
              <th>
                <v:label value="Feed URL"/>
              </th>
              <td class="text">
                <v:label value="--self.v_feed_uri"/>
              </td>
            </tr>
            <tr>
              <th>
                <v:label for="f_title" value="Title"/>
              </th>
              <td>
                <v:text name="f_title" null-value="--''" value="--self.v_title" fmt-function="ENEWS.WA.utf2wide" xhtml_class="textbox" xhtml_size="70%"/>
              </td>
            </tr>
            <tr>
              <th>
                <v:label for="f_home" value="Feed Home"/>
              </th>
              <td>
                <v:text name="f_home" null-value="--''" value="--self.v_home" xhtml_class="textbox" xhtml_size="70%"/>
              </td>
            </tr>
            <v:template name="t4" type="simple" enabled="--self.pshCheck()">
              <tr>
                <th>
                  PubSubHub Server
                </th>
                <td>
                  <v:label value="--self.v_psh"/>
                </td>
              </tr>
              <tr>
                <th>
                  <v:label for="f_psh_enabled" value="PubSubHub Enable"/>
                </th>
                <td>
                  <v:check-box name="f_psh_enabled" is-boolean="1" true-value="1" false-value="0" value="--self.v_psh_enabled">
                 	  <v:after-data-bind>
                 		  <![CDATA[
                 		    if (not ENEWS.WA.check_feeds_grants (self.domain_id, self.account_id))
                          control.vc_add_attribute ('disabled', 'disabled');
            			    ]]>
            			  </v:after-data-bind>
                  </v:check-box>
                </td>
              </tr>
            </v:template>
            <v:template name="t5" type="simple" enabled="--case when (ENEWS.WA.check_feeds_grants (self.domain_id, self.account_id) = 1) then 1 else 0 end">
              <tr>
                <th>
                  <v:label for="f_update_period" value="Update period"/>
                </th>
                <td>
                  <v:select-list name="f_update_period">
                    <v:item value="daily" name="daily" />
                    <v:item value="weekly" name="weekly" />
                    <v:item value="monthly" name="monthly" />
                    <v:item value="yearly" name="yearly" />
                    <v:before-data-bind>
                      <![CDATA[
                        control.ufl_value := self.v_update_period;
                      ]]>
                    </v:before-data-bind>
                  </v:select-list>
                </td>
              </tr>
              <tr>
                <th>
                  <v:label for="f_update_frequency" value="Update frequency"/>
                </th>
                <td>
                  <v:text name="f_update_frequency"
                          null-value="--''"
                          value="--self.v_update_frequency"
                          xhtml_class="textbox"
                          xhtml_size="5"/>
                </td>
              </tr>
              <tr>
                <th>
                  <v:label for="f_store_days" value="Store days for items"/>
                </th>
                <td>
                  <v:text name="f_store_days" null-value="--''" value="--self.v_store_days" xhtml_class="textbox" xhtml_size="5"/>
                </td>
              </tr>
            </v:template>
            <tr>
              <th>
                    <v:label for="f_graph" value="RDF Graph"/>
                  </th>
                  <td>
                    <v:text name="f_graph" null-value="''" value="--self.v_graph" xhtml_class="textbox" xhtml_size="70%"/>
                  </td>
                </tr>
                <tr>
                  <th>
                <v:label for="f_tags" value="Tags"/>
              </th>
              <td>
                <v:text name="f_tags" null-value="''" value="--self.v_tags" xhtml_class="textbox" xhtml_size="70%"/>
                <input type="button" value="Clear" onClick="javascript: document.F1.elements['f_tags'].value = ''" class="button" />
              </td>
            </tr>
            <tr>
              <th>
                <v:label for="f_folder_name" value="Feed folder"/>
              </th>
              <td>
                <v:text name="f_folder_name" null-value="''" value="--self.v_folder_name" xhtml_class="textbox" xhtml_size="40%"/>
                <v:data-list name="f_folder_id" value="--self.v_folder_id" sql="select 0 as EFO_ID, 'Select folder ...' as EFO_PATH2, '' as EFO_PATH from WS.WS.SYS_DAV_USER where U_NAME = 'dav' union all select EFO_ID, ENEWS.WA.folder_path2(EFO_DOMAIN_ID, EFO_ID) as EFO_PATH2, ENEWS.WA.folder_path(EFO_DOMAIN_ID, EFO_ID) as EFO_PATH from ENEWS.WA.FOLDER where EFO_DOMAIN_ID = self.domain_id order by EFO_PATH" key-column="EFO_ID" value-column="EFO_PATH2" xhtml_class="select"/>
              </td>
            </tr>
            <v:template name="t6" type="simple" enabled="--case when (ENEWS.WA.check_admin(self.account_id) = 1) then 1 else 0 end">
              <tr>
                <th>
                  <v:label for="f_directory_name" value="Feed directory"/>
                </th>
                <td>
                  <v:text name="f_directory_name" null-value="''" value="--self.v_directory_name" xhtml_class="textbox" xhtml_size="40%"/>
                  <v:data-list name="f_directory_id" value="--self.v_directory_id" sql="select 0 as ED_ID, 'Select directory ...' as ED_PATH2, '' as ED_PATH from WS.WS.SYS_DAV_USER where U_NAME = 'dav' union all select ED_ID, ENEWS.WA.directory_path2(ED_ID) as ED_PATH2, ENEWS.WA.directory_path(ED_ID) as ED_PATH from ENEWS.WA.DIRECTORY order by ED_PATH" key-column="ED_ID" value-column="ED_PATH2" xhtml_class="select"/>
                </td>
              </tr>
            </v:template>
          </table>
        </div>
            <div id="p_content_1" class="tabContent" style="display: none;">
              <fieldset>
                <legend><b>WebID users</b></legend>
              <table class="form-body" cellspacing="0">
                <tr>
                  <td style="width: 90%; background-color: white;">
                      <table id="s_tbl" class="ODS_grid">
                        <thead>
                        <tr>
                          <th width="15%">Type</th>
                          <th>Value</th>
                          <th width="1%" nowrap="nowrap">ACL: (R)ead, (W)rite</th>
                            <th class="action">Action</th>
                        </tr>
                      </thead>
                        <tbody id="s_tbody">
                          <tr id="s_tr_no"><td colspan="4"><b>No Shares</b></td></tr>
                		  <![CDATA[
                		    <script type="text/javascript">
                        <?vsp
                              declare acl any;

                          acl := (select WAI_ACL from DB.DBA.WA_INSTANCE where WAI_ID = self.domain_id);
                          acl := case when isnull (acl) then vector () else deserialize (acl) end;
                              DB.DBA.wa_aci_lines (acl);

                          acl := deserialize (self.v_acl);
                              DB.DBA.wa_aci_lines (acl, self.v_mode);
                        ?>
                		    </script>
                		  ]]>
                        </tbody>
                		</table>
                	</td>
                  <vm:if test="self.v_mode <> 'view'">
                    <td valign="top" nowrap="nowrap">
                      <img class="pointer" src="/ods/images/icons/add_16.png" border="0" alt="Add Share" title="Add Share" onclick="javascript: TBL.createRow('s', null, {fld_1: {mode: 50, onchange: function(){TBL.changeCell50(this);}}, fld_2: {mode: 51, form: 'F1', tdCssText: 'white-space: nowrap;', className: '_validate_ _webid_'}, fld_3: {mode: 52, value: [1, 0, 0], tdCssText: 'width: 1%; white-space: nowrap; text-align: center;'}});" />
                    </td>
                  </vm:if>
                </tr>
              </table>
              </fieldset>
            </div>
          </div>
        </div>
        <div class="form-footer">
          <v:button name="btn_save" action="simple" value="Save" xhtml_alt="Save feed data" xhtml_class="form-button">
            <v:on-post>
              <![CDATA[
                declare N, isAdmin integer;
                declare home varchar;
                declare params any;

                params := self.vc_page.vc_event.ve_params;
                isAdmin := ENEWS.WA.check_feeds_grants (self.domain_id, self.account_id);
                home := null;
                if (trim(self.f_home.ufl_value) <> '')
                  home := trim(self.f_home.ufl_value);

                self.f_title.ufl_value := trim(self.f_title.ufl_value);
                if (is_empty_or_null(self.f_title.ufl_value))
                {
                  self.vc_error_message := 'Please, enter correct title name.';
                  self.vc_is_valid := 0;
                  return;
                }
                if (isAdmin)
                {
                  self.f_update_frequency.ufl_value := trim (cast (self.f_update_frequency.ufl_value as varchar));
                  self.f_store_days.ufl_value := trim(self.f_store_days.ufl_value);
                  if ((not ENEWS.WA.validate('integer', self.f_update_frequency.ufl_value, 0)) or (atoi(self.f_update_frequency.ufl_value) < 1) or (atoi(self.f_update_frequency.ufl_value) > 8))
                  {
                    self.vc_error_message := 'Please, enter correct update frequency value in range [1, 8]!';
                    self.vc_is_valid := 0;
                    return;
                  }
                  if (ENEWS.WA.channel_update_period (self.f_update_period.ufl_value, atoi(self.f_update_frequency.ufl_value)) < 180)
                  {
                    self.vc_error_message := 'Result update interval must be greater than 3 hours. Please, correct update period or/and update frequency values.';
                    self.vc_is_valid := 0;
                    return;
                  }
                  if ((not ENEWS.WA.validate('integer', self.f_store_days.ufl_value, 0)) or (atoi(self.f_store_days.ufl_value) < 1))
                  {
                    self.vc_error_message := 'Please, enter correct store days value!';
                    self.vc_is_valid := 0;
                    return;
                  }
                }

                self.v_tags := ENEWS.WA.tag_prepare (trim (self.f_tags.ufl_value));
                if (not isnull (self.v_tags) and not ENEWS.WA.validate_tags (self.v_tags))
                {
                  self.vc_is_valid := 0;
                  self.vc_error_message := 'The expression is not valid tag.';
                  return;
                }

                self.v_folder_name := trim(self.f_folder_name.ufl_value);
                if (self.v_folder_name <> '')
                {
                  if (not ENEWS.WA.folder_check_name(self.v_folder_name, 1))
                  {
                    self.vc_error_message := 'Please, enter other folder name. This name contains bad characters.';
                    self.vc_is_valid := 0;
                    return;
                  }
                }
                -- validate ACL rules
                DB.DBA.wa_aci_validate (DB.DBA.wa_aci_params (params));

                -- feed
                if (isAdmin)
                {
                  update ENEWS.WA.FEED
                     set EF_TITLE = self.f_title.ufl_value,
                         EF_HOME_URI = home,
                         EF_UPDATE_PERIOD = self.f_update_period.ufl_value,
                         EF_UPDATE_FREQ = atoi(self.f_update_frequency.ufl_value),
                         EF_STORE_DAYS = atoi(self.f_store_days.ufl_value)
                   where EF_ID = self.v_feed_id;

                  -- PubSubHub
                  self.v_psh_enabled := self.f_psh_enabled.ufl_selected;
                  ENEWS.WA.channel_psh_unsubscribe (self.v_feed_id, self.v_psh, self.v_psh_enabled);
                  ENEWS.WA.channel_psh_subscribe (self.v_feed_id, self.v_psh, self.v_psh_enabled);
                }

                -- domain
                ENEWS.WA.channel_domain (self.v_id, self.domain_id, self.v_feed_id, self.f_title.ufl_value, self.v_tags, self.v_folder_name, trim (self.f_folder_id.ufl_value), self.f_graph.ufl_value);
                self.v_acl := serialize (DB.DBA.wa_aci_params (params));
                ENEWS.WA.channel_acl (self.v_id, self.v_acl);

                -- directory
                if (isAdmin)
                {
                  self.v_directory_name := trim(self.f_directory_name.ufl_value);
                  if (self.v_directory_name <> '')
                  {
                    if (not ENEWS.WA.directory_check_name(self.v_directory_name, 1))
                    {
                      self.vc_error_message := 'Please, enter other directory name. This name contains bad characters.';
                      self.vc_is_valid := 0;
                      return;
                    }
                  }
                  ENEWS.WA.channel_directory(self.v_feed_id, self.v_directory_name, trim(self.f_directory_id.ufl_value));
                }

                self.v_mode := '';
                self.vc_data_bind(e);
              ]]>
           </v:on-post>
          </v:button>
          <v:button name="btn_cancel" action="simple" value="Cancel" xhtml_class="form-button">
            <v:on-post>
              <![CDATA[
                self.v_mode := '';
                self.vc_data_bind(e);
             ]]>
           </v:on-post>
          </v:button>
        </div>
      </v:template>
    </vm:pagebody>
  </vm:pagewrapper>
</v:page>
