extrafieldsinexport.inc.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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, fieldcomputed, fielddefault FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = '".$keyforselect."' AND type != 'separate' AND entity IN (0, ".$conf->entity.') ORDER BY pos ASC';
  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. $typefield = preg_replace('/\(.*$/', '', $obj->type); // double(24,8) -> double
  20. switch ($typefield) {
  21. case 'int':
  22. case 'integer':
  23. case 'double':
  24. case 'price':
  25. $typeFilter = "Numeric";
  26. break;
  27. case 'date':
  28. case 'datetime':
  29. case 'timestamp':
  30. $typeFilter = "Date";
  31. break;
  32. case 'boolean':
  33. $typeFilter = "Boolean";
  34. break;
  35. case 'select':
  36. if (!empty($conf->global->EXPORT_LABEL_FOR_SELECT))
  37. {
  38. $tmpparam = unserialize($obj->param); // $tmpparam may be array with 'options' = array(key1=>val1, key2=>val2 ...)
  39. if ($tmpparam['options'] && is_array($tmpparam['options'])) {
  40. $typeFilter = "Select:".$obj->param;
  41. }
  42. }
  43. break;
  44. case 'sellist':
  45. $tmp = '';
  46. $tmpparam = unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
  47. if ($tmpparam['options'] && is_array($tmpparam['options'])) {
  48. $tmpkeys = array_keys($tmpparam['options']);
  49. $tmp = array_shift($tmpkeys);
  50. }
  51. if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter = "List:".$tmp;
  52. break;
  53. }
  54. if ($obj->type != 'separate')
  55. {
  56. // If not a computed field
  57. if (empty($obj->fieldcomputed))
  58. {
  59. $this->export_fields_array[$r][$fieldname] = $fieldlabel;
  60. $this->export_TypeFields_array[$r][$fieldname] = $typeFilter;
  61. $this->export_entities_array[$r][$fieldname] = $keyforelement;
  62. }
  63. // If this is a computed field
  64. else
  65. {
  66. $this->export_fields_array[$r][$fieldname] = $fieldlabel;
  67. $this->export_TypeFields_array[$r][$fieldname] = $typeFilter.'Compute';
  68. $this->export_special_array[$r][$fieldname] = $obj->fieldcomputed;
  69. $this->export_entities_array[$r][$fieldname] = $keyforelement;
  70. }
  71. }
  72. }
  73. }
  74. // End add axtra fields