<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * CodeIgniter
 * @package         KSFAC
 * @subpackage      Helpers
 * @category        Helpers
 * @author          Manoj
 * @copyright       Copyright (c) 2015 - 2016, OrisysIndia, LLP.
 * @link            http://orisys.in
 * @since           Version 1.0
 * @filesource
 */

 

if ( ! function_exists('upload_api'))
    {
        function upload_api($id,$i)
        {
            $CI =& get_instance();
            $CI->load->database();
            //$CI->load->library('upload');
            $CI->load->model('user_model');   
                             
            $config['upload_path']      = 'uploads';
            $config['allowed_types']    = 'jpg|png|jpeg|JPEG|JPG|PNG';
            $CI->load->library('upload',$config);         
            if ($CI->security->xss_clean($_FILES, TRUE) === FALSE)
                {
                    // file failed the XSS test
                }
            else
            {
                if(isset($_FILES["image".$i]))
                    {
                        $ret    =   array();
                        $error  =   $_FILES["image".$i]["error"];
                        //You need to handle  both cases //If Any browser does not support serializing of multiple files using FormData() 
                        if(!is_array($_FILES["image".$i]["name"])) //single file
                            {   
                                /*print_r($_FILES);
                                print_r("image".$i);
                                // $CI->upload->initialize($config); // Important  
                                if(!$CI->upload->do_upload())
                                {
                                    echo 'inside condition';
                                    print_r($CI->upload->display_errors());
                                }*/
                                $moved                              =   $CI->upload->do_upload("image".$i);
                                //echo 'moved';
                                $image_type                         =   array('.gif','.jpg','.png','.jpeg','.GIF','.JPG','.PNG','.JPEG');
                                $file_data1                         =   $CI->upload->data("image".$i);
                                $file_data1                         =   $CI->upload->data();                                          
                                $data['filename1']                  =   $file_data1['file_name'];
                                if(in_array($file_data1['file_ext'], $image_type))
                                    {                                               
                                        $config1['image_library']   = 'gd2';
                                        $config1['source_image']    = 'uploads/'.$data['filename1'];
                                        $config1['create_thumb']    = TRUE;
                                        $config1['maintain_ratio']  = TRUE;
                                        $config1['width']           = 150;
                                        $config1['height']          = 150;
                                        $CI->load->library('image_lib'); 
                                        $CI->image_lib->initialize($config1);
                                        //$this->image_lib->resize();
                                        //$CI->load->library('image_lib', $config1); 
                                        if ( ! $CI->image_lib->resize())
                                            {
                                                $CI->image_lib->display_errors();
                                            }
                                        $CI->image_lib->clear();
                                    }
                                $arr = array('profile_pic' => $data['filename1']);                                           
                                if(isset($id) && $id !='')
                                    {
                                        $result = $CI->user_model->update('survey_family',$arr,array('family_id'=>$id));
                                    }
                            }
                    }

                if(isset($_FILES["doc".$i]))
                {
                    $ret = array();
                    $error =$_FILES["doc".$i]["error"];
                    //You need to handle  both cases
                    //If Any browser does not support serializing of multiple files using FormData()                             
                    if(!is_array($_FILES["doc".$i]["name"])) //single file
                    {
                        $CI->upload->do_upload("doc".$i);                                           
                        $doc_type =array('.doc','.pdf','.docx','.xls','.odt','.gif','.jpg','.png','.jpeg','.GIF','.JPG','.PNG','.JPEG');                                              
                       $file_data2 = $CI->upload->data();
                       $data['filename2'] = $file_data2['file_name'];
                        if(in_array($file_data2['file_ext'], $doc_type))
                        {
                            $image_type =array('.gif','.jpg','.png','.jpeg','.GIF','.JPG','.PNG','.JPEG');
                            
                            if(in_array($file_data2['file_ext'], $image_type))
                            {                                                               
                                $config1['image_library'] = 'gd2';
                                $config1['source_image'] = 'uploads/'.$data['filename2'];
                                $config1['create_thumb'] = TRUE;
                                $config1['maintain_ratio'] = TRUE;
                                $config1['width'] = 150;
                                $config1['height'] = 150;
                                $CI->load->library('image_lib'); 
                                $CI->image_lib->initialize($config1);
                                //$this->image_lib->resize();
                                //$CI->load->library('image_lib', $config1); 
                                if ( ! $CI->image_lib->resize())
                                    {
                                        $CI->image_lib->display_errors();
                                    }
                                $CI->image_lib->clear();
                            }
                            $arr1 = array( 'doc_pic' => $data['filename2']);
                            if(isset($id) && $id !='')
                                {
                                    $result = $CI->user_model->update('user_data',$arr1,array('id'=>$id));
                                }
                            return TRUE;
                        }
                    } 
                }
             }
        }
    }

  
if ( ! function_exists('excel_upload'))
    {
            function excel_upload($upload_path)
            {
                    $CI =& get_instance();
                    $CI->load->database();
                   

                    if ($CI->security->xss_clean($_FILES["attachment"], TRUE) === FALSE)
                    {
                        // file failed the XSS test
                    }
                    else
                    {
                        if(isset($_FILES["attachment"]))
                        {
                              
                              
                              $config['upload_path'] = $upload_path;
                              $config['allowed_types'] = 'xls|xlsx|XLSX';
//                              $config['max_size'] = '1000';
                              $CI->load->library('upload', $config);
                              $CI->upload->initialize($config);
                              if (!$CI->upload->do_upload('attachment')) {
                              //  return '1';
                                
                              }else {
                              $file_data = $CI->upload->data();
                              $file_path = $file_data['file_name'];
                            
                              return $file_path;
                              }
                        
                    
                        }
                    }
            }
    }    
/* End of file sms_helper.php */
/* Location: ./system/application/helper/sms_helper.php */