HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: /var/www/html/shootinschool/wp-content/plugins/shootin-school-plugin/edit_email.php
<?php
function render_siab_edit_email(){
     global $wpdb;
     $id = $_GET['id'];
     $query = "SELECT * FROM ".DB_EMAILS." WHERE id = $id";
     $email = $wpdb->get_row($query);
     $notes = json_decode($email->notes);
    ?>
    <div class="wrap">
        <div class="css_loader">Loading&#8230;</div>

        <div class="alert alert-info" role="alert" style="border: 1px solid green;border-radius: 5px;">
            <h3> Update Email for <?php echo $email->title?></h3>
            <a class="add-new-h2 btn btn-success" href="admin.php?page=siab-emails"> Back to Email Management</a>
        </div>

        <form id="updateEmail">
            <div class="form-group">
                <label for="subject">Subject:</label>
                <input type="text" name="subject" class="form-control" placeholder="Enter Subject" autocomplete="off" required value='<?php echo $email->subject ? $email->subject : ""; ?>'>
            </div>
            <div class="form-group">
                <label for="emailText">Message:</label>
                <textarea id="email_template" class="form-control" name="body" required>
                    <?php echo $email->body ? $email->body : ""; ?>
                </textarea>
            </div>
            <div>
                <label for="">Keywords:</label>
                <ul>
                    <?php
                    foreach($notes as $note){
                        echo "{".$note."},";
                    }
                    ?>
                </ul>
            </div>

            <div class="form-group">
               <label for="">Choose Where This Template Apply:</label>
             <?php if ($email->notify_via_email==1){?>
                  <div class="email_checkbox">
                    <label><input type="checkbox" name="email_checkbox" value="1" checked >Send Email</label>
                  </div>
             <?php  }else{?>
                <div class="email_checkbox">
                    <label><input type="checkbox" name="email_checkbox" value="1"  >Send Email</label>
                  </div>
             <?php }?>
             <?php if ($email->notify_via_sms==1){?>
                 <div class="sms_checkbox">
                    <label><input type="checkbox" name="sms_checkbox" value="1" checked>Send SMS</label>
                 </div>
             <?php  }else{?>
                <div class="sms_checkbox">
                    <label><input type="checkbox" name="sms_checkbox" value="1" >Send SMS</label>
                 </div>
            <?php }?>

            </div>
        </form>
    </div>
    <div class="form-group">
        <button type="button" class="btn btn-primary" value="<?php echo $email->id?>" onclick="updateEmail(this)">Update</button>
    </div>

<?php }

add_action('wp_ajax_nopriv_update_email', 'update_email');
add_action('wp_ajax_update_email', 'update_email');
function update_email(){

    global $wpdb;
    parse_str($_POST['form_data'], $form_data); //This will convert the string to array
    $id = $_POST['id'];
    // $form_data = $_POST['form_data'];
    if(isset($form_data['sms_checkbox'])){
        $sms_checkbox=1;
     }
     else{
        $sms_checkbox=0;
     }

     if(isset($form_data['email_checkbox'])){
         $email_checkbox=1;
     }
     else{
        $email_checkbox=0;
     }

    $data = array('subject'=> $form_data['subject'], 'body' => $form_data['body'],'notify_via_sms'=> $sms_checkbox,'notify_via_email'=> $email_checkbox);
    $response = new stdClass();

    if( $wpdb->update(DB_EMAILS, $data, array('id' => $id)) ){
        $response->status = true;
        $response->message = "Updated successfully";
    }else{
        $response->status = false;
        $response->message = "Error while updating";
    }
    echo json_encode($response);
    die();
}