<?php

/*
Plugin Name: LogBook SSK Angkasa Pura 2
Plugin URI: https://code.google.com/p/logbook-lenny/
Description: LogBook for SSK Airport (Sultan Syarif Kasim Airport)
Author: Leni Rapika Oktapiani
Version: 1.0.0
Author URI: https://code.google.com/u/114844818880194934018/

*/

/** Jika dipanggil langsung dari http, bukan sebagai plugin, maka
  langsung tewas.
*/
if(!function_exists('add_action'))die('Maaf, jangan dijalankan langsung ya ...!');

/*
#####=====#####=====#####=====#####=====#####=====#####=====
#####=====#####=====#####=====#####=====#####=====#####=====
 ADMIN MENU
#####=====#####=====#####=====#####=====#####=====#####=====
#####=====#####=====#####=====#####=====#####=====#####=====
*/

add_action( 'admin_menu', 'pmb_create_menu' );

function pmb_create_menu() {

  //create custom top-level menu
  //add_menu_page( page_title, menu_title, capability, menu_slug, function, icon_url, position );
  //  page_title  —   The title of the page as shown in the    <title>   tags
  //  menu_title  —   The name of your menu displayed on the dashboard
  //  capability  —   Minimum capability required to view the menu
  //  menu_slug   —   Slug name to refer to the menu; should be a unique name
  //  function    —   Function to be called to display the page content for the item
  //  icon_url    —   URL to a custom image to use as the Menu icon
  //  position    —   Location in the menu order where it should appear

  //add_menu_page( 'PMB', 'PMB', 'manage_options', __FILE__, 'pmb_settings_page', plugins_url( '/images/wp-logo.png', __FILE__ ),0 );
  

  //30 Maret 2012 21:39:27
  //add_menu_page( 'PMB', 'PMB', 'manage_options', __FILE__, 'pmb_settings_page','',0 );

  //01 April 2012 13:23:43 
  //tambahan fitur: agar user yang biasa yang cuma bisa read saja bisa edit datanya sendiri...
  //add_menu_page( 'Log Book SSK', 'Logbook',', 'read', __FILE__, 'pmb_settings_page','',0 );//01 April 2012 13:15:58
  add_menu_page( 'Log Book SSK', 'Perbaikan Peralatan', 'read', __FILE__, 'pmb_settings_page',plugins_url( 'logbook16x16.png', __FILE__ ),0 );// 2012-06-06

  //create submenu items
  //add_submenu_page( parent_slug, page_title, menu_title, capability, menu_slug, function );
  //add_submenu_page( __FILE__, 'PMB > Edit', 'Edit', 'manage_options', __FILE__.'_edit', 'pmb_edit_page' );
  add_submenu_page( __FILE__, 'LogBook > Edit', 'Data Teknisi', 'manage_options', 'pmb_myplugin', 'pmb_edit_page' );
  add_submenu_page( __FILE__, 'LogBook > Edit', 'Data Peralatan', 'manage_options', 'pmb_myplugin', 'pmb_alat_page' );
  add_submenu_page( __FILE__, 'LogBook > Help', 'Help', 'read', __FILE__.'_help', 'pmb_help_page' );
  add_submenu_page( __FILE__, 'LogBook > About', 'About', 'manage_options', __FILE__.'_about', 'pmb_about_page' );


  //Following is a list of all available submenu functions in WordPress.
  //add_dashboard_page  —   Adds a submenu to the Dashboard menu
  //add_posts_page      —   Adds a submenu to the Posts menu
  //add_media_page      —   Adds a submenu to the Media menu
  //add_links_page      —   Adds a submenu to the Links menu
  //add_pages_page      —   Adds a submenu to the Pages menu
  //add_comments_page   —   Adds a submenu to the Comments page
  //add_theme_page      —   Adds a submenu to the Appearance menu
  //add_plugins_page    —   Adds a submenu to the Plugins menu
  //add_users_page      —   Adds a submenu to the Users menu
  //add_management_page —   Adds a submenu to the Tools menu
  //add_options_page    —   Adds a submenu to the Settings menu

  //create a submenu under Settings
  //add_options_page( 'PMB Settings Page', 'PMB', 'manage_options', __FILE__, 'pmb_settings_page' );

}

