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