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