function pmb_settings_page(){

  echo '<div class="wrap">
    <div id="icon-users" class="icon32"></div>
    <h2>Perbaikan Peralatan</h2>
    Lengkapi data perbaikan peralatan di bawah ini :';
	

?>
<form id="form1" name="form1" method="post" action="">
  <p>ID_Teknisi&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" name="textfield" border="5" accesskey="3" tabindex="3" />
</p>
  <p>
    <label>KD_Teknisi&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" name="textfield2" />
    </label>
  </p>
  <p>NIP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" name="textfield23" />
  </p>
  <p>
    <label>Nama_Teknisi&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" name="textfield22" />
    </label>
</p>
  <p>

    <label>TTL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <select name="select">
      <option>01</option>
      <option>02</option>
      <option>03</option>
      <option>04</option>
      <option>05</option>
      <option>06</option>
      <option>07</option>
      <option>08</option>
      <option>09</option>
      <option>10</option>
      <option>11</option>
      <option>12</option>
      <option>13</option>
      <option>14</option>
      <option>15</option>
      <option>16</option>
      <option>17</option>
      <option>18</option>
      <option>19</option>
      <option>20</option>
      <option>21</option>
      <option>22</option>
      <option>23</option>
      <option>24</option>
      <option>25</option>
      <option>16</option>
      <option>27</option>
      <option>28</option>
      <option>29</option>
      <option>30</option>
      <option>31</option>
      <option>32</option>
    </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    </label>
    <select name="select5">
      <option>Januari</option>
      <option>Februari</option>
      <option>Maret</option>
      <option>April</option>
      <option>Mei</option>
      <option>Juni</option>
      <option>Juli</option>
      <option>Agustus</option>
      <option>September</option>
      <option>Oktober</option>
      <option>November</option>
      <option>Desember</option>
    </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <select name="select6">
      <option>2000</option>
      <option>1999</option>
      <option>1998</option>
      <option>1997</option>
      <option>1996</option>
      <option>1995</option>
      <option>1994</option>
      <option>1993</option>
      <option>1992</option>
      <option>1991</option>
      <option>1990</option>
      <option>1989</option>
      <option>1988</option>
      <option>1987</option>
      <option>1986</option>
      <option>1985</option>
      <option>1984</option>
      <option>1983</option>
      <option>1982</option>
      <option>1981</option>
      <option>1980</option>
      <option>1979</option>
      <option>1978</option>
      <option>1977</option>
      <option>1976</option>
      <option>1975</option>
      <option>1974</option>
      <option>1973</option>
      <option>1973</option>
      <option>1971</option>
      <option>1970</option>
    </select>
  </p>

  <p>
    <label>KD_Jabatan&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <select name="select2">
      <option>1</option>
      <option>2</option>
      <option>3</option>
      <option>4</option>
      <option>5</option>
      <option>6</option>
      <option>7</option>
      <option>8</option>
      <option>9</option>
      <option>10</option>
      <option>11</option>
      <option>12</option>
      <option>13</option>
      <option>14</option>
      <option>15</option>
    </select>
    </label>
  </p>
  <p>
    <label>Pendidikan&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <label>
    <input name="radiobutton" type="radio" value="radiobutton" />
    SMA</label>
  &nbsp;&nbsp;&nbsp;&nbsp;
  <label>
  <input name="radiobutton" type="radio" value="radiobutton" />
  DIPLOMA</label>
  &nbsp;&nbsp;&nbsp;&nbsp;
  <label>
  <input name="radiobutton" type="radio" value="radiobutton" />
  STRATA</label>
  </p>
  <p>
    <label></label>
  </p>
  <p>
    <label>Keterangan&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
    <textarea name="textarea" cols="30" rows="10"></textarea>
  </p>
</form>

<?
}





function pmb_edit_page(){
  ?> 
  <div class="wrap"> 
    <div id="icon-edit-pages" class="icon32"></div>
    <h2>Data Teknisi</h2>
<pre>

NIP				: <input type=text name=nama size=20> 
Nama Teknisi	: <input type=text name=nama size=20> 
Alamat			: <input type=text name=aplikasi size=20> 
TTL			    : <input type=text name=merk size=20> 
Jabatan		    : <input type=text name=lokasi size=20> 
Pendidikan	    : <input type=text name=kerusakan size=20>
Tingkat		    : <input type=text name=tindakan size=20>  
Raiting			: <input type=text name=hasil size=20>
Ket 			: <input type=text name=ket size=20> 

<textarea name=pesanan rows=5 cols=30> 
</textarea> 
</pre>
    <?php
}


function pmb_alat_page(){
  ?> 
  <div class="wrap"> 
    <div id="icon-edit-pages" class="icon32"></div>
    <h2>Data Peralatan</h2>
<pre>

NIP				: <input type=text name=nama size=20> 
Nama Teknisi	: <input type=text name=nama size=20> 
Alamat			: <input type=text name=aplikasi size=20> 
TTL			    : <input type=text name=merk size=20> 
Jabatan		    : <input type=text name=lokasi size=20> 
Pendidikan	    : <input type=text name=kerusakan size=20>
Tingkat		    : <input type=text name=tindakan size=20>  
Ket 			: <input type=text name=ket size=20> 

<textarea name=pesanan rows=5 cols=30> 
</textarea> 
</pre>
    <?php
}

