<?php
/*
* @ServerMon v1.1
* @Developed by Maksa988
* @www.Server-Mon.ru
* @Copyright (C) 2014
*/
 if(!defined('SMON'))
	die('Hacking attempt!');
	
class pagesModel extends Controller {
	public function getPage($param) {
		global $db;
		$sql = "SELECT * FROM `".$this->cfg('prefix')."pages` WHERE `page_url` = '{$param}' LIMIT 1";
		$result = $db->query($sql);

		if($result->num_rows == 1){
			return $result->fetch_assoc();
		}
		return false;
	}
	public function getPageID($param) {
		global $db;
		$sql = "SELECT * FROM `".$this->cfg('prefix')."pages` WHERE `page_id` = '{$param}' LIMIT 1";
		$result = $db->query($sql);

		if($result->num_rows == 1){
			return $result->fetch_assoc();
		}
		return false;
	}
	public function editPage($param, $id) {
		global $db;
		$sql = "UPDATE `".$this->cfg('prefix')."pages` SET ".$param." WHERE `page_id` = ".$id;
		$db->query($sql);
		
		if(!$db->error) {
			return true;
		}
		return false;
	}
	public function getPages($param = '') {
		global $db;
		$sql = "SELECT * FROM `".$this->cfg('prefix')."pages` ".$param;
		$result = $db->query($sql);

		$items = array();
		
		if($result->num_rows >= 1){
			while($data = $result->fetch_assoc())
			$items[] = $data;
			
			return $items;
		}
		return false;
	}
	public function createPage($name, $url, $text) {
		global $db;
		$sql = "INSERT INTO `".$this->cfg('prefix')."pages` 
		(	page_name, 
			page_url, 
			page_text, 
			page_author, 
			page_add_time, 
			page_status
		) VALUES (
			'{$name}', 
			'{$url}', 
			'{$text}', 
			'{$_SESSION['user_id']}', 
			NOW(), 
			'1')";
		$db->query($sql);
		
		if(!$db->error) {
			return $db->insert_id;
		}
		return false;;
	}
	public function deletePage($id) {
		global $db;
		$sql = "DELETE FROM `".$this->cfg('prefix')."pages` WHERE `page_id` = '{$id}'";
		$db->query($sql);
		
		if(!$db->error) {
			return true;
		}
		return false;
	}
}