Alle Dateien durch Perltidy laufen lassen. Die verwendeten Optionen sind am Ende...
[kivitendo-erp.git] / bin / mozilla / pe.pl
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2004
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #
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.
20 #
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 #======================================================================
29 #
30 # project administration
31 # partsgroup administration
32 #
33 #======================================================================
34
35 use SL::PE;
36
37 1;
38
39 # end of main
40
41 sub add {
42   $lxdebug->enter_sub();
43
44   $form->{title} = "Add";
45
46   # construct callback
47   $form->{callback} =
48     "$form->{script}?action=add&type=$form->{type}&path=$form->{path}&login=$form->{login}&password=$form->{password}"
49     unless $form->{callback};
50
51   &{"form_$form->{type}_header"};
52   &{"form_$form->{type}_footer"};
53
54   $lxdebug->leave_sub();
55 }
56
57 sub edit {
58   $lxdebug->enter_sub();
59
60   $form->{title} = "Edit";
61
62   if ($form->{type} eq 'project') {
63     PE->get_project(\%myconfig, \%$form);
64   }
65   if ($form->{type} eq 'partsgroup') {
66     PE->get_partsgroup(\%myconfig, \%$form);
67   }
68
69   &{"form_$form->{type}_header"};
70   &{"form_$form->{type}_footer"};
71
72   $lxdebug->leave_sub();
73 }
74
75 sub search {
76   $lxdebug->enter_sub();
77
78   if ($form->{type} eq 'project') {
79     $report        = "project_report";
80     $sort          = 'projectnumber';
81     $form->{title} = $locale->text('Projects');
82
83     $number = qq|
84         <tr>
85           <th align=right width=1%>| . $locale->text('Number') . qq|</th>
86           <td><input name=projectnumber size=20></td>
87         </tr>
88         <tr>
89           <th align=right>| . $locale->text('Description') . qq|</th>
90           <td><input name=description size=60></td>
91         </tr>
92 |;
93
94   }
95   if ($form->{type} eq 'partsgroup') {
96     $report        = "partsgroup_report";
97     $sort          = 'partsgroup';
98     $form->{title} = $locale->text('Groups');
99
100     $number = qq|
101         <tr>
102           <th align=right width=1%>| . $locale->text('Group') . qq|</th>
103           <td><input name=partsgroup size=20></td>
104         </tr>
105 |;
106
107   }
108
109   $form->header;
110
111   print qq|
112 <body>
113
114 <form method=post action=$form->{script}>
115
116 <input type=hidden name=sort value=$sort>
117 <input type=hidden name=type value=$form->{type}>
118
119 <table width=100%>
120   <tr>
121     <th class=listtop>$form->{title}</th>
122   </tr>
123   <tr height="5"></tr>
124   <tr>
125     <td>
126       <table width=100%>
127         $number
128         <tr>
129           <td></td>
130           <td><input name=status class=radio type=radio value=all checked>&nbsp;|
131     . $locale->text('All') . qq|
132           <input name=status class=radio type=radio value=orphaned>&nbsp;|
133     . $locale->text('Orphaned')
134     . qq|</td>
135         </tr>
136       </table>
137     </td>
138   </tr>
139   <tr>
140     <td><hr size=3 noshade></td>
141   </tr>
142 </table>
143
144 <input type=hidden name=nextsub value=$report>
145
146 <input type=hidden name=path value=$form->{path}>
147 <input type=hidden name=login value=$form->{login}>
148 <input type=hidden name=password value=$form->{password}>
149
150 <br>
151 <input class=submit type=submit name=action value="|
152     . $locale->text('Continue') . qq|">
153 </form>
154
155 </body>
156 </html>
157 |;
158
159   $lxdebug->leave_sub();
160 }
161
162 sub project_report {
163   $lxdebug->enter_sub();
164
165   map { $form->{$_} = $form->unescape($form->{$_}) }
166     (projectnumber, description);
167   PE->projects(\%myconfig, \%$form);
168
169   $callback =
170     "$form->{script}?action=project_report&type=$form->{type}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}";
171   $href = $callback;
172
173   if ($form->{status} eq 'all') {
174     $option = $locale->text('All');
175   }
176   if ($form->{status} eq 'orphaned') {
177     $option .= $locale->text('Orphaned');
178   }
179   if ($form->{projectnumber}) {
180     $href     .= "&projectnumber=" . $form->escape($form->{projectnumber});
181     $callback .= "&projectnumber=$form->{projectnumber}";
182     $option   .=
183       "\n<br>" . $locale->text('Project') . " : $form->{projectnumber}";
184   }
185   if ($form->{description}) {
186     $href     .= "&description=" . $form->escape($form->{description});
187     $callback .= "&description=$form->{description}";
188     $option   .=
189       "\n<br>" . $locale->text('Description') . " : $form->{description}";
190   }
191
192   @column_index = $form->sort_columns(qw(projectnumber description));
193
194   $column_header{projectnumber} =
195       qq|<th><a class=listheading href=$href&sort=projectnumber>|
196     . $locale->text('Number')
197     . qq|</a></th>|;
198   $column_header{description} =
199       qq|<th><a class=listheading href=$href&sort=description>|
200     . $locale->text('Description')
201     . qq|</a></th>|;
202
203   $form->{title} = $locale->text('Projects');
204
205   $form->header;
206
207   print qq|
208 <body>
209
210 <table width=100%>
211   <tr>
212     <th class=listtop>$form->{title}</th>
213   </tr>
214   <tr height="5"></tr>
215   <tr>
216     <td>$option</td>
217   </tr>
218   <tr>
219     <td>
220       <table width=100%>
221         <tr class=listheading>
222 |;
223
224   map { print "$column_header{$_}\n" } @column_index;
225
226   print qq|
227         </tr>
228 |;
229
230   # escape callback
231   $form->{callback} = $callback .= "&sort=$form->{sort}";
232
233   # escape callback for href
234   $callback = $form->escape($callback);
235
236   foreach $ref (@{ $form->{project_list} }) {
237
238     $i++;
239     $i %= 2;
240
241     print qq|
242         <tr valign=top class=listrow$i>
243 |;
244
245     $column_data{projectnumber} =
246       qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{projectnumber}</td>|;
247     $column_data{description} = qq|<td>$ref->{description}&nbsp;</td>|;
248
249     map { print "$column_data{$_}\n" } @column_index;
250
251     print "
252         </tr>
253 ";
254   }
255
256   print qq|
257       </table>
258     </td>
259   </tr>
260   <tr>
261     <td><hr size=3 noshade></td>
262   </tr>
263 </table>
264
265 <br>
266 <form method=post action=$form->{script}>
267
268 <input name=callback type=hidden value="$form->{callback}">
269
270 <input type=hidden name=type value=$form->{type}>
271
272 <input type=hidden name=path value=$form->{path}>
273 <input type=hidden name=login value=$form->{login}>
274 <input type=hidden name=password value=$form->{password}>
275
276 <input class=submit type=submit name=action value="|
277     . $locale->text('Add') . qq|">|;
278
279   if ($form->{menubar}) {
280     require "$form->{path}/menu.pl";
281     &menubar;
282   }
283
284   print qq|
285   </form>
286   
287 </body>
288 </html>
289 |;
290
291   $lxdebug->leave_sub();
292 }
293
294 sub form_project_header {
295   $lxdebug->enter_sub();
296
297   $form->{title} = $locale->text("$form->{title} Project");
298
299   # $locale->text('Add Project')
300   # $locale->text('Edit Project')
301
302   $form->{description} =~ s/\"/&quot;/g;
303
304   if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
305     $description =
306       qq|<textarea name="description" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{description}</textarea>|;
307   } else {
308     $description =
309       qq|<input name=description size=60 value="$form->{description}">|;
310   }
311
312   $form->header;
313
314   print qq|
315 <body>
316
317 <form method=post action=$form->{script}>
318
319 <input type=hidden name=id value=$form->{id}>
320 <input type=hidden name=type value=project>
321
322 <table width=100%>
323   <tr>
324     <th class=listtop>$form->{title}</th>
325   </tr>
326   <tr height="5"></tr>
327   <tr>
328     <td>
329       <table>
330         <tr>
331           <th align=right>| . $locale->text('Number') . qq|</th>
332           <td><input name=projectnumber size=20 value="$form->{projectnumber}"></td>
333         </tr>
334         <tr>
335           <th align=right>| . $locale->text('Description') . qq|</th>
336           <td>$description</td>
337         </tr>
338       </table>
339     </td>
340   </tr>
341   <tr>
342     <td colspan=2><hr size=3 noshade></td>
343   </tr>
344 </table>
345 |;
346
347   $lxdebug->leave_sub();
348 }
349
350 sub form_project_footer {
351   $lxdebug->enter_sub();
352
353   print qq|
354
355 <input name=callback type=hidden value="$form->{callback}">
356
357 <input type=hidden name=path value=$form->{path}>
358 <input type=hidden name=login value=$form->{login}>
359 <input type=hidden name=password value=$form->{password}>
360
361 <br><input type=submit class=submit name=action value="|
362     . $locale->text('Save') . qq|">
363 |;
364
365   if ($form->{id} && $form->{orphaned}) {
366     print qq|
367 <input type=submit class=submit name=action value="|
368       . $locale->text('Delete') . qq|">|;
369   }
370
371   if ($form->{menubar}) {
372     require "$form->{path}/menu.pl";
373     &menubar;
374   }
375
376   print qq|
377 </form>
378
379 </body>
380 </html>
381 |;
382
383   $lxdebug->leave_sub();
384 }
385
386 sub save {
387   $lxdebug->enter_sub();
388
389   if ($form->{type} eq 'project') {
390     $form->isblank("projectnumber", $locale->text('Project Number missing!'));
391     PE->save_project(\%myconfig, \%$form);
392     $form->redirect($locale->text('Project saved!'));
393   }
394   if ($form->{type} eq 'partsgroup') {
395     $form->isblank("partsgroup", $locale->text('Group missing!'));
396     PE->save_partsgroup(\%myconfig, \%$form);
397     $form->redirect($locale->text('Group saved!'));
398   }
399
400   $lxdebug->leave_sub();
401 }
402
403 sub delete {
404   $lxdebug->enter_sub();
405
406   PE->delete_tuple(\%myconfig, \%$form);
407
408   if ($form->{type} eq 'project') {
409     $form->redirect($locale->text('Project deleted!'));
410   }
411   if ($form->{type} eq 'partsgroup') {
412     $form->redirect($locale->text('Group deleted!'));
413   }
414
415   $lxdebug->leave_sub();
416 }
417
418 sub continue { &{ $form->{nextsub} } }
419
420 sub partsgroup_report {
421   $lxdebug->enter_sub();
422
423   map { $form->{$_} = $form->unescape($form->{$_}) } (partsgroup);
424   PE->partsgroups(\%myconfig, \%$form);
425
426   $callback =
427     "$form->{script}?action=partsgroup_report&type=$form->{type}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}";
428
429   if ($form->{status} eq 'all') {
430     $option = $locale->text('All');
431   }
432   if ($form->{status} eq 'orphaned') {
433     $option .= $locale->text('Orphaned');
434   }
435   if ($form->{partsgroup}) {
436     $callback .= "&partsgroup=$form->{partsgroup}";
437     $option   .= "\n<br>" . $locale->text('Group') . " : $form->{partsgroup}";
438   }
439
440   @column_index = $form->sort_columns(qw(partsgroup));
441
442   $column_header{partsgroup} =
443     qq|<th class=listheading width=90%>| . $locale->text('Group') . qq|</th>|;
444
445   $form->{title} = $locale->text('Groups');
446
447   $form->header;
448
449   print qq|
450 <body>
451
452 <table width=100%>
453   <tr>
454     <th class=listtop>$form->{title}</th>
455   </tr>
456   <tr height="5"></tr>
457   <tr>
458     <td>$option</td>
459   </tr>
460   <tr>
461     <td>
462       <table width=100%>
463         <tr class=listheading>
464 |;
465
466   map { print "$column_header{$_}\n" } @column_index;
467
468   print qq|
469         </tr>
470 |;
471
472   # escape callback
473   $form->{callback} = $callback;
474
475   # escape callback for href
476   $callback = $form->escape($callback);
477
478   foreach $ref (@{ $form->{item_list} }) {
479
480     $i++;
481     $i %= 2;
482
483     print qq|
484         <tr valign=top class=listrow$i>
485 |;
486
487     $column_data{partsgroup} =
488       qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{partsgroup}</td>|;
489     map { print "$column_data{$_}\n" } @column_index;
490
491     print "
492         </tr>
493 ";
494   }
495
496   print qq|
497       </table>
498     </td>
499   </tr>
500   <tr>
501     <td><hr size=3 noshade></td>
502   </tr>
503 </table>
504
505 <br>
506 <form method=post action=$form->{script}>
507
508 <input name=callback type=hidden value="$form->{callback}">
509
510 <input type=hidden name=type value=$form->{type}>
511
512 <input type=hidden name=path value=$form->{path}>
513 <input type=hidden name=login value=$form->{login}>
514 <input type=hidden name=password value=$form->{password}>
515
516 <input class=submit type=submit name=action value="|
517     . $locale->text('Add') . qq|">|;
518
519   if ($form->{menubar}) {
520     require "$form->{path}/menu.pl";
521     &menubar;
522   }
523
524   print qq|
525   </form>
526
527 </body>
528 </html>
529 |;
530
531   $lxdebug->leave_sub();
532 }
533
534 sub form_partsgroup_header {
535   $lxdebug->enter_sub();
536
537   $form->{title} = $locale->text("$form->{title} Group");
538
539   # $locale->text('Add Group')
540   # $locale->text('Edit Group')
541
542   $form->{partsgroup} =~ s/\"/&quot;/g;
543
544   $form->header;
545
546   print qq|
547 <body>
548
549 <form method=post action=$form->{script}>
550
551 <input type=hidden name=id value=$form->{id}>
552 <input type=hidden name=type value=$form->{type}>
553
554 <table width=100%>
555   <tr>
556     <th class=listtop>$form->{title}</th>
557   </tr>
558   <tr height="5"></tr>
559   <tr>
560     <td>
561       <table width=100%>
562         <tr>
563           <th align=right>| . $locale->text('Group') . qq|</th>
564
565           <td><input name=partsgroup size=30 value="$form->{partsgroup}"></td>
566         </tr>
567       </table>
568     </td>
569   </tr>
570   <tr>
571     <td colspan=2><hr size=3 noshade></td>
572   </tr>
573 </table>
574 |;
575
576   $lxdebug->leave_sub();
577 }
578
579 sub form_partsgroup_footer {
580   $lxdebug->enter_sub();
581
582   print qq|
583
584 <input name=callback type=hidden value="$form->{callback}">
585
586 <input type=hidden name=path value=$form->{path}>
587 <input type=hidden name=login value=$form->{login}>
588 <input type=hidden name=password value=$form->{password}>
589
590 <br><input type=submit class=submit name=action value="|
591     . $locale->text('Save') . qq|">
592 |;
593
594   if ($form->{id} && $form->{orphaned}) {
595     print qq|
596 <input type=submit class=submit name=action value="|
597       . $locale->text('Delete') . qq|">|;
598   }
599
600   if ($form->{menubar}) {
601     require "$form->{path}/menu.pl";
602     &menubar;
603   }
604
605   print qq|
606 </form>
607
608 </body>
609 </html>
610 |;
611
612   $lxdebug->leave_sub();
613 }
614