Guest User

Untitled

a guest
Jan 13th, 2011
67
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3. Plugin Name: Argus Administration Tool
  4. Plugin URI: http://toro.azwestern.edu
  5. 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.
  6. Version: 1.3
  7. Author: Zack Loveless
  8. Author URI: http://www.unifiedtech.org
  9. */
  10.  
  11. /*
  12.  * Special Note: permissions follow the following format: argus_<action>_<module>
  13.  *          where <action> is a wordpress standard action ("edit", "publish", etc)
  14.  *          and <module> is the module name ("visitors")
  15.  *
  16.  * Special Note: methods prefixed with "_" indicate that the method is an action
  17.  *          or filter for wordpress. Methods prefixed with "__" are 'protected'
  18.  *          methods for the argus class.
  19.  */
  20.  
  21. if ( ! class_exists( 'argus' ) )
  22. {
  23.     class argus
  24.     {
  25.         /**#@+
  26.           * Internal reference variables
  27.           *
  28.           * @var    mixed
  29.           * @since 1.0
  30.           */
  31.         protected $db;
  32.         /**#@-*/
  33.  
  34.         public function __construct( )
  35.         {
  36.             global $wpdb;
  37.  
  38.             $this->db =& $wpdb;
  39.  
  40.             add_action( 'init', array( &$this, '_wp_init' ) );
  41.             //add_action( 'admin_init', array( &$this, '_wp_admin_init' ) );
  42.             add_action( 'save_post', array( &$this, '_wp_save_post' ), 1, 2 );
  43.  
  44.             add_action( 'manage_posts_custom_column', array( &$this, '_wp_filter_visitor_column_view' ) );
  45.             add_filter( 'manage_edit-visitor_columns', array( &$this, '_wp_filter_visitor_columns' ) );
  46.         }
  47.  
  48.         /* Wordpress Initializations */
  49.         public function _visitors_meta_box_cb( )
  50.         {
  51.             // http://www.deluxeblogtips.com/2010/04/how-to-create-meta-box-wordpress-post.html
  52.             $m_visitor_info = array(
  53.                     'id' => 'argus_edit_visitor',
  54.                     'name' => 'Visitor Information',
  55.                     'cb' => array( &$this, '_argus_edit_visitor' ),
  56.                     'type' => 'visitor',
  57.                     'context' => 'normal',
  58.                     'priority' => 'high',
  59.                 );
  60.  
  61.             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'] );
  62.             //add_meta_box( 'argus_edit_visitor', 'Visitor Information', array( &$this, '_argus_edit_visitor' ), 'visitor', 'advanced', 'high' );
  63.             //add_meta_box( $id, $title, $callback, $page, $context, $priority, $callback_args );
  64.         }
  65.  
  66.         public function _wp_filter_visitor_column_view( $column )
  67.         {
  68.             global $post;
  69.             if ( $column == "name" )
  70.             {
  71.                 $name = get_post_meta( $post->ID, 'v_f_name', true );
  72.                 $name .= ' ' . get_post_meta( $post->ID, 'v_l_name', true );
  73.                 echo $name;
  74.             }
  75.             elseif ( $column == "type" )
  76.             {
  77.                 $types = get_the_terms( $post->ID, 'v_types' );
  78.                 echo substr(implode( ', ', $types ), 0, -2);    // Outputs the visitor types in a CSV-state.
  79.             }
  80.             elseif ( $column == "loggedin" OR $column == "workstation" )
  81.             {
  82.                 $workstation = get_post_meta( $post->ID, 'v_workstation', true );
  83.                 if ( $column == "workstation" ) echo $workstation;
  84.                 elseif ( $column == "loggedin" ) echo ( !empty($workstation) OR !isset( $workstation ) ) ? 'No' : 'Yes';
  85.             }
  86.             elseif ( $column == "id" )
  87.             {
  88.                 echo get_post_meta( $post->ID, 'v_id', true );
  89.             }
  90.         }
  91.  
  92.         public function _wp_filter_visitor_columns( $columns )
  93.         {
  94.             $columns = array(
  95.                     'cb' => '<input type="checkbox" />',
  96.                     'title' => 'Name',
  97.                     'type' => 'Type',
  98.                     'loggedin' => 'Logged In?',
  99.                     'id' => 'Visitor ID',
  100.                 );
  101.  
  102.             return $columns;
  103.         }
  104.  
  105.         public function _wp_init( )
  106.         {
  107.             $v_args = array(
  108.                     'labels' => array (
  109.                             'name' => 'Visitors', // TODO: __('Visitors')
  110.                             'singular_name' => 'Visitor',
  111.                             'add_new_item' => 'Register New Visitor', // TODO: http://codex.wordpress.org/Function_Reference/register_post_type#Arguments
  112.                         ),
  113.                     'public' => true,
  114.                     'publicly_queryable' => false,
  115.                     'exclude_from_search' => true,
  116.                     'show_ui' => true,
  117.                     'hiearchical' => false,
  118.                     'supports' => array( '' ),
  119.                     'register_meta_box_cb' => array ( &$this, '_visitors_meta_box_cb' ),
  120.                 );
  121.  
  122.             register_post_type( 'visitor', $v_args );
  123.             flush_rewrite_rules( /* flushing rewrite rules for safety. (JIC) */ );
  124.  
  125.             $v_args_taxonomy = array(
  126.                     'label' => 'Visitor Types',
  127.                     'hierarchical' => true,     // Treats this taxonomy as categories for each visitor, not tags
  128.                     'singular_label' => 'Visitor Type',
  129.                     'rewrite' => false,
  130.                     'public' => true,
  131.                     'show_tagcloud' => false,
  132.                     'show_ui' => true,
  133.                     'show_in_nav_menus' => false,
  134.                     'capabilities' => array (
  135.                             //'assign_terms' => 'argus_edit_visitors',
  136.                         ),
  137.                 );
  138.  
  139.             $v_args_accts = array(
  140.                     'label' => 'Accounts',
  141.                     'hierarchical' => true,
  142.                     'singular_label' => 'Account',
  143.                     'rewrite' => false,
  144.                     'public' => true,
  145.                     'show_tagcloud' => false,
  146.                     'show_ui' => true,
  147.                     'show_in_nav_menus' => false,
  148.                     'capabilities' => array (
  149.                             //'assign_terms' => 'argus_edit_visitors',
  150.                         ),
  151.                 );
  152.  
  153.             register_taxonomy( 'v_types', array( 'visitor' ), $v_args_taxonomy );
  154.             //register_taxonomy( 'a_wkstas', array( 'visitor' ), $v_args_wksta );
  155.             register_taxonomy( 'v_accts', array( 'visitor' ), $v_args_accts );
  156.         }
  157.  
  158.         public function _wp_save_post( $post_id, $post )
  159.         {
  160.             if ( empty($_POST)
  161.                     OR !isset($_POST['argus_edit_visitor'])
  162.                     OR !wp_verify_nonce( $_POST['argus_edit_visitor'], 'argus_edit_visitor' ) )
  163.             {
  164.                 echo "Erm. Why?";
  165.                 return $post->ID;
  166.             }
  167.  
  168.             if ( ! current_user_can( 'edit_post', $post->ID ) ) return $post->ID;
  169.  
  170.             // v_f_name | v_l_name | v_workstation | v_id
  171.             // Argh!
  172.  
  173.             $this->__update_post_meta( $post->ID, 'v_f_name', $_POST['v_f_name'] );
  174.             $this->__update_post_meta( $post->ID, 'v_l_name', $_POST['v_l_name'] );
  175.             $this->__update_post_meta( $post->ID, 'v_workstation', $_POST['v_workstation'] );
  176.             $this->__update_post_meta( $post->ID, 'v_id', $_POST['v_id'] );
  177.         }
  178.  
  179.         /* Argus Visitors */
  180.         public function _argus_edit_visitor(  )
  181.         {
  182.             global $post;
  183.             $data = get_post_custom( $post->ID );
  184.  
  185.             $firstName = get_post_meta( $post->ID, 'v_f_name', true );
  186.             $lastName = get_post_meta( $post->ID, 'v_l_name', true );
  187.             $workstation = get_post_meta( $post->ID, 'v_workstation', true );
  188.             $vid = get_post_meta( $post->ID, 'v_id', true );
  189.             $nonce = wp_create_nonce( plugin_basename( __FILE__ ) );
  190.  
  191.             $workstations = $this->__getWorkstationList( isset($workstation) AND !empty($workstation) ? $workstation : '' );
  192.  
  193.             $html = <<<HTML
  194. <table class="form-table">
  195. <tr>
  196.     <th style="width:20%;"><label for="v_f_name">First Name:</label></th>
  197.     <td>
  198.         <input name="v_f_name" id="v_f_name" value="{$firstName}" size="30" style="width:97%;" /><br />
  199.     </td>
  200. </tr>
  201. <tr>
  202.     <th style="width:20%;"><label for="v_l_name">Last Name:</label></th>
  203.     <td>
  204.         <input name="v_l_name" id="v_l_name" value="{$lastName}" size="30" style="width:97%;" /><br />
  205.     </td>
  206. </tr>
  207. <tr>
  208.     <th style="width:20%;"><label for="v_id">Visitor ID:</label></th>
  209.     <td>
  210.         <input name="v_id" id="v_id" value="{$vid}" size="30" style="width:97%" /><br />
  211.         <p>Enter the visitor's ID number as it appears on their form of identification.</p>
  212.     </td>
  213. </tr>
  214. <tr>
  215.     <th style="width:20%;"><label for="v_workstations">Location:</label></th>
  216.     <td>
  217.         {$workstations}<br />
  218.         <p>Select the workstation that the visitor would like to sit at.</p>
  219.     </td>
  220. </tr>
  221. <input type="hidden" name="argus_edit_visitor" id="argus_edit_visitor" value="{$nonce}" />
  222. </table>
  223. HTML;
  224.             echo $html;
  225.         }
  226.  
  227.         /* Argus Internal Functions */
  228.  
  229.         /**
  230.          * Gets a list of workstations from the database and returns them as a <select> control
  231.          *
  232.          * @param   string      The currently selected option
  233.          * @param   string      The prefix to append to the control output
  234.          * @return  object
  235.          * @since 1.1
  236.          */
  237.         protected function __getWorkstationList( $meta, $field_id = 'v_workstations' )
  238.         {
  239.             $sql = "SELECT w.workstation_name AS computer, w.workstation_id AS ID
  240.                         FROM wp_argus_workstations AS w
  241.                             ORDER BY w.workstation_id;";
  242.  
  243.             $results = $this->db->get_results( $sql );
  244.  
  245.             $html = "<select name='{$field_id}' id='{$field_id}' style='width:30%;'>";
  246.  
  247.             foreach ($results as $row)
  248.             {
  249.                 $html .= '<option ' . ($meta == $row->computer ? 'selected="selected"' : '') . ' value="' . $row->ID . '">' . $row->computer . '</option>';
  250.             }
  251.  
  252.             $html .= '</select>';
  253.  
  254.             return $html;
  255.         }
  256.  
  257.         /**
  258.           * Updates post meta for a post. It also automatically deletes or adds the value to field_name if specified
  259.           *
  260.           * @access     protected
  261.           * @param      integer     The post ID for the post we're updating
  262.           * @param      string      The field we're updating/adding/deleting
  263.           * @param      string      [Optional] The value to update/add for field_name. If left blank, data will be deleted.
  264.           * @since 1.3
  265.           */
  266.         protected function __update_post_meta( $post_id, $field_name, $value = '' )
  267.         {
  268.             if ( empty( $value ) OR ! $value )
  269.             {
  270.                 delete_post_meta( $post_id, $field_name );
  271.             }
  272.             elseif ( ! get_post_meta( $post_id, $field_name ) )
  273.             {
  274.                 add_post_meta( $post_id, $field_name, $value );
  275.             }
  276.             else
  277.             {
  278.                 update_post_meta( $post_id, $field_name, $value );
  279.             }
  280.         }
  281.     }
  282. }
  283.  
  284. $argus = new argus();
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×