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
63 changes: 63 additions & 0 deletions max_pkhaladze/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ChallengeN1</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="p-3 m-0 border-0 bd-example">
<?php if (empty($_POST)) : ?>
<!-- Form HTML -->
<form action="index.php" method="POST" enctype="multipart/form-data">
<div class="input-group mt-3">
<span class="input-group-text">First and last name</span>
<input type="text" aria-label="First name" class="form-control" name="first_name" placeholder="First name">
<input type="text" aria-label="Last name" class="form-control" name="last_name" placeholder="Last name">
</div>
<div class="input-group mt-3">
<input type="file" class="form-control" name="profile_picture">
<label class="input-group-text" ></label>
</div>
<div class="d-grid gap-2">
<button type="submit" name="submit" class="btn btn-primary mt-3" value="submit">Submit</button>
</div>
</form>
<?php else: ?>
<?php
// Validate first name and last name
if (!preg_match('/^[A-Za-z]+$/', $_POST['first_name']) || !preg_match('/^[A-Za-z]+$/', $_POST['last_name'])) {
$error_message = 'First and last name must contain only alphabet characters';
} else {
// Create upload folder if it doesn't exist
$upload_folder = 'uploads';
if (!file_exists($upload_folder)) {
mkdir($upload_folder);
}
// Upload profile picture
$profile_picture = $upload_folder . '/' . basename($_FILES['profile_picture']['name']);
if (move_uploaded_file($_FILES['profile_picture']['tmp_name'], $profile_picture)) {
// Show first name, last name and profile picture
$first_name = htmlspecialchars($_POST['first_name']);
$last_name = htmlspecialchars($_POST['last_name']);
} else {
$error_message = 'Failed to upload profile picture';
}
}
?>
<div class="card">
<img src="<?php print $profile_picture; ?>" class="card-img-top" alt="photoebi">
<div class="card-body">
<h2 class="card-title"><?php print $first_name; ?> <?php print $last_name; ?></h2>
</div>
<div>
<!-- Show error message if there is one -->
<?php if (isset($error_message)) { echo $error_message; } ?>
<div>
</div>
<?php endif; ?>
</body>
</html>
87 changes: 87 additions & 0 deletions max_pkhaladze/week2/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.x.x/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://code.jquery.com/jquery-3.x.x.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.x.x/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.x.x/js/bootstrap.min.js"></script>

<title>Github Information</title>
</head>
<body>

<form action="" method="post">
<div class="form-group">
<label for="username">Github Username</label>
<input type="text" class="form-control" name="username" id="username">
</div>
<div class="form-group">
<div class="form-check">
<input class="form-check-input" type="radio" name="info_type" value="repositories" id="repositories">
<label class="form-check-label" for="repositories">
Repositories
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="info_type" value="followers" id="followers">
<label class="form-check-label" for="followers">
Followers
</label>
</div>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>


<?php
if (isset($_POST['username'])) {
$username = $_POST['username'];
$info_type = $_POST['info_type'];

if ($info_type == "repositories") {
$url = "https://api.github.com/users/" . $username . "/repos";
} else {
$url = "https://api.github.com/users/" . $username . "/followers";
}

$options = array(
'http' => array(
'method' => 'GET',
'header' => 'User-Agent: Awesome-Octocat-App'
)
);
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);

$data = json_decode($response);

if ($info_type == "repositories") {
echo "<h2 class='text-center mb-4'>Repositories for " . $username . "</h2>";
echo "<ul class='list-group'>";
foreach ($data as $repo) {
echo "<li class='list-group-item'><a href='" . $repo->html_url . "'>" . $repo->name . "</a></li>";
}
echo "</ul>";
} else {
echo "<h2 class='text-center mb-4'>Followers for " . $username . "</h2>";
echo "<ul class='list-group'>";
foreach ($data as $follower) {
echo "<li class='list-group-item'><a href='" . $follower->html_url
. "'><img class='rounded-circle' src='"
. $follower->avatar_url . "' > " . $follower->login . "</a></li>";
}
echo "</ul>";
}
}
?>


</body>
</html>