/**
  * Check the SugarDepot for updates for the given type as passed in via POST
  * @param type      the type to check for
  * @return array    return an array of releases for each given installed object if an update is found
  */
 function checkForUpdates()
 {
     $json = getJSONobj();
     $type = '';
     if (isset($_REQUEST['type'])) {
         $type = nl2br($_REQUEST['type']);
     }
     $pm = new PackageManager();
     $updates = $pm->checkForUpdates();
     $nodes = array();
     $release_map = array();
     if (!empty($updates)) {
         foreach ($updates as $update) {
             $update = PackageManager::fromNameValueList($update);
             $nodes[] = array('label' => $update['name'], 'description' => $update['description'], 'version' => $update['version'], 'build_number' => $update['build_number'], 'id' => $update['id'], 'type' => $update['type']);
             $release_map[$update['id']] = array('package_id' => $update['package_id'], 'category_id' => $update['category_id'], 'type' => $update['type']);
         }
     }
     //patches
     $filter = array(array('name' => 'type', 'value' => "'patch'"));
     $releases = $pm->getReleases('', '', $filter);
     if (!empty($releases['packages'])) {
         foreach ($releases['packages'] as $update) {
             $update = PackageManager::fromNameValueList($update);
             $nodes[] = array('label' => $update['name'], 'description' => $update['description'], 'version' => $update['version'], 'build_number' => $update['build_number'], 'id' => $update['id'], 'type' => $update['type']);
             $release_map[$update['id']] = array('package_id' => $update['package_id'], 'category_id' => $update['category_id'], 'type' => $update['type']);
         }
     }
     $_SESSION['ML_PATCHES'] = $release_map;
     echo 'result = ' . $json->encode(array('updates' => $nodes));
 }