function obtainResultOperationRate($smarty, $module_name, $local_templates_dir, &$pDB, &$pDB2, &$pDB3, $arrConf, $arrLang)
{
    $_DATA = $_POST;
    $pBillingRates = new paloSantoBillingRates($pDB);
    //obtain parameters from new rates
    $prefix_new = getParameter("Prefix");
    $name_new = getParameter("Name");
    $rate_new = getParameter("Rate");
    $rate_offset_new = getParameter("Rate_offset");
    $trunk_new = getParameter("Trunk");
    $hidden_digits = getParameter("Hidden_Digits");
    $id = getParameter("id");
    $edit = getParameter("namerate");
    $varUpdate = getParameter("checkUpdate");
    //exists Default rate in rate.db
    $pBillingRates->existsDefaultRate($pDB3);
    $action = getAction();
    //into to create new rate
    if ($action == "save_new") {
        $arrTrunks = $pBillingRates->getTrunks($pDB2);
        $arrFormNew = createFormNew($arrLang, $arrTrunks);
        $oForm = new paloForm($smarty, $arrFormNew);
        if (!$oForm->validateForm($_POST)) {
            $strErrorMsg = "<b>" . _tr('The following fields contain errors') . ":</b><br/>";
            $arrErrores = $oForm->arrErroresValidacion;
            if (is_array($arrErrores) && count($arrErrores) > 0) {
                foreach ($arrErrores as $k => $v) {
                    $strErrorMsg .= "{$k}: [{$v['mensaje']}] <br /> ";
                }
            }
            $smarty->assign("mb_message", $strErrorMsg);
            $content = reportBillingNewRate($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
            return $content;
        } else {
            $result = create_rate($pBillingRates, $prefix_new, $name_new, $rate_new, $rate_offset_new, $trunk_new, $hidden_digits);
            if ($result == "name") {
                $smarty->assign("mb_message", $arrLang["error_name"]);
                $content = reportBillingNewRate($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
                return $content;
            }
            if ($result == "successful") {
                $smarty->assign("mb_message", $arrLang["create_new_rate"]);
                $content = reportBillingRates($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
                return $content;
            }
            if ($result == "prefix") {
                $smarty->assign("mb_message", $arrLang["error_prefix"]);
                $content = reportBillingNewRate($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
                return $content;
            }
            if ($result == "error") {
                $smarty->assign("mb_message", $arrLang["error"]);
                $content = reportBillingNewRate($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
                return $content;
            }
        }
    }
    //into to delete rate
    if ($action == "delete") {
        $result = $pBillingRates->deleteRate($id);
        if ($result == true) {
            $smarty->assign("mb_message", $arrLang["deleted"]);
            $content = reportBillingRates($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
            return $content;
        } else {
            $smarty->assign("mb_message", $arrLang["deleted_error"]);
            $content = reportBillingViewRate($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
            return $content;
        }
    }
    if ($action == "save_edit") {
        $arrTrunks = $pBillingRates->getTrunks($pDB2);
        $arrFormEdit = createEditForm($arrLang, $arrTrunks);
        $oForm = new paloForm($smarty, $arrFormEdit);
        if ($edit == 'Default') {
            $trunk_new = isset($trunk_new) ? $trunk_new : "";
            $prefix_new = isset($prefix_new) ? $prefix_new : "";
            $name_new = isset($name_new) ? $name_new : "Default";
        }
        if (!$oForm->validateForm($_POST)) {
            $strErrorMsg = "<b>" . _tr('The following fields contain errors') . ":</b><br/>";
            $arrErrores = $oForm->arrErroresValidacion;
            if (is_array($arrErrores) && count($arrErrores) > 0) {
                foreach ($arrErrores as $k => $v) {
                    $strErrorMsg .= "{$k}: [{$v['mensaje']}] <br /> ";
                }
            }
            //into to edit rate but the field are empty
            $smarty->assign("mb_message", $strErrorMsg);
            $content = reportBillingEditRate($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
            return $content;
        } else {
            if ($varUpdate == "on") {
                $rateOLD = $pBillingRates->getBillingRatesById($id);
                $prefix_new = $rateOLD['prefix'];
                $pDB->beginTransaction();
                $result = update_Last_rates($pBillingRates, $prefix_new, $name_new, $rate_new, $rate_offset_new, $trunk_new, $hidden_digits);
                // crea el rate nuevo
                if ($result == "successful") {
                    $id_new = $pDB->getLastInsertId();
                    $result = $pBillingRates->updateIdParent($id, $id_new);
                    // actualizamos los hijos anteriores al rate
                    if ($result) {
                        $result = $pBillingRates->deleteRate($id);
                        // cerrando el anterior rate valido
                        if ($name_new == "Default") {
                            $result = $pBillingRates->updateSettingRate($rate_new, $rate_offset_new, $pDB3);
                            if ($result) {
                                $pDB->commit();
                                $smarty->assign("mb_message", $arrLang["edit_rate"]);
                                $content = reportBillingRates($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
                                return $content;
                            } else {
                                $pDB->rollBack();
                                $smarty->assign("mb_message", $arrLang["errorUpdateParent"]);
                                $content = reportBillingEditRate($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
                                return $content;
                            }
                        } else {
                            $pDB->commit();
                            $smarty->assign("mb_message", $arrLang["edit_rate"]);
                            $content = reportBillingRates($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
                            return $content;
                        }
                    }
                    $pDB->rollBack();
                    $smarty->assign("mb_message", $arrLang["errorUpdateParent"]);
                    $content = reportBillingEditRate($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
                    return $content;
                }
                if ($result == "error") {
                    $smarty->assign("mb_message", $arrLang["error"]);
                    $pDB->rollBack();
                    $content = reportBillingEditRate($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
                    return $content;
                }
            } else {
                $pDB->beginTransaction();
                $result = edit_rate($pBillingRates, $id, $name_new, $rate_new, $rate_offset_new, $trunk_new, $hidden_digits);
                if ($result == "prefix") {
                    $smarty->assign("mb_message", $arrLang["error_prefix"]);
                    $pDB->rollBack();
                    $content = reportBillingEditRate($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
                    return $content;
                }
                if ($result == "name") {
                    $smarty->assign("mb_message", $arrLang["error_name"]);
                    $pDB->rollBack();
                    $content = reportBillingEditRate($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
                    return $content;
                }
                if ($result == "successful") {
                    if ($name_new == "Default") {
                        $result = $pBillingRates->updateSettingRate($rate_new, $rate_offset_new, $pDB3);
                        if ($result) {
                            $pDB->commit();
                            $smarty->assign("mb_message", $arrLang["edit_rate"]);
                            $content = reportBillingRates($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
                            return $content;
                        } else {
                            $pDB->rollBack();
                            $smarty->assign("mb_message", $arrLang["errorUpdateParent"]);
                            $content = reportBillingEditRate($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
                            return $content;
                        }
                    } else {
                        $pDB->commit();
                        $smarty->assign("mb_message", $arrLang["edit_rate"]);
                        $content = reportBillingRates($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
                        return $content;
                    }
                }
                if ($result == "error") {
                    $smarty->assign("mb_message", $arrLang["error"]);
                    $pDB->rollBack();
                    $content = reportBillingEditRate($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
                    return $content;
                }
            }
        }
    }
    if ($action == "save_import") {
        $arrErrorMsg = "";
        if (!preg_match('/.*\\.csv$/', $_FILES['importcsv']['name'])) {
            $smarty->assign("mb_message", $arrLang["Invalid_file_extension"]);
            $content = reportBillingImportRate($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
            return $content;
        } else {
            if (is_uploaded_file($_FILES['importcsv']['tmp_name'])) {
                $arrTrunks = $pBillingRates->getTrunks($pDB2);
                //obtain the trunks for billing
                $arrForm = createFormNew($arrLang, $arrTrunks);
                $oForm = new paloForm($smarty, $arrForm);
                //$count=0;
                $row = 1;
                if ($handle = fopen($_FILES['importcsv']['tmp_name'], "r")) {
                    $rate_val = fgetcsv($handle, 4096);
                    //Linea 1 header ignorada
                    //Desde linea 2 son datos
                    $pDB->beginTransaction();
                    while (($rate_val = fgetcsv($handle, 4096)) !== FALSE) {
                        $record = array('Prefix' => trim($rate_val[0]), 'Name' => trim($rate_val[1]), 'Rate' => trim($rate_val[2]), 'Rate_offset' => trim($rate_val[3] == 0 ? '0.0' : $rate_val[3]), 'Hidden_Digits' => trim($rate_val[4]), 'Trunk' => trim($rate_val[5]));
                        if ($oForm->validateForm($record)) {
                            $dig = $rate_val[4];
                            if ($rate_val[4] == "") {
                                $dig = 0;
                            }
                            $result = create_rate($pBillingRates, trim($rate_val[0]), trim($rate_val[1]), trim($rate_val[2]), trim($rate_val[3]), trim($rate_val[5]), $dig);
                            if ($result == "name") {
                                $pDB->rollBack();
                                $smarty->assign("mb_message", _tr("Error rate name already exists in database or is duplicated in csv file"));
                                $content = reportBillingImportRate($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
                                return $content;
                            }
                            if ($result == "prefix") {
                                $pDB->rollBack();
                                $smarty->assign("mb_message", _tr("The prefix already exists with the same Trunk in database or is duplicated in csv file"));
                                $content = reportBillingImportRate($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
                                return $content;
                            }
                            if ($result == "error") {
                                $pDB->rollBack();
                                $smarty->assign("mb_message", $arrLang["error_CVS"]);
                                $content = reportBillingImportRate($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
                                return $content;
                            }
                        } else {
                            $arrErrorMsg[$arrLang["Validation Error"]][$count] = $oForm->arrErroresValidacion;
                        }
                    }
                    fclose($handle);
                }
                if ($arrErrorMsg != "") {
                    $pDB->rollBack();
                    foreach ($arrErrorMsg as $Error_type => $on_line) {
                        $strErrorMsg .= "<B><font color=\"red\">" . $Error_type . ":</font></B><BR>";
                        foreach ($on_line as $line => $error_msg) {
                            if (is_array($error_msg)) {
                                foreach ($error_msg as $k => $msg) {
                                    if (!is_array($msg)) {
                                        $error_msg = $msg;
                                    } else {
                                        foreach ($msg as $v) {
                                            $error_msg = $k . " has " . $v;
                                        }
                                    }
                                }
                            }
                            $strErrorMsg .= $arrLang["Error on line"] . ": " . $line . "  " . $error_msg . "<br>";
                        }
                        $strErrorMsg .= '<BR>';
                    }
                    if ($strErrorMsg != "") {
                        $smarty->assign("mb_message", $strErrorMsg);
                        $content = reportBillingImportRate($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
                        return $content;
                    }
                } else {
                    $pDB->commit();
                    $smarty->assign("mb_message", _tr("File was imported successful"));
                    $content = reportBillingRates($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
                    return $content;
                }
            } else {
                $smarty->assign("mb_message", $arrLang["File_error"]);
                $content = reportBillingImportRate($smarty, $module_name, $local_templates_dir, $pDB, $pDB2, $pDB3, $arrConf, $arrLang);
                return $content;
            }
        }
    }
}
<?php

/**
 * functions call to grab a fire fighter to edit
 * Requires the functions.php script as well as 
 * header.php and footer.php. Directs the user to 
 * the edit form when the edit button is clicked and the
 * display fire fighter table if all information is 
 * updated as desired.
 *
 *@author Alphabit Soup
 */
require 'functions.php';
require 'header.php';
//gets the fire fighter's id number from URL
$id = $_GET['id'];
//echo $id;
if ($_GET['action'] == "submit") {
    updateFirefighter($id);
    header('Location: ./displayFirefighter.php');
} else {
    $_POST = getFirefighter($id);
    //var_dump($_POST);
    echo createEditForm();
}
require 'footer.php';