0fd351dbe409545ab85fad472b27a769e0a3368a
[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   if ($form->{menubar}) {
296     require "$form->{path}/menu.pl";
297     &menubar;
298   }
299
300   print qq|
301   </form>
302
303 </body>
304 </html>
305 |;
306
307   $lxdebug->leave_sub();
308 }
309
310 sub form_project_header {
311   $lxdebug->enter_sub();
312
313   $form->{title} = $locale->text("$form->{title} Project");
314
315   # $locale->text('Add Project')
316   # $locale->text('Edit Project')
317
318   $form->{description} =~ s/\"/&quot;/g;
319
320   if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
321     $description =
322       qq|<textarea name="description" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{description}</textarea>|;
323   } else {
324     $description =
325       qq|<input name=description size=60 value="$form->{description}">|;
326   }
327
328   $form->header;
329
330   print qq|
331 <body>
332
333 <form method=post action=$form->{script}>
334
335 <input type=hidden name=id value=$form->{id}>
336 <input type=hidden name=type value=project>
337
338 <table width=100%>
339   <tr>
340     <th class=listtop>$form->{title}</th>
341   </tr>
342   <tr height="5"></tr>
343   <tr>
344     <td>
345       <table>
346         <tr>
347           <th align=right>| . $locale->text('Number') . qq|</th>
348           <td><input name=projectnumber size=20 value="$form->{projectnumber}"></td>
349         </tr>
350         <tr>
351           <th align=right>| . $locale->text('Description') . qq|</th>
352           <td>$description</td>
353         </tr>
354       </table>
355     </td>
356   </tr>
357   <tr>
358     <td colspan=2><hr size=3 noshade></td>
359   </tr>
360 </table>
361 |;
362
363   $lxdebug->leave_sub();
364 }
365
366 sub form_project_footer {
367   $lxdebug->enter_sub();
368
369   print qq|
370
371 <input name=callback type=hidden value="$form->{callback}">
372
373 <input type=hidden name=path value=$form->{path}>
374 <input type=hidden name=login value=$form->{login}>
375 <input type=hidden name=password value=$form->{password}>
376
377 <br><input type=submit class=submit name=action value="|
378     . $locale->text('Save') . qq|">
379 |;
380
381   if ($form->{id} && $form->{orphaned}) {
382     print qq|
383 <input type=submit class=submit name=action value="|
384       . $locale->text('Delete') . qq|">|;
385   }
386
387   if ($form->{menubar}) {
388     require "$form->{path}/menu.pl";
389     &menubar;
390   }
391
392   print qq|
393 </form>
394
395 </body>
396 </html>
397 |;
398
399   $lxdebug->leave_sub();
400 }
401
402 sub save {
403   $lxdebug->enter_sub();
404
405   if ($form->{type} eq 'project') {
406     $form->isblank("projectnumber", $locale->text('Project Number missing!'));
407     PE->save_project(\%myconfig, \%$form);
408     $form->redirect($locale->text('Project saved!'));
409   }
410   if ($form->{type} eq 'partsgroup') {
411     $form->isblank("partsgroup", $locale->text('Group missing!'));
412     PE->save_partsgroup(\%myconfig, \%$form);
413     $form->redirect($locale->text('Group saved!'));
414   }
415
416   # choice pricegroup and save
417   if ($form->{type} eq 'pricegroup') {
418     $form->isblank("pricegroup", $locale->text('Pricegroup missing!'));
419     PE->save_pricegroup(\%myconfig, \%$form);
420     $form->redirect($locale->text('Pricegroup saved!'));
421   }
422
423   $lxdebug->leave_sub();
424 }
425
426 sub delete {
427   $lxdebug->enter_sub();
428
429   PE->delete_tuple(\%myconfig, \%$form);
430
431   if ($form->{type} eq 'project') {
432     $form->redirect($locale->text('Project deleted!'));
433   }
434   if ($form->{type} eq 'partsgroup') {
435     $form->redirect($locale->text('Group deleted!'));
436   }
437   if ($form->{type} eq 'pricegroup') {
438     $form->redirect($locale->text('Pricegroup deleted!'));
439   }
440
441   $lxdebug->leave_sub();
442 }
443
444 sub continue { &{ $form->{nextsub} } }
445
446 sub partsgroup_report {
447   $lxdebug->enter_sub();
448
449   map { $form->{$_} = $form->unescape($form->{$_}) } (partsgroup);
450   PE->partsgroups(\%myconfig, \%$form);
451
452   $callback =
453     "$form->{script}?action=partsgroup_report&type=$form->{type}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}";
454
455   if ($form->{status} eq 'all') {
456     $option = $locale->text('All');
457   }
458   if ($form->{status} eq 'orphaned') {
459     $option .= $locale->text('Orphaned');
460   }
461   if ($form->{partsgroup}) {
462     $callback .= "&partsgroup=$form->{partsgroup}";
463     $option   .= "\n<br>" . $locale->text('Group') . " : $form->{partsgroup}";
464   }
465
466   @column_index = $form->sort_columns(qw(partsgroup));
467
468   $column_header{partsgroup} =
469     qq|<th class=listheading width=90%>| . $locale->text('Group') . qq|</th>|;
470
471   $form->{title} = $locale->text('Groups');
472
473   $form->header;
474
475   print qq|
476 <body>
477
478 <table width=100%>
479   <tr>
480     <th class=listtop>$form->{title}</th>
481   </tr>
482   <tr height="5"></tr>
483   <tr>
484     <td>$option</td>
485   </tr>
486   <tr>
487     <td>
488       <table width=100%>
489         <tr class=listheading>
490 |;
491
492   map { print "$column_header{$_}\n" } @column_index;
493
494   print qq|
495         </tr>
496 |;
497
498   # escape callback
499   $form->{callback} = $callback;
500
501   # escape callback for href
502   $callback = $form->escape($callback);
503
504   foreach $ref (@{ $form->{item_list} }) {
505
506     $i++;
507     $i %= 2;
508
509     print qq|
510         <tr valign=top class=listrow$i>
511 |;
512
513     $column_data{partsgroup} =
514       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>|;
515     map { print "$column_data{$_}\n" } @column_index;
516
517     print "
518         </tr>
519 ";
520   }
521
522   print qq|
523       </table>
524     </td>
525   </tr>
526   <tr>
527     <td><hr size=3 noshade></td>
528   </tr>
529 </table>
530
531 <br>
532 <form method=post action=$form->{script}>
533
534 <input name=callback type=hidden value="$form->{callback}">
535
536 <input type=hidden name=type value=$form->{type}>
537
538 <input type=hidden name=path value=$form->{path}>
539 <input type=hidden name=login value=$form->{login}>
540 <input type=hidden name=password value=$form->{password}>
541
542 <input class=submit type=submit name=action value="|
543     . $locale->text('Add') . qq|">|;
544
545   if ($form->{menubar}) {
546     require "$form->{path}/menu.pl";
547     &menubar;
548   }
549
550   print qq|
551   </form>
552
553 </body>
554 </html>
555 |;
556
557   $lxdebug->leave_sub();
558 }
559
560 sub form_partsgroup_header {
561   $lxdebug->enter_sub();
562
563   $form->{title} = $locale->text("$form->{title} Group");
564
565   # $locale->text('Add Group')
566   # $locale->text('Edit Group')
567
568   $form->{partsgroup} =~ s/\"/&quot;/g;
569
570   $form->header;
571
572   print qq|
573 <body>
574
575 <form method=post action=$form->{script}>
576
577 <input type=hidden name=id value=$form->{id}>
578 <input type=hidden name=type value=$form->{type}>
579
580 <table width=100%>
581   <tr>
582     <th class=listtop>$form->{title}</th>
583   </tr>
584   <tr height="5"></tr>
585   <tr>
586     <td>
587       <table width=100%>
588         <tr>
589           <th align=right>| . $locale->text('Group') . qq|</th>
590
591           <td><input name=partsgroup size=30 value="$form->{partsgroup}"></td>
592         </tr>
593       </table>
594     </td>
595   </tr>
596   <tr>
597     <td colspan=2><hr size=3 noshade></td>
598   </tr>
599 </table>
600 |;
601
602   $lxdebug->leave_sub();
603 }
604
605 sub form_partsgroup_footer {
606   $lxdebug->enter_sub();
607
608   print qq|
609
610 <input name=callback type=hidden value="$form->{callback}">
611
612 <input type=hidden name=path value=$form->{path}>
613 <input type=hidden name=login value=$form->{login}>
614 <input type=hidden name=password value=$form->{password}>
615
616 <br><input type=submit class=submit name=action value="|
617     . $locale->text('Save') . qq|">
618 |;
619
620   if ($form->{id} && $form->{orphaned}) {
621     print qq|
622 <input type=submit class=submit name=action value="|
623       . $locale->text('Delete') . qq|">|;
624   }
625
626   if ($form->{menubar}) {
627     require "$form->{path}/menu.pl";
628     &menubar;
629   }
630
631   print qq|
632 </form>
633
634 </body>
635 </html>
636 |;
637
638   $lxdebug->leave_sub();
639 }
640
641 #################################
642 # get pricesgroups and build up html-code
643 #
644 sub pricegroup_report {
645   $lxdebug->enter_sub();
646
647   map { $form->{$_} = $form->unescape($form->{$_}) } (pricegroup);
648   PE->pricegroups(\%myconfig, \%$form);
649
650   $callback =
651     "$form->{script}?action=pricegroup_report&type=$form->{type}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}";
652
653   if ($form->{status} eq 'all') {
654     $option = $locale->text('All');
655   }
656   if ($form->{status} eq 'orphaned') {
657     $option .= $locale->text('Orphaned');
658   }
659   if ($form->{pricegroup}) {
660     $callback .= "&pricegroup=$form->{pricegroup}";
661     $option   .=
662       "\n<br>" . $locale->text('Pricegroup') . " : $form->{pricegroup}";
663   }
664
665   @column_index = $form->sort_columns(qw(pricegroup));
666
667   $column_header{pricegroup} =
668       qq|<th class=listheading width=90%>|
669     . $locale->text('Pricegroup')
670     . qq|</th>|;
671
672   $form->{title} = $locale->text('Pricegroup');
673
674   $form->header;
675
676   print qq|
677 <body>
678
679 <table width=100%>
680   <tr>
681     <th class=listtop>$form->{title}</th>
682   </tr>
683   <tr height="5"></tr>
684   <tr>
685     <td>$option</td>
686   </tr>
687   <tr>
688     <td>
689       <table width=100%>
690         <tr class=listheading>
691 |;
692
693   map { print "$column_header{$_}\n" } @column_index;
694
695   print qq|
696         </tr>
697 |;
698
699   # escape callback
700   $form->{callback} = $callback;
701
702   # escape callback for href
703   $callback = $form->escape($callback);
704
705   foreach $ref (@{ $form->{item_list} }) {
706
707     $i++;
708     $i %= 2;
709
710     print qq|
711         <tr valign=top class=listrow$i>
712 |;
713     $column_data{pricegroup} =
714       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>|;
715
716     map { print "$column_data{$_}\n" } @column_index;
717
718     print "
719         </tr>
720 ";
721   }
722
723   print qq|
724       </table>
725     </td>
726   </tr>
727   <tr>
728     <td><hr size=3 noshade></td>
729   </tr>
730 </table>
731
732 <br>
733 <form method=post action=$form->{script}>
734
735 <input name=callback type=hidden value="$form->{callback}">
736
737 <input type=hidden name=type value=$form->{type}>
738
739 <input type=hidden name=path value=$form->{path}>
740 <input type=hidden name=login value=$form->{login}>
741 <input type=hidden name=password value=$form->{password}>
742
743 <input class=submit type=submit name=action value="|
744     . $locale->text('Add') . qq|">|;
745
746   if ($form->{menubar}) {
747     require "$form->{path}/menu.pl";
748     &menubar;
749   }
750
751   print qq|
752   </form>
753
754 </body>
755 </html>
756 |;
757
758   $lxdebug->leave_sub();
759 }
760
761 #######################
762 #build up pricegroup_header
763 #
764 sub form_pricegroup_header {
765   $lxdebug->enter_sub();
766
767   # $locale->text('Add Pricegroup')
768   # $locale->text('Edit Pricegroup')
769
770   $form->{title} = $locale->text("$form->{title} Pricegroup");
771
772   $form->{pricegroup} =~ s/\"/&quot;/g;
773
774   $form->header;
775
776   print qq|
777 <body>
778
779 <form method=post action=$form->{script}>
780
781 <input type=hidden name=id value=$form->{id}>
782 <input type=hidden name=type value=$form->{type}>
783
784 <table width=100%>
785   <tr>
786     <th class=listtop>$form->{title}</th>
787   </tr>
788   <tr height="5"></tr>
789   <tr>
790     <td>
791       <table width=100%>
792         <tr>
793           <th align=right>| . $locale->text('Preisgruppe') . qq|</th>
794           <td><input name=pricegroup size=30 value="$form->{pricegroup}"></td>
795         </tr>
796       </table>
797     </td>
798   </tr>
799   <tr>
800     <td colspan=2><hr size=3 noshade></td>
801   </tr>
802 </table>
803 |;
804
805   $lxdebug->leave_sub();
806 }
807 ######################
808 #build up pricegroup_footer
809 #
810 sub form_pricegroup_footer {
811   $lxdebug->enter_sub();
812
813   print qq|
814
815 <input name=callback type=hidden value="$form->{callback}">
816
817 <input type=hidden name=path value=$form->{path}>
818 <input type=hidden name=login value=$form->{login}>
819 <input type=hidden name=password value=$form->{password}>
820
821 <br><input type=submit class=submit name=action value="|
822     . $locale->text('Save') . qq|">
823 |;
824
825   if ($form->{id} && $form->{orphaned}) {
826     print qq|
827 <input type=submit class=submit name=action value="|
828       . $locale->text('Delete') . qq|">|;
829   }
830
831   if ($form->{menubar}) {
832     require "$form->{path}/menu.pl";
833     &menubar;
834   }
835
836   print qq|
837 </form>
838
839 </body>
840 </html>
841 |;
842
843   $lxdebug->leave_sub();
844 }