setup.php 26 KB

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