Advertisement
Guest User

loadpatient.php

a guest
Mar 26th, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 10.51 KB | None | 0 0
  1. <?php
  2.  
  3. // allow us to use core wordpress functions
  4.  
  5. // make sure to replace this with the name of the plugin's root folder name
  6. $plugin_name = 'mmjverify_shortcode';
  7. $oldURL = dirname(__FILE__);
  8. $newURL = str_replace(DIRECTORY_SEPARATOR . 'wp-content' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $plugin_name, '', $oldURL);
  9. include($newURL . DIRECTORY_SEPARATOR . 'wp-load.php');
  10. global $wpdb;
  11.  
  12. function convert_mydate($origdate) {
  13. $find_dash = '-';
  14. $find_slash =  '/';
  15. $dash_pos = strpos($origdate, $find_dash);
  16. $slash_pos = strpos($origdate, $find_slash);
  17.  
  18. if ($dash_pos === false && $slash_pos !== false) {
  19.     $nd = (explode( $find_slash, $origdate ));
  20.    $n_month = $nd[0];
  21.     $n_day = $nd[1];
  22.     $n_year = $nd[2];
  23.     $newdate = $n_year . '-' . $n_month . '-' . $n_day;
  24. } elseif ($dash_pos !== false && $slash_pos === false) {
  25.     $nd = (explode( $find_dash, $origdate ));
  26.    $n_month = $nd[0];
  27.     $n_day = $nd[1];
  28.     $n_year = $nd[2];
  29.     $newdate = $n_year . '-' . $n_month . '-' . $n_day;
  30. }
  31. return $newdate;
  32. }
  33.  
  34. $post = (!empty($_POST)) ? true : false;
  35.  
  36. if($post)
  37. {
  38.     $editid = stripslashes($_POST['editid']);
  39.     $last_name = stripslashes($_POST['last_name']);
  40.     $dob = stripslashes($_POST['dob']);
  41.     $converted_s_dob = convert_mydate($dob);
  42.     $issue_date = stripslashes($_POST['issue_date']);
  43.     $converted_s_issue = convert_mydate($issue_date);
  44.  
  45.     $patient_count = '';
  46.     $search = '';
  47.     $error = '';
  48.    
  49.     if (empty ($editid) && empty ($last_name) && empty ($dob) && empty ($issue_date)) {
  50.         $patient_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM " . $wpdb->prefix . "mmjverify" ) );
  51.         $myrec = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "mmjverify " );
  52.         $result = (isset($myrec)) ? true : false;
  53.         if(!$result) {
  54.             $error .= "No Patients in database";
  55.             echo $error;
  56.         }
  57.         else {
  58.             $patient_list = '';
  59.             $patient_list .= 'There are '.$patient_count.' Patients in the database';
  60.             $patient_list .= '<div class="patient_table">';
  61.             $patient_list .= '<div class="head_wrapper">';
  62.             $patient_list .= '<div class="pid_head">ID</div>';
  63.             $patient_list .= '<div class="first_name_head">First Name</div>';
  64.             $patient_list .= '<div class="last_name_head">Last Name</div>';
  65.             $patient_list .= '<div class="dob_head">Birthdate</div>';
  66.             $patient_list .= '<div class="issue_date_head">Issue Date</div>';
  67.             $patient_list .= '<div class="exp_date_head">Exp Date</div>';
  68.             $patient_list .= '<div class="edit_head">Edit/Delete</div>';
  69.             $patient_list .= '</div>';
  70.             $patient_list .= '<div style="clear:both"></div>';
  71.             foreach ($myrec as $patient) {
  72.                 $editid = intval($patient->id);
  73.                 $first_name = $patient->first_name;
  74.                 $last_name = $patient->last_name;
  75.                 $dob = $patient->dob;
  76.                 $converted_dob = date("m-d-Y", strtotime($dob));
  77.                 $issue_date = $patient->issue_date;
  78.                 $converted_issue = date("m-d-Y", strtotime($issue_date));
  79.                 $exp_date = $patient->exp_date;
  80.                 $converted_exp = date("m-d-Y", strtotime($exp_date));
  81.                 $patient_list .= '<div class="row_wrapper">';
  82.                 $patient_list .= '<div class="pid_row">'.$editid.'</div>';
  83.                 $patient_list .= '<div class="first_name_row">'.$first_name.'</div>';
  84.                 $patient_list .= '<div class="last_name_row">'.$last_name.'</div>';
  85.                 $patient_list .= '<div class="dob_row">'.$converted_dob.'</div>';
  86.                 $patient_list .= '<div class="issue_date_row">'.$converted_issue.'</div>';
  87.                 $patient_list .= '<div class="exp_date_row">'.$converted_exp.'</div>';
  88.                 $patient_list .= '<div class="edit_row"><input class="edit_btn" type="button" value="Edit"><input class="del_btn" type="button" value="Delete"></div>';            
  89.                 $patient_list .= '<div style="clear:both"></div>';
  90.                 $patient_list .= '</div>';
  91.             }
  92.             $patient_list .= '</div>';
  93.             echo $patient_list;
  94.         }
  95.        
  96.     }
  97.     else {  
  98.            
  99.         if(!empty ($editid)) {
  100.             if(empty ($search)) {  
  101.             $search .= 'id = ' . '\''. $editid . '\'';
  102.             }
  103.             else {
  104.             $search .= ' AND id = ' . '\''. $editid . '\'';
  105.             }
  106.         }
  107.    
  108.         if(!empty ($last_name)) {
  109.             if(empty ($search)) {  
  110.             $search .= 'last_name = ' . '\''. $last_name . '\'';
  111.             }
  112.             else {
  113.             $search .= ' AND last_name = ' . '\''. $last_name . '\'';
  114.             }
  115.         }  
  116.        
  117.         if(!empty ($converted_s_dob)) {
  118.             if(empty ($search)) {  
  119.             $search .= 'dob = ' . '\''. $converted_s_dob . '\'';
  120.             }
  121.             else {
  122.             $search .= ' AND dob = ' . '\''. $converted_s_dob . '\'';
  123.             }
  124.         }
  125.        
  126.         if(!empty ($converted_s_issue)) {
  127.             if(empty ($search)) {  
  128.             $search .= 'issue_date = ' . '\''. $converted_s_issue . '\'';
  129.             }
  130.             else {
  131.             $search .= ' AND issue_date = ' . '\''. $converted_s_issue . '\'';
  132.             }
  133.         }
  134.         if(!empty ($search)) {
  135.             $patient_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM " . $wpdb->prefix . "mmjverify WHERE " . $search ) );
  136.             if ( $patient_count > 1 ) {  
  137.                 $myrec = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "mmjverify WHERE " . $search );
  138.             }
  139.             elseif ( $patient_count == 1 ) {
  140.                 $myrec = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "mmjverify WHERE " . $search );
  141.             }
  142.             $result = (isset($myrec)) ? true : false;
  143.             if(!$result) {
  144.                 $error .= "This Patient does not exist";
  145.             }
  146.         }
  147.    
  148.         if(!empty ($error)) {
  149.             echo '<div class="notification_error">'.$error.'</div>'; // set up error div for jQuery/Ajax
  150.         }
  151.         elseif ( $patient_count == 1 ) {  
  152.             $patientform = '';     
  153.             $patientform .= '<h4>Edit a Patient</h4>';
  154.                 $patientform .= '<form id="editpatient-form" action="">';
  155.                     $patientform .= '<div>';
  156.                         $patientform .= '<div class="label_wrap"><label class="error" for="editfirst_name">First Name</label></div>';
  157.                         $patientform .= '<div class="input_wrap"><input name="editfirst_name" type="text" id="editfirst_name" value="'.$myrec->first_name.'"/></div>';
  158.                         $patientform .= '<div style="clear:both"></div>';
  159.                     $patientform .= '</div>';
  160.                     $patientform .= '<div>';
  161.                         $patientform .= '<div class="label_wrap"><label class="error" for="editlast_name">Last Name</label></div>';
  162.                         $patientform .= '<div class="input_wrap"><input name="editlast_name" type="text" id="editlast_name" value="'.$myrec->last_name.'"/></div>';
  163.                         $patientform .= '<div style="clear:both"></div>';
  164.                     $patientform .= '</div>';  
  165.                     $mydob = $myrec->dob;
  166.                     $converted_dob = date("m-d-Y", strtotime($mydob));
  167.                     $patientform .= '<div>';
  168.                         $patientform .= '<div class="label_wrap"><label class="error" for="editdob">Birthdate (mm-dd-yyyy) </label></div>';
  169.                         $patientform .= '<div class="input_wrap"><input name="editdob" type="text" id="editdob" value="'.$converted_dob.'"/></div>';
  170.                         $patientform .= '<div style="clear:both"></div>';
  171.                     $patientform .= '</div>';  
  172.                     $myissue = $myrec->issue_date;
  173.                     $converted_issue = date("m-d-Y", strtotime($myissue));
  174.                     $patientform .= '<div>';
  175.                         $patientform .= '<div class="label_wrap"><label class="error" for="editissue_date">Issue Date (mm-dd-yyyy) </label></div>';
  176.                         $patientform .= '<div class="input_wrap"><input name="editissue_date" type="text" id="editissue_date" value="'.$converted_issue.'"/></div>';
  177.                         $patientform .= '<div style="clear:both"></div>';
  178.                     $patientform .= '</div>';  
  179.                     $myexp = $myrec->exp_date;
  180.                     $converted_exp = date("m-d-Y", strtotime($myexp));
  181.                     $patientform .= '<div>';
  182.                         $patientform .= '<div class="label_wrap"><label class="error" for="editexp_date">Exp. Date (mm-dd-yyyy) </label></div>';
  183.                         $patientform .= '<div class="input_wrap"><input name="editexp_date" type="text" id="editexp_date" value="'.$converted_exp.'"/></div>';
  184.                         $patientform .= '<div style="clear:both"></div>';
  185.                     $patientform .= '</div>';  
  186.                     $patientform .= '<div>';
  187.                         $patientform .= '<div class="label_wrap"><label class="error" for="editdr_info">Doctor\'s Information</label></div>';
  188.                         $patientform .= '<div class="input_wrap"><input name="editdr_info" type="text" id="editdr_info" value="'.$myrec->dr_info.'"/></div>';
  189.                         $patientform .= '<div style="clear:both"></div>';
  190.                         $patientform .= '<input name="editid" type="hidden" id="editid" value="'.$myrec->id.'"/>';
  191.                     $patientform .= '</div>';
  192.                 $patientform .= '<div class="button_wrap"><input type="submit" value="Save" class="button" id="editpatient-submit" /><input class="editdel_btn" type="button" value="Delete"></div>';
  193.             $patientform .= '</form>';
  194.             echo $patientform;
  195.         }
  196.         elseif ( $patient_count > 1 )
  197.         {
  198.        
  199.         $patient_list = '';
  200.             $patient_list .= 'There are '.$patient_count.' Patients that match this description';
  201.             $patient_list .= '<div class="patient_table">';
  202.             $patient_list .= '<div class="head_wrapper">';
  203.             $patient_list .= '<div class="pid_head">ID</div>';
  204.             $patient_list .= '<div class="first_name_head">First Name</div>';
  205.             $patient_list .= '<div class="last_name_head">Last Name</div>';
  206.             $patient_list .= '<div class="dob_head">Birthdate</div>';
  207.             $patient_list .= '<div class="issue_date_head">Issue Date</div>';
  208.             $patient_list .= '<div class="exp_date_head">Exp Date</div>';
  209.             $patient_list .= '<div class="edit_head">Edit/Delete</div>';
  210.             $patient_list .= '</div>';
  211.             $patient_list .= '<div style="clear:both"></div>';
  212.             foreach ($myrec as $patient) {
  213.                 $editid = intval($patient->id);
  214.                 $first_name = $patient->first_name;
  215.                 $last_name = $patient->last_name;
  216.                 $dob = $patient->dob;
  217.                 $converted_dob = date("m-d-Y", strtotime($dob));
  218.                 $issue_date = $patient->issue_date;
  219.                 $converted_issue = date("m-d-Y", strtotime($issue_date));
  220.                 $exp_date = $patient->exp_date;
  221.                 $converted_exp = date("m-d-Y", strtotime($exp_date));
  222.                 $patient_list .= '<div class="row_wrapper">';
  223.                 $patient_list .= '<div class="pid_row">'.$editid.'</div>';
  224.                 $patient_list .= '<div class="first_name_row">'.$first_name.'</div>';
  225.                 $patient_list .= '<div class="last_name_row">'.$last_name.'</div>';
  226.                 $patient_list .= '<div class="dob_row">'.$converted_dob.'</div>';
  227.                 $patient_list .= '<div class="issue_date_row">'.$converted_issue.'</div>';
  228.                 $patient_list .= '<div class="exp_date_row">'.$converted_exp.'</div>';
  229.                 $patient_list .= '<div class="edit_row"><input class="edit_btn" type="button" value="Edit"><input class="del_btn" type="button" value="Delete"></div>';            
  230.                 $patient_list .= '<div style="clear:both"></div>';
  231.                 $patient_list .= '</div>';
  232.             }
  233.             $patient_list .= '</div>';
  234.             echo $patient_list;
  235.         }
  236.     }
  237. }
  238. else {
  239. $error = "What the heck happened?";
  240. echo '<div class="notification_error">'.$error.'</div>'; // set up error div for jQuery/Ajax
  241. }
  242.  
  243. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement