Commit 4c3a0c1e authored by Johan Cwiklinski's avatar Johan Cwiklinski
Browse files

Merge branch '9.5/bugfixes'

parents bf46e02a b7457cbb
......@@ -41,14 +41,6 @@ Html::header_nocache();
Session::checkLoginUser();
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
// Get AJAX input and load it into $_REQUEST
$input = file_get_contents('php://input');
parse_str($input, $_REQUEST);
}
$_REQUEST = Toolbox::clean_cross_side_scripting_deep($_REQUEST);
if (!isset($_REQUEST['action'])) {
Toolbox::logError("Missing action parameter");
http_response_code(400);
......@@ -129,7 +121,8 @@ if ($_REQUEST['action'] === 'update') {
$item = new $itemtype();
$inputs = [];
parse_str($_REQUEST['inputs'], $inputs);
$item->add($inputs);
$item->add(Toolbox::clean_cross_side_scripting_deep($inputs));
} else if ($_REQUEST['action'] === 'bulk_add_item') {
$checkParams(['inputs']);
$item = new $itemtype();
......@@ -142,7 +135,7 @@ if ($_REQUEST['action'] === 'update') {
foreach ($bulk_item_list as $item_entry) {
$item_entry = trim($item_entry);
if (!empty($item_entry)) {
$item->add($inputs + ['name' => $item_entry]);
$item->add(Toolbox::clean_cross_side_scripting_deep($inputs + ['name' => $item_entry]));
}
}
}
......
......@@ -2407,6 +2407,9 @@ abstract class API {
$hclasses[] = "Item_Ticket";
$hclasses[] = "ITILSolution";
$hclasses[] = "ITILFollowup";
$hclasses[] = "Ticket_User";
$hclasses[] = "Group_Ticket";
$hclasses[] = "Supplier_Ticket";
break;
case 'Problem' :
......@@ -2417,6 +2420,9 @@ abstract class API {
$hclasses[] = "Item_Problem";
$hclasses[] = "ITILSolution";
$hclasses[] = "ITILFollowup";
$hclasses[] = "Problem_User";
$hclasses[] = "Group_Problem";
$hclasses[] = "Supplier_Problem";
break;
case 'Change' :
......@@ -2428,6 +2434,9 @@ abstract class API {
$hclasses[] = "Change_Item";
$hclasses[] = "ITILSolution";
$hclasses[] = "ITILFollowup";
$hclasses[] = "Change_User";
$hclasses[] = "Group_Change";
$hclasses[] = "Supplier_Change";
break;
case 'Project' :
......
......@@ -4658,13 +4658,13 @@ class CommonDBTM extends CommonGLPI {
return $searchoptions['toadd'][$value];
}
if ($options['html']) {
return Dropdown::getValueWithUnit(Html::formatNumber($value, false, 0), $unit);
return Dropdown::getValueWithUnit($value, $unit);
}
return $value;
case "decimal" :
if ($options['html']) {
return Dropdown::getValueWithUnit(Html::formatNumber($value), $unit);
return Dropdown::getValueWithUnit($value, $unit, $CFG_GLPI["decimal_number"]);
}
return $value;
......
......@@ -1523,53 +1523,57 @@ class Dropdown {
*
* @since 0.84
*
* @param $value integer number of item
* @param $unit string of unit (maybe year, month, day, hour, % for standard management)
* @param integer $value numeric value
* @param string $unit unit (maybe year, month, day, hour, % for standard management)
* @param integer $decimals number of decimal
**/
static function getValueWithUnit($value, $unit) {
static function getValueWithUnit($value, $unit, $decimals = 0) {
$formatted_number = is_numeric($value)
? Html::formatNumber($value, false, $decimals)
: $value;
if (strlen($unit) == 0) {
return $value;
return $formatted_number;
}
switch ($unit) {
case 'year' :
//TRANS: %d is a number of years
return sprintf(_n('%d year', '%d years', $value), $value);
//TRANS: %s is a number of years
return sprintf(_n('%s year', '%s years', $value), $formatted_number);
case 'month' :
//TRANS: %d is a number of months
return sprintf(_n('%d month', '%d months', $value), $value);
//TRANS: %s is a number of months
return sprintf(_n('%s month', '%s months', $value), $formatted_number);
case 'day' :
//TRANS: %d is a number of days
return sprintf(_n('%d day', '%d days', $value), $value);
//TRANS: %s is a number of days
return sprintf(_n('%s day', '%s days', $value), $formatted_number);
case 'hour' :
//TRANS: %d is a number of hours
return sprintf(_n('%d hour', '%d hours', $value), $value);
//TRANS: %s is a number of hours
return sprintf(_n('%s hour', '%s hours', $value), $formatted_number);
case 'minute' :
//TRANS: %d is a number of minutes
return sprintf(_n('%d minute', '%d minutes', $value), $value);
//TRANS: %s is a number of minutes
return sprintf(_n('%s minute', '%s minutes', $value), $formatted_number);
case 'second' :
//TRANS: %d is a number of seconds
return sprintf(_n('%d second', '%d seconds', $value), $value);
//TRANS: %s is a number of seconds
return sprintf(_n('%s second', '%s seconds', $value), $formatted_number);
case 'millisecond' :
//TRANS: %d is a number of milliseconds
return sprintf(_n('%d millisecond', '%d milliseconds', $value), $value);
//TRANS: %s is a number of milliseconds
return sprintf(_n('%s millisecond', '%s milliseconds', $value), $formatted_number);
case 'auto':
$value = str_replace([' ', ' '], ['', ''], $value); // unformat value
return Toolbox::getSize($value*1024*1024);
return Toolbox::getSize($value*1024*1024);
case '%' :
return sprintf(__('%d%%'), $value);
return sprintf(__('%s%%'), $formatted_number);
default :
return sprintf(__('%1$s %2$s'), $value, $unit);
return sprintf(__('%1$s %2$s'), $formatted_number, $unit);
}
}
......
......@@ -6417,9 +6417,7 @@ JAVASCRIPT;
&& isset($so['toadd'][$data[$ID][$k]['name']])) {
$out .= $so['toadd'][$data[$ID][$k]['name']];
} else {
$number = str_replace(' ', ' ',
Html::formatNumber($data[$ID][$k]['name'], false, 0));
$out .= Dropdown::getValueWithUnit($number, $unit);
$out .= Dropdown::getValueWithUnit($data[$ID][$k]['name'], $unit);
}
}
}
......@@ -6439,9 +6437,7 @@ JAVASCRIPT;
&& isset($so['toadd'][$data[$ID][$k]['name']])) {
$out .= $so['toadd'][$data[$ID][$k]['name']];
} else {
$number = str_replace(' ', ' ',
Html::formatNumber($data[$ID][$k]['name']));
$out .= Dropdown::getValueWithUnit($number, $unit);
$out .= Dropdown::getValueWithUnit($data[$ID][$k]['name'], $unit, $CFG_GLPI["decimal_number"]);
}
}
}
......
......@@ -818,7 +818,6 @@ class GLPIKanbanRights {
itemtype: self.item.itemtype,
items_id: items_id
},
contentType: 'application/json',
success: function(url) {
window.location = url;
}
......@@ -1097,7 +1096,6 @@ class GLPIKanbanRights {
column_field: self.column_field.id,
column_value: column_id
},
contentType: 'application/json',
error: function() {
$(sortable).sortable('cancel');
return false;
......@@ -1145,7 +1143,6 @@ class GLPIKanbanRights {
position: position,
kanban: self.item
},
contentType: 'application/json',
error: function() {
if (error) {
error();
......@@ -1210,7 +1207,6 @@ class GLPIKanbanRights {
column: column,
kanban: self.item
},
contentType: 'application/json',
complete: function() {
$.each(self.user_state.state, function(i, c) {
if (parseInt(c['column']) === parseInt(column)) {
......@@ -1238,7 +1234,6 @@ class GLPIKanbanRights {
column: column,
kanban: self.item
},
contentType: 'application/json',
complete: function() {
$(getColumnElementFromID(column)).remove();
$.each(self.user_state.state, function(i, c) {
......@@ -1267,8 +1262,7 @@ class GLPIKanbanRights {
column: column,
position: position,
kanban: self.item
},
contentType: 'application/json'
}
});
};
......@@ -1294,9 +1288,7 @@ class GLPIKanbanRights {
data: {
users_id: [items_id],
size: self.team_image_size,
},
contentType: 'application/json',
dataType: 'json'
}
}).done(function(data) {
if (data[items_id] !== undefined) {
user_img = data[items_id];
......@@ -1365,9 +1357,7 @@ class GLPIKanbanRights {
data: {
users_id: Object.keys(users),
size: self.team_image_size
},
contentType: 'application/json',
dataType: 'json'
}
}).done(function(data) {
Object.keys(users).forEach(function(user_id) {
const teammember = users[user_id];
......@@ -1823,9 +1813,7 @@ class GLPIKanbanRights {
itemtype: self.item.itemtype,
items_id: self.item.items_id,
column_field: self.column_field.id
},
contentType: 'application/json',
dataType: 'json'
}
}).done(function(columns, textStatus, jqXHR) {
preloadBadgeCache({
trim_cache: true
......@@ -2053,8 +2041,7 @@ class GLPIKanbanRights {
action: action,
column: getColumnIDFromElement(column_el),
kanban: self.item
},
contentType: 'application/json'
}
});
};
......@@ -2092,8 +2079,6 @@ class GLPIKanbanRights {
$.ajax({
method: 'GET',
url: (self.ajax_root + "kanban.php"),
contentType: 'application/json',
dataType: 'json',
async: false,
data: {
action: "get_column",
......@@ -2133,8 +2118,6 @@ class GLPIKanbanRights {
$.ajax({
method: 'POST',
url: (self.ajax_root + "kanban.php"),
contentType: 'application/json',
dataType: 'json',
data: {
action: "create_column",
itemtype: self.item.itemtype,
......@@ -2199,8 +2182,7 @@ class GLPIKanbanRights {
itemtype: self.item.itemtype,
items_id: self.item.items_id,
last_load: self.last_refresh
},
contentType: 'application/json'
}
}).done(function(state) {
if (state['state'] === undefined || state['state'] === null || Object.keys(state['state']).length === 0) {
if (callback) {
......@@ -2274,8 +2256,7 @@ class GLPIKanbanRights {
itemtype: self.item.itemtype,
items_id: self.item.items_id,
state: self.user_state.state
},
contentType: 'application/json'
}
}).done(function(data, textStatus, jqXHR) {
self.user_state.is_dirty = false;
if (success) {
......@@ -2333,7 +2314,6 @@ class GLPIKanbanRights {
itemtype: self.item.itemtype,
items_id: self.item.items_id
},
contentType: 'application/json',
success: function($data) {
const switcher = $(self.element + " .kanban-toolbar select[name='kanban-board-switcher']");
switcher.replaceWith($data);
......
......@@ -275,34 +275,43 @@ class Dropdown extends DbTestCase {
public function dataGetValueWithUnit() {
return [
[1, 'auto', '1024 Kio'],
[1025, 'auto', '1 Gio'],
['1 025', 'auto', '1 Gio'],
[1, 'year', '1 year'],
[2, 'year', '2 years'],
[3, '%', '3%'],
['foo', 'bar', 'foo bar'],
[1, 'month', '1 month'],
[2, 'month', '2 months'],
['any', '', 'any'],
[1, 'day', '1 day'],
[2, 'day', '2 days'],
[1, 'hour', '1 hour'],
[2, 'hour', '2 hours'],
[1, 'minute', '1 minute'],
[2, 'minute', '2 minutes'],
[1, 'second', '1 second'],
[2, 'second', '2 seconds'],
[1, 'millisecond', '1 millisecond'],
[2, 'millisecond', '2 milliseconds'],
[1, 'auto', null, '1024 Kio'],
[1, 'auto', null, '1024 Kio'],
[1025, 'auto', null, '1 Gio'],
[1, 'year', null, '1 year'],
[2, 'year', null, '2 years'],
[3, '%', null, '3%'],
['foo', 'bar', null, 'foo bar'],
[1, 'month', null, '1 month'],
[2, 'month', null, '2 months'],
['any', '', null, 'any'],
[1, 'day', null, '1 day'],
[2, 'day', null, '2 days'],
[1, 'hour', null, '1 hour'],
[2, 'hour', null, '2 hours'],
[1, 'minute', null, '1 minute'],
[2, 'minute', null, '2 minutes'],
[1, 'second', null, '1 second'],
[2, 'second', null, '2 seconds'],
[1, 'millisecond', null, '1 millisecond'],
[2, 'millisecond', null, '2 milliseconds'],
[10, 'bar', null, '10 bar'],
[3.3597, '%', 0, '3%'],
[3.3597, '%', 2, '3.36%'],
[3.3597, '%', 6, '3.359700%'],
[3579, 'day', 0, '3 579 days'],
];
}
/**
* @dataProvider dataGetValueWithUnit
*/
public function testGetValueWithUnit($input, $unit, $expected) {
$this->string(\Dropdown::getValueWithUnit($input, $unit))->isIdenticalTo($expected);
public function testGetValueWithUnit($input, $unit, $decimals, $expected) {
$value = $decimals !== null
? \Dropdown::getValueWithUnit($input, $unit, $decimals)
: \Dropdown::getValueWithUnit($input, $unit);
$this->string($value)->isIdenticalTo($expected);
}
protected function getDropdownValueProvider() {
......
Supports Markdown
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