jováhagyó oldal v0.1
This commit is contained in:
		
							parent
							
								
									24ce86c8f3
								
							
						
					
					
						commit
						445a03e811
					
				
							
								
								
									
										257
									
								
								approval.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										257
									
								
								approval.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,257 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					// munkamenet bekapcsolása, ez minden előtt kell legyen
 | 
				
			||||||
 | 
					session_start();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// belépés ellenőrzése
 | 
				
			||||||
 | 
					//   jelszó hash generálás: echo password_hash('P@ssw0rd', PASSWORD_DEFAULT);
 | 
				
			||||||
 | 
					define('HASHED_PASSWORD', '$2y$10$mt9434TWI2q9QXhSoywyZephTAIEJHb5e1MK45GakfoEndZBfXn8a');
 | 
				
			||||||
 | 
					if (isset($_POST['password']) && password_verify($_POST['password'], HASHED_PASSWORD)===true) {
 | 
				
			||||||
 | 
					    $_SESSION['logged_in'] = true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// kiléptetés
 | 
				
			||||||
 | 
					if (isset($_POST['logout'])){
 | 
				
			||||||
 | 
					    // remove all session variables
 | 
				
			||||||
 | 
					    session_unset();
 | 
				
			||||||
 | 
					    // destroy the session
 | 
				
			||||||
 | 
					    session_destroy(); 
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if ($_SESSION['logged_in']) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ezeket majd külön fájba kéne tenni
 | 
				
			||||||
 | 
					include_once "globals.php";
 | 
				
			||||||
 | 
					// olyan szöveget ad vissza, amibe csak angol ABC betűi és számok szerepelnek (KL)
 | 
				
			||||||
 | 
					function only_alpha_numeric($input)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return preg_replace("/[^a-zA-Z0-9_]+/", "", $input);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					// csatlakozás az adatbázishoz
 | 
				
			||||||
 | 
					function open_sql_connection()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return mysqli_connect(SQL_IP, SQL_USER, SQL_PASS, SQL_DB);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					// Globális SQL-kapcsolat
 | 
				
			||||||
 | 
					$dbconn = open_sql_connection();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function get_images($last_No=-1, $n=10){
 | 
				
			||||||
 | 
					    global $dbconn;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    // felhasználótól jött paraméterek ellenőrzése
 | 
				
			||||||
 | 
					    $last_No = intval($last_No);
 | 
				
			||||||
 | 
					    $n = intval($n);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    $query = "SELECT * FROM publish_table";
 | 
				
			||||||
 | 
					    $query .= " WHERE Confirmed=0";
 | 
				
			||||||
 | 
					    $query .= "   AND No>$last_No";
 | 
				
			||||||
 | 
					    $query .= " ORDER BY No";
 | 
				
			||||||
 | 
					    $query .= " LIMIT $n";
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    $result = $dbconn->query($query);
 | 
				
			||||||
 | 
					    $data = [];
 | 
				
			||||||
 | 
					    while ($row = $result->fetch_assoc()) {
 | 
				
			||||||
 | 
					        $data[] = $row;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    return $data;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function set_approval($Image_FileName, $approved){
 | 
				
			||||||
 | 
					    global $dbconn;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    // felhasználótól jött paraméterek ellenőrzése
 | 
				
			||||||
 | 
					    $approved = $approved === 'true' ? 1 : 0;
 | 
				
			||||||
 | 
					    $Image_FileName = $dbconn->real_escape_string($Image_FileName);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    // jóváhagyás mező beállítása és ellenőrzöttnek jelölés
 | 
				
			||||||
 | 
					    $query = "UPDATE publish_table SET Approved=$approved, Confirmed=1 WHERE Image_FileName='$Image_FileName';";
 | 
				
			||||||
 | 
					    $res = $dbconn->query($query);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    return $res; // true ha sikeres, false ha valami hiba történt
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (isset($_POST["action"])) {
 | 
				
			||||||
 | 
					        $action = only_alpha_numeric($_POST["action"]);
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // parancs kiválasztása
 | 
				
			||||||
 | 
					        switch ($action) {
 | 
				
			||||||
 | 
					            case "get_images": // kép adatok lekérése
 | 
				
			||||||
 | 
					                if (isset($_POST["last_No"]) && isset($_POST["n"])) {
 | 
				
			||||||
 | 
					                    echo json_encode(get_images($_POST["last_No"], $_POST["n"]));
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            case "set_approval": // jováhagyás beállítása
 | 
				
			||||||
 | 
					                if (isset($_POST["Image_FileName"]) && isset($_POST["approved"])) {
 | 
				
			||||||
 | 
					                    echo json_encode(set_approval($_POST["Image_FileName"], $_POST["approved"]));
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        exit(0);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					?>
 | 
				
			||||||
 | 
					<!DOCTYPE html>
 | 
				
			||||||
 | 
					<html lang="hu">
 | 
				
			||||||
 | 
					<head>
 | 
				
			||||||
 | 
					    <meta charset="utf-8"/>
 | 
				
			||||||
 | 
					    <meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0'>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <title>képek jóváhagyása - Fotófal</title>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <script src="js/o.js"></script>
 | 
				
			||||||
 | 
					    <script src="js/socket.js"></script>
 | 
				
			||||||
 | 
					    <script src="js/slider.js"></script>
 | 
				
			||||||
 | 
					    <script src="js/phw.js"></script>
 | 
				
			||||||
 | 
					    <script src="js/color.js"></script>
 | 
				
			||||||
 | 
					    <?php if ($_SESSION['logged_in']) { ?>
 | 
				
			||||||
 | 
					    <script>
 | 
				
			||||||
 | 
					        // ezeket lehetne külön tenni
 | 
				
			||||||
 | 
					        function l(msg){console.log(msg);}
 | 
				
			||||||
 | 
					        function request(url, method, data){
 | 
				
			||||||
 | 
					            return new Promise( (resolve,reject) => {
 | 
				
			||||||
 | 
					                var formData;
 | 
				
			||||||
 | 
					                if(data){
 | 
				
			||||||
 | 
					                    formData = new FormData();
 | 
				
			||||||
 | 
					                    for (var k in data) {
 | 
				
			||||||
 | 
					                        formData.append(k, data[k]);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                fetch(url, {
 | 
				
			||||||
 | 
					                    method: method,
 | 
				
			||||||
 | 
					                    body: formData,
 | 
				
			||||||
 | 
					                })
 | 
				
			||||||
 | 
					                .then(response => response.text())
 | 
				
			||||||
 | 
					                .then(data => resolve(data))
 | 
				
			||||||
 | 
					                .catch((error) => {
 | 
				
			||||||
 | 
					                    console.error('Error: ', error);
 | 
				
			||||||
 | 
					                    reject(error);
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    </script>
 | 
				
			||||||
 | 
					    <script>
 | 
				
			||||||
 | 
					        const MAX_TABLE_ROWS = 10;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        document.addEventListener("DOMContentLoaded", () => {
 | 
				
			||||||
 | 
					            fill_table();
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        function fill_table(){
 | 
				
			||||||
 | 
					            var table_container = o('table_container');
 | 
				
			||||||
 | 
					            var max_new_rows = MAX_TABLE_ROWS - table_container.children.length;
 | 
				
			||||||
 | 
					            var last_No = table_container.children.length ? table_container.children[table_container.children.length-1].details.No : -1;
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            request(
 | 
				
			||||||
 | 
					                'approval.php',
 | 
				
			||||||
 | 
					                'POST',
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    action: 'get_images',
 | 
				
			||||||
 | 
					                    last_No: last_No,
 | 
				
			||||||
 | 
					                    n: max_new_rows,
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					            .then(data => {
 | 
				
			||||||
 | 
					                data = JSON.parse(data);
 | 
				
			||||||
 | 
					                if (data.length) {
 | 
				
			||||||
 | 
					                    data.forEach(image_data => {
 | 
				
			||||||
 | 
					                        table_container.appendChild(render_row(image_data));
 | 
				
			||||||
 | 
					                    });
 | 
				
			||||||
 | 
					                } else if (table_container.innerHTML == '') {
 | 
				
			||||||
 | 
					                    table_container.innerHTML = '<h3>Jelenleg nincs jóváhagyásra váró elem :)</h3>'
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // 
 | 
				
			||||||
 | 
					        function render_row(image_data){
 | 
				
			||||||
 | 
					            var row_container = document.createElement('div');
 | 
				
			||||||
 | 
					            row_container.innerHTML = `
 | 
				
			||||||
 | 
					                <hr />
 | 
				
			||||||
 | 
					                <div>
 | 
				
			||||||
 | 
					                    <button id="button_approve" onclick="set_approval(event);" >Engedélyez</button>
 | 
				
			||||||
 | 
					                    <button id="button_hide" onclick="set_approval(event);" >Entüntet</button>
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					                <img src="ARTWORKS/thumbnails/${image_data["Image_FileName"]}" />
 | 
				
			||||||
 | 
					                <div>
 | 
				
			||||||
 | 
					                    <span>Alkotó: ${image_data["Author"]}</span><br />
 | 
				
			||||||
 | 
					                    <span>Cím: ${image_data["Title"]}</span><br />
 | 
				
			||||||
 | 
					                    <span>Leírás: ${image_data["Description"]}</span><br />
 | 
				
			||||||
 | 
					                    <span>Feltöltés ideje: ${image_data["TS"]}</span><br />
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					            `;
 | 
				
			||||||
 | 
					            row_container.details = image_data;
 | 
				
			||||||
 | 
					            return row_container;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        function set_approval(event){
 | 
				
			||||||
 | 
					            var approved = event.target.id === 'button_approve';
 | 
				
			||||||
 | 
					            var row_container = event.target.parentElement.parentElement;
 | 
				
			||||||
 | 
					            var image_data = row_container.details;
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            request(
 | 
				
			||||||
 | 
					                'approval.php',
 | 
				
			||||||
 | 
					                'POST',
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    action: 'set_approval',
 | 
				
			||||||
 | 
					                    Image_FileName: image_data['Image_FileName'],
 | 
				
			||||||
 | 
					                    approved: approved,
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					            .then(data => {
 | 
				
			||||||
 | 
					                if (data==='true') {
 | 
				
			||||||
 | 
					                    // ha sikeres a kérés, a sor eltüntetése
 | 
				
			||||||
 | 
					                    row_container.parentElement.removeChild(row_container);
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    alert('Valami nem stimmel, kérlek próbáld újra.');
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                // újabb elem betöltése, ha van
 | 
				
			||||||
 | 
					                fill_table();
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    </script>
 | 
				
			||||||
 | 
					    <style>
 | 
				
			||||||
 | 
					    .settings_container {
 | 
				
			||||||
 | 
					        padding: 10px;
 | 
				
			||||||
 | 
					        background-color: blue;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    #table_container > div > img {
 | 
				
			||||||
 | 
					        margin: 5px;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    #table_container > div > div {
 | 
				
			||||||
 | 
					        display: inline-block;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    </style>
 | 
				
			||||||
 | 
					    <?php } ?>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <link href="phw.css" rel="stylesheet">
 | 
				
			||||||
 | 
					</head>
 | 
				
			||||||
 | 
					<body>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<?php if ($_SESSION['logged_in']) { ?>
 | 
				
			||||||
 | 
					    <div class="settings_container" >
 | 
				
			||||||
 | 
					        <!-- TODO: valahogy be lehessen állítani,
 | 
				
			||||||
 | 
					            hogy ne csak az jelenjen meg, amit már egyszer leellenőriztek -->
 | 
				
			||||||
 | 
					        <form method="POST" >
 | 
				
			||||||
 | 
					            <input type="submit" name="logout" value="Kilépés" >
 | 
				
			||||||
 | 
					        </form>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					    <div id="table_container" ></div>
 | 
				
			||||||
 | 
					<?php } else { ?>
 | 
				
			||||||
 | 
					    <form method="POST" >
 | 
				
			||||||
 | 
					        <input type="password" name="password" />
 | 
				
			||||||
 | 
					        <input type="submit" value="Belépés" >
 | 
				
			||||||
 | 
					    </form>
 | 
				
			||||||
 | 
					<?php } ?>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<!-- TESZTVERZIÓ -->
 | 
				
			||||||
 | 
					<section class="testversion-sign">TESZTVERZIÓ</section>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</body>
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user