#!/usr/local/bin/perl
# edit_mods.cgi
# Form for installing and removing usermin modules

require './usermin-lib.pl';
$access{'mods'} || &error($text{'acl_ecannot'});
&header($text{'mods_title'}, "");
print "<hr>\n";

# Display installation form
print "<table width=100%><tr><td valign=top>\n";
print "$text{'mods_desc1'}</td><td valign=top>";

print "<form action=install_mod.cgi enctype=multipart/form-data method=post>\n";
print "<table border>\n";
print "<tr $tb> <td><b>$text{'mods_install'}</b></td> </tr>\n";
print "<tr $cb> <td nowrap>\n";
print "<input type=radio name=source value=0 checked> $text{'mods_local'}\n";
print "<input name=file size=40>\n";
print &file_chooser_button("file", 0),"<br>\n";
print "<input type=radio name=source value=1> $text{'mods_uploaded'}\n";
print "<input name=upload type=file size=30><br>\n";
print "<input type=radio name=source value=2> $text{'mods_ftp'}\n";
print "<input name=url size=40><br>\n";
print "&nbsp;" x 5;
print "<input type=checkbox name=nodeps value=1> $text{'mods_nodeps'}<br>\n";
print "</td></tr></table>\n";
print "<input type=submit value=\"$text{'mods_installok'}\">\n";
print "</form></td></tr></table> <hr>\n";

# Display deletion form
print "<table width=100%><tr>\n";
print "<td valign=top>$text{'mods_desc3'}</td> <td>\n";
print "<form action=delete_mod.cgi>\n";
print "<table border width=100%>\n";
print "<tr $tb> <td valign=top><b>$text{'mods_delete'}</b></td> </tr>\n";
print "<tr> <td $cb><select multiple width=300 name=mod size=10>\n";
$version = &get_usermin_version();
&get_usermin_miniserv_config(\%miniserv);
$home = $miniserv{'root'} eq '/usr/local/useradmin';
@mlist = &list_modules();
foreach $m (@mlist) {
	if (&check_usermin_os_support($m)) {
		local @st = stat("$miniserv{'root'}/$m->{'dir'}");
		local @tm = localtime($st[9]);
		local $vstr = $m->{'version'} == $version ? "" :
			      $m->{'version'} ? "(v. $m->{'version'})" :
			      $home ? "" :
			      sprintf "(%d/%d/%d)",
				      $tm[3], $tm[4]+1, $tm[5]+1900;
		printf "<option value='%s'>%s %s\n",
			$m->{'dir'}, $m->{'desc'}, $vstr;
		}
	}
print "</select></td> </tr></table>\n";
print "<input type=submit value=\"$text{'mods_deleteok'}\">\n";
print "</form></td></tr></table>\n";
print "<hr>\n";

&footer("", $text{'index_return'});

