<?php
class class_author extends class_db
{
	function __construct()
	{
		$this->db();
		$this->author_id = ( isset($_SESSION['author_id']) && $_SESSION['author_id'] ? (int)$_SESSION['author_id'] : 0 );
	}

	function login($static_str_author_account, $static_str_password)
	{
		$str_query = 'SELECT * 
		FROM `authors` 
		WHERE `AuthorAccount` = \'' . mysqli_real_escape_string($this->sql_connect, $static_str_author_account) . '\' ';
		if( !( $sql_result = mysqli_query($this->sql_connect, $str_query) ) )
		{
			$this->write_error_logs($str_query);
			return false;
		}
		else if( mysqli_num_rows($sql_result) == 0 )
		{
			mysqli_free_result($sql_result);
			return false;
		}
		else
		{
			$arr_author_data = mysqli_fetch_assoc($sql_result);
			mysqli_free_result($sql_result);

			if( ( $static_int_author_level = (int)$arr_author_data['AuthorLevel'] ) < 0 )
				return false;

			$str_md5_salt = substr($arr_author_data['Password'], 0, 12);
			if( crypt($static_str_password, $str_md5_salt) == $arr_author_data['Password'] )
			{
				$_SESSION['author_id'] = $arr_author_data['AuthorId'];
				$_SESSION['author_account'] = $arr_author_data['AuthorAccount'];
				$_SESSION['author_level'] = $static_int_author_level;

				if(empty($_SERVER['HTTP_X_FORWARDED_FOR']))
				{
					$str_user_ip = $_SERVER['REMOTE_ADDR'];
					$str_user_proxy = '';
				}
				else
				{
					$str_user_ip = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
					$str_user_ip = $str_user_ip[0];
					$str_user_proxy = $_SERVER['REMOTE_ADDR'];
				}

				$str_tsql = 'UPDATE `authors` 
				SET `LastLogin` = \'' . date('Y-m-d H:i:s') . '\', `LLIP` = \'' . mysqli_real_escape_string($this->sql_connect, $str_user_ip) . '\', `LLProxy` = \'' . $str_user_proxy . '\' 
				WHERE `AuthorId` = \'' . (int)$arr_author_data['AuthorId'] . '\' ';
				if( !mysqli_query($this->sql_connect, $str_tsql) )
					$this->write_error_logs($str_tsql);

				return true;
			}
			else
				return false;
		}
	}

	function get_init_url()
	{
		if( !isset($_SESSION['author_level']) || $_SESSION['author_level'] == '' )
			return false;

		$str_query = 'SELECT `FileName` 
		FROM `author_menus` 
		WHERE `Level` <= \'' . (int)$_SESSION['author_level'] . '\' 
		AND `ParentId` <> \'1\' 
		AND `FileName` <> \'#\' 
		ORDER BY `MenuId` 
		LIMIT 0, 1 ';
		if( !( $sql_result = mysqli_query($this->sql_connect, $str_query) ) )
		{
			$this->write_error_logs($str_query);
			return false;
		}
		else
		{
			$arr_result = mysqli_fetch_assoc($sql_result);
			mysqli_free_result($sql_result);

			return($arr_result['FileName']);
		}
	}

	function get_this_level($static_str_php_self)
	{
		if( $static_str_php_self == '' )
			return false;

		if( false !== ( $uint_pos = strrpos($static_str_php_self, '/') ) )
			$str_php_self = substr($static_str_php_self, ( $uint_pos + 1 ));
		else
			$str_php_self = $static_str_php_self;

		$str_query = 'SELECT `Level` 
		FROM `author_menus` 
		WHERE `FileName` LIKE \'' . mysqli_real_escape_string($this->sql_connect, $str_php_self) . '%\' ';
		if( !( $sql_result = mysqli_query($this->sql_connect, $str_query) ) )
		{
			$this->write_error_logs($str_query);
			return false;
		}
		else if( !( $arr_result = mysqli_fetch_assoc($sql_result) ) )
		{
			mysqli_free_result($sql_result);
			return false;
		}
		else
		{
			mysqli_free_result($sql_result);
			return (int)$arr_result['Level'];
		}
	}

