View file _incfiles/function.php

File size: 3.12Kb
<?php

class MySQL {
	
	private $SQL;
	
	public function connect ($host, $user, $pass, $base) {
		$this->SQL = mysql_connect($host, $user, $pass) or die('Немогу подключиться к серверу!');
		mysql_select_db($base, $this->SQL) or die('Немогу подключиться к серверу!');
		mysql_unbuffered_query("set names 'utf8'", $this->SQL);
	}

	public function query ($sql) {
		return mysql_query($sql, $this->SQL);
	}
	
	public function SQLerror () {
		return mysql_error($this->SQL);
	}
	
	public function SQLrows ($sql) {
		return mysql_num_rows($sql);
	}
	
	public function SQLresult ($sql, $str = 0) {
		return mysql_result($sql, $str, $this->SQL);
	}
	
	public function SQLID () {
		return mysql_insert_id();
	}
	
	public function assoc ($sql) {
		return mysql_fetch_assoc($sql);
	}
	
}

class MyFunctions  {

	public function __header ($title = 'WAP магазин') {
		ob_start();
		session_start();
		return require_once (dirname(__FILE__) . '/head.php');
	}
	
	public function __footer ($block = '') {
		ob_end_flush();
		return require_once (dirname(__FILE__) . '/foot.php');
	}
	
	public function escape ($str) {
		return mysql_real_escape_string(trim($str));
	}
	
	public function utf ($str) {
		return htmlspecialchars(stripslashes($str), ENT_QUOTES, 'UTF-8');
	}
	
	public function _int ($str, $value = false) {
		if ($value) {
			return trim(abs(intval($str)));
		} else {
			return trim(intval($str));
		}
	}
	
	public function _mail ($mail, $theme, $text) {
		$utf = "From: robot@".$_SERVER['HTTP_HOST']." \n";
		$utf.= "X-sender: < robot@".$_SERVER['HTTP_HOST']." >\n";
		$utf.= "Content-Type: text/html; charset=utf-8\n";
		
		return mail($mail, $theme, $text, $utf);
	}
	
	public function _unset ($str = null) {
		setCookie('login', '');
		setCookie('pass', '');
		session_destroy();
		$login = false;
		$pass = false;
		return $str;
	}
	
	public function select ($str, $real) {
		if ($str == $real) {
			return 'selected="selected"';
		}
	}
	
	public function page ($k_page = 1, $page = 1) {
		$page = isset($_GET['page']) ? $this->_int($_GET['page'], true) : 1;

		if ($page < 1) {
			$page = 1;
		}
		
		if ($page > $k_page) {
			$page = $k_page;
		}
		
		return $page;
	}

	public function k_page ($k_post = 0, $k_p_str = 10) {
		return $v_pages = ($k_post != 0) ? ceil($k_post / $k_p_str) : 1;
	}

	public function navigation ($link = '', $k_page = 1, $page = 1) {
		
		echo '<div class="block"><b>Страницы:</b> ';
		
		echo ($page != 1) ? '<a href="'.$link.'page=1">1</a>' : '[1]';

		for ($i =- 3; $i <= 3; $i++) {
			if ($page + $i > 1 && $page + $i < $k_page) :
				
				if ($i ==- 3 && $page + $i > 2) {
					echo ' <a>..</a>'; 
				}
				
				echo ($i != 0) ? ' <a href="'.$link.'page='.($page + $i).'">'.($page + $i).'</a>' : ' ['.($page + $i).']';

				if ($i == 3 && $page + $i < $k_page - 1) {
					echo ' <a>..</a>';
				}
				
			endif;
		}
		
		echo ($page != $k_page) ? ' <a href="'.$link.'page='.$k_page.'">'.$k_page.'</a>' : ' ['.$k_page.']';

		echo '</div>';
	}

}

?>