| 357 |
} |
} |
| 358 |
|
|
| 359 |
switch ($op) { |
switch ($op) { |
|
case 'submit': |
|
|
break; |
|
|
case 'load': |
|
|
break; |
|
| 360 |
case 'form': |
case 'form': |
| 361 |
$form = array(); |
$form = array(); |
| 362 |
|
|
| 363 |
// Create our form and set #tree == true so the $item structure will be maintained |
// Create our form and set #tree == true so the $item structure will be maintained |
| 364 |
// for later usage in the process form values op. |
// for later usage in the process form values op. |
| 365 |
if ($field['multiple']) { |
$form[$fieldname] = array( |
| 366 |
$form[$fieldname] = array( |
//'#type' => 'fieldset', |
|
'#type' => 'fieldset', |
|
| 367 |
//'#title' => t($field['widget']['label']), |
//'#title' => t($field['widget']['label']), |
| 368 |
'#weight' => $field['widget']['weight'], |
//'#weight' => $field['widget']['weight'], |
| 369 |
'#collapsible' => TRUE, |
//'#collapsible' => TRUE, |
| 370 |
'#collapsed' => FALSE, |
//'#collapsed' => FALSE, |
|
'#description' => $field['widget']['description'], |
|
| 371 |
'#tree' => TRUE, |
'#tree' => TRUE, |
| 372 |
); |
); |
|
} |
|
|
else { |
|
|
$form[$fieldname] = array('#tree' => TRUE); |
|
|
} |
|
| 373 |
|
|
| 374 |
// Iterate through field values. |
// Iterate through field values. |
| 375 |
foreach($items as $delta => $item) { |
foreach($items as $delta => $item) { |
| 376 |
//$entity_type = $item['entity_type']; |
$entity_type = $item['entity_type']; |
| 377 |
$form[$fieldname][$delta] = _civinode_cck_widget_manual_item_form($data_type, $field, $delta, $item, $delta); |
$form[$fieldname][$delta] = _civinode_cck_widget_manual_item_form($data_type, $field, $item, $fieldname); |
| 378 |
} |
} |
| 379 |
if ($field['multiple']) { |
if ($field['multiple']) { |
| 380 |
//we want to start from 0, so that |
$form[$fieldname][$delta+1] = _civinode_cck_widget_manual_item_form($data_type, $field); |
| 381 |
//we know when to add a label |
$form[$fieldname][$delta+2] = _civinode_cck_widget_manual_item_form($data_type, $field); |
|
if (!isset($delta)) |
|
|
$delta = -1; |
|
|
$form[$fieldname][$delta+1] = _civinode_cck_widget_manual_item_form($data_type, $field, $delta+1); |
|
|
$form[$fieldname][$delta+2] = _civinode_cck_widget_manual_item_form($data_type, $field, $delta+2); |
|
| 382 |
} |
} |
| 383 |
elseif (count($items) == 0) { |
elseif (count($items) == 0) { |
| 384 |
$form[$fieldname][0] = _civinode_cck_widget_manual_item_form($data_type, $field, 0, $item); |
$form[$fieldname][0] = _civinode_cck_widget_manual_item_form($data_type, $field, $item); |
| 385 |
} |
} |
| 386 |
return $form; |
return $form; |
| 387 |
|
|
| 395 |
return; |
return; |
| 396 |
|
|
| 397 |
case 'process form values': |
case 'process form values': |
| 398 |
$fieldname = $field['field_name']; |
// Don't save empty values, beyond the first value. |
| 399 |
foreach ($items as $delta => $item) { |
foreach ($items as $delta => $item) { |
| 400 |
// $errstr = "widget:pfv($delta) \n"; |
if ($item['value'] == '' && $delta > 0) { |
| 401 |
// ob_start(); |
unset($items[$delta]); |
| 402 |
// print_r($item); |
continue; |
|
// $errstr .= ob_get_clean(); |
|
|
// error_log($errstr); |
|
|
//unpack dojo data |
|
|
if (!is_array($item)) { |
|
|
$items[$delta] = array(); |
|
|
$items[$delta]['entity_type'] = $field['type']; |
|
|
$items[$delta]['object_id'] = $item; |
|
| 403 |
} |
} |
| 404 |
else if (is_array($item) and isset($item['cbox']) and $item['cbox']['key']) { |
//unpack dojo data |
| 405 |
$object_id = $item['cbox']['key']; |
if ($item['object_id']) { |
| 406 |
$items[$delta]['object_id'] = $object_id; |
$object_id = $item['object_id']; |
| 407 |
$items[$delta]['entity_type'] = 'contact'; |
if ($item['entity_type'] == 'contact' and is_array($object_id)) { |
| 408 |
unset($items[$delta]['cbox']); |
$items[$delta]['object_id'] = $item['object_id']['cbox']['key']; |
| 409 |
|
//$items[$delta]['entity_type'] = $item[''] |
| 410 |
|
} |
| 411 |
} |
} |
|
else { //if ($delta > 0) { |
|
|
//chuck out empty items |
|
|
unset($items[$delta]); |
|
|
} |
|
| 412 |
} |
} |
| 413 |
break; |
break; |
| 414 |
|
|
| 426 |
'label' => t('Default'), |
'label' => t('Default'), |
| 427 |
'field types' => array('civicrm_contact', 'civicrm_group'), |
'field types' => array('civicrm_contact', 'civicrm_group'), |
| 428 |
), |
), |
|
'link' => array( |
|
|
'label' => t('Link'), |
|
|
'field types' => array('civicrm_contact'), |
|
|
), |
|
| 429 |
'profiled' => array( |
'profiled' => array( |
| 430 |
'label' => t('Contact Profile'), |
'label' => t('Contact Profile'), |
| 431 |
'field types' => array('civicrm_contact'), |
'field types' => array('civicrm_contact'), |
| 441 |
// switch formatter in case we implement multiple formatters. |
// switch formatter in case we implement multiple formatters. |
| 442 |
switch ($formatter) { |
switch ($formatter) { |
| 443 |
case 'profiled': |
case 'profiled': |
|
return theme('civinode_cck_profiled_contact', $item, $field); |
|
|
break; |
|
|
|
|
|
case 'link': |
|
| 444 |
if ($field['type'] == 'civicrm_contact') |
if ($field['type'] == 'civicrm_contact') |
| 445 |
return theme('civinode_cck_formatter_contact', $item, 'display_name', 'link'); |
return theme('civinode_cck_profiled_contact', $item); |
| 446 |
else if ($field['type'] == 'civicrm_group') |
break; |
|
return theme('civinode_cck_formatter_group', $item, NULL, 'link'); |
|
|
else |
|
|
return theme('civinode_cck_formatter_default', $item); |
|
|
|
|
|
|
|
|
default: |
|
| 447 |
case 'default': |
case 'default': |
| 448 |
if ($field['type'] == 'civicrm_contact') |
if ($field['type'] == 'civicrm_contact') |
| 449 |
return theme('civinode_cck_formatter_contact', $item); |
return theme('civinode_cck_formatter_contact', $item); |
| 462 |
function theme_civinode_cck_formatter_contact($item, $crm_field = 'display_name', $fmt = 'plain') { |
function theme_civinode_cck_formatter_contact($item, $crm_field = 'display_name', $fmt = 'plain') { |
| 463 |
$output = ''; |
$output = ''; |
| 464 |
$object_id = $item['object_id']; |
$object_id = $item['object_id']; |
|
if (!$object_id) |
|
|
return ''; |
|
| 465 |
$contact = array(); |
$contact = array(); |
| 466 |
_civinode_cck_cache_mgr('fetch', NULL, $object_id, $contact); |
_civinode_cck_cache_mgr('fetch', NULL, $object_id, $contact); |
| 467 |
if (civinode_check_error($contact)) |
if (civinode_check_error($contact)) |
| 469 |
$desc = $contact[$crm_field]; |
$desc = $contact[$crm_field]; |
| 470 |
switch ($fmt) { |
switch ($fmt) { |
| 471 |
case 'link': |
case 'link': |
|
$desc = l($desc, "civicrm/contact/view", array(), |
|
|
"reset=1&cid=$object_id", NULL, FALSE, TRUE); |
|
| 472 |
break; |
break; |
| 473 |
case 'plain': |
case 'plain': |
| 474 |
default: |
default: |
| 481 |
|
|
| 482 |
|
|
| 483 |
|
|
| 484 |
function theme_civinode_cck_profiled_contact($item, $field) { |
function theme_civinode_cck_profiled_contact($item) { |
| 485 |
$output = ''; |
$output = ''; |
| 486 |
$object_id = $item['object_id']; |
$object_id = $item['object_id']; |
| 487 |
if (!$object_id) { |
$default_profile = civinode_get_default_profile_id(0); |
| 488 |
return ""; //may want to make this themeable |
$output .= theme('crm_profile_cid', $profile, $object_id); |
|
} |
|
|
//TODO get correct profile from widget info |
|
|
if ($field['default_profile_id']) |
|
|
$default_profile = $field['default_profile_id']; |
|
|
else |
|
|
$default_profile = civinode_get_default_profile_id(0); |
|
|
|
|
|
$contact = civinode_util_load_cdata($object_id, $default_profile); |
|
|
if (civinode_check_error($contact)) |
|
|
return ""; //again, this may need theming |
|
|
|
|
|
$output .= theme('crm_contact', $contact, $field); |
|
|
return $output; |
|
|
} |
|
|
|
|
|
function theme_crm_contact($contact_array, $field) { |
|
|
//For now, we do a table |
|
|
$contact_id = $contact_array['contact_id']; |
|
|
$rows = array(); |
|
|
$header = array(); |
|
|
$pid = $field['default_profile_id'] ? |
|
|
$field['default_profile_id'] : |
|
|
civinode_get_default_profile_id(0); |
|
|
$classes = "crm-profile crm-profile-$pid"; |
|
|
//Get the fields and render them |
|
|
$field_list = civinode_get_profile_field_list($pid, 'view'); |
|
|
$output = "<div class='$classes'>\n"; |
|
|
foreach ($field_list as $node_field => $field) { |
|
|
$field_desc = civinode_get_field_info($pid, $field, 'view'); |
|
|
if (!isset($contact_array[$node_field]) or empty($contact_array[$node_field])) |
|
|
continue; |
|
|
$f_title = $field_desc['title']; |
|
|
if (!$f_title) |
|
|
$f_title = $node_field; |
|
|
$rows[] = |
|
|
array( |
|
|
array('data' => $f_title, 'header' => 1, |
|
|
'class' => 'civinode-profile-header'), |
|
|
array('data' => $contact_array[$node_field]) |
|
|
); |
|
|
} |
|
|
$output .= theme('table', $header, $rows); |
|
|
$output .= "</div>"; |
|
|
|
|
| 489 |
return $output; |
return $output; |
| 490 |
} |
} |
| 491 |
|
|
| 547 |
} |
} |
| 548 |
|
|
| 549 |
/** |
/** |
| 550 |
* Helper function to generate forms for each $item. |
* Helper function to generate forms for each $item. |
|
* This code assumes that the $form will in the larger form api structure |
|
|
* as $hl_form['field_id'][$delta] = $form; at the level of ['field_id'] we |
|
|
* either have the desc and title (as a field set) or just the #tree item. |
|
| 551 |
*/ |
*/ |
| 552 |
function _civinode_cck_widget_manual_item_form($type, $field, $delta = 0, $item = array()) { |
function _civinode_cck_widget_manual_item_form($type, $field, $item = array()) { |
|
$form = array(); //ultimate return value |
|
|
$form_chunk = array(); //ll fields |
|
|
$raw_fieldname = $field['field_name']; |
|
|
$fieldname = $raw_fieldname . "_$delta"; |
|
|
$is_multiple = $field['multiple']; |
|
|
$widget_type = $field['widget']['type']; |
|
|
$group_id = $field['default_group_id']; |
|
|
if (!$group_id) |
|
|
$group_id = 0; |
|
|
$object_id = $item['object_id']; |
|
|
if (!$is_multiple) { |
|
|
//We need to add the label? May be better to add higher up |
|
|
$label = $field['widget']['label']; |
|
|
$label = $label ? $label : $fieldname; |
|
|
$desc = $field['widget']['description']; |
|
|
$form['#title'] = $label; |
|
|
if ($desc) { |
|
|
$form['#description'] = $desc; |
|
|
} |
|
|
} |
|
|
else { |
|
|
//we only want a label on the first item |
|
|
if ($delta == 0) |
|
|
$label = $field['widget']['label']; |
|
|
else |
|
|
$label = NULL; |
|
|
$desc = NULL; |
|
|
} |
|
|
|
|
|
if ($type == 'contact') { |
|
|
//have a contact? |
|
|
if ($object_id) { |
|
|
$contact = array(); |
|
|
_civinode_cck_cache_mgr('fetch', NULL, $object_id, $contact); |
|
|
$object_id = $contact['contact_id']; |
|
|
} |
|
|
if ($widget_type == 'civinode_cck_contact_select') { |
|
|
$options = civinode_group_contact_popup(TRUE, $group_id); |
|
|
$form_chunk = |
|
|
array('#type' => 'select', |
|
|
'#options' => $options, |
|
|
'#default_value' => $object_id ? $object_id : 0, |
|
|
'#weight' => $field['widget']['weight'], |
|
|
); |
|
|
} |
|
|
else if ($widget_type == 'civinode_cck_contact') { |
|
|
$sortname = ''; |
|
|
$key = NULL; |
|
|
if ($object_id) { |
|
|
$key = $object_id; |
|
|
$sortname = $contact['sort_name']; |
|
|
} |
|
|
$form_chunk = |
|
|
civinode_contact_autoselect_widget($fieldname, $label, |
|
|
$key, $sortname, |
|
|
$group_id, |
|
|
$desc); |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else if ($type == 'group') { |
|
|
if ($item['object_id']) |
|
|
$group_id = $item['object_id']; |
|
|
$form_chunk = |
|
|
civinode_group_selector($label, $field['widget']['description'], |
|
|
$group_id); |
|
|
|
|
|
} |
|
|
|
|
|
$form = array_merge($form, $form_chunk); |
|
|
return $form; |
|
|
} |
|
|
|
|
|
function _civinode_cck_widget_manual_item_form_old($type, $field, $delta = 0, $item = array()) { |
|
| 553 |
|
|
| 554 |
|
/* $form['object_id'] = array( |
| 555 |
|
'#type' => 'textfield', |
| 556 |
|
'#title' => t('Contact ID'), |
| 557 |
|
'#size' => 10, |
| 558 |
|
'#maxlength' => 12, |
| 559 |
|
'#default_value' => $item['object_id'], |
| 560 |
|
);*/ |
| 561 |
$fieldname = $field['widget']['field_name']; |
$fieldname = $field['widget']['field_name']; |
|
if ($delta) |
|
|
$fieldname .= "_$delta"; |
|
| 562 |
$widget_type = $field['widget']['type']; |
$widget_type = $field['widget']['type']; |
| 563 |
$label = $field['widget']['label']; |
$label = $field['widget']['label']; |
| 564 |
$label = $label ? $label : $fieldname; |
$label = $label ? $label : $fieldname; |