<?

  $query = "show fields from idx_link";
  $result = $dbConn->Execute($query);
  $i = 0;
  while ($row = $result->FetchRow($result)) {
    if ($i >= 27) {
      $field_orig = $row['Field'];
      $field = str_replace(' ', '_', strtolower($row['Field']));
      if ($row['Type'] == 'varchar(251)') {
        $type = 'varchar(255)';
        $custom_type = 'IMAGE';
      }
      elseif ($row['Type'] == 'date') {
        $type = 'date';
        $custom_type = 'DATE';
      }
      else {
        $type = 'varchar(255)';
        $custom_type = 'TEXT';
      }
      $query = "alter table idx_link change `$field_orig` `$field` $type";
      $dbConn->Execute($query);
      
      $query = "alter table idx_link_temp change `$field_orig` `$field` $type";
      $dbConn->Execute($query); 
      
      $query = "insert into idx_custom_field
                (field_name, field_text, field_type, field_option, required, searchable, permission) values
                ('$field', '', '$custom_type', '', '1', '1', '0')";
      $dbConn->Execute($query);
    }
    $i++;
  }

?>