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