2 /**********************************************************************
3 Copyright (C) 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");
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 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));
422 //--------------------------------------------------------------------------------------
424 function display_customer_trans_tax_details($tax_items, $columns)
426 while ($tax_item = db_fetch($tax_items))
428 $tax = number_format2($tax_item['amount'],user_price_dec());
429 if ($tax_item['included_in_price'])
430 label_row(_("Included") . " " . $tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%) " .
431 _("Amount") . ": $tax", "", "colspan=$columns align=right", "align=right");
433 label_row($tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%)",
434 $tax, "colspan=$columns align=right", "align=right");
438 //--------------------------------------------------------------------------------------
440 function display_supp_trans_tax_details($tax_items, $columns)
442 while ($tax_item = db_fetch($tax_items))
444 $tax = number_format2(abs($tax_item['amount']),user_price_dec());
445 if ($tax_item['included_in_price'])
446 label_row(_("Included") . " " . $tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%) " .
447 _("Amount:") . ": $tax", "colspan=$columns align=right", "align=right");
449 label_row($tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%)",
450 $tax, "colspan=$columns align=right", "align=right");
454 //--------------------------------------------------------------------------------------
456 function display_edit_tax_items($taxes, $columns, $tax_included, $leftspan=0)
460 foreach ($taxes as $taxitem)
464 label_row(_("Included") . " " . $taxitem['tax_type_name'] . " (" . $taxitem['rate'] . "%) " .
465 _("Amount:") . " " . number_format2($taxitem['Value'],user_price_dec()), "", "colspan=$columns align=right", "align=right",$leftspan);
469 label_row($taxitem['tax_type_name'] . " (" . $taxitem['rate'] . "%)",
470 number_format2($taxitem['Value'],user_price_dec()), "colspan=$columns align=right", "align=right",$leftspan);
471 $total += $taxitem['Value'];
478 //--------------------------------------------------------------------------------------
480 function display_footer_exit()
487 //--------------------------------------------------------------------------------------
489 function display_allocations($alloc_result, $total)
493 if (!$alloc_result || db_num_rows($alloc_result) == 0)
496 display_heading2(_("Allocations"));
498 start_table("$table_style width=80%");
500 $th = array( _("Type"), _("Number"), _("Date"), _("Total Amount"),
501 _("Left to Allocate"), _("This Allocation"));
503 $k = $total_allocated = 0;
505 while ($alloc_row = db_fetch($alloc_result))
508 alt_table_row_color($k);
510 label_cell(systypes::name($alloc_row['type']));
511 label_cell(get_trans_view_str($alloc_row['type'],$alloc_row['trans_no']));
512 label_cell(sql2date($alloc_row['tran_date']));
513 amount_cell($alloc_row['Total']);
514 //amount_cell($alloc_row['Total'] - $alloc_row['PrevAllocs'] - $alloc_row['amt']);
515 amount_cell($alloc_row['Total'] - $alloc_row['amt']);
516 amount_cell($alloc_row['amt']);
519 $total_allocated += $alloc_row['amt'];
522 label_cell(_("Total Allocated:"), "align=right colspan=5");
523 amount_cell($total_allocated);
526 label_cell(_("Left to Allocate:"), "align=right colspan=5");
527 amount_cell($total - $total_allocated);
533 //--------------------------------------------------------------------------------------
535 function display_allocations_from($person_type, $person_id, $type, $type_no, $total)
537 switch ($person_type)
539 case payment_person_types::customer() :
540 $alloc_result = get_allocatable_to_cust_transactions($person_id, $type_no, $type);
541 display_allocations($alloc_result, $total);
543 case payment_person_types::supplier() :
544 $alloc_result = get_allocatable_to_supp_transactions($person_id, $type_no, $type);
545 display_allocations($alloc_result, $total);
550 //--------------------------------------------------------------------------------------
551 function display_quick_entries(&$cart, $id, $totamount, $payment=true, $supp_trans=false)
553 if (!isset($id) || $id == null || $id == "")
555 display_error( _("No Quick Entries are defined."));
556 set_focus('totamount');
562 $totamount = -$totamount;
564 $cart->clear_items();
565 $qe = get_quick_entry($id);
566 $qe_lines = get_quick_entry_lines($id);
567 while ($qe_line = db_fetch($qe_lines))
569 if ($qe_line['tax_acc'])
571 $account = get_gl_account($qe_line['account']);
572 $tax_group = $account['tax_code'];
573 $items = get_tax_group_items($tax_group);
574 while ($item = db_fetch($items))
575 $rate += $item['rate'];
577 $totamount = round2($totamount * 100 / ($rate + 100), user_price_dec());
578 //$cart->clear_items();
580 $cart->add_gl_item($qe_line['account'], $qe_line['dimension_id'], $qe_line['dimension2_id'],
581 $totamount, $qe['description']);
584 $acc_name = get_gl_account_name($qe_line['account']);
585 $cart->add_gl_codes_to_trans($qe_line['account'], $acc_name, $qe_line['dimension_id'],
586 $qe_line['dimension2_id'], $totamount, $qe['description']);
588 $items = get_tax_group_items($tax_group);
589 while ($item = db_fetch($items))
591 if ($item['rate'] != 0)
593 $amount = round2($totamount * $item['rate'] / 100, user_price_dec());
594 $code = (($amount < 0 || $payment || $supp_trans) ? $item['purchasing_gl_code'] :
595 $item['sales_gl_code']);
597 $cart->add_gl_item($code, 0, 0, $amount, $qe['description']);
600 $acc_name = get_gl_account_name($code);
601 $cart->add_gl_codes_to_trans($code, $acc_name, 0, 0, $amount, $qe['description']);
609 $amount = round2($totamount * $qe_line['amount'] / 100, user_price_dec());
611 $amount = $qe_line['amount'];
613 $cart->add_gl_item($qe_line['account'], $qe_line['dimension_id'], $qe_line['dimension2_id'],
614 $amount, $qe['description']);
617 $acc_name = get_gl_account_name($qe_line['account']);
618 $cart->add_gl_codes_to_trans($qe_line['account'], $acc_name, $qe_line['dimension_id'],
619 $qe_line['dimension2_id'], $amount, $qe['description']);
623 //line_start_focus();
628 function get_js_open_window($width, $height)
630 $js = "\n<script type=\"text/javascript\">\n"
632 . "function openWindow(url, title)\n"
634 . " var left = (screen.width - $width) / 2;\n"
635 . " var top = (screen.height - $height) / 2;\n"
636 . " return window.open(url, title, 'width=$width,height=$height,left='+left+',top='+top+',screenX='+left+',screenY='+top+',status=no,scrollbars=yes');\n"
644 Setting focus on element $name in $form.
645 If $form<0 $name is element id.
647 function set_focus($name, $form_no=0) {
649 $Ajax->addFocus(true, $name);
650 $_POST['_focus'] = $name;
653 // Set default focus on first field $name if not set yet
655 function default_focus($name, $form_no=0) {
656 if (!isset($_POST['_focus'])) {
661 function get_js_png_fix()
663 $js = "<script type=\"text/javascript\">\n"
664 . "function fixPNG(myImage)\n"
666 . " var arVersion = navigator.appVersion.split(\"MSIE\")\n"
667 . " var version = parseFloat(arVersion[1])\n"
668 . " if ((version >= 5.5) && (version < 7) && (document.body.filters))\n"
670 . " var imgID = (myImage.id) ? \"id='\" + myImage.id + \"' \" : \"\"\n"
671 . " var imgClass = (myImage.className) ? \"class='\" + myImage.className + \"' \" : \"\"\n"
672 . " var imgTitle = (myImage.title) ?\n"
673 . " \"title='\" + myImage.title + \"' \" : \"title='\" + myImage.alt + \"' \"\n"
674 . " var imgStyle = \"display:inline-block;\" + myImage.style.cssText\n"
675 . " var strNewHTML = \"<span \" + imgID + imgClass + imgTitle\n"
676 . " + \" style=\\\"\" + \"width:\" + myImage.width\n"
677 . " + \"px; height:\" + myImage.height\n"
678 . " + \"px;\" + imgStyle + \";\"\n"
679 . " + \"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader\"\n"
680 . " + \"(src=\'\" + myImage.src + \"\', sizingMethod='scale');\\\"></span>\"\n"
681 . " myImage.outerHTML = strNewHTML\n"
688 function get_js_date_picker()
690 global $comp_path, $go_debug;
691 $fpath = $comp_path.'/'.user_company().'/js_cache/'.'date_picker.js';
694 #CCIframe { display: none; left: 0px; position: absolute; top: 0px; height: 250px; width: 270px; z-index: 99;}
695 #CC { position:absolute; background-color:#FFF; margin:0; padding:0; display:none; z-index: 100;}
696 #CC table { font-family: arial, verdana, helvetica, sans-serif;font-size: 8pt; border-left: 1px solid #336; border-right: 1px solid #336;}
697 #CC th { font-weight: normal; text-align: center;}
698 #CC th a { font-weight: normal; text-decoration: none; color: #FFF; padding: 1px;}
699 #CC td { text-align: center;}
700 #CC .header { background-color: #336;}
701 #CC .weekday { background-color: #DDD; color: #000;}
702 #CC .weekend { background-color: #FFC; color: #000;}
703 #CC .weekno { background-color: #c0daf8; color: #555;}
704 #CC .current { border: 1px solid #339; background-color: #336; color: #FFF;}
705 #CC .weekday,#CC .weekend,#CC .current { display: block; text-decoration: none; border: 1px solid #FFF; width: 2em;}
706 #CC .weekday:hover,#CC .weekend:hover,#CC .current:hover { color: #FFF; background-color: #336; border: 1px solid #999;}
707 #CC .previous { text-align: left;}
708 #CC .next { text-align: right;}
709 #CC .previous,#CC .next { padding: 1px 3px 1px 3px; font-size: 1.4em;}
710 #CC .previous a,#CC .next a { color: #FFF; text-decoration: none; font-weight: bold;}
711 #CC .title { text-align: center; font-weight: bold; color: #FFF;}
712 #CC .empty { background-color: #CCC; border: 1px solid #FFF;}
717 if (!file_exists($fpath) || $go_debug) {
719 global $dateseps, $date_system;
721 $how = user_date_format(); // 0 = us/ca, 1 = eu, au, nz, 2 = jp, sw
722 $sep = $dateseps[user_date_sep()]; // date separator
723 $wstart = (($date_system == 1 || $date_system == 2) ? 6 : ($how == 0 ? 0 : 1)); // weekstart (sun = 0, mon = 1)
724 $months = array(_("January"),_("February"),_("March"),_("April"),_("May"),_("June"),_("July"),_("August"),_("September"),_("October"),_("November"),_("December"));
725 $wdays = array(_("Su"),_("Mo"),_("Tu"),_("We"),_("Th"),_("Fr"),_("Sa"));
726 $wno = _("W"); // week no
728 if ($date_system == 1)
729 list($cyear, $cmon, $cday) = gregorian_to_jalali(date("Y"), date("n"), date("j"));
730 else if ($date_system == 2)
731 list($cyear, $cmon, $cday) = gregorian_to_islamic(date("Y"), date("n"), date("j"));
735 function positionInfo(object) {
737 this.getElementLeft = getElementLeft;
738 function getElementLeft() {
741 if(typeof(p_elm) == 'object'){
744 elm = document.getElementById(p_elm);
746 while (elm != null) {
748 elm = elm.offsetParent;
752 this.getElementWidth = getElementWidth;
753 function getElementWidth(){
755 if(typeof(p_elm) == 'object'){
758 elm = document.getElementById(p_elm);
760 return parseInt(elm.offsetWidth);
762 this.getElementRight = getElementRight;
763 function getElementRight(){
764 return getElementLeft(p_elm) + getElementWidth(p_elm);
766 this.getElementTop = getElementTop;
767 function getElementTop() {
770 if(typeof(p_elm) == 'object'){
773 elm = document.getElementById(p_elm);
775 while (elm != null) {
777 elm = elm.offsetParent;
781 this.getElementHeight = getElementHeight;
782 function getElementHeight(){
784 if(typeof(p_elm) == 'object'){
787 elm = document.getElementById(p_elm);
789 return parseInt(elm.offsetHeight);
791 this.getElementBottom = getElementBottom;
792 function getElementBottom(){
793 return getElementTop(p_elm) + getElementHeight(p_elm);
797 var calendarId = 'CC';
799 var currentMonth = 0;
801 var selectedYear = 0;
802 var selectedMonth = 0;
804 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]'];
805 var wdays = ['$wdays[0]', '$wdays[1]', '$wdays[2]', '$wdays[3]', '$wdays[4]', '$wdays[5]', '$wdays[6]'];
806 var dateField = null;
807 function getProperty(p_property){
808 var p_elm = calendarId;
810 if(typeof(p_elm) == 'object'){
813 elm = document.getElementById(p_elm);
819 return elm[p_property];
828 function setElementProperty(p_property, p_value, p_elmId){
831 if(typeof(p_elm) == 'object'){
834 elm = document.getElementById(p_elm);
836 if((elm != null) && (elm.style != null)){
838 elm[ p_property ] = p_value;
841 function setProperty(p_property, p_value) {
842 setElementProperty(p_property, p_value, calendarId);
844 function getDaysInMonth(year, month) {
846 if ($date_system == 1)
848 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];
850 else if ($date_system == 2)
852 return [30,29,30,29,30,29,30,29,30,29,30,(((((11 * year) + 14) % 30) < 11) ? 30 : 29)][month-1];
856 return [31,((!(year % 4 ) && ( (year % 100 ) || !( year % 400 ) ))?29:28),31,30,31,30,31,31,30,31,30,31][month-1];
860 function getDayOfWeek(year, month, day) {
862 if ($date_system == 1 || $date_system == 2)
867 return a - (b * Math.floor(a / b));
871 return mod(Math.floor((j + 1.5)), 7);
874 if ($date_system == 1)
876 var epbase, epyear, t;
877 epbase = year - ((year >= 0) ? 474 : 473);
878 epyear = 474 + mod(epbase, 2820);
879 t = day + ((month <= 7) ? ((month - 1) * 31) : (((month - 1) * 30) + 6)) +
880 Math.floor(((epyear * 682) - 110) / 2816) + (epyear - 1) * 365 +
881 Math.floor(epbase / 2820) * 1029983 + (1948320.5 - 1);
883 else if ($date_system == 2)
886 t = Math.floor((11 * year + 3) / 30) + 354 * year + 30 * month -
887 Math.floor((month - 1) / 2) + day + 1948440 - 385;
895 var date = new Date(year,month-1,day)
896 return date.getDay();
900 this.clearDate = clearDate;
901 function clearDate() {
902 dateField.value = '';
905 this.getWeek = getWeek;
906 function getWeek(year, month, day) {
911 var date = new Date(year,month-1,day);
912 var D = date.getDay();
914 date.setDate(date.getDate() + (4 - D));
915 var YN = date.getFullYear();
916 var ZBDoCY = Math.floor((date.getTime() - new Date(YN, 0, 1, -6)) / 86400000);
917 var WN = 1 + Math.floor(ZBDoCY / 7);
920 this.setDate = setDate;
921 function setDate(year, month, day) {
923 if (month < 10) {month = '0' + month;}
924 if (day < 10) {day = '0' + day;}
928 var dateString = month+'$sep'+day+'$sep'+year;
932 var dateString = day+'$sep'+month+'$sep'+year;
936 var dateString = year+'$sep'+month+'$sep'+day;
939 dateField.value = dateString;
940 setFocus(dateField.name);
941 if (dateField.className=='searchbox')
947 this.changeMonth = changeMonth;
948 function changeMonth(change) {
949 currentMonth += change;
951 if(currentMonth > 12) {
954 } else if(currentMonth < 1) {
958 calendar = document.getElementById(calendarId);
959 calendar.innerHTML = calendarDrawTable();
961 this.changeYear = changeYear;
962 function changeYear(change) {
963 currentYear += change;
965 calendar = document.getElementById(calendarId);
966 calendar.innerHTML = calendarDrawTable();
968 function getCurrentYear() {
969 var year = new Date().getYear();
970 if(year < 1900) year += 1900;
973 function getCurrentMonth() {
974 return new Date().getMonth() + 1;
976 function getCurrentDay() {
977 return new Date().getDate();
979 function calendarDrawTable() {
981 var wstart = $wstart;
982 var wno = ' $wno ';
984 var startDayOfWeek = getDayOfWeek(currentYear, currentMonth, dayOfMonth);
985 var daysInMonth = getDaysInMonth(currentYear, currentMonth);
986 var css_class = null; //CSS class for each day
987 var table = \"<table cellspacing='0' cellpadding='0' border='0'>\";
988 table += \"<tr class='header'>\";
989 table += \" <td colspan='2' class='previous'><a href='javascript:changeCCMonth(-1);'><</a><br><a href='javascript:changeCCYear(-1);'>«</a></td>\";
990 table += \" <td colspan='4' class='title'>\" + months[currentMonth-1] + \"<br>\" + currentYear + \"</td>\";
991 table += \" <td colspan='2' class='next'><a href='javascript:changeCCMonth(1);'>></a><br><a href='javascript:changeCCYear(1);'>»</a></td>\";
994 table += \"<th class='weekno'>\"+wno+\"</th>\";
995 for (var n=0; n<7; n++)
996 table += \"<th>\" + wdays[(wstart+n)%7]+\"</th>\";
998 for(var week=0; week < 6; week++) {
1000 for(var n=0; n < 7; n++) {
1001 dayOfWeek = (wstart+n)%7;
1002 if(week == 0 && startDayOfWeek == dayOfWeek) {
1004 } else if (validDay == 1 && dayOfMonth > daysInMonth) {
1009 if (dayOfMonth > daysInMonth)
1010 table += \"<td class='empty'> </td>\";
1012 table += \"<td class='weekno'>\"+getWeek(currentYear, currentMonth, dayOfMonth)+\"</td>\";
1015 if (dayOfMonth == selectedDay && currentYear == selectedYear && currentMonth == selectedMonth) {
1016 css_class = 'current';
1018 if ($date_system == 1 || $date_system == 2)
1020 } else if (dayOfWeek == 5) {
1024 } else if (dayOfWeek == 0 || dayOfWeek == 6) {
1027 css_class = 'weekend';
1029 css_class = 'weekday';
1031 table += \"<td><a class='\"+css_class+\"' href=\\\"javascript:setCCDate(\"+currentYear+\",\"+currentMonth+\",\"+dayOfMonth+\")\\\">\"+dayOfMonth+\"</a></td>\";
1034 table += \"<td class='empty'> </td>\";
1039 table += \"<tr class='header'><th colspan='8' style='padding: 3px;text-align:center;'><a href='javascript:hideCC();'>$back</a></td></tr>\";
1040 table += \"</table>\";
1044 function show(field) {
1046 if (dateField == field) {
1053 var dateString = new String(dateField.value);
1054 var dateParts = dateString.split('$sep');
1058 selectedMonth = parseInt(dateParts[0],10);
1059 selectedDay = parseInt(dateParts[1],10);
1060 selectedYear = parseInt(dateParts[2],10);
1064 selectedDay = parseInt(dateParts[0],10);
1065 selectedMonth = parseInt(dateParts[1],10);
1066 selectedYear = parseInt(dateParts[2],10);
1070 selectedYear = parseInt(dateParts[0],10);
1071 selectedMonth = parseInt(dateParts[1],10);
1072 selectedDay = parseInt(dateParts[2],10);
1077 if (!(selectedYear && selectedMonth && selectedDay)) {
1079 if ($date_system == 1 || $date_system == 2)
1082 selectedMonth = $cmon;
1083 selectedDay = $cday;
1084 selectedYear = $cyear;
1090 selectedMonth = getCurrentMonth();
1091 selectedDay = getCurrentDay();
1092 selectedYear = getCurrentYear();
1097 currentMonth = selectedMonth;
1098 currentDay = selectedDay;
1099 currentYear = selectedYear;
1100 if(document.getElementById){
1101 calendar = document.getElementById(calendarId);
1102 calendar.innerHTML = calendarDrawTable(currentYear, currentMonth);
1103 var fieldPos = new positionInfo(dateField);
1104 var calendarPos = new positionInfo(calendarId);
1105 var x = fieldPos.getElementLeft();
1106 var y = fieldPos.getElementBottom();
1107 setProperty('left', x + 'px');
1108 setProperty('top', y + 'px');
1109 setProperty('display', 'block');
1111 setElementProperty('left', x + 'px', 'CCIframe');
1112 setElementProperty('top', y + 'px', 'CCIframe');
1113 setElementProperty('width', calendarPos.getElementWidth() + 'px', 'CCIframe');
1114 setElementProperty('height', calendarPos.getElementHeight() + 'px', 'CCIframe');
1115 setElementProperty('display', 'block', 'CCIframe');
1122 setProperty('display', 'none');
1123 setElementProperty('display', 'none', 'CCIframe');
1127 this.visible = visible;
1128 function visible() {
1131 this.can_hide = can_hide;
1135 function date_picker(textField) {
1143 function setCCDate(year, month, day) {
1144 cC.setDate(year, month, day);
1146 function changeCCYear(change) {
1147 cC.changeYear(change);
1149 function changeCCMonth(change) {
1150 cC.changeMonth(change);
1152 document.write(\"<iframe id='CCIframe' src='javascript:false;' frameBorder='0' scrolling='no'></iframe>\");
1153 document.write(\"<div id='CC'></div>\");";
1155 cache_js_file($fpath, $js);
1157 add_js_ufile($fpath);
1162 function alert($msg)
1164 echo "\n<script type=\"text/javascript\">\n"
1166 . "alert('$msg');\n"
1171 if (!function_exists('_vd'))
1173 function _vd($mixed, $title = '', $exit = false)
1175 // Only the site admin is able to proceed here.
1176 $str = (!empty($title) ? ($title .':') : '') .'<pre>';
1177 $str .= print_r($mixed, true); //var_dump($mixed);
1179 display_error('<table><tr><td>'.$str.'</td></tr></table>');
1185 function display_backtrace($cond=true, $msg='') {
1189 $str = "<center><span class='headingtext'>$msg</span></center>\n";
1192 $str .= '<table border=0>';
1193 $trace = debug_backtrace();
1194 foreach($trace as $trn => $tr) {
1195 if (!$trn) continue;
1197 $str .= $tr['file'].':'.$tr['line'].': ';
1198 $str .= '</td><td>';
1199 if (isset($tr['type'])) {
1200 if($tr['type'] == '::') {
1201 $str .= $tr['class'].'::';
1202 } else if($tr['type'] == '->') {
1203 $str .= '('.$tr['class'].' Object)'.'->';
1206 foreach($tr['args'] as $n=>$a) {
1207 if (is_object($tr['args'][$n]))
1208 $tr['args'][$n] = "(".get_class($tr['args'][$n])." Object)";
1209 if (is_array($tr['args'][$n]))
1210 $tr['args'][$n] = "(Array[".count($tr['args'][$n])."])";
1212 $tr['args'][$n] = "'".$tr['args'][$n]."'";
1214 $str .= $tr['function'].'('. implode(',',$tr['args']).')</td>';
1220 display_error($str);