Location: PHPKode > projects > ZAPms > zap/include/libs.php
<?php
//------------------------------------------------------------
// Additional functions
function assignArray($array_var, $array_name = 'array_list', $strip_slash = 1, $success = 0) {
	global $smarty;
	if ($strip_slash) {
		while (list($vari, $parami) = @each($array_var)) {
			while (list($varj, $paramj) = @each($parami)) {
				$array_var[$vari][$varj] = stripslashes($array_var[$vari][$varj]);
			}
		}
	}
	//print_r($array_var);
	$smarty->assign($array_name, $array_var);
	$smarty->assign('success', $success);
}
//------------------------------------------------------------
// html replace
function html_replace($str) {
	$search = array('&', '<', '>', "\'", "'", '\"', '"', 'Ä', 'ä', 'Ö', 'ö', 'Ü', 'ü', 'ß');
	$replace = array('&amp;', '&lt;', '&gt;', '&#039;', '&#039;', '&quot;', '&quot;', '&Auml;', '&auml;', '&Ouml;', '&ouml;', '&Uuml;', '&uuml;', '&szlig;');
	$str = str_replace($search, $replace, $str);
	return $str;
}
//------------------------------------------------------------
// html decode
function html_decode($str) {
	$search = array("&amp;", "&lt;", "&gt;", "&acute;", "&quot;", "&Auml;", "&auml;", "&Ouml;", "&ouml;", "&Uuml;", "&uuml;", "&szlig;");
	$replace = array("&", "<", ">", "'", "\"", "Ä", "ä", "Ö", "ö", "Ü", "ü", "ß");
	$str = str_replace($search, $replace, $str);
	return $str;
}
//------------------------------------------------------------
// code replace
function code_replace($str) {
	$search = array('&lt;', '&gt;', '&#039;', '&quot;', '\"', "\'");
	$replace = array('<', '>', "'", '"', '"', "'");
	$str = str_replace($search, $replace, $str);
	return $str;
}
//------------------------------------------------------------
function trimRequestValues($request_var, $replace=1, $method=1) {
	// 1-keine/2-POST/0-GET
	global $_POST, $_GET;
	while(list($var, $param) = @each($request_var)) {
		if(!empty($_GET[$var]) && $method==0)
			$request_var[$var] = stripslashes(($replace) ? (html_replace(trim($_GET[$var]))) : (trim($_GET[$var])));
		else if(!empty($_POST[$var]) && $method==2)
			$request_var[$var] = stripslashes(($replace) ? (html_replace(trim($_POST[$var]))) : (trim($_POST[$var])));
		else
			$request_var[$var] = stripslashes(($replace) ? (html_replace(trim((!empty($_POST[$var])) ? $_POST[$var] : $_GET[$var]))) : (trim((!empty($_POST[$var]))) ? $_POST[$var] : $_GET[$var]));
	}
	return $request_var;
} 
//------------------------------------------------------------
function implodeRequestValues($request_var) {
	foreach ($request_var as $key => $val) {
		if ($val)
			$result .= $key.'='.$val.'&';
	}
	return substr($result, 0, -1);
}
//------------------------------------------------------------
function explodeRequestValues($request_s, $separator='&') {
	$result = array();
	$request_array = explode($separator, $request_s);
	$i = 0;
	while ($i < count($request_array)) {
		$pair = preg_split('/=/', $request_array[$i]);
		$key = trim($pair[0]);
		$result[$key] = trim($pair[1]);
		$i++;
	}
	return $result;
}
//------------------------------------------------------------
function isValidEmail($sender_mail) {
    if(ereg('^[A-Za-z0-9\._-]+[@][A-Za-z0-9\._-]+[\.].[A-Za-z0-9]+$', $sender_mail))
		return 1;
	else
        return 0;
}
//------------------------------------------------------------
function emailToUnicode($content) {
	$mail_pattern = '/mailto:[^\"]*/';
	preg_match_all($mail_pattern, $content, $found);
	$patterns = $found[0];
	$replacements = $found[0];
	for ($i = 0; $i < count($patterns); $i++) {
		if (isValidEmail(substr($replacements[$i], 7))) {
			$str_unicode ='';
			for ($j = 0; $j < strlen($replacements[$i]); $j++)
				$str_unicode .= '&#'.ord($replacements[$i][$j]).';';
			$replacements[$i] = $str_unicode;
			//print ($replacements[$i].'<br>');
		} else
			$replacements[$i] = '';
	}
	return str_replace($patterns, $replacements, $content);
}
//------------------------------------------------------------
function getContentFromPath($content_path) {
    $content = '';
    if (file_exists($content_path)) {
        $fd = @fopen($content_path, 'r');
        while (!feof($fd))
            $content .= fgets($fd, 4096);
        fclose($fd);
    }
    return $content;
}
//------------------------------------------------------------
function replaceContentWithValues($content, $vars_array) {
    $search = array();
    $replace = array();
    $count = 0;
    foreach ($vars_array as $k => $v) {
        $count ++;
        $search = array_pad($search, $count, '{$'.$k.'}');
        if (strpos($k, 'time') !== false)
            $v = date("d.m.Y", (int)$v);
        else if (strpos($k, 'paycheck') === false)
            $v = nl2br($v);
        $replace = array_pad($replace, $count, $v);
    }
    $content = str_replace($search, $replace, $content);
    return $content;
}
//------------------------------------------------------------
function buildReference($vars_array, $name = '', $surname = '', $title = '', $reference = '') {
    $success = 0;
	if ($reference && $surname) {
		foreach ($vars_array as $k => $v) {
			if ($v['id'] == $reference) {
				$reference = $v['reference'].' '.$title.' '.$surname;
				$success = 1;
				break;
			}
		}
	} else if ($name && $surname)
		$reference = $name.' '.$surname;
	else
		$reference = '';
    return $reference;
}
//------------------------------------------------------------
function getReferenceList($ui_lang) {
	global $SYS_WARN_MSG;
	// reference array for address form
	$cln_reference_array = array(array('id'=>'Mr', 'title'=>'Mr.', 'reference'=>'Dear Mr.'), array('id'=>'Ms', 'title'=>'Ms.', 'reference'=>' Dear Mr.'));
	for ($i=0; $i<sizeof($cln_reference_array); $i++) {
		$cln_reference_array[$i]['title'] = $SYS_WARN_MSG[$ui_lang][$cln_reference_array[$i]['id']];
		$cln_reference_array[$i]['reference'] = $SYS_WARN_MSG[$ui_lang][$SYS_WARN_MSG[$ui_lang][$cln_reference_array[$i]['id']]];
	}
	return $cln_reference_array;
}
//------------------------------------------------------------
function convertDateToTime($date) {
	return (($date) ? (mktime(substr($date,11,2), substr($date,14,2), 0, substr($date,3,2), substr($date,0,2), substr($date,6,4))) : (0));
}

?>
Return current item: ZAPms