/**
  * helper function to make the examples
  * simpler.
  */
 function set_labels_from_array($a)
 {
     $x_axis_labels = new OFC_Elements_Axis_X_Label_Set();
     $x_axis_labels->set_labels($a);
     $this->labels = $x_axis_labels;
     if (isset($this->steps)) {
         $x_axis_labels->set_steps($this->steps);
     }
 }
 public function toObject()
 {
     $this->consolidateParameters();
     $xAxisLabels = new OFC_Elements_Axis_X_Label_Set();
     $xAxisLabels->set_labels($this->labels);
     $xAxisLabels->set_size(10);
     $xAxisLabels->set_colour('#444444');
     $xAxisLabels->set_steps($this->stepsX);
     $xAxis = new OFC_Elements_Axis_X();
     $xAxis->set_steps($this->stepsX);
     $xAxis->set_labels($xAxisLabels);
     $xAxis->set_colour('#CCCCCC');
     $xAxis->set_grid_colour('#AAAAAA');
     $this->chart->set_x_axis($xAxis);
     $yAxis = new OFC_Elements_Axis_Y();
     $yAxis->set_range($this->min1, $this->max1);
     $yAxis->set_colour('#AAAAAA');
     $yAxis->set_grid_colour('#AAAAAA');
     $yAxis->set_steps($this->stepsY1);
     $this->chart->set_y_axis($yAxis);
     $yLegend = new OFC_Elements_Legend_Y($this->data1->getName());
     //$this->chart->set_y_legend($yLegend); // does not work now
     // data 1
     $this->chart->add_element($this->createGraph($this->data1));
     if ($this->hasTwoDataLines()) {
         $yAxisRight = new OFC_Elements_Axis_Y_Right();
         $yAxisRight->set_range($this->min2, $this->max2);
         $yAxisRight->set_colour('#AAAAAA');
         $yAxisRight->set_steps($this->stepsY2);
         //            $this->chart->set_y_axis_right($yAxisRight);
         $this->chart->add_element($this->createGraph($this->data2));
     }
     return $this->chart;
 }
 public function chartDataAction()
 {
     // Disable layout and viewrenderer
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     // Get params
     $type = $this->_getParam('type');
     $start = $this->_getParam('start');
     $offset = $this->_getParam('offset', 0);
     $mode = $this->_getParam('mode');
     $chunk = $this->_getParam('chunk');
     $period = $this->_getParam('period');
     $periodCount = $this->_getParam('periodCount', 1);
     //$end = $this->_getParam('end');
     // Validate chunk/period
     if (!$chunk || !in_array($chunk, $this->_periods)) {
         $chunk = Zend_Date::DAY;
     }
     if (!$period || !in_array($period, $this->_periods)) {
         $period = Zend_Date::MONTH;
     }
     if (array_search($chunk, $this->_periods) >= array_search($period, $this->_periods)) {
         die('whoops');
         return;
     }
     // Validate start
     if ($start && !is_numeric($start)) {
         $start = strtotime($start);
     }
     if (!$start) {
         $start = time();
     }
     // Fixes issues with month view
     Zend_Date::setOptions(array('extend_month' => true));
     // Get timezone
     $timezone = Engine_Api::_()->getApi('settings', 'core')->getSetting('core_locale_timezone', 'GMT');
     $viewer = Engine_Api::_()->user()->getViewer();
     if ($viewer && $viewer->getIdentity() && !empty($viewer->timezone)) {
         $timezone = $viewer->timezone;
     }
     // Make start fit to period?
     $startObject = new Zend_Date($start);
     $startObject->setTimezone($timezone);
     $partMaps = $this->_periodMap[$period];
     foreach ($partMaps as $partType => $partValue) {
         $startObject->set($partValue, $partType);
     }
     // Do offset
     if ($offset != 0) {
         $startObject->add($offset, $period);
     }
     // Get end time
     $endObject = new Zend_Date($startObject->getTimestamp());
     $endObject->setTimezone($timezone);
     $endObject->add($periodCount, $period);
     $endObject->sub(1, Zend_Date::SECOND);
     // Subtract one second
     // Get data
     $statsTable = Engine_Api::_()->getDbtable('statistics', 'core');
     $statsSelect = $statsTable->select()->where('type = ?', $type)->where('date >= ?', gmdate('Y-m-d H:i:s', $startObject->getTimestamp()))->where('date < ?', gmdate('Y-m-d H:i:s', $endObject->getTimestamp()))->order('date ASC');
     $rawData = $statsTable->fetchAll($statsSelect);
     // Now create data structure
     $currentObject = clone $startObject;
     $nextObject = clone $startObject;
     $data = array();
     $dataLabels = array();
     $cumulative = 0;
     $previous = 0;
     do {
         $nextObject->add(1, $chunk);
         $currentObjectTimestamp = $currentObject->getTimestamp();
         $nextObjectTimestamp = $nextObject->getTimestamp();
         $data[$currentObjectTimestamp] = $cumulative;
         // Get everything that matches
         $currentPeriodCount = 0;
         foreach ($rawData as $rawDatum) {
             $rawDatumDate = strtotime($rawDatum->date);
             if ($rawDatumDate >= $currentObjectTimestamp && $rawDatumDate < $nextObjectTimestamp) {
                 $currentPeriodCount += $rawDatum->value;
             }
         }
         // Now do stuff with it
         switch ($mode) {
             default:
             case 'normal':
                 $data[$currentObjectTimestamp] = $currentPeriodCount;
                 break;
             case 'cumulative':
                 $cumulative += $currentPeriodCount;
                 $data[$currentObjectTimestamp] = $cumulative;
                 break;
             case 'delta':
                 $data[$currentObjectTimestamp] = $currentPeriodCount - $previous;
                 $previous = $currentPeriodCount;
                 break;
         }
         $currentObject->add(1, $chunk);
     } while ($currentObject->getTimestamp() < $endObject->getTimestamp());
     // Reprocess label
     $labelStrings = array();
     $labelDate = new Zend_Date();
     foreach ($data as $key => $value) {
         $labelDate->set($key);
         $labelStrings[] = $this->view->locale()->toDate($labelDate, array('size' => 'short'));
         //date('D M d Y', $key);
     }
     // Let's expand them by 1.1 just for some nice spacing
     $minVal = min($data);
     $maxVal = max($data);
     $minVal = floor($minVal * ($minVal < 0 ? 1.1 : 1 / 1.1) / 10) * 10;
     $maxVal = ceil($maxVal * ($maxVal > 0 ? 1.1 : 1 / 1.1) / 10) * 10;
     // Remove some labels if there are too many
     $xlabelsteps = 1;
     if (count($data) > 10) {
         $xlabelsteps = ceil(count($data) / 10);
     }
     // Remove some grid lines if there are too many
     $xsteps = 1;
     if (count($data) > 100) {
         $xsteps = ceil(count($data) / 100);
     }
     // Create base chart
     require_once 'OFC/OFC_Chart.php';
     // Make x axis labels
     $x_axis_labels = new OFC_Elements_Axis_X_Label_Set();
     $x_axis_labels->set_steps($xlabelsteps);
     $x_axis_labels->set_labels($labelStrings);
     // Make x axis
     $labels = new OFC_Elements_Axis_X();
     $labels->set_labels($x_axis_labels);
     $labels->set_colour("#416b86");
     $labels->set_grid_colour("#dddddd");
     $labels->set_steps($xsteps);
     // Make y axis
     $yaxis = new OFC_Elements_Axis_Y();
     $yaxis->set_range($minVal, $maxVal);
     $yaxis->set_colour("#416b86");
     $yaxis->set_grid_colour("#dddddd");
     // Make data
     $graph = new OFC_Charts_Line();
     $graph->set_values(array_values($data));
     $graph->set_colour("#5ba1cd");
     // Make title
     $locale = Zend_Registry::get('Locale');
     $translate = Zend_Registry::get('Zend_Translate');
     $titleStr = $translate->_('_CORE_ADMIN_STATS_' . strtoupper(trim(preg_replace('/[^a-zA-Z0-9]+/', '_', $type), '_')));
     $title = new OFC_Elements_Title($titleStr . ': ' . $this->view->locale()->toDateTime($startObject) . ' to ' . $this->view->locale()->toDateTime($endObject));
     $title->set_style("{font-size: 14px;font-weight: bold;margin-bottom: 10px; color: #777777;}");
     // Make full chart
     $chart = new OFC_Chart();
     $chart->set_bg_colour('#ffffff');
     $chart->set_x_axis($labels);
     $chart->add_y_axis($yaxis);
     $chart->add_element($graph);
     $chart->set_title($title);
     // Send
     $this->getResponse()->setBody($chart->toPrettyString());
 }
Exemple #4
0
for ($i = 0; $i < 6.2; $i += 0.2) {
    $tmp = sin($i) * 1.9;
    $data[] = $tmp;
}
require_once 'OFC/OFC_Chart.php';
$chart = new OFC_Chart();
$chart->set_title(new OFC_Elements_Title('Area Chart'));
//
// Make our area chart:
//
$area = new OFC_Charts_Area_Hollow();
// set the circle line width:
$area->set_width(1);
$area->set_values($data);
// add the area object to the chart:
$chart->add_element($area);
$y_axis = new OFC_Elements_Axis_Y();
$y_axis->set_range(-2, 2, 2);
$y_axis->labels = null;
$y_axis->set_offset(false);
$x_axis = new OFC_Elements_Axis_X();
$x_axis->labels = $data;
$x_axis->set_steps(2);
$x_labels = new OFC_Elements_Axis_X_Label_Set();
$x_labels->set_steps(4);
$x_labels->set_vertical();
// Add the X Axis Labels to the X Axis
$x_axis->set_labels($x_labels);
$chart->add_y_axis($y_axis);
$chart->x_axis = $x_axis;
echo $chart->toPrettyString();
Exemple #5
0
    public function deploy()
    {
        $this->checkExportRights();
        if ($this->_filesLocation === null) {
            throw new Bvb_Grid_Exception($this->__("Please set Javascript and Flash file locations using SetFilesLocation()"));
        }
        $grid = array();
        $newData = array();
        $label = array();
        $result = array();
        parent::deploy();
        $data = parent::_buildGrid();
        if (count($data) == 0) {
            $this->_deploymentContent = '';
            return;
        }
        foreach ($data as $value) {
            foreach ($value as $final) {
                $result[$final['field']][] = is_numeric($final['value']) ? $final['value'] : strip_tags($final['value']);
            }
        }
        if (is_string($this->_xLabels) && isset($result[$this->_xLabels])) {
            $this->_xLabels = $result[$this->_xLabels];
        }
        $graph = new OFC_Chart();
        $title = new OFC_Elements_Title($this->_title);
        $title->set_style($this->_style);
        $graph->set_title($title);
        foreach ($this->_chartOptions as $key => $value) {
            $graph->{$key}($value);
        }
        if (count($this->_xLabels) > 0) {
            $x = new OFC_Elements_Axis_X();
            $x_axis_labels = new OFC_Elements_Axis_X_Label_Set();
            foreach ($this->_xAxisOptions as $key => $value) {
                $x_axis_labels->{$key}($value);
            }
            $x_axis_labels->set_labels($this->_xLabels);
            $x->set_labels($x_axis_labels);
            foreach ($this->_xLabelsOptions as $key => $value) {
                $x->{$key}($value);
            }
            $graph->set_x_axis($x);
        }
        if (!empty($this->_xLegendText) && !empty($this->_xLegendStyle)) {
            $x_legend = new OFC_Elements_Legend_X($this->_xLegendText);
            $x_legend->set_style($this->_xLegendStyle);
            $graph->set_x_legend($x_legend);
        }
        $min = 0;
        $max = 0;
        if (count($this->_values) == 0) {
            $this->setValues(key($result));
        }
        foreach ($this->_values as $key => $value) {
            if (is_array($value)) {
                $support = $value;
                sort($support);
                if (reset($support) < $min) {
                    $min = reset($support);
                }
                if (end($support) > $max) {
                    $max = end($support);
                }
                unset($support);
                $options = $this->_chartOptionsValues[$value];
                if (isset($options['chartType'])) {
                    $this->setChartType($options['chartType']);
                }
                $bar = new $this->_type();
                foreach ($options as $key => $prop) {
                    $bar->{$key}($prop);
                }
                $this->_type();
                $pie = array();
                if ($this->_type == 'Pie') {
                    foreach ($value as $key => $title) {
                        $pie[] = array('value' => $title, 'label' => $this->_xLabels[$key]);
                    }
                    $bar->set_values($pie);
                } else {
                    $bar->set_values($value);
                }
                $graph->add_element($bar);
            } elseif (is_string($value) && isset($result[$value])) {
                $options = $this->_chartOptionsValues[$value];
                if (isset($options['chartType'])) {
                    $this->setChartType($options['chartType']);
                }
                $bar = new $this->_type();
                foreach ($options as $key => $prop) {
                    $bar->{$key}($prop);
                }
                $value = array_map(create_function('$item', ' return (float)$item; '), $result[$value]);
                $support = $value;
                sort($support);
                if (reset($support) < $min) {
                    $min = reset($support);
                }
                if (end($support) > $max) {
                    $max = end($support);
                }
                unset($support);
                $pie = array();
                if ($this->_type == 'OFC_Charts_Pie') {
                    foreach ($value as $key => $title) {
                        $pie[] = array('value' => $title, 'label' => $this->_xLabels[$key]);
                    }
                    $bar->set_values($pie);
                } else {
                    $bar->set_values($value);
                }
                $graph->add_element($bar);
            }
        }
        $max = $max * 1.05;
        $y = new OFC_Elements_Axis_Y();
        $y->set_range($min, $max, ceil($max / 4));
        $graph->add_y_axis($y);
        $final = $graph->toPrettyString();
        if (!is_string($this->_chartId)) {
            $this->_chartId = 'chart_' . rand(1, 10000);
        }
        $script = '
        swfobject.embedSWF(
        "' . $this->_filesLocation['flash'] . '", "' . $this->_chartId . '",
        "' . $this->_chartDimensions['x'] . '", "' . $this->_chartDimensions['y'] . '", "9.0.0", "expressInstall.swf",{"id":"' . $this->_chartId . '"},{"z-index":"1","wmode":"transparent"} );

        function open_flash_chart_data(id)
        {
            return JSON.stringify(window[id]);
        }

        function findSWF(movieName) {
          if (navigator.appName.indexOf("Microsoft")!= -1) {
            return window[movieName];
          } else {
            return document[movieName];
          }
        }
        var ' . $this->_chartId . ' = ' . $final . ';';
        $final = '<div id="' . $this->_chartId . '" >
        loading...
        <br/>
        <p>
        Please note that this content requires flash player 9.0.0</br>
        To test for your version of flash, <a href="http://www.bobbyvandersluis.com/swfobject/testsuite_2_1/test_api_getflashplayerversion.html" target="_blank">click here</a>
        </p>
        </div>';
        if (!$this->_multiple) {
            $final = '<div style="width: 100%;text-align: center">' . $final . '</div>';
        }
        $this->getView()->headScript()->appendFile($this->_filesLocation['js']);
        $this->getView()->headScript()->appendFile($this->_filesLocation['json']);
        $this->getView()->headScript()->appendScript($script);
        $this->_deploymentContent = $final;
        return $this;
    }
