Files
E-42/action/add_member.php

131 lines
4.2 KiB
PHP

<?php
// check if department and name exists
if(!isset($_GET['department']) || !isset($_GET['name']))
die('Name or Department is missing');
// check if department is valid
$departmemt = strtoupper($_GET['department']);
if(empty($departmemt) || !preg_match('/^[A-Z]-[0-9]*$/', $departmemt))
die('Invalid department');
// check if name is valid
$name = htmlentities($_GET['name']);
//TODO verificar se nao tem barras
if(empty( $name) || !preg_match('/^[\w\-()]*$/', $name) )
die('Invalid name');
// load html file
$path = __DIR__ . '/../' . $departmemt . '/index.html';
$html = simplexml_load_file($path);
$staff_list = $html->xpath('//UL[@id="staffList"]');
foreach( $staff_list[0] as $member){
if($member->a->__toString() === $name){
die("Member already exists");
}
}
$new_staff = $staff_list[0]->addChild('li');
$new_staff->a =$name;
$new_staff->a['href'] ='members/'.$name;
// update in department members lists
$html->asXml($path);
// create member profile
$member_page = __DIR__ . '/../' . $departmemt.'/members/'.$name;
mkdir($member_page.'/reports', 0777, true);
$page = fopen($member_page.'/index.html', "w");
$default_page = '<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title>Staff Details: '.$name.' | '.$departmemt.' - Porto Space Team</title>
<meta name="author" content="'.$name.'">
<link rel="stylesheet" href="https://diogo.site/assets/css/main.css" type="text/css">
<link rel="shortcut icon" href="about:blank">
<script src="https://cdn.tiny.cloud/1/no-api-key/tinymce/5/tinymce.min.js" referrerpolicy="origin"></script>
<script src="/js/pageEditor.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,0,0">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
</head>
<body>
<header>
<div id="header-content">
<h1>'.$departmemt.' - Porto Space Team</h1>
<h2>Staff Details: '.$name.'</h2>
<nav>
<ul>
<li><a href="/'.$departmemt.'/">Back</a></li>
<li><a href="#">Profile</a></li>
<li><a href="https://codeberg.org/portospaceteam/'.$departmemt.'/src/branch/master/members/'.$name.'/reports">Reports</a>
</li>
</ul>
</nav>
</div>
</header>
<hr>
<style>
#edit_button{
float: right;
cursor: pointer;
}
#save_page{
margin-top: 2em;
padding: 0.25em;
}
</style>
<main>
<span onclick="editPage()" id="edit_button" class="material-symbols-outlined">
edit
</span>
<section id="mytextarea"><h3>Past Responsibilities</h3>
<p>TODO</p>
<h3>Current Responsibilities</h3>
<p>TODO</p>
<h3>Relevant Education background</h3>
<p>TODO</p>
<h3>About</h3>
<p>TODO</p>
</section>
<input id="save_page" style="display: none;" type="button" value="Save File" onclick="savePage(\''.$name.'\', \''.$departmemt.'\')">
</main>
<hr>
<footer>
<p><small>Unless stated otherwise, you can assume <a href="https://creativecommons.org/licenses/by-sa/4.0/">Attribution-ShareAlike 4.0 International (CC BY-SA
4.0)</a>.</small></p>
</footer>
</body>
</html>';
fwrite($page, $default_page);
fclose( $page);
header('Location: /'. $departmemt.'/');
?>