PageRenderTime 60ms CodeModel.GetById 3ms app.highlight 46ms RepoModel.GetById 1ms app.codeStats 1ms

/wp-content/plugins/formidable/pro/classes/controllers/FrmProStatisticsController.php

https://github.com/rafapires/festival-de-ideias
PHP | 1312 lines | 1039 code | 248 blank | 25 comment | 264 complexity | b8db12893ad4963ecd6bf642bf710409 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2
   3class FrmProStatisticsController{
   4    function FrmProStatisticsController(){
   5        add_action('admin_menu', array( &$this, 'menu' ), 24);
   6        add_action('admin_init', array(&$this, 'admin_js'));
   7        add_shortcode('frm-graph', array(&$this, 'graph_shortcode'));
   8        add_shortcode('frm-stats', array(&$this, 'stats_shortcode'));
   9    }
  10    
  11    function menu(){
  12        global $frm_settings;
  13        add_submenu_page('formidable', 'Formidable | '. __('Reports', 'formidable'), __('Reports', 'formidable'), 'frm_view_reports', 'formidable-reports', array(&$this, 'show'));
  14        
  15        add_action('admin_head-'. sanitize_title($frm_settings->menu) .'_page_formidable-reports', array(&$this, 'head'));
  16    }
  17    
  18    function admin_js(){
  19        if (isset($_GET) and isset($_GET['page']) and $_GET['page'] == 'formidable-reports'){
  20        	wp_enqueue_script('swfobject');
  21        	wp_enqueue_script('json2');
  22        }
  23    }
  24    
  25    function head(){
  26        require_once(FRMPRO_PATH . '/js/ofc-library/open-flash-chart-object.php');
  27        require_once(FRMPRO_PATH . '/js/ofc-library/open-flash-chart.php');
  28    }
  29    
  30    function show(){
  31        global $frmdb, $frm_form, $frm_field, $frm_entry_meta, $frm_entry, $wpdb;
  32        if  (!isset($_GET['form'])){
  33            require_once(FRMPRO_VIEWS_PATH.'/frmpro-statistics/show.php');
  34            return;
  35        }
  36        
  37        $form = $frm_form->getOne($_GET['form']);
  38        //$form_options = maybe_unserialize($form->options);
  39        $fields = $frm_field->getAll("fi.type not in ('divider','captcha','break','rte','textarea','file','grid','html') and fi.form_id=".$form->id, 'field_order ASC');
  40        
  41        $js = '';
  42        $data = array();
  43        $odd = true;
  44        $colors = array('#EF8C08', '#21759B', '#1C9E05');
  45        foreach ($fields as $field){  
  46            $data[$field->id] = $this->get_graph($field, array('colors' => $colors, 'bg_color' => '#FFFFFF', 'odd' => $odd));
  47 
  48            $js .= 'swfobject.embedSWF("'.FRMPRO_URL.'/js/open-flash-chart.swf", "chart_'.$field->id.'",
  49              "650", "400", "9.0.0", "expressInstall.swf", {"get-data":"get_data_'.$field->id.'"},{"wmode":"transparent"});';
  50              
  51            $odd = $odd ? false : true;
  52        }
  53        
  54        $data['time'] = $this->get_daily_entries($form, $colors);
  55        $js .= 'swfobject.embedSWF("'.FRMPRO_URL.'/js/open-flash-chart.swf","chart_time","900","300","9.0.0","expressInstall.swf", {"get-data":"get_data_time"},{"wmode":"transparent"});';
  56        
  57        //$data['hour'] = $this->get_daily_entries($form, $colors, 'HOUR'); //TODO: Fix timezone
  58        //$js .= 'swfobject.embedSWF("'.FRMPRO_URL.'/js/open-flash-chart.swf","chart_hour","900","300","9.0.0","expressInstall.swf", {"get-data":"get_data_hour"} );';
  59        
  60        $data['month'] = $this->get_daily_entries($form, $colors, 'MONTH');
  61        $js .= 'swfobject.embedSWF("'.FRMPRO_URL.'/js/open-flash-chart.swf","chart_month","900","300","9.0.0","expressInstall.swf", {"get-data":"get_data_month"},{"wmode":"transparent"});';
  62        
  63        //$data['year'] = $this->get_daily_entries($form, $colors, 'YEAR');
  64        //$js .= 'swfobject.embedSWF("'.FRMPRO_URL.'/js/open-flash-chart.swf","chart_year","900","300","9.0.0","expressInstall.swf", {"get-data":"get_data_year"} );';
  65        
  66        require(FRMPRO_VIEWS_PATH.'/frmpro-statistics/head.php');
  67        require(FRMPRO_VIEWS_PATH.'/frmpro-statistics/show.php');
  68    }
  69    
  70    function get_graph($field, $args){
  71        $defaults = array(
  72            'ids' => false, 
  73            'colors' => array('#EF8C08', '#21759B', '#1C9E05'), 'grid_color' => '#f7e8bf', 'bg_color' => '#FFFFFF', 
  74            'odd' => false, 'truncate' => 40, 'truncate_label' => 15, 'response_count' => 10, 
  75            'user_id' => false, 'type' => 'default', 'x_axis' => false, 'data_type' => 'count',
  76            'limit' => '', 'x_start' => '', 'x_end' => '', 'show_key' => false, 'min' => '', 'max' => '',
  77            'include_zero' => false, 'width' => 400, 'height' => 400, 'wrap' => 15
  78        );
  79        $args = wp_parse_args($args, $defaults);
  80        $vals = $this->get_graph_values($field, $args);
  81        extract($args);
  82        extract($vals);
  83        
  84
  85        $title = new title( preg_replace("/&#?[a-z0-9]{2,8};/i", "", FrmAppHelper::truncate($field->name, $truncate, 0)) );
  86        $chart = new open_flash_chart();
  87        $chart->set_title( $title );
  88        $bar = new bar_glass();
  89        $x = new x_axis();
  90        $y = new y_axis();
  91        $x_labels = new x_axis_labels();
  92
  93
  94        if (in_array($field->type, array('select', 'checkbox', 'radio', '10radio', 'scale')) and (!isset($x_inputs) or !$x_inputs)){            
  95            $x_labels->rotate(340);
  96            //$x_labels->set_colour( '#A2ACBA' );
  97            //$x->set_colour( '#A2ACBA' );
  98        }else if ($field->type == 'user_id'){            
  99            if(!$pie)
 100                $x_labels->rotate(340);
 101        }else{
 102            $x_labels->rotate(340);
 103        }
 104        
 105        $pie = ($type == 'default') ? $pie : (($type == 'pie') ? true : false);
 106        if ($pie){
 107            $bar = new pie();
 108            $bar->set_alpha(0.6);
 109            $bar->set_start_angle( 35 );
 110            $bar->add_animation( new pie_fade() );
 111            $bar->set_tooltip( '#val# (#percent#)' );
 112            $bar->set_colours( $colors );
 113            $pie_values = array();
 114            
 115            foreach ($values as $val_key => $val){
 116                if($val)
 117                    $pie_values[] = new pie_value($val, wordwrap($labels[$val_key], $wrap, "n")." (". round(($val/$total_count) *100) . "%)");
 118            }
 119            
 120            $bar->set_values( $pie_values );
 121        }else{
 122            $color = $odd ? current($colors) : next($colors);
 123            if(!$color)
 124                $color = reset($colors);
 125
 126            if($type == 'line')
 127                $bar = new line();
 128            else if($type == 'hbar')
 129                $bar = new hbar($color);
 130            else if($type == 'area') 
 131                $bar = new area();
 132            else if($type == 'bar_flat')
 133                $bar = new bar($color);
 134            else
 135                $bar = new bar_glass($color);
 136            
 137            $bar->set_colour( $color);    
 138            $bar->set_values( $values );
 139            if($show_key)
 140                $bar->set_key( stripslashes($field->name), $show_key );
 141                
 142            $x_labels->set_labels( $labels );
 143            $x->set_labels( $x_labels );
 144            $x->set_grid_colour( $grid_color );
 145            $y->set_grid_colour( $grid_color );
 146
 147            if($combine_dates and !strpos($width, '%') and ((count($labels) * 30) > (int)$width))
 148                $x_labels->visible_steps(ceil((count($labels) * 30) / (int)$width));
 149            
 150            $set_max = $max;
 151            if (!empty($values) and empty($max)){
 152                $max = abs(max($values)*1.2);
 153                
 154                if ($max < 3) $max = 3;
 155            }
 156            
 157            foreach($ids as $f_id){
 158                $new_max = abs(max($f_values[$f_id])*1.2);
 159                if($set_max != $max and $new_max > $max)
 160                    $max = $new_max;
 161                unset($f_id);
 162                unset($new_max);
 163            }
 164            
 165            $bars = array();
 166            foreach($f_values as $f_id => $f_vals){
 167                if($type == 'line')
 168                    $bars[$f_id] = new line();
 169                else if($type == 'hbar')
 170                    $bars[$f_id] = new hbar($color);
 171                else if($type == 'area') 
 172                    $bars[$f_id] = new area();
 173                else if($type == 'bar_flat')
 174                    $bars[$f_id] = new bar();
 175                else
 176                    $bars[$f_id] = new bar_glass();
 177                
 178                $color = next($colors);
 179                if(!$color)
 180                    $color = reset($colors);
 181                    
 182                $bars[$f_id]->set_colour( $color );    
 183                $bars[$f_id]->set_values( $f_vals );
 184                if($show_key)
 185                    $bars[$f_id]->set_key( stripslashes($fields[$f_id]->name), $show_key );
 186                
 187                
 188                unset($f_id);
 189            }
 190            
 191            if(isset($max) and !empty($max)){
 192                $step = ceil($max/10);
 193                if(empty($min))
 194                    $min = 0;
 195                $y->set_range($min, $max, $step);
 196            }
 197        }
 198
 199        $chart->add_element( $bar );
 200        if(isset($bars) and !empty($bars)){
 201            foreach($bars as $f_bar)
 202                $chart->add_element( $f_bar );
 203        }
 204        
 205        $chart->set_bg_colour( $bg_color );
 206        
 207        if(!$pie){
 208            $chart->set_y_axis( $y );
 209            $chart->set_x_axis( $x );  
 210        }    
 211        
 212        return $chart->toPrettyString();
 213    }
 214    
 215    function get_google_graph($field, $args){
 216        $defaults = array(
 217            'ids' => false, 
 218            'colors' => '', 'grid_color' => '#CCC', 'bg_color' => '#FFFFFF', 
 219            'odd' => false, 'truncate' => 40, 'truncate_label' => 15, 'response_count' => 10, 
 220            'user_id' => false, 'type' => 'default', 'x_axis' => false, 'data_type' => 'count',
 221            'limit' => '', 'x_start' => '', 'x_end' => '', 'show_key' => false, 'min' => '', 'max' => '',
 222            'include_zero' => false, 'width' => 400, 'height' => 400, 'allowed_col_types' => array('string', 'number')
 223        );
 224        
 225        $args = wp_parse_args($args, $defaults);
 226        $vals = $this->get_graph_values($field, $args);
 227        extract($vals);
 228        extract($args);
 229        
 230        
 231        $pie = ($type == 'default') ? $pie : (($type == 'pie') ? true : false);
 232        if ($pie){
 233            $type = 'pie';
 234            
 235            $cols = array('Field' => array('type' => 'string'), 'Entries' => array('type' => 'number')); //map each array position in rows array
 236            
 237            foreach ($values as $val_key => $val){
 238                if($val)
 239                    $rows[] = array($labels[$val_key], $val);
 240            }
 241        }else{
 242            if(!isset($options['hAxis']))
 243                $options['hAxis'] = array();
 244                
 245            $options['vAxis'] = array('gridlines' => array('color' => $grid_color));
 246            if($combine_dates and !strpos($width, '%') and ((count($labels) * 50) > (int)$width))
 247                $options['hAxis']['showTextEvery'] = (ceil((count($labels) * 50) / (int)$width));
 248            
 249            $options['hAxis']['slantedText'] = true;
 250            $options['hAxis']['slantedTextAngle'] = 20;
 251            
 252            $rn_order = array();
 253            foreach($labels as $lkey => $l){
 254                if(isset($x_field) and $x_field and $x_field->type == 'number'){
 255                    $l = (float)$l;
 256                    $rn_order[] = $l;
 257                }
 258                
 259                $row = array($l, $values[$lkey]);
 260                foreach($f_values as $f_id => $f_vals)
 261                    $row[] = isset($f_vals[$lkey]) ? $f_vals[$lkey] : 0;
 262                
 263                $rows[] = $row;  
 264                unset($lkey);
 265                unset($l);
 266            }
 267            
 268            if(isset($max) and !empty($max))
 269                $options['vAxis']['maxValue'] = $max;
 270            
 271            if(!empty($min))
 272                $options['vAxis']['minValue'] = $min;
 273        }
 274        
 275        if(isset($rn_order) and !empty($rn_order)){
 276            asort($rn_order);
 277            $sorted_rows = array();
 278            foreach($rn_order as $rk => $rv)
 279                $sorted_rows[] = $rows[$rk];
 280            
 281            $rows = $sorted_rows;
 282        }
 283        
 284        $options['backgroundColor'] = $bg_color;
 285        
 286        if($type == 'bar' or $type == 'bar_flat' or $type == 'bar_glass')
 287            $type = 'column';
 288        else if($type == 'hbar')
 289            $type = 'bar';
 290            
 291        $allowed_types = array('pie', 'line', 'column', 'area', 'SteppedArea', 'geo');
 292        if(!in_array($type, $allowed_types))
 293            $type = 'column';
 294        
 295        $options = apply_filters('frm_google_chart', $options, compact('rows', 'cols', 'type', 'atts'));
 296        return $this->convert_to_google($rows, $cols, $options, $type);
 297    }
 298    
 299    function get_graph_values($field, $args){
 300        global $frm_entry_meta, $frm_field, $frmdb, $wpdb;           
 301        $values = $labels = $f_values = $f_labels = $rows = $cols = array();
 302        $pie = false;
 303        
 304        extract($args);
 305        
 306        $show_key = (int)$show_key;
 307        if($show_key and $show_key < 5)
 308            $show_key = 10;
 309            
 310        $options = array('width' => $width, 'height' => $height, 'legend' => 'none');
 311        if(!empty($colors))
 312            $options['colors'] = $colors;
 313        $options['title'] = preg_replace("/&#?[a-z0-9]{2,8};/i", "", FrmAppHelper::truncate($field->name, $truncate, 0));
 314             
 315        if($show_key)
 316            $options['legend'] = array('position' => 'right', 'textStyle' => array('fontSize' => $show_key));
 317            
 318        $fields = $f_inputs = array();
 319        $fields[$field->id] = $field;
 320
 321        if($ids){ 
 322            $ids = explode(',', $ids);
 323
 324            foreach($ids as $id_key => $f){
 325                $ids[$id_key] = $f = trim($f);
 326                if(!$f or empty($f)){
 327                    unset($ids[$id_key]);
 328                    continue;
 329                }
 330
 331                if($add_field = $frm_field->getOne($f)){
 332                    $fields[$add_field->id] = $add_field;
 333                    $ids[$id_key] = $add_field->id;
 334                }
 335                unset($f);
 336                unset($id_key);
 337            }
 338        }else{
 339            $ids = array();
 340        }
 341        
 342        $cols['xaxis'] = array('type' => 'string');
 343        
 344        if($x_axis){
 345            $x_field = $frm_field->getOne($x_axis);
 346            
 347            $query = $x_query = "SELECT meta_value, item_id FROM $frmdb->entry_metas em";
 348            if(!$x_field)
 349                $x_query = "SELECT id, {$x_axis} FROM $frmdb->entries e";
 350            
 351            if($user_id){
 352                $query .= " LEFT JOIN $frmdb->entries e ON (e.id=em.item_id)";
 353                if($x_field)
 354                    $x_query .= " LEFT JOIN $frmdb->entries e ON (e.id=em.item_id)";
 355            }
 356              
 357            if($x_field){
 358                if(isset($allowed_col_types))
 359                    $cols['xaxis'] = array('type' => ((in_array($x_field->type, $allowed_col_types)) ? $x_field->type : 'string'), 'id' => $x_field->id);
 360                $options['hAxis'] = array('title' => stripslashes($x_field->name));
 361                
 362                $x_query .= " WHERE em.field_id='{$x_field->id}'";
 363                if(!empty($x_start)){
 364                    if($x_field->type == 'date')
 365                        $x_start = date('Y-m-d', strtotime($x_start));
 366                    
 367                    $x_query .= " and meta_value >= '$x_start'";
 368                }
 369                
 370                if(!empty($x_end)){
 371                    if($x_field->type == 'date')
 372                        $x_end = date('Y-m-d', strtotime($x_end));
 373                        
 374                    $x_query .= " and meta_value <= '$x_end'";
 375                }
 376            }else{
 377                $cols['xaxis'] = array('type' => 'string');
 378                                
 379                $x_query .= " WHERE form_id=". $field->form_id;
 380                if(!empty($x_start)){
 381                    if(in_array($x_axis, array('created_at', 'updated_at')))
 382                        $x_start = date('Y-m-d', strtotime($x_start));
 383                    $x_query .= " and e.{$x_axis} >= '$x_start'";
 384                }
 385
 386                if(!empty($x_end)){
 387                    if(in_array($x_axis, array('created_at', 'updated_at')))
 388                        $x_end = date('Y-m-d', strtotime($x_end)) .' 23:59:59';
 389                    $x_query .= " and e.{$x_axis} <= '$x_end'";
 390                }
 391            }            
 392            
 393            $q = array();
 394            foreach($fields as $f_id => $f){
 395                if($f_id != $field->id)
 396                    $q[$f_id] = $query ." WHERE em.field_id='{$f_id}'". ( ($user_id) ? " AND user_id='$user_id'" : '');
 397                unset($f);
 398                unset($f_id);
 399            }
 400                
 401            $query .= " WHERE em.field_id='{$field->id}'";
 402            
 403            if($user_id){
 404                $query .= " AND user_id='$user_id'";
 405                $x_query .= " AND user_id='$user_id'";
 406            }
 407
 408            $inputs = $wpdb->get_results($query, ARRAY_A);
 409            $x_inputs = $wpdb->get_results($x_query, ARRAY_A);
 410            
 411            if(!$x_inputs)
 412                $x_inputs = array('id' => '0');
 413 
 414            unset($query);
 415            unset($x_query);
 416            
 417            foreach($q as $f_id => $query){
 418                $f_inputs[$f_id] = $wpdb->get_results($query, ARRAY_A);
 419                unset($query);
 420            }
 421            
 422            unset($q);            
 423        }else{            
 424            if($user_id)
 425                $inputs = $wpdb->get_col("SELECT meta_value FROM $frmdb->entry_metas em LEFT JOIN $frmdb->entries e ON (e.id=em.item_id) WHERE em.field_id='{$field->id}' AND user_id='$user_id'");
 426            else
 427                $inputs = $frm_entry_meta->get_entry_metas_for_field($field->id);
 428                
 429            foreach($fields as $f_id => $f){
 430                if($f_id != $field->id)
 431                    $f_inputs[$f_id] = $wpdb->get_col("SELECT meta_value FROM $frmdb->entry_metas em LEFT JOIN $frmdb->entries e ON (e.id=em.item_id) WHERE em.field_id='{$f_id}'". ( ($user_id) ? " AND user_id='$user_id'" : ''));
 432                unset($f_id);
 433                unset($f);
 434            }
 435        }
 436        
 437        $inputs = array_map('maybe_unserialize', $inputs);
 438        $inputs = stripslashes_deep($inputs);
 439        
 440        foreach($f_inputs as $f_id => $f){
 441            $f = array_map('maybe_unserialize', $f);
 442            $f_inputs[$f_id] = stripslashes_deep($f);
 443            unset($f_id);
 444            unset($f);
 445        }
 446        
 447        if(isset($allowed_col_types)){
 448        //add columns for each field
 449            foreach($fields as $f_id => $f){
 450                $cols[stripslashes($f->name)] = array('type' => ((in_array($f->type, $allowed_col_types)) ? $f->type : 'number'), 'id' => $f->id);
 451                unset($f);
 452                unset($f_id);
 453            }
 454            unset($allowed_col_types);
 455        }
 456        
 457        $field_options = maybe_unserialize($field->options);
 458        $field->field_options = maybe_unserialize($field->field_options);
 459        
 460        global $frm_posts;
 461        
 462        if($user_id){
 463            $form_posts = $frmdb->get_records($frmdb->entries, array('form_id' => $field->form_id, 'post_id >' => 1, 'user_id' => $user_id), '', '', 'id,post_id');
 464        }else if($frm_posts and isset($frm_posts[$field->form_id])){
 465            $form_posts = $frm_posts[$field->form_id];
 466        }else{
 467            $form_posts = $frmdb->get_records($frmdb->entries, array('form_id' => $field->form_id, 'post_id >' => 1), '', '', 'id,post_id');
 468            
 469            $frm_posts = array($field->form_id => $form_posts);
 470        }
 471       
 472        if(!empty($form_posts)){
 473            if(isset($field->field_options['post_field']) and $field->field_options['post_field'] != ''){
 474                if($field->field_options['post_field'] == 'post_category'){
 475                    $field_options = FrmProFieldsHelper::get_category_options($field);
 476                }else if($field->field_options['post_field'] == 'post_custom' and $field->field_options['custom_field'] != ''){
 477                    //check custom fields
 478                    foreach($form_posts as $form_post){
 479                        $meta_value = get_post_meta($form_post->post_id, $field->field_options['custom_field'], true);
 480                        if($meta_value){
 481                            if($x_axis)
 482                                $inputs[] = array('meta_value' => $meta_value, 'item_id' => $form_post->id);
 483                            else
 484                                $inputs[] = $meta_value;
 485                        }
 486                    }
 487                }else{ //if field is post field
 488                    if($field->field_options['post_field'] == 'post_status')
 489                        $field_options = FrmProFieldsHelper::get_status_options($field);
 490                    
 491                    foreach($form_posts as $form_post){
 492                        $post_value = $wpdb->get_var("SELECT ". $field->field_options['post_field'] ." FROM $wpdb->posts WHERE ID=".$form_post->post_id);
 493                        if($post_value){
 494                            if($x_axis)
 495                                $inputs[] = array('meta_value' => $post_value, 'item_id' => $form_post->id);
 496                            else
 497                                $inputs[] = $post_value;
 498                        }
 499                    }
 500                }
 501            }
 502        }
 503        
 504        if($field->type == 'data'){
 505            foreach($inputs as $k => $i){
 506                if(is_numeric($i)){
 507                    if(is_array($inputs[$k]) and isset($inputs[$k]['meta_value'])){
 508                        $inputs[$k]['meta_value'] = FrmProFieldsHelper::get_data_value($inputs[$k]['meta_value'], $field, array('truncate' => 'truncate_label'));
 509                    }else{
 510                       $inputs[$k] = FrmProFieldsHelper::get_data_value($inputs[$k], $field, array('truncate' => 'truncate_label'));
 511                    }
 512                }
 513                unset($k);
 514                unset($i);
 515            }
 516        }
 517        
 518        if(isset($x_inputs) and $x_inputs){
 519            $x_temp = array();
 520            foreach($x_inputs as $x_input){
 521                if($x_field)
 522                    $x_temp[$x_input['item_id']] = $x_input['meta_value'];
 523                else
 524                    $x_temp[$x_input['id']] = $x_input[$x_axis];
 525            }
 526            $x_inputs = apply_filters('frm_graph_value', $x_temp, ($x_field ? $x_field : $x_axis), $args);
 527            
 528            unset($x_temp);
 529            unset($x_input);
 530        }
 531        
 532        if($x_axis and $inputs){
 533            $y_temp = array();
 534            foreach($inputs as $input)
 535                $y_temp[$input['item_id']] = $input['meta_value'];
 536            
 537            foreach($ids as $f_id){
 538                if(!isset($f_values[$f_id]))
 539                    $f_values[$f_id] = array();
 540                $f_values[$f_id][key($y_temp)] = 0;
 541                unset($f_id);
 542            }
 543
 544            $inputs = $y_temp;
 545            
 546            unset($y_temp);
 547            unset($input);
 548        }
 549        
 550        $inputs = apply_filters('frm_graph_value', $inputs, $field, $args);
 551
 552        foreach($f_inputs as $f_id => $f){
 553            $temp = array();
 554            foreach($f as $input){
 555                if(is_array($input)){
 556                    $temp[$input['item_id']] = $input['meta_value'];
 557                    
 558                    foreach($ids as $d){
 559                        if(!isset($f_values[$d][$input['item_id']]))
 560                            $f_values[$d][$input['item_id']] = 0;
 561                        
 562                        unset($d);
 563                    }
 564                }else{
 565                    $temp[] = $input;
 566                }
 567                
 568                unset($input);
 569            }
 570
 571            $f_inputs[$f_id] = apply_filters('frm_graph_value', $temp, $fields[$f_id], $args);
 572            
 573            unset($temp);
 574            unset($input);
 575            unset($f);
 576        }
 577        
 578        
 579        if (in_array($field->type, array('select', 'checkbox', 'radio', '10radio', 'scale')) and (!isset($x_inputs) or !$x_inputs)){ 
 580            if($limit == '') $limit = 10;
 581            $field_opt_count = count($field_options);
 582
 583            if($field_options){
 584            foreach ($field_options as $opt_key => $opt){
 585                $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field->field_options);
 586                $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
 587                $count = 0;
 588                
 589                if(empty($opt))
 590                    continue;
 591                    
 592                $opt = stripslashes_deep($opt);
 593                
 594                foreach ($inputs as $in){
 595                    if (FrmAppHelper::check_selected($in, $field_val)){
 596                        if($data_type == 'total')
 597                            $count += $field_val;
 598                        else
 599                            $count++;
 600                    }
 601                }
 602                
 603                $new_val = FrmAppHelper::truncate($opt, $truncate_label, 2);
 604                
 605                if($count > 0 or $field_opt_count < $limit or (!$count and $include_zero)){
 606                    $labels[$new_val] = $new_val;
 607                    $values[$new_val] = $count;
 608                }
 609                unset($count);
 610                
 611                foreach($f_inputs as $f_id => $f){
 612                    
 613                    foreach($f as $in){
 614                        if(!isset($f_values[$f_id]))
 615                            $f_values[$f_id] = array();    
 616
 617                        if(!isset($f_values[$f_id][$new_val]))
 618                            $f_values[$f_id][$new_val] = 0;
 619                            
 620                        if (FrmAppHelper::check_selected($in, $field_val)){
 621                            if($data_type == 'total')
 622                                $f_values[$f_id][$new_val] += $field_val;
 623                            else
 624                                $f_values[$f_id][$new_val]++;
 625                        }
 626                        
 627                        unset($in);
 628                    }
 629                        
 630                    unset($f_id);
 631                    unset($f);
 632                }
 633                
 634            }
 635            
 636            if($limit != 10 and count($values) > $limit){
 637                $ordered_vals = $values;
 638                arsort($ordered_vals);
 639                $l_count = 0;
 640                foreach($ordered_vals as $vkey => $v){
 641                    $l_count++;
 642                    if($l_count > $limit){
 643                        unset($values[$vkey]);
 644                        unset($labels[$vkey]);
 645                    }
 646                    unset($vkey);
 647                    unset($v);
 648                }
 649                unset($l_count);
 650                unset($ordered_vals);
 651            }
 652            
 653            }
 654            
 655            if (!in_array($field->type, array('checkbox', '10radio', 'scale'))) //and count($field_options) == 2
 656                $pie = true;
 657            
 658        }else if ($field->type == 'user_id'){
 659            $form = $frmdb->get_one_record($frmdb->forms, array('id' => $field->form_id));
 660            $form_options = maybe_unserialize($form->options);
 661            $id_count = array_count_values($inputs);
 662            if ($form->editable and (isset($form_options['single_entry']) and $form_options['single_entry'] and isset($form_options['single_entry_type']) and $form_options['single_entry_type'] == 'user')){
 663                //if only one response per user, do a pie chart of users who have submitted the form
 664                $users_of_blog = (function_exists('get_users')) ? get_users() : get_users_of_blog();
 665                $total_users = count( $users_of_blog );
 666                unset($users_of_blog);
 667                $id_count = count($id_count);
 668                $not_completed = (int)$total_users - (int)$id_count;
 669                $labels = array(__('Completed', 'formidable'), __('Not Completed', 'formidable'));
 670                $values = array($id_count, $not_completed);
 671                $pie = true;
 672            }else{
 673                //arsort($id_count);
 674                foreach ($id_count as $val => $count){
 675                    $user_info = get_userdata($val);
 676                    $labels[] = ($user_info) ? $user_info->display_name : __('Deleted User', 'formidable');
 677                    $values[] = $count;
 678                }
 679                if (count($labels) < 10)
 680                    $pie = true;
 681            }
 682        }else{
 683            if(isset($x_inputs) and $x_inputs){
 684                $calc_array = array();
 685                
 686                foreach ($inputs as $entry_id => $in){
 687                    $entry_id = (int)$entry_id;
 688                    if(!isset($values[$entry_id]))
 689                        $values[$entry_id] = 0;
 690                        
 691                    $labels[$entry_id] = (isset($x_inputs[$entry_id])) ? $x_inputs[$entry_id] : ''; 
 692                    
 693                    if(!isset($calc_array[$entry_id]))
 694                        $calc_array[$entry_id] = array('count' => 0);
 695                        
 696                    if($data_type == 'total' or $data_type == 'average'){    
 697                        $values[$entry_id] += (float)$in;
 698                        $calc_array[$entry_id]['total'] = $values[$entry_id];
 699                        $calc_array[$entry_id]['count']++;
 700                    }else{
 701                        $values[$entry_id]++;
 702                    }
 703                    
 704                    unset($entry_id);
 705                    unset($in);
 706                }
 707                
 708                if($data_type == 'average'){
 709                    foreach($calc_array as $entry_id => $calc){
 710                        $values[$entry_id] = ($calc['total'] / $calc['count']);
 711                        unset($entry_id);
 712                        unset($calc);
 713                    }
 714                }
 715                
 716                $calc_array = array();
 717                foreach($f_inputs as $f_id => $f){
 718                    if(!isset($calc_array[$f_id]))
 719                        $calc_array[$f_id] = array();
 720                        
 721                    foreach($f as $entry_id => $in){
 722                        $entry_id = (int)$entry_id;
 723                        if(!isset($labels[$entry_id])){
 724                            $labels[$entry_id] = (isset($x_inputs[$entry_id])) ? $x_inputs[$entry_id] : '';
 725                            $values[$entry_id] = 0;
 726                        }
 727                        
 728                        if(!isset($calc_array[$f_id][$entry_id]))
 729                            $calc_array[$f_id][$entry_id] = array('count' => 0);
 730                            
 731                        if(!isset($f_values[$f_id][$entry_id]))
 732                            $f_values[$f_id][$entry_id] = 0;
 733                        
 734                        if($data_type == 'total' or $data_type == 'average'){    
 735                            $f_values[$f_id][$entry_id] += (float)$in;
 736                            $calc_array[$f_id][$entry_id]['total'] = $f_values[$f_id][$entry_id];
 737                            $calc_array[$f_id][$entry_id]['count']++;
 738                        }else{
 739                            $f_values[$f_id][$entry_id]++;
 740                        }
 741                        
 742                        unset($entry_id);
 743                        unset($in);
 744                    }
 745                    
 746                    unset($f_id);
 747                    unset($f);
 748                }
 749                
 750                if($data_type == 'average'){
 751                    foreach($calc_array as $f_id => $calc){
 752                        foreach($calc as $entry_id => $c){
 753                            $f_values[$f_id][$entry_id] = ($c['total'] / $c['count']);
 754                            unset($entry_id);
 755                            unset($c);
 756                        }
 757                        unset($calc);
 758                        unset($f_id);
 759                    }
 760                }
 761                unset($calc_array);
 762                
 763            }else{
 764                if(is_array(reset($inputs))){
 765                    $id_count = array_map('implode', $inputs);
 766                    $id_count = array_count_values(array_map('strtolower', $id_count));
 767                }else{
 768                    $id_count = array_count_values(array_map('strtolower', $inputs));
 769                    arsort($id_count);
 770                }
 771                
 772                $i = 0;
 773                foreach ($id_count as $val => $count){
 774                    if ($i < $response_count){
 775                        if ($field->type == 'user_id'){
 776                            $user_info = get_userdata($val);
 777                            $new_val = $user_info->display_name;
 778                        }else{
 779                            $new_val = ucwords($val);
 780                        }
 781                        $labels[$new_val] = $new_val;
 782                        $values[$new_val] = $count;
 783                        
 784                    }
 785                    $i++;
 786                }
 787                
 788                foreach($f_inputs as $f_id => $f){
 789                    $id_count = array_count_values(array_map('strtolower', $f));
 790                    arsort($id_count);
 791
 792                    $i = 0;
 793                    foreach ($id_count as $val => $count){
 794                        if ($i < $response_count){
 795                            if ($field->type == 'user_id'){
 796                                $user_info = get_userdata($val);
 797                                $new_val = $user_info->display_name;
 798                            }else{
 799                                $new_val = ucwords($val);
 800                            }
 801                            $position = array_search($new_val, $labels);
 802                            if(!$position){
 803                                end($labels);
 804                                $position = key($labels);
 805                                $labels[$new_val] = $new_val;
 806                                $values[$new_val] = 0;
 807                                
 808                            }
 809                            $f_values[$f_id][$new_val] = $count;
 810                        }
 811                        $i++;
 812
 813                    }
 814
 815                    unset($f_id);
 816                    unset($f);
 817                }
 818                
 819            }
 820        }
 821
 822         if(isset($x_inputs) and $x_inputs){
 823            $used_vals = $calc_array = array();
 824            foreach($labels as $l_key => $label){
 825                if(empty($label) and (!empty($x_start) or !empty($x_end))){
 826                    unset($values[$l_key]);
 827                    unset($labels[$l_key]);
 828                    continue;
 829                }
 830                
 831                if(in_array($x_axis, array('created_at', 'updated_at'))){
 832                    if($type == 'pie')
 833                        $labels[$l_key] = $label = $inputs[$l_key]; 
 834                    else
 835                        $labels[$l_key] = $label = date('Y-m-d', strtotime($label)); 
 836                }
 837                 
 838                if(isset($used_vals[$label])){
 839                    $values[$l_key] += $values[$used_vals[$label]];
 840                    unset($values[$used_vals[$label]]);
 841                    
 842                    foreach($ids as $f_id){
 843                        if(!isset($f_values[$f_id][$l_key]))
 844                            $f_values[$f_id][$l_key] = 0;
 845                        if(!isset($f_values[$f_id][$used_vals[$label]]))
 846                            $f_values[$f_id][$used_vals[$label]] = 0;
 847                            
 848                        $f_values[$f_id][$l_key] += $f_values[$f_id][$used_vals[$label]];
 849                        unset($f_values[$f_id][$used_vals[$label]]);
 850                        unset($f_id);
 851                    }
 852                    
 853                    unset($labels[$used_vals[$label]]);
 854                }
 855                $used_vals[$label] = $l_key;
 856                
 857                if($data_type == 'average'){
 858                    if(!isset($calc_array[$label]))
 859                        $calc_array[$label] = 0;
 860                    $calc_array[$label]++;
 861                }
 862                
 863                unset($label);
 864                unset($l_key);
 865            }
 866            
 867            if(!empty($calc_array)){
 868                foreach($calc_array as $label => $calc){
 869                    if(isset($used_vals[$label])){
 870                        $values[$used_vals[$label]] = ($values[$used_vals[$label]] / $calc);
 871                        
 872                        foreach($ids as $f_id){
 873                            $f_values[$f_id][$used_vals[$label]] = ($f_values[$f_id][$used_vals[$label]] / $calc);
 874                            unset($f_id);
 875                        }
 876                    }
 877                    
 878                    unset($label);
 879                    unset($calc);
 880                }
 881            }
 882            unset($used_vals);
 883        }
 884        
 885        $combine_dates = false;
 886        if((isset($x_field) and $x_field and $x_field->type == 'date') or in_array($x_axis, array('created_at', 'updated_at')))
 887            $combine_dates = apply_filters('frm_combine_dates', true, $x_field);
 888            
 889        if($combine_dates){
 890            if($include_zero){
 891                $start_timestamp = (empty($x_start)) ? time() : strtotime($x_start);
 892                $end_timestamp = (empty($x_end)) ? time() : strtotime($x_end);
 893                $dates_array = array();
 894                
 895                // Get the dates array
 896                for($e = $start_timestamp; $e <= $end_timestamp; $e += 60*60*24)
 897                    $dates_array[] = date('Y-m-d', $e);
 898                
 899                unset($e);
 900
 901                // Add the zero count days
 902                foreach($dates_array as $date_str){
 903                    if(!in_array($date_str, $labels)){
 904                        $labels[$date_str] = $date_str;
 905                        $values[$date_str] = 0;
 906                        foreach($ids as $f_id){
 907                            if(!isset($f_values[$f_id][$date_str]))
 908                                $f_values[$f_id][$date_str] = 0;
 909                        }
 910                    }
 911                }
 912                
 913                unset($dates_array);
 914                unset($start_timestamp);
 915                unset($end_timestamp);
 916            }
 917            
 918            asort($labels);
 919            
 920            global $frmpro_settings;
 921            foreach($labels as $l_key => $l){
 922                if((isset($x_field) and $x_field and $x_field->type == 'date') or in_array($x_axis, array('created_at', 'updated_at'))){
 923                    if ($type != 'pie' and preg_match('/^\d{4}-\d{2}-\d{2}$/', $l)){ 
 924                        global $frmpro_settings;
 925                        $labels[$l_key] = FrmProAppHelper::convert_date($l, 'Y-m-d', $frmpro_settings->date_format);
 926                    }
 927                }
 928                unset($l_key);
 929                unset($l);
 930            }
 931            
 932            $values = FrmProAppHelper::sort_by_array($values, array_keys($labels));
 933            foreach($ids as $f_id){
 934                $f_values[$f_id] = FrmProAppHelper::sort_by_array($f_values[$f_id], array_keys($labels));
 935                $f_values[$f_id] = FrmProAppHelper::reset_keys($f_values[$f_id]);
 936                ksort($f_values[$f_id]);
 937                unset($f_id);
 938            }
 939        }else{
 940            if(isset($x_inputs) and $x_inputs){
 941                foreach($labels as $l_key => $l){
 942                    foreach($ids as $f_id){
 943                        //do a last check to make sure all bars/lines have a value for each label
 944                        if(!isset($f_values[$f_id][$l_key]))
 945                            $f_values[$f_id][$l_key] = 0;
 946                        unset($fid);
 947                    }
 948                    unset($l_key);
 949                    unset($l);
 950                }
 951            }
 952            
 953            foreach($ids as $f_id){
 954                $f_values[$f_id] = FrmProAppHelper::reset_keys($f_values[$f_id]);
 955                ksort($f_values[$f_id]);
 956                unset($f_id);
 957            }
 958            
 959            ksort($labels);
 960            ksort($values);
 961        }
 962        
 963        $labels = FrmProAppHelper::reset_keys($labels);
 964        $values = FrmProAppHelper::reset_keys($values);
 965        
 966        $return = array('total_count' => count($inputs), 'f_values' => $f_values, 'labels' => $labels, 
 967            'values' => $values, 'pie' => $pie, 'combine_dates' => $combine_dates, 'ids' => $ids, 'cols' => $cols, 
 968            'rows' => $rows, 'options' => $options, 'fields' => $fields
 969        );
 970        
 971        if(isset($x_inputs))
 972            $return['x_inputs'] = $x_inputs;
 973            
 974        return $return;
 975    }
 976    
 977    function convert_to_google($rows, $cols, $options, $type){
 978        $gcontent = '';
 979        if(!empty($cols)){
 980            foreach((array)$cols as $col_name => $col){
 981                $gcontent .= "data.addColumn('". $col['type'] ."','{$col_name}');";
 982                unset($col_name);
 983                unset($col);
 984            }
 985        }
 986        
 987        if(!empty($rows)){
 988            if($type == 'table'){
 989                $last = end($rows);
 990                $count = $last[0]+1;
 991                $gcontent .= "data.addRows($count);\n";
 992                
 993                foreach($rows as $row){
 994                    $gcontent .= "data.setCell(". implode(',', $row). ");"; //data.setCell(0, 0, 'Mike');
 995                    unset($row);
 996                }
 997            }else{
 998                $gcontent .= "data.addRows(". json_encode($rows). ");\n";
 999            }
1000        }
1001        
1002        if(!empty($options))
1003            $gcontent .= "var options=". json_encode($options) ."\n";
1004
1005        return compact('gcontent', 'type');
1006    }
1007    
1008    function get_daily_entries($form, $colors=false, $type="DATE"){
1009        global $wpdb, $frmdb;
1010        
1011        if(!$colors)
1012            $colors = array('#EF8C08', '#21759B', '#1C9E05');
1013           
1014        $type = strtoupper($type); 
1015        //Chart for Entries Submitted
1016        $values = array();
1017        $labels = array();
1018        if($type == 'HOUR')
1019            $start_timestamp = strtotime('-48 hours');
1020        else if($type == 'MONTH')
1021            $start_timestamp = strtotime('-1 year');
1022        else if($type == 'YEAR')
1023            $start_timestamp = strtotime('-10 years');
1024        else
1025            $start_timestamp = strtotime('-1 month');
1026        $end_timestamp = time();
1027        
1028        if($type == 'HOUR'){
1029            $query = "SELECT en.created_at as endate,COUNT(*) as encount FROM $frmdb->entries en WHERE en.created_at >= '".date("Y-n-j H", $start_timestamp).":00:00' AND en.form_id=$form->id GROUP BY endate";
1030        }else{
1031            $query = "SELECT DATE(en.created_at) as endate,COUNT(*) as encount FROM $frmdb->entries en WHERE en.created_at >= '".date("Y-n-j", $start_timestamp)." 00:00:00' AND en.form_id=$form->id GROUP BY $type(en.created_at)";
1032        }
1033
1034        $entries_array = $wpdb->get_results($query);
1035
1036        $temp_array = $counts_array = $dates_array = array();
1037
1038        // Refactor Array for use later on
1039        foreach($entries_array as $e){
1040            $e_key = $e->endate;
1041            if($type == 'HOUR')
1042                $e_key = date('Y-m-d H', strtotime($e->endate)) .':00:00';
1043            else if($type == 'MONTH')
1044                $e_key = date('Y-m', strtotime($e->endate)) .'-01';
1045            else if($type == 'YEAR')
1046                $e_key = date('Y', strtotime($e->endate)) .'-01-01';
1047            $temp_array[$e_key] = $e->encount;
1048        }
1049        
1050        // Get the dates array
1051        if($type == 'HOUR'){
1052            for($e = $start_timestamp; $e <= $end_timestamp; $e += 60*60){
1053                if(!in_array(date('Y-m-d H', $e) .':00:00' , $dates_array))
1054                    $dates_array[] = date('Y-m-d H', $e) .':00:00';
1055            }
1056        
1057            $date_format = get_option('time_format');
1058        }else if($type == 'MONTH'){
1059            for($e = $start_timestamp; $e <= $end_timestamp; $e += 60*60*24*25){
1060                if(!in_array(date('Y-m', $e) .'-01', $dates_array))
1061                    $dates_array[] = date('Y-m', $e) .'-01';
1062            }
1063        
1064            $date_format = 'F Y';
1065        }else if($type == 'YEAR'){
1066            for($e = $start_timestamp; $e <= $end_timestamp; $e += 60*60*24*364){
1067                if(!in_array(date('Y', $e) .'-01-01', $dates_array))
1068                    $dates_array[] = date('Y', $e) .'-01-01';
1069            }
1070        
1071            $date_format = 'Y';
1072        }else{
1073            for($e = $start_timestamp; $e <= $end_timestamp; $e += 60*60*24)
1074                $dates_array[] = date("Y-m-d", $e);
1075
1076            $date_format = get_option('date_format');
1077        }
1078        
1079        // Make sure counts array is in order and includes zero click days
1080        foreach($dates_array as $date_str){
1081          if(isset($temp_array[$date_str]))
1082              $counts_array[$date_str] = $temp_array[$date_str];
1083          else
1084              $counts_array[$date_str] = 0;
1085        }
1086        
1087        foreach ($counts_array as $date => $count){
1088            $labels[] = date_i18n($date_format, strtotime($date));
1089            $values[] = (int)$count;
1090        }
1091
1092        
1093        if($type == 'MONTH')
1094            $title =  __('Monthly Entries', 'formidable');
1095        else if($type == 'YEAR')
1096            $title =  __('Yearly Entries', 'formidable');
1097        else if($type == 'HOUR')
1098            $title =  __('Hourly Entries', 'formidable');
1099        else
1100            $title =  __('Daily Entries', 'formidable');
1101            
1102        $title = new title( $title );
1103        
1104        $line_1_default_dot = new dot();
1105        $line_1_default_dot->colour($colors[0]);
1106        $line_1_default_dot->tooltip('#x_label#<br>#val# Entries');
1107        
1108        $line_1 = new line();
1109        $line_1->set_default_dot_style($line_1_default_dot);
1110        $line_1->set_values( $values );
1111        $line_1->set_colour( $colors[1] );
1112        
1113        $chart = new open_flash_chart();
1114        $chart->set_title( $title );
1115        $chart->set_bg_colour( '#FFFFFF' );
1116        
1117        $x = new x_axis();
1118        $x_labels = new x_axis_labels();
1119        $x_labels->rotate(340);
1120        $x_labels->set_labels( $labels );
1121        if(count($labels) > 15)
1122            $x_labels->visible_steps(2);
1123        $x->set_labels($x_labels);
1124        
1125        $chart->set_x_axis( $x );
1126        
1127        $y = new y_axis();
1128        if (!empty($values)){
1129            $max = max($values)+1;
1130            $step = ceil($max/10);
1131            $y->set_range(0, $max, $step);
1132        }
1133        $chart->add_element( $line_1 );
1134        $chart->set_y_axis( $y );
1135        
1136        return $chart->toPrettyString(); 
1137    }
1138    
1139    function google_graph($atts){
1140        $type = isset($atts['type']) ? $atts['type'] : 'default';
1141        
1142        $defaults = array(
1143            'id' => false, 'id2' => false, 'id3' => false, 'id4' => false, 'ids' => false,
1144            'include_js' => true, 'colors' => '', 'grid_color' => '#CCC', 
1145            'height' => 400, 'width' => 400, 'truncate_label' => 7,
1146            'bg_color' => '#FFFFFF', 'truncate' => 40, 'response_count' => 10, 'user_id' => false, 
1147            'type' => 'default', 'x_axis' => false, 'data_type' => 'count', 'limit' => '',
1148            'x_start' => '', 'x_end' => '', 'show_key' => false, 'min' => '', 'max' => '',
1149            'include_zero' => false
1150        );
1151        
1152        if($type == 'geo'){
1153            $defaults['truncate_label'] = 100;
1154            $defaults['width'] = 600;
1155        }
1156        
1157        extract(shortcode_atts($defaults, $atts));
1158        
1159        if (!$id) return;
1160        global $frm_field, $frm_google_chart;
1161        
1162        if(!$ids and ($id2 or $id3 or $id4)){
1163            $ids = array($id2, $id3, $id4);
1164            $ids = implode(',', $ids);
1165        }
1166 
1167        $x_axis = (!$x_axis or $x_axis == 'false') ? false : $x_axis;
1168        
1169        $user_id = FrmProAppHelper::get_user_id_param($user_id);
1170        
1171        $html = $js = $js_content2 = '';
1172        $fields = $frm_field->getAll("fi.id in ($id)");
1173        if(!empty($colors))
1174            $colors = explode(',', $colors);
1175        
1176        $js_content = '<script type="text/javascript">';
1177        if($include_js and !$frm_google_chart){
1178            $js_content = '<script type="text/javascript" src="https://www.google.com/jsapi"></script>';
1179            $js_content .= '<script type="text/javascript">';
1180            $js_content .= "google.load('visualization', '1.0', {'packages':['". ($type == 'geo' ? 'geochart' : 'corechart')."']});\n";
1181            if($type != 'geo')
1182                $frm_google_chart = true;
1183        }else if($type == 'geo'){
1184            $js_content .= "google.load('visualization', '1', {'packages': ['geochart']});\n";
1185        }
1186        
1187        global $frm_gr_count;
1188        if(!$frm_gr_count)
1189            $frm_gr_count = 0;
1190        foreach ($fields as $field){
1191            $data = $this->get_google_graph($field, compact('ids', 'colors', 'grid_color', 'bg_color', 'truncate', 'truncate_label', 'response_count', 'user_id', 'type', 'x_axis', 'data_type', 'limit', 'x_start', 'x_end', 'show_key', 'min', 'max', 'include_zero', 'width', 'height'));
1192            
1193            $frm_gr_count++;
1194            $this_id = $field->id .'_'. $frm_gr_count;
1195            $html .= '<div id="chart_'. $this_id .'" style="height:'.$height.';width:'.$width.'"></div>';
1196            $js_content2 .= "google.setOnLoadCallback(get_data_{$this_id});\n";
1197            $js_content2 .= "function get_data_{$this_id}(){var data=new google.visualization.DataTable();";
1198            $js_content2 .= $data['gcontent'];
1199            $js_content2 .= "var chart=new google.visualization.". ucfirst($data['type']) ."Chart(document.getElementById('chart_{$this_id}')); chart.draw(data, options);}";  
1200        }
1201            
1202        $js_content .= $js . $js_content2;
1203        $js_content .= '</script>';
1204        
1205        return

Large files files are truncated, but you can click here to view the full file