Removed many global variables from config.default.php to GL Setup, Company Setup...
[fa-stable.git] / includes / ui / ui_input.inc
index 36f99e9ce01bf0e7bd5fc69095c14a804bd3ea59..c1091b3702c63a76df24ae2e5c621167fd64578a 100644 (file)
@@ -37,6 +37,7 @@ function find_submit($prefix, $numeric=true)
     }
     return $numeric ? -1 : null;
 }
+
 //------------------------------------------------------------------------------
 //
 // Helper function for simple db table editor pages
@@ -107,35 +108,47 @@ function hidden($name, $value=null, $echo=true)
                null  - button visible only in fallback mode; optional icon
         Ajax submit:
                true      - standard button; optional icon
-               'process' - displays progress bar during call; optional icon
+
                'default' - default form submit on Ctrl-Enter press; dflt ICON_OK icon
                'selector' - ditto with closing current popup editor window
                'cancel'  - cancel form entry on Escape press; dflt ICON_CANCEL
+               'process' - displays progress bar during call; optional icon
+               'nonajax' - ditto, non-ajax submit
+
+       $atype can contain also multiply type selectors separated by space, 
+       however make sense only combination of 'process' and one of defualt/selector/cancel
 */
 function submit($name, $value, $echo=true, $title=false, $atype=false, $icon=false)
 {
        global $path_to_root;
 
        $aspect='';
-       if (!is_bool($atype)) // necessary: switch uses '=='
-         switch($atype) {
-               case 'process':
-                       $aspect = " aspect='process'"; break;
-               case 'selector':
-                       $aspect = " aspect='selector' rel = '$value'"; 
-                       $value = _("Select");
-                       if ($icon===false) $icon=ICON_SUBMIT; break;
-               case 'default':
-                       $aspect = " aspect='default'"; 
-                       if ($icon===false) $icon=ICON_SUBMIT; break;
-               case 'cancel':
-                       $aspect = " aspect='cancel'"; 
-                       if ($icon===false) $icon=ICON_ESCAPE; break;
-               case null: 
-                       $aspect = fallback_mode() ? 
-                               " aspect='fallback'" : " style='display:none;'"; break;
-        }
+       if ($atype === null) {
+               $aspect = fallback_mode() ? " aspect='fallback'" : " style='display:none;'";
+
+       } elseif (!is_bool($atype)) { // necessary: switch uses '=='
 
+               $aspect = "aspect='$atype' ";
+               $types = explode(' ', $atype);
+
+               foreach ($types as $type) {
+                       switch($type) {
+                               case 'selector':
+                                       $aspect = " aspect='selector' rel = '$value'"; 
+                                       $value = _("Select");
+                                       if ($icon===false) $icon=ICON_SUBMIT; break;
+
+                               case 'default':
+                                       if ($icon===false) $icon=ICON_SUBMIT; break;
+
+                               case 'cancel':
+                                       if ($icon===false) $icon=ICON_ESCAPE; break;
+
+                               case 'nonajax':
+                                       $atype = false;
+                       }
+               }
+       }
        $submit_str = "<button class=\""
            .($atype ? 'ajaxsubmit' : 'inputsubmit')
                ."\" type=\"submit\""
@@ -239,17 +252,24 @@ function submit_return($name, $value, $title=false)
        }
 }
 
-function submit_js_confirm($name, $msg) {
-       add_js_source(
-               "_validate.$name=function(){ return confirm('"
-                       . strtr($msg, array("\n"=>'\\n')) . "');};");
-};
+function submit_js_confirm($name, $msg, $set = true) {
+       global $Ajax;
+       $js = "_validate.$name=".($set ? "function(){ return confirm('"
+                               . strtr($msg, array("\n"=>'\\n')) . "');};"
+                               : 'null;');
+       if (in_ajax()) {
+               $Ajax->addScript(true, $js);
+       } else
+               add_js_source($js);
+}
 //-----------------------------------------------------------------------------------
 
 function set_icon($icon, $title=false)
 {
        global $path_to_root;
-       return "<img src='$path_to_root/themes/".user_theme()."/images/$icon' width='12' height='12' border='0'".($title ? " title='$title'" : "")." />\n";     
+       if (basename($icon) === $icon) // standard icons does not contain path separator
+               $icon = "$path_to_root/themes/".user_theme()."/images/$icon";
+       return "<img src='$icon' width='12' height='12' border='0'".($title ? " title='$title'" : "")." />\n";  
 }
 
 function button($name, $value, $title=false, $icon=false,  $aspect='')
