Select space-update. Also fix not showing logged out when logged out
parent
fdac5278bc
commit
1d9b578d6e
44
plan/do.php
44
plan/do.php
|
@ -1,13 +1,17 @@
|
|||
<?php
|
||||
require '../webdata/init.php';
|
||||
|
||||
$db = database();
|
||||
|
||||
header("Content-Type: application/json");
|
||||
|
||||
if(!checkLogin()){
|
||||
returns("Not logged in",2);
|
||||
}
|
||||
|
||||
$user_id = $_SESSION['user_id'];
|
||||
|
||||
header("Content-Type: application/json");
|
||||
|
||||
|
||||
$data = [];
|
||||
$returns = [];
|
||||
|
@ -127,6 +131,40 @@ if(!empty($data) && isset($user_id)){
|
|||
returns($db->error,1);
|
||||
}
|
||||
|
||||
else if($data['plan'] == 'spaces'){
|
||||
$spaces = [];
|
||||
$getOwnedSpacesSQL = "SELECT space_id, space_name, owner_id userid FROM plan_space s WHERE s.owner_id = $user_id;";
|
||||
$getMemberSpacesSQL = "SELECT s.space_id, s.space_name, member_id userid FROM plan_space_member sm INNER JOIN plan_space s ON sm.space_id = s.space_id WHERE sm.member_id = $user_id;";
|
||||
if(($getOwnedPlans = $db->query($getOwnedSpacesSQL)) && ($getMemberSpaces = $db->query($getMemberSpacesSQL))){
|
||||
|
||||
$numOwned = 1;
|
||||
while($row = $getOwnedPlans->fetch_assoc()){
|
||||
if($row['space_name'] == ''){
|
||||
$row['space_name'] = "Personal space ".$numOwned;
|
||||
}
|
||||
$spaces[] = $row;
|
||||
$numOwned++;
|
||||
}
|
||||
|
||||
$numShared = 1;
|
||||
while($row = $getMemberSpaces->fetch_assoc()){
|
||||
if($row['space_name'] == ''){
|
||||
$row['space_name'] = "Shared space ".$numShared;
|
||||
}
|
||||
$spaces[] = $row;
|
||||
$numShared++;
|
||||
}
|
||||
|
||||
if(isset($_SESSION['lastSpace'])){
|
||||
$returning['lastSpace'] = $_SESSION['lastSpace'];
|
||||
}
|
||||
$returning['spaces'] = $spaces;
|
||||
|
||||
returns($returning);
|
||||
}
|
||||
returns($db->error,1);
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
$sql = "SELECT `plan_store_id`, `name`, `created` FROM plan_store WHERE space_id = $spaceID";
|
||||
|
@ -147,6 +185,10 @@ if(!empty($data) && isset($user_id)){
|
|||
returns($db->error,1);
|
||||
}
|
||||
|
||||
try {
|
||||
$_SESSION['lastSpace'] = $spaceID;
|
||||
} catch (Exception $e){}
|
||||
|
||||
$returns[] = $stores;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,15 @@
|
|||
<h1 class="headline text-center">Grocery Assist</h1>
|
||||
<div class="container" style="padding-top: 5px; text-align: center;">
|
||||
|
||||
<div id="spaceSelectWrapper" style="max-width: 900px; margin: auto;">
|
||||
<div class="input-group" style="width: 200px;">
|
||||
<label class="input-group-text" for="spaceSelect">Space:</label>
|
||||
<select class="form-select" id='spaceSelect' aria-label="Select space">
|
||||
<option>...</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-columns" id="stores" style="text-align: center;">
|
||||
<hr>
|
||||
<h5>Please enable javascript for this page to work</h5>
|
||||
|
|
39
plan/plan.js
39
plan/plan.js
|
@ -369,6 +369,7 @@ class Store {
|
|||
}
|
||||
|
||||
var stores = [];
|
||||
$("#stores").html("");
|
||||
|
||||
$("#addStore").click(ev => {
|
||||
stores.push(new Store());
|
||||
|
@ -385,7 +386,42 @@ $("body").on('click', function(ev){
|
|||
}
|
||||
});
|
||||
|
||||
var spaceID = 0;
|
||||
let spaceID = 0;
|
||||
function getSpaces(){
|
||||
return ajaxReq({plan: 'spaces'}).done(json => {
|
||||
let optionsHtml = "";
|
||||
|
||||
console.log(json);
|
||||
|
||||
let spaceNum = 1;
|
||||
for(const spaceI in json.data.spaces){
|
||||
const space = json.data.spaces[spaceI];
|
||||
if(spaceID === 0){
|
||||
spaceID = space['space_id'];
|
||||
}
|
||||
let spaceName = space['space_name'] || "Space "+spaceNum;
|
||||
optionsHtml += "<option value='"+space['space_id']+"'>"+spaceName+"</option>\n";
|
||||
spaceNum++;
|
||||
}
|
||||
|
||||
let spaceSelectElem = $("#spaceSelect");
|
||||
spaceSelectElem
|
||||
.html(optionsHtml)
|
||||
.on('change', ev => {
|
||||
spaceID = $(ev.target).val();
|
||||
getStores(spaceID);
|
||||
});
|
||||
|
||||
if(typeof json.data.lastSpace !== "undefined"){
|
||||
spaceID = Number(json.data.lastSpace);
|
||||
spaceSelectElem.val(spaceID);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
getSpaces().done(() => { getStores(spaceID); });
|
||||
|
||||
// GET STORES
|
||||
function getStores(spaceID){
|
||||
spaceID = spaceID || 0;
|
||||
|
@ -420,7 +456,6 @@ function getStores(spaceID){
|
|||
})
|
||||
.fail(handleAjaxErrors);
|
||||
}
|
||||
getStores(spaceID);
|
||||
|
||||
|
||||
function ajaxReq( data ){
|
||||
|
|
|
@ -54,8 +54,8 @@ function getHtmlHeaders($prepend = ""){
|
|||
<script src='".$prepend."js/jquery-3.5.1.min.js'></script>
|
||||
<script src='".$prepend."js/popper.min.js'></script>
|
||||
<script src='".$prepend."js/bootstrap.min.js'></script>
|
||||
<script src='".$prepend."js/hammer.js'></script>
|
||||
<script src='".$prepend."js/hammer.jquery.js'></script>
|
||||
<!--<script src='".$prepend."js/hammer.js'></script>
|
||||
<script src='".$prepend."js/hammer.jquery.js'></script>-->
|
||||
\n";
|
||||
}
|
||||
|
||||
|
@ -158,6 +158,7 @@ function checkLogin(): bool{
|
|||
}
|
||||
}
|
||||
|
||||
unset($_SESSION['user_key']);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue