Commit 2bd7b736 authored by Malcolm Blaney's avatar Malcolm Blaney

A few bug fixes: Keep reading from file handle in Reader->PurgeCache

to avoid broken pipe. Groupwizard context for opening account dialog
had got out of sync with sections. Purchase and Sell modules had a
scrolling bug when editing in the grid, because resetForm is called
and previously stole focus. Stock add new supplier now dynamically
adds the account to the import list.
parent 6b746f5b
Pipeline #20063293 passed with stage
in 1 minute and 18 seconds
......@@ -1379,17 +1379,22 @@ class Reader extends Base {
$total = 0;
// Convert $count to bytes to match strlen result.
$count *= 1000000;
$handle = popen('/bin/ls -1tr cache/*.spi', 'r');
$handle = popen('/bin/ls -1tr cache', 'r');
while ($file = trim(fgets($handle))) {
$image = unserialize(file_get_contents($file));
// Only match image files in the cache. Note that *.spi can't be used
// above as a filter because it creates too many arguments. Also if the
// loop is broken while there is still data to read, then pclose() will
// report a broken pipe, so also continue once total has been reached.
if ($total > $count || strpos($file, '.spi') === false) continue;
$image = unserialize(file_get_contents('cache/' . $file));
if (isset($image['body'])) {
$total += strlen($image['body']);
// Only the body is removed to save space, the headers are kept so that
// the original file can be fetched by the image handler if required.
unset($image['body']);
file_put_contents($file, serialize($image));
file_put_contents('cache/' . $file, serialize($image));
}
if ($total > $count) break;
}
pclose($handle);
}
......
......@@ -227,7 +227,8 @@ class Stock extends Base {
'<button id="stock-open-product-form">Open product form</button>' .
'<label for="stock-show-import">Import</label>' .
'<input id="stock-show-import" type="checkbox">' .
'<span id="stock-import-wrapper">' . $this->SupplierSelect() .
'<span id="stock-import-wrapper"><select id="stock-import-supplier">' .
$this->SupplierSelect() . '</select>' .
'<input id="stock-import-file" type="file"></span>' .
'</div>' .
'<input type="checkbox" id="stock-show-columns">' .
......@@ -2994,23 +2995,26 @@ class Stock extends Base {
}
private function UpdateGroup() {
if (!isset($_SESSION['purchase-group'])) return ['done' => true];
// UpdateGroup is called after a new supplier account has been created,
// so update the import select menu on the page.
$options = $this->SupplierSelect();
if (!isset($_SESSION['purchase-group'])) return ['options' => $options];
$purchase_group = $_SESSION['purchase-group'];
if ($this->user->group === $purchase_group) return ['done' => true];
if ($this->user->group === $purchase_group) return ['options' => $options];
$invite = new Invite($this->user, $this->owner);
if (in_array($purchase_group, $invite->Created())) {
$mysqli = connect_db();
$user = $mysqli->escape_string($_POST['supplier']);
$query = 'UPDATE users SET system_group = "'.$purchase_group.'" WHERE '.
'user = "'.$user.'"';
$query = 'UPDATE users SET system_group = "' . $purchase_group . '" ' .
'WHERE user = "' . $user . '"';
if (!$mysqli->query($query)) {
$this->Log('Stock->UpdateGroup: '.$mysqli->error);
$this->Log('Stock->UpdateGroup: ' . $mysqli->error);
}
$mysqli->close();
}
return ['done' => true];
return ['options' => $options];
}
private function ChangeGroup() {
......@@ -3041,12 +3045,11 @@ class Stock extends Base {
private function SupplierSelect() {
$detail = new Detail($this->user, $this->owner);
$select = '<select id="stock-import-supplier">'.
'<option value="">Multiple Suppliers</option>';
$options = '<option value="">Multiple Suppliers</option>';
foreach ($detail->SupplierOnly() as $supplier => $name) {
$select .= '<option value="'.$supplier.'">'.$name.'</option>';
$options .= '<option value="' . $supplier . '">' . $name . '</option>';
}
return $select.'</select>';
return $options;
}
private function TrackQuantity() {
......
This diff is collapsed.
......@@ -2,7 +2,7 @@
// @licstart The following is the entire license notice
// for the JavaScript code in this page.
//
// Copyright (C) 2017 Malcolm Blaney
// Copyright (C) 2018 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -277,28 +277,28 @@ if (!this.dobrado.groupwizard) {
function showGroup() {
// Activate the preferences tab.
$("#account-tabs").tabs("option", "active", 1);
$('#account-tabs').tabs('option', 'active', 1);
// It's a bit hard to know which link was clicked so use the section
// variable as a guide.
if (section === 1) {
$("#group-input").val("admin/invite-notifications");
$('#group-input').val('admin/invite-notifications');
}
if (section === 2) {
$("#group-input").val("admin/purchase-other-order");
if (section === 3) {
$('#group-input').val('admin/purchase-other-order');
}
else if (section === 3) {
$("#group-input").val("admin/purchase-volunteer");
else if (section === 4) {
$('#group-input').val('admin/purchase-volunteer');
}
else if (section === 5) {
var group = $("#groupwizard-current-group").val();
else if (section === 6) {
var group = $('#groupwizard-current-group').val();
if (group) {
$("#group-input").val("admin/invoice-notifications-" + group);
$('#group-input').val('admin/invoice-notifications-' + group);
}
else {
$("#group-input").val("admin/invoice-notifications");
$('#group-input').val('admin/invoice-notifications');
}
}
$("#account-groups .show-members").click();
$('#account-groups .show-members').click();
}
function createGroup() {
......@@ -361,4 +361,4 @@ if (!this.dobrado.groupwizard) {
return ['Africa/Abidjan','Africa/Accra','Africa/Addis_Ababa','Africa/Algiers','Africa/Asmara','Africa/Bamako','Africa/Bangui','Africa/Banjul','Africa/Bissau','Africa/Blantyre','Africa/Brazzaville','Africa/Bujumbura','Africa/Cairo','Africa/Casablanca','Africa/Ceuta','Africa/Conakry','Africa/Dakar','Africa/Dar_es_Salaam','Africa/Djibouti','Africa/Douala','Africa/El_Aaiun','Africa/Freetown','Africa/Gaborone','Africa/Harare','Africa/Johannesburg','Africa/Juba','Africa/Kampala','Africa/Khartoum','Africa/Kigali','Africa/Kinshasa','Africa/Lagos','Africa/Libreville','Africa/Lome','Africa/Luanda','Africa/Lubumbashi','Africa/Lusaka','Africa/Malabo','Africa/Maputo','Africa/Maseru','Africa/Mbabane','Africa/Mogadishu','Africa/Monrovia','Africa/Nairobi','Africa/Ndjamena','Africa/Niamey','Africa/Nouakchott','Africa/Ouagadougou','Africa/Porto-Novo','Africa/Sao_Tome','Africa/Tripoli','Africa/Tunis','Africa/Windhoek','America/Adak','America/Anchorage','America/Anguilla','America/Antigua','America/Araguaina','America/Argentina/Buenos_Aires','America/Argentina/Catamarca','America/Argentina/Cordoba','America/Argentina/Jujuy','America/Argentina/La_Rioja','America/Argentina/Mendoza','America/Argentina/Rio_Gallegos','America/Argentina/Salta','America/Argentina/San_Juan','America/Argentina/San_Luis','America/Argentina/Tucuman','America/Argentina/Ushuaia','America/Aruba','America/Asuncion','America/Atikokan','America/Bahia','America/Bahia_Banderas','America/Barbados','America/Belem','America/Belize','America/Blanc-Sablon','America/Boa_Vista','America/Bogota','America/Boise','America/Cambridge_Bay','America/Campo_Grande','America/Cancun','America/Caracas','America/Cayenne','America/Cayman','America/Chicago','America/Chihuahua','America/Costa_Rica','America/Creston','America/Cuiaba','America/Curacao','America/Danmarkshavn','America/Dawson','America/Dawson_Creek','America/Denver','America/Detroit','America/Dominica','America/Edmonton','America/Eirunepe','America/El_Salvador','America/Fortaleza','America/Glace_Bay','America/Godthab','America/Goose_Bay','America/Grand_Turk','America/Grenada','America/Guadeloupe','America/Guatemala','America/Guayaquil','America/Guyana','America/Halifax','America/Havana','America/Hermosillo','America/Indiana/Indianapolis','America/Indiana/Knox','America/Indiana/Marengo','America/Indiana/Petersburg','America/Indiana/Tell_City','America/Indiana/Vevay','America/Indiana/Vincennes','America/Indiana/Winamac','America/Inuvik','America/Iqaluit','America/Jamaica','America/Juneau','America/Kentucky/Louisville','America/Kentucky/Monticello','America/Kralendijk','America/La_Paz','America/Lima','America/Los_Angeles','America/Lower_Princes','America/Maceio','America/Managua','America/Manaus','America/Marigot','America/Martinique','America/Matamoros','America/Mazatlan','America/Menominee','America/Merida','America/Metlakatla','America/Mexico_City','America/Miquelon','America/Moncton','America/Monterrey','America/Montevideo','America/Montserrat','America/Nassau','America/New_York','America/Nipigon','America/Nome','America/Noronha','America/North_Dakota/Beulah','America/North_Dakota/Center','America/North_Dakota/New_Salem','America/Ojinaga','America/Panama','America/Pangnirtung','America/Paramaribo','America/Phoenix','America/Port-au-Prince','America/Port_of_Spain','America/Porto_Velho','America/Puerto_Rico','America/Rainy_River','America/Rankin_Inlet','America/Recife','America/Regina','America/Resolute','America/Rio_Branco','America/Santa_Isabel','America/Santarem','America/Santiago','America/Santo_Domingo','America/Sao_Paulo','America/Scoresbysund','America/Sitka','America/St_Barthelemy','America/St_Johns','America/St_Kitts','America/St_Lucia','America/St_Thomas','America/St_Vincent','America/Swift_Current','America/Tegucigalpa','America/Thule','America/Thunder_Bay','America/Tijuana','America/Toronto','America/Tortola','America/Vancouver','America/Whitehorse','America/Winnipeg','America/Yakutat','America/Yellowknife','Antarctica/Casey','Antarctica/Davis','Antarctica/DumontDUrville','Antarctica/Macquarie','Antarctica/Mawson','Antarctica/McMurdo','Antarctica/Palmer','Antarctica/Rothera','Antarctica/Syowa','Antarctica/Troll','Antarctica/Vostok','Arctic/Longyearbyen','Asia/Aden','Asia/Almaty','Asia/Amman','Asia/Anadyr','Asia/Aqtau','Asia/Aqtobe','Asia/Ashgabat','Asia/Baghdad','Asia/Bahrain','Asia/Baku','Asia/Bangkok','Asia/Beirut','Asia/Bishkek','Asia/Brunei','Asia/Chita','Asia/Choibalsan','Asia/Colombo','Asia/Damascus','Asia/Dhaka','Asia/Dili','Asia/Dubai','Asia/Dushanbe','Asia/Gaza','Asia/Hebron','Asia/Ho_Chi_Minh','Asia/Hong_Kong','Asia/Hovd','Asia/Irkutsk','Asia/Jakarta','Asia/Jayapura','Asia/Jerusalem','Asia/Kabul','Asia/Kamchatka','Asia/Karachi','Asia/Kathmandu','Asia/Khandyga','Asia/Kolkata','Asia/Krasnoyarsk','Asia/Kuala_Lumpur','Asia/Kuching','Asia/Kuwait','Asia/Macau','Asia/Magadan','Asia/Makassar','Asia/Manila','Asia/Muscat','Asia/Nicosia','Asia/Novokuznetsk','Asia/Novosibirsk','Asia/Omsk','Asia/Oral','Asia/Phnom_Penh','Asia/Pontianak','Asia/Pyongyang','Asia/Qatar','Asia/Qyzylorda','Asia/Rangoon','Asia/Riyadh','Asia/Sakhalin','Asia/Samarkand','Asia/Seoul','Asia/Shanghai','Asia/Singapore','Asia/Srednekolymsk','Asia/Taipei','Asia/Tashkent','Asia/Tbilisi','Asia/Tehran','Asia/Thimphu','Asia/Tokyo','Asia/Ulaanbaatar','Asia/Urumqi','Asia/Ust-Nera','Asia/Vientiane','Asia/Vladivostok','Asia/Yakutsk','Asia/Yekaterinburg','Asia/Yerevan','Atlantic/Azores','Atlantic/Bermuda','Atlantic/Canary','Atlantic/Cape_Verde','Atlantic/Faroe','Atlantic/Madeira','Atlantic/Reykjavik','Atlantic/South_Georgia','Atlantic/St_Helena','Atlantic/Stanley','Australia/Adelaide','Australia/Brisbane','Australia/Broken_Hill','Australia/Currie','Australia/Darwin','Australia/Eucla','Australia/Hobart','Australia/Lindeman','Australia/Lord_Howe','Australia/Melbourne','Australia/Perth','Australia/Sydney','Europe/Amsterdam','Europe/Andorra','Europe/Athens','Europe/Belgrade','Europe/Berlin','Europe/Bratislava','Europe/Brussels','Europe/Bucharest','Europe/Budapest','Europe/Busingen','Europe/Chisinau','Europe/Copenhagen','Europe/Dublin','Europe/Gibraltar','Europe/Guernsey','Europe/Helsinki','Europe/Isle_of_Man','Europe/Istanbul','Europe/Jersey','Europe/Kaliningrad','Europe/Kiev','Europe/Lisbon','Europe/Ljubljana','Europe/London','Europe/Luxembourg','Europe/Madrid','Europe/Malta','Europe/Mariehamn','Europe/Minsk','Europe/Monaco','Europe/Moscow','Europe/Oslo','Europe/Paris','Europe/Podgorica','Europe/Prague','Europe/Riga','Europe/Rome','Europe/Samara','Europe/San_Marino','Europe/Sarajevo','Europe/Simferopol','Europe/Skopje','Europe/Sofia','Europe/Stockholm','Europe/Tallinn','Europe/Tirane','Europe/Uzhgorod','Europe/Vaduz','Europe/Vatican','Europe/Vienna','Europe/Vilnius','Europe/Volgograd','Europe/Warsaw','Europe/Zagreb','Europe/Zaporozhye','Europe/Zurich','Indian/Antananarivo','Indian/Chagos','Indian/Christmas','Indian/Cocos','Indian/Comoro','Indian/Kerguelen','Indian/Mahe','Indian/Maldives','Indian/Mauritius','Indian/Mayotte','Indian/Reunion','Pacific/Apia','Pacific/Auckland','Pacific/Bougainville','Pacific/Chatham','Pacific/Chuuk','Pacific/Easter','Pacific/Efate','Pacific/Enderbury','Pacific/Fakaofo','Pacific/Fiji','Pacific/Funafuti','Pacific/Galapagos','Pacific/Gambier','Pacific/Guadalcanal','Pacific/Guam','Pacific/Honolulu','Pacific/Johnston','Pacific/Kiritimati','Pacific/Kosrae','Pacific/Kwajalein','Pacific/Majuro','Pacific/Marquesas','Pacific/Midway','Pacific/Nauru','Pacific/Niue','Pacific/Norfolk','Pacific/Noumea','Pacific/Pago_Pago','Pacific/Palau','Pacific/Pitcairn','Pacific/Pohnpei','Pacific/Port_Moresby','Pacific/Rarotonga','Pacific/Saipan','Pacific/Tahiti','Pacific/Tarawa','Pacific/Tongatapu','Pacific/Wake','Pacific/Wallis','UTC'];
}
})();
}());
......@@ -225,7 +225,8 @@ if($(this).is(":checked")){purchase.nextWeek.push(user);}
else{$.each(purchase.nextWeek,function(i,item){if(item===user){purchase.nextWeek.splice(i,1);return false;}});}
if(dobrado.localStorage){localStorage.purchase=JSON.stringify(purchase);}
$(".purchase .save").button("option","disabled",false);dobrado.account.preventLogout=true;}
function resetForm(){$("#purchase-product-input").val("").focus();$("#purchase-grower-info").html("");$("#purchase-quota-info").html("");$("#purchase-price-input").val("");$("#purchase-quantity-input").val("");$('.purchase-quantity-info').html('');currentProduct=null;}
function resetForm(){if(viewPurchases){$('#purchase-product-input').focus();}
$('#purchase-product-input').val('');$('#purchase-grower-info').html('');$('#purchase-quota-info').html('');$('#purchase-price-input').val('');$('#purchase-quantity-input').val('');$('.purchase-quantity-info').html('');currentProduct=null;}
function viewAll(){var user=$("#purchase-name-input").val();var label="View all";if(!purchase){return false;}
if(viewPurchases){viewPurchases=false;label=orderMode?"View orders only":"View purchases only";$("#purchase-form .view-all").button("option","label",label);$("#purchase-form .remove").hide();$("#purchase-form .add").hide();$(".purchase-quantity-info").parent().hide();$("#purchase-price-input").parent().hide();if(user===""&&currentProduct){viewAllUsers();}
else{viewAllAvailable(user);}}
......
......@@ -1509,11 +1509,15 @@ if (!this.dobrado.purchase) {
}
function resetForm() {
$("#purchase-product-input").val("").focus();
$("#purchase-grower-info").html("");
$("#purchase-quota-info").html("");
$("#purchase-price-input").val("");
$("#purchase-quantity-input").val("");
// Don't move focus when editing in the grid as it scrolls the page.
if (viewPurchases) {
$('#purchase-product-input').focus();
}
$('#purchase-product-input').val('');
$('#purchase-grower-info').html('');
$('#purchase-quota-info').html('');
$('#purchase-price-input').val('');
$('#purchase-quantity-input').val('');
$('.purchase-quantity-info').html('');
currentProduct = null;
}
......
......@@ -160,7 +160,8 @@ else{$(".sell .done").button("option","disabled",true);$(".sell-finished").dialo
else if(sell.processed.length>1){html+=" (currently <b>"+sell.processed.length+"</b> sales require saving)";}
html+=".";$(".sell .warning").html(html);resetForm();sell.data[++user]=[];}
return false;}
function resetForm(){$("#purchase-product-input").val("").focus();$("#purchase-grower-info").html("");$("#purchase-price-input").val("");$("#purchase-quantity-input").val("");currentProduct=null;}
function resetForm(){if(viewPurchases){$('#purchase-product-input').focus();}
$('#purchase-product-input').val('');$('#purchase-grower-info').html('');$('#purchase-price-input').val('');$('#purchase-quantity-input').val('');currentProduct=null;}
function viewAll(){var username=$("#purchase-name-input").val();var label="View all";if(viewPurchases){viewPurchases=false;label="View purchases only";$("#purchase-form .view-all").button("option","label",label);viewAllAvailable(username);}
else{viewPurchases=true;$("#purchase-form .view-all").button("option","label",label);$(".purchase-all-users").hide();if(sell.data[user]){if(purchaseGrid&&sell.data[user].length!==0){$(purchaseGridId).show();purchaseGrid.setData(sell.data[user]);purchaseGrid.updateRowCount();purchaseGrid.render();purchaseGrid.setSelectedRows([]);}}
if(allAvailableGrid){allAvailableGrid.gotoCell(0,0);$(allAvailableGridId).hide();}}
......
......@@ -1066,10 +1066,14 @@ if (!this.dobrado.sell) {
}
function resetForm() {
$("#purchase-product-input").val("").focus();
$("#purchase-grower-info").html("");
$("#purchase-price-input").val("");
$("#purchase-quantity-input").val("");
// Don't move focus when editing in the grid as it scrolls the page.
if (viewPurchases) {
$('#purchase-product-input').focus();
}
$('#purchase-product-input').val('');
$('#purchase-grower-info').html('');
$('#purchase-price-input').val('');
$('#purchase-quantity-input').val('');
currentProduct = null;
}
......
......@@ -271,4 +271,5 @@ var profile=JSON.parse(response);if(dobrado.localStorage){if(profile.columns){lo
if(profile.sort){localStorage.stockSortColumns=JSON.stringify(profile.sort);}
localStorage.stockProfile=value;}
showAll(true);});}}
dobrado.stock.addUser=function(user){$('#stock-user-input').val(user);stock.users.push(user);updateNames();$.post('/php/request.php',{request:'stock',action:'updateGroup',supplier:user,url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,'stock updateGroup')){return;}});};}());
\ No newline at end of file
dobrado.stock.addUser=function(user){$('#stock-user-input').val(user);stock.users.push(user);updateNames();$.post('/php/request.php',{request:'stock',action:'updateGroup',supplier:user,url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,'stock updateGroup')){return;}
var supplier=JSON.parse(response);$('#stock-import-supplier').html(supplier.options).selectmenu('refresh');});};}());
\ No newline at end of file
......@@ -2298,6 +2298,10 @@ if (!this.dobrado.stock) {
if (dobrado.checkResponseError(response, 'stock updateGroup')) {
return;
}
var supplier = JSON.parse(response);
// Also use this callback to return the import supplier list.
$('#stock-import-supplier').html(supplier.options).
selectmenu('refresh');
});
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment