agenda_other.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  49. $reg = array();
  50. if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
  51. $code = $reg[1];
  52. $value = (GETPOST($code, 'alpha') ? GETPOST($code, 'alpha') : 1);
  53. if (dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity) > 0) {
  54. Header("Location: ".$_SERVER["PHP_SELF"]);
  55. exit;
  56. } else {
  57. dol_print_error($db);
  58. }
  59. }
  60. if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
  61. $code = $reg[1];
  62. if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
  63. Header("Location: ".$_SERVER["PHP_SELF"]);
  64. exit;
  65. } else {
  66. dol_print_error($db);
  67. }
  68. }
  69. if ($action == 'set') {
  70. $getDefaultFilter = GETPOST('AGENDA_DEFAULT_FILTER_TYPE');
  71. $defaultfilter = (is_array($getDefaultFilter)) ? implode(',', $getDefaultFilter) : $getDefaultFilter;
  72. dolibarr_set_const($db, 'AGENDA_USE_EVENT_TYPE_DEFAULT', GETPOST('AGENDA_USE_EVENT_TYPE_DEFAULT'), 'chaine', 0, '', $conf->entity);
  73. dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_TYPE', $defaultfilter, 'chaine', 0, '', $conf->entity);
  74. dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_STATUS', GETPOST('AGENDA_DEFAULT_FILTER_STATUS'), 'chaine', 0, '', $conf->entity);
  75. dolibarr_set_const($db, 'AGENDA_DEFAULT_VIEW', GETPOST('AGENDA_DEFAULT_VIEW'), 'chaine', 0, '', $conf->entity);
  76. $defaultValues = new DefaultValues($db);
  77. $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));
  78. if (!is_array($result) && $result < 0) {
  79. setEventMessages($defaultValues->error, $defaultValues->errors, 'errors');
  80. } elseif (count($result) > 0) {
  81. foreach ($result as $defval) {
  82. $defaultValues->id = $defval->id;
  83. $resultDel = $defaultValues->delete($user);
  84. if ($resultDel < 0) {
  85. setEventMessages($defaultValues->error, $defaultValues->errors, 'errors');
  86. }
  87. }
  88. }
  89. $defaultValues->type = 'createform';
  90. $defaultValues->entity = $conf->entity;
  91. $defaultValues->user_id = 0;
  92. $defaultValues->page = 'comm/action/card.php';
  93. $defaultValues->param = 'complete';
  94. $defaultValues->value = GETPOST('AGENDA_EVENT_DEFAULT_STATUS');
  95. $resultCreat = $defaultValues->create($user);
  96. if ($resultCreat < 0) {
  97. setEventMessages($defaultValues->error, $defaultValues->errors, 'errors');
  98. } else {
  99. setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
  100. }
  101. } elseif ($action == 'specimen') { // For orders
  102. $modele = GETPOST('module', 'alpha');
  103. $commande = new CommandeFournisseur($db);
  104. $commande->initAsSpecimen();
  105. $commande->thirdparty = $specimenthirdparty;
  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/action/doc/pdf_".$modele.".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, $commande);
  120. if ($module->write_file($commande, $langs) > 0) {
  121. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=action&file=SPECIMEN.pdf");
  122. return;
  123. } else {
  124. setEventMessages($module->error, $module->errors, '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 == 'setmodel') {
  132. // Activate a model
  133. //print "sssd".$value;
  134. $ret = addDocumentModel($value, $type, $label, $scandir);
  135. } elseif ($action == 'del') {
  136. $ret = delDocumentModel($value, $type);
  137. if ($ret > 0) {
  138. if ($conf->global->ACTION_EVENT_ADDON_PDF == "$value") {
  139. dolibarr_del_const($db, 'ACTION_EVENT_ADDON_PDF', $conf->entity);
  140. }
  141. }
  142. } elseif ($action == 'setdoc') {
  143. // Set default model
  144. if (dolibarr_set_const($db, "ACTION_EVENT_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
  145. // La constante qui a ete lue en avant du nouveau set
  146. // on passe donc par une variable pour avoir un affichage coherent
  147. $conf->global->ACTION_EVENT_ADDON_PDF = $value;
  148. }
  149. // On active le modele
  150. $ret = delDocumentModel($value, $type);
  151. if ($ret > 0) {
  152. $ret = addDocumentModel($value, $type, $label, $scandir);
  153. }
  154. }
  155. /**
  156. * View
  157. */
  158. $formactions = new FormActions($db);
  159. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  160. $wikihelp = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda';
  161. llxHeader('', $langs->trans("AgendaSetup"), $wikihelp);
  162. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  163. print load_fiche_titre($langs->trans("AgendaSetup"), $linkback, 'title_setup');
  164. $head = agenda_prepare_head();
  165. print dol_get_fiche_head($head, 'other', $langs->trans("Agenda"), -1, 'action');
  166. /*
  167. * Documents models for supplier orders
  168. */
  169. // Define array def of models
  170. $def = array();
  171. $sql = "SELECT nom";
  172. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  173. $sql .= " WHERE type = 'action'";
  174. $sql .= " AND entity = ".$conf->entity;
  175. $resql = $db->query($sql);
  176. if ($resql) {
  177. $i = 0;
  178. $num_rows = $db->num_rows($resql);
  179. while ($i < $num_rows) {
  180. $array = $db->fetch_array($resql);
  181. array_push($def, $array[0]);
  182. $i++;
  183. }
  184. } else {
  185. dol_print_error($db);
  186. }
  187. if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
  188. print load_fiche_titre($langs->trans("AgendaModelModule"), '', '');
  189. print '<table class="noborder centpercent">'."\n";
  190. print '<tr class="liste_titre">'."\n";
  191. print '<td width="100">'.$langs->trans("Name").'</td>'."\n";
  192. print '<td>'.$langs->trans("Description").'</td>'."\n";
  193. print '<td class="center" width="60">'.$langs->trans("Status").'</td>'."\n";
  194. print '<td class="center" width="60">'.$langs->trans("Default").'</td>'."\n";
  195. print '<td class="center" width="40">'.$langs->trans("ShortInfo").'</td>';
  196. print '<td class="center" width="40">'.$langs->trans("Preview").'</td>';
  197. print '</tr>'."\n";
  198. clearstatcache();
  199. foreach ($dirmodels as $reldir) {
  200. $dir = dol_buildpath($reldir."core/modules/action/doc");
  201. if (is_dir($dir)) {
  202. $handle = opendir($dir);
  203. if (is_resource($handle)) {
  204. while (($file = readdir($handle)) !== false) {
  205. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
  206. $name = substr($file, 4, dol_strlen($file) - 16);
  207. $classname = substr($file, 0, dol_strlen($file) - 12);
  208. require_once $dir.'/'.$file;
  209. $module = new $classname($db, new ActionComm($db));
  210. print '<tr class="oddeven">'."\n";
  211. print "<td>";
  212. print (empty($module->name) ? $name : $module->name);
  213. print "</td>\n";
  214. print "<td>\n";
  215. require_once $dir.'/'.$file;
  216. $module = new $classname($db, $specimenthirdparty);
  217. if (method_exists($module, 'info')) {
  218. print $module->info($langs);
  219. } else {
  220. print $module->description;
  221. }
  222. print "</td>\n";
  223. // Active
  224. if (in_array($name, $def)) {
  225. print '<td class="center">'."\n";
  226. if ($conf->global->ACTION_EVENT_ADDON_PDF != "$name") {
  227. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.$name.'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'&type=action">';
  228. print img_picto($langs->trans("Enabled"), 'switch_on');
  229. print '</a>';
  230. } else {
  231. print img_picto($langs->trans("Enabled"), 'switch_on');
  232. }
  233. print "</td>";
  234. } else {
  235. print '<td class="center">'."\n";
  236. 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>';
  237. print "</td>";
  238. }
  239. // Default
  240. print '<td class="center">';
  241. if ($conf->global->ACTION_EVENT_ADDON_PDF == "$name") {
  242. print img_picto($langs->trans("Default"), 'on');
  243. } else {
  244. 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>';
  245. }
  246. print '</td>';
  247. // Info
  248. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  249. $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  250. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  251. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  252. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  253. print '<td class="center">';
  254. print $form->textwithpicto('', $htmltooltip, 1, 0);
  255. print '</td>';
  256. print '<td class="center">';
  257. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&amp;module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
  258. print '</td>';
  259. print "</tr>\n";
  260. }
  261. }
  262. closedir($handle);
  263. }
  264. }
  265. }
  266. print '</table><br>';
  267. }
  268. print '<form action="'.$_SERVER["PHP_SELF"].'" name="agenda">';
  269. print '<input type="hidden" name="token" value="'.newToken().'">';
  270. print '<input type="hidden" name="action" value="set">';
  271. print '<table class="noborder allwidth">'."\n";
  272. print '<tr class="liste_titre">'."\n";
  273. print '<td>'.$langs->trans("Parameters").'</td>'."\n";
  274. print '<td class="center">&nbsp;</td>'."\n";
  275. print '<td class="right">'.$langs->trans("Value").'</td>'."\n";
  276. print '</tr>'."\n";
  277. // AGENDA_DEFAULT_VIEW
  278. print '<tr class="oddeven">'."\n";
  279. $htmltext = $langs->trans("ThisValueCanOverwrittenOnUserLevel", $langs->transnoentitiesnoconv("UserGUISetup"));
  280. print '<td>'.$form->textwithpicto($langs->trans("AGENDA_DEFAULT_VIEW"), $htmltext).'</td>'."\n";
  281. print '<td class="center">&nbsp;</td>'."\n";
  282. print '<td class="right">'."\n";
  283. $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"));
  284. print $form->selectarray('AGENDA_DEFAULT_VIEW', $tmplist, getDolGlobalString('AGENDA_DEFAULT_VIEW'));
  285. print '</td></tr>'."\n";
  286. // Manual or automatic
  287. print '<tr class="oddeven">'."\n";
  288. print '<td>'.$langs->trans("AGENDA_USE_EVENT_TYPE").'</td>'."\n";
  289. print '<td class="center">&nbsp;</td>'."\n";
  290. print '<td class="right">'."\n";
  291. //print ajax_constantonoff('AGENDA_USE_EVENT_TYPE'); Do not use ajax here, we need to reload page to change other combo list
  292. if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
  293. print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_USE_EVENT_TYPE&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  294. } else {
  295. print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_USE_EVENT_TYPE&token='.newToken().'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
  296. }
  297. print '</td></tr>'."\n";
  298. if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
  299. print '<!-- AGENDA_USE_EVENT_TYPE_DEFAULT -->';
  300. print '<tr class="oddeven">'."\n";
  301. print '<td>'.$langs->trans("AGENDA_USE_EVENT_TYPE_DEFAULT").'</td>'."\n";
  302. print '<td class="center">&nbsp;</td>'."\n";
  303. print '<td class="right nowrap">'."\n";
  304. $formactions->select_type_actions($conf->global->AGENDA_USE_EVENT_TYPE_DEFAULT, "AGENDA_USE_EVENT_TYPE_DEFAULT", 'systemauto', 0, 1);
  305. print '</td></tr>'."\n";
  306. }
  307. // AGENDA_EVENT_DEFAULT_STATUS
  308. print '<tr class="oddeven">'."\n";
  309. print '<td>'.$langs->trans("AGENDA_EVENT_DEFAULT_STATUS").'</td>'."\n";
  310. print '<td class="center">&nbsp;</td>'."\n";
  311. print '<td class="right nowrap">'."\n";
  312. $defval = 'na';
  313. $defaultValues = new DefaultValues($db);
  314. $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));
  315. if (!is_array($result) && $result < 0) {
  316. setEventMessages($defaultValues->error, $defaultValues->errors, 'errors');
  317. } elseif (count($result) > 0) {
  318. $defval = reset($result)->value;
  319. }
  320. $formactions->form_select_status_action('agenda', $defval, 1, "AGENDA_EVENT_DEFAULT_STATUS", 0, 1, 'maxwidth200 onrightofpage');
  321. print '</td></tr>'."\n";
  322. // AGENDA_DEFAULT_FILTER_TYPE
  323. print '<tr class="oddeven">'."\n";
  324. print '<td>'.$langs->trans("AGENDA_DEFAULT_FILTER_TYPE").'</td>'."\n";
  325. print '<td class="center">&nbsp;</td>'."\n";
  326. print '<td class="right nowrap">'."\n";
  327. $multiselect = 0;
  328. if (!empty($conf->global->MAIN_ENABLE_MULTISELECT_TYPE)) {
  329. // We use an option here because it adds bugs when used on agenda page "peruser" and "list"
  330. $multiselect = (!empty($conf->global->AGENDA_USE_EVENT_TYPE));
  331. }
  332. $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);
  333. print '</td></tr>'."\n";
  334. // AGENDA_DEFAULT_FILTER_STATUS
  335. // TODO Remove to use the default generic feature
  336. print '<tr class="oddeven">'."\n";
  337. print '<td>'.$langs->trans("AGENDA_DEFAULT_FILTER_STATUS").'</td>'."\n";
  338. print '<td class="center">&nbsp;</td>'."\n";
  339. print '<td class="right">'."\n";
  340. $formactions->form_select_status_action('agenda', getDolGlobalString('AGENDA_DEFAULT_FILTER_STATUS'), 1, 'AGENDA_DEFAULT_FILTER_STATUS', 1, 2, 'minwidth100');
  341. print '</td></tr>'."\n";
  342. print '</table>';
  343. print dol_get_fiche_end();
  344. print $form->buttonsSaveCancel("Save", '');
  345. print '</form>';
  346. print "<br>";
  347. // End of page
  348. llxFooter();
  349. $db->close();