Entfernung von totem Code: Die Funktion menubar() gibt es schon lange nicht mehr.
[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   if ($form->{type} eq 'pricegroup') {
69     PE->get_pricegroup(\%myconfig, \%$form);
70   }
71   &{"form_$form->{type}_header"};
72   &{"form_$form->{type}_footer"};
73
74   $lxdebug->leave_sub();
75 }
76
77 sub search {
78   $lxdebug->enter_sub();
79
80   if ($form->{type} eq 'project') {
81     $report        = "project_report";
82     $sort          = 'projectnumber';
83     $form->{title} = $locale->text('Projects');
84
85     $number = qq|
86         <tr>
87           <th align=right width=1%>| . $locale->text('Number') . qq|</th>
88           <td><input name=projectnumber size=20></td>
89         </tr>
90         <tr>
91           <th align=right>| . $locale->text('Description') . qq|</th>
92           <td><input name=description size=60></td>
93         </tr>
94 |;
95
96   }
97   if ($form->{type} eq 'partsgroup') {
98     $report        = "partsgroup_report";
99     $sort          = 'partsgroup';
100     $form->{title} = $locale->text('Groups');
101
102     $number = qq|
103         <tr>
104           <th align=right width=1%>| . $locale->text('Group') . qq|</th>
105           <td><input name=partsgroup size=20></td>
106         </tr>
107 |;
108
109   }
110
111   # for pricesgroups
112   if ($form->{type} eq 'pricegroup') {
113     $report        = "pricegroup_report";
114     $sort          = 'pricegroup';
115     $form->{title} = $locale->text('Pricegroup');
116
117     $number = qq|
118         <tr>
119           <th align=right width=1%>| . $locale->text('Pricegroup') . qq|</th>
120           <td><input name=pricegroup size=20></td>
121         </tr>
122 |;
123
124   }
125
126   $form->header;
127
128   print qq|
129 <body>
130
131 <form method=post action=$form->{script}>
132
133 <input type=hidden name=sort value=$sort>
134 <input type=hidden name=type value=$form->{type}>
135
136 <table width=100%>
137   <tr>
138     <th class=listtop>$form->{title}</th>
139   </tr>
140   <tr height="5"></tr>
141   <tr>
142     <td>
143       <table width=100%>
144         $number
145         <tr>
146           <td></td>
147           <td><input name=status class=radio type=radio value=all checked>&nbsp;|
148     . $locale->text('All') . qq|
149           <input name=status class=radio type=radio value=orphaned>&nbsp;|
150     . $locale->text('Orphaned') . qq|</td>
151         </tr>
152       </table>
153     </td>
154   </tr>
155   <tr>
156     <td><hr size=3 noshade></td>
157   </tr>
158 </table>
159
160 <input type=hidden name=nextsub value=$report>
161
162 <input type=hidden name=path value=$form->{path}>
163 <input type=hidden name=login value=$form->{login}>
164 <input type=hidden name=password value=$form->{password}>
165
166 <br>
167 <input class=submit type=submit name=action value="|
168     . $locale->text('Continue') . qq|">
169 </form>
170
171 </body>
172 </html>
173 |;
174
175   $lxdebug->leave_sub();
176 }
177
178 sub project_report {
179   $lxdebug->enter_sub();
180
181   map { $form->{$_} = $form->unescape($form->{$_}) }
182     (projectnumber, description);
183   PE->projects(\%myconfig, \%$form);
184
185   $callback =
186     "$form->{script}?action=project_report&type=$form->{type}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}";
187   $href = $callback;
188
189   if ($form->{status} eq 'all') {
190     $option = $locale->text('All');
191   }
192   if ($form->{status} eq 'orphaned') {
193     $option .= $locale->text('Orphaned');
194   }
195   if ($form->{projectnumber}) {
196     $href     .= "&projectnumber=" . $form->escape($form->{projectnumber});
197     $callback .= "&projectnumber=$form->{projectnumber}";
198     $option   .=
199       "\n<br>" . $locale->text('Project') . " : $form->{projectnumber}";
200   }
201   if ($form->{description}) {
202     $href     .= "&description=" . $form->escape($form->{description});
203     $callback .= "&description=$form->{description}";
204     $option   .=
205       "\n<br>" . $locale->text('Description') . " : $form->{description}";
206   }
207
208   @column_index = $form->sort_columns(qw(projectnumber description));
209
210   $column_header{projectnumber} =
211       qq|<th><a class=listheading href=$href&sort=projectnumber>|
212     . $locale->text('Number')
213     . qq|</a></th>|;
214   $column_header{description} =
215       qq|<th><a class=listheading href=$href&sort=description>|
216     . $locale->text('Description')
217     . qq|</a></th>|;
218
219   $form->{title} = $locale->text('Projects');
220
221   $form->header;
222
223   print qq|
224 <body>
225
226 <table width=100%>
227   <tr>
228     <th class=listtop>$form->{title}</th>
229   </tr>
230   <tr height="5"></tr>
231   <tr>
232     <td>$option</td>
233   </tr>
234   <tr>
235     <td>
236       <table width=100%>
237         <tr class=listheading>
238 |;
239
240   map { print "$column_header{$_}\n" } @column_index;
241
242   print qq|
243         </tr>
244 |;
245
246   # escape callback
247   $form->{callback} = $callback .= "&sort=$form->{sort}";
248
249   # escape callback for href
250   $callback = $form->escape($callback);
251
252   foreach $ref (@{ $form->{project_list} }) {
253
254     $i++;
255     $i %= 2;
256
257     print qq|
258         <tr valign=top class=listrow$i>
259 |;
260
261     $column_data{projectnumber} =
262       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>|;
263     $column_data{description} = qq|<td>$ref->{description}&nbsp;</td>|;
264
265     map { print "$column_data{$_}\n" } @column_index;
266
267     print "
268         </tr>
269 ";
270   }
271
272   print qq|
273       </table>
274     </td>
275   </tr>
276   <tr>
277     <td><hr size=3 noshade></td>
278   </tr>
279 </table>
280
281 <br>
282 <form method=post action=$form->{script}>
283
284 <input name=callback type=hidden value="$form->{callback}">
285
286 <input type=hidden name=type value=$form->{type}>
287
288 <input type=hidden name=path value=$form->{path}>
289 <input type=hidden name=login value=$form->{login}>
290 <input type=hidden name=password value=$form->{password}>
291
292 <input class=submit type=submit name=action value="|
293     . $locale->text('Add') . qq|">
294
295   </form>
296
297 </body>
298 </html>
299 |;
300
301   $lxdebug->leave_sub();
302 }
303
304 sub form_project_header {
305   $lxdebug->enter_sub();
306
307   $form->{title} = $locale->text("$form->{title} Project");
308
309   # $locale->text('Add Project')
310   # $locale->text('Edit Project')
311
312   $form->{description} =~ s/\"/&quot;/g;
313
314   if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
315     $description =
316       qq|<textarea name="description" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{description}</textarea>|;
317   } else {
318     $description =
319       qq|<input name=description size=60 value="$form->{description}">|;
320   }
321
322   $form->header;
323
324   print qq|
325 <body>
326
327 <form method=post action=$form->{script}>
328
329 <input type=hidden name=id value=$form->{id}>
330 <input type=hidden name=type value=project>
331
332 <table width=100%>
333   <tr>
334     <th class=listtop>$form->{title}</th>
335   </tr>
336   <tr height="5"></tr>
337   <tr>
338     <td>
339       <table>
340         <tr>
341           <th align=right>| . $locale->text('Number') . qq|</th>
342           <td><input name=projectnumber size=20 value="$form->{projectnumber}"></td>
343         </tr>
344         <tr>
345           <th align=right>| . $locale->text('Description') . qq|</th>
346           <td>$description</td>
347         </tr>
348       </table>
349     </td>
350   </tr>
351   <tr>
352     <td colspan=2><hr size=3 noshade></td>
353   </tr>
354 </table>
355 |;
356
357   $lxdebug->leave_sub();
358 }
359
360 sub form_project_footer {
361   $lxdebug->enter_sub();
362
363   print qq|
364
365 <input name=callback type=hidden value="$form->{callback}">
366
367 <input type=hidden name=path value=$form->{path}>
368 <input type=hidden name=login value=$form->{login}>
369 <input type=hidden name=password value=$form->{password}>
370
371 <br><input type=submit class=submit name=action value="|
372     . $locale->text('Save') . qq|">
373 |;
374
375   if ($form->{id} && $form->{orphaned}) {
376     print qq|
377 <input type=submit class=submit name=action value="|
378       . $locale->text('Delete') . qq|">|;
379   }
380
381   print qq|
382 </form>
383
384 </body>
385 </html>
386 |;
387
388   $lxdebug->leave_sub();
389 }
390
391 sub save {
392   $lxdebug->enter_sub();
393
394   if ($form->{type} eq 'project') {
395     $form->isblank("projectnumber", $locale->text('Project Number missing!'));
396     PE->save_project(\%myconfig, \%$form);
397     $form->redirect($locale->text('Project saved!'));
398   }
399   if ($form->{type} eq 'partsgroup') {
400     $form->isblank("partsgroup", $locale->text('Group missing!'));
401     PE->save_partsgroup(\%myconfig, \%$form);
402     $form->redirect($locale->text('Group saved!'));
403   }
404
405   # choice pricegroup and save
406   if ($form->{type} eq 'pricegroup') {
407     $form->isblank("pricegroup", $locale->text('Pricegroup missing!'));
408     PE->save_pricegroup(\%myconfig, \%$form);
409     $form->redirect($locale->text('Pricegroup saved!'));
410   }
411
412   $lxdebug->leave_sub();
413 }
414
415 sub delete {
416   $lxdebug->enter_sub();
417
418   PE->delete_tuple(\%myconfig, \%$form);
419
420   if ($form->{type} eq 'project') {
421     $form->redirect($locale->text('Project deleted!'));
422   }
423   if ($form->{type} eq 'partsgroup') {
424     $form->redirect($locale->text('Group deleted!'));
425   }
426   if ($form->{type} eq 'pricegroup') {
427     $form->redirect($locale->text('Pricegroup deleted!'));
428   }
429
430   $lxdebug->leave_sub();
431 }
432
433 sub continue { &{ $form->{nextsub} } }
434
435 sub partsgroup_report {
436   $lxdebug->enter_sub();
437
438   map { $form->{$_} = $form->unescape($form->{$_}) } (partsgroup);
439   PE->partsgroups(\%myconfig, \%$form);
440
441   $callback =
442     "$form->{script}?action=partsgroup_report&type=$form->{type}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}";
443
444   if ($form->{status} eq 'all') {
445     $option = $locale->text('All');
446   }
447   if ($form->{status} eq 'orphaned') {
448     $option .= $locale->text('Orphaned');
449   }
450   if ($form->{partsgroup}) {
451     $callback .= "&partsgroup=$form->{partsgroup}";
452     $option   .= "\n<br>" . $locale->text('Group') . " : $form->{partsgroup}";
453   }
454
455   @column_index = $form->sort_columns(qw(partsgroup));
456
457   $column_header{partsgroup} =
458     qq|<th class=listheading width=90%>| . $locale->text('Group') . qq|</th>|;
459
460   $form->{title} = $locale->text('Groups');
461
462   $form->header;
463
464   print qq|
465 <body>
466
467 <table width=100%>
468   <tr>
469     <th class=listtop>$form->{title}</th>
470   </tr>
471   <tr height="5"></tr>
472   <tr>
473     <td>$option</td>
474   </tr>
475   <tr>
476     <td>
477       <table width=100%>
478         <tr class=listheading>
479 |;
480
481   map { print "$column_header{$_}\n" } @column_index;
482
483   print qq|
484         </tr>
485 |;
486
487   # escape callback
488   $form->{callback} = $callback;
489
490   # escape callback for href
491   $callback = $form->escape($callback);
492
493   foreach $ref (@{ $form->{item_list} }) {
494
495     $i++;
496     $i %= 2;
497
498     print qq|
499         <tr valign=top class=listrow$i>
500 |;
501
502     $column_data{partsgroup} =
503       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>|;
504     map { print "$column_data{$_}\n" } @column_index;
505
506     print "
507         </tr>
508 ";
509   }
510
511   print qq|
512       </table>
513     </td>
514   </tr>
515   <tr>
516     <td><hr size=3 noshade></td>
517   </tr>
518 </table>
519
520 <br>
521 <form method=post action=$form->{script}>
522
523 <input name=callback type=hidden value="$form->{callback}">
524
525 <input type=hidden name=type value=$form->{type}>
526
527 <input type=hidden name=path value=$form->{path}>
528 <input type=hidden name=login value=$form->{login}>
529 <input type=hidden name=password value=$form->{password}>
530
531 <input class=submit type=submit name=action value="|
532     . $locale->text('Add') . qq|">
533
534   </form>
535
536 </body>
537 </html>
538 |;
539
540   $lxdebug->leave_sub();
541 }
542
543 sub form_partsgroup_header {
544   $lxdebug->enter_sub();
545
546   $form->{title} = $locale->text("$form->{title} Group");
547
548   # $locale->text('Add Group')
549   # $locale->text('Edit Group')
550
551   $form->{partsgroup} =~ s/\"/&quot;/g;
552
553   $form->header;
554
555   print qq|
556 <body>
557
558 <form method=post action=$form->{script}>
559
560 <input type=hidden name=id value=$form->{id}>
561 <input type=hidden name=type value=$form->{type}>
562
563 <table width=100%>
564   <tr>
565     <th class=listtop>$form->{title}</th>
566   </tr>
567   <tr height="5"></tr>
568   <tr>
569     <td>
570       <table width=100%>
571         <tr>
572           <th align=right>| . $locale->text('Group') . qq|</th>
573
574           <td><input name=partsgroup size=30 value="$form->{partsgroup}"></td>
575         </tr>
576       </table>
577     </td>
578   </tr>
579   <tr>
580     <td colspan=2><hr size=3 noshade></td>
581   </tr>
582 </table>
583 |;
584
585   $lxdebug->leave_sub();
586 }
587
588 sub form_partsgroup_footer {
589   $lxdebug->enter_sub();
590
591   print qq|
592
593 <input name=callback type=hidden value="$form->{callback}">
594
595 <input type=hidden name=path value=$form->{path}>
596 <input type=hidden name=login value=$form->{login}>
597 <input type=hidden name=password value=$form->{password}>
598
599 <br><input type=submit class=submit name=action value="|
600     . $locale->text('Save') . qq|">
601 |;
602
603   if ($form->{id} && $form->{orphaned}) {
604     print qq|
605 <input type=submit class=submit name=action value="|
606       . $locale->text('Delete') . qq|">|;
607   }
608
609   print qq|
610 </form>
611
612 </body>
613 </html>
614 |;
615
616   $lxdebug->leave_sub();
617 }
618
619 #################################
620 # get pricesgroups and build up html-code
621 #
622 sub pricegroup_report {
623   $lxdebug->enter_sub();
624
625   map { $form->{$_} = $form->unescape($form->{$_}) } (pricegroup);
626   PE->pricegroups(\%myconfig, \%$form);
627
628   $callback =
629     "$form->{script}?action=pricegroup_report&type=$form->{type}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}";
630
631   if ($form->{status} eq 'all') {
632     $option = $locale->text('All');
633   }
634   if ($form->{status} eq 'orphaned') {
635     $option .= $locale->text('Orphaned');
636   }
637   if ($form->{pricegroup}) {
638     $callback .= "&pricegroup=$form->{pricegroup}";
639     $option   .=
640       "\n<br>" . $locale->text('Pricegroup') . " : $form->{pricegroup}";
641   }
642
643   @column_index = $form->sort_columns(qw(pricegroup));
644
645   $column_header{pricegroup} =
646       qq|<th class=listheading width=90%>|
647     . $locale->text('Pricegroup')
648     . qq|</th>|;
649
650   $form->{title} = $locale->text('Pricegroup');
651
652   $form->header;
653
654   print qq|
655 <body>
656
657 <table width=100%>
658   <tr>
659     <th class=listtop>$form->{title}</th>
660   </tr>
661   <tr height="5"></tr>
662   <tr>
663     <td>$option</td>
664   </tr>
665   <tr>
666     <td>
667       <table width=100%>
668         <tr class=listheading>
669 |;
670
671   map { print "$column_header{$_}\n" } @column_index;
672
673   print qq|
674         </tr>
675 |;
676
677   # escape callback
678   $form->{callback} = $callback;
679
680   # escape callback for href
681   $callback = $form->escape($callback);
682
683   foreach $ref (@{ $form->{item_list} }) {
684
685     $i++;
686     $i %= 2;
687
688     print qq|
689         <tr valign=top class=listrow$i>
690 |;
691     $column_data{pricegroup} =
692       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->{pricegroup}</td>|;
693
694     map { print "$column_data{$_}\n" } @column_index;
695
696     print "
697         </tr>
698 ";
699   }
700
701   print qq|
702       </table>
703     </td>
704   </tr>
705   <tr>
706     <td><hr size=3 noshade></td>
707   </tr>
708 </table>
709
710 <br>
711 <form method=post action=$form->{script}>
712
713 <input name=callback type=hidden value="$form->{callback}">
714
715 <input type=hidden name=type value=$form->{type}>
716
717 <input type=hidden name=path value=$form->{path}>
718 <input type=hidden name=login value=$form->{login}>
719 <input type=hidden name=password value=$form->{password}>
720
721 <input class=submit type=submit name=action value="|
722     . $locale->text('Add') . qq|">
723
724   </form>
725
726 </body>
727 </html>
728 |;
729
730   $lxdebug->leave_sub();
731 }
732
733 #######################
734 #build up pricegroup_header
735 #
736 sub form_pricegroup_header {
737   $lxdebug->enter_sub();
738
739   # $locale->text('Add Pricegroup')
740   # $locale->text('Edit Pricegroup')
741
742   $form->{title} = $locale->text("$form->{title} Pricegroup");
743
744   $form->{pricegroup} =~ s/\"/&quot;/g;
745
746   $form->header;
747
748   print qq|
749 <body>
750
751 <form method=post action=$form->{script}>
752
753 <input type=hidden name=id value=$form->{id}>
754 <input type=hidden name=type value=$form->{type}>
755
756 <table width=100%>
757   <tr>
758     <th class=listtop>$form->{title}</th>
759   </tr>
760   <tr height="5"></tr>
761   <tr>
762     <td>
763       <table width=100%>
764         <tr>
765           <th align=right>| . $locale->text('Preisgruppe') . qq|</th>
766           <td><input name=pricegroup size=30 value="$form->{pricegroup}"></td>
767         </tr>
768       </table>
769     </td>
770   </tr>
771   <tr>
772     <td colspan=2><hr size=3 noshade></td>
773   </tr>
774 </table>
775 |;
776
777   $lxdebug->leave_sub();
778 }
779 ######################
780 #build up pricegroup_footer
781 #
782 sub form_pricegroup_footer {
783   $lxdebug->enter_sub();
784
785   print qq|
786
787 <input name=callback type=hidden value="$form->{callback}">
788
789 <input type=hidden name=path value=$form->{path}>
790 <input type=hidden name=login value=$form->{login}>
791 <input type=hidden name=password value=$form->{password}>
792
793 <br><input type=submit class=submit name=action value="|
794     . $locale->text('Save') . qq|">
795 |;
796
797   if ($form->{id} && $form->{orphaned}) {
798     print qq|
799 <input type=submit class=submit name=action value="|
800       . $locale->text('Delete') . qq|">|;
801   }
802
803   print qq|
804 </form>
805
806 </body>
807 </html>
808 |;
809
810   $lxdebug->leave_sub();
811 }