639aea0b9acdc661867b09e92dd9029d0e1432fc
[fa-stable.git] / includes / ui / ui_view.inc
1 <?php
2
3 include_once($path_to_root . "/admin/db/voiding_db.inc");
4
5 //--------------------------------------------------------------------------------------
6
7 function get_supplier_trans_view_str($type, $trans_no, $label="")
8 {
9         global $path_to_root, $use_popup_windows;
10
11         $viewer = "";
12         if ($type == systypes::po())
13                 $viewer = "view_po.php";
14         elseif ($type == 20)
15                 $viewer = "view_supp_invoice.php";
16         elseif ($type == 21)
17                 $viewer = "view_supp_credit.php";
18         elseif ($type == 22)
19                 $viewer = "view_supp_payment.php";
20         elseif ($type == 25)
21                 $viewer = "view_grn.php";
22         else
23                 return null;
24
25         if ($label == "")
26                 $label = $trans_no;
27
28         if ($viewer != "")
29         {
30                 if ($use_popup_windows)
31                         $preview_str = "<a target='_blank' href='$path_to_root/purchasing/view/$viewer?trans_no=$trans_no' onclick=\"javascript:openWindow(this.href,this.target); return false;\" >$label</a>";
32                 else
33                         $preview_str = "<a target='_blank' href='$path_to_root/purchasing/view/$viewer?trans_no=$trans_no'>$label</a>";
34         }
35         else
36                 $preview_str = $label;
37
38         return $preview_str;
39 }
40
41 //--------------------------------------------------------------------------------------
42
43 function get_gl_view_str($type, $trans_no, $label="", $force=false)
44 {
45         global $path_to_root, $use_popup_windows;
46
47         if (!$force && !user_show_gl_info())
48                 return "";
49
50         if ($label == "")
51                 $label = _("GL");
52         if ($use_popup_windows)
53                 $gl_view = "<a target='_blank' href='$path_to_root/gl/view/gl_trans_view.php?type_id=$type&trans_no=$trans_no' onclick=\"javascript:openWindow(this.href,this.target); return false;\" >$label</a>";
54         else
55                 $gl_view = "<a target='_blank' href='$path_to_root/gl/view/gl_trans_view.php?type_id=$type&trans_no=$trans_no'>$label</a>";
56
57         return $gl_view;
58 }
59
60 //--------------------------------------------------------------------------------------
61
62 function get_gl_view_str_cell($type, $trans_no, $label="")
63 {
64         $str = get_gl_view_str($type, $trans_no, $label);
65         if ($str != "")
66                 return "<td>$str</td>";
67 }
68
69 //--------------------------------------------------------------------------------------
70
71 function get_customer_trans_view_str($type, $trans_no, $label="")
72 {
73         global $path_to_root, $use_popup_windows;
74
75         $viewer = "";
76         if ($type == 10)
77                 $viewer = "view_invoice.php";
78         elseif ($type == 11)
79                 $viewer = "view_credit.php";
80         elseif ($type == 12)
81                 $viewer = "view_receipt.php";
82         elseif ($type == 13)
83                 $viewer = "view_dispatch.php";
84         elseif ($type == 30)
85                 $viewer = "view_sales_order.php";
86         else
87                 return null;
88
89   if(!is_array($trans_no)) $trans_no = array($trans_no);
90
91   $lbl = $label;
92   $preview_str = '';
93   foreach($trans_no as $trans) {
94         if ($label == "")
95                 $lbl = $trans;
96
97         if($preview_str!='') $preview_str .= ',';
98
99         if ($viewer != "")
100         {
101                 if ($use_popup_windows)
102                         $preview_str .= "<a target='_blank' href='$path_to_root/sales/view/$viewer?trans_no=$trans' onclick=\"javascript:openWindow(this.href,this.target); return false;\" >$lbl</a>";
103                 else
104                         $preview_str .= "<a target='_blank' href='$path_to_root/sales/view/$viewer?trans_no=$trans'>$lbl</a>";
105         }
106         else
107                 $preview_str .= $lbl;
108   }
109
110         return $preview_str;
111 }
112
113 //--------------------------------------------------------------------------------------
114
115 function get_banking_trans_view_str($type, $trans_no, $label="")
116 {
117         global $path_to_root, $use_popup_windows;
118
119         $viewer = "";
120
121         if ($type == 4)
122                 $viewer = "bank_transfer_view.php";
123         elseif ($type == 1)
124                 $viewer = "gl_payment_view.php";
125         elseif ($type == 2)
126                 $viewer = "gl_deposit_view.php";
127         elseif ($type == 0)
128                 $viewer = "";
129         else
130                 return null;
131
132         if ($label == "")
133                 $label = $trans_no;
134
135         if ($viewer != "")
136         {
137                 if ($use_popup_windows)
138                         $preview_str = "<a target='_blank' href='$path_to_root/gl/view/$viewer?trans_no=$trans_no' onclick=\"javascript:openWindow(this.href,this.target); return false;\" >$label</a>";
139                 else
140                         $preview_str = "<a target='_blank' href='$path_to_root/gl/view/$viewer?trans_no=$trans_no'>$label</a>";
141         }
142         else
143                 $preview_str = $label;
144
145         return $preview_str;
146 }
147
148 //--------------------------------------------------------------------------------------
149
150 function get_inventory_trans_view_str($type, $trans_no, $label="")
151 {
152         global $path_to_root, $use_popup_windows;
153
154         $viewer = "";
155
156         if ($type == systypes::inventory_adjustment())
157                 $viewer = "view_adjustment.php";
158         elseif ($type == systypes::location_transfer())
159                 $viewer = "view_transfer.php";
160         else
161                 return null;
162
163         if ($label == "")
164                 $label = $trans_no;
165
166         if ($viewer != "")
167         {
168                 if ($use_popup_windows)
169                         $preview_str = "<a target='_blank' href='$path_to_root/inventory/view/$viewer?trans_no=$trans_no' onclick=\"javascript:openWindow(this.href,this.target); return false;\" >$label</a>";
170                 else
171                         $preview_str = "<a target='_blank' href='$path_to_root/inventory/view/$viewer?trans_no=$trans_no'>$label</a>";
172         }
173         else
174                 $preview_str = $label;
175
176         return $preview_str;
177 }
178
179 //--------------------------------------------------------------------------------------
180
181 function get_manufacturing_trans_view_str($type, $trans_no, $label="")
182 {
183         global $path_to_root, $use_popup_windows;
184
185         $viewer = "";
186
187         if ($type == 28)
188                 $viewer = "wo_issue_view.php";
189         elseif ($type == 29)
190                 $viewer = "wo_production_view.php";
191         elseif ($type == systypes::work_order())
192                 $viewer = "work_order_view.php";
193         else
194                 return null;
195
196         if ($label == "")
197                 $label = $trans_no;
198
199         if ($viewer != "")
200         {
201                 if ($use_popup_windows)
202                         $preview_str = "<a target='_blank' href='$path_to_root/manufacturing/view/$viewer?trans_no=$trans_no' onclick=\"javascript:openWindow(this.href,this.target); return false;\" >$label</a>";
203                 else
204                         $preview_str = "<a target='_blank' href='$path_to_root/manufacturing/view/$viewer?trans_no=$trans_no'>$label</a>";
205         }
206         else
207                 $preview_str = $label;
208
209         return $preview_str;
210 }
211
212 //--------------------------------------------------------------------------------------
213
214 function get_dimensions_trans_view_str($type, $trans_no, $label="")
215 {
216         global $path_to_root, $use_popup_windows;
217
218         $viewer = "";
219
220         if ($type == 40)
221                 $viewer = "view_dimension.php";
222         else
223                 return null;
224
225         if ($label == "")
226                 $label = $trans_no;
227
228         if ($viewer != "")
229         {
230                 if ($use_popup_windows)
231                         $preview_str = "<a target='_blank' href='$path_to_root/dimensions/view/$viewer?trans_no=$trans_no' onclick=\"javascript:openWindow(this.href,this.target); return false;\" >$label</a>";
232                 else
233                         $preview_str = "<a target='_blank' href='$path_to_root/dimensions/view/$viewer?trans_no=$trans_no'>$label</a>";
234         }
235         else
236                 $preview_str = $label;
237
238         return $preview_str;
239 }
240
241 //--------------------------------------------------------------------------------------
242
243 function get_trans_view_str($type, $trans_no, $label="")
244 {
245         $view_str = get_customer_trans_view_str($type, $trans_no, $label);
246         if ($view_str != null)
247                 return $view_str;
248
249         $view_str = get_supplier_trans_view_str($type, $trans_no, $label);
250         if ($view_str != null)
251                 return $view_str;
252
253         $view_str = get_banking_trans_view_str($type, $trans_no, $label);
254         if ($view_str != null)
255                 return $view_str;
256
257         $view_str = get_inventory_trans_view_str($type, $trans_no, $label);
258         if ($view_str != null)
259                 return $view_str;
260
261         $view_str = get_manufacturing_trans_view_str($type, $trans_no, $label);
262         if ($view_str != null)
263                 return $view_str;
264
265         $view_str = get_dimensions_trans_view_str($type, $trans_no, $label);
266         if ($view_str != null)
267                 return $view_str;
268
269         return null;
270 }
271
272 //--------------------------------------------------------------------------------------
273
274 function exchange_rate_display($from_currency, $to_currency, $date_, $buttons=true)
275 {
276         if ($from_currency != $to_currency)
277         {
278                 if ($buttons && isset($_POST['get_rate']))
279                 {
280                         $comp_currency = get_company_currency();
281                         if ($from_currency == $comp_currency)
282                                 $currency = $to_currency;
283                         else
284                                 $currency = $from_currency;
285                         $rate = get_ecb_rate($currency);
286                         if (get_date_exchange_rate($currency, $date_))
287                                 update_exchange_rate($currency, $date_, $rate, $rate);
288                         else
289                                 add_exchange_rate($currency, $date_, $rate, $rate);
290                         if ($from_currency == $comp_currency)
291                                 $rate = 1 / $rate;
292                 }
293                 else
294                         $rate = get_exchange_rate_from_to($to_currency, $from_currency, $date_);
295                 $rate = number_format2($rate, user_exrate_dec());
296         label_row(_("Exchange Rate:"),"1 " . $from_currency . " = " .  $rate . " " . $to_currency .
297                         ($buttons?"  " . submit('get_rate',_("Get"), false):""));
298         }
299 }
300
301 //--------------------------------------------------------------------------------------
302
303 function is_voided_display($type, $id, $label)
304 {
305         global $table_style;
306         $void_entry = get_voided_entry($type, $id);
307
308         if ($void_entry == null)
309                 return false;
310
311         start_table("width=50% $table_style");
312         echo "<tr><td align=center><font color=red>$label</font><br>";
313         echo "<font color=red>" . _("Date Voided:") . " " . sql2date($void_entry["date_"]) . "</font><br>";
314         if (strlen($void_entry["memo_"]) > 0)
315                 echo "<center><font color=red>" . _("Memo:") . " " . $void_entry["memo_"] . "</font><br>";
316         echo "</td></tr>";
317         end_table(1);
318
319         return true;
320 }
321
322 //--------------------------------------------------------------------------------------
323
324 function comments_display_row($type, $id)
325 {
326         $comments = get_comments($type, $id);
327         if ($comments and db_num_rows($comments))
328         {
329                 echo "<tr><td colspan=15>";
330         while ($comment = db_fetch($comments))
331         {
332                 echo $comment["memo_"] . "<br>";
333         }
334                 echo "</td></tr>";
335         }
336 }
337
338 //--------------------------------------------------------------------------------------
339
340 function get_comments_string($type, $type_no)
341 {
342         $str_return = "";
343         $result = get_comments($type, $type_no);
344         while ($comment = db_fetch($result))
345         {
346                 if (strlen($str_return))
347                         $str_return = $str_return . " \n";
348                 $str_return = $str_return . $comment["memo_"];
349         }
350         return $str_return;
351 }
352
353 //--------------------------------------------------------------------------------------
354
355 function view_stock_status($stock_id, $description=null)
356 {
357         global $path_to_root;
358         if ($description)
359                 //hyperlink_params_separate($path_to_root . "/inventory/inquiry/stock_status.php", (user_show_codes()?$stock_id . " - ":"") . $description, "stock_id=$stock_id");
360                 $preview_str = "<a target='_blank' href='$path_to_root/inventory/inquiry/stock_status.php?stock_id=$stock_id' onclick=\"javascript:openWindow(this.href,this.target); return false;\" >". (user_show_codes()?$stock_id . " - ":"") . $description."</a>";
361         else
362                 //hyperlink_params_separate($path_to_root . "/inventory/inquiry/stock_status.php", $stock_id, "stock_id=$stock_id");
363                 $preview_str = "<a target='_blank' href='$path_to_root/inventory/inquiry/stock_status.php?stock_id=$stock_id' onclick=\"javascript:openWindow(this.href,this.target); return false;\" >$stock_id</a>";
364         echo $preview_str;
365 }
366
367 function view_stock_status_cell($stock_id, $description=null)
368 {
369         echo "<td>";
370         view_stock_status($stock_id, $description);
371         echo "</td>";
372 }
373
374 //--------------------------------------------------------------------------------------
375
376 function display_debit_or_credit_cells($value)
377 {
378         if ($value > 0)
379         {
380                 amount_cell($value);
381                 label_cell("");
382         }
383         elseif ($value < 0)
384         {
385                 label_cell("");
386                 amount_cell(abs($value));
387         }
388         else
389         {
390                 //label_cell("");
391                 amount_cell(0);
392                 label_cell("");
393         }
394 }
395
396 //--------------------------------------------------------------------------------------
397
398 function display_customer_trans_tax_details($tax_items, $columns)
399 {
400     while ($tax_item = db_fetch($tax_items))
401     {
402         $tax = number_format2($tax_item['amount'],user_price_dec());
403         if ($tax_item['included_in_price'])
404                 label_row(_("Included") . " " . $tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%) " .
405                         _("Amount") . ": $tax", "", "colspan=$columns align=right", "align=right");
406         else
407                 label_row($tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%)",
408                         $tax, "colspan=$columns align=right", "align=right");
409     }
410 }
411
412 //--------------------------------------------------------------------------------------
413
414 function display_supp_trans_tax_details($tax_items, $columns)
415 {
416     while ($tax_item = db_fetch($tax_items))
417     {
418         $tax = number_format2(abs($tax_item['amount']),user_price_dec());
419         if ($tax_item['included_in_price'])
420                 label_row(_("Included") . " " . $tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%) " .
421                         _("Amount:") . ": $tax", "colspan=$columns align=right", "align=right");
422         else
423                 label_row($tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%)",
424                         $tax, "colspan=$columns align=right", "align=right");
425     }
426 }
427
428 //--------------------------------------------------------------------------------------
429
430 function display_edit_tax_items($taxes, $columns, $tax_included, $leftspan=0)
431 {
432         $total = 0;
433
434     foreach ($taxes as $taxitem)
435     {
436         if ($tax_included)
437         {
438                 label_row(_("Included") . " " . $taxitem['tax_type_name'] . " (" . $taxitem['rate'] . "%) " .
439                         _("Amount:") . " " . number_format2($taxitem['Value'],user_price_dec()), "", "colspan=$columns align=right", "align=right",$leftspan);
440         }
441         else
442         {
443                 label_row($taxitem['tax_type_name'] . " (" . $taxitem['rate'] . "%)",
444                         number_format2($taxitem['Value'],user_price_dec()), "colspan=$columns align=right", "align=right",$leftspan);
445                 $total +=  $taxitem['Value'];
446         }
447     }
448
449     return $total;
450 }
451
452 //--------------------------------------------------------------------------------------
453
454 function display_footer_exit()
455 {
456         global $path_to_root;
457         br(2);
458         end_page();
459         exit;
460 }
461
462 //--------------------------------------------------------------------------------------
463
464 function display_allocations($alloc_result, $total)
465 {
466         global $table_style;
467
468         if (!$alloc_result || db_num_rows($alloc_result) == 0)
469                 return;
470
471     display_heading2(_("Allocations"));
472
473     start_table("$table_style width=80%");
474
475     $th = array( _("Type"), _("Number"), _("Date"), _("Total Amount"),
476         _("Left to Allocate"), _("This Allocation"));
477         table_header($th);
478     $k = $total_allocated = 0;
479
480     while ($alloc_row = db_fetch($alloc_result))
481     {
482
483         alt_table_row_color($k);
484
485         label_cell(systypes::name($alloc_row['type']));
486         label_cell(get_trans_view_str($alloc_row['type'],$alloc_row['trans_no']));
487         label_cell(sql2date($alloc_row['tran_date']));
488         amount_cell($alloc_row['Total']);
489         //amount_cell($alloc_row['Total'] - $alloc_row['PrevAllocs'] - $alloc_row['amt']);
490         amount_cell($alloc_row['Total'] - $alloc_row['amt']);
491         amount_cell($alloc_row['amt']);
492         end_row();
493
494         $total_allocated += $alloc_row['amt'];
495     }
496     start_row();
497         label_cell(_("Total Allocated:"), "align=right colspan=5");
498         amount_cell($total_allocated);
499         end_row();
500         start_row();
501     label_cell(_("Left to Allocate:"), "align=right colspan=5");
502     amount_cell($total - $total_allocated);
503     end_row();
504
505     end_table(1);
506 }
507
508 //--------------------------------------------------------------------------------------
509
510 function display_allocations_from($person_type, $person_id, $type, $type_no, $total)
511 {
512         switch ($person_type)
513         {
514                 case payment_person_types::customer() :
515                         $alloc_result = get_allocatable_to_cust_transactions($person_id, $type_no, $type);
516                         display_allocations($alloc_result, $total);
517                         return;
518                 case payment_person_types::supplier() :
519                         $alloc_result = get_allocatable_to_supp_transactions($person_id, $type_no, $type);
520                         display_allocations($alloc_result, $total);
521                         return;
522         }
523 }
524
525 function get_js_go_back()
526 {
527         $js = "\n<script type=\"text/javascript\">\n"
528                 . "<!--\n"
529                 . "function goBack()\n"
530                 . "{\n"
531                 . "     if (window.history.length <= 1)\n"
532                 . "      window.close();\n"
533                 . "     else\n"
534                 . "      window.history.go(-1);\n"
535                 . "}\n"
536                 . "-->\n"
537                 . "</script>\n";
538         return $js;
539 }
540
541 function get_js_open_window($width, $height)
542 {
543         $js = "\n<script type=\"text/javascript\">\n"
544                 . "<!--\n"
545                 . "function openWindow(url, title)\n"
546                 . "{\n"
547                 . " var left = (screen.width - $width) / 2;\n"
548                 . " var top = (screen.height - $height) / 2;\n"
549                 . " window.open(url, title, 'width=$width,height=$height,left='+left+',top='+top+',screenX='+left+',screenY='+top+',status=no,scrollbars=yes');\n"
550                 . "}\n"
551                 . "-->\n"
552                 . "</script>\n";
553         return $js;
554 }
555
556 function get_js_form_entry($edit_name, $sel_name, $next_name)
557 {
558         $js = "\n<script type=\"text/javascript\">\n"
559                 . "<!--\n"
560                 . "function recalcAccounts()\n"
561                 . "{\n"
562                 . "     var myForm = document.forms[0];\n"
563                 . "     var len = myForm.$sel_name.length;\n"
564                 . "     var txt;\n"
565                 . "     var ac = myForm.$edit_name.value;\n"
566                 . "     var i;\n"
567                 . "     myForm.$sel_name.options[myForm.$sel_name.selectedIndex].selected = false;\n"
568                 . "     for (i = 0; i < len; i++)\n"
569                 . "     {\n"
570                 . "             txt = myForm.$sel_name.options[i].text;\n"
571                 . "             if (txt.indexOf(ac) == 0)\n"
572                 . "             {\n"
573                 . "                     myForm.$sel_name.options[i].selected = true;\n"
574                 . "                     break;\n"
575                 . "             }\n"
576                 . "     }\n"
577                 . "}\n"
578                 . "function setAccount(p, s)\n"
579                 . "{\n"
580                 . "     var myForm = document.forms[0];\n"
581                 . " if (p == 0 && myForm.$edit_name.value == \"\")\n"
582                 . "             return true;\n"
583                 . "     myForm.$edit_name.value = myForm.$sel_name.options[myForm.$sel_name.selectedIndex].value;\n"
584                 . " if (s)\n"
585                 . "  myForm.submit();\n"
586                 . "     myForm.$next_name.focus();\n"
587                 . "     return true;\n"
588                 . "}\n"
589                 . "-->\n"
590                 . "</script>\n";
591         return $js;
592 }
593
594 function get_js_set_focus($name)
595 {
596         $js = "\n<script type=\"text/javascript\">\n"
597                 . "<!--\n"
598                 . "function setFocus()\n"
599                 . "{\n"
600                 . "     document.forms[0].$name.focus();\n"
601                 . "}\n"
602                 . "-->\n"
603                 . "</script>\n";
604         return $js;
605 }
606
607 function get_js_png_fix()
608 {
609         $js = "<script type=\"text/javascript\">\n"
610                 . "function fixPNG(myImage)\n"
611                 . "{\n"
612                 . " var arVersion = navigator.appVersion.split(\"MSIE\")\n"
613                 . " var version = parseFloat(arVersion[1])\n"
614         . " if ((version >= 5.5) && (version < 7) && (document.body.filters))\n"
615         . " {\n"
616         . "  var imgID = (myImage.id) ? \"id='\" + myImage.id + \"' \" : \"\"\n"
617                 . "  var imgClass = (myImage.className) ? \"class='\" + myImage.className + \"' \" : \"\"\n"
618                 . "  var imgTitle = (myImage.title) ?\n"
619                 . "    \"title='\" + myImage.title  + \"' \" : \"title='\" + myImage.alt + \"' \"\n"
620                 . "  var imgStyle = \"display:inline-block;\" + myImage.style.cssText\n"
621                 . "  var strNewHTML = \"<span \" + imgID + imgClass + imgTitle\n"
622         . "    + \" style=\\\"\" + \"width:\" + myImage.width\n"
623         . "    + \"px; height:\" + myImage.height\n"
624         . "    + \"px;\" + imgStyle + \";\"\n"
625         . "    + \"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader\"\n"
626         . "    + \"(src=\'\" + myImage.src + \"\', sizingMethod='scale');\\\"></span>\"\n"
627                 . "  myImage.outerHTML = strNewHTML\n"
628         . " }\n"
629                 . "}\n"
630                 . "</script>\n";
631         return $js;
632 }
633
634 function get_js_date_picker()
635 {
636         global $dateseps, $date_system;
637
638         $how = user_date_format();                              // 0 = us/ca, 1 = eu, au, nz, 2 = jp, sw
639         $sep = $dateseps[user_date_sep()];              // date separator
640         $wstart = (($date_system == 1 || $date_system == 2) ? 6 : ($how == 0 ? 0 : 1));                 // weekstart (sun = 0, mon = 1)
641         $months = array(_("January"),_("February"),_("March"),_("April"),_("May"),_("June"),_("July"),_("August"),_("September"),_("October"),_("November"),_("December"));
642         $wdays = array(_("Su"),_("Mo"),_("Tu"),_("We"),_("Th"),_("Fr"),_("Sa"));
643         $back = _("Back");
644         if ($date_system == 1)
645                 list($cyear, $cmon, $cday) = gregorian_to_jalali(date("Y"), date("n"), date("j"));
646         else if ($date_system == 2)
647                 list($cyear, $cmon, $cday) = gregorian_to_islamic(date("Y"), date("n"), date("j"));
648
649         $js = "<style>
650 #CCIFrame { display: none; left: 0px; position: absolute; top: 0px; height: 250px; width: 250px; z-index: 99;}
651 #CC { position:absolute; background-color:#FFF; margin:0; padding:0; display:none; z-index: 100;}
652 #CC table { font-family: arial, verdana, helvetica, sans-serif;font-size: 8pt; border-left: 1px solid #336; border-right: 1px solid #336;}
653 #CC th { font-weight: normal;}
654 #CC th a { font-weight: normal; text-decoration: none; color: #FFF; padding: 1px;}
655 #CC td { text-align: center;}
656 #CC .header { background-color: #336;}
657 #CC .weekday { background-color: #DDD; color: #000;}
658 #CC .weekend { background-color: #FFC; color: #000;}
659 #CC .current { border: 1px solid #339; background-color: #336; color: #FFF;}
660 #CC .weekday,#CC .weekend,#CC .current { display: block; text-decoration: none; border: 1px solid #FFF; width: 2em;}
661 #CC .weekday:hover,#CC .weekend:hover,#CC .current:hover { color: #FFF; background-color: #336; border: 1px solid #999;}
662 #CC .previous { text-align: left;}
663 #CC .next { text-align: right;}
664 #CC .previous,#CC .next { padding: 1px 3px 1px 3px; font-size: 1.4em;}
665 #CC .previous a,#CC .next a { color: #FFF; text-decoration: none; font-weight: bold;}
666 #CC .title { text-align: center; font-weight: bold; color: #FFF;}
667 #CC .empty { background-color: #CCC; border: 1px solid #FFF;}
668 </style>
669 ";
670         $js .= "<script type=\"text/javascript\">
671 <!--\n
672 function positionInfo(object) {
673   var p_elm = object;
674   this.getElementLeft = getElementLeft;
675   function getElementLeft() {
676     var x = 0;
677     var elm;
678     if(typeof(p_elm) == 'object'){
679       elm = p_elm;
680     } else {
681       elm = document.getElementById(p_elm);
682     }
683     while (elm != null) {
684       x+= elm.offsetLeft;
685       elm = elm.offsetParent;
686     }
687     return parseInt(x);
688   }
689   this.getElementWidth = getElementWidth;
690   function getElementWidth(){
691     var elm;
692     if(typeof(p_elm) == 'object'){
693       elm = p_elm;
694     } else {
695       elm = document.getElementById(p_elm);
696     }
697     return parseInt(elm.offsetWidth);
698   }
699   this.getElementRight = getElementRight;
700   function getElementRight(){
701     return getElementLeft(p_elm) + getElementWidth(p_elm);
702   }
703   this.getElementTop = getElementTop;
704   function getElementTop() {
705     var y = 0;
706     var elm;
707     if(typeof(p_elm) == 'object'){
708       elm = p_elm;
709     } else {
710       elm = document.getElementById(p_elm);
711     }
712     while (elm != null) {
713       y+= elm.offsetTop;
714       elm = elm.offsetParent;
715     }
716     return parseInt(y);
717   }
718   this.getElementHeight = getElementHeight;
719   function getElementHeight(){
720     var elm;
721     if(typeof(p_elm) == 'object'){
722       elm = p_elm;
723     } else {
724       elm = document.getElementById(p_elm);
725     }
726     return parseInt(elm.offsetHeight);
727   }
728   this.getElementBottom = getElementBottom;
729   function getElementBottom(){
730     return getElementTop(p_elm) + getElementHeight(p_elm);
731   }
732 }
733 function CC() {
734   var calendarId = 'CC';
735   var currentYear = 0;
736   var currentMonth = 0;
737   var currentDay = 0;
738   var selectedYear = 0;
739   var selectedMonth = 0;
740   var selectedDay = 0;
741   var months = ['$months[0]','$months[1]','$months[2]','$months[3]','$months[4]','$months[5]','$months[6]','$months[7]','$months[8]','$months[9]','$months[10]','$months[11]'];
742   var wdays = ['$wdays[0]', '$wdays[1]', '$wdays[2]', '$wdays[3]', '$wdays[4]', '$wdays[5]', '$wdays[6]'];
743   var dateField = null;
744   function getProperty(p_property){
745     var p_elm = calendarId;
746     var elm = null;
747     if(typeof(p_elm) == 'object'){
748       elm = p_elm;
749     } else {
750       elm = document.getElementById(p_elm);
751     }
752     if (elm != null){
753       if(elm.style){
754         elm = elm.style;
755         if(elm[p_property]){
756           return elm[p_property];
757         } else {
758           return null;
759         }
760       } else {
761         return null;
762       }
763     }
764   }
765   function setElementProperty(p_property, p_value, p_elmId){
766     var p_elm = p_elmId;
767     var elm = null;
768     if(typeof(p_elm) == 'object'){
769       elm = p_elm;
770     } else {
771       elm = document.getElementById(p_elm);
772     }
773     if((elm != null) && (elm.style != null)){
774       elm = elm.style;
775       elm[ p_property ] = p_value;
776     }
777   }
778   function setProperty(p_property, p_value) {
779     setElementProperty(p_property, p_value, calendarId);
780   }
781   function getDaysInMonth(year, month) {
782 ";
783         if ($date_system == 1)
784                 $js .= "
785     return [31,31,31,31,31,31,30,30,30,30,30,(((((((year - ((year > 0) ? 474 : 473)) % 2820) + 474) + 38) * 682) % 2816) < 682 ? 30 : 29)][month-1];
786 ";
787         else if ($date_system == 2)
788                 $js .= "
789     return [30,29,30,29,30,29,30,29,30,29,30,(((((11 * year) + 14) % 30) < 11) ? 30 : 29)][month-1];
790 ";
791         else
792                 $js .= "
793     return [31,((!(year % 4 ) && ( (year % 100 ) || !( year % 400 ) ))?29:28),31,30,31,30,31,31,30,31,30,31][month-1];
794 ";
795         $js .= "
796   }
797   function getDayOfWeek(year, month, day) {
798 ";
799         if ($date_system == 1 || $date_system == 2)
800         {
801                 $js .= "
802         function mod(a, b)
803         {
804             return a - (b * Math.floor(a / b));
805         }
806         function jwday(j)
807         {
808             return mod(Math.floor((j + 1.5)), 7);
809         }
810 ";
811         if ($date_system == 1)
812                 $js .= "
813     var epbase, epyear, t;
814     epbase = year - ((year >= 0) ? 474 : 473);
815     epyear = 474 + mod(epbase, 2820);
816     t = day + ((month <= 7) ? ((month - 1) * 31) : (((month - 1) * 30) + 6)) +
817       Math.floor(((epyear * 682) - 110) / 2816) + (epyear - 1) * 365 +
818       Math.floor(epbase / 2820) * 1029983 + (1948320.5 - 1);
819 ";
820         else if ($date_system == 2)
821                 $js .= "
822         var t;
823         t = Math.floor((11 * year + 3) / 30) + 354 * year + 30 * month -
824           Math.floor((month - 1) / 2) + day + 1948440 - 385;
825 ";
826         $js .= "
827     return jwday(t);
828 ";
829         }
830         else
831                 $js .= "
832     var date = new Date(year,month-1,day)
833     return date.getDay();
834 ";
835         $js .= "
836   }
837   this.clearDate = clearDate;
838   function clearDate() {
839     dateField.value = '';
840     hide();
841   }
842   this.setDate = setDate;
843   function setDate(year, month, day) {
844     if (dateField) {
845       if (month < 10) {month = '0' + month;}
846       if (day < 10) {day = '0' + day;}
847 ";
848         if ($how == 0)
849                 $js .= "
850       var dateString = month+'$sep'+day+'$sep'+year;
851 ";
852         else if ($how == 1)
853                 $js .= "
854       var dateString = day+'$sep'+month+'$sep'+year;
855 ";
856         else
857                 $js .= "
858       var dateString = year+'$sep'+month+'$sep'+day;
859 ";
860         $js .= "
861       dateField.value = dateString;
862       hide();
863     }
864     return;
865   }
866   this.changeMonth = changeMonth;
867   function changeMonth(change) {
868     currentMonth += change;
869     currentDay = 0;
870     if(currentMonth > 12) {
871       currentMonth = 1;
872       currentYear++;
873     } else if(currentMonth < 1) {
874       currentMonth = 12;
875       currentYear--;
876     }
877     calendar = document.getElementById(calendarId);
878     calendar.innerHTML = calendarDrawTable();
879   }
880   this.changeYear = changeYear;
881   function changeYear(change) {
882     currentYear += change;
883     currentDay = 0;
884     calendar = document.getElementById(calendarId);
885     calendar.innerHTML = calendarDrawTable();
886   }
887   function getCurrentYear() {
888     var year = new Date().getYear();
889     if(year < 1900) year += 1900;
890     return year;
891   }
892   function getCurrentMonth() {
893     return new Date().getMonth() + 1;
894   }
895   function getCurrentDay() {
896     return new Date().getDate();
897   }
898   function calendarDrawTable() {
899     var dayOfMonth = 1;
900     var wstart = $wstart;
901     var validDay = 0;
902     var startDayOfWeek = getDayOfWeek(currentYear, currentMonth, dayOfMonth);
903     var daysInMonth = getDaysInMonth(currentYear, currentMonth);
904     var css_class = null; //CSS class for each day
905     var table = \"<table cellspacing='0' cellpadding='0' border='0'>\";
906     table += \"<tr class='header'>\";
907     table += \"  <td colspan='2' class='previous'><a href='javascript:changeCCMonth(-1);'>&lt;</a><br><a href='javascript:changeCCYear(-1);'>&laquo;</a></td>\";
908     table += \"  <td colspan='3' class='title'>\" + months[currentMonth-1] + \"<br>\" + currentYear + \"</td>\";
909     table += \"  <td colspan='2' class='next'><a href='javascript:changeCCMonth(1);'>&gt;</a><br><a href='javascript:changeCCYear(1);'>&raquo;</a></td>\";
910     table += \"</tr>\";
911     table += \"<tr>\";
912     for (var n=0; n<7; n++)
913         table += \"<th>\" + wdays[(wstart+n)%7]+\"</th>\";
914     table += \"</tr>\";
915     for(var week=0; week < 6; week++) {
916       table += \"<tr>\";
917       for(var n=0; n < 7; n++) {
918         dayOfWeek = (wstart+n)%7;
919         if(week == 0 && startDayOfWeek == dayOfWeek) {
920           validDay = 1;
921         } else if (validDay == 1 && dayOfMonth > daysInMonth) {
922           validDay = 0;
923         }
924         if(validDay) {
925           if (dayOfMonth == selectedDay && currentYear == selectedYear && currentMonth == selectedMonth) {
926             css_class = 'current';
927 ";
928         if ($date_system == 1 || $date_system == 2)
929                 $js .= "
930           } else if (dayOfWeek == 5) {
931 ";
932         else
933                 $js .= "
934           } else if (dayOfWeek == 0 || dayOfWeek == 6) {
935 ";
936                 $js .= "
937             css_class = 'weekend';
938           } else {
939             css_class = 'weekday';
940           }
941           table += \"<td><a class='\"+css_class+\"' href=\\\"javascript:setCCDate(\"+currentYear+\",\"+currentMonth+\",\"+dayOfMonth+\")\\\">\"+dayOfMonth+\"</a></td>\";
942           dayOfMonth++;
943         } else {
944           table += \"<td class='empty'>&nbsp;</td>\";
945         }
946       }
947       table += \"</tr>\";
948     }
949     table += \"<tr class='header'><th colspan='7' style='padding: 3px;'><a href='javascript:hideCC();'>$back</a></td></tr>\";
950     table += \"</table>\";
951     return table;
952   }
953   this.show = show;
954   function show(field) {
955     can_hide = 0;
956     if (dateField == field) {
957       return;
958     } else {
959       dateField = field;
960     }
961     if(dateField) {
962       try {
963         var dateString = new String(dateField.value);
964         var dateParts = dateString.split('$sep');
965 ";
966         if ($how == 0)
967                 $js .= "
968         selectedMonth = parseInt(dateParts[0],10);
969         selectedDay = parseInt(dateParts[1],10);
970         selectedYear = parseInt(dateParts[2],10);
971 ";
972         else if ($how == 1)
973                 $js .= "
974         selectedDay = parseInt(dateParts[0],10);
975         selectedMonth = parseInt(dateParts[1],10);
976         selectedYear = parseInt(dateParts[2],10);
977 ";
978         else
979                 $js .= "
980         selectedYear = parseInt(dateParts[0],10);
981         selectedMonth = parseInt(dateParts[1],10);
982         selectedDay = parseInt(dateParts[2],10);
983 ";
984         $js .= "
985       } catch(e) {}
986     }
987     if (!(selectedYear && selectedMonth && selectedDay)) {
988 ";
989         if ($date_system == 1 || $date_system == 2)
990         {
991                 $js .= "
992       selectedMonth = $cmon;
993       selectedDay = $cday;
994       selectedYear = $cyear;
995 ";
996         }
997         else
998         {
999                 $js .= "
1000       selectedMonth = getCurrentMonth();
1001       selectedDay = getCurrentDay();
1002       selectedYear = getCurrentYear();
1003 ";
1004         }
1005         $js .= "
1006     }
1007     currentMonth = selectedMonth;
1008     currentDay = selectedDay;
1009     currentYear = selectedYear;
1010     if(document.getElementById){
1011       calendar = document.getElementById(calendarId);
1012       calendar.innerHTML = calendarDrawTable(currentYear, currentMonth);
1013       setProperty('display', 'block');
1014       var fieldPos = new positionInfo(dateField);
1015       var calendarPos = new positionInfo(calendarId);
1016       var x = fieldPos.getElementLeft();
1017       var y = fieldPos.getElementBottom();
1018       setProperty('left', x + 'px');
1019       setProperty('top', y + 'px');
1020       if (document.all) {
1021         setElementProperty('display', 'block', 'CCIframe');
1022         setElementProperty('left', x + 'px', 'CCIframe');
1023         setElementProperty('top', y + 'px', 'CCIframe');
1024         setElementProperty('width', calendarPos.getElementWidth() + 'px', 'CCIframe');
1025         setElementProperty('height', calendarPos.getElementHeight() + 'px', 'CCIframe');
1026       }
1027     }
1028   }
1029   this.hide = hide;
1030   function hide() {
1031     if(dateField) {
1032       setProperty('display', 'none');
1033       setElementProperty('display', 'none', 'CCIframe');
1034       dateField = null;
1035     }
1036   }
1037   this.visible = visible;
1038   function visible() {
1039     return dateField
1040   }
1041   this.can_hide = can_hide;
1042   var can_hide = 0;
1043 }
1044 var cC = new CC();
1045 function date_picker(textField) {
1046   cC.show(textField);
1047 }
1048 function hideCC() {
1049   if (cC.visible()) {
1050     cC.hide();
1051   }
1052 }
1053 function setCCDate(year, month, day) {
1054   cC.setDate(year, month, day);
1055 }
1056 function changeCCYear(change) {
1057   cC.changeYear(change);
1058 }
1059 function changeCCMonth(change) {
1060   cC.changeMonth(change);
1061 }
1062 document.write(\"<iframe id='CCIframe' src='javascript:false;' frameBorder='0' scrolling='no'></iframe>\");
1063 document.write(\"<div id='CC'></div>\");
1064 -->
1065 </script>
1066 ";
1067         return $js;
1068 }
1069
1070 function get_js_allocate() {
1071         return "<script>function allocate_all(doc) {
1072         var alloc = 1*document.getElementsByName('left_to_allocate')[0].value;
1073         var amount = 1*document.getElementsByName('amount'+doc)[0].value;
1074         var unallocated = 1*document.getElementsByName('un_allocated'+doc)[0].value;
1075         if(unallocated<amount) amount = unallocated;
1076         if( (unallocated-amount)<=alloc){
1077                 alloc-=unallocated-amount;
1078         amount=unallocated;
1079         }else{
1080         amount=amount+alloc;
1081         alloc=0;
1082         }
1083         document.getElementsByName('amount'+doc)[0].value = amount;
1084         document.getElementsByName('left_to_allocate')[0].value = alloc;
1085         }
1086         function allocate_none(doc) {
1087                 amount = document.getElementsByName('amount'+doc)[0];
1088         document.getElementsByName('left_to_allocate')[0].value +=
1089                         amount.value;
1090         amount.value=0;  }
1091         </script>";
1092 }
1093
1094 function alert($msg)
1095 {
1096         echo "\n<script type=\"text/javascript\">\n"
1097                 . "<!--\n"
1098                 . "alert('$msg');\n"
1099                 . "-->\n"
1100                 . "</script>\n";
1101 }
1102
1103 if (!function_exists('_vd'))
1104 {
1105         function _vd($mixed, $title = '', $exit = false)
1106         {
1107         // Only the site admin is able to proceed here.
1108         echo (!empty($title) ? ($title .':') : '') .'<pre>';
1109         var_dump($mixed);
1110         echo "</pre>\n";
1111         if ($exit)
1112                 exit;
1113         }
1114 }
1115
1116 ?>