<?php
class ControllerModuleHelloworld extends Controller {
private $error = array(); // This is used to set the errors, if any.
public function install(){
$sql = "ALTER TABLE " . DB_PREFIX . "customer ADD `gender` VARCHAR(1) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT 'm'";
$this->db->query($sql);
}
public function uninstall(){
$sql = "ALTER TABLE `" . DB_PREFIX . "customer` DROP `gender`";
$this->db->query($sql);
}
public function index() { // Default function
$this->language->load('extension/module/helloworld'); // Loading the language file of helloworld
$this->document->setTitle($this->language->get('heading_title')); // Set the title of the page to the heading title in the Language file i.e., Hello World
$this->load->model('setting/setting'); // Load the Setting Model (All of the OpenCart Module & General Settings are saved using this Model )
$this->load->model('design/layout');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { // Start If: Validates and check if data is coming by save (POST) method
$this->model_setting_setting->editSetting('modual_helloworld', $this->request->post); // Parse all the coming data to Setting Model to save it in database.
$this->session->data['success'] = $this->language->get('text_success'); // To display the success text on data save
$this->response->redirect($this->url->link('marketplace/extension' . '&type=module', 'user_token=' . $this->session->data['user_token'], true));
// $this->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL')); // Redirect to the Module Listing
} // End If
/*Assign the language data for parsing it to view*/
$data['action'] = $this->url->link('extension/module/helloworld', 'user_token=' . $this->session->data['user_token'], true); // URL to be directed when the save button is pressed
$data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true); // URL to be redirected when cancel button is pressed
/* This block checks, if the hello world text field is set it parses it to view otherwise get the default hello world text field from the database and parse it*/
if (isset($this->request->post['module_helloworld_status'])) {
$data['module_helloworld_status'] = $this->request->post['module_helloworld_status'];
} else {
$data['module_helloworld_status'] = $this->config->get('module_helloworld_status');
}
/* End Block*/
$this->data['modules'] = array();
/* This block parses the Module Settings such as Layout, Position,Status & Order Status to the view*/
if (isset($this->request->post['helloworld_module'])) {
$data['modules'] = $this->request->post['helloworld_module'];
} elseif ($this->config->get('helloworld_module')) {
$data['modules'] = $this->config->get('helloworld_module');
}
/* End Block*/
$this->load->model('design/layout'); // Loading the Design Layout Models
$this->data['layouts'] = $this->model_design_layout->getLayouts(); // Getting all the Layouts available on system
$this->template = 'module/helloworld.tpl'; // Loading the helloworld.tpl template
$this->children = array(
'common/header',
'common/footer'
); // Adding children to our default template i.e., helloworld.tpl
/* Function that validates the data when Save Button is pressed */
protected function validate() {
/* Block to check the user permission to manipulate the module*/
if (!$this->user->hasPermission('modify', 'extension/module/helloworld')) {
$this->error['warning'] = $this->language->get('error_permission');
}
/* End Block*/
return !$this->error;
/* End Block*/
}
/* End Validation Function*/
}