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/locations.php
<?php
// global $postNumber;
$postNumber = 1;
// global $instructor_slno;
$instructor_slno = 1;
// *************** COACHING LOCATIONS *******************
function render_siab_locations()
{
	/**
	 * Create a new table class that will extend the WP_List_Table
	 */
	class Coaching_Locations_List_Table extends WP_List_Table
	{
		/**
		 * Prepare the items for the table to process
		 *
		 * @return Void
		 */

		public function prepare_items()
		{
			$columns = $this->get_columns();
			$hidden = $this->get_hidden_columns();
			$sortable = $this->get_sortable_columns();

			$data = $this->table_data();
			usort($data, array(&$this, 'sort_data'));

			$perPage = 10;
			$currentPage = $this->get_pagenum();
			$totalItems = count($data);

			$this->set_pagination_args(
				array(
					'total_items' => $totalItems,
					'per_page' => $perPage
				)
			);

			$data = array_slice($data, (($currentPage - 1) * $perPage), $perPage);

			$this->_column_headers = array($columns, $hidden, $sortable);
			$this->items = $data;
		}

		/**
		 * Override the parent columns method. Defines the columns to use in your listing table
		 *
		 * @return Array
		 */
		public function get_columns()
		{
			$columns = array(
				'id' => 'Sl No',
				'name' => 'Name',
				'address' => 'Address',
				'phone' => 'Phone',
				'description' => 'Description',
				'working_hours' => 'Working Hours',
				'actions' => 'Actions',
			);

			return $columns;
		}

		/**
		 * Define which columns are hidden
		 *
		 * @return Array
		 */
		public function get_hidden_columns()
		{
			return array();
		}

		/**
		 * Define the sortable columns
		 *
		 * @return Array
		 */
		public function get_sortable_columns()
		{
			return array('name' => array('name', false));
		}

		/**
		 * Get the table data
		 *
		 * @return Array
		 */
		private function table_data()
		{
			global $wpdb;
			$data = $wpdb->get_results("SELECT * FROM " . DB_COACHING_LOCATIONS . " WHERE is_deleted = 0", ARRAY_A);

			return $data;
		}

		/**
		 * Define what data to show on each column of the table
		 *
		 * @param  Array $item        Data
		 * @param  String $column_name - Current column name
		 *
		 * @return Mixed
		 */

		public function column_default($item, $column_name)
		{

			switch ($column_name) {
				case 'id':
					return $item[$column_name];
				case 'name':
					if($item['platform'] =="2"){
						return $item[$column_name]." <b>(BWC)</b>";
					}else if($item['platform'] =="1"){
						return $item[$column_name]." <b>(SHOOTIN SCHOOL)</b>";
					}else if($item['platform'] =="3"){
						return $item[$column_name]. " <b>(BWC/SHOOTIN SCHOOL)</b>";
					}
				case 'address':
				case 'phone':
				case 'description':
					return $item[$column_name];
				case 'working_hours':
					$time = '';
					$id = $item['id'];
					$get_monday = date('Y-m-d', strtotime('monday this week'));
					global $wpdb;
					$CurrentWeekquery = $wpdb->get_results("SELECT *  FROM " . DB_WORKING_HOURS . " WHERE `location_id` = '$id' AND `start_date` = '$get_monday'");
		
					if ($CurrentWeekquery) {
					$data = json_decode($item[$column_name], true);
					foreach ($data as $key => $value) {
						if ($value['open']) {
							$time .= "<div class='working-hrs'><span>" . ucfirst($key) . "</span> { " . date("g:i A", strtotime($value['open'])) . " (open) - " . date("g:i A", strtotime($value['close'])) . " (close) }</div>";
						} else {
							$time .= "<div class='working-hrs'><span>" . ucfirst($key) . "</span> { closed }</div>";
						}
					}
				}
					return $time;

				default:
					return print_r($item, true);
			}
			$postNumber++;
		}

		function column_actions($item)
		{

			$actions = array(
				'edit' => sprintf('<a href="?page=add_location&action=%s&id=' . $item['id'] . '">Edit</a>', $_REQUEST['page'], 'edit', $item['id']),
				'delete' => sprintf('<a href="#"   onclick="openDeleteWarning(' . $item['id'] . ');">Delete</a>', $_REQUEST['page'], 'delete', $item['id']),
			);

			// return sprintf('%1$s %2$s',
			// 	urlencode(base64_encode($item['id'])),
			// 	$this->row_actions($actions)
			// );

			return sprintf(
				'%1$s <span style="color:silver"></span>%3$s',
				/*$1%s*/
				$item['title'],
				/*$2%s*/
				$item['id'],
				/*$3%s*/
				$this->row_actions($actions)
			);
		}

		/**
		 * Allows you to sort the data by the variables set in the $_GET
		 *
		 * @return Mixed
		 */
		private function sort_data($a, $b)
		{
			// Set defaults
			$orderby = 'directorName';
			$order = 'asc';

			// If orderby is set, use this as the sort column
			if (!empty($_GET['orderby'])) {
				$orderby = $_GET['orderby'];
			}

			// If order is set use this as the order
			if (!empty($_GET['order'])) {
				$order = $_GET['order'];
			}

			$result = strcmp($a[$orderby], $b[$orderby]);

			if ($order === 'asc') {
				return $result;
			}

			return -$result;
		}
	}

	function delete_location()
	{
		global $wpdb;
		if (isset($_GET['id'])) {
			if (!empty($_GET['id']) && ($_GET['action'] == 'delete')) {
				$val = $_GET['id'];
				$wpdb->query("UPDATE " . DB_COACHING_LOCATIONS . " SET is_deleted = 1 WHERE id='" . $val . "'");
				//$wpdb->query("Delete from " . DB_COACHING_LOCATIONS . " where id='" . $val . "'");
				$wpdb->query("Delete from " . DB_INSTRUCTORS_AVAILABILITY_SCHEDULE . " where location_id='" . $val . "'");
				$wpdb->query("Delete from " . DB_INSTRUCTORS_AVAILABILITY . " where location_id='" . $val . "'");
				$wpdb->query("Delete from " . DB_WORKING_HOURS . " where location_id='" . $val . "'");
				echo '<div class="updated"><p><strong>Coaching Location has been deleted Successfully.</strong></p></div>';
			}
		}
	}

	/**
	 * Display the list table page
	 *
	 * @return Void
	 */

	$importedListTable = new Coaching_Locations_List_Table();
	$importedListTable->prepare_items();

	?>
	<div class="modal fade" id="WarningModal" role="dialog">


		<div class="modal-dialog">
			<!-- Modal content-->
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">&times;</button>
					<!-- <h4 class="modal-title">Delete coaching location?</h4> -->
				</div>
				<div class="modal-body">

					<p>Are you sure want to delete the location ?</p>
				</div>
				<div class="modal-footer">
					<button type="button" id="ConfirmBtn" class="btn btn-primary">Yes</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">No</button>
				</div>
			</div>
		</div>
	</div>

	<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">


		<div class="modal-dialog">
			<!-- Modal content-->
			
			<div class="modal-content">
				
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">&times;</button>
					<!-- <h4 class="modal-title">Delete coaching location?</h4> -->
				</div>
				<div class="modal-body">
<label>Week Schedule</label>
					<div class="outer-container">
						<div class="container">
							<div id="week-select-calendar" style="margin-left: 25%;"></div>
							
							
							
						</div>
					</div>
					<br>
					<br>
					
					<input type="hidden" value="" id="startDate">
					<label>Schedule Date</label>&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="date" value="" id="txtDate"/>
					<br>
					<br>
					<label>Schedule Time</label>&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" id="schedulerTime" name="schedulerTime" value="" readonly onchange="Timedata(this)" data-format="hh:mm A" class="timepicker_demo ">
					<br><br>
					<small class="errvalidation" style="color:red; display: none;">&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;&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;&nbsp;&nbsp;Please fill all fields</small>
					<br><br>
					<button  class="add-new-h2 btn btn-success  send_schedule" onclick="SendCustomMail()" type="button">Send Schedule</button>
				</div>
				<div class="modal-footer">

				</div>
			</div>
		</div>
	</div>
	<div class="wrap">
		<div class="alert alert-info" role="alert">
			<h3> Coaching Locations </h3>
			<a class="add-new-h2 btn btn-success" href="admin.php?page=add_location">Add New</a>
			<!-- <button type="button" class="btn btn-success"> + Add Location </button> -->
			<!-- <button class="add-new-h2 btn btn-success send_schedule" onclick="SendCustomMail()" type="button">Send Schedule -->
			<!-- <button class="add-new-h2 btn btn-success" type="button">Send Schedule
			</button> -->
			<button type="button" class="add-new-h2 btn btn-success" id="exmbtn" >
			Send Schedule
</button>
		</div>

		<?php delete_location(); ?>
		<?php $importedListTable->display(); ?>
	</div>

	<?php
}