This script executes retrieving and displaying insertions to the user in various modes according to the parameters of GET request.
More...
|
| $mode = null |
|
| $error = null |
|
if(! $_GET||(count( $_GET)==1 &&isset( $_GET[ 'page']))) elseif(isset($_GET['personal']) && $_GET['personal']==true) elseif(isset( $_GET[ 'status']) &&$_GET[ 'status']=='waiting') elseif(isset($_GET['make']) &&isset($_GET['model'])) | else |
|
| if (session_status()===PHP_SESSION_NONE) |
|
| $records = [] |
|
| $feed_name = "Naposledy zveřejněno" |
|
| $feed_filter_declare |
|
if( $mode==="main_page" &&$error===null) if($mode==="personal" && $error===null) elseif( $mode==="admin" &&$error===null) elseif($mode==="default" && $error===null) if( $mode !=="main_page"||isset( $_GET | if [ 'page']))(( $mode==="main_page" &&$offset !=0)||$mode==="default"||(isset( $_GET[ 'page']) &&( $mode==="main_page"||$mode==="default"))) |
|
$i< 10;$i++) { if(count( $records) >=$i+1) { echo '< a href="' . "insertion.php?id=" . htmlspecialchars($records[$i]['id'], ENT_QUOTES, 'UTF-8') . '" class="insertion">';echo '< div class="insertion-img-container">';echo '< img src="' . 'avatar/' . htmlspecialchars($records[$i]['avatar_path'], ENT_QUOTES, 'UTF-8') . '">';echo '</div >';echo '< div class="insertion-info-container">';echo '< div class="insertion-name">' . htmlspecialchars( $records[ $i][ 'make'], ENT_QUOTES, 'UTF-8') . " " . htmlspecialchars( $records[ $i][ 'model'], ENT_QUOTES, 'UTF-8') . '</div >';echo '< div class="insertion-short-decription">' . htmlspecialchars( $records[ $i][ 'short_description'], ENT_QUOTES, 'UTF-8') . '</div >';echo '< div class="insertion-details">' . htmlspecialchars( $records[ $i][ 'year'], ENT_QUOTES, 'UTF-8') . ", " . htmlspecialchars( $records[ $i][ 'mileage'], ENT_QUOTES, 'UTF-8') . " km" . '</div >';echo '< div class="insertion-price">' . htmlspecialchars( $records[ $i][ 'price'], ENT_QUOTES, 'UTF-8') . " Kč" . '</div >';if( $mode==="personal") { echo '< div class="insertion-status">Status:' . htmlspecialchars( $records[ $i][ 'insertion_status'], ENT_QUOTES, 'UTF-8') . '</div >';} echo '</div >';echo '</a >';} } ?> | endif |
|
if(count( $records) > 0)(( $offset/10 - 2) >=0) if(($offset/10 - 1) >=0) | $query = $_GET |
|
| $query ['page'] = $offset/10+1 |
|
| $queryString = http_build_query($query) |
|
| $query ['page'] = isset($query['page']) ? $query['page'] + 1 : 2 |
|
| $query ['page'] = isset($query['page']) ? $query['page'] + 2 : 3 |
|
This script executes retrieving and displaying insertions to the user in various modes according to the parameters of GET request.
1) Defines the current mode of displaying the insertions. Modes are the following:
- "main_page", if GET request parameters are empty or contain the number of page to display only. In this mode, the only available filter and order of displaying the insertions is descending by the date of their posting. Only published insertions are displayed. Searchabar for the detailed search by make and model is displayed in this mode.
- "personal", if there's "personal" parameter of the value of "true" among the current GET request parametres. Displays all the existing insertions with the value of 'seller_id' column that equals to the 'user_id' in $_SESSION (all the insertions of the current user). Terminates and redirects with error, if 'user_id' isn't set in $_SESSION. In this mode, the only available filter and order of displaying the insertions is descending by the date of their posting. Also is the only mode where current status of the insertion (whether 'waiting' or 'published') is displayed.
- "admin", if there's "status" parameter of the value of "waiting" among the current GET request parametres. Checks if the user is in fact an authorized admin (first by the contents of $_SESSION, then by the value of 'admin' column by the current 'user_id' of $_SESSION), terminates and redirects with error in case of inability to provide the complete check or negative results of the check. Displays all the insertions that are currently awaiting to be confirmed to be published by the website admins. Retrieves all the insertions with the 'waiting' value of the column 'insertion_status' of the 'insertions' table. In this mode, the only available filter and order of displaying the insertions is descending by the date of their posting.
- "default", if there's 'make' and 'model' among the current GET request parameters. Displays all the 'published' insertions of the make and model that are set in GET parameters. Results can be filtered and ordered: descending by the date of their posting, descedning by the price, ascending by the price. Filtering is set by optional 'filter' and 'order' parameters of the current GET request, users can set them through the select field available above the insertions list. Changing the value of the select triggers redirect to the new insertions page with new 'filter' and 'order' parameters. Initial displayed value of the select is set according to 'filter' and 'order' parameters of the current GET request by filter_insertions.js script included at the bottom of <body>. 2) Connects to the database. 3) Retrieves the insertions according to the current mode and GET parameters. 4) Displays the retrived insertions list with minor changes of the interface according to the mode (name of the list, available options of the filter, insertions status). In case of no insertions been found for the current GET parameters, an error occuring during the communication with database or invalid values of make or model in the URL (user altering the URL), displays the message that no insertions were found or the URL is invalid. 5) In case of 1 or more insertions been found, displays page index buttons below. Insertions are displayed at maximum of 10 per page according to the 'page' parameter of the current GET request. 'page=1' displays 1st to 10th insertions of the whole insertions list that is retrieved. Among the page index buttons are links to the pages of the: second previous 10 in the list, if they exist; previous 10 in the list, if they exist; current page; next 10 in the list, if they exist; second next 10 insertions in the list, if they exist.