From a60516ae0d192d21c974a6096b72030251239a15 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 25 Oct 2012 14:16:06 +0200 Subject: [PATCH 01/17] Fix: Show warning only if transaction level not correct --- htdocs/core/lib/functions.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 6416cac14ef..a5b2a8366e8 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -159,7 +159,7 @@ function dol_shutdown() global $conf,$user,$langs,$db; $disconnectdone=false; $depth=0; if (is_object($db) && ! empty($db->connected)) { $depth=$db->transaction_opened; $disconnectdone=$db->close(); } - dol_syslog("--- End access to ".$_SERVER["PHP_SELF"].($disconnectdone?' (Warn: db disconnection forced, transaction depth was '.$depth.')':''), ($disconnectdone?LOG_WARNING:LOG_DEBUG)); + dol_syslog("--- End access to ".$_SERVER["PHP_SELF"].(($disconnectdone && $depth)?' (Warn: db disconnection forced, transaction depth was '.$depth.')':''), (($disconnectdone && $depth)?LOG_WARNING:LOG_DEBUG)); } From cbff238cbd27861ac7e447a3f249363faa021ad0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 25 Oct 2012 16:23:58 +0200 Subject: [PATCH 02/17] New: Support property "required" for extra fields. --- .../adherents/admin/adherent_extrafields.php | 12 ++-- htdocs/adherents/fiche.php | 8 ++- htdocs/comm/addpropal.php | 4 +- htdocs/comm/mailing/fiche.php | 12 +++- htdocs/comm/propal.php | 4 +- htdocs/commande/fiche.php | 8 ++- htdocs/compta/facture.php | 8 ++- htdocs/contact/fiche.php | 34 +++++++---- htdocs/core/admin_extrafields.inc.php | 4 +- htdocs/core/class/extrafields.class.php | 4 +- htdocs/core/db/mysql.class.php | 3 +- htdocs/core/db/mysqli.class.php | 3 +- htdocs/core/db/pgsql.class.php | 3 + htdocs/core/tpl/admin_extrafields_add.tpl.php | 18 +++--- .../core/tpl/admin_extrafields_edit.tpl.php | 9 ++- htdocs/product/admin/product_extrafields.php | 43 ++------------ htdocs/product/fiche.php | 8 ++- htdocs/societe/admin/contact_extrafields.php | 43 ++------------ htdocs/societe/admin/societe_extrafields.php | 6 +- htdocs/societe/soc.php | 8 ++- test/soapui/Dolibarr-soapui-project.xml | 57 ++++++++++--------- 21 files changed, 147 insertions(+), 152 deletions(-) diff --git a/htdocs/adherents/admin/adherent_extrafields.php b/htdocs/adherents/admin/adherent_extrafields.php index 4941cff79c5..59fa9a28b95 100755 --- a/htdocs/adherents/admin/adherent_extrafields.php +++ b/htdocs/adherents/admin/adherent_extrafields.php @@ -1,7 +1,7 @@ * Copyright (C) 2003 Jean-Louis Bergamo - * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -88,7 +88,8 @@ print ''.$langs->trans("Label").''; print ''.$langs->trans("AttributeCode").''; print ''.$langs->trans("Type").''; print ''.$langs->trans("Size").''; -print ''.$langs->trans("Unique").''; +print ''.$langs->trans("Unique").''; +print ''.$langs->trans("Required").''; print ' '; print "\n"; @@ -101,7 +102,8 @@ foreach($extrafields->attribute_type as $key => $value) print "".$key."\n"; print "".$type2label[$extrafields->attribute_type[$key]]."\n"; print ''.$extrafields->attribute_size[$key]."\n"; - print ''.yn($extrafields->attribute_unique[$key])."\n"; + print ''.yn($extrafields->attribute_unique[$key])."\n"; + print ''.yn($extrafields->attribute_required[$key])."\n"; print ''.img_edit().''; print "  ".img_delete()."\n"; print ""; @@ -149,7 +151,7 @@ if ($action == 'edit' && ! empty($attrname)) require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php'; } -$db->close(); - llxFooter(); + +$db->close(); ?> diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php index 4807c408d9b..1658e4dd1f0 100644 --- a/htdocs/adherents/fiche.php +++ b/htdocs/adherents/fiche.php @@ -906,7 +906,9 @@ else foreach($extrafields->attribute_label as $key=>$label) { $value=(isset($_POST["options_".$key])?GETPOST('options_'.$key,'alpha'):$object->array_options["options_".$key]); - print ''.$label.''; + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print '>'.$label.''; print $extrafields->showInputField($key,$value); print ''."\n"; } @@ -1150,7 +1152,9 @@ else foreach($extrafields->attribute_label as $key=>$label) { $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print ''.$label.''; + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print '>'.$label.''; print $extrafields->showInputField($key,$value); print ''."\n"; } diff --git a/htdocs/comm/addpropal.php b/htdocs/comm/addpropal.php index 52f63e172a7..7d03960dd11 100644 --- a/htdocs/comm/addpropal.php +++ b/htdocs/comm/addpropal.php @@ -237,7 +237,9 @@ if ($action == 'create') foreach($extrafields->attribute_label as $key=>$label) { $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print "".$label.''; + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print '>'.$label.''; print $extrafields->showInputField($key,$value); print ''."\n"; } diff --git a/htdocs/comm/mailing/fiche.php b/htdocs/comm/mailing/fiche.php index 7fa1160d43d..8e3b5064a70 100644 --- a/htdocs/comm/mailing/fiche.php +++ b/htdocs/comm/mailing/fiche.php @@ -650,7 +650,9 @@ if ($action == 'create') foreach($extrafields->attribute_label as $key=>$label) { $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print ''.$label.''; + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print '>'.$label.''; print $extrafields->showInputField($key,$value); print ''."\n"; } @@ -810,7 +812,9 @@ else foreach($extrafields->attribute_label as $key=>$label) { $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print ''.$label.''; + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print '>'.$label.''; print $extrafields->showInputField($key,$value); print "\n"; } @@ -1044,7 +1048,9 @@ else foreach($extrafields->attribute_label as $key=>$label) { $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print ''.$label.''; + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print '>'.$label.''; print $extrafields->showInputField($key,$value); print "\n"; } diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 0f9d67113fd..0df445e2b28 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -1538,7 +1538,9 @@ if (empty($reshook) && ! empty($extrafields->attribute_label)) foreach($extrafields->attribute_label as $key=>$label) { $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print "".$label.''; + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print '>'.$label.''; print $extrafields->showInputField($key,$value); print ''."\n"; } diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 641fcbce1ae..aeae2a8e3f5 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -1517,7 +1517,9 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G foreach($extrafields->attribute_label as $key=>$label) { $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print "".$label.''; + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print '>'.$label.''; print $extrafields->showInputField($key,$value); print ''."\n"; } @@ -2047,7 +2049,9 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G foreach($extrafields->attribute_label as $key=>$label) { $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print ''.$label.''; + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print '>'.$label.''; print $extrafields->showInputField($key,$value); print ''."\n"; } diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 1d230ad7406..5963d2b13ec 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -2003,7 +2003,9 @@ if ($action == 'create') foreach($extrafields->attribute_label as $key=>$label) { $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print ''.$label.''; + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print '>'.$label.''; print $extrafields->showInputField($key,$value); print ''."\n"; } @@ -2970,7 +2972,9 @@ else if ($id > 0 || ! empty($ref)) foreach($extrafields->attribute_label as $key=>$label) { $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print ''.$label.''; + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print '>'.$label.''; print $extrafields->showInputField($key,$value); print ''."\n"; } diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index 7beb9e56799..3027eb22026 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -432,30 +432,36 @@ else print ''.$langs->trans("PostOrFunction").'poste).'">'; + $colspan=3; + if ($conf->use_javascript_ajax && $socid > 0) $colspan=2; + // Address if (($objsoc->typent_code == 'TE_PRIVATE' || ! empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->address)) == 0) $object->address = $objsoc->address; // Predefined with third party print ''.$langs->trans("Address"); - print ''; + print ''; - $rowspan=3; - if (empty($conf->global->SOCIETE_DISABLE_STATE)) $rowspan++; - - print ''; - if ($conf->use_javascript_ajax && $socid) print ''.$langs->trans('CopyAddressFromSoc').''; - print ''; + if ($conf->use_javascript_ajax && $socid > 0) + { + $rowspan=3; + if (empty($conf->global->SOCIETE_DISABLE_STATE)) $rowspan++; + + print ''; + print ''.$langs->trans('CopyAddressFromSoc').''; + print ''; + } print ''; // Zip / Town if (($objsoc->typent_code == 'TE_PRIVATE' || ! empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->zip)) == 0) $object->zip = $objsoc->zip; // Predefined with third party if (($objsoc->typent_code == 'TE_PRIVATE' || ! empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->town)) == 0) $object->town = $objsoc->town; // Predefined with third party - print ''.$langs->trans("Zip").' / '.$langs->trans("Town").''; + print ''.$langs->trans("Zip").' / '.$langs->trans("Town").''; print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6).' '; print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectcountry_id','state_id')); print ''; // Country if (dol_strlen(trim($object->fk_pays)) == 0) $object->fk_pays = $objsoc->country_id; // Predefined with third party - print ''.$langs->trans("Country").''; + print ''.$langs->trans("Country").''; print $form->select_country((isset($_POST["country_id"])?$_POST["country_id"]:$object->country_id),'country_id'); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); print ''; @@ -463,7 +469,7 @@ else // State if (empty($conf->global->SOCIETE_DISABLE_STATE)) { - print ''.$langs->trans('State').''; + print ''.$langs->trans('State').''; if ($object->country_id) { print $formcompany->select_state(isset($_POST["state_id"])?$_POST["state_id"]:$object->state_id,$object->country_code,'state_id'); @@ -517,7 +523,9 @@ else foreach($extrafields->attribute_label as $key=>$label) { $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:(isset($object->array_options["options_".$key])?$object->array_options["options_".$key]:'')); - print ''.$label.''; + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print '>'.$label.''; print $extrafields->showInputField($key,$value); print ''."\n"; } @@ -732,7 +740,9 @@ else foreach($extrafields->attribute_label as $key=>$label) { $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print ''.$label.''; + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print '>'.$label.''; print $extrafields->showInputField($key,$value); print "\n"; } diff --git a/htdocs/core/admin_extrafields.inc.php b/htdocs/core/admin_extrafields.inc.php index c1a7da31374..84624eda50b 100644 --- a/htdocs/core/admin_extrafields.inc.php +++ b/htdocs/core/admin_extrafields.inc.php @@ -64,7 +64,7 @@ if ($action == 'add') // 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'],$extrasize,$elementtype,(GETPOST('unique')?1:0)); + $result=$extrafields->addExtraField($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['pos'],$extrasize,$elementtype,(GETPOST('unique')?1:0),(GETPOST('required')?1:0)); if ($result > 0) { header("Location: ".$_SERVER["PHP_SELF"]); @@ -119,7 +119,7 @@ if ($action == 'update') { if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname'])) { - $result=$extrafields->update($_POST['attrname'],$_POST['label'],$_POST['type'],$extrasize,$elementtype,(GETPOST('unique')?1:0)); + $result=$extrafields->update($_POST['attrname'],$_POST['label'],$_POST['type'],$extrasize,$elementtype,(GETPOST('unique')?1:0),(GETPOST('required')?1:0)); if ($result > 0) { header("Location: ".$_SERVER["PHP_SELF"]); diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index a0eb75b61bc..6a129787f76 100755 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -91,7 +91,7 @@ class ExtraFields if (empty($label)) return -1; // Create field into database - $result=$this->create($attrname,$type,$size,$elementtype, $unique); + $result=$this->create($attrname,$type,$size,$elementtype, $unique, $required); $err1=$this->errno; if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS') { @@ -361,7 +361,7 @@ class ExtraFields private function update_label($attrname,$label,$type,$size,$elementtype,$unique=0,$required=0) { global $conf; - dol_syslog(get_class($this)."::update_label $attrname,$label,$type,$size"); + dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required); if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) { diff --git a/htdocs/core/db/mysql.class.php b/htdocs/core/db/mysql.class.php index dc33a4eb17d..86374b94dea 100644 --- a/htdocs/core/db/mysql.class.php +++ b/htdocs/core/db/mysql.class.php @@ -1011,7 +1011,8 @@ class DoliDBMysql $sql = "ALTER TABLE ".$table; $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type']; if ($field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') $sql.="(".$field_desc['value'].")"; - + if ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL') $sql.=" NOT NULL"; + dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG); if (! $this->query($sql)) return -1; diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index 8db96ca32a1..a5e296b5a8b 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -1005,7 +1005,8 @@ class DoliDBMysqli $sql = "ALTER TABLE ".$table; $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type']; if ($field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') $sql.="(".$field_desc['value'].")"; - + if ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL') $sql.=" NOT NULL"; + dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG); if (! $this->query($sql)) return -1; diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index 16f02559e28..e45352c0ed4 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -1221,6 +1221,9 @@ class DoliDBPgsql $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type']; if ($field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') $sql.="(".$field_desc['value'].")"; + // FIXME May not work with pgsql. May need to run a second request. If it works, just remove the FIXME tag + if ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL') $sql.=" NOT NULL"; + dol_syslog($sql,LOG_DEBUG); if (! $this->query($sql)) return -1; diff --git a/htdocs/core/tpl/admin_extrafields_add.tpl.php b/htdocs/core/tpl/admin_extrafields_add.tpl.php index a4ebedcc54c..c4cacb0b23e 100644 --- a/htdocs/core/tpl/admin_extrafields_add.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_add.tpl.php @@ -23,12 +23,14 @@ function init_typeoffields(type) { var size = jQuery("#size"); - if (type == 'date') { size.val('').attr('disabled','disabled'); } - else if (type == 'datetime') { size.val('').attr('disabled','disabled'); } - else if (type == 'double') { size.val('24,8').removeAttr('disabled'); } - else if (type == 'int') { size.val('10').removeAttr('disabled'); } - else if (type == 'text') { size.val('2000').removeAttr('disabled'); } - else if (type == 'varchar') { size.val('255').removeAttr('disabled'); } + var unique = jQuery("#unique"); + var required = jQuery("#required"); + if (type == 'date') { size.val('').attr('disabled','disabled'); unique.removeAttr('disabled','disabled'); } + else if (type == 'datetime') { size.val('').attr('disabled','disabled'); unique.removeAttr('disabled','disabled'); } + else if (type == 'double') { size.val('24,8').removeAttr('disabled'); unique.removeAttr('disabled','disabled'); } + else if (type == 'int') { size.val('10').removeAttr('disabled'); unique.removeAttr('disabled','disabled'); } + else if (type == 'text') { size.val('2000').removeAttr('disabled'); unique.attr('disabled','disabled').removeAttr('checked'); } + else if (type == 'varchar') { size.val('255').removeAttr('disabled'); unique.removeAttr('disabled','disabled'); } else size.val('').attr('disabled','disabled'); } init_typeoffields(''); @@ -55,7 +57,9 @@ trans("Size"); ?> -trans("Unique"); ?>"> +trans("Unique"); ?>> + +trans("Required"); ?>>

