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