agenda_other.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <?php
  2. /* Copyright (C) 2008-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2011 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2011-2017 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  6. * Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
  7. * Copyright (C) 2017 Open-DSI <support@open-dsi.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/admin/agenda_other.php
  24. * \ingroup agenda
  25. * \brief Autocreate actions for agenda module setup page
  26. */
  27. // Load Dolibarr environment
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/defaultvalues.class.php';
  33. if (!$user->admin) {
  34. accessforbidden();
  35. }
  36. // Load translation files required by the page
  37. $langs->loadLangs(array('admin', 'other', 'agenda', 'users'));
  38. $action = GETPOST('action', 'aZ09');
  39. $value = GETPOST('value', 'alpha');
  40. $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
  41. $param = GETPOST('param', 'alpha');
  42. $cancel = GETPOST('cancel', 'alpha');
  43. $scandir = GETPOST('scan_dir', 'alpha');
  44. $type = 'action';
  45. /*
  46. * Actions
  47. */
  48. $error = 0;
  49. $errors = array();
  50. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  51. $reg = array();
  52. if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
  53. $code = $reg[1];
  54. $value = (GETPOST($code, 'alpha') ? GETPOST($code, 'alpha') : 1);
  55. if (dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity) > 0) {
  56. Header("Location: ".$_SERVER["PHP_SELF"]);
  57. exit;
  58. } else {
  59. dol_print_error($db);
  60. }
  61. }
  62. if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
  63. $code = $reg[1];
  64. if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
  65. Header("Location: ".$_SERVER["PHP_SELF"]);
  66. exit;
  67. } else {
  68. dol_print_error($db);
  69. }
  70. }
  71. if ($action == 'set') {
  72. $getDefaultFilter = GETPOST('AGENDA_DEFAULT_FILTER_TYPE');
  73. $defaultfilter = (is_array($getDefaultFilter)) ? implode(',', $getDefaultFilter) : $getDefaultFilter;
  74. dolibarr_set_const($db, 'AGENDA_USE_EVENT_TYPE_DEFAULT', GETPOST('AGENDA_USE_EVENT_TYPE_DEFAULT'), 'chaine', 0, '', $conf->entity);
  75. dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_TYPE', $defaultfilter, 'chaine', 0, '', $conf->entity);
  76. dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_STATUS', GETPOST('AGENDA_DEFAULT_FILTER_STATUS'), 'chaine', 0, '', $conf->entity);
  77. dolibarr_set_const($db, 'AGENDA_DEFAULT_VIEW', GETPOST('AGENDA_DEFAULT_VIEW'), 'chaine', 0, '', $conf->entity);
  78. $defaultValues = new DefaultValues($db);
  79. $result = $defaultValues->fetchAll('', '', 0, 0, array('t.page'=>'comm/action/card.php', 't.param'=>'complete', 't.user_id'=>'0', 't.type'=>'createform', 't.entity'=>$conf->entity));
  80. if (!is_array($result) && $result < 0) {
  81. setEventMessages($defaultValues->error, $defaultValues->errors, 'errors');
  82. } elseif (count($result) > 0) {
  83. foreach ($result as $defval) {
  84. $defaultValues->id = $defval->id;
  85. $resultDel = $defaultValues->delete($user);
  86. if ($resultDel < 0) {
  87. setEventMessages($defaultValues->error, $defaultValues->errors, 'errors');
  88. }
  89. }
  90. }
  91. $defaultValues->type = 'createform';
  92. $defaultValues->entity = $conf->entity;
  93. $defaultValues->user_id = 0;
  94. $defaultValues->page = 'comm/action/card.php';
  95. $defaultValues->param = 'complete';
  96. $defaultValues->value = GETPOST('AGENDA_EVENT_DEFAULT_STATUS');
  97. $resultCreat = $defaultValues->create($user);
  98. if ($resultCreat < 0) {
  99. setEventMessages($defaultValues->error, $defaultValues->errors, 'errors');
  100. } else {
  101. setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
  102. }
  103. } elseif ($action == 'specimen') { // For orders
  104. $modele = GETPOST('module', 'alpha');
  105. $commande = new CommandeFournisseur($db);
  106. $commande->initAsSpecimen();
  107. $commande->thirdparty = $specimenthirdparty;
  108. // Search template files
  109. $file = ''; $classname = ''; $filefound = 0;
  110. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  111. foreach ($dirmodels as $reldir) {
  112. $file = dol_buildpath($reldir."core/modules/action/doc/pdf_".$modele.".modules.php", 0);
  113. if (file_exists($file)) {
  114. $filefound = 1;
  115. $classname = "pdf_".$modele;
  116. break;
  117. }
  118. }
  119. if ($filefound) {
  120. require_once $file;
  121. $module = new $classname($db, $commande);
  122. if ($module->write_file($commande, $langs) > 0) {
  123. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=action&file=SPECIMEN.pdf");
  124. return;
  125. } else {
  126. setEventMessages($module->error, $module->errors, 'errors');
  127. dol_syslog($module->error, LOG_ERR);
  128. }
  129. } else {
  130. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  131. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  132. }
  133. } elseif ($action == 'setmodel') {
  134. // Activate a model
  135. //print "sssd".$value;
  136. $ret = addDocumentModel($value, $type, $label, $scandir);
  137. } elseif ($action == 'del') {
  138. $ret = delDocumentModel($value, $type);
  139. if ($ret > 0) {
  140. if ($conf->global->ACTION_EVENT_ADDON_PDF == "$value") {
  141. dolibarr_del_const($db, 'ACTION_EVENT_ADDON_PDF', $conf->entity);
  142. }
  143. }
  144. } elseif ($action == 'setdoc') {
  145. // Set default model
  146. if (dolibarr_set_const($db, "ACTION_EVENT_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
  147. // La constante qui a ete lue en avant du nouveau set
  148. // on passe donc par une variable pour avoir un affichage coherent
  149. $conf->global->ACTION_EVENT_ADDON_PDF = $value;
  150. }
  151. // On active le modele
  152. $ret = delDocumentModel($value, $type);
  153. if ($ret > 0) {
  154. $ret = addDocumentModel($value, $type, $label, $scandir);
  155. }
  156. }
  157. /**
  158. * View
  159. */
  160. $formactions = new FormActions($db);
  161. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  162. $wikihelp = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda|DE:Modul_Terminplanung';
  163. llxHeader('', $langs->trans("AgendaSetup"), $wikihelp);
  164. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  165. print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
  166. $head = agenda_prepare_head();
  167. print dol_get_fiche_head($head, 'other', $langs->trans("Agenda"), -1, 'action');
  168. /*
  169. * Miscellaneous
  170. */
  171. // Define array def of models
  172. $def = array();
  173. $sql = "SELECT nom";
  174. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  175. $sql .= " WHERE type = 'action'";
  176. $sql .= " AND entity = ".$conf->entity;
  177. $resql = $db->query($sql);
  178. if ($resql) {
  179. $i = 0;
  180. $num_rows = $db->num_rows($resql);
  181. while ($i < $num_rows) {
  182. $array = $db->fetch_array($resql);
  183. array_push($def, $array[0]);
  184. $i++;
  185. }
  186. } else {
  187. dol_print_error($db);
  188. }
  189. if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
  190. print load_fiche_titre($langs->trans("AgendaModelModule"), '', '');
  191. print '<table class="noborder centpercent">'."\n";
  192. print '<tr class="liste_titre">'."\n";
  193. print '<td width="100">'.$langs->trans("Name").'</td>'."\n";
  194. print '<td>'.$langs->trans("Description").'</td>'."\n";
  195. print '<td class="center" width="60">'.$langs->trans("Status").'</td>'."\n";
  196. print '<td class="center" width="60">'.$langs->trans("Default").'</td>'."\n";
  197. print '<td class="center" width="40">'.$langs->trans("ShortInfo").'</td>';
  198. print '<td class="center" width="40">'.$langs->trans("Preview").'</td>';
  199. print '</tr>'."\n";
  200. clearstatcache();
  201. foreach ($dirmodels as $reldir) {
  202. $dir = dol_buildpath($reldir."core/modules/action/doc");
  203. if (is_dir($dir)) {
  204. $handle = opendir($dir);
  205. if (is_resource($handle)) {
  206. while (($file = readdir($handle)) !== false) {
  207. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
  208. $name = substr($file, 4, dol_strlen($file) - 16);
  209. $classname = substr($file, 0, dol_strlen($file) - 12);
  210. require_once $dir.'/'.$file;
  211. $module = new $classname($db, new ActionComm($db));
  212. print '<tr class="oddeven">'."\n";
  213. print "<td>";
  214. print (empty($module->name) ? $name : $module->name);
  215. print "</td>\n";
  216. print "<td>\n";
  217. require_once $dir.'/'.$file;
  218. $module = new $classname($db, $specimenthirdparty);
  219. if (method_exists($module, 'info')) {
  220. print $module->info($langs);
  221. } else {
  222. print $module->description;
  223. }
  224. print "</td>\n";
  225. // Active
  226. if (in_array($name, $def)) {
  227. print '<td class="center">'."\n";
  228. if ($conf->global->ACTION_EVENT_ADDON_PDF != "$name") {
  229. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.$name.'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'&type=action">';
  230. print img_picto($langs->trans("Enabled"), 'switch_on');
  231. print '</a>';
  232. } else {
  233. print img_picto($langs->trans("Enabled"), 'switch_on');
  234. }
  235. print "</td>";
  236. } else {
  237. print '<td class="center">'."\n";
  238. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmodel&token='.newToken().'&value='.$name.'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'&type=action">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  239. print "</td>";
  240. }
  241. // Default
  242. print '<td class="center">';
  243. if ($conf->global->ACTION_EVENT_ADDON_PDF == "$name") {
  244. print img_picto($langs->trans("Default"), 'on');
  245. } else {
  246. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&token='.newToken().'&value='.urlencode($name).'&amp;scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'&amp;type=action"" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
  247. }
  248. print '</td>';
  249. // Info
  250. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  251. $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  252. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  253. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  254. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  255. print '<td class="center">';
  256. print $form->textwithpicto('', $htmltooltip, 1, 0);
  257. print '</td>';
  258. print '<td class="center">';
  259. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&amp;module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
  260. print '</td>';
  261. print "</tr>\n";
  262. }
  263. }
  264. closedir($handle);
  265. }
  266. }
  267. }
  268. print '</table><br>';
  269. print load_fiche_titre($langs->trans('MiscellaneousOptions'), '', '');
  270. }
  271. print '<form action="'.$_SERVER["PHP_SELF"].'" name="agenda">';
  272. print '<input type="hidden" name="token" value="'.newToken().'">';
  273. print '<input type="hidden" name="action" value="set">';
  274. print '<table class="noborder allwidth">'."\n";
  275. print '<tr class="liste_titre">'."\n";
  276. print '<td>'.$langs->trans("Parameters").'</td>'."\n";
  277. print '<td class="center">&nbsp;</td>'."\n";
  278. print '<td class="right">'.$langs->trans("Value").'</td>'."\n";
  279. print '</tr>'."\n";
  280. // AGENDA_DEFAULT_VIEW
  281. print '<tr class="oddeven">'."\n";
  282. $htmltext = $langs->trans("ThisValueCanOverwrittenOnUserLevel", $langs->transnoentitiesnoconv("UserGUISetup"));
  283. print '<td>'.$form->textwithpicto($langs->trans("AGENDA_DEFAULT_VIEW"), $htmltext).'</td>'."\n";
  284. print '<td class="center">&nbsp;</td>'."\n";
  285. print '<td class="right">'."\n";
  286. $tmplist = array(''=>'&nbsp;', 'show_list'=>$langs->trans("ViewList"), 'show_month'=>$langs->trans("ViewCal"), 'show_week'=>$langs->trans("ViewWeek"), 'show_day'=>$langs->trans("ViewDay"), 'show_peruser'=>$langs->trans("ViewPerUser"));
  287. print $form->selectarray('AGENDA_DEFAULT_VIEW', $tmplist, getDolGlobalString('AGENDA_DEFAULT_VIEW'));
  288. print '</td></tr>'."\n";
  289. // Manual or automatic
  290. print '<tr class="oddeven">'."\n";
  291. print '<td>'.$langs->trans("AGENDA_USE_EVENT_TYPE").'</td>'."\n";
  292. print '<td class="center">&nbsp;</td>'."\n";
  293. print '<td class="right">'."\n";
  294. //print ajax_constantonoff('AGENDA_USE_EVENT_TYPE'); Do not use ajax here, we need to reload page to change other combo list
  295. if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
  296. print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_USE_EVENT_TYPE&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  297. } else {
  298. print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_USE_EVENT_TYPE&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
  299. }
  300. print '</td></tr>'."\n";
  301. if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
  302. print '<!-- AGENDA_USE_EVENT_TYPE_DEFAULT -->';
  303. print '<tr class="oddeven">'."\n";
  304. print '<td>'.$langs->trans("AGENDA_USE_EVENT_TYPE_DEFAULT").'</td>'."\n";
  305. print '<td class="center">&nbsp;</td>'."\n";
  306. print '<td class="right nowrap">'."\n";
  307. $formactions->select_type_actions($conf->global->AGENDA_USE_EVENT_TYPE_DEFAULT, "AGENDA_USE_EVENT_TYPE_DEFAULT", 'systemauto', 0, 1);
  308. print '</td></tr>'."\n";
  309. }
  310. // AGENDA_EVENT_DEFAULT_STATUS
  311. print '<tr class="oddeven">'."\n";
  312. print '<td>'.$langs->trans("AGENDA_EVENT_DEFAULT_STATUS").'</td>'."\n";
  313. print '<td class="center">&nbsp;</td>'."\n";
  314. print '<td class="right nowrap">'."\n";
  315. $defval = 'na';
  316. $defaultValues = new DefaultValues($db);
  317. $result = $defaultValues->fetchAll('', '', 0, 0, array('t.page'=>'comm/action/card.php', 't.param'=>'complete', 't.user_id'=>'0', 't.type'=>'createform', 't.entity'=>$conf->entity));
  318. if (!is_array($result) && $result < 0) {
  319. setEventMessages($defaultValues->error, $defaultValues->errors, 'errors');
  320. } elseif (count($result) > 0) {
  321. $defval = reset($result)->value;
  322. }
  323. $formactions->form_select_status_action('agenda', $defval, 1, "AGENDA_EVENT_DEFAULT_STATUS", 0, 1, 'maxwidth200 onrightofpage');
  324. print '</td></tr>'."\n";
  325. // AGENDA_DEFAULT_FILTER_TYPE
  326. print '<tr class="oddeven">'."\n";
  327. print '<td>'.$langs->trans("AGENDA_DEFAULT_FILTER_TYPE").'</td>'."\n";
  328. print '<td class="center">&nbsp;</td>'."\n";
  329. print '<td class="right nowrap">'."\n";
  330. $multiselect = 0;
  331. if (!empty($conf->global->MAIN_ENABLE_MULTISELECT_TYPE)) {
  332. // We use an option here because it adds bugs when used on agenda page "peruser" and "list"
  333. $multiselect = (!empty($conf->global->AGENDA_USE_EVENT_TYPE));
  334. }
  335. $formactions->select_type_actions($conf->global->AGENDA_DEFAULT_FILTER_TYPE, "AGENDA_DEFAULT_FILTER_TYPE", '', (empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : -1), 1, $multiselect);
  336. print '</td></tr>'."\n";
  337. // AGENDA_DEFAULT_FILTER_STATUS
  338. // TODO Remove to use the default generic feature
  339. print '<tr class="oddeven">'."\n";
  340. print '<td>'.$langs->trans("AGENDA_DEFAULT_FILTER_STATUS").'</td>'."\n";
  341. print '<td class="center">&nbsp;</td>'."\n";
  342. print '<td class="right">'."\n";
  343. $formactions->form_select_status_action('agenda', getDolGlobalString('AGENDA_DEFAULT_FILTER_STATUS'), 1, 'AGENDA_DEFAULT_FILTER_STATUS', 1, 2, 'minwidth100');
  344. print '</td></tr>'."\n";
  345. print '</table>';
  346. print $form->buttonsSaveCancel("Save", '');
  347. print '</form>';
  348. print dol_get_fiche_end();
  349. // End of page
  350. llxFooter();
  351. $db->close();