// Register and define the settings
add_action('admin_init', 'pmb_myplugin_admin_init');
function pmb_myplugin_admin_init(){
  register_setting(
    'pmb_myplugin_options', //The first parameter is the setting group name
    'pmb_myplugin_options', //and the second parameter is the option name as you would use it in a get_option() call
    'pmb_myplugin_validate_options'//  The third parameter is an optional function callback
  );

  // The first function call,   add_settings_section() , defines how the section on the page will show. 
  //The four required parameters it uses follow: 
  add_settings_section(
    'pmb_myplugin_main',         // An HTML ID tag for the section
    'Edit Data PMB',             // The section title text that will show within an <H3> tag 
    'pmb_myplugin_section_text', // The name of the callback function that will echo some explanations about that section 
    'pmb_myplugin'               // The settings page on which to show the section (that is, the  ?page=pmb_myplugin  part of the page URL)
  );
  add_settings_field('pmb_myplugin_text_string','Enter text here','pmb_myplugin_setting_input','pmb_myplugin','pmb_myplugin_main');
}

//need to define two simple callback functions: 
//  One to display a few explanations about the section and 
//  one to output and fill the form field. 

// Explanations about this section
function pmb_myplugin_section_text() {
  echo '<p>Edit data PMB di sini.</p>';
  print_r(get_option( 'pmb_myplugin_options' ));
}
// Display and fill the form field
function pmb_myplugin_setting_input() {
    // get option 'text_string' value from the database
    $options = get_option( 'pmb_myplugin_options' );
    $text_string = $options['text_string'];
    // echo the field
    //echo "<input id='text_string' name='pmb_myplugin_options[text_string]' type='text' value='{$options['text_string']}' />";
    echo "<input id='text_string' name='pmb_myplugin_options[text_string]' type='text' value='$text_string' />";
}

// Validate user input (we want text only)
function pmb_myplugin_validate_options( $input ) {
  $valid = array();
  $valid['text_string'] = preg_replace(
      '/[^a-zA-Z]/',
      '',
      $input['text_string'] );

  if( $valid['text_string'] != $input['text_string'] ) {
    add_settings_error(
      'pmb_myplugin_text_string',
      'pmb_myplugin_texterror',
      'Incorrect value entered!',
      'error'
    );
  }

  return $valid;
}



function pmb_help_page(){
  ?> 
     <div class="wrap"> 
            <div id="icon-tools" class="icon32"></div>
         <h2>Help</h2> 
         <p>
         PMB ini hanya untuk menampung data calon mahasiswa secara on-line. 
         </p>
          Jika Anda memiliki pertanyaan, silahkan ke <a href="http://jazman.keren.la/">Lenny Keren la ...!</a>

     </div> 
     <?php
}
function pmb_about_page(){
  ?> 
  <div class="wrap"> 
    <div id="icon-options-general" class="icon32"></div>
    <h2>About  My Plugin  </h2>
    <a href="http://jazman.keren.la/">Lenny Keren la ...!</a>

  </div> 
  <?php
}









/*
#####=====#####=====#####=====#####=====#####=====#####=====
#####=====#####=====#####=====#####=====#####=====#####=====
 DASHBOARD WIDGETS
#####=====#####=====#####=====#####=====#####=====#####=====
#####=====#####=====#####=====#####=====#####=====#####=====
*/
add_action( 'wp_dashboard_setup', 'pmb_dashboard_widgets' );
function pmb_dashboard_widgets() {
  //create a custom dashboard widget
  //wp_add_dashboard_widget( widget_id, widget_name, callback,control_callback );
    wp_add_dashboard_widget( 'pmb_dashboard','LogBook Information', 'pmb_dashboard_widget_display' );
}
function pmb_dashboard_widget_display()
{
  //TODO: QUERY YANG DAFTAR DI SINI
  echo ' <h3>Statistik LogBook</h3><p> Pada saat ini Logbook sedang Offline !!! Maaf ....</p> ';
}





/*
#####=====#####=====#####=====#####=====#####=====#####=====
 WIDGETS
 /wp-admin/widgets.php
#####=====#####=====#####=====#####=====#####=====#####=====
*/

// use widgets_init action hook to execute custom function
add_action( 'widgets_init', 'pmb_register_widgets' );
             
 //register our widget
function pmb_register_widgets() {
  register_widget( 'pmb_widgetexample_widget_my_info' );
}


