agenda_other.php 14 KB

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