function _action()
{
    global $user, $db, $conf, $langs;
    $PDOdb = new TPDOdb();
    //$PDOdb->debug=true;
    /*******************************************************************
     * ACTIONS
     *
     * Put here all code to do according to value of "action" parameter
     ********************************************************************/
    $action = __get('action', 'view');
    switch ($action) {
        case 'new':
        case 'add':
            $assetOf = new TAssetOF();
            $assetOf->set_values($_REQUEST);
            $fk_product = __get('fk_product', 0, 'int');
            $fk_nomenclature = __get('fk_nomenclature', 0, 'int');
            _fiche($PDOdb, $assetOf, 'edit', $fk_product, $fk_nomenclature);
            break;
        case 'edit':
            $assetOf = new TAssetOF();
            $assetOf->load($PDOdb, $_REQUEST['id']);
            _fiche($PDOdb, $assetOf, 'edit');
            break;
        case 'create':
        case 'save':
            $assetOf = new TAssetOF();
            if (!empty($_REQUEST['id'])) {
                $assetOf->load($PDOdb, $_REQUEST['id'], false);
                $mode = 'view';
            } else {
                $mode = $action == 'create' ? 'view' : 'edit';
            }
            $assetOf->set_values($_REQUEST);
            $fk_product = __get('fk_product_to_add', 0);
            $quantity_to_create = __get('quantity_to_create', 1);
            $fk_nomenclature = __get('fk_nomenclature', 0);
            if ($fk_product > 0) {
                $assetOf->addLine($PDOdb, $fk_product, 'TO_MAKE', $quantity_to_create, 0, '', $fk_nomenclature);
            }
            if (!empty($_REQUEST['TAssetOFLine'])) {
                foreach ($_REQUEST['TAssetOFLine'] as $k => $row) {
                    if (!isset($assetOf->TAssetOFLine[$k])) {
                        $assetOf->TAssetOFLine[$k] = new TAssetOFLine();
                    }
                    if (!empty($conf->global->ASSET_DEFINED_WORKSTATION_BY_NEEDED)) {
                        $assetOf->TAssetOFLine[$k]->set_workstations($PDOdb, $row['fk_workstation']);
                        unset($row['fk_workstation']);
                    }
                    $assetOf->TAssetOFLine[$k]->set_values($row);
                }
                foreach ($assetOf->TAssetOFLine as &$line) {
                    $line->TAssetOFLine = array();
                }
            }
            if (!empty($_REQUEST['TAssetWorkstationOF'])) {
                foreach ($_REQUEST['TAssetWorkstationOF'] as $k => $row) {
                    //Association des utilisateurs à un poste de travail
                    if (!empty($conf->global->ASSET_DEFINED_USER_BY_WORKSTATION)) {
                        $assetOf->TAssetWorkstationOF[$k]->set_users($PDOdb, $row['fk_user']);
                        unset($row['fk_user']);
                    }
                    //Association des opérations à une poste de travail (mode opératoire)
                    if (!empty($conf->global->ASSET_DEFINED_OPERATION_BY_WORKSTATION)) {
                        $assetOf->TAssetWorkstationOF[$k]->set_tasks($PDOdb, $row['fk_task']);
                        unset($row['fk_task']);
                    }
                    $assetOf->TAssetWorkstationOF[$k]->set_values($row);
                }
            }
            $assetOf->entity = $conf->entity;
            //Permet de mettre à jour le lot de l'OF parent
            if (!empty($assetOf->fk_assetOf_parent)) {
                $assetOf->update_parent = true;
            }
            $assetOf->save($PDOdb);
            _fiche($PDOdb, $assetOf, $mode);
            break;
        case 'valider':
            $error = 0;
            $assetOf = new TAssetOF();
            $id = GETPOST('id');
            if (empty($id)) {
                exit('Where is Waldo ?');
            }
            $assetOf->load($PDOdb, $id);
            //Si use_lot alors check de la saisie du lot pour chaque ligne avant validation
            if (!empty($conf->global->USE_LOT_IN_OF) && !empty($conf->global->OF_LOT_MANDATORY)) {
                if (!$assetOf->checkLotIsFill()) {
                    _fiche($PDOdb, $assetOf, 'view');
                    break;
                }
            }
            $res = $assetOf->validate($PDOdb);
            if ($res > 0) {
                //Relaod de l'objet OF parce que createOfAndCommandesFourn() fait tellement de truc que c'est le bordel
                $assetOf = new TAssetOF();
                if (!empty($_REQUEST['id'])) {
                    $assetOf->load($PDOdb, $_REQUEST['id'], false);
                }
            }
            _fiche($PDOdb, $assetOf, 'view');
            break;
        case 'lancer':
            $assetOf = new TAssetOF();
            $id = GETPOST('id');
            if (empty($id)) {
                exit('Where is Waldo ?');
            }
            $assetOf->load($PDOdb, $id);
            $assetOf->openOF($PDOdb);
            $assetOf->load($PDOdb, $id);
            _fiche($PDOdb, $assetOf, 'view');
            break;
        case 'terminer':
            $assetOf = new TAssetOF();
            $assetOf->load($PDOdb, $_REQUEST['id']);
            $assetOf->closeOF($PDOdb);
            $assetOf->load($PDOdb, $_REQUEST['id']);
            _fiche($PDOdb, $assetOf, 'view');
            break;
        case 'delete':
            $assetOf = new TAssetOF();
            $assetOf->load($PDOdb, $_REQUEST['id']);
            //$PDOdb->db->debug=true;
            $assetOf->delete($PDOdb);
            header('Location: ' . dol_buildpath('/of/liste_of.php?delete_ok=1', 1));
            exit;
            break;
        case 'view':
            $assetOf = new TAssetOF();
            $assetOf->load($PDOdb, $_REQUEST['id']);
            _fiche($PDOdb, $assetOf, 'view');
            break;
        case 'createDocOF':
            $id_of = $_REQUEST['id'];
            $assetOf = new TAssetOF();
            $assetOf->load($PDOdb, $id_of, false);
            $TOFToGenerate = array($assetOf->rowid);
            if ($conf->global->ASSET_CONCAT_PDF) {
                $assetOf->getListeOFEnfants($PDOdb, $TOFToGenerate, $assetOf->rowid);
            }
            //			var_dump($TOFToGenerate);exit;
            foreach ($TOFToGenerate as $id_of) {
                $assetOf = new TAssetOF();
                $assetOf->load($PDOdb, $id_of, false);
                //echo $id_of;
                $TRes[] = generateODTOF($PDOdb, $assetOf);
                //echo '...ok<br />';
            }
            $TFilePath = get_tab_file_path($TRes);
            //	var_dump($TFilePath);exit;
            if ($conf->global->ASSET_CONCAT_PDF) {
                ob_start();
                $pdf = pdf_getInstance();
                if (class_exists('TCPDF')) {
                    $pdf->setPrintHeader(false);
                    $pdf->setPrintFooter(false);
                }
                $pdf->SetFont(pdf_getPDFFont($langs));
                if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) {
                    $pdf->SetCompression(false);
                }
                //$pdf->SetCompression(false);
                $pagecount = concatPDFOF($pdf, $TFilePath);
                if ($pagecount) {
                    $pdf->Output($TFilePath[0], 'F');
                    if (!empty($conf->global->MAIN_UMASK)) {
                        @chmod($file, octdec($conf->global->MAIN_UMASK));
                    }
                }
                ob_clean();
            }
            header("Location: " . DOL_URL_ROOT . "/document.php?modulepart=of&entity=1&file=" . $TRes[0]['dir_name'] . "/" . $TRes[0]['num_of'] . ".pdf");
            break;
        case 'control':
            $assetOf = new TAssetOF();
            $assetOf->load($PDOdb, $_REQUEST['id']);
            $subAction = __get('subAction', false);
            if ($subAction) {
                $assetOf->updateControl($PDOdb, $subAction);
            }
            _fiche_control($PDOdb, $assetOf);
            break;
        case 'addAssetLink':
            $assetOf = new TAssetOF();
            $assetOf->load($PDOdb, __get('id', 0, 'int'));
            $idLine = __get('idLine', 0, 'int');
            $idAsset = __get('idAsset', 0, 'int');
            if ($idLine && $idAsset) {
                $find = false;
                foreach ($assetOf->TAssetOFLine as $TAssetOFLine) {
                    if ($TAssetOFLine->getId() == $idLine) {
                        $find = true;
                        $asset = new TAsset();
                        $asset->load($PDOdb, $idAsset);
                        $TAssetOFLine->addAssetLink($asset);
                        break;
                    }
                }
                if (!$find) {
                    setEventMessage('Erreur sur l\'identifiant de l\'équipement', 'errors');
                }
            } else {
                setEventMessage('Erreur sur la saisie de l\'équipement.', 'errors');
            }
            _fiche($PDOdb, $assetOf, 'edit');
            break;
        case 'deleteAssetLink':
            $assetOf = new TAssetOF();
            $assetOf->load($PDOdb, __get('id', 0, 'int'));
            $idLine = __get('idLine', 0, 'int');
            $idAsset = __get('idAsset', 0, 'int');
            if ($idLine && $idAsset) {
                TAsset::del_element_element($PDOdb, $idLine, $idAsset, 'TAsset');
            } else {
                setEventMessage('Erreur sur un des identifiants', 'errors');
            }
            _fiche($PDOdb, $assetOf, 'edit');
            break;
        default:
            $assetOf = new TAssetOF();
            $assetOf->load($PDOdb, $_REQUEST['id'], false);
            _fiche($PDOdb, $assetOf, 'view');
            break;
    }
}