prefix . 'attendance'; $table_name_index = $wpdb->prefix . 'attendance_index'; if($wpdb->get_var("show tables like '$table_name '") != $table_name ) { $sql = "CREATE TABLE " . $table_name . " ( `id` int(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, `adate` date NOT NULL, `user_id` int(10) NOT NULL, `entrytime` datetime NOT NULL, `display_name` varchar(250) NOT NULL, `exittime` datetime NOT NULL, `entry_ip_address` varchar(100) NOT NULL, `exit_ip_address` varchar(100) NOT NULL, UNIQUE KEY " . $table_name_index . " (`user_id`,`adate`) );"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } } // run the install scripts upon plugin activation register_activation_hook(__FILE__,'aistore2030_options_install'); add_action( 'admin_menu', 'aistore2030_register_my_custom_menu_page' ); function aistore2030_register_my_custom_menu_page() { add_menu_page('Attendance', 'Attendance', 'manage_options', 'aistore2030_full_attendance','aistore2030_full_attendance','',71); add_submenu_page( 'aistore2030_full_attendance', 'Attendance Page', 'Attendance Page', 'manage_options', 'aistore2030_daily_attendance', 'aistore2030_daily_attendance'); add_submenu_page( 'aistore2030_full_attendance', 'Punch in/out', 'Punch in/out', 'manage_options', 'aistore2030_punch_in_punch_out', 'aistore2030_punch_in_punch_out'); } function aistore2030_daily_attendance() { $user = wp_get_current_user(); $id=$user->ID ; global $wpdb; $month=date('m'); if (isset($_REQUEST['month'])) { $month=$_REQUEST['month']; } $table_name = $wpdb->prefix . 'attendance'; $result = $wpdb->get_results("SELECT user_id,display_name,count(user_id ) as working_days FROM $table_name WHERE MONTH(adate)=".$month." GROUP by user_id,display_name"); echo "

Employee working days report monthly for salary preparation

"; $url=admin_url("admin.php?page=aistore2030_daily_attendance&month=".date('m', strtotime('-4 month'))); echo "".date('F', strtotime('-4 month')) . " "; $url=admin_url("admin.php?page=aistore2030_daily_attendance&month=".date('m', strtotime('-3 month'))); echo "".date('F', strtotime('-3 month')) . " "; $url=admin_url("admin.php?page=aistore2030_daily_attendance&month=".date('m', strtotime('-2 month'))); echo "".date('F', strtotime('-2 month')) . " "; $url=admin_url("admin.php?page=aistore2030_daily_attendance&month=".date('m', strtotime('-1 month'))); echo "".date('F', strtotime('-1 month')) . " "; $url=admin_url("admin.php?page=aistore2030_daily_attendance&month=".date('m')); echo "".date('F') . " "; ?> "; echo ""; echo ""; echo ""; echo ""; } echo "
User Id Full Name Working Days
".$wp_formmaker_submits->user_id."".$wp_formmaker_submits->display_name."".$wp_formmaker_submits->working_days."
"; } function aistore2030_full_attendance() { echo "
" ; $user = wp_get_current_user(); $id=$user->ID ; global $wpdb; $user_id=$id; if (isset($_REQUEST['user_id'])) { $user_id = sanitize_text_field($_REQUEST['user_id']); } echo "

Full Attendance sheet of the company (Recent 60 Records )

" ; $table_name = $wpdb->prefix . 'attendance'; $result = $wpdb->get_results("SELECT distinct display_name,user_id FROM $table_name order by id desc"); $i=0; echo '' ; foreach($result as $display_name){ $i=$i+1; $url=admin_url( 'admin.php?page=aistore2030_full_attendance&user_id='.$display_name->user_id ); echo "" ; if($i==3) { echo "" ; $i=0; } } echo "
".$display_name->display_name."
" ; $table_name = $wpdb->prefix . 'attendance'; $result = $wpdb->get_results( $wpdb->prepare( "SELECT * , TIMESTAMPDIFF(HOUR, entrytime, entrytime) AS hours_different FROM $table_name where user_id=%d limit 60",$user_id)); ?> "; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
id Date Name Entry Time Entry IP Address Exit Time Exit IP Address Hours Different
".$wp_formmaker_submits->id."".$wp_formmaker_submits->adate."".$wp_formmaker_submits->display_name."".$wp_formmaker_submits->entrytime."".$wp_formmaker_submits->entry_ip_address."".$wp_formmaker_submits->exittime."".$wp_formmaker_submits->exit_ip_address."".$wp_formmaker_submits->hours_different."
"; } function aistore2030_punch_in_punch_out() { global $wpdb; $table_name = $wpdb->prefix . 'attendance'; $user = wp_get_current_user(); $id=$user->ID ; $display_name=$user->display_name ; $ip_address=aistore_getRealIpAddr(); if ( ! isset( $_POST['punch_nonce'] ) || ! wp_verify_nonce( $_POST['punch_nonce'], 'punch_nonce' ) ) { } else { $type = sanitize_text_field($_REQUEST['type']); if($type=="in") { $wpdb->query( $wpdb->prepare( "INSERT INTO $table_name (user_id,adate, display_name,entrytime,entry_ip_address ) VALUES (%d,date(now()),%s,now() ,%s)",array($id, $display_name,$ip_address ))); } elseif($type=="out") { $wpdb->query( $wpdb->prepare( "update $table_name set exittime= now() , exit_ip_address = %s where user_id = %d and adate= date(now()) " ,array( $ip_address, $id) ) ); } } ?>

Attendance sheet

Punch INPunch Out
get_results("SELECT * FROM wp1f_attendance WHERE DATE(entrytime) = CURDATE() order by id desc"); foreach($result as $wp_formmaker_submits){ echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
Name Entry time Exit time
".$wp_formmaker_submits->display_name."".$wp_formmaker_submits->entrytime." ("; echo "".$wp_formmaker_submits->entry_ip_address." )".$wp_formmaker_submits->exittime." ( "; echo "".$wp_formmaker_submits->exit_ip_address." )
"; } function aistore_getRealIpAddr() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } return $ip; } ?>