@ECHO OFF
::MODE CON: COLS=65 LINES=35
color 5e
@echo off
:: BatchGotAdmin (Run as Admin code starts)
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
    pushd "%CD%"
    CD /D "%~dp0"
:: BatchGotAdmin (Run as Admin code ends)
ECHO]
ECHO Upgrade Started at %time% on %date% on workstation %computername% on %userprofile%\Desktop

ECHO ..................................................
ECHO Updating CAS Server Version 4.5 Version 1.3.2 , Please Wait ..... 
ECHO ..................................................
ECHO]
COLOR 5E
TIMEOUT /T 5 /NOBREAK
: Name of the database user with rights to all tables
set dbuser=root

:: Password for the database user
set dbpass=root

:: Error log path
set mysqlexe="C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin\mysql.exe"


set filepath=.\lib\Script.sql

IF EXIST C:\CCTNSApplication (GOTO NOWINDIR) ELSE (GOTO END)

:NOWINDIR
xcopy ".\lib\pdf_reports.jar" "C:\CCTNSApplication\CCTNSApplication\lib\" /S /Y
xcopy ".\lib\CctnsReports.jar" "C:\CCTNSApplication\CCTNSApplication\lib\" /S /Y
xcopy ".\lib\CCTNS_Commons.jar" "C:\CCTNSApplication\CCTNSApplication\lib\" /S /Y
xcopy ".\lib\CCTNS_Offline_Application.jar" "C:\CCTNSApplication\CCTNSApplication\" /S /Y

%mysqlexe% --user=%dbuser% --password=%dbpass% -f  <  %filepath%
ECHO]
ECHO :::::::::::::::::"Script Executed Successfully":::::::::::::::::::::
ECHO]


ECHO]
Echo ::::The Below Issues Fixed in CAS 4.5 Offline Patch Version 1.3.2:::::::::::::::
ECHO]
Echo Offline fixed issues and Customization-:  
ECHO]
Echo 1.	IIF1 Act Section Major Head & Miner Head marked as Mandatory 
Echo 2.	Arrest Memo Print issue for uploaded photo has been resolved 
Echo 3.	Act Section Option Added on bail Bond Security Option.
Echo 4.	Major Head Minor Head Master Added for Some Sections 



ECHO]
Echo ::::::::::Please check Version details in CAS login Page after Updating Patch::::::::
ECHO]
Echo Please read above changes in latest Patch and press enter to continue backup....
Pause

Echo ::::::::::Now Starting Backup Task ,Please wait ::::::::
TIMEOUT /T 5 /NOBREAK
call .\CCTNS_UTILITY\Setup.bat
pause

:END
ECHO ::::::Server Installation directory is missing, Please run at Server system:::::

