agenda.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. /* Copyright (C) 2008-2014 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. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/admin/agenda.php
  21. * \ingroup agenda
  22. * \brief Autocreate actions for agenda module setup page
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
  27. if (!$user->admin)
  28. accessforbidden();
  29. $langs->load("admin");
  30. $langs->load("other");
  31. $action = GETPOST('action','alpha');
  32. $cancel = GETPOST('cancel','alpha');
  33. // Get list of triggers available
  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 ($action == "save" && empty($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 (GETPOST($param,'alpha')) $res = dolibarr_set_const($db,$param,GETPOST($param,'alpha'),'chaine',0,'',$conf->entity);
  69. else $res = dolibarr_del_const($db,$param,$conf->entity);
  70. if (! $res > 0) $error++;
  71. }
  72. if (! $error)
  73. {
  74. setEventMessage($langs->trans("SetupSaved"));
  75. $db->commit();
  76. }
  77. else
  78. {
  79. setEventMessage($langs->trans("Error"),'errors');
  80. $db->rollback();
  81. }
  82. }
  83. if (preg_match('/set_(.*)/',$action,$reg))
  84. {
  85. $code=$reg[1];
  86. $value=(GETPOST($code) ? GETPOST($code) : 1);
  87. if (dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity) > 0)
  88. {
  89. Header("Location: ".$_SERVER["PHP_SELF"]);
  90. exit;
  91. }
  92. else
  93. {
  94. dol_print_error($db);
  95. }
  96. }
  97. if (preg_match('/del_(.*)/',$action,$reg))
  98. {
  99. $code=$reg[1];
  100. if (dolibarr_del_const($db, $code, $conf->entity) > 0)
  101. {
  102. Header("Location: ".$_SERVER["PHP_SELF"]);
  103. exit;
  104. }
  105. else
  106. {
  107. dol_print_error($db);
  108. }
  109. }
  110. /**
  111. * View
  112. */
  113. llxHeader();
  114. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  115. print_fiche_titre($langs->trans("AgendaSetup"),$linkback,'setup');
  116. print "<br>\n";
  117. $head=agenda_prepare_head();
  118. dol_fiche_head($head, 'autoactions', $langs->trans("Agenda"), 0, 'action');
  119. print $langs->trans("AgendaAutoActionDesc")."<br>\n";
  120. print $langs->trans("OnlyActiveElementsAreShown").'<br>';
  121. print "<br>\n";
  122. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  123. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  124. print '<input type="hidden" name="action" value="save">';
  125. $var=true;
  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.
  145. if ($trigger['code'] == 'FICHINTER_CLASSIFY_BILLED' && empty($conf->global->FICHINTER_CLASSIFY_BILLED)) continue;
  146. $var=!$var;
  147. print '<tr '.$bc[$var].'>';
  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 '.$bc[$var].' type="checkbox" name="'.$key.'" value="1"'.((($action=='selectall'||$value) && $action!="selectnone")?' checked="checked"':'').'>';
  154. print '</td></tr>'."\n";
  155. }
  156. }
  157. }
  158. print '</table>';
  159. print '<br><div class="center">';
  160. print '<input type="submit" name="save" class="button" value="'.$langs->trans("Save").'">';
  161. print "</div>";
  162. print "</form>\n";
  163. dol_fiche_end();
  164. print "<br>";
  165. llxFooter();
  166. $db->close();