Location: PHPKode > projects > nSys Flat News System > nsys-flat-news-system/include/functions/classes-admin.php
<?php

/**
 *
 * nSys 2.0 Flat - News System by b3.portal
 * HomePage: http://bosniamaj.co.cc
 * Theese are classes and functions required for script to work
 *
 *    DO NOT EDIT THIS FILE
 *
 * @version 2.0
 * @copyright hide@address.com 2010
 */

/*
   Working with members
 */
class User extends DisplayHtml{
	var $nSysUser=0;
	var $nSysUserID=0;
	var $nSysUserName=0;
	var $nSysUserLevel=0;
	var $IDmax=0;
	var $LastBackup=0;

	function CheckLogIn($i=NULL){
		$go .= $this->DisplayNav();
		if((isset($_COOKIE["nSysUser"]))||($this->nSysUser==1))
		{
			$cookie=explode("|",$_COOKIE["nSysUser"]);
			$readfile=file("../include/users.php");
			foreach($readfile as $number => $userinfo)
			{
				if(!preg_match("/^<\?/",$userinfo))
				{
					$info=explode("|",$userinfo);
					if(($cookie[1]==$info[2])&&($cookie[2]==$info[3]))
					{
						$this->nSysUser=1;
						$this->nSysUserName=$info[2];
						if(($info[1]>100)||($info[1]<0)||(!ctype_digit($info[1])))
						{
							$this->nSysUserLevel=1;
							$go .= $this->DivOpen("error","Error");
							$go .= LangErrorLevel;
							$go .= $this->DivClose();
						}
						else
						{
							$a=$info[1];
							$b=$info[0];
							$i++;
						}
					}
				}
			}
			if($i==1)
			{
				$this->nSysUserLevel=$a;
				$this->nSysUserID=$b;
				$go .= $this->ShowPages(htmlspecialchars($_GET["page"]),htmlspecialchars($_GET["do"]),$i);
			}
			elseif($i!=1)
			{
				$go .= $this->DivOpen("error","Error");
				$go .= LangIncorrectLogIn;
				$go .= $this->DivClose();
				$go .= $this->DisplayLoginForm();
			}
		}
		else
		{
			$go .= $this->DisplayLoginForm();
		}
		return $go;
	}

	/* show home */
	function ShowHome(){
		if($this->nSysUser==1)
		{
			$go .= $this->AutomaticBackup();
			$go .= $this->Heading("h2",LangWelcome." ".$this->nSysUserName." [".$this->aOpen("?page=logout","",LangLogOut).$this->aClose()."]");
			$go .= LangChooseLang."<br />";
			$go .= $this->DivOpen("cats","Forms");
			$go .= $this->DisplayLangs();
			$go .= $this->DivClose();
			$go .= LangCats.":<br />";
			$go .= $this->DivOpen("cats","Forms");
			$go .= $this->DisplayCats();
			$go .= $this->DivClose();
		}
		else
		{
			$go .= $this->CheckLogIn();
		}
		return $go;
	}

	function DisplayLangs($c=1){
		$langfile = "../include/InstalledLangs.txt";
		$file=file($langfile, FILE_IGNORE_NEW_LINES);
		if ($c==1)
		{
			$go .= $this->FormOpen("?do=lang","post","SelectLang","","");
		}
		$go .= "<select name=\"lang\" id=\"lang\">";
		foreach ($file as $num => $f)
		{
			$n=explode(" - ",$f);
			$go .= "<option value=\"$n[1]\">$n[0]</option>";
		}
		$go .= "</select> &nbsp;";
		if ($c==1)
		{
			$go .= $this->InputOpen("submit","SelectLang",LangContinue,"");
		}
		if ($this->CheckUser("level",$this->nSysUserName)>=90)
		{
			$go .= $this->aOpen("?do=addlang","",LangOrAddLang).$this->aClose();
		}
		if ($c==1)
		{
			$go .= $this->FormClose();
		}
		return $go;
	}

	function DisplayCats($c=0){
		global $nSysNewsShow;
		$catfile="../include/categories.php";
		$file=file($catfile);
		if (isset($_GET["do"]))
		{
			$do=$_GET["do"];
			$newname=htmlspecialchars($_POST["name"]);
			$newdesc=htmlspecialchars($_POST["desc"]);
			$catid=htmlspecialchars($_POST["catid"]);
			$go .= $this->ManageCats($do,$catid,$newname,$newdesc);
		}
		$go .= "<ul class=\"vertical\">";
		$go .= "<li>".$this->DivOpen("0","").$this->aOpen("?do=addcat","",LangAddCat).$this->aClose().$this->DivClose()."</li>\n";
		foreach ($file as $num => $f)
		{
			if((!preg_match("/^<\?/",$f))&&($f!="\n"))
			{
				$n=explode("|",$f);
				$n[2] = str_replace("\n","",$n[2]);
				$forma .= $this->FormOpen("?do=editcat","post","EditCat","","");
				$forma .= "<label>".LangName."<br /> ".$this->InputOpen("text","name","$n[1]","")."</label>";
				$forma .= "<label>".LangDesc."<br /> ".$this->InputOpen("text","desc","$n[2]","")."</label>";
				$forma .= $this->InputOpen("hidden","catid","$n[0]","")."</label>";
				$forma .= "<label>".$this->InputOpen("submit","EditCat",LangContinue,"")."</label>";
				$forma .= $this->FormClose();
				$go .= "<li>";
				$go .= $this->DivOpen("0","").$n[1]."<em style=\"float:none;font-size:11px\">".$n[2]."</em><span id=\"$n[0]\">$forma</span>".$this->DivClose();
				$go .= "<em>[".LangIC."] echo \$news->DisplayNews($n[0]);</em>";
				$go .= "</li>\n";
				unset($forma);
			}
		}
		$go .= "</ul><div class=\"clearboth\">&nbsp;</div>";
		return $go;
	}

