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,
20 $viewer = "purchasing/view/";
21 if ($type == ST_PURCHORDER)
22 $viewer .= "view_po.php";
23 elseif ($type == ST_SUPPINVOICE)
24 $viewer .= "view_supp_invoice.php";
25 elseif ($type == ST_SUPPCREDIT)
26 $viewer .= "view_supp_credit.php";
27 elseif ($type == ST_SUPPAYMENT)
28 $viewer .= "view_supp_payment.php";
29 elseif ($type == ST_SUPPRECEIVE)
30 $viewer .= "view_grn.php";
33 $viewer .= "?trans_no=$trans_no";
38 return viewer_link($label, $viewer, $class, $id, $icon);
41 //--------------------------------------------------------------------------------------
43 function get_gl_view_str($type, $trans_no, $label="", $force=false, $class='', $id='')
45 if (!$force && !user_show_gl_info())
54 $url = ($type == ST_WORKORDER && !work_order_is_closed($trans_no)) ? "manufacturing/view/wo_costs_view.php?trans_no=$trans_no"
55 : "gl/view/gl_trans_view.php?type_id=$type&trans_no=$trans_no";
57 return viewer_link($label, $url, $class, $id, $icon);
60 //--------------------------------------------------------------------------------------
62 function get_gl_view_str_cell($type, $trans_no, $label="")
64 $str = get_gl_view_str($type, $trans_no, $label);
66 return "<td>$str</td>";
69 //--------------------------------------------------------------------------------------
71 function get_customer_trans_view_str($type, $trans_no, $label="", $icon=false,
74 $viewer = "sales/view/";
76 if ($type == ST_SALESINVOICE)
77 $viewer .= "view_invoice.php";
78 elseif ($type == ST_CUSTCREDIT)
79 $viewer .= "view_credit.php";
80 elseif ($type == ST_CUSTPAYMENT)
81 $viewer .= "view_receipt.php";
82 elseif ($type == ST_CUSTDELIVERY)
83 $viewer .= "view_dispatch.php";
84 elseif ($type == ST_SALESORDER || $type == ST_SALESQUOTE)
85 $viewer .= "view_sales_order.php";
89 if(!is_array($trans_no)) $trans_no = array($trans_no);
94 foreach($trans_no as $trans) {
97 if($preview_str!='') $preview_str .= ',';
99 $preview_str .= viewer_link($lbl, $viewer."?trans_no=$trans&trans_type=$type",
106 //--------------------------------------------------------------------------------------
108 function get_banking_trans_view_str($type, $trans_no, $label="",
109 $icon=false, $class='', $id='')
114 if ($type == ST_BANKTRANSFER)
115 $viewer = "bank_transfer_view.php";
116 elseif ($type == ST_BANKPAYMENT)
117 $viewer = "gl_payment_view.php";
118 elseif ($type == ST_BANKDEPOSIT)
119 $viewer = "gl_deposit_view.php";
123 return viewer_link($label, "gl/view/$viewer?trans_no=$trans_no",
127 //--------------------------------------------------------------------------------------
129 function get_inventory_trans_view_str($type, $trans_no, $label="",
130 $icon=false, $class='', $id='')
132 $viewer = "inventory/view/";
134 if ($type == ST_INVADJUST)
135 $viewer .= "view_adjustment.php";
136 elseif ($type == ST_LOCTRANSFER)
137 $viewer .= "view_transfer.php";
140 $viewer .= "?trans_no=$trans_no";
145 return viewer_link($label, $viewer, $class, $id, $icon);
148 //--------------------------------------------------------------------------------------
150 function get_manufacturing_trans_view_str($type, $trans_no, $label="",
151 $icon=false, $class='', $id='')
153 $viewer = "manufacturing/view/";
155 if ($type == ST_MANUISSUE)
156 $viewer .= "wo_issue_view.php";
157 elseif ($type == ST_MANURECEIVE)
158 $viewer .= "wo_production_view.php";
159 elseif ($type == ST_WORKORDER)
160 $viewer .= "work_order_view.php";
164 $viewer .= "?trans_no=$trans_no";
169 return viewer_link($label, $viewer, $class, $id, $icon);
172 //--------------------------------------------------------------------------------------
174 function get_dimensions_trans_view_str($type, $trans_no, $label="", $icon=false,
177 if ($type == ST_DIMENSION)
178 $viewer = "dimensions/view/view_dimension.php?trans_no=$trans_no";
185 return viewer_link($label, $viewer, $class, $id, $icon);
188 Journal entry or cost update postings link
190 function get_journal_trans_view_str($type, $trans_no, $label="", $icon=false,
193 if ($type == ST_JOURNAL || $type == ST_COSTUPDATE)
194 $viewer = "gl/view/gl_trans_view.php?type_id=$type&trans_no=$trans_no";
201 return viewer_link($label, $viewer, $class, $id, $icon);
204 //--------------------------------------------------------------------------------------
206 function get_package_view_str($pkg, $label="", $icon=false, $class='', $id='')
213 return viewer_link($label, "includes/ui/view_package.php?id=$pkg", $class, $id, $icon);
217 //--------------------------------------------------------------------------------------
219 function get_trans_view_str($type, $trans_no, $label="", $icon=false,
222 $view_str = get_customer_trans_view_str($type, $trans_no, $label, $icon, $class, $id);
223 if ($view_str != null)
226 $view_str = get_supplier_trans_view_str($type, $trans_no, $label, $icon, $class, $id);
227 if ($view_str != null)
230 $view_str = get_banking_trans_view_str($type, $trans_no, $label, $icon, $class, $id);
231 if ($view_str != null)
234 $view_str = get_inventory_trans_view_str($type, $trans_no, $label, $icon, $class, $id);
235 if ($view_str != null)
238 $view_str = get_manufacturing_trans_view_str($type, $trans_no, $label, $icon, $class, $id);
239 if ($view_str != null)
242 $view_str = get_dimensions_trans_view_str($type, $trans_no, $label, $icon, $class, $id);
243 if ($view_str != null)
246 $view_str = get_journal_trans_view_str($type, $trans_no, $label, $icon, $class, $id);
247 if ($view_str != null)
253 //--------------------------------------------------------------------------------------
254 // Displays currency exchange rate for given date.
255 // When there is no exrate for today,
256 // gets it form ECB and stores in local database.
258 function exchange_rate_display($from_currency, $to_currency, $date_, $edit_rate=false)
262 if ($from_currency != $to_currency)
264 $comp_currency = get_company_currency();
265 if ($from_currency == $comp_currency)
266 $currency = $to_currency;
268 $currency = $from_currency;
270 if ($date_ == Today()) {
271 $rate = get_date_exchange_rate($currency, $date_);
273 $row = get_currency($currency);
274 if ($row['auto_update']) {
275 $rate = retrieve_exrate($currency, $date_);
277 add_exchange_rate($currency, $date_, $rate, $rate);
282 $rate = get_exchange_rate_from_home_currency($currency, $date_);
283 if ($from_currency != $comp_currency)
284 $rate = 1 / ($rate / get_exchange_rate_from_home_currency($to_currency, $date_));
286 $rate = number_format2($rate, user_exrate_dec());
288 text_row(_("Exchange Rate:"), '_ex_rate', $rate, 8, 8, null, "", " $from_currency = 1 $to_currency");
290 label_row(_("Exchange Rate:"),"<span style='vertical-align:top;' id='_ex_rate'>$rate</span> $from_currency = 1 $to_currency" );
291 $Ajax->addUpdate('_ex_rate','_ex_rate', $rate);
295 //--------------------------------------------------------------------------------------
297 function is_voided_display($type, $id, $label)
299 $void_entry = get_voided_entry($type, $id);
301 if ($void_entry == null)
304 start_table(TABLESTYLE, "width=50%");
305 echo "<tr><td align=center><font color=red>$label</font><br>";
306 echo "<font color=red>" . _("Date Voided:") . " " . sql2date($void_entry["date_"]) . "</font><br>";
307 if (strlen($void_entry["memo_"]) > 0)
308 echo "<center><font color=red>" . _("Memo:") . " " . $void_entry["memo_"] . "</font></center><br>";
315 //--------------------------------------------------------------------------------------
317 function comments_display_row($type, $id)
319 $comments = get_comments($type, $id);
320 if ($comments and db_num_rows($comments))
322 echo "<tr><td colspan=15>";
323 while ($comment = db_fetch($comments))
325 echo $comment["memo_"] . "<br>";
331 //--------------------------------------------------------------------------------------
333 function get_comments_string($type, $type_no)
336 $result = get_comments($type, $type_no);
337 while ($comment = db_fetch($result))
339 if (strlen($str_return))
340 $str_return = $str_return . " \n";
341 $str_return = $str_return . $comment["memo_"];
346 //--------------------------------------------------------------------------------------
348 function view_stock_status($stock_id, $description=null, $echo=true)
350 global $path_to_root;
352 //hyperlink_params_separate($path_to_root . "/inventory/inquiry/stock_status.php", (user_show_codes()?$stock_id . " - ":"") . $description, "stock_id=$stock_id");
353 $preview_str = "<a target='_blank' href='$path_to_root/inventory/inquiry/stock_status.php?stock_id=$stock_id' onclick=\"javascript:openWindow(this.href,this.target); return false;\" >". (user_show_codes()?$stock_id . " - ":"") . $description."</a>";
355 //hyperlink_params_separate($path_to_root . "/inventory/inquiry/stock_status.php", $stock_id, "stock_id=$stock_id");
356 $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>";
362 function view_stock_status_cell($stock_id, $description=null)
365 view_stock_status($stock_id, $description);
369 //--------------------------------------------------------------------------------------
371 function display_debit_or_credit_cells($value, $bold=false)
373 $value = round2($value, user_price_dec());
376 amount_cell($value, $bold);
382 amount_cell(abs($value), $bold);
386 //--------------------------------------------------------------------------------------
388 function display_customer_trans_tax_details($tax_items, $columns)
390 global $alternative_tax_include_on_docs, $suppress_tax_rates;
392 while ($tax_item = db_fetch($tax_items))
394 if (!$tax_item['amount'])
397 $tax = number_format2($tax_item['amount'],user_price_dec());
398 if (isset($suppress_tax_rates) && $suppress_tax_rates == 1)
399 $tax_type_name = $tax_item['tax_type_name'];
401 $tax_type_name = $tax_item['tax_type_name']." (".$tax_item['rate']."%) ";
402 if ($tax_item['included_in_price'])
404 if (isset($alternative_tax_include_on_docs) && $alternative_tax_include_on_docs == 1)
407 label_row(_("Total Tax Excluded"), number_format2($tax_item['net_amount'], user_price_dec()),
408 "colspan=$columns align=right", "align=right");
409 label_row($tax_type_name, $tax, "colspan=$columns align=right", "align=right");
413 label_row(_("Included") . " " . $tax_type_name
414 . ": $tax", "", "colspan=$columns align=right", "align=right");
417 label_row($tax_type_name, $tax, "colspan=$columns align=right", "align=right");
421 //--------------------------------------------------------------------------------------
423 function display_supp_trans_tax_details($tax_items, $columns)
425 while ($tax_item = db_fetch($tax_items))
427 if (!$tax_item['amount'])
430 $tax = number_format2(abs($tax_item['amount']),user_price_dec());
431 if ($tax_item['included_in_price'])
432 label_row(_("Included") . " " . $tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%) "
433 . ": $tax", '', "colspan=$columns align=right", "align=right");
435 label_row($tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%)",
436 $tax, "colspan=$columns align=right", "align=right");
440 //--------------------------------------------------------------------------------------
442 function display_edit_tax_items($taxes, $columns, $tax_included, $leftspan=0)
446 foreach ($taxes as $taxitem)
450 label_row(_("Included") . " " . $taxitem['tax_type_name'] . " (" . $taxitem['rate'] . "%) "
451 . " " . number_format2($taxitem['Value'],user_price_dec()), "", "colspan=$columns align=right", "align=right",$leftspan);
455 label_row($taxitem['tax_type_name'] . " (" . $taxitem['rate'] . "%)",
456 number_format2($taxitem['Value'],user_price_dec()), "colspan=$columns align=right", "align=right",$leftspan);
457 $total += round2($taxitem['Value'], user_price_dec());
464 //--------------------------------------------------------------------------------------
466 function display_footer_exit()
469 end_page(false, false, true);
473 //--------------------------------------------------------------------------------------
475 function display_allocations($alloc_result, $total)
477 global $systypes_array;
479 if (!$alloc_result || db_num_rows($alloc_result) == 0)
482 display_heading2(_("Allocations"));
484 start_table(TABLESTYLE, "width=80%");
486 $th = array( _("Type"), _("Number"), _("Date"), _("Total Amount"),
487 _("Left to Allocate"), _("This Allocation"));
489 $k = $total_allocated = 0;
491 while ($alloc_row = db_fetch($alloc_result))
494 alt_table_row_color($k);
496 label_cell($systypes_array[$alloc_row['type']]);
497 label_cell(get_trans_view_str($alloc_row['type'],$alloc_row['trans_no']));
498 label_cell(sql2date($alloc_row['tran_date']));
499 $alloc_row['Total'] = round2($alloc_row['Total'], user_price_dec());
500 $alloc_row['amt'] = round2($alloc_row['amt'], user_price_dec());
501 amount_cell($alloc_row['Total']);
502 //amount_cell($alloc_row['Total'] - $alloc_row['PrevAllocs'] - $alloc_row['amt']);
503 amount_cell($alloc_row['Total'] - $alloc_row['amt']);
504 amount_cell($alloc_row['amt']);
507 $total_allocated += $alloc_row['amt'];
510 label_cell(_("Total Allocated:"), "align=right colspan=5");
511 amount_cell($total_allocated);
514 label_cell(_("Left to Allocate:"), "align=right colspan=5");
515 $total = round2($total, user_price_dec());
516 amount_cell($total - $total_allocated);
522 //--------------------------------------------------------------------------------------
524 function display_allocations_from($person_type, $person_id, $type, $type_no, $total)
526 switch ($person_type)
529 $alloc_result = get_allocatable_to_cust_transactions($person_id, $type_no, $type);
530 display_allocations($alloc_result, $total);
533 $alloc_result = get_allocatable_to_supp_transactions($person_id, $type_no, $type);
534 display_allocations($alloc_result, $total);
539 //--------------------------------------------------------------------------------------
541 // Expands selected quick entry $id into GL posings and adds to cart.
542 // returns calculated amount posted to bank GL account.
544 function display_quick_entries(&$cart, $id, $base, $type, $descr='')
548 if (!isset($id) || $id == null || $id == "")
550 display_error( _("No Quick Entries are defined."));
551 set_focus('totamount');
555 if ($type == QE_DEPOSIT)
557 if ($type != QE_SUPPINV) // only one quick entry on journal/bank transaction
558 $cart->clear_items();
559 $qe = get_quick_entry($id);
560 if ($qe['bal_type'] == 1)
562 if ($qe['base_amount'] == 1.0) // monthly
563 $begin = begin_month($cart->tran_date);
566 if (is_account_balancesheet($qe['base_desc'])) // total
569 $begin = begin_fiscalyear(); // from fiscalyear begin
571 $base = get_gl_trans_from_to($begin, $cart->tran_date, $qe['base_desc']);
574 if ($descr != '') $qe['description'] .= ': '.$descr;
575 $result = get_quick_entry_lines($id);
576 if (db_num_rows($result) == 0)
578 display_error( _("No Quick Entry lines are defined."));
579 set_focus('totamount');
583 while ($row = db_fetch($result))
587 switch (strtolower($row['action'])) {
588 case "t": // post taxes calculated on base amount
589 case "t+": // ditto & increase base amount
590 case "t-": // ditto & reduce base amount
591 if (substr($row['action'],0,1) != 'T')
592 $totrate += get_tax_type_default_rate($row['dest_id']);
597 foreach($qe_lines as $qe_line)
599 switch (strtolower($qe_line['action'])) {
600 case "=": // post current base amount to GL account
603 case "a": // post amount to GL account and reduce base
604 $part = $qe_line['amount'];
606 case "a+": // post amount to GL account and increase base
607 $part = $qe_line['amount']; $base += $part;
609 case "a-": // post amount to GL account and reduce base
610 $part = $qe_line['amount']; $base -= $part;
612 case "%": // store acc*amount% to GL account
613 $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
615 case "%+": // ditto & increase base amount
616 $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
619 case "%-": // ditto & reduce base amount
620 $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
623 case "t": // post taxes calculated on base amount
624 case "t+": // ditto & increase base amount
625 case "t-": // ditto & reduce base amount
628 $taxbase = $base/($totrate+100);
632 if (substr($qe_line['action'],0,1) != 'T')
636 $item_tax = get_tax_type($qe_line['dest_id']);
637 //if ($type == QE_SUPPINV && substr($qe_line['action'],0,1) != 'T')
638 if ($type == QE_SUPPINV)
640 $taxgroup = $cart->tax_group_id;
642 $res = get_tax_group_rates($cart->tax_group_id);
643 while ($row = db_fetch($res))
644 $rates += $row['rate'];
648 $tax = round2($part * $item_tax['rate'], user_price_dec());
649 if ($tax==0) continue 2;
650 $gl_code = ($type == QE_DEPOSIT || ($type == QE_JOURNAL && $base < 0))
651 ? $item_tax['sales_gl_code'] : $item_tax['purchasing_gl_code'];
652 if (!is_tax_gl_unique($gl_code)) {
653 display_error(_("Cannot post to GL account used by more than one tax type."));
656 if ($type != QE_SUPPINV)
657 $cart->add_gl_item($gl_code,
658 $qe_line['dimension_id'], $qe_line['dimension2_id'],
659 $tax, $qe['description']);
662 $acc_name = get_gl_account_name($gl_code);
663 $cart->add_gl_codes_to_trans($gl_code,
664 $acc_name, $qe_line['dimension_id'],
665 $qe_line['dimension2_id'], $tax, $qe['description']);
667 if (strpos($qe_line['action'], '+'))
669 elseif (strpos($qe_line['action'], '-'))
673 if ($type != QE_SUPPINV)
674 $cart->add_gl_item($qe_line['dest_id'], $qe_line['dimension_id'],
675 $qe_line['dimension2_id'], $part, $qe['description']);
678 $acc_name = get_gl_account_name($qe_line['dest_id']);
679 $cart->add_gl_codes_to_trans($qe_line['dest_id'],
680 $acc_name, $qe_line['dimension_id'],
681 $qe_line['dimension2_id'], $part, $qe['description']);
688 //--------------------------------------------------------------------------------------
690 // Simple English version of number to words conversion.
692 function _number_to_words($number)
694 $Bn = floor($number / 1000000000); /* Billions (giga) */
695 $number -= $Bn * 1000000000;
696 $Gn = floor($number / 1000000); /* Millions (mega) */
697 $number -= $Gn * 1000000;
698 $kn = floor($number / 1000); /* Thousands (kilo) */
699 $number -= $kn * 1000;
700 $Hn = floor($number / 100); /* Hundreds (hecto) */
701 $number -= $Hn * 100;
702 $Dn = floor($number / 10); /* Tens (deca) */
703 $n = $number % 10; /* Ones */
708 $res .= _number_to_words($Bn) . " Billion";
710 $res .= (empty($res) ? "" : " ") . _number_to_words($Gn) . " Million";
712 $res .= (empty($res) ? "" : " ") . _number_to_words($kn) . " Thousand";
714 $res .= (empty($res) ? "" : " ") . _number_to_words($Hn) . " Hundred";
716 $ones = array("", "One", "Two", "Three", "Four", "Five", "Six",
717 "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen",
718 "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eightteen",
720 $tens = array("", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty",
721 "Seventy", "Eigthy", "Ninety");
728 $res .= $ones[$Dn * 10 + $n];
733 $res .= "-" . $ones[$n];
742 function price_in_words($amount, $document=0)
744 // use local price_in_words() if the hook is defined
745 $price = hook_price_in_words($amount, $document);
749 // Only usefor Remittance and Receipts as default
750 if (!($document == ST_SUPPAYMENT || $document == ST_CUSTPAYMENT || $document == ST_CHEQUE))
752 if ($amount < 0 || $amount > 999999999999)
754 $dec = user_price_dec();
757 $divisor = pow(10, $dec);
758 $frac = round2($amount - floor($amount), $dec) * $divisor;
759 $frac = sprintf("%0{$dec}d", $frac);
761 $frac = " $and $frac/$divisor";
765 return _number_to_words(intval($amount)) . $frac;
768 function get_js_open_window($width, $height)
770 $js ="function openWindow(url, title)\n"
772 . " var left = (screen.width - $width) / 2;\n"
773 . " var top = (screen.height - $height) / 2;\n"
774 . " return window.open(url, title, 'width=$width,height=$height,left='+left+',top='+top+',screenX='+left+',screenY='+top+',status=no,scrollbars=yes');\n"
780 Setting focus on element $name in $form.
781 If $form<0 $name is element id.
783 function set_focus($name, $form_no=0) {
785 $Ajax->addFocus(true, $name);
786 $_POST['_focus'] = $name;
789 // Set default focus on first field $name if not set yet
790 // Returns unique name if $name=null
792 function default_focus($name=null, $form_no=0) {
795 $name = uniqid('_el',true);
796 if (!isset($_POST['_focus'])) {
802 Reset focus to next control element (e.g. link).
804 function reset_focus()
806 unset($_POST['_focus']);
809 function get_js_date_picker()
812 $fpath = company_path().'/js_cache/'.'date_picker.js';
814 if (!file_exists($fpath) || $go_debug) {
816 global $dateseps, $date_system;
818 $how = user_date_format(); // 0 = us/ca, 1 = eu, au, nz, 2 = jp, sw
819 $sep = $dateseps[user_date_sep()]; // date separator
820 $wstart = (($date_system == 1 || $date_system == 2 || $date_system == 3) ? 6 : ($how == 0 ? 0 : 1)); // weekstart (sun = 0, mon = 1)
821 $months = array(_("January"),_("February"),_("March"),_("April"),_("May"),_("June"),_("July"),_("August"),_("September"),_("October"),_("November"),_("December"));
822 $wdays = array(_("Su"),_("Mo"),_("Tu"),_("We"),_("Th"),_("Fr"),_("Sa"));
823 $wno = _("W"); // week no
825 if ($date_system == 1)
826 list($cyear, $cmon, $cday) = gregorian_to_jalali(date("Y"), date("n"), date("j"));
827 else if ($date_system == 2)
828 list($cyear, $cmon, $cday) = gregorian_to_islamic(date("Y"), date("n"), date("j"));
832 function positionInfo(object) {
834 this.getElementLeft = getElementLeft;
835 function getElementLeft() {
838 if(typeof(p_elm) == 'object'){
841 elm = document.getElementById(p_elm);
843 while (elm != null) {
845 elm = elm.offsetParent;
849 this.getElementWidth = getElementWidth;
850 function getElementWidth(){
852 if(typeof(p_elm) == 'object'){
855 elm = document.getElementById(p_elm);
857 return parseInt(elm.offsetWidth);
859 this.getElementRight = getElementRight;
860 function getElementRight(){
861 return getElementLeft(p_elm) + getElementWidth(p_elm);
863 this.getElementTop = getElementTop;
864 function getElementTop() {
867 if(typeof(p_elm) == 'object'){
870 elm = document.getElementById(p_elm);
872 while (elm != null) {
874 elm = elm.offsetParent;
878 this.getElementHeight = getElementHeight;
879 function getElementHeight(){
881 if(typeof(p_elm) == 'object'){
884 elm = document.getElementById(p_elm);
886 return parseInt(elm.offsetHeight);
888 this.getElementBottom = getElementBottom;
889 function getElementBottom(){
890 return getElementTop(p_elm) + getElementHeight(p_elm);
894 var calendarId = 'CC';
896 var currentMonth = 0;
898 var selectedYear = 0;
899 var selectedMonth = 0;
901 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]'];
902 var wdays = ['$wdays[0]', '$wdays[1]', '$wdays[2]', '$wdays[3]', '$wdays[4]', '$wdays[5]', '$wdays[6]'];
903 var dateField = null;
904 function getProperty(p_property){
905 var p_elm = calendarId;
907 if(typeof(p_elm) == 'object'){
910 elm = document.getElementById(p_elm);
916 return elm[p_property];
925 function setElementProperty(p_property, p_value, p_elmId){
928 if(typeof(p_elm) == 'object'){
931 elm = document.getElementById(p_elm);
933 if((elm != null) && (elm.style != null)){
935 elm[ p_property ] = p_value;
938 function setProperty(p_property, p_value) {
939 setElementProperty(p_property, p_value, calendarId);
941 function getDaysInMonth(year, month) {
943 if ($date_system == 1)
945 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];
947 else if ($date_system == 2)
949 return [30,29,30,29,30,29,30,29,30,29,30,(((((11 * year) + 14) % 30) < 11) ? 30 : 29)][month-1];
953 return [31,((!(year % 4 ) && ( (year % 100 ) || !( year % 400 ) ))?29:28),31,30,31,30,31,31,30,31,30,31][month-1];
957 function getDayOfWeek(year, month, day) {
959 if ($date_system == 1 || $date_system == 2)
964 return a - (b * Math.floor(a / b));
968 return mod(Math.floor((j + 1.5)), 7);
971 if ($date_system == 1)
973 var epbase, epyear, t;
974 epbase = year - ((year >= 0) ? 474 : 473);
975 epyear = 474 + mod(epbase, 2820);
976 t = day + ((month <= 7) ? ((month - 1) * 31) : (((month - 1) * 30) + 6)) +
977 Math.floor(((epyear * 682) - 110) / 2816) + (epyear - 1) * 365 +
978 Math.floor(epbase / 2820) * 1029983 + (1948320.5 - 1);
980 else if ($date_system == 2)
983 t = Math.floor((11 * year + 3) / 30) + 354 * year + 30 * month -
984 Math.floor((month - 1) / 2) + day + 1948440 - 385;
992 var date = new Date(year,month-1,day)
993 return date.getDay();
997 this.clearDate = clearDate;
998 function clearDate() {
999 dateField.value = '';
1002 this.getWeek = getWeek;
1003 function getWeek(year, month, day) {
1008 var date = new Date(year,month-1,day);
1009 var D = date.getDay();
1011 date.setDate(date.getDate() + (4 - D));
1012 var YN = date.getFullYear();
1013 var ZBDoCY = Math.floor((date.getTime() - new Date(YN, 0, 1, -6)) / 86400000);
1014 var WN = 1 + Math.floor(ZBDoCY / 7);
1017 this.setDate = setDate;
1018 function setDate(year, month, day) {
1020 if (month < 10) {month = '0' + month;}
1021 if (day < 10) {day = '0' + day;}
1025 var dateString = month+'$sep'+day+'$sep'+year;
1029 var dateString = day+'$sep'+month+'$sep'+year;
1033 var dateString = year+'$sep'+month+'$sep'+day;
1036 dateField.value = dateString;
1037 setFocus(dateField.name);
1038 if(dateField.getAttribute('aspect')=='cdate')
1039 setElementProperty('color', (dateField.value==user.date ? 'black':'red'), dateField);
1040 if (dateField.className=='searchbox')
1046 this.changeMonth = changeMonth;
1047 function changeMonth(change) {
1048 currentMonth += change;
1050 if(currentMonth > 12) {
1053 } else if(currentMonth < 1) {
1057 calendar = document.getElementById(calendarId);
1058 calendar.innerHTML = calendarDrawTable();
1060 this.changeYear = changeYear;
1061 function changeYear(change) {
1062 currentYear += change;
1064 calendar = document.getElementById(calendarId);
1065 calendar.innerHTML = calendarDrawTable();
1067 function getCurrentYear() {
1068 var year = new Date().getYear();
1069 if(year < 1900) year += 1900;
1072 function getCurrentMonth() {
1073 return new Date().getMonth() + 1;
1075 function getCurrentDay() {
1076 return new Date().getDate();
1078 function calendarDrawTable() {
1080 var wstart = $wstart;
1081 var wno = ' $wno ';
1083 var startDayOfWeek = getDayOfWeek(currentYear, currentMonth, dayOfMonth);
1084 var daysInMonth = getDaysInMonth(currentYear, currentMonth);
1085 var css_class = null; //CSS class for each day
1086 var table = \"<table cellspacing='0' cellpadding='0' border='0'>\";
1087 table += \"<tr class='header'>\";
1088 table += \" <td colspan='2' class='previous'><a href='javascript:changeCCMonth(-1);'><</a><br><a href='javascript:changeCCYear(-1);'>«</a></td>\";
1089 table += \" <td colspan='4' class='title'>\" + months[currentMonth-1] + \"<br>\" + currentYear + \"</td>\";
1090 table += \" <td colspan='2' class='next'><a href='javascript:changeCCMonth(1);'>></a><br><a href='javascript:changeCCYear(1);'>»</a></td>\";
1093 table += \"<th class='weekno'>\"+wno+\"</th>\";
1094 for (var n=0; n<7; n++)
1095 table += \"<th>\" + wdays[(wstart+n)%7]+\"</th>\";
1097 for(var week=0; week < 6; week++) {
1099 for(var n=0; n < 7; n++) {
1100 dayOfWeek = (wstart+n)%7;
1101 if(week == 0 && startDayOfWeek == dayOfWeek) {
1103 } else if (validDay == 1 && dayOfMonth > daysInMonth) {
1108 if (dayOfMonth > daysInMonth)
1109 table += \"<td class='empty'> </td>\";
1111 table += \"<td class='weekno'>\"+getWeek(currentYear, currentMonth, dayOfMonth)+\"</td>\";
1114 if (dayOfMonth == selectedDay && currentYear == selectedYear && currentMonth == selectedMonth) {
1115 css_class = 'current';
1117 if ($date_system == 1 || $date_system == 2 || $date_system == 3)
1119 } else if (dayOfWeek == 5) {
1123 } else if (dayOfWeek == 0 || dayOfWeek == 6) {
1126 css_class = 'weekend';
1128 css_class = 'weekday';
1130 table += \"<td><a class='\"+css_class+\"' href=\\\"javascript:setCCDate(\"+currentYear+\",\"+currentMonth+\",\"+dayOfMonth+\")\\\">\"+dayOfMonth+\"</a></td>\";
1133 table += \"<td class='empty'> </td>\";
1138 table += \"<tr class='header'><th colspan='8' style='padding: 3px;text-align:center;'><a href='javascript:hideCC();'>$back</a></td></tr>\";
1139 table += \"</table>\";
1143 function show(field) {
1145 if (dateField == field) {
1152 var dateString = new String(dateField.value);
1153 var dateParts = dateString.split('$sep');
1157 selectedMonth = parseInt(dateParts[0],10);
1158 selectedDay = parseInt(dateParts[1],10);
1159 selectedYear = parseInt(dateParts[2],10);
1163 selectedDay = parseInt(dateParts[0],10);
1164 selectedMonth = parseInt(dateParts[1],10);
1165 selectedYear = parseInt(dateParts[2],10);
1169 selectedYear = parseInt(dateParts[0],10);
1170 selectedMonth = parseInt(dateParts[1],10);
1171 selectedDay = parseInt(dateParts[2],10);
1176 if (!(selectedYear && selectedMonth && selectedDay)) {
1178 if ($date_system == 1 || $date_system == 2)
1181 selectedMonth = $cmon;
1182 selectedDay = $cday;
1183 selectedYear = $cyear;
1189 selectedMonth = getCurrentMonth();
1190 selectedDay = getCurrentDay();
1191 selectedYear = getCurrentYear();
1196 currentMonth = selectedMonth;
1197 currentDay = selectedDay;
1198 currentYear = selectedYear;
1199 if(document.getElementById){
1200 calendar = document.getElementById(calendarId);
1201 calendar.innerHTML = calendarDrawTable(currentYear, currentMonth);
1202 var fieldPos = new positionInfo(dateField);
1203 var calendarPos = new positionInfo(calendarId);
1204 var x = fieldPos.getElementLeft();
1205 var y = fieldPos.getElementBottom();
1206 setProperty('left', x + 'px');
1207 setProperty('top', y + 'px');
1208 setProperty('display', 'block');
1210 setElementProperty('left', x + 'px', 'CCIframe');
1211 setElementProperty('top', y + 'px', 'CCIframe');
1212 setElementProperty('width', calendarPos.getElementWidth() + 'px', 'CCIframe');
1213 setElementProperty('height', calendarPos.getElementHeight() + 'px', 'CCIframe');
1214 setElementProperty('display', 'block', 'CCIframe');
1221 setProperty('display', 'none');
1222 setElementProperty('display', 'none', 'CCIframe');
1226 this.visible = visible;
1227 function visible() {
1230 this.can_hide = can_hide;
1234 function date_picker(textField) {
1242 function setCCDate(year, month, day) {
1243 cC.setDate(year, month, day);
1245 function changeCCYear(change) {
1246 cC.changeYear(change);
1248 function changeCCMonth(change) {
1249 cC.changeMonth(change);
1251 document.write(\"<iframe id='CCIframe' src='javascript:false;' frameBorder='0' scrolling='no'></iframe>\");
1252 document.write(\"<div id='CC'></div>\");";
1254 cache_js_file($fpath, $js);
1256 add_js_ufile($fpath);
1261 function alert($msg)
1263 echo "\n<script type=\"text/javascript\">\n"
1265 . "alert('$msg');\n"
1270 if (!function_exists('_vd'))
1272 function _vd($mixed, $title = '', $exit = false)
1274 $str = (!empty($title) ? ($title .':') : '') .'<pre>';
1275 $str .= print_r($mixed, true); //var_dump($mixed);
1277 display_notification('<table><tr><td>'.$str.'</td></tr></table>');
1283 function _vl($mixed, $title = '', $exit = false)
1285 error_log((!empty($title) ? ($title .':') : '') . var_export($mixed, true));
1290 function display_backtrace($cond=true, $msg='') {
1293 $str = "<center><span class='headingtext'>$msg</span></center>\n";
1296 $str .= get_backtrace(true);
1297 display_error($str);