setup.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. <?php
  2. /* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) ---Put here your own copyright and developer email---
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/modulebuilder/template/admin/setup.php
  20. * \ingroup mymodule
  21. * \brief MyModule setup page.
  22. */
  23. // Load Dolibarr environment
  24. $res = 0;
  25. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  26. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
  27. $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
  28. }
  29. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  30. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
  31. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  32. $i--; $j--;
  33. }
  34. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
  35. $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
  36. }
  37. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
  38. $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
  39. }
  40. // Try main.inc.php using relative path
  41. if (!$res && file_exists("../../main.inc.php")) {
  42. $res = @include "../../main.inc.php";
  43. }
  44. if (!$res && file_exists("../../../main.inc.php")) {
  45. $res = @include "../../../main.inc.php";
  46. }
  47. if (!$res) {
  48. die("Include of main fails");
  49. }
  50. global $langs, $user;
  51. // Libraries
  52. require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
  53. require_once '../lib/mymodule.lib.php';
  54. //require_once "../class/myclass.class.php";
  55. // Translations
  56. $langs->loadLangs(array("admin", "mymodule@mymodule"));
  57. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  58. $hookmanager->initHooks(array('mymodulesetup', 'globalsetup'));
  59. // Access control
  60. if (!$user->admin) {
  61. accessforbidden();
  62. }
  63. // Parameters
  64. $action = GETPOST('action', 'aZ09');
  65. $backtopage = GETPOST('backtopage', 'alpha');
  66. $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
  67. $value = GETPOST('value', 'alpha');
  68. $label = GETPOST('label', 'alpha');
  69. $scandir = GETPOST('scan_dir', 'alpha');
  70. $type = 'myobject';
  71. $arrayofparameters = array(
  72. 'MYMODULE_MYPARAM1'=>array('type'=>'string', 'css'=>'minwidth500' ,'enabled'=>1),
  73. 'MYMODULE_MYPARAM2'=>array('type'=>'textarea','enabled'=>1),
  74. //'MYMODULE_MYPARAM3'=>array('type'=>'category:'.Categorie::TYPE_CUSTOMER, 'enabled'=>1),
  75. //'MYMODULE_MYPARAM4'=>array('type'=>'emailtemplate:thirdparty', 'enabled'=>1),
  76. //'MYMODULE_MYPARAM5'=>array('type'=>'yesno', 'enabled'=>1),
  77. //'MYMODULE_MYPARAM5'=>array('type'=>'thirdparty_type', 'enabled'=>1),
  78. //'MYMODULE_MYPARAM6'=>array('type'=>'securekey', 'enabled'=>1),
  79. //'MYMODULE_MYPARAM7'=>array('type'=>'product', 'enabled'=>1),
  80. );
  81. $error = 0;
  82. $setupnotempty = 0;
  83. // Set this to 1 to use the factory to manage constants. Warning, the generated module will be compatible with version v15+ only
  84. $useFormSetup = 0;
  85. // Convert arrayofparameter into a formSetup object
  86. if ($useFormSetup && (float) DOL_VERSION >= 15) {
  87. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php';
  88. $formSetup = new FormSetup($db);
  89. // you can use the param convertor
  90. $formSetup->addItemsFromParamsArray($arrayofparameters);
  91. // or use the new system see exemple as follow (or use both because you can ;-) )
  92. /*
  93. // Hôte
  94. $item = $formSetup->newItem('NO_PARAM_JUST_TEXT');
  95. $item->fieldOverride = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'];
  96. $item->cssClass = 'minwidth500';
  97. // Setup conf MYMODULE_MYPARAM1 as a simple string input
  98. $item = $formSetup->newItem('MYMODULE_MYPARAM1');
  99. // Setup conf MYMODULE_MYPARAM1 as a simple textarea input but we replace the text of field title
  100. $item = $formSetup->newItem('MYMODULE_MYPARAM2');
  101. $item->nameText = $item->getNameText().' more html text ';
  102. // Setup conf MYMODULE_MYPARAM3
  103. $item = $formSetup->newItem('MYMODULE_MYPARAM3');
  104. $item->setAsThirdpartyType();
  105. // Setup conf MYMODULE_MYPARAM4 : exemple of quick define write style
  106. $formSetup->newItem('MYMODULE_MYPARAM4')->setAsYesNo();
  107. // Setup conf MYMODULE_MYPARAM5
  108. $formSetup->newItem('MYMODULE_MYPARAM5')->setAsEmailTemplate('thirdparty');
  109. // Setup conf MYMODULE_MYPARAM6
  110. $formSetup->newItem('MYMODULE_MYPARAM6')->setAsSecureKey()->enabled = 0; // disabled
  111. // Setup conf MYMODULE_MYPARAM7
  112. $formSetup->newItem('MYMODULE_MYPARAM7')->setAsProduct();
  113. */
  114. $setupnotempty = count($formSetup->items);
  115. }
  116. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  117. /*
  118. * Actions
  119. */
  120. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  121. if ($action == 'updateMask') {
  122. $maskconst = GETPOST('maskconst', 'alpha');
  123. $maskvalue = GETPOST('maskvalue', 'alpha');
  124. if ($maskconst) {
  125. $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
  126. if (!($res > 0)) {
  127. $error++;
  128. }
  129. }
  130. if (!$error) {
  131. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  132. } else {
  133. setEventMessages($langs->trans("Error"), null, 'errors');
  134. }
  135. } elseif ($action == 'specimen') {
  136. $modele = GETPOST('module', 'alpha');
  137. $tmpobjectkey = GETPOST('object');
  138. $tmpobject = new $tmpobjectkey($db);
  139. $tmpobject->initAsSpecimen();
  140. // Search template files
  141. $file = ''; $classname = ''; $filefound = 0;
  142. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  143. foreach ($dirmodels as $reldir) {
  144. $file = dol_buildpath($reldir."core/modules/mymodule/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0);
  145. if (file_exists($file)) {
  146. $filefound = 1;
  147. $classname = "pdf_".$modele."_".strtolower($tmpobjectkey);
  148. break;
  149. }
  150. }
  151. if ($filefound) {
  152. require_once $file;
  153. $module = new $classname($db);
  154. if ($module->write_file($tmpobject, $langs) > 0) {
  155. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=mymodule-".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
  156. return;
  157. } else {
  158. setEventMessages($module->error, null, 'errors');
  159. dol_syslog($module->error, LOG_ERR);
  160. }
  161. } else {
  162. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  163. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  164. }
  165. } elseif ($action == 'setmod') {
  166. // TODO Check if numbering module chosen can be activated by calling method canBeActivated
  167. $tmpobjectkey = GETPOST('object');
  168. if (!empty($tmpobjectkey)) {
  169. $constforval = 'MYMODULE_'.strtoupper($tmpobjectkey)."_ADDON";
  170. dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
  171. }
  172. } elseif ($action == 'set') {
  173. // Activate a model
  174. $ret = addDocumentModel($value, $type, $label, $scandir);
  175. } elseif ($action == 'del') {
  176. $ret = delDocumentModel($value, $type);
  177. if ($ret > 0) {
  178. $tmpobjectkey = GETPOST('object');
  179. if (!empty($tmpobjectkey)) {
  180. $constforval = 'MYMODULE_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
  181. if ($conf->global->$constforval == "$value") {
  182. dolibarr_del_const($db, $constforval, $conf->entity);
  183. }
  184. }
  185. }
  186. } elseif ($action == 'setdoc') {
  187. // Set or unset default model
  188. $tmpobjectkey = GETPOST('object');
  189. if (!empty($tmpobjectkey)) {
  190. $constforval = 'MYMODULE_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
  191. if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
  192. // The constant that was read before the new set
  193. // We therefore requires a variable to have a coherent view
  194. $conf->global->$constforval = $value;
  195. }
  196. // We disable/enable the document template (into llx_document_model table)
  197. $ret = delDocumentModel($value, $type);
  198. if ($ret > 0) {
  199. $ret = addDocumentModel($value, $type, $label, $scandir);
  200. }
  201. }
  202. } elseif ($action == 'unsetdoc') {
  203. $tmpobjectkey = GETPOST('object');
  204. if (!empty($tmpobjectkey)) {
  205. $constforval = 'MYMODULE_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
  206. dolibarr_del_const($db, $constforval, $conf->entity);
  207. }
  208. }
  209. /*
  210. * View
  211. */
  212. $form = new Form($db);
  213. $help_url = '';
  214. $page_name = "MyModuleSetup";
  215. llxHeader('', $langs->trans($page_name), $help_url);
  216. // Subheader
  217. $linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
  218. print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
  219. // Configuration header
  220. $head = mymoduleAdminPrepareHead();
  221. print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "mymodule@mymodule");
  222. // Setup page goes here
  223. echo '<span class="opacitymedium">'.$langs->trans("MyModuleSetupPage").'</span><br><br>';
  224. if ($action == 'edit') {
  225. if ($useFormSetup && (float) DOL_VERSION >= 15) {
  226. print $formSetup->generateOutput(true);
  227. } else {
  228. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  229. print '<input type="hidden" name="token" value="'.newToken().'">';
  230. print '<input type="hidden" name="action" value="update">';
  231. print '<table class="noborder centpercent">';
  232. print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  233. foreach ($arrayofparameters as $constname => $val) {
  234. if ($val['enabled']==1) {
  235. $setupnotempty++;
  236. print '<tr class="oddeven"><td>';
  237. $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : '');
  238. print '<span id="helplink'.$constname.'" class="spanforparamtooltip">'.$form->textwithpicto($langs->trans($constname), $tooltiphelp, 1, 'info', '', 0, 3, 'tootips'.$constname).'</span>';
  239. print '</td><td>';
  240. if ($val['type'] == 'textarea') {
  241. print '<textarea class="flat" name="'.$constname.'" id="'.$constname.'" cols="50" rows="5" wrap="soft">' . "\n";
  242. print $conf->global->{$constname};
  243. print "</textarea>\n";
  244. } elseif ($val['type']== 'html') {
  245. require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
  246. $doleditor = new DolEditor($constname, $conf->global->{$constname}, '', 160, 'dolibarr_notes', '', false, false, $conf->fckeditor->enabled, ROWS_5, '90%');
  247. $doleditor->Create();
  248. } elseif ($val['type'] == 'yesno') {
  249. print $form->selectyesno($constname, $conf->global->{$constname}, 1);
  250. } elseif (preg_match('/emailtemplate:/', $val['type'])) {
  251. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
  252. $formmail = new FormMail($db);
  253. $tmp = explode(':', $val['type']);
  254. $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user, null, 1); // We set lang=null to get in priority record with no lang
  255. //$arraydefaultmessage = $formmail->getEMailTemplate($db, $tmp[1], $user, null, 0, 1, '');
  256. $arrayofmessagename = array();
  257. if (is_array($formmail->lines_model)) {
  258. foreach ($formmail->lines_model as $modelmail) {
  259. //var_dump($modelmail);
  260. $moreonlabel = '';
  261. if (!empty($arrayofmessagename[$modelmail->label])) {
  262. $moreonlabel = ' <span class="opacitymedium">(' . $langs->trans("SeveralLangugeVariatFound") . ')</span>';
  263. }
  264. // The 'label' is the key that is unique if we exclude the language
  265. $arrayofmessagename[$modelmail->id] = $langs->trans(preg_replace('/\(|\)/', '', $modelmail->label)) . $moreonlabel;
  266. }
  267. }
  268. print $form->selectarray($constname, $arrayofmessagename, $conf->global->{$constname}, 'None', 0, 0, '', 0, 0, 0, '', '', 1);
  269. } elseif (preg_match('/category:/', $val['type'])) {
  270. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  271. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  272. $formother = new FormOther($db);
  273. $tmp = explode(':', $val['type']);
  274. print img_picto('', 'category', 'class="pictofixedwidth"');
  275. print $formother->select_categories($tmp[1], $conf->global->{$constname}, $constname, 0, $langs->trans('CustomersProspectsCategoriesShort'));
  276. } elseif (preg_match('/thirdparty_type/', $val['type'])) {
  277. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  278. $formcompany = new FormCompany($db);
  279. print $formcompany->selectProspectCustomerType($conf->global->{$constname}, $constname);
  280. } elseif ($val['type'] == 'securekey') {
  281. print '<input required="required" type="text" class="flat" id="'.$constname.'" name="'.$constname.'" value="'.(GETPOST($constname, 'alpha') ?GETPOST($constname, 'alpha') : $conf->global->{$constname}).'" size="40">';
  282. if (!empty($conf->use_javascript_ajax)) {
  283. print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token'.$constname.'" class="linkobject"');
  284. }
  285. if (!empty($conf->use_javascript_ajax)) {
  286. print "\n".'<script type="text/javascript">';
  287. print '$(document).ready(function () {
  288. $("#generate_token'.$constname.'").click(function() {
  289. $.get( "'.DOL_URL_ROOT.'/core/ajax/security.php", {
  290. action: \'getrandompassword\',
  291. generic: true
  292. },
  293. function(token) {
  294. $("#'.$constname.'").val(token);
  295. });
  296. });
  297. });';
  298. print '</script>';
  299. }
  300. } elseif ($val['type'] == 'product') {
  301. if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) {
  302. $selected = (empty($conf->global->$constname) ? '' : $conf->global->$constname);
  303. $form->select_produits($selected, $constname, '', 0);
  304. }
  305. } else {
  306. print '<input name="'.$constname.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.$conf->global->{$constname}.'">';
  307. }
  308. print '</td></tr>';
  309. }
  310. }
  311. print '</table>';
  312. print '<br><div class="center">';
  313. print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
  314. print '</div>';
  315. print '</form>';
  316. }
  317. print '<br>';
  318. } else {
  319. if ($useFormSetup && (float) DOL_VERSION >= 15) {
  320. if (!empty($formSetup->items)) {
  321. print $formSetup->generateOutput();
  322. }
  323. } else {
  324. if (!empty($arrayofparameters)) {
  325. print '<table class="noborder centpercent">';
  326. print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  327. foreach ($arrayofparameters as $constname => $val) {
  328. if ($val['enabled']==1) {
  329. $setupnotempty++;
  330. print '<tr class="oddeven"><td>';
  331. $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : '');
  332. print $form->textwithpicto($langs->trans($constname), $tooltiphelp);
  333. print '</td><td>';
  334. if ($val['type'] == 'textarea') {
  335. print dol_nl2br($conf->global->{$constname});
  336. } elseif ($val['type']== 'html') {
  337. print $conf->global->{$constname};
  338. } elseif ($val['type'] == 'yesno') {
  339. print ajax_constantonoff($constname);
  340. } elseif (preg_match('/emailtemplate:/', $val['type'])) {
  341. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
  342. $formmail = new FormMail($db);
  343. $tmp = explode(':', $val['type']);
  344. $template = $formmail->getEMailTemplate($db, $tmp[1], $user, $langs, $conf->global->{$constname});
  345. if ($template<0) {
  346. setEventMessages(null, $formmail->errors, 'errors');
  347. }
  348. print $langs->trans($template->label);
  349. } elseif (preg_match('/category:/', $val['type'])) {
  350. $c = new Categorie($db);
  351. $result = $c->fetch($conf->global->{$constname});
  352. if ($result < 0) {
  353. setEventMessages(null, $c->errors, 'errors');
  354. } elseif ($result > 0 ) {
  355. $ways = $c->print_all_ways(' &gt;&gt; ', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formated text
  356. $toprint = array();
  357. foreach ($ways as $way) {
  358. $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ? ' style="background: #' . $c->color . ';"' : ' style="background: #bbb"') . '>' . $way . '</li>';
  359. }
  360. print '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
  361. }
  362. } elseif (preg_match('/thirdparty_type/', $val['type'])) {
  363. if ($conf->global->{$constname}==2) {
  364. print $langs->trans("Prospect");
  365. } elseif ($conf->global->{$constname}==3) {
  366. print $langs->trans("ProspectCustomer");
  367. } elseif ($conf->global->{$constname}==1) {
  368. print $langs->trans("Customer");
  369. } elseif ($conf->global->{$constname}==0) {
  370. print $langs->trans("NorProspectNorCustomer");
  371. }
  372. } elseif ($val['type'] == 'product') {
  373. $product = new Product($db);
  374. $resprod = $product->fetch($conf->global->{$constname});
  375. if ($resprod > 0) {
  376. print $product->ref;
  377. } elseif ($resprod < 0) {
  378. setEventMessages(null, $product->errors, "errors");
  379. }
  380. } else {
  381. print $conf->global->{$constname};
  382. }
  383. print '</td></tr>';
  384. }
  385. }
  386. print '</table>';
  387. }
  388. }
  389. if ($setupnotempty) {
  390. print '<div class="tabsAction">';
  391. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
  392. print '</div>';
  393. } else {
  394. print '<br>'.$langs->trans("NothingToSetup");
  395. }
  396. }
  397. $moduledir = 'mymodule';
  398. $myTmpObjects = array();
  399. $myTmpObjects['MyObject'] = array('includerefgeneration'=>0, 'includedocgeneration'=>0);
  400. foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
  401. if ($myTmpObjectKey == 'MyObject') {
  402. continue;
  403. }
  404. if ($myTmpObjectArray['includerefgeneration']) {
  405. /*
  406. * Orders Numbering model
  407. */
  408. $setupnotempty++;
  409. print load_fiche_titre($langs->trans("NumberingModules", $myTmpObjectKey), '', '');
  410. print '<table class="noborder centpercent">';
  411. print '<tr class="liste_titre">';
  412. print '<td>'.$langs->trans("Name").'</td>';
  413. print '<td>'.$langs->trans("Description").'</td>';
  414. print '<td class="nowrap">'.$langs->trans("Example").'</td>';
  415. print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
  416. print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  417. print '</tr>'."\n";
  418. clearstatcache();
  419. foreach ($dirmodels as $reldir) {
  420. $dir = dol_buildpath($reldir."core/modules/".$moduledir);
  421. if (is_dir($dir)) {
  422. $handle = opendir($dir);
  423. if (is_resource($handle)) {
  424. while (($file = readdir($handle)) !== false) {
  425. if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
  426. $file = substr($file, 0, dol_strlen($file) - 4);
  427. require_once $dir.'/'.$file.'.php';
  428. $module = new $file($db);
  429. // Show modules according to features level
  430. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
  431. continue;
  432. }
  433. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
  434. continue;
  435. }
  436. if ($module->isEnabled()) {
  437. dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
  438. print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
  439. print $module->info();
  440. print '</td>';
  441. // Show example of numbering model
  442. print '<td class="nowrap">';
  443. $tmp = $module->getExample();
  444. if (preg_match('/^Error/', $tmp)) {
  445. $langs->load("errors");
  446. print '<div class="error">'.$langs->trans($tmp).'</div>';
  447. } elseif ($tmp == 'NotConfigured') {
  448. print $langs->trans($tmp);
  449. } else {
  450. print $tmp;
  451. }
  452. print '</td>'."\n";
  453. print '<td class="center">';
  454. $constforvar = 'MYMODULE_'.strtoupper($myTmpObjectKey).'_ADDON';
  455. if (getDolGlobalString($constforvar) == $file) {
  456. print img_picto($langs->trans("Activated"), 'switch_on');
  457. } else {
  458. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.urlencode($file).'">';
  459. print img_picto($langs->trans("Disabled"), 'switch_off');
  460. print '</a>';
  461. }
  462. print '</td>';
  463. $mytmpinstance = new $myTmpObjectKey($db);
  464. $mytmpinstance->initAsSpecimen();
  465. // Info
  466. $htmltooltip = '';
  467. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  468. $nextval = $module->getNextValue($mytmpinstance);
  469. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  470. $htmltooltip .= ''.$langs->trans("NextValue").': ';
  471. if ($nextval) {
  472. if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
  473. $nextval = $langs->trans($nextval);
  474. }
  475. $htmltooltip .= $nextval.'<br>';
  476. } else {
  477. $htmltooltip .= $langs->trans($module->error).'<br>';
  478. }
  479. }
  480. print '<td class="center">';
  481. print $form->textwithpicto('', $htmltooltip, 1, 0);
  482. print '</td>';
  483. print "</tr>\n";
  484. }
  485. }
  486. }
  487. closedir($handle);
  488. }
  489. }
  490. }
  491. print "</table><br>\n";
  492. }
  493. if ($myTmpObjectArray['includedocgeneration']) {
  494. /*
  495. * Document templates generators
  496. */
  497. $setupnotempty++;
  498. $type = strtolower($myTmpObjectKey);
  499. print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
  500. // Load array def with activated templates
  501. $def = array();
  502. $sql = "SELECT nom";
  503. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  504. $sql .= " WHERE type = '".$db->escape($type)."'";
  505. $sql .= " AND entity = ".$conf->entity;
  506. $resql = $db->query($sql);
  507. if ($resql) {
  508. $i = 0;
  509. $num_rows = $db->num_rows($resql);
  510. while ($i < $num_rows) {
  511. $array = $db->fetch_array($resql);
  512. array_push($def, $array[0]);
  513. $i++;
  514. }
  515. } else {
  516. dol_print_error($db);
  517. }
  518. print "<table class=\"noborder\" width=\"100%\">\n";
  519. print "<tr class=\"liste_titre\">\n";
  520. print '<td>'.$langs->trans("Name").'</td>';
  521. print '<td>'.$langs->trans("Description").'</td>';
  522. print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
  523. print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
  524. print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
  525. print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
  526. print "</tr>\n";
  527. clearstatcache();
  528. foreach ($dirmodels as $reldir) {
  529. foreach (array('', '/doc') as $valdir) {
  530. $realpath = $reldir."core/modules/".$moduledir.$valdir;
  531. $dir = dol_buildpath($realpath);
  532. if (is_dir($dir)) {
  533. $handle = opendir($dir);
  534. if (is_resource($handle)) {
  535. while (($file = readdir($handle)) !== false) {
  536. $filelist[] = $file;
  537. }
  538. closedir($handle);
  539. arsort($filelist);
  540. foreach ($filelist as $file) {
  541. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
  542. if (file_exists($dir.'/'.$file)) {
  543. $name = substr($file, 4, dol_strlen($file) - 16);
  544. $classname = substr($file, 0, dol_strlen($file) - 12);
  545. require_once $dir.'/'.$file;
  546. $module = new $classname($db);
  547. $modulequalified = 1;
  548. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
  549. $modulequalified = 0;
  550. }
  551. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
  552. $modulequalified = 0;
  553. }
  554. if ($modulequalified) {
  555. print '<tr class="oddeven"><td width="100">';
  556. print (empty($module->name) ? $name : $module->name);
  557. print "</td><td>\n";
  558. if (method_exists($module, 'info')) {
  559. print $module->info($langs);
  560. } else {
  561. print $module->description;
  562. }
  563. print '</td>';
  564. // Active
  565. if (in_array($name, $def)) {
  566. print '<td class="center">'."\n";
  567. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
  568. print img_picto($langs->trans("Enabled"), 'switch_on');
  569. print '</a>';
  570. print '</td>';
  571. } else {
  572. print '<td class="center">'."\n";
  573. 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>';
  574. print "</td>";
  575. }
  576. // Default
  577. print '<td class="center">';
  578. $constforvar = 'MYMODULE_'.strtoupper($myTmpObjectKey).'_ADDON';
  579. if (getDolGlobalString($constforvar) == $name) {
  580. //print img_picto($langs->trans("Default"), 'on');
  581. // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset
  582. 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).'&amp;type='.urlencode($type).'" alt="'.$langs->trans("Disable").'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
  583. } else {
  584. 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>';
  585. }
  586. print '</td>';
  587. // Info
  588. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  589. $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  590. if ($module->type == 'pdf') {
  591. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  592. }
  593. $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
  594. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  595. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  596. $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
  597. print '<td class="center">';
  598. print $form->textwithpicto('', $htmltooltip, 1, 0);
  599. print '</td>';
  600. // Preview
  601. print '<td class="center">';
  602. if ($module->type == 'pdf') {
  603. $newname = preg_replace('/_'.preg_quote(strtolower($myTmpObjectKey), '/').'/', '', $name);
  604. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.urlencode($newname).'&object='.urlencode($myTmpObjectKey).'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
  605. } else {
  606. print img_object($langs->trans("PreviewNotAvailable"), 'generic');
  607. }
  608. print '</td>';
  609. print "</tr>\n";
  610. }
  611. }
  612. }
  613. }
  614. }
  615. }
  616. }
  617. }
  618. print '</table>';
  619. }
  620. }
  621. if (empty($setupnotempty)) {
  622. print '<br>'.$langs->trans("NothingToSetup");
  623. }
  624. // Page end
  625. print dol_get_fiche_end();
  626. llxFooter();
  627. $db->close();