	function get_root_menus($static_uint_user_level)
	{
		$str_query = 'SELECT * 
		FROM `author_menus` 
		WHERE `ParentId` = \'0\' 
		AND `Level` <= \'' . (int)$static_uint_user_level . '\' 
		ORDER BY `MenuId` ';
		if( !( $sql_result = mysqli_query($this->sql_connect, $str_query) ) )
		{
			$this->write_error_logs($str_query);
			return false;
		}
		else
			return $this->result_setto_array($sql_result);
	}

	function get_sub_menus($static_uint_user_level)
	{
		$str_query = 'SELECT * 
		FROM `author_menus` 
		WHERE `ParentId` <> \'0\' 
		AND `Level` <= \'' . (int)$static_uint_user_level . '\' 
		ORDER BY `ParentId`, `MenuId` ';
		if( !( $sql_result = mysqli_query($this->sql_connect, $str_query) ) )
		{
			$this->write_error_logs($str_query);
			return false;
		}
		else
			return $this->result_setto_array($sql_result);
	}	

	function get_author()
	{
		$str_query = 'SELECT * 
		FROM `authors` 
		WHERE `AuthorId` = \'' . (int)$this->author_id . '\' ';
		if( !( $sql_result = mysqli_query($this->sql_connect, $str_query) ) )
		{
			$this->write_error_logs($str_query);
			return false;
		}
		else
			return $this->result_setto_array($sql_result);
	}
	
	function modify_password($static_str_old_password, $static_str_new_password)
	{
		$str_query = 'SELECT `Password` 
		FROM `authors` 
		WHERE `AuthorId` = \'' . (int)$this->author_id . '\' ';
		if( !( $sql_result = mysqli_query($this->sql_connect, $str_query) ) )
		{
			$this->write_error_logs($str_query);
			return false;
		}
		else if( !( $arr_data = mysqli_fetch_assoc($sql_result) ) )
		{
			mysqli_free_result($sql_result);
			return false;
		}
		else
		{
			mysqli_free_result($sql_result);
			$str_encoded_password = $arr_data['Password'];

			$str_md5_salt = substr($str_encoded_password, 0, 12);
			if( crypt($static_str_old_password, $str_md5_salt) == $str_encoded_password )
			{
				$str_tsql = 'UPDATE `authors` 
				SET `Password` = \'' . crypt($static_str_new_password) . '\' 
				WHERE `AuthorId` = \'' . (int)$this->author_id . '\' ';
				if( !mysqli_query($this->sql_connect, $str_tsql) )
				{
					$this->write_error_logs($str_tsql);
					return false;
				}
				else
					return true;
			}
			else
				return false;
		}
	}

	function get_news_cates()
	{
		$str_query = 'SELECT * 
		FROM `news_cates` 
		WHERE 1 
		ORDER BY `Order` ';
		if( !( $sql_result = mysqli_query($this->sql_connect, $str_query) ) )
		{
			$this->write_error_logs($str_query);
			return false;
		}
		else
			return $this->result_setto_array($sql_result);
	}

	function get_news_cate_by_news_cate_id($static_uint_news_cate_id)
	{
		$str_query = 'SELECT * 
		FROM `news_cates` 
		WHERE `NewsCateId` = \'' . (int)$static_uint_news_cate_id . '\' ';
		if( !( $sql_result = mysqli_query($this->sql_connect, $str_query) ) )
		{
			$this->write_error_logs($str_query);
			return false;
		}
		else
			return $this->result_setto_array($sql_result);
	}

