agenda.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. /* Copyright (C) 2008-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2011 Regis Houssin <regis@dolibarr.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/admin/agenda.php
  20. * \ingroup agenda
  21. * \brief Autocreate actions for agenda module setup page
  22. */
  23. require("../main.inc.php");
  24. require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
  25. require_once(DOL_DOCUMENT_ROOT."/lib/agenda.lib.php");
  26. if (!$user->admin)
  27. accessforbidden();
  28. $langs->load("admin");
  29. $langs->load("other");
  30. $langs->load("agenda");
  31. $action=$_POST["action"];
  32. // Load array of all events supported by triggers
  33. // TODO add function
  34. $sql = "SELECT a.rowid, a.code, a.label, a.elementtype";
  35. $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a";
  36. $sql.= " ORDER BY a.rang ASC";
  37. $resql=$db->query($sql);
  38. if ($resql)
  39. {
  40. $num = $db->num_rows($resql);
  41. $i = 0;
  42. while ($i < $num)
  43. {
  44. $obj = $db->fetch_object($resql);
  45. $triggers[$i]['rowid'] = $obj->rowid;
  46. $triggers[$i]['code'] = $obj->code;
  47. $triggers[$i]['element'] = $obj->elementtype;
  48. $triggers[$i]['label'] = ($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
  49. $i++;
  50. }
  51. $db->free($resql);
  52. }
  53. else
  54. {
  55. dol_print_error($db);
  56. }
  57. /*
  58. * Actions
  59. */
  60. if ($_POST["action"] == "save" && empty($_POST["cancel"]))
  61. {
  62. $i=0;
  63. $db->begin();
  64. foreach ($triggers as $trigger)
  65. {
  66. $param='MAIN_AGENDA_ACTIONAUTO_'.$trigger['code'];
  67. //print "param=".$param." - ".$_POST[$param];
  68. if (! empty($_POST[$param])) dolibarr_set_const($db,$param,$_POST[$param],'chaine',0,'',$conf->entity);
  69. else dolibarr_del_const($db,$param,$conf->entity);
  70. }
  71. $db->commit();
  72. $mesg = '<font class="ok">'.$langs->trans("SetupSaved").'</font>';
  73. }
  74. /**
  75. * Affichage du formulaire de saisie
  76. */
  77. llxHeader();
  78. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  79. print_fiche_titre($langs->trans("AgendaSetup"),$linkback,'setup');
  80. print "<br>\n";
  81. print $langs->trans("AgendaAutoActionDesc")."<br>\n";
  82. print "<br>\n";
  83. $head=agenda_prepare_head();
  84. dol_fiche_head($head, 'autoactions', $langs->trans("Agenda"));
  85. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  86. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  87. print '<input type="hidden" name="action" value="save">';
  88. $var=true;
  89. print '<table class="noborder" width="100%">';
  90. print '<tr class="liste_titre">';
  91. print '<td colspan="2">'.$langs->trans("ActionsEvents").'</td>';
  92. print '<td><a href="'.$_SERVER["PHP_SELF"].'?action=selectall">'.$langs->trans("All").'</a>/<a href="'.$_SERVER["PHP_SELF"].'?action=selectnone">'.$langs->trans("None").'</a>';
  93. print '</tr>'."\n";
  94. if (! empty($triggers))
  95. {
  96. foreach ($triggers as $trigger)
  97. {
  98. $module = $trigger['element'];
  99. if ($module == 'order_supplier' || $module == 'invoice_supplier') $module = 'fournisseur';
  100. if ($module == 'shipping') $module = 'expedition_bon';
  101. if ($module == 'member') $module = 'adherent';
  102. //print 'module='.$module.'<br>';
  103. if ($conf->$module->enabled)
  104. {
  105. $var=!$var;
  106. print '<tr '.$bc[$var].'>';
  107. print '<td>'.$trigger['code'].'</td>';
  108. print '<td>'.$trigger['label'].'</td>';
  109. print '<td align="right" width="40">';
  110. $key='MAIN_AGENDA_ACTIONAUTO_'.$trigger['code'];
  111. $value=$conf->global->$key;
  112. print '<input '.$bc[$var].' type="checkbox" name="'.$key.'" value="1"'.((($_GET["action"]=='selectall'||$value) && $_GET["action"]!="selectnone")?' checked="true"':'').'>';
  113. print '</td></tr>'."\n";
  114. }
  115. }
  116. }
  117. print '</table>';
  118. print '<br><center>';
  119. print '<input type="submit" name="save" class="button" value="'.$langs->trans("Save").'">';
  120. print ' &nbsp; &nbsp; ';
  121. print '<input type="submit" name="cancel" class="button" value="'.$langs->trans("Cancel").'">';
  122. print "</center>";
  123. print "</form>\n";
  124. print '</div>';
  125. if ($mesg) print "<br>$mesg<br>";
  126. print "<br>";
  127. $db->close();
  128. llxFooter();
  129. ?>