setup.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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. // Access control
  58. if (!$user->admin) {
  59. accessforbidden();
  60. }
  61. // Parameters
  62. $action = GETPOST('action', 'aZ09');
  63. $backtopage = GETPOST('backtopage', 'alpha');
  64. $value = GETPOST('value', 'alpha');
  65. $label = GETPOST('label', 'alpha');
  66. $scandir = GETPOST('scan_dir', 'alpha');
  67. $type = 'myobject';
  68. $arrayofparameters = array(
  69. 'MYMODULE_MYPARAM1'=>array('type'=>'string', 'css'=>'minwidth500' ,'enabled'=>1),
  70. 'MYMODULE_MYPARAM2'=>array('type'=>'textarea','enabled'=>1),
  71. //'MYMODULE_MYPARAM3'=>array('type'=>'category:'.Categorie::TYPE_CUSTOMER, 'enabled'=>1),
  72. //'MYMODULE_MYPARAM4'=>array('type'=>'emailtemplate:thirdparty', 'enabled'=>1),
  73. //'MYMODULE_MYPARAM5'=>array('type'=>'yesno', 'enabled'=>1),
  74. //'MYMODULE_MYPARAM5'=>array('type'=>'thirdparty_type', 'enabled'=>1),
  75. //'MYMODULE_MYPARAM6'=>array('type'=>'securekey', 'enabled'=>1),
  76. //'MYMODULE_MYPARAM7'=>array('type'=>'product', 'enabled'=>1),
  77. );
  78. $error = 0;
  79. $setupnotempty = 0;
  80. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  81. /*
  82. * Actions
  83. */
  84. if ((float) DOL_VERSION >= 6) {
  85. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  86. }
  87. if ($action == 'updateMask') {
  88. $maskconstorder = GETPOST('maskconstorder', 'alpha');
  89. $maskorder = GETPOST('maskorder', 'alpha');
  90. if ($maskconstorder) {
  91. $res = dolibarr_set_const($db, $maskconstorder, $maskorder, 'chaine', 0, '', $conf->entity);
  92. if (!($res > 0)) {
  93. $error++;
  94. }
  95. }
  96. if (!$error) {
  97. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  98. } else {
  99. setEventMessages($langs->trans("Error"), null, 'errors');
  100. }
  101. } elseif ($action == 'specimen') {
  102. $modele = GETPOST('module', 'alpha');
  103. $tmpobjectkey = GETPOST('object');
  104. $tmpobject = new $tmpobjectkey($db);
  105. $tmpobject->initAsSpecimen();
  106. // Search template files
  107. $file = ''; $classname = ''; $filefound = 0;
  108. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  109. foreach ($dirmodels as $reldir) {
  110. $file = dol_buildpath($reldir."core/modules/mymodule/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0);
  111. if (file_exists($file)) {
  112. $filefound = 1;
  113. $classname = "pdf_".$modele;
  114. break;
  115. }
  116. }
  117. if ($filefound) {
  118. require_once $file;
  119. $module = new $classname($db);
  120. if ($module->write_file($tmpobject, $langs) > 0) {
  121. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
  122. return;
  123. } else {
  124. setEventMessages($module->error, null, 'errors');
  125. dol_syslog($module->error, LOG_ERR);
  126. }
  127. } else {
  128. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  129. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  130. }
  131. } elseif ($action == 'setmod') {
  132. // TODO Check if numbering module chosen can be activated by calling method canBeActivated
  133. $tmpobjectkey = GETPOST('object');
  134. if (!empty($tmpobjectkey)) {
  135. $constforval = 'MYMODULE_'.strtoupper($tmpobjectkey)."_ADDON";
  136. dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
  137. }
  138. } elseif ($action == 'set') {
  139. // Activate a model
  140. $ret = addDocumentModel($value, $type, $label, $scandir);
  141. } elseif ($action == 'del') {
  142. $ret = delDocumentModel($value, $type);
  143. if ($ret > 0) {
  144. $tmpobjectkey = GETPOST('object');
  145. if (!empty($tmpobjectkey)) {
  146. $constforval = 'MYMODULE_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
  147. if ($conf->global->$constforval == "$value") {
  148. dolibarr_del_const($db, $constforval, $conf->entity);
  149. }
  150. }
  151. }
  152. } elseif ($action == 'setdoc') {
  153. // Set or unset default model
  154. $tmpobjectkey = GETPOST('object');
  155. if (!empty($tmpobjectkey)) {
  156. $constforval = 'MYMODULE_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
  157. if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
  158. // The constant that was read before the new set
  159. // We therefore requires a variable to have a coherent view
  160. $conf->global->$constforval = $value;
  161. }
  162. // We disable/enable the document template (into llx_document_model table)
  163. $ret = delDocumentModel($value, $type);
  164. if ($ret > 0) {
  165. $ret = addDocumentModel($value, $type, $label, $scandir);
  166. }
  167. }
  168. } elseif ($action == 'unsetdoc') {
  169. $tmpobjectkey = GETPOST('object');
  170. if (!empty($tmpobjectkey)) {
  171. $constforval = 'MYMODULE_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
  172. dolibarr_del_const($db, $constforval, $conf->entity);
  173. }
  174. }
  175. /*
  176. * View
  177. */
  178. $form = new Form($db);
  179. $help_url = '';
  180. $page_name = "MyModuleSetup";
  181. llxHeader('', $langs->trans($page_name), $help_url);
  182. // Subheader
  183. $linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
  184. print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
  185. // Configuration header
  186. $head = mymoduleAdminPrepareHead();
  187. print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "mymodule@mymodule");
  188. // Setup page goes here
  189. echo '<span class="opacitymedium">'.$langs->trans("MyModuleSetupPage").'</span><br><br>';
  190. if ($action == 'edit') {
  191. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  192. print '<input type="hidden" name="token" value="'.newToken().'">';
  193. print '<input type="hidden" name="action" value="update">';
  194. print '<table class="noborder centpercent">';
  195. print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  196. foreach ($arrayofparameters as $constname => $val) {
  197. if ($val['enabled']==1) {
  198. $setupnotempty++;
  199. print '<tr class="oddeven"><td>';
  200. $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : '');
  201. print '<span id="helplink'.$constname.'" class="spanforparamtooltip">'.$form->textwithpicto($langs->trans($constname), $tooltiphelp, 1, 'info', '', 0, 3, 'tootips'.$constname).'</span>';
  202. print '</td><td>';
  203. if ($val['type'] == 'textarea') {
  204. print '<textarea class="flat" name="'.$constname.'" id="'.$constname.'" cols="50" rows="5" wrap="soft">' . "\n";
  205. print $conf->global->{$constname};
  206. print "</textarea>\n";
  207. } elseif ($val['type']== 'html') {
  208. require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
  209. $doleditor = new DolEditor($constname, $conf->global->{$constname}, '', 160, 'dolibarr_notes', '', false, false, $conf->fckeditor->enabled, ROWS_5, '90%');
  210. $doleditor->Create();
  211. } elseif ($val['type'] == 'yesno') {
  212. print $form->selectyesno($constname, $conf->global->{$constname}, 1);
  213. } elseif (preg_match('/emailtemplate:/', $val['type'])) {
  214. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
  215. $formmail = new FormMail($db);
  216. $tmp = explode(':', $val['type']);
  217. $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user, null, 1); // We set lang=null to get in priority record with no lang
  218. //$arraydefaultmessage = $formmail->getEMailTemplate($db, $tmp[1], $user, null, 0, 1, '');
  219. $arrayofmessagename = array();
  220. if (is_array($formmail->lines_model)) {
  221. foreach ($formmail->lines_model as $modelmail) {
  222. //var_dump($modelmail);
  223. $moreonlabel = '';
  224. if (!empty($arrayofmessagename[$modelmail->label])) {
  225. $moreonlabel = ' <span class="opacitymedium">(' . $langs->trans("SeveralLangugeVariatFound") . ')</span>';
  226. }
  227. // The 'label' is the key that is unique if we exclude the language
  228. $arrayofmessagename[$modelmail->id] = $langs->trans(preg_replace('/\(|\)/', '', $modelmail->label)) . $moreonlabel;
  229. }
  230. }
  231. print $form->selectarray($constname, $arrayofmessagename, $conf->global->{$constname}, 'None', 0, 0, '', 0, 0, 0, '', '', 1);
  232. } elseif (preg_match('/category:/', $val['type'])) {
  233. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  234. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  235. $formother = new FormOther($db);
  236. $tmp = explode(':', $val['type']);
  237. print img_picto('', 'category', 'class="pictofixedwidth"');
  238. print $formother->select_categories($tmp[1], $conf->global->{$constname}, $constname, 0, $langs->trans('CustomersProspectsCategoriesShort'));
  239. } elseif (preg_match('/thirdparty_type/', $val['type'])) {
  240. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  241. $formcompany = new FormCompany($db);
  242. print $formcompany->selectProspectCustomerType($conf->global->{$constname}, $constname);
  243. } elseif ($val['type'] == 'securekey') {
  244. print '<input required="required" type="text" class="flat" id="'.$constname.'" name="'.$constname.'" value="'.(GETPOST($constname, 'alpha') ?GETPOST($constname, 'alpha') : $conf->global->{$constname}).'" size="40">';
  245. if (!empty($conf->use_javascript_ajax)) {
  246. print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token'.$constname.'" class="linkobject"');
  247. }
  248. if (!empty($conf->use_javascript_ajax)) {
  249. print "\n".'<script type="text/javascript">';
  250. print '$(document).ready(function () {
  251. $("#generate_token'.$constname.'").click(function() {
  252. $.get( "'.DOL_URL_ROOT.'/core/ajax/security.php", {
  253. action: \'getrandompassword\',
  254. generic: true
  255. },
  256. function(token) {
  257. $("#'.$constname.'").val(token);
  258. });
  259. });
  260. });';
  261. print '</script>';
  262. }
  263. } elseif ($val['type'] == 'product') {
  264. if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) {
  265. $selected = (empty($conf->global->$constname) ? '' : $conf->global->$constname);
  266. $form->select_produits($selected, $constname, '', 0);
  267. }
  268. } else {
  269. print '<input name="'.$constname.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.$conf->global->{$constname}.'">';
  270. }
  271. print '</td></tr>';
  272. }
  273. }
  274. print '</table>';
  275. print '<br><div class="center">';
  276. print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
  277. print '</div>';
  278. print '</form>';
  279. print '<br>';
  280. } else {
  281. if (!empty($arrayofparameters)) {
  282. print '<table class="noborder centpercent">';
  283. print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  284. foreach ($arrayofparameters as $constname => $val) {
  285. if ($val['enabled']==1) {
  286. $setupnotempty++;
  287. print '<tr class="oddeven"><td>';
  288. $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : '');
  289. print $form->textwithpicto($langs->trans($constname), $tooltiphelp);
  290. print '</td><td>';
  291. if ($val['type'] == 'textarea') {
  292. print dol_nl2br($conf->global->{$constname});
  293. } elseif ($val['type']== 'html') {
  294. print $conf->global->{$constname};
  295. } elseif ($val['type'] == 'yesno') {
  296. print ajax_constantonoff($constname);
  297. } elseif (preg_match('/emailtemplate:/', $val['type'])) {
  298. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
  299. $formmail = new FormMail($db);
  300. $tmp = explode(':', $val['type']);
  301. $template = $formmail->getEMailTemplate($db, $tmp[1], $user, $langs, $conf->global->{$constname});
  302. if ($template<0) {
  303. setEventMessages(null, $formmail->errors, 'errors');
  304. }
  305. print $langs->trans($template->label);
  306. } elseif (preg_match('/category:/', $val['type'])) {
  307. $c = new Categorie($db);
  308. $result = $c->fetch($conf->global->{$constname});
  309. if ($result < 0) {
  310. setEventMessages(null, $c->errors, 'errors');
  311. }
  312. $ways = $c->print_all_ways(' &gt;&gt; ', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formated text
  313. $toprint = array();
  314. foreach ($ways as $way) {
  315. $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ? ' style="background: #' . $c->color . ';"' : ' style="background: #bbb"') . '>' . $way . '</li>';
  316. }
  317. print '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
  318. } elseif (preg_match('/thirdparty_type/', $val['type'])) {
  319. if ($conf->global->{$constname}==2) {
  320. print $langs->trans("Prospect");
  321. } elseif ($conf->global->{$constname}==3) {
  322. print $langs->trans("ProspectCustomer");
  323. } elseif ($conf->global->{$constname}==1) {
  324. print $langs->trans("Customer");
  325. } elseif ($conf->global->{$constname}==0) {
  326. print $langs->trans("NorProspectNorCustomer");
  327. }
  328. } elseif ($val['type'] == 'product') {
  329. $product = new Product($db);
  330. $resprod = $product->fetch($conf->global->{$constname});
  331. if ($resprod > 0) {
  332. print $product->ref;
  333. } elseif ($resprod < 0) {
  334. setEventMessages(null, $object->errors, "errors");
  335. }
  336. } else {
  337. print $conf->global->{$constname};
  338. }
  339. print '</td></tr>';
  340. }
  341. }
  342. print '</table>';
  343. print '<div class="tabsAction">';
  344. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
  345. print '</div>';
  346. } else {
  347. print '<br>'.$langs->trans("NothingToSetup");
  348. }
  349. }
  350. $moduledir = 'mymodule';
  351. $myTmpObjects = array();
  352. $myTmpObjects['MyObject'] = array('includerefgeneration'=>0, 'includedocgeneration'=>0);
  353. foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
  354. if ($myTmpObjectKey == 'MyObject') {
  355. continue;
  356. }
  357. if ($myTmpObjectArray['includerefgeneration']) {
  358. /*
  359. * Orders Numbering model
  360. */
  361. $setupnotempty++;
  362. print load_fiche_titre($langs->trans("NumberingModules", $myTmpObjectKey), '', '');
  363. print '<table class="noborder centpercent">';
  364. print '<tr class="liste_titre">';
  365. print '<td>'.$langs->trans("Name").'</td>';
  366. print '<td>'.$langs->trans("Description").'</td>';
  367. print '<td class="nowrap">'.$langs->trans("Example").'</td>';
  368. print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
  369. print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  370. print '</tr>'."\n";
  371. clearstatcache();
  372. foreach ($dirmodels as $reldir) {
  373. $dir = dol_buildpath($reldir."core/modules/".$moduledir);
  374. if (is_dir($dir)) {
  375. $handle = opendir($dir);
  376. if (is_resource($handle)) {
  377. while (($file = readdir($handle)) !== false) {
  378. if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
  379. $file = substr($file, 0, dol_strlen($file) - 4);
  380. require_once $dir.'/'.$file.'.php';
  381. $module = new $file($db);
  382. // Show modules according to features level
  383. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
  384. continue;
  385. }
  386. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
  387. continue;
  388. }
  389. if ($module->isEnabled()) {
  390. dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
  391. print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
  392. print $module->info();
  393. print '</td>';
  394. // Show example of numbering model
  395. print '<td class="nowrap">';
  396. $tmp = $module->getExample();
  397. if (preg_match('/^Error/', $tmp)) {
  398. $langs->load("errors");
  399. print '<div class="error">'.$langs->trans($tmp).'</div>';
  400. } elseif ($tmp == 'NotConfigured') {
  401. print $langs->trans($tmp);
  402. } else {
  403. print $tmp;
  404. }
  405. print '</td>'."\n";
  406. print '<td class="center">';
  407. $constforvar = 'MYMODULE_'.strtoupper($myTmpObjectKey).'_ADDON';
  408. if ($conf->global->$constforvar == $file) {
  409. print img_picto($langs->trans("Activated"), 'switch_on');
  410. } else {
  411. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.urlencode($file).'">';
  412. print img_picto($langs->trans("Disabled"), 'switch_off');
  413. print '</a>';
  414. }
  415. print '</td>';
  416. $mytmpinstance = new $myTmpObjectKey($db);
  417. $mytmpinstance->initAsSpecimen();
  418. // Info
  419. $htmltooltip = '';
  420. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  421. $nextval = $module->getNextValue($mytmpinstance);
  422. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  423. $htmltooltip .= ''.$langs->trans("NextValue").': ';
  424. if ($nextval) {
  425. if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
  426. $nextval = $langs->trans($nextval);
  427. }
  428. $htmltooltip .= $nextval.'<br>';
  429. } else {
  430. $htmltooltip .= $langs->trans($module->error).'<br>';
  431. }
  432. }
  433. print '<td class="center">';
  434. print $form->textwithpicto('', $htmltooltip, 1, 0);
  435. print '</td>';
  436. print "</tr>\n";
  437. }
  438. }
  439. }
  440. closedir($handle);
  441. }
  442. }
  443. }
  444. print "</table><br>\n";
  445. }
  446. if ($myTmpObjectArray['includedocgeneration']) {
  447. /*
  448. * Document templates generators
  449. */
  450. $setupnotempty++;
  451. $type = strtolower($myTmpObjectKey);
  452. print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
  453. // Load array def with activated templates
  454. $def = array();
  455. $sql = "SELECT nom";
  456. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  457. $sql .= " WHERE type = '".$db->escape($type)."'";
  458. $sql .= " AND entity = ".$conf->entity;
  459. $resql = $db->query($sql);
  460. if ($resql) {
  461. $i = 0;
  462. $num_rows = $db->num_rows($resql);
  463. while ($i < $num_rows) {
  464. $array = $db->fetch_array($resql);
  465. array_push($def, $array[0]);
  466. $i++;
  467. }
  468. } else {
  469. dol_print_error($db);
  470. }
  471. print "<table class=\"noborder\" width=\"100%\">\n";
  472. print "<tr class=\"liste_titre\">\n";
  473. print '<td>'.$langs->trans("Name").'</td>';
  474. print '<td>'.$langs->trans("Description").'</td>';
  475. print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
  476. print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
  477. print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
  478. print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
  479. print "</tr>\n";
  480. clearstatcache();
  481. foreach ($dirmodels as $reldir) {
  482. foreach (array('', '/doc') as $valdir) {
  483. $realpath = $reldir."core/modules/".$moduledir.$valdir;
  484. $dir = dol_buildpath($realpath);
  485. if (is_dir($dir)) {
  486. $handle = opendir($dir);
  487. if (is_resource($handle)) {
  488. while (($file = readdir($handle)) !== false) {
  489. $filelist[] = $file;
  490. }
  491. closedir($handle);
  492. arsort($filelist);
  493. foreach ($filelist as $file) {
  494. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
  495. if (file_exists($dir.'/'.$file)) {
  496. $name = substr($file, 4, dol_strlen($file) - 16);
  497. $classname = substr($file, 0, dol_strlen($file) - 12);
  498. require_once $dir.'/'.$file;
  499. $module = new $classname($db);
  500. $modulequalified = 1;
  501. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
  502. $modulequalified = 0;
  503. }
  504. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
  505. $modulequalified = 0;
  506. }
  507. if ($modulequalified) {
  508. print '<tr class="oddeven"><td width="100">';
  509. print (empty($module->name) ? $name : $module->name);
  510. print "</td><td>\n";
  511. if (method_exists($module, 'info')) {
  512. print $module->info($langs);
  513. } else {
  514. print $module->description;
  515. }
  516. print '</td>';
  517. // Active
  518. if (in_array($name, $def)) {
  519. print '<td class="center">'."\n";
  520. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
  521. print img_picto($langs->trans("Enabled"), 'switch_on');
  522. print '</a>';
  523. print '</td>';
  524. } else {
  525. print '<td class="center">'."\n";
  526. 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>';
  527. print "</td>";
  528. }
  529. // Default
  530. print '<td class="center">';
  531. $constforvar = 'MYMODULE_'.strtoupper($myTmpObjectKey).'_ADDON';
  532. if ($conf->global->$constforvar == $name) {
  533. //print img_picto($langs->trans("Default"), 'on');
  534. // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset
  535. 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>';
  536. } else {
  537. 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>';
  538. }
  539. print '</td>';
  540. // Info
  541. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  542. $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  543. if ($module->type == 'pdf') {
  544. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  545. }
  546. $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
  547. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  548. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  549. $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
  550. print '<td class="center">';
  551. print $form->textwithpicto('', $htmltooltip, 1, 0);
  552. print '</td>';
  553. // Preview
  554. print '<td class="center">';
  555. if ($module->type == 'pdf') {
  556. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&object='.$myTmpObjectKey.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
  557. } else {
  558. print img_object($langs->trans("PreviewNotAvailable"), 'generic');
  559. }
  560. print '</td>';
  561. print "</tr>\n";
  562. }
  563. }
  564. }
  565. }
  566. }
  567. }
  568. }
  569. }
  570. print '</table>';
  571. }
  572. }
  573. if (empty($setupnotempty)) {
  574. print '<br>'.$langs->trans("NothingToSetup");
  575. }
  576. // Page end
  577. print dol_get_fiche_end();
  578. llxFooter();
  579. $db->close();