agenda_other.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. <?php
  2. /* Copyright (C) 2008-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2011 Regis Houssin <regis.houssin@capnetworks.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 <http://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. $langs->load("admin");
  34. $langs->load("other");
  35. $action = GETPOST('action','alpha');
  36. $value = GETPOST('value','alpha');
  37. $param = GETPOST('param','alpha');
  38. $cancel = GETPOST('cancel','alpha');
  39. $scandir = GETPOST('scandir','alpha');
  40. $type = 'action';
  41. /*
  42. * Actions
  43. */
  44. if (preg_match('/set_(.*)/',$action,$reg))
  45. {
  46. $code=$reg[1];
  47. $value=(GETPOST($code) ? GETPOST($code) : 1);
  48. if (dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity) > 0)
  49. {
  50. Header("Location: ".$_SERVER["PHP_SELF"]);
  51. exit;
  52. }
  53. else
  54. {
  55. dol_print_error($db);
  56. }
  57. }
  58. if (preg_match('/del_(.*)/',$action,$reg))
  59. {
  60. $code=$reg[1];
  61. if (dolibarr_del_const($db, $code, $conf->entity) > 0)
  62. {
  63. Header("Location: ".$_SERVER["PHP_SELF"]);
  64. exit;
  65. }
  66. else
  67. {
  68. dol_print_error($db);
  69. }
  70. }
  71. // Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...)
  72. if ($action == 'setModuleOptions')
  73. {
  74. if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity);
  75. if (! $res > 0) $error++;
  76. if (! $error)
  77. {
  78. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  79. }
  80. else
  81. {
  82. setEventMessages($langs->trans("Error"), null, 'errors');
  83. }
  84. }
  85. if ($action == 'set')
  86. {
  87. dolibarr_set_const($db, 'AGENDA_USE_EVENT_TYPE_DEFAULT', GETPOST('AGENDA_USE_EVENT_TYPE_DEFAULT'), 'chaine', 0, '', $conf->entity);
  88. dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_TYPE', GETPOST('AGENDA_DEFAULT_FILTER_TYPE'), 'chaine', 0, '', $conf->entity);
  89. dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_STATUS', GETPOST('AGENDA_DEFAULT_FILTER_STATUS'), 'chaine', 0, '', $conf->entity);
  90. dolibarr_set_const($db, 'AGENDA_DEFAULT_VIEW', GETPOST('AGENDA_DEFAULT_VIEW'), 'chaine', 0, '', $conf->entity);
  91. }
  92. else if ($action == 'specimen') // For orders
  93. {
  94. $modele=GETPOST('module','alpha');
  95. $commande = new CommandeFournisseur($db);
  96. $commande->initAsSpecimen();
  97. $commande->thirdparty=$specimenthirdparty;
  98. // Search template files
  99. $file=''; $classname=''; $filefound=0;
  100. $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
  101. foreach($dirmodels as $reldir)
  102. {
  103. $file=dol_buildpath($reldir."core/modules/action/doc/pdf_".$modele.".modules.php",0);
  104. if (file_exists($file))
  105. {
  106. $filefound=1;
  107. $classname = "pdf_".$modele;
  108. break;
  109. }
  110. }
  111. if ($filefound)
  112. {
  113. require_once $file;
  114. $module = new $classname($db,$commande);
  115. if ($module->write_file($commande,$langs) > 0)
  116. {
  117. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=action&file=SPECIMEN.pdf");
  118. return;
  119. }
  120. else
  121. {
  122. setEventMessages($module->error, $module->errors, 'errors');
  123. dol_syslog($module->error, LOG_ERR);
  124. }
  125. }
  126. else
  127. {
  128. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  129. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  130. }
  131. }
  132. // Activate a model
  133. else if ($action == 'setmodel')
  134. {
  135. //print "sssd".$value;
  136. $ret = addDocumentModel($value, $type, $label, $scandir);
  137. }
  138. else if ($action == 'del')
  139. {
  140. $ret = delDocumentModel($value, $type);
  141. if ($ret > 0)
  142. {
  143. if ($conf->global->ACTION_EVENT_ADDON_PDF == "$value") dolibarr_del_const($db, 'ACTION_EVENT_ADDON_PDF',$conf->entity);
  144. }
  145. }
  146. // Set default model
  147. else if ($action == 'setdoc')
  148. {
  149. if (dolibarr_set_const($db, "ACTION_EVENT_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
  150. {
  151. // La constante qui a ete lue en avant du nouveau set
  152. // on passe donc par une variable pour avoir un affichage coherent
  153. $conf->global->ACTION_EVENT_ADDON_PDF = $value;
  154. }
  155. // On active le modele
  156. $ret = delDocumentModel($value, $type);
  157. if ($ret > 0)
  158. {
  159. $ret = addDocumentModel($value, $type, $label, $scandir);
  160. }
  161. }
  162. /**
  163. * View
  164. */
  165. $formactions=new FormActions($db);
  166. $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
  167. llxHeader();
  168. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  169. print load_fiche_titre($langs->trans("AgendaSetup"),$linkback,'title_setup');
  170. print "<br>\n";
  171. $head=agenda_prepare_head();
  172. dol_fiche_head($head, 'other', $langs->trans("Agenda"), -1, 'action');
  173. /*
  174. * Documents models for supplier orders
  175. */
  176. // Define array def of models
  177. $def = array();
  178. $sql = "SELECT nom";
  179. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  180. $sql.= " WHERE type = 'action'";
  181. $sql.= " AND entity = ".$conf->entity;
  182. $resql=$db->query($sql);
  183. if ($resql)
  184. {
  185. $i = 0;
  186. $num_rows=$db->num_rows($resql);
  187. while ($i < $num_rows)
  188. {
  189. $array = $db->fetch_array($resql);
  190. array_push($def, $array[0]);
  191. $i++;
  192. }
  193. }
  194. else
  195. {
  196. dol_print_error($db);
  197. }
  198. if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
  199. {
  200. print load_fiche_titre($langs->trans("AgendaModelModule"),'','');
  201. print '<table class="noborder" width="100%">'."\n";
  202. print '<tr class="liste_titre">'."\n";
  203. print '<td width="100">'.$langs->trans("Name").'</td>'."\n";
  204. print '<td>'.$langs->trans("Description").'</td>'."\n";
  205. print '<td align="center" width="60">'.$langs->trans("Status").'</td>'."\n";
  206. print '<td align="center" width="60">'.$langs->trans("Default").'</td>'."\n";
  207. print '<td align="center" width="40">'.$langs->trans("ShortInfo").'</td>';
  208. print '<td align="center" width="40">'.$langs->trans("Preview").'</td>';
  209. print '</tr>'."\n";
  210. clearstatcache();
  211. foreach ($dirmodels as $reldir)
  212. {
  213. $dir = dol_buildpath($reldir."core/modules/action/doc/");
  214. if (is_dir($dir))
  215. {
  216. $handle=opendir($dir);
  217. if (is_resource($handle))
  218. {
  219. while (($file = readdir($handle))!==false)
  220. {
  221. if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
  222. {
  223. $name = substr($file, 4, dol_strlen($file) -16);
  224. $classname = substr($file, 0, dol_strlen($file) -12);
  225. require_once $dir.'/'.$file;
  226. $module = new $classname($db, new ActionComm($db));
  227. print '<tr class="oddeven">'."\n";
  228. print "<td>";
  229. print (empty($module->name)?$name:$module->name);
  230. print "</td>\n";
  231. print "<td>\n";
  232. require_once $dir.$file;
  233. $module = new $classname($db,$specimenthirdparty);
  234. if (method_exists($module,'info'))
  235. print $module->info($langs);
  236. else
  237. print $module->description;
  238. print "</td>\n";
  239. // Active
  240. if (in_array($name, $def))
  241. {
  242. print '<td align="center">'."\n";
  243. if ($conf->global->ACTION_EVENT_ADDON_PDF != "$name")
  244. {
  245. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=action">';
  246. print img_picto($langs->trans("Enabled"),'switch_on');
  247. print '</a>';
  248. }
  249. else
  250. {
  251. print img_picto($langs->trans("Enabled"),'switch_on');
  252. }
  253. print "</td>";
  254. }
  255. else
  256. {
  257. print '<td align="center">'."\n";
  258. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmodel&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=action">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
  259. print "</td>";
  260. }
  261. // Default
  262. print '<td align="center">';
  263. if ($conf->global->ACTION_EVENT_ADDON_PDF == "$name")
  264. {
  265. print img_picto($langs->trans("Default"),'on');
  266. }
  267. else
  268. {
  269. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=action"" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
  270. }
  271. print '</td>';
  272. // Info
  273. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  274. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  275. $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  276. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  277. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  278. print '<td align="center">';
  279. print $form->textwithpicto('',$htmltooltip,1,0);
  280. print '</td>';
  281. print '<td align="center">';
  282. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&amp;module='.$name.'">'.img_object($langs->trans("Preview"),'order').'</a>';
  283. print '</td>';
  284. print "</tr>\n";
  285. }
  286. }
  287. closedir($handle);
  288. }
  289. }
  290. }
  291. print '</table><br>';
  292. }
  293. print '<form action="'.$_SERVER["PHP_SELF"].'" name="agenda">';
  294. print '<input type="hidden" name="action" value="set">';
  295. print '<table class="noborder allwidth">'."\n";
  296. print '<tr class="liste_titre">'."\n";
  297. print '<td>'.$langs->trans("Parameters").'</td>'."\n";
  298. print '<td align="center">&nbsp;</td>'."\n";
  299. print '<td align="right">'.$langs->trans("Value").'</td>'."\n";
  300. print '</tr>'."\n";
  301. // Manual or automatic
  302. print '<tr class="oddeven">'."\n";
  303. print '<td>'.$langs->trans("AGENDA_USE_EVENT_TYPE").'</td>'."\n";
  304. print '<td align="center">&nbsp;</td>'."\n";
  305. print '<td align="right">'."\n";
  306. //print ajax_constantonoff('AGENDA_USE_EVENT_TYPE'); Do not use ajax here, we need to reload page to change other combo list
  307. if (empty($conf->global->AGENDA_USE_EVENT_TYPE))
  308. {
  309. print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_USE_EVENT_TYPE">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
  310. }
  311. else
  312. {
  313. print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_USE_EVENT_TYPE">'.img_picto($langs->trans("Enabled"),'switch_on').'</a>';
  314. }
  315. print '</td></tr>'."\n";
  316. if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
  317. {
  318. print '<!-- AGENDA_USE_EVENT_TYPE_DEFAULT -->';
  319. print '<tr class="oddeven">'."\n";
  320. print '<td>'.$langs->trans("AGENDA_USE_EVENT_TYPE_DEFAULT").'</td>'."\n";
  321. print '<td align="center">&nbsp;</td>'."\n";
  322. print '<td align="right" class="nowrap">'."\n";
  323. $formactions->select_type_actions($conf->global->AGENDA_USE_EVENT_TYPE_DEFAULT, "AGENDA_USE_EVENT_TYPE_DEFAULT", 'systemauto', 0, 1);
  324. print '</td></tr>'."\n";
  325. }
  326. // AGENDA_DEFAULT_FILTER_TYPE
  327. print '<tr class="oddeven">'."\n";
  328. print '<td>'.$langs->trans("AGENDA_DEFAULT_FILTER_TYPE").'</td>'."\n";
  329. print '<td align="center">&nbsp;</td>'."\n";
  330. print '<td align="right" class="nowrap">'."\n";
  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);
  332. print '</td></tr>'."\n";
  333. // AGENDA_DEFAULT_FILTER_STATUS
  334. print '<tr class="oddeven">'."\n";
  335. print '<td>'.$langs->trans("AGENDA_DEFAULT_FILTER_STATUS").'</td>'."\n";
  336. print '<td align="center">&nbsp;</td>'."\n";
  337. print '<td align="right">'."\n";
  338. $formactions->form_select_status_action('agenda', $conf->global->AGENDA_DEFAULT_FILTER_STATUS, 1, 'AGENDA_DEFAULT_FILTER_STATUS', 1, 2);
  339. print '</td></tr>'."\n";
  340. // AGENDA_DEFAULT_VIEW
  341. print '<tr class="oddeven">'."\n";
  342. print '<td>'.$langs->trans("AGENDA_DEFAULT_VIEW").'</td>'."\n";
  343. print '<td align="center">&nbsp;</td>'."\n";
  344. print '<td align="right">'."\n";
  345. $tmplist=array('show_month'=>$langs->trans("ViewCal"), 'show_week'=>$langs->trans("ViewWeek"), 'show_day'=>$langs->trans("ViewDay"), 'show_list'=>$langs->trans("ViewList"), 'show_peruser'=>$langs->trans("ViewPerUser"));
  346. print $form->selectarray('AGENDA_DEFAULT_VIEW', $tmplist, $conf->global->AGENDA_DEFAULT_VIEW);
  347. print '</td></tr>'."\n";
  348. // AGENDA NOTIFICATION
  349. if ($conf->global->MAIN_FEATURES_LEVEL > 0)
  350. {
  351. print '<tr class="oddeven">'."\n";
  352. print '<td>'.$langs->trans('AGENDA_NOTIFICATION').'</td>'."\n";
  353. print '<td align="center">&nbsp;</td>'."\n";
  354. print '<td align="right">'."\n";
  355. if (empty($conf->global->AGENDA_NOTIFICATION)) {
  356. print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_NOTIFICATION">'.img_picto($langs->trans('Disabled'),'switch_off').'</a>';
  357. print '</td></tr>'."\n";
  358. } else {
  359. print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_NOTIFICATION">'.img_picto($langs->trans('Enabled'),'switch_on').'</a>';
  360. print '</td></tr>'."\n";
  361. print '<tr class="oddeven">'."\n";
  362. print '<td>'.$langs->trans('AGENDA_NOTIFICATION_SOUND').'</td>'."\n";
  363. print '<td align="center">&nbsp;</td>'."\n";
  364. print '<td align="right">'."\n";
  365. if (empty($conf->global->AGENDA_NOTIFICATION_SOUND)) {
  366. print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_AGENDA_NOTIFICATION_SOUND">'.img_picto($langs->trans('Disabled'),'switch_off').'</a>';
  367. } else {
  368. print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_AGENDA_NOTIFICATION_SOUND">'.img_picto($langs->trans('Enabled'),'switch_on').'</a>';
  369. }
  370. print '</td></tr>'."\n";
  371. }
  372. }
  373. print '</table>';
  374. dol_fiche_end();
  375. print '<div class="center"><input class="button" type="submit" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'"></div>';
  376. print '</form>';
  377. print "<br>";
  378. llxFooter();
  379. $db->close();