Dolibarr software doesn't find my file

411 Views Asked by At

I'm looking to create Forms in Dolibarr software but apparently he doesn't find the file card.php.

The software is installed in /var/www/html/dolibarr

I have a left menu which looks like this :

$this->menu[$r]=array('fk_menu'=>'fk_mainmenu=moduletest,fk_leftmenu=PremierMenu',          // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftm$
                        'type'=>'left',                                 // This is a Left menu entry
                        'titre'=>'Formulaire Dolibarr',
                        'mainmenu'=>'moduletest',
                        'leftmenu'=>'PremierMenu',
                        'url'=>'moduletest/card.php?action=create',
                        'langs'=>'mymodule@mymodule',           // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
                        'position'=>102,
                        'enabled'=> 1,
                        'perms'=>'1',                                         
                        'target'=>'',
                        'user'=>2);
$r++;

And my card.php looks like this (it's a simple form because I'm learning about php and Dolibarr modules) :

<?php
/* Copyright (C) 2002-2006 Rodolphe Quiedeville <[email protected]>
 * Copyright (C) 2002-2003 Jean-Louis Bergamo   <[email protected]>
 * Copyright (C) 2004-2015 Laurent Destailleur  <[email protected]>
 * Copyright (C) 2004      Eric Seigne          <[email protected]>
 * Copyright (C) 2005-2017 Regis Houssin        <[email protected]>
 * Copyright (C) 2005      Lionel Cousteix      <[email protected]>
 * Copyright (C) 2011      Herve Prot           <[email protected]>
 * Copyright (C) 2012      Juanjo Menent        <[email protected]>
 * Copyright (C) 2013      Florian Henry        <[email protected]>
 * Copyright (C) 2013-2016 Alexandre Spangaro   <[email protected]>
 * Copyright (C) 2015      Jean-François Ferry  <[email protected]>
 * Copyright (C) 2015      Ari Elbaz (elarifr)  <[email protected]>
 * Copyright (C) 2015      Charlie Benke        <[email protected]>
 * Copyright (C) 2016      Raphaël Doursenaud   <[email protected]>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 *       \file       htdocs/moduletest/card.php
 *       \brief      Tab of user card
 */

// Load Dolibarr environment
$res=0;
// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
if (! $res && ! empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res=@include($_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php");
// Try main.inc.php into web root detected using web root caluclated from SCRIPT_FILENAME
$tmp=empty($_SERVER['SCRIPT_FILENAME'])?'':$_SERVER['SCRIPT_FILENAME'];$tmp2=realpath(__FILE__); $i=strlen($tmp)-1; $j=strlen($tmp2)-1;
while($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i]==$tmp2[$j]) { $i--; $j--; }
if (! $res && $i > 0 && file_exists(substr($tmp, 0, ($i+1))."/main.inc.php")) $res=@include(substr($tmp, 0, ($i+1))."/main.inc.php");
if (! $res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i+1)))."/main.inc.php")) $res=@include(dirname(substr($tmp, 0, ($i+1)))."/main.inc.php");
// Try main.inc.php using relative path
if (! $res && file_exists("../main.inc.php")) $res=@include("../main.inc.php");
if (! $res && file_exists("../../main.inc.php")) $res=@include("../../main.inc.php");
if (! $res && file_exists("../../../main.inc.php")) $res=@include("../../../main.inc.php");
if (! $res) die("Include of main fails");

include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php');
include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php');

$langs->load("mymodule@mymodule");


$id             = GETPOST('id','int');
$action         = GETPOST('action','alpha');
$mode           = GETPOST('mode','alpha');
$confirm        = GETPOST('confirm','alpha');
$subaction      = GETPOST('subaction','alpha');
$group          = GETPOST("group","int",3);
$cancel         = GETPOST('cancel');


/*
 * Actions
 */

