workstation.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. <?php
  2. /* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2020 Gauthier VERDOL <gauthier.verdol@atm-consulting.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/admin/workstation.php
  20. * \ingroup workstation
  21. * \brief Workstation setup page.
  22. */
  23. // Load Dolibarr environment
  24. require "../main.inc.php";
  25. // Libraries
  26. require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
  27. require_once DOL_DOCUMENT_ROOT.'/workstation/lib/workstation.lib.php';
  28. //require_once "../class/myclass.class.php";
  29. // Translations
  30. $langs->loadLangs(array("admin", "workstation"));
  31. // Parameters
  32. $action = GETPOST('action', 'aZ09');
  33. $backtopage = GETPOST('backtopage', 'alpha');
  34. $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
  35. $value = GETPOST('value', 'alpha');
  36. /*$arrayofparameters = array(
  37. 'WORKSTATION_MYPARAM1'=>array('css'=>'minwidth200', 'enabled'=>1),
  38. 'WORKSTATION_MYPARAM2'=>array('css'=>'minwidth500', 'enabled'=>1)
  39. );*/
  40. $error = 0;
  41. $setupnotempty = 0;
  42. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  43. // Access control
  44. if (!$user->admin) {
  45. accessforbidden();
  46. }
  47. /*
  48. * Actions
  49. */
  50. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  51. if ($action == 'updateMask') {
  52. $maskconstorder = GETPOST('maskconstWorkstation', 'alpha');
  53. $maskorder = GETPOST('maskWorkstation', 'alpha');
  54. if ($maskconstorder) {
  55. $res = dolibarr_set_const($db, $maskconstorder, $maskorder, 'chaine', 0, '', $conf->entity);
  56. }
  57. if (!($res > 0)) {
  58. $error++;
  59. }
  60. if (!$error) {
  61. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  62. } else {
  63. setEventMessages($langs->trans("Error"), null, 'errors');
  64. }
  65. } elseif ($action == 'specimen') {
  66. $modele = GETPOST('module', 'alpha');
  67. $tmpobjectkey = GETPOST('object');
  68. $tmpobject = new $tmpobjectkey($db);
  69. $tmpobject->initAsSpecimen();
  70. // Search template files
  71. $file = ''; $classname = ''; $filefound = 0;
  72. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  73. foreach ($dirmodels as $reldir) {
  74. $file = dol_buildpath($reldir."core/modules/workstation/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0);
  75. if (file_exists($file)) {
  76. $filefound = 1;
  77. $classname = "pdf_".$modele;
  78. break;
  79. }
  80. }
  81. if ($filefound) {
  82. require_once $file;
  83. $module = new $classname($db);
  84. if ($module->write_file($tmpobject, $langs) > 0) {
  85. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
  86. return;
  87. } else {
  88. setEventMessages($module->error, null, 'errors');
  89. dol_syslog($module->error, LOG_ERR);
  90. }
  91. } else {
  92. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  93. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  94. }
  95. } elseif ($action == 'set') {
  96. // Activate a model
  97. $ret = addDocumentModel($value, $type, $label, $scandir);
  98. } elseif ($action == 'del') {
  99. $tmpobjectkey = GETPOST('object');
  100. $ret = delDocumentModel($value, $type);
  101. if ($ret > 0) {
  102. $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF';
  103. if ($conf->global->$constforval == "$value") {
  104. dolibarr_del_const($db, $constforval, $conf->entity);
  105. }
  106. }
  107. } elseif ($action == 'setdoc') {
  108. // Set default model
  109. $tmpobjectkey = GETPOST('object');
  110. $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF';
  111. if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
  112. // The constant that was read before the new set
  113. // We therefore requires a variable to have a coherent view
  114. $conf->global->$constforval = $value;
  115. }
  116. // On active le modele
  117. $ret = delDocumentModel($value, $type);
  118. if ($ret > 0) {
  119. $ret = addDocumentModel($value, $type, $label, $scandir);
  120. }
  121. } elseif ($action == 'setmod') {
  122. // TODO Check if numbering module chosen can be activated
  123. // by calling method canBeActivated
  124. $tmpobjectkey = GETPOST('object');
  125. $constforval = 'WORKSTATION_'.strtoupper($tmpobjectkey)."_ADDON";
  126. dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
  127. }
  128. /*
  129. * View
  130. */
  131. $form = new Form($db);
  132. $help_url = '';
  133. $page_name = "WorkstationSetup";
  134. llxHeader('', $langs->trans($page_name), $help_url);
  135. // Subheader
  136. $linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
  137. print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
  138. // Configuration header
  139. $head = workstationAdminPrepareHead();
  140. print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "workstation");
  141. // Setup page goes here
  142. //echo '<span class="opacitymedium">'.$langs->trans("WorkstationSetupPage").'</span><br><br>';
  143. if ($action == 'edit') {
  144. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  145. print '<input type="hidden" name="token" value="'.newToken().'">';
  146. print '<input type="hidden" name="action" value="update">';
  147. print '<table class="noborder centpercent">';
  148. print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  149. foreach ($arrayofparameters as $key => $val) {
  150. print '<tr class="oddeven"><td>';
  151. $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
  152. print $form->textwithpicto($langs->trans($key), $tooltiphelp);
  153. print '</td><td><input name="'.$key.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.getDolGlobalString($key).'"></td></tr>';
  154. }
  155. print '</table>';
  156. print '<br><div class="center">';
  157. print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
  158. print '</div>';
  159. print '</form>';
  160. print '<br>';
  161. } else {
  162. if (!empty($arrayofparameters)) {
  163. print '<table class="noborder centpercent">';
  164. print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  165. foreach ($arrayofparameters as $key => $val) {
  166. $setupnotempty++;
  167. print '<tr class="oddeven"><td>';
  168. $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
  169. print $form->textwithpicto($langs->trans($key), $tooltiphelp);
  170. print '</td><td>'.getDolGlobalString($key).'</td></tr>';
  171. }
  172. print '</table>';
  173. print '<div class="tabsAction">';
  174. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
  175. print '</div>';
  176. }/* else {
  177. print '<br>'.$langs->trans("NothingToSetup");
  178. }*/
  179. }
  180. $moduledir = 'workstation';
  181. $myTmpObjects = array();
  182. $myTmpObjects['workstation'] = array('includerefgeneration'=>1, 'includedocgeneration'=>0);
  183. foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
  184. if ($myTmpObjectKey == 'MyObject') {
  185. continue;
  186. }
  187. if ($myTmpObjectArray['includerefgeneration']) {
  188. /*
  189. * Orders Numbering model
  190. */
  191. $setupnotempty++;
  192. print load_fiche_titre($langs->trans("NumberingModules", $myTmpObjectKey), '', '');
  193. print '<table class="noborder centpercent">';
  194. print '<tr class="liste_titre">';
  195. print '<td>'.$langs->trans("Name").'</td>';
  196. print '<td>'.$langs->trans("Description").'</td>';
  197. print '<td class="nowrap">'.$langs->trans("Example").'</td>';
  198. print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
  199. print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  200. print '</tr>'."\n";
  201. clearstatcache();
  202. foreach ($dirmodels as $reldir) {
  203. $dir = dol_buildpath($reldir."core/modules/".$moduledir);
  204. if (is_dir($dir)) {
  205. $handle = opendir($dir);
  206. if (is_resource($handle)) {
  207. while (($file = readdir($handle)) !== false) {
  208. if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
  209. $file = substr($file, 0, dol_strlen($file) - 4);
  210. require_once $dir.'/'.$file.'.php';
  211. $module = new $file($db);
  212. // Show modules according to features level
  213. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
  214. continue;
  215. }
  216. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
  217. continue;
  218. }
  219. if ($module->isEnabled()) {
  220. dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
  221. print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
  222. print $module->info();
  223. print '</td>';
  224. // Show example of numbering model
  225. print '<td class="nowrap">';
  226. $tmp = $module->getExample();
  227. if (preg_match('/^Error/', $tmp)) {
  228. $langs->load("errors");
  229. print '<div class="error">'.$langs->trans($tmp).'</div>';
  230. } elseif ($tmp == 'NotConfigured') {
  231. print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
  232. } else {
  233. print $tmp;
  234. }
  235. print '</td>'."\n";
  236. print '<td class="center">';
  237. $constforvar = 'WORKSTATION_'.strtoupper($myTmpObjectKey).'_ADDON';
  238. if (getDolGlobalString($constforvar) == $file) {
  239. print img_picto($langs->trans("Activated"), 'switch_on');
  240. } else {
  241. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.urlencode($file).'">';
  242. print img_picto($langs->trans("Disabled"), 'switch_off');
  243. print '</a>';
  244. }
  245. print '</td>';
  246. $mytmpinstance = new $myTmpObjectKey($db);
  247. $mytmpinstance->initAsSpecimen();
  248. // Info
  249. $htmltooltip = '';
  250. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  251. $nextval = $module->getNextValue($mytmpinstance);
  252. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  253. $htmltooltip .= ''.$langs->trans("NextValue").': ';
  254. if ($nextval) {
  255. if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
  256. $nextval = $langs->trans($nextval);
  257. }
  258. $htmltooltip .= $nextval.'<br>';
  259. } else {
  260. $htmltooltip .= $langs->trans($module->error).'<br>';
  261. }
  262. }
  263. print '<td class="center">';
  264. print $form->textwithpicto('', $htmltooltip, 1, 0);
  265. print '</td>';
  266. print "</tr>\n";
  267. }
  268. }
  269. }
  270. closedir($handle);
  271. }
  272. }
  273. }
  274. print "</table><br>\n";
  275. }
  276. if ($myTmpObjectArray['includedocgeneration']) {
  277. /*
  278. * Document templates generators
  279. */
  280. $setupnotempty++;
  281. $type = strtolower($myTmpObjectKey);
  282. print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
  283. // Load array def with activated templates
  284. $def = array();
  285. $sql = "SELECT nom";
  286. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  287. $sql .= " WHERE type = '".$db->escape($type)."'";
  288. $sql .= " AND entity = ".$conf->entity;
  289. $resql = $db->query($sql);
  290. if ($resql) {
  291. $i = 0;
  292. $num_rows = $db->num_rows($resql);
  293. while ($i < $num_rows) {
  294. $array = $db->fetch_array($resql);
  295. array_push($def, $array[0]);
  296. $i++;
  297. }
  298. } else {
  299. dol_print_error($db);
  300. }
  301. print "<table class=\"noborder\" width=\"100%\">\n";
  302. print "<tr class=\"liste_titre\">\n";
  303. print '<td>'.$langs->trans("Name").'</td>';
  304. print '<td>'.$langs->trans("Description").'</td>';
  305. print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
  306. print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
  307. print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
  308. print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
  309. print "</tr>\n";
  310. clearstatcache();
  311. foreach ($dirmodels as $reldir) {
  312. foreach (array('', '/doc') as $valdir) {
  313. $realpath = $reldir."core/modules/".$moduledir.$valdir;
  314. $dir = dol_buildpath($realpath);
  315. if (is_dir($dir)) {
  316. $handle = opendir($dir);
  317. if (is_resource($handle)) {
  318. while (($file = readdir($handle)) !== false) {
  319. $filelist[] = $file;
  320. }
  321. closedir($handle);
  322. arsort($filelist);
  323. foreach ($filelist as $file) {
  324. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
  325. if (file_exists($dir.'/'.$file)) {
  326. $name = substr($file, 4, dol_strlen($file) - 16);
  327. $classname = substr($file, 0, dol_strlen($file) - 12);
  328. require_once $dir.'/'.$file;
  329. $module = new $classname($db);
  330. $modulequalified = 1;
  331. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
  332. $modulequalified = 0;
  333. }
  334. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
  335. $modulequalified = 0;
  336. }
  337. if ($modulequalified) {
  338. print '<tr class="oddeven"><td width="100">';
  339. print (empty($module->name) ? $name : $module->name);
  340. print "</td><td>\n";
  341. if (method_exists($module, 'info')) {
  342. print $module->info($langs);
  343. } else {
  344. print $module->description;
  345. }
  346. print '</td>';
  347. // Active
  348. if (in_array($name, $def)) {
  349. print '<td class="center">'."\n";
  350. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
  351. print img_picto($langs->trans("Enabled"), 'switch_on');
  352. print '</a>';
  353. print '</td>';
  354. } else {
  355. print '<td class="center">'."\n";
  356. 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>';
  357. print "</td>";
  358. }
  359. // Default
  360. print '<td class="center">';
  361. $constforvar = 'WORKSTATION_'.strtoupper($myTmpObjectKey).'_ADDON';
  362. if (getDolGlobalString($constforvar) == $name) {
  363. print img_picto($langs->trans("Default"), 'on');
  364. } else {
  365. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;token='.newToken().'&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
  366. }
  367. print '</td>';
  368. // Info
  369. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  370. $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  371. if ($module->type == 'pdf') {
  372. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  373. }
  374. $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
  375. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  376. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  377. $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
  378. print '<td class="center">';
  379. print $form->textwithpicto('', $htmltooltip, 1, 0);
  380. print '</td>';
  381. // Preview
  382. print '<td class="center">';
  383. if ($module->type == 'pdf') {
  384. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&object='.$myTmpObjectKey.'">'.img_object($langs->trans("Preview"), 'generic').'</a>';
  385. } else {
  386. print img_object($langs->trans("PreviewNotAvailable"), 'generic');
  387. }
  388. print '</td>';
  389. print "</tr>\n";
  390. }
  391. }
  392. }
  393. }
  394. }
  395. }
  396. }
  397. }
  398. print '</table>';
  399. }
  400. }
  401. /*if (empty($setupnotempty)) {
  402. print '<br>'.$langs->trans("NothingToSetup");
  403. }*/
  404. // Page end
  405. print dol_get_fiche_end();
  406. llxFooter();
  407. $db->close();