* Copyright (C) 2003 Jean-Louis Bergamo * Copyright (C) 2004-2011 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/admin/societe_extrafields.php * \ingroup societe * \brief Page to setup extra fields of third party * \version $Id: societe_extrafields.php,v 1.6 2011/07/31 22:23:21 eldy Exp $ */ require("../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php"); $langs->load("companies"); $langs->load("admin"); $extrafields = new ExtraFields($db); $form = new Form($db); // List of supported format $type2label=array( 'varchar'=>$langs->trans('String'), 'text'=>$langs->trans('Text'), 'int'=>$langs->trans('Int'), //'date'=>$langs->trans('Date'), //'datetime'=>$langs->trans('DateAndTime') ); $action=GETPOST("action"); $elementtype='company'; if (!$user->admin) accessforbidden(); /* * Actions */ if ($action == 'add') { if ($_POST["button"] != $langs->trans("Cancel")) { // Check values if (GETPOST('type')=='varchar' && GETPOST('size') > 255) { $error++; $langs->load("errors"); $mesg=$langs->trans("ErrorSizeTooLongForVarcharType"); $action = 'create'; } if (! $error) { // Type et taille non encore pris en compte => varchar(255) if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname'])) { $result=$extrafields->addExtraField($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['pos'],$_POST['size'],$elementtype); if ($result > 0) { Header("Location: ".$_SERVER["PHP_SELF"]); exit; } else { $error++; $mesg=$extrafields->error; } } else { $error++; $langs->load("errors"); $mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode")); $action = 'create'; } } } } // Rename field if ($action == 'update') { if ($_POST["button"] != $langs->trans("Cancel")) { // Check values if (GETPOST('type')=='varchar' && GETPOST('size') > 255) { $error++; $langs->load("errors"); $mesg=$langs->trans("ErrorSizeTooLongForVarcharType"); $action = 'edit'; } if (! $error) { if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname'])) { $result=$extrafields->update($_POST['attrname'],$_POST['type'],$_POST['size'],$elementtype); if ($result > 0) { if (isset($_POST['label'])) { $extrafields->update_label($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['size'],$elementtype); } Header("Location: ".$_SERVER["PHP_SELF"]); exit; } else { $error++; $mesg=$extrafields->error; } } else { $error++; $langs->load("errors"); $mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode")); } } } } # Suppression attribut if ($action == 'delete') { if(isset($_GET["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_GET["attrname"])) { $result=$extrafields->delete($_GET["attrname"],$elementtype); if ($result >= 0) { Header("Location: ".$_SERVER["PHP_SELF"]); exit; } else $mesg=$extrafields->error; } else { $error++; $langs->load("errors"); $mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode")); } } /* * View */ $textobject=$langs->transnoentitiesnoconv("ThirdParty"); $help_url='EN:Module Third Parties setup|FR:Paramétrage_du_module_Tiers'; llxHeader('',$langs->trans("CompanySetup"),$help_url); $linkback=''.$langs->trans("BackToModuleList").''; print_fiche_titre($langs->trans("CompanySetup"),$linkback,'setup'); $head = societe_admin_prepare_head($adh); dol_fiche_head($head, 'attributes', $langs->trans("ThirdParty"), 0, 'company'); print $langs->trans("DefineHereComplementaryAttributes",$textobject).'
'."\n"; print '
'; dol_htmloutput_errors($mesg); // Load attribute_label $extrafields->fetch_name_optionals_label($elementtype); print ""; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; $var=True; foreach($extrafields->attribute_type as $key => $value) { $var=!$var; print ""; print "\n"; print "\n"; print "\n"; print '\n"; print '\n"; print ""; // $i++; } print "
'.$langs->trans("Label").''.$langs->trans("AttributeCode").''.$langs->trans("Type").''.$langs->trans("Size").' 
".$extrafields->attribute_label[$key]."".$key."".$type2label[$extrafields->attribute_type[$key]]."'.$extrafields->attribute_size[$key]."'.img_edit().''; print "  ".img_delete()."
"; dol_fiche_end(); /* * Barre d'actions * */ if ($action != 'create' && $action != 'edit') { print '"; } /* ************************************************************************** */ /* */ /* Creation d'un champ optionnel /* */ /* ************************************************************************** */ if ($action == 'create') { print "
"; print_titre($langs->trans('NewAttribute')); print '
'; print ''; print ''; print ''; // Label print ''; // Code print ''; // Type print ''; // Size print ''; print ''; print "\n"; print "
'.$langs->trans("Label").'
'.$langs->trans("AttributeCode").' ('.$langs->trans("AlphaNumOnlyCharsAndNoSpace").')
'.$langs->trans("Type").''; print $form->selectarray('type',$type2label,GETPOST('type')); print '
'.$langs->trans("Size").'
  '; print '
\n"; } /* ************************************************************************** */ /* */ /* Edition d'un champ optionnel */ /* */ /* ************************************************************************** */ if ($_GET["attrname"] && $action == 'edit') { print "
"; print_titre($langs->trans("FieldEdition",$_GET["attrname"])); /* * formulaire d'edition */ print '
'; print ''; print ''; print ''; print ''; // Label print ''; print ''; print ''; // Code print ''; print ''; print ''; print ''; // Type $type=$extrafields->attribute_type[$_GET["attrname"]]; $size=$extrafields->attribute_size[$_GET["attrname"]]; print ''; print ''; // Size print ''; print ''; print '
'.$langs->trans("Label").'
'.$langs->trans("AttributeCode").''.$_GET["attrname"].' 
'.$langs->trans("Type").''; print $type2label[$type]; print ''; print '
'.$langs->trans("Size").'
  '; print '
'; print "
"; } $db->close(); llxFooter('$Date: 2011/07/31 22:23:21 $ - $Revision: 1.6 $'); ?>