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