<?php



function ticket_status_list($name, $selected_id=null,  $submit_on_change=false, $all_option=false){
    $status = array(1 => _("Opened"), 2 => _("Closed"), 3 => _("Replied") );

    return array_selector($name, $selected_id, $status, 
        array( 
            'select_submit'=> $submit_on_change,
            'async' => false,
            'spec_option'=> ($all_option == true ? _("All") : false ),
            'disabled' => false ) ); // FIX?
}

function ticket_status_list_cells($label, $name, $selected_id=null,  $submit_on_change=false, $all_option=false){
    if ($label != null)
        echo "<td>$label</td>\n";
    echo "<td>";
    echo ticket_status_list($name, $selected_id, $submit_on_change, $all_option);
    echo "</td>\n";
}

function user_types($name, $selected_id=null,  $submit_on_change=false, $all_option=false){
    $status = array(ST_CUSTOMER => _("Customer"), ST_SUPPLIER => _("Supplier") );

    return array_selector($name, $selected_id, $status, 
        array( 
            'select_submit'=> $submit_on_change,
            'async' => false,
            'spec_option'=> ($all_option ? $all_option : false ),
            'disabled' => false ) ); // FIX?
}

function user_types_cells($label, $name, $selected_id=null,  $submit_on_change=false, $all_option=false){
    if ($label != null)
        echo "<td>$label</td>\n";
    echo "<td>";
    echo user_types($name, $selected_id, $submit_on_change, $all_option);
    echo "</td>\n";
}



function customer_ticket_types($name, $selected_id=null,  $submit_on_change=false, $all_option=false){
    global $systypes_array;
    $status = array(ST_SALESINVOICE => $systypes_array[ST_SALESINVOICE],ST_CUSTCREDIT => $systypes_array[ST_CUSTCREDIT],ST_CUSTDELIVERY => $systypes_array[ST_CUSTDELIVERY],ST_SALESORDER => $systypes_array[ST_SALESORDER],ST_CUSTPAYMENT => $systypes_array[ST_CUSTPAYMENT]);

    return array_selector($name, $selected_id, $status, 
        array( 
            'select_submit'=> $submit_on_change,
            'async' => false,
            'spec_option'=> ($all_option == true ? _($all_option) : false ),
            'disabled' => false ) ); // FIX?
}

function customer_ticket_types_cells($label, $name, $selected_id=null,  $submit_on_change=false, $all_option=false){
    if ($label != null)
        echo "<td>$label</td>\n";
    echo "<td>";
    echo customer_ticket_types($name, $selected_id, $submit_on_change, $all_option);
    echo "</td>\n";
}

function supplier_ticket_types($name, $selected_id=null,  $submit_on_change=false, $all_option=false){
    global $systypes_array;

    $status = array(ST_PURCHORDER => $systypes_array[ST_PURCHORDER],ST_SUPPINVOICE => $systypes_array[ST_SUPPINVOICE],ST_SUPPCREDIT => $systypes_array[ST_SUPPCREDIT],ST_SUPPAYMENT => $systypes_array[ST_SUPPAYMENT],ST_SUPPRECEIVE => $systypes_array[ST_SUPPRECEIVE]);

    return array_selector($name, $selected_id, $status, 
        array( 
            'select_submit'=> $submit_on_change,
            'async' => false,
            'spec_option'=> ($all_option == true ? _($all_option) : false ),
            'disabled' => false ) ); // FIX?
}

function supplier_ticket_types_cells($label, $name, $selected_id=null,  $submit_on_change=false, $all_option=false){
    if ($label != null)
        echo "<td>$label</td>\n";
    echo "<td>";
    echo supplier_ticket_types($name, $selected_id, $submit_on_change, $all_option);
    echo "</td>\n";
}


function sales_invoice_list($name, $selected_id=null,  $submit_on_change=false, $all_option=false,$sql=''){

    // display_error($selected_id);
    return combo_input($name, $selected_id, $sql, 'trans_no', 'reference',
        array(
            'spec_option' => $all_option ? _($all_option) : false,
            'select_submit'=> $submit_on_change,
            'async' => false,
        ) );

    // return array_selector($name, $selected_id, $sql,'reference','reference', 
    //     array( 
    //         'select_submit'=> $submit_on_change,
    //         'async' => false,
    //         'spec_option'=> ($all_option == true ? _($all_option) : false ),
    //         'disabled' => false ) ); // FIX?
}

function sales_invoice_list_cells($label, $name, $selected_id=null,  $submit_on_change=false, $all_option=false,$sql=''){
    if ($label != null)
        echo "<td>$label</td>\n";
    echo "<td>";
    echo sales_invoice_list($name, $selected_id, $submit_on_change, $all_option,$sql);
    echo "</td>\n";
}


function crm_deparments_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,  $show_inactive = false, $multiple=false){

   $departments_list = GetSingleValue('kv_crm_option', 'option_value', ['option_name' => 'departments_list']);

   $sql = "SELECT id, role FROM ".TB_PREF."security_roles WHERE id IN (".implode($departments_list, ',').") ";
    return combo_input($name, $selected_id, $sql, 'id', 'description',
        array(
            'spec_option'=>$new_item ? _("New role") : false,
            'spec_id' => '',
            'select_submit'=> $submit_on_change,
            'multi'=> $multiple,
            'show_inactive' => $show_inactive
        ) );
}


function crm_deparments_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,$show_inactive = false)
{
    if ($label != null)
        echo "<td>$label</td>\n";
    echo "<td>";
    echo crm_deparments_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
    echo "</td>\n";
}

function crm_deparments_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,$show_inactive = false)
{
    echo "<tr><td class='label'>$label</td>";
    crm_deparments_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
    echo "</tr>\n";
}




?>