donation.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <?php
  2. /* Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2012-2015 Juanjo Menent <jmenent@2byte.es>
  4. * Copyright (C) 2013-2017 Philippe Grand <philippe.grand@atoo-net.com>
  5. * Copyright (C) 2015-2020 Alexandre Spangaro <aspangaro@open-dsi.fr>
  6. * Copyright (C) 2015 Benoit Bruchard <benoitb21@gmail.com>
  7. * Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.net>
  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/don/admin/donation.php
  24. * \ingroup donations
  25. * \brief Page to setup the donation module
  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/donation.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  32. if (isModEnabled('accounting')) {
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  34. }
  35. // Load translation files required by the page
  36. $langs->loadLangs(array('admin', 'donations', 'accountancy', 'other'));
  37. if (!$user->admin) {
  38. accessforbidden();
  39. }
  40. $action = GETPOST('action', 'aZ09');
  41. $value = GETPOST('value');
  42. $label = GETPOST('label', 'alpha');
  43. $scandir = GETPOST('scan_dir', 'alpha');
  44. $type = 'donation';
  45. /*
  46. * Action
  47. */
  48. if ($action == 'specimen') {
  49. $modele = GETPOST('module', 'alpha');
  50. $don = new Don($db);
  51. $don->initAsSpecimen();
  52. // Search template files
  53. $dir = DOL_DOCUMENT_ROOT."/core/modules/dons/";
  54. $file = $modele.".modules.php";
  55. if (file_exists($dir.$file)) {
  56. $classname = $modele;
  57. require_once $dir.$file;
  58. $obj = new $classname($db);
  59. if ($obj->write_file($don, $langs) > 0) {
  60. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=donation&file=SPECIMEN.html");
  61. return;
  62. } else {
  63. setEventMessages($obj->error, $obj->errors, 'errors');
  64. dol_syslog($obj->error, LOG_ERR);
  65. }
  66. } else {
  67. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  68. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  69. }
  70. } elseif ($action == 'setdoc') {
  71. // Set default model
  72. if (dolibarr_set_const($db, "DON_ADDON_MODEL", $value, 'chaine', 0, '', $conf->entity)) {
  73. // The constant that was read before the new set
  74. // So we go through a variable for a coherent display
  75. $conf->global->DON_ADDON_MODEL = $value;
  76. }
  77. // It enables the model
  78. $ret = delDocumentModel($value, $type);
  79. if ($ret > 0) {
  80. $ret = addDocumentModel($value, $type, $label, $scandir);
  81. }
  82. } elseif ($action == 'set') {
  83. // Activate a model
  84. $ret = addDocumentModel($value, $type, $label, $scandir);
  85. } elseif ($action == 'del') {
  86. $ret = delDocumentModel($value, $type);
  87. if ($ret > 0) {
  88. if ($conf->global->DON_ADDON_MODEL == "$value") {
  89. dolibarr_del_const($db, 'DON_ADDON_MODEL', $conf->entity);
  90. }
  91. }
  92. }
  93. // Options
  94. if ($action == 'set_DONATION_ACCOUNTINGACCOUNT') {
  95. $account = GETPOST('DONATION_ACCOUNTINGACCOUNT', 'alpha');
  96. $res = dolibarr_set_const($db, "DONATION_ACCOUNTINGACCOUNT", $account, 'chaine', 0, '', $conf->entity);
  97. if (!($res > 0)) {
  98. $error++;
  99. }
  100. if (!$error) {
  101. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  102. $action = ''; // To avoid to execute next actions
  103. } else {
  104. setEventMessages($langs->trans("Error"), null, 'errors');
  105. $action = ''; // To avoid to execute next actions
  106. }
  107. }
  108. if ($action == 'set_DONATION_MESSAGE') {
  109. $freemessage = GETPOST('DONATION_MESSAGE', 'restricthtml'); // No alpha here, we want exact string
  110. $res = dolibarr_set_const($db, "DONATION_MESSAGE", $freemessage, 'chaine', 0, '', $conf->entity);
  111. if (!($res > 0)) {
  112. $error++;
  113. }
  114. if (!$error) {
  115. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  116. $action = ''; // To avoid to execute next actions
  117. } else {
  118. setEventMessages($langs->trans("Error"), null, 'errors');
  119. $action = ''; // To avoid to execute next actions
  120. }
  121. }
  122. // Other cases
  123. $reg = array();
  124. if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
  125. $code = $reg[1];
  126. if (dolibarr_set_const($db, $code, 1, 'chaine', 0, '', $conf->entity) > 0) {
  127. header("Location: ".$_SERVER["PHP_SELF"]);
  128. exit;
  129. } else {
  130. dol_print_error($db);
  131. }
  132. }
  133. if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
  134. $code = $reg[1];
  135. if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
  136. header("Location: ".$_SERVER["PHP_SELF"]);
  137. exit;
  138. } else {
  139. dol_print_error($db);
  140. }
  141. }
  142. /*
  143. * View
  144. */
  145. $dir = "../../core/modules/dons/";
  146. $form = new Form($db);
  147. if (isModEnabled('accounting')) {
  148. $formaccounting = new FormAccounting($db);
  149. }
  150. llxHeader('', $langs->trans("DonationsSetup"), 'DonConfiguration');
  151. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  152. print load_fiche_titre($langs->trans("DonationsSetup"), $linkback, 'title_setup');
  153. $head = donation_admin_prepare_head();
  154. print dol_get_fiche_head($head, 'general', $langs->trans("Donations"), -1, 'payment');
  155. // Document templates
  156. print load_fiche_titre($langs->trans("DonationsModels"), '', '');
  157. // Defined the template definition table
  158. $type = 'donation';
  159. $def = array();
  160. $sql = "SELECT nom";
  161. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  162. $sql .= " WHERE type = '".$db->escape($type)."'";
  163. $resql = $db->query($sql);
  164. if ($resql) {
  165. $i = 0;
  166. $num_rows = $db->num_rows($resql);
  167. while ($i < $num_rows) {
  168. $array = $db->fetch_array($resql);
  169. array_push($def, $array[0]);
  170. $i++;
  171. }
  172. } else {
  173. dol_print_error($db);
  174. }
  175. print '<table class="noborder centpercent">';
  176. print '<tr class="liste_titre">';
  177. print '<td>'.$langs->trans("Name").'</td>';
  178. print '<td>'.$langs->trans("Description").'</td>';
  179. print '<td class="center" width="60">'.$langs->trans("Activated").'</td>';
  180. print '<td class="center" width="60">'.$langs->trans("Default").'</td>';
  181. print '<td class="center" width="80">'.$langs->trans("ShortInfo").'</td>';
  182. print '<td class="center" width="80">'.$langs->trans("Preview").'</td>';
  183. print "</tr>\n";
  184. clearstatcache();
  185. $handle = opendir($dir);
  186. if (is_resource($handle)) {
  187. while (($file = readdir($handle)) !== false) {
  188. if (preg_match('/\.modules\.php$/i', $file)) {
  189. $name = substr($file, 0, dol_strlen($file) - 12);
  190. $classname = substr($file, 0, dol_strlen($file) - 12);
  191. require_once $dir.'/'.$file;
  192. $module = new $classname($db);
  193. // Show modules according to features level
  194. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
  195. continue;
  196. }
  197. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
  198. continue;
  199. }
  200. if ($module->isEnabled()) {
  201. print '<tr class="oddeven"><td width=\"100\">';
  202. echo $module->name;
  203. print '</td>';
  204. print '<td>';
  205. print $module->description;
  206. print '</td>';
  207. // Active
  208. if (in_array($name, $def)) {
  209. if ($conf->global->DON_ADDON_MODEL == $name) {
  210. print "<td class=\"center\">\n";
  211. print img_picto($langs->trans("Enabled"), 'switch_on');
  212. print '</td>';
  213. } else {
  214. print "<td class=\"center\">\n";
  215. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
  216. print '</td>';
  217. }
  218. } else {
  219. print "<td class=\"center\">\n";
  220. print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
  221. print "</td>";
  222. }
  223. // Default
  224. if ($conf->global->DON_ADDON_MODEL == "$name") {
  225. print "<td class=\"center\">";
  226. print img_picto($langs->trans("Default"), 'on');
  227. print '</td>';
  228. } else {
  229. print "<td class=\"center\">";
  230. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
  231. print '</td>';
  232. }
  233. // Info
  234. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  235. $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  236. if ($module->type == 'pdf') {
  237. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  238. }
  239. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  240. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  241. $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
  242. print '<td class="center">';
  243. print $form->textwithpicto('', $htmltooltip, -1, 0);
  244. print '</td>';
  245. // Preview
  246. print '<td class="center">';
  247. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'" target="specimen">'.img_object($langs->trans("Preview"), 'generic').'</a>';
  248. print '</td>';
  249. print "</tr>\n";
  250. }
  251. }
  252. }
  253. closedir($handle);
  254. }
  255. print '</table><br>';
  256. /*
  257. * Params
  258. */
  259. print load_fiche_titre($langs->trans("Options"), '', '');
  260. print '<table class="noborder centpercent">';
  261. print '<tr class="liste_titre">';
  262. print '<td>'.$langs->trans("Parameters").'</td>';
  263. print '<td width="60" class="center">'.$langs->trans("Value")."</td>\n";
  264. print '<td></td>';
  265. print "</tr>\n";
  266. if (isModEnabled("societe")) {
  267. print '<tr class="oddeven">';
  268. print '<td colspan="2">';
  269. print $langs->trans("DonationUseThirdparties");
  270. print '</td>';
  271. print '<td class="center">';
  272. if ($conf->use_javascript_ajax) {
  273. print ajax_constantonoff('DONATION_USE_THIRDPARTIES');
  274. } else {
  275. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  276. print $form->selectarray("DONATION_USE_THIRDPARTIES", $arrval, $conf->global->DONATION_USE_THIRDPARTIES);
  277. }
  278. print "</td>\n";
  279. print "</tr>\n";
  280. }
  281. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  282. print '<input type="hidden" name="token" value="'.newToken().'" />';
  283. print '<input type="hidden" name="action" value="set_DONATION_ACCOUNTINGACCOUNT" />';
  284. print '<tr class="oddeven">';
  285. print '<td>';
  286. $label = $langs->trans("AccountAccounting");
  287. print '<label for="DONATION_ACCOUNTINGACCOUNT">'.$label.'</label></td>';
  288. print '<td class="center">';
  289. if (isModEnabled('accounting')) {
  290. print $formaccounting->select_account($conf->global->DONATION_ACCOUNTINGACCOUNT, 'DONATION_ACCOUNTINGACCOUNT', 1, '', 1, 1);
  291. } else {
  292. print '<input type="text" size="10" id="DONATION_ACCOUNTINGACCOUNT" name="DONATION_ACCOUNTINGACCOUNT" value="'.$conf->global->DONATION_ACCOUNTINGACCOUNT.'">';
  293. }
  294. print '</td><td class="center">';
  295. print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'" />';
  296. print "</td></tr>\n";
  297. print '</form>';
  298. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  299. print '<input type="hidden" name="token" value="'.newToken().'" />';
  300. print '<input type="hidden" name="action" value="set_DONATION_MESSAGE" />';
  301. print '<tr class="oddeven"><td colspan="2">';
  302. print $langs->trans("FreeTextOnDonations").' '.img_info($langs->trans("AddCRIfTooLong")).'<br>';
  303. print '<textarea name="DONATION_MESSAGE" class="flat" cols="80">'.$conf->global->DONATION_MESSAGE.'</textarea>';
  304. print '</td><td class="center">';
  305. print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'" />';
  306. print "</td></tr>\n";
  307. print "</table>\n";
  308. print '</form>';
  309. /*
  310. * French params
  311. */
  312. if (preg_match('/fr/i', $conf->global->MAIN_INFO_SOCIETE_COUNTRY)) {
  313. print '<br>';
  314. print load_fiche_titre($langs->trans("FrenchOptions"), '', '');
  315. print '<table class="noborder centpercent">';
  316. print '<tr class="liste_titre">';
  317. print '<td>'.$langs->trans("Parameters").'</td>'."\n";
  318. print '<td class="center">'.$langs->trans("Status").'</td>'."\n";
  319. print "</tr>\n";
  320. print '<tr class="oddeven">';
  321. print '<td width="80%">'.$langs->trans("DONATION_ART200").'</td>';
  322. print '<td class="center">';
  323. if ($conf->use_javascript_ajax) {
  324. print ajax_constantonoff('DONATION_ART200');
  325. } else {
  326. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  327. print $form->selectarray("DONATION_ART200", $arrval, $conf->global->DONATION_ART200);
  328. }
  329. print '</td></tr>';
  330. print '<tr class="oddeven">';
  331. print '<td width="80%">'.$langs->trans("DONATION_ART238").'</td>';
  332. print '<td class="center">';
  333. if ($conf->use_javascript_ajax) {
  334. print ajax_constantonoff('DONATION_ART238');
  335. } else {
  336. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  337. print $form->selectarray("DONATION_ART238", $arrval, $conf->global->DONATION_ART238);
  338. }
  339. print '</td></tr>';
  340. print '<tr class="oddeven">';
  341. print '<td width="80%">'.$langs->trans("DONATION_ART978").'</td>';
  342. print '<td class="center">';
  343. if ($conf->use_javascript_ajax) {
  344. print ajax_constantonoff('DONATION_ART978');
  345. } else {
  346. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  347. print $form->selectarray("DONATION_ART978", $arrval, $conf->global->DONATION_ART978);
  348. }
  349. print '</td></tr>';
  350. print "</table>\n";
  351. }
  352. llxFooter();
  353. $db->close();