<?php

$title = 'Project Storage';
require './header.php';
$cards = fRecordSet::build('Card', array('uid=' => $_GET['cardid']));
if ($cards->count() == 0) {
    fURL::redirect("/kiosk/addcard.php?cardid=" . $_GET['cardid']);
}
$card = $cards->getRecord(0);
$user = new User($card->getUserId());
$user->load();
if (isset($_POST['print'])) {
    $project = new Project($_POST['print']);
    $project->load();
    if ($project->getUserId() != $user->getId()) {
        print "Incorrect project ID";
        exit;
    }
    $data = array('storage_id' => $project->getId(), 'name' => $project->getName(), 'ownername' => $user->getFullName(), 'more_info' => $project->getDescription(), 'completion_date' => $project->getToDate()->format('Y/m/d'), 'max_extention' => "14");
    $data_string = json_encode($data);
    $ch = curl_init('http://kiosk.london.hackspace.org.uk:12345/print/dnh');
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data_string)));
    $result = curl_exec($ch);
    curl_close($ch);
    echo "<p>Your sticker is being printed now.</p>";
}
$projects = fRecordSet::build('Project', array('state_id!=' => array('6', '7'), 'user_id=' => $user->getId()));
?>
 if (!$project->getId()) {
     $auto = true;
     $logDetails = "Request created";
     $project->setState('Pending Approval');
     $initial = true;
 } else {
     $auto = false;
     $logDetails = "Request updated";
     $initial = false;
 }
 $project->setUpdatedDate(date('Y-m-d'));
 $project->setUserId($user->getId());
 $project->store();
 $project->submitLog($logDetails, $user->getId());
 // post to Google Groups
 $projectUser = new User($project->getUserId());
 $message = '<strong>' . $project->getName() . "</strong><br>\n" . "https://london.hackspace.org.uk/storage/" . $project->getId() . "<br>\n" . "by <a href=\"https://london.hackspace.org.uk/members/member.php?id=" . $project->getUserId() . "\">" . htmlspecialchars($projectUser->getFullName()) . "</a><br>\n" . $project->outputDates() . "<br>\n" . $project->outputDuration() . ' ' . $project->outputLocation() . "<br>\n<br>\n" . nl2br(stripslashes($project->getDescription())) . "<br>\n<br>\n";
 if ($auto && !$project->isShortTerm()) {
     $message .= "<strong>***If no one replies to this topic the request will be automatically approved within " . $project->automaticApprovalDuration() . " days.***</strong>";
 }
 $project->submitMailingList($message, $initial);
 // is this a short term request? If so automatically approve it
 if ($project->isShortTerm()) {
     $project->setState('Approved');
     $project->store();
     // log the update
     $logmsg = 'Short term storage detected, status automatically changed to ' . $project->getState();
     $project->submitLog($logmsg, false);
     $project->submitMailingList($logmsg);
 }
 fURL::redirect("/storage/{$project->getId()}");
<?php

$page = 'storagedetails_edit';
$title = "Storage details";
require '../header.php';
ensureMember();
$project = new Project(filter_var($_GET['id'], FILTER_SANITIZE_STRING));
$projectslogs = fRecordSet::build('ProjectsLog', array('project_id=' => $project->getId()), array('id' => 'asc'));
$states = fRecordSet::build('ProjectState', array(), array('id' => 'asc'));
$projectUser = new User($project->getUserId());
// has the project owner set the status to removed or extended?
if (isset($_POST['remove']) || isset($_POST['extend']) && $user->getId() == $project->getUserId()) {
    try {
        fRequest::validateCSRFToken($_POST['token']);
        if (isset($_POST['remove']) && $project->canTransitionStates($project->getState(), 'Removed')) {
            $project->setState('Removed');
        } else {
            if (isset($_POST['extend']) && $project->canTransitionStates($project->getState(), 'Extended')) {
                $project->setState('Extended');
            }
        }
        $project->store();
        $project->submitLog('Status changed to ' . $project->getState(), $user->getId());
        fURL::redirect("/storage/{$project->getId()}");
    } catch (fValidationException $e) {
        echo $e->printMessage();
    } catch (fSQLException $e) {
        echo '<div class="alert alert-danger">An unexpected error occurred, please try again later</div>';
    }
}
// has another member updated the status?
<?php

$page = 'storagedetails_print';
$title = "Storage list";
require '../header-mini.php';
ensureMember();
$project = new Project(filter_var($_GET['id'], FILTER_SANITIZE_STRING));
$to = new DateTime($project->getToDate());
$projectUser = new User($project->getUserId());
if ($project->getState() != 'Approved') {
    echo "<p>Your Do Not Hack sticker will become available when your storage request is approved.</p>";
    exit;
}
?>
<style type="text/css">
	.print {
		max-width: 700px;
		margin-left: auto;
		margin-right: auto;
		font-family: sans-serif;
	}
	h1, h2, h3 {
		padding: 0;
		margin: 10px;
	}
	img {
		display: block;
		margin-left: auto;
		margin-right: auto;
	}
	#qrcode {