public function put_array($array) { $reflector = new ReflectionClass(get_class($this)); $measurement = $reflector->newInstance(); if (!empty($array["id"])) { $measurement = apiDB::getMeasurement($array["id"], get_class($this)); } else { if (empty($array["locationid"])) { //Throwing this error before calling getUserByLocationId() below. return "Error: Location ID has to be specified if measurement ID is not set"; } } $locid = empty($array["locationid"]) ? $measurement->locationid : $array["locationid"]; $user = apiDB::getUserByLocationId($locid); if ($_SERVER['PHP_AUTH_USER'] != $user->email && $this->access <= 1) { return "Not authorized to add measurements to location " . $locid; } $measurement->reading = empty($array[$measurement->columnName()]) ? $measurement->reading : $array[$measurement->columnName()]; $measurement->fromdate = empty($array["fromdate"]) ? $measurement->fromdate : $array["fromdate"]; $measurement->todate = empty($array["todate"]) ? $measurement->todate : $array["todate"]; $measurement->locationid = empty($array["locationid"]) ? $measurement->locationid : $array["locationid"]; $measurement->note = empty($array["note"]) ? $measurement->note : $array["note"]; if (empty($measurement->id)) { return apiDB::addMeasurement($measurement); } else { return apiDB::updateMeasurement($measurement->id, $measurement); } }