<?php  

include(dirname(dirname(dirname(__FILE__)))."/objects/class_connection.php");
include(dirname(dirname(dirname(__FILE__)))."/objects/class_adminprofile.php");
include(dirname(dirname(dirname(__FILE__)))."/objects/class_setting.php");
include(dirname(dirname(dirname(__FILE__)))."/objects/class_dayweek_avail.php");
include(dirname(dirname(dirname(__FILE__)))."/header.php");
$con = new cleanto_db();
$conn = $con->connect();
$objadminprofile = new cleanto_adminprofile();
$objadminprofile->conn = $conn;
$settings = new cleanto_setting();
$settings->conn = $conn;
$timeavailability= new cleanto_dayweek_avail();
$timeavailability->conn = $conn;
if(isset($_POST['updateinfo'])){
	$objadminprofile->fullname = $_POST['fullname'];
	$objadminprofile->address = $_POST['address'];
	$objadminprofile->city = $_POST['city'];
	$objadminprofile->zip = $_POST['zip'];
	$objadminprofile->state = $_POST['state'];
	$objadminprofile->country = $_POST['country'];
	$objadminprofile->phone = $_POST['phone'];
	$objadminprofile->id = $_POST['id'];
	if($objadminprofile->update_profile()){
		echo "Info Updated";
	}
	else {
		echo "Not Updated";
	}
}
elseif(isset($_POST['updateinfowithpass'])){
	$objadminprofile->fullname = $_POST['fullname'];
	$objadminprofile->address = $_POST['address'];
	$objadminprofile->city = $_POST['city'];
	$objadminprofile->zip = $_POST['zip'];
	$objadminprofile->state = $_POST['state'];
	$objadminprofile->country = $_POST['country'];
	$objadminprofile->phone = $_POST['phone'];
	$objadminprofile->id = $_POST['id'];
	$objadminprofile->password = $_POST['password'];
	if($objadminprofile->update_profile_withpass()){
		echo "Info Updated";
	}
	else {
		echo "Not Updated";
	}
}
elseif(isset($_POST['updatepass'])){
  $objadminprofile->fullname = $_POST['fullname'];
	$objadminprofile->email = $_POST['adminemail'];
	$objadminprofile->address = $_POST['address'];
	$objadminprofile->city = $_POST['city'];
	$objadminprofile->zip = $_POST['zip'];
	$objadminprofile->state = $_POST['state'];
	$objadminprofile->country = $_POST['country'];
	$objadminprofile->phone = $_POST['phone'];
	$objadminprofile->id = $_POST['id'];
	$op=$_POST['oldpassword'];
	$dp=$_POST['dboldpassword'];
	$np=$_POST['newpassword'];
	$rp=$_POST['retypepassword'];
	$operation = 1;
	if ($_POST['oldpassword'] != "") {
		if ($op != $dp) {
			
			$operation = 2;
			echo "sorry";
		} else { 
			if($np != "" && $rp != ""){
				$operation = 3;
				if ($np == $rp) { 
					$objadminprofile->password=md5($rp);
					$update=$objadminprofile->update_profile();
					if($update){
						$_SESSION['ct_adminid']=$_POST['id'];
					}
				} else{
					echo "Please Retype Correct Password...";
				}
			}else{
				if ($operation == 1) {
					$objadminprofile->password=$dp;
					$update=$objadminprofile->update_profile();
					if($update){
						$_SESSION['ct_adminid']=$_POST['id'];
					}
				}
			}
		}
	} 
}elseif(isset($_POST['check_for_option'])){
	$check_for_products  = "select * from ct_services,ct_services_method,ct_service_methods_units";
	$hh = mysqli_query($conn,$check_for_products);
	$t = $timeavailability->get_timeavailability_check();
	$last = "";
	if($settings->get_option('ct_company_address')=="" ||
		$settings->get_option('ct_company_city')=="" ||
		$settings->get_option('ct_company_state')=="" ||
		$settings->get_option('ct_company_name')=="" ||
		$settings->get_option('ct_company_email')=="" ||
		$settings->get_option('ct_company_zip_code')=="" ||
		$settings->get_option('ct_company_country')=="" ||
		mysqli_num_rows($hh)=="" ||
		mysqli_num_rows($t)==""){
		$last = "Please Fill all the Company Informations and add some Services and Addons.";
	}
	if($last != ""){
		echo $last;
	}
}else if(isset($_POST['staff_old_password_change'])){
	$op=md5($_POST['staff_old_password']);
	$dp=$_POST['staff_olddb_password'];
	$np=$_POST['staff_new_password'];
	if ($op != $dp) {
		echo "sorry";die();
	}else{
		$objadminprofile->id = $_POST['current_log_in_id'];
		$objadminprofile->password = $np;
		$objadminprofile->update_password_api();
	}
}
?>