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

function balikin($str)
	{
	$search = array ("'xpsijix'");

	$replace = array ("'");

	$str = preg_replace($search,$replace,$str);

	return $str;
	}

function cegah($str)
	{
    $str = trim(htmlentities(htmlspecialchars($str)));
	$search = array ("'\''");
	$replace = array ("xpsijix");

	$str = preg_replace($search,$replace,$str);
	return $str;
  	}
function cegah2($str)
	{
	$str2=base_url('media');
    $str = trim($str);
	$search = array ("'\..\/\..\/\..\/media'","'\..\/\..\/media'","'\..\/media'");
	$replace = array ($str2,$str2,$str2);
	$str = preg_replace($search,$replace,$str);
	return $str;
  	}
function cegah3($str)
	{
	$str2=' class="img-responsive"></img>';
	$str3='"img-responsive"';
    $str = trim($str);
	$search = array ("'></img>'",'"example1"');
	$replace = array ($str2,$str3);
	$str = preg_replace($search,$replace,$str);
	return $str;
  	}	
function cegah4($str)
	{
	$str2="../../media";
    $str = trim($str);
	$search = array ("'\..\/media'");
	$replace = array ($str2);

	$str = preg_replace($search,$replace,$str);
	return $str;
  	}	

	
function acakhuruf($panjang)
	{
   $karakter = 'ABCDEFGHIJKLMNOPQRSTUVWXZ';
   $string = '';
   for($i = 0; $i < $panjang; $i++) {
   $pos = rand(0, strlen($karakter)-1);
   $string .= $karakter{$pos};
   }
    return $string;
	}
function acakurl($str) {
	$hasil = '';
    $kunci = '979a218e0632df2935317f98d47956c7';
    for ($i = 0; $i < strlen($str); $i++) {
        $karakter = substr($str, $i, 1);
        $kuncikarakter = substr($kunci, ($i % strlen($kunci))-1, 1);
        $karakter = chr(ord($karakter)+ord($kuncikarakter));
        $hasil .= $karakter;
        
    }
    return urlencode(base64_encode($hasil));
}
 
function kembaliurl($str) {
    $str = base64_decode(urldecode($str));
    $hasil = '';
    $kunci = '979a218e0632df2935317f98d47956c7';
    for ($i = 0; $i < strlen($str); $i++) {
        $karakter = substr($str, $i, 1);
        $kuncikarakter = substr($kunci, ($i % strlen($kunci))-1, 1);
        $karakter = chr(ord($karakter)-ord($kuncikarakter));
        $hasil .= $karakter;
        
    }
    return $hasil;
}
function kirimtelegram($message_text) {
	$CI =& get_instance();
    $url = "https://api.telegram.org/bot590957422:AAH0o6avo7fG6aYJyzVrCAvpq2O8EOYNyUc/sendMessage?&chat_id=-232357720";
    $url = $url . "&text=" . urlencode($message_text." di Aplkasi Absen");
    $ch = curl_init();
    $optArray = array(
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true
    );
    curl_setopt_array($ch, $optArray);
    $result = curl_exec($ch);
    curl_close($ch);
}
function chmod_r($dir, $dirPermissions, $filePermissions) {
      $dp = opendir($dir);
       while($file = readdir($dp)) {
         if (($file == ".") || ($file == ".."))
            continue;

        $fullPath = $dir."/".$file;

         if(is_dir($fullPath)) {
            echo('DIR:' . $fullPath . "\n");
            chmod($fullPath, $dirPermissions);
            chmod_r($fullPath, $dirPermissions, $filePermissions);
         } else {
            echo('FILE:' . $fullPath . "\n");
            chmod($fullPath, $filePermissions);
         }

       }
     closedir($dp);
  }
