05-12-2025, 03:19 AM
Kod PHP:
<?php
Tworzymy klasę rozszerzającą dla klasy głównej.
Kod PHP:
class AppClass extends Core
{
Metoda , która zostanie uruchomiona jako pierwsza po zainicjalizowaniu obiektu.
Kod PHP:
public function AppStart()
{
global $Lang;
Sprawdzamy czy użytkownik jest zalogowany na konto administratora.
Kod PHP:
if($this->AppSessionGetValue('admin_id') != "")
{
Tworzymy nagłówek strony .
Kod PHP:
$this->AppBody .= '<h1>'.$Lang['ap_a1_users_header'].'</h1>';
$this->AppBody .= '<div class="heading_row"></div>';
W pasku tytułu wpisujemy informację , która będzie określała nasze obecne położenie .
Kod PHP:
$this->AppTitle = $Lang['ap_a1_users_header'];
if($_GET['delete'] == 'yes')
{
Usunięcie użytkownika spowoduje skasowanie wszystkich jego danych . Pierwszym elementem są wszystkie jego dane z tabeli głównej .
Kod PHP:
$SqlConfig = 'DELETE FROM '.$this->DBPrefix.'user WHERE user_id = "'.$this->AppDBSecure($_GET['user_id']).'"';
if(!$this->AppDBQuery($SqlConfig))
{
$this->AppBody .= $this->AppShowError('Query error',__FILE__,__LINE__,$SqlConfig);
}
Następnie definiujemy w tablicy zapytania przeznaczone do usunięcia ich danych z innych tabel w systemie , takich jak : albumy , obrazy , przyjaciele , lubię to , inne miejsca , prywatne wiadomości , publikacje oraz komentarze .
Kod PHP:
$SqlConfigTable[] = 'DELETE FROM '.$this->DBPrefix.'album WHERE album_user_id = "'.$this->AppDBSecure($_GET['user_id']).'"';
$SqlConfigTable[] = 'DELETE FROM '.$this->DBPrefix.'album_pictures WHERE pic_user_id = "'.$this->AppDBSecure($_GET['user_id']).'"';
$SqlConfigTable[] = 'DELETE FROM '.$this->DBPrefix.'friends WHERE friend_user_id = "'.$this->AppDBSecure($_GET['user_id']).'"';
$SqlConfigTable[] = 'DELETE FROM '.$this->DBPrefix.'friends WHERE friend_friend_id = "'.$this->AppDBSecure($_GET['user_id']).'"';
$SqlConfigTable[] = 'DELETE FROM '.$this->DBPrefix.'likeit WHERE likeit_user_id = "'.$this->AppDBSecure($_GET['user_id']).'"';
$SqlConfigTable[] = 'DELETE FROM '.$this->DBPrefix.'likeit WHERE likeit_friend_id = "'.$this->AppDBSecure($_GET['user_id']).'"';
$SqlConfigTable[] = 'DELETE FROM '.$this->DBPrefix.'otherplaces WHERE place_user_id = "'.$this->AppDBSecure($_GET['user_id']).'"';
$SqlConfigTable[] = 'DELETE FROM '.$this->DBPrefix.'pm_received WHERE pm_to_user = "'.$this->AppDBSecure($_GET['user_id']).'"';
$SqlConfigTable[] = 'DELETE FROM '.$this->DBPrefix.'pm_send WHERE pm_from_user = "'.$this->AppDBSecure($_GET['user_id']).'"';
$SqlConfigTable[] = 'DELETE FROM '.$this->DBPrefix.'publication WHERE publication_user_id = "'.$this->AppDBSecure($_GET['user_id']).'"';
$SqlConfigTable[] = 'DELETE FROM '.$this->DBPrefix.'comment WHERE comm_user_id = "'.$this->AppDBSecure($_GET['user_id']).'"';
Tworzymy pętle , w której wykonujemy każde z zapytań zdefiniowanych w tablicy .
Kod PHP:
for($f=0;$f<count($SqlConfigTable);$f++)
{
if(!$this->AppDBQuery($SqlConfig))
{
$this->AppBody .= $this->AppShowError('Query error',__FILE__,__LINE__,$SqlConfig);
}
}
Informujemy użytkownika , że dana akcja zakończyła się sukcesem .
Kod PHP:
$this->AppBody .= $this->AppPrintSuccess($Lang['ap_a2_user_was_delete']);
}
Liczymy użytkowników , co pozwoli nam na podział ich na strony w przypadku większej ilości .
Kod PHP:
$SqlConfig = 'SELECT count(user_id) FROM '.$this->DBPrefix.'user WHERE user_is_firm = ""';
if(!$this->AppDBQuery($SqlConfig))
{
$this->AppBody .= $this->AppShowError('Query error',__FILE__,__LINE__,$SqlConfig);
}
$Result = $this->AppDBResult();
$Rows = $this->AppDBHowMany();
Podział z uwzględnieniem 150 użytkowników na jednej stronie .
Kod PHP:
$HowManyPagesTemp = $Result[0]['count(user_id)'] / 150;
$HowManyPagesTemp = explode('.',$HowManyPagesTemp);
$HowManyPages = $HowManyPagesTemp[0];
if($HowManyPagesTemp[1] > 0)
{
$HowManyPages++;
}
Pobieramy z adresu URL numer obecnej strony , a następnie tworzymy zmienną , która będzie użyta w zapytaniach do bazy danych jako limit danych do pobrania .
Kod PHP:
$PageSelect = $_GET['page'];
if($_GET['page'] == "")
{
$StartFrom = 0;
}
else
{
if(empty($_GET['page']) OR $_GET['page'] == 1)
{
$StartFrom = 0;
}
else
{
$_GET['page'] = $_GET['page'] - 1;
$StartFrom = 150 * $_GET['page'];
}
}
if($PageSelect == "" OR $PageSelect == 1)
{
$CurrentPage = 1;
}
else
{
$CurrentPage = $PageSelect;
}
Tworzymy miejsce zawierające łącza , dzięki którym będziemy mogli przechodzić na dowolną stronę zawierającą dane użytkownika .
Kod PHP:
if($HowManyPages > 1)
{
$this->AppBody .= '<div style="padding-left: 5px; padding-right: 5px; padding-top: 5px; padding-bottom: 5px; text-align: right;">';
$this->AppBody .= $Lang['l2_a3_page'];
for($i=1;$i<($HowManyPages+1);$i++)
{
if($CurrentPage == $i)
{
$this->AppBody .= $i;
}
else
{
$this->AppBody .= '<a href="'.$this->AppUrl.'admin.php?app=users&page='.$i.'">'.$i.'</a>';
}
if($i<$HowManyPages)
{
$this->AppBody .= ' , ';
}
}
$this->AppBody .= '</div';
}
Wybieramy podstawowe dane na temat wszystkich użytkowników naszego portalu z uwzględnieniem liczby rekordów .
Kod PHP:
$SqlConfig = 'SELECT user_id,user_lang,user_firstname,user_lastname,user_gender,user_birth_day,user_birth_month,user_birth_year,user_email,user_active,user_reg FROM '.$this->DBPrefix.'user WHERE user_is_firm = "" LIMIT '.$this->AppDBSecure($StartFrom).',150';
if(!$this->AppDBQuery($SqlConfig))
{
$this->AppBody .= $this->AppShowError('Query error',__FILE__,__LINE__,$SqlConfig);
}
$Result = $this->AppDBResult();
$Rows = $this->AppDBHowMany();
Tworzymy tabelę , w której zamieścimy dane oraz odpowiednie akcje .
Kod PHP:
$this->AppBody .= '<table cellpadding="0" cellspacing="0" border="0" width="100%">';
$this->AppBody .= '<tr>';
$this->AppBody .= '<td class="fb_header_info">'.$Lang['ap_a2_U_user_id'].'</td>';
$this->AppBody .= '<td class="fb_header_info">'.$Lang['ap_a2_U_user_lang'].'</td>';
$this->AppBody .= '<td class="fb_header_info">'.$Lang['ap_a2_U_user_firstname2'].'</td>';
$this->AppBody .= '<td class="fb_header_info">'.$Lang['ap_a2_U_user_gender'].'</td>';
$this->AppBody .= '<td class="fb_header_info">'.$Lang['ap_a2_U_user_birth_day2'].'</td>';
$this->AppBody .= '<td class="fb_header_info">'.$Lang['ap_a2_U_user_email'].'</td>';
$this->AppBody .= '<td class="fb_header_info">'.$Lang['ap_a3_user_active'].'</td>';
$this->AppBody .= '<td class="fb_header_info">'.$Lang['ap_a2_U_user_reg'].'</td>';
$this->AppBody .= '<td class="fb_header_info">'.$Lang['ap_a3_edit_user'].'</td>';
$this->AppBody .= '<td class="fb_header_info">'.$Lang['ap_a1_delete'].'</td>';
$this->AppBody .= '</tr>';
for($f=0;$f<$Rows;$f++)
{
Każdy rząd będzie miał inny kolor , tak aby można było łatwo odróżnić dane poszczególnych użytkowników .
Kod PHP:
if($RowColor == 1)
{
$TdClass = 'fb_row_1';
$RowColor = 0;
}
else
{
$TdClass = 'fb_row_2';
$RowColor = 1;
}
$this->AppBody .= '<tr>';
$this->AppBody .= '<td class="'.$TdClass.'">'.$this->AppDBUnsecure($Result[$f]['user_id']).'</td>';
$this->AppBody .= '<td class="'.$TdClass.'">'.$this->AppDBUnsecure($Result[$f]['user_lang']).'</td>';
$this->AppBody .= '<td class="'.$TdClass.'">'.$this->AppDBUnsecure($Result[$f]['user_firstname']).' '.$this->AppDBUnsecure($Result[$f]['user_lastname']).'</td>';
$this->AppBody .= '<td class="'.$TdClass.'">';
Rozróżniamy płeć danej osoby .
Kod PHP:
if($this->AppDBUnsecure($Result[$f]['user_gender']) == 'm')
{
$this->AppBody .= $Lang['ap_a2_U_men'];
}
else
{
$this->AppBody .= $Lang['ap_a2_U_women'];
}
$this->AppBody .= '</td>';
$this->AppBody .= '<td class="'.$TdClass.'">'.$this->AppDBUnsecure($Result[$f]['user_birth_day']).'-'.$this->AppDBUnsecure($Result[$f]['user_birth_month']).'-'.$this->AppDBUnsecure($Result[$f]['user_birth_year']).'</td>';
$this->AppBody .= '<td class="'.$TdClass.'">'.$this->AppDBUnsecure($Result[$f]['user_email']).'</td>';
Sprawdzamy czy dane konto jest aktywne .
Kod PHP:
if($this->AppDBUnsecure($Result[$f]['user_active']) == 'y')
{
$this->AppBody .= '<td class="'.$TdClass.'">'.$Lang['ap_a2_U_yes'].'</td>';
}
else
{
$this->AppBody .= '<td class="'.$TdClass.'" style="background-color: #600000; color: #ffffff;">'.$Lang['ap_a2_U_no'].'</td>';
}
$this->AppBody .= '<td class="'.$TdClass.'">'.date('d-m-Y H:i:s', $this->AppDBUnsecure($Result[$f]['user_reg'])).'</td>';
Defiuniujemy odpowiednie akcje dla każdej z osób .
Kod PHP:
$this->AppBody .= '<td class="'.$TdClass.'"><a href="'.$this->AppUrl.'index.php?app=showprofile&option='.$Result[$f]['user_id'].'">'.$Lang['ap_a3_edit_user'].'</a></td>';
$this->AppBody .= '<td class="'.$TdClass.'"><a href="JavaScript:DeleteInfo(\''.$this->AppUrl.'admin.php?app=users&delete=yes&user_id='.$Result[$f]['user_id'].'\',\''.$Lang['l2_a1_accept_deleting'].'\');">'.$Lang['ap_a3_delete_user'].'</a></td>';
$this->AppBody .= '</tr>';
}
$this->AppBody .= '</table>';
}
else
{
Jeżeli użytkownik nie posiada odpowiednich uprawnień , przekierowujemy go do strony głównej panelu , aby się zalogował .
Kod PHP:
header('location: '.$this->AppUrl.'admin.php');
}
}
}
?>