/**
  * Used as a helper for simple conditional fieldset administration,
  * this function returns an array of lookup ids (Metadata->id) for
  * each of the columns/fields that this lookup's column affects.
  *
  * Return value:
  *
  * Associative array keyed by field_id, value is an array of lookup
  * ids.
  *
  * array(
  *      1 => array(1, 2, 3, 4),
  *      ...
  * );
  */
 function getNextValuesForLookup($oLookup)
 {
     /* 
      * GENERAL GAME PLAN
      *
      * Get the instance attached to the lookup, and and call
      * getNextValuesForBehaviour on its behaviour.
      *
      * If there's no instance or behaviour, return an empty array
      * for each field that the lookup's field affects.
      */
     $oLookup =& KTUtil::getObject('MetaData', $oLookup);
     $oInstance =& KTValueInstance::getByLookupSingle($oLookup);
     if (PEAR::isError($oInstance)) {
         $GLOBALS['default']->log->error('KTMetadataUtil::getNextValuesForLookup, got dud instance id, returned: ' . print_r($oInstance, true));
         return $oInstance;
     }
     if (!is_null($oInstance) && $oInstance->getBehaviourId()) {
         // if we have an instance, and we have a behaviour, return
         // the actual values for that behaviour.
         $oBehaviour =& KTFieldBehaviour::get($oInstance->getBehaviourId());
         if (PEAR::isError($oBehaviour)) {
             $GLOBALS['default']->log->error('KTMetadataUtil::getNextValuesForLookup, got dud behaviour id, returned: ' . print_r($oBehaviour, true));
             return $res;
         }
         return KTMetadataUtil::getNextValuesForBehaviour($oBehaviour);
     }
     // No instance or no behaviour, so send an empty array for each
     // field that we affect.
     $aChildFieldIds = KTMetadataUtil::getChildFieldIds($oLookup->getDocFieldId());
     if (PEAR::isError($aChildFieldIds)) {
         $GLOBALS['default']->log->error('KTMetadataUtil::getNextValuesForLookup, getChildFieldIds returned: ' . print_r($aChildFieldIds, true));
         return $res;
     }
     foreach ($aChildFieldIds as $iFieldId) {
         $aValues[$iFieldId] = array();
     }
     return $aValues;
 }