Location: PHPKode > projects > Homeless Mangement Information System > hmis/include/date_encrypted_functions.inc
<?php
//*Client Data System, Copyright (C) 2000, 2001, 2002, 2003 Tedd Kelleher.  This is free software, subject to the 
//*GNU GENERAL PUBLIC LICENSE, Version 2, June 1991 (in file named gpl.txt), which should accompany 
//*any distribution of this file.  Tedd Kelleher can be contacted at hide@address.com


function date_encrypted_find_index_unix_time ( $unix_time )
{
    //Convert epoch time to format used in encrypted dates table
    //echo "<br>date_encrypted_find_index_unix_time ( $unix_time )";
    $year = safe_date( 'Y', $unix_time );
    $month = safe_date( 'm', $unix_time );
    /*if ( $month < 10 )  {
        $month = '0'.$month;
    }*/
    $day = safe_date( 'd', $unix_time );
    /*if ( $day < 10 )  {
        $day = '0'.$day;
    }*/
    
    $year_month_day_format = $year.$month.$day;
    //echo ' format:'.$year_month_day_format;
    $index = date_encrypted_find ( $year_month_day_format );
    //echo ' returning from date_encrypted_find_index_unix_time() -- Date index is: '.$index.'<p>';
    //echo ' return $index ';
    return $index;
}



function date_encrypted_find ( $year_month_day_format )
{
    //echo '<br>date_encrypted_find()...Year month day format is: '.$year_month_day_format.'<p/>';
    $date_in_table = $year_month_day_format.'1000';
    
    //echo "Date in table: ".$date_in_table."<p/>";
    
    $en = new Encryption();
    
    $encrypted_date = $en->encrypt_data ( $date_in_table );
    
    //Find the matching index value
    $sql = " 
    SELECT * 
        FROM 
            dates_encrypted
        WHERE 
            date_encrypted LIKE '".addslashes ( $encrypted_date )."'";
    //echo $sql.'<p>';
    
    $result = run_query ( $sql, 'Pulling matching date index' );
    
    $count =  num_rows ( $result );
    //echo "num_rows:$count";
    $encrypted_index = fetch_array ( $result, 'Pulling encrypted date index', 0 );
    
    //echo 'Matching rows count is: '.$count.'<p>';
    //echo 'Encrypted date indx is: '.$encrypted_index['date_index_encrypted'].'<p>';
    
    $decrypted_date_index = $en->decrypt_data ( $encrypted_index['date_index_encrypted'] );
    //unset ($en);
    //echo 'The date index returned is: '.$decrypted_date_index.'<p>';
    
    return $decrypted_date_index;
}



function date_encrypted_translate_index ( $date_index )
{
    if( $date_index != 0 )
    {
        $en = new Encryption();
        //echo '<br>date_encrypted_translate_index(): Date index is: '. $date_index.'<p/>';
        $encrypted_index = $en->encrypt_data ( $date_index );
        
        //Find the matching index value
        $sql = "
        SELECT date_encrypted
            FROM 
                dates_encrypted
            WHERE
                date_index_encrypted LIKE '".addslashes ( $encrypted_index )."'";
        //echo $sql;
        
        $result = run_query ( $sql, 'Pulling matching date index translate' );
        //echo num_rows ( $result );
        $encrypted_date = fetch_result ( $result, 'Pulling encrypted date' );
          
        $decrypted_date = $en->decrypt_data ( $encrypted_date );
    }
    return $decrypted_date;
    
}



function date_encrypted_translate_index_to_unix_time ( $date_index )
{
    //echo 'Date index to unix is: '. $date_index.'<p/>';
    
    $decrypted_date = date_encrypted_translate_index ( $date_index );
      
    $year = substr ( $decrypted_date, 0, 4 );
    $month = substr ( $decrypted_date, 4, 2 );
    $day = substr ( $decrypted_date, 6, 2 );
    
    $decrypted_unix_date = safe_mktime( 0, 0, 0, $month, $day, $year );
    //echo 'DATE: '.$year.' - '.$month.' - '.$day.' - '.$decrypted_unix_date." - ".time()."<p>";
    
    return $decrypted_unix_date;
}


function date_encrypted_translate_index_to_date_array ( $date_index )
{
    //echo 'Date index to date array is: '. $date_index.'<p/>';
    
    $decrypted_date = date_encrypted_translate_index ( $date_index );
    $ret['year'] = substr ( $decrypted_date, 0, 4 );
    $ret['month'] = substr ( $decrypted_date, 4, 2 );
    $ret['day'] = substr ( $decrypted_date, 6, 2 );
    
    //$decrypted_unix_date = safe_mktime( 0, 0, 0, $month, $day, $year );
    //echo 'DATE: '.$year.' - '.$month.' - '.$day.' - '.$decrypted_unix_date." - ".time()."<p>";
    
    return $ret;

}





















?>
Return current item: Homeless Mangement Information System