# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: contributions/modules/pirets/pirets.admin.inc
--- contributions/modules/pirets/pirets.admin.inc Base (1.1)
+++ contributions/modules/pirets/pirets.admin.inc Locally Modified (Based On 1.1)
@@ -384,6 +384,7 @@
  * Useful field selection form.
  */
 function pirets_sets_fields_form() {
+
   module_load_include('inc', 'pirets', 'pirets.connect');
   // The classes must be configured first.
   if (variable_get('pirets_classes', NULL) === NULL) {
@@ -402,14 +403,27 @@
     'fields' => array(
       '#weight' => 10,
     ),
+
   );
+    $form['fields']['#tree'] = TRUE;
   foreach ($fields as $field) {
-    $form['fields'][$field['system_name']] = array(
+        $form['fields'][$field['system_name']]['cck'] = array(
       '#type' => 'checkbox',
       '#title' => t('@sysname (@longname)', array('@sysname' => $field['system_name'], '@longname' => $field['long_name'])),
       '#default_value' => $field['cck'],
       '#weight' => $weight += 10,
     );
+        $form['fields'][$field['system_name']]['cck_field_name'] = array (
+                '#type' => 'textfield',
+                '#default_value' => $field['cck_field_name']?$field['cck_field_name']:substr($field['system_name'], 0, 25),
+                '#weight' => $weight += 1,
+                '#maxlength' => 25,
+                '#field_prefix' => '<span dir="ltr">pirets_',
+                '#field_suffix' => '</span>',
+                '#attributes' => array('dir'=>'ltr'),
+                '#size' => 15,
+                '#description' => t('Field name (a-z, 0-9, _)'),
+        );
   }
   $form['submit']['#weight'] = $weight += 10;
   return $form;
@@ -425,9 +439,9 @@
   $weight = 20;
   foreach ($fields as $id => $field) {
     // If the field is checked on the form, but we're not currently using it…
-    if ($form_state['values'][$id] && !$field['cck']) {
+        if ($form_state['values']['fields'][$id]['cck'] && !$field['cck']) {
       $cck_field = array(
-        'field_name' => 'pirets_' . $id,
+                    'field_name' => 'pirets_' . $form_state['values']['fields'][$id]['cck_field_name'],
         'type_name' => 'pirets_prop',
         'label' => $field['long_name'],
         'weight' => $weight += 10,
@@ -487,15 +501,16 @@
       $record = array(
         'system_name' => $id,
         'cck' => 1,
+                    'cck_field_name' => $form_state['values']['fields'][$id]['cck_field_name'],
       );
       drupal_set_message(t('Creating field %label (@id).', array('%label' => $cck_field['label'], '@id' => $id)));
       drupal_write_record('pirets_fields', $record, 'system_name');
     }
     // Else if the field is unchecked on the form but we ARE currently using it…
-    elseif (!$form_state['values'][$id] && $field['cck']) {
-      $label = db_result(db_query('SELECT label FROM {content_node_field_instance} WHERE field_name = "%s" && type_name = "%s"', 'pirets_' . $id, 'pirets_prop'));
+        elseif (!$form_state['values']['fields'][$id]['cck'] && $field['cck']) {
+            $label = db_result(db_query('SELECT label FROM {content_node_field_instance} WHERE field_name = "%s" && type_name = "%s"', 'pirets_' . $field['cck_field_name'], 'pirets_prop'));
       drupal_set_message(t('Removing field %label (@id).', array('%label' => $label, '@id' => $id)));
-      content_field_instance_delete('pirets_' . $id, 'pirets_prop');
\ No newline at end of file
+            content_field_instance_delete('pirets_' . $field['cck_field_name'], 'pirets_prop');
\ No newline at end of file
       // If that field was the image count field, delete the image field too.
       if ($field['correlation'] === 'pic_count') {
         drupal_set_message(t('Removing <em>Images</em> field.'));
Index: contributions/modules/pirets/pirets.batch.inc
--- contributions/modules/pirets/pirets.batch.inc Base (1.1)
+++ contributions/modules/pirets/pirets.batch.inc Locally Modified (Based On 1.1)
@@ -120,7 +120,7 @@
     // Load the info for the properties which already belong to
     // this class.
     $context['results']['db_props'] = array();
-    $rez = db_query("SELECT nid, pirets_crc32_value, pirets_{$context['results']['mls_field']}_value AS mls FROM {content_type_pirets_prop} WHERE pirets_class_value = \"%s\"", $context['results']['class']);
+    $rez = db_query("SELECT nid, pirets_crc32_value, pirets_{$context['results']['fields'][$context['results']['mls_field']]['cck_field_name']}_value AS mls FROM {content_type_pirets_prop} WHERE pirets_class_value = \"%s\"", $context['results']['class']);
     while ($prop = db_fetch_array($rez)) {
       $prop = array_map('intval', $prop);
       $context['results']['db_props'][$prop['mls']] = $prop;
@@ -218,7 +218,7 @@
         else {
           $value = $prop[$field];
         }
-        $node_child = 'pirets_' . $field;
\ No newline at end of file
+        $node_child = 'pirets_' . $_fields[$field]['cck_field_name'];
\ No newline at end of file
         if (is_array($value)) {
           $cck_value = array();
           foreach ($value as $val) {
Index: contributions/modules/pirets/pirets.install
--- contributions/modules/pirets/pirets.install Base (1.1)
+++ contributions/modules/pirets/pirets.install Locally Modified (Based On 1.1)
@@ -129,7 +129,7 @@
     fieldgroup_delete('pirets_prop', 'group_pirets');
   }
   while ($sysname = db_fetch_array($rez)) {
-    content_field_instance_delete('pirets_' . $sysname['system_name'], 'pirets_prop');
+    content_field_instance_delete('pirets_' . $sysname['cck_field_name'], 'pirets_prop');
   }
   content_field_instance_delete('pirets_crc32', 'pirets_prop');
   content_field_instance_delete('pirets_class', 'pirets_prop');
@@ -224,10 +224,17 @@
           'default' => '',
           'description' => 'The special correlation of this field, if any.',
         ),
+        'cck_field_name' => array(
+            'type' => 'varchar',
+            'length' => 32,
+            'not null' => TRUE,
+            'default' => '',
+            'description' => 'Corresponding CCK System Name'),
       ),
       'primary key' => array('system_name'),
       'indexes' => array(
         'cck' => array('cck'),
+        'cck_field_name_idx' => array('cck_field_name'),
       ),
     ),
     'pirets_lookups' => array(
@@ -329,3 +336,10 @@
   variable_del('pirets_limit_suffix');
   return array();
 }
+
+function pirets_update_6304(&$sandbox) {
+    $ret = array();
+    db_add_field($ret, 'pirets_fields', 'cck_field_name', array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => '', 'description' => 'Corresponding CCK System Name'));
+    db_add_index($ret, 'pirets_fields', 'cck_field_name_idx', array('cck_field_name'));
+    return $ret;
+}
\ No newline at end of file