	function search_news($static_uint_news_cate_id, $static_str_subject_keyword, $static_str_start_date, $static_str_end_date, $static_uint_offset, $static_uint_row_count)
	{
		$str_query = 'SELECT DISTINCT `news`.* 
		FROM `news` 
		LEFT JOIN `news_cates_news` 
		ON `news_cates_news`.`NewsId` = `news`.`NewsId` 
		WHERE `news`.`AuthorId` = \'' . (int)$this->author_id . '\' ';

		if( $static_uint_news_cate_id )
			$str_query .= 'AND `news_cates_news`.`NewsCateId` = \'' . (int)$static_uint_news_cate_id . '\' ';

		if( $static_str_subject_keyword )
			$str_query .= 'AND `news`.`Subject` LIKE \'%' . mysqli_real_escape_string($this->sql_connect, $static_str_subject_keyword) . '%\' ';

		if( $static_str_start_date )
			$str_query .= 'AND `news`.`Date` >= \'' . mysqli_real_escape_string($this->sql_connect, $static_str_start_date) . '\' ';

		if( $static_str_end_date )
			$str_query .= 'AND `news`.`Date` <= \'' . mysqli_real_escape_string($this->sql_connect, $static_str_end_date) . '\' ';
		
		$str_query .= 'ORDER BY `news`.`Date` DESC ';
		
		if( $static_uint_row_count )
			$str_query .= 'LIMIT ' . (int)$static_uint_offset . ', ' . (int)$static_uint_row_count . ' ';

		if( !( $sql_result = mysqli_query($this->sql_connect, $str_query) ) )
		{
			$this->write_error_logs($str_query);
			return false;
		}
		else
			return $this->result_setto_array($sql_result);
	}

	function get_news_by_news_id($static_uint_news_id)
	{
		$str_query = 'SELECT * 
		FROM `news` 
		WHERE `AuthorId` = \'' . (int)$this->author_id . '\' 
		AND `NewsId` = \'' . (int)$static_uint_news_id . '\' ';
		if( !( $sql_result = mysqli_query($this->sql_connect, $str_query) ) )
		{
			$this->write_error_logs($str_query);
			return false;
		}
		else
			return $this->result_setto_array($sql_result);
	}

