PageRenderTime 44ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/admin/dons.php

https://github.com/asterix14/dolibarr
PHP | 271 lines | 195 code | 42 blank | 34 comment | 33 complexity | 76a86cd191f232781d1f7c1f12bab441 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/admin/dons.php
  19. * \ingroup dons
  20. * \brief Page d'administration/configuration du module Dons
  21. */
  22. require("../main.inc.php");
  23. require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
  24. require_once(DOL_DOCUMENT_ROOT."/compta/dons/class/don.class.php");
  25. $langs->load("admin");
  26. $langs->load("donations");
  27. if (!$user->admin) accessforbidden();
  28. $typeconst=array('yesno','texte','chaine');
  29. /*
  30. * Action
  31. */
  32. if ($_GET["action"] == 'specimen')
  33. {
  34. $modele=$_GET["module"];
  35. $don = new Don($db);
  36. $don->initAsSpecimen();
  37. // Charge le modele
  38. $dir = DOL_DOCUMENT_ROOT . "/core/modules/dons/";
  39. $file = $modele.".modules.php";
  40. if (file_exists($dir.$file))
  41. {
  42. $classname = $modele;
  43. require_once($dir.$file);
  44. $obj = new $classname($db);
  45. if ($obj->write_file($don,$langs) > 0)
  46. {
  47. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=donation&file=SPECIMEN.html");
  48. return;
  49. }
  50. else
  51. {
  52. $mesg='<div class="error">'.$obj->error.'</div>';
  53. dol_syslog($obj->error, LOG_ERR);
  54. }
  55. }
  56. else
  57. {
  58. $mesg='<div class="error">'.$langs->trans("ErrorModuleNotFound").'</div>';
  59. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  60. }
  61. }
  62. if ($_GET["action"] == 'setdoc')
  63. {
  64. $db->begin();
  65. if (dolibarr_set_const($db, "DON_ADDON_MODEL",$_GET["value"],'chaine',0,'',$conf->entity))
  66. {
  67. $conf->global->DON_ADDON_MODEL = $_GET["value"];
  68. }
  69. // On active le modele
  70. $type='donation';
  71. $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
  72. $sql_del.= " WHERE nom = '".$db->escape($_GET["value"])."' AND type = '".$type."'";
  73. $result1=$db->query($sql_del);
  74. $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
  75. $sql.= " VALUES ('".$db->escape($_GET["value"])."', '".$type."', ".$conf->entity.", ";
  76. $sql.= ($_GET["label"]?"'".$db->escape($_GET["label"])."'":'null').", ";
  77. $sql.= (! empty($_GET["scandir"])?"'".$db->escape($_GET["scandir"])."'":"null");
  78. $sql.= ")";
  79. $result2=$db->query($sql);
  80. if ($result1 && $result2)
  81. {
  82. $db->commit();
  83. }
  84. else
  85. {
  86. $db->rollback();
  87. }
  88. }
  89. if ($_GET["action"] == 'set')
  90. {
  91. $type='donation';
  92. $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
  93. $sql.= " VALUES ('".$db->escape($_GET["value"])."','".$type."',".$conf->entity.", ";
  94. $sql.= ($_GET["label"]?"'".$db->escape($_GET["label"])."'":'null').", ";
  95. $sql.= (! empty($_GET["scandir"])?"'".$db->escape($_GET["scandir"])."'":"null");
  96. $sql.= ")";
  97. $resql=$db->query($sql);
  98. }
  99. if ($_GET["action"] == 'del')
  100. {
  101. $type='donation';
  102. $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
  103. $sql .= " WHERE nom = '".$_GET["value"]."' AND type = '".$type."'";
  104. $resql=$db->query($sql);
  105. }
  106. /*
  107. * View
  108. */
  109. $dir = "../core/modules/dons/";
  110. $form=new Form($db);
  111. llxHeader('',$langs->trans("DonationsSetup"),'DonConfiguration');
  112. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  113. print_fiche_titre($langs->trans("DonationsSetup"),$linkback,'setup');
  114. // Document templates
  115. print '<br>';
  116. print_titre($langs->trans("DonationsModels"));
  117. // Defini tableau def de modele
  118. $type='donation';
  119. $def = array();
  120. $sql = "SELECT nom";
  121. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  122. $sql.= " WHERE type = '".$type."'";
  123. $resql=$db->query($sql);
  124. if ($resql)
  125. {
  126. $i = 0;
  127. $num_rows=$db->num_rows($resql);
  128. while ($i < $num_rows)
  129. {
  130. $array = $db->fetch_array($resql);
  131. array_push($def, $array[0]);
  132. $i++;
  133. }
  134. }
  135. else
  136. {
  137. dol_print_error($db);
  138. }
  139. print '<table class="noborder" width=\"100%\">';
  140. print '<tr class="liste_titre">';
  141. print '<td>'.$langs->trans("Name").'</td>';
  142. print '<td>'.$langs->trans("Description").'</td>';
  143. print '<td align="center" width="60">'.$langs->trans("Activated").'</td>';
  144. print '<td align="center" width="60">'.$langs->trans("Default").'</td>';
  145. print '<td align="center" width="80">'.$langs->trans("Infos").'</td>';
  146. print "</tr>\n";
  147. clearstatcache();
  148. $handle=opendir($dir);
  149. $var=True;
  150. if (is_resource($handle))
  151. {
  152. while (($file = readdir($handle))!==false)
  153. {
  154. if (preg_match('/\.modules\.php$/i',$file))
  155. {
  156. $var = !$var;
  157. $name = substr($file, 0, dol_strlen($file) -12);
  158. $classname = substr($file, 0, dol_strlen($file) -12);
  159. require_once($dir.'/'.$file);
  160. $module=new $classname($db);
  161. // Show modules according to features level
  162. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  163. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  164. if ($module->isEnabled())
  165. {
  166. print '<tr '.$bc[$var].'><td width=\"100\">';
  167. echo $module->name;
  168. print '</td>';
  169. print '<td>';
  170. print $module->description;
  171. print '</td>';
  172. // Active
  173. if (in_array($name, $def))
  174. {
  175. print "<td align=\"center\">\n";
  176. if ($conf->global->DON_ADDON_MODEL == $name)
  177. {
  178. print img_picto($langs->trans("Enabled"),'on');
  179. }
  180. else
  181. {
  182. print '&nbsp;';
  183. print '</td><td align="center">';
  184. print '<a href="dons.php?action=setdoc&value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Enabled"),'on').'</a>';
  185. }
  186. print '</td>';
  187. }
  188. else
  189. {
  190. print "<td align=\"center\">\n";
  191. 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"),'off').'</a>';
  192. print "</td>";
  193. }
  194. // Defaut
  195. print "<td align=\"center\">";
  196. if ($conf->global->DON_ADDON_MODEL == "$name")
  197. {
  198. print img_picto($langs->trans("Default"),'on');
  199. }
  200. else
  201. {
  202. 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>';
  203. }
  204. print '</td>';
  205. // Info
  206. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  207. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  208. if ($module->type == 'pdf')
  209. {
  210. $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  211. }
  212. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  213. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  214. $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
  215. $text='<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'" target="specimen">'.img_object($langs->trans("Preview"),'generic').'</a>';
  216. print '<td align="center">';
  217. print $form->textwithpicto(' &nbsp; '.$text,$htmltooltip,-1,0);
  218. print '</td>';
  219. print "</tr>\n";
  220. }
  221. }
  222. }
  223. closedir($handle);
  224. }
  225. print '</table>';
  226. print "<br>";
  227. $db->close();
  228. llxFooter();
  229. ?>