Advertisement
djuggler

Untitled

Mar 21st, 2015
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.02 KB | None | 0 0
  1. ************ FILE: player_management_system.php *******************
  2. <?php
  3. /*
  4. Plugin Name: player Management System (pms)
  5. Plugin URI: http://playermanagement.org/wp-content/plugins/player-management-system/
  6. Description: A brief description of the Plugin.
  7. Version: 0.1
  8. Author: Name
  9. Author URI: http://url.com/
  10. License: All Rights Reserved
  11.  
  12. pms = player management system
  13. */
  14.  
  15. global $pms_db_version;
  16. $pms_db_version = '1.0.0';
  17.  
  18. if (!defined('pms_THEME_DIR'))
  19. define('pms_THEME_DIR', ABSPATH . 'wp-content/themes/' . get_template());
  20.  
  21. if (!defined('pms_PLUGIN_NAME'))
  22. define('pms_PLUGIN_NAME', trim(dirname(plugin_basename(__FILE__)), '/'));
  23.  
  24. if (!defined('pms_PLUGIN_DIR'))
  25. define('pms_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . pms_PLUGIN_NAME);
  26.  
  27. if (!defined('pms_PLUGIN_URL'))
  28. define('pms_PLUGIN_URL', WP_PLUGIN_URL . '/' . pms_PLUGIN_NAME);
  29.  
  30. if (!defined('pms_VERSION_KEY'))
  31. define('pms_VERSION_KEY', 'pms_version');
  32.  
  33. if (!defined('pms_VERSION_NUM'))
  34. define('pms_VERSION_NUM', '1.0.0');
  35.  
  36. //INCLUDE DEPENDENCIES
  37. include(pms_PLUGIN_DIR."/objects/class.Base.php");
  38. include(pms_PLUGIN_DIR."/objects/class.player.php");
  39.  
  40. //SETUP
  41. function pms_install(){
  42. //Do some installation work
  43. global $wpdb;
  44. global $pms_db_version;
  45.  
  46. $table_name = $wpdb->prefix . 'pms_players';
  47.  
  48. $charset_collate = $wpdb->get_charset_collate();
  49.  
  50. $sql = "CREATE TABLE $table_name (
  51. ChildID int(11) NOT NULL AUTO_INCREMENT,
  52. FirstName varchar(25) NOT NULL,
  53. MiddleName varchar(25) NULL,
  54. Surname varchar(45) NOT NULL,
  55. Gender tinyint(4) DEFAULT 0 NOT NULL,
  56. Birthdate date DEFAULT '0000-00-00' NOT NULL,
  57. RegionID int(11) DEFAULT 0 NOT NULL,
  58. Biography text NOT NULL,
  59. Status tinyint(4) DEFAULT 0 NOT NULL,
  60. DateAdded date DEFAULT '0000-00-00' NOT NULL,
  61. PictureFilename varchar(255) NULL,
  62. VideoFilename varchar(255) NULL,
  63. SiblingGroup tinyint(1) DEFAULT 0,
  64. PRIMARY KEY (ChildID),
  65. UNIQUE KEY ChildID (ChildID)
  66.  
  67. ) $charset_collate;";
  68.  
  69. require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
  70. dbDelta( $sql );
  71.  
  72.  
  73. $table_name = $wpdb->prefix . 'pms_regions';
  74.  
  75. $charset_collate = $wpdb->get_charset_collate();
  76.  
  77. $sql = "CREATE TABLE $table_name (
  78. `RegionID` int(11) NOT NULL AUTO_INCREMENT,
  79. `RegionName` varchar(50) NOT NULL DEFAULT '',
  80. PRIMARY KEY (`RegionID`)
  81. ) $charset_collate;";
  82.  
  83. dbDelta( $sql );
  84.  
  85. add_option( 'pms_db_version', $pms_db_version );
  86. add_option(pms_VERSION_KEY, pms_VERSION_NUM);
  87. }
  88.  
  89. function pms_install_data() {
  90. global $wpdb;
  91.  
  92. /* $welcome_name = 'Mr. WordPres';
  93. $welcome_text = 'Congratulations, you just completed the installation!';
  94. */
  95. /* $wpdb->insert(
  96. $table_name,
  97. array(
  98. 'time' => current_time( 'mysql' ),
  99. 'name' => $welcome_name,
  100. 'text' => $welcome_text,
  101. )
  102. ); */
  103.  
  104. $table_name = $wpdb->prefix . 'pms_regions';
  105.  
  106. $wpdb->query("INSERT INTO $table_name
  107. (`RegionID`, `RegionName`)
  108. VALUES
  109. (1,'Northeast'),
  110. (2,'East'),
  111. (3,'Knox'),
  112. (4,'Southeast'),
  113. (5,'Hamilton'),
  114. (6,'Upper Cumberland'),
  115. (7,'Mid Cumberland'),
  116. (8,'Davidson'),
  117. (9,'South Central'),
  118. (10,'Shelby'),
  119. (11,'Northwest'),
  120. (12,'Southwest');");
  121.  
  122. }
  123.  
  124. register_activation_hook(__FILE__,'pms_install');
  125. register_activation_hook(__FILE__,'pms_install_data');
  126.  
  127.  
  128.  
  129.  
  130. //SCRIPTS
  131. function pms_scripts(){
  132. wp_register_script('pms_script',plugin_dir_url( __FILE__ ).'js/pms.js');
  133. wp_enqueue_script('pms_script');
  134. }
  135. add_action('wp_enqueue_scripts','pms_scripts');
  136.  
  137. //HOOKS
  138. add_action('init','pms_init');
  139. /********************************************************/
  140. /* FUNCTIONS
  141. ********************************************************/
  142. function pms_init(){
  143. //do work
  144. run_sub_process();
  145. }
  146.  
  147. function run_sub_process(){
  148. //more work
  149. }
  150.  
  151. /***************************************************
  152. * Settings menu
  153. ***************************************************/
  154. add_action('admin_menu', 'pms_admin_menu');
  155.  
  156. function pms_admin_menu() {
  157. $page_title = 'player Management System Settings';
  158. $menu_title = 'player System';
  159. $capability = 'manage_options';
  160. $menu_slug = 'pms-settings';
  161. $function = 'pms_settings';
  162. add_options_page($page_title, $menu_title, $capability, $menu_slug, $function);
  163. }
  164.  
  165. function pms_settings() {
  166. if (!current_user_can('manage_options')) {
  167. wp_die('You do aaa not have sufficient permissions to access this page.');
  168. }
  169.  
  170. // Here is where you could start displaying the HTML needed for the settings
  171. // page, or you could include a file that handles the HTML output for you.
  172. echo "<h1>player Management System Settings</h1>";
  173. //echo "<p>Customize the player Management System here.</p>";
  174. echo "<p>No customization settings are necessary at this time.</p>";
  175. }
  176.  
  177. add_action('admin_menu', 'pms_menu_pages');
  178.  
  179. /***************************************************
  180. * pms menu
  181. ***************************************************/
  182. function pms_menu_pages() {
  183. // Add the top-level admin menu
  184. $page_title = 'pms List players';
  185. $menu_title = 'player System';
  186. $capability = 'manage_options';
  187. $menu_slug = 'pms-listplayers';
  188. $function = 'pms_listplayers';
  189. add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, 'dashicons-universal-access', 3);
  190.  
  191. // Add submenu page with same slug as parent to ensure no duplicates
  192. $sub_menu_title = 'List players';
  193. add_submenu_page($menu_slug, $page_title, $sub_menu_title, $capability, $menu_slug, $function);
  194.  
  195. // Now add the submenu page for Add player
  196. $submenu_page_title = 'pms Add player';
  197. $submenu_title = 'Add player';
  198. $submenu_slug = 'pms-addplayer';
  199. $submenu_function = 'pms_addplayer';
  200. add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $capability, $submenu_slug, $submenu_function);
  201.  
  202. // Now add the submenu page for settings
  203. /* $submenu_page_title = 'pms Settings';
  204. $submenu_title = 'Settings';
  205. $submenu_slug = 'pms-settings';
  206. $submenu_function = 'pms_settings';
  207. add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $capability, $submenu_slug, $submenu_function);
  208. */
  209.  
  210. // Now add the submenu page for Help
  211. $submenu_page_title = 'pms Help';
  212. $submenu_title = 'Help';
  213. $submenu_slug = 'pms-help';
  214. $submenu_function = 'pms_help';
  215. add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $capability, $submenu_slug, $submenu_function);
  216. }
  217.  
  218. /* SEE ABOVE function pms_settings() {} */
  219.  
  220. function pms_listplayers() {
  221. if (!current_user_can('manage_options')) {
  222. wp_die('You do asdsad not have sufficient permissions to access this page.');
  223. }
  224.  
  225. //Create player object
  226. $player = new player(0);
  227.  
  228. // Render the HTML for Listing the players
  229. echo "<div class=\"wrap\">";
  230. echo "<h2>player Management System - List players</h2>";
  231. //echo "<p>List of all players goes here.</p>";
  232. echo "<form id=\"players-filter\" method=\"get\" action=\"\">";
  233.  
  234. $player->listAllplayers();
  235.  
  236. if($player->hasErrors()){
  237. $player->showErrors();
  238. }
  239. //@submit_button();
  240. echo "</form>";
  241. echo "<br class=\"clear\" />";
  242. echo "</div>";
  243. }
  244.  
  245. function pms_addplayer() {
  246. if (!current_user_can('manage_options')) {
  247. wp_die('You do dfdfdnot have sufficient permissions to access this page.');
  248. }
  249. //Create player object
  250. $player = new player(0);
  251.  
  252. // Render the HTML for the Help page or include a file that does
  253. echo "<h1>player Management System - Add player</h1>";
  254. echo "<p>Form to add a new player goes here.</p>";
  255. $player->addeditform();
  256. }
  257.  
  258. function pms_help() {
  259. if (!current_user_can('manage_options')) {
  260. wp_die('You do dfs2 not have sufficient permissions to access this page.');
  261. }
  262.  
  263. // Render the HTML for the Help page or include a file that does
  264. echo "<h1>player Management System Help</h1>";
  265. echo "<p>This explains how to use the player Management System.</p>";
  266. }
  267. ?>
  268. ************ FILE: class.Player.php *******************
  269.  
  270. <?php /*
  271. FILENAME: class.player.php
  272. PROJECT: Player Management System
  273. DESCRIPTION: Object for managing players
  274. AUTHOR: name
  275. CREATION DATE: March 2015
  276. MODIFIED BY/ON:
  277. VARIABLES:
  278.  
  279. */ ?>
  280. <?php
  281. class player extends Base{
  282. private $_resultset;
  283. private $uploaddir;
  284.  
  285. public $_playerid;
  286.  
  287. //form variables
  288.  
  289. public function __construct($playerid){
  290. $this->_playerid = $playerid;
  291. $this->uploaddir = wp_upload_dir();
  292. //$this->_errors[] = 'broken2';
  293. }
  294.  
  295. public function getAllplayers(){
  296. global $wpdb;
  297.  
  298. $pms_players_table = $wpdb->prefix . 'pms_players'; //Good practice
  299. $pms_regions_table = $wpdb->prefix . 'pms_regions'; //Good practice
  300. $this->_resultset = $wpdb->get_results( "
  301. select
  302. a.ChildID,
  303. a.FirstName,
  304. a.MiddleName,
  305. a.Surname,
  306. a.Gender,
  307. a.Birthdate,
  308. a.SiblingGroup,
  309. a.RegionID,
  310. a.Biography,
  311. a.Status,
  312. a.VideoFilename,
  313. r.RegionName
  314. from $pms_players_table a
  315. left outer join $pms_regions_table r
  316. on a.RegionID = r.RegionID
  317. order by a.ChildID DESC;
  318. ");
  319.  
  320. //$videofilename = $randomProfile[0]->VideoFilename;
  321. //$picturefilename = $randomProfile[0]->PictureFilename;
  322.  
  323. }
  324.  
  325. public function listAllplayers(){
  326. $this->getAllplayers();
  327.  
  328. //print_r($this->_resultset);
  329. $numberofcolumns = 9;
  330. ?>
  331. <div id="playerslistcontainer">
  332. <table id="currentplayers" class="wp-list-table widefat fixed players">
  333. <thead>
  334. <tr>
  335. <th>
  336. ID
  337. </th>
  338. <th>
  339. Status
  340. </th>
  341. <th>
  342. Video?
  343. </th>
  344. <th>
  345. Name
  346. </th>
  347. <th>
  348. Gender
  349. </th>
  350. <th>
  351. Age
  352. </th>
  353. <th>
  354. Sib Grp
  355. </th>
  356. <th>
  357. Region
  358. </th>
  359. <th>
  360. Edit/Delete
  361. </th>
  362. </tr>
  363. </thead>
  364. <?php
  365. foreach($this->_resultset as $row){
  366. echo "<tr>";
  367. echo "<td>".$row->ChildID."</td>";
  368. echo "<td>";
  369. switch(intval($row->Status)){
  370. case 0: // Inactive
  371. echo "Inactive";
  372. break;
  373. case 1: // Active
  374. echo "Active";
  375. break;
  376. case 2: // Placement pending
  377. echo "Placement pending";
  378. break;
  379. case 3: // player pending
  380. echo "player pending";
  381. break;
  382. default: // unknown
  383. echo "Unknown";
  384. }
  385. echo "</td>";
  386. echo "<td>";
  387. if(strlen(trim($row->VideoFilename))
  388. && file_exists($this->uploaddir['baseurl']."/videos/".$row->VideoFilename)){
  389. echo "Yes";
  390. } else {
  391. echo "No";
  392. }
  393. echo "</td>";
  394. echo "<td>";
  395. $childname = trim($row->FirstName)." ".trim($row->MiddleName);
  396. $childname = trim($childname)." ".trim($row->Surname);
  397. $childname = trim($childname);
  398. echo $childname;
  399. echo "</td>";
  400. echo "<td>";
  401. switch(intval($row->Gender)){
  402. case 0: //Female
  403. echo "Female";
  404. break;
  405. case 1: //Male
  406. echo "Male";
  407. break;
  408. default: //Unknown
  409. echo "Unknown";
  410. }
  411. echo "</td>";
  412. echo "<td title=\"".date("M d Y",strtotime($row->Birthdate))."\">";
  413. echo intval((time() - strtotime($row->Birthdate))/60/60/24/365);
  414. echo "</td>";
  415. echo "<td>";
  416. switch($row->SiblingGroup){
  417. case 1:
  418. echo "Yes";
  419. break;
  420. case 0:
  421. echo "No";
  422. break;
  423. }
  424. echo "</td>";
  425. echo "<td>".$row->RegionName."</td>";
  426. echo "<td>Edit&nbsp;/&nbsp;Delete</td>";
  427. echo "</tr>";
  428. }
  429. ?>
  430. </table>
  431. </div>
  432. <?php
  433. }
  434.  
  435. public function addeditform(){
  436. echo "<p>form here</p>";
  437. echo "<form id=\"players-frmaddedit\" method=\"post\" action=\"".admin_url( )."?page=pms-addplayer\">";
  438. if ( function_exists('wp_nonce_field') )
  439. wp_nonce_field('player-managemet-system-action_pms-addplayer');
  440. //@settings_fields('wp_plugin_template-group');
  441. //@do_settings_fields('wp_plugin_template-group');
  442. echo "<input type=\"hidden\" name=\"action\" value=\"pms-addplayer\" />";
  443. @submit_button('Add player');
  444. echo "</form>";
  445. }
  446. }
  447. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement