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/add_session.php
<?php
function add_session(){

	global $wpdb;
	$id = '';
	$data = '';

	if(isset($_GET['id'])){
		$id = $_GET['id'];
        $data =$wpdb->get_row("select * from " . DB_PACKAGE_SESSIONS . " where ID ='$id'");
	}


?>
  <div class="wrap">
		<div class="alert alert-info" role="alert" style="border: 1px solid green;border-radius: 5px;">
			<?php
			  if(isset($_GET['id'])){
			  	 echo "<h3> Edit Session </h3>";
			  }else{
                 echo "<h3> Add Session </h3>";
			  }
			?>

			<a class="add-new-h2" href="admin.php?page=siab-packages">View Session </a>

		</div>
		<style>


		.biodata{


			width: 37.4% !important;


			}.red{


				border: 1px solid red !important;


			}


		</style>


		<div id="Saveress" class="Saveress below-h2">





		</div>


		<form id="createSession" >
			<input type="hidden" name="action" value="save_session">
			<input type="hidden" name="id" value="<?php echo $data->id;?>">


			<table  class="form-table" id='links'>


				<tbody>


					<tr>


						<th >Session  Name</th>


						<td><input type="text" name="session_name" id="project-name" autocomplete="off" placeholder="Name" value="<?php echo $data->session_name;?>" class="biodata common2" required/>


						</td>


					</tr>
					<tr>


						<th >Package Group</th>


						<td><select name="category_id" required="">
							<option value="">Select Group</option>
							<?php
							global $wpdb;
							$selected ='';

							$results = $wpdb->get_results("SELECT * FROM ". DB_PACKAGE_SESSIONS ."  order by id DESC ");
							foreach ($results as $result)

	                        {
	                        	if($data->category_id==$result->id){
								  $selected = "selected";
							    }
	                        	 echo "<option value='".$result->id."' ".$selected.">".$result->name."</option>";
	                        }
							?>


						</select>


						</td>


					</tr>





					<tr>


						<th > Credit Unlimited</th>


						<td>
							<input type="radio" name="credit_type" value="1" <?php if($data->credit_type == 1){ echo"checked"; }?> onclick="CreditType(this)"> Yes<br>
							<input type="radio" name="credit_type" value="0" <?php if($data->credit_type == 1){ echo"checked"; }else{ echo"checked";} ?> onclick="CreditType(this)"> No<br>

							<input type="text"  name="credit" <?php if($data->credit_type == 1){?> style="display: none;"; <?php }?>  id="credit_no" autocomplete="off" placeholder="Credit" value="<?php echo $data->credit;?>"   class="biodata common2" required/>


						</td>


					</tr>
					<tr>


						<th > Price</th>


						<td>

							<input type="text" name="price"  id="floor-name" autocomplete="off" placeholder="Price" value="<?php echo $data->price;?>"   class="biodata common2" required/>


						</td>


					</tr>
					<tr>


						<th > Min-capacity </th>


						<td><input type="text" name="min_capacity"  id="floor-name" autocomplete="off" placeholder="Min-capacity" value="<?php echo $data->min_capacity;?>"   class="biodata common2" required/>


						</td>


					</tr><tr>


						<th > Max-capacity </th>


						<td><input type="text" name="max_capacity"  id="floor-name" autocomplete="off" placeholder="Max-capacity"  value="<?php echo $data->max_capacity;?>"   class="biodata common2" required/>


						</td>


					</tr>
					<tr>


						<th > Description</th>


						<td>
							<textarea name="description" id="floor-name" autocomplete="off" placeholder="Description"  class="biodata common2" ><?php echo $data->description;?></textarea>


						</td>


					</tr>




				</tbody>


			</table>


			<p class="submit">


				<input type="button" name="submitm"  value="Save Changes "  id="" onclick="SaveSession()" class="button button-primary"/>


			</p>





		</form>

	</div>
<?php
}
add_action( 'wp_ajax_nopriv_save_group', 'save_session' );
add_action( 'wp_ajax_save_session', 'save_session' );
function save_session() {
    global $wpdb;

	$args=array(

       "session_name" =>$_POST['session_name'],
       "price" =>$_POST['price'],
       "min_capacity" =>$_POST['min_capacity'],
       "max_capacity" =>$_POST['max_capacity'],
       "credit_type" =>$_POST['credit_type'],
       "credit" =>$_POST['credit'],
       "description" =>$_POST['description'],
       "category_id" =>$_POST['category_id'],
      );

    if($_POST['id']){

    	$where=array("id" => $_POST['id']);
    	$sql = $wpdb->update(DB_PACKAGE_SESSIONS, $args, $where);

        $statusArr = array("status" => TRUE,"type" =>1 ,"message" => "You have successfully Updated");
        die( json_encode($statusArr));


    }else{

		$sql = $wpdb->insert($table_name, $args);
		if ( $sql) {
        	$statusArr = array("status" => TRUE,"type" =>0 , "message" => "You have successfully Added");
           die( json_encode($statusArr));
        }else{
        	$statusArr = array("status" => False, "message" => "You have successfully submitted your details!");
        	die( $wpdb->last_query);
        }

        $statusArr = array("status" => TRUE,"type" =>0 , "message" => "You have successfully Added");
         die( json_encode($statusArr));

    }


}

?>