// If create a request
if ($action == 'create')
{
        $object = new Moduletest($db);

        $db->begin();

            $nom = GETPOST('nom');
            $prenom = GETPOST('prenom');
            $datenaissance = dol_mktime(0, 0, 0, GETPOST('datenaissance_month'), GETPOST('datenaissance_day'), GETPOST('datenaissance_year'));
            $adresse=GETPOST('adresse');
            $codepostal=GETPOST('codepostal');
            $pays=GETPOST('pays');
            $valideur = GETPOST('valideur');


        // If no name
            if (empty($nom))
            {
                setEventMessages($langs->trans("Pas de nom"), null, 'errors');
                $error++;
                $action='create';
            }

        // If no firstname
            if (empty($prenom))
            {
                setEventMessages($langs->trans("Pas de prénom"), null, 'errors');
                $error++;
                $action='create';
            }

        // If no birthday
            if (empty($datenaissance))
            {
                setEventMessages($langs->trans("Pas de date de naissance"), null, 'errors');
                $error++;
                $action='create';
            }

        // If no address
            if (empty($adresse))
            {
                setEventMessages($langs->trans("Pas d'adresse"), null, 'errors');
                $error++;
                $action='create';
            }

        // If no code postal
            if (empty($codepostal))
            {
                setEventMessages($langs->trans("Pas de code postal"), null, 'errors');
                $error++;
                $action='create';
            }

        // If no validator designated
            if ($valideur < 1)
            {
                setEventMessages($langs->transnoentitiesnoconv('InvalidValidatorCP'), null, 'errors');
                $error++;
            }

            $result = 0;

            if (! $error)
            {
            $object->nom = $nom;
            $object->prenom = $prenom;
            $object->datenaissance = $datenaissance;
            $object->adresse = $adresse;
            $object->codepostal = $codepostal;
        $object->pays = $pays;
            $result = $object->create($user);
                if ($result <= 0)
                {
                        setEventMessages($object->error, $object->errors, 'errors');
                        $error++;
                }
            }

// If no SQL error we redirect to the request card
            if (! $error)
            {
                $db->commit();

                header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
                exit;
            }
            else
                {
                $db->rollback();
            }
    }
}


/*
 * View
 */

$form = new Form($db);
$object = new Moduletest($db);

llxHeader('', $langs->trans('Formulaire de test'));

if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create')
{
   // Formulaire de demande de congés payés
   print load_fiche_titre($langs->trans('MenuAddCP'), '', 'title_hrm.png');

   // Formulaire de demande
   print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" onsubmit="return valider()" name="demandeCP">'."\n";
   print '<input type="hidden" name="action" value="create" />'."\n";

   dol_fiche_head();

        print '<table class="border" width="100%">';
        print '<tbody>';

        // Nom
        print '<tr>';
        print '<td class="titlefield fieldrequired">'.$langs->trans("Nom").'</td>';
        print '<td>';
        print '<input type="hidden" name="nom" value="'.$object->nom.'">';
        print '</td></tr>';

        // Prenom
        print '<tr>';
        print '<td class="titlefield fieldrequired">'.$langs->trans("Nom").'</td>';
        print '<td>';
        print '<input type="hidden" name="prenom" value="'.$object->prenom.'">';
        print '</td></tr>';

    // Date Naissance
        print '<tr>';
        print '<td class="fieldrequired">'.$langs->trans("Nom").'</td>';
        print '</td>';
    print '<td>';
    if (! GETPOST('datenaissance')) {
            $form->select_date(-1, 'datenaissance', 0, 0, 0, '', 1, 1);
        } else {
            $tmpdate = dol_mktime(0, 0, 0, GETPOST('datenaissance_month'), GETPOST('datenaissance_day'), GETPOST('datenaissance_year'));
            $form->select_date($tmpdate, 'datenaissance', 0, 0, 0, '', 1, 1);
        }
        print '</td>';
        print '</tr>';

    // Adresse
        print '<tr>';
        print '<td class="titlefield fieldrequired">'.$langs->trans("Adresse").'</td>';
        print '<td>';
        print '<input type="hidden" name="adresse" value="'.$object->adresse.'">';
    print '</td></tr>';

    // Code Postal
        print '<tr>';
        print '<td class="titlefield fieldrequired">'.$langs->trans("Code Postal").'</td>';
        print '<td>';
        print '<input type="hidden" name="codepostal" value="'.$object->codepostal.'">';
        print '</td></tr>';

    // Country
        print '<tr><td>'.fieldLabel('Pays','selectcountry_id').'</td><td class="maxwidthonsmartphone">';
        print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->pays));
        if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
        print '</td></tr>';

        print '</tbody>';
        print '</table>';

        dol_fiche_end();

        print '<div class="center">';
        print '<input type="submit" value="'.$langs->trans("SendRequestCP").'" name="bouton" class="button">';
        print '&nbsp; &nbsp; ';
        print '<input type="button" value="'.$langs->trans("Cancel").'" class="button" onclick="history.go(-1)">';
        print '</div>';

        print '</from>'."\n";
    }
}

dol_print_error($db);

llxFooter();
$db->close();

This file has all rights but when I click on my submenu Formulaire Dolibarr, I'm getting a blank page.

enter image description here

The url becomes : http://172.30.10.180/moduletest/card.php?action=create&idmenu=202&mainmenu=moduletest&leftmenu=

Do you have any idea if my PHP script gets any issue ?

I tried with an other file which just contains echo ... and it works, but not with card.php

2

There are 2 best solutions below

0
On

Import the file that content your class Moduletest

0
On

Yo need to change:

'url'=>'moduletest/card.php?action=create'

to:

'url'=>'/moduletest/card.php?action=create'

Dolibarr search in modxxx.class.php needs the "/" before the links in menu.