class pmb_widgetexample_widget_my_info extends WP_Widget {
  //process the new widget
  function pmb_widgetexample_widget_my_info() {
      $widget_ops = array(
          'classname' =>  'pmb_widgetexample_widget_class',
          'description' =>  'Display a user\'s favorite movie and song.'
      );
      $this->WP_Widget( 'pmb_widgetexample_widget_my_info', 'PMB Info',
          $widget_ops );
  }

    //build the widget settings form
    function form($instance) {
        $defaults = array( 'title' =>  'My Info', 'movie' =>  '', 'song' =>  '' );
        $instance = wp_parse_args( (array) $instance, $defaults );
        $title = $instance['title'];
        $movie = $instance['movie'];
        $song = $instance['song'];
        ?> 
         <p>Title: <input class="widefat" name="<?php echo $this->get_field_name('title');?>" type="text"
            value="<?php echo esc_attr($title); ?>" /></p> 
         <p>Favorite Movie:  <input class="widefat" name="<?php echo $this->get_field_name( 'movie' ); ?>"  type="text" value=" <?php echo esc_attr( $movie ); ?>" /></p> 
         <p>Favorite Song:   <textarea class="widefat" name="<?php echo $this->get_field_name( 'song' ); ?>" /><?php echo esc_attr( $song ); ?></textarea></p> 
         <?php
    }


  //save the widget settings
  function update($new_instance, $old_instance) {
      $instance = $old_instance;
      $instance['title'] = strip_tags( $new_instance['title'] );
      $instance['movie'] = strip_tags( $new_instance['movie'] );
      $instance['song'] = strip_tags( $new_instance['song'] );
           
      return $instance;
  }
  //display the widget
  function widget($args, $instance) {
    extract($args);
    echo $before_widget;
    $title = apply_filters( 'widget_title', $instance['title'] );
    $movie = empty( $instance['movie'] ) ? ' &nbsp;' : $instance['movie'];
    $song = empty( $instance['song'] ) ? ' &nbsp;' : $instance['song'];

    if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
    echo ' <p> Fav Movie: ' . $movie . ' </p> ';
    echo ' <p> Fav Song: ' . $song . ' </p> ';
    echo $after_widget;
  }
}











             
/* Add the post form to the user/profile edit page in the admin. */
add_action( 'show_user_profile', 'pmb_post_form' );
add_action( 'edit_user_profile', 'pmb_post_form' );

