<?php
/* Ulyxex version 1.6.7.8 ***************/
/* code http://ulyxex.logz.org **********/
/* Andre Lozano http://andre-lozano.org */

//~ this code is used by "page" and "search"
class ViewPage extends Ulyxex {
	public object $h;
	public object $t;
	public int $pos;
	public string $typePage;
	public string $Select;
	public string $From;
	public string $SelectCount;
	public string $OrderSort;
	public array $Cond;
	public string $page_data;
	public string $next_pages;
	public int $items;
	
	function __construct($pageId=0,$sortStyle=0,$typePage="page"){
		$this->h = New Htmlz();
		$this->t = New Translate();
		$this->pos = isset($_GET['pg'])?$this->h->num($_GET['pg']):0;
		$this->Select = 	SELECT.
								ARTICLES.".ID ARTID,".ARTICLES.".CONTENT,".ARTICLES.".DATEPAGE,".ARTICLES.".SUBJECT,".
								USERS.".USERNAME,".USERS.".ID IDUSERID";
		$this->From = 		FROM.
								ARTICLES.
								INNERJOIN.PAGES._ON_.ARTICLES.".PAGEID = ".PAGES.".ID".
								INNERJOIN.USERS._ON_.ARTICLES.".USERID = ".USERS.".ID";
		$this->SelectCount = 	SELECT."COUNT(".ARTICLES.".ID) AS NUM";
		$this->OrderSort = "";
		$this->Cond = array();
		$this->typePage = $typePage;
		if ($pageId){
			$this->page_data = $this->page_data($pageId,$sortStyle);
			$this->next_pages = $this->next_pages($pageId);
		}
	}		
	public function page_data($pageId=0,$sortStyle=0){
		$h = $this->h;$t = $this->t;
		$sortOrder = array("DATEPAGE DESC","SUBJECT DESC","DATEPAGE ASC");
		$pgPos = ($this->pos)?($this->pos - 1) * ARTICLESPAGE:0;
		$this->Cond = array();
		$i = 0;
		if (isset($_POST['searchwebsite'])){// IF SEARCH !!!
			$this->Cond[] = " MATCH(".ARTICLES.".CONTENT,".ARTICLES.".SUBJECT) AGAINST('".$h->safe($_POST['searchwebsite'])."') ";
		} else {
			$this->Cond[] = PAGES.".ID = ".$pageId;
		}
		$this->Cond[] = ARTICLES.".HIDE = 0";
		$this->Cond[] = PAGES.".HIDE = 0";
		$this->OrderSort = isset($_POST['searchwebsite'])?"":ORDERBY.$sortOrder[$sortStyle]." LIMIT ".$pgPos.",".ARTICLESPAGE;
		$query = $this->Select.$this->From.$this->Where($this->Cond).$this->OrderSort;
		$query = $this->q($query,true);
		if ($line = $this->fetch($query)){
			$article = $line['CONTENT'];
			$article .= $h->nav(
				$h->ahref(
					"index.php?k=user&amp;v=".$line['IDUSERID']."&amp;t=".$h->clean_short_url($line['USERNAME']),
					$line['USERNAME'],
					$h->alt($t->w("show")." ".$t->wz("user").$line['USERNAME'])
				)
				." ".$line['DATEPAGE']." ".
				$h->ahref(
					"index.php?k=article&amp;v=".$line['ARTID']."&amp;t=".$h->clean_short_url($line['SUBJECT']),
					"url",
					$h->alt($t->w("open url")." ".$t->wz("article").$line['SUBJECT'])
				)
			,$h->v("class","contenturl").$h->v("id",$t->w("article-nav").$line['ARTID']));
			
			$result = $h->article($article,$h->v("id","article_".$line['ARTID']));
			
			while ( $line = $this->fetch($query) ){
				if (isset($_POST['searchwebsite']) && $i == ARTICLESPAGE){// IF SEARCH !!! items max
					break;
				}
				$article = $line['CONTENT'];
				$article .= $h->nav(
					$h->ahref(
						"index.php?k=user&amp;v=".$line['IDUSERID']."&amp;t=".$h->clean_short_url($line['USERNAME']),
						$line['USERNAME'],
						$h->alt($t->wr("show").$t->wz("user").$line['USERNAME'])
					)
					." ".$line['DATEPAGE']." ".
					$h->ahref(
						"index.php?k=article&amp;v=".$line['ARTID']."&amp;t=".$h->clean_short_url($line['SUBJECT']),
						"url",
						$h->alt($t->wr("open url").$t->wz("article").$line['SUBJECT'])
					)
				,$h->v("class","contenturl").$h->v("id",$t->w("article-nav").$line['ARTID']));
				
				$result .= $h->article($article,$h->v("id","article_".$line['ARTID']));
				$i++;
			}
			return $h->articles($result,$t->w("main-content-articles"));
		} else {
			return "";
		}
	}
	public function next_pages($pageId=0){
		$h = $this->h;$t = $this->t;
		if (isset($_POST['searchwebsite'])){// IF SEARCH !!!
			return "";
		}
		$this->Cond = array();
		$this->Cond[] = ARTICLES.".HIDE = 0";
		$this->Cond[] = PAGES.".HIDE = 0";
		$this->Cond[] = PAGES.".ID = ".$pageId;
		
		$query = $this->SelectCount.$this->From.$this->Where($this->Cond);
		$query = $this->q($query);
		if ($line = $this->fetch($query)){
			$this->items = $line['NUM'];
			/* total pages */
			$pages = $this->items/ARTICLESPAGE; 
			$pages++;
			$result = array();
			if ($pages > 2){
				for($i=1;$i < $pages;$i++){
					$num = $i?strval($i):"0";
					if ($i == $this->pos || ($this->pos == 0 && $i == 1)){
						$styles = $h->v("class","linkbtn").$h->v("style","background-color:Gainsboro;font-weight:bold;");
						$result[] = $h->ahref("index.php?k=".$this->typePage."&amp;v=".$pageId."&amp;pg=".$num,$num,$styles.$h->alt($t->w("next pages")));
					} else {
						$styles = $h->v("class","linkbtn");
						$result[] = $h->ahref("index.php?k=".$this->typePage."&amp;v=".$pageId."&amp;pg=".$num,$num,$styles.$h->alt($t->w("next pages")));
					}
				}
			}
			return implode(" . ",$result);
		}
	}
}
?>

page url