@echo off

rem -- http://phpnow.org
rem -- YinzCN_at_Gmail.com

setlocal enableextensions
call Pn\config.cmd
if "%php%"=="" exit /b

if not "%1"=="" (
  call :%1 %1
  goto :eof
)

:reset_mydpwd
set /p newpwd=-^> ÖØÉè root ÃÜÂë: 
if "%newpwd%"=="" goto reset_mydpwd
echo.
set pnTmp=%SystemRoot%\Temp\Pn_%RANDOM%.%RANDOM%
echo SET PASSWORD FOR 'root'@'localhost' = PASSWORD('%newpwd%');>%pnTmp%
if exist %myd_dir%\data\%COMPUTERNAME%.pid %net% stop %myd_svc%
set myini=%CD%\%myd_dir%\my.ini
start /b %myd_dir%\bin\%myd_exe% --defaults-file="%myini%" --init-file=%pnTmp%
%myd_dir%\bin\mysqladmin.exe shutdown -uroot -p"%newpwd%"
echo  µÈ´ý MySQL ÍË³ö ...
echo.
%php% "while(@file_exists('%myd_dir%\data\%COMPUTERNAME%.pid')) usleep(50000);"
echo.>%pnTmp%
del %pnTmp% /Q
%net% start %myd_svc% || %pause%

set dzzoffice_config_dir=htdocs\core\config\config.php
SetLocal EnableDelayedExpansion
(for /f "delims=" %%a in (htdocs\core\config\config.php) do (
  set change=
  echo "%%a"|find "$_config['db']['1']['dbpw']">nul&&set change=1
  if not defined change (echo.%%a) else (
    echo $_config['db']['1']['dbpw']='%newpwd%';
  )
))>htdocs\core\config\config_1.php

del htdocs\core\config\config.php
ren htdocs\core\config\config_1.php config.php


goto end
:end
prompt