agenda_other.php 15 KB

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