You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
6.2 KiB
Plaintext

<?php
function fulcrm_collection_permission() {
return array( 'administer fulcrm collection' => array( 'title' => t('Administer fulcrm collection'),
'description' => t('Perform main installation/administration tasks for fulcrm collection.'),
),
);
}
function fulcrm_collection_menu() {
/*
$items[ 'admin/config/services/fulcrm' ] = array( 'page callback' => 'system_admin_menu_block_page',
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
'title' => 'fulcrm',
'description' => 'Configuration integration with fulcrm.org.',
'position' => 'right',
'access callback' => 'user_access',
'access arguments' => array('access administration pages'),
);
*/
$items[ 'admin/config/services/fulcrm/collection' ] = array( 'page callback' => 'fulcrm_collection_admin',
'file' => 'fulcrm_collection.admin.inc',
'title' => 'fulcrm Collection',
'description' => 'Configure collection for fulcrm.org.',
'access callback' => 'user_access',
'access arguments' => array('administer fulcrm collection'),
);
return $items;
}
function fulcrm_collection_get_d_value( $d, $key ) {
$key = explode( '.', $key );
foreach ( $key as $bit ) {
if ( array_key_exists( $bit, $d ) )
$d = $d[ $bit ];
else
return NULL;
}
return $d;
}
function _fulcrm_collection_set_d_value( &$d, $key, $value ) {
switch ( count( $key ) ) {
case 0:
return NULL;
case 1:
$d[ $key[ 0 ] ] = $value;
return $value;
default:
if ( !array_key_exists( $key[ 0 ], $d ) )
$d[ $key[ 0 ] ] = array();
return _fulcrm_collection_set_value( $d[ $key[ 0 ] ], array_slice( $key, 1 ), $value );
}
}
function fulcrm_collection_set_d_value( &$d, $key, $value ) {
return _fulcrm_collection_set_d_value( $d, explode( '.', $key ), $value );
}
function fulcrm_collection_form_values_to_d( $prefix, $values ) {
$d = array();
foreach ( $values as $k => $v ) {
$bits = explode( '/fulcrm/', $k );
if ( ( count( $bits ) === 2 ) && ( $bits[ 0 ] === $prefix ) ) {
if ( $bits[ 1 ] === 'fulcrm_collections' )
fulcrm_collection_set_d_value( $d, $bits[ 1 ], array( $v ) );
else
fulcrm_collection_set_d_value( $d, $bits[ 1 ], $v );
}
}
return $d;
}
function fulcrm_collection_to_form( $prefix, $collection_data, $d = array() ) {
$form = array();
foreach ( $collection_data[ '_structure' ] as $set_data ) {
switch ( $set_data[ 'type' ] ) {
case 'ddataset':
$fieldset = array( '#type' => 'fieldset',
'#title' => $set_data[ 'name' ],
'#description' => $set_data[ 'description' ],
);
foreach ( $set_data[ 'fields' ] as $field_data ) {
switch ( $field_data[ 'type' ] ) {
case 'text':
case 'email':
case 'tel':
$fieldset[ $prefix . '/fulcrm/' . $field_data[ 'key' ] ] = array( '#type' => 'textfield',
'#title' => $field_data[ 'name' ],
'#description' => $field_data[ 'description' ],
'#required' => $field_data[ 'required' ],
'#default_value' => fulcrm_collection_get_d_value( $d, $field_data[ 'key' ] ),
);
break;
case 'textarea':
$fieldset[ $prefix . '/fulcrm/' . $field_data[ 'key' ] ] = array( '#type' => 'textarea',
'#title' => $field_data[ 'name' ],
'#description' => $field_data[ 'description' ],
'#required' => $field_data[ 'required' ],
'#default_value' => fulcrm_collection_get_d_value( $d, $field_data[ 'key' ] ),
);
break;
default:
drupal_set_message( t('Cannot handle ":type" collection structure.', array( ':type' => $field_data[ 'type' ] )), 'error' );
break;
}
}
$form[] = $fieldset;
break;
default:
drupal_set_message( t('Cannot handle ":type" collection structure.', array( 'type' => $set_data[ 'type' ] )), 'error' );
break;
}
}
$form[ $prefix . '/fulcrm/fulcrm_collections' ] = array( '#type' => 'hidden',
'#default_value' => $collection_data[ 's' ],
);
return $form;
}