<?php

require_once '../commons/base.inc.php';
try {
    $Host = $FOGCore->getHostItem();
    // Try and get the task.
    $Task = $Host->get('task');
    // Work on the current Snapin Task.
    $SnapinTask = new SnapinTask($_REQUEST['taskid']);
    if (!$SnapinTask->isValid()) {
        throw new Exception('#!ns');
    }
    //Get the snapin to work off of.
    $Snapin = new Snapin($SnapinTask->get('snapinID'));
    // Find the Storage Group
    if ($Snapin && $Snapin->getStorageGroup() && $Snapin->isValid() && $Snapin->getStorageGroup()->isValid()) {
        $StorageGroup = $Snapin->getStorageGroup();
    }
    // Allow plugins to enact against this. (e.g. location)
    $HookManager->processEvent('SNAPIN_GROUP', array('Host' => &$Host, 'StorageGroup' => &$StorageGroup));
    // Assign the file for sending.
    if (!$StorageGroup || !$StorageGroup->isValid()) {
        if (file_exists(rtrim($FOGCore->getSetting('FOG_SNAPINDIR'), '/') . '/' . $Snapin->get('file'))) {
            $SnapinFile = rtrim($FOGCore->getSetting('FOG_SNAPINDIR'), '/') . '/' . $Snapin->get('file');
        } elseif (file_exists($Snapin->get('file'))) {
            $SnapinFile = $Snapin->get('file');
        }
    } else {
        $StorageNode = $StorageGroup->getMasterStorageNode();
        // Allow plugins to enact against this. (e.g. location)
        $HookManager->processEvent('SNAPIN_NODE', array('Host' => &$Host, 'StorageNode' => &$StorageNode));