">   diff --git a/htdocs/core/tpl/admin_extrafields_edit.tpl.php b/htdocs/core/tpl/admin_extrafields_edit.tpl.php index b93f136bc5d..e63c6856210 100644 --- a/htdocs/core/tpl/admin_extrafields_edit.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_edit.tpl.php @@ -23,11 +23,13 @@ function init_typeoffields(type) { var size = jQuery("#size"); + var unique = jQuery("#unique"); + var required = jQuery("#required"); if (type == 'date') { size.attr('disabled','disabled'); } else if (type == 'datetime') { size.attr('disabled','disabled'); } else if (type == 'double') { size.removeAttr('disabled'); } else if (type == 'int') { size.removeAttr('disabled'); } - else if (type == 'text') { size.removeAttr('disabled'); } + else if (type == 'text') { size.removeAttr('disabled'); unique.attr('disabled','disabled').removeAttr('checked'); } else if (type == 'varchar') { size.removeAttr('disabled'); } else size.val('').attr('disabled','disabled'); } @@ -52,6 +54,7 @@ $type=$extrafields->attribute_type[$attrname]; $size=$extrafields->attribute_size[$attrname]; $unique=$extrafields->attribute_unique[$attrname]; +$required=$extrafields->attribute_required[$attrname]; ?> trans("Type"); ?> @@ -60,7 +63,9 @@ $unique=$extrafields->attribute_unique[$attrname]; trans("Size"); ?> -trans("Unique"); ?>"> +trans("Unique"); ?>> + +trans("Required"); ?>> diff --git a/htdocs/product/admin/product_extrafields.php b/htdocs/product/admin/product_extrafields.php index 7c445643881..1671b3cf770 100755 --- a/htdocs/product/admin/product_extrafields.php +++ b/htdocs/product/admin/product_extrafields.php @@ -101,7 +101,8 @@ print ''.$langs->trans("Label").''; print ''.$langs->trans("AttributeCode").''; print ''.$langs->trans("Type").''; print ''.$langs->trans("Size").''; -print ''.$langs->trans("Unique").''; +print ''.$langs->trans("Unique").''; +print ''.$langs->trans("Required").''; print ' '; print "\n"; @@ -114,7 +115,8 @@ foreach($extrafields->attribute_type as $key => $value) print "".$key."\n"; print "".$type2label[$extrafields->attribute_type[$key]]."\n"; print ''.$extrafields->attribute_size[$key]."\n"; - print ''.yn($extrafields->attribute_unique[$key])."\n"; + print ''.yn($extrafields->attribute_unique[$key])."\n"; + print ''.yn($extrafields->attribute_required[$key])."\n"; print ''.img_edit().''; print "  ".img_delete()."\n"; print ""; @@ -159,42 +161,7 @@ if ($action == 'edit' && ! empty($attrname)) print "
"; print_titre($langs->trans("FieldEdition", $attrname)); - /* - * formulaire d'edition - */ - print '
'; - print ''; - print ''; - print ''; - print ''; - - // Label - print ''; - print ''; - print ''; - // Code - print ''; - print ''; - print ''; - print ''; - // Type - $type=$extrafields->attribute_type[$attrname]; - $size=$extrafields->attribute_size[$attrname]; - print ''; - print ''; - // Size - print ''; - - print '
'.$langs->trans("Label").'
'.$langs->trans("AttributeCode").''.$attrname.' 
'.$langs->trans("Type").''; - print $type2label[$type]; - print ''; - print '
'.$langs->trans("Size").'
'; - - print '

  '; - print '
'; - - print "
"; - + require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php'; } llxFooter(); diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index 42faf7ff7da..ce68665cb69 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -828,7 +828,9 @@ else foreach($extrafields->attribute_label as $key=>$label) { $value=(GETPOST('options_'.$key)?GETPOST('options_'.$key):$object->array_options["options_".$key]); - print ''.$label.''; + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print '>'.$label.''; print $extrafields->showInputField($key,$value); print ''."\n"; } @@ -1037,7 +1039,9 @@ else foreach($extrafields->attribute_label as $key=>$label) { $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print ''.$label.''; + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print '>'.$label.''; print $extrafields->showInputField($key,$value); print ''."\n"; } diff --git a/htdocs/societe/admin/contact_extrafields.php b/htdocs/societe/admin/contact_extrafields.php index baed4711c32..61f72f29d5c 100755 --- a/htdocs/societe/admin/contact_extrafields.php +++ b/htdocs/societe/admin/contact_extrafields.php @@ -88,7 +88,8 @@ print ''.$langs->trans("Label").''; print ''.$langs->trans("AttributeCode").''; print ''.$langs->trans("Type").''; print ''.$langs->trans("Size").''; -print ''.$langs->trans("Unique").''; +print ''.$langs->trans("Unique").''; +print ''.$langs->trans("Required").''; print ' '; print "\n"; @@ -101,7 +102,8 @@ foreach($extrafields->attribute_type as $key => $value) print "".$key."\n"; print "".$type2label[$extrafields->attribute_type[$key]]."\n"; print ''.$extrafields->attribute_size[$key]."\n"; - print ''.yn($extrafields->attribute_unique[$key])."\n"; + print ''.yn($extrafields->attribute_unique[$key])."\n"; + print ''.yn($extrafields->attribute_required[$key])."\n"; print ''.img_edit().''; print "  ".img_delete()."\n"; print ""; @@ -146,42 +148,7 @@ if ($action == 'edit' && ! empty($attrname)) print "
"; print_titre($langs->trans("FieldEdition", $attrname)); - /* - * formulaire d'edition - */ - print '
'; - print ''; - print ''; - print ''; - print ''; - - // Label - print ''; - print ''; - print ''; - // Code - print ''; - print ''; - print ''; - print ''; - // Type - $type=$extrafields->attribute_type[$attrname]; - $size=$extrafields->attribute_size[$attrname]; - print ''; - print ''; - // Size - print ''; - - print '
'.$langs->trans("Label").'
'.$langs->trans("AttributeCode").''.$attrname.' 
'.$langs->trans("Type").''; - print $type2label[$type]; - print ''; - print '
'.$langs->trans("Size").'
'; - - print '

  '; - print '
