<?php defined('BASEPATH') or exit('No direct script access allowed');

/*
Module Name: COI Special Approval
Description: Conflict of Interest – Special Approval Form (CEO/PCEO approval)
Version: 1.0.0
Requires at least: 3.4.0
*/

define('COI_SPECIAL_APPROVAL_MODULE', 'coi_special_approval');

hooks()->add_action('admin_init', 'csa_register_permissions');
hooks()->add_action('admin_init', 'csa_init_menu');

register_activation_hook(COI_SPECIAL_APPROVAL_MODULE, 'csa_activation_hook');
register_uninstall_hook(COI_SPECIAL_APPROVAL_MODULE, 'csa_uninstall_hook');

function csa_activation_hook()
{
  require_once(__DIR__.'/install.php');
}

function csa_uninstall_hook()
{
  require_once(__DIR__.'/uninstall.php');
}

function csa_register_permissions()
{
  $capabilities = [];
  $capabilities['capabilities'] = [
    'view'     => _l('permission_view'),
    'view_own' => _l('permission_view_own'),
    'create'   => _l('permission_create'),
    'edit'     => _l('permission_edit'),
    'delete'   => _l('permission_delete'),
    'approve'  => 'Approve (CEO/PCEO)', // custom capability
  ];

  register_staff_capabilities('coi_special_approval', $capabilities, 'COI Special Approval');
}

function csa_init_menu()
{
  $CI = &get_instance();

  if (staff_can('view', 'coi_special_approval') || staff_can('view_own', 'coi_special_approval')) {
    $CI->app_menu->add_sidebar_children_item('new_declaration', [
      'slug'     => 'coi_special_approval',
      'name'     => _l('coidisclosure'),
      'href'     => admin_url('coi_special_approval'),
      'position' => 10,
      //'icon'     => 'fa fa-check-circle',
    ]);

    if (is_admin()) {
        $CI->app_menu->add_sidebar_children_item('new_declaration', [
        'slug'     => 'coi_special_approval_settings',
        'name'     => 'COI & EE Approval Setting',
        'href'     => admin_url('coi_special_approval/settings'),
        'position' => 99,
      ]);
    }
  }
}

register_language_files(COI_SPECIAL_APPROVAL_MODULE, ['coi_special_approval']);
