
<?php
  $Users = file($UsersDatabase);
  $Mode = $_GET['mode'];
  for($i = 0; $i < count($Users); $i = $i + 2)
  {
    if($Mode == 'NameSort')
      $Arr[] = trim($Users[$i])."\n".trim($Users[($i + 1)]);
    elseif($Mode == 'EmailSort')
      $Arr[] = trim($Users[($i+1)])."\n".trim($Users[$i]);
  }
  sort($Arr);
  if($Mode == 'NameSort')
    $Str = implode("\n", $Arr);
  elseif($Mode == 'EmailSort')
  {
    $Users = '';
    for($i = 0; $i < count($Arr); $i++)
    {
      $Pos = strpos($Arr[$i], "\n");
      $Str1 = substr($Arr[$i], 0, $Pos);
      $Str2 = substr($Arr[$i], ($Pos+1), strlen($Arr[$i])-1);
      $Str .= $Str2."\n".$Str1."\n";
    }
  }
  SaveStringInFile($UsersDatabase, $Str, 'w');
  Refresh('pollusersdata');

?>