/* Function for displaying an extra form on the user edit page. */
function pmb_post_form( $user ) {

  /* Get the current user's meta */
  $first_name = get_user_meta( $user->ID, 'first_name', true );
  $tempat_lahir = get_user_meta( $user->ID, 'tempat_lahir', true );
  $tahun_lahir = get_user_meta( $user->ID, 'tahun_lahir', true );
  $bulan_lahir = get_user_meta( $user->ID, 'bulan_lahir', true );
  $hari_lahir = get_user_meta( $user->ID, 'hari_lahir', true );
  $alamat = get_user_meta( $user->ID, 'alamat', true );
  $rt = get_user_meta( $user->ID, 'rt', true );
  $rw = get_user_meta( $user->ID, 'rw', true );
  $kota = get_user_meta( $user->ID, 'kota', true );
  $provinsi = get_user_meta( $user->ID, 'provinsi', true );
  $kode_pos = get_user_meta( $user->ID, 'kode_pos', true );
  $telepon = get_user_meta( $user->ID, 'telepon', true );
  $hp = get_user_meta( $user->ID, 'hp', true );
  $agama = get_user_meta( $user->ID, 'agama', true );
  $status_menikah = get_user_meta( $user->ID, 'status_menikah', true );
  $jenis_kelamin = get_user_meta( $user->ID, 'jenis_kelamin', true );
  $sekolah_asal = get_user_meta( $user->ID, 'sekolah_asal', true );
  $status_sekolah = get_user_meta( $user->ID, 'status_sekolah', true );
  $jurusan_sekolah = get_user_meta( $user->ID, 'jurusan_sekolah', true );
  $nomor_ijazah = get_user_meta( $user->ID, 'nomor_ijazah', true );
  $sumber_info = get_user_meta( $user->ID, 'sumber_info', true );
  $keberatan = get_user_meta( $user->ID, 'keberatan', true );
  $pilihan1 = get_user_meta( $user->ID, 'pilihan1', true );
  $pilihan2 = get_user_meta( $user->ID, 'pilihan2', true );
  $pilihan3 = get_user_meta( $user->ID, 'pilihan3', true );
  ?>
  
  <h3>LOGBOOK</h3>
  <p>Silahkan isi Logbook dibawah ini dengan data yang sesuai dengan data yang benar dan sesuai dengan yang telah dikerjakan</p>
  <table class="form-table" >

    <tr>
      <th><label for="tempat_lahir">Hari</label></th>
      <td>
        <input type="text" id="tempat_lahir" name="tempat_lahir" value="<?php echo $tempat_lahir;?>" class="regular-text">
        <br />
        <span class="description">Masukkan hari melakukan perbaikan. </span>
      </td>
    </tr>
    
    <tr>
      <th><label for="hari_lahir">Tanggal perbaikan</label></th>
      <td>
        <input type="text" id="hari_lahir" name="hari_lahir" value="<?php echo $hari_lahir;?>" class="regular-text">
        <br />
        <span class="description">Masukkan 2 (DUA) DIGIT tanggal tanggal perbaikan peralatan. </span>
      </td>
    </tr>
    
    <tr>
      <th><label for="bulan_lahir">Bulan</label></th>
      <td>
        <input type="text" id="bulan_lahir" name="bulan_lahir" value="<?php echo $bulan_lahir;?>" class="regular-text">
        <br />
        <span class="description">Masukkan 2 (DUA) DIGIT bulan perbaikan peralatan. </span>
      </td>
    </tr>

    <tr>
      <th><label for="tahun_lahir">Tahun</label></th>
      <td>
        <input type="text" id="tahun_lahir" name="tahun_lahir" value="<?php echo $tahun_lahir;?>" class="regular-text">
        <br />
        <span class="description">Masukkan EMPAT DIGIT tahun perbaikan peralatan. </span>
      </td>
    </tr>
    
    <tr>
      <th><label for="first_name">Nama Peralatan</label></th>
      <td>
        <input type="text" id="first_name" name="first_name" value="<?php echo $first_name;?>" class="regular-text">
        <br />
        <span class="description">Masukkan Nama peralatan yang diperbaiki. </span>
      </td>
    </tr>


    <tr>
      <th><label for="alamat">Aplikasi</label></th>
      <td>
        <textarea name="alamat" id="alamat" rows="5" cols="30"><?php echo $alamat;?></textarea>
        <br />
        <span class="description">Masukkan aplikasi peralatan. </span>
      </td>
    </tr>
    <tr>
      <th><label for="rt">Merk</label></th>
      <td>
        <input type="text" id="rt" name="rt" value="<?php echo $rt;?>" class="regular-text">
        <br />
        <span class="description">Masukkan merk dari peralatan. </span>
      </td>
    </tr>
    <tr>
      <th><label for="rw">Lokasi</label></th>
      <td>
        <input type="text" id="rw" name="rw" value="<?php echo $rw;?>" class="regular-text">
        <br />
        <span class="description">Masukkan Lokasi / tempat peralatan. </span>
      </td>
    </tr>
    <tr>
      <th><label for="kota">Kerusakan</label></th>
      <td>
        <input type="text" id="kota" name="kota" value="<?php echo $kota;?>" class="regular-text">
        <br />
        <span class="description">Masukkan kerusakan yang terjadi. </span>
      </td>
    </tr>
    <tr>
      <th><label for="provinsi">Tindakan</label></th>
      <td>
        <input type="text" id="provinsi" name="provinsi" value="<?php echo $provinsi;?>" class="regular-text">
        <br />
        <span class="description">Masukkan Tindakan yang dilakukanuntuk perbaikan. </span>
      </td>
    </tr>
    <tr>
      <th><label for="kode_pos">Hasil</label></th>
      <td>
        <input type="text" id="kode_pos" name="kode_pos" value="<?php echo $kode_pos;?>" class="regular-text">
        <br />
        <span class="description">Masukkan hasil yang didapat. </span>
      </td>
    </tr>
    <tr>
      <th><label for="telepon">Keterangan</label></th>
      <td>
        <input type="text" id="telepon" name="telepon" value="<?php echo $telepon;?>" class="regular-text">
        <br />
        <span class="description">Keterangan. </span>
      </td>
    </tr>
    <tr>
      <th><label for="hp">Nama Teknisi</label></th>
      <td>
        <input type="text" id="hp" name="hp" value="<?php echo $hp;?>" class="regular-text">
        <br />
        <span class="description">Masukkan nama teknisi<i>hand phone</i> / <i>mobile phone</i> Anda. </span>
      </td>
    </tr>
    <tr>
      <th><label for="agama">Agama</label></th>
      <td>
        <!-- <input type="text" id="agama" name="agama" value="<?php echo $agama;?>" class="regular-text"> -->
        <SELECT NAME="agama" ID="agama">
          <OPTION VALUE=""></OPTION>
          <OPTION VALUE="Islam" <?php selected( $agama, 'Islam' ); ?>>Islam</OPTION>
          <OPTION VALUE="Kristen Katolik" <?php selected( $agama, 'Kristen Katolik' ); ?>>Kristen Katolik</OPTION>
          <OPTION VALUE="Kristen Protestan" <?php selected( $agama, 'Kristen Protestan' ); ?>>Kristen Protestan</OPTION>
          <OPTION VALUE="Hindu" <?php selected( $agama, 'Hindu' ); ?>>Hindu</OPTION>
          <OPTION VALUE="Budha" <?php selected( $agama, 'Budha' ); ?>>Budha</OPTION>
          <OPTION VALUE="Lainnya" <?php selected( $agama, 'Lainnya' ); ?>>Lainnya</OPTION>
        </SELECT>
        <br />
        <span class="description">Masukkan agama Anda. </span>
      </td>
    </tr>
    <tr>
      <th><label for="status_menikah">Status Menikah</label></th>
      <td>
        <!-- <input type="text" id="status_menikah" name="status_menikah" value="<?php echo $status_menikah;?>" class="regular-text"> -->
        <SELECT NAME="status_menikah" ID="status_menikah">
          <OPTION VALUE=""></OPTION>
          <OPTION VALUE="Belum Menikah" <?php selected( $status_menikah, 'Belum Menikah' ); ?>>Belum Menikah</OPTION>
          <OPTION VALUE="Menikah" <?php selected( $status_menikah, 'Menikah' ); ?>>Menikah</OPTION>
        </SELECT>

        <br />
        <span class="description">Masukkan status menikah Anda. </span>
      </td>
    </tr>
    <tr>
      <th><label for="jenis_kelamin">Jenis Kelamin</label></th>
      <td>
        <!-- <input type="text" id="jenis_kelamin" name="jenis_kelamin" value="<?php echo $jenis_kelamin;?>" class="regular-text"> -->
        <SELECT NAME="jenis_kelamin" ID="jenis_kelamin">
          <OPTION VALUE=""></OPTION>
          <OPTION VALUE="Laki-laki" <?php selected( $jenis_kelamin, 'Laki-laki' ); ?>>Laki-laki</OPTION>
          <OPTION VALUE="Perempuan" <?php selected( $jenis_kelamin, 'Perempuan' ); ?>>Perempuan</OPTION>
        </SELECT>
        <br />
        <span class="description">Masukkan jenis_kelamin Anda. </span>
      </td>
    </tr>
    <tr>
      <th><label for="sekolah_asal">Asal SLTA</label></th>
      <td>
        <SELECT NAME="sekolah_asal" ID="sekolah_asal">
          <OPTION VALUE=""></OPTION>
          <OPTION VALUE="SMU" <?php selected( $sekolah_asal, 'SMU' ); ?>>SMU</OPTION>
          <OPTION VALUE="SMK" <?php selected( $sekolah_asal, 'SMK' ); ?>>SMK</OPTION>
          <OPTION VALUE="Madrasah Aliyah" <?php selected( $sekolah_asal, 'Madrasah Aliyah' ); ?>>Madrasah Aliyah</OPTION>
          <OPTION VALUE="Lainnya" <?php selected( $sekolah_asal, 'Lainnya' ); ?>>Lainnya</OPTION>
        </SELECT>
        <br />
        <span class="description">Masukkan asal sekolah Anda. </span>
      </td>
    </tr>
    <tr>
      <th><label for="status_sekolah">Status Sekolah</label></th>
      <td>
        <SELECT NAME="status_sekolah" ID="status_sekolah">
          <OPTION VALUE=""></OPTION>
          <OPTION VALUE="Negeri" <?php selected( $status_sekolah, 'Negeri' ); ?>>Negeri</OPTION>
          <OPTION VALUE="Swasta" <?php selected( $status_sekolah, 'Swasta' ); ?>>Swasta</OPTION>
        </SELECT>
        <br />
        <span class="description">Masukkan Status Sekolah Anda. </span>
      </td>
    </tr>


    <tr>
      <th><label for="jurusan_sekolah">Jurusan</label></th>
      <td>
        <SELECT NAME="jurusan_sekolah" ID="jurusan_sekolah">
          <OPTION VALUE=""></OPTION>
          <OPTION VALUE="IPA" <?php selected( $jurusan_sekolah, 'IPA' ); ?>>IPA</OPTION>
          <OPTION VALUE="IPS" <?php selected( $jurusan_sekolah, 'IPS' ); ?>>IPS</OPTION>
          <OPTION VALUE="Bahasa" <?php selected( $jurusan_sekolah, 'Bahasa' ); ?>>Bahasa</OPTION>
          <OPTION VALUE="Lainnya" <?php selected( $jurusan_sekolah, 'Lainnya' ); ?>>Lainnya</OPTION>
        </SELECT>
        <br />
        <span class="description">Masukkan Jurusan Anda saat Anda sekolah dahulu. </span>
      </td>
    </tr>

    <tr>
      <th><label for="nomor_ijazah">Nomor Ijazah</label></th>
      <td>
        <input type="text" id="nomor_ijazah" name="nomor_ijazah" value="<?php echo $nomor_ijazah;?>" class="regulartext">
        <br />
        <span class="description">Masukkan nomor ijazah terakhir Anda saat Anda sekolah dahulu. </span>
      </td>
    </tr>

    <tr>
      <th><label for="sumber_info">Sumber Informasi Pendaftaran</label></th>
      <td>
        <SELECT NAME="sumber_info" ID="sumber_info">
          <OPTION VALUE=""></OPTION>
          <OPTION VALUE="Koran" <?php selected( $sumber_info, 'Koran' ); ?>>Koran</OPTION>
          <OPTION VALUE="Brosur" <?php selected( $sumber_info, 'Brosur' ); ?>>Brosur</OPTION>
          <OPTION VALUE="Spanduk" <?php selected( $sumber_info, 'Spanduk' ); ?>>Spanduk</OPTION>
          <OPTION VALUE="Teman" <?php selected( $sumber_info, 'Teman' ); ?>>Teman/Saudara</OPTION>
          <OPTION VALUE="Radio" <?php selected( $sumber_info, 'Radio' ); ?>>Radio</OPTION>
          <OPTION VALUE="Televisi" <?php selected( $sumber_info, 'Televisi' ); ?>>Televisi</OPTION>
          <OPTION VALUE="Lainnya" <?php selected( $sumber_info, 'Lainnya' ); ?>>Lainnya</OPTION>
        </SELECT>
        <br />
        <span class="description">Pilih darimana Anda mendapatkan informasi tentang Politeknik Kampar.
        Informasi Anda tentang ini akan membantu perbaikan proses PMB ditahuntahun berikutnya.
        </span>
      </td>
    </tr>


    <tr>
      <th><label for="keberatan">Keberatan bila biodata ini diberikan pada institusi pendidikan lain?</label></th>
      <td>
        <SELECT NAME="keberatan" ID="keberatan">
          <OPTION VALUE=""></OPTION>
          <OPTION VALUE="Ya" <?php selected( $keberatan, 'Ya' ); ?>>Ya</OPTION>
          <OPTION VALUE="Tidak" <?php selected( $keberatan, 'Tidak' ); ?>>Tidak</OPTION>
        </SELECT>
        <br />
        <span class="description">
        Data Anda jika anda izinkan dapat kami berikan ke institusi pendidikan lain, sehingga Anda tidak akan kerepotan lagi untuk mendaftar ke Perguruan Tinggi/Institusi Pendidikan lainnya.
        </span>
      </td>
    </tr>

    <tr>
      <th><label for="pilihan1">
      Program Studi yang diminati (Sesuai Urutan Prioritas)</label></th>
      <td>
        <SELECT NAME="pilihan1" ID="pilihan1">
          <OPTION VALUE=""></OPTION>
          <OPTION VALUE="Teknik Informatika" <?php selected( $pilihan1, 'Teknik Informatika' ); ?>>Teknik Informatika (TIF)</OPTION>
          <OPTION VALUE="Teknik Pengolahan Sawit" <?php selected( $pilihan1, 'Teknik Pengolahan Sawit' ); ?>>Teknik Pengolahan Sawit (TPS)</OPTION>
          <OPTION VALUE="Perawatan dan Perbaikan Mesin" <?php selected( $pilihan1, 'Perawatan dan Perbaikan Mesin' ); ?>>Perawatan dan Perbaikan Mesin (PPM)</OPTION>
        </SELECT>
        <br />

        <SELECT NAME="pilihan2" ID="pilihan2">
          <OPTION VALUE=""></OPTION>
          <OPTION VALUE="Teknik Informatika" <?php selected( $pilihan2, 'Teknik Informatika' ); ?>>Teknik Informatika (TIF)</OPTION>
          <OPTION VALUE="Teknik Pengolahan Sawit" <?php selected( $pilihan2, 'Teknik Pengolahan Sawit' ); ?>>Teknik Pengolahan Sawit (TPS)</OPTION>
          <OPTION VALUE="Perawatan dan Perbaikan Mesin" <?php selected( $pilihan2, 'Perawatan dan Perbaikan Mesin' ); ?>>Perawatan dan Perbaikan Mesin (PPM)</OPTION>
        </SELECT>
        <br />

        <SELECT NAME="pilihan3" ID="pilihan3">
          <OPTION VALUE=""></OPTION>
          <OPTION VALUE="Teknik Informatika" <?php selected( $pilihan3, 'Teknik Informatika' ); ?>>Teknik Informatika (TIF)</OPTION>
          <OPTION VALUE="Teknik Pengolahan Sawit" <?php selected( $pilihan3, 'Teknik Pengolahan Sawit' ); ?>>Teknik Pengolahan Sawit (TPS)</OPTION>
          <OPTION VALUE="Perawatan dan Perbaikan Mesin" <?php selected( $pilihan3, 'Perawatan dan Perbaikan Mesin' ); ?>>Perawatan dan Perbaikan Mesin (PPM)</OPTION>
        </SELECT>
        <br />
        <span class="description">
        
        </span>
      </td>
    </tr>


  </table>
  <?php
}



