2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 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/gpl-3.0.html>.
11 ***********************************************************************/
12 include_once($path_to_root . "/admin/db/voiding_db.inc");
13 include_once($path_to_root . "/includes/types.inc");
15 //--------------------------------------------------------------------------------------
17 function get_supplier_trans_view_str($type, $trans_no, $label="", $icon=false)
22 if ($type == systypes::po())
23 $viewer = "view_po.php";
25 $viewer = "view_supp_invoice.php";
27 $viewer = "view_supp_credit.php";
29 $viewer = "view_supp_payment.php";
31 $viewer = "view_grn.php";
40 $pars = access_string($label);
41 if (user_graphic_links() && $icon)
42 $pars[0] = set_icon($icon, $pars[0]);
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>";
46 $preview_str = $label;
51 //--------------------------------------------------------------------------------------
53 function get_gl_view_str($type, $trans_no, $label="", $force=false)
57 if (!$force && !user_show_gl_info())
66 $pars = access_string($label);
67 if (user_graphic_links() && $icon)
68 $pars[0] = set_icon($icon, $pars[0]);
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>";
74 //--------------------------------------------------------------------------------------
76 function get_gl_view_str_cell($type, $trans_no, $label="")
78 $str = get_gl_view_str($type, $trans_no, $label);
80 return "<td>$str</td>";
83 //--------------------------------------------------------------------------------------
85 function get_customer_trans_view_str($type, $trans_no, $label="", $icon=false)
91 $viewer = "view_invoice.php";
93 $viewer = "view_credit.php";
95 $viewer = "view_receipt.php";
97 $viewer = "view_dispatch.php";
99 $viewer = "view_sales_order.php";
103 if(!is_array($trans_no)) $trans_no = array($trans_no);
108 foreach($trans_no as $trans) {
111 if($preview_str!='') $preview_str .= ',';
115 $pars = access_string($lbl);
116 if (user_graphic_links() && $icon)
117 $pars[0] = set_icon($icon, $pars[0]);
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>";
121 $preview_str .= $lbl;
127 //--------------------------------------------------------------------------------------
129 function get_banking_trans_view_str($type, $trans_no, $label="", $icon=false)
131 global $path_to_root;
136 $viewer = "bank_transfer_view.php";
138 $viewer = "gl_payment_view.php";
140 $viewer = "gl_deposit_view.php";
151 $pars = access_string($label);
152 if (user_graphic_links() && $icon)
153 $pars[0] = set_icon($icon, $pars[0]);
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>";
157 $preview_str = $label;
162 //--------------------------------------------------------------------------------------
164 function get_inventory_trans_view_str($type, $trans_no, $label="", $icon=false)
166 global $path_to_root;
170 if ($type == systypes::inventory_adjustment())
171 $viewer = "view_adjustment.php";
172 elseif ($type == systypes::location_transfer())
173 $viewer = "view_transfer.php";
182 $pars = access_string($label);
183 if (user_graphic_links() && $icon)
184 $pars[0] = set_icon($icon, $pars[0]);
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>";
188 $preview_str = $label;
193 //--------------------------------------------------------------------------------------
195 function get_manufacturing_trans_view_str($type, $trans_no, $label="", $icon=false)
197 global $path_to_root;
202 $viewer = "wo_issue_view.php";
204 $viewer = "wo_production_view.php";
205 elseif ($type == systypes::work_order())
206 $viewer = "work_order_view.php";
215 $pars = access_string($label);
216 if (user_graphic_links() && $icon)
217 $pars[0] = set_icon($icon, $pars[0]);
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>";
221 $preview_str = $label;
226 //--------------------------------------------------------------------------------------
228 function get_dimensions_trans_view_str($type, $trans_no, $label="", $icon=false)
230 global $path_to_root;
235 $viewer = "view_dimension.php";
244 $pars = access_string($label);
245 if (user_graphic_links() && $icon)
246 $pars[0] = set_icon($icon, $pars[0]);
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>";
250 $preview_str = $label;
255 //--------------------------------------------------------------------------------------
257 function get_trans_view_str($type, $trans_no, $label="", $icon=false)
259 $view_str = get_customer_trans_view_str($type, $trans_no, $label, $icon);
260 if ($view_str != null)
263 $view_str = get_supplier_trans_view_str($type, $trans_no, $label, $icon);
264 if ($view_str != null)
267 $view_str = get_banking_trans_view_str($type, $trans_no, $label, $icon);
268 if ($view_str != null)
271 $view_str = get_inventory_trans_view_str($type, $trans_no, $label, $icon);
272 if ($view_str != null)
275 $view_str = get_manufacturing_trans_view_str($type, $trans_no, $label, $icon);
276 if ($view_str != null)
279 $view_str = get_dimensions_trans_view_str($type, $trans_no, $label, $icon);
280 if ($view_str != null)
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.
291 function exchange_rate_display($from_currency, $to_currency, $date_, $edit_rate=false)
295 if ($from_currency != $to_currency)
297 $comp_currency = get_company_currency();
298 if ($from_currency == $comp_currency)
299 $currency = $to_currency;
301 $currency = $from_currency;
303 if ($date_ == Today()) {
304 $rate = get_date_exchange_rate($currency, $date_);
306 $rate = get_ecb_rate($currency);
308 add_exchange_rate($currency, $date_, $rate, $rate);
312 $rate = get_exchange_rate_from_home_currency($currency, $date_);
313 if ($from_currency != $comp_currency)
314 $rate = 1 / ($rate / get_exchange_rate_from_home_currency($to_currency, $date_));
316 $rate = number_format2($rate, user_exrate_dec());
318 text_row(_("Exchange Rate:"), '_ex_rate', $rate, 8, 8, null, "", " $from_currency = 1 $to_currency");
320 label_row(_("Exchange Rate:"),"<span style='vertical-align:top;' id='_ex_rate'>$rate</span> $from_currency = 1 $to_currency" );
321 $Ajax->addUpdate('_ex_rate','_ex_rate', $rate);
325 //--------------------------------------------------------------------------------------
327 function is_voided_display($type, $id, $label)
330 $void_entry = get_voided_entry($type, $id);
332 if ($void_entry == null)
335 start_table("width=50% $table_style");
336 echo "<tr><td align=center><font color=red>$label</font><br>";
337 echo "<font color=red>" . _("Date Voided:") . " " . sql2date($void_entry["date_"]) . "</font><br>";
338 if (strlen($void_entry["memo_"]) > 0)
339 echo "<center><font color=red>" . _("Memo:") . " " . $void_entry["memo_"] . "</font></center><br>";
346 //--------------------------------------------------------------------------------------
348 function comments_display_row($type, $id)
350 $comments = get_comments($type, $id);
351 if ($comments and db_num_rows($comments))
353 echo "<tr><td colspan=15>";
354 while ($comment = db_fetch($comments))
356 echo $comment["memo_"] . "<br>";
362 //--------------------------------------------------------------------------------------
364 function get_comments_string($type, $type_no)
367 $result = get_comments($type, $type_no);
368 while ($comment = db_fetch($result))
370 if (strlen($str_return))
371 $str_return = $str_return . " \n";
372 $str_return = $str_return . $comment["memo_"];
377 //--------------------------------------------------------------------------------------
379 function view_stock_status($stock_id, $description=null, $echo=true)
381 global $path_to_root;
383 //hyperlink_params_separate($path_to_root . "/inventory/inquiry/stock_status.php", (user_show_codes()?$stock_id . " - ":"") . $description, "stock_id=$stock_id");
384 $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>";
386 //hyperlink_params_separate($path_to_root . "/inventory/inquiry/stock_status.php", $stock_id, "stock_id=$stock_id");
387 $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>";
393 function view_stock_status_cell($stock_id, $description=null)
396 view_stock_status($stock_id, $description);
400 //--------------------------------------------------------------------------------------
402 function display_debit_or_credit_cells($value)
412 amount_cell(abs($value));
416 //--------------------------------------------------------------------------------------
418 function display_customer_trans_tax_details($tax_items, $columns)
420 while ($tax_item = db_fetch($tax_items))
422 $tax = number_format2($tax_item['amount'],user_price_dec());
423 if ($tax_item['included_in_price'])
424 label_row(_("Included") . " " . $tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%) " .
425 _("Amount") . ": $tax", "", "colspan=$columns align=right", "align=right");
427 label_row($tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%)",
428 $tax, "colspan=$columns align=right", "align=right");
432 //--------------------------------------------------------------------------------------
434 function display_supp_trans_tax_details($tax_items, $columns)
436 while ($tax_item = db_fetch($tax_items))
438 $tax = number_format2(abs($tax_item['amount']),user_price_dec());
439 if ($tax_item['included_in_price'])
440 label_row(_("Included") . " " . $tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%) " .
441 _("Amount") . ": $tax", "colspan=$columns align=right", "align=right");
443 label_row($tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%)",
444 $tax, "colspan=$columns align=right", "align=right");
448 //--------------------------------------------------------------------------------------
450 function display_edit_tax_items($taxes, $columns, $tax_included, $leftspan=0)
454 foreach ($taxes as $taxitem)
458 label_row(_("Included") . " " . $taxitem['tax_type_name'] . " (" . $taxitem['rate'] . "%) " .
459 _("Amount:") . " " . number_format2($taxitem['Value'],user_price_dec()), "", "colspan=$columns align=right", "align=right",$leftspan);
463 label_row($taxitem['tax_type_name'] . " (" . $taxitem['rate'] . "%)",
464 number_format2($taxitem['Value'],user_price_dec()), "colspan=$columns align=right", "align=right",$leftspan);
465 $total += round2($taxitem['Value'], user_price_dec());
472 //--------------------------------------------------------------------------------------
474 function display_footer_exit()
481 //--------------------------------------------------------------------------------------
483 function display_allocations($alloc_result, $total)
487 if (!$alloc_result || db_num_rows($alloc_result) == 0)
490 display_heading2(_("Allocations"));
492 start_table("$table_style width=80%");
494 $th = array( _("Type"), _("Number"), _("Date"), _("Total Amount"),
495 _("Left to Allocate"), _("This Allocation"));
497 $k = $total_allocated = 0;
499 while ($alloc_row = db_fetch($alloc_result))
502 alt_table_row_color($k);
504 label_cell(systypes::name($alloc_row['type']));
505 label_cell(get_trans_view_str($alloc_row['type'],$alloc_row['trans_no']));
506 label_cell(sql2date($alloc_row['tran_date']));
507 $alloc_row['Total'] = round2($alloc_row['Total'], user_price_dec());
508 $alloc_row['amt'] = round2($alloc_row['amt'], user_price_dec());
509 amount_cell($alloc_row['Total']);
510 //amount_cell($alloc_row['Total'] - $alloc_row['PrevAllocs'] - $alloc_row['amt']);
511 amount_cell($alloc_row['Total'] - $alloc_row['amt']);
512 amount_cell($alloc_row['amt']);
515 $total_allocated += $alloc_row['amt'];
518 label_cell(_("Total Allocated:"), "align=right colspan=5");
519 amount_cell($total_allocated);
522 label_cell(_("Left to Allocate:"), "align=right colspan=5");
523 $total = round2($total, user_price_dec());
524 amount_cell($total - $total_allocated);
530 //--------------------------------------------------------------------------------------
532 function display_allocations_from($person_type, $person_id, $type, $type_no, $total)
534 switch ($person_type)
536 case payment_person_types::customer() :
537 $alloc_result = get_allocatable_to_cust_transactions($person_id, $type_no, $type);
538 display_allocations($alloc_result, $total);
540 case payment_person_types::supplier() :
541 $alloc_result = get_allocatable_to_supp_transactions($person_id, $type_no, $type);
542 display_allocations($alloc_result, $total);
547 //--------------------------------------------------------------------------------------
549 // Expands selected quick entry $id into GL posings and adds to cart.
550 // returns calculated amount posted to bank GL account.
552 function display_quick_entries(&$cart, $id, $base, $type, $descr='')
556 if (!isset($id) || $id == null || $id == "")
558 display_error( _("No Quick Entries are defined."));
559 set_focus('totamount');
563 if ($type == QE_DEPOSIT)
565 if ($type != QE_SUPPINV) // only one quick entry on journal/bank transaction
566 $cart->clear_items();
567 $qe = get_quick_entry($id);
568 if ($descr != '') $qe['description'] .= ': '.$descr;
569 $result = get_quick_entry_lines($id);
571 while ($qe_line = db_fetch($result))
573 switch (strtolower($qe_line['action'])) {
574 case "=": // post current base amount to GL account
577 case "a": // post amount to GL account and reduce base
578 $part = $qe_line['amount'];
580 case "a+": // post amount to GL account and increase base
581 $part = $qe_line['amount']; $base += $part;
583 case "a-": // post amount to GL account and reduce base
584 $part = $qe_line['amount']; $base -= $part;
586 case "%": // store acc*amount% to GL account
587 $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
589 case "%+": // ditto & increase base amount
590 $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
593 case "%-": // ditto & reduce base amount
594 $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
597 case "t": // post taxes calculated on base amount
598 case "t+": // ditto & increase base amount
599 case "t-": // ditto & reduce base amount
600 //$taxes = get_taxes_for_item_tax($qe_line['dest_id']);
602 if ($type == QE_SUPPINV)
604 $res = get_tax_group_items($cart->tax_group_id);
605 while ($row = db_fetch($res))
606 $taxes[] = array('rate'=>$row['rate'], 'sales_gl_code'=>$row['sales_gl_code'],
607 'purchasing_gl_code'=>$row['purchasing_gl_code']);
611 $res = get_all_tax_types_simple();
613 while ($tt = db_fetch($res))
615 if ($qe_line['dest_id'] & $i)
617 $row2 = get_tax_type($tt['id']);
618 $taxes[] = array('rate'=>$row2['rate'], 'sales_gl_code'=>$row2['sales_gl_code'],
619 'purchasing_gl_code'=>$row2['purchasing_gl_code']);
627 if (substr($qe_line['action'],0,1) != 'T') {
628 foreach ($taxes as $index => $item_tax) {
629 $totrate += $item_tax['rate'];
632 $taxbase = $base/($totrate+100);
633 foreach ($taxes as $index => $item_tax) {
634 $tax = round2($taxbase * $item_tax['rate'], user_price_dec());
635 $gl_code = ($type == QE_DEPOSIT || ($type == QE_JOURNAL && $base < 0))
636 ? $item_tax['sales_gl_code'] : $item_tax['purchasing_gl_code'];
638 if ($tax==0) continue;
639 if (!is_tax_gl_unique($gl_code)) {
640 display_error(_("Cannot post to GL account used by more than one tax type."));
643 if ($type != QE_SUPPINV)
644 $cart->add_gl_item($gl_code,
645 $qe_line['dimension_id'], $qe_line['dimension2_id'],
646 $tax, $qe['description']);
649 $acc_name = get_gl_account_name($gl_code);
650 $cart->add_gl_codes_to_trans($gl_code,
651 $acc_name, $qe_line['dimension_id'],
652 $qe_line['dimension2_id'], $tax, $qe['description']);
655 if (strpos($qe_line['action'], '+'))
657 elseif (strpos($qe_line['action'], '-'))
661 if ($type != QE_SUPPINV)
662 $cart->add_gl_item($qe_line['dest_id'], $qe_line['dimension_id'],
663 $qe_line['dimension2_id'], $part, $qe['description']);
666 $acc_name = get_gl_account_name($qe_line['dest_id']);
667 $cart->add_gl_codes_to_trans($qe_line['dest_id'],
668 $acc_name, $qe_line['dimension_id'],
669 $qe_line['dimension2_id'], $part, $qe['description']);
677 function get_js_open_window($width, $height)
679 $js ="function openWindow(url, title)\n"
681 . " var left = (screen.width - $width) / 2;\n"
682 . " var top = (screen.height - $height) / 2;\n"
683 . " return window.open(url, title, 'width=$width,height=$height,left='+left+',top='+top+',screenX='+left+',screenY='+top+',status=no,scrollbars=yes');\n"
689 Setting focus on element $name in $form.
690 If $form<0 $name is element id.
692 function set_focus($name, $form_no=0) {
694 $Ajax->addFocus(true, $name);
695 $_POST['_focus'] = $name;
698 // Set default focus on first field $name if not set yet
700 function default_focus($name, $form_no=0) {
701 if (!isset($_POST['_focus'])) {
706 function get_js_png_fix()
708 $js = "function fixPNG(myImage)\n"
710 . " var arVersion = navigator.appVersion.split(\"MSIE\")\n"
711 . " var version = parseFloat(arVersion[1])\n"
712 . " if ((version >= 5.5) && (version < 7) && (document.body.filters))\n"
714 . " var imgID = (myImage.id) ? \"id='\" + myImage.id + \"' \" : \"\"\n"
715 . " var imgClass = (myImage.className) ? \"class='\" + myImage.className + \"' \" : \"\"\n"
716 . " var imgTitle = (myImage.title) ?\n"
717 . " \"title='\" + myImage.title + \"' \" : \"title='\" + myImage.alt + \"' \"\n"
718 . " var imgStyle = \"display:inline-block;\" + myImage.style.cssText\n"
719 . " var strNewHTML = \"<span \" + imgID + imgClass + imgTitle\n"
720 . " + \" style=\\\"\" + \"width:\" + myImage.width\n"
721 . " + \"px; height:\" + myImage.height\n"
722 . " + \"px;\" + imgStyle + \";\"\n"
723 . " + \"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader\"\n"
724 . " + \"(src=\'\" + myImage.src + \"\', sizingMethod='scale');\\\"></span>\"\n"
725 . " myImage.outerHTML = strNewHTML\n"
731 function get_js_date_picker()
733 global $comp_path, $go_debug;
734 $fpath = $comp_path.'/'.user_company().'/js_cache/'.'date_picker.js';
736 if (!file_exists($fpath) || $go_debug) {
738 global $dateseps, $date_system;
740 $how = user_date_format(); // 0 = us/ca, 1 = eu, au, nz, 2 = jp, sw
741 $sep = $dateseps[user_date_sep()]; // date separator
742 $wstart = (($date_system == 1 || $date_system == 2) ? 6 : ($how == 0 ? 0 : 1)); // weekstart (sun = 0, mon = 1)
743 $months = array(_("January"),_("February"),_("March"),_("April"),_("May"),_("June"),_("July"),_("August"),_("September"),_("October"),_("November"),_("December"));
744 $wdays = array(_("Su"),_("Mo"),_("Tu"),_("We"),_("Th"),_("Fr"),_("Sa"));
745 $wno = _("W"); // week no
747 if ($date_system == 1)
748 list($cyear, $cmon, $cday) = gregorian_to_jalali(date("Y"), date("n"), date("j"));
749 else if ($date_system == 2)
750 list($cyear, $cmon, $cday) = gregorian_to_islamic(date("Y"), date("n"), date("j"));
754 function positionInfo(object) {
756 this.getElementLeft = getElementLeft;
757 function getElementLeft() {
760 if(typeof(p_elm) == 'object'){
763 elm = document.getElementById(p_elm);
765 while (elm != null) {
767 elm = elm.offsetParent;
771 this.getElementWidth = getElementWidth;
772 function getElementWidth(){
774 if(typeof(p_elm) == 'object'){
777 elm = document.getElementById(p_elm);
779 return parseInt(elm.offsetWidth);
781 this.getElementRight = getElementRight;
782 function getElementRight(){
783 return getElementLeft(p_elm) + getElementWidth(p_elm);
785 this.getElementTop = getElementTop;
786 function getElementTop() {
789 if(typeof(p_elm) == 'object'){
792 elm = document.getElementById(p_elm);
794 while (elm != null) {
796 elm = elm.offsetParent;
800 this.getElementHeight = getElementHeight;
801 function getElementHeight(){
803 if(typeof(p_elm) == 'object'){
806 elm = document.getElementById(p_elm);
808 return parseInt(elm.offsetHeight);
810 this.getElementBottom = getElementBottom;
811 function getElementBottom(){
812 return getElementTop(p_elm) + getElementHeight(p_elm);
816 var calendarId = 'CC';
818 var currentMonth = 0;
820 var selectedYear = 0;
821 var selectedMonth = 0;
823 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]'];
824 var wdays = ['$wdays[0]', '$wdays[1]', '$wdays[2]', '$wdays[3]', '$wdays[4]', '$wdays[5]', '$wdays[6]'];
825 var dateField = null;
826 function getProperty(p_property){
827 var p_elm = calendarId;
829 if(typeof(p_elm) == 'object'){
832 elm = document.getElementById(p_elm);
838 return elm[p_property];
847 function setElementProperty(p_property, p_value, p_elmId){
850 if(typeof(p_elm) == 'object'){
853 elm = document.getElementById(p_elm);
855 if((elm != null) && (elm.style != null)){
857 elm[ p_property ] = p_value;
860 function setProperty(p_property, p_value) {
861 setElementProperty(p_property, p_value, calendarId);
863 function getDaysInMonth(year, month) {
865 if ($date_system == 1)
867 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];
869 else if ($date_system == 2)
871 return [30,29,30,29,30,29,30,29,30,29,30,(((((11 * year) + 14) % 30) < 11) ? 30 : 29)][month-1];
875 return [31,((!(year % 4 ) && ( (year % 100 ) || !( year % 400 ) ))?29:28),31,30,31,30,31,31,30,31,30,31][month-1];
879 function getDayOfWeek(year, month, day) {
881 if ($date_system == 1 || $date_system == 2)
886 return a - (b * Math.floor(a / b));
890 return mod(Math.floor((j + 1.5)), 7);
893 if ($date_system == 1)
895 var epbase, epyear, t;
896 epbase = year - ((year >= 0) ? 474 : 473);
897 epyear = 474 + mod(epbase, 2820);
898 t = day + ((month <= 7) ? ((month - 1) * 31) : (((month - 1) * 30) + 6)) +
899 Math.floor(((epyear * 682) - 110) / 2816) + (epyear - 1) * 365 +
900 Math.floor(epbase / 2820) * 1029983 + (1948320.5 - 1);
902 else if ($date_system == 2)
905 t = Math.floor((11 * year + 3) / 30) + 354 * year + 30 * month -
906 Math.floor((month - 1) / 2) + day + 1948440 - 385;
914 var date = new Date(year,month-1,day)
915 return date.getDay();
919 this.clearDate = clearDate;
920 function clearDate() {
921 dateField.value = '';
924 this.getWeek = getWeek;
925 function getWeek(year, month, day) {
930 var date = new Date(year,month-1,day);
931 var D = date.getDay();
933 date.setDate(date.getDate() + (4 - D));
934 var YN = date.getFullYear();
935 var ZBDoCY = Math.floor((date.getTime() - new Date(YN, 0, 1, -6)) / 86400000);
936 var WN = 1 + Math.floor(ZBDoCY / 7);
939 this.setDate = setDate;
940 function setDate(year, month, day) {
942 if (month < 10) {month = '0' + month;}
943 if (day < 10) {day = '0' + day;}
947 var dateString = month+'$sep'+day+'$sep'+year;
951 var dateString = day+'$sep'+month+'$sep'+year;
955 var dateString = year+'$sep'+month+'$sep'+day;
958 dateField.value = dateString;
959 setFocus(dateField.name);
960 if (dateField.className=='searchbox')
966 this.changeMonth = changeMonth;
967 function changeMonth(change) {
968 currentMonth += change;
970 if(currentMonth > 12) {
973 } else if(currentMonth < 1) {
977 calendar = document.getElementById(calendarId);
978 calendar.innerHTML = calendarDrawTable();
980 this.changeYear = changeYear;
981 function changeYear(change) {
982 currentYear += change;
984 calendar = document.getElementById(calendarId);
985 calendar.innerHTML = calendarDrawTable();
987 function getCurrentYear() {
988 var year = new Date().getYear();
989 if(year < 1900) year += 1900;
992 function getCurrentMonth() {
993 return new Date().getMonth() + 1;
995 function getCurrentDay() {
996 return new Date().getDate();
998 function calendarDrawTable() {
1000 var wstart = $wstart;
1001 var wno = ' $wno ';
1003 var startDayOfWeek = getDayOfWeek(currentYear, currentMonth, dayOfMonth);
1004 var daysInMonth = getDaysInMonth(currentYear, currentMonth);
1005 var css_class = null; //CSS class for each day
1006 var table = \"<table cellspacing='0' cellpadding='0' border='0'>\";
1007 table += \"<tr class='header'>\";
1008 table += \" <td colspan='2' class='previous'><a href='javascript:changeCCMonth(-1);'><</a><br><a href='javascript:changeCCYear(-1);'>«</a></td>\";
1009 table += \" <td colspan='4' class='title'>\" + months[currentMonth-1] + \"<br>\" + currentYear + \"</td>\";
1010 table += \" <td colspan='2' class='next'><a href='javascript:changeCCMonth(1);'>></a><br><a href='javascript:changeCCYear(1);'>»</a></td>\";
1013 table += \"<th class='weekno'>\"+wno+\"</th>\";
1014 for (var n=0; n<7; n++)
1015 table += \"<th>\" + wdays[(wstart+n)%7]+\"</th>\";
1017 for(var week=0; week < 6; week++) {
1019 for(var n=0; n < 7; n++) {
1020 dayOfWeek = (wstart+n)%7;
1021 if(week == 0 && startDayOfWeek == dayOfWeek) {
1023 } else if (validDay == 1 && dayOfMonth > daysInMonth) {
1028 if (dayOfMonth > daysInMonth)
1029 table += \"<td class='empty'> </td>\";
1031 table += \"<td class='weekno'>\"+getWeek(currentYear, currentMonth, dayOfMonth)+\"</td>\";
1034 if (dayOfMonth == selectedDay && currentYear == selectedYear && currentMonth == selectedMonth) {
1035 css_class = 'current';
1037 if ($date_system == 1 || $date_system == 2)
1039 } else if (dayOfWeek == 5) {
1043 } else if (dayOfWeek == 0 || dayOfWeek == 6) {
1046 css_class = 'weekend';
1048 css_class = 'weekday';
1050 table += \"<td><a class='\"+css_class+\"' href=\\\"javascript:setCCDate(\"+currentYear+\",\"+currentMonth+\",\"+dayOfMonth+\")\\\">\"+dayOfMonth+\"</a></td>\";
1053 table += \"<td class='empty'> </td>\";
1058 table += \"<tr class='header'><th colspan='8' style='padding: 3px;text-align:center;'><a href='javascript:hideCC();'>$back</a></td></tr>\";
1059 table += \"</table>\";
1063 function show(field) {
1065 if (dateField == field) {
1072 var dateString = new String(dateField.value);
1073 var dateParts = dateString.split('$sep');
1077 selectedMonth = parseInt(dateParts[0],10);
1078 selectedDay = parseInt(dateParts[1],10);
1079 selectedYear = parseInt(dateParts[2],10);
1083 selectedDay = parseInt(dateParts[0],10);
1084 selectedMonth = parseInt(dateParts[1],10);
1085 selectedYear = parseInt(dateParts[2],10);
1089 selectedYear = parseInt(dateParts[0],10);
1090 selectedMonth = parseInt(dateParts[1],10);
1091 selectedDay = parseInt(dateParts[2],10);
1096 if (!(selectedYear && selectedMonth && selectedDay)) {
1098 if ($date_system == 1 || $date_system == 2)
1101 selectedMonth = $cmon;
1102 selectedDay = $cday;
1103 selectedYear = $cyear;
1109 selectedMonth = getCurrentMonth();
1110 selectedDay = getCurrentDay();
1111 selectedYear = getCurrentYear();
1116 currentMonth = selectedMonth;
1117 currentDay = selectedDay;
1118 currentYear = selectedYear;
1119 if(document.getElementById){
1120 calendar = document.getElementById(calendarId);
1121 calendar.innerHTML = calendarDrawTable(currentYear, currentMonth);
1122 var fieldPos = new positionInfo(dateField);
1123 var calendarPos = new positionInfo(calendarId);
1124 var x = fieldPos.getElementLeft();
1125 var y = fieldPos.getElementBottom();
1126 setProperty('left', x + 'px');
1127 setProperty('top', y + 'px');
1128 setProperty('display', 'block');
1130 setElementProperty('left', x + 'px', 'CCIframe');
1131 setElementProperty('top', y + 'px', 'CCIframe');
1132 setElementProperty('width', calendarPos.getElementWidth() + 'px', 'CCIframe');
1133 setElementProperty('height', calendarPos.getElementHeight() + 'px', 'CCIframe');
1134 setElementProperty('display', 'block', 'CCIframe');
1141 setProperty('display', 'none');
1142 setElementProperty('display', 'none', 'CCIframe');
1146 this.visible = visible;
1147 function visible() {
1150 this.can_hide = can_hide;
1154 function date_picker(textField) {
1162 function setCCDate(year, month, day) {
1163 cC.setDate(year, month, day);
1165 function changeCCYear(change) {
1166 cC.changeYear(change);
1168 function changeCCMonth(change) {
1169 cC.changeMonth(change);
1171 document.write(\"<iframe id='CCIframe' src='javascript:false;' frameBorder='0' scrolling='no'></iframe>\");
1172 document.write(\"<div id='CC'></div>\");";
1174 cache_js_file($fpath, $js);
1176 add_js_ufile($fpath);
1181 function alert($msg)
1183 echo "\n<script type=\"text/javascript\">\n"
1185 . "alert('$msg');\n"
1190 if (!function_exists('_vd'))
1192 function _vd($mixed, $title = '', $exit = false)
1194 // Only the site admin is able to proceed here.
1195 $str = (!empty($title) ? ($title .':') : '') .'<pre>';
1196 $str .= print_r($mixed, true); //var_dump($mixed);
1198 display_error('<table><tr><td>'.$str.'</td></tr></table>');
1204 function display_backtrace($cond=true, $msg='') {
1208 $str = "<center><span class='headingtext'>$msg</span></center>\n";
1211 $str .= '<table border=0>';
1212 $trace = debug_backtrace();
1213 foreach($trace as $trn => $tr) {
1214 if (!$trn) continue;
1216 $str .= $tr['file'].':'.$tr['line'].': ';
1217 $str .= '</td><td>';
1218 if (isset($tr['type'])) {
1219 if($tr['type'] == '::') {
1220 $str .= $tr['class'].'::';
1221 } else if($tr['type'] == '->') {
1222 $str .= '('.$tr['class'].' Object)'.'->';
1225 foreach($tr['args'] as $n=>$a) {
1226 if (is_object($tr['args'][$n]))
1227 $tr['args'][$n] = "(".get_class($tr['args'][$n])." Object)";
1228 if (is_array($tr['args'][$n]))
1229 $tr['args'][$n] = "(Array[".count($tr['args'][$n])."])";
1231 $tr['args'][$n] = "'".$tr['args'][$n]."'";
1233 $str .= $tr['function'].'('. implode(',',$tr['args']).')</td>';
1239 display_error($str);