Plugin Directory

Changeset 795003


Ignore:
Timestamp:
10/28/2013 09:04:18 PM (12 years ago)
Author:
ajferg
Message:

1.7.0

  • Now including a graph before displaying logs in admin area, to show leads over time.
Location:
tailored-tools
Files:
34 added
4 edited

Legend:

Unmodified
Added
Removed
  • tailored-tools/trunk/form.contact.php

    r752666 r795003  
    2323    public      $avail_ayah     = true;
    2424    public      $check_bad_words= true;
     25   
     26    public      $show_graph     = true;
    2527   
    2628   
  • tailored-tools/trunk/lib/class.forms.php

    r752666 r795003  
    2626    public      $shortcode      = 'FormShortcode';
    2727    public      $log_type       = false;            // False to disable logging, or post-type
     28    public      $show_graph     = false;            // Embed a graph before results to show leads over time
    2829    public      $submit_key     = 'submit_form';    // submit button key - for processing.
    2930    public      $submit_label   = 'Submit Form';
     
    621622            echo '<div class="updated"><p>Settings have been saved.</p></div>'."\n";
    622623        }
     624        // Show graph
     625        if ($this->log_type)    $this->admin_graph_logs();
    623626        // Show & Save logged submissions
    624627        if ($this->log_type)    $this->admin_list_logs();
     
    704707   
    705708   
     709   
     710    /**
     711     *  Graph our enquiries over time.
     712     */
     713    function admin_graph_logs() {
     714        if (!$this->show_graph || !$this->log_type)     return false;
     715        wp_enqueue_script('google-jsapi', '//www.google.com/jsapi', false, false, true);
     716        wp_enqueue_script('jquery-ui-datepicker');
     717        wp_enqueue_style('ui-datepicker', '//ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css');
     718        add_action('admin_print_footer_scripts', array($this,'admin_graph_js'));
     719       
     720        if ($_REQUEST['date_from']) {   $_REQUEST['date_from'] = date('M j, Y', strtotime( $_REQUEST['date_from'] ));   }
     721        if ($_REQUEST['date_to']) { $_REQUEST['date_to'] = date('M j, Y', strtotime( $_REQUEST['date_to'] ));   }
     722       
     723       
     724        if (empty($_REQUEST['date_from']))  $_REQUEST['date_from'] = date('M j, Y', strtotime("-30 days"));
     725        if (empty($_REQUEST['date_to']))    $_REQUEST['date_to'] = date('M j, Y');
     726       
     727        global $wpdb;
     728        $total_leads = $wpdb->get_var("
     729            SELECT COUNT( * ) AS `num_leads`
     730            FROM `{$wpdb->posts}`
     731            WHERE `post_type` = '{$this->log_type}'
     732              AND DATE(`post_date`) BETWEEN '".date('Y-m-d',strtotime($_REQUEST['date_from']))."' AND '".date('Y-m-d',strtotime($_REQUEST['date_to']))."'
     733        ");
     734        ?>
     735        <div id="graph">
     736            <p class="total_leads">Number of leads for selected time period: <?php echo $total_leads; ?></p>
     737            <div class="ranges">
     738            <form method="POST">
     739                <p><label><span>From:</span> <input type="text" name="date_from" value="<?php echo $_REQUEST['date_from']; ?>" /></label></p>
     740                <p><label><span>To:</span> <input type="text" name="date_to" value="<?php echo $_REQUEST['date_to']; ?>" /></label></p>
     741                <p class="submit"><input class="button-primary" type="submit" value="Go" /></p>
     742            </form>
     743            </div>
     744            <div id="chart"></div>
     745        </div>
     746<style><!--
     747#graph { background:#FFF; margin:1em 0.5em 2em; padding:0.5em; border:1px solid #DFDFDF; border-radius:0.3em; }
     748#graph p.total_leads { float:left; margin:0; padding:0.5em 0 0; }
     749#graph .ranges { text-align:right; }
     750#graph .ranges p { display:inline-block; margin:0 1em 0; padding:0; }
     751#graph .ranges p input { cursor:pointer; }
     752--></style>
     753        <?php
     754    }
     755   
     756    function admin_graph_js() {
     757        global $wpdb;
     758        $data = array();
     759        $date  = $_REQUEST['date_from'];
     760        $loop = 0;
     761        while (strtotime($date) <= strtotime($_REQUEST['date_to'])) {
     762            $result = $wpdb->get_results("
     763                SELECT COUNT( * ) AS `num_leads`, DATE(`post_date`) AS `date`
     764                FROM `{$wpdb->posts}`
     765                WHERE `post_type` = '{$this->log_type}'
     766                  AND DATE(`post_date`) = '".date('Y-m-d',strtotime($date))."';
     767            ");
     768            $data[] = array(   
     769                'Date'  => date('jS M Y', strtotime($date)),   
     770                'Leads' => $result[0]->num_leads,
     771            );
     772            $date = date('Y-m-d', strtotime("+1 day", strtotime($date)));
     773
     774        }
     775        ?>
     776<script type="text/javascript"><!--
     777jQuery(document).ready(function($){
     778    $('#graph .ranges label input').datepicker({ numberOfMonths:3, showButtonPanel:true, dateFormat:'M d, yy' });
     779});
     780
     781google.load('visualization', '1.0', {'packages':['corechart']});
     782google.setOnLoadCallback(drawChart);
     783function drawChart() {
     784   
     785    var data = google.visualization.arrayToDataTable([
     786        ['Day', 'Leads'],
     787        <?php
     788        foreach ($data as $row) {
     789            echo "['".$row['Date']."', ".$row['Leads']." ],";
     790        }
     791        ?>
     792       
     793    ]);
     794   
     795    var options = {
     796        title:  "Leads per day",
     797    };
     798   
     799    var chart = new google.visualization.LineChart(document.getElementById('chart'));
     800    chart.draw(data, options);
     801}
     802--></script>
     803        <?php
     804    }
     805   
     806   
    706807    /**
    707808     *  Extend this if you want to list logged submissions
     
    722823        <?php
    723824    }
     825   
     826   
     827   
    724828   
    725829   
     
    811915
    812916
    813 
    814 
    815 
    816 
    817917?>
  • tailored-tools/trunk/readme.txt

    r752666 r795003  
    33Tags:               
    44Requires at least:  3.0
    5 Tested up to:       3.6
    6 Stable tag:         1.6
     5Tested up to:       3.7
     6Stable tag:         1.7
    77
    88Contains some helper classes to help you build custom forms.
     
    5454
    5555== Changelog ==
     56= 1.7 =
     57* Now including a graph before displaying logs in admin area, to show leads over time.
    5658
    5759= 1.6 =
  • tailored-tools/trunk/tools.php

    r752666 r795003  
    33Plugin Name:    Tailored Tools
    44Description:    Adds some functionality to WordPress that you'll need.  (Version 1.5+ has different style rules. Do not upgrade without checking these.)
    5 Version:        1.6
     5Version:        1.7
    66Author:         Tailored Web Services
    77Author URI:     http://www.tailored.com.au
Note: See TracChangeset for help on using the changeset viewer.