diff --git a/ChangeLog b/ChangeLog index 2c0e2377f61..ba13be8ba5a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -44,10 +44,11 @@ For users: - New: Chart are faster to build - New: Value of data into charts are visible on mouse hover. - New: Import wizard can import contacts. +- New: Import wizard can import personalized fields. +- New: Personalized fields support int type. - New: Install process is now two times faster. - New: Can sort files into backup tool. - New: Default output charset are utf8 into backup tool. -- New: Extra fields support int type. - New: Add brazilian states. - New: Increase usability of module project. - New: Automatic list of documents in ECM module is ok for customers, diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php index 57bc9bde1d3..52e14a638d9 100644 --- a/htdocs/core/lib/product.lib.php +++ b/htdocs/core/lib/product.lib.php @@ -135,7 +135,47 @@ function product_prepare_head($object, $user) return $head; } +/** +* Return array head with list of tabs to view object informations. +* +* @param Object $object Product +* @return array head array with tabs +*/ +function product_admin_prepare_head($object, $tab) +{ + global $langs, $conf, $user; + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT."/product/admin/product.php"; + $head[$h][1] = $tab; + $head[$h][2] = 'general'; + $h++; + + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab + // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab + complete_head_from_modules($conf,$langs,$object,$head,$h,'product_admin'); + + $head[$h][0] = DOL_URL_ROOT.'/product/admin/product_extrafields.php'; + $head[$h][1] = $langs->trans("ExtraFields"); + $head[$h][2] = 'attributes'; + $h++; + + complete_head_from_modules($conf,$langs,$object,$head,$h,'product_admin','remove'); + + return $head; +} + + +/** + * + * Enter description here ... + * @param unknown_type $product + * @param unknown_type $socid + */ function show_stats_for_company($product,$socid) { global $conf,$langs,$user,$db; diff --git a/htdocs/core/modules/import/import_csv.modules.php b/htdocs/core/modules/import/import_csv.modules.php index b6afe2b8e42..2b31a203fc7 100644 --- a/htdocs/core/modules/import/import_csv.modules.php +++ b/htdocs/core/modules/import/import_csv.modules.php @@ -322,9 +322,14 @@ class ImportCsv extends ModeleImports $i=0; $errorforthistable=0; - // Loop on each fields in the match array ($key = 1..n, $val=alias of field) + // 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 @@ -350,7 +355,7 @@ class ImportCsv extends ModeleImports //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 (! 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']; @@ -383,6 +388,7 @@ class ImportCsv extends ModeleImports } } + //print 'Val to use as insert is '.$newval.'
'; } @@ -442,18 +448,19 @@ class ImportCsv extends ModeleImports // Define $listfields and $listvalues to build SQL request if ($listfields) { $listfields.=', '; $listvalues.=', '; } - $listfields.=preg_replace('/^.*\./i','',$val); + $listfields.=$fieldname; if ($arrayrecord[($key-1)]['type'] < 0) $listvalues.="null"; - else if ($arrayrecord[($key-1)]['type'] == 0) $listvalues.="''"; - else if ($arrayrecord[($key-1)]['type'] > 0) $listvalues.="'".$this->db->escape($newval)."'"; + elseif ($arrayrecord[($key-1)]['type'] == 0) $listvalues.="''"; + elseif ($arrayrecord[($key-1)]['type'] > 0) $listvalues.="'".$this->db->escape($newval)."'"; } $i++; } - // Loop on each hidden fields - if (is_array($objimport->array_import_fieldshidden[0])) + // 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])) { - foreach($objimport->array_import_fieldshidden[0] as $key => $val) + // 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.=', '; } @@ -462,27 +469,25 @@ class ImportCsv extends ModeleImports $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 'Show listfields='.$listfields.'
listvalues='.$listvalues.'
'; + //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) { - // If some values need to be found somewhere else than in source file: Case we need a rowid found from a fetch on a reference. - // This is used when insert must be done when a parent row already exists - // $objimport->array_import_convertvalue=array('s.fk_soc'=>array('rule'=>'fetchidfromref',file='/societe.class.php','class'=>'Societe','method'=>'fetch')); - foreach($objimport->array_import_convertvalue as $alias => $rulearray) - { - if (empty($rulearray['rule']) || $rulearray['rule']!='fetchidfromref') continue; - dol_syslog("We need to get rowid from ref=".$alias." using value found in column ".$array_match_database_to_file." in source file, so ".$arrayrecord[$array_match_database_to_file]['val']); - } - - // If some values need to be found somewhere else than in source file: Case we need lastinsert id from previous insert - // This is used when insert must be done in several tables - // $objimport->array_import_convertvalue=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t'); - // TODO + //var_dump($objimport->array_import_convertvalue); exit; // Build SQL request $sql ='INSERT INTO '.$tablename.'('.$listfields.', import_key'; @@ -513,10 +518,10 @@ class ImportCsv extends ModeleImports } } } - else + /*else { - dol_print_error('Ne doit pas arriver AAA'); - } + dol_print_error('','ErrorFieldListEmptyFor '.$alias."/".$tablename); + }*/ } } } diff --git a/htdocs/core/modules/modAdherent.class.php b/htdocs/core/modules/modAdherent.class.php index 41f5bc4be3b..d163486a41f 100644 --- a/htdocs/core/modules/modAdherent.class.php +++ b/htdocs/core/modules/modAdherent.class.php @@ -211,10 +211,24 @@ class modAdherent extends DolibarrModules $this->import_label[$r]="Members"; // 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('a'=>MAIN_DB_PREFIX.'adherent'); + $this->import_tables_array[$r]=array('a'=>MAIN_DB_PREFIX.'adherent','extra'=>MAIN_DB_PREFIX.'adherent_extrafields'); $this->import_tables_creator_array[$r]=array('a'=>'fk_user_author'); // Fields to store import user id $this->import_fields_array[$r]=array('a.civilite'=>"Civility",'a.nom'=>"Lastname*",'a.prenom'=>"Firstname",'a.login'=>"Login*","a.pass"=>"Password","a.fk_adherent_type"=>"MemberType*",'a.morphy'=>'MorPhy*','a.societe'=>'Company','a.adresse'=>"Address",'a.cp'=>"Zip",'a.ville'=>"Town",'a.pays'=>"Country",'a.phone'=>"PhonePro",'a.phone_perso'=>"PhonePerso",'a.phone_mobile'=>"PhoneMobile",'a.email'=>"Email",'a.naiss'=>"Birthday",'a.statut'=>"Status*",'a.photo'=>"Photo",'a.note'=>"Note",'a.datec'=>'DateCreation','a.datefin'=>'DateEndSubscription'); - $this->import_regex_array[$r]=array('a.civilite'=>'code@'.MAIN_DB_PREFIX.'c_civilite','a.fk_adherent_type'=>'rowid@'.MAIN_DB_PREFIX.'adherent_type','a.morphy'=>'(phy|mor)','a.statut'=>'^[0|1]','a.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','a.datefin'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$'); + // Add extra fields + $sql="SELECT name, label FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'member'"; + $resql=$this->db->query($sql); + if ($resql) // This can fail when class is used on old database (during migration for example) + { + while ($obj=$this->db->fetch_object($resql)) + { + $fieldname='extra.'.$obj->name; + $fieldlabel=ucfirst($obj->label); + $this->import_fields_array[$r][$fieldname]=$fieldlabel; + } + } + // End add extra fields + $this->import_fieldshidden_array[$r]=array('extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'adherent'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent) + $this->import_regex_array[$r]=array('a.civilite'=>'code@'.MAIN_DB_PREFIX.'c_civilite','a.fk_adherent_type'=>'rowid@'.MAIN_DB_PREFIX.'adherent_type','a.morphy'=>'(phy|mor)','a.statut'=>'^[0|1]','a.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','a.datefin'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$'); $this->import_examplevalues_array[$r]=array('a.civilite'=>"MR",'a.nom'=>'Smith','a.prenom'=>'John','a.login'=>'jsmith','a.pass'=>'passofjsmith','a.fk_adherent_type'=>'1','a.morphy'=>'"mor" or "phy"','a.societe'=>'JS company','a.adresse'=>'21 jump street','a.cp'=>'55000','a.ville'=>'New York','a.pays'=>'1','a.email'=>'jsmith@example.com','a.naiss'=>'1972-10-10','a.statut'=>"0 or 1",'a.note'=>"This is a comment on member",'a.datec'=>dol_print_date($now,'%Y-%m-%d'),'a.datefin'=>dol_print_date(dol_time_plus_duree($now, 1, 'y'),'%Y-%m-%d')); } diff --git a/htdocs/core/modules/modProduct.class.php b/htdocs/core/modules/modProduct.class.php index 4e061e99772..c156fb0df3c 100644 --- a/htdocs/core/modules/modProduct.class.php +++ b/htdocs/core/modules/modProduct.class.php @@ -71,7 +71,7 @@ class modProduct extends DolibarrModules $this->requiredby = array("modStock","modBarcode"); // Config pages - $this->config_page_url = array("produit.php@product"); + $this->config_page_url = array("product.php@product"); $this->langfiles = array("products","companies","stocks","bills"); // Constants @@ -139,9 +139,24 @@ class modProduct extends DolibarrModules //if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge ($this->export_entities_array[$r],array('p.stock'=>'product','p.pmp'=>'product')); if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge ($this->export_entities_array[$r],array('p.pmp'=>'product')); if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge ($this->export_entities_array[$r],array('p.barcode'=>'product')); + // Add extra fields + $sql="SELECT name, label FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product'"; + $resql=$this->db->query($sql); + if ($resql) // This can fail when class is used on old database (during migration for example) + { + while ($obj=$this->db->fetch_object($resql)) + { + $fieldname='extra.'.$obj->name; + $fieldlabel=ucfirst($obj->label); + $this->export_fields_array[$r][$fieldname]=$fieldlabel; + $this->export_entities_array[$r][$fieldname]='product'; + } + } + // End add axtra fields $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'product as p'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object'; $this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity("product", 1).')'; @@ -154,9 +169,23 @@ class modProduct extends DolibarrModules $this->import_label[$r]="Products"; // 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('p'=>MAIN_DB_PREFIX.'product'); + $this->import_tables_array[$r]=array('p'=>MAIN_DB_PREFIX.'product','extra'=>MAIN_DB_PREFIX.'product_extrafields'); $this->import_tables_creator_array[$r]=array('p'=>'fk_user_author'); // Fields to store import user id $this->import_fields_array[$r]=array('p.ref'=>"Ref*",'p.label'=>"Label*",'p.description'=>"Description",'p.note'=>"Note",'p.price'=>"SellingPriceHT",'p.price_ttc'=>"SellingPriceTTC",'p.tva_tx'=>'VAT','p.tosell'=>"OnSell*",'p.tobuy'=>"OnBuy*",'p.fk_product_type'=>"Type*",'p.finished'=>'Nature','p.duration'=>"Duration",'p.weight'=>"Weight",'p.volume'=>"Volume",'p.datec'=>'DateCreation*'); + // Add extra fields + $sql="SELECT name, label FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product'"; + $resql=$this->db->query($sql); + if ($resql) // This can fail when class is used on old database (during migration for example) + { + while ($obj=$this->db->fetch_object($resql)) + { + $fieldname='extra.'.$obj->name; + $fieldlabel=ucfirst($obj->label); + $this->import_fields_array[$r][$fieldname]=$fieldlabel; + } + } + // End add extra fields + $this->import_fieldshidden_array[$r]=array('extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'product'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent) $this->import_regex_array[$r]=array('p.ref'=>'[^ ]','p.tosell'=>'^[0|1]$','p.tobuy'=>'^[0|1]$','p.fk_product_type'=>'^[0|1]$','p.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$'); $this->import_examplevalues_array[$r]=array('p.ref'=>"PR123456",'p.label'=>"My product",'p.description'=>"This is a description example for record",'p.note'=>"Some note",'p.price'=>"100",'p.price_ttc'=>"110",'p.tva_tx'=>'10','p.tosell'=>"0 or 1",'p.tobuy'=>"0 or 1",'p.fk_product_type'=>"0 for product/1 for service",'p.finished'=>'','p.duration'=>"1y",'p.datec'=>'2008-12-31'); } diff --git a/htdocs/core/modules/modService.class.php b/htdocs/core/modules/modService.class.php index 860de81b81f..d318b62046f 100644 --- a/htdocs/core/modules/modService.class.php +++ b/htdocs/core/modules/modService.class.php @@ -69,7 +69,7 @@ class modService extends DolibarrModules $this->requiredby = array("modContrat"); // Config pages - $this->config_page_url = array("produit.php@product"); + $this->config_page_url = array("product.php@product"); $this->langfiles = array("products","companies","bills"); // Constants @@ -125,11 +125,55 @@ class modService extends DolibarrModules if (! empty($conf->stock->enabled)) $this->export_fields_array[$r]=array_merge ($this->export_fields_array[$r],array('p.stock'=>'Stock')); $this->export_entities_array[$r]=array('p.rowid'=>"service",'p.ref'=>"service",'p.label'=>"service",'p.description'=>"service",'p.accountancy_code_sell'=>'service','p.accountancy_code_sell'=>'service','p.note'=>"service",'p.price_base_type'=>"service",'p.price'=>"service",'p.price_ttc'=>"service",'p.tva_tx'=>"service",'p.tosell'=>"service",'p.duration'=>"service",'p.datec'=>"service",'p.tms'=>"service"); if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge ($this->export_entities_array[$r],array('p.stock'=>'product')); + // Add extra fields + $sql="SELECT name, label FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product'"; + $resql=$this->db->query($sql); + if ($resql) // This can fail when class is used on old database (during migration for example) + { + while ($obj=$this->db->fetch_object($resql)) + { + $fieldname='extra.'.$obj->name; + $fieldlabel=ucfirst($obj->label); + $this->export_fields_array[$r][$fieldname]=$fieldlabel; + $this->export_entities_array[$r][$fieldname]='product'; + } + } + // End add axtra fields $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'product as p'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object'; $this->export_sql_end[$r] .=' WHERE p.fk_product_type = 1 AND p.entity IN ('.getEntity("product", 1).')'; + + // Imports + //-------- + $r=0; + + $r++; + $this->import_code[$r]=$this->rights_class.'_'.$r; + $this->import_label[$r]="Products"; // 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('p'=>MAIN_DB_PREFIX.'product','extra'=>MAIN_DB_PREFIX.'product_extrafields'); + $this->import_tables_creator_array[$r]=array('p'=>'fk_user_author'); // Fields to store import user id + $this->import_fields_array[$r]=array('p.ref'=>"Ref*",'p.label'=>"Label*",'p.description'=>"Description",'p.note'=>"Note",'p.price'=>"SellingPriceHT",'p.price_ttc'=>"SellingPriceTTC",'p.tva_tx'=>'VAT','p.tosell'=>"OnSell*",'p.tobuy'=>"OnBuy*",'p.fk_product_type'=>"Type*",'p.finished'=>'Nature','p.duration'=>"Duration",'p.weight'=>"Weight",'p.volume'=>"Volume",'p.datec'=>'DateCreation*'); + // Add extra fields + $sql="SELECT name, label FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product'"; + $resql=$this->db->query($sql); + if ($resql) // This can fail when class is used on old database (during migration for example) + { + while ($obj=$this->db->fetch_object($resql)) + { + $fieldname='extra.'.$obj->name; + $fieldlabel=ucfirst($obj->label); + $this->import_fields_array[$r][$fieldname]=$fieldlabel; + } + } + // End add extra fields + $this->import_fieldshidden_array[$r]=array('extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'product'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent) + $this->import_regex_array[$r]=array('p.ref'=>'[^ ]','p.tosell'=>'^[0|1]$','p.tobuy'=>'^[0|1]$','p.fk_product_type'=>'^[0|1]$','p.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$'); + $this->import_examplevalues_array[$r]=array('p.ref'=>"PR123456",'p.label'=>"My product",'p.description'=>"This is a description example for record",'p.note'=>"Some note",'p.price'=>"100",'p.price_ttc'=>"110",'p.tva_tx'=>'10','p.tosell'=>"0 or 1",'p.tobuy'=>"0 or 1",'p.fk_product_type'=>"0 for product/1 for service",'p.finished'=>'','p.duration'=>"1y",'p.datec'=>'2008-12-31'); } diff --git a/htdocs/core/modules/modSociete.class.php b/htdocs/core/modules/modSociete.class.php index 6f5f3080ef2..c96bd6beb0f 100644 --- a/htdocs/core/modules/modSociete.class.php +++ b/htdocs/core/modules/modSociete.class.php @@ -269,16 +269,29 @@ class modSociete extends DolibarrModules $this->import_label[$r]='ImportDataset_company_1'; $this->import_icon[$r]='company'; $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('s'=>MAIN_DB_PREFIX.'societe'); // List of tables to insert into (insert done in same order) - $this->import_fields_array[$r]=array('s.nom'=>"Name*",'s.status'=>"Status",'s.client'=>"Customer*",'s.fournisseur'=>"Supplier*",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode",'s.address'=>"Address",'s.cp'=>"Zip",'s.ville'=>"Town",'s.fk_pays'=>"CountryCode",'s.tel'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",'s.siret'=>"IdProf1",'s.siren'=>"IdProf2",'s.ape'=>"IdProf3",'s.idprof4'=>"IdProf4",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note'=>"Note",'s.fk_typent'=>"ThirdPartyType",'s.fk_effectif'=>"Effectif","s.fk_forme_juridique"=>"JuridicalStatus",'s.fk_prospectlevel'=>'ProspectLevel','s.fk_stcomm'=>'ProspectStatus','s.default_lang'=>'DefaultLanguage','s.barcode'=>'BarCode','s.datec'=>"DateCreation"); - $this->import_fieldshidden_array[$r]=array('s.fk_user_creat'=>'user->id'); + $this->import_tables_array[$r]=array('s'=>MAIN_DB_PREFIX.'societe','extra'=>MAIN_DB_PREFIX.'societe_extrafields'); // List of tables to insert into (insert done in same order) + $this->import_fields_array[$r]=array('s.nom'=>"Name*",'s.status'=>"Status",'s.client'=>"Customer*",'s.fournisseur'=>"Supplier*",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode",'s.address'=>"Address",'s.cp'=>"Zip",'s.ville'=>"Town",'s.fk_pays'=>"CountryCode",'s.tel'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",'s.siret'=>"IdProf1",'s.siren'=>"IdProf2",'s.ape'=>"IdProf3",'s.idprof4'=>"IdProf4",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note'=>"Note",'s.fk_typent'=>"ThirdPartyType",'s.fk_effectif'=>"Effectif","s.fk_forme_juridique"=>"JuridicalStatus",'s.fk_prospectlevel'=>'ProspectLevel','s.fk_stcomm'=>'ProspectStatus*','s.default_lang'=>'DefaultLanguage','s.barcode'=>'BarCode','s.datec'=>"DateCreation"); + // Add extra fields + $sql="SELECT name, label FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'company'"; + $resql=$this->db->query($sql); + if ($resql) // This can fail when class is used on old database (during migration for example) + { + while ($obj=$this->db->fetch_object($resql)) + { + $fieldname='extra.'.$obj->name; + $fieldlabel=ucfirst($obj->label); + $this->import_fields_array[$r][$fieldname]=$fieldlabel; + } + } + // End add extra fields + $this->import_fieldshidden_array[$r]=array('s.fk_user_creat'=>'user->id','extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'societe'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent) $this->import_convertvalue_array[$r]=array( 's.fk_typent'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ctypent.class.php','class'=>'Ctypent','method'=>'fetch','dict'=>'DictionnaryCompanyType'), 's.fk_pays'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/cpays.class.php','class'=>'Cpays','method'=>'fetch','dict'=>'DictionnaryCountry'), ); //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t'); $this->import_regex_array[$r]=array('s.status'=>'^[0|1]','s.client'=>'^[0|1|2|3]','s.fournisseur'=>'^[0|1]','s.fk_typent'=>'id@'.MAIN_DB_PREFIX.'c_typent','s.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$'); - $this->import_examplevalues_array[$r]=array('s.nom'=>"MyBigCompany",'s.status'=>"0 (closed) or 1 (active)",'s.client'=>'0 (no customer no prospect)/1 (customer)/2 (prospect)/3 (customer and prospect)','s.fournisseur'=>'0 or 1','s.datec'=>dol_print_date(mktime(),'%Y-%m-%d'),'s.code_client'=>"CU01-0001",'s.code_fournisseur'=>"SU01-0001",'s.address'=>"61 jump street",'s.cp'=>"123456",'s.ville'=>"Big town",'s.fk_pays'=>'US, FR, DE...','s.tel'=>"0101010101",'s.fax'=>"0101010102",'s.url'=>"http://mycompany.com",'s.email'=>"test@mycompany.com",'s.siret'=>"",'s.siren'=>"",'s.ape'=>"",'s.idprof4'=>"",'s.tva_intra'=>"FR0123456789",'s.capital'=>"10000",'s.note'=>"This is an example of note for record",'s.fk_typent'=>"2",'s.fk_effectif'=>"3","s.fk_forme_juridique"=>"1",'s.fk_prospectlevel'=>'PL_MEDIUM','s.fk_stcomm'=>'','s.default_lang'=>'en_US','s.barcode'=>'123456789'); + $this->import_examplevalues_array[$r]=array('s.nom'=>"MyBigCompany",'s.status'=>"0 (closed) or 1 (active)",'s.client'=>'0 (no customer no prospect)/1 (customer)/2 (prospect)/3 (customer and prospect)','s.fournisseur'=>'0 or 1','s.datec'=>dol_print_date(mktime(),'%Y-%m-%d'),'s.code_client'=>"CU01-0001",'s.code_fournisseur'=>"SU01-0001",'s.address'=>"61 jump street",'s.cp'=>"123456",'s.ville'=>"Big town",'s.fk_pays'=>'US, FR, DE...','s.tel'=>"0101010101",'s.fax'=>"0101010102",'s.url'=>"http://mycompany.com",'s.email'=>"test@mycompany.com",'s.siret'=>"",'s.siren'=>"",'s.ape'=>"",'s.idprof4'=>"",'s.tva_intra'=>"FR0123456789",'s.capital'=>"10000",'s.note'=>"This is an example of note for record",'s.fk_typent'=>"2",'s.fk_effectif'=>"3","s.fk_forme_juridique"=>"1",'s.fk_prospectlevel'=>'PL_MEDIUM','s.fk_stcomm'=>'0','s.default_lang'=>'en_US','s.barcode'=>'123456789'); // Import list of contact and attributes $r++; diff --git a/htdocs/install/mysql/migration/3.1.0-3.2.0.sql b/htdocs/install/mysql/migration/3.1.0-3.2.0.sql index bc0a4ac8223..695f36a8205 100755 --- a/htdocs/install/mysql/migration/3.1.0-3.2.0.sql +++ b/htdocs/install/mysql/migration/3.1.0-3.2.0.sql @@ -245,3 +245,8 @@ ALTER TABLE llx_product_stock DROP COLUMN location; -- DROP TABLE llx_cond_reglement; -- DROP TABLE llx_expedition_methode; -- DROP TABLE llx_product_fournisseur; + +ALTER TABLE llx_adherent_extrafields ADD COLUMN import_key varchar(14); +ALTER TABLE llx_product_extrafields ADD COLUMN import_key varchar(14); +ALTER TABLE llx_societe_extrafields ADD COLUMN import_key varchar(14); + \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_adherent_extrafields.sql b/htdocs/install/mysql/tables/llx_adherent_extrafields.sql index 4a38857aed0..13f75088c8c 100755 --- a/htdocs/install/mysql/tables/llx_adherent_extrafields.sql +++ b/htdocs/install/mysql/tables/llx_adherent_extrafields.sql @@ -22,5 +22,6 @@ create table llx_adherent_extrafields ( rowid integer AUTO_INCREMENT PRIMARY KEY, tms timestamp, - fk_object integer NOT NULL -- member id + fk_object integer NOT NULL, -- member id + import_key varchar(14) -- import key )ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_product_extrafields.sql b/htdocs/install/mysql/tables/llx_product_extrafields.sql index e53dcd2767f..03fdda47419 100755 --- a/htdocs/install/mysql/tables/llx_product_extrafields.sql +++ b/htdocs/install/mysql/tables/llx_product_extrafields.sql @@ -20,5 +20,6 @@ create table llx_product_extrafields ( rowid integer AUTO_INCREMENT PRIMARY KEY, tms timestamp, - fk_object integer NOT NULL + fk_object integer NOT NULL, + import_key varchar(14) -- import key ) ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_societe_extrafields.sql b/htdocs/install/mysql/tables/llx_societe_extrafields.sql index 1a2febf4376..d8e74ae5902 100755 --- a/htdocs/install/mysql/tables/llx_societe_extrafields.sql +++ b/htdocs/install/mysql/tables/llx_societe_extrafields.sql @@ -20,6 +20,7 @@ create table llx_societe_extrafields ( rowid integer AUTO_INCREMENT PRIMARY KEY, tms timestamp, - fk_object integer NOT NULL + fk_object integer NOT NULL, + import_key varchar(14) -- import key ) ENGINE=innodb; diff --git a/htdocs/product/admin/produit.php b/htdocs/product/admin/product.php similarity index 98% rename from htdocs/product/admin/produit.php rename to htdocs/product/admin/product.php index 24de62f5e99..1de35cbee03 100644 --- a/htdocs/product/admin/produit.php +++ b/htdocs/product/admin/product.php @@ -29,6 +29,7 @@ require("../../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/core/lib/product.lib.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formbarcode.class.php"); $langs->load("admin"); @@ -130,14 +131,8 @@ llxHeader('',$title); $linkback=''.$langs->trans("BackToModuleList").''; print_fiche_titre($title,$linkback,'setup'); -$h = 0; - -$head[$h][0] = DOL_URL_ROOT."/product/admin/produit.php"; -$head[$h][1] = $tab; -$hselected=$h; -$h++; - -dol_fiche_head($head, $hselected, $langs->trans("ModuleSetup")); +$head = product_admin_prepare_head(null, $tab); +dol_fiche_head($head, 'general', $tab, 0, 'product'); $form=new Form($db); $var=true; diff --git a/htdocs/product/admin/product_extrafields.php b/htdocs/product/admin/product_extrafields.php new file mode 100755 index 00000000000..c24782a9396 --- /dev/null +++ b/htdocs/product/admin/product_extrafields.php @@ -0,0 +1,226 @@ + + * Copyright (C) 2003 Jean-Louis Bergamo + * Copyright (C) 2004-2011 Laurent Destailleur + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/societe/admin/societe_extrafields.php + * \ingroup societe + * \brief Page to setup extra fields of third party + */ + +require("../../main.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/core/lib/product.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php"); + +$langs->load("companies"); +$langs->load("admin"); +$langs->load("products"); + +$extrafields = new ExtraFields($db); +$form = new Form($db); + +// List of supported format +$type2label=array( +'varchar'=>$langs->trans('String'), +'text'=>$langs->trans('Text'), +'int'=>$langs->trans('Int'), +//'date'=>$langs->trans('Date'), +//'datetime'=>$langs->trans('DateAndTime') +); + +$action=GETPOST("action"); +$elementtype='product'; + +if (!$user->admin) accessforbidden(); + + +/* + * Actions + */ + +require(DOL_DOCUMENT_ROOT."/core/admin_extrafields.inc.php"); + + + +/* + * View + */ + +$title = $langs->trans('ProductServiceSetup'); +$tab = $langs->trans("ProductsAndServices"); +if (empty($conf->produit->enabled)) +{ + $title = $langs->trans('ServiceSetup'); + $tab = $langs->trans('Services'); +} +else if (empty($conf->service->enabled)) +{ + $title = $langs->trans('ProductSetup'); + $tab = $langs->trans('Products'); +} + +$help_url='EN:Module Third Parties setup|FR:Paramétrage_du_module_Tiers'; +llxHeader('',$title); + + +$linkback=''.$langs->trans("BackToModuleList").''; +print_fiche_titre($title,$linkback,'setup'); + + +$head = product_admin_prepare_head(null, $tab); + +dol_fiche_head($head, 'attributes', $tab, 0, 'product'); + + +print $langs->trans("DefineHereComplementaryAttributes",$textobject).'
'."\n"; +print '
'; + +dol_htmloutput_errors($mesg); + +// Load attribute_label +$extrafields->fetch_name_optionals_label($elementtype); + +print ""; + +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print "\n"; + +$var=True; +foreach($extrafields->attribute_type as $key => $value) +{ + $var=!$var; + print ""; + print "\n"; + print "\n"; + print "\n"; + print '\n"; + print '\n"; + print ""; + // $i++; +} + +print "
'.$langs->trans("Label").''.$langs->trans("AttributeCode").''.$langs->trans("Type").''.$langs->trans("Size").' 
".$extrafields->attribute_label[$key]."".$key."".$type2label[$extrafields->attribute_type[$key]]."'.$extrafields->attribute_size[$key]."'.img_edit().''; + print "  ".img_delete()."
"; + +dol_fiche_end(); + +/* + * Barre d'actions + * + */ +if ($action != 'create' && $action != 'edit') +{ + print '
'; + print "".$langs->trans("NewAttribute").""; + print "
"; +} + + +/* ************************************************************************** */ +/* */ +/* Creation d'un champ optionnel + /* */ +/* ************************************************************************** */ + +if ($action == 'create') +{ + print "
"; + print_titre($langs->trans('NewAttribute')); + + print '
'; + print ''; + print ''; + + print ''; + + // Label + print ''; + // Code + print ''; + // Type + print ''; + // Size + print ''; + + print "
'.$langs->trans("Label").'
'.$langs->trans("AttributeCode").' ('.$langs->trans("AlphaNumOnlyCharsAndNoSpace").')
'.$langs->trans("Type").''; + print $form->selectarray('type',$type2label,GETPOST('type')); + print '
'.$langs->trans("Size").'
\n"; + + print '

  '; + print '
