Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ************ FILE: player_management_system.php *******************
- <?php
- /*
- Plugin Name: player Management System (pms)
- Plugin URI: http://playermanagement.org/wp-content/plugins/player-management-system/
- Description: A brief description of the Plugin.
- Version: 0.1
- Author: Name
- Author URI: http://url.com/
- License: All Rights Reserved
- pms = player management system
- */
- global $pms_db_version;
- $pms_db_version = '1.0.0';
- if (!defined('pms_THEME_DIR'))
- define('pms_THEME_DIR', ABSPATH . 'wp-content/themes/' . get_template());
- if (!defined('pms_PLUGIN_NAME'))
- define('pms_PLUGIN_NAME', trim(dirname(plugin_basename(__FILE__)), '/'));
- if (!defined('pms_PLUGIN_DIR'))
- define('pms_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . pms_PLUGIN_NAME);
- if (!defined('pms_PLUGIN_URL'))
- define('pms_PLUGIN_URL', WP_PLUGIN_URL . '/' . pms_PLUGIN_NAME);
- if (!defined('pms_VERSION_KEY'))
- define('pms_VERSION_KEY', 'pms_version');
- if (!defined('pms_VERSION_NUM'))
- define('pms_VERSION_NUM', '1.0.0');
- //INCLUDE DEPENDENCIES
- include(pms_PLUGIN_DIR."/objects/class.Base.php");
- include(pms_PLUGIN_DIR."/objects/class.player.php");
- //SETUP
- function pms_install(){
- //Do some installation work
- global $wpdb;
- global $pms_db_version;
- $table_name = $wpdb->prefix . 'pms_players';
- $charset_collate = $wpdb->get_charset_collate();
- $sql = "CREATE TABLE $table_name (
- ChildID int(11) NOT NULL AUTO_INCREMENT,
- FirstName varchar(25) NOT NULL,
- MiddleName varchar(25) NULL,
- Surname varchar(45) NOT NULL,
- Gender tinyint(4) DEFAULT 0 NOT NULL,
- Birthdate date DEFAULT '0000-00-00' NOT NULL,
- RegionID int(11) DEFAULT 0 NOT NULL,
- Biography text NOT NULL,
- Status tinyint(4) DEFAULT 0 NOT NULL,
- DateAdded date DEFAULT '0000-00-00' NOT NULL,
- PictureFilename varchar(255) NULL,
- VideoFilename varchar(255) NULL,
- SiblingGroup tinyint(1) DEFAULT 0,
- PRIMARY KEY (ChildID),
- UNIQUE KEY ChildID (ChildID)
- ) $charset_collate;";
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
- dbDelta( $sql );
- $table_name = $wpdb->prefix . 'pms_regions';
- $charset_collate = $wpdb->get_charset_collate();
- $sql = "CREATE TABLE $table_name (
- `RegionID` int(11) NOT NULL AUTO_INCREMENT,
- `RegionName` varchar(50) NOT NULL DEFAULT '',
- PRIMARY KEY (`RegionID`)
- ) $charset_collate;";
- dbDelta( $sql );
- add_option( 'pms_db_version', $pms_db_version );
- add_option(pms_VERSION_KEY, pms_VERSION_NUM);
- }
- function pms_install_data() {
- global $wpdb;
- /* $welcome_name = 'Mr. WordPres';
- $welcome_text = 'Congratulations, you just completed the installation!';
- */
- /* $wpdb->insert(
- $table_name,
- array(
- 'time' => current_time( 'mysql' ),
- 'name' => $welcome_name,
- 'text' => $welcome_text,
- )
- ); */
- $table_name = $wpdb->prefix . 'pms_regions';
- $wpdb->query("INSERT INTO $table_name
- (`RegionID`, `RegionName`)
- VALUES
- (1,'Northeast'),
- (2,'East'),
- (3,'Knox'),
- (4,'Southeast'),
- (5,'Hamilton'),
- (6,'Upper Cumberland'),
- (7,'Mid Cumberland'),
- (8,'Davidson'),
- (9,'South Central'),
- (10,'Shelby'),
- (11,'Northwest'),
- (12,'Southwest');");
- }
- register_activation_hook(__FILE__,'pms_install');
- register_activation_hook(__FILE__,'pms_install_data');
- //SCRIPTS
- function pms_scripts(){
- wp_register_script('pms_script',plugin_dir_url( __FILE__ ).'js/pms.js');
- wp_enqueue_script('pms_script');
- }
- add_action('wp_enqueue_scripts','pms_scripts');
- //HOOKS
- add_action('init','pms_init');
- /********************************************************/
- /* FUNCTIONS
- ********************************************************/
- function pms_init(){
- //do work
- run_sub_process();
- }
- function run_sub_process(){
- //more work
- }
- /***************************************************
- * Settings menu
- ***************************************************/
- add_action('admin_menu', 'pms_admin_menu');
- function pms_admin_menu() {
- $page_title = 'player Management System Settings';
- $menu_title = 'player System';
- $capability = 'manage_options';
- $menu_slug = 'pms-settings';
- $function = 'pms_settings';
- add_options_page($page_title, $menu_title, $capability, $menu_slug, $function);
- }
- function pms_settings() {
- if (!current_user_can('manage_options')) {
- wp_die('You do aaa not have sufficient permissions to access this page.');
- }
- // Here is where you could start displaying the HTML needed for the settings
- // page, or you could include a file that handles the HTML output for you.
- echo "<h1>player Management System Settings</h1>";
- //echo "<p>Customize the player Management System here.</p>";
- echo "<p>No customization settings are necessary at this time.</p>";
- }
- add_action('admin_menu', 'pms_menu_pages');
- /***************************************************
- * pms menu
- ***************************************************/
- function pms_menu_pages() {
- // Add the top-level admin menu
- $page_title = 'pms List players';
- $menu_title = 'player System';
- $capability = 'manage_options';
- $menu_slug = 'pms-listplayers';
- $function = 'pms_listplayers';
- add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, 'dashicons-universal-access', 3);
- // Add submenu page with same slug as parent to ensure no duplicates
- $sub_menu_title = 'List players';
- add_submenu_page($menu_slug, $page_title, $sub_menu_title, $capability, $menu_slug, $function);
- // Now add the submenu page for Add player
- $submenu_page_title = 'pms Add player';
- $submenu_title = 'Add player';
- $submenu_slug = 'pms-addplayer';
- $submenu_function = 'pms_addplayer';
- add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $capability, $submenu_slug, $submenu_function);
- // Now add the submenu page for settings
- /* $submenu_page_title = 'pms Settings';
- $submenu_title = 'Settings';
- $submenu_slug = 'pms-settings';
- $submenu_function = 'pms_settings';
- add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $capability, $submenu_slug, $submenu_function);
- */
- // Now add the submenu page for Help
- $submenu_page_title = 'pms Help';
- $submenu_title = 'Help';
- $submenu_slug = 'pms-help';
- $submenu_function = 'pms_help';
- add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $capability, $submenu_slug, $submenu_function);
- }
- /* SEE ABOVE function pms_settings() {} */
- function pms_listplayers() {
- if (!current_user_can('manage_options')) {
- wp_die('You do asdsad not have sufficient permissions to access this page.');
- }
- //Create player object
- $player = new player(0);
- // Render the HTML for Listing the players
- echo "<div class=\"wrap\">";
- echo "<h2>player Management System - List players</h2>";
- //echo "<p>List of all players goes here.</p>";
- echo "<form id=\"players-filter\" method=\"get\" action=\"\">";
- $player->listAllplayers();
- if($player->hasErrors()){
- $player->showErrors();
- }
- //@submit_button();
- echo "</form>";
- echo "<br class=\"clear\" />";
- echo "</div>";
- }
- function pms_addplayer() {
- if (!current_user_can('manage_options')) {
- wp_die('You do dfdfdnot have sufficient permissions to access this page.');
- }
- //Create player object
- $player = new player(0);
- // Render the HTML for the Help page or include a file that does
- echo "<h1>player Management System - Add player</h1>";
- echo "<p>Form to add a new player goes here.</p>";
- $player->addeditform();
- }
- function pms_help() {
- if (!current_user_can('manage_options')) {
- wp_die('You do dfs2 not have sufficient permissions to access this page.');
- }
- // Render the HTML for the Help page or include a file that does
- echo "<h1>player Management System Help</h1>";
- echo "<p>This explains how to use the player Management System.</p>";
- }
- ?>
- ************ FILE: class.Player.php *******************
- <?php /*
- FILENAME: class.player.php
- PROJECT: Player Management System
- DESCRIPTION: Object for managing players
- AUTHOR: name
- CREATION DATE: March 2015
- MODIFIED BY/ON:
- VARIABLES:
- */ ?>
- <?php
- class player extends Base{
- private $_resultset;
- private $uploaddir;
- public $_playerid;
- //form variables
- public function __construct($playerid){
- $this->_playerid = $playerid;
- $this->uploaddir = wp_upload_dir();
- //$this->_errors[] = 'broken2';
- }
- public function getAllplayers(){
- global $wpdb;
- $pms_players_table = $wpdb->prefix . 'pms_players'; //Good practice
- $pms_regions_table = $wpdb->prefix . 'pms_regions'; //Good practice
- $this->_resultset = $wpdb->get_results( "
- select
- a.ChildID,
- a.FirstName,
- a.MiddleName,
- a.Surname,
- a.Gender,
- a.Birthdate,
- a.SiblingGroup,
- a.RegionID,
- a.Biography,
- a.Status,
- a.VideoFilename,
- r.RegionName
- from $pms_players_table a
- left outer join $pms_regions_table r
- on a.RegionID = r.RegionID
- order by a.ChildID DESC;
- ");
- //$videofilename = $randomProfile[0]->VideoFilename;
- //$picturefilename = $randomProfile[0]->PictureFilename;
- }
- public function listAllplayers(){
- $this->getAllplayers();
- //print_r($this->_resultset);
- $numberofcolumns = 9;
- ?>
- <div id="playerslistcontainer">
- <table id="currentplayers" class="wp-list-table widefat fixed players">
- <thead>
- <tr>
- <th>
- ID
- </th>
- <th>
- Status
- </th>
- <th>
- Video?
- </th>
- <th>
- Name
- </th>
- <th>
- Gender
- </th>
- <th>
- Age
- </th>
- <th>
- Sib Grp
- </th>
- <th>
- Region
- </th>
- <th>
- Edit/Delete
- </th>
- </tr>
- </thead>
- <?php
- foreach($this->_resultset as $row){
- echo "<tr>";
- echo "<td>".$row->ChildID."</td>";
- echo "<td>";
- switch(intval($row->Status)){
- case 0: // Inactive
- echo "Inactive";
- break;
- case 1: // Active
- echo "Active";
- break;
- case 2: // Placement pending
- echo "Placement pending";
- break;
- case 3: // player pending
- echo "player pending";
- break;
- default: // unknown
- echo "Unknown";
- }
- echo "</td>";
- echo "<td>";
- if(strlen(trim($row->VideoFilename))
- && file_exists($this->uploaddir['baseurl']."/videos/".$row->VideoFilename)){
- echo "Yes";
- } else {
- echo "No";
- }
- echo "</td>";
- echo "<td>";
- $childname = trim($row->FirstName)." ".trim($row->MiddleName);
- $childname = trim($childname)." ".trim($row->Surname);
- $childname = trim($childname);
- echo $childname;
- echo "</td>";
- echo "<td>";
- switch(intval($row->Gender)){
- case 0: //Female
- echo "Female";
- break;
- case 1: //Male
- echo "Male";
- break;
- default: //Unknown
- echo "Unknown";
- }
- echo "</td>";
- echo "<td title=\"".date("M d Y",strtotime($row->Birthdate))."\">";
- echo intval((time() - strtotime($row->Birthdate))/60/60/24/365);
- echo "</td>";
- echo "<td>";
- switch($row->SiblingGroup){
- case 1:
- echo "Yes";
- break;
- case 0:
- echo "No";
- break;
- }
- echo "</td>";
- echo "<td>".$row->RegionName."</td>";
- echo "<td>Edit / Delete</td>";
- echo "</tr>";
- }
- ?>
- </table>
- </div>
- <?php
- }
- public function addeditform(){
- echo "<p>form here</p>";
- echo "<form id=\"players-frmaddedit\" method=\"post\" action=\"".admin_url( )."?page=pms-addplayer\">";
- if ( function_exists('wp_nonce_field') )
- wp_nonce_field('player-managemet-system-action_pms-addplayer');
- //@settings_fields('wp_plugin_template-group');
- //@do_settings_fields('wp_plugin_template-group');
- echo "<input type=\"hidden\" name=\"action\" value=\"pms-addplayer\" />";
- @submit_button('Add player');
- echo "</form>";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement