1. function profile_to_cck_configure() {
  2.   drupal_set_title(t('Convert Profiles to CCK'));
  3.  
  4.   $output = t("Easily convert profile data to a CCK node type of your choice. Choose your settings below. On the next screen, you'll be able to match your profile dat
  5. a with the fields of your CCK node type.");
  6.  
  7.   if (!module_exists('profile')) {
  8.     $output .= drupal_set_message(t('You do not have the core profile module enable
  9. d. This module\'s purpose is to convert profile data to a CCK type.'), 'error');
  10.   }
  11.   else {
  12.     $output .= drupal_get_form('profile_to_cck_configure_form');
  13.   }
  14.   return $output;
  15. }
  16.  
  17. function profile_to_cck_convert_form() {
  18.  
  19.   $profile_fields = db_query("SELECT fid, title, name, type, options FROM {profile_
  20. fields}");
  21.  
  22.   $form['field_match'] = array(
  23.     '#type' => 'fieldset',
  24.     '#title' => t('Field Match'),
  25.     '#tree' => TRUE
  26.   );
  27.  
  28.   while ($profile_field = db_fetch_array($profile_fields)) {
  29.     // print_r($profile_field);
  30.     $title = $profile_field['title'];
  31.  
  32.     $form['field_match'][$title]['node_field'] = array(
  33.       '#type' => 'markup',
  34.       '#value' => check_plain($title),
  35.     );
  36.  
  37.     $fields = array();
  38.     foreach (content_fields(NULL, $profile_node) as $node_field) {
  39.       $fields[] = $node_field['field_name'];
  40.     }
  41.     $form['field_match'][$title]['profile_field'] = array(
  42.       '#type' => 'select',
  43.       '#options' => $fields,
  44.  
  45.     );
  46.  
  47.   }
  48.   $form['field_match']['submit'] = array(
  49.     '#type' => 'submit',
  50.     '#value' => t('Convert'),
  51.     '#weight' => 10
  52.   );
  53.  
  54. //  print_r($form);
  55.   return $form;
  56. }
  57.  
  58. function theme_profile_to_cck_convert_form($form) {
  59.   $header = array(t('Profile Field'), t('Node Field'));
  60.  
  61.   foreach (element_children($form['field_match']) as $key) {
  62.     $rows[] = array(
  63.       drupal_render($form['field_match'][$key]['node_field']),
  64.       drupal_render($form['field_match'][$key]['profile_field']),
  65.     );
  66.   }
  67.   $form['field_match']['#value'] = theme('table', $header, $rows);
  68.  
  69.   $output .= drupal_render($form);
  70.  
  71.   return $output;
  72. }