Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
data_source_graph_edit_fns.inc
1 <?php
17 require_once SQ_CORE_PACKAGE_PATH.'/files/image/image_edit_fns.inc';
18 
31 {
32 
37  public $graph_types = Array(
38  'Image_Graph_Plot_Bar',
39  'Image_Graph_Plot_Line',
40  'Image_Graph_Plot_Area',
41  'Image_Graph_Plot_Smoothed_Line',
42  'Image_Graph_Plot_Smoothed_Area',
43  'Image_Graph_Plot_Pie',
44  'Image_Graph_Plot_Step',
45  'Image_Graph_Plot_Impulse',
46  'Image_Graph_Plot_Dot',
47  'Image_Graph_Plot_Radar',
48  'Image_Graph_Plot_CandleStick',
49  'Image_Graph_Plot_Band',
50  );
51 
56  public $fill_grad_types = Array(
57  'none' => '-- Leave Empty --',
58  'IMAGE_GRAPH_GRAD_VERTICAL' => 'Vertically',
59  'IMAGE_GRAPH_GRAD_HORIZONTAL' => 'Horizontally',
60  'IMAGE_GRAPH_GRAD_VERTICAL_MIRRORED' => 'Mirrored Vertically (the color grades from a-b-a vertically)',
61  'IMAGE_GRAPH_GRAD_HORIZONTAL_MIRRORED' => 'Mirrored Horizontally (the color grades from a-b-a horizontally)',
62  'IMAGE_GRAPH_GRAD_DIAGONALLY_TL_BR' => 'Diagonally from top-left to right-bottom',
63  'IMAGE_GRAPH_GRAD_DIAGONALLY_BL_TR' => 'Diagonally from bottom-left to top-right',
64  'IMAGE_GRAPH_GRAD_RADIAL' => 'Radially (concentric circles in the center)',
65  );
66 
67 
72  public $marker_types = Array(
73  'none' => '-- Leave Empty --',
74  'Image_Graph_Marker_Asterisk' => 'Mark Asterisk For A Dataset',
75  'Image_Graph_Marker_Average' => 'Mark Average For A Dataset',
76  'Image_Graph_Marker_Box' => 'Mark Box For A Dataset',
77  'Image_Graph_Marker_Cross' => 'Mark Cross For A Dataset',
78  'Image_Graph_Marker_Diamond' => 'Mark Diamond For A Dataset',
79  'Image_Graph_Marker_Plus' => 'Mark Plus For A Dataset',
80  'Image_Graph_Marker_Star' => 'Mark Star For A Dataset',
81  'Image_Graph_Marker_Triangle' => 'Mark Triangle For A Dataset',
82  'Image_Graph_Marker_Value' => 'Mark Value For A Dataset',
83  'Image_Graph_Marker_Bubble' => 'Mark Bubble For A Dataset',
84  );
85 
90  public $value_marker_types = Array(
91  'IMAGE_GRAPH_VALUE_X' => 'Mark x-Axis Values',
92  'IMAGE_GRAPH_VALUE_Y' => 'Mark y-Axis Values',
93  );
94 
99  public $pointing_types = Array(
100  'none' => '-- Leave Empty --',
101  'Image_Graph_Marker_Pointing_Angular' => 'Image_Graph_Marker_Pointing_Angular',
102  'Image_Graph_Marker_Pointing_Radial' => 'Image_Graph_Marker_Pointing_Radial',
103  'Image_Graph_Marker_ReversePinpoint' => 'Image_Graph_Marker_ReversePinpoint',
104  );
105 
106 
111  function __construct()
112  {
113  parent::__construct();
114 
115  }//end constructor
116 
117 
118 //-- DATASETS SCREEN --//
119 
120 
131  function paintAddPlots(&$asset, &$o, $prefix)
132  {
133  $wa = $asset->writeAccess('attributes');
134  if ($wa) {
135  $o->openField('Name');
136  text_box($prefix.'_new_name', '', '20', '20');
137  $o->closeField();
138  $o->openField('Data Source');
139  asset_finder($prefix.'_new_data_source', 0, Array('data_source_db' => 'I', 'data_source_rss' => 'I'));
140  $o->closeField();
141  }
142 
143  $datasets = $asset->attr('datasets');
144  $plot_order = $asset->attr('plot_order');
145  if (!empty($datasets)) {
146  $o->openField('Current Plots');
147  echo '<table class="sq-backend-table">';
148  echo '<tr>
149  <td>Plot Name</td>
150  <td>Data Source</td>';
151  if ($wa) echo '<td>Delete?</td>';
152  echo '</tr>';
153  foreach ($plot_order as $key => $plot_name) {
154  ?>
155  <tr>
156  <td><?php echo $plot_name; ?></td>
157  <td><?php echo get_asset_tag_line($datasets[$plot_name]['assetid']); ?></td>
158  <?php
159  if ($wa) {
160  echo '<td>';
161  check_box($prefix.'_delete_plot_'.$plot_name, $plot_name);
162  echo '</td>';
163  }
164  ?>
165  </tr>
166  <?php
167  }
168  echo '</table>';
169  $o->closeField();
170  } else {
171  $o->openField('Current Plots');
172  echo 'There is no plot.';
173  $o->closeField();
174  }
175  return TRUE;
176 
177  }//end paintAddPlots()
178 
179 
190  function processAddPlots(&$asset, &$o, $prefix)
191  {
192  $datasets = $asset->attr('datasets');
193  $plot_order = $asset->attr('plot_order');
194 
195  if (!empty($_POST[$prefix.'_new_name']) && $_POST[$prefix.'_new_data_source']['assetid'] != '0') {
196  $datasets = $asset->attr('datasets');
197  $dataset_assetid = $_POST[$prefix.'_new_data_source']['assetid'];
198 
199  // get the first result, extract the field names from that
200  // otherwise, fall back on 'Not saved'
201  $axis_default_val = 'Not saved';
202  $data_source_asset =& $GLOBALS['SQ_SYSTEM']->am->getAsset($dataset_assetid);
203  if (!is_null($data_source_asset)) {
204  $first_result = reset($data_source_asset->getResultSet('default'));
205  if (is_array($first_result)) {
206  $data = array_keys($first_result);
207  // default to the first field available to us
208  $axis_default_val = reset($data);
209  }
210  }
211 
212  $datasets[$_POST[$prefix.'_new_name']] = Array(
213  'assetid' => $dataset_assetid,
214  'settings' => Array(
215  'plot_name' => $_POST[$prefix.'_new_name'],
216  'display_name' => $_POST[$prefix.'_new_name'],
217  'graph_type' => 'Image_Graph_Plot_Bar',
218  'x_axis' => $axis_default_val,
219  'y_axis' => $axis_default_val,
220  'accumulative' => 0,
221  'fill_colour' => 'ffffff',
222  'gradient_type' => 'none',
223  'gradient_1' => '000000',
224  'gradient_2' => '000000',
225  'line_colour' => '000000',
226  'marker_font_colour' => 'ffffff',
227  'marker_line_colour' => '000000',
228  'marker_fill_colour' => '000000',
229  'bar_spacing' => 0,
230  'use_stacked' => FALSE,
231  'marker_type' => 'none',
232  'value_marker_type' => 'IMAGE_GRAPH_VALUE_X',
233  'pointer_type' => 'none',
234  'pointer_length' => 20,
235  ),
236  );
237  // add plot_order entry
238  $index = count($plot_order);
239  $plot_order[$index] = $_POST[$prefix.'_new_name'];
240 
241  // plot has been added. Modify $_POST value here to bring the
242  // moved plot's settings in the next screen
243  $_POST[$prefix.'_plot_name'] = $index;
244  $_POST[$prefix.'_prev_plot_name'] = $index;
245  }//end if
246 
247  if (!empty($datasets)) {
248  foreach ($datasets as $key => $dataset) {
249  if (isset($_POST[$prefix.'_delete_plot_'.str_replace(' ', '_', $key)]) && !empty($_POST[$prefix.'_delete_plot_'.str_replace(' ', '_', $key)])) {
250  unset($datasets[$key]);
251  unset($plot_order[array_search($key, $plot_order)]);
252 
253  // re-order plot_order array
254  if (!empty($datasets)) {
255  $keys = array_keys($plot_order);
256  ksort($keys, SORT_NUMERIC);
257 
258  $index = 0;
259  $new_plot_order = Array();
260  foreach ($keys as $key) {
261  $new_plot_order[$index] = $plot_order[$key];
262  $index++;
263  }
264  $plot_order = $new_plot_order;
265  }
266 
267  }
268  }
269  }
270  $asset->setAttrValue('datasets', $datasets);
271  $asset->setAttrValue('plot_order', $plot_order);
272  return TRUE;
273 
274  }//end processAddPlots()
275 
276 
287  function paintChoosePlots(&$asset, &$o, $prefix)
288  {
289  $plot_order = $asset->attr('plot_order');
290  $o->openField('Choose a plot');
291 
292  $plot_name = isset($_POST[$prefix.'_plot_name']) ? $_POST[$prefix.'_plot_name'] : '0';
293 
294  combo_box($prefix.'_plot_name', $plot_order, FALSE, $plot_name);
295  ?>
296  <br /><b>Note</b>&nbsp;:&nbsp;If you choose a plot other than one displayed below and submit, then the current changes in the plot settings <b>WILL NOT</b> be applied,
297  i.e. If you want to submit the changes in the plot settings, <b>DO NOT</b> choose a new plot here
298  <?php
299  hidden_field($prefix.'_prev_plot_name', $plot_name);
300  $o->closeField();
301  return TRUE;
302 
303  }//end paintChoosePlots()
304 
305 
316  function processChoosePlots(&$asset, &$o, $prefix)
317  {
318  return TRUE;
319 
320  }//end processChoosePlots()
321 
322 
333  function paintGeneralPlotSettings(&$asset, &$o, $prefix)
334  {
335  $wa = $asset->writeAccess('attributes');
336  $datasets = $asset->attr('datasets');
337  $plot_order = $asset->attr('plot_order');
338 
339  if (isset($_POST[$prefix.'_plot_name'])) {
340  $plot_not_deleted = !empty($datasets[$plot_order[intval($_POST[$prefix.'_plot_name'])]]);
341  if ($plot_not_deleted) {
342  $plot_name = $plot_order[intval($_POST[$prefix.'_plot_name'])];
343  } else {
344  $plot_name = $plot_order[0];
345  }
346  } else {
347  $plot_name = $plot_order[0];
348  }
349 
350  $data_source_asset =& $GLOBALS['SQ_SYSTEM']->am->getAsset($datasets[$plot_name]['assetid']);
351  $result = $data_source_asset->getResultSet('default');
352  $data = array_keys($result[0]);
353  foreach ($data as $field) {
354  $fields[$field] = $field;
355  }
356 
357  $o->openField('Plot Name');
358  echo '<b>'.$plot_name.'</b>';
359  $o->closeField();
360 
361  if ($wa) {
362  $o->openField('Display Name');
363  if (empty($datasets[$plot_name]['settings']['display_name']) || $datasets[$plot_name]['settings']['display_name'] == $plot_name) {
364  $display_name = $plot_name;
365  } else {
366  $display_name = $datasets[$plot_name]['settings']['display_name'];
367  }
368  text_box($prefix.'_display_name', $display_name);
369  $o->closeField();
370  if ($this->moreThanOnePlot($asset, $prefix)) {
371  $o->openField('Move the plot');
372  combo_box($prefix.'_move_this_plot', Array(0 => '-- Leave Empty --', 1 => 'Backward', 2 => 'Forward'), FALSE, 0);
373  ?>
374  <br /><b>Note</b>&nbsp;:&nbsp;You can move this plot <b>backward</b> or <b>forward</b> as shown in the final graph
375  <?php
376  $o->closeField();
377  }
378  $o->openField('Data Source');
379  asset_finder($prefix.'_data_source', !empty($datasets[$plot_name]['assetid']) ? $datasets[$plot_name]['assetid'] : '0', Array('data_source_db' => 'I', 'data_source_rss' => 'I'));
380  $o->closeField();
381  $o->openField(translate('choose').' x-Axis');
382  combo_box($prefix.'_x_axis', $fields, FALSE, empty($datasets[$plot_name]['settings']['x_axis']) ? current($fields) : $datasets[$plot_name]['settings']['x_axis']);
383  $o->closeField();
384  $o->openField(translate('choose').' y-Axis');
385  combo_box($prefix.'_y_axis', $fields, FALSE, empty($datasets[$plot_name]['settings']['y_axis']) ? current($fields) : $datasets[$plot_name]['settings']['y_axis']);
386  $o->closeField();
387  $o->openField(translate('choose').' '.translate('graph_type'));
388  combo_box($prefix.'_graph_type', $this->graph_types, FALSE, array_search($datasets[$plot_name]['settings']['graph_type'], $this->graph_types));
389  $o->closeField();
390  $o->openField('Accumulative?');
391  combo_box($prefix.'_accumulative', Array(1 => 'Yes', 0 => 'No'), FALSE, $datasets[$plot_name]['settings']['accumulative']);
392  ?>
393  <br /><b>Note</b>&nbsp;:&nbsp;If it's yes, y-Axis values are accumulated
394  <?php
395  hidden_field($prefix.'_plot_settings_submit', '1');
396  $o->closeField();
397 
398  $o->openField('Fill Colour');
399  colour_box($prefix.'_fill_colour', empty($datasets[$plot_name]['settings']['fill_colour']) ? 'ffffff' : $datasets[$plot_name]['settings']['fill_colour']);
400  $o->closeField();
401  $o->openField('Line Colour');
402  colour_box($prefix.'_line_colour', empty($datasets[$plot_name]['settings']['line_colour']) ? '000000' : $datasets[$plot_name]['settings']['line_colour']);
403  $o->closeField();
404  $o->openField('Fill Gradient Type');
405  combo_box($prefix.'_gradient_type', $this->fill_grad_types, FALSE, $datasets[$plot_name]['settings']['gradient_type']);
406  ?>
407  <br /><b>Note</b>&nbsp;:&nbsp;If the type is set other than 'Leave Empty', a fill colour is ignored
408  <?php
409  $o->closeField();
410  $o->openField('Gradient Colour 1');
411  colour_box($prefix.'_gradient_1', empty($datasets[$plot_name]['settings']['gradient_1']) ? '000000' : $datasets[$plot_name]['settings']['gradient_1']);
412  $o->closeField();
413  $o->openField('Gradient Colour 2');
414  colour_box($prefix.'_gradient_2', empty($datasets[$plot_name]['settings']['gradient_2']) ? '000000' : $datasets[$plot_name]['settings']['gradient_2']);
415  $o->closeField();
416 
417  } else {
418 
419  $o->openField('Display Name');
420  echo $datasets[$plot_name]['settings']['display_name'];
421  $o->closeField();
422  $o->openField('Data Source');
423  echo get_asset_tag_line($datasets[$plot_name]['assetid']);
424  $o->closeField();
425  $o->openField('x-Axis');
426  echo $datasets[$plot_name]['settings']['x_axis'];
427  $o->closeField();
428  $o->openField('y-Axis');
429  echo $datasets[$plot_name]['settings']['y_axis'];
430  $o->closeField();
431  $o->openField('Type of Graph');
432  echo $datasets[$plot_name]['settings']['graph_type'];
433  $o->closeField();
434  $o->openField('Accumulative');
435  echo (intval($datasets[$plot_name]['settings']['accumulative'])) ? 'Yes' : 'No';
436  ?>
437  <br /><b>Note</b>&nbsp;:&nbsp;If it's yes, y-Axis values are accumulated
438  <?php
439  $o->closeField();
440  $o->openField('Fill Colour');
441  if (empty($datasets[$plot_name]['settings']['fill_colour'])) {
442  echo 'none';
443  } else {
444  echo '<table><tr>
445  <td width="20" height="13" style="background-color: #'.$datasets[$plot_name]['settings']['fill_colour'].'"></td>
446  <td>&nbsp;#'.$datasets[$plot_name]['settings']['fill_colour'].'</td>
447  </tr></table>';
448  }
449  $o->closeField();
450  $o->openField('Line Colour');
451  if (empty($datasets[$plot_name]['settings']['line_colour'])) {
452  echo 'none';
453  } else {
454  echo '<table><tr>
455  <td width="20" height="13" style="background-color: #'.$datasets[$plot_name]['settings']['line_colour'].'"></td>
456  <td>&nbsp;#'.$datasets[$plot_name]['settings']['line_colour'].'</td>
457  </tr></table>';
458  }
459  $o->closeField();
460  $o->openField('Fill Gradient Type');
461  echo $datasets[$plot_name]['settings']['gradient_type'];
462  ?>
463  <br /><b>Note</b>&nbsp;:&nbsp;If the type is set other than 'Leave Empty', a fill colour is ignored
464  <?php
465  $o->closeField();
466  $o->openField('Gradient Colour 1');
467  if (empty($datasets[$plot_name]['settings']['gradient_1'])) {
468  echo 'none';
469  } else {
470  echo '<table><tr>
471  <td width="20" height="13" style="background-color: #'.$datasets[$plot_name]['settings']['gradient_1'].'"></td>
472  <td>&nbsp;#'.$datasets[$plot_name]['settings']['gradient_1'].'</td>
473  </tr></table>';
474  }
475  $o->closeField();
476  $o->openField('Gradient Colour 2');
477  if (empty($datasets[$plot_name]['settings']['gradient_2'])) {
478  echo 'none';
479  } else {
480  echo '<table><tr>
481  <td width="20" height="13" style="background-color: #'.$datasets[$plot_name]['settings']['gradient_2'].'"></td>
482  <td>&nbsp;#'.$datasets[$plot_name]['settings']['gradient_2'].'</td>
483  </tr></table>';
484  }
485  $o->closeField();
486  }//end else
487 
488  return TRUE;
489 
490  }//end paintGeneralPlotSettings()
491 
492 
503  function processGeneralPlotSettings(&$asset, &$o, $prefix)
504  {
505  $plot_settings_submit = isset($_POST[$prefix.'_plot_settings_submit']);
506  $wa = $asset->writeAccess('attributes');
507  if ($wa && $plot_settings_submit) {
508  $datasets = $asset->attr('datasets');
509  $plot_order = $asset->attr('plot_order');
510 
511  $plot_not_deleted = isset($datasets[$plot_order[intval($_POST[$prefix.'_plot_name'])]]);
512  $plot_changed = ($_POST[$prefix.'_plot_name'] !== $_POST[$prefix.'_prev_plot_name']);
513 
514  if (!$plot_changed && $plot_not_deleted) {
515  $plot_name = $plot_order[intval($_POST[$prefix.'_plot_name'])];
516  $datasets[$plot_name]['assetid'] = $_POST[$prefix.'_data_source']['assetid'];
517  $datasets[$plot_name]['settings']['display_name'] = $_POST[$prefix.'_display_name'];
518  $datasets[$plot_name]['settings']['x_axis'] = $_POST[$prefix.'_x_axis'];
519  $datasets[$plot_name]['settings']['y_axis'] = $_POST[$prefix.'_y_axis'];
520  $datasets[$plot_name]['settings']['graph_type'] = $this->graph_types[intval($_POST[$prefix.'_graph_type'])];
521  $datasets[$plot_name]['settings']['accumulative'] = $_POST[$prefix.'_accumulative'];
522  $datasets[$plot_name]['settings']['fill_colour'] = $_POST[$prefix.'_fill_colour'];
523  $datasets[$plot_name]['settings']['line_colour'] = $_POST[$prefix.'_line_colour'];
524  $datasets[$plot_name]['settings']['gradient_type'] = $_POST[$prefix.'_gradient_type'];
525  $datasets[$plot_name]['settings']['gradient_1'] = $_POST[$prefix.'_gradient_1'];
526  $datasets[$plot_name]['settings']['gradient_2'] = $_POST[$prefix.'_gradient_2'];
527  if (isset($_POST[$prefix.'_bar_spacing'])) {
528  $datasets[$plot_name]['settings']['bar_spacing'] = $_POST[$prefix.'_bar_spacing'];
529  }
530  $asset->setAttrValue('datasets', $datasets);
531 
532  // Re-order plots
533  if (isset($_POST[$prefix.'_move_this_plot']) && $_POST[$prefix.'_move_this_plot'] != '0') {
534 
535  $current_index = array_search($plot_name, $plot_order);
536 
537  $swap = FALSE;
538  switch ($_POST[$prefix.'_move_this_plot']) {
539  case '1':
540  // move backward
541  if ($current_index > 0) {
542  $dest_index = $current_index - 1;
543  $swap = TRUE;
544  }
545  break;
546  case '2':
547  // move forward
548  if ($current_index < (count($plot_order) - 1)) {
549  $dest_index = $current_index + 1;
550  $swap = TRUE;
551  }
552  break;
553  }
554  if ($swap) {
555  $dest_value = $plot_order[$dest_index];
556  $current_value = $plot_order[$current_index];
557  $plot_order[$dest_index] = $current_value;
558  $plot_order[$current_index] = $dest_value;
559  $asset->setAttrValue('plot_order', $plot_order);
560 
561  // plot has been moved. Modify $_POST value here to bring the
562  // moved plot's settings in the next screen
563  $_POST[$prefix.'_plot_name'] = $dest_index;
564  $_POST[$prefix.'_prev_plot_name'] = $dest_index;
565  }
566  }//end if
567  } else {
568  return FALSE;
569  }
570  }//end if
571 
572  return TRUE;
573 
574  }//end processGeneralPlotSettings()
575 
576 
587  function paintPlotSpecificSettings(&$asset, &$o, $prefix)
588  {
589  $wa = $asset->writeAccess('attributes');
590  $datasets = $asset->attr('datasets');
591  $plot_order = $asset->attr('plot_order');
592  if (isset($_POST[$prefix.'_plot_name'])) {
593  $plot_not_deleted = !empty($datasets[$plot_order[intval($_POST[$prefix.'_plot_name'])]]);
594  if ($plot_not_deleted) {
595  $plot_name = $plot_order[intval($_POST[$prefix.'_plot_name'])];
596  } else {
597  $plot_name = $plot_order[0];
598  }
599  } else {
600  $plot_name = $plot_order[0];
601  }
602 
603  $data_source_asset =& $GLOBALS['SQ_SYSTEM']->am->getAsset($datasets[$plot_name]['assetid']);
604  $result = $data_source_asset->getResultSet('default');
605  $data = array_keys($result[0]);
606  foreach ($data as $field) {
607  $fields[$field] = $field;
608  }
609 
610  $plot_type = $datasets[$plot_name]['settings']['graph_type'];
611  if ($wa) {
612  switch ($plot_type) {
613  case 'Image_Graph_Plot_Bar' :
614  case 'Image_Graph_Plot_Area' :
615  $o->openField('Spacing');
616  text_box($prefix.'_bar_spacing', empty($datasets[$plot_name]['settings']['bar_spacing']) ? '0' : $datasets[$plot_name]['settings']['bar_spacing'], '10');
617  $o->closeField();
618  $o->openField('Stacked');
619  check_box($prefix.'_use_stacked', '1', isset($datasets[$plot_name]['settings']['use_stacked']) ? $datasets[$plot_name]['settings']['use_stacked'] : FALSE);
620  $o->note('Do you want to use stacked bar graph?');
621  ?>
622  <table class="sq-backend-table">
623  <tr>
624  <td>Title and Data Source</td>
625  <td>Gradient Details</td>
626  <?php if ($wa) echo '<td>Delete?</td>'; ?>
627  </tr>
628 
629  <?php
630  $key = 0;
631  if (!empty($datasets[$plot_name]['settings']['stacked_data'])) {
632  foreach ($datasets[$plot_name]['settings']['stacked_data'] as $key => $stack_data) {
633  ?>
634  <tr>
635  <td>
636  Title : <?php text_box($prefix.'_stacked_'.strval($key).'_title', $stack_data['title'], 50); ?><br />
637  <?php
638  asset_finder($prefix.'_stacked_'.strval($key).'_datasource', $stack_data['datasource'], Array('data_source_db' => 'I', 'data_source_rss' => 'I'));
639  echo '<br />';
640  if (!empty($stack_data['datasource'])) {
641  $data_source_asset =& $GLOBALS['SQ_SYSTEM']->am->getAsset($stack_data['datasource']);
642  $result = $data_source_asset->getResultSet('default');
643  $data = array_keys($result[0]);
644  foreach ($data as $field) {
645  $fields[$field] = $field;
646  }
647  }
648  echo 'x-axis&nbsp;:&nbsp;';
649  combo_box($prefix.'_stacked_'.strval($key).'_x_axis', $fields, FALSE, $stack_data['x_axis']);
650  echo '<br />y-axis&nbsp;:&nbsp;';
651  combo_box($prefix.'_stacked_'.strval($key).'_y_axis', $fields, FALSE, $stack_data['y_axis']);
652  ?>
653  </td>
654  <td>
655  <?php combo_box($prefix.'_stacked_'.strval($key).'_gradient_type', $this->fill_grad_types, FALSE, $stack_data['gradient_type']); ?><br />
656  <?php colour_box($prefix.'_stacked_'.strval($key).'_gradient_colour_2', $stack_data['colour_1']); ?>Gradient Colour 1<br />
657  <?php colour_box($prefix.'_stacked_'.strval($key).'_gradient_colour_1', $stack_data['colour_2']); ?>Gradient Colour 2<br />
658  </td>
659  <td>
660  <?php
661  if ($wa) {
662  check_box($prefix.'_stacked_'.strval($key).'_delete', '1', FALSE);
663  }
664  ?>
665  </td>
666  </tr>
667  <?php
668  }//end foreach
669 
670  $key++;
671  }//end if
672  ?>
673  <tr>
674  <td>
675  Title : <?php text_box($prefix.'_stacked_'.strval($key).'_title', '', 50); ?><br />
676  <?php asset_finder($prefix.'_stacked_'.strval($key).'_datasource', 0, Array('data_source_db' => 'I', 'data_source_rss' => 'I')); ?>
677  </td>
678  <td>
679  <?php combo_box($prefix.'_stacked_'.strval($key).'_gradient_type', $this->fill_grad_types, FALSE, 'none'); ?><br />
680  <?php colour_box($prefix.'_stacked_'.strval($key).'_gradient_colour_1', '000000'); ?>Gradient Colour 1<br />
681  <?php colour_box($prefix.'_stacked_'.strval($key).'_gradient_colour_2', '000000'); ?>Gradient Colour 2<br />
682  </td>
683  <td></td>
684  </tr>
685  </table>
686  <?php
687  $o->note('Note: If the gradient option is not chosen, the first colour is used to fill the bar.');
688  $o->closeField();
689  break;
690  case 'Image_Graph_Plot_Line' :
691  case 'Image_Graph_Plot_Smoothed_Area' :
692  case 'Image_Graph_Plot_Smoothed_Line' :
693  case 'Image_Graph_Plot_Pie' :
694  case 'Image_Graph_Plot_Step' :
695  case 'Image_Graph_Plot_Impulse' :
696  case 'Image_Graph_Plot_Dot' :
697  case 'Image_Graph_Plot_Radar' :
698  case 'Image_Graph_Plot_CandleStick' :
699  case 'Image_Graph_Plot_Band' :
700  break;
701  default :
702  break;
703 
704  }//end switch
705 
706  } else {
707  switch ($plot_type) {
708  case 'Image_Graph_Plot_Bar' :
709  $o->openField('Spacing');
710  echo $datasets[$plot_name]['settings']['bar_spacing'];
711  $o->closeField();
712  $o->openField('Stacked');
713  $o->closeField();
714  break;
715  case 'Image_Graph_Plot_Line' :
716  case 'Image_Graph_Plot_Area' :
717  case 'Image_Graph_Plot_Smoothed_Line' :
718  case 'Image_Graph_Plot_Smoothed_Area' :
719  case 'Image_Graph_Plot_Pie' :
720  case 'Image_Graph_Plot_Step' :
721  case 'Image_Graph_Plot_Impulse' :
722  case 'Image_Graph_Plot_Dot' :
723  case 'Image_Graph_Plot_Radar' :
724  case 'Image_Graph_Plot_CandleStick' :
725  case 'Image_Graph_Plot_Band' :
726  $o->openField('None');
727  $o->closeField();
728  break;
729  default :
730  break;
731  }
732  }
733  return TRUE;
734 
735  }//end paintPlotSpecificSettings()
736 
737 
748  function processPlotSpecificSettings(&$asset, &$o, $prefix)
749  {
750  $plot_settings_submit = isset($_POST[$prefix.'_plot_settings_submit']);
751  $wa = $asset->writeAccess('attributes');
752  if ($wa && $plot_settings_submit) {
753  $datasets = $asset->attr('datasets');
754  $plot_order = $asset->attr('plot_order');
755 
756  $plot_not_deleted = isset($datasets[$plot_order[intval($_POST[$prefix.'_plot_name'])]]);
757  $plot_changed = ($_POST[$prefix.'_plot_name'] != $_POST[$prefix.'_prev_plot_name']);
758 
759  if (!$plot_changed && $plot_not_deleted) {
760  $plot_name = $plot_order[intval($_POST[$prefix.'_plot_name'])];
761  $plot_type = $datasets[$plot_name]['settings']['graph_type'];
762  switch ($plot_type) {
763  case 'Image_Graph_Plot_Bar' :
764  case 'Image_Graph_Plot_Area' :
765  if (isset($_POST[$prefix.'_bar_spacing'])) {
766  $datasets[$plot_name]['settings']['bar_spacing'] = $_POST[$prefix.'_bar_spacing'];
767  }
768  $datasets[$plot_name]['settings']['use_stacked'] = isset($_POST[$prefix.'_use_stacked']);
769  $key = 0;
770  if (!empty($datasets[$plot_name]['settings']['stacked_data'])) {
771  // Delete?
772  foreach ($datasets[$plot_name]['settings']['stacked_data'] as $key => $stack_data) {
773  if (isset($_POST[$prefix.'_stacked_'.strval($key).'_delete'])) {
774  unset($datasets[$plot_name]['settings']['stacked_data'][$key]);
775  unset($_POST[$prefix.'_stacked_'.strval($key).'_datasource']);
776  }
777  }
778  if (!empty($datasets[$plot_name]['settings']['stacked_data'])) {
779  foreach ($datasets[$plot_name]['settings']['stacked_data'] as $key => $stack_data) {
780  if (isset($_POST[$prefix.'_stacked_'.strval($key).'_title'])) {
781  $datasets[$plot_name]['settings']['stacked_data'][$key]['title'] = $_POST[$prefix.'_stacked_'.strval($key).'_title'];
782  $datasets[$plot_name]['settings']['stacked_data'][$key]['datasource'] = $_POST[$prefix.'_stacked_'.strval($key).'_datasource']['assetid'];
783  $datasets[$plot_name]['settings']['stacked_data'][$key]['colour_1'] = $_POST[$prefix.'_stacked_'.strval($key).'_gradient_colour_1'];
784  $datasets[$plot_name]['settings']['stacked_data'][$key]['colour_2'] = $_POST[$prefix.'_stacked_'.strval($key).'_gradient_colour_2'];
785  $datasets[$plot_name]['settings']['stacked_data'][$key]['gradient_type'] = $_POST[$prefix.'_stacked_'.strval($key).'_gradient_type'];
786  $datasets[$plot_name]['settings']['stacked_data'][$key]['x_axis'] = $_POST[$prefix.'_stacked_'.strval($key).'_x_axis'];
787  $datasets[$plot_name]['settings']['stacked_data'][$key]['y_axis'] = $_POST[$prefix.'_stacked_'.strval($key).'_y_axis'];
788  }
789 
790  }
791  $key++;
792  }
793  }
794  // check a new one
795  if (!empty($_POST[$prefix.'_stacked_'.strval($key).'_datasource']) && $_POST[$prefix.'_stacked_'.strval($key).'_datasource']['assetid'] != '0') {
796  $datasets[$plot_name]['settings']['stacked_data'][$key]['title'] = $_POST[$prefix.'_stacked_'.strval($key).'_title'];
797  $datasets[$plot_name]['settings']['stacked_data'][$key]['datasource'] = $_POST[$prefix.'_stacked_'.strval($key).'_datasource']['assetid'];
798  $datasets[$plot_name]['settings']['stacked_data'][$key]['colour_1'] = $_POST[$prefix.'_stacked_'.strval($key).'_gradient_colour_1'];
799  $datasets[$plot_name]['settings']['stacked_data'][$key]['colour_2'] = $_POST[$prefix.'_stacked_'.strval($key).'_gradient_colour_2'];
800  $datasets[$plot_name]['settings']['stacked_data'][$key]['gradient_type'] = $_POST[$prefix.'_stacked_'.strval($key).'_gradient_type'];
801 
802  $data_source_asset =& $GLOBALS['SQ_SYSTEM']->am->getAsset($_POST[$prefix.'_stacked_'.strval($key).'_datasource']['assetid']);
803  $result = $data_source_asset->getResultSet('default');
804  $datasets[$plot_name]['settings']['stacked_data'][$key]['x_axis'] = array_pop(array_keys($result[0]));
805  $datasets[$plot_name]['settings']['stacked_data'][$key]['y_axis'] = $datasets[$plot_name]['settings']['stacked_data'][$key]['x_axis'];
806  }
807  break;
808  case 'Image_Graph_Plot_Line' :
809  case 'Image_Graph_Plot_Smoothed_Area' :
810  case 'Image_Graph_Plot_Smoothed_Line' :
811  case 'Image_Graph_Plot_Pie' :
812  case 'Image_Graph_Plot_Step' :
813  case 'Image_Graph_Plot_Impulse' :
814  case 'Image_Graph_Plot_Dot' :
815  case 'Image_Graph_Plot_Radar' :
816  case 'Image_Graph_Plot_CandleStick' :
817  case 'Image_Graph_Plot_Band' :
818  break;
819  default :
820  break;
821  }//end switch
822 
823  $asset->setAttrValue('datasets', $datasets);
824 
825  }//end if
826 
827  }//end if
828 
829  return TRUE;
830 
831  }//end processPlotSpecificSettings()
832 
833 
844  function paintMarkerSettings(&$asset, &$o, $prefix)
845  {
846  $wa = $asset->writeAccess('attributes');
847  $datasets = $asset->attr('datasets');
848  $plot_order = $asset->attr('plot_order');
849 
850  if (isset($_POST[$prefix.'_plot_name'])) {
851  $plot_not_deleted = !empty($datasets[$plot_order[intval($_POST[$prefix.'_plot_name'])]]);
852  if ($plot_not_deleted) {
853  $plot_name = $plot_order[intval($_POST[$prefix.'_plot_name'])];
854  } else {
855  asort($datasets);
856  $plot_name = array_pop(array_keys($datasets));
857  }
858  } else {
859  asort($datasets);
860  $plot_name = array_pop(array_keys($datasets));
861  }
862 
863 
864  $data_source_asset =& $GLOBALS['SQ_SYSTEM']->am->getAsset($datasets[$plot_name]['assetid']);
865  $result = $data_source_asset->getResultSet('default');
866  $data = array_keys($result[0]);
867  foreach ($data as $field) {
868  $fields[$field] = $field;
869  }
870 
871  $colours = Array(
872  'Set Font Colour' => 'marker_font_colour',
873  'Set Line Colour' => 'marker_line_colour',
874  'Set Fill Colour' => 'marker_fill_colour',
875  );
876  if ($wa) {
877  $o->openField('Choose The Type Of Marker');
878  combo_box($prefix.'_marker_type', $this->marker_types, FALSE, empty($datasets[$plot_name]['settings']['marker_type']) ? 'none' : $datasets[$plot_name]['settings']['marker_type']);
879  ?>
880  <br /><b>Note</b>&nbsp;:&nbsp;If you don't want to use marker, leave this empty
881  <?php
882  $o->closeField();
883  $o->openField('Choose Value To be Marked On The Graph');
884  combo_box($prefix.'_value_marker_type', $this->value_marker_types, FALSE, empty($datasets[$plot_name]['settings']['value_marker_type']) ? 'none' : $datasets[$plot_name]['settings']['value_marker_type']);
885  $o->closeField();
886  foreach ($colours as $field_title => $key) {
887  $o->openField($field_title);
888  colour_box($prefix.'_'.$key, empty($datasets[$plot_name]['settings'][$key]) ? '000000' : $datasets[$plot_name]['settings'][$key]);
889  $o->closeField();
890  }
891  $o->openField('Choose The Marker Pointer');
892  combo_box($prefix.'_pointer_type', $this->pointing_types, FALSE, empty($datasets[$plot_name]['settings']['pointer_type']) ? 'none' : $datasets[$plot_name]['settings']['pointer_type']);
893  ?>
894  <br /><b>Note</b>&nbsp;:&nbsp;If you don't want to use pointer, leave this empty
895  <?php
896  $o->closeField();
897  $o->openField('Set The Length Of The Pointer');
898  text_box($prefix.'_pointer_length', empty($datasets[$plot_name]['settings']['pointer_length']) ? '20' : $datasets[$plot_name]['settings']['pointer_length'], 5);
899  $o->closeField();
900  } else {
901  $o->openField('Choose The Type Of Marker');
902  echo $datasets[$plot_name]['settings']['marker_type'];
903  $o->closeField();
904  $o->openField('Choose Value To be Marked On The Graph');
905  echo $datasets[$plot_name]['settings']['value_marker_type'];
906  $o->closeField();
907  foreach ($colours as $field_title => $key) {
908  $o->openField($field_title);
909  if (empty($datasets[$plot_name]['settings'][$key])) {
910  echo 'none';
911  } else {
912  echo '<table><tr>
913  <td width="20" height="13" style="background-color: #'.$datasets[$plot_name]['settings'][$key].'"></td>
914  <td>&nbsp;#'.$datasets[$plot_name]['settings'][$key].'</td>
915  </tr></table>';
916  }
917  $o->closeField();
918  }
919  $o->openField('Choose The Marker Pointer');
920  echo $datasets[$plot_name]['settings']['pointer_type'];
921  $o->closeField();
922  $o->openField('Set The Length Of The Pointer');
923  echo $datasets[$plot_name]['settings']['pointer_length'];
924  $o->closeField();
925 
926  }
927 
928  }//end paintMarkerSettings()
929 
930 
941  function processMarkerSettings(&$asset, &$o, $prefix)
942  {
943  $wa = $asset->writeAccess('attributes');
944  $plot_settings_submit = isset($_POST[$prefix.'_plot_settings_submit']);
945  if ($wa && $plot_settings_submit) {
946  $datasets = $asset->attr('datasets');
947  $plot_order = $asset->attr('plot_order');
948  $plot_not_deleted = @isset($datasets[$plot_order[intval($_POST[$prefix.'_plot_name'])]]);
949  $plot_changed = ($_POST[$prefix.'_plot_name'] != $_POST[$prefix.'_prev_plot_name']);
950  if (!$plot_changed && $plot_not_deleted) {
951  $plot_name = $plot_order[intval($_POST[$prefix.'_plot_name'])];
952  $datasets[$plot_name]['settings']['marker_type'] = $_POST[$prefix.'_marker_type'];
953  $datasets[$plot_name]['settings']['value_marker_type'] = $_POST[$prefix.'_value_marker_type'];
954  $datasets[$plot_name]['settings']['marker_font_colour'] = $_POST[$prefix.'_marker_font_colour'];
955  $datasets[$plot_name]['settings']['marker_line_colour'] = $_POST[$prefix.'_marker_line_colour'];
956  $datasets[$plot_name]['settings']['marker_fill_colour'] = $_POST[$prefix.'_marker_fill_colour'];
957  $datasets[$plot_name]['settings']['pointer_type'] = $_POST[$prefix.'_pointer_type'];
958  $datasets[$plot_name]['settings']['pointer_length'] = $_POST[$prefix.'_pointer_length'];
959  $asset->setAttrValue('datasets', $datasets);
960  }
961  }
962 
963  return $wa;
964 
965  }//end processMarkerSettings()
966 
967 
968 //-- PREVIEWS --//
969 
970 
981  function paintGlobalSettingPreview(&$asset, &$o, $prefix)
982  {
983  $href = $asset->getBackendHref('global_settings');
984  $width = $asset->attr('width');
985  $height = $asset->attr('height');
986  $alt = $asset->attr('alt');
987  $title = $asset->attr('title');
988  ?>
989  <b>Note</b><br />
990  <ul>
991  <li>
992  This graph is generated with <b>random dataset</b> to present the look and feel of the graph
993  </li>
994  <li>
995  The front end image <b>WILL NOT</b> be updated until a dataset is added.<br />i.e. the changes on this screen is not shown in the front end unless a dataset is set.
996  </li>
997  </ul>
998  <img alt="<?php echo $alt; ?>" title="<?php echo $title; ?>" src="<?php echo $href.'&preview_graph=1' ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" alt="" />
999  <?php
1000 
1001  return TRUE;
1002 
1003  }//end paintGlobalSettingPreview()
1004 
1005 
1016  function processGlobalSettingPreview(&$asset, &$o, $prefix)
1017  {
1018  return TRUE;
1019 
1020  }//end processGlobalSettingPreview()
1021 
1022 
1033  function paintSinglePreview(&$asset, &$o, $prefix)
1034  {
1035  $datasets = $asset->attr('datasets');
1036  $plot_order = $asset->attr('plot_order');
1037  $plot_not_deleted = @isset($datasets[$plot_order[intval($_POST[$prefix.'_plot_name'])]]);
1038  if (!empty($_POST[$prefix.'_plot_name']) && $plot_not_deleted) {
1039  $plot_name = $plot_order[intval($_POST[$prefix.'_plot_name'])];
1040  } else {
1041  $plot_name = $plot_order[0];
1042  }
1043  if ($datasets[$plot_name]['settings']['x_axis'] == 'Not saved' || $datasets[$plot_name]['settings']['y_axis'] == 'Not saved') {
1044  ?>
1045  <b>Not available</b>&nbsp;:&nbsp;Please set both of x-Axis and y-Axis correctly<br />
1046  <?php
1047  } else {
1048  $graph_info = serialize($datasets[$plot_name]);
1049  $href = $asset->getBackendHref('datasets');
1050  $alt = $asset->attr('alt');
1051  $title = $asset->attr('title');
1052  ?>
1053  <b>Note</b>&nbsp;:&nbsp;This graph is generated with <b>random dataset</b> to present the look and feel of the graph<br /><br />
1054  <img alt="<?php echo $alt; ?>" title="<?php echo $title; ?>" src="<?php echo $href.'&preview_graph=1&graph_info='.urlencode($graph_info) ?>" width="<?php echo $asset->attr('width'); ?>" height="<?php echo $asset->attr('height'); ?>" />
1055  <?php
1056  }
1057  return FALSE;
1058 
1059  }//end paintSinglePreview()
1060 
1061 
1072  function processSinglePreview(&$asset, &$o, $prefix)
1073  {
1074  return FALSE;
1075 
1076  }//end processSinglePreview()
1077 
1078 
1089  function paintFinalPreview(&$asset, &$o, $prefix)
1090  {
1091  $datasets = $asset->attr('datasets');
1092  $preview = TRUE;
1093  $not_set = Array();
1094  foreach ($datasets as $name => $dataset) {
1095  if ($dataset['settings']['x_axis'] == 'Not saved' || $dataset['settings']['y_axis'] == 'Not saved') {
1096  $preview = FALSE;
1097  $not_set[] = $name;
1098  }
1099  }
1100 
1101  if (!$preview) {
1102  ?>
1103  <b>Not available</b>&nbsp;:&nbsp;Please set both of x-Axis and y-Axis correctly for <?php echo implode(',', $not_set); ?><br />
1104  <?php
1105  } else {
1106  $href = $asset->getBackendHref('datasets');
1107  $alt = $asset->attr('alt');
1108  $title = $asset->attr('title');
1109  ?>
1110  <b>Note</b>&nbsp;:&nbsp;This graph is the same as one that is printed on the frontend with <b>real datasets</b>.<br /><br />
1111  <img alt="<?php echo $alt; ?>" title="<?php echo $title; ?>" src="<?php echo $href.'&preview_graph=1&final_preview=1' ?>" width="<?php echo $asset->attr('width'); ?>" height="<?php echo $asset->attr('height'); ?>" alt="" />
1112  <?php
1113  }
1114 
1115  return FALSE;
1116 
1117  }//end paintFinalPreview()
1118 
1119 
1130  function processFinalPreview(&$asset, &$o, $prefix)
1131  {
1132  return FALSE;
1133 
1134  }//end processFinalPreview()
1135 
1136 
1137 //-- SHOW IFS --//
1138 
1139 
1149  function isAddMode(&$asset, $prefix)
1150  {
1151  return $this->_isMode($asset, $prefix, 'add');
1152 
1153  }//end isAddMode()
1154 
1155 
1165  function isEditMode(&$asset, $prefix)
1166  {
1167  return $this->_isMode($asset, $prefix, 'edit') &&
1168  $this->datasetNotEmpty($asset, $prefix);
1169 
1170  }//end isEditMode()
1171 
1172 
1183  function _isMode(&$asset, $prefix, $type)
1184  {
1185  $mode = $asset->attr('mode');
1186  return ($mode == $type);
1187 
1188  }//end _isMode()
1189 
1190 
1200  function datasetNotEmpty(&$asset, $prefix)
1201  {
1202  $datasets = $asset->attr('datasets');
1203  return !empty($datasets);
1204 
1205  }//end datasetNotEmpty()
1206 
1207 
1217  function moreThanOnePlot(&$asset, $prefix)
1218  {
1219  return count($asset->attr('datasets')) > 1;
1220 
1221  }//end moreThanOnePlot()
1222 
1223 
1224 }//end class
1225 
1226 ?>