2017-05-08 21:00:23 +02:00
< ? php
2017-07-08 15:43:36 +02:00
/* Copyright ( C ) 2004 - 2017 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) --- Put here your own copyright and developer email ---
2017-05-08 21:00:23 +02:00
*
* 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2017-05-08 21:00:23 +02:00
*/
/**
2017-05-27 13:46:34 +02:00
* \file htdocs / modulebuilder / template / admin / setup . php
2017-05-08 21:00:23 +02:00
* \ingroup mymodule
2017-06-14 11:44:12 +02:00
* \brief MyModule setup page .
2017-05-08 21:00:23 +02:00
*/
// Load Dolibarr environment
2019-11-13 19:35:02 +01:00
$res = 0 ;
2017-06-23 20:03:15 +02:00
// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
2021-02-26 18:26:44 +01:00
if ( ! $res && ! empty ( $_SERVER [ " CONTEXT_DOCUMENT_ROOT " ])) {
$res = @ include $_SERVER [ " CONTEXT_DOCUMENT_ROOT " ] . " /main.inc.php " ;
}
2018-05-23 17:16:58 +02:00
// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
2019-11-13 19:35:02 +01:00
$tmp = empty ( $_SERVER [ 'SCRIPT_FILENAME' ]) ? '' : $_SERVER [ 'SCRIPT_FILENAME' ]; $tmp2 = realpath ( __FILE__ ); $i = strlen ( $tmp ) - 1 ; $j = strlen ( $tmp2 ) - 1 ;
2021-02-26 18:26:44 +01:00
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 " ;
}
2017-06-23 20:03:15 +02:00
// Try main.inc.php using relative path
2021-02-26 18:26:44 +01:00
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 " );
}
2017-06-23 20:03:15 +02:00
2017-05-08 21:00:23 +02:00
global $langs , $user ;
// Libraries
2019-11-13 19:35:02 +01:00
require_once DOL_DOCUMENT_ROOT . " /core/lib/admin.lib.php " ;
2017-05-08 21:00:23 +02:00
require_once '../lib/mymodule.lib.php' ;
//require_once "../class/myclass.class.php";
2017-08-26 15:22:13 +02:00
2017-05-08 21:00:23 +02:00
// Translations
2017-08-26 15:22:13 +02:00
$langs -> loadLangs ( array ( " admin " , " mymodule@mymodule " ));
2017-05-08 21:00:23 +02:00
// Access control
2021-01-06 20:24:45 +01:00
if ( ! $user -> admin ) {
accessforbidden ();
}
2017-05-08 21:00:23 +02:00
// Parameters
2020-09-16 19:39:50 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2017-12-15 10:46:11 +01:00
$backtopage = GETPOST ( 'backtopage' , 'alpha' );
2017-05-08 21:00:23 +02:00
2020-05-31 22:59:33 +02:00
$value = GETPOST ( 'value' , 'alpha' );
2020-12-11 14:22:36 +01:00
$label = GETPOST ( 'label' , 'alpha' );
$scandir = GETPOST ( 'scan_dir' , 'alpha' );
$type = 'myobject' ;
2020-05-31 22:59:33 +02:00
2019-11-13 19:35:02 +01:00
$arrayofparameters = array (
2021-02-14 15:02:05 +01:00
'MYMODULE_MYPARAM1' => array ( 'type' => 'string' , 'css' => 'minwidth500' , 'enabled' => 1 ),
'MYMODULE_MYPARAM2' => array ( 'type' => 'textarea' , 'enabled' => 1 ),
//'MYMODULE_MYPARAM3'=>array('type'=>'category:'.Categorie::TYPE_CUSTOMER, 'enabled'=>1),
//'MYMODULE_MYPARAM4'=>array('type'=>'emailtemplate:thirdparty', 'enabled'=>1),
//'MYMODULE_MYPARAM5'=>array('type'=>'yesno', 'enabled'=>1),
2021-03-26 19:47:48 +01:00
//'MYMODULE_MYPARAM5'=>array('type'=>'thirdparty_type', 'enabled'=>1),
2021-04-23 17:12:34 +02:00
//'MYMODULE_MYPARAM6'=>array('type'=>'securekey', 'enabled'=>1),
//'MYMODULE_MYPARAM7'=>array('type'=>'product', 'enabled'=>1),
2018-07-10 14:56:04 +02:00
);
2017-08-26 15:22:13 +02:00
2020-05-31 22:59:33 +02:00
$error = 0 ;
2020-06-01 04:02:47 +02:00
$setupnotempty = 0 ;
2017-06-01 12:11:45 +02:00
2021-04-29 10:01:10 +02:00
$dirmodels = array_merge ( array ( '/' ), ( array ) $conf -> modules_parts [ 'models' ]);
2019-05-09 14:36:48 +02:00
2017-05-08 21:00:23 +02:00
/*
* Actions
*/
2019-05-09 14:36:48 +02:00
2021-01-06 20:24:45 +01:00
if (( float ) DOL_VERSION >= 6 ) {
2018-06-13 20:43:02 +02:00
include DOL_DOCUMENT_ROOT . '/core/actions_setmoduleoptions.inc.php' ;
}
2017-06-01 12:11:45 +02:00
2021-01-06 20:24:45 +01:00
if ( $action == 'updateMask' ) {
2020-05-31 22:59:33 +02:00
$maskconstorder = GETPOST ( 'maskconstorder' , 'alpha' );
$maskorder = GETPOST ( 'maskorder' , 'alpha' );
2021-01-06 20:24:45 +01:00
if ( $maskconstorder ) {
$res = dolibarr_set_const ( $db , $maskconstorder , $maskorder , 'chaine' , 0 , '' , $conf -> entity );
2021-01-23 17:49:08 +01:00
if ( ! ( $res > 0 )) {
$error ++ ;
}
2021-01-06 20:24:45 +01:00
}
2020-05-31 22:59:33 +02:00
2021-01-06 20:24:45 +01:00
if ( ! $error ) {
2020-05-31 22:59:33 +02:00
setEventMessages ( $langs -> trans ( " SetupSaved " ), null , 'mesgs' );
} else {
setEventMessages ( $langs -> trans ( " Error " ), null , 'errors' );
}
2021-01-06 20:24:45 +01:00
} elseif ( $action == 'specimen' ) {
2020-05-31 22:59:33 +02:00
$modele = GETPOST ( 'module' , 'alpha' );
$tmpobjectkey = GETPOST ( 'object' );
$tmpobject = new $tmpobjectkey ( $db );
$tmpobject -> initAsSpecimen ();
// Search template files
$file = '' ; $classname = '' ; $filefound = 0 ;
$dirmodels = array_merge ( array ( '/' ), ( array ) $conf -> modules_parts [ 'models' ]);
2021-01-06 20:24:45 +01:00
foreach ( $dirmodels as $reldir ) {
2020-05-31 22:59:33 +02:00
$file = dol_buildpath ( $reldir . " core/modules/mymodule/doc/pdf_ " . $modele . " _ " . strtolower ( $tmpobjectkey ) . " .modules.php " , 0 );
2021-01-06 20:24:45 +01:00
if ( file_exists ( $file )) {
2020-05-31 22:59:33 +02:00
$filefound = 1 ;
$classname = " pdf_ " . $modele ;
break ;
}
}
2021-01-06 20:24:45 +01:00
if ( $filefound ) {
2020-05-31 22:59:33 +02:00
require_once $file ;
$module = new $classname ( $db );
2021-01-06 20:24:45 +01:00
if ( $module -> write_file ( $tmpobject , $langs ) > 0 ) {
2020-05-31 22:59:33 +02:00
header ( " Location: " . DOL_URL_ROOT . " /document.php?modulepart= " . strtolower ( $tmpobjectkey ) . " &file=SPECIMEN.pdf " );
return ;
} else {
setEventMessages ( $module -> error , null , 'errors' );
dol_syslog ( $module -> error , LOG_ERR );
}
} else {
setEventMessages ( $langs -> trans ( " ErrorModuleNotFound " ), null , 'errors' );
dol_syslog ( $langs -> trans ( " ErrorModuleNotFound " ), LOG_ERR );
}
2021-01-06 20:24:45 +01:00
} elseif ( $action == 'setmod' ) {
2020-12-11 14:22:36 +01:00
// TODO Check if numbering module chosen can be activated by calling method canBeActivated
2020-05-31 22:59:33 +02:00
$tmpobjectkey = GETPOST ( 'object' );
2020-12-11 14:22:36 +01:00
if ( ! empty ( $tmpobjectkey )) {
$constforval = 'MYMODULE_' . strtoupper ( $tmpobjectkey ) . " _ADDON " ;
dolibarr_set_const ( $db , $constforval , $value , 'chaine' , 0 , '' , $conf -> entity );
}
2021-01-06 20:24:45 +01:00
} elseif ( $action == 'set' ) {
// Activate a model
2020-12-11 14:22:36 +01:00
$ret = addDocumentModel ( $value , $type , $label , $scandir );
} elseif ( $action == 'del' ) {
2020-05-31 22:59:33 +02:00
$ret = delDocumentModel ( $value , $type );
2020-12-11 14:22:36 +01:00
if ( $ret > 0 ) {
$tmpobjectkey = GETPOST ( 'object' );
if ( ! empty ( $tmpobjectkey )) {
$constforval = 'MYMODULE_' . strtoupper ( $tmpobjectkey ) . '_ADDON_PDF' ;
2021-01-07 18:00:23 +01:00
if ( $conf -> global -> $constforval == " $value " ) {
dolibarr_del_const ( $db , $constforval , $conf -> entity );
}
2020-12-11 14:22:36 +01:00
}
2020-05-31 22:59:33 +02:00
}
2021-01-06 20:24:45 +01:00
} elseif ( $action == 'setdoc' ) {
// Set or unset default model
2020-05-31 22:59:33 +02:00
$tmpobjectkey = GETPOST ( 'object' );
2020-12-11 14:22:36 +01:00
if ( ! empty ( $tmpobjectkey )) {
$constforval = 'MYMODULE_' . strtoupper ( $tmpobjectkey ) . '_ADDON_PDF' ;
if ( dolibarr_set_const ( $db , $constforval , $value , 'chaine' , 0 , '' , $conf -> entity )) {
// The constant that was read before the new set
// We therefore requires a variable to have a coherent view
$conf -> global -> $constforval = $value ;
}
2020-05-31 22:59:33 +02:00
2020-12-11 14:22:36 +01:00
// We disable/enable the document template (into llx_document_model table)
$ret = delDocumentModel ( $value , $type );
if ( $ret > 0 ) {
$ret = addDocumentModel ( $value , $type , $label , $scandir );
}
2020-05-31 22:59:33 +02:00
}
2020-12-11 14:22:36 +01:00
} elseif ( $action == 'unsetdoc' ) {
2020-05-31 22:59:33 +02:00
$tmpobjectkey = GETPOST ( 'object' );
2020-12-11 14:22:36 +01:00
if ( ! empty ( $tmpobjectkey )) {
$constforval = 'MYMODULE_' . strtoupper ( $tmpobjectkey ) . '_ADDON_PDF' ;
dolibarr_del_const ( $db , $constforval , $conf -> entity );
}
2020-05-31 22:59:33 +02:00
}
2017-06-01 12:11:45 +02:00
2019-05-09 14:36:48 +02:00
2017-05-08 21:00:23 +02:00
/*
* View
*/
2017-06-01 12:11:45 +02:00
2020-05-31 22:59:33 +02:00
$form = new Form ( $db );
2021-04-29 10:01:10 +02:00
$help_url = '' ;
2017-05-08 21:00:23 +02:00
$page_name = " MyModuleSetup " ;
2021-04-29 10:01:10 +02:00
llxHeader ( '' , $langs -> trans ( $page_name ), $help_url );
2017-05-08 21:00:23 +02:00
// Subheader
2019-11-13 19:35:02 +01:00
$linkback = '<a href="' . ( $backtopage ? $backtopage : DOL_URL_ROOT . '/admin/modules.php?restore_lastsearch_values=1' ) . '">' . $langs -> trans ( " BackToModuleList " ) . '</a>' ;
2017-05-27 13:46:34 +02:00
2021-04-29 10:01:10 +02:00
print load_fiche_titre ( $langs -> trans ( $page_name ), $linkback , 'title_setup' );
2017-05-08 21:00:23 +02:00
// Configuration header
$head = mymoduleAdminPrepareHead ();
2021-04-29 10:01:10 +02:00
print dol_get_fiche_head ( $head , 'settings' , $langs -> trans ( $page_name ), - 1 , " mymodule@mymodule " );
2017-05-08 21:00:23 +02:00
// Setup page goes here
2019-05-09 14:36:48 +02:00
echo '<span class="opacitymedium">' . $langs -> trans ( " MyModuleSetupPage " ) . '</span><br><br>' ;
2017-05-08 21:00:23 +02:00
2017-08-26 15:22:13 +02:00
2021-01-06 20:24:45 +01:00
if ( $action == 'edit' ) {
2017-08-26 15:22:13 +02:00
print '<form method="POST" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-08-26 15:22:13 +02:00
print '<input type="hidden" name="action" value="update">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2017-08-26 15:22:13 +02:00
print '<tr class="liste_titre"><td class="titlefield">' . $langs -> trans ( " Parameter " ) . '</td><td>' . $langs -> trans ( " Value " ) . '</td></tr>' ;
2021-02-14 15:02:05 +01:00
foreach ( $arrayofparameters as $constname => $val ) {
if ( $val [ 'enabled' ] == 1 ) {
$setupnotempty ++ ;
print '<tr class="oddeven"><td>' ;
$tooltiphelp = (( $langs -> trans ( $constname . 'Tooltip' ) != $constname . 'Tooltip' ) ? $langs -> trans ( $constname . 'Tooltip' ) : '' );
2021-02-14 16:48:44 +01:00
print '<span id="helplink' . $constname . '" class="spanforparamtooltip">' . $form -> textwithpicto ( $langs -> trans ( $constname ), $tooltiphelp , 1 , 'info' , '' , 0 , 3 , 'tootips' . $constname ) . '</span>' ;
2021-02-14 15:02:05 +01:00
print '</td><td>' ;
if ( $val [ 'type' ] == 'textarea' ) {
2021-02-14 16:44:42 +01:00
print '<textarea class="flat" name="' . $constname . '" id="' . $constname . '" cols="50" rows="5" wrap="soft">' . " \n " ;
2021-02-14 15:02:05 +01:00
print $conf -> global -> { $constname };
print " </textarea> \n " ;
2021-02-14 16:44:42 +01:00
} elseif ( $val [ 'type' ] == 'html' ) {
2021-02-14 15:02:05 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
$doleditor = new DolEditor ( $constname , $conf -> global -> { $constname }, '' , 160 , 'dolibarr_notes' , '' , false , false , $conf -> fckeditor -> enabled , ROWS_5 , '90%' );
$doleditor -> Create ();
} elseif ( $val [ 'type' ] == 'yesno' ) {
print $form -> selectyesno ( $constname , $conf -> global -> { $constname }, 1 );
} elseif ( preg_match ( '/emailtemplate:/' , $val [ 'type' ])) {
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php' ;
$formmail = new FormMail ( $db );
$tmp = explode ( ':' , $val [ 'type' ]);
2021-02-14 16:44:42 +01:00
$nboftemplates = $formmail -> fetchAllEMailTemplate ( $tmp [ 1 ], $user , null , 1 ); // We set lang=null to get in priority record with no lang
2021-02-14 15:02:05 +01:00
//$arraydefaultmessage = $formmail->getEMailTemplate($db, $tmp[1], $user, null, 0, 1, '');
$arrayofmessagename = array ();
if ( is_array ( $formmail -> lines_model )) {
foreach ( $formmail -> lines_model as $modelmail ) {
//var_dump($modelmail);
$moreonlabel = '' ;
if ( ! empty ( $arrayofmessagename [ $modelmail -> label ])) {
$moreonlabel = ' <span class="opacitymedium">(' . $langs -> trans ( " SeveralLangugeVariatFound " ) . ')</span>' ;
}
// The 'label' is the key that is unique if we exclude the language
2021-02-14 16:44:42 +01:00
$arrayofmessagename [ $modelmail -> id ] = $langs -> trans ( preg_replace ( '/\(|\)/' , '' , $modelmail -> label )) . $moreonlabel ;
2021-02-14 15:02:05 +01:00
}
}
print $form -> selectarray ( $constname , $arrayofmessagename , $conf -> global -> { $constname }, 'None' , 0 , 0 , '' , 0 , 0 , 0 , '' , '' , 1 );
} elseif ( preg_match ( '/category:/' , $val [ 'type' ])) {
2021-02-14 16:44:42 +01:00
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php' ;
2021-02-14 15:02:05 +01:00
$formother = new FormOther ( $db );
$tmp = explode ( ':' , $val [ 'type' ]);
print img_picto ( '' , 'category' , 'class="pictofixedwidth"' );
2021-02-14 16:44:42 +01:00
print $formother -> select_categories ( $tmp [ 1 ], $conf -> global -> { $constname }, $constname , 0 , $langs -> trans ( 'CustomersProspectsCategoriesShort' ));
2021-03-26 19:47:48 +01:00
} elseif ( preg_match ( '/thirdparty_type/' , $val [ 'type' ])) {
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php' ;
$formcompany = new FormCompany ( $db );
print $formcompany -> selectProspectCustomerType ( $conf -> global -> { $constname }, $constname );
2021-04-09 10:58:33 +02:00
} elseif ( $val [ 'type' ] == 'securekey' ) {
2021-04-13 20:28:25 +02:00
print '<input required="required" type="text" class="flat" id="' . $constname . '" name="' . $constname . '" value="' . ( GETPOST ( $constname , 'alpha' ) ? GETPOST ( $constname , 'alpha' ) : $conf -> global -> { $constname }) . '" size="40">' ;
if ( ! empty ( $conf -> use_javascript_ajax )) {
print ' ' . img_picto ( $langs -> trans ( 'Generate' ), 'refresh' , 'id="generate_token' . $constname . '" class="linkobject"' );
}
if ( ! empty ( $conf -> use_javascript_ajax )) {
print " \n " . '<script type="text/javascript">' ;
print ' $ ( document ) . ready ( function () {
2021-04-09 10:58:33 +02:00
$ ( " #generate_token'. $constname .' " ) . click ( function () {
$ . get ( " '.DOL_URL_ROOT.'/core/ajax/security.php " , {
action : \ ' getrandompassword\ ' ,
generic : true
},
function ( token ) {
$ ( " #'. $constname .' " ) . val ( token );
});
});
}); ' ;
2021-04-23 17:12:34 +02:00
print '</script>' ;
}
2021-04-15 16:10:01 +02:00
} elseif ( $val [ 'type' ] == 'product' ) {
2021-04-23 17:12:34 +02:00
if ( ! empty ( $conf -> product -> enabled ) || ! empty ( $conf -> service -> enabled )) {
$selected = ( empty ( $conf -> global -> $constname ) ? '' : $conf -> global -> $constname );
$form -> select_produits ( $selected , $constname , '' , 0 );
}
2021-02-14 16:48:44 +01:00
} else {
2021-02-14 16:44:42 +01:00
print '<input name="' . $constname . '" class="flat ' . ( empty ( $val [ 'css' ]) ? 'minwidth200' : $val [ 'css' ]) . '" value="' . $conf -> global -> { $constname } . '">' ;
2021-02-14 15:02:05 +01:00
}
print '</td></tr>' ;
}
2017-08-26 15:22:13 +02:00
}
print '</table>' ;
print '<br><div class="center">' ;
2020-11-19 20:23:38 +01:00
print '<input class="button button-save" type="submit" value="' . $langs -> trans ( " Save " ) . '">' ;
2017-08-26 15:22:13 +02:00
print '</div>' ;
print '</form>' ;
print '<br>' ;
2020-05-21 09:35:30 +02:00
} else {
2021-01-06 20:24:45 +01:00
if ( ! empty ( $arrayofparameters )) {
2019-05-21 15:31:56 +02:00
print '<table class="noborder centpercent">' ;
2018-09-24 10:08:57 +02:00
print '<tr class="liste_titre"><td class="titlefield">' . $langs -> trans ( " Parameter " ) . '</td><td>' . $langs -> trans ( " Value " ) . '</td></tr>' ;
2017-08-26 15:22:13 +02:00
2021-02-14 16:44:42 +01:00
foreach ( $arrayofparameters as $constname => $val ) {
if ( $val [ 'enabled' ] == 1 ) {
$setupnotempty ++ ;
print '<tr class="oddeven"><td>' ;
$tooltiphelp = (( $langs -> trans ( $constname . 'Tooltip' ) != $constname . 'Tooltip' ) ? $langs -> trans ( $constname . 'Tooltip' ) : '' );
print $form -> textwithpicto ( $langs -> trans ( $constname ), $tooltiphelp );
print '</td><td>' ;
if ( $val [ 'type' ] == 'textarea' ) {
print dol_nl2br ( $conf -> global -> { $constname });
} elseif ( $val [ 'type' ] == 'html' ) {
print $conf -> global -> { $constname };
} elseif ( $val [ 'type' ] == 'yesno' ) {
print ajax_constantonoff ( $constname );
} elseif ( preg_match ( '/emailtemplate:/' , $val [ 'type' ])) {
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php' ;
$formmail = new FormMail ( $db );
$tmp = explode ( ':' , $val [ 'type' ]);
$template = $formmail -> getEMailTemplate ( $db , $tmp [ 1 ], $user , $langs , $conf -> global -> { $constname });
if ( $template < 0 ) {
setEventMessages ( null , $formmail -> errors , 'errors' );
}
print $langs -> trans ( $template -> label );
} elseif ( preg_match ( '/category:/' , $val [ 'type' ])) {
$c = new Categorie ( $db );
$result = $c -> fetch ( $conf -> global -> { $constname });
if ( $result < 0 ) {
setEventMessages ( null , $c -> errors , 'errors' );
2021-10-26 14:11:51 +02:00
} elseif ( $result > 0 ) {
$ways = $c -> print_all_ways ( ' >> ' , 'none' , 0 , 1 ); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formated text
$toprint = array ();
foreach ( $ways as $way ) {
$toprint [] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ( $c -> color ? ' style="background: #' . $c -> color . ';"' : ' style="background: #bbb"' ) . '>' . $way . '</li>' ;
}
print '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode ( ' ' , $toprint ) . '</ul></div>' ;
2021-02-14 16:44:42 +01:00
}
2021-03-26 19:47:48 +01:00
} elseif ( preg_match ( '/thirdparty_type/' , $val [ 'type' ])) {
if ( $conf -> global -> { $constname } == 2 ) {
print $langs -> trans ( " Prospect " );
} elseif ( $conf -> global -> { $constname } == 3 ) {
print $langs -> trans ( " ProspectCustomer " );
} elseif ( $conf -> global -> { $constname } == 1 ) {
print $langs -> trans ( " Customer " );
} elseif ( $conf -> global -> { $constname } == 0 ) {
print $langs -> trans ( " NorProspectNorCustomer " );
}
2021-04-15 16:10:01 +02:00
} elseif ( $val [ 'type' ] == 'product' ) {
2021-04-23 17:12:34 +02:00
$product = new Product ( $db );
$resprod = $product -> fetch ( $conf -> global -> { $constname });
if ( $resprod > 0 ) {
print $product -> ref ;
} elseif ( $resprod < 0 ) {
setEventMessages ( null , $object -> errors , " errors " );
}
2021-02-14 16:44:42 +01:00
} else {
2021-04-15 16:10:01 +02:00
print $conf -> global -> { $constname };
2021-02-14 16:44:42 +01:00
}
print '</td></tr>' ;
}
2018-09-24 10:08:57 +02:00
}
2017-08-26 15:22:13 +02:00
2018-09-24 10:08:57 +02:00
print '</table>' ;
print '<div class="tabsAction">' ;
2021-09-27 12:24:01 +02:00
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?action=edit&token=' . newToken () . '">' . $langs -> trans ( " Modify " ) . '</a>' ;
2018-09-24 10:08:57 +02:00
print '</div>' ;
2020-05-21 09:35:30 +02:00
} else {
2018-09-24 10:08:57 +02:00
print '<br>' . $langs -> trans ( " NothingToSetup " );
}
2017-08-26 15:22:13 +02:00
}
2020-05-31 22:59:33 +02:00
$moduledir = 'mymodule' ;
$myTmpObjects = array ();
2020-10-31 14:32:18 +01:00
$myTmpObjects [ 'MyObject' ] = array ( 'includerefgeneration' => 0 , 'includedocgeneration' => 0 );
2020-05-31 22:59:33 +02:00
2020-06-01 12:36:09 +02:00
foreach ( $myTmpObjects as $myTmpObjectKey => $myTmpObjectArray ) {
2021-01-06 20:24:45 +01:00
if ( $myTmpObjectKey == 'MyObject' ) {
continue ;
}
2020-05-31 22:59:33 +02:00
if ( $myTmpObjectArray [ 'includerefgeneration' ]) {
/*
* Orders Numbering model
*/
2020-06-01 04:02:47 +02:00
$setupnotempty ++ ;
2020-05-31 22:59:33 +02:00
print load_fiche_titre ( $langs -> trans ( " NumberingModules " , $myTmpObjectKey ), '' , '' );
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
print '<table class="noborder centpercent">' ;
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " Name " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Description " ) . '</td>' ;
print '<td class="nowrap">' . $langs -> trans ( " Example " ) . '</td>' ;
print '<td class="center" width="60">' . $langs -> trans ( " Status " ) . '</td>' ;
print '<td class="center" width="16">' . $langs -> trans ( " ShortInfo " ) . '</td>' ;
print '</tr>' . " \n " ;
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
clearstatcache ();
2020-06-01 04:02:47 +02:00
2021-01-06 20:24:45 +01:00
foreach ( $dirmodels as $reldir ) {
2020-05-31 22:59:33 +02:00
$dir = dol_buildpath ( $reldir . " core/modules/ " . $moduledir );
2020-06-01 04:02:47 +02:00
2021-01-06 20:24:45 +01:00
if ( is_dir ( $dir )) {
2020-05-31 22:59:33 +02:00
$handle = opendir ( $dir );
2021-01-06 20:24:45 +01:00
if ( is_resource ( $handle )) {
while (( $file = readdir ( $handle )) !== false ) {
if ( strpos ( $file , 'mod_' . strtolower ( $myTmpObjectKey ) . '_' ) === 0 && substr ( $file , dol_strlen ( $file ) - 3 , 3 ) == 'php' ) {
2020-05-31 22:59:33 +02:00
$file = substr ( $file , 0 , dol_strlen ( $file ) - 4 );
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
require_once $dir . '/' . $file . '.php' ;
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
$module = new $file ( $db );
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
// Show modules according to features level
2021-01-06 20:24:45 +01:00
if ( $module -> version == 'development' && $conf -> global -> MAIN_FEATURES_LEVEL < 2 ) {
continue ;
}
if ( $module -> version == 'experimental' && $conf -> global -> MAIN_FEATURES_LEVEL < 1 ) {
continue ;
}
2020-06-01 04:02:47 +02:00
2021-01-06 20:24:45 +01:00
if ( $module -> isEnabled ()) {
2020-05-31 22:59:33 +02:00
dol_include_once ( '/' . $moduledir . '/class/' . strtolower ( $myTmpObjectKey ) . '.class.php' );
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
print '<tr class="oddeven"><td>' . $module -> name . " </td><td> \n " ;
print $module -> info ();
print '</td>' ;
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
// Show example of numbering model
print '<td class="nowrap">' ;
$tmp = $module -> getExample ();
2020-11-28 02:09:27 +01:00
if ( preg_match ( '/^Error/' , $tmp )) {
$langs -> load ( " errors " );
print '<div class="error">' . $langs -> trans ( $tmp ) . '</div>' ;
2021-01-06 20:24:45 +01:00
} elseif ( $tmp == 'NotConfigured' ) {
print $langs -> trans ( $tmp );
} else {
print $tmp ;
}
2020-05-31 22:59:33 +02:00
print '</td>' . " \n " ;
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
print '<td class="center">' ;
$constforvar = 'MYMODULE_' . strtoupper ( $myTmpObjectKey ) . '_ADDON' ;
2021-01-06 20:24:45 +01:00
if ( $conf -> global -> $constforvar == $file ) {
2020-05-31 22:59:33 +02:00
print img_picto ( $langs -> trans ( " Activated " ), 'switch_on' );
} else {
2020-09-30 15:13:28 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?action=setmod&token=' . newToken () . '&object=' . strtolower ( $myTmpObjectKey ) . '&value=' . urlencode ( $file ) . '">' ;
2020-05-31 22:59:33 +02:00
print img_picto ( $langs -> trans ( " Disabled " ), 'switch_off' );
print '</a>' ;
}
print '</td>' ;
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
$mytmpinstance = new $myTmpObjectKey ( $db );
$mytmpinstance -> initAsSpecimen ();
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
// Info
$htmltooltip = '' ;
$htmltooltip .= '' . $langs -> trans ( " Version " ) . ': <b>' . $module -> getVersion () . '</b><br>' ;
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
$nextval = $module -> getNextValue ( $mytmpinstance );
if ( " $nextval " != $langs -> trans ( " NotAvailable " )) { // Keep " on nextval
$htmltooltip .= '' . $langs -> trans ( " NextValue " ) . ': ' ;
if ( $nextval ) {
2021-01-07 18:00:23 +01:00
if ( preg_match ( '/^Error/' , $nextval ) || $nextval == 'NotConfigured' ) {
2020-05-31 22:59:33 +02:00
$nextval = $langs -> trans ( $nextval );
2021-01-07 18:00:23 +01:00
}
$htmltooltip .= $nextval . '<br>' ;
2020-05-31 22:59:33 +02:00
} else {
$htmltooltip .= $langs -> trans ( $module -> error ) . '<br>' ;
}
}
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
print '<td class="center">' ;
print $form -> textwithpicto ( '' , $htmltooltip , 1 , 0 );
print '</td>' ;
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
print " </tr> \n " ;
}
}
}
closedir ( $handle );
}
}
}
print " </table><br> \n " ;
}
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
if ( $myTmpObjectArray [ 'includedocgeneration' ]) {
/*
* Document templates generators
*/
2020-06-01 04:02:47 +02:00
$setupnotempty ++ ;
2020-05-31 22:59:33 +02:00
$type = strtolower ( $myTmpObjectKey );
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
print load_fiche_titre ( $langs -> trans ( " DocumentModules " , $myTmpObjectKey ), '' , '' );
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
// Load array def with activated templates
$def = array ();
$sql = " SELECT nom " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " document_model " ;
2020-09-20 02:57:15 +02:00
$sql .= " WHERE type = ' " . $db -> escape ( $type ) . " ' " ;
2020-05-31 22:59:33 +02:00
$sql .= " AND entity = " . $conf -> entity ;
$resql = $db -> query ( $sql );
2021-01-06 20:24:45 +01:00
if ( $resql ) {
2020-05-31 22:59:33 +02:00
$i = 0 ;
$num_rows = $db -> num_rows ( $resql );
2021-01-06 20:24:45 +01:00
while ( $i < $num_rows ) {
2020-05-31 22:59:33 +02:00
$array = $db -> fetch_array ( $resql );
array_push ( $def , $array [ 0 ]);
$i ++ ;
}
} else {
dol_print_error ( $db );
}
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
print " <table class= \" noborder \" width= \" 100% \" > \n " ;
print " <tr class= \" liste_titre \" > \n " ;
print '<td>' . $langs -> trans ( " Name " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Description " ) . '</td>' ;
print '<td class="center" width="60">' . $langs -> trans ( " Status " ) . " </td> \n " ;
print '<td class="center" width="60">' . $langs -> trans ( " Default " ) . " </td> \n " ;
print '<td class="center" width="38">' . $langs -> trans ( " ShortInfo " ) . '</td>' ;
print '<td class="center" width="38">' . $langs -> trans ( " Preview " ) . '</td>' ;
print " </tr> \n " ;
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
clearstatcache ();
2020-06-01 04:02:47 +02:00
2021-01-06 20:24:45 +01:00
foreach ( $dirmodels as $reldir ) {
foreach ( array ( '' , '/doc' ) as $valdir ) {
2020-05-31 22:59:33 +02:00
$realpath = $reldir . " core/modules/ " . $moduledir . $valdir ;
$dir = dol_buildpath ( $realpath );
2020-06-01 04:02:47 +02:00
2021-01-06 20:24:45 +01:00
if ( is_dir ( $dir )) {
2020-05-31 22:59:33 +02:00
$handle = opendir ( $dir );
2021-01-06 20:24:45 +01:00
if ( is_resource ( $handle )) {
while (( $file = readdir ( $handle )) !== false ) {
2020-05-31 22:59:33 +02:00
$filelist [] = $file ;
}
closedir ( $handle );
arsort ( $filelist );
2020-06-01 04:02:47 +02:00
2021-01-06 20:24:45 +01:00
foreach ( $filelist as $file ) {
if ( preg_match ( '/\.modules\.php$/i' , $file ) && preg_match ( '/^(pdf_|doc_)/' , $file )) {
if ( file_exists ( $dir . '/' . $file )) {
2020-05-31 22:59:33 +02:00
$name = substr ( $file , 4 , dol_strlen ( $file ) - 16 );
$classname = substr ( $file , 0 , dol_strlen ( $file ) - 12 );
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
require_once $dir . '/' . $file ;
$module = new $classname ( $db );
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
$modulequalified = 1 ;
2021-01-06 20:24:45 +01:00
if ( $module -> version == 'development' && $conf -> global -> MAIN_FEATURES_LEVEL < 2 ) {
$modulequalified = 0 ;
}
if ( $module -> version == 'experimental' && $conf -> global -> MAIN_FEATURES_LEVEL < 1 ) {
$modulequalified = 0 ;
}
2020-06-01 04:02:47 +02:00
2021-01-06 20:24:45 +01:00
if ( $modulequalified ) {
2020-05-31 22:59:33 +02:00
print '<tr class="oddeven"><td width="100">' ;
print ( empty ( $module -> name ) ? $name : $module -> name );
print " </td><td> \n " ;
2021-01-06 20:24:45 +01:00
if ( method_exists ( $module , 'info' )) {
print $module -> info ( $langs );
} else {
print $module -> description ;
}
2020-05-31 22:59:33 +02:00
print '</td>' ;
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
// Active
2021-01-06 20:24:45 +01:00
if ( in_array ( $name , $def )) {
2020-05-31 22:59:33 +02:00
print '<td class="center">' . " \n " ;
2021-09-19 14:41:46 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?action=del&token=' . newToken () . '&value=' . urlencode ( $name ) . '">' ;
2020-05-31 22:59:33 +02:00
print img_picto ( $langs -> trans ( " Enabled " ), 'switch_on' );
print '</a>' ;
print '</td>' ;
} else {
print '<td class="center">' . " \n " ;
2021-09-19 14:41:46 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?action=set&token=' . newToken () . '&value=' . urlencode ( $name ) . '&scan_dir=' . urlencode ( $module -> scandir ) . '&label=' . urlencode ( $module -> name ) . '">' . img_picto ( $langs -> trans ( " Disabled " ), 'switch_off' ) . '</a>' ;
2020-05-31 22:59:33 +02:00
print " </td> " ;
}
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
// Default
print '<td class="center">' ;
$constforvar = 'MYMODULE_' . strtoupper ( $myTmpObjectKey ) . '_ADDON' ;
2020-12-11 14:22:36 +01:00
if ( $conf -> global -> $constforvar == $name ) {
//print img_picto($langs->trans("Default"), 'on');
// Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset
2021-09-19 18:03:38 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?action=unsetdoc&token=' . newToken () . '&object=' . urlencode ( strtolower ( $myTmpObjectKey )) . '&value=' . urlencode ( $name ) . '&scan_dir=' . urlencode ( $module -> scandir ) . '&label=' . urlencode ( $module -> name ) . '&type=' . urlencode ( $type ) . '" alt="' . $langs -> trans ( " Disable " ) . '">' . img_picto ( $langs -> trans ( " Enabled " ), 'on' ) . '</a>' ;
2020-05-31 22:59:33 +02:00
} else {
2021-09-19 18:03:38 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?action=setdoc&token=' . newToken () . '&object=' . urlencode ( strtolower ( $myTmpObjectKey )) . '&value=' . urlencode ( $name ) . '&scan_dir=' . urlencode ( $module -> scandir ) . '&label=' . urlencode ( $module -> name ) . '" alt="' . $langs -> trans ( " Default " ) . '">' . img_picto ( $langs -> trans ( " Disabled " ), 'off' ) . '</a>' ;
2020-05-31 22:59:33 +02:00
}
print '</td>' ;
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
// Info
$htmltooltip = '' . $langs -> trans ( " Name " ) . ': ' . $module -> name ;
$htmltooltip .= '<br>' . $langs -> trans ( " Type " ) . ': ' . ( $module -> type ? $module -> type : $langs -> trans ( " Unknown " ));
2021-01-06 20:24:45 +01:00
if ( $module -> type == 'pdf' ) {
2020-05-31 22:59:33 +02:00
$htmltooltip .= '<br>' . $langs -> trans ( " Width " ) . '/' . $langs -> trans ( " Height " ) . ': ' . $module -> page_largeur . '/' . $module -> page_hauteur ;
}
$htmltooltip .= '<br>' . $langs -> trans ( " Path " ) . ': ' . preg_replace ( '/^\//' , '' , $realpath ) . '/' . $file ;
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
$htmltooltip .= '<br><br><u>' . $langs -> trans ( " FeaturesSupported " ) . ':</u>' ;
$htmltooltip .= '<br>' . $langs -> trans ( " Logo " ) . ': ' . yn ( $module -> option_logo , 1 , 1 );
$htmltooltip .= '<br>' . $langs -> trans ( " MultiLanguage " ) . ': ' . yn ( $module -> option_multilang , 1 , 1 );
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
print '<td class="center">' ;
print $form -> textwithpicto ( '' , $htmltooltip , 1 , 0 );
print '</td>' ;
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
// Preview
print '<td class="center">' ;
2021-01-06 20:24:45 +01:00
if ( $module -> type == 'pdf' ) {
2020-12-03 13:19:35 +01:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?action=specimen&module=' . $name . '&object=' . $myTmpObjectKey . '">' . img_object ( $langs -> trans ( " Preview " ), 'pdf' ) . '</a>' ;
2020-05-31 22:59:33 +02:00
} else {
print img_object ( $langs -> trans ( " PreviewNotAvailable " ), 'generic' );
}
print '</td>' ;
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
print " </tr> \n " ;
}
}
}
}
}
}
}
}
2020-06-01 04:02:47 +02:00
2020-05-31 22:59:33 +02:00
print '</table>' ;
}
}
2020-06-01 04:02:47 +02:00
if ( empty ( $setupnotempty )) {
print '<br>' . $langs -> trans ( " NothingToSetup " );
}
2020-05-31 22:59:33 +02:00
2017-05-08 21:00:23 +02:00
// Page end
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2017-08-26 15:22:13 +02:00
2017-05-08 21:00:23 +02:00
llxFooter ();
2017-08-26 15:22:13 +02:00
$db -> close ();