public function index()
    {
        if (!userHasPermission('admin:cdn:utilities:findOrphan')) {
            unauthorised();
        }

        // --------------------------------------------------------------------------

        $oInput = Factory::service('Input');
        if ($oInput::isCli()) {
            $this->indexCli();
        } else {

            if ($oInput->post()) {

                //  A little form validation
                $type   = $oInput->post('type');
                $parser = $oInput->post('parser');
                $error  = '';

                if ($type == 'db' && $parser == 'create') {
                    $error = 'Cannot use "Add to database" results parser when finding orphaned database objects.';
                }

                if (empty($error)) {

                    switch ($type) {

                        case 'db':

                            $oCdn                  = Factory::service('Cdn', 'nails/module-cdn');
                            $this->data['orphans'] = $oCdn->findOrphanedObjects();
                            break;

                        //  @TODO
                        case 'file':

                            $this->data['message'] = '<strong>TODO:</strong> find orphaned files.';
                            break;

                        //  Invalid request
                        default:

                            $this->data['error'] = 'Invalid search type.';
                            break;
                    }

                    if (isset($this->data['orphans'])) {

                        switch ($parser) {

                            case 'list':

                                $this->data['success'] = '<strong>Search complete!</strong> your results are show below.';
                                break;

                            //  @todo: keep the unset(), it prevents the table from rendering
                            case 'purge':

                                $this->data['message'] = '<strong>TODO:</strong> purge results.';
                                unset($this->data['orphans']);
                                break;

                            case 'create':

                                $this->data['message'] = '<strong>TODO:</strong> create objects using results.';
                                unset($this->data['orphans']);
                                break;

                            //  Invalid request
                            default:

                                $this->data['error'] = 'Invalid result parse selected.';
                                unset($this->data['orphans']);
                                break;
                        }
                    }

                } else {

                    $this->data['error'] = 'An error occurred. ' . $error;
                }
            }

            // --------------------------------------------------------------------------

            $this->data['page']->title = 'CDN: Find Orphaned Objects';

            // --------------------------------------------------------------------------

            Helper::loadView('index');
        }
    }