description = __("The add-on adds a widget to display a list of upcoming appointments in the dashboard welcome page.", 'appointment-hour-booking' ); // Check if the plugin is active if( !$this->addon_is_active() ) return; add_action('wp_dashboard_setup', array(&$this, 'add_dashboard_widgets') ); } // End __construct public function add_dashboard_widgets() { wp_add_dashboard_widget('dashboard_widget', 'Appointment Hour Booking: Upcoming appointments', array(&$this, 'pp_DashboardWidget')); } /************************ PRIVATE METHODS *****************************/ /************************ PUBLIC METHODS *****************************/ /** * print list */ public function pp_DashboardWidget($atts = array()) { global $wpdb, $cp_appb_plugin; extract( shortcode_atts( array( 'calendar' => '', 'showdelete' => '0', 'columnlabels' => 'TIME,SERVICE,data', 'columns' => 'TIME,SERVICE,data', 'datefrom' => 'today', 'dateto' => 'today +1 month', 'paidonly' => "", 'maxitems' => "10", 'datelabel' => __('Date', 'appointment-hour-booking'), 'status' => "-1" ), $atts ) ); $buffer = '
'.__('Next','appointment-hour-booking')." ".$maxitems." ".__('upcoming appointments:','appointment-hour-booking')."
"; wp_enqueue_script( "jquery" ); $cond = '1=1'; if ($calendar) $cond .= " AND formid=".intval($calendar); // calculate dates $from = date("Y-m-d",strtotime($datefrom)); $to = date("Y-m-d",strtotime($dateto)); $events_query = "SELECT * FROM ".$wpdb->prefix.$cp_appb_plugin->table_messages. " WHERE ".$cond." ORDER BY time DESC"; $events = $wpdb->get_results($events_query); // pre-select time-slots $selection = array(); foreach($events as $item) { $data = unserialize($item->posted_data); if (!$paidonly || $data['paid']) { foreach($data["apps"] as $app) if ($app["date"] >= $from && $app["date"] <= $to && ($status == '-1' || $status == $app["cancelled"]) && $app["cancelled"] != 'Cancelled' && $app["cancelled"] != 'Cancelled by customer') { $selection[] = array($app["date"]." ".$app["slot"], $app["date"], $app["slot"], $data, $item->notifyto, $item->data, $app["cancelled"], $app["service"]); } } } // order time-slots function listgroupd_addon_appbkfastsortfn($a, $b) { return ($a[0] > $b[0]); } usort($selection, "listgroupd_addon_appbkfastsortfn" ); // clean fields IDs $fields = explode(",",trim($columns)); for($j=0; $j'; $buffer .= ''.$lastdate.''; $buffer .= ''; $colnum = 0; foreach ($columnlabels as $item) { $colnum++; $buffer .= ''.trim($item).''; } if ($showdelete) $buffer .= ''; $buffer .= ''; } $buffer .= ''; for($j=0; $j'.$this->make_links_clickable(trim($value), is_array(@$params[$item]) ).''; } if ($showdelete) $buffer .= '['.__('delete','appointment-hour-booking').']'; $buffer .= ''; } $buffer .= ''; echo $buffer; } // end pp_DashboardWidget private function make_links_clickable($text, $is_upload) { $link = preg_replace('!(((f|ht)tp(s)?://)[-a-zA-Zа-яА-Я()0-9@:%_+.~#?&;//=]+)!i', '*LLLK*', $text); if ($is_upload) $link = str_replace('*LLLK*', basename($text), $link); else $link = str_replace('*LLLK*', $text, $link); return $link; } /** * log */ private function _log($adarray = array()) { $h = fopen( __DIR__.'/logs.txt', 'a' ); $log = ""; foreach( $_REQUEST as $KEY => $VAL ) { $log .= $KEY.": ".$VAL."\n"; } foreach( $adarray as $KEY => $VAL ) { $log .= $KEY.": ".$VAL."\n"; } $log .= "================================================\n"; fwrite( $h, $log ); fclose( $h ); } } // End Class // Main add-on code $CPAPPB_DashboardWidget_obj = new CPAPPB_DashboardWidget(); // Add addon object to the objects list global $cpappb_addons_objs_list; $cpappb_addons_objs_list[ $CPAPPB_DashboardWidget_obj->get_addon_id() ] = $CPAPPB_DashboardWidget_obj; } ?>