	function ManageCats($do,$id,$newname,$newdesc,$c=0){
		$catfile="../include/categories.php";
		if ($do=="editcat")
		{
			if ((!empty($newname))&&(!empty($id)))
			{
				if (empty($newdesc))
				{
					$newdesc=LangNoDesc;
				}
				$file=file($catfile);
				foreach ($file as $num => $f)
				{
					if(!preg_match("/^<\?/",$f))
					{
						$n=explode("|",$f);
						if ($id==$n[0])
						{
							$fp=fopen($catfile,"r");
							$l = strlen($f);
							$r=fread($fp,filesize($catfile));
							$l1 = strlen($r);
							if(substr($r,$l1-$l,$l)==$f)
							{
								$nn="";
							}
							else
							{
								$nn="\n";
							}
							fclose($fp);
							$old=$f;
							$c++;
						}
					}
				}
				if($c==1)
				{
					$str = str_replace("<?php die(\"\"); ?>","",file_get_contents($catfile));
					$exp = explode($old,$str);
					$new .= "<?php die(\"\"); ?>";
					$new .= $exp[0];
					$new .= $id."|".$newname."|".$newdesc;
					$new .= $nn.$exp[1];
					$go = $this->WriteToFiles($catfile,"w",$new);
				}
				else
				{
					$go .= $this->DivOpen("error","Error");
					$go .= LangNoSuchCat."!";
					$go .= $this->DivClose();
				}
			}
			else
			{
				$go .= $this->DivOpen("error","Error");
				$go .= LangFieldsEmpty;
				$go .= $this->DivClose();
			}
		}
		if ($do=="addcat")
		{
			if (isset($_POST["AddCat"]))
			{
				$file=file($catfile);
				foreach ($file as $num => $f)
				{
					if (!preg_match("/^<\?/",$f))
					{
						$n=explode("|",$f);
						if($n[0]>=$this->IDmax) { $this->IDmax=$n[0]+1; }
					}
				}
				if((!empty($newname))&&($this->IDmax!=0))
				{
					if(empty($newdesc)) { $newdesc = LangNoDesc; }
					$input="\n".$this->IDmax."|$newname|$newdesc";
					$go .= $this->WriteToFiles($catfile,"a",$input);
				}
			}
			else
			{
				$forma .= $this->FormOpen("?do=addcat","post","AddCat","","");
				$forma .= LangAddCat."<br />";
				$forma .= "<label>".LangName."<br /> ".$this->InputOpen("text","name","$n[1]","")."</label>";
				$forma .= "<label>".LangDesc."<br /> ".$this->InputOpen("text","desc","$n[2]","")."</label>";
				$forma .= "<label>".$this->InputOpen("submit","AddCat",LangContinue,"")."</label>";
				$forma .= $this->FormClose();
				$go .= $forma;
			}
		}
		return $go;
	}

	function SelectCat($selected=NULL){
		$catfile="../include/categories.php";
		$file=file($catfile);
		$go .= "<select name=\"category\" id=\"category\">";
		foreach ($file as $num => $f)
		{
			if (!preg_match("/^<\?/",$f))
			{
				$n=explode("|",$f);
				$selected=str_replace("\n","",$selected);
				$n[0]=str_replace("\n","",$n[0]);
				if ($selected==$n[0]) {	$s=" selected=\"selected\""; }
				else { $s=""; }
				$go .= "<option value=\"$n[0]\"$s>$n[1]</option>";
			}
		}
		$go .= "</select>";
		return $go;
	}
	function CommsPermission($selected=1){
		$go .= "<select name=\"comms\" id=\"comms\">";
		$selected=str_replace("\n","",$selected);
		if (($selected=="1"))
		{
			$go .= "<option value=\"1\" selected=\"selected\">".LangYes."</option>";
			$go .= "<option value=\"0\">".LangNo."</option>";
		}
		else
		{
			$go .= "<option value=\"1\">".LangYes."</option>";
			$go .= "<option value=\"0\" selected=\"selected\">".LangNo."</option>";
		}
		$go .= "</select>";
		return $go;
	}

	/* Navigation */
	function DisplayNav(){
		$go .= $this->DivOpen("navigation","navigation");
		$go .= "<ul>";
		$go .= "<li>".$this->aOpen(dirname($_SERVER["PHP_SELF"]),"","<em>".LangNavHomeDesc."</em>".LangNavHome).$this->aClose()."</li>";
		if($this->nSysUser==1)
		{
			$go .= "<li>".$this->aOpen("?page=news&do=submit","","<em>".LangNavSNewsDesc."</em>".LangNavSNews).$this->aClose()."</li>";
			$go .= "<li>".$this->aOpen("?page=news&do=edit","","<em>".LangNavNewsDesc."</em>".LangNavNews).$this->aClose()."</li>";
			$go .= "<li>".$this->aOpen("?page=news&do=approve","","<em>".LangNavAppDesc."</em>".LangNavApp.$this->CountPending()).$this->aClose()."</li>";
			$go .= "<li>".$this->aOpen("?page=users","","<em>".LangNavUsersDesc."</em>".LangNavUsers).$this->aClose()."</li>";
			$go .= "<li>".$this->aOpen("?page=config","","<em>".LangNavConfigDesc."</em>".LangNavConfig).$this->aClose()."</li>";
			$go .= "<li>".$this->aOpen("?page=backups","","<em>".LangNavBDesc."</em>".LangNavB).$this->aClose()."</li>";
		}
		$go .= "<li>".$this->aOpen("?page=help","","<em>".LangNavHelpDesc."</em>".LangNavHelp).$this->aClose()."</li>";
		$go .= "</ul>";
		$go .= $this->DivClose();
		return $go;
	}

	/* Display pages */
	function ShowPages($cat,$subcat,$i){
		switch($cat)
		{
			case "news":
				$go = $this->AdminNews($subcat,$i);
				break;
			case "users":
				$go = $this->AdminUsers($subcat,$i);
				break;
			case "config":
				$go = $this->ShowConfig();
				break;
			case "logout":
				$go = $this->LogOut();
				break;
			case "backups":
				$go = $this->ShowBackups($subcat);
				break;
			case "help":
				$go = $this->ShowHelp();
				break;





			default:
			$go = $this->ShowHome();
		}
		return $go;
	}
	/* Display pages */

	function CountPending($i=0){
		$folder="../include/";
		$files=scandir($folder);
		for($j=0;$j<count($files);$j++)
		{
			if(preg_match("/^pending/",$files[$j]))
			{
				$i++;
			}
		}
		if($i<1)

		{
			$i="";
		}
		else
		{
			$i="($i)";
		}
		return $i;
	}

