function show_stores() { page_head("Stores"); table_start(); table_header(array("Name<br><small>Click for details</small>", "Files<br><small>Click to view</small>", "Capacity", "Used", "% used", "Available")); $stores = store_enum(); foreach ($stores as $store) { $nfiles = file_count("store_id={$store->id}"); table_row(array("<a href=hl.php?action=store&id={$store->id}>{$store->name}</a>", "<a href=hl.php?action=file_search_action&store_id={$store->id}>{$nfiles}</a>", size_str($store->capacity), size_str($store->used), progress_bar(100 * $store->used / $store->capacity), $store->unavailable ? "No" : "Yes")); } table_end(); echo ' <a href="hl.php?action=edit_store_form"> <button type="button" class="btn btn-default"> Add store </button> </a> '; page_tail(); }
function recommended_store($req) { $source = source_lookup_auth($req->authenticator); if (!$source) { error("auth failure"); return; } $stores = store_enum('unavailable=0'); foreach ($stores as $store) { $space = $store->capacity - $store->used; if ($req->file_size < $space) { $reply = success(); $reply->store = $store; echo json_encode($reply); return; } } error("no store has sufficient free space"); return; }