@@ -265,16 +285,18 @@ function button($name, $value, $title=false, $icon=false,  $aspect='')
        {
                if ($value == _("Delete")) // Helper during implementation
                        $icon = ICON_DELETE;
-               return "<button type='submit' class='editbutton' name='".
-                       htmlentities(strtr($name, array('.'=>'=2E',' '=>'=20','='=>'=3D','['=>'=5B'))).
-                       "' value='1'" . ($title ? " title='$title'":" title='$value'")
+               return "<button type='submit' class='editbutton' name='"
+                       .htmlentities(strtr($name, array('.'=>'=2E', '='=>'=3D',// ' '=>'=20','['=>'=5B'
+                       )))
+                       ."' value='1'" . ($title ? " title='$title'":" title='$value'")
                        . ($aspect ? " aspect='$aspect'" : '')
                        . $rel
                        ." />".set_icon($icon)."</button>\n";
        }
        else
                return "<input type='submit' class='editbutton' name='"
-                       .htmlentities(strtr($name, array('.'=>'=2E',' '=>'=20','='=>'=3D','['=>'=5B')))
+                       .htmlentities(strtr($name, array('.'=>'=2E', '='=>'=3D',// ' '=>'=20','['=>'=5B'
+                       )))
                        ."' value='$value'"
                        .($title ? " title='$title'":'')
                        . ($aspect ? " aspect='$aspect'" : '')
@@ -362,7 +384,10 @@ function check_row($label, $name, $value=null, $submit_on_change=false, $title=f
 }
 
 //-----------------------------------------------------------------------------------
-function radio($label, $name, $value, $selected, $submit_on_change=false) {
+function radio($label, $name, $value, $selected=null, $submit_on_change=false)
+{
+       if (!isset($selected))
+               $selected = get_post($name) == $value;
 
        if ($submit_on_change === true)
                $submit_on_change = 
@@ -581,7 +606,7 @@ function link_row_ex($label, $name, $size, $max=null, $title=null, $value=null,
 function date_cells($label, $name, $title = null, $check=null, $inc_days=0, 
        $inc_months=0, $inc_years=0, $params=null, $submit_on_change=false)
 {
-       global $use_date_picker, $path_to_root, $Ajax;
+       global $path_to_root, $Ajax;
 
        if (!isset($_POST[$name]) || $_POST[$name] == "")
        {
@@ -599,9 +624,13 @@ function date_cells($label, $name, $title = null, $check=null, $inc_days=0,
                        $_POST[$name] = $dd;
                }
        }
-       if ($use_date_picker)
+       if (user_use_date_picker())
+       {
+               $calc_image = (file_exists("$path_to_root/themes/".user_theme()."/images/cal.gif")) ? 
+                       "$path_to_root/themes/".user_theme()."/images/cal.gif" : "$path_to_root/themes/default/images/cal.gif";
                $post_label = "<a tabindex='-1' href=\"javascript:date_picker(document.getElementsByName('$name')[0]);\">"
-               . "     <img src='$path_to_root/themes/default/images/cal.gif' width='16' height='16' border='0' alt='"._('Click Here to Pick up the date')."'></a>\n";
+               . "     <img src='$calc_image' width='16' height='16' border='0' alt='"._('Click Here to Pick up the date')."'></a>\n";
+       }       
        else
                $post_label = "";
 
@@ -610,15 +639,15 @@ function date_cells($label, $name, $title = null, $check=null, $inc_days=0,
 
        echo "<td>";
        
-       $class = $submit_on_change ? 'class="searchbox"' : '';
+       $class = $submit_on_change ? 'date active' : 'date';
 
        $aspect = $check ? 'aspect="cdate"' : '';
        if ($check && (get_post($name) != Today()))
                $aspect .= ' style="color:#FF0000"';
 
        default_focus($name);
-
-       echo "<input type=\"text\" name=\"$name\" $class $aspect size=\"9\" maxlength=\"12\" value=\"" 
+       $size = (user_date_format()>3)?11:10; 
+       echo "<input type=\"text\" name=\"$name\" class=\"$class\" $aspect size=\"$size\" maxlength=\"12\" value=\"" 
         . $_POST[$name]. "\""
         .($title ? " title='$title'": '')." > $post_label";
        echo "</td>\n";
@@ -862,7 +891,7 @@ function inactive_control_cell($id, $value, $table, $key)
                        get_post('Update')) && (check_value('Inactive'.$id) != $value)) {
                        update_record_status($id, !$value, $table, $key);
                }
-               echo '<td align="center">'. checkbox(null, $name, $value, true, '', "align='center'")
+               echo '<td align="center">'. checkbox(null, $name, $value, true, '')
                        . hidden("LInact[$id]", $value, false) . '</td>';       
        }
 }
@@ -889,4 +918,63 @@ function inactive_control_column(&$th) {
                $Ajax->activate('_page_body');
        }
 }
