/**
  * Function called when a Dolibarrr business event is done.
  * All functions "run_trigger" are triggered if file
  * is inside directory core/triggers
  *
  * 	@param		string		$action		Event action code
  * 	@param		Object		$object		Object
  * 	@param		User		$user		Object user
  * 	@param		Translate	$langs		Object langs
  * 	@param		conf		$conf		Object conf
  * 	@return		int						<0 if KO, 0 if no triggered ran, >0 if OK
  */
 public function run_trigger($action, $object, $user, $langs, $conf)
 {
     // Put here code you want to execute when a Dolibarr business events occurs.
     // Data and type of action are stored into $object and $action
     // Users
     define('INC_FROM_DOLIBARR', true);
     dol_include_once('/dolidacticiel/config.php');
     dol_include_once('/dolidacticiel/class/dolidacticiel.class.php');
     $PDOdb = new TPDOdb();
     //if ($action != 'TDOLIDACTICIEL_LOAD' && $action != 'TDOLIDACTICIELUSER_LOAD') {var_dump($action);exit;}
     TDolidacticiel::testConditions($PDOdb, $user, $object, $action, $conf);
     return 0;
 }
$PDOdb = new TPDOdb();
/*
 * View
 */
$page_name = "dolidacticielSetup";
llxHeader('', $langs->trans($page_name));
// Subheader
$linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php">' . $langs->trans("BackToModuleList") . '</a>';
print_fiche_titre($langs->trans($page_name), $linkback);
// Configuration header
$head = dolidacticielAdminPrepareHead();
dol_fiche_head($head, 'otherstests', $langs->trans("Module104640Name"), 0, "dolidacticiel@dolidacticiel");
// Setup page goes here
$form = new Form($db);
$var = false;
$TDolidacticielByATM = TDolidacticiel::getAllByATM($PDOdb, $conf);
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>' . $langs->trans("DolidacticielListOfModuleByATMTitle") . '</td>';
print '<td>' . $langs->trans("DolidacticielListOfModuleByATMDescription") . '</td>';
print '<td>' . $langs->trans("DolidacticielListOfModuleByATMDolistore") . '</td>';
print '</tr>';
foreach ($TDolidacticielByATM as $test) {
    if (!empty($test->module_name) && $conf->{$test->module_name}->enabled) {
        $alt = $langs->transnoentitiesnoconv('DolidacticielTestAvailable');
        $picto = 'statut4';
        $showLink = false;
    } else {
        $alt = $langs->transnoentitiesnoconv('DolidacticielTestUnavailable');
        $picto = 'statut5';
        $showLink = true;
<?php

require 'config.php';
dol_include_once('/dolidacticiel/class/dolidacticiel.class.php');
dol_include_once('/core/lib/usergroups.lib.php');
$id = GETPOST('id');
$u = new User($db);
$u->fetch($id);
$u->getrights();
if ($u->id <= 0) {
    exit('ErrorUser');
}
llxHeader();
$head = user_prepare_head($u);
$title = $langs->trans("Achievements");
dol_fiche_head($head, 'achievements', $title);
$PDOdb = new TPDOdb();
$Tab = TDolidacticiel::getAll($PDOdb, $u, $conf);
print '<table class="border" width="100%">';
foreach ($Tab as &$d) {
    print '<tr><td width="50%"><strong>' . $d->title . '</strong><br />' . $d->description . '</td><td>' . ($d->currentUserAchievement ? img_picto('Ok', 'star') : '') . '</td></tr>';
}
print '</table>';
dol_fiche_end();
llxFooter();
 function prevCodeAchievement(&$PDOdb, &$user)
 {
     if (empty($this->prev_code)) {
         return true;
     }
     $TCode = explode(',', $this->prev_code);
     foreach ($TCode as $code) {
         $prevTest = new TDolidacticiel();
         $prevTest->loadBy($PDOdb, $code, 'code', true);
         if (!$prevTest->getUserAchievement($user->id)) {
             return false;
         }
     }
     return true;
 }
$d->save($PDOdb);
$code = 'PC1';
$d = new TDolidacticiel();
$d->loadBy($PDOdb, $code, 'code');
$d->set_values(array('mainmenu' => 'commercial', 'code' => $code, 'prev_code' => 'P6', 'title' => $langs->trans('title' . $code), 'description' => $langs->trans('description' . $code), 'action' => 'PROPAL_CREATE', 'cond' => '$object->socid == self::getStaticId($PDOdb, "societe", "nom", "Ciel & Terre")', 'level' => 0, 'rights' => '$user->rights->propal->creer', 'mainmenutips' => 'a#mainmenua_commercial', 'tips' => 'a.vsmenu[href*="/comm/propal.php?action=create&leftmenu=propals"]', 'module_name' => 'propale'));
$d->save($PDOdb);
$code = 'PC2';
$d = new TDolidacticiel();
$d->loadBy($PDOdb, $code, 'code');
$d->set_values(array('mainmenu' => 'commercial', 'code' => $code, 'prev_code' => 'PC1', 'title' => $langs->trans('title' . $code), 'description' => $langs->trans('description' . $code), 'action' => 'LINEPROPAL_INSERT', 'cond' => '$object->product_type == 0 && $object->price === price2num(199.90)', 'level' => 0, 'rights' => '$user->rights->propal->creer', 'mainmenutips' => 'a#mainmenua_commercial', 'tips' => 'label[for=prod_entry_mode_free]', 'module_name' => 'propale'));
$d->save($PDOdb);
$code = 'U1';
$d = new TDolidacticiel();
$d->loadBy($PDOdb, $code, 'code');
$d->set_values(array('mainmenu' => 'home', 'code' => $code, 'prev_code' => 'P2', 'title' => $langs->trans('title' . $code), 'description' => $langs->trans('description' . $code), 'action' => 'USER_CREATE', 'cond' => '$object->lastname === "Dupont"', 'level' => 0, 'rights' => '$user->rights->user->user->creer', 'mainmenutips' => 'a#mainmenua_home', 'tips' => 'a.vmenu[href*="/user/home.php?leftmenu=users"]', 'module_name' => 'user'));
$d->save($PDOdb);
$code = 'PJ1';
$d = new TDolidacticiel();
$d->loadBy($PDOdb, $code, 'code');
$d->set_values(array('mainmenu' => 'project', 'code' => $code, 'prev_code' => '', 'title' => $langs->trans('title' . $code), 'description' => $langs->trans('description' . $code), 'action' => 'PROJECT_CREATE', 'cond' => '', 'level' => 0, 'rights' => '$user->rights->projet->creer', 'mainmenutips' => 'a#mainmenua_project', 'tips' => 'a.vsmenu[href*="/projet/card.php?leftmenu=projects&action=create"]', 'module_name' => 'projet'));
$d->save($PDOdb);
$code = 'INV1';
$d = new TDolidacticiel();
$d->loadBy($PDOdb, $code, 'code');
$d->set_values(array('mainmenu' => 'products', 'code' => $code, 'prev_code' => 'P1', 'title' => $langs->trans('title' . $code), 'description' => $langs->trans('description' . $code), 'action' => 'TINVENTORY_CREATE', 'cond' => '$object->title === "' . $langs->trans('DolidacticielTitleInventoryForTest') . '" && $conf->stock->enabled', 'level' => 0, 'rights' => '$user->rights->inventory->create', 'mainmenutips' => 'a#mainmenua_products', 'tips' => 'a.vsmenu[href*="/inventory/inventory.php?action=create"]', 'from_atm' => 1, 'module_name' => 'inventory'));
$d->save($PDOdb);
$code = 'INV2';
$d = new TDolidacticiel();
$d->loadBy($PDOdb, $code, 'code');
$d->set_values(array('mainmenu' => 'products', 'code' => $code, 'prev_code' => 'INV1', 'title' => $langs->trans('title' . $code), 'description' => $langs->trans('description' . $code), 'action' => 'TINVENTORY_UPDATE', 'cond' => '$object->title === "' . $langs->trans('DolidacticielTitleInventoryForTest') . '" && count($object->TInventorydet) > 0', 'level' => 0, 'rights' => '$user->rights->inventory->write && $conf->stock->enabled', 'mainmenutips' => 'a#mainmenua_products', 'tips' => 'a.vsmenu[href*="/inventory/inventory.php?action=list"]', 'from_atm' => 1, 'module_name' => 'inventory'));
$d->save($PDOdb);
// Dolibarr environment
require '../config.php';
// Libraries
require_once DOL_DOCUMENT_ROOT . "/core/lib/admin.lib.php";
require_once '../lib/dolidacticiel.lib.php';
dol_include_once('/dolidacticiel/class/dolidacticiel.class.php');
// Translations
$langs->load("dolidacticiel@dolidacticiel");
// Access control
if (!$user->admin) {
    accessforbidden();
}
$PDOdb = new TPDOdb();
// Parameters
$action = GETPOST('action', 'alpha');
$dolidacticiel = new TDolidacticiel();
/*
 * Actions
 */
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'));