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);
36 use SL::ReportGenerator;
38 require "bin/mozilla/common.pl";
39 require "bin/mozilla/reportgenerator.pl";
42 $lxdebug->enter_sub();
44 $auth->assert('project_edit');
47 $form->{callback} = build_std_url('action') unless $form->{callback};
49 display_project_form();
51 $lxdebug->leave_sub();
55 $lxdebug->enter_sub();
57 $auth->assert('project_edit');
60 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
61 #/show hhistory button
62 $form->{title} = "Edit";
64 $form->{project} = Projects->get_project('id' => $form->{id}, 'orphaned' => 1);
66 display_project_form();
68 $lxdebug->leave_sub();
72 $lxdebug->enter_sub();
74 $auth->assert('project_edit');
76 $form->{title} = $locale->text('Projects');
79 print $form->parse_html_template('projects/search');
81 $lxdebug->leave_sub();
85 $lxdebug->enter_sub();
87 $auth->assert('project_edit');
89 $form->{sort} ||= 'projectnumber';
91 my $filter = $form->{filter} || { };
92 Projects->search_projects(%{ $filter }, 'sort' => $form->{sort});
94 my $report = SL::ReportGenerator->new(\%myconfig, $form);
96 my @columns = qw(projectnumber description active);
97 my @hidden_vars = ('filter');
98 my $href = build_std_url('action=project_report', @hidden_vars);
101 'projectnumber' => { 'text' => $locale->text('Number'), },
102 'description' => { 'text' => $locale->text('Description'), },
103 'active' => { 'text' => $locale->text('Active'), 'visible' => 'both' eq $filter->{active}, },
106 foreach (qw(projectnumber description)) {
107 $column_defs{$_}->{link} = $href . "&sort=$_";
108 $column_defs{$_}->{visible} = 1;
111 $report->set_columns(%column_defs);
112 $report->set_column_order(@columns);
114 $report->set_export_options('project_report', @hidden_vars);
116 $report->set_sort_indicator($form->{sort}, 1);
119 push @options, $locale->text('All') if ($filter->{all});
120 push @options, $locale->text('Orphaned') if ($filter->{orphaned});
121 push @options, $locale->text('Project Number') . " : $filter->{projectnumber}" if ($filter->{projectnumber});
122 push @options, $locale->text('Description') . " : $filter->{description}" if ($filter->{description});
123 push @options, $locale->text('Active') if ($filter->{active} eq 'active');
124 push @options, $locale->text('Inactive') if ($filter->{active} eq 'inactive');
125 push @options, $locale->text('Orphaned') if ($filter->{status} eq 'orphaned');
127 $form->{title} = $locale->text('Projects');
129 $report->set_options('top_info_text' => join("\n", @options),
130 'output_format' => 'HTML',
131 'title' => $form->{title},
132 'attachment_basename' => $locale->text('project_list') . strftime('_%Y%m%d', localtime time),
134 $report->set_options_from_form();
136 my $edit_url = build_std_url('action=edit&type=project');
137 my $callback = $form->escape($href) . '&sort=' . E($form->{sort});
139 foreach $project (@{ $form->{project_list} }) {
140 $project->{active} = $project->{active} ? $locale->text('Yes') : $locale->text('No');
142 my $row = { map { $_ => { 'data' => $project->{$_} } } keys %{ $project } };
144 $row->{projectnumber}->{link} = $edit_url . "&id=" . E($project->{id}) . "&callback=${callback}";
146 $report->add_data($row);
149 $report->generate_with_headers();
151 $lxdebug->leave_sub();
154 sub display_project_form {
155 $lxdebug->enter_sub();
157 $auth->assert('project_edit');
159 $form->{project} ||= { };
161 $form->{title} = $form->{project}->{id} ? $locale->text("Edit Project") : $locale->text("Add Project");
164 print $form->parse_html_template('projects/project_form');
166 $lxdebug->leave_sub();
170 $lxdebug->enter_sub();
172 $auth->assert('project_edit');
174 $form->isblank("project.projectnumber", $locale->text('Project Number missing!'));
176 my $project = $form->{project} || { };
177 my $is_new = !$project->{id};
178 $project->{id} = Projects->save_project(%{ $project });
181 if(!exists $form->{addition} && $project->{id} ne "") {
182 $form->{id} = $project->{id};
183 $form->{snumbers} = qq|projectnumber_| . $project->{projectnumber};
184 $form->{addition} = "SAVED";
185 $form->save_history($form->dbconnect(\%myconfig));
187 # /saving the history
189 if ($form->{callback}) {
190 map { $form->{callback} .= "&new_${_}=" . $form->escape($project->{$_}); } qw(projectnumber description id);
191 my $message = $is_new ? $locale->text('The project has been added.') : $locale->text('The project has been saved.');
192 $form->{callback} .= "&message=" . E($message);
195 $form->redirect($locale->text('Project saved!'));
197 $lxdebug->leave_sub();
201 $lxdebug->enter_sub();
203 delete $form->{project}->{id} if ($form->{project});
206 $lxdebug->leave_sub();
210 $lxdebug->enter_sub();
212 $auth->assert('project_edit');
214 my $project = $form->{project} || { };
215 Projects->delete_project('id' => $project->{id});
218 if(!exists $form->{addition}) {
219 $form->{snumbers} = qq|projectnumber_| . $project->{projectnumber};
220 $form->{addition} = "DELETED";
221 $form->save_history($form->dbconnect(\%myconfig));
223 # /saving the history
225 $form->redirect($locale->text('Project deleted!'));
227 $lxdebug->leave_sub();
231 call_sub($form->{nextsub});