=== Lista de Inscritos ===
== Installation ==
/**
* Plugin Name: Lista de Inscritos
* Plugin URI: http://localhost/
* Description: Plugin para gerenciar lista dos inscritos nas corridas
* Version: 1.0 or whatever version of the plugin (pretty self explanatory)
* Author: Henrique Wilson
* Author URI: http://henriquewilson.com.br
* License: A "Slug" license name e.g. GPL12
*/
// EVENTOS DB
global $jal_db_version;
$jal_db_version = '1.0';
function jal_install() {
global $wpdb;
global $jal_db_version;
$table_name = $wpdb->prefix . 'inscritos';
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
time datetime DEFAULT '0000-00-00 00:00:00',
modalidade text ,
evento_id mediumint(9) ,
nome text ,
telefone text ,
celular text ,
sexo text ,
nascimento text ,
email text ,
rg text ,
cpf text ,
cep text ,
endereco text ,
numero text ,
cidade text ,
estado text ,
nome_contato text ,
telefone_contato text ,
celular_contato text ,
pais text ,
complemento text ,
profissao text ,
equipe text ,
UNIQUE KEY id (id)
) $charset_collate;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
add_option( 'jal_db_version', $jal_db_version );
}
register_activation_hook( __FILE__, 'jal_install' );
class PageSubscribers {
protected $plugin_slug;
private static $instance;
protected $templates;
public static function get_instance() {
if( null == self::$instance ) {
self::$instance = new PageSubscribers();
}
return self::$instance;
}
private function __construct() {
$this->templates = array();
// Add a filter to the attributes metabox to inject template into the cache.
add_filter(
'page_attributes_dropdown_pages_args',
array( $this, 'register_project_templates' )
);
// Add a filter to the save post to inject out template into the page cache
add_filter(
'wp_insert_post_data',
array( $this, 'register_project_templates' )
);
// Add a filter to the template include to determine if the page has our
// template assigned and return it's path
add_filter(
'template_include',
array( $this, 'view_project_template')
);
// Add your templates to this array.
$this->templates = array(
'report-template.php' => 'Relatórios de inscritos',
);
}
/**
* Adds our template to the pages cache in order to trick WordPress
* into thinking the template file exists where it doens't really exist.
*
*/
public function register_project_templates( $atts ) {
// Create the key used for the themes cache
$cache_key = 'page_templates-' . md5( get_theme_root() . '/' . get_stylesheet() );
// Retrieve the cache list.
// If it doesn't exist, or it's empty prepare an array
$templates = wp_get_theme()->get_page_templates();
if ( empty( $templates ) ) {
$templates = array();
}
// New cache, therefore remove the old one
wp_cache_delete( $cache_key , 'themes');
// Now add our template to the list of templates by merging our templates
// with the existing templates array from the cache.
$templates = array_merge( $templates, $this->templates );
// Add the modified cache to allow WordPress to pick it up for listing
// available templates
wp_cache_add( $cache_key, $templates, 'themes', 1800 );
return $atts;
}
/**
* Checks if the template is assigned to the page
*/
public function view_project_template( $template ) {
global $post;
if (!isset($this->templates[get_post_meta($post->ID, '_wp_page_template', true)])){
return $template;
}
$file = plugin_dir_path(__FILE__). get_post_meta(
$post->ID, '_wp_page_template', true
);
// Just to be safe, we check if the file exist first
if( file_exists( $file ) ) {
return $file;
} else { echo $file; }
return $template;
}
}
add_action( 'plugins_loaded', array( 'PageSubscribers', 'get_instance' ) );
add_action( 'init', 'addRewritesHW' );
function addRewritesHW() {
add_rewrite_endpoint( "xls-download", EP_PERMALINK );
add_feed( "xls-download", 'xls_download' );
}
function xls_download() {
$evento_id = $_GET['id'];
$eventoNome = get_the_title( $evento_id );
header("Content-type: application/vnd-ms-excel");
header("Content-Disposition: attachment; filename=$eventoNome.xls");
global $wpdb;
$table_name = $wpdb->prefix . 'inscritos';
$subscribList = $wpdb->get_results( "SELECT * FROM $table_name WHERE evento_id='$evento_id' ORDER BY modalidade ", OBJECT );
echo '';
echo '
';
$modalidade = "";
foreach ($subscribList as $key => $item) :
if ($modalidade != $item->modalidade) :
$modalidade = $item->modalidade;
?>