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 == systypes::po())
22 $viewer .= "view_po.php";
24 $viewer .= "view_supp_invoice.php";
26 $viewer .= "view_supp_credit.php";
28 $viewer = "view_supp_payment.php";
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/";
77 $viewer .= "view_invoice.php";
79 $viewer .= "view_credit.php";
81 $viewer .= "view_receipt.php";
83 $viewer .= "view_dispatch.php";
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",
106 //--------------------------------------------------------------------------------------
108 function get_banking_trans_view_str($type, $trans_no, $label="",
109 $icon=false, $class='', $id='')
115 $viewer = "bank_transfer_view.php";
117 $viewer = "gl_payment_view.php";
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 == systypes::inventory_adjustment())
135 $viewer .= "view_adjustment.php";
136 elseif ($type == systypes::location_transfer())
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/";
156 $viewer .= "wo_issue_view.php";
158 $viewer .= "wo_production_view.php";
159 elseif ($type == systypes::work_order())
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,
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 == 0 || $type == 35)
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 $rate = get_ecb_rate($currency);
262 add_exchange_rate($currency, $date_, $rate, $rate);
266 $rate = get_exchange_rate_from_home_currency($currency, $date_);
267 if ($from_currency != $comp_currency)
268 $rate = 1 / ($rate / get_exchange_rate_from_home_currency($to_currency, $date_));
270 $rate = number_format2($rate, user_exrate_dec());
272 text_row(_("Exchange Rate:"), '_ex_rate', $rate, 8, 8, null, "", " $from_currency = 1 $to_currency");
274 label_row(_("Exchange Rate:"),"<span id='_ex_rate'>$rate</span> $from_currency = 1 $to_currency" );
275 $Ajax->addUpdate('_ex_rate','_ex_rate', $rate);
279 //--------------------------------------------------------------------------------------
281 function is_voided_display($type, $id, $label)
284 $void_entry = get_voided_entry($type, $id);
286 if ($void_entry == null)
289 start_table("width=50% $table_style");
290 echo "<tr><td align=center><font color=red>$label</font><br>";
291 echo "<font color=red>" . _("Date Voided:") . " " . sql2date($void_entry["date_"]) . "</font><br>";
292 if (strlen($void_entry["memo_"]) > 0)
293 echo "<center><font color=red>" . _("Memo:") . " " . $void_entry["memo_"] . "</font></center><br>";
300 //--------------------------------------------------------------------------------------
302 function comments_display_row($type, $id)
304 $comments = get_comments($type, $id);
305 if ($comments and db_num_rows($comments))
307 echo "<tr><td colspan=15>";
308 while ($comment = db_fetch($comments))
310 echo $comment["memo_"] . "<br>";
316 //--------------------------------------------------------------------------------------
318 function get_comments_string($type, $type_no)
321 $result = get_comments($type, $type_no);
322 while ($comment = db_fetch($result))
324 if (strlen($str_return))
325 $str_return = $str_return . " \n";
326 $str_return = $str_return . $comment["memo_"];
331 //--------------------------------------------------------------------------------------
333 function view_stock_status($stock_id, $description=null, $echo=true)
335 global $path_to_root;
337 //hyperlink_params_separate($path_to_root . "/inventory/inquiry/stock_status.php", (user_show_codes()?$stock_id . " - ":"") . $description, "stock_id=$stock_id");
338 $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>";
340 //hyperlink_params_separate($path_to_root . "/inventory/inquiry/stock_status.php", $stock_id, "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;\" >$stock_id</a>";
347 function view_stock_status_cell($stock_id, $description=null)
350 view_stock_status($stock_id, $description);
354 //--------------------------------------------------------------------------------------
356 function display_debit_or_credit_cells($value)
366 amount_cell(abs($value));
376 //--------------------------------------------------------------------------------------
378 function display_customer_trans_tax_details($tax_items, $columns)
380 while ($tax_item = db_fetch($tax_items))
382 $tax = number_format2($tax_item['amount'],user_price_dec());
383 if ($tax_item['included_in_price'])
384 label_row(_("Included") . " " . $tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%) " .
385 _("Amount") . ": $tax", "", "colspan=$columns align=right", "align=right");
387 label_row($tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%)",
388 $tax, "colspan=$columns align=right", "align=right");
392 //--------------------------------------------------------------------------------------
394 function display_supp_trans_tax_details($tax_items, $columns)
396 while ($tax_item = db_fetch($tax_items))
398 $tax = number_format2(abs($tax_item['amount']),user_price_dec());
399 if ($tax_item['included_in_price'])
400 label_row(_("Included") . " " . $tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%) " .
401 _("Amount") . ": $tax", "colspan=$columns align=right", "align=right");
403 label_row($tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%)",
404 $tax, "colspan=$columns align=right", "align=right");
408 //--------------------------------------------------------------------------------------
410 function display_edit_tax_items($taxes, $columns, $tax_included, $leftspan=0)
414 foreach ($taxes as $taxitem)
418 label_row(_("Included") . " " . $taxitem['tax_type_name'] . " (" . $taxitem['rate'] . "%) " .
419 _("Amount:") . " " . number_format2($taxitem['Value'],user_price_dec()), "", "colspan=$columns align=right", "align=right",$leftspan);
423 label_row($taxitem['tax_type_name'] . " (" . $taxitem['rate'] . "%)",
424 number_format2($taxitem['Value'],user_price_dec()), "colspan=$columns align=right", "align=right",$leftspan);
425 $total += round2($taxitem['Value'], user_price_dec());
432 //--------------------------------------------------------------------------------------
434 function display_footer_exit()
441 //--------------------------------------------------------------------------------------
443 function display_allocations($alloc_result, $total)
447 if (!$alloc_result || db_num_rows($alloc_result) == 0)
450 display_heading2(_("Allocations"));
452 start_table("$table_style width=80%");
454 $th = array( _("Type"), _("Number"), _("Date"), _("Total Amount"),
455 _("Left to Allocate"), _("This Allocation"));
457 $k = $total_allocated = 0;
459 while ($alloc_row = db_fetch($alloc_result))
462 alt_table_row_color($k);
464 label_cell(systypes::name($alloc_row['type']));
465 label_cell(get_trans_view_str($alloc_row['type'],$alloc_row['trans_no']));
466 label_cell(sql2date($alloc_row['tran_date']));
467 $alloc_row['Total'] = round2($alloc_row['Total'], user_price_dec());
468 $alloc_row['amt'] = round2($alloc_row['amt'], user_price_dec());
469 amount_cell($alloc_row['Total']);
470 //amount_cell($alloc_row['Total'] - $alloc_row['PrevAllocs'] - $alloc_row['amt']);
471 amount_cell($alloc_row['Total'] - $alloc_row['amt']);
472 amount_cell($alloc_row['amt']);
475 $total_allocated += $alloc_row['amt'];
478 label_cell(_("Total Allocated:"), "align=right colspan=5");
479 amount_cell($total_allocated);
482 label_cell(_("Left to Allocate:"), "align=right colspan=5");
483 $total = round2($total, user_price_dec());
484 amount_cell($total - $total_allocated);
490 //--------------------------------------------------------------------------------------
492 function display_allocations_from($person_type, $person_id, $type, $type_no, $total)
494 switch ($person_type)
496 case payment_person_types::customer() :
497 $alloc_result = get_allocatable_to_cust_transactions($person_id, $type_no, $type);
498 display_allocations($alloc_result, $total);
500 case payment_person_types::supplier() :
501 $alloc_result = get_allocatable_to_supp_transactions($person_id, $type_no, $type);
502 display_allocations($alloc_result, $total);
507 //--------------------------------------------------------------------------------------
509 // Expands selected quick entry $id into GL posings and adds to cart.
510 // returns calculated amount posted to bank GL account.
512 function display_quick_entries(&$cart, $id, $base, $type, $descr='')
516 if (!isset($id) || $id == null || $id == "")
518 display_error( _("No Quick Entries are defined."));
519 set_focus('totamount');
523 if ($type == QE_DEPOSIT)
525 if ($type != QE_SUPPINV) // only one quick entry on journal/bank transaction
526 $cart->clear_items();
527 $qe = get_quick_entry($id);
528 if ($descr != '') $qe['description'] .= ': '.$descr;
529 $qe_lines = get_quick_entry_lines($id);
530 while ($qe_line = db_fetch($qe_lines))
532 switch (strtolower($qe_line['action'])) {
533 case "=": // post current base amount to GL account
536 case "a": // post amount to GL account and reduce base
537 $part = $qe_line['amount'];
539 case "a+": // post amount to GL account and increase base
540 $part = $qe_line['amount']; $base += $part;
542 case "a-": // post amount to GL account and reduce base
543 $part = $qe_line['amount']; $base -= $part;
545 case "%": // store acc*amount% to GL account
546 $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
548 case "%+": // ditto & increase base amount
549 $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
552 case "%-": // ditto & reduce base amount
553 $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
556 case "t": // post taxes calculated on base amount
557 case "t+": // ditto & increase base amount
558 case "t-": // ditto & reduce base amount
559 $taxes = get_taxes_for_item_tax($qe_line['dest_id']);
561 foreach ($taxes as $index => $item_tax) {
562 if(substr($qe_line['action'],0,1) != 'T')
563 $tax = round2($base * $item_tax['rate']
564 / ($item_tax['rate'] + 100), user_price_dec());
566 $tax = round2($base * $item_tax['rate'] / 100, user_price_dec());
568 $gl_code = ($type == QE_DEPOSIT || ($type == QE_JOURNAL && $base < 0))
569 ? $item_tax['sales_gl_code'] : $item_tax['purchasing_gl_code'];
571 if ($type != QE_SUPPINV)
572 $cart->add_gl_item($gl_code,
573 $qe_line['dimension_id'], $qe_line['dimension2_id'],
574 $tax, $qe['description']);
577 $acc_name = get_gl_account_name($gl_code);
578 $cart->add_gl_codes_to_trans($gl_code,
579 $acc_name, $qe_line['dimension_id'],
580 $qe_line['dimension2_id'], $tax, $qe['description']);
583 if (strpos($qe_line['action'], '+'))
585 elseif (strpos($qe_line['action'], '-'))
589 if ($type != QE_SUPPINV)
590 $cart->add_gl_item($qe_line['dest_id'], $qe_line['dimension_id'],
591 $qe_line['dimension2_id'], $part, $qe['description']);
594 $acc_name = get_gl_account_name($qe_line['dest_id']);
595 $cart->add_gl_codes_to_trans($qe_line['dest_id'],
596 $acc_name, $qe_line['dimension_id'],
597 $qe_line['dimension2_id'], $part, $qe['description']);
605 function get_js_open_window($width, $height)
607 $js ="function openWindow(url, title)\n"
609 . " var left = (screen.width - $width) / 2;\n"
610 . " var top = (screen.height - $height) / 2;\n"
611 . " return window.open(url, title, 'width=$width,height=$height,left='+left+',top='+top+',screenX='+left+',screenY='+top+',status=no,scrollbars=yes');\n"
617 Setting focus on element $name in $form.
618 If $form<0 $name is element id.
620 function set_focus($name, $form_no=0) {
622 $Ajax->addFocus(true, $name);
623 $_POST['_focus'] = $name;
626 // Set default focus on first field $name if not set yet
627 // Returns unique name if $name=null
629 function default_focus($name=null, $form_no=0) {
632 $name = uniqid('_el',true);
633 if (!isset($_POST['_focus'])) {
639 function get_js_png_fix()
641 $js = "function fixPNG(myImage)\n"
643 . " var arVersion = navigator.appVersion.split(\"MSIE\")\n"
644 . " var version = parseFloat(arVersion[1])\n"
645 . " if ((version >= 5.5) && (version < 7) && (document.body.filters))\n"
647 . " var imgID = (myImage.id) ? \"id='\" + myImage.id + \"' \" : \"\"\n"
648 . " var imgClass = (myImage.className) ? \"class='\" + myImage.className + \"' \" : \"\"\n"
649 . " var imgTitle = (myImage.title) ?\n"
650 . " \"title='\" + myImage.title + \"' \" : \"title='\" + myImage.alt + \"' \"\n"
651 . " var imgStyle = \"display:inline-block;\" + myImage.style.cssText\n"
652 . " var strNewHTML = \"<span \" + imgID + imgClass + imgTitle\n"
653 . " + \" style=\\\"\" + \"width:\" + myImage.width\n"
654 . " + \"px; height:\" + myImage.height\n"
655 . " + \"px;\" + imgStyle + \";\"\n"
656 . " + \"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader\"\n"
657 . " + \"(src=\'\" + myImage.src + \"\', sizingMethod='scale');\\\"></span>\"\n"
658 . " myImage.outerHTML = strNewHTML\n"
664 function get_js_date_picker()
666 global $comp_path, $go_debug;
667 $fpath = $comp_path.'/'.user_company().'/js_cache/'.'date_picker.js';
669 if (!file_exists($fpath) || $go_debug) {
671 global $dateseps, $date_system;
673 $how = user_date_format(); // 0 = us/ca, 1 = eu, au, nz, 2 = jp, sw
674 $sep = $dateseps[user_date_sep()]; // date separator
675 $wstart = (($date_system == 1 || $date_system == 2) ? 6 : ($how == 0 ? 0 : 1)); // weekstart (sun = 0, mon = 1)
676 $months = array(_("January"),_("February"),_("March"),_("April"),_("May"),_("June"),_("July"),_("August"),_("September"),_("October"),_("November"),_("December"));
677 $wdays = array(_("Su"),_("Mo"),_("Tu"),_("We"),_("Th"),_("Fr"),_("Sa"));
678 $wno = _("W"); // week no
680 if ($date_system == 1)
681 list($cyear, $cmon, $cday) = gregorian_to_jalali(date("Y"), date("n"), date("j"));
682 else if ($date_system == 2)
683 list($cyear, $cmon, $cday) = gregorian_to_islamic(date("Y"), date("n"), date("j"));
687 function positionInfo(object) {
689 this.getElementLeft = getElementLeft;
690 function getElementLeft() {
693 if(typeof(p_elm) == 'object'){
696 elm = document.getElementById(p_elm);
698 while (elm != null) {
700 elm = elm.offsetParent;
704 this.getElementWidth = getElementWidth;
705 function getElementWidth(){
707 if(typeof(p_elm) == 'object'){
710 elm = document.getElementById(p_elm);
712 return parseInt(elm.offsetWidth);
714 this.getElementRight = getElementRight;
715 function getElementRight(){
716 return getElementLeft(p_elm) + getElementWidth(p_elm);
718 this.getElementTop = getElementTop;
719 function getElementTop() {
722 if(typeof(p_elm) == 'object'){
725 elm = document.getElementById(p_elm);
727 while (elm != null) {
729 elm = elm.offsetParent;
733 this.getElementHeight = getElementHeight;
734 function getElementHeight(){
736 if(typeof(p_elm) == 'object'){
739 elm = document.getElementById(p_elm);
741 return parseInt(elm.offsetHeight);
743 this.getElementBottom = getElementBottom;
744 function getElementBottom(){
745 return getElementTop(p_elm) + getElementHeight(p_elm);
749 var calendarId = 'CC';
751 var currentMonth = 0;
753 var selectedYear = 0;
754 var selectedMonth = 0;
756 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]'];
757 var wdays = ['$wdays[0]', '$wdays[1]', '$wdays[2]', '$wdays[3]', '$wdays[4]', '$wdays[5]', '$wdays[6]'];
758 var dateField = null;
759 function getProperty(p_property){
760 var p_elm = calendarId;
762 if(typeof(p_elm) == 'object'){
765 elm = document.getElementById(p_elm);
771 return elm[p_property];
780 function setElementProperty(p_property, p_value, p_elmId){
783 if(typeof(p_elm) == 'object'){
786 elm = document.getElementById(p_elm);
788 if((elm != null) && (elm.style != null)){
790 elm[ p_property ] = p_value;
793 function setProperty(p_property, p_value) {
794 setElementProperty(p_property, p_value, calendarId);
796 function getDaysInMonth(year, month) {
798 if ($date_system == 1)
800 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];
802 else if ($date_system == 2)
804 return [30,29,30,29,30,29,30,29,30,29,30,(((((11 * year) + 14) % 30) < 11) ? 30 : 29)][month-1];
808 return [31,((!(year % 4 ) && ( (year % 100 ) || !( year % 400 ) ))?29:28),31,30,31,30,31,31,30,31,30,31][month-1];
812 function getDayOfWeek(year, month, day) {
814 if ($date_system == 1 || $date_system == 2)
819 return a - (b * Math.floor(a / b));
823 return mod(Math.floor((j + 1.5)), 7);
826 if ($date_system == 1)
828 var epbase, epyear, t;
829 epbase = year - ((year >= 0) ? 474 : 473);
830 epyear = 474 + mod(epbase, 2820);
831 t = day + ((month <= 7) ? ((month - 1) * 31) : (((month - 1) * 30) + 6)) +
832 Math.floor(((epyear * 682) - 110) / 2816) + (epyear - 1) * 365 +
833 Math.floor(epbase / 2820) * 1029983 + (1948320.5 - 1);
835 else if ($date_system == 2)
838 t = Math.floor((11 * year + 3) / 30) + 354 * year + 30 * month -
839 Math.floor((month - 1) / 2) + day + 1948440 - 385;
847 var date = new Date(year,month-1,day)
848 return date.getDay();
852 this.clearDate = clearDate;
853 function clearDate() {
854 dateField.value = '';
857 this.getWeek = getWeek;
858 function getWeek(year, month, day) {
863 var date = new Date(year,month-1,day);
864 var D = date.getDay();
866 date.setDate(date.getDate() + (4 - D));
867 var YN = date.getFullYear();
868 var ZBDoCY = Math.floor((date.getTime() - new Date(YN, 0, 1, -6)) / 86400000);
869 var WN = 1 + Math.floor(ZBDoCY / 7);
872 this.setDate = setDate;
873 function setDate(year, month, day) {
875 if (month < 10) {month = '0' + month;}
876 if (day < 10) {day = '0' + day;}
880 var dateString = month+'$sep'+day+'$sep'+year;
884 var dateString = day+'$sep'+month+'$sep'+year;
888 var dateString = year+'$sep'+month+'$sep'+day;
891 dateField.value = dateString;
892 setFocus(dateField.name);
893 if(dateField.getAttribute('aspect')=='cdate')
894 setElementProperty('color', (dateField.value==user.date ? 'black':'red'), dateField);
895 if (dateField.className=='searchbox')
901 this.changeMonth = changeMonth;
902 function changeMonth(change) {
903 currentMonth += change;
905 if(currentMonth > 12) {
908 } else if(currentMonth < 1) {
912 calendar = document.getElementById(calendarId);
913 calendar.innerHTML = calendarDrawTable();
915 this.changeYear = changeYear;
916 function changeYear(change) {
917 currentYear += change;
919 calendar = document.getElementById(calendarId);
920 calendar.innerHTML = calendarDrawTable();
922 function getCurrentYear() {
923 var year = new Date().getYear();
924 if(year < 1900) year += 1900;
927 function getCurrentMonth() {
928 return new Date().getMonth() + 1;
930 function getCurrentDay() {
931 return new Date().getDate();
933 function calendarDrawTable() {
935 var wstart = $wstart;
936 var wno = ' $wno ';
938 var startDayOfWeek = getDayOfWeek(currentYear, currentMonth, dayOfMonth);
939 var daysInMonth = getDaysInMonth(currentYear, currentMonth);
940 var css_class = null; //CSS class for each day
941 var table = \"<table cellspacing='0' cellpadding='0' border='0'>\";
942 table += \"<tr class='header'>\";
943 table += \" <td colspan='2' class='previous'><a href='javascript:changeCCMonth(-1);'><</a><br><a href='javascript:changeCCYear(-1);'>«</a></td>\";
944 table += \" <td colspan='4' class='title'>\" + months[currentMonth-1] + \"<br>\" + currentYear + \"</td>\";
945 table += \" <td colspan='2' class='next'><a href='javascript:changeCCMonth(1);'>></a><br><a href='javascript:changeCCYear(1);'>»</a></td>\";
948 table += \"<th class='weekno'>\"+wno+\"</th>\";
949 for (var n=0; n<7; n++)
950 table += \"<th>\" + wdays[(wstart+n)%7]+\"</th>\";
952 for(var week=0; week < 6; week++) {
954 for(var n=0; n < 7; n++) {
955 dayOfWeek = (wstart+n)%7;
956 if(week == 0 && startDayOfWeek == dayOfWeek) {
958 } else if (validDay == 1 && dayOfMonth > daysInMonth) {
963 if (dayOfMonth > daysInMonth)
964 table += \"<td class='empty'> </td>\";
966 table += \"<td class='weekno'>\"+getWeek(currentYear, currentMonth, dayOfMonth)+\"</td>\";
969 if (dayOfMonth == selectedDay && currentYear == selectedYear && currentMonth == selectedMonth) {
970 css_class = 'current';
972 if ($date_system == 1 || $date_system == 2)
974 } else if (dayOfWeek == 5) {
978 } else if (dayOfWeek == 0 || dayOfWeek == 6) {
981 css_class = 'weekend';
983 css_class = 'weekday';
985 table += \"<td><a class='\"+css_class+\"' href=\\\"javascript:setCCDate(\"+currentYear+\",\"+currentMonth+\",\"+dayOfMonth+\")\\\">\"+dayOfMonth+\"</a></td>\";
988 table += \"<td class='empty'> </td>\";
993 table += \"<tr class='header'><th colspan='8' style='padding: 3px;text-align:center;'><a href='javascript:hideCC();'>$back</a></td></tr>\";
994 table += \"</table>\";
998 function show(field) {
1000 if (dateField == field) {
1007 var dateString = new String(dateField.value);
1008 var dateParts = dateString.split('$sep');
1012 selectedMonth = parseInt(dateParts[0],10);
1013 selectedDay = parseInt(dateParts[1],10);
1014 selectedYear = parseInt(dateParts[2],10);
1018 selectedDay = parseInt(dateParts[0],10);
1019 selectedMonth = parseInt(dateParts[1],10);
1020 selectedYear = parseInt(dateParts[2],10);
1024 selectedYear = parseInt(dateParts[0],10);
1025 selectedMonth = parseInt(dateParts[1],10);
1026 selectedDay = parseInt(dateParts[2],10);
1031 if (!(selectedYear && selectedMonth && selectedDay)) {
1033 if ($date_system == 1 || $date_system == 2)
1036 selectedMonth = $cmon;
1037 selectedDay = $cday;
1038 selectedYear = $cyear;
1044 selectedMonth = getCurrentMonth();
1045 selectedDay = getCurrentDay();
1046 selectedYear = getCurrentYear();
1051 currentMonth = selectedMonth;
1052 currentDay = selectedDay;
1053 currentYear = selectedYear;
1054 if(document.getElementById){
1055 calendar = document.getElementById(calendarId);
1056 calendar.innerHTML = calendarDrawTable(currentYear, currentMonth);
1057 var fieldPos = new positionInfo(dateField);
1058 var calendarPos = new positionInfo(calendarId);
1059 var x = fieldPos.getElementLeft();
1060 var y = fieldPos.getElementBottom();
1061 setProperty('left', x + 'px');
1062 setProperty('top', y + 'px');
1063 setProperty('display', 'block');
1065 setElementProperty('left', x + 'px', 'CCIframe');
1066 setElementProperty('top', y + 'px', 'CCIframe');
1067 setElementProperty('width', calendarPos.getElementWidth() + 'px', 'CCIframe');
1068 setElementProperty('height', calendarPos.getElementHeight() + 'px', 'CCIframe');
1069 setElementProperty('display', 'block', 'CCIframe');
1076 setProperty('display', 'none');
1077 setElementProperty('display', 'none', 'CCIframe');
1081 this.visible = visible;
1082 function visible() {
1085 this.can_hide = can_hide;
1089 function date_picker(textField) {
1097 function setCCDate(year, month, day) {
1098 cC.setDate(year, month, day);
1100 function changeCCYear(change) {
1101 cC.changeYear(change);
1103 function changeCCMonth(change) {
1104 cC.changeMonth(change);
1106 document.write(\"<iframe id='CCIframe' src='javascript:false;' frameBorder='0' scrolling='no'></iframe>\");
1107 document.write(\"<div id='CC'></div>\");";
1109 cache_js_file($fpath, $js);
1111 add_js_ufile($fpath);
1116 function alert($msg)
1118 echo "\n<script type=\"text/javascript\">\n"
1120 . "alert('$msg');\n"
1125 if (!function_exists('_vd'))
1127 function _vd($mixed, $title = '', $exit = false)
1129 // Only the site admin is able to proceed here.
1130 $str = (!empty($title) ? ($title .':') : '') .'<pre>';
1131 $str .= print_r($mixed, true); //var_dump($mixed);
1133 display_error('<table><tr><td>'.$str.'</td></tr></table>');
1139 function display_backtrace($cond=true, $msg='') {
1143 $str = "<center><span class='headingtext'>$msg</span></center>\n";
1146 $str .= '<table border=0>';
1147 $trace = debug_backtrace();
1148 foreach($trace as $trn => $tr) {
1149 if (!$trn) continue;
1151 $str .= $tr['file'].':'.$tr['line'].': ';
1152 $str .= '</td><td>';
1153 if (isset($tr['type'])) {
1154 if($tr['type'] == '::') {
1155 $str .= $tr['class'].'::';
1156 } else if($tr['type'] == '->') {
1157 $str .= '('.$tr['class'].' Object)'.'->';
1160 foreach($tr['args'] as $n=>$a) {
1161 if (is_object($tr['args'][$n]))
1162 $tr['args'][$n] = "(".get_class($tr['args'][$n])." Object)";
1163 if (is_array($tr['args'][$n]))
1164 $tr['args'][$n] = "(Array[".count($tr['args'][$n])."])";
1166 $tr['args'][$n] = "'".$tr['args'][$n]."'";
1168 $str .= $tr['function'].'('. implode(',',$tr['args']).')</td>';
1174 display_error($str);