	function add_news($static_str_date, $static_str_subject, $static_str_author, $static_str_abstract)
	{
		if( $static_str_date > date('Y-m-d') )
			$uint_build_time = strtotime($static_str_date . ' 00:00:00');
		else
			$uint_build_time = time();

		$str_tsql = 'INSERT INTO `news` 
		(`AuthorId`, `Date`, `Subject`, `Author`, `Abstract`, `Active`, `BuildTime`) 
		VALUES 
		(\'' . (int)$this->author_id . '\', \'' . mysqli_real_escape_string($this->sql_connect, $static_str_date) . '\', \'' . mysqli_real_escape_string($this->sql_connect, $static_str_subject) . '\', \'' . mysqli_real_escape_string($this->sql_connect, $static_str_author) . '\', \'' . mysqli_real_escape_string($this->sql_connect, $static_str_abstract) . '\', \'0\', \'' . (int)$uint_build_time . '\') ';
		if( !mysqli_query($this->sql_connect, $str_tsql) )
		{
			$this->write_error_logs($str_tsql);
			return false;
		}
		else
			return mysqli_insert_id($this->sql_connect);
	}

	function update_news($static_uint_news_id, $static_str_date, $static_str_subject, $static_str_author, $static_str_abstract)
	{
		$str_tsql = 'UPDATE `news` 
		SET `Date` = \'' . mysqli_real_escape_string($this->sql_connect, $static_str_date) . '\', `Subject` = \'' . mysqli_real_escape_string($this->sql_connect, $static_str_subject) . '\', `Author` = \'' . mysqli_real_escape_string($this->sql_connect, $static_str_author) . '\', `Abstract` = \'' . mysqli_real_escape_string($this->sql_connect, $static_str_abstract) . '\'';
		
		if( $static_str_date > date('Y-m-d') )
			$str_tsql .= ', `BuildTime` = \'' . strtotime($static_str_date . ' 00:00:00') . '\'';

		$str_tsql .= ' WHERE `AuthorId` = \'' . (int)$this->author_id . '\' 
		AND `NewsId` = \'' . (int)$static_uint_news_id . '\' ';
		if( !mysqli_query($this->sql_connect, $str_tsql) )
		{
			$this->write_error_logs($str_tsql);
			return false;
		}
		else
			return true;
	}

	function delete_news($static_uint_news_id)
	{
		$str_tsql = 'DELETE 
		FROM `news` 
		WHERE `AuthorId` = \'' . (int)$this->author_id . '\' 
		AND `NewsId` = \'' . (int)$static_uint_news_id . '\' ';
		if( !mysqli_query($this->sql_connect, $str_tsql) )
		{
			$this->write_error_logs($str_tsql);
			return false;
		}
		else
			return true;
	}

	function get_news_cates_by_news_id($static_uint_news_id)
	{
		$str_query = 'SELECT `news_cates`.* 
		FROM `news_cates` 
		INNER JOIN `news_cates_news` 
		ON `news_cates_news`.`NewsCateId` = `news_cates`.`NewsCateId` 
		AND `news_cates_news`.`NewsId` = \'' . (int)$static_uint_news_id . '\' 
		WHERE 1 
		ORDER BY `news_cates`.`Order` ';
		if( !( $sql_result = mysqli_query($this->sql_connect, $str_query) ) )
		{
			$this->write_error_logs($str_query);
			return false;
		}
		else
			return $this->result_setto_array($sql_result);
	}

	function add_news_cates_news($static_uint_news_cate_id, $static_uint_news_id)
	{
		$str_tsql = 'INSERT INTO `news_cates_news` 
		(`NewsCateId`, `NewsId`) 
		VALUES 
		(\'' . (int)$static_uint_news_cate_id . '\', \'' . (int)$static_uint_news_id . '\') ';
		if( !mysqli_query($this->sql_connect, $str_tsql) )
		{
			$this->write_error_logs($str_tsql);
			return false;
		}
		else
			return true;
	}

	function delete_news_cates_news($static_uint_news_cate_id, $static_uint_news_id)
	{
		$str_tsql = 'DELETE 
		FROM `news_cates_news` 
		WHERE `NewsCateId` = \'' . (int)$static_uint_news_cate_id . '\' 
		AND `NewsId` = \'' . (int)$static_uint_news_id . '\' ';
		if( !mysqli_query($this->sql_connect, $str_tsql) )
		{
			$this->write_error_logs($str_tsql);
			return false;
		}
		else
			return true;
	}

	function clear_news_cates_by_news_id($static_uint_news_id)
	{
		$str_tsql = 'DELETE 
		FROM `news_cates_news` 
		WHERE `NewsId` = \'' . (int)$static_uint_news_id . '\' ';
		if( !mysqli_query($this->sql_connect, $str_tsql) )
		{
			$this->write_error_logs($str_tsql);
			return false;
		}
		else
			return true;
	}

	function check_news_has_pictures($static_uint_news_id)
	{
		$str_query = 'SELECT COUNT(`PictureId`) AS `PictureCount`
		FROM `news_pictures` 
		WHERE `NewsId` = \'' . (int)$static_uint_news_id . '\' ';
		if( !( $sql_result = mysqli_query($this->sql_connect, $str_query) ) )
		{
			$this->write_error_logs($str_query);
			return false;
		}
		else if( !( $arr_result = $this->result_setto_array($sql_result) ) )
			return false;
		else
			return (bool)$arr_result[0]['PictureCount'];
	}

	function get_news_pictures_by_news_id($static_uint_news_id)
	{
		$str_query = 'SELECT * 
		FROM `news_pictures` 
		WHERE `NewsId` = \'' . (int)$static_uint_news_id . '\' 
		ORDER BY `IsCover` DESC, `PictureId` ';
		if( !( $sql_result = mysqli_query($this->sql_connect, $str_query) ) )
		{
			$this->write_error_logs($str_query);
			return false;
		}
		else
			return $this->result_setto_array($sql_result);
	}

	function get_news_pictures_is_cover_by_news_id($static_uint_news_id)
	{
		$str_query = 'SELECT * 
		FROM `news_pictures` 
		WHERE `NewsId` = \'' . (int)$static_uint_news_id . '\' 
		AND `IsCover` = \'1\' ';
		if( !( $sql_result = mysqli_query($this->sql_connect, $str_query) ) )
		{
			$this->write_error_logs($str_query);
			return false;
		}
		else
			return $this->result_setto_array($sql_result);
	}

	function get_news_picture_by_news_id_n_hash($static_uint_news_id, $static_str_hash)
	{
		$str_query = 'SELECT * 
		FROM `news_pictures` 
		WHERE `NewsId` = \'' . (int)$static_uint_news_id . '\' 
		AND `Hash` = \'' . mysqli_real_escape_string($this->sql_connect, $static_str_hash) . '\' ';
		if( !( $sql_result = mysqli_query($this->sql_connect, $str_query) ) )
		{
			$this->write_error_logs($str_query);
			return false;
		}
		else
			return $this->result_setto_array($sql_result);
	}

	function get_news_picture_by_picture_id($static_uint_picture_id)
	{
		$str_query = 'SELECT * 
		FROM `news_pictures` 
		WHERE `PictureId` = \'' . (int)$static_uint_picture_id . '\' ';
		if( !( $sql_result = mysqli_query($this->sql_connect, $str_query) ) )
		{
			$this->write_error_logs($str_query);
			return false;
		}
		else
			return $this->result_setto_array($sql_result);
	}

	function add_news_picture($static_uint_news_id, $static_str_hash)
	{
		$str_tsql = 'INSERT INTO `news_pictures` 
		(`NewsId`, `Hash`) 
		VALUES 
		(\'' . (int)$static_uint_news_id . '\', \'' . mysqli_real_escape_string($this->sql_connect, $static_str_hash) . '\') ';
		if( !mysqli_query($this->sql_connect, $str_tsql) )
		{
			$this->write_error_logs($str_tsql);
			return false;
		}
		else
			return mysqli_insert_id($this->sql_connect);
	}

	function update_news_picture_subject($static_uint_picture_id, $static_str_subject)
	{
		$str_tsql = 'UPDATE `news_pictures` 
		SET `Subject` = \'' . mysqli_real_escape_string($this->sql_connect, $static_str_subject) . '\' 
		WHERE `PictureId` = \'' . (int)$static_uint_picture_id . '\' ';
		if( !mysqli_query($this->sql_connect, $str_tsql) )
		{
			$this->write_error_logs($str_tsql);
			return false;
		}
		else
			return true;
	}

	function set_news_picture_is_cover($static_uint_picture_id)
	{
		if( !( $arr_news_picture = $this->get_news_picture_by_picture_id($static_uint_picture_id) ) )
			return false;

		mysqli_query($this->sql_connect, 'BEGIN;');

		$str_tsql = 'UPDATE `news_pictures` 
		SET `IsCover` = \'0\' 
		WHERE `NewsId` = \'' . $arr_news_picture[0]['NewsId'] . '\' ';
		if( !mysqli_query($this->sql_connect, $str_tsql) )
		{
			$this->write_error_logs($str_tsql);
			mysqli_query($this->sql_connect, 'COMMIT;');

			return false;
		}

		$str_tsql = 'UPDATE `news_pictures` 
		SET `IsCover` = \'1\' 
		WHERE `PictureId` = \'' . (int)$static_uint_picture_id . '\' ';
		if( !mysqli_query($this->sql_connect, $str_tsql) )
		{
			$this->write_error_logs($str_tsql);
			mysqli_query($this->sql_connect, 'ROLLBACK;');
			mysqli_query($this->sql_connect, 'COMMIT;');

			return false;
		}

		mysqli_query($this->sql_connect, 'COMMIT;');

		return true;
	}

	function delete_news_picture($static_uint_picture_id)
	{
		$str_tsql = 'DELETE 
		FROM `news_pictures` 
		WHERE `PictureId` = \'' . (int)$static_uint_picture_id . '\' ';
		if( !mysqli_query($this->sql_connect, $str_tsql) )
		{
			$this->write_error_logs($str_tsql);
			return false;
		}
		else
			return true;
	}

	function check_news_has_videos($static_uint_news_id)
	{
		$str_query = 'SELECT COUNT(`VideoId`) AS `VideoCount`
		FROM `news_videos` 
		WHERE `NewsId` = \'' . (int)$static_uint_news_id . '\' ';
		if( !( $sql_result = mysqli_query($this->sql_connect, $str_query) ) )
		{
			$this->write_error_logs($str_query);
			return false;
		}
		else if( !( $arr_result = $this->result_setto_array($sql_result) ) )
			return false;
		else
			return (bool)$arr_result[0]['VideoCount'];
	}

	function get_news_videos_by_news_id($static_uint_news_id)
	{
		$str_query = 'SELECT * 
		FROM `news_videos` 
		WHERE `NewsId` = \'' . (int)$static_uint_news_id . '\' 
		ORDER BY `IsCover` DESC, `VideoId` ';
		if( !( $sql_result = mysqli_query($this->sql_connect, $str_query) ) )
		{
			$this->write_error_logs($str_query);
			return false;
		}
		else
			return $this->result_setto_array($sql_result);
	}

	function get_news_video_by_news_id_n_video_no($static_uint_news_id, $static_str_video_no)
	{
		$str_query = 'SELECT * 
		FROM `news_videos` 
		WHERE `NewsId` = \'' . (int)$static_uint_news_id . '\' 
		AND `VideoNo` = \'' . mysqli_real_escape_string($this->sql_connect, $static_str_video_no) . '\' ';
		if( !( $sql_result = mysqli_query($this->sql_connect, $str_query) ) )
		{
			$this->write_error_logs($str_query);
			return false;
		}
		else
			return $this->result_setto_array($sql_result);
	}

	function get_news_video_by_video_id($static_uint_video_id)
	{
		$str_query = 'SELECT * 
		FROM `news_videos` 
		WHERE `VideoId` = \'' . (int)$static_uint_video_id . '\' ';
		if( !( $sql_result = mysqli_query($this->sql_connect, $str_query) ) )
		{
			$this->write_error_logs($str_query);
			return false;
		}
		else
			return $this->result_setto_array($sql_result);
	}

	function add_news_video($static_uint_news_id, $static_str_subject, $static_str_video_no)
	{
		$str_tsql = 'INSERT INTO `news_videos` 
		(`NewsId`, `Subject`, `VideoNo`) 
		VALUES 
		(\'' . (int)$static_uint_news_id . '\', \'' . mysqli_real_escape_string($this->sql_connect, $static_str_subject) . '\', \'' . mysqli_real_escape_string($this->sql_connect, $static_str_video_no) . '\') ';
		if( !mysqli_query($this->sql_connect, $str_tsql) )
		{
			$this->write_error_logs($str_tsql);
			return false;
		}
		else
			return mysqli_insert_id($this->sql_connect);
	}

	function update_news_video($static_uint_video_id, $static_str_subject, $static_str_video_no, $static_uint_order)
	{
		$str_tsql = 'UPDATE `news_videos` 
		SET `Subject` = \'' . mysqli_real_escape_string($this->sql_connect, $static_str_subject) . '\', `VideoNo` = \'' . mysqli_real_escape_string($this->sql_connect, $static_str_video_no) . '\', `Order` = \'' . (int)$static_uint_order . '\' 
		WHERE `VideoId` = \'' . (int)$static_uint_video_id . '\' ';
		if( !mysqli_query($this->sql_connect, $str_tsql) )
		{
			$this->write_error_logs($str_tsql);
			return false;
		}
		else
			return true;
	}

	function update_news_video_order($static_uint_video_id, $static_uint_order)
	{
		$str_tsql = 'UPDATE `news_videos` 
		SET `Order` = \'' . (int)$static_uint_order . '\' 
		WHERE `VideoId` = \'' . (int)$static_uint_video_id . '\' ';
		if( !mysqli_query($this->sql_connect, $str_tsql) )
		{
			$this->write_error_logs($str_tsql);
			return false;
		}
		else
			return true;
	}

	function delete_news_video($static_uint_video_id)
	{
		$str_tsql = 'DELETE 
		FROM `news_videos` 
		WHERE `VideoId` = \'' . (int)$static_uint_video_id . '\' ';
		if( !mysqli_query($this->sql_connect, $str_tsql) )
		{
			$this->write_error_logs($str_tsql);
			return false;
		}
		else
			return true;
	}

	function get_image_by_size_n_hash($static_uint_width, $static_uint_height, $static_str_hash)
	{
		$str_query = 'SELECT * FROM `image_uploads` WHERE `Width` = \'' . (int)$static_uint_width . '\' AND `Height` = \'' . (int)$static_uint_height . '\' AND `Hash` = \'' . mysqli_real_escape_string($this->sql_connect, $static_str_hash) . '\' ';
		if( !( $sql_result = mysqli_query($this->sql_connect, $str_query) ) )
		{
			$this->write_error_logs($str_query);
			return false;
		}
		else
			return $this->result_setto_array($sql_result);
	}

	function add_image($static_uint_width, $static_uint_height, $static_str_hash, $static_str_img_type)
	{
		$str_temp_file_name = dechex(time()) . str_pad(mt_rand(0, 65535), 4, '0', STR_PAD_LEFT);

		$str_tsql = 'INSERT INTO `image_uploads` (`FileName`, `Width`, `Height`, `Hash`) VALUES (\'' . mysqli_real_escape_string($this->sql_connect, $str_temp_file_name) . '\', \'' . (int)$static_uint_width . '\', \'' . (int)$static_uint_height . '\', \'' . mysqli_real_escape_string($this->sql_connect, $static_str_hash) . '\') ';

		mysqli_query($this->sql_connect, 'BEGIN;');

		if( !mysqli_query($this->sql_connect, $str_tsql) )
		{
			$this->write_error_logs($str_tsql);

			mysqli_query($this->sql_connect, 'ROLLBACK;');
			mysqli_query($this->sql_connect, 'COMMIT;');

			return false;
		}

		$uint_image_id = mysqli_insert_id($this->sql_connect);
		$str_file_name = (date('y') % 10) . dechex(date('n')) . date('d') . str_pad(($uint_image_id % 10000), 4, '0', STR_PAD_LEFT) . '.' . $static_str_img_type;

		$str_tsql = 'UPDATE `image_uploads` SET `FileName` = \'' . mysqli_real_escape_string($this->sql_connect, $str_file_name) . '\' WHERE `ImageId` = \'' . (int)$uint_image_id . '\' ';

		if( !mysqli_query($this->sql_connect, $str_tsql) )
		{
			$this->write_error_logs($str_tsql);

			mysqli_query($this->sql_connect, 'ROLLBACK;');
			mysqli_query($this->sql_connect, 'COMMIT;');

			return false;
		}

		mysqli_query($this->sql_connect, 'COMMIT;');

		return $str_file_name;
	}

	function delete_image_by_file_name($static_str_file_name)
	{
		$str_tsql = 'DELETE FROM `image_uploads` WHERE `FileName` = \'' . mysqli_real_escape_string($this->sql_connect, $static_str_file_name) . '\' ';
		if( !mysqli_query($this->sql_connect, $str_tsql) )
		{
			$this->write_error_logs($str_tsql);
			return false;
		}
		else
			return true;
	}
}
?>