$langs->load("categories");
$action = GETPOST('action');
$id = (int) GETPOST('id');
$commid = (int) GETPOST('commid');
$PDOdb = new TPDOdb();
switch ($action) {
    case 'add':
        TCommercialCategory::add($PDOdb, $id, $commid);
        _fiche($PDOdb, $id);
        break;
    case 'delete':
        TCommercialCategory::del($PDOdb, $id, $commid);
        _fiche($PDOdb, $id);
        break;
    default:
        _fiche($PDOdb, $id);
        break;
}
function _fiche(&$PDOdb, $id)
{
    global $conf, $db, $langs, $user, $form;
    $object = new Categorie($db);
    $result = $object->fetch($id);
    $object->fetch_optionals($id, $extralabels);
    if ($result <= 0) {
        dol_print_error($db, $object->error);
        exit;
    }
    llxHeader("", "", $langs->trans("Categories"));
    $title = $langs->trans("CustomersCategoryShort");
    $head = categories_prepare_head($object, Categorie::TYPE_CUSTOMER);
                $k = $dispatch->addChild($PDOdb, 'TDispatchAsset');
                $dispatch->TDispatchAsset[$k]->fk_asset = $asset->getId();
                $dispatch->TDispatchAsset[$k]->fk_object = $TLine[-1]['fk_object'];
                $dispatch->TDispatchAsset[$k]->object_type = $type_object;
                $dispatch->TDispatchAsset[$k]->asset = $asset;
                $dispatch->save($PDOdb);
            }
        }
        break;
    case 'delete-line':
        $k = (int) GETPOST('k');
        $dispatch->TDispatchAsset[$k]->to_delete = true;
        $dispatch->save($PDOdb);
        break;
}
_fiche($PDOdb, $dispatch);
function _fiche(&$PDOdb, &$dispatch)
{
    global $db, $conf, $langs;
    llxHeader();
    $form = new TFormCore('auto', 'asset', 'post');
    echo $form->hidden('action', 'save');
    echo $form->hidden('id', $dispatch->fk_object);
    echo $form->hidden('type_object', $dispatch->type_object);
    $object = _header($dispatch->fk_object, $dispatch->type_object);
    $pListe[0] = "Sélectionnez une ligne";
    foreach ($object->lines as $k => &$line) {
        $label = !empty($line->label) ? $line->label : $line->libelle;
        if (empty($label) && !empty($line->desc)) {
            $label = $line->desc;
        }
Beispiel #3
0
        //charge l'objet hero correspondant à l'id passé en paramètre
        $hero->load($PDOdb, GETPOST('id'));
        _fiche($PDOdb, $hero);
        break;
    case 'save':
        //charge l'objet hero correspondant à l'id passé en paramètre
        $hero->load($PDOdb, GETPOST('id'));
        //ajoute les valeurs au héro en base de donnée (sauvegarde)
        $hero->set_values($_REQUEST);
        //attribution de la clé étrangère THaPouvoir à Hero
        $k = $hero->addChild($PDOdb, 'THaPouvoir');
        //récupération des pouvoirs du héro
        $hero->THaPouvoir[$k]->name = GETPOST('power');
        //sauvegarde du héro
        $hero->save($PDOdb);
        _fiche($PDOdb, $hero);
        break;
    default:
        _liste($PDOdb);
        break;
}
llxFooter();
function _liste(&$PDOdb)
{
    global $langs;
    $l = new TListviewTBS('listHero');
    //requete récupérant les attributs de chaque héro
    $sql = " SELECT rowid as ID, name, description FROM " . MAIN_DB_PREFIX . "hero";
    //affichage du template
    //utilisation de tableaux imbriqués :
    // le premier tableau définit les lignes
 */
if ($action) {
    switch ($action) {
        case 'view':
            $dolidacticiel->load($PDOdb, GETPOST('id'));
            _fiche($PDOdb, $dolidacticiel, 'view');
            break;
        case 'edit':
            $dolidacticiel->load($PDOdb, GETPOST('id'));
            _fiche($PDOdb, $dolidacticiel, 'edit');
            break;
        case 'save':
            $dolidacticiel->load($PDOdb, GETPOST('id'));
            $dolidacticiel->set_values($_REQUEST);
            $dolidacticiel->save($PDOdb);
            _fiche($PDOdb, $dolidacticiel, 'view');
            break;
        case 'liste':
            _liste($PDOdb, $dolidacticiel, $action);
            break;
        default:
            _liste($PDOdb, $dolidacticiel, $action);
            break;
    }
} else {
    _liste($PDOdb, $dolidacticiel, 'view');
}
llxFooter();
$db->close();
function _liste(&$PDOdb, &$dolidacticiel, $action)
{
     _fiche($PDOdb, $idea, 'view');
     break;
 case 'new':
     if ($user->rights->ideabox->create < 1) {
         accessforbidden();
     }
     $idea = new TIdeabox();
     _fiche($PDOdb, $idea, 'edit');
     break;
 case 'edit':
     if ($user->rights->ideabox->create < 1) {
         accessforbidden();
     }
     $idea = new TIdeabox();
     $idea->load($PDOdb, $id);
     _fiche($PDOdb, $idea, 'edit');
     break;
 case 'save':
     if ($user->rights->ideabox->create < 1) {
         accessforbidden();
     }
     $idea = new TIdeabox();
     $idea->load($PDOdb, $id);
     $idea->set_values($_REQUEST);
     $idea->save($PDOdb);
     setEventMessage($langs->trans('IdeaboxUpdateSaveControlEvent'));
     header('Location: ' . dol_buildpath('/ideabox/ideabox.php', 2) . '?id=' . $idea->getId() . '&action=view');
     break;
 case 'delete':
     if ($user->rights->ideabox->create < 1) {
         accessforbidden();
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;
    }
}
$fk_object = GETPOST('fk_object');
$action = GETPOST('action');
$PDOdb = new TPDOdb();
$c = new TChecklist();
$c->loadBy($PDOdb, $type_object, $fk_object);
switch ($action) {
    case 'yesido':
        //$PDOdb->debug=true;
        $c->iDoIt(GETPOST('k'));
        $c->setCheck();
        $c->save($PDOdb);
        break;
    default:
        break;
}
_fiche($c);
function _fiche(&$c)
{
    global $db, $conf, $langs, $user;
    llxHeader('', 'Checklist');
    $PDOdb = new TPDOdb();
    if ($c->type_object == 'project') {
        dol_include_once('/projet/class/project.class.php');
        dol_include_once('/core/lib/project.lib.php');
        $object = new Project($db);
        $object->fetch($c->fk_object);
        $head = project_prepare_head($object);
        dol_fiche_head($head, 'checklist', $langs->trans("Project"), 0, $object->public ? 'projectpub' : 'project');
    }
    ?>
	<table class="border" >
        $control->load($ATMdb, $id);
        if ($control->removeChild('TAssetControlMultiple', __get('id_value', 0, 'integer'))) {
            $control->save($ATMdb);
            setEventMessage($langs->trans('AssetMsgDeleteControlValue'));
        } else {
            setEventMessage($langs->trans('AssetErrDeleteControlValue'));
        }
        _fiche($ATMdb, $control, 'view');
        break;
    default:
        if ($id <= 0) {
            header('Location: ' . DOL_MAIN_URL_ROOT . '/custom/asset/list_control.php');
        }
        $control = new TAssetControl();
        $control->load($ATMdb, $id);
        _fiche($ATMdb, $control, 'view');
        break;
}
function _fiche(&$ATMdb, &$control, $mode = 'view', $editValue = false)
{
    global $db, $langs;
    llxHeader('', $langs->trans('AssetAddControl'), '', '');
    $TBS = new TTemplateTBS();
    $form = new TFormCore();
    $form->Set_typeaff($mode);
    $TForm = array('id' => $control->getId(), 'libelle' => $form->texte('', 'libelle', $control->libelle, 50, 255), 'type' => $form->combo('', 'type', TAssetControl::$TType, $control->type), 'question' => $form->texte('', 'question', $control->question, 120, 255));
    $TFormVal = _fiche_value($ATMdb, $editValue);
    $TVal = _liste_valeur($ATMdb, $control->getId(), $control->type);
    print $TBS->render('./tpl/control.tpl.php', array('TVal' => $TVal), array('co' => $TForm, 'FormVal' => $TFormVal, 'view' => array('mode' => $mode, 'editValue' => $editValue, 'type' => $control->type, 'url' => dol_buildpath('/of/control.php', 1))));
    llxFooter();
}