<?php

/*
 * Copyright (c) 2018 Earworks.
 * Codeigniter Project Template Modification
 * Please contact our email for more information :
 * contact@earworks.co.id
 */

defined('BASEPATH') OR exit('No direct script access allowed');

if (!function_exists('show_alert')) {

    function show_alert() {
        $CI = & get_instance();
        $return = null;
        foreach ($CI->session->flashdata() as $k => $v) {
            $call = "show_alert_" . $k;
            if (function_exists($call)) {
                $return .= $call($v);
            } else {
                $return .= show_alert_danger('key ' . $k . ' not exist');
            }
        }
        return $return;
    }

}
if (!function_exists('show_alert_danger')) {

    function show_alert_danger($msg = null) {
        $CI = & get_instance();
        $alert = '<div class="alert alert-danger alert-dismissible">'
                . '<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>'
                . '<strong>{key}</strong> {msg}'
                . '</div>';
        $return = null;
        if (is_array($msg)) {
            foreach ($msg as $m) {
                $return .= strtr($alert, array(
                    '{key}' => $CI->lang->line('error') . '!',
                    '{msg}' => $m
                ));
            }
        } else {
            $return = strtr($alert, array(
                '{key}' => $CI->lang->line('error') . '!',
                '{msg}' => $msg
            ));
        }
        return $return;
    }

}
if (!function_exists('show_alert_success')) {

    function show_alert_success($msg = null) {
        $CI = & get_instance();
        $alert = '<div class="alert alert-success alert-dismissible">'
                . '<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>'
                . '<strong>{key}</strong> {msg}'
                . '</div>';
        $return = null;
        if (is_array($msg)) {
            foreach ($msg as $m) {
                $return .= strtr($alert, array(
                    '{key}' => $CI->lang->line('success') . '!',
                    '{msg}' => $m
                ));
            }
        } else {
            $return = strtr($alert, array(
                '{key}' => $CI->lang->line('success') . '!',
                '{msg}' => $msg
            ));
        }
        return $return;
    }

}
if (!function_exists('show_alert_info')) {

    function show_alert_info($msg = null) {
        $CI = & get_instance();
        $alert = '<div class="alert alert-info alert-dismissible">'
                . '<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>'
                . '<strong>{key}</strong> {msg}'
                . '</div>';
        $return = null;
        if (is_array($msg)) {
            foreach ($msg as $m) {
                $return .= strtr($alert, array(
                    '{key}' => $CI->lang->line('info') . '!',
                    '{msg}' => $m
                ));
            }
        } else {
            $return = strtr($alert, array(
                '{key}' => $CI->lang->line('info') . '!',
                '{msg}' => $msg
            ));
        }
        return $return;
    }

}
if (!function_exists('show_alert_warning')) {

    function show_alert_warning($msg = null) {
        $CI = & get_instance();
        $alert = '<div class="alert alert-warning alert-dismissible">'
                . '<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>'
                . '<strong>{key}</strong> {msg}'
                . '</div>';
        $return = null;
        if (is_array($msg)) {
            foreach ($msg as $m) {
                $return .= strtr($alert, array(
                    '{key}' => $CI->lang->line('warning') . '!',
                    '{msg}' => $m
                ));
            }
        } else {
            $return = strtr($alert, array(
                '{key}' => $CI->lang->line('warning') . '!',
                '{msg}' => $msg
            ));
        }
        return $return;
    }

}