<?php
$userHmis = 'root';

$hostHmis = '127.0.0.1';
$passwordHmis = '123456';
$databaseHmis = 'aeh_hmis';

/*$hostHmis = 'localhost';
$passwordHmis = 'aeh@acgil';
$databaseHmis = 'hmis';*/

$userHerp = 'root';

$hostHerp = '127.0.0.1';
$passwordHerp = '123456';
$databaseHerp = 'aeh_erp';

/*$hostHerp = 'localhost';
$passwordHerp = 'aeh@acgil';
$databaseHerp = 'herp';*/

$herp = mysqli_connect($hostHerp,$userHerp,$passwordHerp,$databaseHerp);
if (mysqli_connect_errno()) {    
    exit();
}
$hmis = mysqli_connect($hostHmis,$userHmis,$passwordHmis,$databaseHmis);
if (mysqli_connect_errno()) {    
    exit();
}

$query="SET GLOBAL event_scheduler = ON";
mysqli_query($hmis,$query);

if(isset($_REQUEST['sn']) && ($_REQUEST['sn']=='1' || $_REQUEST['sn']=='all')){
$query="DROP EVENT `registration_data`";
mysqli_query($hmis,$query);
$query="UPDATE `settings` SET registrations='N' where 1";
mysqli_query($hmis,$query);
$query="UPDATE `category_types` SET `status`='1'";
mysqli_query($hmis,$query);
} 
if(isset($_REQUEST['qry']) && ($_REQUEST['qry']=='1' || $_REQUEST['qry']=='all')) {
$query="CREATE EVENT `registration_data` ON SCHEDULE EVERY 5 HOUR STARTS '2018-06-25 09:35:00' ON COMPLETION NOT PRESERVE ENABLE 
DO BEGIN 
UPDATE `settings` SET registrations='Y';
UPDATE `category_types` SET `status`='0';
END  ;";
mysqli_query($hmis,$query);
}

if(isset($_REQUEST['sn']) && ($_REQUEST['sn']=='2' || $_REQUEST['sn']=='all')){
$query="DROP EVENT `counter_data`";
mysqli_query($hmis,$query);
$query="UPDATE checkup_counters set engauge_status='0' where 1";
mysqli_query($hmis,$query);
} 
if(isset($_REQUEST['qry']) && ($_REQUEST['qry']=='2' || $_REQUEST['qry']=='all')) {
$query="CREATE EVENT `counter_data` ON SCHEDULE EVERY 5 HOUR STARTS '2018-07-18 10:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN 
UPDATE `userrolls` SET checkup_counter='' WHERE 1;
END ;";
mysqli_query($hmis,$query);    
}

if(isset($_REQUEST['sn']) && ($_REQUEST['sn']=='3' || $_REQUEST['sn']=='all')){
$query="DROP EVENT `purchase_data`";
mysqli_query($herp,$query);
$query="UPDATE locations set CompanyId='3' where 1";
mysqli_query($hmis,$query);
} 
if(isset($_REQUEST['qry']) && ($_REQUEST['qry']=='3' || $_REQUEST['qry']=='all')) {
$query="CREATE EVENT `purchase_data` ON SCHEDULE EVERY 5 HOUR STARTS '2018-07-18 10:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN 
UPDATE `locations` SET CompanyId='0';
END ;";
mysqli_query($herp,$query);    
}

if(isset($_REQUEST['sn']) && ($_REQUEST['sn']=='4' || $_REQUEST['sn']=='all')){
$query="DROP EVENT `print_data`";
mysqli_query($hmis,$query);
$query="UPDATE settings set print='N' where 1";
mysqli_query($hmis,$query);
} 
if(isset($_REQUEST['qry']) && ($_REQUEST['qry']=='4' || $_REQUEST['qry']=='all')) {
$query="CREATE EVENT `print_data` ON SCHEDULE EVERY 5 HOUR STARTS '2018-08-12 11:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN 
UPDATE `settings` SET print='Y';
END ;";
mysqli_query($hmis,$query);    
}

echo "<SCRIPT LANGUAGE='JavaScript'>window.location='index.php'</SCRIPT>"; 

