Skip to content

Commit

Permalink
Merge pull request #37 from rogerpueyo/fix36
Browse files Browse the repository at this point in the history
Fix issue #36
  • Loading branch information
miquelmartos authored May 21, 2017
2 parents afee5a5 + b1a64df commit a1dbe9d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion guifi_api.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
25 changes: 25 additions & 0 deletions guifi_includes.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a1dbe9d

Please sign in to comment.