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())
55 return viewer_link($label,
56 "gl/view/gl_trans_view.php?type_id=$type&trans_no=$trans_no",
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_trans_view_str($type, $trans_no, $label="", $icon=false,
209 $view_str = get_customer_trans_view_str($type, $trans_no, $label, $icon, $class, $id);
210 if ($view_str != null)
213 $view_str = get_supplier_trans_view_str($type, $trans_no, $label, $icon, $class, $id);
214 if ($view_str != null)
217 $view_str = get_banking_trans_view_str($type, $trans_no, $label, $icon, $class, $id);
218 if ($view_str != null)
221 $view_str = get_inventory_trans_view_str($type, $trans_no, $label, $icon, $class, $id);
222 if ($view_str != null)
225 $view_str = get_manufacturing_trans_view_str($type, $trans_no, $label, $icon, $class, $id);
226 if ($view_str != null)
229 $view_str = get_dimensions_trans_view_str($type, $trans_no, $label, $icon, $class, $id);
230 if ($view_str != null)
233 $view_str = get_journal_trans_view_str($type, $trans_no, $label, $icon, $class, $id);
234 if ($view_str != null)
240 //--------------------------------------------------------------------------------------
241 // Displays currency exchange rate for given date.
242 // When there is no exrate for today,
243 // gets it form ECB and stores in local database.
245 function exchange_rate_display($from_currency, $to_currency, $date_, $edit_rate=false)
249 if ($from_currency != $to_currency)
251 $comp_currency = get_company_currency();
252 if ($from_currency == $comp_currency)
253 $currency = $to_currency;
255 $currency = $from_currency;
257 if ($date_ == Today()) {
258 $rate = get_date_exchange_rate($currency, $date_);
260 $row = get_currency($currency);
261 if ($row['auto_update']) {
262 $rate = retrieve_exrate($currency, $date_);
264 add_exchange_rate($currency, $date_, $rate, $rate);
269 $rate = get_exchange_rate_from_home_currency($currency, $date_);
270 if ($from_currency != $comp_currency)
271 $rate = 1 / ($rate / get_exchange_rate_from_home_currency($to_currency, $date_));
273 $rate = number_format2($rate, user_exrate_dec());
275 text_row(_("Exchange Rate:"), '_ex_rate', $rate, 8, 8, null, "", " $from_currency = 1 $to_currency");
277 label_row(_("Exchange Rate:"),"<span style='vertical-align:top;' id='_ex_rate'>$rate</span> $from_currency = 1 $to_currency" );
278 $Ajax->addUpdate('_ex_rate','_ex_rate', $rate);
282 //--------------------------------------------------------------------------------------
284 function is_voided_display($type, $id, $label)
287 $void_entry = get_voided_entry($type, $id);
289 if ($void_entry == null)
292 start_table("width=50% $table_style");
293 echo "<tr><td align=center><font color=red>$label</font><br>";
294 echo "<font color=red>" . _("Date Voided:") . " " . sql2date($void_entry["date_"]) . "</font><br>";
295 if (strlen($void_entry["memo_"]) > 0)
296 echo "<center><font color=red>" . _("Memo:") . " " . $void_entry["memo_"] . "</font></center><br>";
303 //--------------------------------------------------------------------------------------
305 function comments_display_row($type, $id)
307 $comments = get_comments($type, $id);
308 if ($comments and db_num_rows($comments))
310 echo "<tr><td colspan=15>";
311 while ($comment = db_fetch($comments))
313 echo $comment["memo_"] . "<br>";
319 //--------------------------------------------------------------------------------------
321 function get_comments_string($type, $type_no)
324 $result = get_comments($type, $type_no);
325 while ($comment = db_fetch($result))
327 if (strlen($str_return))
328 $str_return = $str_return . " \n";
329 $str_return = $str_return . $comment["memo_"];
334 //--------------------------------------------------------------------------------------
336 function view_stock_status($stock_id, $description=null, $echo=true)
338 global $path_to_root;
340 //hyperlink_params_separate($path_to_root . "/inventory/inquiry/stock_status.php", (user_show_codes()?$stock_id . " - ":"") . $description, "stock_id=$stock_id");
341 $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>";
343 //hyperlink_params_separate($path_to_root . "/inventory/inquiry/stock_status.php", $stock_id, "stock_id=$stock_id");
344 $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>";
350 function view_stock_status_cell($stock_id, $description=null)
353 view_stock_status($stock_id, $description);
357 //--------------------------------------------------------------------------------------
359 function display_debit_or_credit_cells($value)
361 $value = round2($value, user_price_dec());
370 amount_cell(abs($value));
374 //--------------------------------------------------------------------------------------
376 function display_customer_trans_tax_details($tax_items, $columns)
378 while ($tax_item = db_fetch($tax_items))
380 $tax = number_format2($tax_item['amount'],user_price_dec());
381 if ($tax_item['included_in_price'])
382 label_row(_("Included") . " " . $tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%) " .
383 _("Amount") . ": $tax", "", "colspan=$columns align=right", "align=right");
385 label_row($tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%)",
386 $tax, "colspan=$columns align=right", "align=right");
390 //--------------------------------------------------------------------------------------
392 function display_supp_trans_tax_details($tax_items, $columns)
394 while ($tax_item = db_fetch($tax_items))
396 $tax = number_format2(abs($tax_item['amount']),user_price_dec());
397 if ($tax_item['included_in_price'])
398 label_row(_("Included") . " " . $tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%) " .
399 _("Amount") . ": $tax", "colspan=$columns align=right", "align=right");
401 label_row($tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%)",
402 $tax, "colspan=$columns align=right", "align=right");
406 //--------------------------------------------------------------------------------------
408 function display_edit_tax_items($taxes, $columns, $tax_included, $leftspan=0)
412 foreach ($taxes as $taxitem)
416 label_row(_("Included") . " " . $taxitem['tax_type_name'] . " (" . $taxitem['rate'] . "%) " .
417 _("Amount:") . " " . number_format2($taxitem['Value'],user_price_dec()), "", "colspan=$columns align=right", "align=right",$leftspan);
421 label_row($taxitem['tax_type_name'] . " (" . $taxitem['rate'] . "%)",
422 number_format2($taxitem['Value'],user_price_dec()), "colspan=$columns align=right", "align=right",$leftspan);
423 $total += round2($taxitem['Value'], user_price_dec());
430 //--------------------------------------------------------------------------------------
432 function display_footer_exit()
439 //--------------------------------------------------------------------------------------
441 function display_allocations($alloc_result, $total)
443 global $table_style, $systypes_array;
445 if (!$alloc_result || db_num_rows($alloc_result) == 0)
448 display_heading2(_("Allocations"));
450 start_table("$table_style width=80%");
452 $th = array( _("Type"), _("Number"), _("Date"), _("Total Amount"),
453 _("Left to Allocate"), _("This Allocation"));
455 $k = $total_allocated = 0;
457 while ($alloc_row = db_fetch($alloc_result))
460 alt_table_row_color($k);
462 label_cell($systypes_array[$alloc_row['type']]);
463 label_cell(get_trans_view_str($alloc_row['type'],$alloc_row['trans_no']));
464 label_cell(sql2date($alloc_row['tran_date']));
465 $alloc_row['Total'] = round2($alloc_row['Total'], user_price_dec());
466 $alloc_row['amt'] = round2($alloc_row['amt'], user_price_dec());
467 amount_cell($alloc_row['Total']);
468 //amount_cell($alloc_row['Total'] - $alloc_row['PrevAllocs'] - $alloc_row['amt']);
469 amount_cell($alloc_row['Total'] - $alloc_row['amt']);
470 amount_cell($alloc_row['amt']);
473 $total_allocated += $alloc_row['amt'];
476 label_cell(_("Total Allocated:"), "align=right colspan=5");
477 amount_cell($total_allocated);
480 label_cell(_("Left to Allocate:"), "align=right colspan=5");
481 $total = round2($total, user_price_dec());
482 amount_cell($total - $total_allocated);
488 //--------------------------------------------------------------------------------------
490 function display_allocations_from($person_type, $person_id, $type, $type_no, $total)
492 switch ($person_type)
495 $alloc_result = get_allocatable_to_cust_transactions($person_id, $type_no, $type);
496 display_allocations($alloc_result, $total);
499 $alloc_result = get_allocatable_to_supp_transactions($person_id, $type_no, $type);
500 display_allocations($alloc_result, $total);
505 //--------------------------------------------------------------------------------------
507 // Expands selected quick entry $id into GL posings and adds to cart.
508 // returns calculated amount posted to bank GL account.
510 function display_quick_entries(&$cart, $id, $base, $type, $descr='')
514 if (!isset($id) || $id == null || $id == "")
516 display_error( _("No Quick Entries are defined."));
517 set_focus('totamount');
521 if ($type == QE_DEPOSIT)
523 if ($type != QE_SUPPINV) // only one quick entry on journal/bank transaction
524 $cart->clear_items();
525 $qe = get_quick_entry($id);
526 if ($descr != '') $qe['description'] .= ': '.$descr;
527 $result = get_quick_entry_lines($id);
529 while ($row = db_fetch($result))
533 switch (strtolower($row['action'])) {
534 case "t": // post taxes calculated on base amount
535 case "t+": // ditto & increase base amount
536 case "t-": // ditto & reduce base amount
537 if (substr($row['action'],0,1) != 'T')
538 $totrate += get_tax_type_default_rate($row['dest_id']);
543 foreach($qe_lines as $qe_line)
545 switch (strtolower($qe_line['action'])) {
546 case "=": // post current base amount to GL account
549 case "a": // post amount to GL account and reduce base
550 $part = $qe_line['amount'];
552 case "a+": // post amount to GL account and increase base
553 $part = $qe_line['amount']; $base += $part;
555 case "a-": // post amount to GL account and reduce base
556 $part = $qe_line['amount']; $base -= $part;
558 case "%": // store acc*amount% to GL account
559 $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
561 case "%+": // ditto & increase base amount
562 $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
565 case "%-": // ditto & reduce base amount
566 $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
569 case "t": // post taxes calculated on base amount
570 case "t+": // ditto & increase base amount
571 case "t-": // ditto & reduce base amount
574 $taxbase = $base/($totrate+100);
578 if (substr($qe_line['action'],0,1) != 'T')
582 $item_tax = get_tax_type($qe_line['dest_id']);
583 if ($type == QE_SUPPINV && substr($qe_line['action'],0,1) != 'T')
585 $taxgroup = $cart->tax_group_id;
587 $res = get_tax_group_items($cart->tax_group_id);
588 while ($row = db_fetch($res))
589 $rates += $row['rate'];
593 $tax = round2($part * $item_tax['rate'], user_price_dec());
594 if ($tax==0) continue 2;
595 $gl_code = ($type == QE_DEPOSIT || ($type == QE_JOURNAL && $base < 0))
596 ? $item_tax['sales_gl_code'] : $item_tax['purchasing_gl_code'];
597 if (!is_tax_gl_unique($gl_code)) {
598 display_error(_("Cannot post to GL account used by more than one tax type."));
601 if ($type != QE_SUPPINV)
602 $cart->add_gl_item($gl_code,
603 $qe_line['dimension_id'], $qe_line['dimension2_id'],
604 $tax, $qe['description']);
607 $acc_name = get_gl_account_name($gl_code);
608 $cart->add_gl_codes_to_trans($gl_code,
609 $acc_name, $qe_line['dimension_id'],
610 $qe_line['dimension2_id'], $tax, $qe['description']);
612 if (strpos($qe_line['action'], '+'))
614 elseif (strpos($qe_line['action'], '-'))
618 if ($type != QE_SUPPINV)
619 $cart->add_gl_item($qe_line['dest_id'], $qe_line['dimension_id'],
620 $qe_line['dimension2_id'], $part, $qe['description']);
623 $acc_name = get_gl_account_name($qe_line['dest_id']);
624 $cart->add_gl_codes_to_trans($qe_line['dest_id'],
625 $acc_name, $qe_line['dimension_id'],
626 $qe_line['dimension2_id'], $part, $qe['description']);
634 function get_js_open_window($width, $height)
636 $js ="function openWindow(url, title)\n"
638 . " var left = (screen.width - $width) / 2;\n"
639 . " var top = (screen.height - $height) / 2;\n"
640 . " return window.open(url, title, 'width=$width,height=$height,left='+left+',top='+top+',screenX='+left+',screenY='+top+',status=no,scrollbars=yes');\n"
646 Setting focus on element $name in $form.
647 If $form<0 $name is element id.
649 function set_focus($name, $form_no=0) {
651 $Ajax->addFocus(true, $name);
652 $_POST['_focus'] = $name;
655 // Set default focus on first field $name if not set yet
656 // Returns unique name if $name=null
658 function default_focus($name=null, $form_no=0) {
661 $name = uniqid('_el',true);
662 if (!isset($_POST['_focus'])) {
668 Reset focus to next control element (e.g. link).
670 function reset_focus()
672 unset($_POST['_focus']);
675 function get_js_png_fix()
677 $js = "function fixPNG(myImage)\n"
679 . " var arVersion = navigator.appVersion.split(\"MSIE\")\n"
680 . " var version = parseFloat(arVersion[1])\n"
681 . " if ((version >= 5.5) && (version < 7) && (document.body.filters))\n"
683 . " var imgID = (myImage.id) ? \"id='\" + myImage.id + \"' \" : \"\"\n"
684 . " var imgClass = (myImage.className) ? \"class='\" + myImage.className + \"' \" : \"\"\n"
685 . " var imgTitle = (myImage.title) ?\n"
686 . " \"title='\" + myImage.title + \"' \" : \"title='\" + myImage.alt + \"' \"\n"
687 . " var imgStyle = \"display:inline-block;\" + myImage.style.cssText\n"
688 . " var strNewHTML = \"<span \" + imgID + imgClass + imgTitle\n"
689 . " + \" style=\\\"\" + \"width:\" + myImage.width\n"
690 . " + \"px; height:\" + myImage.height\n"
691 . " + \"px;\" + imgStyle + \";\"\n"
692 . " + \"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader\"\n"
693 . " + \"(src=\'\" + myImage.src + \"\', sizingMethod='scale');\\\"></span>\"\n"
694 . " myImage.outerHTML = strNewHTML\n"
700 function get_js_date_picker()
702 global $comp_path, $go_debug;
703 $fpath = $comp_path.'/'.user_company().'/js_cache/'.'date_picker.js';
705 if (!file_exists($fpath) || $go_debug) {
707 global $dateseps, $date_system;
709 $how = user_date_format(); // 0 = us/ca, 1 = eu, au, nz, 2 = jp, sw
710 $sep = $dateseps[user_date_sep()]; // date separator
711 $wstart = (($date_system == 1 || $date_system == 2) ? 6 : ($how == 0 ? 0 : 1)); // weekstart (sun = 0, mon = 1)
712 $months = array(_("January"),_("February"),_("March"),_("April"),_("May"),_("June"),_("July"),_("August"),_("September"),_("October"),_("November"),_("December"));
713 $wdays = array(_("Su"),_("Mo"),_("Tu"),_("We"),_("Th"),_("Fr"),_("Sa"));
714 $wno = _("W"); // week no
716 if ($date_system == 1)
717 list($cyear, $cmon, $cday) = gregorian_to_jalali(date("Y"), date("n"), date("j"));
718 else if ($date_system == 2)
719 list($cyear, $cmon, $cday) = gregorian_to_islamic(date("Y"), date("n"), date("j"));
723 function positionInfo(object) {
725 this.getElementLeft = getElementLeft;
726 function getElementLeft() {
729 if(typeof(p_elm) == 'object'){
732 elm = document.getElementById(p_elm);
734 while (elm != null) {
736 elm = elm.offsetParent;
740 this.getElementWidth = getElementWidth;
741 function getElementWidth(){
743 if(typeof(p_elm) == 'object'){
746 elm = document.getElementById(p_elm);
748 return parseInt(elm.offsetWidth);
750 this.getElementRight = getElementRight;
751 function getElementRight(){
752 return getElementLeft(p_elm) + getElementWidth(p_elm);
754 this.getElementTop = getElementTop;
755 function getElementTop() {
758 if(typeof(p_elm) == 'object'){
761 elm = document.getElementById(p_elm);
763 while (elm != null) {
765 elm = elm.offsetParent;
769 this.getElementHeight = getElementHeight;
770 function getElementHeight(){
772 if(typeof(p_elm) == 'object'){
775 elm = document.getElementById(p_elm);
777 return parseInt(elm.offsetHeight);
779 this.getElementBottom = getElementBottom;
780 function getElementBottom(){
781 return getElementTop(p_elm) + getElementHeight(p_elm);
785 var calendarId = 'CC';
787 var currentMonth = 0;
789 var selectedYear = 0;
790 var selectedMonth = 0;
792 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]'];
793 var wdays = ['$wdays[0]', '$wdays[1]', '$wdays[2]', '$wdays[3]', '$wdays[4]', '$wdays[5]', '$wdays[6]'];
794 var dateField = null;
795 function getProperty(p_property){
796 var p_elm = calendarId;
798 if(typeof(p_elm) == 'object'){
801 elm = document.getElementById(p_elm);
807 return elm[p_property];
816 function setElementProperty(p_property, p_value, p_elmId){
819 if(typeof(p_elm) == 'object'){
822 elm = document.getElementById(p_elm);
824 if((elm != null) && (elm.style != null)){
826 elm[ p_property ] = p_value;
829 function setProperty(p_property, p_value) {
830 setElementProperty(p_property, p_value, calendarId);
832 function getDaysInMonth(year, month) {
834 if ($date_system == 1)
836 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];
838 else if ($date_system == 2)
840 return [30,29,30,29,30,29,30,29,30,29,30,(((((11 * year) + 14) % 30) < 11) ? 30 : 29)][month-1];
844 return [31,((!(year % 4 ) && ( (year % 100 ) || !( year % 400 ) ))?29:28),31,30,31,30,31,31,30,31,30,31][month-1];
848 function getDayOfWeek(year, month, day) {
850 if ($date_system == 1 || $date_system == 2)
855 return a - (b * Math.floor(a / b));
859 return mod(Math.floor((j + 1.5)), 7);
862 if ($date_system == 1)
864 var epbase, epyear, t;
865 epbase = year - ((year >= 0) ? 474 : 473);
866 epyear = 474 + mod(epbase, 2820);
867 t = day + ((month <= 7) ? ((month - 1) * 31) : (((month - 1) * 30) + 6)) +
868 Math.floor(((epyear * 682) - 110) / 2816) + (epyear - 1) * 365 +
869 Math.floor(epbase / 2820) * 1029983 + (1948320.5 - 1);
871 else if ($date_system == 2)
874 t = Math.floor((11 * year + 3) / 30) + 354 * year + 30 * month -
875 Math.floor((month - 1) / 2) + day + 1948440 - 385;
883 var date = new Date(year,month-1,day)
884 return date.getDay();
888 this.clearDate = clearDate;
889 function clearDate() {
890 dateField.value = '';
893 this.getWeek = getWeek;
894 function getWeek(year, month, day) {
899 var date = new Date(year,month-1,day);
900 var D = date.getDay();
902 date.setDate(date.getDate() + (4 - D));
903 var YN = date.getFullYear();
904 var ZBDoCY = Math.floor((date.getTime() - new Date(YN, 0, 1, -6)) / 86400000);
905 var WN = 1 + Math.floor(ZBDoCY / 7);
908 this.setDate = setDate;
909 function setDate(year, month, day) {
911 if (month < 10) {month = '0' + month;}
912 if (day < 10) {day = '0' + day;}
916 var dateString = month+'$sep'+day+'$sep'+year;
920 var dateString = day+'$sep'+month+'$sep'+year;
924 var dateString = year+'$sep'+month+'$sep'+day;
927 dateField.value = dateString;
928 setFocus(dateField.name);
929 if(dateField.getAttribute('aspect')=='cdate')
930 setElementProperty('color', (dateField.value==user.date ? 'black':'red'), dateField);
931 if (dateField.className=='searchbox')
937 this.changeMonth = changeMonth;
938 function changeMonth(change) {
939 currentMonth += change;
941 if(currentMonth > 12) {
944 } else if(currentMonth < 1) {
948 calendar = document.getElementById(calendarId);
949 calendar.innerHTML = calendarDrawTable();
951 this.changeYear = changeYear;
952 function changeYear(change) {
953 currentYear += change;
955 calendar = document.getElementById(calendarId);
956 calendar.innerHTML = calendarDrawTable();
958 function getCurrentYear() {
959 var year = new Date().getYear();
960 if(year < 1900) year += 1900;
963 function getCurrentMonth() {
964 return new Date().getMonth() + 1;
966 function getCurrentDay() {
967 return new Date().getDate();
969 function calendarDrawTable() {
971 var wstart = $wstart;
972 var wno = ' $wno ';
974 var startDayOfWeek = getDayOfWeek(currentYear, currentMonth, dayOfMonth);
975 var daysInMonth = getDaysInMonth(currentYear, currentMonth);
976 var css_class = null; //CSS class for each day
977 var table = \"<table cellspacing='0' cellpadding='0' border='0'>\";
978 table += \"<tr class='header'>\";
979 table += \" <td colspan='2' class='previous'><a href='javascript:changeCCMonth(-1);'><</a><br><a href='javascript:changeCCYear(-1);'>«</a></td>\";
980 table += \" <td colspan='4' class='title'>\" + months[currentMonth-1] + \"<br>\" + currentYear + \"</td>\";
981 table += \" <td colspan='2' class='next'><a href='javascript:changeCCMonth(1);'>></a><br><a href='javascript:changeCCYear(1);'>»</a></td>\";
984 table += \"<th class='weekno'>\"+wno+\"</th>\";
985 for (var n=0; n<7; n++)
986 table += \"<th>\" + wdays[(wstart+n)%7]+\"</th>\";
988 for(var week=0; week < 6; week++) {
990 for(var n=0; n < 7; n++) {
991 dayOfWeek = (wstart+n)%7;
992 if(week == 0 && startDayOfWeek == dayOfWeek) {
994 } else if (validDay == 1 && dayOfMonth > daysInMonth) {
999 if (dayOfMonth > daysInMonth)
1000 table += \"<td class='empty'> </td>\";
1002 table += \"<td class='weekno'>\"+getWeek(currentYear, currentMonth, dayOfMonth)+\"</td>\";
1005 if (dayOfMonth == selectedDay && currentYear == selectedYear && currentMonth == selectedMonth) {
1006 css_class = 'current';
1008 if ($date_system == 1 || $date_system == 2)
1010 } else if (dayOfWeek == 5) {
1014 } else if (dayOfWeek == 0 || dayOfWeek == 6) {
1017 css_class = 'weekend';
1019 css_class = 'weekday';
1021 table += \"<td><a class='\"+css_class+\"' href=\\\"javascript:setCCDate(\"+currentYear+\",\"+currentMonth+\",\"+dayOfMonth+\")\\\">\"+dayOfMonth+\"</a></td>\";
1024 table += \"<td class='empty'> </td>\";
1029 table += \"<tr class='header'><th colspan='8' style='padding: 3px;text-align:center;'><a href='javascript:hideCC();'>$back</a></td></tr>\";
1030 table += \"</table>\";
1034 function show(field) {
1036 if (dateField == field) {
1043 var dateString = new String(dateField.value);
1044 var dateParts = dateString.split('$sep');
1048 selectedMonth = parseInt(dateParts[0],10);
1049 selectedDay = parseInt(dateParts[1],10);
1050 selectedYear = parseInt(dateParts[2],10);
1054 selectedDay = parseInt(dateParts[0],10);
1055 selectedMonth = parseInt(dateParts[1],10);
1056 selectedYear = parseInt(dateParts[2],10);
1060 selectedYear = parseInt(dateParts[0],10);
1061 selectedMonth = parseInt(dateParts[1],10);
1062 selectedDay = parseInt(dateParts[2],10);
1067 if (!(selectedYear && selectedMonth && selectedDay)) {
1069 if ($date_system == 1 || $date_system == 2)
1072 selectedMonth = $cmon;
1073 selectedDay = $cday;
1074 selectedYear = $cyear;
1080 selectedMonth = getCurrentMonth();
1081 selectedDay = getCurrentDay();
1082 selectedYear = getCurrentYear();
1087 currentMonth = selectedMonth;
1088 currentDay = selectedDay;
1089 currentYear = selectedYear;
1090 if(document.getElementById){
1091 calendar = document.getElementById(calendarId);
1092 calendar.innerHTML = calendarDrawTable(currentYear, currentMonth);
1093 var fieldPos = new positionInfo(dateField);
1094 var calendarPos = new positionInfo(calendarId);
1095 var x = fieldPos.getElementLeft();
1096 var y = fieldPos.getElementBottom();
1097 setProperty('left', x + 'px');
1098 setProperty('top', y + 'px');
1099 setProperty('display', 'block');
1101 setElementProperty('left', x + 'px', 'CCIframe');
1102 setElementProperty('top', y + 'px', 'CCIframe');
1103 setElementProperty('width', calendarPos.getElementWidth() + 'px', 'CCIframe');
1104 setElementProperty('height', calendarPos.getElementHeight() + 'px', 'CCIframe');
1105 setElementProperty('display', 'block', 'CCIframe');
1112 setProperty('display', 'none');
1113 setElementProperty('display', 'none', 'CCIframe');
1117 this.visible = visible;
1118 function visible() {
1121 this.can_hide = can_hide;
1125 function date_picker(textField) {
1133 function setCCDate(year, month, day) {
1134 cC.setDate(year, month, day);
1136 function changeCCYear(change) {
1137 cC.changeYear(change);
1139 function changeCCMonth(change) {
1140 cC.changeMonth(change);
1142 document.write(\"<iframe id='CCIframe' src='javascript:false;' frameBorder='0' scrolling='no'></iframe>\");
1143 document.write(\"<div id='CC'></div>\");";
1145 cache_js_file($fpath, $js);
1147 add_js_ufile($fpath);
1152 function alert($msg)
1154 echo "\n<script type=\"text/javascript\">\n"
1156 . "alert('$msg');\n"
1161 if (!function_exists('_vd'))
1163 function _vd($mixed, $title = '', $exit = false)
1165 // Only the site admin is able to proceed here.
1166 $str = (!empty($title) ? ($title .':') : '') .'<pre>';
1167 $str .= print_r($mixed, true); //var_dump($mixed);
1169 display_error('<table><tr><td>'.$str.'</td></tr></table>');
1175 function display_backtrace($cond=true, $msg='') {
1179 $str = "<center><span class='headingtext'>$msg</span></center>\n";
1182 $str .= '<table border=0>';
1183 $trace = debug_backtrace();
1184 foreach($trace as $trn => $tr) {
1185 if (!$trn) continue;
1187 $str .= $tr['file'].':'.$tr['line'].': ';
1188 $str .= '</td><td>';
1189 if (isset($tr['type'])) {
1190 if($tr['type'] == '::') {
1191 $str .= $tr['class'].'::';
1192 } else if($tr['type'] == '->') {
1193 $str .= '('.$tr['class'].' Object)'.'->';
1196 foreach($tr['args'] as $n=>$a) {
1197 if (is_object($tr['args'][$n]))
1198 $tr['args'][$n] = "(".get_class($tr['args'][$n])." Object)";
1199 if (is_array($tr['args'][$n]))
1200 $tr['args'][$n] = "(Array[".count($tr['args'][$n])."])";
1202 $tr['args'][$n] = "'".$tr['args'][$n]."'";
1204 $str .= $tr['function'].'('. implode(',',$tr['args']).')</td>';
1210 display_error($str);