Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Tsotne Phartsvania/Task1/_function.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

function emptyInput($name,$lastname,$image){
$result = false;
if(empty($name) || empty($lastname) || empty($image) ){
$result = true;
}
else {
$result = false;
}
return $result;
}
function invalidName($name){
$result = false;
if(empty($name) || !preg_match("/^[a-zA-Z0-9]*$/", $name)){
$result = true;
}
else {
$result = false;
}
return $result;
}
function invalidLastName($lastname){
$result = false;
if(empty($lastname) || !preg_match("/^[a-zA-Z0-9]*$/", $lastname)){
$result = true;
}
else {
$result = false;
}
return $result;
}
110 changes: 110 additions & 0 deletions Tsotne Phartsvania/Task1/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

if (isset($_POST["submit"])){
$name = htmlspecialchars($_POST['user_name']);
$lastname = htmlspecialchars($_POST['last_name']);
$image = $_FILES['image'];

// include function
include_once "_function.php";

if(emptyInput($name,$lastname,$image) !== false){
header("Location: index.php?error=ცარიელია ველები. გთხოვთ შეავსოთ.");
exit;
}
if(invalidname($name) !== false){
header("Location: index.php?error=მხოლოდ ლათინური ასოები.");
exit();
}
if(invalidLastName($lastname) !== false){
header("Location: index.php?error=მხოლოდ ლათინური ასოები.");
exit();
}
if(empty($_FILES['image']['tmp_name'])){
header('Location: index.php?error=გთხოვთ ატვირთოთ ფოტო.');
}else{
if($_FILES['image']['type'] == 'image/png' || $_FILES['image']['type'] == 'image/jpg'){
$image = $_FILES['image'];
$imagePath = '';
if(!is_dir('images')){
mkdir('images');
}
$imagePath = 'images/' . time() .'_' . $image['name'];
move_uploaded_file($image['tmp_name'],$imagePath);
}else{
header("Location: index.php?error=მხოლოდ jpg და png გაფარტოების ფაილის ატვირთვა შეგიძლიათ");
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
</head>
<body>
<?php if($_SERVER["REQUEST_METHOD"] == "GET") : ?>
<div class="container mt-4">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">
<h1>რეგისტრაცია</h1>
</div>
<div class="card-body">

<?php if(isset($_GET['error'])) :?>
<p class="alert alert-danger" role="alert">
<?= $_GET['error'] ?>
</p>
<?php endif ?>

<form method="POST" action="<?php $_SERVER['PHP_SELF'] ?>" enctype="multipart/form-data">
<div class="mb-3">
<label class="form-label">სახელი: </label>
<input type="text" class="form-control" name="user_name" placeholder="User Name">
</div>
<div class="mb-3">
<label class="form-label">გვარი: </label>
<input type="text" class="form-control" name="last_name" placeholder="Last Name" >
</div>
<div class="mb-3">
<label for="formFile" class="form-label d-flex">ფოტოს ატვირთვა</label>
<span class=""><strong>მხოლოდ jpg და png გაფართოების ფოტო.</strong></span>
<input class="form-control" type="file" name="image" id="formFile">
</div>
<div class="mb-3 align-items-center">
<button class="btn btn-primary" type="submit" name="submit">Click Me</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<?php else : ?>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">User</div>
<div class="card-body">
<a href="/index.php" class="btn btn-warning">Back</a>
<div class="card" style="width:400px">
<img class="card-img-top" src="<?= $imagePath ?>" alt="Card image" style="width:100%">
<div class="card-body">
<h4 class="card-title"><?= "$name $lastname" ?></h4>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endif ?>
</body>
</html>
29 changes: 29 additions & 0 deletions Tsotne Phartsvania/Task2/_function.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

function getAPIDate($url,$name){

$curl = curl_init();

curl_setopt_array($curl,[
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $url,
CURLOPT_USERAGENT => $name
]);
$response = curl_exec($curl);

curl_close($curl);
return json_decode($response,true);
}

function auth($name){

$url = "https://api.github.com/users/$name";
$response = getAPIDate($url,$name);
if(!isset($response['message'])):
session_start();
$_SESSION['name'] = $name;
return header("Location: home.php");
else:
return header("Location: index.php?error=ესეთი მომხმარებელი ვერ მოიძებნა.");
endif;
}
7 changes: 7 additions & 0 deletions Tsotne Phartsvania/Task2/form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
//include function
include '_function.php';

$name = $_POST['user_name'];

auth($name);
149 changes: 149 additions & 0 deletions Tsotne Phartsvania/Task2/home.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?php

session_start();
if(isset($_SESSION['name'])):
include "_function.php";
$url = "https://api.github.com/users/{$_SESSION['name']}";
$response = getAPIDate($url,$_SESSION['name']);

if(!isset($response['message'])){
$_SESSION['followers'] = $response['followers'];
$_SESSION['repos'] = $response['public_repos'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

</head>
<body style="background-color: #eee;">
<section >
<div class="container py-5">
<div class="row">
<?php if(!isset($response['message'])) : ?>
<div class="col">
<nav aria-label="breadcrumb" class="bg-light rounded-3 p-3 mb-4">
<?php if(isset($_GET['warning'])){ ?>
<p class="alert alert-warning" role="alert"><?= $_GET['warning']?>
<?php } ?>
<ol class="breadcrumb mb-0">
<li class="breadcrumb-item"><a href="#">Home</a></li>
<li class="breadcrumb-item"><a href="#">User</a></li>
<li class="breadcrumb-item active" aria-current="page">User Profile</li>
</ol>

</nav>
</div>


<div class="row">
<div class="col-lg-4">
<div class="card mb-4">
<div class="card-body text-center">
<img src="<?= $response['avatar_url'] ?>" alt="avatar"
class="rounded-circle img-fluid" style="width: 150px;">
<h5 class="my-3"></h5>
<p class="text-muted mb-1">Full Stack Developer</p>
<p class="text-muted mb-4"></p>
<div class="d-flex justify-content-center mb-2">
<?php
if($response['followers'] > 0 || $response['public_repos'] > 0):
?>
<?php
if($response['followers'] > 0):
?>
<a href="view_followers.php?per_page=10&page=1" class="btn btn-primary">View Followers</a>
<?php
endif
?>
<?php
if($response['public_repos'] >0):
?>
<a href="view_repositors.php?per_page=10&page=1" class="btn btn-outline-primary ms-1">View Repositor</a>
<?php
endif
?>
<?php
endif
?>
<a href="logout.php" class="btn btn-outline-primary ms-1">Logout</a>
</div>
</div>
</div>

</div>
<div class="col-lg-8">
<div class="card mb-4">
<div class="card-body">
<div class="row">
<div class="col-sm-3">
<p class="mb-0">Full Name</p>
</div>
<div class="col-sm-9">
<p class="text-muted mb-0"><?= $response['name'] ?? $response['login'] ?></p>
</div>
</div>
<hr>
<div class="row">
<div class="col-sm-3">
<p class="mb-0">Following</p>
</div>
<div class="col-sm-9">
<p class="text-muted mb-0"><?= $response['following'] ?></p>
</div>
</div>
<hr>
<div class="row">
<div class="col-sm-3">
<p class="mb-0">Followers</p>
</div>
<div class="col-sm-9">
<p class="text-muted mb-0"><?= $response['followers'] ?></p>
</div>
</div>

<hr>
<div class="row">
<div class="col-sm-3">
<p class="mb-0">Git Hub LInk </p>
</div>
<div class="col-sm-9">
<a href="<?= $response['html_url'] ?>"><p class="text-muted mb-0">Here</p></a>
</div>
</div>
<hr/>
<div class="row">
<div class="col-sm-3">
<p class="mb-0">Address</p>
</div>
<div class="col-sm-9">
<p class="text-muted mb-0"><?= $response['location'] ?? 'Not Found' ?></p>
</div>
</div>
</div>
</div>

</div>
</div>
<?php else :?>
<h1><?= $response['message'] ?></h1>
<a href='<?= "logout.php" ?>' class='btn btn-primary'>Logout</a>
<?php
endif
?>
</div>
</div>
</section>

</body>
</html>
<?php
else :
header('Location: index.php?error=თქვენ არ გაგივლიათ ავტორიზაცია');
endif
?>
48 changes: 48 additions & 0 deletions Tsotne Phartsvania/Task2/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
session_start();

if(!isset($_SESSION['name'])):
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<body>
<div class="container mt-5 pt-5">
<div class="row">
<div class="col-12 col-sm-8 col-md-6 m-auto">
<div class="card border-0 shadow">
<div class="card-body">
<?php if(isset($_GET['error'])){ ?>
<p class="alert alert-danger" role="alert"><?php echo $_GET['error']?>
<?php } ?>
<div style="text-align: center">
<svg class="my-3" xmlns="http://www.w3.org/2000/svg" width="50" height="50" fill="currentColor" class="bi bi-person-circle" viewBox="0 0 16 16">
<path d="M11 6a3 3 0 1 1-6 0 3 3 0 0 1 6 0z"/>
<path fill-rule="evenodd" d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm8-7a7 7 0 0 0-5.468 11.37C3.242 11.226 4.805 10 8 10s4.757 1.225 5.468 2.37A7 7 0 0 0 8 1z"/>
</svg>
</div>

<form action="form.php" method="POST">
<input class="form-control my-3 py-2" name="user_name" placeholder="GitHub UserName" />
<div class="text-center mt-3">
<button class="btn btn-primary">Click</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>

</body>
</html>
<?php else :
header('Location: home.php');
endif
?>
9 changes: 9 additions & 0 deletions Tsotne Phartsvania/Task2/logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
session_start();

session_unset();
session_destroy();

header("Location: index.php");

?>
Loading