<TITLE>ARY discussion group administration</TITLE>
<! includeFile("../body"); >

<CENTER>
<FONT SIZE=5>Discussion group administration:</FONT><BR>
(group administration)<BR>
<P></P>

<TABLE WIDTH=400>
<TR><TD><CENTER>
Please, select group and function you wold like to execute
</CENTER></TD></TR>
</TABLE>


<!
$color1="NAVY";
$color2="BLUE";
$color3="#99CCCC";

$sock=msqlConnect();
if ($sock<0) {
   echo("<CENTER><TABLE WIDTH=500 BORDER=2 BGCOLOR=\"$color3\">\n");
   echo("<TR><TD>\n<BR><CENTER>$ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
   exit(0);
   }

if (msqlSelectDB($sock, "leptospira")<0) {
   echo("<CENTER><TABLE WIDTH=400 BORDER=2 BGCOLOR=$color3>\n");
   echo("<TR><TD>\n<BR><CENTER>$ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
   exit(0);
   }

$err="";

if ($delete=="OK") {
   if (msqlQuery($sock, "SELECT sgid FROM subgroup WHERE gid=$nmbr")<0) {
      echo("<CENTER><TABLE WIDTH=400 BORDER=2 BGCOLOR=$color3>\n");
      echo("<TR><TD>\n<BR><CENTER>$ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
      }
   $fd=msqlStoreResult();
   $n=msqlNumRows($fd);
   if ($n>0) {
      $err="Sorry, you can not delete this GROUP.<BR>There are $n subgroups in this group!<BR>You have to delete subgroups first :(";
      echo("<CENTER><TABLE WIDTH=400 BORDER=2 BGCOLOR=$color3>\n");
      echo("<TR><TD>\n<BR><CENTER>$err</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
      exit(0);
      }

   $delete="DELETE FROM group WHERE gid=$nmbr";
   $nmbr=0; $change=0;
   if (msqlQuery($sock, $delete)<0) {
      echo("<CENTER><TABLE WIDTH=400 BORDER=2 BGCOLOR=$color3>\n");
      echo("<TR><TD>\n<BR><CENTER>$ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
      }
   }

if ((int)$change==0) {
   $group="";
   $opis="";
   $radova=0;
   }
else {
   if ($group=="") {
      $err="Title must be supplied.";
      }
   if ($err=="") {
   if ($opis=="") {
      $opis="(none)";
      }

   $radova=(int)$radova;
   $nmbr=(int)$nmbr;
   if ($nmbr>0) {
      $update="UPDATE group SET gname='$group', gdesc='$opis' WHERE gid=$nmbr";
      if (msqlQuery($sock, $update)<0) {
         echo("<CENTER><TABLE WIDTH=400 BORDER=2 BGCOLOR=$color3>\n");
         echo("<TR><TD>\n<BR><CENTER>$ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
         }
      else {
         $group=""; $opis="";
         $chng=0;
         $nmbr=0;
         }
      }
   else {
      if (msqlQuery($sock, "SELECT _seq FROM group")<0) {
         echo("<CENTER><TABLE WIDTH=400 BORDER=2 BGCOLOR=$color3>\n");
         echo("<TR><TD>\n<BR><CENTER>$ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
         exit(0);
         }

      $fd=msqlStoreResult();
      $data=msqlFetchRow($fd);
      $nmbr=(int)$data[0];
      
      $insert="INSERT INTO group VALUES ($nmbr,'$group','$opis')";
      if (msqlQuery($sock, $insert)<0) {
         echo("<CENTER><TABLE WIDTH=400 BORDER=2 BGCOLOR=$color3>\n");
         echo("<TR><TD>\n<BR><CENTER>$ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
         }
      else {
         $group=""; $opis="";
         $chng=0;
         $nmbr=0;
         }
      }
   }
}


if ($err!="") {
         echo("<CENTER><TABLE WIDTH=400 BORDER=2 BGCOLOR=$color3>\n");
         echo("<TR><TD>\n<BR><CENTER>$err</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
}

if (msqlQuery($sock, "SELECT * FROM group ORDER BY gname")<0) {
   echo("<CENTER><TABLE WIDTH=400 BORDER=2 BGCOLOR=$color3>\n");
   echo("<TR><TD>\n<BR><CENTER>$ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
   exit(0);
   }

$fd=msqlStoreResult();
$data=msqlFetchRow($fd);

$tbl=0;

echo("<FORM ACTION=\"group.msql\">\n");
echo("<INPUT TYPE=\"HIDDEN\" NAME=\"change\" VALUE=1>\n");
echo("<TABLE WIDTH=600>\n");
$tbl=1;

$ima=0;
echo("<TR><TD><CENTER><FONT COLOR=\"BLACK\">Group</CENTER></TD><TD></TD><TD><FONT COLOR=\"BLACK\"><CENTER>Description</TD><TD><CENTER></CENTER></TD></TR>\n");

while(#$data>0) {
   if ((int)$nmbr==(int)$data[0]) {
      $ima=1;
      echo("<TR>");
      echo("<INPUT TYPE=\"HIDDEN\" NAME=\"nmbr\" VALUE=\"$nmbr\">\n");
      echo("<TD BGCOLOR=\"$color1\" COLSPAN=2><CENTER><FONT COLOR=\"WHITE\"><INPUT NAME=\"group\" SIZE=10 VALUE=\"$data[1]\"></INPUT></CENTER></TD>");
      echo("<TD BGCOLOR=\"$color2\" COLSPAN=2><FONT COLOR=\"WHITE\"><INPUT NAME=\"opis\" SIZE=40 VALUE=\"$data[2]\"></INPUT></TD></TR>\n");
      }
   else {
      echo("<TR><TD BGCOLOR=\"$color1\"><CENTER><FONT COLOR=\"WHITE\"><A HREF=\"group.msql?nmbr=$data[0]\">$data[1]</A></CENTER></TD><TD BGCOLOR=\"$color3\"><CENTER><A HREF=\"group.msql?delete=OK&nmbr=$data[0]\">*</A></TD><TD BGCOLOR=\"$color2\"><FONT COLOR=\"WHITE\">$data[2]</TD><TD BGCOLOR=\"$color3\"><CENTER><A HREF=\"sgroup.msql?group=$data[0]\">E</A></CENTER></TD></TR>\n");
      }
   $data=msqlFetchRow($fd);
   }
msqlFreeResult($fd);

if ($ima==0) {
      echo("<TR>");
      echo("<TD BGCOLOR=\"$color1\" COLSPAN=2><CENTER><FONT COLOR=\"WHITE\"><CENTER><INPUT NAME=\"group\" VALUE=\"$group\" SIZE=10></INPUT></CENTER></TD>");
      echo("<TD BGCOLOR=\"$color2\" COLSPAN=2><FONT COLOR=\"WHITE\"><INPUT NAME=\"opis\" VALUE=\"$opis\" SIZE=40></INPUT></TD></TR>\n");
      echo("<INPUT TYPE=\"HIDDEN\" NAME=\"nmbr\" VALUE=\"0\">\n");
}

echo("<TR><TD COLSPAN=4><CENTER><TABLE WIDTH=200><TR><TD WIDTH=50%><CENTER><INPUT TYPE=\"reset\" VALUE=\"RESET\"></TD><TD><CENTER><INPUT TYPE=\"submit\" VALUE=\"EDIT\"></TD></TR></TABLE></CENTER></TD></TR>\n");

echo("<TR><TD COLSPAN=3><CENTER></TD></TR>\n");
echo("</TABLE>\n");
echo("</FORM>\n");

>
