donation.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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-2017 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
  6. * Copyright (C) 2015 Benoit Bruchard <benoitb21@gmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/don/admin/dons.php
  23. * \ingroup donations
  24. * \brief Page to setup the donation module
  25. */
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
  28. require_once DOL_DOCUMENT_ROOT . '/core/lib/donation.lib.php';
  29. require_once DOL_DOCUMENT_ROOT . '/don/class/don.class.php';
  30. require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
  31. if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
  32. $langs->load("admin");
  33. $langs->load("donations");
  34. $langs->load("accountancy");
  35. $langs->load('other');
  36. if (!$user->admin) accessforbidden();
  37. $typeconst=array('yesno','texte','chaine');
  38. $action = GETPOST('action','alpha');
  39. $value = GETPOST('value');
  40. $type='donation';
  41. /*
  42. * Action
  43. */
  44. if ($action == 'specimen')
  45. {
  46. $modele=GETPOST('module','alpha');
  47. $don = new Don($db);
  48. $don->initAsSpecimen();
  49. // Search template files
  50. $dir = DOL_DOCUMENT_ROOT . "/core/modules/dons/";
  51. $file = $modele.".modules.php";
  52. if (file_exists($dir.$file))
  53. {
  54. $classname = $modele;
  55. require_once $dir.$file;
  56. $obj = new $classname($db);
  57. if ($obj->write_file($don,$langs) > 0)
  58. {
  59. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=donation&file=SPECIMEN.html");
  60. return;
  61. }
  62. else
  63. {
  64. setEventMessages($obj->error, $obj->errors, 'errors');
  65. dol_syslog($obj->error, LOG_ERR);
  66. }
  67. }
  68. else
  69. {
  70. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  71. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  72. }
  73. }
  74. // Set default model
  75. else if ($action == 'setdoc')
  76. {
  77. if (dolibarr_set_const($db, "DON_ADDON_MODEL",$value,'chaine',0,'',$conf->entity))
  78. {
  79. // The constant that was read before the new set
  80. // So we go through a variable for a coherent display
  81. $conf->global->DON_ADDON_MODEL = $value;
  82. }
  83. // It enables the model
  84. $ret = delDocumentModel($value, $type);
  85. if ($ret > 0)
  86. {
  87. $ret = addDocumentModel($value, $type, $label, $scandir);
  88. }
  89. }
  90. // Activate a model
  91. else if ($action == 'set')
  92. {
  93. $ret = addDocumentModel($value, $type, $label, $scandir);
  94. }
  95. else if ($action == 'del')
  96. {
  97. $ret = delDocumentModel($value, $type);
  98. if ($ret > 0)
  99. {
  100. if ($conf->global->DON_ADDON_MODEL == "$value") dolibarr_del_const($db, 'DON_ADDON_MODEL',$conf->entity);
  101. }
  102. }
  103. // Options
  104. if ($action == 'set_DONATION_ACCOUNTINGACCOUNT')
  105. {
  106. $account = GETPOST('DONATION_ACCOUNTINGACCOUNT'); // No alpha here, we want exact string
  107. $res = dolibarr_set_const($db, "DONATION_ACCOUNTINGACCOUNT",$account,'chaine',0,'',$conf->entity);
  108. if (! $res > 0) $error++;
  109. if (! $error)
  110. {
  111. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  112. }
  113. else
  114. {
  115. setEventMessages($langs->trans("Error"), null, 'errors');
  116. }
  117. }
  118. if ($action == 'set_DONATION_MESSAGE')
  119. {
  120. $freemessage = GETPOST('DONATION_MESSAGE'); // No alpha here, we want exact string
  121. $res = dolibarr_set_const($db, "DONATION_MESSAGE",$freemessage,'chaine',0,'',$conf->entity);
  122. if (! $res > 0) $error++;
  123. if (! $error)
  124. {
  125. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  126. }
  127. else
  128. {
  129. setEventMessages($langs->trans("Error"), null, 'errors');
  130. }
  131. }
  132. // Activate an article
  133. else if ($action == 'setart200') {
  134. $setart200 = GETPOST('value', 'int');
  135. $res = dolibarr_set_const($db, "DONATION_ART200", $setart200, 'yesno', 0, '', $conf->entity);
  136. if (! $res > 0)
  137. $error ++;
  138. if (! $error) {
  139. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  140. } else {
  141. setEventMessages($langs->trans("Error"), null, 'mesgs');
  142. }
  143. }
  144. else if ($action == 'setart238') {
  145. $setart238 = GETPOST('value', 'int');
  146. $res = dolibarr_set_const($db, "DONATION_ART238", $setart238, 'yesno', 0, '', $conf->entity);
  147. if (! $res > 0)
  148. $error ++;
  149. if (! $error) {
  150. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  151. } else {
  152. setEventMessages($langs->trans("Error"), null, 'mesgs');
  153. }
  154. }
  155. else if ($action == 'setart885') {
  156. $setart885 = GETPOST('value', 'int');
  157. $res = dolibarr_set_const($db, "DONATION_ART885", $setart885, 'yesno', 0, '', $conf->entity);
  158. if (! $res > 0)
  159. $error ++;
  160. if (! $error) {
  161. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  162. } else {
  163. setEventMessages($langs->trans("Error"), null, 'mesgs');
  164. }
  165. }
  166. /*
  167. * View
  168. */
  169. $dir = "../../core/modules/dons/";
  170. $form=new Form($db);
  171. if (! empty($conf->accounting->enabled)) $formaccounting = New FormAccounting($db);
  172. llxHeader('',$langs->trans("DonationsSetup"),'DonConfiguration');
  173. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  174. print load_fiche_titre($langs->trans("DonationsSetup"),$linkback,'title_setup');
  175. $head = donation_admin_prepare_head();
  176. dol_fiche_head($head, 'general', $langs->trans("Donations"), 0, 'payment');
  177. // Document templates
  178. print load_fiche_titre($langs->trans("DonationsModels"), '', '');
  179. // Defined the template definition table
  180. $type='donation';
  181. $def = array();
  182. $sql = "SELECT nom";
  183. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  184. $sql.= " WHERE type = '".$type."'";
  185. $resql=$db->query($sql);
  186. if ($resql)
  187. {
  188. $i = 0;
  189. $num_rows=$db->num_rows($resql);
  190. while ($i < $num_rows)
  191. {
  192. $array = $db->fetch_array($resql);
  193. array_push($def, $array[0]);
  194. $i++;
  195. }
  196. }
  197. else
  198. {
  199. dol_print_error($db);
  200. }
  201. print '<table class="noborder" width="100%">';
  202. print '<tr class="liste_titre">';
  203. print '<td>'.$langs->trans("Name").'</td>';
  204. print '<td>'.$langs->trans("Description").'</td>';
  205. print '<td align="center" width="60">'.$langs->trans("Activated").'</td>';
  206. print '<td align="center" width="60">'.$langs->trans("Default").'</td>';
  207. print '<td align="center" width="80">'.$langs->trans("ShortInfo").'</td>';
  208. print '<td align="center" width="80">'.$langs->trans("Preview").'</td>';
  209. print "</tr>\n";
  210. clearstatcache();
  211. $handle=opendir($dir);
  212. if (is_resource($handle))
  213. {
  214. while (($file = readdir($handle))!==false)
  215. {
  216. if (preg_match('/\.modules\.php$/i',$file))
  217. {
  218. $name = substr($file, 0, dol_strlen($file) -12);
  219. $classname = substr($file, 0, dol_strlen($file) -12);
  220. require_once $dir.'/'.$file;
  221. $module=new $classname($db);
  222. // Show modules according to features level
  223. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  224. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  225. if ($module->isEnabled())
  226. {
  227. print '<tr class="oddeven"><td width=\"100\">';
  228. echo $module->name;
  229. print '</td>';
  230. print '<td>';
  231. print $module->description;
  232. print '</td>';
  233. // Active
  234. if (in_array($name, $def))
  235. {
  236. if ($conf->global->DON_ADDON_MODEL == $name)
  237. {
  238. print "<td align=\"center\">\n";
  239. print img_picto($langs->trans("Enabled"),'switch_on');
  240. print '</td>';
  241. }
  242. else
  243. {
  244. print "<td align=\"center\">\n";
  245. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Enabled"),'switch_on').'</a>';
  246. print '</td>';
  247. }
  248. }
  249. else
  250. {
  251. print "<td align=\"center\">\n";
  252. print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
  253. print "</td>";
  254. }
  255. // Default
  256. if ($conf->global->DON_ADDON_MODEL == "$name")
  257. {
  258. print "<td align=\"center\">";
  259. print img_picto($langs->trans("Default"),'on');
  260. print '</td>';
  261. }
  262. else
  263. {
  264. print "<td align=\"center\">";
  265. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
  266. print '</td>';
  267. }
  268. // Info
  269. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  270. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  271. if ($module->type == 'pdf')
  272. {
  273. $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  274. }
  275. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  276. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  277. $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
  278. print '<td align="center">';
  279. print $form->textwithpicto('',$htmltooltip,-1,0);
  280. print '</td>';
  281. // Preview
  282. print '<td align="center">';
  283. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'" target="specimen">'.img_object($langs->trans("Preview"),'generic').'</a>';
  284. print '</td>';
  285. print "</tr>\n";
  286. }
  287. }
  288. }
  289. closedir($handle);
  290. }
  291. print '</table><br>';
  292. /*
  293. * Params
  294. */
  295. print load_fiche_titre($langs->trans("Options"), '', '');
  296. print '<table class="noborder" width="100%">';
  297. print '<tr class="liste_titre">';
  298. print '<td>'.$langs->trans("Parameters").'</td>';
  299. print '<td width="60" align="center">'.$langs->trans("Value")."</td>\n";
  300. print '<td></td>';
  301. print "</tr>\n";
  302. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  303. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />';
  304. print '<input type="hidden" name="action" value="set_DONATION_ACCOUNTINGACCOUNT" />';
  305. print '<tr class="oddeven">';
  306. print '<td>';
  307. $label = $langs->trans("AccountAccounting");
  308. print '<label for="DONATION_ACCOUNTINGACCOUNT">' . $label . '</label></td>';
  309. print '<td>';
  310. if (! empty($conf->accounting->enabled))
  311. {
  312. print $formaccounting->select_account($conf->global->DONATION_ACCOUNTINGACCOUNT, 'DONATION_ACCOUNTINGACCOUNT', 1, '', 1, 1);
  313. }
  314. else
  315. {
  316. print '<input type="text" size="10" id="DONATION_ACCOUNTINGACCOUNT" name="DONATION_ACCOUNTINGACCOUNT" value="' . $conf->global->DONATION_ACCOUNTINGACCOUNT . '">';
  317. }
  318. print '</td><td align="right">';
  319. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'" />';
  320. print "</td></tr>\n";
  321. print '</form>';
  322. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  323. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />';
  324. print '<input type="hidden" name="action" value="set_DONATION_MESSAGE" />';
  325. print '<tr class="oddeven"><td colspan="2">';
  326. print $langs->trans("FreeTextOnDonations").' '.img_info($langs->trans("AddCRIfTooLong")).'<br>';
  327. print '<textarea name="DONATION_MESSAGE" class="flat" cols="80">'.$conf->global->DONATION_MESSAGE.'</textarea>';
  328. print '</td><td align="right">';
  329. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'" />';
  330. print "</td></tr>\n";
  331. print "</table>\n";
  332. print '</form>';
  333. /*
  334. * French params
  335. */
  336. if (preg_match('/fr/i',$conf->global->MAIN_INFO_SOCIETE_COUNTRY))
  337. {
  338. print '<br>';
  339. print load_fiche_titre($langs->trans("FrenchOptions"), '', '');
  340. print '<table class="noborder" width="100%">';
  341. print '<tr class="liste_titre">';
  342. print '<td colspan="3">' . $langs->trans('Parameters') . '</td>';
  343. print "</tr>\n";
  344. print '<tr class="oddeven">';
  345. print '<td width="80%">' . $langs->trans("DONATION_ART200") . '</td>';
  346. if (! empty($conf->global->DONATION_ART200)) {
  347. print '<td align="center" colspan="2"><a href="' . $_SERVER['PHP_SELF'] . '?action=setart200&value=0">';
  348. print img_picto($langs->trans("Activated"), 'switch_on');
  349. print '</a></td>';
  350. } else {
  351. print '<td align="center" colspan="2"><a href="' . $_SERVER['PHP_SELF'] . '?action=setart200&value=1">';
  352. print img_picto($langs->trans("Disabled"), 'switch_off');
  353. print '</a></td>';
  354. }
  355. print '</tr>';
  356. print '<tr class="oddeven">';
  357. print '<td width="80%">' . $langs->trans("DONATION_ART238") . '</td>';
  358. if (! empty($conf->global->DONATION_ART238)) {
  359. print '<td align="center" colspan="2"><a href="' . $_SERVER['PHP_SELF'] . '?action=setart238&value=0">';
  360. print img_picto($langs->trans("Activated"), 'switch_on');
  361. print '</a></td>';
  362. } else {
  363. print '<td align="center" colspan="2"><a href="' . $_SERVER['PHP_SELF'] . '?action=setart238&value=1">';
  364. print img_picto($langs->trans("Disabled"), 'switch_off');
  365. print '</a></td>';
  366. }
  367. print '</tr>';
  368. print '<tr class="oddeven">';
  369. print '<td width="80%">' . $langs->trans("DONATION_ART885") . '</td>';
  370. if (! empty($conf->global->DONATION_ART885)) {
  371. print '<td align="center" colspan="2"><a href="' . $_SERVER['PHP_SELF'] . '?action=setart885&value=0">';
  372. print img_picto($langs->trans("Activated"), 'switch_on');
  373. print '</a></td>';
  374. } else {
  375. print '<td align="center" colspan="2"><a href="' . $_SERVER['PHP_SELF'] . '?action=setart885&value=1">';
  376. print img_picto($langs->trans("Disabled"), 'switch_off');
  377. print '</a></td>';
  378. }
  379. print '</tr>';
  380. print "</table>\n";
  381. }
  382. llxFooter();
  383. $db->close();