1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
30 # project administration
31 #======================================================================
33 use POSIX qw(strftime);
37 use SL::ReportGenerator;
39 require "bin/mozilla/common.pl";
40 require "bin/mozilla/reportgenerator.pl";
43 $lxdebug->enter_sub();
45 $auth->assert('project_edit');
48 $form->{callback} = build_std_url('action') unless $form->{callback};
50 display_project_form();
52 $lxdebug->leave_sub();
56 $lxdebug->enter_sub();
58 $auth->assert('project_edit');
61 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
62 #/show hhistory button
63 $form->{title} = "Edit";
65 $form->{project} = Projects->get_project('id' => $form->{id}, 'orphaned' => 1);
67 display_project_form();
69 $lxdebug->leave_sub();
73 $lxdebug->enter_sub();
75 $auth->assert('project_edit');
77 $form->{title} = $locale->text('Projects');
79 $form->{CUSTOM_VARIABLES} = CVar->get_configs('module' => 'Projects');
80 ($form->{CUSTOM_VARIABLES_FILTER_CODE},
81 $form->{CUSTOM_VARIABLES_INCLUSION_CODE}) = CVar->render_search_options('variables' => $form->{CUSTOM_VARIABLES},
82 'include_prefix' => 'l_',
83 'include_value' => 'Y');
86 print $form->parse_html_template('projects/search');
88 $lxdebug->leave_sub();
92 $lxdebug->enter_sub();
94 $auth->assert('project_edit');
96 $form->{sort} ||= 'projectnumber';
97 my $filter = $form->{filter} || { };
99 Projects->search_projects(%{ $filter }, 'sort' => $form->{sort});
101 my $cvar_configs = CVar->get_configs('module' => 'Projects');
103 my $report = SL::ReportGenerator->new(\%myconfig, $form);
105 my @columns = qw(projectnumber description active);
106 my @hidden_vars = ('filter');
107 my $href = build_std_url('action=project_report', @hidden_vars);
109 my @includeable_custom_variables = grep { $_->{includeable} } @{ $cvar_configs };
110 my %column_defs_cvars = ();
111 foreach (@includeable_custom_variables) {
112 $column_defs_cvars{"cvar_$_->{name}"} = {
113 'text' => $_->{description},
114 'visible' => $form->{"l_cvar_$_->{name}"} eq 'Y',
118 push @columns, map { "cvar_$_->{name}" } @includeable_custom_variables;
121 'projectnumber' => { 'text' => $locale->text('Number'), },
122 'description' => { 'text' => $locale->text('Description'), },
123 'active' => { 'text' => $locale->text('Active'), 'visible' => 'both' eq $filter->{active}, },
127 foreach (qw(projectnumber description)) {
128 $column_defs{$_}->{link} = $href . "&sort=$_";
129 $column_defs{$_}->{visible} = 1;
132 $report->set_columns(%column_defs);
133 $report->set_column_order(@columns);
135 $report->set_export_options('project_report', @hidden_vars, 'sort');
137 $report->set_sort_indicator($form->{sort}, 1);
140 push @options, $locale->text('All') if ($filter->{all});
141 push @options, $locale->text('Orphaned') if ($filter->{orphaned});
142 push @options, $locale->text('Project Number') . " : $filter->{projectnumber}" if ($filter->{projectnumber});
143 push @options, $locale->text('Description') . " : $filter->{description}" if ($filter->{description});
144 push @options, $locale->text('Active') if ($filter->{active} eq 'active');
145 push @options, $locale->text('Inactive') if ($filter->{active} eq 'inactive');
146 push @options, $locale->text('Orphaned') if ($filter->{status} eq 'orphaned');
148 $form->{title} = $locale->text('Projects');
150 $report->set_options('top_info_text' => join("\n", @options),
151 'output_format' => 'HTML',
152 'title' => $form->{title},
153 'attachment_basename' => $locale->text('project_list') . strftime('_%Y%m%d', localtime time),
155 $report->set_options_from_form();
157 CVar->add_custom_variables_to_report('module' => 'Projects',
158 'trans_id_field' => 'id',
159 'configs' => $cvar_configs,
160 'column_defs' => \%column_defs,
161 'data' => $form->{project_list});
163 my $edit_url = build_std_url('action=edit&type=project');
164 my $callback = $form->escape($href) . '&sort=' . E($form->{sort});
166 foreach $project (@{ $form->{project_list} }) {
167 $project->{active} = $project->{active} ? $locale->text('Yes') : $locale->text('No');
169 my $row = { map { $_ => { 'data' => $project->{$_} } } keys %{ $project } };
171 $row->{projectnumber}->{link} = $edit_url . "&id=" . E($project->{id}) . "&callback=${callback}";
173 $report->add_data($row);
176 $report->generate_with_headers();
178 $lxdebug->leave_sub();
181 sub display_project_form {
182 $lxdebug->enter_sub();
184 $auth->assert('project_edit');
186 $form->{project} ||= { };
188 $form->{title} = $form->{project}->{id} ? $locale->text("Edit Project") : $locale->text("Add Project");
190 $form->{CUSTOM_VARIABLES} = CVar->get_custom_variables('module' => 'Projects', 'trans_id' => $form->{project}->{id});
191 $main::lxdebug->dump(0, "cv", $form->{CUSTOM_VARIABLES});
192 CVar->render_inputs('variables' => $form->{CUSTOM_VARIABLES}) if (scalar @{ $form->{CUSTOM_VARIABLES} });
195 print $form->parse_html_template('projects/project_form');
197 $lxdebug->leave_sub();
201 $lxdebug->enter_sub();
203 $auth->assert('project_edit');
205 $form->isblank("project.projectnumber", $locale->text('Project Number missing!'));
207 my $project = $form->{project} || { };
208 my $is_new = !$project->{id};
209 $project->{id} = Projects->save_project(%{ $project });
212 if(!exists $form->{addition} && $project->{id} ne "") {
213 $form->{id} = $project->{id};
214 $form->{snumbers} = qq|projectnumber_| . $project->{projectnumber};
215 $form->{addition} = "SAVED";
216 $form->save_history($form->dbconnect(\%myconfig));
218 # /saving the history
220 if ($form->{callback}) {
221 map { $form->{callback} .= "&new_${_}=" . $form->escape($project->{$_}); } qw(projectnumber description id);
222 my $message = $is_new ? $locale->text('The project has been added.') : $locale->text('The project has been saved.');
223 $form->{callback} .= "&message=" . E($message);
226 $form->redirect($locale->text('Project saved!'));
228 $lxdebug->leave_sub();
232 $lxdebug->enter_sub();
234 delete $form->{project}->{id} if ($form->{project});
237 $lxdebug->leave_sub();
241 $lxdebug->enter_sub();
243 $auth->assert('project_edit');
245 my $project = $form->{project} || { };
246 Projects->delete_project('id' => $project->{id});
249 if(!exists $form->{addition}) {
250 $form->{snumbers} = qq|projectnumber_| . $project->{projectnumber};
251 $form->{addition} = "DELETED";
252 $form->save_history($form->dbconnect(\%myconfig));
254 # /saving the history
256 $form->redirect($locale->text('Project deleted!'));
258 $lxdebug->leave_sub();
262 call_sub($form->{nextsub});