package GUI::UrlLaunch;

use strict;
use System;

use vars qw(@CATS);
@CATS = ('t3','brocade','switch','switch2','se','tape','ve');

sub update {
  my($q) = @_;

  print Html->body();
  my $G = Labels->read();
  my $L = Labels->read("GUI::UrlLaunch");

  my $urls = Util->deserialize("UrlLaunch.txt") || {};

  print Html->header2("admin.system.url_launch");

  if ($q->{ACTION_update}) {
     foreach my $e (keys %$q) {
         if (substr($e,0,4) eq "url_") {
            my $cat = substr($e,4);
            my $val = $q->{$e};
            my $name = $q->{"name_$cat"};
            my $name2 = $q->{"name2_$cat"};
            my $val2  = $q->{"url2_$cat"};
            $urls->{$cat}[0] = $name;
            $urls->{$cat}[1] = $val;
            $urls->{$cat}[2] = $name2;
            $urls->{$cat}[3] = $val2;
         }
     }
     Util->serialize("UrlLaunch.txt", $urls);
     print Html->info($L->{updated});
  }

  my $out =<<EOF;
<table border=1 cellspacing=0 cellpadding=0 width=90% bgcolor=white cellpadding=2>
  <tr><td bgcolor=#666699 colspan=3>
      <form><input type=hidden name=GO value=GUI::UrlLaunch::update>
      <font color=white><b>$L->{title}
  <tr bgcolor=#CCCCFF>
        <th><b>$L->{type}
        <td><b>$L->{name}
        <td><b>$L->{url}</td>
      </td>
EOF
  if (!$urls->{brocade}[0]) {
    $urls->{brocade} = ["Brocade","http://\$ip"];
  }
  foreach my $cat (@CATS) {
    my $abb = Util->abb("$cat.medium") || $cat;
    $out .= "<tr ><td align=right><b>$abb</b> 1:</td>
                 <td ><input type=text name=name_$cat size=15 value=\"$urls->{$cat}[0]\"></td>
                 <td><input type=text name=url_$cat size=50 value=\"$urls->{$cat}[1]\"></td>
             <tr><td align=right>2:</td>
                 <td><input type=text name=name2_$cat size=15 value=\"$urls->{$cat}[2]\"></td>
                 <td><input type=text name=url2_$cat size=50 value=\"$urls->{$cat}[3]\"></td>
             <tr><td colspan=3></td>
            ";
  }
  $out .= "</table><b><input type=submit name=ACTION_update value=$G->{submit_update}>";
  print $out;

}

1;
