/** * Updates shippers and shipments that have been changed in the form * * Backend use only. * @return boolean True on success, false an failure, * null on noop. * @static */ static function update_shipments_from_post() { if (empty($_POST['bshipment'])) { return null; } $success = true; $changed = false; // Update all shipment conditions if (!empty($_POST['max_weight'])) { foreach ($_POST['max_weight'] as $shipment_id => $max_weight) { $max_weight = Weight::getWeight(contrexx_input2raw($max_weight)); $shipper_id = intval($_POST['sid'][$shipment_id]); $fee = floatval($_POST['fee'][$shipment_id]); $free_from = floatval($_POST['free_from'][$shipment_id]); if ($max_weight == Weight::getWeight(self::$arrShipments[$shipper_id][$shipment_id]['max_weight']) && $free_from == self::$arrShipments[$shipper_id][$shipment_id]['free_from'] && $fee == self::$arrShipments[$shipper_id][$shipment_id]['fee']) { continue; } //DBG::log("Shipment::update_shipments_from_post(): max_weight $max_weight == ".self::$arrShipments[$shipper_id][$shipment_id]['max_weight'].", free_from $free_from == ".self::$arrShipments[$shipper_id][$shipment_id]['free_from'].", fee $fee == ".self::$arrShipments[$shipper_id][$shipment_id]['fee']); $changed = true; $success &= self::_update_shipment($shipment_id, $shipper_id, $fee, $free_from, $max_weight); } } foreach ($_POST['shipper_name'] as $shipper_id => $shipper_name) { $shipper_name = contrexx_input2raw($shipper_name); $active = !empty($_POST['active'][$shipper_id]); $zone_id = intval($_POST['zone_id'][$shipper_id]); $zone_id_old = Zones::getZoneIdByShipperId($shipper_id); if ($shipper_name == self::$arrShippers[$shipper_id]['name'] && $active == self::$arrShippers[$shipper_id]['active'] && $zone_id == $zone_id_old) { continue; } $changed = true; $success &= self::_update_shipper($shipper_id, $active); $success &= self::_rename_shipper($shipper_id, $shipper_name); $success &= Zones::update_shipper_relation($zone_id, $shipper_id); } if ($changed) { return $success; } return null; }