'; - - print "
"; - + require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php'; } llxFooter(); diff --git a/htdocs/societe/admin/societe_extrafields.php b/htdocs/societe/admin/societe_extrafields.php index 81c60a3cfb4..f093186e1c9 100755 --- a/htdocs/societe/admin/societe_extrafields.php +++ b/htdocs/societe/admin/societe_extrafields.php @@ -88,7 +88,8 @@ print ''.$langs->trans("Label").''; print ''.$langs->trans("AttributeCode").''; print ''.$langs->trans("Type").''; print ''.$langs->trans("Size").''; -print ''.$langs->trans("Unique").''; +print ''.$langs->trans("Unique").''; +print ''.$langs->trans("Required").''; print ' '; print "\n"; @@ -101,7 +102,8 @@ foreach($extrafields->attribute_type as $key => $value) print "".$key."\n"; print "".$type2label[$extrafields->attribute_type[$key]]."\n"; print ''.$extrafields->attribute_size[$key]."\n"; - print ''.yn($extrafields->attribute_unique[$key])."\n"; + print ''.yn($extrafields->attribute_unique[$key])."\n"; + print ''.yn($extrafields->attribute_required[$key])."\n"; print ''.img_edit().''; print "  ".img_delete()."\n"; print ""; diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index 2a5650aad91..05b0644d4ac 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -957,7 +957,9 @@ else foreach($extrafields->attribute_label as $key=>$label) { $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:(isset($object->array_options["options_".$key])?$object->array_options["options_".$key]:'')); - print ''.$label.''; + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print '>'.$label.''; print $extrafields->showInputField($key,$value); print ''."\n"; } @@ -1379,7 +1381,9 @@ else foreach($extrafields->attribute_label as $key=>$label) { $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print ''.$label.''; + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print '>'.$label.''; print $extrafields->showInputField($key,$value); print "\n"; } diff --git a/test/soapui/Dolibarr-soapui-project.xml b/test/soapui/Dolibarr-soapui-project.xml index 973bfb6e1d0..e74f5181696 100755 --- a/test/soapui/Dolibarr-soapui-project.xml +++ b/test/soapui/Dolibarr-soapui-project.xml @@ -1,5 +1,5 @@ - -http://localhostdolibarr/dolibarrnew/webservices/server_other.php?wsdl + +http://localhostdolibarr/dolibarrnew/webservices/server_other.php?wsdl @@ -522,7 +522,7 @@ dolibarrkey aaa admin - admin + changeme 1 @@ -536,7 +536,7 @@ - dolibarrkey + ? ? admin admin @@ -692,7 +692,7 @@ -]]>http://schemas.xmlsoap.org/wsdl/http://localhostdolibarr/dolibarrnew/webservices/server_productorservice.php<xml-fragment/>UTF-8http://localhostdolibarr/dolibarrnew/webservices/server_productorservice.php +]]>http://schemas.xmlsoap.org/wsdl/http://localhost/dolibarr/htdocs/webservices/server_productorservice.php<xml-fragment/>UTF-8http://localhost/dolibarr/htdocs/webservices/server_productorservice.php @@ -733,14 +733,14 @@ -]]><xml-fragment/>UTF-8http://localhostdolibarr/dolibarrnew/webservices/server_productorservice.php +]]><xml-fragment/>UTF-8http://localhost/dolibarr/htdocs/webservices/server_productorservice.php dolibarrkey - + ? admin admin @@ -750,27 +750,27 @@ -]]><xml-fragment/>UTF-8http://localhostdolibarr/dolibarrnew/webservices/server_productorservice.php +]]>UTF-8http://localhost/dolibarr/htdocs/webservices/server_productorservice.php - dolibarrkey + ? ? - admin - admin - + ? + ? + ? - 0 - - + ? + ? + ? -]]>http://localhostdolibarr/webservices/server_user.php?wsdl +]]>http://localhostdolibarr/webservices/server_user.php?wsdl @@ -1028,21 +1028,24 @@ -]]>http://schemas.xmlsoap.org/wsdl/http://localhostdolibarr/webservices/server_thirdparty.php<xml-fragment/>UTF-8http://localhostdolibarr/webservices/server_thirdparty.php - - - +]]>http://schemas.xmlsoap.org/wsdl/http://localhostdolibarr/webservices/server_thirdparty.php<xml-fragment/>UTF-8http://localhostdolibarr/webservices/server_thirdparty.php + + + + + dolibarrkey - PRESTASHOP + aaa admin admin - + - - - - -]]>UTF-8http://localhostdolibarr/webservices/server_thirdparty.php + 1 + + + + +]]>UTF-8http://localhostdolibarr/webservices/server_thirdparty.php From 7eae9988684e5aa6b535cb9a14c4e2604082d497 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 26 Oct 2012 00:57:51 +0200 Subject: [PATCH 03/17] Fix: Bad default value --- htdocs/install/mysql/tables/llx_product.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/install/mysql/tables/llx_product.sql b/htdocs/install/mysql/tables/llx_product.sql index f8faa8f59e6..c8f340e735b 100644 --- a/htdocs/install/mysql/tables/llx_product.sql +++ b/htdocs/install/mysql/tables/llx_product.sql @@ -67,7 +67,7 @@ create table llx_product volume_units tinyint DEFAULT NULL, stock integer, -- Current physical stock (dernormalized field) pmp double(24,8) DEFAULT 0 NOT NULL, - canvas varchar(32) DEFAULT 'default@product', + canvas varchar(32) DEFAULT NULL, finished tinyint DEFAULT NULL, hidden tinyint DEFAULT 0, -- Need permission see also hidden products import_key varchar(14) -- Import key From bc2280e4ab35cc6c1ae14df0befe7b3d3d52869b Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 26 Oct 2012 09:12:19 +0200 Subject: [PATCH 04/17] Fix: avoid phpunit warning --- htdocs/exports/class/export.class.php | 2 +- test/phpunit/ExportTest.php | 58 +++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/htdocs/exports/class/export.class.php b/htdocs/exports/class/export.class.php index 8e7115137b6..25149294e0d 100644 --- a/htdocs/exports/class/export.class.php +++ b/htdocs/exports/class/export.class.php @@ -476,7 +476,7 @@ class Export require_once $dir.$file; $objmodel = new $classname($this->db); - if ($sqlquery) $sql = $sqlquery; + if (! empty($sqlquery)) $sql = $sqlquery; else $sql=$this->build_sql($indice, $array_selected, $array_filterValue, $array_filtered); // Run the sql diff --git a/test/phpunit/ExportTest.php b/test/phpunit/ExportTest.php index 267af4057fc..0d0fcf8186f 100755 --- a/test/phpunit/ExportTest.php +++ b/test/phpunit/ExportTest.php @@ -144,27 +144,77 @@ class ExportTest extends PHPUnit_Framework_TestCase $model='csv'; // Build export file - $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $sql); + $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), array(), $sql); $expectedresult=1; $this->assertEquals($result,$expectedresult); $model='tsv'; // Build export file - $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $sql); + $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), array(), $sql); $expectedresult=1; $this->assertEquals($result,$expectedresult); $model='excel'; // Build export file - $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $sql); + $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), array(), $sql); $expectedresult=1; $this->assertEquals($result,$expectedresult); return true; } + /** + * Test filtered export function + * + * @return void + */ + public function testExportFilteredExport() + { + global $conf,$user,$langs,$db; + + $sql = "SELECT f.facnumber as f_facnumber, f.amount as f_amount, f.total as f_total, f.tva as f_tva FROM ".MAIN_DB_PREFIX."facture f"; + + $objexport=new Export($db); + //$objexport->load_arrays($user,$datatoexport); + + // Define properties + $datatoexport='test'; + $array_selected = array("f.facnumber"=>1, "f.amount"=>2, "f.total"=>3, "f.tva"=>4); + $array_export_fields = array("f.facnumber"=>"FacNumber", "f.amount"=>"FacAmount", "f.total"=>"FacTotal", "f.tva"=>"FacVat"); + $array_filtervalue = array("f.amount" => ">100"); + $array_filtered = array("f.amount" => 1); + $array_alias = array("f_facnumber"=>"facnumber", "f_amount"=>"amount", "f_total"=>"total", "f_tva"=>"tva"); + $objexport->array_export_fields[0]=$array_export_fields; + $objexport->array_export_alias[0]=$array_alias; + + dol_mkdir($conf->export->dir_temp); + + $model='csv'; + + // Build export file + $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $array_filtervalue, $array_filtered, $sql); + $expectedresult=1; + $this->assertEquals($result,$expectedresult); + + $model='tsv'; + + // Build export file + $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $array_filtervalue, $array_filtered, $sql); + $expectedresult=1; + $this->assertEquals($result,$expectedresult); + + $model='excel'; + + // Build export file + $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $array_filtervalue, $array_filtered, $sql); + $expectedresult=1; + $this->assertEquals($result,$expectedresult); + + return true; + } + /** * Test export function * @@ -183,7 +233,7 @@ class ExportTest extends PHPUnit_Framework_TestCase $result=$objexport->load_arrays($user,$datatoexport); // Build export file - $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $sql); + $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), array(), $sql); $expectedresult=1; $this->assertEquals($result,$expectedresult); From 4a0336759eb6cdf5742dd4d7224b536c91b8391d Mon Sep 17 00:00:00 2001 From: simnandez Date: Fri, 26 Oct 2012 09:21:08 +0200 Subject: [PATCH 05/17] Trad: Add ca_ES and es_ES missing translations --- htdocs/langs/ca_ES/admin.lang | 13 +++++++------ htdocs/langs/ca_ES/other.lang | 2 +- htdocs/langs/es_ES/admin.lang | 13 +++++++------ htdocs/langs/es_ES/other.lang | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/htdocs/langs/ca_ES/admin.lang b/htdocs/langs/ca_ES/admin.lang index 48569efa05e..06873ef9f89 100644 --- a/htdocs/langs/ca_ES/admin.lang +++ b/htdocs/langs/ca_ES/admin.lang @@ -1059,14 +1059,14 @@ LDAPServerUseTLS=Usuari TLS LDAPServerUseTLSExample=El seu servidor utilitza TLS LDAPServerDn=DN del servidor LDAPAdminDn=DN del administrador -LDAPAdminDnExample=DN complet (ej: cn=adminldap,dc=my-domain,dc=com) +LDAPAdminDnExample=DN complet (ej: cn=adminldap,dc=example,dc=com) LDAPPassword=Contrasenya de l'administrador LDAPUserDn=DN dels usuaris -LDAPUserDnExample=DN complet (ej: ou=users,dc=my-domain,dc=com) +LDAPUserDnExample=DN complet (ej: ou=users,dc=example,dc=com) LDAPGroupDn=DN dels grups -LDAPGroupDnExample=DN complet (ej: ou=groups,dc=my-domain,dc=com) +LDAPGroupDnExample=DN complet (ej: ou=groups,dc=example,dc=com) LDAPServerExample=Adreça del servidor (ej: localhost, 192.168.0.2, ldaps://ldap.example.com/) -LDAPServerDnExample=DN complet (ej: dc=my-domain,dc=com) +LDAPServerDnExample=DN complet (ej: dc=example,dc=com) LDAPPasswordExample=Contrasenya del administrador LDAPDnSynchroActive=Sincronització d'usuaris i grups LDAPDnSynchroActiveExample=Sincronització LDAP vers Dolibarr ó Dolibarr vers LDAP @@ -1076,9 +1076,9 @@ LDAPDnContactActiveExample=Sincronització activada/desactivada LDAPDnMemberActive=Sincronització dels membres LDAPDnMemberActiveExample=Sincronització activada/desactivada LDAPContactDn=DN dels contactes Dolibarr -LDAPContactDnExample=DN complet (ej: ou=contacts,dc=my-domain,dc=com) +LDAPContactDnExample=DN complet (ej: ou=contacts,dc=example,dc=com) LDAPMemberDn=DN dels membres -LDAPMemberDnExample=DN complet (ex: ou=members,dc=society,dc=com) +LDAPMemberDnExample=DN complet (ex: ou=members,dc=example,dc=com) LDAPMemberObjectClassList=Llista de objectClass LDAPMemberObjectClassListExample=Llista de ObjectClass que defineixen els atributs d'un registre (ex: top, inetorgperson o top, user for active directory) LDAPUserObjectClassList=Llista de objectClass @@ -1094,6 +1094,7 @@ LDAPTestSynchroContact=Provar la sincronització de contactes LDAPTestSynchroUser=Provar la sincronització d'usuaris LDAPTestSynchroGroup=Provar la sincronització de grups LDAPTestSynchroMember=Provar la sincronització de membres +LDAPTestSearch=Provar una recerca LDAP LDAPSynchroOK=Prova de sincronització realitzada correctament LDAPSynchroKO=Prova de sincronització errònia LDAPSynchroKOMayBePermissions=Error de la prova de sincronització. Comproveu que la connexió al servidor sigui correcta i que permet les actualitzacions LDAP diff --git a/htdocs/langs/ca_ES/other.lang b/htdocs/langs/ca_ES/other.lang index 2ff868eec4f..45fadd6eefe 100644 --- a/htdocs/langs/ca_ES/other.lang +++ b/htdocs/langs/ca_ES/other.lang @@ -113,7 +113,7 @@ VolumeUnitmm3=mm3 (µl) VolumeUnitounce=unça VolumeUnitlitre=litre VolumeUnitgallon=galó -Size=tamany +Size=Tamany SizeUnitm=m SizeUnitdm=dm SizeUnitcm=cm diff --git a/htdocs/langs/es_ES/admin.lang b/htdocs/langs/es_ES/admin.lang index 5d454ea8565..d5a9df404a9 100644 --- a/htdocs/langs/es_ES/admin.lang +++ b/htdocs/langs/es_ES/admin.lang @@ -1062,12 +1062,12 @@ LDAPServerUseTLS=Usuario TLS LDAPServerUseTLSExample=Su servidor utiliza TLS LDAPServerDn=DN del servidor LDAPAdminDn=DN del administrador -LDAPAdminDnExample=DN completo (ej: cn=adminldap,dc=my-domain,dc=com) +LDAPAdminDnExample=DN completo (ej: cn=adminldap,dc=example,dc=com) LDAPPassword=Contraseña del administrador LDAPUserDn=DN de los usuarios -LDAPUserDnExample=DN completo (ej: ou=users,dc=my-domain,dc=com) +LDAPUserDnExample=DN completo (ej: ou=users,dc=example,dc=com) LDAPGroupDn=DN de los grupos -LDAPGroupDnExample=DN completo (ej: ou=groups,dc=my-domain,dc=com) +LDAPGroupDnExample=DN completo (ej: ou=groups,dc=example,dc=com) LDAPServerExample=Dirección del servidor (ej: localhost, 192.168.0.2, ldaps://ldap.example.com/) LDAPServerDnExample=DN completo (ej: dc=my-domain,dc=com) LDAPPasswordExample=Contraseña del administrador @@ -1079,7 +1079,7 @@ LDAPDnContactActiveExample=Sincronización activada/desactivada LDAPDnMemberActive=Sincronización de los miembros LDAPDnMemberActiveExample=Sincronización activada/desactivada LDAPContactDn=DN de los contactos Dolibarr -LDAPContactDnExample=DN completo (ej: ou=contacts,dc=my-domain,dc=com) +LDAPContactDnExample=DN completo (ej: ou=contacts,dc=example,dc=com) LDAPMemberDn=DN de los miembros LDAPMemberDnExample=DN completo (ex: ou=members,dc=society,dc=com) LDAPMemberObjectClassList=Lista de objectClass @@ -1091,12 +1091,13 @@ LDAPGroupObjectClassListExample=Lista de ObjectClass que definen los atributos d LDAPContactObjectClassList=Lista de objectClass LDAPContactObjectClassListExample=Lista de objectClass que definen los atributos de un registro (ej: top,inetOrgPerson o top,user for active directory) LDAPMemberTypeDn=DN de los tipos de miembros -LDAPMemberTypeDnExample=DN complet (ej: ou=type_members,dc=society,dc=com) +LDAPMemberTypeDnExample=DN complet (ej: ou=type_members,dc=example,dc=com) LDAPTestConnect=Probar la conexión LDAP LDAPTestSynchroContact=Probar la sincronización de contactos LDAPTestSynchroUser=Probar la sincronización de usuarios LDAPTestSynchroGroup=Probar la sincronización de grupos LDAPTestSynchroMember=Probar la sincronización de miembros +LDAPTestSearch=Probar una búsqueda LDAP LDAPSynchroOK=Prueba de sincronización realizada correctamente LDAPSynchroKO=Prueba de sincronización erronea LDAPSynchroKOMayBePermissions=Error de la prueba de sincronización. Compruebe que la conexión al servidor sea correcta y que permite las actualizaciones LDAP @@ -1129,7 +1130,7 @@ LDAPFieldCommonNameExample=Ejemplo : cn LDAPFieldName=Nombre LDAPFieldNameExample=Ejemplo : sn LDAPFieldFirstName=Nombre -LDAPFieldFirstNameExample=Ejemplo : givenname +LDAPFieldFirstNameExample=Ejemplo : givenName LDAPFieldMail=E-Mail LDAPFieldMailExample=Ejemplo : mail LDAPFieldPhone=Teléfono trabajo diff --git a/htdocs/langs/es_ES/other.lang b/htdocs/langs/es_ES/other.lang index df10df64e11..2b8c16417f0 100644 --- a/htdocs/langs/es_ES/other.lang +++ b/htdocs/langs/es_ES/other.lang @@ -112,7 +112,7 @@ VolumeUnitmm3=mm3 (µl) VolumeUnitounce=onza VolumeUnitlitre=litro VolumeUnitgallon=galón -Size=tamaño +Size=Tamaño SizeUnitm=m SizeUnitdm=dm SizeUnitcm=cm From c521a77e92dc8d162c7b26a95a352ac7095f8d4a Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 26 Oct 2012 15:20:47 +0200 Subject: [PATCH 06/17] New: add key generator in webservices admin page --- htdocs/core/modules/modProjet.class.php | 2 ++ htdocs/webservices/admin/webservices.php | 41 +++++++++++++++++------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/htdocs/core/modules/modProjet.class.php b/htdocs/core/modules/modProjet.class.php index 52f2040caff..01b39fadfb0 100644 --- a/htdocs/core/modules/modProjet.class.php +++ b/htdocs/core/modules/modProjet.class.php @@ -42,6 +42,8 @@ class modProjet extends DolibarrModules */ function __construct($db) { + global $conf; + $this->db = $db; $this->numero = 400; diff --git a/htdocs/webservices/admin/webservices.php b/htdocs/webservices/admin/webservices.php index 85fc5023455..dccfce8ed82 100644 --- a/htdocs/webservices/admin/webservices.php +++ b/htdocs/webservices/admin/webservices.php @@ -1,7 +1,8 @@ - * Copyright (C) 2005-2010 Laurent Destailleur - * Copyright (C) 2011 Juanjo Menent +/* Copyright (C) 2004 Rodolphe Quiedeville + * Copyright (C) 2005-2010 Laurent Destailleur + * Copyright (C) 2011 Juanjo Menent + * Copyright (C) 2012 Regis Houssin * * 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 @@ -28,10 +29,10 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; $langs->load("admin"); -if (! $user->admin) accessforbidden(); +if (! $user->admin) + accessforbidden(); $actionsave=GETPOST("save"); -$mesg=''; // Sauvegardes parametres if ($actionsave) @@ -45,12 +46,12 @@ if ($actionsave) if ($i >= 1) { $db->commit(); - $mesg = "".$langs->trans("SetupSaved").""; + setEventMessage($langs->trans("SetupSaved")); } else { $db->rollback(); - $mesg = "".$langs->trans("Error").""; + setEventMessage($langs->trans("Error"), 'errors'); } } @@ -80,7 +81,10 @@ print ""; print ''; print ''.$langs->trans("KeyForWebServicesAccess").''; -print ''; +print ''; +if (! empty($conf->use_javascript_ajax)) + print ' '.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"'); +print ''; print ' '; print ''; @@ -92,8 +96,6 @@ print ''; print ''; -dol_htmloutput_mesg($mesg); - print '

