add( Image_Graph::vertical( Image_Graph::factory('title', array($current_user->first_name." $current_user->last_name:"."$table_name", 12)), Image_Graph::vertical( $Plotarea = Image_Graph::factory('plotarea'), $Legend = Image_Graph::factory('legend'), 90 ), 10 ) ); $Legend->setPlotarea($Plotarea); $activities=$wpdb->get_col("SELECT DISTINCT activity FROM ".$table_prefix."abagraph WHERE user_id={$current_user->data->ID} and table_id=$table_id ORDER by activity ASC"); $num_activities=sizeof($activities); $colors=array('blue','red','fuchsia','lawngreen','purple'); for($i=0;$i<=$num_activities-1;$i+=1){ $datings[$i]=$wpdb->get_results("SELECT stamp,value FROM ".$table_prefix."abagraph WHERE user_id={$current_user->data->ID} and activity='$activities[$i]' and table_id=$table_id ORDER by activity ASC, stamp ASC"); $Dataset[$i] =& Image_Graph::factory('dataset'); if ($activities[$i] == "Generalization"){ $Plot[$i] =& $Plotarea->addNew('Image_Graph_Plot_Dot', array(&$Dataset[$i])); $Marker1 =& Image_Graph::factory('Image_Graph_Marker_Triangle'); $Marker1->setFillColor('green'); $Marker1->setLineColor('black'); $Plot[$i]->setMarker($Marker1); $Plot[$i]->setTitle($activities[$i]); } else if ($activities[$i] == "Interobserver Agreement"){ $Plot[$i] =& $Plotarea->addNew('Image_Graph_Plot_Dot', array(&$Dataset[$i])); $Marker2 =& Image_Graph::factory('Image_Graph_Marker_Plus'); $Marker2->setFillColor('yellow'); $Marker2->setLineColor('black'); $Plot[$i]->setMarker($Marker2); $Plot[$i]->setTitle($activities[$i]); } else if ($activities[$i] == "Baseline"){ $Plot[$i] =& $Plotarea->addNew('Plot_Impulse', array(&$Dataset[$i])); $Plot[$i]->setLineColor('gold'); $Plot[$i]->setTitle($activities[$i]); } else if ($activities[$i] == "Condition Line"){ $Plot[$i] =& $Plotarea->addNew('Plot_Impulse', array(&$Dataset[$i])); $Plot[$i]->setLineColor('brown'); $Plot[$i]->setTitle($activities[$i]); } else if ($activities[$i] == "Criteria Line"){ $Plot[$i] =& $Plotarea->addNew('line', array(&$Dataset[$i])); $Plot[$i]->setLineColor('brown'); $Plot[$i]->setTitle($activities[$i]); } else if ($activities[$i] == "Pretest"){ $Plot[$i] =& $Plotarea->addNew('Image_Graph_Plot_Dot', array(&$Dataset[$i])); $Marker2 =& Image_Graph::factory('Image_Graph_Marker_Asterisk'); $Marker2->setFillColor('cyan'); $Marker2->setSize(6); $Marker2->setLineColor('cyan'); $Plot[$i]->setMarker($Marker2); $Plot[$i]->setTitle($activities[$i]); } else if ($activities[$i] == "Pretest|"){ $Plot[$i] =& $Plotarea->addNew('Plot_Impulse', array(&$Dataset[$i])); $Plot[$i]->setLineColor('cyan'); $Plot[$i]->setTitle($activities[$i]); } else { $linestyle =& Image_Graph::factory('Image_Graph_Line_Solid',array_shift($colors)); $linestyle->setThickness(3); $Plot[$i] =& $Plotarea->addNew('line', array(&$Dataset[$i])); $Plot[$i]->setLineStyle($linestyle); $Plot[$i]->setTitle($activities[$i]); } foreach ($datings[$i] as $daty){ $Dataset[$i]->addPoint($daty->stamp, $daty->value); } } $Font =& $Graph->addNew('ttf_font', '/usr/share/fonts/truetype/freefont/FreeMonoBold'); $Font->setSize(12); $Graph->setFont($Font); $Plotarea->Image_Graph_Plotarea('Image_Graph_Axis','Image_Graph_Axis'); $Plotarea->setAxisPadding(5, 'bottom'); $Plotarea->setAxisPadding(25, 'left'); $Plotarea->setAxisPadding(25, 'right'); $Plotarea->setAxisPadding(25, 'top'); $YAxis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y); $XAxis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X); $XAxis->setTitle('Date'); include_once 'Image/Graph/DataPreprocessor/Date.php'; $dateFormatter = new Image_Graph_DataPreprocessor_Date("m/d"); $XAxis->setDataPreProcessor(&$dateFormatter); $Graph->done( array('filename' => '../wp-content/uploads/'.$current_user->user_login.''.$table_id.'_abagraph.png') ); } function get_table_name_abagraph($table_id) { global $wpdb,$current_user; $table_name = $wpdb->get_var("SELECT DISTINCT table_name FROM {$wpdb->prefix}abagraph WHERE user_id={$current_user->data->ID} and table_id=$table_id;"); return $table_name; } function abagraph_install() { global $wpdb; if (!current_user_can('activate_plugins')) return; $table_name1 = $wpdb->prefix . 'abagraph'; $table_name2 = $wpdb->prefix . 'activities'; // if activities table doesn't exist, create it if ( $wpdb->get_var("show tables like '$table_name2'") != $table_name2) { $sql= "CREATE TABLE $table_name2 ( ID bigint(20) PRIMARY KEY AUTO_INCREMENT, activity varchar(250) NOT NULL, UNIQUE KEY activity (activity))"; require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); dbDelta($sql); $insert_sql = "INSERT INTO $table_name2 (ID,activity) values (1,'Generalization'),(2,'Interobserver Agreement'),(3,'Pretest'),(4,'Baseline'),(5,'Pretest|'),(6,'Criteria Line'),(7,'Condition Line');"; $wpdb->query($insert_sql); } // if abagraph table doesn't exist, create it if ( $wpdb->get_var("show tables like '$table_name1'") != $table_name1 ) { $sql = "CREATE TABLE $table_name1 ( id int PRIMARY KEY AUTO_INCREMENT, activity varchar(250) NOT NULL, user_id bigint(20) NOT NULL, table_id int NOT NULL, table_name varchar(250) NOT NULL, stamp int NOT NULL, value double NOT NULL)"; require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); dbDelta($sql); } } register_activation_hook(__FILE__,'abagraph_install'); function aba_managePanel() { if (function_exists('add_management_page')) { add_management_page('ABAgraph','ABAgraph',7,basename(__FILE__),'aba_show_manage_panel'); } } add_action('admin_menu','aba_managePanel'); function aba_show_manage_panel() { global $wpdb, $current_user, $wp_version; $table_prefix = $wpdb->prefix; if (isset($_GET['abagraph_delete'])) { $item_id = $_GET['abagraph_delete']; $table_id=$wpdb->get_var("SELECT table_id FROM ".$table_prefix."abagraph WHERE id=".$item_id." AND user_id={$current_user->data->ID}"); $sql = "DELETE FROM ".$table_prefix."abagraph WHERE id=".$item_id." AND user_id=".$current_user->data->ID; $wpdb->query($sql); } if (isset($_POST['abagraph_value'])) { // insert data here $date = strtotime($_POST['abagraph_year']."-".$_POST['abagraph_month']."-".$_POST['abagraph_day']); $value = $wpdb->escape($_POST['abagraph_value']); $table_id = array_shift(split(':',$wpdb->escape($_POST['abagraph_table_id']))); $table_name = trim(array_pop(split(':',$wpdb->escape($_POST['abagraph_table_id'])))); $activity = $wpdb->escape($_POST['abagraph_activity']); $sql = "INSERT INTO ".$table_prefix."abagraph (activity, user_id, table_id, table_name, stamp, value) values ('$activity',{$current_user->data->ID},$table_id,'$table_name',$date,$value)"; if (!empty($value)){ $wpdb->query($sql); } $table_name=get_table_name_abagraph($table_id); if (empty($table_name)) { ?>
user_login."; ?>

