Last active
December 30, 2016 18:36
-
-
Save prahladyeri/f12a786fe21f56ba7672b7b4fa7e3d0e to your computer and use it in GitHub Desktop.
An open source utility module for CodeIgniter Framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Common Utilities Library | |
* | |
* An open source library module for CodeIgniter Framework | |
* | |
* This content is released under the MIT License (MIT) | |
* | |
* Copyright (c) 2016, Prahlad Yeri | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to deal | |
* in the Software without restriction, including without limitation the rights | |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
* copies of the Software, and to permit persons to whom the Software is | |
* furnished to do so, subject to the following conditions: | |
* | |
* The above copyright notice and this permission notice shall be included in | |
* all copies or substantial portions of the Software. | |
* | |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
* THE SOFTWARE. | |
* | |
* @author Prahlad Yeri | |
* @copyright Copyright (c) 2016, Prahlad Yeri | |
* @license http://opensource.org/licenses/MIT MIT License | |
* @link https://gist.github.com/prahladyeri/f12a786fe21f56ba7672b7b4fa7e3d0e | |
*/ | |
class Utils | |
{ | |
private $CI; | |
public function __construct() | |
{ | |
//parent::_construct(); | |
$this->CI =& get_instance(); | |
//$CI->load->helper('url'); | |
$this->CI->load->library('session'); | |
$this->CI->load->database(); | |
} | |
/** | |
* Move uploaded file to a permanent location | |
* | |
* @param $tmpfilename Temporary filename | |
* @param $filename Proper Filename | |
* @param $path Proper path | |
*/ | |
public function save_uploaded_file($tmpfilename, $filename, $path) { | |
//this will be passed: | |
//$newpath = APPPATH."upload/$id"; | |
if (!file_exists($path)){ | |
mkdir($path, 0777, true); | |
} | |
move_uploaded_file($tmpfilename, $path."/".$filename); | |
return $path."/".$filename; | |
} | |
public function is_session_valid($redirect=true) | |
{ | |
if (!$this->CI->session->has_userdata("email")) | |
{ | |
if ($redirect) exit("Invalid session.<br><br>Click <a href=\"/main/login\">here</a> to login."); | |
return FALSE; | |
} | |
// else if ($this->CI->session->userdata("username")=="admin" && $this->CI->session->userdata("usertype") == "affiliate") | |
// { | |
// exit("Invalid user type."); | |
// return FALSE; | |
// } | |
else | |
{ | |
return TRUE; | |
} | |
} | |
// public function is_payment_info_added($id) | |
// { | |
// $query = $this->CI->db->query("select business_name from affiliates where id=?", array($id)); | |
// $tres = $query->result_array(); | |
// $affiliate = $tres[0]; | |
// if ($affiliate["business_name"] === null || $affiliate["business_name"] === "") { | |
// return FALSE; | |
// } | |
// else | |
// { | |
// return TRUE; | |
// } | |
// } | |
// | |
// | |
// public function is_zip_code_valid($zip_code) | |
// { | |
// //check zip_code | |
// $query = $this->CI->db->query("select count(*) as cnt from zip_codes where zip_code=?", array($zip_code)); | |
// $results = $query->result_array(); | |
// //var_dump($_POST["pay_zip_code"]); | |
// //var_dump($results); | |
// $cnt = $results[0]["cnt"]; | |
// error_log("is_zip_code_valid::$cnt"); | |
// if ($cnt==0) | |
// { | |
// return FALSE; | |
// } | |
// else { | |
// return TRUE; | |
// } | |
// } | |
}?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment