Plugin Directory

Changeset 1690167


Ignore:
Timestamp:
07/03/2017 11:53:17 PM (9 years ago)
Author:
datainterlock
Message:

Wordpress 0.1.6

Location:
note-press/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • note-press/trunk/Note_Press.php

    r1689102 r1690167  
    11<?php
    22
    3 
    4 
    53/**
    6 
    74 * The WordPress Plugin Boilerplate.
    8 
    95 *
    10 
    116 * A foundation off of which to build well-documented WordPress plugins that
    12 
    137 * also follow WordPress Coding Standards and PHP best practices.
    14 
    158 *
    16 
    179 * @package   Note_Press
    18 
    1910 * @author    datainterlock <postmaster@datainterlock.com>
    20 
    2111 * @license   GPL-3.0+
    22 
    2312 * @link      http://www.datainterlock.com
    24 
    2513 * @Copyright (C) 2015 Rod Kinnison postmaster@datainterlock.com
    26 
    2714 *
    28 
    2915 * @wordpress-plugin
    30 
    3116 * Plugin Name:       Note Press
    32 
    3317 * Plugin URI:        http://www.datainterlock.com
    34 
    3518 * Description:       Add, edit and delete multiple notes and display them with icons on the Admin page or dashboard.
    36 
    37  * Version:           0.1.5
    38 
     19 * Version:           0.1.6
    3920 * Author:            datainterlock
    40 
    4121 * Author URI:        http://www.datainterlock.com
    42 
    4322 * Text Domain:       Note_Press
    44 
    4523 * License:           -3.0+
    46 
    4724 * License URI:       http://www.gnu.org/licenses/gpl-3.0.html
    48 
    4925 * Domain Path:       /languages
    50 
    5126 * WordPress-Plugin-Boilerplate: v2.6.1
    5227
    5328
    54 
    55 
    56 
    5729This program is free software: you can redistribute it and/or modify
    58 
    5930it under the terms of the GNU General Public License as published by
    60 
    6131the Free Software Foundation, either version 3 of the License.
    6232
    63 
    64 
    6533This program is distributed in the hope that it will be useful,
    66 
    6734but WITHOUT ANY WARRANTY; without even the implied warranty of
    68 
    6935MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    70 
    7136GNU General Public License for more details.
    7237
    73 
    74 
    7538You should have received a copy of the GNU General Public License
    76 
    7739along with this program.  If not, see <http://www.gnu.org/licenses/>.
    7840
    79 
    80 
    8141The basic structure of this plugin was cloned from the [WordPress-Plugin-Boilerplate]
    82 
    8342(https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate) project. Thanks Tom!
    8443
    85 
    86 
    8744Many of the features of the Boilerplate, such as the admin settings, css and js are included
    88 
    8945in this plugin yet are not used in this version. I've went ahead and included them as I do have
    90 
    9146plans to use them in the future.
    92 
    9347*/
    94 
    9548// If this file is called directly, abort.
    9649
     50if ( ! defined( 'WPINC' ) ) {
     51    die;
     52}
    9753
     54/**
     55 * The code that runs during plugin activation.
     56 * This action is documented in includes/class-Note_Press-activator.php
     57 */
     58function activate_Note_Press() {
     59    require_once plugin_dir_path( __FILE__ ) . 'includes/class-Note_Press-activator.php';
     60    Note_Press_Activator::activate();
     61}
    9862
    99 if ( ! defined( 'WPINC' ) ) {
     63/**
     64 * The code that runs during plugin deactivation.
     65 * This action is documented in includes/class-Note_Press-deactivator.php
     66 */
     67function deactivate_Note_Press() {
     68    require_once plugin_dir_path( __FILE__ ) . 'includes/class-Note_Press-deactivator.php';
     69    Note_Press_Deactivator::deactivate();
     70}
    10071
    101     die;
     72register_activation_hook( __FILE__, 'activate_Note_Press' );
     73register_deactivation_hook( __FILE__, 'deactivate_Note_Press' );
     74
     75/**
     76 * The core plugin class that is used to define internationalization,
     77 * admin-specific hooks, and public-facing site hooks.
     78 */
     79require plugin_dir_path( __FILE__ ) . 'includes/class-Note_Press.php';
     80
     81/**
     82 * Begins execution of the plugin.
     83 *
     84 * Since everything within the plugin is registered via hooks,
     85 * then kicking off the plugin from this point in the file does
     86 * not affect the page life cycle.
     87 *
     88 * @since    1.0.0
     89 */
     90function run_Note_Press() {
     91
     92    $plugin = new Note_Press();
     93    $plugin->run();
    10294
    10395}
    104 
    105 
    106 
    107 /**
    108 
    109  * The code that runs during plugin activation.
    110 
    111  * This action is documented in includes/class-Note_Press-activator.php
    112 
    113  */
    114 
    115 function activate_Note_Press() {
    116 
    117     require_once plugin_dir_path( __FILE__ ) . 'includes/class-Note_Press-activator.php';
    118 
    119     Note_Press_Activator::activate();
    120 
    121 }
    122 
    123 
    124 
    125 /**
    126 
    127  * The code that runs during plugin deactivation.
    128 
    129  * This action is documented in includes/class-Note_Press-deactivator.php
    130 
    131  */
    132 
    133 function deactivate_Note_Press() {
    134 
    135     require_once plugin_dir_path( __FILE__ ) . 'includes/class-Note_Press-deactivator.php';
    136 
    137     Note_Press_Deactivator::deactivate();
    138 
    139 }
    140 
    141 
    142 
    143 register_activation_hook( __FILE__, 'activate_Note_Press' );
    144 
    145 register_deactivation_hook( __FILE__, 'deactivate_Note_Press' );
    146 
    147 
    148 
    149 /**
    150 
    151  * The core plugin class that is used to define internationalization,
    152 
    153  * admin-specific hooks, and public-facing site hooks.
    154 
    155  */
    156 
    157 require plugin_dir_path( __FILE__ ) . 'includes/class-Note_Press.php';
    158 
    159 
    160 
    161 /**
    162 
    163  * Begins execution of the plugin.
    164 
    165  *
    166 
    167  * Since everything within the plugin is registered via hooks,
    168 
    169  * then kicking off the plugin from this point in the file does
    170 
    171  * not affect the page life cycle.
    172 
    173  *
    174 
    175  * @since    1.0.0
    176 
    177  */
    178 
    179 function run_Note_Press() {
    180 
    181 
    182 
    183     $plugin = new Note_Press();
    184 
    185     $plugin->run();
    186 
    187 
    188 
    189 }
    190 
    19196run_Note_Press();
    192 
    193 
    194 
    195 
    196 
  • note-press/trunk/README.txt

    r1689296 r1690167  
    4949Note Press will allow you to create Sticky notes on the Wordpress Admin Dashboard and allow you to chose the color of the note.  A  Sticky note will be the only way that users, like contributors who have access to the dashboard but do not have Note Press access, can see notes sent to them.
    5050
     51= Does Note Press support multi-site? =
     52Yes, but.  There is no capability to send notes across sites.  Each site will have it's own copy of Note Press activated but each site can only send note to that site's users.
     53
    5154= Can the icons be replaced? =
    5255
     
    7679
    7780== Changelog ==
     81= 0.1.6 =
     82* Fixed an error with database name being hard coded.
     83* Added limited multi-site abilities.
     84
    7885= 0.1.5 =
    7986* Added the ability to send notes to other users with at least Author priviliges.
  • note-press/trunk/admin/Note_Press-admin-menu.php

    r1689102 r1690167  
    11<?php
    2 
    3 
    4 
    52/**
    6 
    7  * Provide a admin area view for the plugin
    8 
    9  *
    10 
    11  * This file is used to markup the admin-facing aspects of the plugin.
    12 
    13  *
    14 
    15  * @link       http://www.datainterlock.com
    16 
    17  * @since      1.0.0
    18 
    19  *
    20 
    21  * @package    Notepress2
    22 
    23  * @subpackage Notepress2/admin/partials
    24 
    25  
    26 
    27  */
    28 
    29 
    30 
     3* Provide a admin area view for the plugin
     4*
     5* This file is used to markup the admin-facing aspects of the plugin.
     6*
     7* @link       http://www.datainterlock.com
     8* @since      1.0.0
     9*
     10* @package    Notepress2
     11* @subpackage Notepress2/admin/partials
     12
     13*/
    3114/**
    32 
    33  * Represents the view for the administration dashboard.
    34 
    35  *
    36 
    37  * This includes the header, options, and other information that should provide
    38 
    39  * The User Interface to the end user.
    40 
    41  *
    42 
    43  * @package   Note_Press
    44 
    45  * @author    datainterlock <postmaster@datainterlock.com>
    46 
    47  * @license   GPL-3.0+
    48 
    49  * @link      http://www.datainterlock.com
    50 
    51  * @Copyright (C) 2015 Rod Kinnison postmaster@datainterlock.com
    52 
    53  */
    54 
    55 
     15* Represents the view for the administration dashboard.
     16*
     17* This includes the header, options, and other information that should provide
     18* The User Interface to the end user.
     19*
     20* @package   Note_Press
     21* @author    datainterlock <postmaster@datainterlock.com>
     22* @license   GPL-3.0+
     23* @link      http://www.datainterlock.com
     24* @Copyright (C) 2015 Rod Kinnison postmaster@datainterlock.com
     25*/
    5626
    5727if (!defined('WPINC'))
    58 
    59     {
    60 
     28    {
    6129    die;
    62 
    63     }
    64 
     30    }
    6531echo '<div class="wrap">';
    66 
    6732echo '<table width="100%" cellpadding="5">';
    68 
    6933echo '<tr><td width="100px"><img src="' . plugin_dir_url(__FILE__) . 'images/NPLogo1.png" align="bottom" hspace="3" width="100" height="97" /></td>';
    70 
    7134echo '<td><h1>' . __('Note Press', 'Note_Press') . '</h1>';
    72 
    7335echo '<p>' . __('For more information and instructions please visit our website at: ', 'Note_Press') . '<a href="http://www.datainterlock.com" target="_blank">http://www.datainterlock.com</a>
    7436
     
    8446
    8547<br>';
    86 
    87 echo __('Please consider supporting the development of Note Press by clicking the image above and becoming a Patreon.','Note_Press');
    88 
     48echo __('Please consider supporting the development of Note Press by clicking the image above and becoming a Patreon.', 'Note_Press');
    8949echo '
    9050
     
    9252
    9353</tr></table><hr />';
    94 
    9554if (!class_exists('WP_List_Table'))
    96 
    97     {
    98 
     55    {
    9956    require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
    100 
    101     }
    102 
     57    }
    10358class Note_Press_List_Table extends WP_List_Table
    104 
    105     {
    106 
     59    {
    10760    var $example_data = array();
    108 
    10961    function __construct()
    110 
    111         {
    112 
     62        {
    11363        global $status, $page;
    114 
    11564        parent::__construct(array(
    116 
    11765            'singular' => __('note', 'mylisttable'),
    118 
    11966            'plural' => __('notes', 'mylisttable'),
    120 
    12167            'ajax' => false
    122 
    12368        ));
    124 
    125         }
    126 
     69        }
    12770    function column_default($item, $column_name)
    128 
    129         {
    130 
     71        {
    13172        if (is_super_admin())
    132 
    133         {
    134 
    135         switch ($column_name)
    136 
    137         {
    138 
    139             case 'icon':
    140 
    141             case 'title':
    142 
    143             case 'addedby':
    144 
    145             case 'userto':
    146 
    147             case 'datetime':
    148 
    149             case 'priority':
    150 
    151             case 'userread':
    152 
    153             case 'deadline':
    154 
    155                 return $item[$column_name];
    156 
     73            {
     74            switch ($column_name)
     75            {
     76                case 'icon':
     77                case 'title':
     78                case 'addedby':
     79                case 'userto':
     80                case 'datetime':
     81                case 'priority':
     82                case 'userread':
     83                case 'deadline':
     84                    return $item[$column_name];
     85                default:
     86                    return print_r($item, true);
     87            }
     88            }
     89        else
     90            {
     91            switch ($column_name)
     92            {
     93                case 'icon':
     94                case 'title':
     95                case 'addedby':
     96                case 'datetime':
     97                case 'priority':
     98                case 'deadline':
     99                    return $item[$column_name];
     100                default:
     101                    return print_r($item, true);
     102            }
     103            }
     104        }
     105    function column_title($item)
     106        {
     107        $actions = array(
     108            'view' => sprintf('<a href="?page=%s&action=%s&id=%s">' . __('View', 'Note_Press') . '</a>', $_REQUEST['page'], 'view', $item['ID']),
     109            'edit' => sprintf('<a href="?page=%s&action=%s&id=%s">' . __('Edit', 'Note_Press') . '</a>', $_REQUEST['page'], 'edit', $item['ID']),
     110            'delete' => sprintf('<a href="?page=%s&action=%s&id=%s" onclick="return confirm(\'' . __('Are you sure you want to delete this note?', 'Note_Press') . '\')">' . __('Delete', 'Note_Press') . '</a>', $_REQUEST['page'], 'delete', $item['ID'])
     111        );
     112        return sprintf('%1$s %2$s', $item['title'], $this->row_actions($actions));
     113        }
     114    function get_bulk_actions()
     115        {
     116        $actions = array(
     117            'delete' => __('Delete', 'Note_Press')
     118        );
     119        return $actions;
     120        }
     121    function column_cb($item)
     122        {
     123        return sprintf('<input type="checkbox" name="id[]" value="%s" />', $item['ID']);
     124        }
     125    function get_columns()
     126        {
     127        if (is_super_admin())
     128            {
     129            $columns = array(
     130                'cb' => '<input type="checkbox" />',
     131                'icon' => __('Icon', 'Note_Press'),
     132                'title' => __('Title', 'Note_Press'),
     133                'addedby' => __('By', 'Note_Press'),
     134                'userto' => __('To', 'Note_Press'),
     135                'datetime' => __('Date', 'Note_Press'),
     136                'priority' => __('Priority', 'Note_Press'),
     137                'userread' => __('Read', 'Note_Press'),
     138                'deadline' => __('Deadline', 'Note_Press')
     139            );
     140            }
     141        else
     142            {
     143            $columns = array(
     144                'cb' => '<input type="checkbox" />',
     145                'icon' => __('Icon', 'Note_Press'),
     146                'title' => __('Title', 'Note_Press'),
     147                'addedby' => __('By', 'Note_Press'),
     148                'datetime' => __('Date', 'Note_Press'),
     149                'priority' => __('Priority', 'Note_Press'),
     150                'deadline' => __('Deadline', 'Note_Press')
     151            );
     152            }
     153        return $columns;
     154        }
     155    function get_sortable_columns()
     156        {
     157        if (is_super_admin())
     158            {
     159            $sortable_columns = array(
     160                'title' => array(
     161                    'title',
     162                    false
     163                ),
     164                'addedby' => array(
     165                    'addedby',
     166                    false
     167                ),
     168                'userto' => array(
     169                    'userto',
     170                    false
     171                ),
     172                'userread' => array(
     173                    'userread',
     174                    false
     175                ),
     176                'datetime' => array(
     177                    'datetime',
     178                    false
     179                ),
     180                'priority' => array(
     181                    'priority',
     182                    false
     183                ),
     184                'deadline' => array(
     185                    'deadline',
     186                    false
     187                )
     188            );
     189            }
     190        else
     191            {
     192            $sortable_columns = array(
     193                'title' => array(
     194                    'title',
     195                    false
     196                ),
     197                'addedby' => array(
     198                    'addedby',
     199                    false
     200                ),
     201                'datetime' => array(
     202                    'datetime',
     203                    false
     204                ),
     205                'priority' => array(
     206                    'priority',
     207                    false
     208                ),
     209                'deadline' => array(
     210                    'deadline',
     211                    false
     212                )
     213            );
     214            }
     215        return $sortable_columns;
     216        }
     217    function get_items($column = 'title', $order = 'DESC')
     218        {
     219        global $wpdb;
     220        $table_name = $wpdb->prefix . "Note_Press";
     221        switch ($order)
     222        {
     223            case 'asc':
     224                $order = 'ASC';
     225                break;
     226            case 'desc':
     227                $order = 'DESC';
     228                break;
     229            case 'ASC':
     230                $order = 'ASC';
     231                break;
     232            case 'DESC':
     233                $order = 'ASC';
     234                break;
    157235            default:
    158 
    159                 return print_r($item, true);
    160 
    161         }
    162 
    163         }
    164 
    165         else
    166 
    167         {
    168 
    169         switch ($column_name)
    170 
    171         {
    172 
    173             case 'icon':
    174 
    175             case 'title':
    176 
    177             case 'addedby':
    178 
    179             case 'datetime':
    180 
    181             case 'priority':
    182 
    183             case 'deadline':
    184 
    185                 return $item[$column_name];
    186 
    187             default:
    188 
    189                 return print_r($item, true);
    190 
    191         }
    192 
    193         }
    194 
    195         }
    196 
    197     function column_title($item)
    198 
    199         {
    200 
    201         $actions = array(
    202 
    203             'view' => sprintf('<a href="?page=%s&action=%s&id=%s">' . __('View', 'Note_Press') . '</a>', $_REQUEST['page'], 'view', $item['ID']),
    204 
    205             'edit' => sprintf('<a href="?page=%s&action=%s&id=%s">' . __('Edit', 'Note_Press') . '</a>', $_REQUEST['page'], 'edit', $item['ID']),
    206 
    207             'delete' => sprintf('<a href="?page=%s&action=%s&id=%s" onclick="return confirm(\'' . __('Are you sure you want to delete this note?', 'Note_Press') . '\')">' . __('Delete', 'Note_Press') . '</a>', $_REQUEST['page'], 'delete', $item['ID'])
    208 
     236                $order = 'DESC';
     237        }
     238        if (is_super_admin())
     239            {
     240            switch ($column)
     241            {
     242                case 'title':
     243                    $column = 'Title';
     244                    break;
     245                case 'addedby':
     246                    $column = 'AddedBy';
     247                    break;
     248                case 'userto':
     249                    $column = 'UserTo';
     250                    break;
     251                case 'userread':
     252                    $column = 'UserRead';
     253                    break;
     254                case 'datetime':
     255                    $column = 'Date';
     256                    break;
     257                case 'priority':
     258                    $column = 'Priority';
     259                    break;
     260                case 'deadline':
     261                    $column = 'Deadline';
     262                    break;
     263                default:
     264                    $column = 'Title';
     265            }
     266            }
     267        else
     268            {
     269            switch ($column)
     270            {
     271                case 'title':
     272                    $column = 'Title';
     273                    break;
     274                case 'addedby':
     275                    $column = 'AddedBy';
     276                    break;
     277                case 'datetime':
     278                    $column = 'Date';
     279                    break;
     280                case 'priority':
     281                    $column = 'Priority';
     282                    break;
     283                case 'deadline':
     284                    $column = 'Deadline';
     285                    break;
     286                default:
     287                    $column = 'Title';
     288            }
     289            }
     290        $uid = get_current_user_id();
     291        if (isset($_GET['s']))
     292            {
     293            if (is_super_admin())
     294                {
     295                $myfilter = " where Title LIKE '%%%s%%' or Content LIKE '%%%s%%'";
     296                }
     297            else
     298                {
     299                $myfilter = " where Title LIKE '%%%s%%' or Content LIKE '%%%s%%' and userTo = $uid";
     300                }
     301            $SQL = $wpdb->prepare("SELECT * FROM $table_name" . $myfilter . " order by $column $order", $_GET['s'], $_GET['s']);
     302            }
     303        else
     304            {
     305            if (is_super_admin())
     306                {
     307                $SQL = "SELECT * FROM $table_name order by $column $order";
     308                }
     309            else
     310                {
     311                $SQL = "SELECT * FROM $table_name where userTo = $uid order by $column $order";
     312                }
     313            }
     314        $mylink = $wpdb->get_results($SQL);
     315        return $mylink;
     316        }
     317    function prepare_items()
     318        {
     319        $_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', $_SERVER['REQUEST_URI']);
     320        if (isset($_GET['orderby']) && isset($_GET['order']))
     321            {
     322            $orderby = $_GET['orderby'];
     323            $order   = $_GET['order'];
     324            }
     325        else
     326            {
     327            $orderby = 'title';
     328            $order   = 'ASC';
     329            }
     330        $mylink = $this->get_items($orderby, $order);
     331        foreach ($mylink as $link)
     332            {
     333            $users = get_users(array(
     334                'fields' => array(
     335                    'display_name',
     336                    'ID'
     337                )
     338            ));
     339            foreach ($users as $user)
     340                {
     341                if ($user->ID == $link->AddedBy)
     342                    {
     343                    $username = $user->display_name;
     344                    }
     345                if ($user->ID == $link->userTo)
     346                    {
     347                    $userto = $user->display_name;
     348                    }
     349                }
     350            $iconpath = get_option("Note_Press_icons_url") . $link->Icon;
     351            switch ($link->Priority)
     352            {
     353                case 0:
     354                    $picon = "<img src=" . plugins_url('admin/images/P0.png', dirname(__FILE__)) . " alt='Icon not found'>";
     355                    break;
     356                case 1:
     357                    $picon = "<img src=" . plugins_url('admin/images/P1.png', dirname(__FILE__)) . " alt='Icon not found'>";
     358                    break;
     359                case 2:
     360                    $picon = "<img src=" . plugins_url('admin/images/P2.png', dirname(__FILE__)) . " alt='Icon not found'>";
     361                    break;
     362            }
     363            if ($link->Deadline == NULL)
     364                {
     365                $thisdate = '';
     366                }
     367            else
     368                {
     369                $date     = new DateTime($link->Deadline);
     370                $thisdate = date_format($date, 'Y-m-d');
     371                }
     372            if (is_super_admin())
     373                {
     374                switch ($link->userRead)
     375                {
     376                    case 0:
     377                        $userread = "<img src=" . plugins_url('admin/images/X.png', dirname(__FILE__)) . " alt='Icon not found'>";
     378                        break;
     379                    case 1:
     380                        $userread = "<img src=" . plugins_url('admin/images/CH.png', dirname(__FILE__)) . " alt='Icon not found'>";
     381                        break;
     382                }
     383                $example_data[] = array(
     384                    'ID' => $link->ID,
     385                    'icon' => '<img src="' . $iconpath . '" width="16" height="16" />',
     386                    'title' => '<a href="?page=Note_Press-Main-Menu&action=view&id=' . $link->ID . '">' . $link->Title . '</a>',
     387                    'addedby' => $username,
     388                    'userto' => $userto,
     389                    'userread' => $userread,
     390                    'datetime' => $link->Date,
     391                    'priority' => $picon,
     392                    'deadline' => $thisdate
     393                );
     394                }
     395            else
     396                {
     397                $example_data[] = array(
     398                    'ID' => $link->ID,
     399                    'icon' => '<img src="' . $iconpath . '" width="16" height="16" />',
     400                    'title' => '<a href="?page=Note_Press-Main-Menu&action=view&id=' . $link->ID . '">' . $link->Title . '</a>',
     401                    'addedby' => $username,
     402                    'datetime' => $link->Date,
     403                    'priority' => $picon,
     404                    'deadline' => $thisdate
     405                );
     406                }
     407            }
     408        $columns               = $this->get_columns();
     409        $hidden                = array();
     410        $sortable              = $this->get_sortable_columns();
     411        $this->_column_headers = array(
     412            $columns,
     413            $hidden,
     414            $sortable
    209415        );
    210 
    211         return sprintf('%1$s %2$s', $item['title'], $this->row_actions($actions));
    212 
    213         }
    214 
    215     function get_bulk_actions()
    216 
    217         {
    218 
    219         $actions = array(
    220 
    221             'delete' => __('Delete', 'Note_Press')
    222 
    223         );
    224 
    225         return $actions;
    226 
    227         }
    228 
    229     function column_cb($item)
    230 
    231         {
    232 
    233         return sprintf('<input type="checkbox" name="id[]" value="%s" />', $item['ID']);
    234 
    235         }
    236 
    237     function get_columns()
    238 
    239         {
    240 
    241         if (is_super_admin())
    242 
    243         {
    244 
    245         $columns = array(
    246 
    247             'cb' => '<input type="checkbox" />',
    248 
    249             'icon' => __('Icon', 'Note_Press'),
    250 
    251             'title' => __('Title', 'Note_Press'),
    252 
    253             'addedby' => __('By', 'Note_Press'),
    254 
    255             'userto' => __('To', 'Note_Press'),
    256 
    257             'datetime' => __('Date', 'Note_Press'),
    258 
    259             'priority' => __('Priority', 'Note_Press'),
    260 
    261             'userread' => __('Read', 'Note_Press'),
    262 
    263             'deadline' => __('Deadline', 'Note_Press')
    264 
    265         );
    266 
    267         }
    268 
    269         else
    270 
    271         {
    272 
    273         $columns = array(
    274 
    275             'cb' => '<input type="checkbox" />',
    276 
    277             'icon' => __('Icon', 'Note_Press'),
    278 
    279             'title' => __('Title', 'Note_Press'),
    280 
    281             'addedby' => __('By', 'Note_Press'),
    282 
    283             'datetime' => __('Date', 'Note_Press'),
    284 
    285             'priority' => __('Priority', 'Note_Press'),
    286 
    287             'deadline' => __('Deadline', 'Note_Press')
    288 
    289         );
    290 
    291         }
    292 
    293         return $columns;
    294 
    295         }
    296 
    297     function get_sortable_columns()
    298 
    299         {
    300 
    301         if (is_super_admin())
    302 
    303         {
    304 
    305         $sortable_columns = array(
    306 
    307             'title' => array(
    308 
    309                 'title',
    310 
    311                 false
    312 
    313             ),
    314 
    315             'addedby' => array(
    316 
    317                 'addedby',
    318 
    319                 false
    320 
    321             ),
    322 
    323             'userto' => array(
    324 
    325                 'userto',
    326 
    327                 false
    328 
    329             ),
    330 
    331             'userread' => array(
    332 
    333                 'userread',
    334 
    335                 false
    336 
    337             ),
    338 
    339             'datetime' => array(
    340 
    341                 'datetime',
    342 
    343                 false
    344 
    345             ),
    346 
    347             'priority' => array(
    348 
    349                 'priority',
    350 
    351                 false
    352 
    353             ),
    354 
    355             'deadline' => array(
    356 
    357                 'deadline',
    358 
    359                 false
    360 
     416        $per_page              = 5;
     417        $current_page          = $this->get_pagenum();
     418        $total_items           = count(@$example_data);
     419        if ($total_items > 0)
     420            {
     421            $example_data = array_slice($example_data, (($current_page - 1) * $per_page), $per_page);
     422            }
     423        $this->set_pagination_args(array(
     424            'total_items' => $total_items,
     425            'per_page' => $per_page
     426        ));
     427        $this->items = @$example_data;
     428        }
     429    }
     430function Note_Press_render_list_page()
     431    {
     432    $myListTable = new Note_Press_List_Table();
     433    $myListTable->prepare_items();
     434    echo '</pre><div class="wrap"><h3>' . __('Notes', 'Note_Press') . '</h3>';
     435    echo '<hr>';
     436    echo '<form method="get">';
     437    $nonce = wp_create_nonce('Note-Press-nonce');
     438    echo '<input type="hidden" name="_wpnonce" value="' . $nonce . '">';
     439    echo '<input type="hidden" name="page" value="' . $_REQUEST['page'] . '" />' . $myListTable->search_box(__("Search", "Note_Press"), 'search_id');
     440    echo '</form>';
     441    echo '<form id="events-filter" method="get">';
     442    echo '<input type="hidden" name="page" value="' . $_REQUEST['page'] . '" />';
     443    $myListTable->display();
     444    echo '</form>';
     445    echo '</div>';
     446    }
     447function Note_PressshowMessage($message, $errormsg = false)
     448    {
     449    if ($errormsg)
     450        {
     451        echo '<div id="message" class="error">';
     452        }
     453    else
     454        {
     455        echo '<div id="message" class="updated fade">';
     456        }
     457    echo "<p><strong>$message</strong></p></div>";
     458    }
     459function Note_Pressshow_menu()
     460    {
     461    echo '<form action="" method="get">';
     462    echo '<button class="button-primary" type="submit" name="action" value="Add">' . __('Add A Note', 'Note_Press') . '</button>';
     463    echo '<input name="page" type="hidden" value="Note_Press-Main-Menu" />';
     464    echo '</form><hr>';
     465    }
     466function Note_Pressget_notes()
     467    {
     468    global $wpdb;
     469    Note_Pressshow_menu();
     470    Note_Press_render_list_page();
     471    }
     472function Note_Pressshow_note($which)
     473    {
     474    global $wpdb;
     475    $table_name = $wpdb->prefix . "Note_Press";
     476    $link       = $wpdb->get_row("SELECT * FROM $table_name where ID=$which");
     477    if ($link->userTo == get_current_user_id())
     478        {
     479        $wpdb->update($table_name, array(
     480            'userRead' => '1'
     481        ), array(
     482            'ID' => $which
     483        ), array(
     484            '%s'
     485        ), array(
     486            '%d'
     487        ));
     488        }
     489    if (!$link)
     490        {
     491        Note_PressshowMessage(__('That note was not found.', 'Note_Press'), true);
     492        Note_Pressget_notes();
     493        }
     494    else
     495        {
     496        $users = get_users(array(
     497            'fields' => array(
     498                'display_name',
     499                'ID'
    361500            )
    362 
    363         );
    364 
    365         }
    366 
    367         else
    368 
    369         {
    370 
    371         $sortable_columns = array(
    372 
    373             'title' => array(
    374 
    375                 'title',
    376 
    377                 false
    378 
    379             ),
    380 
    381             'addedby' => array(
    382 
    383                 'addedby',
    384 
    385                 false
    386 
    387             ),
    388 
    389             'datetime' => array(
    390 
    391                 'datetime',
    392 
    393                 false
    394 
    395             ),
    396 
    397             'priority' => array(
    398 
    399                 'priority',
    400 
    401                 false
    402 
    403             ),
    404 
    405             'deadline' => array(
    406 
    407                 'deadline',
    408 
    409                 false
    410 
    411             )
    412 
    413         );
    414 
    415         }
    416 
    417         return $sortable_columns;
    418 
    419         }
    420 
    421     function get_items($column = 'title', $order = 'DESC')
    422 
    423         {
    424 
    425         global $wpdb;
    426 
    427    
    428 
     501        ));
     502        foreach ($users as $user)
     503            {
     504            if ($user->ID == $link->AddedBy)
     505                {
     506                $username = $user->display_name;
     507                }
     508            }
     509        echo '<h3>' . __('View a Note', 'Note_Press') . '</h3>';
     510        echo '<hr>';
     511        echo '<form action="" method="get">';
     512        echo '<input name="page" type="hidden" value="Note_Press-Main-Menu" />';
     513        echo '<button class="button-primary" type="submit" name="edit" value="' . $link->ID . '">' . __('Edit This Note', 'Note_Press') . '</button>';
     514        echo '&nbsp;';
     515        echo '<button class="button-primary" type="submit" name="action" value="List">' . __('Back to List', 'Note_Press') . '</button>';
     516        echo '</form><hr>';
     517        $iconpath = get_option("Note_Press_icons_url") . $link->Icon;
     518        echo '<table class="form-table widefat ltr" border="1" width="100%">';
     519        echo "<tr><td><h3><img src='$iconpath' width='16' height='16' />&nbsp;&nbsp;" . __('Title:', 'Note_Press') . " $link->Title</h3></td></tr>";
     520        echo "<tr><td><p><strong>" . __('Date Added/Last Edited:', 'Note_Press') . "</strong> $link->Date</p></td></tr>";
     521        echo "<tr><td><p><strong>" . __('Added By:', 'Note_Press') . "</strong> $username</p></td></tr>";
     522        switch ($link->Priority)
     523        {
     524            case 0:
     525                $picon = "<img src=" . plugins_url('admin/images/P0.png', dirname(__FILE__)) . " alt='Icon not found'>";
     526                break;
     527            case 1:
     528                $picon = "<img src=" . plugins_url('admin/images/P1.png', dirname(__FILE__)) . " alt='Icon not found'>";
     529                break;
     530            case 2:
     531                $picon = "<img src=" . plugins_url('admin/images/P2.png', dirname(__FILE__)) . " alt='Icon not found'>";
     532                break;
     533        }
     534        echo "<tr><td><p><strong>" . __('Priority:', 'Note_Press') . "</strong> $picon</p></td></tr>";
     535        if ($link->Deadline == NULL)
     536            {
     537            $thisdate = '';
     538            }
     539        else
     540            {
     541            $date     = new DateTime($link->Deadline);
     542            $thisdate = date_format($date, 'Y-m-d');
     543            }
     544        echo "<tr><td><p><strong>" . __('Deadline:', 'Note_Press') . "</strong> $thisdate</p></td></tr>";
     545        $content = do_shortcode(nl2br($link->Content));
     546        echo "<tr><td><p><strong>" . __('Contents:', 'Note_Press') . "</strong></p><hr><p> $content</p></td></tr>";
     547        echo '</table>';
     548        }
     549    }
     550function Note_Pressadd_note($which = -1)
     551    {
     552    global $wpdb, $current_user, $wp_roles;
     553    if ($which <> -1)
     554        {
    429555        $table_name = $wpdb->prefix . "Note_Press";
    430 
    431         switch ($order)
    432 
    433         {
    434 
    435             case 'asc':
    436 
    437                 $order = 'ASC';
    438 
     556        $mylink     = $wpdb->get_row("SELECT * FROM $table_name where ID=$which");
     557        if (!$mylink)
     558            {
     559            Note_PressshowMessage(__('That note was not found.', 'Note_Press'), true);
     560            Note_Pressget_notes();
     561            exit;
     562            }
     563        }
     564    echo '<form action="" method="get">';
     565    echo '<input name="page" type="hidden" value="Note_Press-Main-Menu" />';
     566    echo '<button class="button-primary" type="submit" name="List" value="List">' . __('Back to List', 'Note_Press') . '</button>';
     567    echo '<hr>';
     568    echo '</form>';
     569    echo '<form action="" method="post">';
     570    $nonce = wp_create_nonce('Note-Press-nonce');
     571    echo '<input type="hidden" name="_wpnonce" value="' . $nonce . '">';
     572    if ($which <> -1)
     573        {
     574        echo '<h3>' . __('Edit a Note', 'Note_Press') . '</h3>';
     575        }
     576    else
     577        {
     578        echo '<h3>' . __('Add a Note', 'Note_Press') . '</h3>';
     579        }
     580    echo '<hr>';
     581    echo '<div id="poststuff">
     582
     583            <div id="post-body" class="metabox-holder columns-2">
     584
     585
     586
     587                <div id="post-body-content">';
     588    echo '          <div id="namediv" class="stuffbox">';
     589    echo '              <h3><label for="Title">' . __('Title:', 'Note_Press') . '</label></h3>';
     590    echo '              <div class="inside">';
     591    echo '                  <input name="Title" type="text" id="Title" size="100" maxlength="255" value="';
     592    if ($which <> -1)
     593        {
     594        echo $mylink->Title;
     595        }
     596    echo '" required>
     597
     598
     599
     600                            <p>' . __('Enter a title for this note.', 'Note_Press') . '</p>';
     601    echo '              </div>';
     602    echo '          </div>';
     603    if ($which == -1)
     604        {
     605        // ******************************************************  User To
     606        echo '          <div id="namediv" class="stuffbox">';
     607        echo '              <h3><label for="To">' . __('To:', 'Note_Press') . '</label></h3>';
     608        echo '              <div class="inside">';
     609        if (is_multisite())
     610        {
     611            $blogs = $wpdb->get_results("SELECT blog_id FROM {$wpdb->blogs}", ARRAY_A);
     612            if ($blogs)
     613            {
     614                $userlist = NULL;
     615                foreach($blogs as $blog)
     616                {
     617                    $userlist = get_users( array(
     618                    'blog_id'  => get_current_blog_id()
     619                    ));
     620                    //$userlist = (object) array_merge((array) $userlist, (array) $templist);
     621                }
     622            }
     623        }
     624        else
     625        {
     626            echo 'No';
     627            $userlist = get_users();
     628        }
     629        echo '                  <select name="UserTo[]" multiple="multiple" required>';
     630        $roles = $wp_roles->get_names();
     631        foreach ($roles as $role)
     632            {
     633            if ($role <> "Subscriber")
     634                {
     635                echo '<option value="' . $role . '">' . $role . '</option>';
     636                }
     637            }
     638        foreach ($userlist as $user)
     639            {
     640            $checked = '';
     641            if (!in_array( 'subscriber', (array) $user->roles ) )
     642                {
     643                    if ($user->ID == get_current_user_id())
     644                    {
     645                    $checked = ' selected = "selected"';
     646                    }
     647                echo '<option value="' . $user->ID . '"' . $checked . '>' . $user->display_name . '</option>';
     648                }
     649            }
     650        echo '                      </select> ';
     651        echo '                  <p>' . __('Choose who you wish to send this note to. Ctl-click to choose multiple recipients.', 'Note_Press') . '</p>';
     652        echo '              </div>';
     653        echo '          </div>';
     654        // ******************************************************
     655        }
     656    $checked = '';
     657    $color   = '';
     658    if ($which <> -1)
     659        {
     660        if ($mylink->Sticky == 1)
     661            {
     662            $checked = ' checked = "checked"';
     663            $color   = $mylink->StickyColor;
     664            }
     665        }
     666    // ******************************************************  Color Picker Test
     667    echo '          <div id="namediv" class="stuffbox">';
     668    echo '              <h3><label for="To">' . __('Sticky Note:', 'Note_Press') . '</label></h3>';
     669    echo '              <div class="inside">';
     670    echo '              <input style="width:10px" type="checkbox" name="makesticky"' . $checked . '>Make this note a Dashboard sticky.<br><br>';
     671    echo '              <input name="stickycolor" type="text" value="' . $color . '" class="NPcolor-field" />';
     672    echo '                  <p>' . __('<strong>Note: </strong>Users who do not have the ability to write notes can only see Sticky Notes.', 'Note_Press') . '</p>';
     673    echo '              </div>';
     674    echo '          </div>';
     675    // ****************************************************** Deadline
     676    $thisdate = '';
     677    if ($which <> -1)
     678        {
     679        if ($mylink->Deadline == NULL)
     680            {
     681            $thisdate = '';
     682            }
     683        else
     684            {
     685            $date     = new DateTime($mylink->Deadline);
     686            $thisdate = date_format($date, 'Y-m-d');
     687            }
     688        }
     689    echo '          <div id="namediv" class="stuffbox">';
     690    echo '              <h3><label for="Deadline">' . __('Deadline:', 'Note_Press') . '</label></h3>';
     691    echo '              <div class="inside">';
     692    echo '                  <input name="Deadline" type="date" id="Date" pattern="[0-9]{4}-[0-9]{2}-[0-9]{2}" value="' . $thisdate . '">';
     693    echo '                  <p>' . __('Enter a deadline for this note or leave this field blank for no deadline.</br> <strong>Not all browswers support a date picker</strong>. If you do not have the option to select a date, please enter one in the format MM/DD/YYYY.', 'Note_Press') . '</p>';
     694    echo '              </div>';
     695    echo '          </div>';
     696    $checked1 = '';
     697    $checked2 = '';
     698    $checked3 = '';
     699    if ($which <> -1)
     700        {
     701        switch ($mylink->Priority)
     702        {
     703            case 0:
     704                $checked1 = 'selected="selected"';
    439705                break;
    440 
    441             case 'desc':
    442 
    443                 $order = 'DESC';
    444 
     706            case 1:
     707                $checked2 = 'selected="selected"';
    445708                break;
    446 
    447             case 'ASC':
    448 
    449                 $order = 'ASC';
    450 
     709            case 2:
     710                $checked3 = 'selected="selected"';
    451711                break;
    452 
    453             case 'DESC':
    454 
    455                 $order = 'ASC';
    456 
    457                 break;
    458 
    459             default:
    460 
    461                 $order = 'DESC';
    462 
    463         }
    464 
    465         if (is_super_admin())
    466 
    467         {
    468 
    469         switch ($column)
    470 
    471         {
    472 
    473             case 'title':
    474 
    475                 $column = 'Title';
    476 
    477                 break;
    478 
    479             case 'addedby':
    480 
    481                 $column = 'AddedBy';
    482 
    483                 break;
    484 
    485             case 'userto':
    486 
    487                 $column = 'UserTo';
    488 
    489                 break;
    490 
    491             case 'userread':
    492 
    493                 $column = 'UserRead';
    494 
    495                 break;
    496 
    497             case 'datetime':
    498 
    499                 $column = 'Date';
    500 
    501                 break;
    502 
    503             case 'priority':
    504 
    505                 $column = 'Priority';
    506 
    507                 break;
    508 
    509             case 'deadline':
    510 
    511                 $column = 'Deadline';
    512 
    513                 break;
    514 
    515             default:
    516 
    517                 $column = 'Title';
    518 
    519         }
    520 
    521         }
    522 
    523         else
    524 
    525         {
    526 
    527         switch ($column)
    528 
    529         {
    530 
    531             case 'title':
    532 
    533                 $column = 'Title';
    534 
    535                 break;
    536 
    537             case 'addedby':
    538 
    539                 $column = 'AddedBy';
    540 
    541                 break;
    542 
    543             case 'datetime':
    544 
    545                 $column = 'Date';
    546 
    547                 break;
    548 
    549             case 'priority':
    550 
    551                 $column = 'Priority';
    552 
    553                 break;
    554 
    555             case 'deadline':
    556 
    557                 $column = 'Deadline';
    558 
    559                 break;
    560 
    561             default:
    562 
    563                 $column = 'Title';
    564 
    565         }
    566 
    567         }
    568 
    569         $uid = get_current_user_id();
    570 
    571         if (isset($_GET['s']))
    572 
    573             {
    574 
    575             if (is_super_admin())
    576 
    577             {
    578 
    579                 $myfilter = " where Title LIKE '%%%s%%' or Content LIKE '%%%s%%'";
    580 
    581             }
    582 
     712        }
     713        }
     714    echo '          <div id="namediv" class="stuffbox">';
     715    echo '              <h3><label for="Priority">' . __('Priority:', 'Note_Press') . '</label></h3>';
     716    echo '              <div class="inside">';
     717    echo '                 
     718
     719                            <select name="Priority">
     720
     721                            <option value=0 style="background-image:url(' . plugins_url('admin/images/P0.png', dirname(__FILE__)) . ')" ' . $checked1 . '>' . __("Low", "Note_Press") . '</option>
     722
     723                            <option value=1 style="background-image:url(' . plugins_url('admin/images/P1.png', dirname(__FILE__)) . ')" ' . $checked2 . '>' . __("Medium", "Note_Press") . '</option>
     724
     725                            <option value=2 style="background-image:url(' . plugins_url('admin/images/P2.png', dirname(__FILE__)) . ')" ' . $checked3 . '>' . __("High", "Note_Press") . '</option>
     726
     727                            </select> ';
     728    echo '                  <p>' . __('Select a priority for this note.', 'Note_Press') . '</p>';
     729    echo '              </div>';
     730    echo '          </div>';
     731    echo '          <div id="icondiv" class="stuffbox">';
     732    echo '              <h3><label for="Icon">' . __('Icon:', 'Note_Press') . '</label></h3>';
     733    echo '              <div class="inside">';
     734    $count = 0;
     735    if ($which <> -1)
     736        {
     737        $blank = false;
     738        }
     739    else
     740        {
     741        $blank = true;
     742        }
     743    echo '<table width="100%" border="0">';
     744    $path  = get_option("Note_Press_icons_path");
     745    $files = scandir($path);
     746    foreach ($files as $myfile)
     747        {
     748        if ($myfile <> '.' && $myfile <> '..')
     749            {
     750            if ($count == 0)
     751                {
     752                echo '<tr>';
     753                $enddone = FALSE;
     754                }
     755            $iconpath = get_option("Note_Press_icons_url") . $myfile;
     756            echo '<td><input type="radio" name="iconselect[]" value="' . $myfile . '"';
     757            if ($blank)
     758                {
     759                echo ' checked ';
     760                $blank = false;
     761                }
     762            if ($which <> -1)
     763                {
     764                if ($mylink->Icon == $myfile)
     765                    {
     766                    echo ' checked ';
     767                    }
     768                }
     769            echo '><img src="' . $iconpath . '" width="16" height="16"/></td>';
     770            $count++;
     771            if ($count == 15)
     772                {
     773                $count = 0;
     774                echo '</tr>';
     775                $enddone = TRUE;
     776                }
     777            }
     778        }
     779    if (!$enddone)
     780        {
     781        echo '</tr>';
     782        }
     783    echo '</table>';
     784    echo '<p>' . __('Select an icon for this note.', 'Note_Press') . '</p>';
     785    echo '              </div>';
     786    echo '          </div>';
     787    echo '          <div id="authordiv" class="stuffbox">';
     788    $users = get_users(array(
     789        'fields' => array(
     790            'display_name',
     791            'ID'
     792        )
     793    ));
     794    foreach ($users as $user)
     795        {
     796        if ($which <> -1)
     797            {
     798            if ($user->ID == $mylink->AddedBy)
     799                {
     800                $username = $user->display_name;
     801                }
     802            }
     803        else
     804            {
     805            if ($user->ID == $current_user->ID)
     806                {
     807                $username = $user->display_name;
     808                }
     809            }
     810        }
     811    echo '          <h3><label for="Author">' . __('Author/Editor: ', 'Note_Press') . $username . '</label></h3>';
     812    echo '          <input name="display_name" type="hidden" value="' . $username . '" />';
     813    echo '          </div>';
     814    echo '          <div id="namediv" class="stuffbox">';
     815    echo '              <h3><label for="Note">' . __('Contents:', 'Note_Press') . '</label></h3>';
     816    echo '              <div class="inside">';
     817    if ($which <> -1)
     818        {
     819        $content = $mylink->Content;
     820        }
     821    else
     822        {
     823        $content = '';
     824        }
     825    $editor_id = 'Note_Presseditor';
     826    wp_editor($content, $editor_id);
     827    echo '              </div>';
     828    echo '          </div>';
     829    echo '      </div>';
     830    echo '
     831
     832                <div id="postbox-container-1" class="postbox-container">
     833
     834                    <div id="side-sortables" class="meta-box-sortables ui-sortable">
     835
     836                        <div id="linksubmitdiv" class="postbox ">
     837
     838                        <h3 class="hndle ui-sortable-handle"><span>' . __('Save', 'Note_Press') . '</span></h3>
     839
     840                            <div class="inside">
     841
     842                                <div class="submitbox" id="submitlink">
     843
     844                                    <div id="major-publishing-actions">                 
     845
     846                                        <div id="publishing-action">';
     847    if ($which <> -1)
     848        {
     849        echo '<button  class="button-primary" type="submit" name="Update" value="' . $mylink->ID . '">' . __('Update Note', 'Note_Press') . '</button>';
     850        }
     851    else
     852        {
     853        echo '<input name="DoAdd" type="submit" class="button-large button-primary" id="publish" accesskey="p" value="' . __('Add Note', 'Note_Press') . '">';
     854        }
     855    echo '                              </div>
     856
     857                                        <div class="clear">
     858
     859                                        </div>
     860
     861                                    </div>
     862
     863                                    <div class="clear">
     864
     865                                    </div>
     866
     867                                </div>
     868
     869                            </div>
     870
     871                        </div>
     872
     873                    </div>
     874
     875                </div>';
     876    echo '  </div>';
     877    echo '</div>';
     878    echo '<div id="clear"></div>';
     879    echo '</form>';
     880    }
     881function Note_Pressupdate_note($thisid)
     882    {
     883    global $wpdb;
     884    if (stripslashes_deep($_POST['Title']) == '')
     885        {
     886        Note_PressshowMessage(__('A note must have a title.', 'Note_Press'), true);
     887        Note_Pressget_notes();
     888        exit;
     889        }
     890    $table_name = $wpdb->prefix . "Note_Press";
     891    $mylink     = $wpdb->get_row("SELECT * FROM $table_name where ID=$thisid");
     892    if (!$mylink)
     893        {
     894        Note_PressshowMessage(__('That note was not found.', 'Note_Press'), true);
     895        }
     896    else
     897        {
     898        if (!empty($_POST['Deadline']))
     899            {
     900            $thisdate = date("Y-m-d H:i:s", strtotime($_POST['Deadline']));
     901            }
     902        else
     903            {
     904            $thisdate = NULL;
     905            }
     906        if (isset($_POST['makesticky']))
     907            {
     908            $makesticky  = 1;
     909            $stickycolor = $_POST['stickycolor'];
     910            }
     911        else
     912            {
     913            $makesticky  = 0;
     914            $stickycolor = $_POST['stickycolor'];
     915            }
     916        $wpdb->update($table_name, array(
     917            'Icon' => $_POST['iconselect'][0],
     918            'Title' => stripslashes_deep($_POST['Title']),
     919            'AddedBy' => get_current_user_id(),
     920            'Content' => stripslashes_deep($_POST["Note_Presseditor"]),
     921            'Date' => date("Y-m-d H:i:s"),
     922            'Deadline' => stripslashes_deep($thisdate),
     923            'Priority' => stripslashes_deep($_POST['Priority']),
     924            'Sticky' => stripslashes_deep($makesticky),
     925            'StickyColor' => stripslashes_deep($stickycolor),
     926            'userTo' => $mylink->userTo
     927        ), array(
     928            'ID' => $_POST['Update']
     929        ));
     930        Note_PressshowMessage($_POST['Title'] . ' updated.');
     931        }
     932    Note_Pressget_notes();
     933    }
     934function Note_Pressinsert_note()
     935    {
     936    global $wpdb;
     937    if (stripslashes_deep($_POST['Title']) == '')
     938        {
     939        Note_PressshowMessage(__('A note must have a title.', 'Note_Press'), true);
     940        Note_Pressget_notes();
     941        exit;
     942        }
     943    $table_name = $wpdb->prefix . "Note_Press";
     944    if (!empty($_POST['Deadline']))
     945        {
     946        $thisdate = date("Y-m-d H:i:s", strtotime($_POST['Deadline']));
     947        }
     948    else
     949        {
     950        $thisdate = NULL;
     951        }
     952    if (isset($_POST['makesticky']))
     953        {
     954        $makesticky  = 1;
     955        $stickycolor = $_POST['stickycolor'];
     956        }
     957    else
     958        {
     959        $makesticky  = 0;
     960        $stickycolor = $_POST['stickycolor'];
     961        }
     962    $sendto   = array();
     963    $userlist = get_users();
     964    foreach ($_POST['UserTo'] as $whoto)
     965        {
     966        if ($whoto == "Administrator")
     967            {
     968            foreach ($userlist as $user)
     969                {
     970                if (user_can($user, 'administrator'))
     971                    {
     972                    if (!in_array($user->ID, $sendto))
     973                        {
     974                        array_push($sendto, $user->ID);
     975                        }
     976                    }
     977                }
     978            }
     979        elseif ($whoto == "Editor")
     980            {
     981            foreach ($userlist as $user)
     982                {
     983                if (user_can($user, 'editor'))
     984                    {
     985                    if (!in_array($user->ID, $sendto))
     986                        {
     987                        array_push($sendto, $user->ID);
     988                        }
     989                    }
     990                }
     991            }
     992        elseif ($whoto == "Author")
     993            {
     994            foreach ($userlist as $user)
     995                {
     996                if (user_can($user, 'author'))
     997                    {
     998                    if (!in_array($user->ID, $sendto))
     999                        {
     1000                        array_push($sendto, $user->ID);
     1001                        }
     1002                    }
     1003                }
     1004            }
     1005        elseif ($whoto == "Contributor")
     1006            {
     1007            foreach ($userlist as $user)
     1008                {
     1009                if (user_can($user, 'contributor'))
     1010                    {
     1011                    if (!in_array($user->ID, $sendto))
     1012                        {
     1013                        array_push($sendto, $user->ID);
     1014                        }
     1015                    }
     1016                }
     1017            }
     1018        else
     1019            {
     1020            if (!in_array($whoto, $sendto))
     1021                {
     1022                array_push($sendto, $whoto);
     1023                }
     1024            }
     1025        }
     1026    foreach ($sendto as $idto)
     1027        {
     1028        $wpdb->insert($table_name, array(
     1029            'Icon' => $_POST['iconselect'][0],
     1030            'Title' => stripslashes_deep($_POST['Title']),
     1031            'AddedBy' => get_current_user_id(),
     1032            'Content' => stripslashes_deep($_POST["Note_Presseditor"]),
     1033            'Date' => date("Y-m-d H:i:s"),
     1034            'Deadline' => stripslashes_deep($thisdate),
     1035            'Priority' => stripslashes_deep($_POST['Priority']),
     1036            'Sticky' => stripslashes_deep($makesticky),
     1037            'StickyColor' => stripslashes_deep($stickycolor),
     1038            'userTo' => $idto
     1039        ));
     1040        }
     1041    Note_PressshowMessage($_POST['Title'] . ' Added.');
     1042    Note_Pressget_notes();
     1043    }
     1044function Note_Pressdelete_multi_note($thisid)
     1045    {
     1046    global $wpdb;
     1047    $table_name = $wpdb->prefix . "Note_Press";
     1048    $mylink     = $wpdb->get_results("SELECT * FROM $table_name where ID=$thisid");
     1049    if (!$mylink)
     1050        {
     1051        }
     1052    else
     1053        {
     1054        $wpdb->delete($table_name, array(
     1055            'ID' => $thisid
     1056        ));
     1057        }
     1058    }
     1059function Note_Pressdelete_note($thisid)
     1060    {
     1061    global $wpdb;
     1062    $table_name = $wpdb->prefix . "Note_Press";
     1063    $mylink     = $wpdb->get_results("SELECT * FROM $table_name where ID=$thisid");
     1064    if (!$mylink)
     1065        {
     1066        Note_PressshowMessage(__('That note was not found', 'Note_Press'), true);
     1067        }
     1068    else
     1069        {
     1070        $wpdb->delete($table_name, array(
     1071            'ID' => $thisid
     1072        ));
     1073        Note_PressshowMessage(__('Note Deleted!', 'Note_Press'));
     1074        }
     1075    }
     1076function Note_PressCheckDB()
     1077    {
     1078    global $wpdb;
     1079    $tablename = $wpdb->prefix . "Note_Press";
     1080    $bt=false;
     1081    if ($wpdb->get_var("SHOW TABLES LIKE 'datainterlock_wp_Note_Press'") == "datainterlock_wp_Note_Press")
     1082    {
     1083        if (get_bloginfo('name') != 'DataInterlock')
     1084        {
     1085            $bt=true;
     1086        }
     1087    }
     1088    $SQL       = "SHOW COLUMNS FROM $tablename LIKE 'Sticky'";
     1089    $wpdb->get_results($SQL);
     1090    if ($wpdb->num_rows == 0 || $bt)
     1091        {
     1092        Note_PressshowMessage(__('Please deactivate and re-activate Note Press to complete the upgrade.', 'Note_Press'), true);
     1093        return true;
     1094        }
     1095    else
     1096        {
     1097        return false;
     1098        }
     1099    }
     1100if (Note_PressCheckDB())
     1101    {
     1102    die();
     1103    }
     1104if (isset($_REQUEST['_wpnonce']))
     1105    {
     1106    $nonce = $_REQUEST['_wpnonce'];
     1107    if (!wp_verify_nonce($nonce, 'Note-Press-nonce'))
     1108        {
     1109        // This nonce is not valid.
     1110        die('Security check');
     1111        }
     1112    }
     1113if (isset($_POST['Update']))
     1114    {
     1115    Note_Pressupdate_note($_POST['Update']);
     1116    }
     1117elseif (isset($_POST['DoAdd']))
     1118    {
     1119    Note_Pressinsert_note();
     1120    }
     1121elseif (isset($_GET['s']))
     1122    {
     1123    Note_Pressget_notes();
     1124    }
     1125elseif (isset($_GET['List']) || isset($_GET['orderby']) && isset($_GET['order']))
     1126    {
     1127    Note_Pressget_notes();
     1128    }
     1129elseif (isset($_GET['edit']))
     1130    {
     1131    Note_Pressadd_note($_GET['edit']);
     1132    }
     1133elseif (@$_GET['action'] == 'Add')
     1134    {
     1135    Note_Pressadd_note();
     1136    }
     1137elseif (isset($_GET['action']))
     1138    {
     1139    if ($_GET['action'] == 'view')
     1140        {
     1141        Note_Pressshow_note($_GET['id']);
     1142        }
     1143    elseif ($_GET['action'] == 'edit')
     1144        {
     1145        Note_Pressadd_note($_GET['id']);
     1146        }
     1147    elseif ($_GET['action'] == 'delete')
     1148        {
     1149        if (is_array($_GET['id']))
     1150            {
     1151            $count = 0;
     1152            foreach ($_GET['id'] as $id)
     1153                {
     1154                Note_Pressdelete_multi_note($id);
     1155                $count++;
     1156                }
     1157            if ($count == 1)
     1158                {
     1159                Note_PressshowMessage($count . __('Note Deleted!', 'Note_Press'));
     1160                }
    5831161            else
    584 
    585             {
    586 
    587                 $myfilter = " where Title LIKE '%%%s%%' or Content LIKE '%%%s%%' and userTo = $uid";
    588 
    589             }
    590 
    591             $SQL = $wpdb->prepare("SELECT * FROM $table_name" . $myfilter . " order by $column $order",
    592 
    593             $_GET['s'],$_GET['s']);
    594 
    595             }
    596 
    597         else
    598 
    599             {
    600 
    601             if (is_super_admin())
    602 
    603             {
    604 
    605                 $SQL = "SELECT * FROM $table_name order by $column $order";
    606 
    607             }
    608 
    609             else
    610 
    611             {
    612 
    613                 $SQL = "SELECT * FROM $table_name where userTo = $uid order by $column $order";
    614 
    615             }
    616 
    617             }
    618 
    619         $mylink = $wpdb->get_results($SQL);
    620 
    621         return $mylink;
    622 
    623         }
    624 
    625     function prepare_items()
    626 
    627         {
    628 
    629         $_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', $_SERVER['REQUEST_URI']);
    630 
    631         if (isset($_GET['orderby']) && isset($_GET['order']))
    632 
    633             {
    634 
    635             $orderby = $_GET['orderby'];
    636 
    637             $order   = $_GET['order'];
    638 
    639             }
    640 
    641         else
    642 
    643             {
    644 
    645             $orderby = 'title';
    646 
    647             $order   = 'ASC';
    648 
    649             }
    650 
    651         $mylink = $this->get_items($orderby, $order);
    652 
    653         foreach ($mylink as $link)
    654 
    655             {
    656 
    657             $users = get_users(array(
    658 
    659                 'fields' => array(
    660 
    661                     'display_name',
    662 
    663                     'ID'
    664 
    665                 )
    666 
    667             ));
    668 
    669             foreach ($users as $user)
    670 
    671                 {
    672 
    673                 if ($user->ID == $link->AddedBy)
    674 
    675                     {
    676 
    677                     $username = $user->display_name;
    678 
    679                     }
    680 
    681                 if ($user->ID == $link->userTo)
    682 
    683                     {
    684 
    685                     $userto = $user->display_name;
    686 
    687                     }
    688 
    689                 }
    690 
    691             $iconpath = get_option("Note_Press_icons_url") . $link->Icon;
    692 
    693             switch ($link->Priority)
    694 
    695             {
    696 
    697                 case 0:
    698 
    699                     $picon = "<img src=" . plugins_url('admin/images/P0.png', dirname(__FILE__)) . " alt='Icon not found'>";
    700 
    701                     break;
    702 
    703                 case 1:
    704 
    705                     $picon = "<img src=" . plugins_url('admin/images/P1.png', dirname(__FILE__)) . " alt='Icon not found'>";
    706 
    707                     break;
    708 
    709                 case 2:
    710 
    711                     $picon = "<img src=" . plugins_url('admin/images/P2.png', dirname(__FILE__)) . " alt='Icon not found'>";
    712 
    713                     break;
    714 
    715             }
    716 
    717             if ($link->Deadline == NULL)
    718 
    719                 {
    720 
    721                 $thisdate = '';
    722 
    723                 }
    724 
    725             else
    726 
    727                 {
    728 
    729                 $date     = new DateTime($link->Deadline);
    730 
    731                 $thisdate = date_format($date, 'Y-m-d');
    732 
    733                 }
    734 
    735             if (is_super_admin())
    736 
    737             {
    738 
    739                 switch ($link->userRead)
    740 
    741                 {
    742 
    743                     case 0: $userread = "<img src=".plugins_url('admin/images/X.png', dirname(__FILE__))." alt='Icon not found'>";
    744 
    745                             break;
    746 
    747                     case 1: $userread = "<img src=".plugins_url('admin/images/CH.png', dirname(__FILE__))." alt='Icon not found'>";
    748 
    749                             break;
    750 
    751                 }               
    752 
    753             $example_data[] = array(
    754 
    755                 'ID' => $link->ID,
    756 
    757                 'icon' => '<img src="' . $iconpath . '" width="16" height="16" />',
    758 
    759                 'title' => '<a href="?page=Note_Press-Main-Menu&action=view&id=' . $link->ID . '">' . $link->Title . '</a>',
    760 
    761                 'addedby' => $username,
    762 
    763                 'userto' => $userto,
    764 
    765                 'userread' => $userread,
    766 
    767                 'datetime' => $link->Date,
    768 
    769                 'priority' => $picon,
    770 
    771                 'deadline' => $thisdate
    772 
    773             );
    774 
    775             }
    776 
    777             else
    778 
    779             {
    780 
    781             $example_data[] = array(
    782 
    783                 'ID' => $link->ID,
    784 
    785                 'icon' => '<img src="' . $iconpath . '" width="16" height="16" />',
    786 
    787                 'title' => '<a href="?page=Note_Press-Main-Menu&action=view&id=' . $link->ID . '">' . $link->Title . '</a>',
    788 
    789                 'addedby' => $username,
    790 
    791                 'datetime' => $link->Date,
    792 
    793                 'priority' => $picon,
    794 
    795                 'deadline' => $thisdate
    796 
    797             );
    798 
    799             }
    800 
    801             }
    802 
    803         $columns               = $this->get_columns();
    804 
    805         $hidden                = array();
    806 
    807         $sortable              = $this->get_sortable_columns();
    808 
    809         $this->_column_headers = array(
    810 
    811             $columns,
    812 
    813             $hidden,
    814 
    815             $sortable
    816 
    817         );
    818 
    819         $per_page              = 5;
    820 
    821         $current_page          = $this->get_pagenum();
    822 
    823         $total_items           = count(@$example_data);
    824 
    825         if ($total_items > 0)
    826 
    827             {
    828 
    829             $example_data = array_slice($example_data, (($current_page - 1) * $per_page), $per_page);
    830 
    831             }
    832 
    833         $this->set_pagination_args(array(
    834 
    835             'total_items' => $total_items,
    836 
    837             'per_page' => $per_page
    838 
    839         ));
    840 
    841         $this->items = @$example_data;
    842 
    843         }
    844 
    845     }
    846 
    847 function Note_Press_render_list_page()
    848 
    849     {
    850 
    851     $myListTable = new Note_Press_List_Table();
    852 
    853     $myListTable->prepare_items();
    854 
    855     echo '</pre><div class="wrap"><h3>' . __('Notes', 'Note_Press') . '</h3>';
    856 
    857     echo '<hr>';
    858 
    859     echo '<form method="get">';
    860 
    861     $nonce = wp_create_nonce( 'Note-Press-nonce' );
    862 
    863     echo '<input type="hidden" name="_wpnonce" value="'.$nonce.'">';
    864 
    865     echo '<input type="hidden" name="page" value="' . $_REQUEST['page'] . '" />' . $myListTable->search_box(__("Search", "Note_Press"), 'search_id');
    866 
    867     echo '</form>';
    868 
    869     echo '<form id="events-filter" method="get">';
    870 
    871     echo '<input type="hidden" name="page" value="' . $_REQUEST['page'] . '" />';
    872 
    873     $myListTable->display();
    874 
    875     echo '</form>';
    876 
    877     echo '</div>';
    878 
    879     }
    880 
    881 function Note_PressshowMessage($message, $errormsg = false)
    882 
    883     {
    884 
    885     if ($errormsg)
    886 
    887         {
    888 
    889         echo '<div id="message" class="error">';
    890 
    891         }
    892 
    893     else
    894 
    895         {
    896 
    897         echo '<div id="message" class="updated fade">';
    898 
    899         }
    900 
    901     echo "<p><strong>$message</strong></p></div>";
    902 
    903     }
    904 
    905 function Note_Pressshow_menu()
    906 
    907     {
    908 
    909     echo '<form action="" method="get">';
    910 
    911     echo '<button class="button-primary" type="submit" name="action" value="Add">' . __('Add A Note', 'Note_Press') . '</button>';
    912 
    913     echo '<input name="page" type="hidden" value="Note_Press-Main-Menu" />';
    914 
    915     echo '</form><hr>';
    916 
    917     }
    918 
    919 function Note_Pressget_notes()
    920 
    921     {
    922 
    923     global $wpdb;
    924 
    925     Note_Pressshow_menu();
    926 
    927     Note_Press_render_list_page();
    928 
    929     }
    930 
    931 function Note_Pressshow_note($which)
    932 
    933     {
    934 
    935     global $wpdb;
    936 
    937     $table_name = $wpdb->prefix . "Note_Press";
    938 
    939     $link     = $wpdb->get_row("SELECT * FROM $table_name where ID=$which");
    940 
    941     if ($link->userTo == get_current_user_id())
    942 
    943     {
    944 
    945         $wpdb->update($table_name, array(
    946 
    947             'userRead' => '1'
    948 
    949         ), array(
    950 
    951             'ID' => $which
    952 
    953         ), array(
    954 
    955             '%s'
    956 
    957         ), array(
    958 
    959             '%d'
    960 
    961         ));
    962 
    963     }
    964 
    965     if (!$link)
    966 
    967         {
    968 
    969         Note_PressshowMessage(__('That note was not found.', 'Note_Press'), true);
    970 
     1162                {
     1163                Note_PressshowMessage($count . __(' Notes Deleted!', 'Note_Press'));
     1164                }
     1165            }
     1166        elseif (isset($_GET['id']))
     1167            {
     1168            Note_Pressdelete_note($_GET['id']);
     1169            }
     1170        else
     1171            {
     1172            Note_PressshowMessage(__('No notes selected.', 'Note_Press'));
     1173            }
    9711174        Note_Pressget_notes();
    972 
    973         }
    974 
    975     else
    976 
    977         {
    978 
    979             $users = get_users(array(
    980 
    981                 'fields' => array(
    982 
    983                     'display_name',
    984 
    985                     'ID'
    986 
    987                 )
    988 
    989             ));
    990 
    991             foreach ($users as $user)
    992 
    993                 {
    994 
    995                 if ($user->ID == $link->AddedBy)
    996 
    997                     {
    998 
    999                     $username = $user->display_name;
    1000 
    1001                     }
    1002 
    1003                 }           
    1004 
    1005             echo '<h3>'.__('View a Note','Note_Press').'</h3>';
    1006 
    1007             echo '<hr>';           
    1008 
    1009             echo '<form action="" method="get">';
    1010 
    1011             echo '<input name="page" type="hidden" value="Note_Press-Main-Menu" />';
    1012 
    1013             echo '<button class="button-primary" type="submit" name="edit" value="' . $link->ID . '">' . __('Edit This Note', 'Note_Press') . '</button>';
    1014 
    1015             echo '&nbsp;';
    1016 
    1017             echo '<button class="button-primary" type="submit" name="action" value="List">' . __('Back to List', 'Note_Press') . '</button>';
    1018 
    1019             echo '</form><hr>';
    1020 
    1021             $iconpath = get_option("Note_Press_icons_url") . $link->Icon;
    1022 
    1023             echo '<table class="form-table widefat ltr" border="1" width="100%">';
    1024 
    1025             echo "<tr><td><h3><img src='$iconpath' width='16' height='16' />&nbsp;&nbsp;" . __('Title:', 'Note_Press') . " $link->Title</h3></td></tr>";
    1026 
    1027             echo "<tr><td><p><strong>" . __('Date Added/Last Edited:', 'Note_Press') . "</strong> $link->Date</p></td></tr>";
    1028 
    1029             echo "<tr><td><p><strong>" . __('Added By:', 'Note_Press') . "</strong> $username</p></td></tr>";
    1030 
    1031             switch ($link->Priority)
    1032 
    1033             {
    1034 
    1035                 case 0:
    1036 
    1037                     $picon = "<img src=" . plugins_url('admin/images/P0.png', dirname(__FILE__)) . " alt='Icon not found'>";
    1038 
    1039                     break;
    1040 
    1041                 case 1:
    1042 
    1043                     $picon = "<img src=" . plugins_url('admin/images/P1.png', dirname(__FILE__)) . " alt='Icon not found'>";
    1044 
    1045                     break;
    1046 
    1047                 case 2:
    1048 
    1049                     $picon = "<img src=" . plugins_url('admin/images/P2.png', dirname(__FILE__)) . " alt='Icon not found'>";
    1050 
    1051                     break;
    1052 
    1053             }
    1054 
    1055             echo "<tr><td><p><strong>" . __('Priority:', 'Note_Press') . "</strong> $picon</p></td></tr>";
    1056 
    1057             if ($link->Deadline == NULL)
    1058 
    1059                 {
    1060 
    1061                 $thisdate = '';
    1062 
    1063                 }
    1064 
    1065             else
    1066 
    1067                 {
    1068 
    1069                 $date     = new DateTime($link->Deadline);
    1070 
    1071                 $thisdate = date_format($date, 'Y-m-d');
    1072 
    1073                 }
    1074 
    1075             echo "<tr><td><p><strong>" . __('Deadline:', 'Note_Press') . "</strong> $thisdate</p></td></tr>";
    1076 
    1077             $content = do_shortcode(nl2br($link->Content));
    1078 
    1079             echo "<tr><td><p><strong>" . __('Contents:', 'Note_Press') . "</strong></p><hr><p> $content</p></td></tr>";
    1080 
    1081             echo '</table>';
    1082 
    1083             }
    1084 
    1085     }
    1086 
    1087 function Note_Pressadd_note($which = -1)
    1088 
    1089     {
    1090 
    1091     global $wpdb, $current_user, $wp_roles;
    1092 
    1093     if ($which <> -1)
    1094 
    1095         {
    1096 
    1097         $table_name = $wpdb->prefix . "Note_Press";
    1098 
    1099         $mylink     = $wpdb->get_row("SELECT * FROM $table_name where ID=$which");
    1100 
    1101         if (!$mylink)
    1102 
    1103             {
    1104 
    1105             Note_PressshowMessage(__('That note was not found.', 'Note_Press'), true);
    1106 
    1107             Note_Pressget_notes();
    1108 
    1109             exit;
    1110 
    1111             }
    1112 
    1113         }
    1114 
    1115        
    1116 
    1117     echo '<form action="" method="get">';
    1118 
    1119     echo '<input name="page" type="hidden" value="Note_Press-Main-Menu" />';
    1120 
    1121     echo '<button class="button-primary" type="submit" name="List" value="List">' . __('Back to List', 'Note_Press') . '</button>';
    1122 
    1123     echo '<hr>';
    1124 
    1125     echo '</form>';
    1126 
    1127     echo '<form action="" method="post">';
    1128 
    1129     $nonce = wp_create_nonce( 'Note-Press-nonce' );
    1130 
    1131     echo '<input type="hidden" name="_wpnonce" value="'.$nonce.'">';   
    1132 
    1133     if ($which <> -1)
    1134 
    1135     {   
    1136 
    1137     echo '<h3>'.__('Edit a Note','Note_Press').'</h3>';
    1138 
    1139     }
    1140 
    1141     else
    1142 
    1143     {
    1144 
    1145     echo '<h3>'.__('Add a Note','Note_Press').'</h3>';
    1146 
    1147     }
    1148 
    1149     echo '<hr>';
    1150 
    1151        
    1152 
    1153     echo '<div id="poststuff">
    1154 
    1155             <div id="post-body" class="metabox-holder columns-2">
    1156 
    1157 
    1158 
    1159                 <div id="post-body-content">';
    1160 
    1161     echo '          <div id="namediv" class="stuffbox">';
    1162 
    1163     echo '              <h3><label for="Title">' . __('Title:', 'Note_Press') . '</label></h3>';
    1164 
    1165     echo '              <div class="inside">';
    1166 
    1167     echo '                  <input name="Title" type="text" id="Title" size="100" maxlength="255" value="';
    1168 
    1169     if ($which <> -1)
    1170 
    1171         {
    1172 
    1173         echo $mylink->Title;
    1174 
    1175         }
    1176 
    1177     echo '" required>
    1178 
    1179 
    1180 
    1181                             <p>' . __('Enter a title for this note.', 'Note_Press') . '</p>';
    1182 
    1183     echo '              </div>';
    1184 
    1185     echo '          </div>';
    1186 
    1187 
    1188 
    1189     if ($which == -1)
    1190 
    1191     {   
    1192 
    1193         // ******************************************************  User To
    1194 
    1195         echo '          <div id="namediv" class="stuffbox">';
    1196 
    1197         echo '              <h3><label for="To">' . __('To:', 'Note_Press') . '</label></h3>';
    1198 
    1199         echo '              <div class="inside">';
    1200 
    1201         echo '                  <select name="UserTo[]" multiple="multiple" required>';
    1202 
    1203         $roles = $wp_roles->get_names();
    1204 
    1205         foreach ($roles as $role)
    1206 
    1207         {
    1208 
    1209             if ($role <> "Subscriber")
    1210 
    1211             {
    1212 
    1213                 echo '<option value="'.$role.'">' . $role . '</option>';
    1214 
    1215             }
    1216 
    1217         }
    1218 
    1219         $userlist = get_users();
    1220 
    1221         foreach ($userlist as $user)
    1222 
    1223         {
    1224 
    1225             $checked = '';
    1226 
    1227             if (!user_can($user,"subscriber"))
    1228 
    1229             {
    1230 
    1231                 if ($user->ID == get_current_user_id())
    1232 
    1233                 {
    1234 
    1235                     $checked = ' selected = "selected"';
    1236 
    1237                 }
    1238 
    1239                 echo '<option value="'.$user->ID.'"'.$checked.'>' . $user->display_name . '</option>';
    1240 
    1241             }
    1242 
    1243         }
    1244 
    1245         echo '                      </select> ';
    1246 
    1247         echo '                  <p>' . __('Choose who you wish to send this note to. Ctl-click to choose multiple recipients.', 'Note_Press') . '</p>';
    1248 
    1249         echo '              </div>';
    1250 
    1251         echo '          </div>';
    1252 
    1253         // ******************************************************
    1254 
    1255     }
    1256 
    1257     $checked = '';
    1258 
    1259     $color = '';
    1260 
    1261     if ($which <> -1)
    1262 
    1263     {
    1264 
    1265         if ($mylink->Sticky == 1)
    1266 
    1267         {
    1268 
    1269             $checked = ' checked = "checked"';
    1270 
    1271             $color = $mylink->StickyColor;
    1272 
    1273         }
    1274 
    1275     }
    1276 
    1277     // ******************************************************  Color Picker Test
    1278 
    1279     echo '          <div id="namediv" class="stuffbox">';
    1280 
    1281     echo '              <h3><label for="To">' . __('Sticky Note:', 'Note_Press') . '</label></h3>';
    1282 
    1283     echo '              <div class="inside">';
    1284 
    1285     echo '              <input style="width:10px" type="checkbox" name="makesticky"'.$checked.'>Make this note a Dashboard sticky.<br><br>';
    1286 
    1287     echo '              <input name="stickycolor" type="text" value="'.$color.'" class="NPcolor-field" />';
    1288 
    1289     echo '                  <p>' . __('<strong>Note: </strong>Users who do not have the ability to write notes can only see Sticky Notes.', 'Note_Press') . '</p>';
    1290 
    1291     echo '              </div>';
    1292 
    1293     echo '          </div>';
    1294 
    1295     // ****************************************************** Deadline
    1296 
    1297     $thisdate = '';
    1298 
    1299     if ($which <> -1)
    1300 
    1301         {
    1302 
    1303         if ($mylink->Deadline == NULL)
    1304 
    1305             {
    1306 
    1307             $thisdate = '';
    1308 
    1309             }
    1310 
    1311         else
    1312 
    1313             {
    1314 
    1315             $date     = new DateTime($mylink->Deadline);
    1316 
    1317             $thisdate = date_format($date, 'Y-m-d');
    1318 
    1319             }
    1320 
    1321         }   
    1322 
    1323     echo '          <div id="namediv" class="stuffbox">';
    1324 
    1325     echo '              <h3><label for="Deadline">' . __('Deadline:', 'Note_Press') . '</label></h3>';
    1326 
    1327     echo '              <div class="inside">';
    1328 
    1329     echo '                  <input name="Deadline" type="date" id="Date" pattern="[0-9]{4}-[0-9]{2}-[0-9]{2}" value="' . $thisdate . '">';
    1330 
    1331     echo '                  <p>' . __('Enter a deadline for this note or leave this field blank for no deadline.</br> <strong>Not all browswers support a date picker</strong>. If you do not have the option to select a date, please enter one in the format MM/DD/YYYY.', 'Note_Press') . '</p>';
    1332 
    1333     echo '              </div>';
    1334 
    1335     echo '          </div>';
    1336 
    1337     $checked1 = '';
    1338 
    1339     $checked2 = '';
    1340 
    1341     $checked3 = '';
    1342 
    1343     if ($which <> -1)
    1344 
    1345         {
    1346 
    1347         switch ($mylink->Priority)
    1348 
    1349         {
    1350 
    1351             case 0:
    1352 
    1353                 $checked1 = 'selected="selected"';
    1354 
    1355                 break;
    1356 
    1357             case 1:
    1358 
    1359                 $checked2 = 'selected="selected"';
    1360 
    1361                 break;
    1362 
    1363             case 2:
    1364 
    1365                 $checked3 = 'selected="selected"';
    1366 
    1367                 break;
    1368 
    1369         }
    1370 
    1371         }
    1372 
    1373     echo '          <div id="namediv" class="stuffbox">';
    1374 
    1375     echo '              <h3><label for="Priority">' . __('Priority:', 'Note_Press') . '</label></h3>';
    1376 
    1377     echo '              <div class="inside">';
    1378 
    1379     echo '                 
    1380 
    1381                             <select name="Priority">
    1382 
    1383                             <option value=0 style="background-image:url(' . plugins_url('admin/images/P0.png', dirname(__FILE__)) . ')" ' . $checked1 . '>' . __("Low", "Note_Press") . '</option>
    1384 
    1385                             <option value=1 style="background-image:url(' . plugins_url('admin/images/P1.png', dirname(__FILE__)) . ')" ' . $checked2 . '>' . __("Medium", "Note_Press") . '</option>
    1386 
    1387                             <option value=2 style="background-image:url(' . plugins_url('admin/images/P2.png', dirname(__FILE__)) . ')" ' . $checked3 . '>' . __("High", "Note_Press") . '</option>
    1388 
    1389                             </select> ';
    1390 
    1391     echo '                  <p>' . __('Select a priority for this note.', 'Note_Press') . '</p>';
    1392 
    1393     echo '              </div>';
    1394 
    1395     echo '          </div>';
    1396 
    1397     echo '          <div id="icondiv" class="stuffbox">';
    1398 
    1399     echo '              <h3><label for="Icon">' . __('Icon:', 'Note_Press') . '</label></h3>';
    1400 
    1401     echo '              <div class="inside">';
    1402 
    1403     $count = 0;
    1404 
    1405     if ($which <> -1)
    1406 
    1407         {
    1408 
    1409         $blank = false;
    1410 
    1411         }
    1412 
    1413     else
    1414 
    1415         {
    1416 
    1417         $blank = true;
    1418 
    1419         }
    1420 
    1421     echo '<table width="100%" border="0">';
    1422 
    1423     $path  = get_option("Note_Press_icons_path");
    1424 
    1425     $files = scandir($path);
    1426 
    1427     foreach ($files as $myfile)
    1428 
    1429         {
    1430 
    1431         if ($myfile <> '.' && $myfile <> '..')
    1432 
    1433             {
    1434 
    1435             if ($count == 0)
    1436 
    1437                 {
    1438 
    1439                 echo '<tr>';
    1440 
    1441                 $enddone = FALSE;
    1442 
    1443                 }
    1444 
    1445             $iconpath = get_option("Note_Press_icons_url") . $myfile;
    1446 
    1447             echo '<td><input type="radio" name="iconselect[]" value="' . $myfile . '"';
    1448 
    1449             if ($blank)
    1450 
    1451                 {
    1452 
    1453                 echo ' checked ';
    1454 
    1455                 $blank = false;
    1456 
    1457                 }
    1458 
    1459             if ($which <> -1)
    1460 
    1461                 {
    1462 
    1463                 if ($mylink->Icon == $myfile)
    1464 
    1465                     {
    1466 
    1467                     echo ' checked ';
    1468 
    1469                     }
    1470 
    1471                 }
    1472 
    1473             echo '><img src="' . $iconpath . '" width="16" height="16"/></td>';
    1474 
    1475             $count++;
    1476 
    1477             if ($count == 15)
    1478 
    1479                 {
    1480 
    1481                 $count = 0;
    1482 
    1483                 echo '</tr>';
    1484 
    1485                 $enddone = TRUE;
    1486 
    1487                 }
    1488 
    1489             }
    1490 
    1491         }
    1492 
    1493     if (!$enddone)
    1494 
    1495         {
    1496 
    1497         echo '</tr>';
    1498 
    1499         }
    1500 
    1501     echo '</table>';
    1502 
    1503     echo '<p>' . __('Select an icon for this note.', 'Note_Press') . '</p>';
    1504 
    1505     echo '              </div>';
    1506 
    1507     echo '          </div>';
    1508 
    1509     echo '          <div id="authordiv" class="stuffbox">';
    1510 
    1511     $users = get_users(array(
    1512 
    1513         'fields' => array(
    1514 
    1515             'display_name',
    1516 
    1517             'ID'
    1518 
    1519         )
    1520 
    1521     ));
    1522 
    1523     foreach ($users as $user)
    1524 
    1525         {
    1526 
    1527             if ($which <> -1)
    1528 
    1529             {   
    1530 
    1531                 if ($user->ID == $mylink->AddedBy)
    1532 
    1533                 {
    1534 
    1535                     $username = $user->display_name;
    1536 
    1537                 }
    1538 
    1539             }
    1540 
    1541             else
    1542 
    1543             {
    1544 
    1545                 if ($user->ID == $current_user->ID)
    1546 
    1547                 {
    1548 
    1549                     $username = $user->display_name;
    1550 
    1551                 }                       
    1552 
    1553             }
    1554 
    1555         }
    1556 
    1557     echo '          <h3><label for="Author">' . __('Author/Editor: ', 'Note_Press') . $username . '</label></h3>';
    1558 
    1559     echo '          <input name="display_name" type="hidden" value="' . $username . '" />';
    1560 
    1561     echo '          </div>';
    1562 
    1563     echo '          <div id="namediv" class="stuffbox">';
    1564 
    1565     echo '              <h3><label for="Note">' . __('Contents:', 'Note_Press') . '</label></h3>';
    1566 
    1567     echo '              <div class="inside">';
    1568 
    1569     if ($which <> -1)
    1570 
    1571         {
    1572 
    1573         $content = $mylink->Content;
    1574 
    1575         }
    1576 
    1577     else
    1578 
    1579         {
    1580 
    1581         $content = '';
    1582 
    1583         }
    1584 
    1585     $editor_id = 'Note_Presseditor';
    1586 
    1587     wp_editor($content, $editor_id);
    1588 
    1589     echo '              </div>';
    1590 
    1591     echo '          </div>';
    1592 
    1593     echo '      </div>';
    1594 
    1595     echo '
    1596 
    1597                 <div id="postbox-container-1" class="postbox-container">
    1598 
    1599                     <div id="side-sortables" class="meta-box-sortables ui-sortable">
    1600 
    1601                         <div id="linksubmitdiv" class="postbox ">
    1602 
    1603                         <h3 class="hndle ui-sortable-handle"><span>' . __('Save', 'Note_Press') . '</span></h3>
    1604 
    1605                             <div class="inside">
    1606 
    1607                                 <div class="submitbox" id="submitlink">
    1608 
    1609                                     <div id="major-publishing-actions">                 
    1610 
    1611                                         <div id="publishing-action">';
    1612 
    1613     if ($which <> -1)
    1614 
    1615         {
    1616 
    1617         echo '<button  class="button-primary" type="submit" name="Update" value="' . $mylink->ID . '">' . __('Update Note', 'Note_Press') . '</button>';
    1618 
    1619         }
    1620 
    1621     else
    1622 
    1623         {
    1624 
    1625         echo '<input name="DoAdd" type="submit" class="button-large button-primary" id="publish" accesskey="p" value="' . __('Add Note', 'Note_Press') . '">';
    1626 
    1627         }
    1628 
    1629     echo '                              </div>
    1630 
    1631                                         <div class="clear">
    1632 
    1633                                         </div>
    1634 
    1635                                     </div>
    1636 
    1637                                     <div class="clear">
    1638 
    1639                                     </div>
    1640 
    1641                                 </div>
    1642 
    1643                             </div>
    1644 
    1645                         </div>
    1646 
    1647                     </div>
    1648 
    1649                 </div>';
    1650 
    1651     echo '  </div>';
    1652 
    1653     echo '</div>';
    1654 
    1655     echo '<div id="clear"></div>';
    1656 
    1657     echo '</form>';
    1658 
    1659     }
    1660 
    1661 function Note_Pressupdate_note($thisid)
    1662 
    1663     {
    1664 
    1665     global $wpdb;
    1666 
    1667     if (stripslashes_deep($_POST['Title']) == '')
    1668 
    1669         {
    1670 
    1671         Note_PressshowMessage(__('A note must have a title.', 'Note_Press'), true);
    1672 
     1175        }
     1176    else
     1177        {
    16731178        Note_Pressget_notes();
    1674 
    1675         exit;
    1676 
    1677         }
    1678 
    1679     $table_name = $wpdb->prefix . "Note_Press";
    1680 
    1681     $mylink     = $wpdb->get_row("SELECT * FROM $table_name where ID=$thisid");
    1682 
    1683     if (!$mylink)
    1684 
    1685         {
    1686 
    1687         Note_PressshowMessage(__('That note was not found.', 'Note_Press'), true);
    1688 
    1689         }
    1690 
    1691     else
    1692 
    1693         {
    1694 
    1695         if (!empty($_POST['Deadline']))
    1696 
    1697             {
    1698 
    1699             $thisdate = date("Y-m-d H:i:s", strtotime($_POST['Deadline']));
    1700 
    1701             }
    1702 
    1703         else
    1704 
    1705             {
    1706 
    1707             $thisdate = NULL;
    1708 
    1709             }
    1710 
    1711         if (isset($_POST['makesticky']))
    1712 
    1713         {
    1714 
    1715             $makesticky = 1;
    1716 
    1717             $stickycolor = $_POST['stickycolor'];
    1718 
    1719         }
    1720 
    1721         else
    1722 
    1723         {
    1724 
    1725             $makesticky = 0;
    1726 
    1727             $stickycolor = $_POST['stickycolor'];
    1728 
    1729         }
    1730 
    1731         $wpdb->update($table_name, array(
    1732 
    1733             'Icon' =>$_POST['iconselect'][0],
    1734 
    1735             'Title' => stripslashes_deep($_POST['Title']),
    1736 
    1737             'AddedBy' => get_current_user_id(),
    1738 
    1739             'Content' => stripslashes_deep($_POST["Note_Presseditor"]),
    1740 
    1741             'Date' => date("Y-m-d H:i:s"),
    1742 
    1743             'Deadline' => stripslashes_deep($thisdate),
    1744 
    1745             'Priority' => stripslashes_deep($_POST['Priority']),
    1746 
    1747             'Sticky' => stripslashes_deep($makesticky),
    1748 
    1749             'StickyColor' => stripslashes_deep($stickycolor),
    1750 
    1751             'userTo' => $mylink->userTo
    1752 
    1753         ), array(
    1754 
    1755             'ID' => $_POST['Update']
    1756 
    1757         ));
    1758 
    1759         Note_PressshowMessage($_POST['Title'] . ' updated.');
    1760 
    1761         }
    1762 
     1179        }
     1180    }
     1181else
     1182    {
    17631183    Note_Pressget_notes();
    1764 
    1765     }
    1766 
    1767 function Note_Pressinsert_note()
    1768 
    1769     {
    1770 
    1771     global $wpdb;
    1772 
    1773     if (stripslashes_deep($_POST['Title']) == '')
    1774 
    1775         {
    1776 
    1777         Note_PressshowMessage(__('A note must have a title.', 'Note_Press'), true);
    1778 
    1779         Note_Pressget_notes();
    1780 
    1781         exit;
    1782 
    1783         }
    1784 
    1785     $table_name = $wpdb->prefix . "Note_Press";
    1786 
    1787     if (!empty($_POST['Deadline']))
    1788 
    1789         {
    1790 
    1791         $thisdate = date("Y-m-d H:i:s", strtotime($_POST['Deadline']));
    1792 
    1793         }
    1794 
    1795     else
    1796 
    1797         {
    1798 
    1799         $thisdate = NULL;
    1800 
    1801         }
    1802 
    1803     if (isset($_POST['makesticky']))
    1804 
    1805     {
    1806 
    1807         $makesticky = 1;
    1808 
    1809         $stickycolor = $_POST['stickycolor'];
    1810 
    1811     }
    1812 
    1813     else
    1814 
    1815     {
    1816 
    1817         $makesticky = 0;
    1818 
    1819         $stickycolor = $_POST['stickycolor'];
    1820 
    1821     }       
    1822 
    1823     $sendto = array();
    1824 
    1825     $userlist = get_users();
    1826 
    1827     foreach ($_POST['UserTo'] as $whoto)
    1828 
    1829     {
    1830 
    1831         if ($whoto == "Administrator")
    1832 
    1833         {
    1834 
    1835             foreach($userlist as $user)
    1836 
    1837             {
    1838 
    1839                 if (user_can($user,'administrator'))
    1840 
    1841                 {
    1842 
    1843                     if (!in_array($user->ID,$sendto))
    1844 
    1845                     {
    1846 
    1847                         array_push($sendto,$user->ID);
    1848 
    1849                     }
    1850 
    1851                 }
    1852 
    1853             }
    1854 
    1855         }
    1856 
    1857         elseif ($whoto == "Editor")
    1858 
    1859         {
    1860 
    1861             foreach($userlist as $user)
    1862 
    1863             {
    1864 
    1865                 if (user_can($user,'editor'))
    1866 
    1867                 {
    1868 
    1869                     if (!in_array($user->ID,$sendto))
    1870 
    1871                     {
    1872 
    1873                         array_push($sendto,$user->ID);
    1874 
    1875                     }
    1876 
    1877                 }
    1878 
    1879             }           
    1880 
    1881         }
    1882 
    1883         elseif ($whoto == "Author")
    1884 
    1885         {
    1886 
    1887             foreach($userlist as $user)
    1888 
    1889             {
    1890 
    1891                 if (user_can($user,'author'))
    1892 
    1893                 {
    1894 
    1895                     if (!in_array($user->ID,$sendto))
    1896 
    1897                     {
    1898 
    1899                         array_push($sendto,$user->ID);
    1900 
    1901                     }
    1902 
    1903                 }
    1904 
    1905             }           
    1906 
    1907         }
    1908 
    1909         elseif ($whoto == "Contributor")
    1910 
    1911         {
    1912 
    1913             foreach($userlist as $user)
    1914 
    1915             {
    1916 
    1917                 if (user_can($user,'contributor'))
    1918 
    1919                 {
    1920 
    1921                     if (!in_array($user->ID,$sendto))
    1922 
    1923                     {
    1924 
    1925                         array_push($sendto,$user->ID);
    1926 
    1927                     }
    1928 
    1929                 }
    1930 
    1931             }           
    1932 
    1933         }
    1934 
    1935         else
    1936 
    1937         {
    1938 
    1939             if (!in_array($whoto,$sendto))
    1940 
    1941             {
    1942 
    1943                 array_push($sendto,$whoto);
    1944 
    1945             }
    1946 
    1947         }
    1948 
    1949     }
    1950 
    1951     foreach($sendto as $idto)
    1952 
    1953     {
    1954 
    1955     $wpdb->insert($table_name, array(
    1956 
    1957         'Icon' => $_POST['iconselect'][0],
    1958 
    1959         'Title' => stripslashes_deep($_POST['Title']),
    1960 
    1961         'AddedBy' => get_current_user_id(),
    1962 
    1963         'Content' => stripslashes_deep($_POST["Note_Presseditor"]),
    1964 
    1965         'Date' => date("Y-m-d H:i:s"),
    1966 
    1967         'Deadline' => stripslashes_deep($thisdate),
    1968 
    1969         'Priority' => stripslashes_deep($_POST['Priority']),
    1970 
    1971         'Sticky' => stripslashes_deep($makesticky),
    1972 
    1973         'StickyColor' => stripslashes_deep($stickycolor),
    1974 
    1975         'userTo' => $idto
    1976 
    1977     ));
    1978 
    1979     }
    1980 
    1981     Note_PressshowMessage($_POST['Title'] . ' Added.');
    1982 
    1983     Note_Pressget_notes();
    1984 
    1985     }
    1986 
    1987 function Note_Pressdelete_multi_note($thisid)
    1988 
    1989     {
    1990 
    1991     global $wpdb;
    1992 
    1993     $table_name = $wpdb->prefix . "Note_Press";
    1994 
    1995     $mylink     = $wpdb->get_results("SELECT * FROM $table_name where ID=$thisid");
    1996 
    1997     if (!$mylink)
    1998 
    1999         {
    2000 
    2001         }
    2002 
    2003     else
    2004 
    2005         {
    2006 
    2007         $wpdb->delete($table_name, array(
    2008 
    2009             'ID' => $thisid
    2010 
    2011         ));
    2012 
    2013         }
    2014 
    2015     }
    2016 
    2017 function Note_Pressdelete_note($thisid)
    2018 
    2019     {
    2020 
    2021     global $wpdb;
    2022 
    2023     $table_name = $wpdb->prefix . "Note_Press";
    2024 
    2025     $mylink     = $wpdb->get_results("SELECT * FROM $table_name where ID=$thisid");
    2026 
    2027     if (!$mylink)
    2028 
    2029         {
    2030 
    2031         Note_PressshowMessage(__('That note was not found', 'Note_Press'), true);
    2032 
    2033         }
    2034 
    2035     else
    2036 
    2037         {
    2038 
    2039         $wpdb->delete($table_name, array(
    2040 
    2041             'ID' => $thisid
    2042 
    2043         ));
    2044 
    2045         Note_PressshowMessage(__('Note Deleted!', 'Note_Press'));
    2046 
    2047         }
    2048 
    2049     }
    2050 
    2051 
    2052 
    2053 function Note_PressCheckDB()
    2054 
    2055 {
    2056 
    2057     global $wpdb;
    2058 
    2059     $tablename = $wpdb->prefix . "Note_Press";
    2060 
    2061     $SQL = "SHOW COLUMNS FROM $tablename LIKE 'Sticky'";
    2062 
    2063     $wpdb->get_results($SQL);
    2064 
    2065     if ($wpdb->num_rows == 0)
    2066 
    2067     {
    2068 
    2069         Note_PressshowMessage(__('Please deactivate and re-activate Note Press to complete the upgrade.', 'Note_Press'), true);
    2070 
    2071         return true;
    2072 
    2073     }
    2074 
    2075     else
    2076 
    2077     {
    2078 
    2079         return false;
    2080 
    2081     }
    2082 
    2083 }
    2084 
    2085 
    2086 
    2087 if (Note_PressCheckDB())
    2088 
    2089 {
    2090 
    2091     die();
    2092 
    2093 }
    2094 
    2095 if (isset($_REQUEST['_wpnonce']))
    2096 
    2097 {
    2098 
    2099     $nonce = $_REQUEST['_wpnonce'];
    2100 
    2101     if ( ! wp_verify_nonce( $nonce, 'Note-Press-nonce' ) ) {
    2102 
    2103         // This nonce is not valid.
    2104 
    2105         die( 'Security check' );
    2106 
    2107     }
    2108 
    2109 }
    2110 
    2111 if (isset($_POST['Update']))
    2112 
    2113     {
    2114 
    2115     Note_Pressupdate_note($_POST['Update']);
    2116 
    2117     }
    2118 
    2119 elseif (isset($_POST['DoAdd']))
    2120 
    2121     {
    2122 
    2123     Note_Pressinsert_note();
    2124 
    2125     }
    2126 
    2127 elseif (isset($_GET['s']))
    2128 
    2129     {
    2130 
    2131     Note_Pressget_notes();
    2132 
    2133     }
    2134 
    2135 elseif (isset($_GET['List']) || isset($_GET['orderby']) && isset($_GET['order']))
    2136 
    2137     {
    2138 
    2139     Note_Pressget_notes();
    2140 
    2141     }
    2142 
    2143 elseif (isset($_GET['edit']))
    2144 
    2145     {
    2146 
    2147     Note_Pressadd_note($_GET['edit']);
    2148 
    2149     }
    2150 
    2151 elseif (@$_GET['action'] == 'Add')
    2152 
    2153     {
    2154 
    2155     Note_Pressadd_note();
    2156 
    2157     }
    2158 
    2159 elseif (isset($_GET['action']))
    2160 
    2161     {
    2162 
    2163     if ($_GET['action'] == 'view')
    2164 
    2165         {
    2166 
    2167         Note_Pressshow_note($_GET['id']);
    2168 
    2169         }
    2170 
    2171     elseif ($_GET['action'] == 'edit')
    2172 
    2173         {
    2174 
    2175         Note_Pressadd_note($_GET['id']);
    2176 
    2177         }
    2178 
    2179     elseif ($_GET['action'] == 'delete')
    2180 
    2181         {
    2182 
    2183         if (is_array($_GET['id']))
    2184 
    2185             {
    2186 
    2187             $count = 0;
    2188 
    2189             foreach ($_GET['id'] as $id)
    2190 
    2191                 {
    2192 
    2193                 Note_Pressdelete_multi_note($id);
    2194 
    2195                 $count++;
    2196 
    2197                 }
    2198 
    2199             if ($count == 1)
    2200 
    2201                 {
    2202 
    2203                 Note_PressshowMessage($count . __('Note Deleted!', 'Note_Press'));
    2204 
    2205                 }
    2206 
    2207             else
    2208 
    2209                 {
    2210 
    2211                 Note_PressshowMessage($count . __(' Notes Deleted!', 'Note_Press'));
    2212 
    2213                 }
    2214 
    2215             }
    2216 
    2217         elseif (isset($_GET['id']))
    2218 
    2219             {
    2220 
    2221             Note_Pressdelete_note($_GET['id']);
    2222 
    2223             }
    2224 
    2225         else
    2226 
    2227             {
    2228 
    2229             Note_PressshowMessage(__('No notes selected.', 'Note_Press'));
    2230 
    2231             }
    2232 
    2233         Note_Pressget_notes();
    2234 
    2235         }
    2236 
    2237     else
    2238 
    2239         {
    2240 
    2241         Note_Pressget_notes();
    2242 
    2243         }
    2244 
    2245     }
    2246 
    2247 else
    2248 
    2249     {
    2250 
    2251     Note_Pressget_notes();
    2252 
    2253     }
    2254 
    2255 
    2256 
     1184    }
    22571185?>
  • note-press/trunk/includes/class-Note_Press-activator.php

    r1689102 r1690167  
    11<?php
    2 
    32/**
    4 
    53 * Fired during plugin activation
    6 
    74 *
    8 
    95 * @link       http://www.datainterlock.com
    10 
    116 * @since      1.0.0
    12 
    137 *
    14 
    158 * @package    Note_Press
    16 
    179 * @subpackage Note_Press/includes
    18 
    1910 */
    20 
    2111/**
    22 
    2312 * Fired during plugin activation.
    24 
    2513 *
    26 
    2714 * This class defines all code necessary to run during the plugin's activation.
    28 
    2915 *
    30 
    3116 * @since      1.0.0
    32 
    3317 * @package    Note_Press
    34 
    3518 * @subpackage Note_Press/includes
    36 
    3719 * @author     Rod Kinnison <postmaster@datainterlock.com>
    38 
    3920 */
    40 
    4121class Note_Press_Activator
    42 
    4322    {
    44 
    4523    /**
    46 
    4724     * Short Description. (use period)
    48 
    4925     *
    50 
    5126     * Long Description.
    52 
    5327     *
    54 
    5528     * @since    1.0.0
    56 
    5729     */
    5830
    59 
    60 
    6131    public static function activate()
    62 
    6332        {
    64 
    6533        global $wpdb;
    6634
    67 
     35        function table_column_exists($table_name, $column_name)
     36            {
     37            global $wpdb;
     38            $column = $wpdb->get_results($wpdb->prepare("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = %s ", DB_NAME, $table_name, $column_name));
     39            if (!empty($column))
     40                {
     41                return true;
     42                }
     43            return false;
     44            }
     45       
     46        function db_install($table_name)
     47        {
     48            global $wpdb;
     49            if($wpdb->get_var("SHOW TABLES LIKE 'datainterlock_wp_Note_Press'") == "datainterlock_wp_Note_Press")
     50            {
     51                $GLOBALS['wpdb']->query("RENAME TABLE `datainterlock_wp_Note_Press` to $table_name");
     52            }
     53           
     54            $sql        = "
     55                CREATE TABLE IF NOT EXISTS `$table_name` (
     56                  `ID` int(11) NOT NULL AUTO_INCREMENT,
     57                  `Icon` varchar(50) NOT NULL,
     58                  `Title` varchar(255) NOT NULL,
     59                  `Content` mediumtext NOT NULL,
     60                  `Date` datetime NOT NULL,
     61                  `AddedBy` varchar(255) NOT NULL,
     62                  `userTo` varchar(255) NOT NULL,
     63                  `userRead` tinyint(1) NOT NULL DEFAULT '0',
     64                  `Priority` int(11) NOT NULL,
     65                  `Deadline` datetime DEFAULT NULL,
     66                  `Sticky` tinyint(1) NOT NULL DEFAULT '0',
     67                  `StickyColor` varchar(20) NOT NULL DEFAULT '#eeee22',
     68                  PRIMARY KEY (`ID`)
     69                ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=16 ;
     70            ";
     71            $wpdb->query($sql);
     72            if (!table_column_exists($table_name,'Priority'))
     73                {
     74                    $sql = "
     75                    ALTER TABLE $table_name
     76                    DROP COLUMN ViewLevel,
     77                    DROP COLUMN Category,
     78                    ADD COLUMN `userTo` varchar(255) NOT NULL,
     79                    ADD COLUMN `userRead` tinyint(1) NOT NULL DEFAULT '0',
     80                    ADD COLUMN `Priority` int(11) NOT NULL,
     81                    ADD COLUMN `Deadline` datetime DEFAULT NULL
     82                 ";
     83                    $wpdb->query($sql);
     84                    $noteList   = $wpdb->get_results("SELECT * FROM $table_name");
     85                    foreach ($noteList as $note)
     86                    {
     87                        $users = get_users( array( 'fields' => array( 'display_name','ID' ) ) );
     88                        foreach ($users as $user)
     89                        {
     90                            if ($user->display_name == $note->AddedBy)
     91                            {
     92                                $userid = $user->ID;
     93                            }
     94                        }
     95                        $wpdb->update($table_name, array(
     96                        'userTo' => $userid,
     97                        'AddedBy' => $userid,
     98                        'userRead' => 0,
     99                        'Priority' => 0,
     100                        'Deadline' => NULL
     101                        ), array(
     102                        'ID' => $note->ID
     103                        ));
     104                    }
     105                }
     106            if (!table_column_exists($table_name,'Sticky'))
     107                {       
     108                    $sql =
     109                    "ALTER TABLE $table_name
     110                    ADD COLUMN `Sticky` tinyint(1) NOT NULL DEFAULT '0',
     111                    ADD COLUMN `StickyColor` varchar(20) NOT NULL DEFAULT '#eeee22'
     112                    ";
     113                    $wpdb->query($sql);             
     114                }               
     115        }
    68116
    69117        if (file_exists(plugin_dir_path( __DIR__ ).'messages.pot'))
    70 
    71118        {
    72 
    73119            unlink(plugin_dir_path( __DIR__ ).'messages.pot');
    74 
    75120        }
    76121
    77 
    78 
    79122        if (file_exists(plugin_dir_path( __DIR__ ).'messages.temp'))
    80 
    81123        {
    82 
    83124            unlink(plugin_dir_path( __DIR__ ).'messages.temp');
    84 
    85125        }
    86 
    87 
    88 
    89         function table_column_exists($table_name, $column_name)
    90 
     126        if (is_multisite())
     127        {
     128            $blogs = $wpdb->get_results("SELECT blog_id FROM {$wpdb->blogs}", ARRAY_A);
     129            if ($blogs)
    91130            {
    92 
    93             global $wpdb;
    94 
    95             $column = $wpdb->get_results($wpdb->prepare("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = %s ", DB_NAME, $table_name, $column_name));
    96 
    97             if (!empty($column))
    98 
     131                foreach($blogs as $blog)
    99132                {
    100 
    101                 return true;
    102 
     133                    switch_to_blog($blog['blog_id']);
     134                    $table_name = $wpdb->prefix . "Note_Press";
     135                    db_install($table_name);
     136                    restore_current_blog();
    103137                }
    104 
    105             return false;
    106 
    107138            }
    108 
    109 
    110 
    111         $table_name = $wpdb->prefix . "Note_Press";
    112 
    113         $sql        = "
    114 
    115             CREATE TABLE IF NOT EXISTS `datainterlock_wp_Note_Press` (
    116 
    117               `ID` int(11) NOT NULL AUTO_INCREMENT,
    118 
    119               `Icon` varchar(50) NOT NULL,
    120 
    121               `Title` varchar(255) NOT NULL,
    122 
    123               `Content` mediumtext NOT NULL,
    124 
    125               `Date` datetime NOT NULL,
    126 
    127               `AddedBy` varchar(255) NOT NULL,
    128 
    129               `userTo` varchar(255) NOT NULL,
    130 
    131               `userRead` tinyint(1) NOT NULL DEFAULT '0',
    132 
    133               `Priority` int(11) NOT NULL,
    134 
    135               `Deadline` datetime DEFAULT NULL,
    136 
    137               `Sticky` tinyint(1) NOT NULL DEFAULT '0',
    138 
    139               `StickyColor` varchar(20) NOT NULL DEFAULT '#eeee22',
    140 
    141               PRIMARY KEY (`ID`)
    142 
    143             ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=16 ;
    144 
    145         ";
    146 
    147         $wpdb->query($sql);
    148 
    149         if (!table_column_exists($table_name,'Priority'))
    150 
    151             {
    152 
    153                 $sql = "
    154 
    155                 ALTER TABLE $table_name
    156 
    157                 DROP COLUMN ViewLevel,
    158 
    159                 DROP COLUMN Category,
    160 
    161                 ADD COLUMN `userTo` varchar(255) NOT NULL,
    162 
    163                 ADD COLUMN `userRead` tinyint(1) NOT NULL DEFAULT '0',
    164 
    165                 ADD COLUMN `Priority` int(11) NOT NULL,
    166 
    167                 ADD COLUMN `Deadline` datetime DEFAULT NULL
    168 
    169              ";
    170 
    171                 $wpdb->query($sql);
    172 
    173                 $noteList   = $wpdb->get_results("SELECT * FROM $table_name");
    174 
    175                 foreach ($noteList as $note)
    176 
    177                 {
    178 
    179                     $users = get_users( array( 'fields' => array( 'display_name','ID' ) ) );
    180 
    181                     foreach ($users as $user)
    182 
    183                     {
    184 
    185                         if ($user->display_name == $note->AddedBy)
    186 
    187                         {
    188 
    189                             $userid = $user->ID;
    190 
    191                         }
    192 
    193                     }
    194 
    195                     $wpdb->update($table_name, array(
    196 
    197                     'userTo' => $userid,
    198 
    199                     'AddedBy' => $userid,
    200 
    201                     'userRead' => 0,
    202 
    203                     'Priority' => 0,
    204 
    205                     'Deadline' => NULL
    206 
    207                     ), array(
    208 
    209                     'ID' => $note->ID
    210 
    211                     ));
    212 
    213                 }
    214 
    215             }
    216 
    217         if (!table_column_exists($table_name,'Sticky'))
    218 
    219             {       
    220 
    221                 $sql =
    222 
    223                 "ALTER TABLE $table_name
    224 
    225                 ADD COLUMN `Sticky` tinyint(1) NOT NULL DEFAULT '0',
    226 
    227                 ADD COLUMN `StickyColor` varchar(20) NOT NULL DEFAULT '#eeee22'
    228 
    229                 ";
    230 
    231                 $wpdb->query($sql);             
    232 
    233             }
    234 
     139        }
     140        else
     141        {
     142            $table_name = $wpdb->prefix . "Note_Press";
     143            db_install($table_name);
     144        }
    235145        update_option("Note_Press_db_version", '2.1');
    236 
    237146        }
    238 
    239147    }
    240 
  • note-press/trunk/includes/class-Note_Press.php

    r1689102 r1690167  
    141141        $this->plugin_name = 'Note_Press';
    142142
    143         $this->version = '0.1.5';
     143        $this->version = '0.1.6';
    144144
    145145
  • note-press/trunk/uninstall.php

    r1689102 r1690167  
    11<?php
    2 
    32/**
    4 
    53 * Fired when the plugin is uninstalled.
    6 
    74 *
    8 
    95 * @package   Note_Press
    10 
    116 * @author    datainterlock <postmaster@datainterlock.com>
    12 
    137 * @license   GPL-3.0+
    14 
    158 * @link      http://www.datainterlock.com
    16 
    179 * @Copyright (C) 2015 Rod Kinnison postmaster@datainterlock.com
    18 
    1910 */
    2011
    21 
    22 
    2312// If uninstall not called from WordPress, then exit
    24 
    2513if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
    26 
    2714    exit;
    28 
    2915}
    30 
    3116if (is_multisite())
    32 
    3317{
    34 
    3518    global $wpdb;
    36 
    3719    $blogs = $wpdb->get_results("SELECT blog_id FROM {$wpdb->blogs}", ARRAY_A);
    38 
    3920    delete_option("Note_Press_db_version");
    40 
    4121    if ($blogs)
    42 
    4322    {
    44 
    4523        foreach($blogs as $blog)
    46 
    4724        {
    48 
    4925            switch_to_blog($blog['blog_id']);
    50 
    5126            delete_option("Note_Press_db_version");
    52 
    5327            $table_name = $wpdb->prefix . "Note_Press";
    54 
    5528            $GLOBALS['wpdb']->query("DROP TABLE `".$GLOBALS['wpdb']->prefix."$table_name`");
    56 
    5729            $GLOBALS['wpdb']->query("OPTIMIZE TABLE `" .$GLOBALS['wpdb']->prefix."options`");
    58 
    5930            restore_current_blog();
    60 
    6131        }
    62 
    6332    }
    64 
    6533}
    66 
    6734else
    68 
    6935{
    70 
    7136    delete_option("Note_Press_db_version");
    72 
    7337    $table_name = $wpdb->prefix . "Note_Press";
    74 
    7538    $GLOBALS['wpdb']->query("DROP TABLE `".$GLOBALS['wpdb']->prefix."$table_name`");
    76 
    7739    $GLOBALS['wpdb']->query("OPTIMIZE TABLE `" .$GLOBALS['wpdb']->prefix."options`");
    78 
    7940}
Note: See TracChangeset for help on using the changeset viewer.