<?php

/*
 * This file is create for storing name of table, and field.
 * 
 */

if (!function_exists('delete_file')) {

    function delete_file($file) {		
        if (@unlink($file)) {
            return TRUE;
        }
		
        return FALSE;
    }
}

if (!function_exists('resize_image')) {

    function resize_image($image, $new_height, $new_width, $path, $new_path = '', $thumb_marker = '', $ratio = true){
        $ci = &get_instance();
        list($width, $height) = getimagesize($path . $image);
		$new_path = empty($new_path) ? $path . 'thumbs/' : $new_path;
		$new_width = empty($new_width) ? (($width * $new_height) / $height) : $new_width;
		
		$config = array(
					   'source_image'   => $path . $image,
					   'new_image'      => $new_path . $image,
					   'create_thumb'   => true,
					   'thumb_marker'	=> $thumb_marker,
					   'maintain_ratio' => $ratio,
					   'height'         => $new_height,
            		   'width'			=> $new_width
					   );
		
		$ci->load->library('image_lib');
		$ci->image_lib->clear();
		$ci->image_lib->initialize($config);
		$ci->image_lib->resize();
    }
}

if (!function_exists('file_multi_upload')) {
	
	function file_multi_upload($fieldName, $path){
		$ci = &get_instance();
        $ci->load->library('upload');
        $config = array(// takes an array of initialization options
            "upload_path" => $path,
            "overwrite" => FALSE,
            "allowed_types" => "gif|jpg|png"
        );
        $ci->upload->initialize($config);
		$ci->upload->do_multi_upload($fieldName); // use same as you did in the input field
		$result = $ci->upload->get_multi_upload_data();
		
        if(empty($result))
            return FALSE;
        
        return $result;
	}
}

if (!function_exists('moneyFormat')) {
    function moneyFormat($amount, $dec=2) {
		$result = number_format($amount, $dec);
		return $result;
    }
}