<?php
	
	if( !$this->network->id ) {
		$this->redirect('home');
	}
	if( !$this->user->is_logged ) {
		$this->redirect('home');
	}
	
	$db2->query('SELECT 1 FROM users WHERE iduser="'.$this->user->id.'" AND is_network_admin=1 LIMIT 1');
	if( 0 == $db2->num_rows() ) {
		$this->redirect('dashboard');
	}
	
	
	/*************************************************************************/
	// needed before proceeding
	require_once('_all-required-language.php');
	
	$this->load_langfile('global/global.php');	
	$this->load_langfile('inside/admin.php');

	/*************************************************************************/
	
	
	require_once('_all-required-dashboard-admin.php');
	

	/*************************************************************************/

	$D->codpage = '';
	if ($this->param('p')) $D->codpage = $this->param('p');

	$D->optionactive_admin = 7;
	$D->tab_sub = 1;

	if (!empty($D->codpage)) {
		
		$r = $this->db2->fetch("SELECT * FROM pages WHERE code='".$D->codpage."' LIMIT 1");
		if (!$r) $this->redirect($C->SITE_URL.'admin/pages');
		
		$D->codpage = $r->code;
		$D->idcategory = $r->idcategory;
		$D->idsubcategory = $r->idsubcategory;
		$D->titlepage = stripslashes($r->title);
		$D->description = stripslashes($r->description);
		$D->status = $r->status;
		$D->verified = $r->verified;
		unset($r);
		
		$this->load_template('admin_pages-edit.php');
		
	} else {

		$D->htmlPages = '';
		$r = $this->db2->query('SELECT * FROM pages ORDER BY created DESC');
		while( $obj = $this->db2->fetch_object($r) ) {
			$D->title = stripslashes($obj->title);
			$D->idpage = $obj->idpage;
			$D->idowner = $obj->idowner;
			$D->avatar = $obj->avatar_page;
			$D->status = $obj->status;
			$D->code = $obj->code;
			$D->url = $obj->url;
			$D->htmlPages .= $this->load_template('__admin-pages-one-page.php', FALSE);
		}
	
		unset($r, $obj);

		$this->load_template('admin_pages.php');
	}
		
	/*************************************************************************/

?>