agenda.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. /* Copyright (C) 2008-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2011 Regis Houssin <regis.houssin@capnetworks.com>
  4. * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/admin/agenda.php
  22. * \ingroup agenda
  23. * \brief Autocreate actions for agenda module setup page
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
  28. if (!$user->admin)
  29. accessforbidden();
  30. $langs->load("admin");
  31. $langs->load("other");
  32. $action = GETPOST('action','alpha');
  33. $cancel = GETPOST('cancel','alpha');
  34. // Get list of triggers available
  35. $sql = "SELECT a.rowid, a.code, a.label, a.elementtype";
  36. $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a";
  37. $sql.= " ORDER BY a.rang ASC";
  38. $resql=$db->query($sql);
  39. if ($resql)
  40. {
  41. $num = $db->num_rows($resql);
  42. $i = 0;
  43. while ($i < $num)
  44. {
  45. $obj = $db->fetch_object($resql);
  46. $triggers[$i]['rowid'] = $obj->rowid;
  47. $triggers[$i]['code'] = $obj->code;
  48. $triggers[$i]['element'] = $obj->elementtype;
  49. $triggers[$i]['label'] = ($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label);
  50. $i++;
  51. }
  52. $db->free($resql);
  53. }
  54. else
  55. {
  56. dol_print_error($db);
  57. }
  58. /*
  59. * Actions
  60. */
  61. if ($action == "save" && empty($cancel))
  62. {
  63. $i=0;
  64. $db->begin();
  65. foreach ($triggers as $trigger)
  66. {
  67. $param='MAIN_AGENDA_ACTIONAUTO_'.$trigger['code'];
  68. //print "param=".$param." - ".$_POST[$param];
  69. if (GETPOST($param,'alpha')) $res = dolibarr_set_const($db,$param,GETPOST($param,'alpha'),'chaine',0,'',$conf->entity);
  70. else $res = dolibarr_del_const($db,$param,$conf->entity);
  71. if (! $res > 0) $error++;
  72. }
  73. if (! $error)
  74. {
  75. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  76. $db->commit();
  77. }
  78. else
  79. {
  80. setEventMessages($langs->trans("Error"),null, 'errors');
  81. $db->rollback();
  82. }
  83. }
  84. if (preg_match('/set_(.*)/',$action,$reg))
  85. {
  86. $code=$reg[1];
  87. $value=(GETPOST($code) ? GETPOST($code) : 1);
  88. if (dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity) > 0)
  89. {
  90. Header("Location: ".$_SERVER["PHP_SELF"]);
  91. exit;
  92. }
  93. else
  94. {
  95. dol_print_error($db);
  96. }
  97. }
  98. if (preg_match('/del_(.*)/',$action,$reg))
  99. {
  100. $code=$reg[1];
  101. if (dolibarr_del_const($db, $code, $conf->entity) > 0)
  102. {
  103. Header("Location: ".$_SERVER["PHP_SELF"]);
  104. exit;
  105. }
  106. else
  107. {
  108. dol_print_error($db);
  109. }
  110. }
  111. /**
  112. * View
  113. */
  114. llxHeader();
  115. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  116. print load_fiche_titre($langs->trans("AgendaSetup"),$linkback,'title_setup');
  117. print "<br>\n";
  118. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  119. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  120. print '<input type="hidden" name="action" value="save">';
  121. $head=agenda_prepare_head();
  122. dol_fiche_head($head, 'autoactions', $langs->trans("Agenda"), -1, 'action');
  123. print $langs->trans("AgendaAutoActionDesc")."<br>\n";
  124. print $langs->trans("OnlyActiveElementsAreShown").'<br>';
  125. print "<br>\n";
  126. print '<table class="noborder" width="100%">';
  127. print '<tr class="liste_titre">';
  128. print '<td colspan="2">'.$langs->trans("ActionsEvents").'</td>';
  129. print '<td><a href="'.$_SERVER["PHP_SELF"].'?action=selectall">'.$langs->trans("All").'</a>/<a href="'.$_SERVER["PHP_SELF"].'?action=selectnone">'.$langs->trans("None").'</a>';
  130. print '</tr>'."\n";
  131. // Show each trigger (list is in c_action_trigger)
  132. if (! empty($triggers))
  133. {
  134. foreach ($triggers as $trigger)
  135. {
  136. $module = $trigger['element'];
  137. if ($module == 'order_supplier' || $module == 'invoice_supplier') $module = 'fournisseur';
  138. if ($module == 'shipping') $module = 'expedition_bon';
  139. if ($module == 'member') $module = 'adherent';
  140. if ($module == 'project') $module = 'projet';
  141. //print 'module='.$module.'<br>';
  142. if (! empty($conf->$module->enabled))
  143. {
  144. // Discard special case: If option FICHINTER_CLASSIFY_BILLED is not set, we discard both trigger FICHINTER_CLASSIFY_BILLED and FICHINTER_CLASSIFY_UNBILLED
  145. if ($trigger['code'] == 'FICHINTER_CLASSIFY_BILLED' && empty($conf->global->FICHINTER_CLASSIFY_BILLED)) continue;
  146. if ($trigger['code'] == 'FICHINTER_CLASSIFY_UNBILLED' && empty($conf->global->FICHINTER_CLASSIFY_BILLED)) continue;
  147. print '<tr class="oddeven">';
  148. print '<td>'.$trigger['code'].'</td>';
  149. print '<td>'.$trigger['label'].'</td>';
  150. print '<td align="right" width="40">';
  151. $key='MAIN_AGENDA_ACTIONAUTO_'.$trigger['code'];
  152. $value=$conf->global->$key;
  153. print '<input class="oddeven" type="checkbox" name="'.$key.'" value="1"'.((($action=='selectall'||$value) && $action!="selectnone")?' checked':'').'>';
  154. print '</td></tr>'."\n";
  155. }
  156. }
  157. }
  158. print '</table>';
  159. dol_fiche_end();
  160. print '<div class="center">';
  161. print '<input type="submit" name="save" class="button" value="'.$langs->trans("Save").'">';
  162. print "</div>";
  163. print "</form>\n";
  164. print "<br>";
  165. llxFooter();
  166. $db->close();