import sql-ledger 2.4.4
[freeside.git] / sql-ledger / old / sql-ledger / bin / mozilla / pe.pl
1 #=====================================================================
2 # SQL-Ledger Accounting
3 # Copyright (c) 1998-2002
4 #
5 #  Author: Dieter Simader
6 #   Email: dsimader@sql-ledger.org
7 #     Web: http://www.sql-ledger.org
8 #
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #======================================================================
23 #
24 # project administration
25 # partsgroup administration
26 #
27 #======================================================================
28
29
30 use SL::PE;
31
32 1;
33 # end of main
34
35
36
37 sub add {
38   
39   $form->{title} = "Add";
40
41   # construct callback
42   $form->{callback} = "$form->{script}?action=add&type=$form->{type}&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback};
43
44   &{ "form_$form->{type}_header" };
45   &{ "form_$form->{type}_footer" };
46   
47 }
48
49
50 sub edit {
51   
52   $form->{title} = "Edit";
53
54   if ($form->{type} eq 'project') {
55     PE->get_project(\%myconfig, \%$form);
56   }
57   if ($form->{type} eq 'partsgroup') {
58     PE->get_partsgroup(\%myconfig, \%$form);
59   }
60
61   &{ "form_$form->{type}_header" };
62   &{ "form_$form->{type}_footer" };
63   
64 }
65
66
67 sub search {
68
69   if ($form->{type} eq 'project') {
70     $report = "project_report";
71     $sort = 'projectnumber';
72     $form->{title} = $locale->text('Projects');
73
74     $number = qq|
75         <tr>
76           <th align=right width=1%>|.$locale->text('Number').qq|</th>
77           <td><input name=projectnumber size=20></td>
78         </tr>
79         <tr>
80           <th align=right>|.$locale->text('Description').qq|</th>
81           <td><input name=description size=60></td>
82         </tr>
83 |;
84
85   }
86   if ($form->{type} eq 'partsgroup') {
87     $report = "partsgroup_report";
88     $sort = 'partsgroup';
89     $form->{title} = $locale->text('Groups');
90     
91     $number = qq|
92         <tr>
93           <th align=right width=1%>|.$locale->text('Group').qq|</th>
94           <td><input name=partsgroup size=20></td>
95         </tr>
96 |;
97
98   }
99
100   $form->header;
101
102   print qq|
103 <body>
104
105 <form method=post action=$form->{script}>
106
107 <input type=hidden name=sort value=$sort>
108 <input type=hidden name=type value=$form->{type}>
109
110 <table width=100%>
111   <tr>
112     <th class=listtop>$form->{title}</th>
113   </tr>
114   <tr height="5"></tr>
115   <tr>
116     <td>
117       <table width=100%>
118         $number
119         <tr>
120           <td></td>
121           <td><input name=status class=radio type=radio value=all checked>&nbsp;|.$locale->text('All').qq|
122           <input name=status class=radio type=radio value=orphaned>&nbsp;|.$locale->text('Orphaned').qq|</td>
123         </tr>
124       </table>
125     </td>
126   </tr>
127   <tr>
128     <td><hr size=3 noshade></td>
129   </tr>
130 </table>
131
132 <input type=hidden name=nextsub value=$report>
133
134 <input type=hidden name=path value=$form->{path}>
135 <input type=hidden name=login value=$form->{login}>
136 <input type=hidden name=password value=$form->{password}>
137
138 <br>
139 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
140 </form>
141
142 </body>
143 </html>
144 |;
145
146 }
147
148
149
150 sub project_report {
151
152   map { $form->{$_} = $form->unescape($form->{$_}) } (projectnumber, description);
153   PE->projects(\%myconfig, \%$form);
154
155   $callback = "$form->{script}?action=project_report&type=$form->{type}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}";
156   $href = $callback;
157   
158   if ($form->{status} eq 'all') {
159     $option = $locale->text('All');
160   }
161   if ($form->{status} eq 'orphaned') {
162     $option .= $locale->text('Orphaned');
163   }
164   if ($form->{projectnumber}) {
165     $href .= "&projectnumber=".$form->escape($form->{projectnumber});
166     $callback .= "&projectnumber=$form->{projectnumber}";
167     $option .= "\n<br>".$locale->text('Project')." : $form->{projectnumber}";
168   }
169   if ($form->{description}) {
170     $href .= "&description=".$form->escape($form->{description});
171     $callback .= "&description=$form->{description}";
172     $option .= "\n<br>".$locale->text('Description')." : $form->{description}";
173   }
174     
175
176   @column_index = $form->sort_columns(qw(projectnumber description));
177
178   $column_header{projectnumber} = qq|<th><a class=listheading href=$href&sort=projectnumber>|.$locale->text('Number').qq|</a></th>|;
179   $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
180
181   $form->{title} = $locale->text('Projects');
182
183   $form->header;
184  
185   print qq|
186 <body>
187
188 <table width=100%>
189   <tr>
190     <th class=listtop>$form->{title}</th>
191   </tr>
192   <tr height="5"></tr>
193   <tr>
194     <td>$option</td>
195   </tr>
196   <tr>
197     <td>
198       <table width=100%>
199         <tr class=listheading>
200 |;
201
202   map { print "$column_header{$_}\n" } @column_index;
203   
204   print qq|
205         </tr>
206 |;
207
208   # escape callback
209   $form->{callback} = $callback .= "&sort=$form->{sort}";
210
211   # escape callback for href
212   $callback = $form->escape($callback);
213   
214   foreach $ref (@{ $form->{project_list} }) {
215     
216     $i++; $i %= 2;
217     
218     print qq|
219         <tr valign=top class=listrow$i>
220 |;
221     
222     $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>|;
223     $column_data{description} = qq|<td>$ref->{description}&nbsp;</td>|;
224     
225     map { print "$column_data{$_}\n" } @column_index;
226     
227     print "
228         </tr>
229 ";
230   }
231   
232   print qq|
233       </table>
234     </td>
235   </tr>
236   <tr>
237     <td><hr size=3 noshade></td>
238   </tr>
239 </table>
240
241 <br>
242 <form method=post action=$form->{script}>
243
244 <input name=callback type=hidden value="$form->{callback}">
245
246 <input type=hidden name=type value=$form->{type}>
247
248 <input type=hidden name=path value=$form->{path}>
249 <input type=hidden name=login value=$form->{login}>
250 <input type=hidden name=password value=$form->{password}>
251
252 <input class=submit type=submit name=action value="|.$locale->text('Add').qq|">
253
254 </body>
255 </html>
256 |;
257
258 }
259
260
261 sub form_project_header {
262
263   $form->{title} = $locale->text("$form->{title} Project");
264   
265 # $locale->text('Add Project')
266 # $locale->text('Edit Project')
267
268   $form->{description} =~ s/"/&quot;/g;
269
270   if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
271     $description = qq|<textarea name="description" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{description}</textarea>|;
272   } else {
273     $description = qq|<input name=description size=60 value="$form->{description}">|;
274   }
275   
276   $form->header;
277
278   print qq|
279 <body>
280
281 <form method=post action=$form->{script}>
282
283 <input type=hidden name=id value=$form->{id}>
284 <input type=hidden name=type value=project>
285
286 <table width=100%>
287   <tr>
288     <th class=listtop>$form->{title}</th>
289   </tr>
290   <tr height="5"></tr>
291   <tr>
292     <td>
293       <table>
294         <tr>
295           <th align=right>|.$locale->text('Number').qq|</th>
296           <td><input name=projectnumber size=20 value="$form->{projectnumber}"></td>
297         </tr>
298         <tr>
299           <th align=right>|.$locale->text('Description').qq|</th>
300           <td>$description</td>
301         </tr>
302       </table>
303     </td>
304   </tr>
305   <tr>
306     <td colspan=2><hr size=3 noshade></td>
307   </tr>
308 </table>
309 |;
310
311 }
312
313
314 sub form_project_footer {
315
316   print qq|
317
318 <input name=callback type=hidden value="$form->{callback}">
319
320 <input type=hidden name=path value=$form->{path}>
321 <input type=hidden name=login value=$form->{login}>
322 <input type=hidden name=password value=$form->{password}>
323
324 <br><input type=submit class=submit name=action value="|.$locale->text('Save').qq|">
325 |;
326
327   if ($form->{id} && $form->{orphaned}) {
328     print qq|
329 <input type=submit class=submit name=action value="|.$locale->text('Delete').qq|">|;
330   }
331
332   print qq|
333 </form>
334
335 </body>
336 </html>
337 |;
338
339 }
340
341
342 sub save {
343
344   if ($form->{type} eq 'project') {
345     $form->isblank("projectnumber", $locale->text('Project Number missing!'));
346     PE->save_project(\%myconfig, \%$form);
347     $form->redirect($locale->text('Project saved!'));
348   }
349   if ($form->{type} eq 'partsgroup') {
350     $form->isblank("partsgroup", $locale->text('Group missing!'));
351     PE->save_partsgroup(\%myconfig, \%$form);
352     $form->redirect($locale->text('Group saved!'));
353   }
354
355 }
356
357
358 sub delete {
359
360   PE->delete_tuple(\%myconfig, \%$form);
361   
362   if ($form->{type} eq 'project') { 
363     $form->redirect($locale->text('Project deleted!'));
364   }
365   if ($form->{type} eq 'partsgroup') {
366     $form->redirect($locale->text('Group deleted!'));
367   }
368
369 }
370
371
372 sub continue { &{ $form->{nextsub} } };
373
374
375 sub partsgroup_report {
376
377   map { $form->{$_} = $form->unescape($form->{$_}) } (partsgroup);
378   PE->partsgroups(\%myconfig, \%$form);
379
380   $callback = "$form->{script}?action=partsgroup_report&type=$form->{type}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}";
381   
382   if ($form->{status} eq 'all') {
383     $option = $locale->text('All');
384   }
385   if ($form->{status} eq 'orphaned') {
386     $option .= $locale->text('Orphaned');
387   }
388   if ($form->{partsgroup}) {
389     $callback .= "&partsgroup=$form->{partsgroup}";
390     $option .= "\n<br>".$locale->text('Group')." : $form->{partsgroup}";
391   }
392    
393
394   @column_index = (partsgroup);
395
396   $column_header{partsgroup} = qq|<th class=listheading width=90%>|.$locale->text('Group').qq|</th>|;
397
398   $form->{title} = $locale->text('Groups');
399
400   $form->header;
401  
402   print qq|
403 <body>
404
405 <table width=100%>
406   <tr>
407     <th class=listtop>$form->{title}</th>
408   </tr>
409   <tr height="5"></tr>
410   <tr>
411     <td>$option</td>
412   </tr>
413   <tr>
414     <td>
415       <table width=100%>
416         <tr class=listheading>
417 |;
418
419   map { print "$column_header{$_}\n" } @column_index;
420   
421   print qq|
422         </tr>
423 |;
424
425   # escape callback
426   $form->{callback} = $callback;
427
428   # escape callback for href
429   $callback = $form->escape($callback);
430   
431   foreach $ref (@{ $form->{item_list} }) {
432     
433     $i++; $i %= 2;
434     
435     print qq|
436         <tr valign=top class=listrow$i>
437 |;
438     
439
440     $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>|;
441     
442     map { print "$column_data{$_}\n" } @column_index;
443     
444     print "
445         </tr>
446 ";
447   }
448   
449   print qq|
450       </table>
451     </td>
452   </tr>
453   <tr>
454     <td><hr size=3 noshade></td>
455   </tr>
456 </table>
457
458 <br>
459 <form method=post action=$form->{script}>
460
461 <input name=callback type=hidden value="$form->{callback}">
462
463 <input type=hidden name=type value=$form->{type}>
464
465 <input type=hidden name=path value=$form->{path}>
466 <input type=hidden name=login value=$form->{login}>
467 <input type=hidden name=password value=$form->{password}>
468
469 <input class=submit type=submit name=action value="|.$locale->text('Add').qq|">
470
471 </body>
472 </html>
473 |;
474
475 }
476
477
478 sub form_partsgroup_header {
479
480   $form->{title} = $locale->text("$form->{title} Group");
481   
482 # $locale->text('Add Group')
483 # $locale->text('Edit Group')
484
485   $form->{partsgroup} =~ s/"/&quot;/g;
486
487   
488   $form->header;
489
490   print qq|
491 <body>
492
493 <form method=post action=$form->{script}>
494
495 <input type=hidden name=id value=$form->{id}>
496 <input type=hidden name=type value=$form->{type}>
497
498 <table width=100%>
499   <tr>
500     <th class=listtop>$form->{title}</th>
501   </tr>
502   <tr height="5"></tr>
503   <tr>
504     <td>
505       <table width=100%>
506         <tr>
507           <th align=right>|.$locale->text('Group').qq|</th>
508           <td><input name=partsgroup size=30 value="$form->{partsgroup}"></td>
509         </tr>
510       </table>
511     </td>
512   </tr>
513   <tr>
514     <td colspan=2><hr size=3 noshade></td>
515   </tr>
516 </table>
517 |;
518
519 }
520
521
522 sub form_partsgroup_footer {
523
524   print qq|
525
526 <input name=callback type=hidden value="$form->{callback}">
527
528 <input type=hidden name=path value=$form->{path}>
529 <input type=hidden name=login value=$form->{login}>
530 <input type=hidden name=password value=$form->{password}>
531
532 <br><input type=submit class=submit name=action value="|.$locale->text('Save').qq|">
533 |;
534
535   if ($form->{id} && $form->{orphaned}) {
536     print qq|
537 <input type=submit class=submit name=action value="|.$locale->text('Delete').qq|">|;
538   }
539
540   print qq|
541 </form>
542
543 </body>
544 </html>
545 |;
546
547 }
548
549