Exemple #6
0
/**
 * $array['title']
 * $array['legend_y']
 * $array['legend_x']
 * $array['values']
 * $array['values_key']
 * $array['range_max']
 * $array['range_step']
 * @param $array
 * @return unknown_type
 */
function create_chart_data($array)
{
    if (!$array) {
        return;
    }
    require_once 'OFC/OFC_Chart.php';
    $chart = new OFC_Chart();
    $chart->set_bg_colour('#ffffff');
    $title = new OFC_Elements_Title($array['title']);
    $title->set_style('{color: #567300; font-size: 16px; font-weight:bold;}');
    $chart->set_title($title);
    $yl = new OFC_Elements_Legend_Y($array['legend_y']);
    $yl->set_style('{font-size:18px;}');
    $chart->set_y_legend($yl);
    $xl = new OFC_Elements_Legend_X($array['legend_x']);
    $xl->set_style('{font-size:18px;color:#Ff0}');
    $chart->set_x_legend($xl);
    $elements = array();
    $colors = array('', '#CC00AA', '#9C48F0', '#b0de09', '#0d8ecf', '#ff6600', '#fcd202', '#E2EBFF', '#AAAAAA');
    foreach ($array['values'] as $k => $v) {
        ksort($v, SORT_STRING);
        $line = new OFC_Charts_Line();
        $line->set_key($array['values_key'][$k], 12);
        $colors[$k] ? $line->set_colour($colors[$k]) : '';
        $line->set_values(array_values($v));
        $default_dot = new OFC_Charts_Line_Dot();
        $default_dot->tooltip('#x_label#<br>#val#');
        $line->set_default_dot_style($default_dot);
        $elements[] = $line;
        $array['values'][$k] =& $v;
    }
    foreach ($elements as $element) {
        $chart->add_element($element);
    }
    $x = new OFC_Elements_Axis_X();
    $x->colour = '#909090';
    $x_axis_labels = new OFC_Elements_Axis_X_Label_Set();
    $x->set_steps($array['show_step']);
    $x_axis_labels->set_steps($array['show_step']);
    if (is_array($array['values'][0])) {
        $keys = array_keys($array['values'][0]);
    } else {
        $keys = array_keys($array['values']);
    }
    $x_axis_labels->set_labels($keys);
    $x_axis_labels->set_size(12);
    $x_axis_labels->set_colour('#Ff0');
    $x_axis_labels->set_rotate('-45');
    $x->set_labels($x_axis_labels);
    $chart->set_x_axis($x);
    $y = new OFC_Elements_Axis_Y();
    $range_min = isset($array['range_min']) ? $array['range_min'] : 0;
    $y->set_range($range_min, $array['range_max'], $array['range_step']);
    $chart->set_y_axis($y);
    return $chart->toPrettyString();
}
Exemple #7
0
    function pn_handle_options_page()
    {
        session_cache_limiter(FALSE);
        global $wpdb, $pn_plugin_url, $pn_plugin_dir;
        $action_url = $_SERVER['REQUEST_URI'];
        $unsent_mails = array();
        if (isset($_REQUEST['pnd'])) {
            $plimus_pn = $wpdb->prefix . "plimus_pn";
            $id = $_REQUEST['pnd'];
            $query_db = "DELETE FROM {$plimus_pn} WHERE pn_orn = {$id}";
            $delete = $wpdb->query($query_db);
        }
        $search_term = isset($_POST['search_item']) ? trim($_POST['search_item']) : '';
        $global_days = null;
        if (isset($_REQUEST['filter_all']) && !empty($_REQUEST['filter_all']) && !empty($search_term) && $search_term != 'Filter By Keyword') {
            $filter = isset($_SESSION['filter_by_type']) ? $_SESSION['filter_by_type'] : 'date';
            $global_days = isset($_REQUEST['filter_by_dates']) ? $_REQUEST['filter_by_dates'] : $_SESSION['filter_by_dates'];
            $terms = explode(" ", $search_term);
            $search_where = ' WHERE pn_meta_value LIKE ';
            foreach ($terms as $term) {
                $search_where .= "('%{$term}%') OR pn_meta_value LIKE ";
            }
            $search_where = substr_replace($search_where, '', -22);
            $search_data = $wpdb->get_results("SELECT pn.pn_orn FROM {$wpdb->prefix}plimus_pn as pn {$search_where}", OBJECT_K);
            if (!empty($search_data)) {
                $search_query = " WHERE pn.pn_orn IN ('" . implode("','", array_keys($search_data)) . "');";
            } else {
                $search_query = '';
            }
        } else {
            $filter = 'date';
            if (isset($_REQUEST['show']) && $_REQUEST['show'] == 'all') {
                $global_days = 0;
            }
            unset($_SESSION['filter_by_type']);
            unset($_SESSION['filter_by_dates']);
            $search_query = '';
        }
        if ($search_query != '') {
            $amount_data = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}plimus_pn as pn");
            $total_amount = array();
            if (!empty($amount_data)) {
                foreach ($amount_data as $key => $data) {
                    if ($data->pn_meta_key == 'invoiceAmountUSD' || $data->pn_meta_key == 'transactionDate') {
                        $total_amount[$data->pn_orn][$data->pn_meta_key] = $data->pn_meta_value;
                    }
                }
            }
            $this_month = 0;
            $last_month = 0;
            $total_sum = 0;
            foreach ($total_amount as $key => $data) {
                $total_sum += (double) $data['invoiceAmountUSD'];
                if (date('mY') == date('mY', strtotime($data['transactionDate']))) {
                    $this_month += (double) $data['invoiceAmountUSD'];
                }
                $lmonth = date('m') - 1;
                if (date('' . $lmonth . 'Y') == date('mY', strtotime($data['transactionDate']))) {
                    $last_month += (double) $data['invoiceAmountUSD'];
                }
            }
        }
        if (isset($_REQUEST['filter_all'])) {
            $filter = isset($_POST['filter_by_type']) ? $_POST['filter_by_type'] : $_SESSION['filter_by_type'];
            $_SESSION['filter_by_type'] = $filter;
        }
        $selected[$filter] = 'selected';
        if (isset($_REQUEST['filter_all']) && isset($_REQUEST['filter_by_dates']) && $_REQUEST['filter_by_dates'] != '0') {
            $global_days = isset($_REQUEST['filter_by_dates']) ? $_REQUEST['filter_by_dates'] : $_SESSION['filter_by_dates'];
            $_SESSION['filter_by_dates'] = $global_days;
        }
        $transaction_data = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}plimus_pn as pn {$search_query}"));
        $this_month = 0;
        $last_month = 0;
        $total_sum = 0;
        if (!empty($transaction_data)) {
            $default_footer = '</div>';
            $table_rows = array();
            $products = array();
            $products_date = array();
            $remove_row = array();
            $transactions = array();
            foreach ($transaction_data as $key => $data) {
                $transactions[$data->pn_orn][$data->pn_meta_key] = $data->pn_meta_value;
            }
            $firt_entry = 0;
            $j = 0;
            if (!empty($transactions)) {
                foreach ($transactions as $key => $data_array) {
                    $item = '';
                    $promotions_array = array();
                    $days_past = (int) (strtotime('today') / 86400 - strtotime($data_array['transactionDate']) / 86400);
                    $firt_entry = $days_past > $firt_entry ? $days_past : $firt_entry;
                    if (!empty($data_array)) {
                        //$key++;
                        $invoice_url = preg_match('/http\\:\\/\\//i', $data_array['invoiceInfoURL']) ? $data_array['invoiceInfoURL'] : 'http://' . $data_array['invoiceInfoURL'];
                        $company = $data_array['company'] != '' ? "<font style='font-weight: bold;' >Coustomer company: </font>{$data_array['company']} <br />" : '';
                        $address1 = $data_array['address1'] != '' ? "<font style='font-weight: bold;' >Coustomer address one: </font>{$data_array['address1']} {$data_array['zipCode']},{$data_array['city']}, {$data_array['state']}, {$data_array['country']} <br />" : '';
                        $address2 = $data_array['address2'] != '' ? "<font style='font-weight: bold;' >Coustomer address two: </font>{$data_array['address2']} <br />" : '';
                        $contact = $data_array['email'] != '' ? "<font style='font-weight: bold;' >Coustomer contact: </font> {$data_array['workPhone']} / {$data_array['extension']} " : '';
                        $mobile_phone = $data_array['mobilePhone'] != '' ? "<font style='font-weight: bold;' > mobile: </font> {$data_array['mobilePhone']}" : '';
                        $home_phone = $data_array['homePhone'] != '' ? "<font style='font-weight: bold;' > home: </font>{$data_array['homePhone']}" : '';
                        $fax = $data_array['faxNumber'] != '' ? "<font style='font-weight: bold;' > fax: </font>{$data_array['faxNumber']} <br />" : '';
                        $coustomer_cc = $data_array['creditCardType'] != '' ? "<font style='font-weight: bold;' > Credit card: </font>{$data_array['creditCardType']} <br />" : '';
                        $ship_to = $data_array['shippingFirstName'] != '' || $data_array['shippingLastName'] != '' ? " <font style='font-weight: bold;' >Shiping To: </font>{$data_array['shippingFirstName']} {$data_array['shippingLastName']} {$data_array['shippingZipCode']} {$data_array['shippingCity']} {$data_array['shippingState']} {$data_array['shippingCountry']}" : '';
                        $shippingMethod = $data_array['shippingMethod'] != '' ? " <font style='font-weight: bold;' > shiping method: </font> {$data_array['shippingMethod']}<br />" : '';
                        $invoiceChargeAmount = $data_array['invoiceChargeAmount'] != '' ? " <font style='font-weight: bold;' >Invoice Amount: </font> {$data_array['invoiceChargeAmount']} {$data_array['invoiceChargeCurrency']} (\$ {$data_array['invoiceAmountUSD']}) <a href='{$invoice_url}' target='_blank'>{$data_array['invoiceInfoURL']}</a><br />" : '';
                        $coupon = $data_array['coupon'] != '' ? "<font style='font-weight: bold;' >Used a coupon: </font> {$data_array['coupon']} " : '';
                        $couponCode = $data_array['couponCode'] != '' ? " <font style='font-weight: bold;' > code: </font>  {$data_array['couponCode']} " : '';
                        $couponValue = $data_array['couponValue'] != '' ? "  <font style='font-weight: bold;' >amount: </font>  {$data_array['couponValue']} {$data_array['invoiceChargeCurrency']} " : '';
                        $referrer = $data_array['referrer'] != '' ? " <font style='font-weight: bold;' > referer: </font>  {$data_array['referrer']} <br />" : '';
                        $table_coupon = $data_array['coupon'] != '' ? "{$data_array['coupon']} ({$data_array['couponCode']})" : '';
                        $coupon = (double) str_replace(',', '', $data_array['couponValue']);
                        $promotions_html = '';
                        $currency = $data_array['currency'];
                        $tr_date = str_replace(' ', '/', substr_replace((string) $data_array['transactionDate'], '', -9));
                        $charge = 0;
                        if ($tr_date != '') {
                            $product_name = $data_array['productName'];
                            if ($filter == 'contract') {
                                $product_name = $data_array['contractName'];
                            }
                            $charge = str_replace(',', '.', $data_array['invoiceAmountUSD']);
                            $products[$tr_date][$key] = array('amount' => isset($products[$tr_date][$product_name]) && in_array($transactiontype, array('CHARGE', 'RECURRING')) ? (double) $products[$tr_date][$product_name] + (double) $charge : 0, 'name' => $product_name);
                        }
                        if ($data_array['promoteContractsNum'] > 0) {
                            for ($i = 0; $i < $data_array['promoteContractsNum']; $i++) {
                                $promotions_html .= '<font style="font-weight: bold;" > Promotion: </font> ' . $data_array["promoteContractName{$i}"] . '
								<font style="font-weight: bold;" > owner: </font> ' . $data_array["promoteContractOwner{$i}"] . '
								<font style="font-weight: bold;" > price: </font> ' . $data_array["promoteContractPrice{$i}"] . '
								<font style="font-weight: bold;" > qty: </font> ' . $data_array["promoteContractQuantity{$i}"] . '
								<font style="font-weight: bold;" > licence: </font> ' . $data_array["promoteContractLicenseKey{$i}"] . '<br />';
                            }
                        }
                        $remove_row[$tr_date][] = $key;
                        $productname = isset($data_array['productName']) ? $data_array['productName'] : '';
                        $contractname = isset($data_array['contractName']) ? $data_array['contractName'] : '';
                        $quantity = isset($data_array['quantity']) ? $data_array['quantity'] : '';
                        $invoiceamountusd = isset($data_array['invoiceAmountUSD']) ? $data_array['invoiceAmountUSD'] : '';
                        $paymentmethod = isset($data_array['paymentMethod']) ? $data_array['paymentMethod'] : '';
                        $transactiontype = isset($data_array['transactionType']) ? $data_array['transactionType'] : '';
                        $prtitle = isset($data_array['title']) ? $data_array['title'] : '';
                        $firstname = isset($data_array['firstName']) ? $data_array['firstName'] : '';
                        $lastname = isset($data_array['lastName']) ? $data_array['lastName'] : '';
                        $premail = isset($data_array['email']) ? $data_array['email'] : '';
                        $transactiondate = isset($data_array['transactionDate']) ? $data_array['transactionDate'] : '';
                        $table_rows[$key] = "<tr><td>{$productname}</td><td>{$contractname}</td><td>{$quantity}</td>\n\t\t\t\t\t\t\t<td>{$invoiceamountusd}</td><td> {$table_coupon}</td><td>{$paymentmethod}</td>\n\t\t\t\t\t\t\t<td>{$transactiontype}</td><td>{$prtitle} {$firstname} {$lastname}</td><td>{$premail}</td>\n\t\t\t\t\t\t\t<td>{$transactiondate}</td><td id='more-info-{$key}'><a href='javascript: void(0)' title='More Info' onclick='showMoreInfo({$key})'>More</a> </td>\n\t\t\t\t\t\t\t<td style='background: #f9f9f9;'>\n\t\t\t\t\t\t\t\t<div class='more-info-panel' id='mi-{$key}' style='display: none;'>\n\t\t\t\t\t\t\t\t\t{$company}{$address1}{$address2}{$contact}{$mobile_phone}{$home_phone}{$fax}{$coustomer_cc}{$ship_to}{$shippingMethod}{$invoiceChargeAmount}\n\t\t\t\t\t\t\t\t\t{$coupon}{$couponCode}{$couponValue}{$referrer}\n\t\t\t\t\t\t\t\t\t" . $promotions_html . "\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</td></tr>";
                        $un_date = str_replace(' ', '/', substr_replace($transactiondate, '', -9));
                        $unsent_mails[] = array($un_date, $premail);
                    }
                    $j++;
                }
            }
            if ($search_query == '') {
                foreach ($products as $date => $data) {
                    foreach ($data as $key => $value) {
                        $total_sum += (double) $value['amount'];
                        if (date('mY') == date('mY', strtotime($date))) {
                            $this_month += $value['amount'];
                        }
                        $lmonth = $current_month = date('m') - 1;
                        if (date('' . $lmonth . 'Y') == date('mY', strtotime($date))) {
                            $last_month += $value['amount'];
                        }
                    }
                }
            }
            // sort by days
            $selected_date = array(0 => '', 7 => '', 15 => '', 30 => '', 60 => '', 120 => '');
            //if($filter == 'date'){
            $has_results = false;
            $global_days = $global_days == 0 ? $firt_entry : $global_days;
            $selected_date[$global_days] = 'selected="selected"';
            while (!$has_results) {
                $results = array();
                $data_dates = array();
                for ($i = 0; $i < (int) $global_days; $i++) {
                    $date = date('m/d/Y', time() - $i * 86400);
                    $data_dates[$i] = $date;
                }
                $keys = array_keys($products);
                foreach ($data_dates as $date) {
                    if (!array_key_exists($date, $products)) {
                        $products[$date][] = array();
                        $results[$date] = false;
                        continue;
                    }
                    $results[$date] = true;
                }
                foreach ($results as $res) {
                    if ($res) {
                        $has_results = true;
                        break;
                    }
                }
                if (!$has_results) {
                    if ($global_days = 0) {
                        $global_days = 7;
                    } else {
                        if ($global_days = 7) {
                            $global_days = 15;
                        } else {
                            $global_days = 2 * $global_days;
                        }
                    }
                }
                if ($global_days > 120) {
                    break;
                }
            }
            if ($global_days != 0 && false) {
                foreach ($keys as $key) {
                    if (!in_array($key, $data_dates) && isset($remove_row[$key])) {
                        foreach ($remove_row[$key] as $row_id) {
                            unset($table_rows[$row_id]);
                        }
                        unset($products[$key]);
                    }
                }
            }
            foreach ((array) $products as $date => $data) {
                $date_key = strtotime($date);
                foreach ($data as $key => $value) {
                    $products[$date_key][$key] = $value;
                }
                unset($products[$date]);
            }
            ksort($products);
            foreach ($products as $date => $data) {
                $date_key = date('m/d/Y', $date);
                foreach ($data as $key => $value) {
                    $products[$date_key][$key] = $value;
                }
                unset($products[$date]);
            }
            //}
            // end sort by days
            /* json */
            require_once 'pn-chart/OFC/OFC_Chart.php';
            $title_is = '';
            $values = array();
            $tips = array();
            $bar = new OFC_Charts_Bar();
            $max_price = 0;
            $amount = array();
            $array_keys = array_keys($products);
            foreach ($products as $date => $data) {
                if ($filter == 'date') {
                    $price = array();
                    foreach ($data as $key => $value) {
                        if (!isset($price[$date])) {
                            $price[$date] = 0;
                        }
                        $price[$date] += isset($value['amount']) ? $value['amount'] : 0;
                    }
                    $price = (double) $price[$date] < 0 ? 0 : (double) $price[$date];
                    $x_label[] = new OFC_Elements_Axis_X_Label('$' . $price, '#999999', 10, -50);
                    $tip_price = number_format($price, 2, '.', ',');
                    $tip = "\${$tip_price} ({$date})";
                    $val = new OFC_Charts_Bar_Value($price);
                    $val->set_tooltip($tip);
                    $values[] = $val;
                    $max_price = $max_price < $price ? $price + $price / 4 : $max_price;
                } else {
                    if ($date != $array_keys[count($array_keys) - 1]) {
                        foreach ($data as $key => $value) {
                            if (!empty($value) && isset($value['amount'])) {
                                if (!isset($amount[$value['name']])) {
                                    $amount[$value['name']] = 0;
                                }
                                $amount[$value['name']] += $value['amount'];
                            }
                        }
                        continue;
                    }
                    foreach ($data as $key => $value) {
                        if (!empty($value)) {
                            $amount[$value['name']] += $value['amount'];
                        }
                    }
                    foreach ($amount as $product_name => $product_val) {
                        $x_label[] = new OFC_Elements_Axis_X_Label(str_replace('|', ' ', $product_name), '#999999', 10, -50);
                        $tip_price = number_format($product_val, 2, '.', ',');
                        $tip = ucwords($product_name) . " (\$ {$tip_price})";
                        $val = new OFC_Charts_Bar_Value($product_val);
                        $val->set_tooltip($tip);
                        $values[] = $val;
                        $max_price = $max_price < $product_val ? $product_val + $product_val / 4 : $max_price;
                    }
                }
            }
            $bar->set_colour('#119CD3');
            $bar->set_values($values);
            $title = new OFC_Elements_Title($title_is);
            $x_l_set = new OFC_Elements_Axis_X_Label_Set();
            $x_l_set->set_steps(1);
            $x_l_set->set_labels($x_label);
            $x_axis = new OFC_Elements_Axis_X();
            $x_axis->set_3d(0);
            $x_axis->set_colours('#DDDDDD', '#DDDDDD');
            $x_axis->set_stroke(1);
            $x_axis->set_labels($x_l_set);
            $step = $max_price > 500 ? $max_price > 5000 ? $max_price > 50000 ? $max_price > 500000 ? $max_price > 5000000 ? 5000000 : 500000 : 50000 : 5000 : 500 : 50;
            $y_axis = new OFC_Elements_Axis_Y();
            $y_axis->set_colours('#DDDDDD', '#DDDDDD');
            $y_axis->set_range(0, $max_price, $step);
            $chart = new OFC_Chart();
            $chart->set_title($title);
            $chart->set_bg_colour('#F9F9F9');
            $chart->set_x_axis($x_axis);
            $chart->set_y_axis($y_axis);
            $chart->add_element($bar);
            $path = $pn_plugin_dir . "/pn-chart/data.json";
            $file = @fopen($path, "w");
            @fwrite($file, $chart->toString());
            @fclose($file);
            /* end json */
            $result = '';
            if (isset($_REQUEST['filter_all']) && $search_term != 'Filter By Keyword' && $search_term != '' && count($table_rows)) {
                $result = '<i style="color: #777">Showing results for "<strong>' . $search_term . '</strong>"</i>';
            } else {
                if (isset($_REQUEST['filter_all']) && $search_term != 'Filter By Keyword' && $search_term != '' && !count($table_rows)) {
                    $result = '<i style="color: #777">There is no transactions in this time period, that contain <strong>"' . $search_term . '"</strong>. Select your timespan in filter section.</i>';
                }
            }
            $master_table = $result . "<br /><br /><table id='pn-table-main' class='tablesorter'>";
            $master_table .= "<thead><tr><th> Product name </th><th> Contract name </th><th> Qty </th>\n\t\t\t\t<th> Invoice amount (USD)</th><th> Coupon code</th><th> Method </th><th> Transaction type</th><th> Customer name </th><th> Customer email </th><th> Transaction Date </th><td></td></tr></thead><tbody>";
            $master_table .= implode('', $table_rows) . "</tbody></table>";
            $master_table .= <<<END
\t\t\t\t\t\t\t<div id="pager" class="pager">
\t\t\t\t\t\t\t\t<form>
\t\t\t\t\t\t\t\t\t\t<img src="{$pn_plugin_url}/images/first.png" class="first"/>
\t\t\t\t\t\t\t\t\t\t<img src="{$pn_plugin_url}/images/prev.png" class="prev"/>
\t\t\t\t\t\t\t\t\t\t<input type="text" style="width:50px; height:18px; padding: 0px 0px 3px 0px;" class="pagedisplay" />
\t\t\t\t\t\t\t\t\t\t<img src="{$pn_plugin_url}/images/next.png" class="next"/>
\t\t\t\t\t\t\t\t\t\t<img src="{$pn_plugin_url}/images/last.png" class="last"/>
\t\t\t\t\t\t\t\t\t\t<select class="pagesize">
\t\t\t\t\t\t\t  <option value="5">5 per page</option>
\t\t\t\t\t\t\t\t\t\t\t\t<option value="10">10 per page</option>
\t\t\t\t\t\t\t\t\t\t\t\t<option value="20">20 per page</option>
\t\t\t\t\t\t\t\t\t\t\t\t<option value="50" selected="selected">50 per page</option>

\t\t\t\t\t\t\t\t\t\t</select>
\t\t\t\t\t\t\t\t</form>
\t\t\t\t\t\t</div>
END;
        }
        ?>
		<script type="text/javascript">
			swfobject.embedSWF("<?php 
        echo $pn_plugin_url . "/pn-chart/open-flash-chart.swf";
        ?>
", "pn_chart", "900px", "220px", "9.0.0", "expressInstall.swf", {"data-file":"<?php 
        echo $pn_plugin_url;
        ?>
/pn-chart/data.json"});
		</script>
		<div class="wrap">
		<h2><a href="http://www.bluesnap.com" title="Bluesnap - Take charge" target="_blank"><img src="<?php 
        echo $pn_plugin_url;
        ?>
/images/plimus_logo.png" alt="Plimu IPN" id="plimus-logo" /></a>for WordPress</h2>
		
		<h5><font color="#999999">This Month:</font> <font color="#555555"> $<?php 
        echo number_format($this_month, 2, '.', ',');
        ?>
</font> &nbsp;&nbsp;|&nbsp;&nbsp; <font color="#999999"> Last Month:</font> <font color="#555555"> $<?php 
        echo number_format($last_month, 2, '.', ',');
        ?>
</font> &nbsp;&nbsp;|&nbsp;&nbsp;  <font color="#999999"> Total Amount:</font> <font color="#555555"> $<?php 
        echo number_format($total_sum, 2, '.', ',');
        ?>
</font> </h5>
			<!--<i id="small_size">* Send registration notifications (again), dates in mm/dd/yyyy format please</i>
			 <form action="<?php 
        //echo $action_url;
        ?>
" method="post" id="new_email_form" >
				From <input type="text" name="new_from_date" value="12/1/2010" /> to <input type="text" name="new_to_date" value="12/16/2010" />
				<input type="submit" name="new_mails_submit" id="new_mails_submit" value="Send Registration Emails" class="button"/><br />
					<br /><i id="note">&nbsp;&nbsp;&nbsp;&nbsp;** in your <b>HTML new password email</b> template use <code>{USER_FULL_NAME}</code> <code>{NEW_PASSWORD}</code> <code>{LOGIN_URL}</code> shortcodes, to replace it with user</i>
				<textarea cols="90" rows="10" name="pn_email_tmp" id="pn_email_tmp" ><?php 
        //echo $pn_tpl_reg_email_text
        ?>
</textarea><div id="legend"></div>
				<textarea cols="80" rows="10" name="pn_email_res" id="pn_email_res" ><?php 
        //echo $email_message
        ?>
</textarea><div id="legend"></div>
			</form><br /><br /> -->
		<form action="<?php 
        echo $action_url;
        ?>
" id="search_form" method="POST">
			<select name="filter_by_type" id="filter_by_type" >
				<option value="date" <?php 
        echo isset($selected['date']) ? $selected['date'] : '';
        ?>
 >Show by date</option>
				<option value="product" <?php 
        echo isset($selected['product']) ? $selected['product'] : '';
        ?>
 >Show by product</option>
				<option value="contract" <?php 
        echo isset($selected['contract']) ? $selected['contract'] : '';
        ?>
 >Show by contract</option>
			</select>
			<select name="filter_by_dates" id="filter_by_dates" >
				<option value="0" <?php 
        echo $selected_date[0];
        ?>
>All transactions</option>
				<option value="7" <?php 
        echo $selected_date[7];
        ?>
>Last 7 days</option>
				<option value="15" <?php 
        echo $selected_date[15];
        ?>
>Last 15 days</option>
				<option value="30" <?php 
        echo $selected_date[30];
        ?>
>Last 30 days</option>
				<option value="60" <?php 
        echo $selected_date[60];
        ?>
>Last 60 days</option>
				<option value="120" <?php 
        echo $selected_date[120];
        ?>
>Last 120 days</option>
			</select>
			<input type="text" name="search_item" id="search_item" size="40" value="<?php 
        $search_term = strlen(trim($search_term)) ? $search_term : 'Filter By Keyword';
        echo $search_term;
        ?>
" />
			
			<input type="submit" value=" Submit  " name="filter_all" class="button" />
			<a href="<?php 
        echo $action_url;
        ?>
&show=all" title="Show All" class="button"> Show All </a>
		</form>
	<br />
		<?php 
        if (!empty($transaction_data)) {
            ?>
			<br />
			<div id="resize" style="width:1000px; height:250px; padding: 10px;">
				<div id="pn_chart"></div>
			</div>
			<?php 
            echo $master_table . $default_footer;
        } else {
            if (isset($_REQUEST['filter_all']) && ($search_term != '' || $search_term != 'Filter By Keyword') && empty($transaction_data)) {
                echo "<h5></i>There are no results for '{$_POST['search_item']}'.</i></h5>";
            } else {
                echo "<h5></i>There are no registered sales yet, but hopefully things are about to change.</i></h5>";
            }
        }
        ?>
		<h5><a href="http://www.prelovac.com" title="Plugin by Prelovac Media"><img src="<?php 
        echo $pn_plugin_url;
        ?>
/images/logo.png"  style="margin-top: 30px;"/></a> </h5>
		
		</div><br />
		
		<?php 
    }