prefix . "adminnote";
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
name VARCHAR(255) NOT NULL,
text text NOT NULL,
create_by INT(11) NOT NULL,
userid INT(11) NOT NULL,
UNIQUE KEY id (id)
)";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
add_option( "admin_note_version", $admin_note_db_version );
}
register_activation_hook( __FILE__, 'admin_note_install');
function admin_note_menu(){
$url_icon = plugins_url().'/adminnote/notes.png';
add_menu_page( 'Admin Notes', 'Notes', 'manage_options', 'admin-note', 'admin_note_menu_callback', $url_icon, 3 );
}
function add_custom_style(){
echo '';
echo '';
echo '';
}
add_action('admin_head', 'add_custom_style');
function getUserName($id){
global $wpdb;
$user_info = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE `ID` = ".$id);
return $user_info->display_name;
}
function admin_note_menu_callback(){
$plugin_dir_path = plugin_dir_url(__FILE__);
if ( !current_user_can( 'manage_options' )) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
global $current_user;
get_currentuserinfo();
if(empty($_GET['action'])):
global $wpdb;
if($_POST){
$note_delete = $_POST['note_delete'];
$count = 0;
foreach($note_delete as $note){
$wpdb->delete( $wpdb->prefix."adminnote" , array( 'id' => $note ) );
$count += 1;
}
header('Location: ./admin.php?page=admin-note');
}
$totalItems = $wpdb->get_var( "SELECT COUNT(*) FROM ".$wpdb->prefix."adminnote WHERE `create_by` = $current_user->ID" );
$totalItemsPerPage = 10;
$pageRange = 5;
if($pageRange %2 == 0) $pageRange = $pageRange + 1;
$totalPage = ceil($totalItems/$totalItemsPerPage);
$currentPage = (isset($_GET['nv'])) ? $_GET['nv'] : 1;
if($currentPage < 1) {
wp_die( __( 'This page does not exist' ) );
}elseif($totalPage > 0 && $currentPage > $totalPage){
wp_die( __( 'This page does not exist' ) );
}
$paginationHTML = '';
if($totalPage > 1){
$start = '';
$prev = '
Previous';
if($currentPage > 1){
$start = '';
$prev = 'Previous';
}
$next = 'Next';
$end = '';
if($currentPage < $totalPage){
$next = 'Next';
$end = '';
}
if($pageRange < $totalPage){
if($currentPage == 1){
$startPage = 1;
$endPage = $pageRange;
}else if($currentPage == $totalPage){
$startPage = $totalPage - $pageRange + 1;
$endPage = $totalPage;
}else{
$startPage = $currentPage - ($pageRange-1)/2;
$endPage = $currentPage + ($pageRange-1)/2;
if($startPage < 1){
$endPage = $endPage + 1;
$startPage = 1;
}
if($endPage > $totalPage){
$endPage = $totalPage;
$startPage = $endPage - $pageRange + 1;
}
}
}else{
$startPage = 1;
$endPage = $totalPage;
}
for($i = $startPage; $i <= $endPage; $i++){
if($i == $currentPage) {
$listPages .= ''.$i.'';
}else{
$listPages .= ''.$i.'';
}
}
$paginationHTML = '';
}
$position = ($currentPage-1)*$totalItemsPerPage;
$note_info = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."adminnote WHERE `create_by` = $current_user->ID ORDER BY `id` DESC LIMIT $position , $totalItemsPerPage" );
?>
get_results("SELECT `ID`,`user_login`,`display_name` FROM $wpdb->users");
global $current_user;
get_currentuserinfo();
if($_POST){
$datetime = current_time( 'mysql' );
$title = $_POST['title'];
$content = $_POST['content'];
$create_by = $current_user->ID;
$userid = $_POST['note_for'];
$wpdb->insert($wpdb->prefix.'adminnote', array(
'time' => $datetime,
'name' => $title,
'text' => $content,
'userid'=> $userid,
'create_by' => $create_by,
), array(
'%s',
'%s',
'%s',
'%d',
'%d',
));
$last_insert_id = $wpdb->insert_id;
if($last_insert_id > 0){
header('Location: ./admin.php?page=admin-note');
}else{
header('Location: ./admin.php?page=admin-note');
}
}
?>
get_row("SELECT * FROM ".$wpdb->prefix."adminnote WHERE `id` = ".$note_id);
$users = $wpdb->get_results("SELECT `ID`,`user_login`,`display_name` FROM $wpdb->users");
global $current_user;
get_currentuserinfo();
if($current_user->ID != $note_info->create_by){
wp_die( __( 'You do not have sufficient permissions to access this page.' ));
}
if($_POST){
$title = $_POST['title'];
$content = $_POST['content'];
$create_by = $current_user->ID;
$userid = $_POST['note_for'];
$wpdb->update($wpdb->prefix.'adminnote', array(
'name' => $title,
'text' => $content,
'userid'=> $userid,
),
array('id' => $note_id),
array(
'%s',
'%s',
'%d',
),
array('%d'));
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
header("Location: $actual_link");
}
?>