diff --git a/guifi_api.inc.php b/guifi_api.inc.php index ead773f..8c68d71 100644 --- a/guifi_api.inc.php +++ b/guifi_api.inc.php @@ -573,7 +573,7 @@ function _guifi_api_device_check_parameters($gapi, &$parameters) { return FALSE; } $model = db_fetch_object(db_query("SELECT model name FROM {guifi_model_specs} WHERE mid = '%d' LIMIT 1", $model_id)); - if (!guifi_validate_types('firmware', $firmware, $model->name)) { + if (true &&!guifi_validate_firmware($firmware, $model_id, $gapi)) { $gapi->addError(403, "firmware is not supported: $firmware"); return FALSE; } diff --git a/guifi_includes.inc.php b/guifi_includes.inc.php index 5fd60bc..5a54812 100644 --- a/guifi_includes.inc.php +++ b/guifi_includes.inc.php @@ -172,6 +172,31 @@ function guifi_types($type,$start = 24,$end = 0,$relations = NULL) { return $values; } +/** +* Function guifi_validate_firmware +* +* This function true if a device model is compatible with a certain firmware, +* false otherwise. +* +* @param string $firmware The firmware name +* @param int $model_id The numeric id of the device model +* @return bool +*/ +function guifi_validate_firmware($firmware, $model_id) { + $fquery = db_query("SELECT {id} FROM {guifi_firmware} WHERE nom='%s' ORDER BY id", $firmware); + $flist = db_fetch_object($fquery); + + if (count($flist) == 1) { + $fmquery = db_query("SELECT COUNT(*) AS count FROM {guifi_configuracioUnSolclic} WHERE mid='%s' AND fid='%s' ORDER BY id", $model_id, $flist->id); + $fmlist = db_fetch_object($fmquery); + + if ($fmlist->count == 1) + return true; + } + + return false; +} + function guifi_validate_types($type, $text, $relations = NULL) { if ($relations == NULL) { $query = db_query("SELECT COUNT(*) AS count FROM {guifi_types} WHERE type='%s' AND text = '%s' ORDER BY id", $type, $text);