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";
125 return viewer_link($label, "gl/view/$viewer?trans_no=$trans_no",
129 //--------------------------------------------------------------------------------------
131 function get_inventory_trans_view_str($type, $trans_no, $label="",
132 $icon=false, $class='', $id='')
134 $viewer = "inventory/view/";
136 if ($type == systypes::inventory_adjustment())
137 $viewer .= "view_adjustment.php";
138 elseif ($type == systypes::location_transfer())
139 $viewer .= "view_transfer.php";
142 $viewer .= "?trans_no=$trans_no";
147 return viewer_link($label, $viewer, $class, $id, $icon);
150 //--------------------------------------------------------------------------------------
152 function get_manufacturing_trans_view_str($type, $trans_no, $label="",
153 $icon=false, $class='', $id='')
155 $viewer = "manufacturing/view/";
158 $viewer .= "wo_issue_view.php";
160 $viewer .= "wo_production_view.php";
161 elseif ($type == systypes::work_order())
162 $viewer .= "work_order_view.php";
166 $viewer .= "?trans_no=$trans_no";
171 return viewer_link($label, $viewer, $class, $id, $icon);
174 //--------------------------------------------------------------------------------------
176 function get_dimensions_trans_view_str($type, $trans_no, $label="", $icon=false,
180 $viewer = "dimensions/view_dimension.php?trans_no=$trans_no";
187 return viewer_link($label, $viewer, $class, $id, $icon);
190 //--------------------------------------------------------------------------------------
192 function get_trans_view_str($type, $trans_no, $label="", $icon=false,
195 $view_str = get_customer_trans_view_str($type, $trans_no, $label, $icon, $class, $id);
196 if ($view_str != null)
199 $view_str = get_supplier_trans_view_str($type, $trans_no, $label, $icon, $class, $id);
200 if ($view_str != null)
203 $view_str = get_banking_trans_view_str($type, $trans_no, $label, $icon, $class, $id);
204 if ($view_str != null)
207 $view_str = get_inventory_trans_view_str($type, $trans_no, $label, $icon, $class, $id);
208 if ($view_str != null)
211 $view_str = get_manufacturing_trans_view_str($type, $trans_no, $label, $icon, $class, $id);
212 if ($view_str != null)
215 $view_str = get_dimensions_trans_view_str($type, $trans_no, $label, $icon, $class, $id);
216 if ($view_str != null)
222 //--------------------------------------------------------------------------------------
223 // Displays currency exchange rate for given date.
224 // When there is no exrate for today,
225 // gets it form ECB and stores in local database.
227 function exchange_rate_display($from_currency, $to_currency, $date_, $edit_rate=false)
231 if ($from_currency != $to_currency)
233 $comp_currency = get_company_currency();
234 if ($from_currency == $comp_currency)
235 $currency = $to_currency;
237 $currency = $from_currency;
239 if ($date_ == Today()) {
240 $rate = get_date_exchange_rate($currency, $date_);
242 $rate = get_ecb_rate($currency);
244 add_exchange_rate($currency, $date_, $rate, $rate);
248 $rate = get_exchange_rate_from_home_currency($currency, $date_);
249 if ($from_currency != $comp_currency)
250 $rate = 1 / ($rate / get_exchange_rate_from_home_currency($to_currency, $date_));
252 $rate = number_format2($rate, user_exrate_dec());
254 text_row(_("Exchange Rate:"), '_ex_rate', $rate, 8, 8, null, "", " $from_currency = 1 $to_currency");
256 label_row(_("Exchange Rate:"),"<span id='_ex_rate'>$rate</span> $from_currency = 1 $to_currency" );
257 $Ajax->addUpdate('_ex_rate','_ex_rate', $rate);
261 //--------------------------------------------------------------------------------------
263 function is_voided_display($type, $id, $label)
266 $void_entry = get_voided_entry($type, $id);
268 if ($void_entry == null)
271 start_table("width=50% $table_style");
272 echo "<tr><td align=center><font color=red>$label</font><br>";
273 echo "<font color=red>" . _("Date Voided:") . " " . sql2date($void_entry["date_"]) . "</font><br>";
274 if (strlen($void_entry["memo_"]) > 0)
275 echo "<center><font color=red>" . _("Memo:") . " " . $void_entry["memo_"] . "</font></center><br>";
282 //--------------------------------------------------------------------------------------
284 function comments_display_row($type, $id)
286 $comments = get_comments($type, $id);
287 if ($comments and db_num_rows($comments))
289 echo "<tr><td colspan=15>";
290 while ($comment = db_fetch($comments))
292 echo $comment["memo_"] . "<br>";
298 //--------------------------------------------------------------------------------------
300 function get_comments_string($type, $type_no)
303 $result = get_comments($type, $type_no);
304 while ($comment = db_fetch($result))
306 if (strlen($str_return))
307 $str_return = $str_return . " \n";
308 $str_return = $str_return . $comment["memo_"];
313 //--------------------------------------------------------------------------------------
315 function view_stock_status($stock_id, $description=null, $echo=true)
317 global $path_to_root;
319 //hyperlink_params_separate($path_to_root . "/inventory/inquiry/stock_status.php", (user_show_codes()?$stock_id . " - ":"") . $description, "stock_id=$stock_id");
320 $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>";
322 //hyperlink_params_separate($path_to_root . "/inventory/inquiry/stock_status.php", $stock_id, "stock_id=$stock_id");
323 $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>";
329 function view_stock_status_cell($stock_id, $description=null)
332 view_stock_status($stock_id, $description);
336 //--------------------------------------------------------------------------------------
338 function display_debit_or_credit_cells($value)
348 amount_cell(abs($value));
358 //--------------------------------------------------------------------------------------
360 function display_customer_trans_tax_details($tax_items, $columns)
362 while ($tax_item = db_fetch($tax_items))
364 $tax = number_format2($tax_item['amount'],user_price_dec());
365 if ($tax_item['included_in_price'])
366 label_row(_("Included") . " " . $tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%) " .
367 _("Amount") . ": $tax", "", "colspan=$columns align=right", "align=right");
369 label_row($tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%)",
370 $tax, "colspan=$columns align=right", "align=right");
374 //--------------------------------------------------------------------------------------
376 function display_supp_trans_tax_details($tax_items, $columns)
378 while ($tax_item = db_fetch($tax_items))
380 $tax = number_format2(abs($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_edit_tax_items($taxes, $columns, $tax_included, $leftspan=0)
396 foreach ($taxes as $taxitem)
400 label_row(_("Included") . " " . $taxitem['tax_type_name'] . " (" . $taxitem['rate'] . "%) " .
401 _("Amount:") . " " . number_format2($taxitem['Value'],user_price_dec()), "", "colspan=$columns align=right", "align=right",$leftspan);
405 label_row($taxitem['tax_type_name'] . " (" . $taxitem['rate'] . "%)",
406 number_format2($taxitem['Value'],user_price_dec()), "colspan=$columns align=right", "align=right",$leftspan);
407 $total += round2($taxitem['Value'], user_price_dec());
414 //--------------------------------------------------------------------------------------
416 function display_footer_exit()
423 //--------------------------------------------------------------------------------------
425 function display_allocations($alloc_result, $total)
429 if (!$alloc_result || db_num_rows($alloc_result) == 0)
432 display_heading2(_("Allocations"));
434 start_table("$table_style width=80%");
436 $th = array( _("Type"), _("Number"), _("Date"), _("Total Amount"),
437 _("Left to Allocate"), _("This Allocation"));
439 $k = $total_allocated = 0;
441 while ($alloc_row = db_fetch($alloc_result))
444 alt_table_row_color($k);
446 label_cell(systypes::name($alloc_row['type']));
447 label_cell(get_trans_view_str($alloc_row['type'],$alloc_row['trans_no']));
448 label_cell(sql2date($alloc_row['tran_date']));
449 $alloc_row['Total'] = round2($alloc_row['Total'], user_price_dec());
450 $alloc_row['amt'] = round2($alloc_row['amt'], user_price_dec());
451 amount_cell($alloc_row['Total']);
452 //amount_cell($alloc_row['Total'] - $alloc_row['PrevAllocs'] - $alloc_row['amt']);
453 amount_cell($alloc_row['Total'] - $alloc_row['amt']);
454 amount_cell($alloc_row['amt']);
457 $total_allocated += $alloc_row['amt'];
460 label_cell(_("Total Allocated:"), "align=right colspan=5");
461 amount_cell($total_allocated);
464 label_cell(_("Left to Allocate:"), "align=right colspan=5");
465 $total = round2($total, user_price_dec());
466 amount_cell($total - $total_allocated);
472 //--------------------------------------------------------------------------------------
474 function display_allocations_from($person_type, $person_id, $type, $type_no, $total)
476 switch ($person_type)
478 case payment_person_types::customer() :
479 $alloc_result = get_allocatable_to_cust_transactions($person_id, $type_no, $type);
480 display_allocations($alloc_result, $total);
482 case payment_person_types::supplier() :
483 $alloc_result = get_allocatable_to_supp_transactions($person_id, $type_no, $type);
484 display_allocations($alloc_result, $total);
489 //--------------------------------------------------------------------------------------
491 // Expands selected quick entry $id into GL posings and adds to cart.
492 // returns calculated amount posted to bank GL account.
494 function display_quick_entries(&$cart, $id, $base, $type, $descr='')
498 if (!isset($id) || $id == null || $id == "")
500 display_error( _("No Quick Entries are defined."));
501 set_focus('totamount');
505 if ($type == QE_DEPOSIT)
507 if ($type != QE_SUPPINV) // only one quick entry on journal/bank transaction
508 $cart->clear_items();
509 $qe = get_quick_entry($id);
510 if ($descr != '') $qe['description'] .= ': '.$descr;
511 $qe_lines = get_quick_entry_lines($id);
512 while ($qe_line = db_fetch($qe_lines))
514 switch (strtolower($qe_line['action'])) {
515 case "=": // post current base amount to GL account
518 case "a": // post amount to GL account and reduce base
519 $part = $qe_line['amount'];
521 case "a+": // post amount to GL account and increase base
522 $part = $qe_line['amount']; $base += $part;
524 case "a-": // post amount to GL account and reduce base
525 $part = $qe_line['amount']; $base -= $part;
527 case "%": // store acc*amount% to GL account
528 $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
530 case "%+": // ditto & increase base amount
531 $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
534 case "%-": // ditto & reduce base amount
535 $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
538 case "t": // post taxes calculated on base amount
539 case "t+": // ditto & increase base amount
540 case "t-": // ditto & reduce base amount
541 $taxes = get_taxes_for_item_tax($qe_line['dest_id']);
543 foreach ($taxes as $index => $item_tax) {
544 if(substr($qe_line['action'],0,1) != 'T')
545 $tax = round2($base * $item_tax['rate']
546 / ($item_tax['rate'] + 100), user_price_dec());
548 $tax = round2($base * $item_tax['rate'] / 100, user_price_dec());
550 $gl_code = ($type == QE_DEPOSIT || ($type == QE_JOURNAL && $base < 0))
551 ? $item_tax['sales_gl_code'] : $item_tax['purchasing_gl_code'];
553 if ($type != QE_SUPPINV)
554 $cart->add_gl_item($gl_code,
555 $qe_line['dimension_id'], $qe_line['dimension2_id'],
556 $tax, $qe['description']);
559 $acc_name = get_gl_account_name($gl_code);
560 $cart->add_gl_codes_to_trans($gl_code,
561 $acc_name, $qe_line['dimension_id'],
562 $qe_line['dimension2_id'], $tax, $qe['description']);
565 if (strpos($qe_line['action'], '+'))
567 elseif (strpos($qe_line['action'], '-'))
571 if ($type != QE_SUPPINV)
572 $cart->add_gl_item($qe_line['dest_id'], $qe_line['dimension_id'],
573 $qe_line['dimension2_id'], $part, $qe['description']);
576 $acc_name = get_gl_account_name($qe_line['dest_id']);
577 $cart->add_gl_codes_to_trans($qe_line['dest_id'],
578 $acc_name, $qe_line['dimension_id'],
579 $qe_line['dimension2_id'], $part, $qe['description']);
587 function get_js_open_window($width, $height)
589 $js = "\n<script type=\"text/javascript\">\n"
591 . "function openWindow(url, title)\n"
593 . " var left = (screen.width - $width) / 2;\n"
594 . " var top = (screen.height - $height) / 2;\n"
595 . " return window.open(url, title, 'width=$width,height=$height,left='+left+',top='+top+',screenX='+left+',screenY='+top+',status=no,scrollbars=yes');\n"
603 Setting focus on element $name in $form.
604 If $form<0 $name is element id.
606 function set_focus($name, $form_no=0) {
608 $Ajax->addFocus(true, $name);
609 $_POST['_focus'] = $name;
612 // Set default focus on first field $name if not set yet
613 // Returns unique name if $name=null
615 function default_focus($name=null, $form_no=0) {
618 $name = uniqid('_el',true);
619 if (!isset($_POST['_focus'])) {
625 function get_js_png_fix()
627 $js = "<script type=\"text/javascript\">\n"
628 . "function fixPNG(myImage)\n"
630 . " var arVersion = navigator.appVersion.split(\"MSIE\")\n"
631 . " var version = parseFloat(arVersion[1])\n"
632 . " if ((version >= 5.5) && (version < 7) && (document.body.filters))\n"
634 . " var imgID = (myImage.id) ? \"id='\" + myImage.id + \"' \" : \"\"\n"
635 . " var imgClass = (myImage.className) ? \"class='\" + myImage.className + \"' \" : \"\"\n"
636 . " var imgTitle = (myImage.title) ?\n"
637 . " \"title='\" + myImage.title + \"' \" : \"title='\" + myImage.alt + \"' \"\n"
638 . " var imgStyle = \"display:inline-block;\" + myImage.style.cssText\n"
639 . " var strNewHTML = \"<span \" + imgID + imgClass + imgTitle\n"
640 . " + \" style=\\\"\" + \"width:\" + myImage.width\n"
641 . " + \"px; height:\" + myImage.height\n"
642 . " + \"px;\" + imgStyle + \";\"\n"
643 . " + \"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader\"\n"
644 . " + \"(src=\'\" + myImage.src + \"\', sizingMethod='scale');\\\"></span>\"\n"
645 . " myImage.outerHTML = strNewHTML\n"
652 function get_js_date_picker()
654 global $comp_path, $go_debug;
655 $fpath = $comp_path.'/'.user_company().'/js_cache/'.'date_picker.js';
657 if (!file_exists($fpath) || $go_debug) {
659 global $dateseps, $date_system;
661 $how = user_date_format(); // 0 = us/ca, 1 = eu, au, nz, 2 = jp, sw
662 $sep = $dateseps[user_date_sep()]; // date separator
663 $wstart = (($date_system == 1 || $date_system == 2) ? 6 : ($how == 0 ? 0 : 1)); // weekstart (sun = 0, mon = 1)
664 $months = array(_("January"),_("February"),_("March"),_("April"),_("May"),_("June"),_("July"),_("August"),_("September"),_("October"),_("November"),_("December"));
665 $wdays = array(_("Su"),_("Mo"),_("Tu"),_("We"),_("Th"),_("Fr"),_("Sa"));
666 $wno = _("W"); // week no
668 if ($date_system == 1)
669 list($cyear, $cmon, $cday) = gregorian_to_jalali(date("Y"), date("n"), date("j"));
670 else if ($date_system == 2)
671 list($cyear, $cmon, $cday) = gregorian_to_islamic(date("Y"), date("n"), date("j"));
675 function positionInfo(object) {
677 this.getElementLeft = getElementLeft;
678 function getElementLeft() {
681 if(typeof(p_elm) == 'object'){
684 elm = document.getElementById(p_elm);
686 while (elm != null) {
688 elm = elm.offsetParent;
692 this.getElementWidth = getElementWidth;
693 function getElementWidth(){
695 if(typeof(p_elm) == 'object'){
698 elm = document.getElementById(p_elm);
700 return parseInt(elm.offsetWidth);
702 this.getElementRight = getElementRight;
703 function getElementRight(){
704 return getElementLeft(p_elm) + getElementWidth(p_elm);
706 this.getElementTop = getElementTop;
707 function getElementTop() {
710 if(typeof(p_elm) == 'object'){
713 elm = document.getElementById(p_elm);
715 while (elm != null) {
717 elm = elm.offsetParent;
721 this.getElementHeight = getElementHeight;
722 function getElementHeight(){
724 if(typeof(p_elm) == 'object'){
727 elm = document.getElementById(p_elm);
729 return parseInt(elm.offsetHeight);
731 this.getElementBottom = getElementBottom;
732 function getElementBottom(){
733 return getElementTop(p_elm) + getElementHeight(p_elm);
737 var calendarId = 'CC';
739 var currentMonth = 0;
741 var selectedYear = 0;
742 var selectedMonth = 0;
744 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]'];
745 var wdays = ['$wdays[0]', '$wdays[1]', '$wdays[2]', '$wdays[3]', '$wdays[4]', '$wdays[5]', '$wdays[6]'];
746 var dateField = null;
747 function getProperty(p_property){
748 var p_elm = calendarId;
750 if(typeof(p_elm) == 'object'){
753 elm = document.getElementById(p_elm);
759 return elm[p_property];
768 function setElementProperty(p_property, p_value, p_elmId){
771 if(typeof(p_elm) == 'object'){
774 elm = document.getElementById(p_elm);
776 if((elm != null) && (elm.style != null)){
778 elm[ p_property ] = p_value;
781 function setProperty(p_property, p_value) {
782 setElementProperty(p_property, p_value, calendarId);
784 function getDaysInMonth(year, month) {
786 if ($date_system == 1)
788 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];
790 else if ($date_system == 2)
792 return [30,29,30,29,30,29,30,29,30,29,30,(((((11 * year) + 14) % 30) < 11) ? 30 : 29)][month-1];
796 return [31,((!(year % 4 ) && ( (year % 100 ) || !( year % 400 ) ))?29:28),31,30,31,30,31,31,30,31,30,31][month-1];
800 function getDayOfWeek(year, month, day) {
802 if ($date_system == 1 || $date_system == 2)
807 return a - (b * Math.floor(a / b));
811 return mod(Math.floor((j + 1.5)), 7);
814 if ($date_system == 1)
816 var epbase, epyear, t;
817 epbase = year - ((year >= 0) ? 474 : 473);
818 epyear = 474 + mod(epbase, 2820);
819 t = day + ((month <= 7) ? ((month - 1) * 31) : (((month - 1) * 30) + 6)) +
820 Math.floor(((epyear * 682) - 110) / 2816) + (epyear - 1) * 365 +
821 Math.floor(epbase / 2820) * 1029983 + (1948320.5 - 1);
823 else if ($date_system == 2)
826 t = Math.floor((11 * year + 3) / 30) + 354 * year + 30 * month -
827 Math.floor((month - 1) / 2) + day + 1948440 - 385;
835 var date = new Date(year,month-1,day)
836 return date.getDay();
840 this.clearDate = clearDate;
841 function clearDate() {
842 dateField.value = '';
845 this.getWeek = getWeek;
846 function getWeek(year, month, day) {
851 var date = new Date(year,month-1,day);
852 var D = date.getDay();
854 date.setDate(date.getDate() + (4 - D));
855 var YN = date.getFullYear();
856 var ZBDoCY = Math.floor((date.getTime() - new Date(YN, 0, 1, -6)) / 86400000);
857 var WN = 1 + Math.floor(ZBDoCY / 7);
860 this.setDate = setDate;
861 function setDate(year, month, day) {
863 if (month < 10) {month = '0' + month;}
864 if (day < 10) {day = '0' + day;}
868 var dateString = month+'$sep'+day+'$sep'+year;
872 var dateString = day+'$sep'+month+'$sep'+year;
876 var dateString = year+'$sep'+month+'$sep'+day;
879 dateField.value = dateString;
880 setFocus(dateField.name);
881 if(dateField.getAttribute('aspect')=='cdate')
882 setElementProperty('color', (dateField.value==user.date ? 'black':'red'), dateField);
883 if (dateField.className=='searchbox')
889 this.changeMonth = changeMonth;
890 function changeMonth(change) {
891 currentMonth += change;
893 if(currentMonth > 12) {
896 } else if(currentMonth < 1) {
900 calendar = document.getElementById(calendarId);
901 calendar.innerHTML = calendarDrawTable();
903 this.changeYear = changeYear;
904 function changeYear(change) {
905 currentYear += change;
907 calendar = document.getElementById(calendarId);
908 calendar.innerHTML = calendarDrawTable();
910 function getCurrentYear() {
911 var year = new Date().getYear();
912 if(year < 1900) year += 1900;
915 function getCurrentMonth() {
916 return new Date().getMonth() + 1;
918 function getCurrentDay() {
919 return new Date().getDate();
921 function calendarDrawTable() {
923 var wstart = $wstart;
924 var wno = ' $wno ';
926 var startDayOfWeek = getDayOfWeek(currentYear, currentMonth, dayOfMonth);
927 var daysInMonth = getDaysInMonth(currentYear, currentMonth);
928 var css_class = null; //CSS class for each day
929 var table = \"<table cellspacing='0' cellpadding='0' border='0'>\";
930 table += \"<tr class='header'>\";
931 table += \" <td colspan='2' class='previous'><a href='javascript:changeCCMonth(-1);'><</a><br><a href='javascript:changeCCYear(-1);'>«</a></td>\";
932 table += \" <td colspan='4' class='title'>\" + months[currentMonth-1] + \"<br>\" + currentYear + \"</td>\";
933 table += \" <td colspan='2' class='next'><a href='javascript:changeCCMonth(1);'>></a><br><a href='javascript:changeCCYear(1);'>»</a></td>\";
936 table += \"<th class='weekno'>\"+wno+\"</th>\";
937 for (var n=0; n<7; n++)
938 table += \"<th>\" + wdays[(wstart+n)%7]+\"</th>\";
940 for(var week=0; week < 6; week++) {
942 for(var n=0; n < 7; n++) {
943 dayOfWeek = (wstart+n)%7;
944 if(week == 0 && startDayOfWeek == dayOfWeek) {
946 } else if (validDay == 1 && dayOfMonth > daysInMonth) {
951 if (dayOfMonth > daysInMonth)
952 table += \"<td class='empty'> </td>\";
954 table += \"<td class='weekno'>\"+getWeek(currentYear, currentMonth, dayOfMonth)+\"</td>\";
957 if (dayOfMonth == selectedDay && currentYear == selectedYear && currentMonth == selectedMonth) {
958 css_class = 'current';
960 if ($date_system == 1 || $date_system == 2)
962 } else if (dayOfWeek == 5) {
966 } else if (dayOfWeek == 0 || dayOfWeek == 6) {
969 css_class = 'weekend';
971 css_class = 'weekday';
973 table += \"<td><a class='\"+css_class+\"' href=\\\"javascript:setCCDate(\"+currentYear+\",\"+currentMonth+\",\"+dayOfMonth+\")\\\">\"+dayOfMonth+\"</a></td>\";
976 table += \"<td class='empty'> </td>\";
981 table += \"<tr class='header'><th colspan='8' style='padding: 3px;text-align:center;'><a href='javascript:hideCC();'>$back</a></td></tr>\";
982 table += \"</table>\";
986 function show(field) {
988 if (dateField == field) {
995 var dateString = new String(dateField.value);
996 var dateParts = dateString.split('$sep');
1000 selectedMonth = parseInt(dateParts[0],10);
1001 selectedDay = parseInt(dateParts[1],10);
1002 selectedYear = parseInt(dateParts[2],10);
1006 selectedDay = parseInt(dateParts[0],10);
1007 selectedMonth = parseInt(dateParts[1],10);
1008 selectedYear = parseInt(dateParts[2],10);
1012 selectedYear = parseInt(dateParts[0],10);
1013 selectedMonth = parseInt(dateParts[1],10);
1014 selectedDay = parseInt(dateParts[2],10);
1019 if (!(selectedYear && selectedMonth && selectedDay)) {
1021 if ($date_system == 1 || $date_system == 2)
1024 selectedMonth = $cmon;
1025 selectedDay = $cday;
1026 selectedYear = $cyear;
1032 selectedMonth = getCurrentMonth();
1033 selectedDay = getCurrentDay();
1034 selectedYear = getCurrentYear();
1039 currentMonth = selectedMonth;
1040 currentDay = selectedDay;
1041 currentYear = selectedYear;
1042 if(document.getElementById){
1043 calendar = document.getElementById(calendarId);
1044 calendar.innerHTML = calendarDrawTable(currentYear, currentMonth);
1045 var fieldPos = new positionInfo(dateField);
1046 var calendarPos = new positionInfo(calendarId);
1047 var x = fieldPos.getElementLeft();
1048 var y = fieldPos.getElementBottom();
1049 setProperty('left', x + 'px');
1050 setProperty('top', y + 'px');
1051 setProperty('display', 'block');
1053 setElementProperty('left', x + 'px', 'CCIframe');
1054 setElementProperty('top', y + 'px', 'CCIframe');
1055 setElementProperty('width', calendarPos.getElementWidth() + 'px', 'CCIframe');
1056 setElementProperty('height', calendarPos.getElementHeight() + 'px', 'CCIframe');
1057 setElementProperty('display', 'block', 'CCIframe');
1064 setProperty('display', 'none');
1065 setElementProperty('display', 'none', 'CCIframe');
1069 this.visible = visible;
1070 function visible() {
1073 this.can_hide = can_hide;
1077 function date_picker(textField) {
1085 function setCCDate(year, month, day) {
1086 cC.setDate(year, month, day);
1088 function changeCCYear(change) {
1089 cC.changeYear(change);
1091 function changeCCMonth(change) {
1092 cC.changeMonth(change);
1094 document.write(\"<iframe id='CCIframe' src='javascript:false;' frameBorder='0' scrolling='no'></iframe>\");
1095 document.write(\"<div id='CC'></div>\");";
1097 cache_js_file($fpath, $js);
1099 add_js_ufile($fpath);
1104 function alert($msg)
1106 echo "\n<script type=\"text/javascript\">\n"
1108 . "alert('$msg');\n"
1113 if (!function_exists('_vd'))
1115 function _vd($mixed, $title = '', $exit = false)
1117 // Only the site admin is able to proceed here.
1118 $str = (!empty($title) ? ($title .':') : '') .'<pre>';
1119 $str .= print_r($mixed, true); //var_dump($mixed);
1121 display_error('<table><tr><td>'.$str.'</td></tr></table>');
1127 function display_backtrace($cond=true, $msg='') {
1131 $str = "<center><span class='headingtext'>$msg</span></center>\n";
1134 $str .= '<table border=0>';
1135 $trace = debug_backtrace();
1136 foreach($trace as $trn => $tr) {
1137 if (!$trn) continue;
1139 $str .= $tr['file'].':'.$tr['line'].': ';
1140 $str .= '</td><td>';
1141 if (isset($tr['type'])) {
1142 if($tr['type'] == '::') {
1143 $str .= $tr['class'].'::';
1144 } else if($tr['type'] == '->') {
1145 $str .= '('.$tr['class'].' Object)'.'->';
1148 foreach($tr['args'] as $n=>$a) {
1149 if (is_object($tr['args'][$n]))
1150 $tr['args'][$n] = "(".get_class($tr['args'][$n])." Object)";
1151 if (is_array($tr['args'][$n]))
1152 $tr['args'][$n] = "(Array[".count($tr['args'][$n])."])";
1154 $tr['args'][$n] = "'".$tr['args'][$n]."'";
1156 $str .= $tr['function'].'('. implode(',',$tr['args']).')</td>';
1162 display_error($str);