	/* News admin page */
	function AdminNews($sub,$i=NULL){
		if(($this->nSysUser==1)&&(isset($this->nSysUserName)))
		{
			$newsfile="../include/news.php";
        /* submit news */
		if($sub=="submit")
		{
			if(isset($_POST["SubmitNews"]))
			{
				$subject=htmlspecialchars($_POST["subject"]);
				$text=htmlspecialchars($_POST["newstext"]);
				$text=str_replace("\n","<br />",$text);
				$text=str_replace("\r","",$text);
				$text=str_replace("|","-",$text);
				$date=date("d.m.Y H:i:s");
				$cat=htmlspecialchars($_POST["category"]);
				$comms=htmlspecialchars($_POST["comms"]);
				if(empty($cat))
				{
					$cat="1";
				}
				if((!empty($subject))&&(!empty($text)))
				{
					$old = explode("<?php die(\"\"); ?>",file_get_contents($newsfile));
					  $findi=explode("|",$old[1]);
					  $id=$findi[0]+1;
					$new .= "<?php die(\"\"); ?>";
					$new .= "\n$id|$date|$this->nSysUserName|$subject|$text|0|0|$cat|$comms";
					$new .= $old[1];
					echo $this->WriteToFiles($newsfile,"w",$new);
					#$go .= $this->ChangeNumOfUser($this->nSysUserID,1,NULL);
				}
				else
				{
					$go .= $this->DivOpen("error","Error");
					$go .= LangFieldsEmpty;
					$go .= $this->DivClose();
				}
			}
			elseif(isset($_POST["UploadNews"]))
			{
				if($_FILES["txtnews"]["size"]>0)
				{
					if($_FILES["txtnews"]["type"]!="text/plain")
					{
						$go .= $this->DivOpen("error","Error");
						$go .= LangFileType;
						$go .= $this->DivClose();
					}
					else
					{
						$user=str_replace(" ","_",$this->nSysUserName);
						$date=date("d-m-Y-H-i-s");
						if(copy($_FILES["txtnews"]["tmp_name"],"../include/pending-".$user."-".$date.".txt"))
						{
							$go .= $this->DivOpen("success","Success");
							$go .= LangUploadSuccess;
							$go .= $this->DivClose();
						}
						else
						{
							$go .= $this->DivOpen("error","Error");
							$go .= LangUploadFail;
							$go .= $this->DivClose();
						}
					}
				}
				else
				{
					$go .= $this->DivOpen("error","Error");
					$go .= LangFileEmpty;
					$go .= $this->DivClose();
				}
			}
			$go .= $this->Heading("h2",LangSubmitNews);
			$go .= $this->DivOpen("SubmitNews","TopFull Forms");
			$go .= $this->FormOpen("","post","UploadNews","","","multipart/form-data");
			$go .= "<label>".LangUploadFile.$this->DivOpen("linkhelp","linkhelp").$this->aOpen("","","<em>".LangHelpUpload."</em>[".LangNavHelp."]").$this->aClose().$this->DivClose()."<br /> ";
			$go .= $this->InputOpen("file","txtnews","","")."</label>";
			$go .= "<label>".$this->InputOpen("submit","UploadNews",LangUpload,"")."</label>";
			$go .= $this->FormClose();
			$go .= "<br />".LangOrSubmit."<br />";
			$go .= $this->FormOpen("","post","SubmitNews","","");
			$go .= "<label>".LangSubject."<br /> ".$this->InputOpen("text","subject","","")."</label>";
			$go .= "<label>".LangNewsText."<br /> ".$this->TextArea("newstext","85","20","")."</label>";
			$go .= "<label>".LangCats."<br /> ".$this->SelectCat()."</label>";
			$go .= "<label>".LangAllowComms."<br /> ".$this->CommsPermission(1)."</label>";
			$go .= "<label>".$this->InputOpen("submit","SubmitNews",LangContinue,"")."</label>";
			$go .= $this->FormClose();
			$go .= $this->DivClose();
		}
        /* submit news */
			/* edit news */
			if($sub=="edit")
			{
				$newsid=$_GET["id"];
				if(isset($newsid))
				{
					$go .= $this->EditNews($newsid);
				}
				$file=file($newsfile);
				$link="?page=news&do=edit&id=";
				$go .= $this->Heading("h2",LangEditNews);
				$go .= $this->DivOpen("EditNews","Forms");
				$go .= "<div id=\"Accordion1\" class=\"Accordion\" tabindex=\"0\">";
				#$go .= "".$this->DivOpen("0","").LangEdit.$this->DivClose()."<em>".LangDelete."</em></li>\n";
				foreach($file as $num => $f)
				{
					if(!preg_match("/^<\?/",$f))
					{
						$n=explode("|",$f);
						$n[4]=str_replace("<br />","\n",$n[4]);
						$n[4]=htmlspecialchars_decode($n[4]);
						$n[4]=stripslashes($n[4]);
						$n[8]=str_replace("\n","",$n[8]);
						$n[8]=str_replace("\r","",$n[8]);
						$n[8]=str_replace(" ","",$n[8]);
						/* Form */
						$forma .= $this->FormOpen("$link".$n[0],$method="post","SubmitForm".$n[0],"","","");
						$forma .= "<label>".LangSubject."<br /> ".$this->InputOpen("text","subject","$n[3]","")."</label>";
			            $forma .= "<label>".LangNewsText."<br /> ".$this->TextArea("newstext","85","20","$n[4]")."</label>";
						$forma .= "<label>".LangCats."<br /> ".$this->SelectCat($n[7])."</label>";
						$forma .= "<label>".LangAllowComms."<br /> ".$this->CommsPermission($n[8])."</label>";
            			$forma .= "<label>".$this->InputOpen("submit","SubmitNews".$n[0],LangContinue,"")."</label>";
						$forma .= $this->InputOpen("hidden","nid",$n[0],"","");
						$forma .= $this->FormClose();

						/* Form */
						$go .= "<div class=\"AccordionPanel\">\n";
						$go .= $this->DivOpen("$n[0]","AccordionPanelTab").$n[3]." (".$n[2].")".$this->DivClose()."\n<div class=\"AccordionPanelContent\">$forma</div>\n";
						$go .= "<em>";
						$go .= $this->aOpen("?page=news&do=delete&id=$n[0]","",LangDelete).$this->aClose();
						$go .= "</em></div>\n";
						unset($forma);
					}
				}
				$go .= "</div><div class=\"clearboth\">&nbsp;</div>
				<script type=\"text/javascript\">
				<!--
				var Accordion1 = new Spry.Widget.Accordion(\"Accordion1\");
				//-->
				</script>";
				$go .= $this->DivClose();
			}
			/* edit news */
			/* approve */
				if($sub=="approve")
				{
					if(isset($_POST["SubmitNews"]))
					{
						$subject=htmlspecialchars($_POST["subject"]);
						$text=htmlspecialchars($_POST["newstext"]);
						$text=str_replace("\n","<br />",$text);
						$text=str_replace("\r","",$text);
						$text=str_replace("|","-",$text);
						$ninfo=htmlspecialchars($_POST["newsinfo"]);
						$n=explode("-",$ninfo);
						$cat=htmlspecialchars($_POST["category"]);
						$comms=htmlspecialchars($_POST["comms"]);
						$authorID=$this->CheckUser("id",$n[0]);
						$fileinfo=htmlspecialchars($_POST["fileinfo"]);
						if(empty($cat))
						{
							$cat="1";
						}
						if((!empty($subject))&&(!empty($text)))
						{
							$old = explode("<?php die(\"\"); ?>",file_get_contents($newsfile));
							$findi=explode("|",$old[1]);
							$id=$findi[0]+1;
							$new .= "<?php die(\"\"); ?>";
							$new .= "\n$id|$n[1]|$n[0]|$subject|$text|0|0|$cat|$comms";
							$new .= $old[1];
							if ($this->WriteToFiles($newsfile,"w",$new))
							{
								unlink("../include/".$fileinfo);
								#$go .= $this->ChangeNumOfUser($authorID,1,NULL);
							}

						}
						else
						{
							$go .= $this->DivOpen("error","Error");
							$go .= LangFieldsEmpty;

							$go .= $this->DivClose();
						}

					}
					$folder="../include/";
					$files=scandir($folder);
					$go .= $this->Heading("h2",LangApproveNews);
					$go .= $this->DivOpen("EditNews","Forms");
					$go .= "<ul class=\"vertical\">";
					$go .= "<li>".$this->DivOpen("0","").LangNavApp.$this->DivClose()."<em>".LangDelete."</em></li>\n";
					$j=0;
					for($i=0;$i<count($files);$i++)
					{
						if(preg_match("/^pending/",$files[$i]))
						{
							$n=explode("-",$files[$i]);
							$author=$n[1];
							$date=str_replace(".txt","" ,"$n[2].$n[3].$n[4] $n[5]:$n[6]:$n[7]" );

							$file = $folder.$files[$i];
							$fp=fopen($file,"r");
							$read=fread($fp,filesize($file));
							$info = explode("\n",$read);
							$sub=str_replace("\n","",$info[0]);
							$text=str_replace($sub,"",$read);

							$forma .= $this->FormOpen("","post","SubmitNews","","");
							$forma .= "<label>".LangSubject."<br /> ".$this->InputOpen("text","subject","$sub","")."</label>";
							$forma .= "<label>".LangNewsText."<br /> ".$this->TextArea("newstext","85","20","$text")."</label>";
							$forma .= "<label>".LangCats."<br /> ".$this->SelectCat()."</label>";
							$forma .= "<label>".LangAllowComms."<br /> ".$this->CommsPermission(1)."</label>";
							$forma .= "<label>".$this->InputOpen("submit","SubmitNews",LangContinue,"")."</label>";
							$forma .= "<label>".$this->InputOpen("hidden","newsinfo",$author."-".$date,"")."</label>";
							$forma .= "<label>".$this->InputOpen("hidden","fileinfo",$files[$i],"")."</label>";
							$forma .= $this->FormClose();

							$go .= "<li>";
							$go .= $this->DivOpen("0","").$sub." by ".$author."<span id=\"$n[0]\">$forma</span>".$this->DivClose();
							$go .= "<em>";
							$go .= $this->aOpen("?page=news&do=delete&id=$n[0]","",LangDelete).$this->aClose();
							$go .= "</em></li>\n";
							unset($forma);

							$j++;
						}
					}
					$go .= "</ul><div class=\"clearboth\">&nbsp;</div>";
					$go .= $this->DivClose();
					if($j<1)
					{
						$go .= $this->DivOpen("success","Success");
						$go .= LangNoPending;
						$go .= $this->DivClose();
					}
				}
			/* approve */
			/* delete */
			if($sub=="delete")
			{
				$id=$_GET["id"];
				if (!ctype_digit($id))
				{
					$go .= $this->DivOpen("error","Error");
					$go .= LangIDNotNumeric;
					$go .= $this->DivClose();
				}
				else
				{
					$nf=file($newsfile);
					foreach ($nf as $num => $f)
					{
						if (!preg_match("/^<\?/",$f))
						{
							$n=explode("|",$f);
							if($id==$n[0])
							{

								$fp=fopen($newsfile,"r");
								$l = strlen($f);
								$r=fread($fp,filesize($newsfile));
								$l1 = strlen($r);
								if(substr($r,$l1-$l,$l)==$f)
								{
									$old="\n".$f;
								}
								else
								{
									$old=$f;
								}
								fclose($fp);
								$author=$n[2];
								$title=$n[3];
								break;
							}
						}
					}
					if(!isset($_GET["confirm"]))
					{
						$forma .= $this->FormOpen("?page=news&do=delete&id=$id&confirm=ok","post","DeleteNews1","","");
						$forma .= "<label>".$this->InputOpen("submit","DeleteNews",LangContinue,"")."</label>";
						$forma .= $this->FormClose();
						$go .= $this->DivOpen("EditNews","Forms");

						$go .= LangDelNews." ".$title."<br />";
						$go .= LangConfirm;
						$go .= $forma;
						$go .= $this->DivClose();
						unset($forma);
					}
					elseif($_GET["confirm"]=="ok")
					{
						$alevel=$this->CheckUser("level",$author);;
						if(($this->nSysUserLevel>$alevel)||($this->nSysUserName==$author))
						{
							$str=str_replace("<?php die(\"\"); ?>","",file_get_contents($newsfile));
							$exp=explode($old,$str);
							$tw .= "<?php die(\"\"); ?>";
							$tw .= $exp[0];
							$tw .= $exp[1];
							$go .= $this->WriteToFiles($newsfile,"w",$tw);
							#$go .= $this->ChangeNumOfUser($this->CheckUser("id",$author),-1);
							if(!headers_sent())
							{
								$go .= header("Location: ?page=news&do=edit");
							}
							else
							{
								$go .= "<script language=\"javascript\">document.location(?page=news&do=edit)</script>";
							}

						}
						else
						{
							$go .= $this->DivOpen("error","Error");
							$go .= LangLowerLevel;
							$go .= $this->DivClose();
						}
					}
				}
			}
			/* delete */
		}
		else
		{
			$go .= $this->DisplayLoginForm();
		}
		return $go;
	}
	/* edit news func */
		function EditNews($nid,$c=0){
			if(($this->nSysUser==1)&&(isset($this->nSysUserName)))
			{
			$newsfile="../include/news.php";
			if(!ctype_digit($nid))
			{
				$go .= $this->DivOpen("error","Error");
				$go .= LangNotNumeric."!";
				$go .= $this->DivClose();
			}
			else
			{
				$file=file($newsfile);
				foreach($file as $num => $f)
				{
					if(!preg_match("/^<\?/",$f))
					{
						$n=explode("|",$f);
						if($nid==$n[0])
						{
							$old=$f;

							$author = $n[2];
							$views = $n[5];
							$comms = $n[6];
							$cat = $n[7];
							$comms1 = $n[8];

							$c++;
						}
					}
				}
				/* check */
				if($c>1)
				{
					$go .= $this->DivOpen("error","Error");
					$go .= LangMultipleNews."!";
					$go .= $this->DivClose();
				}
				elseif($c<1)
				{
					$go .= $this->DivOpen("error","Error");
					$go .= LangNoSuchNews."!";
					$go .= $this->DivClose();
				}

				elseif($c==1)
				{
					if($this->nSysUserLevel >= $this->CheckUser("level",$author))
					{
						if(isset($_POST["SubmitNews$nid"]))
						{
							$title = htmlspecialchars($_POST["subject"]);
							$text = htmlspecialchars($_POST["newstext"]);
							$text = stripslashes($text);
							$text=str_replace("\n","<br />",$text);
							$text=str_replace("\r","",$text);
							$text=str_replace("|","-",$text);
							$date=date("d.m.Y H:i:s");
							$catt=htmlspecialchars($_POST["category"]);
							$comms1=htmlspecialchars($_POST["comms"]);
							if(!empty($catt)) { $cat=$catt; }
							if((!empty($title))&&(!empty($text)))
							{
								$str = str_replace("<?php die(\"\"); ?>","",file_get_contents($newsfile));
								$exp = explode("$old",$str);
								$new .= "<?php die(\"\"); ?>";
								$new .= $exp[0];
								$new .= $nid."|".$date."|".$author."|".$title."|".$text."|".$views."|".$comms."|".$cat."|".$comms1."\n";
								$new .= $exp[1];
								$go = $this->WriteToFiles($newsfile,"w",$new);
							}
							else
							{
								$go .= $this->DivOpen("error","Error");
								$go .= LangFieldsEmpty;
								$go .= $this->DivClose();
							}
						}
					}
					else
					{
						$go .= $this->DivOpen("error","Error");
						$go .= LangLowerLevel;
						$go .= $this->DivClose();
					}
				}
				/* check */
			}
			}
			else
			{
				$go .= $this->DivOpen("error","Error");
				$go .= LangPleaseLogIn;
				$go .= $this->DivClose();
			}
			return $go;
		}


	/* edit news func */
 /* admin users */
	function AdminUsers($subcat,$i){
		if(($this->nSysUser==1)&&(isset($this->nSysUserName)))
		{
			$userfile="../include/users.php";
			$go .= $this->Heading("h2",LangNavUsersDesc);
			if(($subcat=="addnew")&&($this->nSysUserLevel>=90))
			{
				if(isset($_POST["AddUser"]))
				{

					$uf=file($userfile);
					foreach ($uf as $num => $f)
					{
						if (!preg_match("/^<\?/",$f))
						{
							$n=explode("|",$f);
							if($n[0]>=$this->IDmax) { $this->IDmax=$n[0]+1; }
						}
					}
					$username=htmlspecialchars($_POST["username"]);
					$pass=md5(htmlspecialchars($_POST["password"]));
					$email=htmlspecialchars($_POST["email"]);
					$level=htmlspecialchars($_POST["level"]);
					if((!empty($username))&&(!empty($pass))&&(!empty($email))&&(!empty($level))&&($level>0)&&($level<100)&&(ctype_digit($level))&&($level<$this->nSysUserLevel))
					{
						$input="\n".$this->IDmax."|$level|$username|$pass|$email|0|0";
						$go .= $this->WriteToFiles($userfile,"a",$input);
					}
					else
					{
						$go .= $this->DivOpen("error","Error");
						$go .= LangFieldsEmpty;
						$go .= $this->DivClose();
					}
				}
				else
				{
					$forma .= $this->FormOpen("","post","AddUser1","","");
					$forma .= "<label>".LangUsername."<br /> ".$this->InputOpen("text","username","","")."</label>";

					$forma .= "<label>".LangPassword."<br /> ".$this->InputOpen("password","password","","")."</label>";
					$forma .= "<label>".LangEmail."<br /> ".$this->InputOpen("text","email","","")."</label>";
					$forma .= "<label>".LangLevel."<br /> ".$this->InputOpen("text","level","50","",$maxlenght=" maxlength=\"2\"")."</label>";
					$forma .= "<label>".$this->InputOpen("submit","AddUser",LangContinue,"")."</label>";
					$forma .= $this->FormClose();
					$go .= $this->DivOpen("EditUsers","Forms");
					$go .= LangAddUser;
					$go .= $forma;
					$go .= $this->DivClose();
				}
			}

			if($subcat=="edit")
			{
				if(!ctype_digit($_GET["id"]))
				{
					$go .= $this->DivOpen("error","Error");

					$go .= LangIDNotNumeric;
					$go .= $this->DivClose();
				}
				else
				{
					$id=$_GET["id"];
					if (($_GET["confirm"]=="ok")&&(isset($_POST["EditUser"])))
					{
						$userlevel=$this->CheckUser("level",htmlspecialchars($_POST["username"]));
						if (($this->nSysUserLevel>=90)&&($this->nSysUserLevel>$userlevel)&&($id!=$this->nSysUserID))
						{
							$uf=file($userfile);
							$username=htmlspecialchars($_POST["username"]);
							$pass=$_POST["password"];
							$email=htmlspecialchars($_POST["email"]);
							$level=htmlspecialchars($_POST["level"]);
							if (ctype_digit($level))
							{
							    foreach ($uf as $num => $f)
							{
								if (!preg_match("/^<\?/",$f))
								{
									$n=explode("|",$f);
									if ($id==$n[0])
									{
										$a=$n[3];
										$b=$n[5];
										$c=$n[6];
										$old=$f;
									}
								}
							}
							if(empty($pass))
							{
								$pass=$a;
							}
							else
							{
								$pass=md5(htmlspecialchars($_POST["password"]));
							}
							$new="$id|$level|$username|$pass|$email|$b|$c";
							$str=str_replace("<?php die(\"\"); ?>","",file_get_contents($userfile));
							$exp=explode($old,$str);
							$tw .= "<?php die(\"\"); ?>";
							$tw .= $exp[0];
							$tw .= $new;
							$tw .= $exp[1];
							echo $this->WriteToFiles($userfile,"w",$tw);
							}
							else
							{
							    $go .= $this->DivOpen("error","Error");
								$go .= LangIDNotNumeric;
								$go .= $this->DivClose();
							}

						}
						else
						{
							$go .= $this->DivOpen("error","Error");
							$go .= LangErrorEditing;
							$go .= $this->DivClose();
						}
					}
					else
					{
						$uf=file($userfile);
						foreach($uf as $num => $f)
						{
							if (!preg_match("/^<\?/",$f))
							{
								$n=explode("|",$f);
								if($id==$n[0])
								{
									$forma .= $this->FormOpen("?page=users&do=edit&id=$n[0]&confirm=ok","post","EditUser1","","");
									$forma .= "<label>".LangUsername."<br /> ".$this->InputOpen("text","username","$n[2]","")."</label>";
									$forma .= "<label>".LangPassword."<br /> ".$this->InputOpen("password","password","","")."</label>";
									$forma .= "<label>".LangEmail."<br /> ".$this->InputOpen("text","email","$n[4]","")."</label>";
									$forma .= "<label>".LangLevel."<br /> ".$this->InputOpen("text","level","$n[1]","",$maxlenght=" maxlength=\"2\"")."</label>";
									$forma .= "<label>".$this->InputOpen("submit","EditUser",LangContinue,"")."</label>";
									$forma .= $this->FormClose();
									$go .= $this->DivOpen("EditUsers","Forms");
									$go .= LangEditUser;
									$go .= $forma;
									$go .= $this->DivClose();
									unset($forma);
									break;
								}
							}
						}
					}
				}
			}
			if($subcat=="delete")
			{
				$id=$_GET["id"];
				if (!ctype_digit($id))
				{
					$go .= $this->DivOpen("error","Error");
					$go .= LangIDNotNumeric;
					$go .= $this->DivClose();
				}
				else
				{
					$uf=file($userfile);
					foreach ($uf as $num => $f)
					{
						if (!preg_match("/^<\?/",$f))
						{
							$n=explode("|",$f);
							if($id==$n[0])
							{

								$fp=fopen($userfile,"r");
								$l = strlen($f);
								$r=fread($fp,filesize($userfile) );
								$l1 = strlen($r);
								if(substr($r,$l1-$l,$l)==$f)
								{
									$old="\n".$f;
								}
								else
								{
									$old=$f;
								}
								fclose($fp);
								$usern=$n[2];
								break;
							}
						}
					}
					if(!isset($_GET["confirm"]))
					{
						$forma .= $this->FormOpen("?page=users&do=delete&id=$id&confirm=ok","post","DeleteUser1","","");
						$forma .= "<label>".$this->InputOpen("submit","DeleteUser",LangContinue,"")."</label>";
						$forma .= $this->FormClose();
						$go .= $this->DivOpen("EditUsers","Forms");
						$go .= LangDelUser." ".$usern."<br />";
						$go .= LangConfirm;
						$go .= $forma;
						$go .= $this->DivClose();
						unset($forma);
					}
					elseif($_GET["confirm"]=="ok")
					{
						$userlevel=$this->CheckUser("level",$usern);
						if(($this->nSysUserLevel>$userlevel)&&($this->nSysUserLevel>=90))
						{
							$str=str_replace("<?php die(\"\"); ?>","",file_get_contents($userfile));
							$exp=explode($old,$str);
							$tw .= "<?php die(\"\"); ?>";
							$tw .= $exp[0];
							$tw .= $exp[1];
							$go .= $this->WriteToFiles($userfile,"w",$tw);
						}
						else
						{
							$go .= $this->DivOpen("error","Error");
							$go .= LangErrorEditing;
							$go .= $this->DivClose();
						}
					}
				}
			}
			$go .= $this->DivOpen("EditUsers","Forms");
			$go .= "<ul class=\"vertical\">";
			$go .= "<li>".$this->DivOpen("0","").$this->aOpen("?page=users&do=addnew","",LangAddUser).$this->aClose().$this->DivClose()."<em>".LangEditOrDel."</em></li>\n";
			$uf=file($userfile);
			foreach ($uf as $num => $f)
			{
				if ((!preg_match("/^<\?/",$f))&&($f!="\n"))
				{
					$n=explode("|",$f);
					$go .= "<li>";
					$go .= $this->DivOpen("0","").$n[0]." ".$n[2]." (level: ".$n[1].")".$this->DivClose();
					$go .= "<em>";
					$go .= $this->aOpen("?page=users&do=edit&id=$n[0]","",LangEdit).$this->aClose()." | ".$this->aOpen("?page=users&do=delete&id=$n[0]","",LangDelete).$this->aClose();
					$go .= "</em></li>\n";
				}
			}
			$go .= "</ul><div class=\"clearboth\">&nbsp;</div>";
			$go .= $this->DivClose();
		}
		else
		{
			$go .= $this->DisplayLoginForm();
		}
		return $go;
	}
/* admin users */

	    /* change num of news */
		function ChangeNumOfUser($userid,$where=1,$comm=NULL){
			if(($this->nSysUser==1)&&(isset($this->nSysUserName)))
			{
			$userfile="../include/users.php";
			$file=file($userfile);

			$con=file_get_contents($userfile);
			foreach($file as $num => $f)
			{
				$n=explode("|",$f);
				if($userid==$n[0])
				{
					$old = $f;
					if($comm==NULL)
					{

						$n[5]=$n[5]+$where;
					}
					elseif($comm==1)
					{
						$n[6]=$n[6]+$where;
					}
					for($i=0;$i<count($n);$i++)
					{
						if($i==count($n)-1)
						{
							$sep="";
						}
						else
						{
							$sep="|";
						}
						$new .= $n[$i].$sep;
					}
					break;
				}
			}
			$exp = explode("$old",htmlspecialchars($con));
			$tw .= htmlspecialchars_decode($exp[0]);
			$tw .= $new;
			$tw .= $exp[1];
			$go = $this->WriteToFiles($userfile,"w",$tw);
			}
			else
			{
				$go .= $this->DivOpen("error","Error");
				$go .= LangPleaseLogIn;
				$go .= $this->DivClose();
			}
			return $go;
		}
		/* change num of news */

	/*check user */
	function CheckUser($what,$username){
		$userfile="../include/users.php";
		if($what=="id"){ $what="0"; }
		if($what=="level"){ $what=1; }
		if($what=="username"){ $what=2; }
		if($what=="email"){ $what=4; }
		if($what=="news"){ $what=5; }
		if($what=="comments"){ $what=6; }
		$file=file($userfile);
		foreach($file as $num => $f)
		{
			if(!preg_match("/^<\?/",$f))
			{
				$n=explode("|",$f);
				if($username==$n[2])
				{
					$go = $n[$what];
					break;
				}
			}
		}
		return $go;
	}
	/*check user */

	/* show config */
		function ShowConfig(){
			global $nSysLoc, $nSysAdminMail, $nSysLang, $nSysNewsShow,
				$nSysNewsBackup, $nSysNewsShort, $nSysCommentsAllow,
				$nSysCommentsVerify, $nSysCommentsBBcode, $nSysSupport;
			$go .= $this->Heading("h1",LangNavConfig);
			if (isset($_POST["EditConfig"]))
			{
				$configfile="../include/config.php";
				$email=htmlspecialchars($_POST["nSysAdminMail"]);
				$lang=htmlspecialchars($_POST["lang"]);
				$show=htmlspecialchars($_POST["nSysNewsShow"]);
				$backup=htmlspecialchars($_POST["nSysNewsBackup"]);
				$short=htmlspecialchars($_POST["nSysNewsShort"]);
				$callow=htmlspecialchars($_POST["nSysCommentsAllow"]);
				$cverify=htmlspecialchars($_POST["nSysCommentsVerify"]);
				$cbbcode=htmlspecialchars($_POST["nSysCommentsBBCode"]);
				$support=htmlspecialchars($_POST["nSysSupport"]);
				if ((!isset($email))||($this->nSysUserLevel<100)) { $email=$nSysAdminMail; }
				if (empty($lang)) { $lang=$nSysLang; }
				if ((empty($show))||(!ctype_digit($show))) { $show=$nSysNewsShow; }
				if (empty($backup)) { $backup=$nSysNewsBackup; }
				if ((empty($short))||(!ctype_digit($short))) { $short=$nSysNewsShort; }
				if (empty($callow)) { $callow=$nSysCommentsAllow; }
				if (empty($cverify)) { $cverify=$nSysCommentsVerify; }
				if (empty($cbbcode)) { $bbcode=$nSysCommentsBBCode; }
				if (empty($support)) { $support=$nSysSupport; }
				$configdata="<?php
\$nSysLoc = \"$nSysLoc\";
\$nSysAdminMail = \"$email\";
\$nSysLang = \"$lang\";
\$nSysNewsShow = \"$show\";
\$nSysNewsBackup = \"$backup\";
\$nSysNewsShort = \"$short\";
\$nSysCommentsAllow =\"$callow\";
\$nSysCommentsVerify = \"$cverify\";
\$nSysCommentsBBcode = \"$cbbcode\";
\$nSysSupport = \"$support\";
?>";
				echo $this->WriteToFiles($configfile,"w",$configdata);
				if(!headers_sent()) { header("Location: ?page=config"); }
			}
			$go .= $this->DivOpen("config","Forms");
			if (($this->nSysUser==1)&&($this->nSysUserLevel>=90))
			{
				$go .= $this->FormOpen("","post","EditConfig","","");
				if ($this->nSysUserLevel>99)
				{
					$go .= "<label>".LangAdminEmail."<br />".$this->InputOpen("text","nSysAdminMail","$nSysAdminMail","").LangTextF."</label>";
				}
				$go .= "<label>".LangChooseLang."<br />".$this->DisplayLangs(0)."</label>";
				$go .= "<label>".LangNewsShow."<br />".$this->InputOpen("text","nSysNewsShow","$nSysNewsShow","").LangNumF."</label>";
				$go .= "<label>".LangNewsBackup."<br />".$this->InputOpen("text","nSysNewsBackup","$nSysNewsBackup","")."(yes/no)</label>";
				$go .= "<label>".LangNewsShort."<br />".$this->InputOpen("text","nSysNewsShort","$nSysNewsShort","").LangNumF."</label>";
				$go .= "<label>".LangCommsAllow."<br />".$this->InputOpen("text","nSysCommentsAllow","$nSysCommentsAllow","")."(yes/no)</label>";
				$go .= "<label>".LangCommsVerify."<br />".$this->InputOpen("text","nSysCommentsVerify","$nSysCommentsVerify","")."(yes/no)</label>";
				$go .= "<label>".LangCommsBBCode."<br />".$this->InputOpen("text","nSysCommentsBBCode","$nSysCommentsBBcode","")."(yes/no)</label>";
				$go .= "<label>".LangSupportnSys."<br />".$this->InputOpen("text","nSysSupport","$nSysSupport","")."(yes/no)</label>";
				$go .= "<label>".$this->InputOpen("submit","EditConfig",LangContinue,"")."</label>";
				$go .= $this->FormClose();

			}
			else
			{
				$go .= $this->DivOpen("error","Error");
				$go .= LangNoPermissions;
				$go .= $this->DivClose();
			}
			$go .= $this->DivClose();
			return $go;
		}
	/* END show config */

	/* News admin page */

	/* Add Lang */
	function AddLang()
	{
		$go .= $this->DivOpen("AddLang","AddLang");
		$go .= $this->aOpen("./.","",LangClose." X").$this->aClose();
		$go .= $this->DivOpen("cats","Forms");
		if (isset($_POST["AddNewLang"]))
		{
			if ($_FILES["LFile"]["size"]>0)
			{
				if ($_FILES["LFile"]["type"]=="application/octet-stream")
				{
					$name1 = htmlspecialchars($_POST["LName"]);
					$name = strtolower($name1);
					$name = str_replace(" ","_",$name).".php";
					$fp = fopen("../include/InstalledLangs.txt","a");
					if ((copy($_FILES["LFile"]["tmp_name"],"../lang/".$name))&&(fwrite($fp,"\r\n$name1 - $name")))
					{
						$go .= $this->DivOpen("error","Success");
						$go .= LangLUploadSuccess;
						$go .= $this->DivClose();
					}

					else
					{
						$go .= $this->DivOpen("error","Error");

						$go .= LangUploadFailed;
						$go .= $this->DivClose();
					}
					fclose($fp);
				}
				else
				{
					$go .= $this->DivOpen("error","Error");
					$go .= LangWrongType." ".LangPHPOnly;
					$go .= $this->DivClose();
				}
			}
			else
			{
				$go .= $this->DivOpen("error","Error");
				$go .= LangFieldsEmpty;
				$go .= $this->DivClose();
			}
		}
		else
		{
			if ($this->nSysUser==1)
			{
				$go .= $this->FormOpen("","post","AddNewLang","","","multipart/form-data");
				$go .= "<label>".$this->InputOpen("text","LName",LangName,"")."</label>";
				$go .= "<label>".$this->InputOpen("file","LFile","","")."</label>";
				$go .= $this->InputOpen("submit","AddNewLang",LangContinue,"")."<br />";
				$go .= $this->FormClose();
			}
			else
			{
				$go .= "";
			}
		}
		$go .= $this->DivClose();
		$go .= $this->DivClose();
		return $go;
	}
	/* END Add Lang */

    /* Backups */
    function ShowBackups($sub){
    	global $nSysAdminMail, $nSysNewsBackup;
    	$go .= $this->Heading("h1",LangNavB." [".$this->aOpen("?page=backups&do=makeone","",LangMakeBackup).$this->aClose()."]");
    	if ($nSysNewsBackup=="yes")	{ $bpstatus="<font style=\"color:green\">".LangON."</font>"; }
    	else { $bpstatus="<font style=\"color:red\">".LangOFF."</font><br />".LangOFFHelp; }
    	$go .= $this->Paragraph(LangBackups90."<br />");
    	$go .= $this->Paragraph(LangABackups." ".$bpstatus."<br /><br />");
    	if ($this->nSysUserLevel>=90)
    	{
    		if ($sub=="makeone")
    		{
    			$folder="../include/";
    			$bname="backup_".date("m_d_Y_H_i_s").".php";
    			if (copy($folder."news.php",$folder.$bname))
    			{
    				$go .= $this->DivOpen("success","Success");
    				$go .= LangBackupMade." ".$bname;
    				$go .= $this->DivClose();
    			}
    			else
    			{
    				$go .= $this->DivOpen("error","Error");
    				$go .= LangBackupNotMade." ".$this->aOpen("mailto:$nSysAdminMail","",$nSysAdminMail).$this->aClose();
    				$go .= $this->DivClose();
    			}
    		}
    		if ($sub=="delete")
    		{
    			$go .= $this->DeleteBackups();
    		}
    		if ($sub="restore")
    		{
    			$fname=htmlspecialchars($_GET["fname"]);
    			$go .= $this->RestoreBackup($fname);
    		}
    	}
    	$go .= $this->Paragraph($this->CountBackups()." ".LangBSoFar." [".$this->aOpen("?page=backups&do=delete","",LangBackupsDel).$this->aClose()."]<br /><br/>");
    	if ($this->nSysUserLevel>=90)
    	{
    		$go .= $this->DisplayBackups();
    	}
    	return $go;
    }

	function CountBackups($i=0){
		$folder="../include/";
		$files=scandir($folder);
		for($j=0;$j<count($files);$j++)
		{
			if(preg_match("/^backup/",$files[$j]))
			{
				$i++;
			}
		}
		return $i;
	}

	function DisplayBackups(){
		$folder="../include/";
		$files=scandir($folder,1);
		for($j=0;$j<count($files);$j++)
		{
			if(preg_match("/^backup/",$files[$j]))
			{
				$nf = str_replace(".php","",$files[$j]);
				$n = explode("_",$nf);
				$go .= $this->Paragraph($this->aOpen("?page=backups&do=restore&fname=$nf","",LangRestoreBackup)." $n[2].$n[1].$n[3] $n[4]:$n[5]:$n[6]".$this->aClose());
			}
		}
		return $go;
	}

	function DeleteBackups(){
		if ($this->nSysUserLevel>=90)
		{
			$folder="../include/";
			$files=scandir($folder,1);
			for($j=0;$j<count($files);$j++)
			{
				if(preg_match("/^backup/",$files[$j]))
				{
					unlink($folder.$files[$j]);
				}
			}
		}
	}

	function RestoreBackup($fname){
		global $nSysAdminMail;
		if ($this->nSysUserLevel>=90)
		{
			$folder="../include/";
			if(preg_match("/^backup/",$fname))
			{
				if(is_file($folder.$fname.".php"))
				{
					$getdata = str_replace("<?php die(\"\"); ?>","",file_get_contents($folder.$fname.".php"));
					$input .= "<?php die(\"\"); ?>";
					$input .= $getdata;
					if ($this->WriteToFiles($folder."news.php","w",$input,0))
					{
						$n=explode("_",$fname);
						$go .= $this->DivOpen("success","Success");
						$go .= LangBackupRestored." $n[1].$n[2].$n[3] $n[4]:$n[5]:$n[6]";
						$go .= $this->DivClose();
					}
					else
					{
						$go .= $this->DivOpen("error","Error");
						$go .= LangBackupNotRestored." ".$this->aOpen("mailto:$nSysAdminMail","",$nSysAdminMail).$this->aClose();
						$go .= $this->DivClose();
					}
				}
				else
				{
					$go .= $this->DivOpen("error","Error");
					$go .= LangNoSuchFile." ".$fname.".php";
					$go .= $this->DivClose();
				}
			}
		}
		return $go;
	}

	function AutomaticBackup(){
		global $nSysNewsBackup;
		if ($nSysNewsBackup=="yes")
		{
			$folder="../include/";
			$files=scandir($folder,1);
			for($j=0;$j<count($files);$j++)
			{
				if(preg_match("/^backup/",$files[$j]))
				{
					$n=explode("_",$files[$j]);
					$lb=$n[1].$n[2].$n[3];
					if ($lb>$this->LastBackup) { $this->LastBackup=$lb; }
				}
			}
			$now=date("mdY");
			if ($now>$this->LastBackup)
			{
				$bname="backup_".date("m_d_Y_H_i_s").".php";
				copy($folder."news.php",$folder.$bname);
			}
		}
	}
    /* END Backups */

	/* Help */
	function ShowHelp(){
		$go .= $this->Heading("h2",LangNavHelp);
		$folder="../docs/help/";
		$files=scandir($folder);
		$go .= "<a name=\"top\"></a>";
		for ($i=0;$i<count($files);$i++)
		{
			if (($files[$i]!=".")&&($files[$i]!="..")&&($files[$i]!=".htaccess")&&($files[$i]!=".ThumbsDB"))
			{
				$n = explode(" - ",$files[$i]);
				$name=str_replace(".txt","",$files[$i]);
				$go .= $this->Paragraph($this->aOpen("#$n[0]","",$name).$this->aClose());
			}
		}
		$go .= $this->Heading("h3",LangNavHelp);
		for ($i=0;$i<count($files);$i++)
		{
			if (($files[$i]!=".")&&($files[$i]!="..")&&($files[$i]!=".htaccess")&&($files[$i]!=".ThumbsDB"))
			{
				$n = explode(" - ",$files[$i]);
				$name=str_replace(".txt","",$files[$i]);
				$go .= $this->Paragraph("<a name=\"$n[0]\"></a> ".$this->Heading("h3",$name));
				$fp = fopen($folder.$files[$i],"r");
				$read=fread($fp,filesize($folder.$files[$i]));
				$read=str_replace("\n","<br />",$read);
				$go .= $read."<br />";
				$go .= $this->aOpen("#top","",LangToTop).$this->aClose();
				fclose($fp);
			}
		}

		return $go;
	}
	/* END Help */

	/* Log in form */
	function DisplayLoginForm(){
		if($this->nSysUser==1)
		{
			$go .= LangAlreadyLogged;
		}
		else
		{
				$go .= $this->Heading("h2",LangPleaseLogIn);
				$go .= $this->DivOpen("LogIn","TopFull Forms");
				$go .= $this->FormOpen("","post","LogIn","","");
				$go .= "<label>".LangUsername."<br /> ".$this->InputOpen("text","user","","")."</label>";
				$go .= "<label>".LangPassword."<br /> ".$this->InputOpen("password","pass","","")."</label>";
				$go .= "<label>".LangRememberMe."<br /> ".$this->InputOpen("checkbox","remember","remember","","","checked ")."</label>";
				$go .= "<label>".$this->InputOpen("submit","SubmitLogIn",LangContinue,"")."</label>";
				$go .= $this->FormClose();
				$go .= $this->DivClose();
		}
		return $go;
	}

	/* Log In */
	function LogIn($user,$pass,$remember){
		if((!empty($user))&&(!empty($pass)))
		{
			$user=htmlspecialchars($_POST["user"]);
			$pass=htmlspecialchars($_POST["pass"]);
			if(!empty($remember))
			{
				$remember=24*356;
			}
			else
			{
				$remember=1;
			}
		$pass=md5($pass);
		$readfile=file("../include/users.php");
		foreach($readfile as $num => $uinfo)
		{
			if(!preg_match("/^<\?/",$uinfo))
			{
				$info=explode("|",$uinfo);
				if(($user==$info[2])&&($pass==$info[3]))
				{
					$userID=$info[0];
					if(setcookie("nSysUser","$userID|$user|$pass",time()+3600*$remember,"",""))
					{
						$go .= $this->DivOpen("success","Success");
						$go .= LangLoggedIn;
						$go .= $this->DivClose();
					}
					else
					{
						$go .= $this->DivOpen("error","Error");
						$go .= LangLogInImpossible;
						$go .= $this->DivClose();

					}
				}
				else
				{
					$go .= $this->DivOpen("error","Error");
					$go .= LangIncorrectLogIn;
					$go .= $this->DivClose();
				}

			}
		}
		}
		else
		{
			$go .= $this->DivOpen("error","Error");
			$go .= LangFieldsEmpty;
			$go .= $this->DivClose();
			$go .= $this->DisplayLoginForm();
		}
		return $go;
	}

	function LogOut()
	{
		if (setcookie("nSysUser","",time()-3600))
        {
			if (!headers_sent())
            {
				header("Location: ./.");
			}
            else
            {
                $go .= $this->aOpen("./.","",LangLoggedOut).$this->aClose();
            }
		}
        return $go;
	}

}


?>
Return current item: nSys Flat News System