--- smeserver-trac-0.4/root/usr/lib/perl5/site_perl/esmith/FormMagick/Panel/trac.pm.newlines 2007-04-27 00:54:46.000000000 -0600
+++ smeserver-trac-0.4/root/usr/lib/perl5/site_perl/esmith/FormMagick/Panel/trac.pm 2008-04-26 09:16:34.000000000 -0600
@@ -1,954 +1,954 @@
-#!/usr/bin/perl -w
-#----------------------------------------------------------------------
-# $Id: trac.pm 69 2007-03-25 13:20:24Z marco $
-# vim: ft=perl ts=4 sw=4 et:
-#----------------------------------------------------------------------
-# Copyright (C) 2007 Marco Hess
-#
-# 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.
-#
-# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#----------------------------------------------------------------------
-
-package esmith::FormMagick::Panel::trac;
-
-use strict;
-use warnings;
-
-use esmith::FormMagick;
-use esmith::AccountsDB;
-use esmith::ConfigDB;
-use esmith::DomainsDB;
-use esmith::cgi;
-use esmith::util;
-use File::Basename;
-use Exporter;
-use Carp;
-use Sys::Syslog;
-
-use constant TRUE => 1;
-use constant FALSE => 0;
-
-our @ISA = qw(esmith::FormMagick Exporter);
-
-our @EXPORT = qw(
- show_trac_projects
- print_trac_field_name
- repositories_list
- group_list
- user_list
- max_trac_project_name_length
- handle_trac_projects
- create_trac_project
- remove_trac_project
- getExtraParams
- print_save_or_add_button
- validate_name
- validate_radio
- wherenext
- maxLength
-);
-
-our $ConfigDB = esmith::ConfigDB->open
- or die "Can't open the Config database : $!\n" ;
-
-our $AccountsDB = esmith::AccountsDB->open
- or die "Can't open the Account database : $!\n" ;
-
-our $DomainsDB = esmith::DomainsDB->open
- or die "Can't open the Domains database : $!\n" ;
-
-
-# fields and records separator for sub records
-use constant FS => "," ;
-use constant RS => ";" ;
-
-=pod
-
-=head1 NAME
-
-esmith::FormMagick::Panels::trac - Trac
-
-=head1 SYNOPSIS
-
-use esmith::FormMagick::Panels::trac
-
-my $panel = esmith::FormMagick::Panel::trac->new();
-$panel->display();
-
-=head1 DESCRIPTION
-
-This module is the backend to the Trac panel, responsible
-for supplying all functions used by that panel. It is a subclass
-of esmith::FormMagick itself, so it inherits the functionality
-of a FormMagick object.
-
-=cut
-
-=head2 new()
-
-Exactly as for esmith::FormMagick
-
-=cut
-
-sub new
-{
- my $proto = shift;
- my $class = ref($proto) || $proto;
- my $self = esmith::FormMagick::new($class);
- $self->{calling_package} = (caller)[0];
-
- return $self;
-}
-
-=head1 HTML GENERATION ROUTINES
-
-Routines for generating chunks of HTML needed by the panel.
-
-=cut
-
-=head2 show_trac_projects()
-
-This function displays a table of trac project environments on the system
-including the links to modify and remove the trac project environment.
-
-=cut
-
-sub show_trac_projects {
- my $fm = shift;
- my $q = $fm->{cgi};
-
- # Setup the various localised text field for the trac project table
- my $name = $fm->localise('TRAC_TABLE_HEADER_NAME');
- my $description = $fm->localise('TRAC_TABLE_HEADER_DESCRIPTION');
- my $domains = $fm->localise('TRAC_TABLE_HEADER_DOMAINS');
- my $repository = $fm->localise('TRAC_TABLE_HEADER_REPOSITORY');
- my $path = $fm->localise('TRAC_TABLE_HEADER_PATH');
- my $access = $fm->localise('TRAC_TABLE_HEADER_ACCESS');
- my $action_h = $fm->localise('TRAC_TABLE_HEADER_ACTION');
- my $view = $fm->localise('TRAC_ACTION_VIEW');
- my $modify = $fm->localise('TRAC_ACTION_MODIFY');
- my $remove = $fm->localise('TRAC_ACTION_REMOVE');
- my $backup = $fm->localise('TRAC_ACTION_BACKUP');
- my $restore = $fm->localise('TRAC_ACTION_RESTORE');
-
- print $q->start_table({-class => 'sme-noborder'}), "\n";
-
- # Check if any repositories exist
- my @repositories = $AccountsDB->get_all_by_prop('type' => 'repository');
- unless ( scalar @repositories )
- {
- print $q->Tr($q->td($q->h2($fm->localise('NO_REPOSITORIES'))));
- return "";
- }
-
- # TODO what about the case that all repositories have been deleted
- # but the Trac project environments are still there? Can we remove the
- # trac projects or do we need to reassign the projects to
- # another repository? The code above prevents us from accessing the
- # trac projects when there are no more repositories.
-
- print $q->Tr($q->td($q->a({-class => "button-like",
- href => "trac?page=0&page_stack=&Next=Next&wherenext=Create"},
- $fm->localise('TRAC_ADD_BUTTON'))));
-
- # Check if any trac projects exist
- my @TracProjects = $AccountsDB->get_all_by_prop('type' => 'trac');
- unless ( scalar @TracProjects )
- {
- print $q->Tr($q->td($q->h2($fm->localise('NO_TRAC_PROJECTS'))));
- return "";
- }
-
- # Show the list of configures trac projects
- print $q->Tr($q->td($q->h2($fm->localise('CURRENT_TRAC_PROJECTS'))));
-
- print $q->Tr($q->td($fm->localise('TRAC_MODIFY_REMOVE_BUTTON_DESCRIPTION')));
-
- print $q->start_table({-CLASS => "sme-border"}),"\n";
- print $q->Tr (
- esmith::cgi::genSmallCell($q, $name, "header"),
- esmith::cgi::genSmallCell($q, $description,"header"),
- esmith::cgi::genSmallCell($q, $domains, "header"),
- esmith::cgi::genSmallCell($q, $repository, "header"),
- esmith::cgi::genSmallCell($q, $path, "header"),
- esmith::cgi::genSmallCell($q, $access, "header"),
- esmith::cgi::genSmallCell($q, $action_h, "header", 3)),"\n";
-
- my $scriptname = basename($0);
-
- foreach my $TracProject (@TracProjects)
- {
- my $trac_name = $TracProject->key();
- my $trac_desc = $TracProject->prop('Description');
- my $trac_domains = join(" ", split(FS, $TracProject->prop('Domains')));
- my $trac_repo = $TracProject->prop('Repository');
- my $trac_path = $TracProject->prop('RepositoryPath');
- my $trac_access = $TracProject->prop('Access') || 'local';
- my $modifiable = $TracProject->prop('Modifiable') || 'yes';
- my $removable = $TracProject->prop('Removable') || 'yes';
-
- my $params = $fm->build_trac_project_cgi_params($trac_name, $TracProject->props());
-
- my $href = "$scriptname?$params&action=modify&wherenext=";
-
- my $actionView = ' ';
- $actionView .= $q->a({href => '/' . $TracProject->key(),
- target => '_blank'}, $view ) . ' ';
-
- my $actionModify = ' ';
- if ($modifiable eq 'yes')
- {
- $actionModify .= $q->a({href => "${href}Modify"}, $modify) . ' ';
- }
-
- my $actionRemove = ' ';
- if ($removable eq 'yes')
- {
- $actionRemove .= $q->a({href => "${href}Remove"}, $remove) . ' ';
- }
-
- my $actionBackup = ' ';
- $actionBackup .= $q->a({href => "${href}Backup"}, $backup) . ' ';
-
- my $actionRestore = ' ';
- $actionRestore .= $q->a({href => "${href}Restore"}, $restore) . ' ';
-
- print $q->Tr(
- esmith::cgi::genSmallCell($q, $trac_name, "normal"),
- esmith::cgi::genSmallCell($q, $trac_desc, "normal"),
- esmith::cgi::genSmallCell($q, $trac_domains, "normal"),
- esmith::cgi::genSmallCell($q, $trac_repo, "normal"),
- esmith::cgi::genSmallCell($q, $trac_path, "normal"),
- esmith::cgi::genSmallCell($q, $trac_access, "normal"),
- esmith::cgi::genSmallCell($q, $actionView, "normal"),
- esmith::cgi::genSmallCell($q, $actionModify, "normal"),
- esmith::cgi::genSmallCell($q, $actionRemove, "normal")
- );
- }
-
- print $q->end_table,"\n";
-
- print $q->end_table,"\n";
-
- return "";
-}
-
-=cut
-
-=head2 print_save_or_add_button()
-
-Prints the ADD button when a new trac project environment is addded and the SAVE buttom
-whem modifications are made.
-
-=cut
-
-sub print_save_or_add_button {
-
- my ($fm) = @_;
-
- my $cgi = $fm->{cgi};
-
- if (($cgi->param("action") || '') eq "modify") {
- $fm->print_button("SAVE");
- } else {
- $fm->print_button("ADD");
- }
-}
-
-=head1 HELPER FUNCTIONS FOR THE PANEL
-
-Routines for modifying the database and signaling events
-from the server-manager panel
-
-=cut
-
-=head2 build_trac_project_cgi_params($fm, $tracprojectname, %oldprops)
-
-Constructs the parameters for the links in the trac project environments table
-
-=cut
-
-sub build_trac_project_cgi_params {
- my ($self, $tracprojectname, %oldprops) = @_;
-
- my %props = (
- page => 0,
- page_stack => "",
- tracName => $tracprojectname,
- );
-
- return $self->props_to_query_string(\%props);
-}
-
-*wherenext = \&CGI::FormMagick::wherenext;
-
-=head2 print_trac_field_name()
-
-Helper function to print the field NAME so that it becomes
-an edit field upon ADD and a fixed field upon MODIFY.
-
-Also read all the account db values so the other fields
-can show the existing values.
-
-=cut
-
-sub print_trac_field_name {
- my $fm = shift;
- my $in = $fm->{cgi}->param('tracName') || '';
- my $action = $fm->{cgi}->param('action') || '';
-
- print qq(
\n);
-
- if ($action eq 'modify' and $in) {
- #-------------------------------------------------------
- # Updating an existing record.
- #--------------------------------------------------------
-
- my $rec = $AccountsDB->get($in);
- my $modifiable = $rec->prop('Modifiable') || 'yes';
- my $removable = $rec->prop('Removable') || 'yes';
-
- print qq(
-
$in
-
-
-
- );
-
- # Read the values for each field from the accounts db and store
- # them in the cgi object so our form will have the correct
- # info displayed.
- my $q = $fm->{cgi};
- if ($rec)
- {
- $q->param(-name=>'tracDescription',-value=>
- $rec->prop('Description'));
-
- $q->param(-name=>'tracRepository',-value=>
- $rec->prop('Repository'));
-
- $q->param(-name=>'tracRepositoryPath',-value=>
- $rec->prop('RepositoryPath'));
-
- # domain list is handled separately
-
- $q->param(-name=>'tracGroups',-value=>
- join(FS, split(FS, $rec->prop('Groups'))));
-
- $q->param(-name=>'tracUsers',-value=>
- join(FS, split(FS, $rec->prop('Users'))));
-
- $q->param(-name=>'tracAccess',-value=>
- $rec->prop('Access')),
- }
- } else {
- #-------------------------------------------------------
- # Adding a new record so allow an entry field for the
- # name.
- #--------------------------------------------------------
- print qq(
-
-
-
- );
- }
-
- print qq(
\n);
- return undef;
-}
-
-
-=head2 print_trac_domains()
-
-When this server has more than one domain this function takes
-the list of domains and returns a string of html checkboxes
-for all these domains.
-
-Those domains that are listed with this Trac environment
-will have their checkbox checked.
-
-=cut
-
-sub print_trac_domains() {
-
- # Retrieve the Trac account name from the CGI parameters
- my $fm = shift;
- my $name = $fm->{'cgi'}->param('tracName');
- my $action = $fm->{'cgi'}->param("action") || '';
- my $out = "";
-
- # Get a full list of all the domains on this server.
- my @domains = $DomainsDB->get_all_by_prop( type => 'domain' );
- my $numdomains = @domains;
-
- # If there is more than one domain, we generate a list
- # of checkboxes. Otherwise we just show the primary domain.
- if ($numdomains > 1) {
-
- # With the Trac account name, get the list of the Domains for which
- # this Trac account is active.
- my $trac_domains_list = "";
- if ($AccountsDB->get($name)) {
- $trac_domains_list = $AccountsDB->get($name)->prop('Domains');
- }
-
- # Split the comma separated list into the individual bits.
- my %trac_domains;
- foreach my $trac_domain ( split ( /,/, $trac_domains_list ) ) {
- $trac_domains{$trac_domain} = 1;
- }
-
- # Now generate the table of domains with a checkbox in front of it.
- # If the domain is in our listed domains for the Trac environment, the
- # checkbox will show checked.
- $out = "
\n";
-
- foreach my $domain (sort @domains) {
-
- # If this is a ADD form, we default check all domains, otherwise only
- # those that are in our Trac project list.
- my $checked = "";
- if ( $action eq 'modify' ) {
- if ( $trac_domains{ $domain->key() } ) {
- $checked = "checked";
- }
- } else {
- $checked = "checked";
- }
-
- $out .= "
\n";
- $out .= "
key . "\">
\n";
- $out .= "
" . $domain->key . "
\n";
- $out .= "
\n";
- }
-
- $out .= "
\n";
- $out .= "
\n";
- $out .= "
\n";
- }
- else
- {
- # We only have a single domain, so we just show this domain but without the
- # checkbox (so it can't be unchecked).
- my $domainname = $ConfigDB->get('DomainName')->value();
- $out = "
\n);
+
+ if ($action eq 'modify' and $in) {
+ #-------------------------------------------------------
+ # Updating an existing record.
+ #--------------------------------------------------------
+
+ my $rec = $AccountsDB->get($in);
+ my $modifiable = $rec->prop('Modifiable') || 'yes';
+ my $removable = $rec->prop('Removable') || 'yes';
+
+ print qq(
+
$in
+
+
+
+ );
+
+ # Read the values for each field from the accounts db and store
+ # them in the cgi object so our form will have the correct
+ # info displayed.
+ my $q = $fm->{cgi};
+ if ($rec)
+ {
+ $q->param(-name=>'tracDescription',-value=>
+ $rec->prop('Description'));
+
+ $q->param(-name=>'tracRepository',-value=>
+ $rec->prop('Repository'));
+
+ $q->param(-name=>'tracRepositoryPath',-value=>
+ $rec->prop('RepositoryPath'));
+
+ # domain list is handled separately
+
+ $q->param(-name=>'tracGroups',-value=>
+ join(FS, split(FS, $rec->prop('Groups'))));
+
+ $q->param(-name=>'tracUsers',-value=>
+ join(FS, split(FS, $rec->prop('Users'))));
+
+ $q->param(-name=>'tracAccess',-value=>
+ $rec->prop('Access')),
+ }
+ } else {
+ #-------------------------------------------------------
+ # Adding a new record so allow an entry field for the
+ # name.
+ #--------------------------------------------------------
+ print qq(
+
+
+
+ );
+ }
+
+ print qq(
\n);
+ return undef;
+}
+
+
+=head2 print_trac_domains()
+
+When this server has more than one domain this function takes
+the list of domains and returns a string of html checkboxes
+for all these domains.
+
+Those domains that are listed with this Trac environment
+will have their checkbox checked.
+
+=cut
+
+sub print_trac_domains() {
+
+ # Retrieve the Trac account name from the CGI parameters
+ my $fm = shift;
+ my $name = $fm->{'cgi'}->param('tracName');
+ my $action = $fm->{'cgi'}->param("action") || '';
+ my $out = "";
+
+ # Get a full list of all the domains on this server.
+ my @domains = $DomainsDB->get_all_by_prop( type => 'domain' );
+ my $numdomains = @domains;
+
+ # If there is more than one domain, we generate a list
+ # of checkboxes. Otherwise we just show the primary domain.
+ if ($numdomains > 1) {
+
+ # With the Trac account name, get the list of the Domains for which
+ # this Trac account is active.
+ my $trac_domains_list = "";
+ if ($AccountsDB->get($name)) {
+ $trac_domains_list = $AccountsDB->get($name)->prop('Domains');
+ }
+
+ # Split the comma separated list into the individual bits.
+ my %trac_domains;
+ foreach my $trac_domain ( split ( /,/, $trac_domains_list ) ) {
+ $trac_domains{$trac_domain} = 1;
+ }
+
+ # Now generate the table of domains with a checkbox in front of it.
+ # If the domain is in our listed domains for the Trac environment, the
+ # checkbox will show checked.
+ $out = "
\n";
+
+ foreach my $domain (sort @domains) {
+
+ # If this is a ADD form, we default check all domains, otherwise only
+ # those that are in our Trac project list.
+ my $checked = "";
+ if ( $action eq 'modify' ) {
+ if ( $trac_domains{ $domain->key() } ) {
+ $checked = "checked";
+ }
+ } else {
+ $checked = "checked";
+ }
+
+ $out .= "
\n";
+ $out .= "
key . "\">
\n";
+ $out .= "
" . $domain->key . "
\n";
+ $out .= "
\n";
+ }
+
+ $out .= "
\n";
+ $out .= "
\n";
+ $out .= "
\n";
+ }
+ else
+ {
+ # We only have a single domain, so we just show this domain but without the
+ # checkbox (so it can't be unchecked).
+ my $domainname = $ConfigDB->get('DomainName')->value();
+ $out = "