dons.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <?php
  2. /* Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2012-2013 Juanjo Menent <jmenent@2byte.es>
  4. * Copyright (C) 2013 Philippe Grand <philippe.grand@atoo-net.com>
  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/dons.php
  21. * \ingroup dons
  22. * \brief Page d'administration/configuration du module Dons
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/compta/dons/class/don.class.php';
  27. $langs->load("admin");
  28. $langs->load("donations");
  29. $langs->load('other');
  30. if (!$user->admin) accessforbidden();
  31. $typeconst=array('yesno','texte','chaine');
  32. $action = GETPOST('action','alpha');
  33. /*
  34. * Action
  35. */
  36. if ($action == 'specimen')
  37. {
  38. $modele=GETPOST('module','alpha');
  39. $don = new Don($db);
  40. $don->initAsSpecimen();
  41. // Search template files
  42. $dir = DOL_DOCUMENT_ROOT . "/core/modules/dons/";
  43. $file = $modele.".modules.php";
  44. if (file_exists($dir.$file))
  45. {
  46. $classname = $modele;
  47. require_once $dir.$file;
  48. $obj = new $classname($db);
  49. if ($obj->write_file($don,$langs) > 0)
  50. {
  51. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=donation&file=SPECIMEN.html");
  52. return;
  53. }
  54. else
  55. {
  56. setEventMessage($obj->error,'errors');
  57. dol_syslog($obj->error, LOG_ERR);
  58. }
  59. }
  60. else
  61. {
  62. setEventMessage($langs->trans("ErrorModuleNotFound"),'errors');
  63. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  64. }
  65. }
  66. // Set default model
  67. else if ($action == 'setdoc')
  68. {
  69. if (dolibarr_set_const($db, "DON_ADDON_MODEL",$value,'chaine',0,'',$conf->entity))
  70. {
  71. // La constante qui a ete lue en avant du nouveau set
  72. // on passe donc par une variable pour avoir un affichage coherent
  73. $conf->global->DON_ADDON_MODEL = $value;
  74. }
  75. // On active le modele
  76. $ret = delDocumentModel($value, $type);
  77. if ($ret > 0)
  78. {
  79. $ret = addDocumentModel($value, $type, $label, $scandir);
  80. }
  81. }
  82. // Activate a model
  83. else if ($action == 'set')
  84. {
  85. $ret = addDocumentModel($value, $type, $label, $scandir);
  86. }
  87. else if ($action == 'del')
  88. {
  89. $ret = delDocumentModel($value, $type);
  90. if ($ret > 0)
  91. {
  92. if ($conf->global->DON_ADDON_MODEL == "$value") dolibarr_del_const($db, 'DON_ADDON_MODEL',$conf->entity);
  93. }
  94. }
  95. /*
  96. * View
  97. */
  98. $dir = "../core/modules/dons/";
  99. $form=new Form($db);
  100. llxHeader('',$langs->trans("DonationsSetup"),'DonConfiguration');
  101. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  102. print_fiche_titre($langs->trans("DonationsSetup"),$linkback,'setup');
  103. // Document templates
  104. print '<br>';
  105. print_titre($langs->trans("DonationsModels"));
  106. // Defini tableau def de modele
  107. $type='donation';
  108. $def = array();
  109. $sql = "SELECT nom";
  110. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  111. $sql.= " WHERE type = '".$type."'";
  112. $resql=$db->query($sql);
  113. if ($resql)
  114. {
  115. $i = 0;
  116. $num_rows=$db->num_rows($resql);
  117. while ($i < $num_rows)
  118. {
  119. $array = $db->fetch_array($resql);
  120. array_push($def, $array[0]);
  121. $i++;
  122. }
  123. }
  124. else
  125. {
  126. dol_print_error($db);
  127. }
  128. print '<table class="noborder" width="100%">';
  129. print '<tr class="liste_titre">';
  130. print '<td>'.$langs->trans("Name").'</td>';
  131. print '<td>'.$langs->trans("Description").'</td>';
  132. print '<td align="center" width="60">'.$langs->trans("Activated").'</td>';
  133. print '<td align="center" width="60">'.$langs->trans("Default").'</td>';
  134. print '<td align="center" width="80">'.$langs->trans("ShortInfo").'</td>';
  135. print "</tr>\n";
  136. clearstatcache();
  137. $handle=opendir($dir);
  138. $var=True;
  139. if (is_resource($handle))
  140. {
  141. while (($file = readdir($handle))!==false)
  142. {
  143. if (preg_match('/\.modules\.php$/i',$file))
  144. {
  145. $var = !$var;
  146. $name = substr($file, 0, dol_strlen($file) -12);
  147. $classname = substr($file, 0, dol_strlen($file) -12);
  148. require_once $dir.'/'.$file;
  149. $module=new $classname($db);
  150. // Show modules according to features level
  151. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  152. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  153. if ($module->isEnabled())
  154. {
  155. print '<tr '.$bc[$var].'><td width=\"100\">';
  156. echo $module->name;
  157. print '</td>';
  158. print '<td>';
  159. print $module->description;
  160. print '</td>';
  161. // Active
  162. if (in_array($name, $def))
  163. {
  164. print "<td align=\"center\">\n";
  165. if ($conf->global->DON_ADDON_MODEL == $name)
  166. {
  167. print img_picto($langs->trans("Enabled"),'switch_on');
  168. }
  169. else
  170. {
  171. print '&nbsp;';
  172. print '</td><td align="center">';
  173. print '<a href="dons.php?action=setdoc&value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Enabled"),'switch_on').'</a>';
  174. }
  175. print '</td>';
  176. }
  177. else
  178. {
  179. print "<td align=\"center\">\n";
  180. 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>';
  181. print "</td>";
  182. }
  183. // Defaut
  184. print "<td align=\"center\">";
  185. if ($conf->global->DON_ADDON_MODEL == "$name")
  186. {
  187. print img_picto($langs->trans("Default"),'on');
  188. }
  189. else
  190. {
  191. 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>';
  192. }
  193. print '</td>';
  194. // Info
  195. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  196. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  197. if ($module->type == 'pdf')
  198. {
  199. $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  200. }
  201. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  202. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  203. $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
  204. $text='<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'" target="specimen">'.img_object($langs->trans("Preview"),'generic').'</a>';
  205. print '<td align="center">';
  206. print $form->textwithpicto(' &nbsp; '.$text,$htmltooltip,-1,0);
  207. print '</td>';
  208. print "</tr>\n";
  209. }
  210. }
  211. }
  212. closedir($handle);
  213. }
  214. print '</table>';
  215. print "<br>";
  216. $db->close();
  217. llxFooter();
  218. ?>