<?php

if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

class chunk_c_install extends CI_Model implements chunk_interface
{

    public function get_admin_html()
    {
        return '<div class="control-group"><div class="controls">'
                . form_checkbox('create_c_install_file', '1', $this->input->post('create_c_install_file')) . ' ' . $this->lang->line('Create install controller')
                . '</div></div>';
    }

    public function run()
    {
        // Create install controller
        if ($this->input->post('create_c_install_file')) {
            $conInstFolder = $this->skeleton_model_admin->getModuleFolder() . '/controllers';
            if (!$this->skeleton_model_admin->createFolder($conInstFolder)) {

                return FALSE;
            }
            if (!$this->createInstallControllerFile($conInstFolder)) {

                return FALSE;
            }
        }
    }

    protected function createInstallControllerFile($conInstFolder)
    {
        $moduleName = $this->input->post('moduleName');
        $source = str_replace('MODULE', $moduleName, file_get_contents($this->skeleton_model_admin->getSrcFolder() . '/controllers/install.php'));

        return $this->skeleton_model_admin->createFile($conInstFolder . '/' . $moduleName . '_install.php', $source);
    }

}