'; @@ -154,7 +156,24 @@ print '
'; print '
'; print $langs->trans("OnlyActiveElementsAreShown", DOL_URL_ROOT.'/admin/modules.php'); -$db->close(); +if (! empty($conf->use_javascript_ajax)) +{ + print "\n".''; +} + llxFooter(); +$db->close(); ?> From 970933ec7f7dc2c405108243b675bde0294ca7fc Mon Sep 17 00:00:00 2001 From: simnandez Date: Fri, 26 Oct 2012 17:29:41 +0200 Subject: [PATCH 07/17] Fix: [ bug #579 ] Multi-Company and imports --- .../modules/import/import_csv.modules.php | 48 +++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/htdocs/core/modules/import/import_csv.modules.php b/htdocs/core/modules/import/import_csv.modules.php index 1861e974576..da2493264be 100644 --- a/htdocs/core/modules/import/import_csv.modules.php +++ b/htdocs/core/modules/import/import_csv.modules.php @@ -2,6 +2,7 @@ /* Copyright (C) 2006-2012 Laurent Destailleur * Copyright (C) 2009-2012 Regis Houssin * Copyright (C) 2012 Christophe Battarel + * Copyright (C) 2012 Juanjo Menent * * 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 @@ -583,10 +584,19 @@ class ImportCsv extends ModeleImports //var_dump($objimport->array_import_convertvalue); exit; // Build SQL request - $sql ='INSERT INTO '.$tablename.'('.$listfields.', import_key'; - if (! empty($objimport->array_import_tables_creator[0][$alias])) $sql.=', '.$objimport->array_import_tables_creator[0][$alias]; - $sql.=') VALUES('.$listvalues.", '".$importid."'"; - if (! empty($objimport->array_import_tables_creator[0][$alias])) $sql.=', '.$user->id; + if (! tablewithentity($tablename)) + { + $sql ='INSERT INTO '.$tablename.'('.$listfields.', import_key'; + if (! empty($objimport->array_import_tables_creator[0][$alias])) $sql.=', '.$objimport->array_import_tables_creator[0][$alias]; + $sql.=') VALUES('.$listvalues.", '".$importid."'"; + } + else + { + $sql ='INSERT INTO '.$tablename.'('.$listfields.', import_key, entity'; + if (! empty($objimport->array_import_tables_creator[0][$alias])) $sql.=', '.$objimport->array_import_tables_creator[0][$alias]; + $sql.=') VALUES('.$listvalues.", '".$importid."', ".$conf->entity ; + } + if (! empty($objimport->array_import_tables_creator[0][$alias])) $sql.=', '.$user->id; $sql.=')'; dol_syslog("import_csv.modules sql=".$sql); @@ -637,4 +647,34 @@ function cleansep($value) return str_replace(',','/',$value); }; +/** + * Returns if a table contains entity column + * + * @param string $table Table name + * @return int 1 if table contains entity, 0 if not and -1 if error + */ +function tablewithentity($table) +{ + global $db; + $sql = "SHOW COLUMNS FROM ".$table." LIKE 'entity'"; + + $resql=$db->query($sql); + if ($resql) + { + $numrows=$db->num_rows($resql); + if ($numrows) + { + return 1; + } + else + { + return 0; + } + } + else + { + return -1; + } +} + ?> From 7aec22769449badcb723578a7bcc84f5ee481ecb Mon Sep 17 00:00:00 2001 From: simnandez Date: Fri, 26 Oct 2012 17:52:53 +0200 Subject: [PATCH 08/17] New: More import options. Products stocks --- htdocs/core/modules/modProduct.class.php | 22 +++++++++++++++++++ htdocs/product/stock/class/entrepot.class.php | 17 ++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/htdocs/core/modules/modProduct.class.php b/htdocs/core/modules/modProduct.class.php index ec6971689b7..87114427243 100644 --- a/htdocs/core/modules/modProduct.class.php +++ b/htdocs/core/modules/modProduct.class.php @@ -223,6 +223,28 @@ class modProduct extends DolibarrModules 'sp.remise_percent'=>'0' ); } + + if (! empty($conf->stock->enabled)) + { + // Import stocks + $r++; + $this->import_code[$r]=$this->rights_class.'_'.$r; + $this->import_label[$r]="Stocks"; // Translation key + $this->import_icon[$r]='stock'; + $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon + $this->import_tables_array[$r]=array('ps'=>MAIN_DB_PREFIX.'product_stock'); + $this->import_fields_array[$r]=array('ps.fk_product'=>"Product*",'ps.fk_entrepot'=>"Warehouse*", + 'ps.reel'=>"Stock*",'ps.pmp'=>"PMP" + ); + + $this->import_convertvalue_array[$r]=array( + 'ps.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'product'), + 'ps.fk_entrepot'=>array('rule'=>'fetchidfromref','classfile'=>'/product/stock/class/entrepot.class.php','class'=>'Entrepot','method'=>'fetch','element'=>'label') + ); + $this->import_examplevalues_array[$r]=array('ps.fk_product'=>"PREF123456",'ps.fk_entrepot'=>"ALM001", + 'ps.reel'=>"10",'ps.pmp'=>"25" + ); + } } diff --git a/htdocs/product/stock/class/entrepot.class.php b/htdocs/product/stock/class/entrepot.class.php index 30a590016e5..eec0b8b22cf 100644 --- a/htdocs/product/stock/class/entrepot.class.php +++ b/htdocs/product/stock/class/entrepot.class.php @@ -240,13 +240,26 @@ class Entrepot extends CommonObject * Load warehouse data * * @param int $id Warehouse id + * @param string $ref Warehouse label * @return int >0 if OK, <0 if KO */ - function fetch($id) + function fetch($id, $ref='') { + global $conf; + $sql = "SELECT rowid, label, description, statut, lieu, address, cp as zip, ville as town, fk_pays as country_id"; $sql .= " FROM ".MAIN_DB_PREFIX."entrepot"; - $sql .= " WHERE rowid = ".$id; + + if ($id) + { + $sql.= " WHERE rowid = '".$id."'"; + } + + else + { + $sql.= " WHERE entity = " .$conf->entity; + if ($ref) $sql.= " AND label = '".$this->db->escape($ref)."'"; + } dol_syslog(get_class($this)."::fetch sql=".$sql); $result = $this->db->query($sql); From 425ebae8023aa2595d367e1621f355be5bd0c46b Mon Sep 17 00:00:00 2001 From: simnandez Date: Fri, 26 Oct 2012 18:19:04 +0200 Subject: [PATCH 09/17] New: More import options. Products categories --- htdocs/categories/class/categorie.class.php | 15 +++++- htdocs/core/modules/modCategorie.class.php | 51 +++++++++++++++++++ .../install/mysql/migration/3.2.0-3.3.0.sql | 1 + .../mysql/tables/llx_categorie_product.sql | 6 ++- 4 files changed, 69 insertions(+), 4 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index c7ffdc63753..acf708005d3 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -63,13 +63,24 @@ class Categorie * Load category into memory from database * * @param int $id Id of category + * @param strin $label Label of category * @return int <0 if KO, >0 if OK */ - function fetch($id) + function fetch($id,$label='') { + global $conf; + $sql = "SELECT rowid, fk_parent, entity, label, description, fk_soc, visible, type"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie"; - $sql.= " WHERE rowid = ".$id; + if ($id) + { + $sql.= " WHERE rowid = '".$id."'"; + } + + else + { + if ($label) $sql.= " WHERE label = '".$this->db->escape($label)."' AND entity=".$conf->entity;; + } dol_syslog(get_class($this)."::fetch sql=".$sql); $resql = $this->db->query($sql); diff --git a/htdocs/core/modules/modCategorie.class.php b/htdocs/core/modules/modCategorie.class.php index cb5fe07ee5f..4cdc10e2357 100644 --- a/htdocs/core/modules/modCategorie.class.php +++ b/htdocs/core/modules/modCategorie.class.php @@ -178,6 +178,57 @@ class modCategorie extends DolibarrModules $this->import_regex_array[$r]=array('ca.type'=>'^[0|1|2|3]'); $this->import_examplevalues_array[$r]=array('ca.label'=>"Supplier Category",'ca.type'=>"1",'ca.description'=>"Imported category"); + + if (! empty($conf->product->enabled)) + { + //Products + $r++; + $this->import_code[$r]=$this->rights_class.'_'.$r; + $this->import_label[$r]="CatSupList"; // Translation key + $this->import_icon[$r]=$this->picto; + $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon + $this->import_tables_array[$r]=array('cp'=>MAIN_DB_PREFIX.'categorie_product'); + $this->import_fields_array[$r]=array('cp.fk_categorie'=>"Category*",'cp.fk_product'=>"Product*" + ); + + $this->import_convertvalue_array[$r]=array( + 'cp.fk_categorie'=>array('rule'=>'fetchidfromref','classfile'=>'/categories/class/categorie.class.php','class'=>'Categorie','method'=>'fetch','element'=>'category'), + 'cp.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'product') + ); + $this->import_examplevalues_array[$r]=array('cp.fk_categorie'=>"Imported category",'cp.fk_product'=>"PREF123456"); + } + + //Customers + $r++; + $this->import_code[$r]=$this->rights_class.'_'.$r; + $this->import_label[$r]="Clientes por categoría"; // Translation key + $this->import_icon[$r]=$this->picto; + $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon + $this->import_tables_array[$r]=array('co'=>MAIN_DB_PREFIX.'categorie_societe'); + $this->import_fields_array[$r]=array('co.fk_categorie'=>"Categorie*",'co.fk_societe'=>"Tercero*" + ); + + $this->import_convertvalue_array[$r]=array( + 'co.fk_categorie'=>array('rule'=>'fetchidfromref','classfile'=>'/categories/class/categorie.class.php','class'=>'Categorie','method'=>'fetch','element'=>'category'), + 'co.fk_societe'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty') + ); + $this->import_examplevalues_array[$r]=array('co.fk_categorie'=>"Nombre categoría",'co.fk_societe'=>"Nombre cliente"); + + // Suppliers + $r++; + $this->import_code[$r]=$this->rights_class.'_'.$r; + $this->import_label[$r]="Proveedores por categoría"; // Translation key + $this->import_icon[$r]=$this->picto; + $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon + $this->import_tables_array[$r]=array('co'=>MAIN_DB_PREFIX.'categorie_fournisseur'); + $this->import_fields_array[$r]=array('co.fk_categorie'=>"Categorie*",'co.fk_societe'=>"Tercero*" + ); + + $this->import_convertvalue_array[$r]=array( + 'co.fk_categorie'=>array('rule'=>'fetchidfromref','classfile'=>'/categories/class/categorie.class.php','class'=>'Categorie','method'=>'fetch','element'=>'category'), + 'co.fk_societe'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty') + ); + $this->import_examplevalues_array[$r]=array('co.fk_categorie'=>"Nombre categoria",'co.fk_societe'=>"Nombre proveedor"); } diff --git a/htdocs/install/mysql/migration/3.2.0-3.3.0.sql b/htdocs/install/mysql/migration/3.2.0-3.3.0.sql index 259726d354c..d9dd806d397 100755 --- a/htdocs/install/mysql/migration/3.2.0-3.3.0.sql +++ b/htdocs/install/mysql/migration/3.2.0-3.3.0.sql @@ -772,6 +772,7 @@ ALTER TABLE llx_entrepot ADD COLUMN import_key varchar(14) AFTER fk_user_author; ALTER TABLE llx_product_fournisseur_price ADD COLUMN import_key varchar(14) AFTER fk_user; ALTER TABLE llx_product_stock ADD COLUMN import_key varchar(14) AFTER pmp; ALTER TABLE llx_societe_rib ADD COLUMN import_key varchar(14) AFTER adresse_proprio; +ALTER TABLE llx_categorie_product ADD COLUMN import_key varchar(14) AFTER fk_product; -- Export filter ALTER TABLE llx_export_model ADD COLUMN filter text AFTER field; diff --git a/htdocs/install/mysql/tables/llx_categorie_product.sql b/htdocs/install/mysql/tables/llx_categorie_product.sql index f10a5e32c61..2cdcf6802e4 100644 --- a/htdocs/install/mysql/tables/llx_categorie_product.sql +++ b/htdocs/install/mysql/tables/llx_categorie_product.sql @@ -1,6 +1,7 @@ -- ============================================================================ -- Copyright (C) 2005 Brice Davoleau --- Copyright (C) 2005 Matthieu Valleton +-- Copyright (C) 2005 Matthieu Valleton +-- Copyright (C) 2012 Juanjo Menent -- -- 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 @@ -20,5 +21,6 @@ create table llx_categorie_product ( fk_categorie integer NOT NULL, - fk_product integer NOT NULL + fk_product integer NOT NULL, + import_key varchar(14) )ENGINE=innodb; From d4df585e3c00427b125e320dc307bb107180ce3f Mon Sep 17 00:00:00 2001 From: simnandez Date: Fri, 26 Oct 2012 18:34:49 +0200 Subject: [PATCH 10/17] New: More import options. Customer and suppliers categories --- htdocs/core/modules/modCategorie.class.php | 70 ++++++++++--------- .../install/mysql/migration/3.2.0-3.3.0.sql | 2 + .../tables/llx_categorie_fournisseur.sql | 4 +- .../mysql/tables/llx_categorie_societe.sql | 4 +- 4 files changed, 46 insertions(+), 34 deletions(-) diff --git a/htdocs/core/modules/modCategorie.class.php b/htdocs/core/modules/modCategorie.class.php index 4cdc10e2357..67f10c599d4 100644 --- a/htdocs/core/modules/modCategorie.class.php +++ b/htdocs/core/modules/modCategorie.class.php @@ -197,38 +197,44 @@ class modCategorie extends DolibarrModules ); $this->import_examplevalues_array[$r]=array('cp.fk_categorie'=>"Imported category",'cp.fk_product'=>"PREF123456"); } - - //Customers - $r++; - $this->import_code[$r]=$this->rights_class.'_'.$r; - $this->import_label[$r]="Clientes por categoría"; // Translation key - $this->import_icon[$r]=$this->picto; - $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon - $this->import_tables_array[$r]=array('co'=>MAIN_DB_PREFIX.'categorie_societe'); - $this->import_fields_array[$r]=array('co.fk_categorie'=>"Categorie*",'co.fk_societe'=>"Tercero*" - ); - - $this->import_convertvalue_array[$r]=array( - 'co.fk_categorie'=>array('rule'=>'fetchidfromref','classfile'=>'/categories/class/categorie.class.php','class'=>'Categorie','method'=>'fetch','element'=>'category'), - 'co.fk_societe'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty') - ); - $this->import_examplevalues_array[$r]=array('co.fk_categorie'=>"Nombre categoría",'co.fk_societe'=>"Nombre cliente"); - - // Suppliers - $r++; - $this->import_code[$r]=$this->rights_class.'_'.$r; - $this->import_label[$r]="Proveedores por categoría"; // Translation key - $this->import_icon[$r]=$this->picto; - $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon - $this->import_tables_array[$r]=array('co'=>MAIN_DB_PREFIX.'categorie_fournisseur'); - $this->import_fields_array[$r]=array('co.fk_categorie'=>"Categorie*",'co.fk_societe'=>"Tercero*" - ); - - $this->import_convertvalue_array[$r]=array( - 'co.fk_categorie'=>array('rule'=>'fetchidfromref','classfile'=>'/categories/class/categorie.class.php','class'=>'Categorie','method'=>'fetch','element'=>'category'), - 'co.fk_societe'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty') - ); - $this->import_examplevalues_array[$r]=array('co.fk_categorie'=>"Nombre categoria",'co.fk_societe'=>"Nombre proveedor"); + + if (! empty($conf->societe->enabled)) + { + //Customers + $r++; + $this->import_code[$r]=$this->rights_class.'_'.$r; + $this->import_label[$r]="CatCusList"; // Translation key + $this->import_icon[$r]=$this->picto; + $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon + $this->import_tables_array[$r]=array('cs'=>MAIN_DB_PREFIX.'categorie_societe'); + $this->import_fields_array[$r]=array('cs.fk_categorie'=>"Categorie*",'cs.fk_societe'=>"ThirdParty*" + ); + + $this->import_convertvalue_array[$r]=array( + 'cs.fk_categorie'=>array('rule'=>'fetchidfromref','classfile'=>'/categories/class/categorie.class.php','class'=>'Categorie','method'=>'fetch','element'=>'category'), + 'cs.fk_societe'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty') + ); + $this->import_examplevalues_array[$r]=array('cs.fk_categorie'=>"Imported category",'cs.fk_societe'=>"MyBigCompany"); + } + + if (! empty($conf->fournisseur->enabled)) + { + // Suppliers + $r++; + $this->import_code[$r]=$this->rights_class.'_'.$r; + $this->import_label[$r]="CatSupList"; // Translation key + $this->import_icon[$r]=$this->picto; + $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon + $this->import_tables_array[$r]=array('cs'=>MAIN_DB_PREFIX.'categorie_fournisseur'); + $this->import_fields_array[$r]=array('cs.fk_categorie'=>"Categorie*",'co.fk_societe'=>"Supplier*" + ); + + $this->import_convertvalue_array[$r]=array( + 'cs.fk_categorie'=>array('rule'=>'fetchidfromref','classfile'=>'/categories/class/categorie.class.php','class'=>'Categorie','method'=>'fetch','element'=>'category'), + 'cs.fk_societe'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty') + ); + $this->import_examplevalues_array[$r]=array('cs.fk_categorie'=>"Imported category",'cs.fk_societe'=>"MyBigCompany"); + } } diff --git a/htdocs/install/mysql/migration/3.2.0-3.3.0.sql b/htdocs/install/mysql/migration/3.2.0-3.3.0.sql index d9dd806d397..16b325b5376 100755 --- a/htdocs/install/mysql/migration/3.2.0-3.3.0.sql +++ b/htdocs/install/mysql/migration/3.2.0-3.3.0.sql @@ -773,6 +773,8 @@ ALTER TABLE llx_product_fournisseur_price ADD COLUMN import_key varchar(14) AFTE ALTER TABLE llx_product_stock ADD COLUMN import_key varchar(14) AFTER pmp; ALTER TABLE llx_societe_rib ADD COLUMN import_key varchar(14) AFTER adresse_proprio; ALTER TABLE llx_categorie_product ADD COLUMN import_key varchar(14) AFTER fk_product; +ALTER TABLE llx_categorie_societe ADD COLUMN import_key varchar(14) AFTER fk_societe; +ALTER TABLE llx_categorie_fournisseur ADD COLUMN import_key varchar(14) AFTER fk_societe; -- Export filter ALTER TABLE llx_export_model ADD COLUMN filter text AFTER field; diff --git a/htdocs/install/mysql/tables/llx_categorie_fournisseur.sql b/htdocs/install/mysql/tables/llx_categorie_fournisseur.sql index 535972686c2..36b1e7ab37b 100644 --- a/htdocs/install/mysql/tables/llx_categorie_fournisseur.sql +++ b/htdocs/install/mysql/tables/llx_categorie_fournisseur.sql @@ -2,6 +2,7 @@ -- Copyright (C) 2006 Rodolphe Quiedeville -- Copyright (C) 2012 Laurent Destailleur -- Copyright (C) 2012 Regis Houssin +-- Copyright (C) 2012 Juanjo Menent -- -- 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 @@ -21,5 +22,6 @@ create table llx_categorie_fournisseur ( fk_categorie integer NOT NULL, - fk_societe integer NOT NULL + fk_societe integer NOT NUL, + import_key varchar(14) )ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_categorie_societe.sql b/htdocs/install/mysql/tables/llx_categorie_societe.sql index 1e9da3f158e..46d5a51ea06 100644 --- a/htdocs/install/mysql/tables/llx_categorie_societe.sql +++ b/htdocs/install/mysql/tables/llx_categorie_societe.sql @@ -1,5 +1,6 @@ -- ============================================================================ -- Copyright (C) 2007 Patrick Raguin +-- Copyright (C) 2012 Juanjo Menent -- -- 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 @@ -19,5 +20,6 @@ create table llx_categorie_societe ( fk_categorie integer NOT NULL, - fk_societe integer NOT NULL + fk_societe integer NOT NULL, + import_key varchar(14) )ENGINE=innodb; From 9a05bc8e8379ffeb3058f419a1ee5b721afc469b Mon Sep 17 00:00:00 2001 From: simnandez Date: Fri, 26 Oct 2012 18:38:34 +0200 Subject: [PATCH 11/17] New: More import options. Products categories --- htdocs/core/modules/modCategorie.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/modCategorie.class.php b/htdocs/core/modules/modCategorie.class.php index 67f10c599d4..c3252510d8e 100644 --- a/htdocs/core/modules/modCategorie.class.php +++ b/htdocs/core/modules/modCategorie.class.php @@ -226,7 +226,7 @@ class modCategorie extends DolibarrModules $this->import_icon[$r]=$this->picto; $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon $this->import_tables_array[$r]=array('cs'=>MAIN_DB_PREFIX.'categorie_fournisseur'); - $this->import_fields_array[$r]=array('cs.fk_categorie'=>"Categorie*",'co.fk_societe'=>"Supplier*" + $this->import_fields_array[$r]=array('cs.fk_categorie'=>"Categorie*",'cs.fk_societe'=>"Supplier*" ); $this->import_convertvalue_array[$r]=array( From 3821bf8c66a8ac1242c8db44b75a34d037dae2e1 Mon Sep 17 00:00:00 2001 From: simnandez Date: Fri, 26 Oct 2012 18:43:34 +0200 Subject: [PATCH 12/17] New: More import options. Products categories --- htdocs/core/modules/modCategorie.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/modules/modCategorie.class.php b/htdocs/core/modules/modCategorie.class.php index c3252510d8e..55277e2a6f1 100644 --- a/htdocs/core/modules/modCategorie.class.php +++ b/htdocs/core/modules/modCategorie.class.php @@ -207,7 +207,7 @@ class modCategorie extends DolibarrModules $this->import_icon[$r]=$this->picto; $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon $this->import_tables_array[$r]=array('cs'=>MAIN_DB_PREFIX.'categorie_societe'); - $this->import_fields_array[$r]=array('cs.fk_categorie'=>"Categorie*",'cs.fk_societe'=>"ThirdParty*" + $this->import_fields_array[$r]=array('cs.fk_categorie'=>"Category*",'cs.fk_societe'=>"ThirdParty*" ); $this->import_convertvalue_array[$r]=array( @@ -226,7 +226,7 @@ class modCategorie extends DolibarrModules $this->import_icon[$r]=$this->picto; $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon $this->import_tables_array[$r]=array('cs'=>MAIN_DB_PREFIX.'categorie_fournisseur'); - $this->import_fields_array[$r]=array('cs.fk_categorie'=>"Categorie*",'cs.fk_societe'=>"Supplier*" + $this->import_fields_array[$r]=array('cs.fk_categorie'=>"Category*",'cs.fk_societe'=>"Supplier*" ); $this->import_convertvalue_array[$r]=array( From 9ada60afbc3f00ba5b6afc6d274c0116109c5d95 Mon Sep 17 00:00:00 2001 From: simnandez Date: Fri, 26 Oct 2012 18:53:56 +0200 Subject: [PATCH 13/17] New: More import options. Products categories --- htdocs/core/modules/modCategorie.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/modCategorie.class.php b/htdocs/core/modules/modCategorie.class.php index 55277e2a6f1..4f4ecba0714 100644 --- a/htdocs/core/modules/modCategorie.class.php +++ b/htdocs/core/modules/modCategorie.class.php @@ -184,7 +184,7 @@ class modCategorie extends DolibarrModules //Products $r++; $this->import_code[$r]=$this->rights_class.'_'.$r; - $this->import_label[$r]="CatSupList"; // Translation key + $this->import_label[$r]="CatProdList"; // Translation key $this->import_icon[$r]=$this->picto; $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon $this->import_tables_array[$r]=array('cp'=>MAIN_DB_PREFIX.'categorie_product'); From 7a48351909602422eb36319d8eb8ac9651946981 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 27 Oct 2012 00:23:16 +0200 Subject: [PATCH 14/17] Fix: delete file from ecm module --- htdocs/core/class/html.form.class.php | 18 +++++++++--------- htdocs/core/class/html.formfile.class.php | 7 ++++--- htdocs/core/js/lib_head.js | 7 +++++-- htdocs/core/lib/ajax.lib.php | 6 +++--- htdocs/ecm/index.php | 4 ++-- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index d3e80221e12..69c5b37ce69 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -654,7 +654,7 @@ class Form * @param int $showempty Add an empty field * @param int $showtype Show third party type in combolist (customer, prospect or supplier) * @param int $forcecombo Force to use combo box - * @param array $event Event options + * @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @return string HTML string with */ function select_company($selected='',$htmlname='socid',$filter='',$showempty=0, $showtype=0, $forcecombo=0, $event=array()) @@ -2315,8 +2315,8 @@ class Form $autoOpen=false; $dialogconfirm.='-'.$button; } - $pageyes=$page.'&action='.$action.'&confirm=yes'; - $pageno=($useajax == 2?$page.'&confirm=no':''); + $pageyes=(preg_match('/\?/',$page)?'&':'?').'action='.$action.'&confirm=yes'; + $pageno=($useajax == 2 ? (preg_match('/\?/',$page)?'&':'?').'confirm=no':''); // Add input fields into list of fields to read during submit (inputok and inputko) if (is_array($formquestion)) { @@ -2823,17 +2823,17 @@ class Form } /** - * Output html select to select thirdparty + * Output html select to select thirdparty * - * @param string $page Page - * @param string $selected Id preselected - * @param string $htmlname Name of HTML select + * @param string $page Page + * @param string $selected Id preselected + * @param string $htmlname Name of HTML select * @param string $filter Optionnal filters criteras * @param int $showempty Add an empty field * @param int $showtype Show third party type in combolist (customer, prospect or supplier) * @param int $forcecombo Force to use combo box - * @param array $event Event options - * @return void + * @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) + * @return void */ function form_thirdparty($page, $selected='', $htmlname='socid', $filter='',$showempty=0, $showtype=0, $forcecombo=0, $event=array()) { diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index d4f22200fdb..b67e05defc7 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -576,7 +576,7 @@ class FormFile * @param array $filearray Array of files loaded by dol_dir_list('files') function before calling this * @param Object $object Object on which document is linked to * @param string $modulepart Value for modulepart used by download or viewimage wrapper - * @param string $param Parameters on sort links + * @param string $param Parameters on sort links (param must start with &, example &aaa=bbb&ccc=ddd) * @param int $forcedownload Force to open dialog box "Save As" when clicking on file * @param string $relativepath Relative path of docs (autodefined if not provided) * @param int $permtodelete Permission to delete @@ -678,9 +678,10 @@ class FormFile print ''; } // Delete or view link + // ($param must start with &) print ''; - if ($useinecm) print ''.img_view().'   '; - if ($permtodelete) print ''.img_delete().''; + if ($useinecm) print ''.img_view().'   '; + if ($permtodelete) print ''.img_delete().''; else print ' '; print ""; print "\n"; diff --git a/htdocs/core/js/lib_head.js b/htdocs/core/js/lib_head.js index 62427857749..d9088ba83ba 100644 --- a/htdocs/core/js/lib_head.js +++ b/htdocs/core/js/lib_head.js @@ -757,8 +757,11 @@ function confirmConstantAction(action, url, code, input, box, entity, yesButton, }); } -/* This is to allow to transform all select box into ajax autocomplete box - * with just one line: $(function() { $( "#listmotifcons" ).combobox(); }); +/* + * ================================================================= + * This is to allow to transform all select box into ajax autocomplete box + * with just one line: $(function() { $( "#idofmylist" ).combobox(); }); + * ================================================================= */ (function( $ ) { $.widget( "ui.combobox", { diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index e5b8a1d5f12..82a6dadcfb8 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -290,10 +290,10 @@ function ajax_dialog($title,$message,$w=350,$h=150) } /** - * Convert a select html field into an ajax combobox + * Convert a html select field into an ajax combobox * - * @param string $htmlname Name of html field - * @param array $event Event options + * @param string $htmlname Name of html select field + * @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @return string Return html string to convert a select field into a combo */ function ajax_combobox($htmlname, $event=array()) diff --git a/htdocs/ecm/index.php b/htdocs/ecm/index.php index af33f004067..304e9718637 100644 --- a/htdocs/ecm/index.php +++ b/htdocs/ecm/index.php @@ -168,7 +168,7 @@ if ($action == 'confirm_deletefile') { $langs->load("other"); $result=$ecmdir->fetch($section); - if (! $result > 0) + if (! ($result > 0)) { dol_print_error($db,$ecmdir->error); exit; @@ -396,7 +396,7 @@ print $langs->trans("ECMAreaDesc")."
"; print $langs->trans("ECMAreaDesc2")."
"; print "
\n"; -// Confirm remove file +// Confirm remove file (for non javascript users) if ($action == 'delete' && empty($conf->use_javascript_ajax)) { $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.$section.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile','','',1); From eb4cf359ec2c3d83f9b80729f70897b27741e353 Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Sat, 27 Oct 2012 11:12:41 +0200 Subject: [PATCH 15/17] fix error in constant name for SOCIETE_CODEFOURNISSEUR_ADDON in get_codefournisseur() --- htdocs/societe/class/societe.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index f985c1ec674..8b2d9284824 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1757,7 +1757,7 @@ class Societe extends CommonObject $dirsociete=array_merge(array('/core/modules/societe/'),$conf->societe_modules); foreach ($dirsociete as $dirroot) { - $res=dol_include_once($dirroot.$conf->global->SOCIETE_FOURNISSEUR_ADDON.'.php'); + $res=dol_include_once($dirroot.$conf->global->SOCIETE_CODEFOURNISSEUR_ADDON.'.php'); if ($res) break; } $var = $conf->global->SOCIETE_CODEFOURNISSEUR_ADDON; From 2bbfad24600ca7524172fc899d69c5808f237d08 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 27 Oct 2012 11:30:08 +0200 Subject: [PATCH 16/17] Fix: missing parameter --- htdocs/core/ajax/saveinplace.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/core/ajax/saveinplace.php b/htdocs/core/ajax/saveinplace.php index 2854c30f0fa..fa1fe128138 100644 --- a/htdocs/core/ajax/saveinplace.php +++ b/htdocs/core/ajax/saveinplace.php @@ -54,6 +54,7 @@ if (! empty($field) && ! empty($element) && ! empty($table_element) && ! empty($ $loadmethod = GETPOST('loadmethod','alpha',2); $savemethod = GETPOST('savemethod','alpha',2); $savemethodname = (! empty($savemethod) ? $savemethod : 'setValueFrom'); + $newelement = $element; $view=''; $format='text'; From 253e3412dba987a217ca10213e3f836f2b6414d7 Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Sat, 27 Oct 2012 12:55:28 +0200 Subject: [PATCH 17/17] fix wrong insert sql construction field type detection was made before optional conversions so it might be wrong; i replaced it with a more simple solution --- .../modules/import/import_csv.modules.php | 1326 +++++++++-------- 1 file changed, 669 insertions(+), 657 deletions(-) diff --git a/htdocs/core/modules/import/import_csv.modules.php b/htdocs/core/modules/import/import_csv.modules.php index da2493264be..f2d76e5089a 100644 --- a/htdocs/core/modules/import/import_csv.modules.php +++ b/htdocs/core/modules/import/import_csv.modules.php @@ -1,658 +1,670 @@ - - * Copyright (C) 2009-2012 Regis Houssin - * Copyright (C) 2012 Christophe Battarel - * Copyright (C) 2012 Juanjo Menent - * - * 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 . - * or see http://www.gnu.org/ - */ - -/** - * \file htdocs/core/modules/import/import_csv.modules.php - * \ingroup import - * \brief File to load import files with CSV format - */ - -require_once DOL_DOCUMENT_ROOT .'/core/modules/import/modules_import.php'; - - -/** - * Class to import CSV files - */ -class ImportCsv extends ModeleImports -{ - var $db; - var $datatoimport; - - var $error=''; - var $errors=array(); - - var $id; // Id of driver - var $label; // Label of driver - var $extension; // Extension of files imported by driver - var $version; // Version of driver - - var $label_lib; // Label of external lib used by driver - var $version_lib; // Version of external lib used by driver - - var $separator; - - var $handle; // Handle fichier - - var $cacheconvert=array(); // Array to cache list of value found after a convertion - var $cachefieldtable=array(); // Array to cache list of value found into fields@tables - - - /** - * Constructor - * - * @param DoliDB $db Database handler - * @param string $datatoimport String code describing import set (ex: 'societe_1') - */ - function __construct($db,$datatoimport) - { - global $conf,$langs; - $this->db = $db; - - $this->separator=','; // Change also function cleansep - if (! empty($conf->global->IMPORT_CSV_SEPARATOR_TO_USE)) $this->separator=$conf->global->IMPORT_CSV_SEPARATOR_TO_USE; - $this->enclosure='"'; - $this->escape='"'; - - $this->id='csv'; // Same value then xxx in file name export_xxx.modules.php - $this->label='Csv'; // Label of driver - $this->desc=$langs->trans("CSVFormatDesc",$this->separator,$this->enclosure,$this->escape); - $this->extension='csv'; // Extension for generated file by this driver - $this->picto='mime/other'; // Picto - $this->version='1.34'; // Driver version - - // If driver use an external library, put its name here - $this->label_lib='Dolibarr'; - $this->version_lib=DOL_VERSION; - - $this->datatoimport=$datatoimport; - if (preg_match('/^societe_/',$datatoimport)) $this->thirpartyobject=new Societe($this->db); - } - - /** - * getDriverId - * - * @return int Id - */ - function getDriverId() - { - return $this->id; - } - - /** - * getDriverLabel - * - * @param string $key Key - * @return string Label - */ - function getDriverLabel($key='') - { - return $this->label; - } - - /** - * getDriverDesc - * - * @param string $key Key - * @return string Description - */ - function getDriverDesc($key='') - { - return $this->desc; - } - - /** - * getDriverExtension - * - * @return string Driver suffix - */ - function getDriverExtension() - { - return $this->extension; - } - - /** - * getDriverVersion - * - * @param string $key Key - * @return string Driver version - */ - function getDriverVersion($key='') - { - return $this->version; - } - - /** - * getDriverLabel - * - * @param string $key Key - * @return string Label of external lib - */ - function getLibLabel($key='') - { - return $this->label_lib; - } - - /** - * getLibVersion - * - * @param string $key Key - * @return string Version of external lib - */ - function getLibVersion($key='') - { - return $this->version_lib; - } - - - /** - * Output header of an example file for this format - * - * @param Translate $outputlangs Output language - * @return string - */ - function write_header_example($outputlangs) - { - return ''; - } - - /** - * Output title line of an example file for this format - * - * @param Translate $outputlangs Output language - * @param array $headerlinefields Array of fields name - * @return string - */ - function write_title_example($outputlangs,$headerlinefields) - { - $s.=join($this->separator,array_map('cleansep',$headerlinefields)); - return $s."\n"; - } - - /** - * Output record of an example file for this format - * - * @param Translate $outputlangs Output language - * @param array $contentlinevalues Array of lines - * @return string - */ - function write_record_example($outputlangs,$contentlinevalues) - { - $s=join($this->separator,array_map('cleansep',$contentlinevalues)); - return $s."\n"; - } - - /** - * Output footer of an example file for this format - * - * @param Translate $outputlangs Output language - * @return string - */ - function write_footer_example($outputlangs) - { - return ''; - } - - - - /** - * Open input file - * - * @param string $file Path of filename - * @return int <0 if KO, >=0 if OK - */ - function import_open_file($file) - { - global $langs; - $ret=1; - - dol_syslog(get_class($this)."::open_file file=".$file); - - ini_set('auto_detect_line_endings',1); // For MAC compatibility - - $this->handle = fopen(dol_osencode($file), "r"); - if (! $this->handle) - { - $langs->load("errors"); - $this->error=$langs->trans("ErrorFailToOpenFile",$file); - $ret=-1; - } - else - { - $this->file=$file; - } - - return $ret; - } - - /** - * Input header line from file - * - * @return int <0 if KO, >=0 if OK - */ - function import_read_header() - { - return 0; - } - - - /** - * Return array of next record in input file. - * - * @return Array Array of field values. Data are UTF8 encoded. [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string) - */ - function import_read_record() - { - global $conf; - - $arrayres=array(); - if (version_compare(phpversion(), '5.3') < 0) - { - $arrayres=fgetcsv($this->handle,100000,$this->separator,$this->enclosure); - } - else - { - $arrayres=fgetcsv($this->handle,100000,$this->separator,$this->enclosure,$this->escape); - } - - //var_dump($this->handle); - //var_dump($arrayres);exit; - $newarrayres=array(); - if ($arrayres && is_array($arrayres)) - { - foreach($arrayres as $key => $val) - { - if (! empty($conf->global->IMPORT_CSV_FORCE_CHARSET)) // Forced charset - { - if (strtolower($conf->global->IMPORT_CSV_FORCE_CHARSET) == 'utf8') - { - $newarrayres[$key]['val']=$val; - $newarrayres[$key]['type']=(dol_strlen($val)?1:-1); // If empty we considere it's null - } - else - { - $newarrayres[$key]['val']=utf8_encode($val); - $newarrayres[$key]['type']=(dol_strlen($val)?1:-1); // If empty we considere it's null - } - } - else // Autodetect format (UTF8 or ISO) - { - if (utf8_check($val)) - { - $newarrayres[$key]['val']=$val; - $newarrayres[$key]['type']=(dol_strlen($val)?1:-1); // If empty we considere it's null - } - else - { - $newarrayres[$key]['val']=utf8_encode($val); - $newarrayres[$key]['type']=(dol_strlen($val)?1:-1); // If empty we considere it's null - } - } - } - - $this->col=count($newarrayres); - } - - return $newarrayres; - } - - /** - * Close file handle - * - * @return void - */ - function import_close_file() - { - fclose($this->handle); - return 0; - } - - - /** - * Insert a record into database - * - * @param array $arrayrecord Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]... - * @param array $array_match_file_to_database Array of target fields where to insert data: [fieldpos] => 's.fieldname', [fieldpos+1]... - * @param Object $objimport Object import (contains objimport->import_tables_array, objimport->import_fields_array, objimport->import_convertvalue_array, ...) - * @param int $maxfields Max number of fields to use - * @param string $importid Import key - * @return int <0 if KO, >0 if OK - */ - function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid) - { - global $langs,$conf,$user; - global $thirdparty_static; // Specifi to thirdparty import - - $error=0; - $warning=0; - $this->errors=array(); - $this->warnings=array(); - - //dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid); - - //var_dump($array_match_file_to_database); - //var_dump($arrayrecord); - $array_match_database_to_file=array_flip($array_match_file_to_database); - $sort_array_match_file_to_database=$array_match_file_to_database; - ksort($sort_array_match_file_to_database); - - //var_dump($sort_array_match_file_to_database); - - if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0]['val']))) - { - //print 'W'; - $this->warnings[$warning]['lib']=$langs->trans('EmptyLine'); - $this->warnings[$warning]['type']='EMPTY'; - $warning++; - } - else - { - // For each table to insert, me make a separate insert - foreach($objimport->array_import_tables[0] as $alias => $tablename) - { - // Build sql request - $sql=''; - $listfields=''; - $listvalues=''; - $i=0; - $errorforthistable=0; - - // Loop on each fields in the match array: $key = 1..n, $val=alias of field (s.nom) - foreach($sort_array_match_file_to_database as $key => $val) - { - $fieldalias=preg_replace('/\..*$/i','',$val); - $fieldname=preg_replace('/^.*\./i','',$val); - - if ($alias != $fieldalias) continue; // Not a field of current table - - if ($key <= $maxfields) - { - // Set $newval with value to insert and set $listvalues with sql request part for insert - $newval=''; - if ($arrayrecord[($key-1)]['type'] > 0) $newval=$arrayrecord[($key-1)]['val']; // If type of field is not null or '' but string - - // Make some tests on $newval - - // Is it a required field ? - if (preg_match('/\*/',$objimport->array_import_fields[0][$val]) && ($newval=='')) - { - $this->errors[$error]['lib']=$langs->trans('ErrorMissingMandatoryValue',$key); - $this->errors[$error]['type']='NOTNULL'; - $errorforthistable++; - $error++; - } - // Test format only if field is not a missing mandatory field (field may be a value or empty but not mandatory) - else - { - // We convert field if required - if (! empty($objimport->array_import_convertvalue[0][$val])) - { - //print 'Must convert '.$newval.' with rule '.join(',',$objimport->array_import_convertvalue[0][$val]).'. '; - if ($objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeid' || $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromref') - { - if (! is_numeric($newval)) // If value into input import file is not a numeric, we apply the function defined into descriptor - { - $file=$objimport->array_import_convertvalue[0][$val]['classfile']; - $class=$objimport->array_import_convertvalue[0][$val]['class']; - $method=$objimport->array_import_convertvalue[0][$val]['method']; - if (empty($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval])) - { - dol_include_once($file); - $classinstance=new $class($this->db); - call_user_func_array(array($classinstance, $method),array('', $newval)); - $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]=$classinstance->id; - //print 'We have made a '.$class.'->'.$method.' to get id from code '.$newval.'. '; - if (! empty($classinstance->id)) - { - $newval=$classinstance->id; - } - else - { - if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) $this->errors[$error]['lib']=$langs->trans('ErrorFieldValueNotIn',$key,$newval,'code',$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict'])); - else if (!empty($objimport->array_import_convertvalue[0][$val]['element'])) $this->errors[$error]['lib']=$langs->trans('ErrorFieldRefNotIn',$key,$newval,$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['element'])); - else $this->errors[$error]['lib']='ErrorFieldValueNotIn'; - $this->errors[$error]['type']='FOREIGNKEY'; - $errorforthistable++; - $error++; - } - } - else - { - $newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]; - } - } - - } - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='zeroifnull') - { - if (empty($newval)) $newval='0'; - } - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifnull') - { - if (empty($newval) || $newval='auto') - { - $this->thirpartyobject->get_codeclient(0,0); - $newval=$this->thirpartyobject->code_client; - //print 'code_client='.$newval; - } - } - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifnull') - { - if (empty($newval) || $newval='auto') - { - $newval=$this->thirpartyobject->get_codefournisseur(0,1); - $newval=$this->thirpartyobject->code_fournisseur; - //print 'code_fournisseur='.$newval; - } - } - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifnull') - { - if (empty($newval) || $newval='auto') - { - $this->thirpartyobject->get_codecompta('customer'); - $newval=$this->thirpartyobject->code_compta; - //print 'code_compta='.$newval; - } - } - elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifnull') - { - if (empty($newval) || $newval='auto') - { - $this->thirpartyobject->get_codecompta('supplier'); - $newval=$this->thirpartyobject->code_compta_fournisseur; - //print 'code_compta_fournisseur='.$newval; - } - } - - //print 'Val to use as insert is '.$newval.'
'; - } - - // Test regexp - if (! empty($objimport->array_import_regex[0][$val]) && ($newval != '')) - { - // If test is "Must exist in a field@table" - if (preg_match('/^(.*)@(.*)$/',$objimport->array_import_regex[0][$val],$reg)) - { - $field=$reg[1]; - $table=$reg[2]; - - // Load content of field@table into cache array - if (! is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache - { - $sql="SELECT ".$field." as aliasfield FROM ".$table; - $resql=$this->db->query($sql); - if ($resql) - { - $num=$this->db->num_rows($resql); - $i=0; - while ($i < $num) - { - $obj=$this->db->fetch_object($resql); - if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield; - $i++; - } - } - else - { - dol_print_error($this->db); - } - } - - // Now we check cache is not empty (should not) and key is into cache - if (! is_array($this->cachefieldtable[$field.'@'.$table]) || ! in_array($newval,$this->cachefieldtable[$field.'@'.$table])) - { - $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn',$key,$newval,$field,$table); - $this->errors[$error]['type']='FOREIGNKEY'; - $errorforthistable++; - $error++; - } - } - // If test is just a static regex - else if (! preg_match('/'.$objimport->array_import_regex[0][$val].'/i',$newval)) - { - //if ($key == 19) print "xxx".$newval."zzz".$objimport->array_import_regex[0][$val]."
"; - $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorWrongValueForField',$key,$newval,$objimport->array_import_regex[0][$val]); - $this->errors[$error]['type']='REGEX'; - $errorforthistable++; - $error++; - } - } - - // Other tests - // ... - } - - // Define $listfields and $listvalues to build SQL request - if ($listfields) { $listfields.=', '; $listvalues.=', '; } - $listfields.=$fieldname; - - if ($arrayrecord[($key-1)]['type'] < 0) $listvalues.=($newval=='0'?$newval:"null"); - elseif ($arrayrecord[($key-1)]['type'] == 0) $listvalues.="''"; - elseif ($arrayrecord[($key-1)]['type'] > 0) $listvalues.="'".$this->db->escape($newval)."'"; - } - $i++; - } - - // We add hidden fields (but only if there is at least one field to add into table) - if ($listfields && is_array($objimport->array_import_fieldshidden[0])) - { - // Loop on each hidden fields to add them into listfields/listvalues - foreach($objimport->array_import_fieldshidden[0] as $key => $val) - { - if (! preg_match('/^'.preg_quote($alias).'\./', $key)) continue; // Not a field of current table - if ($listfields) { $listfields.=', '; $listvalues.=', '; } - if ($val == 'user->id') - { - $listfields.=preg_replace('/^'.preg_quote($alias).'\./','',$key); - $listvalues.=$user->id; - } - elseif (preg_match('/^lastrowid-/',$val)) - { - $tmp=explode('-',$val); - $lastinsertid=$this->db->last_insert_id($tmp[1]); - $listfields.=preg_replace('/^'.preg_quote($alias).'\./','',$key); - $listvalues.=$lastinsertid; - //print $key."-".$val."-".$listfields."-".$listvalues."
";exit; - } - } - } - //print 'listfields='.$listfields.'
listvalues='.$listvalues.'
'; - - // If no error for this $alias/$tablename, we have a complete $listfields and $listvalues that are defined - if (! $errorforthistable) - { - //print "$alias/$tablename/$listfields/$listvalues
"; - if ($listfields) - { - //var_dump($objimport->array_import_convertvalue); exit; - - // Build SQL request - if (! tablewithentity($tablename)) - { - $sql ='INSERT INTO '.$tablename.'('.$listfields.', import_key'; - if (! empty($objimport->array_import_tables_creator[0][$alias])) $sql.=', '.$objimport->array_import_tables_creator[0][$alias]; - $sql.=') VALUES('.$listvalues.", '".$importid."'"; - } - else - { - $sql ='INSERT INTO '.$tablename.'('.$listfields.', import_key, entity'; - if (! empty($objimport->array_import_tables_creator[0][$alias])) $sql.=', '.$objimport->array_import_tables_creator[0][$alias]; - $sql.=') VALUES('.$listvalues.", '".$importid."', ".$conf->entity ; - } + + * Copyright (C) 2009-2012 Regis Houssin + * Copyright (C) 2012 Christophe Battarel + * Copyright (C) 2012 Juanjo Menent + * + * 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 . + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/core/modules/import/import_csv.modules.php + * \ingroup import + * \brief File to load import files with CSV format + */ + +require_once DOL_DOCUMENT_ROOT .'/core/modules/import/modules_import.php'; + + +/** + * Class to import CSV files + */ +class ImportCsv extends ModeleImports +{ + var $db; + var $datatoimport; + + var $error=''; + var $errors=array(); + + var $id; // Id of driver + var $label; // Label of driver + var $extension; // Extension of files imported by driver + var $version; // Version of driver + + var $label_lib; // Label of external lib used by driver + var $version_lib; // Version of external lib used by driver + + var $separator; + + var $handle; // Handle fichier + + var $cacheconvert=array(); // Array to cache list of value found after a convertion + var $cachefieldtable=array(); // Array to cache list of value found into fields@tables + + + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $datatoimport String code describing import set (ex: 'societe_1') + */ + function __construct($db,$datatoimport) + { + global $conf,$langs; + $this->db = $db; + + $this->separator=','; // Change also function cleansep + if (! empty($conf->global->IMPORT_CSV_SEPARATOR_TO_USE)) $this->separator=$conf->global->IMPORT_CSV_SEPARATOR_TO_USE; + $this->enclosure='"'; + $this->escape='"'; + + $this->id='csv'; // Same value then xxx in file name export_xxx.modules.php + $this->label='Csv'; // Label of driver + $this->desc=$langs->trans("CSVFormatDesc",$this->separator,$this->enclosure,$this->escape); + $this->extension='csv'; // Extension for generated file by this driver + $this->picto='mime/other'; // Picto + $this->version='1.34'; // Driver version + + // If driver use an external library, put its name here + $this->label_lib='Dolibarr'; + $this->version_lib=DOL_VERSION; + + $this->datatoimport=$datatoimport; + if (preg_match('/^societe_/',$datatoimport)) $this->thirpartyobject=new Societe($this->db); + } + + /** + * getDriverId + * + * @return int Id + */ + function getDriverId() + { + return $this->id; + } + + /** + * getDriverLabel + * + * @param string $key Key + * @return string Label + */ + function getDriverLabel($key='') + { + return $this->label; + } + + /** + * getDriverDesc + * + * @param string $key Key + * @return string Description + */ + function getDriverDesc($key='') + { + return $this->desc; + } + + /** + * getDriverExtension + * + * @return string Driver suffix + */ + function getDriverExtension() + { + return $this->extension; + } + + /** + * getDriverVersion + * + * @param string $key Key + * @return string Driver version + */ + function getDriverVersion($key='') + { + return $this->version; + } + + /** + * getDriverLabel + * + * @param string $key Key + * @return string Label of external lib + */ + function getLibLabel($key='') + { + return $this->label_lib; + } + + /** + * getLibVersion + * + * @param string $key Key + * @return string Version of external lib + */ + function getLibVersion($key='') + { + return $this->version_lib; + } + + + /** + * Output header of an example file for this format + * + * @param Translate $outputlangs Output language + * @return string + */ + function write_header_example($outputlangs) + { + return ''; + } + + /** + * Output title line of an example file for this format + * + * @param Translate $outputlangs Output language + * @param array $headerlinefields Array of fields name + * @return string + */ + function write_title_example($outputlangs,$headerlinefields) + { + $s.=join($this->separator,array_map('cleansep',$headerlinefields)); + return $s."\n"; + } + + /** + * Output record of an example file for this format + * + * @param Translate $outputlangs Output language + * @param array $contentlinevalues Array of lines + * @return string + */ + function write_record_example($outputlangs,$contentlinevalues) + { + $s=join($this->separator,array_map('cleansep',$contentlinevalues)); + return $s."\n"; + } + + /** + * Output footer of an example file for this format + * + * @param Translate $outputlangs Output language + * @return string + */ + function write_footer_example($outputlangs) + { + return ''; + } + + + + /** + * Open input file + * + * @param string $file Path of filename + * @return int <0 if KO, >=0 if OK + */ + function import_open_file($file) + { + global $langs; + $ret=1; + + dol_syslog(get_class($this)."::open_file file=".$file); + + ini_set('auto_detect_line_endings',1); // For MAC compatibility + + $this->handle = fopen(dol_osencode($file), "r"); + if (! $this->handle) + { + $langs->load("errors"); + $this->error=$langs->trans("ErrorFailToOpenFile",$file); + $ret=-1; + } + else + { + $this->file=$file; + } + + return $ret; + } + + /** + * Input header line from file + * + * @return int <0 if KO, >=0 if OK + */ + function import_read_header() + { + return 0; + } + + + /** + * Return array of next record in input file. + * + * @return Array Array of field values. Data are UTF8 encoded. [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string) + */ + function import_read_record() + { + global $conf; + + $arrayres=array(); + if (version_compare(phpversion(), '5.3') < 0) + { + $arrayres=fgetcsv($this->handle,100000,$this->separator,$this->enclosure); + } + else + { + $arrayres=fgetcsv($this->handle,100000,$this->separator,$this->enclosure,$this->escape); + } + + //var_dump($this->handle); + //var_dump($arrayres);exit; + $newarrayres=array(); + if ($arrayres && is_array($arrayres)) + { + foreach($arrayres as $key => $val) + { + if (! empty($conf->global->IMPORT_CSV_FORCE_CHARSET)) // Forced charset + { + if (strtolower($conf->global->IMPORT_CSV_FORCE_CHARSET) == 'utf8') + { + $newarrayres[$key]['val']=$val; + $newarrayres[$key]['type']=(dol_strlen($val)?1:-1); // If empty we considere it's null + } + else + { + $newarrayres[$key]['val']=utf8_encode($val); + $newarrayres[$key]['type']=(dol_strlen($val)?1:-1); // If empty we considere it's null + } + } + else // Autodetect format (UTF8 or ISO) + { + if (utf8_check($val)) + { + $newarrayres[$key]['val']=$val; + $newarrayres[$key]['type']=(dol_strlen($val)?1:-1); // If empty we considere it's null + } + else + { + $newarrayres[$key]['val']=utf8_encode($val); + $newarrayres[$key]['type']=(dol_strlen($val)?1:-1); // If empty we considere it's null + } + } + } + + $this->col=count($newarrayres); + } + + return $newarrayres; + } + + /** + * Close file handle + * + * @return void + */ + function import_close_file() + { + fclose($this->handle); + return 0; + } + + + /** + * Insert a record into database + * + * @param array $arrayrecord Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]... + * @param array $array_match_file_to_database Array of target fields where to insert data: [fieldpos] => 's.fieldname', [fieldpos+1]... + * @param Object $objimport Object import (contains objimport->import_tables_array, objimport->import_fields_array, objimport->import_convertvalue_array, ...) + * @param int $maxfields Max number of fields to use + * @param string $importid Import key + * @return int <0 if KO, >0 if OK + */ + function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid) + { + global $langs,$conf,$user; + global $thirdparty_static; // Specifi to thirdparty import + + $error=0; + $warning=0; + $this->errors=array(); + $this->warnings=array(); + + //dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid); + + //var_dump($array_match_file_to_database); + //var_dump($arrayrecord); + $array_match_database_to_file=array_flip($array_match_file_to_database); + $sort_array_match_file_to_database=$array_match_file_to_database; + ksort($sort_array_match_file_to_database); + + //var_dump($sort_array_match_file_to_database); + + if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0]['val']))) + { + //print 'W'; + $this->warnings[$warning]['lib']=$langs->trans('EmptyLine'); + $this->warnings[$warning]['type']='EMPTY'; + $warning++; + } + else + { + // For each table to insert, me make a separate insert + foreach($objimport->array_import_tables[0] as $alias => $tablename) + { + // Build sql request + $sql=''; + $listfields=''; + $listvalues=''; + $i=0; + $errorforthistable=0; + + // Loop on each fields in the match array: $key = 1..n, $val=alias of field (s.nom) + foreach($sort_array_match_file_to_database as $key => $val) + { + $fieldalias=preg_replace('/\..*$/i','',$val); + $fieldname=preg_replace('/^.*\./i','',$val); + + if ($alias != $fieldalias) continue; // Not a field of current table + + if ($key <= $maxfields) + { + // Set $newval with value to insert and set $listvalues with sql request part for insert + $newval=''; + if ($arrayrecord[($key-1)]['type'] > 0) $newval=$arrayrecord[($key-1)]['val']; // If type of field is not null or '' but string + + // Make some tests on $newval + + // Is it a required field ? + if (preg_match('/\*/',$objimport->array_import_fields[0][$val]) && ($newval=='')) + { + $this->errors[$error]['lib']=$langs->trans('ErrorMissingMandatoryValue',$key); + $this->errors[$error]['type']='NOTNULL'; + $errorforthistable++; + $error++; + } + // Test format only if field is not a missing mandatory field (field may be a value or empty but not mandatory) + else + { + // We convert field if required + if (! empty($objimport->array_import_convertvalue[0][$val])) + { + //print 'Must convert '.$newval.' with rule '.join(',',$objimport->array_import_convertvalue[0][$val]).'. '; + if ($objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeid' || $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromref') + { + if (! is_numeric($newval)) // If value into input import file is not a numeric, we apply the function defined into descriptor + { + $file=$objimport->array_import_convertvalue[0][$val]['classfile']; + $class=$objimport->array_import_convertvalue[0][$val]['class']; + $method=$objimport->array_import_convertvalue[0][$val]['method']; + if (empty($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval])) + { + dol_include_once($file); + $classinstance=new $class($this->db); + call_user_func_array(array($classinstance, $method),array('', $newval)); + $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]=$classinstance->id; + //print 'We have made a '.$class.'->'.$method.' to get id from code '.$newval.'. '; + if (! empty($classinstance->id)) + { + $newval=$classinstance->id; + } + else + { + if (!empty($objimport->array_import_convertvalue[0][$val]['dict'])) $this->errors[$error]['lib']=$langs->trans('ErrorFieldValueNotIn',$key,$newval,'code',$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['dict'])); + else if (!empty($objimport->array_import_convertvalue[0][$val]['element'])) $this->errors[$error]['lib']=$langs->trans('ErrorFieldRefNotIn',$key,$newval,$langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val]['element'])); + else $this->errors[$error]['lib']='ErrorFieldValueNotIn'; + $this->errors[$error]['type']='FOREIGNKEY'; + $errorforthistable++; + $error++; + } + } + else + { + $newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]; + } + } + + } + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='zeroifnull') + { + if (empty($newval)) $newval='0'; + } + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomercodeifnull') + { + if (empty($newval) || $newval='auto') + { + $this->thirpartyobject->get_codeclient(0,0); + $newval=$this->thirpartyobject->code_client; + //print 'code_client='.$newval; + } + } + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsuppliercodeifnull') + { + if (empty($newval) || $newval='auto') + { + $newval=$this->thirpartyobject->get_codefournisseur(0,1); + $newval=$this->thirpartyobject->code_fournisseur; + //print 'code_fournisseur='.$newval; + } + } + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getcustomeraccountancycodeifnull') + { + if (empty($newval) || $newval='auto') + { + $this->thirpartyobject->get_codecompta('customer'); + $newval=$this->thirpartyobject->code_compta; + //print 'code_compta='.$newval; + } + } + elseif ($objimport->array_import_convertvalue[0][$val]['rule']=='getsupplieraccountancycodeifnull') + { + if (empty($newval) || $newval='auto') + { + $this->thirpartyobject->get_codecompta('supplier'); + $newval=$this->thirpartyobject->code_compta_fournisseur; + //print 'code_compta_fournisseur='.$newval; + } + } + + //print 'Val to use as insert is '.$newval.'
'; + } + + // Test regexp + if (! empty($objimport->array_import_regex[0][$val]) && ($newval != '')) + { + // If test is "Must exist in a field@table" + if (preg_match('/^(.*)@(.*)$/',$objimport->array_import_regex[0][$val],$reg)) + { + $field=$reg[1]; + $table=$reg[2]; + + // Load content of field@table into cache array + if (! is_array($this->cachefieldtable[$field.'@'.$table])) // If content of field@table not already loaded into cache + { + $sql="SELECT ".$field." as aliasfield FROM ".$table; + $resql=$this->db->query($sql); + if ($resql) + { + $num=$this->db->num_rows($resql); + $i=0; + while ($i < $num) + { + $obj=$this->db->fetch_object($resql); + if ($obj) $this->cachefieldtable[$field.'@'.$table][]=$obj->aliasfield; + $i++; + } + } + else + { + dol_print_error($this->db); + } + } + + // Now we check cache is not empty (should not) and key is into cache + if (! is_array($this->cachefieldtable[$field.'@'.$table]) || ! in_array($newval,$this->cachefieldtable[$field.'@'.$table])) + { + $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorFieldValueNotIn',$key,$newval,$field,$table); + $this->errors[$error]['type']='FOREIGNKEY'; + $errorforthistable++; + $error++; + } + } + // If test is just a static regex + else if (! preg_match('/'.$objimport->array_import_regex[0][$val].'/i',$newval)) + { + //if ($key == 19) print "xxx".$newval."zzz".$objimport->array_import_regex[0][$val]."
"; + $this->errors[$error]['lib']=$langs->transnoentitiesnoconv('ErrorWrongValueForField',$key,$newval,$objimport->array_import_regex[0][$val]); + $this->errors[$error]['type']='REGEX'; + $errorforthistable++; + $error++; + } + } + + // Other tests + // ... + } + + // Define $listfields and $listvalues to build SQL request + if ($listfields) { $listfields.=', '; $listvalues.=', '; } + $listfields.=$fieldname; +/* +field type detection was made before conversions so it can be wrong + if ($arrayrecord[($key-1)]['type'] < 0) $listvalues.=($newval=='0'?$newval:"null"); + elseif ($arrayrecord[($key-1)]['type'] == 0) $listvalues.="''"; + elseif ($arrayrecord[($key-1)]['type'] > 0) $listvalues.="'".$this->db->escape($newval)."'"; +*/ +/* +lines below replace lines above and are much simple +*/ + if (!isset($newval)) $listvalues.="null"; + elseif (empty($newval)) $listvalues.="''"; + else $listvalues.="'".$this->db->escape($newval)."'"; +/* +end of replace +*/ + + } + $i++; + } + + // We add hidden fields (but only if there is at least one field to add into table) + if ($listfields && is_array($objimport->array_import_fieldshidden[0])) + { + // Loop on each hidden fields to add them into listfields/listvalues + foreach($objimport->array_import_fieldshidden[0] as $key => $val) + { + if (! preg_match('/^'.preg_quote($alias).'\./', $key)) continue; // Not a field of current table + if ($listfields) { $listfields.=', '; $listvalues.=', '; } + if ($val == 'user->id') + { + $listfields.=preg_replace('/^'.preg_quote($alias).'\./','',$key); + $listvalues.=$user->id; + } + elseif (preg_match('/^lastrowid-/',$val)) + { + $tmp=explode('-',$val); + $lastinsertid=$this->db->last_insert_id($tmp[1]); + $listfields.=preg_replace('/^'.preg_quote($alias).'\./','',$key); + $listvalues.=$lastinsertid; + //print $key."-".$val."-".$listfields."-".$listvalues."
";exit; + } + } + } + //print 'listfields='.$listfields.'
listvalues='.$listvalues.'
'; + + // If no error for this $alias/$tablename, we have a complete $listfields and $listvalues that are defined + if (! $errorforthistable) + { + //print "$alias/$tablename/$listfields/$listvalues
"; + if ($listfields) + { + //var_dump($objimport->array_import_convertvalue); exit; + + // Build SQL request + if (! tablewithentity($tablename)) + { + $sql ='INSERT INTO '.$tablename.'('.$listfields.', import_key'; + if (! empty($objimport->array_import_tables_creator[0][$alias])) $sql.=', '.$objimport->array_import_tables_creator[0][$alias]; + $sql.=') VALUES('.$listvalues.", '".$importid."'"; + } + else + { + $sql ='INSERT INTO '.$tablename.'('.$listfields.', import_key, entity'; + if (! empty($objimport->array_import_tables_creator[0][$alias])) $sql.=', '.$objimport->array_import_tables_creator[0][$alias]; + $sql.=') VALUES('.$listvalues.", '".$importid."', ".$conf->entity ; + } if (! empty($objimport->array_import_tables_creator[0][$alias])) $sql.=', '.$user->id; - $sql.=')'; - dol_syslog("import_csv.modules sql=".$sql); - - //print '> '.join(',',$arrayrecord); - //print 'sql='.$sql; - //print '
'."\n"; - - // Run insert request - if ($sql) - { - $resql=$this->db->query($sql); - if ($resql) - { - //print '.'; - } - else - { - //print 'E'; - $this->errors[$error]['lib']=$this->db->lasterror(); - $this->errors[$error]['type']='SQL'; - $error++; - } - } - } - /*else - { - dol_print_error('','ErrorFieldListEmptyFor '.$alias."/".$tablename); - }*/ - } - - if ($error) break; - } - } - - return 1; - } - -} - -/** - * Clean a string from separator - * - * @param string $value Remove separator - * @return string String without separator - */ -function cleansep($value) -{ - return str_replace(',','/',$value); -}; - -/** - * Returns if a table contains entity column - * - * @param string $table Table name - * @return int 1 if table contains entity, 0 if not and -1 if error - */ + $sql.=')'; + dol_syslog("import_csv.modules sql=".$sql); + + //print '> '.join(',',$arrayrecord); + //print 'sql='.$sql; + //print '
'."\n"; + + // Run insert request + if ($sql) + { + $resql=$this->db->query($sql); + if ($resql) + { + //print '.'; + } + else + { + //print 'E'; + $this->errors[$error]['lib']=$this->db->lasterror(); + $this->errors[$error]['type']='SQL'; + $error++; + } + } + } + /*else + { + dol_print_error('','ErrorFieldListEmptyFor '.$alias."/".$tablename); + }*/ + } + + if ($error) break; + } + } + + return 1; + } + +} + +/** + * Clean a string from separator + * + * @param string $value Remove separator + * @return string String without separator + */ +function cleansep($value) +{ + return str_replace(',','/',$value); +}; + +/** + * Returns if a table contains entity column + * + * @param string $table Table name + * @return int 1 if table contains entity, 0 if not and -1 if error + */ function tablewithentity($table) { global $db; @@ -675,6 +687,6 @@ function tablewithentity($table) { return -1; } -} - -?> +} + +?>