<?php
/**
 * Cusotmers controlls the actions for customers
 */
class CustomersController{
    private $model;

    function __construct(){
        $this->model = new CustomersModel();
    }

    /**
     * get all commecrial lead customers linked to package
     * @return json list with commercial lead customers
     */
    public function getComercialLeadCustomers(){
        echo json_encode($this->model->getComercialLeadCustomers());
    }

    /**
     * returns all the order types existing in the application
     * @return Array with all order types
     */
    public function getOrderTypes() {
        echo json_encode($this->model->getOrderTypes());
    }

    /**
     * save default order type for cl
     * @return Array update emssage
     */
    public function saveDefaultOrderType() {
        $defaultIdOrderType = isset($_REQUEST['defaultIdOrderType']) ? $_REQUEST['defaultIdOrderType'] : 0;
        echo json_encode($this->model->saveDefaultOrderType($defaultIdOrderType));
    }

    /**
     * dave order type for each custoemr
     * @return Array update message
     */
    public function saveCustomersOrderTypes() {
        $customers = isset($_REQUEST['customers']) ? $_REQUEST['customers'] : '[]';
        echo json_encode($this->model->saveCustomersOrderTypes($customers));
    }

    /**
     * include customers template
     */
    public function customersTemplate(){
        global $user;
        require_once('templates/CustomersTemplate.php');
    }

    /**
     * include custoemrs view template
     */
    public function customersViewTemplate(){
        require_once('templates/CustomersViewTemplate.php');
    }

    /**
     * open custoemrs page
     */
    public function showPage(){
        require_once('CustomersPage.php');
    }
}
