%doc>
#
# $Id: sql-test2.html,v 1.10 2002/03/07 09:20:06 fpmip Exp $
#
# sql-test.html is an example of how to use sql queries
# Authors : Tycho Fruru
# Alexandre Dulaunoy
# Copyright (C) 2001, 2002 Tycho Fruru
# Copyright (C) 2001, 2002 Conostix S.A. Luxembourg - Tycho Fruru
# Copyright (C) 2001, 2002 Alexandre Dulaunoy
# This program 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; either version 2 of the License, or (at your
# option) any later version. See .
#
# 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.
#
%doc>
<%args>
$session
$action=>"none"
$agent_id=>"0"
%args>
<%perl>
my $agent_query = "select agent_id,agent_type_name,agent_location from agents ".
"where exists (select login_name from user_rights where login_name = '".$session->{userid}."' and ".
"user_rights.agent_id = agents.agent_id and can_view = 't') ".
"order by agent_id";
my @results = $m->comp('../internal/sql-query.ipfc',query=>$agent_query);
if ($action eq "add") {
my (@x,@xsorted);
my ($cpt,$found,$resultaction,$where);
@x = split(/,/, $session->{agentview});
foreach my $element (@x) {
if ($agent_id eq $element){
$found = "1";
$where=$cpt;
}
$cpt++;
}
if ($found eq "") {
$x[$cpt] = $agent_id;
$session->{'lastaction'}="agent $agent_id added";
} else {
$session->{'lastaction'}="agent already in viewer";
}
@xsorted = sort { $a <=> $b } @x;
$session->{agentview} = join(',', @xsorted);
} elsif ($action eq "remove") {
my (@x,@xsorted);
my ($cpt, $found,$where);
@x = split(/,/, $session->{agentview});
foreach my $element (@x) {
if ($agent_id eq $element) {
$found = "1";
$where=$cpt;
}
$cpt++;
}
if ($found eq "1") {
splice @x, $where, 1;
$session->{'lastaction'}="agent $agent_id removed"
} else {
$session->{'lastaction'}="agent not in viewer";
}
@xsorted = sort { $a <=> $b } @x;
$session->{agentview} = join(',', @xsorted);
} elsif ($action eq "none") {
$session->{'lastaction'}="none";
}
%perl>
<%perl>
my $return = $m->comp('../internal/head-page.html',title=>'Initial workscreen',session=>$session);
%perl>
| ID |
Type |
Name |
Location |
% my @x = split(/,/, $session->{agentview});
% foreach my $entry (@x) {
% my $querya = "select agent_enabled,agent_id,agent_type_name,agent_location,agent_name from agents where agent_id=$entry";
% my @results = $m->comp('../internal/sql-query.ipfc',query=>$querya);
% my $cpt;
% my $agentid;
% my $current_line;
% foreach $current_line (@results) {
| <% $current_line->[1] %> |
<% $current_line->[2] %> |
<% $current_line->[4] %> |
<% $current_line->[3] %> |
% }
%}
<%perl>
my $endbody = $m->comp('../internal/end-page.html');
%perl>