Files
BE_IBL/application/controllers/tools/Xcopy-new-sipe.php
2026-04-15 15:23:57 +07:00

352 lines
20 KiB
PHP

<?php
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
class Xcopy extends MY_Controller
{
function __construct() {
parent::__construct();
}
function log() {
$xdb = $this->load->database("onedev",true);
$pwd = $xdb->password;
$temp_file = tempnam(sys_get_temp_dir(), '-log-db') . ".sql";
if ( file_exists($temp_file) ) unlink($temp_file);
$cmd = "mysqldump --triggers --routines --no-data -u root -p$pwd one_log > $temp_file";
exec($cmd);
if (file_exists($temp_file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($temp_file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($temp_file));
readfile($temp_file);
unlink($temp_file);
exit;
}
}
function update($mcuCode) {
$sql = "update mcu_offline_prepare set McuOfflinePrepareIsDownloaded = 'Y'
where McuOfflinePrepareCode = ?";
$query = $this->db->query($sql,array($mcuCode));
if (! $query) {
echo "ERR| MCU Code : $mcuCode is not found !";
echo $this->db->error()->message;
exit;
}
echo "OK |MCU Offline $mcuCode sudah ter download !";
}
function info($branchCode,$mcuCode) {
$sql = "select * from m_branch where M_BranchIsActive = 'Y' and M_BranchCode = ? and M_BranchIsDefault = 'Y'";
$query = $this->db->query($sql,array($branchCode));
if (! $query) {
echo "ERR|$branchCode is not the default branch !";
echo $this->db->error()->message;
exit;
}
$rows = $query->result_array();
if (count($rows) == 0) {
echo "ERR|$branchCode is not the default branch !";
echo $this->db->error()->message;
exit;
}
$branchName = $rows[0]["M_BranchName"];
$sql = "select M_CompanyName, McuOfflinePrepareStartDate, McuOfflinePrepareEndDate , McuOfflinePrepareIsDownloaded
from mcu_offline_prepare join m_company on McuOfflinePrepareM_CompanyID = M_CompanyID
where McuOfflinePrepareCode = ? and McuOfflinePrepareIsActive = 'Y'";
$query = $this->db->query($sql, array($mcuCode));
if (! $query) {
echo "ERR|Kode MCU $mcuCode tidak ada";
echo $this->db->error()->message;
exit;
}
$rows = $query->result_array();
if (count($rows) == 0) {
echo "ERR|Kode MCU $mcuCode tidak ada";
exit;
}
if ( $rows[0]["McuOfflinePrepareIsDownloaded"] == "Y" ) {
echo "ERR|Kode MCU $mcuCode sudah di download.";
exit;
}
$startDate = $rows[0]["McuOfflinePrepareStartDate"];
$endDate = $rows[0]["McuOfflinePrepareEndDate"];
$companyName = $rows[0]["M_CompanyName"];
echo "OK|Cabang\t\t: $branchName\nKode MCU\t: $mcuCode\nCompany\t\t: $companyName\nStart\t\t: $startDate\nEnd\t\t: $endDate";
}
function db($mcuCode) {
$xdb = $this->load->database("onedev",true);
$pwd = $xdb->password;
$temp_c = tempnam(sys_get_temp_dir(), 'temp_c') . ".sql";
if ( file_exists($temp_c) ) unlink($temp_c);
$partials = ['address_loc','g_moustatuslog','m_doctor','m_doctoraddress','m_doctorpj','m_doctorso','m_patient','m_patientaddress','mcu_offline_prepare','ss_price_mou','t_packet','t_packetdetail','t_price','t_priceaddon','t_priceref','t_profile','t_profiledetail','ss_price_mou_px','m_mou','m_company'];
$sql = "select * from mcu_offline_prepare where McuOfflinePrepareCode=?";
$qry = $this->db->query($sql, array($mcuCode));
if (! $qry ) {
echo "ERR : No MCU Offline Prepare $mcuCode \n";
exit;
}
$rows = $qry->result_array();
if ( count($rows) > 0 ) {
$r = $rows[0];
$companyID = $r["McuOfflinePrepareM_CompanyID"];
$defaultMouID = $r["McuOfflinePrepareM_MouDefaultID"];
$s_doctor = "0";
$doctors = json_decode($r["McuOfflinePrepareDoctors"],true);
foreach($doctors as $d) {
$s_doctor .= "," . $d["id"];
}
$s_mou = "0";
$mous = json_decode($r["McuOfflinePrepareMous"],true);
foreach($mous as $m) {
$s_mou .= "," . $m["id"];
}
$mcuOfflineID = $r["McuOfflinePrepareID"];
$sql = "select T_OrderHeaderM_PatientID as id from t_orderheader
where T_OrderHeaderIsActive ='Y' and T_OrderHeaderM_CompanyID = ?
order by T_OrderHeaderM_PatientID";
$qry = $this->db->query($sql, array($companyID) );
$s_patient = "0";
$s_patientMaxID = 0;
if ($qry) {
$rows = $qry->result_array();
foreach($rows as $r) {
$s_patient .= "," . $r["id"];
$s_patientMaxID = $r["id"];
}
}
$s_packet = "0";
$sql = "select distinct T_PacketID as id from t_packet where T_PacketIsActive = 'Y' and T_PacketM_MouID in ($s_mou) ";
$qry = $this->db->query($sql );
if ($qry) {
$rows = $qry->result_array();
foreach($rows as $r) {
$s_packet .= "," . $r["id"];
}
}
$s_price= "0";
$sql = "select distinct T_PriceID as id from t_price where T_PriceIsActive = 'Y' and T_PriceM_MouID in ($s_mou) ";
$qry = $this->db->query($sql );
if ($qry) {
$rows = $qry->result_array();
foreach($rows as $r) {
$s_price .= "," . $r["id"];
}
}
} else {
echo "ERR : No MCU Offline Prepare $mcuCode \n";
exit;
}
// add routines
$cmd = "mysqldump --skip-triggers --routines -n -t -d -u root -p$pwd one >> $temp_c";
exec($cmd);
foreach($partials as $p) {
switch($p) {
case "address_loc":
$where = " Address_LocM_PatientID in ( $s_patient ) ";
break;
case "g_moustatuslog" :
$where = " G_MouStatusLogM_MouID in ( $s_mou ) ";
break;
case "m_doctor" :
$where = " M_DoctorID in ( $s_doctor ) ";
break;
case "m_doctoraddress" :
$where = " M_DoctorAddressM_DoctorID in ($s_doctor)";
break;
case "m_doctorpj":
$where = "M_DoctorPjM_DoctorID in ( $s_doctor)";
break;
case "m_doctorso":
$where = "M_DoctorSoM_DoctorID in ($s_doctor) ";
break;
case "m_patient":
$where = "M_PatientID in ($s_patient)";
break;
case "m_patientaddress":
$where = "M_PatientAddressM_PatientID in ($s_patient)";
break;
case "mcu_offline_prepare":
$where = "McuOfflinePrepareID = $mcuOfflineID";
break;
case "m_mou":
$where = "M_MouID in ($s_mou)";
break;
case "m_company":
$where = "M_CompanyID in ($companyID)";
break;
case "ss_price_mou":
$where = "Ss_PriceMouM_MouID in ($s_mou)";
break;
case "t_packet":
$where = "T_PacketM_MouID in ($s_mou)";
break;
case "t_packetdetail":
$where = "T_PacketDetailT_PacketID in ($s_packet)";
break;
case "t_price":
$where = "T_PriceM_MouID in ($s_mou)";
break;
case "t_priceaddon":
$where = "T_PriceAddonT_PriceID in ($s_price)";
break;
case "t_priceref":
$where = "T_PriceRefT_PriceID in ($s_price)";
break;
case "ss_price_mou_px":
$where = "Ss_PriceMouPxM_MouID in ($s_mou)";
break;
}
if ($where == "" ) {
$cmd = "mysqldump --triggers -u root -p$pwd one $p >> $temp_c";
} else {
$cmd = "mysqldump --triggers -u root -p$pwd -w \"$where\" one $p >> $temp_c";
}
exec($cmd);
}
$tables_a ="conf_clinic conf_default conf_refinternal conf_systems documentation_group documentation_group_detail fisik_templateresult fo_verificationslabel fo_verificationtype group_result group_resultdetail helper_nattests jpa_test lcprep_adekuasi lcprep_interpretasi lcprep_interpretasigroup lcprep_interpretasisubgroup lcprep_kategoriumum log_type m_advice_fisik m_agingtype m_almari m_bank_account m_branch m_city m_companybusiness m_companystaffposition m_companytype m_courier m_courier_area m_courierstatusreceive m_dayofweek m_delivery m_deliverytype m_dflt_allergy m_dflt_chestabdomen m_dflt_drugconsumption m_dflt_eyes m_dflt_generalcondition m_dflt_lifestyle m_dflt_medicalhistory m_dflt_nerve m_dflt_tht m_dflt_tooth m_dflt_vitalsign m_dflt_vitalsign_cbx m_difference m_district m_eksposi m_emailconfig m_idtype m_instrumentassay m_instrumentconvert m_instrumentmethode m_itemadditional m_itemadditionaltest m_k3_allergy m_k3_chestabdomen m_k3_drugconsumption m_k3_eyes m_k3_generalcondition m_k3_lifestyle m_k3_medicalhistory m_k3_nerve m_k3_tht m_k3_tooth m_k3_vitalsign m_k3_vitalsign_cbx m_k3_workplace_accident m_k3_workplace_hazards m_kelurahan m_labreference m_lang m_mcunonlab m_methode_priority m_moutype m_no_form m_nonsample m_omzettype m_papsmearbahan m_papsmearcategory m_papsmearcheck m_paymenttype m_position m_province m_rack m_religion m_samplingtime m_satellite m_schedule m_schedulegroup m_schedulegrouptest m_sex m_specialist m_staff m_status m_statusdetail m_statusref m_statusreference m_statussample m_subarea m_supplies m_template_msg m_time m_title m_user m_usergroup m_value m_vendorsample map_word map_word_lang mcu_reporttemplate mcu_reporttemplatedetail nat_advice nat_advice_abnormal nat_advice_fisik nat_bahan nat_bank nat_cito nat_companylevel nat_delta_check nat_delta_type nat_flag nat_group nat_hierarchy nat_instrument nat_jpa nat_jpadetail nat_jpagroup nat_lang nat_mcunormalnolab nat_methode nat_multirule nat_multirule_detail nat_normalvalue nat_normalvaluelang nat_normalvaluetype nat_position nat_requirement nat_requirementposition nat_sampletype nat_sex nat_staff nat_subgroup nat_subsubgroup nat_tat_group nat_tat_item nat_test nat_testlang nat_testone nat_testrequirement nat_testtype nat_trend_analysis nat_unit nat_unitlang noreg_prefix number_map r_inputtype r_report r_reportdetail r_reportgroup result_handlingdifftime s_menu s_numbering s_privilege s_regional so_template so_templatedetail so_templatelabel so_templatevalue so_testtemplate sys_kapus t_addon t_antibiotic t_bacteria t_bahan t_favorite t_instrument t_instrument_used t_nonlab t_resulttemplate t_sampleimg t_samplestation t_sampletype t_specimenlocal t_test t_test_tat t_testcalculation t_testcalculation_detail t_testconclusion t_testtype t_worklist t_worklistdetail t_worklistdetailv2 usergroup_report vw_medical_history_left_right t_sampling_queue_status " ;
$cmd = "mysqldump --triggers -u root -p$pwd one $tables_a >> $temp_c";
exec($cmd);
$tables_c = "courier_adhoc cr_order debug f_bill f_bill_detail f_bill_payment f_bill_payment_detail f_dp_labreference f_payment f_payment_kasir f_payment_kasir_detail f_payment_orderheader f_payment_test f_paymentdetail f_returcharge fo_status fo_verificationsvalue helper_bahan helper_order helper_sst helper_sstcall incoming_ref incoming_ref_child incoming_ref_detail itf_raw itf_result last_sampling_so_status last_status last_statusgroup last_statuspayment last_statuspx last_statussample log_other_fna log_other_fnadetails log_other_lcprep log_other_lcprepadekuasi log_other_lcprepdetails log_other_lcprepinterpretasi log_other_lcprepkategoriumum log_other_papsmear log_other_papsmearbahan log_other_papsmearcategory log_other_papsmearcheck log_other_papsmeardetails log_other_papsmearmaturasi management_courier mcu_agreement mcu_agreement_customer mcu_agreement_facility mcu_agreement_formula mcu_agreement_implementation mcu_agreement_marketing mcu_agreement_notes mcu_agreement_price mcu_agreement_promise mcu_agreement_result_type mcu_agreement_scopework mcu_agreement_send_result mcu_agreementtype mcu_download mcu_patient mcu_preregister mcu_preregister_details mcu_preregister_patients mcu_preregister_tests mcu_resume mcu_resumedetails mcu_resumeother mcu_screening order_attr order_delivery order_log order_px order_px_log other_cytologi other_cytologidetails other_fna other_fnadetails other_lcprep other_lcprepadekuasi other_lcprepdetails other_lcprepinterpretasi other_lcprepkategoriumum other_mikro other_mikrodetails other_papsmear other_papsmearbahan other_papsmearcategory other_papsmearcheck other_papsmeardetails other_papsmearmaturasi pre_analytic result_courier result_couriercominghome result_couriercominghome_details result_courierspk result_courierspk_detail result_courierspk_detail_step_by_step result_email result_frontoffice result_frontoffice_by_step result_handover result_handoveremail result_handoveremail_log result_handoveremail_step result_handoverpatient result_handoverpatient_log result_office result_processtooffice result_processtooffice_log result_receive result_sendcourier result_sendcourier_by_step result_sendemail result_sendemail_by_step result_verification_by_step result_verifications result_verifications_value result_wa sample_by_step sample_so_by_step sampling_note_station sampling_note_station_by_save snap_doctor_fee so_imageupload so_resultentry so_resultentry_fisik_umum so_resultentry_last_status so_resultentrydetail so_resultentrydetail_other so_walklettercourier so_walklettercourierdetail so_walkletterresult so_walkletterresultdetail ss_expertisi ss_mou_profile ss_no_promise ss_no_promise_mou ss_piutang ss_piutang_packet ss_piutang_payment ss_piutang_test ss_piutang_test_backup ss_price_mou_del ss_price_mou_v2 ss_tat_v2 ss_tat_v2_nonlab ss_tat_v2b ss_tat_v2c ssr_mr01 ssr_mr03 ssr_mr04 ssr_mr05 ssr_mr05_piutang ssr_mr07 ssr_mr09 ssr_mr11 summary_samplestorage sys_f_kapus sys_f_kapus_sum ";
$tables_c2 = "t_barcodelab t_email_nonlab t_order_calc t_orderdelivery t_orderdeliverynote t_orderdetail t_orderdetail_daily t_orderdetailaddon t_orderdetaillang t_orderheader t_orderheader_daily t_orderheaderaddon t_orderheaderuser t_ordermessage t_orderpromise t_orderreq t_ordersample t_ordersampleaddon t_ordersamplereq t_ordersupplies t_ordertx t_paymentdaily t_paymentdetail_daily t_receiverefacceptcourier t_receiverefacceptcourierdetail t_receiverefacceptcourierdp t_receiverefdistributcourier t_receiverefdistributcourierdetail t_receivereferencedelivery t_receivereferencedeliverydetail t_receivereferenceheader t_receivereferencepatient t_receivereferencetest t_ref_deliveryorder t_ref_deliveryorder_child t_ref_deliveryorder_detail t_resultinstrument t_samplestorage t_samplestorage_detail t_samplestoragedestroy t_samplestoragedestroy_detail t_samplestoragedestroy_detailnonsample t_samplestorageempty t_samplestorageemptydetail t_samplestorageout t_samplestorageout_detail t_sampling_queue_by_action t_sampling_queue_last_status t_sampling_queue_last_status_so t_samplingso t_samplingso_film t_samplingso_form t_samplingso_requirement t_worklist_confirm t_worklist_ref_confirm t_worklist_ref_confirmdetail tx_branch_status tx_mou_release xfer_internal xfer_internaldetail fo_verification_delivery fo_verification_delivery_add ";
$cmd = "mysqldump --triggers --no-data -u root -p$pwd one $tables_c $tables_c2 >> $temp_c";
exec($cmd);
// add maxID for m_kelurahan, m_district , m_city , m_province
$sql = "select max(M_PatientAddressID) mID from m_patientaddress
where M_PatientAddressM_PatientID in ( $s_patient )";
$qry = $this->db->query($sql);
$max_M_PatientAddressID= 0;
if ($qry) {
$row = $qry->row();
if (isset($row)) $max_M_PatientAddressID = $row->mID;
}
$sql = "select max(M_KelurahanID) mID from m_kelurahan where M_KelurahanIsActive = 'Y'";
$qry = $this->db->query($sql);
$maxKelurahanID = 0;
if ($qry) {
$row = $qry->row();
if (isset($row)) $maxKelurahanID = $row->mID;
}
$sql = "select max(M_DistrictID) mID from m_district where M_DistrictIsActive = 'Y'";
$qry = $this->db->query($sql);
$maxDistrictID = 0;
if ($qry) {
$row = $qry->row();
if (isset($row)) $maxDistrictID = $row->mID;
}
$sql = "select max(M_CityID) mID from m_city where M_CityIsActive = 'Y'";
$qry = $this->db->query($sql);
$maxCityID = 0;
if ($qry) {
$row = $qry->row();
if (isset($row)) $maxCityID=$row->mID;
}
$sql = "select max(M_ProvinceID) mID from m_province where M_ProvinceIsActive = 'Y'";
$qry = $this->db->query($sql);
$maxProvinceID = 0;
if ($qry) {
$row = $qry->row();
if (isset($row)) $maxProvinceID = $row->mID;
}
$add_max =<<<EOF
drop table if exists last_master_id;
create table last_master_id (
id int not null auto_increment primary key,
M_PatientID int,
M_PatientAddressID int,
M_KelurahanID int,
M_DistrictID int,
M_CityID int,
M_ProvinceID int
);
insert into last_master_id values ( NULL , $s_patientMaxID, $max_M_PatientAddressID, $maxKelurahanID, $maxDistrictID,
$maxCityID, $maxProvinceID);
update m_company set M_CompanyIsDefault = 'Y' where M_CompanyID = $companyID;
update m_mou set M_MouIsDefault = 'Y' where M_MouID = $defaultMouID;
update mcu_offline_prepare set McuOfflinePrepareIsDownloaded='Y' where McuOfflinePrepareID = $mcuOfflineID;
EOF
;
file_put_contents($temp_c, $add_max, FILE_APPEND);
$fn_lookup_external =<<<EOF
delimiter ;;
drop function if exists fn_lookup_external;;
CREATE DEFINER=`root`@`localhost` FUNCTION `fn_lookup_external`(`pNo` varchar(32), `pType` varchar(1)) RETURNS varchar(32) CHARSET latin1
READS SQL DATA
begin
if pType = 'L' then
return pNo;
end if;
end;;
delimiter ;
EOF
;
file_put_contents($temp_c, $fn_lookup_external , FILE_APPEND);
$update_s_numbering =<<<EOF
update s_numbering set
S_NumberingPrefix = '', S_NumberingSufix = '',
S_NumberingDigit=2, S_NumberingCounter=1 where S_NumberingType = 'L';
EOF
;
file_put_contents($temp_c, $update_s_numbering, FILE_APPEND);
$cmd = "gzip $temp_c";
exec($cmd);
$temp_c .= ".gz";
if (file_exists($temp_c)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($temp_c).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($temp_c));
readfile($temp_c);
unlink($temp_c);
exit;
}
}
function app() {
$temp_file = tempnam(sys_get_temp_dir(), 'x-copy-tar') . "tar.gz";
if ( file_exists($temp_file) ) unlink($temp_file);
$cmd="tar --exclude=database.php --exclude-vcs -zcf $temp_file -C /home/one/project/one one-api one-ui -C /home/one/project/birt one";
exec($cmd);
if (file_exists($temp_file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($temp_file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($temp_file));
readfile($temp_file);
unlink($temp_file);
exit;
}
}
}