PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/product/admin/product_extrafields.php

https://bitbucket.org/speedealing/speedealing
PHP | 203 lines | 107 code | 45 blank | 51 comment | 13 complexity | 53bc1d3d7130f91cb374f3331301feea MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
  4. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2012 Marcos GarcĂ­a <marcosgdf@gmail.com>
  6. * Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.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/societe/admin/societe_extrafields.php
  23. * \ingroup societe
  24. * \brief Page to setup extra fields of third party
  25. */
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  29. $langs->load("companies");
  30. $langs->load("admin");
  31. $langs->load("products");
  32. $extrafields = new ExtraFields($db);
  33. $form = new Form($db);
  34. // List of supported format
  35. $tmptype2label=getStaticMember(get_class($extrafields),'type2label');
  36. $type2label=array('');
  37. foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->trans($val);
  38. $action=GETPOST('action', 'alpha');
  39. $attrname=GETPOST('attrname', 'alpha');
  40. $elementtype='product';
  41. if (!$user->admin) accessforbidden();
  42. /*
  43. * Actions
  44. */
  45. require DOL_DOCUMENT_ROOT.'/core/admin_extrafields.inc.php';
  46. /*
  47. * View
  48. */
  49. $title = $langs->trans('ProductServiceSetup');
  50. $tab = $langs->trans("ProductsAndServices");
  51. if (empty($conf->produit->enabled))
  52. {
  53. $title = $langs->trans('ServiceSetup');
  54. $tab = $langs->trans('Services');
  55. }
  56. else if (empty($conf->service->enabled))
  57. {
  58. $title = $langs->trans('ProductSetup');
  59. $tab = $langs->trans('Products');
  60. }
  61. llxHeader('',$title);
  62. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  63. print_fiche_titre($title,$linkback,'setup');
  64. $head = product_admin_prepare_head();
  65. dol_fiche_head($head, 'attributes', $tab, 0, 'product');
  66. print $langs->trans('DefineHereComplementaryAttributes', $tab).'<br>'."\n";
  67. print '<br>';
  68. dol_htmloutput_errors($mesg);
  69. // Load attribute_label
  70. $extrafields->fetch_name_optionals_label($elementtype);
  71. print "<table summary=\"listofattributes\" class=\"noborder\" width=\"100%\">";
  72. print '<tr class="liste_titre">';
  73. print '<td>'.$langs->trans("Label").'</td>';
  74. print '<td>'.$langs->trans("AttributeCode").'</td>';
  75. print '<td>'.$langs->trans("Type").'</td>';
  76. print '<td align="right">'.$langs->trans("Size").'</td>';
  77. print '<td align="right">'.$langs->trans("Unique").'</td>';
  78. print '<td width="80">&nbsp;</td>';
  79. print "</tr>\n";
  80. $var=True;
  81. foreach($extrafields->attribute_type as $key => $value)
  82. {
  83. $var=!$var;
  84. print "<tr ".$bc[$var].">";
  85. print "<td>".$extrafields->attribute_label[$key]."</td>\n";
  86. print "<td>".$key."</td>\n";
  87. print "<td>".$type2label[$extrafields->attribute_type[$key]]."</td>\n";
  88. print '<td align="right">'.$extrafields->attribute_size[$key]."</td>\n";
  89. print '<td align="right">'.yn($extrafields->attribute_unique[$key])."</td>\n";
  90. print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit&attrname='.$key.'">'.img_edit().'</a>';
  91. print "&nbsp; <a href=\"".$_SERVER["PHP_SELF"]."?action=delete&attrname=$key\">".img_delete()."</a></td>\n";
  92. print "</tr>";
  93. // $i++;
  94. }
  95. print "</table>";
  96. dol_fiche_end();
  97. // Buttons
  98. if ($action != 'create' && $action != 'edit')
  99. {
  100. print '<div class="tabsAction">';
  101. print "<a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?action=create\">".$langs->trans("NewAttribute")."</a>";
  102. print "</div>";
  103. }
  104. /* ************************************************************************** */
  105. /* */
  106. /* Creation d'un champ optionnel
  107. /* */
  108. /* ************************************************************************** */
  109. if ($action == 'create')
  110. {
  111. print "<br>";
  112. print_titre($langs->trans('NewAttribute'));
  113. require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
  114. }
  115. /* ************************************************************************** */
  116. /* */
  117. /* Edition d'un champ optionnel */
  118. /* */
  119. /* ************************************************************************** */
  120. if ($action == 'edit' && ! empty($attrname))
  121. {
  122. print "<br>";
  123. print_titre($langs->trans("FieldEdition", $attrname));
  124. /*
  125. * formulaire d'edition
  126. */
  127. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?attrname='.$attrname.'">';
  128. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  129. print '<input type="hidden" name="attrname" value="'.$attrname.'">';
  130. print '<input type="hidden" name="action" value="update">';
  131. print '<table summary="listofattributes" class="border" width="100%">';
  132. // Label
  133. print '<tr>';
  134. print '<td class="fieldrequired" required>'.$langs->trans("Label").'</td><td class="valeur"><input type="text" name="label" size="40" value="'.$extrafields->attribute_label[$attrname].'"></td>';
  135. print '</tr>';
  136. // Code
  137. print '<tr>';
  138. print '<td class="fieldrequired" required>'.$langs->trans("AttributeCode").'</td>';
  139. print '<td class="valeur">'.$attrname.'&nbsp;</td>';
  140. print '</tr>';
  141. // Type
  142. $type=$extrafields->attribute_type[$attrname];
  143. $size=$extrafields->attribute_size[$attrname];
  144. print '<tr><td class="fieldrequired" required>'.$langs->trans("Type").'</td>';
  145. print '<td class="valeur">';
  146. print $type2label[$type];
  147. print '<input type="hidden" name="type" value="'.$type.'">';
  148. print '</td></tr>';
  149. // Size
  150. print '<tr><td class="fieldrequired" required>'.$langs->trans("Size").'</td><td class="valeur"><input type="text" name="size" size="5" value="'.$size.'"></td></tr>';
  151. print '</table>';
  152. print '<center><br><input type="submit" name="button" class="button" value="'.$langs->trans("Save").'"> &nbsp; ';
  153. print '<input type="submit" name="button" class="button" value="'.$langs->trans("Cancel").'"></center>';
  154. print "</form>";
  155. }
  156. llxFooter();
  157. $db->close();
  158. ?>