'Javascript chart settings form', 'page callback' => 'fusioncharts_form_ccksettings_js', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } /** * Menu callback for AHAH form(). */ function fusioncharts_form_ccksettings_js() { include_once(drupal_get_path('module', 'fusioncharts') .'/settings.inc'); $form = _fusioncharts_settings_subform($_POST['chart_type'], $node); $form = array_merge_recursive($form, _fusioncharts_cck_matrix_headings($_POST['chart_type'])); $output = ahah_render($form, "chart_settings"); $output .= ''; //reinitialise the colorpickers print drupal_to_js(array('data' => $output, 'status' => true)); exit(); } /** * Implmentation of hook_form_alter() */ function fusioncharts_cck_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'content_field_edit_form' && $form['#field']['type'] == 'fusioncharts_cck') { $form['field']['#type'] = 'hidden'; //hide the multiple values form. It does not work with this module! } } /** * Implementation of hook_field_info(). */ function fusioncharts_cck_field_info() { return array( 'fusioncharts_cck' => array( 'label' => t('FusionChart'), 'description' => t('Store chart in the database.'), ), ); } /** * Implementation of hook_field(). */ function fusioncharts_cck_field($op, &$node, $field, &$items, $teaser, $page) { switch ($op) { case 'load': $fc_cck_data = db_fetch_object(db_query("SELECT data FROM {fusionchart_cck_node_field} WHERE vid = %d and field_name = '%s'", $node->vid, $field['field_name'])); $chart_defaults = db_fetch_object(db_query("SELECT * FROM {fusioncharts_cck_fields} WHERE field_name = '%s'", $field['field_name'])); $values['chart_type'] = $chart_defaults->chart_type; $values['settings'] = unserialize($chart_defaults->settings); $values['attributes'] = unserialize($chart_defaults->attributes); $values['width'] = $chart_defaults->width; $values['height'] = $chart_defaults->height; $values['data'] = unserialize($fc_cck_data->data); $values['cols'] = $chart_defaults->cols; $additions = array($field['field_name'] => $values); return $additions; break; case 'insert': db_query("INSERT INTO {fusionchart_cck_node_field} (nid, vid, field_name, delta, data) VALUES (%d, %d, '%s', %d, '%s')", $node->nid, $node->vid, $field['field_name'], 0, serialize($items[0]['matrix'])); break; case 'update': db_query("UPDATE {fusionchart_cck_node_field} SET data = '%s' where vid = %d AND field_name = '%s' AND delta = %d", serialize($items[0]['matrix']), $node->vid, $field['field_name'], 0); break; case 'delete': db_query("DELETE FROM {fusionchart_cck_node_field} WHERE nid = %d", $node->nid); break; } } /** * Implementation of hook_content_is_empty(). */ function fusioncharts_cck_content_is_empty($item, $field) { return FALSE; if (empty($item['value']) && (string)$item['value'] !== '0') { return TRUE; } return FALSE; } /** * Implementation of hook_theme(). */ function fusioncharts_cck_theme() { return array( 'fusioncharts_cck_formatter_default' => array( 'arguments' => array('element' => NULL), ), 'fusioncharts_cck_formatter_table' => array( 'arguments' => array('element' => NULL), ), ); } /** * Implementation of hook_field_formatter_info(). */ function fusioncharts_cck_field_formatter_info() { return array( 'default' => array( 'label' => t('Chart'), 'field types' => array('fusioncharts_cck'), ), 'table' => array( 'label' => t('Data in table form'), 'field types' => array('fusioncharts_cck'), ), ); } /** * Theme function for 'default' field formatter. * * @param $element The whole node, containing extra information relating to this field * @return HTML to be outputed. */ function theme_fusioncharts_cck_formatter_default($element) { static $rendered; //since we are rendering the whole thing in one go, we don't want to rerender for each row if ($rendered[$element['#field_name']] != TRUE) { $rendered[$element['#field_name']] = TRUE; $field_info = $element['#node']->$element['#field_name']; //strip out the # symbols from the colors foreach ($field_info['settings'] as $key => $value) { if (substr($value, 0, 1) == '#' && strlen($value) == 7) { //remove the # from the color $field_info['settings'][$key] = substr($value, 1); } } foreach ($field_info['attributes'] as $key => $value) { if (substr($value, 0, 1) == '#' && strlen($value) == 7) { //remove the # from the color $field_info['attributes']['color'][] = substr($value, 1); unset ($field_info['attributes'][$key]); } } $chart->data = fusionchart_cck_data_process($field_info['chart_type'], $field_info['data'], $field_info['cols']); $chart->chart_type = $field_info['chart_type']; $chart->settings = $field_info['settings']; $chart->attributes = $field_info['attributes']; $chart->width = $field_info['width']; $chart->height = $field_info['height']; return theme('fusionchart', $chart); } } /** * Theme function for 'table' field formatter. * * @param $element The whole node, containing extra information relating to this field * @return HTML to be outputed. */ function theme_fusioncharts_cck_formatter_table($element) { static $rendered; //since we are rendering the whole thing in one go, we don't want to rerender for each row if ($rendered != 'rendered') { $rendered = 'rendered'; $field_info = $element['#node']->$element['#field_name']; $header = explode("\n", $field_info['cols']); array_unshift($header, t('Label')); return theme('table', $header, $field_info['data']); //this is currently only good for single series charts } } /** * Process the data into the correct form for fusioncharts core to handle */ function fusionchart_cck_data_process($chart_type, $raw_data, $cols) { $cols = explode("\n", $cols); switch ($chart_type) { case 'Column 3D': case 'Column 2D': case 'Line 2D': case 'Area 2D': case 'Bar 2D': case 'Pie 2D': case 'Pie 3D': case 'Doughnut 2D': case 'Funnel Chart': $data = $raw_data; break; case 'Multi-series Column 2D': case 'Multi-series Column 3D': case 'Multi-series Line 2D': case 'Multi-series Bar 2D': case 'Multi-series Area 2D': case 'Stacked Column 3D': case 'Stacked Column 2D': case 'Stacked Bar 2D': case 'Stacked Area 2D': $no_of_rows = count($raw_data); $no_of_cols = count($cols); for ($i=0; $i<$no_of_cols; $i++) { for ($j=0; $j<$no_of_rows; $j++) { if ($raw_data[$j][$i] != '') { $data[] = array($raw_data[$j][0], $cols[$i], $raw_data[$j][$i+1]); } } } break; case 'Multi-series Column 2D + Line - Dual Y Axis': case 'Multi-series Column 3D + Line - Dual Y Axis': $no_of_rows = count($raw_data); $no_of_cols = count($cols); for ($i=0; $i<$no_of_cols; $i++) { for ($j=0; $j<$no_of_rows; $j++) { if ($raw_data[$j][$i] != '') { list($axis, $heading) = explode("|", $cols[$i]); $data[] = array($heading, $raw_data[$j][0], strtoupper($axis), $raw_data[$j][$i+1]); } } } break; case 'Candlestick Chart': //not implemented yet break; case 'Gantt Chart': //not implemented yet break; } return $data; } /** * Implementation of hook_widget_info(). */ function fusioncharts_cck_widget_info() { return array( 'fusioncharts_cck' => array( 'label' => t('Chart'), 'field types' => array('fusioncharts_cck'), ), ); } /** * Implementation of hook_widget_settings(). */ function fusioncharts_cck_widget_settings($op, $widget) { include_once(drupal_get_path('module', 'fusioncharts') .'/settings.inc'); //load the css and javascript now becasue it won't get included with the ahah drupal_add_css('misc/farbtastic/farbtastic.css'); drupal_add_js('misc/farbtastic/farbtastic.js'); drupal_add_js(drupal_get_path('module', 'colorpicker'). '/js/colorpicker.js'); drupal_add_css(drupal_get_path('module', 'colorpicker'). '/css/colorpicker.css'); switch ($op) { case 'form': $field_name = arg(5); $default_values = db_fetch_object(db_query("SELECT * FROM {fusioncharts_cck_fields} WHERE field_name = '%s'", $field_name)); $chart_type = !empty($default_values->chart_type) ? $default_values->chart_type : 'Column 3D'; $form = array(); $form['width'] = array( '#type' => 'textfield', '#title' => t('Width'), '#default_value' => !empty($default_values->width) ? $default_values->width : 300, '#element_validate' => array('_fusioncharts_cck_widget_settings_width_validate'), '#required' => TRUE, ); $form['height'] = array( '#type' => 'textfield', '#title' => t('Height'), '#default_value' => !empty($default_values->height) ? $default_values->height : 300, '#element_validate' => array('_fusioncharts_cck_widget_settings_height_validate'), '#required' => TRUE, ); $form['rows'] = array( '#type' => 'textfield', '#title' => t('Number of rows'), '#default_value' => !empty($default_values->rows) ? $default_values->rows : 10, '#element_validate' => array('_fusioncharts_cck_widget_settings_rows_validate'), '#required' => TRUE, ); $chart_types = fusioncharts_settings('fusioncharts'); $form['chart_type'] = array( '#type' => 'select', '#title' => t('Chart type'), '#default_value' => $chart_type, '#options' => $chart_types, '#description' => t('The is the type of chart to build. The chart options and data required depend on the type of chart.'), '#required' => TRUE, '#ahah' => array( 'path' => 'fusioncharts/js/cckchartsettings', 'wrapper' => 'chart-settings', 'method' => 'replace', 'effect' => 'fade', ), ); $form['chart_settings_a'] = array( '#type' => 'markup', '#value' => '