function T($var, $c = 0)
{
    global $$var;
    if (empty($c))
        $$var = $_REQUEST["$var"];
    else
        $$var = strip_tags($_REQUEST["$var"]);
    return $_REQUEST[$var];
}
function hari($d,$m,$y) {
$a=date('w',mktime(1,0,0,$m,$d,$y));
$bb=array("MINGGU","SENIN","SELASA","RABU","KAMIS","JUM'AT","SABTU");
return $bb[$a];
}
function bulan($bln)
{
    $bulan = array('', 'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni',
        'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember');
    $tes = $bln * 1;
    return $bulan[$tes];
}
function input_text($name,$value,$tambah='') {
if ($name=='kt_kunci') $tambah='style="width:150px"';
return "<input type=\"text\" class=\"text-input\" name=\"$name\" value=\"$value\" $tambah/>";
}

function input_textarea($name,$value,$tambah='') {
return "<textarea class=\"textarea\" name=\"$name\" $tambah/>$value</textarea>";
}
function input_select1($nama,$option,$nilai,$tambahan='') {
$a = "<select name=\"$nama\"$tambahan>\n";
foreach ($option as $key=>$value) {
$sub=($nilai==$value)?" selected":"";
$a .= "<option$sub>$value</option>\n";
}
$a.= "</select>\n";
return $a;
}
function input_select2($nama,$option,$nilai,$tambahan='') {
$a = "<select class=\"input-combo\" name=\"$nama\"$tambahan>\n";
foreach ($option as $key=>$value) {
$sub =($key==$nilai)?" selected":"";
$a .= "<option value=\"$key\"$sub>$value</option>\n";
}
$a .= "</select>\n";
return $a;
}
function input_password($name,$value,$tambah='') {
return "<input type=\"password\" class=\"text-input\" name=\"$name\" value=\"$value\" $tambah/>";
}
function input_file($name,$tambah='') {
return "<input type=\"file\"  class=\"file\" name=\"$name\" $tambah/>";
}
function input_radio($name,$value,$value2='',$tambah='') {
$sub=($value==$value2)?"checked":"";
return "<input type=\"radio\"  value=\"$value\" $sub class=\"radio\" name=\"$name\" $tambah/>";
}
function input_submit($name,$value,$tambah='') {
if ($value=='Cancel') $tambah="onclick='history.back();return false;'";
return "<input type=\"submit\" name=\"$name\" value=\"$value\" class=\"button\" $tambah/>";
}

function input_checkbox($name,$value,$value2='',$tambah='') {
$sub=($value==$value2)?"checked":"";
return "<input type=\"checkbox\" name=\"$name\" $sub value=\"$value\" $tambah/>";
}

function input_hidden($name,$value) {
return "<input type=\"hidden\" name=\"$name\" value=\"$value\"/>";
}

function input_button($name,$value,$tambahan='') {
return "<input type=\"button\" name=\"$name\" value=\"$value\" class=\"button\" $tambahan/>";
}
function jam_to_dec($jam) {
$a=explode(':',$jam);
$hasil=$a[2]+ ($a[1]*60) + ($a[0]*3600);
return $hasil;
}

function dec_to_jam($dec) {
$a=($dec % 3600);
$jam= ($dec - $a) / 3600;
$b= ($a % 60);
$mnt= ($a - $b) /60;
$dtk=$b;
$aa1=str_pad($jam,2,0,STR_PAD_LEFT);
$aa2=str_pad($mnt,2,0,STR_PAD_LEFT);
$aa3=str_pad($dtk,2,0,STR_PAD_LEFT);
return "$aa1:$aa2:$aa3";
}
function jml_hari($mm,$yy) {
switch ($mm) {
case 1: 
case 3:
case 5: 
case 7: 
case 8: 
case 10: 
case 12: $a=31; break;
case 4:
case 6:
case 9:
case 11: $a=30; break;
case 2 :
    $a=($yy % 4==0) ? 29 : 28;
    break; 
}
return $a;
}
function Parse_Data($data,$p1,$p2){
	$data=" ".$data;
	$hasil="";
	$awal=strpos($data,$p1);
	if($awal!=""){
		$akhir=strpos(strstr($data,$p1),$p2);
		if($akhir!=""){
			$hasil=substr($data,$awal+strlen($p1),$akhir-strlen($p1));
		}
	}
	return $hasil;	
}
?>