'; + + print "
\n"; +} + +/* ************************************************************************** */ +/* */ +/* Edition d'un champ optionnel */ +/* */ +/* ************************************************************************** */ +if ($_GET["attrname"] && $action == 'edit') +{ + print "
"; + print_titre($langs->trans("FieldEdition",$_GET["attrname"])); + + /* + * formulaire d'edition + */ + print '
'; + print ''; + print ''; + print ''; + print ''; + + // Label + print ''; + print ''; + print ''; + // Code + print ''; + print ''; + print ''; + print ''; + // Type + $type=$extrafields->attribute_type[$_GET["attrname"]]; + $size=$extrafields->attribute_size[$_GET["attrname"]]; + print ''; + print ''; + // Size + print ''; + + print '
'.$langs->trans("Label").'
'.$langs->trans("AttributeCode").''.$_GET["attrname"].' 
'.$langs->trans("Type").''; + print $type2label[$type]; + print ''; + print '
'.$langs->trans("Size").'
'; + + print '

  '; + print '
'; + + print "
"; + +} + +llxFooter(); + +$db->close(); +?> diff --git a/htdocs/societe/admin/societe_extrafields.php b/htdocs/societe/admin/societe_extrafields.php index 307ee163c9e..313e8fc0b33 100755 --- a/htdocs/societe/admin/societe_extrafields.php +++ b/htdocs/societe/admin/societe_extrafields.php @@ -70,7 +70,7 @@ $linkback=''.$langs->trans("BackToM print_fiche_titre($langs->trans("CompanySetup"),$linkback,'setup'); -$head = societe_admin_prepare_head($adh); +$head = societe_admin_prepare_head(null); dol_fiche_head($head, 'attributes', $langs->trans("ThirdParty"), 0, 'company');