<?php

/*
 * PuzzleApp
 * Webemyos
 * Jérôme Oliva
 * GNU Licence
 */

namespace Apps\Asso;

use Core\Core\Core;
use Apps\Base\Base;
use Core\Core\Request;
use Core\Core\Response;

use Apps\Asso\Module\Admin\AdminController;



class Asso extends Base {

    /**
     * Author and version
     * */
    public $Author = 'Webemyos';
    public $Version = '1.0.0';

    /**
     * Constructeur
     * */
    function __construct() {
        $this->Core = Core::getInstance();
        parent::__construct($this->Core, "Asso");
    }

    /**
     * Set public route
     */
    function GetRoute($routes = "") {
        $this->Route->SetPublic(array());

        return $this->Route;
    }

    /*     * *
     * Execute action after install
     */

    function PostInstall() {
        \Apps\EeApp\Helper\AppHelper::UpdateAppParams($this->Core,
                "Asso",
                $this->Version,
                "", // Add Description of the app
                0, // Set 1 if the App have a AdminWidgetDashBoard
                0  // Set 1 if the App have a Member Module
        );
    }

    /**
     * Start Admin
     */
    function Run() {
        echo parent::RunApp($this->Core, "Asso", "Asso");
    }

    /**
     * Save a member
     */
    function SaveMember() {
      $adminController = new AdminController($this->Core);

      if ($adminController->SaveMember($this->Core, Request::GetPosts())) {
          return Response::Success($adminController->GetTabMember());
      } else {
          return Response::Error();
      }
    }

    /**
     * Delete a member
     */
    function DeleteMember() {
      $adminController = new AdminController($this->Core);

      if ($adminController->DeleteMember(Request::GetPost("MemberId"))) {
          return Response::Success($adminController->GetTabMember());
      } else {
          return Response::Error();
      }
    }

    /***
     * Save a MemberShip
     */
    function SaveMemberShip() {
      $adminController = new AdminController($this->Core);

      if ($adminController->SaveMemberShip($this->Core, Request::GetPosts())) {
          return Response::Success($adminController->GetTabMemberShip());
      } else {
          return Response::Error();
      }
    }

    /**
     * Delete a member ship
     */
    function DeleteMemberShip() {
      $adminController = new AdminController($this->Core);

      if ($adminController->DeleteMemberShip(Request::GetPost("MemberShipId"))) {
          return Response::Success($adminController->GetTabMemberShip());
      } else {
          return Response::Error();
      }
    }

    /***
     * Save a SaveReceipt
     */
    function SaveReceipt() {
      $adminController = new AdminController($this->Core);

      if ($adminController->SaveReceipt($this->Core, Request::GetPosts())) {
          return Response::Success($adminController->GetTabBudget());
      } else {
          return Response::Error();
      }
    }

    /**
     * Delete a receipt
     */
    function DeleteReceipt() {
      $adminController = new AdminController($this->Core);

      if ($adminController->DeleteReceipt(Request::GetPost("ReceiptId"))) {
          return Response::Success($adminController->GetTabBudget());
      } else {
          return Response::Error();
      }
    }

    /***
     * Save a SaveExpense
     */
    function SaveExpense() {
      $adminController = new AdminController($this->Core);

      if ($adminController->SaveExpense($this->Core, Request::GetPosts())) {
          return Response::Success($adminController->GetTabBudget());
      } else {
          return Response::Error();
      }
    }

    /**
     * Delete a Expense
     */
    function DeleteExpense() {
      $adminController = new AdminController($this->Core);

      if ($adminController->DeleteExpense(Request::GetPost("ExpenseId"))) {
          return Response::Success($adminController->GetTabBudget());
      } else {
          return Response::Error();
      }
    }
    
    /***
     * Save a SaveEquipment
     */
    function SaveEquipment() {
      $adminController = new AdminController($this->Core);

      if ($adminController->SaveEquipment($this->Core, Request::GetPosts())) {
          return Response::Success($adminController->GetTabEquipment());
      } else {
          return Response::Error();
      }
    }

    /**
     * Delete a Equipment
     */
    function DeleteEquipment() {
      $adminController = new AdminController($this->Core);

      if ($adminController->DeleteEquipment(Request::GetPost("EquipmentId"))) {
          return Response::Success($adminController->GetTabEquipment());
      } else {
          return Response::Error();
      }
    }

    /*     * *
     * Run member Controller
     * 
     * /
      /*function RunMember(){
      $memberController = new MemberController($this->Core);
      return $memberController->Index();
      } */

    /**
     * Get The siteMap 
     */
    /* public function GetSiteMap(){
      return SitemapHelper::GetSiteMap($this->Core);
      } */

    /*     * *
     * Get the widget
     */
    /* public function GetWidget($type = "", $params = "") {

      switch ($type) {
      case "AdminDashboard" :
      $widget = new \Apps\Asso\Widget\AdminDashBoard\AdminDashBoard($this->Core);
      break;
      }

      return $widget->Render();
      } */

    /*     * *
     * Get Forum Addable widget
     */
    /* public function GetListWidget(){
      return array(array("Name" => "LastMessage",
      "Description" => $this->Core->GetCode("Asso.DescriptionLastMessageWidget")),
      );
      } */
}