/* Add the update function to the user update hooks. */
add_action( 'personal_options_update', 'pmb_post_update' );
add_action( 'edit_user_profile_update', 'pmb_post_update' );
             
/* Function for updating the user's favorite post. */
function pmb_post_update( $user_id ) {
             
    /* Check if the current user has permission to edit the user. */
    if ( !current_user_can( 'edit_user', $user_id ) )
        return false;
             

    /* Only accept numbers 0-9 since it's a year. */
    $tahun_lahir = preg_replace( "/[^0-9]/", '', $_POST['tahun_lahir'] );
    $bulan_lahir = preg_replace( "/[^0-9]/", '', $_POST['bulan_lahir'] );
    $hari_lahir = preg_replace( "/[^0-9]/", '', $_POST['hari_lahir'] );
    $rt = preg_replace( "/[^0-9]/", '', $_POST['rt'] );
    $rw = preg_replace( "/[^0-9]/", '', $_POST['rw'] );
    $kode_pos = preg_replace( "/[^0-9]/", '', $_POST['kode_pos'] );

    /* Update the user's tahun_lahir */
    update_user_meta( $user_id, 'tahun_lahir', $tahun_lahir );
    update_user_meta( $user_id, 'bulan_lahir', $bulan_lahir );
    update_user_meta( $user_id, 'hari_lahir', $hari_lahir );
    update_user_meta( $user_id, 'rt', $rt );
    update_user_meta( $user_id, 'rw', $rw );
    update_user_meta( $user_id, 'kode_pos', $kode_pos );


    //$tempat_lahir = strip_tags($_POST['tempat_lahir']);
    update_user_meta( $user_id, 'first_name', htmlentities( wp_strip_all_tags($_POST['first_name'])) );
    update_user_meta( $user_id, 'tempat_lahir', htmlentities( wp_strip_all_tags($_POST['tempat_lahir'])) );
    update_user_meta( $user_id, 'alamat', htmlentities( wp_strip_all_tags($_POST['alamat'])) );
    update_user_meta( $user_id, 'kota', htmlentities( wp_strip_all_tags($_POST['kota'])) );
    update_user_meta( $user_id, 'provinsi', htmlentities( wp_strip_all_tags($_POST['provinsi'])) );
    update_user_meta( $user_id, 'telepon', htmlentities( wp_strip_all_tags($_POST['telepon'])) );
    update_user_meta( $user_id, 'hp', htmlentities( wp_strip_all_tags($_POST['hp'])) );
    update_user_meta( $user_id, 'agama', htmlentities( wp_strip_all_tags($_POST['agama'])) );
    update_user_meta( $user_id, 'status_menikah', htmlentities( wp_strip_all_tags($_POST['status_menikah'])) );
    update_user_meta( $user_id, 'jenis_kelamin', htmlentities( wp_strip_all_tags($_POST['jenis_kelamin'])) );
    update_user_meta( $user_id, 'sekolah_asal', htmlentities( wp_strip_all_tags($_POST['sekolah_asal'])) );
    update_user_meta( $user_id, 'status_sekolah', htmlentities( wp_strip_all_tags($_POST['status_sekolah'])) );

    update_user_meta( $user_id, 'jurusan_sekolah', htmlentities( wp_strip_all_tags($_POST['jurusan_sekolah'])) );
    update_user_meta( $user_id, 'nomor_ijazah', htmlentities( wp_strip_all_tags($_POST['nomor_ijazah'])) );
    update_user_meta( $user_id, 'sumber_info', htmlentities( wp_strip_all_tags($_POST['sumber_info'])) );
    update_user_meta( $user_id, 'keberatan', htmlentities( wp_strip_all_tags($_POST['keberatan'])) );
    update_user_meta( $user_id, 'pilihan1', htmlentities( wp_strip_all_tags($_POST['pilihan1'])) );
    update_user_meta( $user_id, 'pilihan2', htmlentities( wp_strip_all_tags($_POST['pilihan2'])) );
    update_user_meta( $user_id, 'pilihan3', htmlentities( wp_strip_all_tags($_POST['pilihan3'])) );


}












?>
