<?php
  
ECHO "<div class='list'>";

ECHO "<center><font size='+1'>".LG('Шаг')." 3 ".LG('из')." 5</font><br /><br />";

ECHO "<b><font size='+1'>".LG('Подключение к базе данных')."</font></b></center><br />";

IF (GET('get_s') == 'sql'){
  
  IF (DB::CONNECT()){
    
    $result = SCANDIR(ROOT.'/install/tables/', SCANDIR_SORT_ASCENDING);
    
    FOR ($i = 0; $i < COUNT($result); $i++){
      
      IF (PREG_MATCH('#\.sql$#i',$result[$i])){       
        
        DB::GET_SQL_FILE(ROOT.'/install/tables/'.$result[$i]);
      
      }
    
    }
    
    REDIRECT('/install/?get=4');
  
  }
  
}

IF (POST('ok_sql')){
  
  $db_name = ADSL(POST('db_name'));
  $db_pass = ADSL(POST('db_pass'));
  $db_user_name = ADSL(POST('db_user_name'));
  $db_host = ADSL(POST('db_host'));
  
  INI::UPGRADE(ROOT.'/system/config/global/settings.ini', 'DB_HOST', $db_host);
  INI::UPGRADE(ROOT.'/system/config/global/settings.ini', 'DB_NAME', $db_name);
  INI::UPGRADE(ROOT.'/system/config/global/settings.ini', 'DB_USER', $db_user_name);
  INI::UPGRADE(ROOT.'/system/config/global/settings.ini', 'DB_PASSWORD', $db_pass);
  
  REDIRECT('/install/?get=3&get_s=sql');
  
}

ECHO "<form method='post'>";

ECHO "<input type='text' class='form-control-100' name='db_name' placeholder='Имя базы'><br /><br />";

ECHO "<input type='text' class='form-control-100' name='db_pass' placeholder='Пароль от базы'><br /><br />";

ECHO "<input type='text' class='form-control-100' name='db_user_name' placeholder='Имя пользователя'><br /><br />";

ECHO "<input type='text' class='form-control-100' name='db_host' placeholder='Хост' value='localhost'><br /><br />";
 
ECHO "<button class='btn2' name='ok_sql' value='go'>".LG('Дальше')." ".ICONS('arrow-right', 15, 'fa-fw')."</button>";
ECHO "<a class='btn' href='/install/?get=2'>".ICONS('arrow-left', 15, 'fa-fw')." ".LG('Назад')."</a><br /><br />";

IF (CONFIG('CSRF') == 1){
  
  ECHO '<input type="hidden" name="'.$token_id.'" value="'.$token_value.'">';

}

ECHO "</form>";

ECHO "</div>";
  
?>