dons.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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."/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)
  28. accessforbidden();
  29. $typeconst=array('yesno','texte','chaine');
  30. /*
  31. * Action
  32. */
  33. if ($_GET["action"] == 'specimen')
  34. {
  35. $modele=$_GET["module"];
  36. $don = new Don($db);
  37. $don->initAsSpecimen();
  38. // Charge le modele
  39. $dir = DOL_DOCUMENT_ROOT . "/includes/modules/dons/";
  40. $file = $modele.".modules.php";
  41. if (file_exists($dir.$file))
  42. {
  43. $classname = $modele;
  44. require_once($dir.$file);
  45. $obj = new $classname($db);
  46. if ($obj->write_file($don,$langs) > 0)
  47. {
  48. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=donation&file=SPECIMEN.html");
  49. return;
  50. }
  51. else
  52. {
  53. $mesg='<div class="error">'.$obj->error.'</div>';
  54. dol_syslog($obj->error, LOG_ERR);
  55. }
  56. }
  57. else
  58. {
  59. $mesg='<div class="error">'.$langs->trans("ErrorModuleNotFound").'</div>';
  60. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  61. }
  62. }
  63. if ($_GET["action"] == 'setdoc')
  64. {
  65. $db->begin();
  66. if (dolibarr_set_const($db, "DON_ADDON_MODEL",$_GET["value"],'chaine',0,'',$conf->entity))
  67. {
  68. $conf->global->DON_ADDON_MODEL = $_GET["value"];
  69. }
  70. // On active le modele
  71. $type='donation';
  72. $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
  73. $sql_del.= " WHERE nom = '".$db->escape($_GET["value"])."' AND type = '".$type."'";
  74. $result1=$db->query($sql_del);
  75. $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
  76. $sql.= " VALUES ('".$db->escape($_GET["value"])."', '".$type."', ".$conf->entity.", ";
  77. $sql.= ($_GET["label"]?"'".$db->escape($_GET["label"])."'":'null').", ";
  78. $sql.= (! empty($_GET["scandir"])?"'".$db->escape($_GET["scandir"])."'":"null");
  79. $sql.= ")";
  80. $result2=$db->query($sql);
  81. if ($result1 && $result2)
  82. {
  83. $db->commit();
  84. }
  85. else
  86. {
  87. $db->rollback();
  88. }
  89. }
  90. if ($_GET["action"] == 'set')
  91. {
  92. $type='donation';
  93. $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
  94. $sql.= " VALUES ('".$db->escape($_GET["value"])."','".$type."',".$conf->entity.", ";
  95. $sql.= ($_GET["label"]?"'".$db->escape($_GET["label"])."'":'null').", ";
  96. $sql.= (! empty($_GET["scandir"])?"'".$db->escape($_GET["scandir"])."'":"null");
  97. $sql.= ")";
  98. if ($db->query($sql))
  99. {
  100. }
  101. }
  102. if ($_GET["action"] == 'del')
  103. {
  104. $type='donation';
  105. $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
  106. $sql .= " WHERE nom = '".$_GET["value"]."' AND type = '".$type."'";
  107. if ($db->query($sql))
  108. {
  109. }
  110. }
  111. /*
  112. * View
  113. */
  114. $dir = "../includes/modules/dons/";
  115. $html=new Form($db);
  116. llxHeader('',$langs->trans("DonationsSetup"),'DonConfiguration');
  117. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  118. print_fiche_titre($langs->trans("DonationsSetup"),$linkback,'setup');
  119. /*
  120. * PDF
  121. */
  122. print '<br>';
  123. print_titre($langs->trans("DonationsModels"));
  124. // Defini tableau def de modele
  125. $type='donation';
  126. $def = array();
  127. $sql = "SELECT nom";
  128. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  129. $sql.= " WHERE type = '".$type."'";
  130. $resql=$db->query($sql);
  131. if ($resql)
  132. {
  133. $i = 0;
  134. $num_rows=$db->num_rows($resql);
  135. while ($i < $num_rows)
  136. {
  137. $array = $db->fetch_array($resql);
  138. array_push($def, $array[0]);
  139. $i++;
  140. }
  141. }
  142. else
  143. {
  144. dol_print_error($db);
  145. }
  146. print '<table class="noborder" width=\"100%\">';
  147. print '<tr class="liste_titre">';
  148. print '<td>'.$langs->trans("Name").'</td>';
  149. print '<td>'.$langs->trans("Description").'</td>';
  150. print '<td align="center" width="60">'.$langs->trans("Activated").'</td>';
  151. print '<td align="center" width="60">'.$langs->trans("Default").'</td>';
  152. print '<td align="center" width="32" colspan="2">'.$langs->trans("Infos").'</td>';
  153. print "</tr>\n";
  154. clearstatcache();
  155. $handle=opendir($dir);
  156. $var=True;
  157. if (is_resource($handle))
  158. {
  159. while (($file = readdir($handle))!==false)
  160. {
  161. if (preg_match('/\.modules\.php$/i',$file))
  162. {
  163. $var = !$var;
  164. $name = substr($file, 0, dol_strlen($file) -12);
  165. $classname = substr($file, 0, dol_strlen($file) -12);
  166. require_once($dir.'/'.$file);
  167. $module=new $classname($db);
  168. // Show modules according to features level
  169. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  170. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  171. if ($module->isEnabled())
  172. {
  173. print '<tr '.$bc[$var].'><td width=\"100\">';
  174. echo $module->name;
  175. print '</td>';
  176. print '<td>';
  177. print $module->description;
  178. print '</td>';
  179. // Active
  180. if (in_array($name, $def))
  181. {
  182. print "<td align=\"center\">\n";
  183. if ($conf->global->DON_ADDON_MODEL == $name)
  184. {
  185. print img_picto($langs->trans("Enabled"),'on');
  186. }
  187. else
  188. {
  189. print '&nbsp;';
  190. print '</td><td align="center">';
  191. 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>';
  192. }
  193. print '</td>';
  194. }
  195. else
  196. {
  197. print "<td align=\"center\">\n";
  198. 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>';
  199. print "</td>";
  200. }
  201. // Defaut
  202. print "<td align=\"center\">";
  203. if ($conf->global->DON_ADDON_MODEL == "$name")
  204. {
  205. print img_picto($langs->trans("Default"),'on');
  206. }
  207. else
  208. {
  209. 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>';
  210. }
  211. print '</td>';
  212. // Info
  213. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  214. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  215. $htmltooltip.='<br>'.$langs->trans("Height").'/'.$langs->trans("Width").': '.$module->page_hauteur.'/'.$module->page_largeur;
  216. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  217. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  218. $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
  219. print '<td align="center">';
  220. print $html->textwithpicto('',$htmltooltip,1,0);
  221. print '</td>';
  222. print '<td align="center">';
  223. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'" target="specimen">'.img_object($langs->trans("Preview"),'generic').'</a>';
  224. print '</td>';
  225. print "</tr>\n";
  226. }
  227. }
  228. }
  229. closedir($handle);
  230. }
  231. print '</table>';
  232. print "<br>";
  233. $db->close();
  234. llxFooter();
  235. ?>