+
+function customer_credit_row($customer, $credit, $parms='')
+{
+       global $path_to_root;
+       
+       label_row( _("Current Credit:"),
+               "<a target='_blank' " . ($credit<0 ? 'class="redfg"' : '')
+               ."href='$path_to_root/sales/inquiry/customer_inquiry.php?customer_id=".$customer."'"
+               ." onclick=\"javascript:openWindow(this.href,this.target); return false;\" >"
+               . price_format($credit)
+               ."</a>", $parms);
+}
+
+function supplier_credit_row($supplier, $credit, $parms='')
+{
+       global $path_to_root;
+       
+       label_row( _("Current Credit:"),
+               "<a target='_blank' " . ($credit<0 ? 'class="redfg"' : '')
+               ."href='$path_to_root/purchasing/inquiry/supplier_inquiry.php?supplier_id=".$supplier."'"
+               ." onclick=\"javascript:openWindow(this.href,this.target); return false;\" >"
+               . price_format($credit)
+               ."</a>", $parms);
+}
+
+/*
+       Edit transaction link to be used in transaction inquires
+*/
+function edit_trans_link($trans_type, $trans_no, $url='')
+{
+       global $path_to_root, $trans_editors;
+
+       if (!$url) $url = @$trans_editors[$trans_type];
+
+       if (!$trans_no || !$url)
+               return '';
+
+       if (is_closed_trans($trans_type, $trans_no)) {
+               return set_icon(ICON_CLOSED, _('Closed'));
+       } else {
+               $link_text = user_graphic_links() ? set_icon(ICON_EDIT, _('Edit')) : _('Edit');
+               return "<a href='".$path_to_root . sprintf($url, $trans_no, $trans_type)."'>$link_text</a>";
+       }
+}
+
+function bank_balance_row($bank_acc, $parms='')
+{
+       global $path_to_root;
+
+       $to = add_days(Today(), 1);
+       $bal = get_balance_before_for_bank_account($bank_acc, $to);
+       label_row( _("Bank Balance:"),
+               "<a target='_blank' " . ($bal<0 ? 'class="redfg"' : '')
+               ."href='$path_to_root/gl/inquiry/bank_inquiry.php?bank_account=".$bank_acc."'"
+               ." onclick=\"javascript:openWindow(this.href,this.target); return false;\" >&nbsp;"
+               . price_format($bal)
+               ."</a>", $parms);
+}
+
 ?>
\ No newline at end of file