Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Argus Administration Tool
- Plugin URI: http://toro.azwestern.edu
- Description: Argus is an Administration Tool used to manage and track Visitors in the ACCL along with providing a way to report problems within the ACCL. This tool also incorporates the Offenders database for tracking offenders in the ACCL.
- Version: 1.3
- Author: Zack Loveless
- Author URI: http://www.unifiedtech.org
- */
- /*
- * Special Note: permissions follow the following format: argus_<action>_<module>
- * where <action> is a wordpress standard action ("edit", "publish", etc)
- * and <module> is the module name ("visitors")
- *
- * Special Note: methods prefixed with "_" indicate that the method is an action
- * or filter for wordpress. Methods prefixed with "__" are 'protected'
- * methods for the argus class.
- */
- if ( ! class_exists( 'argus' ) )
- {
- class argus
- {
- /**#@+
- * Internal reference variables
- *
- * @var mixed
- * @since 1.0
- */
- protected $db;
- /**#@-*/
- public function __construct( )
- {
- global $wpdb;
- $this->db =& $wpdb;
- add_action( 'init', array( &$this, '_wp_init' ) );
- //add_action( 'admin_init', array( &$this, '_wp_admin_init' ) );
- add_action( 'save_post', array( &$this, '_wp_save_post' ), 1, 2 );
- add_action( 'manage_posts_custom_column', array( &$this, '_wp_filter_visitor_column_view' ) );
- add_filter( 'manage_edit-visitor_columns', array( &$this, '_wp_filter_visitor_columns' ) );
- }
- /* Wordpress Initializations */
- public function _visitors_meta_box_cb( )
- {
- // http://www.deluxeblogtips.com/2010/04/how-to-create-meta-box-wordpress-post.html
- $m_visitor_info = array(
- 'id' => 'argus_edit_visitor',
- 'name' => 'Visitor Information',
- 'cb' => array( &$this, '_argus_edit_visitor' ),
- 'type' => 'visitor',
- 'context' => 'normal',
- 'priority' => 'high',
- );
- add_meta_box( $m_visitor_info['id'], $m_visitor_info['name'], $m_visitor_info['cb'], $m_visitor_info['type'], $m_visitor_info['context'], $m_visitor_info['priority'] );
- //add_meta_box( 'argus_edit_visitor', 'Visitor Information', array( &$this, '_argus_edit_visitor' ), 'visitor', 'advanced', 'high' );
- //add_meta_box( $id, $title, $callback, $page, $context, $priority, $callback_args );
- }
- public function _wp_filter_visitor_column_view( $column )
- {
- global $post;
- if ( $column == "name" )
- {
- $name = get_post_meta( $post->ID, 'v_f_name', true );
- $name .= ' ' . get_post_meta( $post->ID, 'v_l_name', true );
- echo $name;
- }
- elseif ( $column == "type" )
- {
- $types = get_the_terms( $post->ID, 'v_types' );
- echo substr(implode( ', ', $types ), 0, -2); // Outputs the visitor types in a CSV-state.
- }
- elseif ( $column == "loggedin" OR $column == "workstation" )
- {
- $workstation = get_post_meta( $post->ID, 'v_workstation', true );
- if ( $column == "workstation" ) echo $workstation;
- elseif ( $column == "loggedin" ) echo ( !empty($workstation) OR !isset( $workstation ) ) ? 'No' : 'Yes';
- }
- elseif ( $column == "id" )
- {
- echo get_post_meta( $post->ID, 'v_id', true );
- }
- }
- public function _wp_filter_visitor_columns( $columns )
- {
- $columns = array(
- 'cb' => '<input type="checkbox" />',
- 'title' => 'Name',
- 'type' => 'Type',
- 'loggedin' => 'Logged In?',
- 'id' => 'Visitor ID',
- );
- return $columns;
- }
- public function _wp_init( )
- {
- $v_args = array(
- 'labels' => array (
- 'name' => 'Visitors', // TODO: __('Visitors')
- 'singular_name' => 'Visitor',
- 'add_new_item' => 'Register New Visitor', // TODO: http://codex.wordpress.org/Function_Reference/register_post_type#Arguments
- ),
- 'public' => true,
- 'publicly_queryable' => false,
- 'exclude_from_search' => true,
- 'show_ui' => true,
- 'hiearchical' => false,
- 'supports' => array( '' ),
- 'register_meta_box_cb' => array ( &$this, '_visitors_meta_box_cb' ),
- );
- register_post_type( 'visitor', $v_args );
- flush_rewrite_rules( /* flushing rewrite rules for safety. (JIC) */ );
- $v_args_taxonomy = array(
- 'label' => 'Visitor Types',
- 'hierarchical' => true, // Treats this taxonomy as categories for each visitor, not tags
- 'singular_label' => 'Visitor Type',
- 'rewrite' => false,
- 'public' => true,
- 'show_tagcloud' => false,
- 'show_ui' => true,
- 'show_in_nav_menus' => false,
- 'capabilities' => array (
- //'assign_terms' => 'argus_edit_visitors',
- ),
- );
- $v_args_accts = array(
- 'label' => 'Accounts',
- 'hierarchical' => true,
- 'singular_label' => 'Account',
- 'rewrite' => false,
- 'public' => true,
- 'show_tagcloud' => false,
- 'show_ui' => true,
- 'show_in_nav_menus' => false,
- 'capabilities' => array (
- //'assign_terms' => 'argus_edit_visitors',
- ),
- );
- register_taxonomy( 'v_types', array( 'visitor' ), $v_args_taxonomy );
- //register_taxonomy( 'a_wkstas', array( 'visitor' ), $v_args_wksta );
- register_taxonomy( 'v_accts', array( 'visitor' ), $v_args_accts );
- }
- public function _wp_save_post( $post_id, $post )
- {
- if ( empty($_POST)
- OR !isset($_POST['argus_edit_visitor'])
- OR !wp_verify_nonce( $_POST['argus_edit_visitor'], 'argus_edit_visitor' ) )
- {
- echo "Erm. Why?";
- return $post->ID;
- }
- if ( ! current_user_can( 'edit_post', $post->ID ) ) return $post->ID;
- // v_f_name | v_l_name | v_workstation | v_id
- // Argh!
- $this->__update_post_meta( $post->ID, 'v_f_name', $_POST['v_f_name'] );
- $this->__update_post_meta( $post->ID, 'v_l_name', $_POST['v_l_name'] );
- $this->__update_post_meta( $post->ID, 'v_workstation', $_POST['v_workstation'] );
- $this->__update_post_meta( $post->ID, 'v_id', $_POST['v_id'] );
- }
- /* Argus Visitors */
- public function _argus_edit_visitor( )
- {
- global $post;
- $data = get_post_custom( $post->ID );
- $firstName = get_post_meta( $post->ID, 'v_f_name', true );
- $lastName = get_post_meta( $post->ID, 'v_l_name', true );
- $workstation = get_post_meta( $post->ID, 'v_workstation', true );
- $vid = get_post_meta( $post->ID, 'v_id', true );
- $nonce = wp_create_nonce( plugin_basename( __FILE__ ) );
- $workstations = $this->__getWorkstationList( isset($workstation) AND !empty($workstation) ? $workstation : '' );
- $html = <<<HTML
- <table class="form-table">
- <tr>
- <th style="width:20%;"><label for="v_f_name">First Name:</label></th>
- <td>
- <input name="v_f_name" id="v_f_name" value="{$firstName}" size="30" style="width:97%;" /><br />
- </td>
- </tr>
- <tr>
- <th style="width:20%;"><label for="v_l_name">Last Name:</label></th>
- <td>
- <input name="v_l_name" id="v_l_name" value="{$lastName}" size="30" style="width:97%;" /><br />
- </td>
- </tr>
- <tr>
- <th style="width:20%;"><label for="v_id">Visitor ID:</label></th>
- <td>
- <input name="v_id" id="v_id" value="{$vid}" size="30" style="width:97%" /><br />
- <p>Enter the visitor's ID number as it appears on their form of identification.</p>
- </td>
- </tr>
- <tr>
- <th style="width:20%;"><label for="v_workstations">Location:</label></th>
- <td>
- {$workstations}<br />
- <p>Select the workstation that the visitor would like to sit at.</p>
- </td>
- </tr>
- <input type="hidden" name="argus_edit_visitor" id="argus_edit_visitor" value="{$nonce}" />
- </table>
- HTML;
- echo $html;
- }
- /* Argus Internal Functions */
- /**
- * Gets a list of workstations from the database and returns them as a <select> control
- *
- * @param string The currently selected option
- * @param string The prefix to append to the control output
- * @return object
- * @since 1.1
- */
- protected function __getWorkstationList( $meta, $field_id = 'v_workstations' )
- {
- $sql = "SELECT w.workstation_name AS computer, w.workstation_id AS ID
- FROM wp_argus_workstations AS w
- ORDER BY w.workstation_id;";
- $results = $this->db->get_results( $sql );
- $html = "<select name='{$field_id}' id='{$field_id}' style='width:30%;'>";
- foreach ($results as $row)
- {
- $html .= '<option ' . ($meta == $row->computer ? 'selected="selected"' : '') . ' value="' . $row->ID . '">' . $row->computer . '</option>';
- }
- $html .= '</select>';
- return $html;
- }
- /**
- * Updates post meta for a post. It also automatically deletes or adds the value to field_name if specified
- *
- * @access protected
- * @param integer The post ID for the post we're updating
- * @param string The field we're updating/adding/deleting
- * @param string [Optional] The value to update/add for field_name. If left blank, data will be deleted.
- * @since 1.3
- */
- protected function __update_post_meta( $post_id, $field_name, $value = '' )
- {
- if ( empty( $value ) OR ! $value )
- {
- delete_post_meta( $post_id, $field_name );
- }
- elseif ( ! get_post_meta( $post_id, $field_name ) )
- {
- add_post_meta( $post_id, $field_name, $value );
- }
- else
- {
- update_post_meta( $post_id, $field_name, $value );
- }
- }
- }
- }
- $argus = new argus();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement