Fixed an array_combine object issue.
[fa-stable.git] / includes / ui / ui_lists.inc
index df6e4b17796f06cdf8ad66816a83e792868984bb..cd3be97c047a562b874810984867b9a61bf2b0d0 100644 (file)
@@ -214,11 +214,15 @@ $opts = array(            // default options
                        }
                        $cat = $contact_row[$opts['category']];
                        if ($opts['category'] !== false && $cat != $lastcat){
+                               if ($lastcat!==null)
+                                       $selector .= "</optgroup>";
                                $selector .= "<optgroup label='".$cat."'>\n";
                                $lastcat = $cat;
                        }
                        $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
                }
+               if ($lastcat!==null)
+                       $selector .= "</optgroup>";
                db_free_result($result);
        }
 
@@ -368,7 +372,6 @@ $opts = array(              // default options
 
        if ($first_id!==false) {
                $sel = ($found===$first_id) || ($found===false && ($spec_option===false)) ? "selected='selected'" : '';
-               $selector = sprintf($first_opt, $sel).$selector;
        }
        // Prepend special option.
        if ($spec_option !== false) { // if special option used - add it
@@ -417,26 +420,19 @@ function _format_add_curr($row)
                '' : ("&nbsp;-&nbsp;" . $row[2]));
 }
 
-function add_edit_combo($combo_name,$url,$key_param='',$restrict_pages='')
+function add_edit_combo($type)
 {
-       global $path_to_root, $page_security;
+       global $path_to_root, $popup_editors, $use_icon_for_editkey;
 
+       if (!isset($use_icon_for_editkey) || $use_icon_for_editkey==0)
+               return "";
        // Derive theme path
        $theme_path = $path_to_root . '/themes/' . user_theme();
 
-       // Check if $url already has other parameters
-       if ($key_param) {
-               $key_param = ((strpos($url,'?')) ? '&' : '?') . $key_param;
-       }
-
-       $return_url = ($key_param) ?  "<a target = '_blank' href='$url${key_param}=' onclick=\"javascript:var combo_id=document.forms[0].$combo_name;openWindow(this.href+combo_id.options[combo_id.selectedIndex].value,this.target); return false;\" tabindex='-1'><img width='16' height='16' border='0' alt='Add/Edit' title='Add/Edit' src='$theme_path/images/".ICON_EDIT."'></a>" : "<a target = '_blank' href='$url${key_param}' onclick=\"javascript:openWindow(this.href,this.target); return false;\" tabindex='-1'><img width='16' height='16' border='0' alt='Add/Edit' title='Add/Edit' src='$theme_path/images/".ICON_EDIT."'></a>";
-
-       // Don't pass edit button code If restrict_pages contains instructions but fails security check
-       if ($restrict_pages && strpos($restrict_pages, $page_security) === false) {
-               return '';
-       }
-
-       return $return_url;
+       $key = $popup_editors[$type][1];
+       $onclick = "onclick=\"javascript:callEditor($key); return false;\"";
+       $img = "<img width='12' height='12' border='0' alt='Add/Edit' title='Add/Edit' src='$theme_path/images/".ICON_EDIT."'>";
+       return "<a target = '_blank' href='#' $onclick tabindex='-1'>$img</a>"; 
 }
 
 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
@@ -457,6 +453,7 @@ function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_
            'order' => array('supp_ref'),
                'search_box' => $mode!=0,
                'type' => 1,
+        'search' => array("supp_ref","supp_name","gst_no"),        
                'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
                'spec_id' => $all_items,
                'select_submit'=> $submit_on_change,
@@ -466,10 +463,7 @@ function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_
                'show_inactive'=>$all
                ));
        if ($editkey)
-       {
-               global $path_to_root;
-               $ret .= add_edit_combo('supplier_id',"$path_to_root/purchasing/manage/suppliers.php?popup=1",'supplier_id');            
-       }
+               $ret .= add_edit_combo('supplier');             
        return $ret;
 }
 
@@ -512,6 +506,7 @@ function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_
                'search_box' => $mode!=0,
                'type' => 1,
                'size' => 20,
+        'search' => array("debtor_ref","name","tax_id"),        
                'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
                'spec_id' => $all_items,
                'select_submit'=> $submit_on_change,
@@ -521,10 +516,7 @@ function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_
                'show_inactive' => $show_inactive
        ) );
        if ($editkey)
-       {
-               global $path_to_root;
-               $ret .= add_edit_combo('customer_id',"$path_to_root/sales/manage/customers.php?popup=1", "debtor_no");
-       }       
+               $ret .= add_edit_combo('customer');
        return $ret;
 }
 
@@ -575,8 +567,7 @@ function customer_branches_list($customer_id, $name, $selected_id=null,
        ) );
        if ($editkey)
        {
-               global $path_to_root;
-               $ret .= add_edit_combo('branch_id',"$path_to_root/sales/manage/customer_branches.php?popup=1",'SelectedBranch');
+               $ret .= add_edit_combo('branch');
        }       
        return $ret;
 }
@@ -687,7 +678,7 @@ return combo_input($name, $selected_id, $sql, 'id', '',
 function _format_fiscalyears($row)
 {
        return sql2date($row[1]) . "&nbsp;-&nbsp;" . sql2date($row[2])
-       . "&nbsp;&nbsp;" . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
+       . "&nbsp;&nbsp;" . ($row[3] ? _('Closed') : _('Active'));
 }
 
 function fiscalyears_list_cells($label, $name, $selected_id=null)
@@ -723,7 +714,7 @@ $options = array(
        if (!$showclosed)
                $options['where'][] = "closed=0";
        if($showtype)
-               $options['where'][] = "type_=$showtype";
+               $options['where'][] = "type_=".db_escape($showtype);
 
        return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
 }
@@ -775,10 +766,7 @@ function stock_items_list($name, $selected_id=null, $all_option=false,
                'order' => array('c.description','stock_id')
          ), $opts) );
        if ($editkey)
-       {
-               global $path_to_root;
-               $ret .= add_edit_combo('stock_id',"$path_to_root/inventory/manage/items.php?popup=1",'stock_id');               
-       }
+               $ret .= add_edit_combo('item');         
        return $ret;
          
 }
@@ -850,8 +838,11 @@ function sales_items_list($name, $selected_id=null, $all_option=false,
          ), $opts) );
 }
 
-function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
+function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $editkey=false)
 {
+       if ($editkey)
+               set_editor('item', $name, $editkey);
+
        if ($label != null)
                echo "<td>$label</td>\n";
        echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
@@ -906,7 +897,7 @@ function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
        $all_option=false, $submit_on_change=false, $editkey = false)
 {
        return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
-               array('where'=>array("stock_id != '$parent_stock_id'")), $editkey);
+               array('where'=>array("stock_id != ".db_escape($parent_stock_id))), $editkey);
 }
 
 function stock_component_items_list_cells($label, $name, $parent_stock_id, 
@@ -915,7 +906,7 @@ function stock_component_items_list_cells($label, $name, $parent_stock_id,
        if ($label != null)
                echo "<td>$label</td>\n";
        echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
-               array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true),
+               array('where'=>array("stock_id != ".db_escape($parent_stock_id)), 'cells'=>true),
                $editkey);
 }
 //------------------------------------------------------------------------------------
@@ -1426,7 +1417,7 @@ function workcenter_list_row($label, $name, $selected_id=null, $all_option=false
 
 //-----------------------------------------------------------------------------------------------
 
-function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
+function bank_accounts_list($name, $selected_id=null, $submit_on_change=false, $spec_option=false)
 {
        $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
                FROM ".TB_PREF."bank_accounts";
@@ -1435,6 +1426,8 @@ function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
        array(
                'format' => '_format_add_curr',
                'select_submit'=> $submit_on_change,
+               'spec_option' => $spec_option,
+               'spec_id' => '',
                'async' => false
        ) );
 }
@@ -1927,8 +1920,7 @@ function journal_types_list_cells($label, $name, $value=null, $submit_on_change=
        $items = $systypes_array;
 
        // exclude quotes, orders and dimensions
-       foreach (array(ST_PURCHORDER, ST_WORKORDER, ST_SALESORDER, ST_DIMENSION, 
-                               ST_SALESQUOTE) as $excl)
+       foreach (array(ST_PURCHORDER, ST_SALESORDER, ST_DIMENSION, ST_SALESQUOTE, ST_LOCTRANSFER) as $excl)
                        unset($items[$excl]);
        
        echo array_selector($name, $value, $items, 
@@ -2217,7 +2209,7 @@ function security_roles_list_row($label, $name, $selected_id=null, $new_item=fal
        echo "</tr>\n";
 }
 
-function tab_list_row($label, $name, $selected_id=null, $all = false)
+function tab_list_row($label, $name, $selected_id=null)
 {
        global $installed_extensions;
        
@@ -2225,12 +2217,6 @@ function tab_list_row($label, $name, $selected_id=null, $all = false)
        foreach ($_SESSION['App']->applications as $app) {
                $tabs[$app->id] = access_string($app->name, true);
        }
-       if ($all) {     // add also not active ext. modules
-               foreach ($installed_extensions as $ext) {
-                       if ($ext['type'] == 'module' && !$ext['active'])
-                               $tabs[$ext['tab']] = access_string($ext['title'], true);
-               }
-       }
        echo "<tr>\n";
        echo "<td class='label'>$label</td><td>\n";
        echo array_selector($name, $selected_id, $tabs);
@@ -2381,7 +2367,7 @@ function payment_services($name)
 {
        global $payment_services;
 
-       $services = array_combine(array_keys($payment_services), array_keys($payment_services));
+       $services = (object)array_combine(array_keys($payment_services), array_keys($payment_services));
 
        return array_selector($name, null, $services, array(
                        'spec_option'=> _("No payment Link"),