extrafieldsinexport.inc.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. if (empty($keyforselect) || empty($keyforelement) || empty($keyforaliasextra))
  3. {
  4. //print $keyforselet.' - '.$keyforelement.' - '.$keyforaliasextra;
  5. dol_print_error('', 'include of file extrafieldsinexport.inc.php was done but var $keyforselect or $keyforelement or $keyforaliasextra was not set');
  6. exit;
  7. }
  8. // Add extra fields
  9. $sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = '".$keyforselect."' AND type != 'separate' AND entity IN (0, ".$conf->entity.')';
  10. //print $sql;
  11. $resql=$this->db->query($sql);
  12. if ($resql) // This can fail when class is used on old database (during migration for example)
  13. {
  14. while ($obj=$this->db->fetch_object($resql))
  15. {
  16. $fieldname=$keyforaliasextra.'.'.$obj->name;
  17. $fieldlabel=ucfirst($obj->label);
  18. $typeFilter="Text";
  19. switch($obj->type)
  20. {
  21. case 'int':
  22. case 'double':
  23. case 'price':
  24. $typeFilter="Numeric";
  25. break;
  26. case 'date':
  27. case 'datetime':
  28. $typeFilter="Date";
  29. break;
  30. case 'boolean':
  31. $typeFilter="Boolean";
  32. break;
  33. case 'sellist':
  34. $tmp='';
  35. $tmpparam=unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
  36. if ($tmpparam['options'] && is_array($tmpparam['options'])) {
  37. $tmpkeys=array_keys($tmpparam['options']);
  38. $tmp=array_shift($tmpkeys);
  39. }
  40. if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
  41. break;
  42. }
  43. if ($obj->type!='separate') {
  44. $this->export_fields_array[$r][$fieldname]=$fieldlabel;
  45. $this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
  46. $this->export_entities_array[$r][$fieldname]=$keyforelement;
  47. }
  48. }
  49. }
  50. // End add axtra fields