<?php

/********************************************************************************
	- MemHT Portal -
	
	Copyright (C) 2007-2008 by Miltenovik Manojlo
	http://www.memht.com
	
	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your opinion) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License along
	with this program; if not, see <http://www.gnu.org/licenses/> (GPLv2)
	or write to the Free Software Foundation, Inc., 51 Franklin Street,
	Fifth Floor, Boston, MA02110-1301, USA.
		
********************************************************************************/

if (!defined("_LOAD_PAGE_")) {
	die("<table style='padding: 2px; border: 1px solid #999; background-color: #EEE; font-family: Verdana; font-size: 10px;' align='center'><tr><td><b>Error:</b> This file cannot be opened directly!</td></tr></table>");
}

$op = (isset($_REQUEST['op'])) ? inCode($_REQUEST['op']) : "" ;
$subop = (isset($_GET['subop'])) ? inCode($_GET['subop']) : "" ;

function submain() {
	global $dblink;
	
	if ($result = $dblink->get_list("SELECT nome,titolo FROM memht_pagine WHERE enabled=1 AND (nome='articles' OR nome='blog' OR nome='download' OR nome='gallery' OR nome='guide' OR nome='mylinks' OR nome='news') ORDER BY nome")) {
		echo "<div align='center'>\n";
			echo "<form name='submission' action='index.php?page=submission' method='post'>\n";
			echo "<select name='op'>\n";
			foreach ($result as $row) {		
				echo "<option value='".outCode($row['nome'])."'>".outCode($row['titolo'])."</option>\n";
			}
			echo "</select>\n";
			echo " <input type='submit' value='"._SELECT_."'>\n";
			echo "</form>\n";
		echo "</div>\n";
	} else {
		echo "<div align='center' id='errorText'><b>"._EMPTY_."</b></div>\n";
	}
}

function submit_articles($subop) {
	global $dblink,$siteConfig,$tzNOW,$userid;
	
	switch ($subop) {
		default:
			echo "<table width='100%' align='center' cellspacing='0' cellpadding='1'>";
			echo "<form name='formsarticles' method='post' action='index.php?page=submission&op=articles&subop=add'>";
			
				echo "<tr><td width='20%'><b>"._TITLE_."</b></td><td><input type='text' name='name' size='40' maxlength='255'></td></tr>\n";
				echo "<tr><td><b>"._ARGUMENT_."</b></td><td>\n";
					echo "<select name='argument'>\n";
						$result = $dblink->get_list("SELECT * FROM memht_argomenti ORDER BY nome");
						foreach ($result as $row) {
							$aid = intval($row['id']);
							$nome = outCode($row['nome']);
	
							echo "<option value='$aid'>$nome</option>\n";
						}
					echo "</select></td></tr>\n";
				echo "<tr><td><b>"._LANGUAGE_."</b></td><td>\n";
					echo "<select name='language'>\n";
						echo "<option value='0'>"._GLOBAL_."</option>\n";
						$result = $dblink->get_list("SELECT * FROM memht_content_languages ORDER BY language");
						foreach ($result as $row) {
							$lid = intval($row['id']);
							$llanguage = outCode($row['language']);
							$default = intval($row['default']);
							
							$selected = ($default==1) ? " selected" : "" ;
							echo "<option value='$lid'{$selected}>$llanguage</option>\n";
						}
					echo "</select></td></tr>\n";
				echo "<tr><td><b>"._AUTHOR_."</b></td><td><input type='text' name='author' size='30' maxlength='255'></td></tr>\n";
				echo "<tr><td><b>"._EMAIL_."</b></td><td><input type='text' name='email' size='30' maxlength='255'></td></tr>\n";
				echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
				echo "<tr><td valign='top' colspan='2'><b>"._DESCRIPTION_."</b><br>";
					textarea("description","100%","200px",1,"fulladmin");
				echo "</td></tr>\n";
				echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
				echo "<tr><td valign='top' colspan='2'><b>"._TEXT_."</b><br>";
					textarea("text","100%","400px",1,"fulladmin");
				echo "</td></tr>\n";
				
				echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
				if (extension_loaded('gd') AND $siteConfig['graphic_check']==1) {
					echo "<tr><td><img src='".$siteConfig['site_url']."/imgCode.php?name=chk_submission&nc=".md5(time()+rand())."' title='header=["._SECURITY_CODE_."] body=["._SECURITY_CODE_TEXT_."]' alt='Captcha'></td><td valign='bottom'>&nbsp;<b>"._CODE_."</b><br>&nbsp;<input type='text' name='post_code_page' size='10' maxlength='255'></td></tr>\n";
				}
				echo "<tr><td colspan='2'><input type='submit' name='Submit' value='"._ADD_."'></td></tr>\n";
	
			echo "</form>\n";
			echo "</table>\n";
		break;
		case "add":
			@session_start();
			if ((isset($_POST['post_code_page']) AND isset($_SESSION['chk_submission']) AND strtolower($_POST['post_code_page'])==strtolower($_SESSION['chk_submission'])) OR !(extension_loaded('gd') AND $siteConfig['graphic_check']==1)) {
				
				$name = (isset($_POST['name'])) ? inCode($_POST['name']) : "" ;
				$argument = (isset($_POST['argument'])) ? intval($_POST['argument']) : 0 ;
				$description = (isset($_POST['description'])) ? inCode($_POST['description']) : "" ;
				$text = (isset($_POST['text'])) ? inCode($_POST['text']) : "" ;
				$author = (isset($_POST['author'])) ? inCode($_POST['author']) : "" ;
				$email = (isset($_POST['email'])) ? inCode($_POST['email']) : "" ;
				$language = (isset($_POST['language'])) ? intval($_POST['language']) : 0 ;
				
				$save = true;
				if ($name=="" OR !validate($name)) { $save = false; $msg = _TITLE_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
				if ($author=="" OR !validate($author)) { $save = false; $msg = _AUTHOR_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
				if (!validEmail($email)) { $save = false; $msg = _MAILNOTVALID_; }
				
				if ($save) {
					$dblink->query("INSERT INTO memht_articoli (id,argomento,nome,descrizione,testo,autore,email,data,waiting,language)
									VALUES (null,'$argument','$name','$description','$text','$author','$email',$tzNOW,'1','$language')");
					//3.9.0
					if (isUser($userid)) { $dblink->query("UPDATE memht_utenti SET contributes=contributes+5 WHERE id=$userid"); addToGroups(2); }
					echo "<div align='center' class='box'><b>"._THANKFORCONTRIBUTE_."</b></div>";
				} else {
					echo "<div align='center' id='errorText'><b>$msg</b></div>";
				}
			} else {
				echo "<div align='center' id='errorText'><b>"._WRONGSECCODE_."</b></div>";
			}
		break;
	}
}

function submit_blog($subop) {
	global $dblink,$siteConfig,$tzNOW,$userid;
	
	switch ($subop) {
		default:
			echo "<table width='100%' align='center' cellspacing='0' cellpadding='1'>";
			echo "<form name='formsblog' method='post' action='index.php?page=submission&op=blog&subop=add'>";
			
				echo "<tr><td width='20%'><b>"._TITLE_."</b></td><td><input type='text' name='name' size='40' maxlength='255'></td></tr>\n";
				echo "<tr><td><b>"._CATEGORY_."</b></td><td>\n";
					echo "<select name='argument'>\n";
						$result = $dblink->get_list("SELECT id,name FROM memht_blog_categories ORDER BY name");
						foreach ($result as $row) {
							$cid = intval($row['id']);
							$name = outCode($row['name']);
	
							echo "<option value='$cid'>$name</option>\n";
						}
					echo "</select></td></tr>\n";
				echo "<tr><td><b>"._AUTHOR_."</b></td><td><input type='text' name='author' size='30' maxlength='255'></td></tr>\n";
				echo "<tr><td><b>"._LANGUAGE_."</b></td><td>\n";
					echo "<select name='language'>\n";
						echo "<option value='0'>"._GLOBAL_."</option>\n";
						$result = $dblink->get_list("SELECT * FROM memht_content_languages ORDER BY language");
						foreach ($result as $row) {
							$lid = intval($row['id']);
							$llanguage = outCode($row['language']);
							$default = intval($row['default']);
							
							$selected = ($default==1) ? " selected" : "" ;
							echo "<option value='$lid'{$selected}>$llanguage</option>\n";
						}
					echo "</select></td></tr>\n";
				echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
				echo "<tr><td valign='top' colspan='2'><b>"._HOMETEXT_."</b><br>";
					textarea("home","100%","200px",1,"fulladmin");
				echo "</td></tr>\n";
				echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
				echo "<tr><td valign='top' colspan='2'><b>"._TEXT_."</b><br>";
					textarea("text","100%","400px",1,"fulladmin");
				echo "</td></tr>\n";
				
				echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
				if (extension_loaded('gd') AND $siteConfig['graphic_check']==1) {
					echo "<tr><td><img src='".$siteConfig['site_url']."/imgCode.php?name=chk_submission&nc=".md5(time()+rand())."' title='header=["._SECURITY_CODE_."] body=["._SECURITY_CODE_TEXT_."]' alt='Captcha'></td><td valign='bottom'>&nbsp;<b>"._CODE_."</b><br>&nbsp;<input type='text' name='post_code_page' size='10' maxlength='255'></td></tr>\n";
				}
				echo "<tr><td colspan='2'><input type='submit' name='Submit' value='"._ADD_."'></td></tr>\n";
	
			echo "</form>\n";
			echo "</table>\n";
		break;
		case "add":
			@session_start();
			if ((isset($_POST['post_code_page']) AND isset($_SESSION['chk_submission']) AND strtolower($_POST['post_code_page'])==strtolower($_SESSION['chk_submission'])) OR !(extension_loaded('gd') AND $siteConfig['graphic_check']==1)) {
				
				$name = (isset($_POST['name'])) ? inCode($_POST['name']) : "" ;
				$argument = (isset($_POST['argument'])) ? intval($_POST['argument']) : 0 ;
				$home = (isset($_POST['home'])) ? inCode($_POST['home']) : "" ;
				$text = (isset($_POST['text'])) ? inCode($_POST['text']) : "" ;
				$author = (isset($_POST['author'])) ? inCode($_POST['author']) : "" ;
				$language = (isset($_POST['language'])) ? intval($_POST['language']) : 0 ;
				
				$save = true;
				if ($name=="" OR !validate($name)) { $save = false; $msg = _TITLE_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
				if ($home=="") { $save = false; $msg = _HOMETEXT_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
				if ($author=="" OR !validate($author)) { $save = false; $msg = _AUTHOR_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
				
				if ($save) {
					$dblink->query("INSERT INTO memht_blog_posts (id,category,title,home_text,full_text,author,date,waiting,language)
									VALUES (null,'$argument','$name','$home','$text','$author',$tzNOW,'1','$language')");
					//3.9.0
					if (isUser($userid)) { $dblink->query("UPDATE memht_utenti SET contributes=contributes+5 WHERE id=$userid"); addToGroups(2); }
					echo "<div align='center' class='box'><b>"._THANKFORCONTRIBUTE_."</b></div>";
				} else {
					echo "<div align='center' id='errorText'><b>$msg</b></div>";
				}
			} else {
				echo "<div align='center' id='errorText'><b>"._WRONGSECCODE_."</b></div>";
			}
		break;
	}
}

function submit_download($subop) {
	global $dblink,$siteConfig,$tzNOW,$userid,$level,$spcs;
	
	switch ($subop) {
		default:
			echo "<table width='100%' align='center' cellspacing='0' cellpadding='1'>";
			echo "<form name='formsnews' method='post' action='index.php?page=submission&op=download&subop=add'>";
				echo "<tr><td width='20%'><b>"._FILENAME_."</b></td><td><input type='text' name='name' size='40' maxlength='255'></td></tr>\n";
				echo "<tr><td><b>"._URL_."</b></td><td><input type='text' name='url' size='40' maxlength='255'></td></tr>\n";
				echo "<tr><td><b>"._CATEGORY_."</b></td><td>\n";
				echo "<select name='category'>\n";
					if ($result = $dblink->get_list("SELECT id,nome FROM memht_download_categorie WHERE parent=0 ORDER BY nome")) {
						foreach ($result as $row) {
							$id = intval($row['id']);
							$nome = outCode($row['nome']);
							
							echo "<option value='$id'>$nome</div>";
							godeepSubmissionFiles($id,$level,$spcs);
						}
					}
				echo "</select>\n";

				echo "</select></td></tr>\n";
				echo "<tr><td><b>"._DIMENSION_."</b></td><td><input type='text' name='size' size='20' maxlength='255'> bytes</td></tr>\n";
				echo "<tr><td><b>"._DEMO_."</b></td><td><input type='text' name='demolink' size='40' maxlength='255'></td></tr>\n";
				echo "<tr><td><b>"._VERSION_."</b></td><td><input type='text' name='version' size='20' maxlength='255'></td></tr>\n";
				echo "<tr><td><b>"._AUTHOR_."</b></td><td><input type='text' name='author' size='30' maxlength='255'></td></tr>\n";
				echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
				echo "<tr><td valign='top' colspan='2'><b>"._DESCRIPTION_."</b><br>\n";
					textarea("description","100%","200px",1,"simple");
				echo "</td></tr>\n";
				
				echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
				if (extension_loaded('gd') AND $siteConfig['graphic_check']==1) {
					echo "<tr><td><img src='".$siteConfig['site_url']."/imgCode.php?name=chk_submission&nc=".md5(time()+rand())."' title='header=["._SECURITY_CODE_."] body=["._SECURITY_CODE_TEXT_."]' alt='Captcha'></td><td valign='bottom'>&nbsp;<b>"._CODE_."</b><br>&nbsp;<input type='text' name='post_code_page' size='10' maxlength='255'></td></tr>\n";
				}
				echo "<tr><td colspan='2'><input type='submit' name='Submit' value='"._ADD_."'></td></tr>\n";
	
			echo "</form>\n";
			echo "</table>\n";
		break;
		case "add":
			@session_start();
			if ((isset($_POST['post_code_page']) AND isset($_SESSION['chk_submission']) AND strtolower($_POST['post_code_page'])==strtolower($_SESSION['chk_submission'])) OR !(extension_loaded('gd') AND $siteConfig['graphic_check']==1)) {
				
				$name = (isset($_POST['name'])) ? inCode($_POST['name']) : "" ;
				$url = (isset($_POST['url'])) ? inCode($_POST['url']) : "" ;
				$category = (isset($_POST['category'])) ? intval($_POST['category']) : 0 ;
				$size = (isset($_POST['size'])) ? intval($_POST['size']) : 0 ;
				$demolink = (isset($_POST['demolink'])) ? inCode($_POST['demolink']) : "" ;
				$version = (isset($_POST['version'])) ? inCode($_POST['version']) : "" ;
				$author = (isset($_POST['author'])) ? inCode($_POST['author']) : "" ;
				$description = (isset($_POST['description'])) ? inCode($_POST['description']) : "" ;			
				
				$save = true;
				if ($name=="" OR !validate($name)) { $save = false; $msg = _TITLE_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
				if (!validate($url,"url")) { $save = false; $msg = _URL_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
				if ($author=="" OR !validate($author)) { $save = false; $msg = _AUTHOR_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
				
				if ($save) {
					$dblink->query("INSERT INTO memht_download (id,cat,nome,url,descrizione,dimensione,data,autore,demolink,version,waiting)
									VALUES (null,'$category','$name','$url','$description','$size',$tzNOW,'$author','$demolink','$version','1')");
					//3.9.0
					if (isUser($userid)) { $dblink->query("UPDATE memht_utenti SET contributes=contributes+5 WHERE id=$userid"); addToGroups(2); }
					echo "<div align='center' class='box'><b>"._THANKFORCONTRIBUTE_."</b></div>";
				} else {
					echo "<div align='center' id='errorText'><b>$msg</b></div>";
				}
			} else {
				echo "<div align='center' id='errorText'><b>"._WRONGSECCODE_."</b></div>";
			}
		break;
	}
}

function submit_gallery($subop) {
	global $dblink,$siteConfig,$tzNOW,$userid;
	
	switch ($subop) {
		default:
			echo "<table width='100%' align='center' cellspacing='0' cellpadding='1'>";
			echo "<form name='formsgallery' method='post' action='index.php?page=submission&op=gallery&subop=add' enctype='multipart/form-data'>";
			
				echo "<tr><td width='20%'><b>"._CATEGORY_."</b></td><td>";
				echo "<select name='category'>\n";
					$cres = $dblink->get_list("SELECT * FROM memht_gallery_categories WHERE enabled=1 ORDER BY name");
					foreach ($cres as $crow) {
						$cid = intval($crow['id']);
						$cname = outCode($crow['name']);
						
						echo "<option value='$cid'>$cname</option>\n";
					}
				echo "</select></td></tr>\n";
				echo "<tr><td><b>"._NAME_."</b></td><td><input type='text' name='name' size='40' maxlength='255'></td></tr>\n";
				echo "<tr><td><b>"._IMAGE_."</b></td><td><input type='file' name='image' size='25'></td></tr>\n";
				if (!extension_loaded('gd')) {
					echo "<tr><td><b>"._THUMBNAIL_."</b></td><td><input type='file' name='thumbnail' size='25'> <span id='info'>"._ACTIVE_WHEN_GD_OFF_."</span></td></tr>\n";
				}
				echo "<tr><td><b>"._ATTACHMENT_."</b></td><td><input type='text' name='attachment' size='40' maxlength='255'></td></tr>\n";
				echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
				echo "<tr><td valign='top' colspan='2'><b>"._DESCRIPTION_."</b><br>";
					textarea("description","100%","200px",1,"fulladmin");
				echo "</td></tr>\n";
				
				echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
				if (extension_loaded('gd') AND $siteConfig['graphic_check']==1) {
					echo "<tr><td><img src='".$siteConfig['site_url']."/imgCode.php?name=chk_submission&nc=".md5(time()+rand())."' title='header=["._SECURITY_CODE_."] body=["._SECURITY_CODE_TEXT_."]' alt='Captcha'></td><td valign='bottom'>&nbsp;<b>"._CODE_."</b><br>&nbsp;<input type='text' name='post_code_page' size='10' maxlength='255'></td></tr>\n";
				}
				echo "<tr><td colspan='2'><input type='submit' name='Submit' value='"._ADD_."'></td></tr>\n";
	
			echo "</form>\n";
			echo "</table>\n";
		break;
		case "add":
			@session_start();
			if ((isset($_POST['post_code_page']) AND isset($_SESSION['chk_submission']) AND strtolower($_POST['post_code_page'])==strtolower($_SESSION['chk_submission'])) OR !(extension_loaded('gd') AND $siteConfig['graphic_check']==1)) {
				
				$name = (isset($_POST['name'])) ? inCode($_POST['name']) : "" ;
				$category = (isset($_POST['category'])) ? intval($_POST['category']) : 0 ;
				$description = (isset($_POST['description'])) ? inCode($_POST['description']) : "" ;
				$attachment = (isset($_POST['attachment'])) ? inCode($_POST['attachment']) : "" ;
				
				$save = true;
				if ($name=="" OR !validate($name)) { $save = false; $msg = _TITLE_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
				
				if ($save) {
					$cfgrow = $dblink->get_row("SELECT * FROM memht_gallery_config");
					$thumb_max_weight = intval($cfgrow['thumb_max_weight']);
					$thumb_max_w = intval($cfgrow['thumb_max_w']);
					$thumb_max_h = intval($cfgrow['thumb_max_h']);
					$img_max_weight = intval($cfgrow['img_max_weight']);
					$img_max_w = intval($cfgrow['img_max_w']);
					$img_max_h = intval($cfgrow['img_max_h']);					
					
					require_once("inc/class/uploadFile.class.php");
					$upload = new uploadFile();
					$upload->show_errors = false;
					$upload->mime = array('image/gif','image/pjpeg','image/jpeg','image/png','image/tiff','image/bmp');
					$upload->path = "pages/gallery/gallery/";
					$upload->path_thumb = "pages/gallery/gallery/thumb/";
					$upload->max_width = $img_max_w;
					$upload->max_height = $img_max_h;
					$upload->max_size = $img_max_weight;
					if (extension_loaded('gd')) { $upload->createthumb = true; }
					$upload->thumb_width = $thumb_max_w;
					$upload->thumb_height = $thumb_max_h;
					
					$upload->field = "image";
					if (!$imgfile = $upload->upload()) { $save = false; $msg = $upload->error; }
								
					if (!extension_loaded('gd') AND $save) {
						$upload->path = "pages/gallery/gallery/thumb";
						$upload->max_width = $thumb_max_w;
						$upload->max_height = $thumb_max_h;
						$upload->max_size = $thumb_max_weight;
						$upload->field = "thumbnail";
						if (!$thumb = $upload->upload()) { $save = false; $msg = $upload->error; }
					} else {
						$thumb = $upload->thumbname;
					}
				
					$dblink->query("INSERT INTO memht_gallery_images (id,category,title,imgfile,thumb,attachfile,description,waiting)
									VALUES (null,'$category','$name','$imgfile','$thumb','$attachment','$description','1')");
					//3.9.0
					if (isUser($userid)) { $dblink->query("UPDATE memht_utenti SET contributes=contributes+5 WHERE id=$userid"); addToGroups(2); }
					echo "<div align='center' class='box'><b>"._THANKFORCONTRIBUTE_."</b></div>";
				} else {
					echo "<div align='center' id='errorText'><b>$msg</b></div>";
				}
			} else {
				echo "<div align='center' id='errorText'><b>"._WRONGSECCODE_."</b></div>";
			}
		break;
	}
}

function submit_guide($subop) {
	global $dblink,$siteConfig,$tzNOW,$userid;
	
	switch ($subop) {
		default:
			echo "<table width='100%' align='center' cellspacing='0' cellpadding='1'>";
			echo "<form name='formsguide' method='post' action='index.php?page=submission&op=guide&subop=add'>";
			
				echo "<tr><td width='20%'><b>"._TITLE_."</b></td><td><input type='text' name='name' size='40' maxlength='255'></td></tr>\n";
				echo "<tr><td><b>"._ARGUMENT_."</b></td><td>\n";
					echo "<select name='argument'>\n";
						$result = $dblink->get_list("SELECT * FROM memht_argomenti ORDER BY nome");
						foreach ($result as $row) {
							$aid = intval($row['id']);
							$nome = outCode($row['nome']);
	
							echo "<option value='$aid'>$nome</option>\n";
						}
					echo "</select></td></tr>\n";
				echo "<tr><td><b>"._LANGUAGE_."</b></td><td>\n";
					echo "<select name='language'>\n";
						echo "<option value='0'>"._GLOBAL_."</option>\n";
						$result = $dblink->get_list("SELECT * FROM memht_content_languages ORDER BY language");
						foreach ($result as $row) {
							$lid = intval($row['id']);
							$llanguage = outCode($row['language']);
							$default = intval($row['default']);
							
							$selected = ($default==1) ? " selected" : "" ;
							echo "<option value='$lid'{$selected}>$llanguage</option>\n";
						}
					echo "</select></td></tr>\n";
				echo "<tr><td><b>"._AUTHOR_."</b></td><td><input type='text' name='author' size='30' maxlength='255'></td></tr>\n";
				echo "<tr><td><b>"._EMAIL_."</b></td><td><input type='text' name='email' size='30' maxlength='255'></td></tr>\n";
				echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
				echo "<tr><td valign='top' colspan='2'><b>"._DESCRIPTION_."</b><br>";
					textarea("description","100%","200px",1,"fulladmin");
				echo "</td></tr>\n";
				echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
				echo "<tr><td valign='top' colspan='2'><b>"._TEXT_."</b><br>";
					textarea("text","100%","400px",1,"fulladmin");
				echo "</td></tr>\n";
				
				echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
				if (extension_loaded('gd') AND $siteConfig['graphic_check']==1) {
					echo "<tr><td><img src='".$siteConfig['site_url']."/imgCode.php?name=chk_submission&nc=".md5(time()+rand())."' title='header=["._SECURITY_CODE_."] body=["._SECURITY_CODE_TEXT_."]' alt='Captcha'></td><td valign='bottom'>&nbsp;<b>"._CODE_."</b><br>&nbsp;<input type='text' name='post_code_page' size='10' maxlength='255'></td></tr>\n";
				}
				echo "<tr><td colspan='2'><input type='submit' name='Submit' value='"._ADD_."'></td></tr>\n";
	
			echo "</form>\n";
			echo "</table>\n";
		break;
		case "add":
			@session_start();
			if ((isset($_POST['post_code_page']) AND isset($_SESSION['chk_submission']) AND strtolower($_POST['post_code_page'])==strtolower($_SESSION['chk_submission'])) OR !(extension_loaded('gd') AND $siteConfig['graphic_check']==1)) {
				
				$name = (isset($_POST['name'])) ? inCode($_POST['name']) : "" ;
				$argument = (isset($_POST['argument'])) ? intval($_POST['argument']) : 0 ;
				$description = (isset($_POST['description'])) ? inCode($_POST['description']) : "" ;
				$text = (isset($_POST['text'])) ? inCode($_POST['text']) : "" ;
				$author = (isset($_POST['author'])) ? inCode($_POST['author']) : "" ;
				$email = (isset($_POST['email'])) ? inCode($_POST['email']) : "" ;
				$language = (isset($_POST['language'])) ? intval($_POST['language']) : 0 ;
				
				$save = true;
				if ($name=="" OR !validate($name)) { $save = false; $msg = _TITLE_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
				if ($description=="") { $save = false; $msg = _DESCRIPTION_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
				if ($author=="" OR !validate($author)) { $save = false; $msg = _AUTHOR_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
				if (!validEmail($email)) { $save = false; $msg = _MAILNOTVALID_; }
				
				if ($save) {
					$dblink->query("INSERT INTO memht_guide (id,argomento,nome,descrizione,testo,autore,email,data,waiting,language)
									VALUES (null,'$argument','$name','$description','$text','$author','$email',$tzNOW,'1','$language')");
					//3.9.0
					if (isUser($userid)) { $dblink->query("UPDATE memht_utenti SET contributes=contributes+5 WHERE id=$userid"); addToGroups(2); }
					echo "<div align='center' class='box'><b>"._THANKFORCONTRIBUTE_."</b></div>";
				} else {
					echo "<div align='center' id='errorText'><b>$msg</b></div>";
				}
			} else {
				echo "<div align='center' id='errorText'><b>"._WRONGSECCODE_."</b></div>";
			}
		break;
	}
}

function submit_mylinks($subop) {
	global $dblink,$siteConfig,$tzNOW,$userid,$level,$spcs;
	
	switch ($subop) {
		default:
			echo "<table width='100%' align='center' cellspacing='0' cellpadding='1'>";
			echo "<form name='formsmylinks' method='post' action='index.php?page=submission&op=mylinks&subop=add'>";
			echo "<tr><td width='25%'><b>"._CATEGORY_."</b></td><td>\n";
			
			echo "<select name='category'>\n";
				if ($result = $dblink->get_list("SELECT id,name FROM memht_mylinks_cat WHERE parent=0 ORDER BY name")) {
					foreach ($result as $row) {
						$id = intval($row['id']);
						$nome = outCode($row['name']);
						
						echo "<option value='$id'>$nome</div>";
						godeepSubmission($id,$level,$spcs);
					}
				}
			echo "</select>\n";

			echo "</td>\n";
			echo "<tr><td><b>"._SITENAME_."</b></td><td><input type='text' name='name' size='40' maxlength='255'></td></tr>\n";
			echo "<tr><td><b>"._SITEURL_."</b></td><td><input type='text' name='url' size='40' maxlength='255' value='http://'></td></tr>\n";
			echo "<tr><td><b>"._EMAIL_."</b></td><td><input type='text' name='email' size='40' maxlength='255'></td></tr>\n";
			echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
			echo "<tr><td valign='top' colspan='2'><b>"._DESCRIPTION_."</b><br>";
				textarea("description","100%","200px",1,"fulladmin");
			echo "</td></tr>\n";
			
			echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
			if (extension_loaded('gd') AND $siteConfig['graphic_check']==1) {
				echo "<tr><td><img src='".$siteConfig['site_url']."/imgCode.php?name=chk_submission&nc=".md5(time()+rand())."' title='header=["._SECURITY_CODE_."] body=["._SECURITY_CODE_TEXT_."]' alt='Captcha'></td><td valign='bottom'>&nbsp;<b>"._CODE_."</b><br>&nbsp;<input type='text' name='post_code_page' size='10' maxlength='255'></td></tr>\n";
			}
			echo "<tr><td colspan='2'><input type='submit' name='Submit' value='"._ADD_."'>\n";
		echo "</form>\n";
		echo "</table>\n";
			
		break;
		case "add":
			@session_start();
			if ((isset($_POST['post_code_page']) AND isset($_SESSION['chk_submission']) AND strtolower($_POST['post_code_page'])==strtolower($_SESSION['chk_submission'])) OR !(extension_loaded('gd') AND $siteConfig['graphic_check']==1)) {
				
				$name = (isset($_POST['name'])) ? inCode($_POST['name']) : "" ;
				$category = (isset($_POST['category'])) ? inCode($_POST['category']) : "" ;
				$url = (isset($_POST['url'])) ? inCode($_POST['url']) : "" ;
				$description = (isset($_POST['description'])) ? inCode($_POST['description']) : "" ;
				$email = (isset($_POST['email'])) ? inCode($_POST['email']) : "" ;
				
				$save = true;
				if ($name=="") { $save = false; $msg = _SITENAME_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
				if (!validate($url,"url")) { $save = false; $msg = _SITEURL_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
				if (!validEmail($email)) { $save = false; $msg = _MAILNOTVALID_; }
				if ($description=="") { $save = false; $msg = _DESCRIPTION_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
				
				if ($save) {
					$dblink->query("INSERT INTO memht_mylinks (id,cat,name,url,email,description,flag)
									VALUES (null,'$category','$name','$url','$email','$description','0')");
					//3.9.0
					if (isUser($userid)) { $dblink->query("UPDATE memht_utenti SET contributes=contributes+5 WHERE id=$userid"); addToGroups(2); }
					echo "<div align='center' class='box'><b>"._THANKFORCONTRIBUTE_."</b></div>";
				} else {
					echo "<div align='center' id='errorText'><b>$msg</b></div>";
				}
			} else {
				echo "<div align='center' id='errorText'><b>"._WRONGSECCODE_."</b></div>";
			}
		break;
	}
}

function submit_news($subop) {
	global $dblink,$siteConfig,$tzNOW,$userid;
	
	switch ($subop) {
		default:
			echo "<table width='100%' align='center' cellspacing='0' cellpadding='1'>";
			echo "<form name='formsnews' method='post' action='index.php?page=submission&op=news&subop=add'>";
			
				echo "<tr><td width='20%'><b>"._TITLE_."</b></td><td><input type='text' name='name' size='40' maxlength='255'></td></tr>\n";
				echo "<tr><td><b>"._ARGUMENT_."</b></td><td>\n";
					echo "<select name='argument'>\n";
						$result = $dblink->get_list("SELECT * FROM memht_argomenti ORDER BY nome");
						foreach ($result as $row) {
							$aid = intval($row['id']);
							$nome = outCode($row['nome']);
	
							echo "<option value='$aid'>$nome</option>\n";
						}
					echo "</select></td></tr>\n";
				echo "<tr><td><b>"._LANGUAGE_."</b></td><td>\n";
					echo "<select name='language'>\n";
						echo "<option value='0'>"._GLOBAL_."</option>\n";
						$result = $dblink->get_list("SELECT * FROM memht_content_languages ORDER BY language");
						foreach ($result as $row) {
							$lid = intval($row['id']);
							$llanguage = outCode($row['language']);
							$default = intval($row['default']);
							
							$selected = ($default==1) ? " selected" : "" ;
							echo "<option value='$lid'{$selected}>$llanguage</option>\n";
						}
					echo "</select></td></tr>\n";
				echo "<tr><td><b>"._AUTHOR_."</b></td><td><input type='text' name='author' size='30' maxlength='255'></td></tr>\n";
				echo "<tr><td><b>"._EMAIL_."</b></td><td><input type='text' name='email' size='30' maxlength='255'></td></tr>\n";
				echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
				echo "<tr><td valign='top' colspan='2'><b>"._HOMETEXT_."</b><br>";
					textarea("home","100%","200px",1,"fulladmin");
				echo "</td></tr>\n";
				echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
				echo "<tr><td valign='top' colspan='2'><b>"._TEXT_."</b><br>";
					textarea("text","100%","400px",1,"fulladmin");
				echo "</td></tr>\n";
				
				echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
				if (extension_loaded('gd') AND $siteConfig['graphic_check']==1) {
					echo "<tr><td><img src='".$siteConfig['site_url']."/imgCode.php?name=chk_submission&nc=".md5(time()+rand())."' title='header=["._SECURITY_CODE_."] body=["._SECURITY_CODE_TEXT_."]' alt='Captcha'></td><td valign='bottom'>&nbsp;<b>"._CODE_."</b><br>&nbsp;<input type='text' name='post_code_page' size='10' maxlength='255'></td></tr>\n";
				}
				echo "<tr><td colspan='2'><input type='submit' name='Submit' value='"._ADD_."'></td></tr>\n";
	
			echo "</form>\n";
			echo "</table>\n";
		break;
		case "add":
			@session_start();
			if ((isset($_POST['post_code_page']) AND isset($_SESSION['chk_submission']) AND strtolower($_POST['post_code_page'])==strtolower($_SESSION['chk_submission'])) OR !(extension_loaded('gd') AND $siteConfig['graphic_check']==1)) {
				
				$name = (isset($_POST['name'])) ? inCode($_POST['name']) : "" ;
				$argument = (isset($_POST['argument'])) ? intval($_POST['argument']) : 0 ;
				$home = (isset($_POST['home'])) ? inCode($_POST['home']) : "" ;
				$text = (isset($_POST['text'])) ? inCode($_POST['text']) : "" ;
				$author = (isset($_POST['author'])) ? inCode($_POST['author']) : "" ;
				$email = (isset($_POST['email'])) ? inCode($_POST['email']) : "" ;
				$language = (isset($_POST['language'])) ? intval($_POST['language']) : 0 ;
				
				$save = true;
				if ($name=="" OR !validate($name)) { $save = false; $msg = _TITLE_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
				if ($home=="") { $save = false; $msg = _HOMETEXT_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
				if ($author=="" OR !validate($author)) { $save = false; $msg = _AUTHOR_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
				if (!validEmail($email)) { $save = false; $msg = _MAILNOTVALID_; }
				
				if ($save) {
					$dblink->query("INSERT INTO memht_news (id,argomento,nome,testo_home,testo,autore,email,data,waiting,language)
									VALUES (null,'$argument','$name','$home','$text','$author','$email',$tzNOW,'1','$language')");
					//3.9.0
					if (isUser($userid)) { $dblink->query("UPDATE memht_utenti SET contributes=contributes+5 WHERE id=$userid"); addToGroups(2); }
					echo "<div align='center' class='box'><b>"._THANKFORCONTRIBUTE_."</b></div>";
				} else {
					echo "<div align='center' id='errorText'><b>$msg</b></div>";
				}
			} else {
				echo "<div align='center' id='errorText'><b>"._WRONGSECCODE_."</b></div>";
			}
		break;
	}
}

switch($op) {
	default:
		submain();
	break;
	
	//Articles
	case "articles":
		submit_articles($subop);
	break;
	
	//Blog
	case "blog":
		submit_blog($subop);
	break;
	
	//Download
	case "download":
		$level = 100;
		$spcs = "";
		function godeepSubmissionFiles($id,$level,$spcs) {
			global $dblink;
				
			$parent = intval($id);
			if ($result = $dblink->get_list("SELECT id,nome FROM memht_download_categorie WHERE parent=$parent ORDER BY nome") AND $level>0) {
				$spcs .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
				foreach ($result as $row) {
					$id = intval($row['id']);
					$nome = outCode($row['nome']);
					
					echo "<option value='$id'>{$spcs}$nome</div>";
					$level--;
					godeepSubmissionFiles($id,$level,$spcs);
				}
			}
		}
		submit_download($subop);
	break;
	
	//Gallery
	case "gallery":
		submit_gallery($subop);
	break;
	
	//Guide
	case "guide":
		submit_guide($subop);
	break;
	
	//MyLinks
	case "mylinks":
		$level = 100;
		$spcs = "";
		function godeepSubmission($id,$level,$spcs,$now=0) {
			global $dblink;
				
			$parent = intval($id);
			if ($result = $dblink->get_list("SELECT id,name FROM memht_mylinks_cat WHERE parent=$parent ORDER BY name") AND $level>0) {
				$spcs .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
				foreach ($result as $row) {
					$id = intval($row['id']);
					$name = outCode($row['name']);
					
					$selected = ($now==$id) ? " selected" : "" ;
					echo "<option value='$id'{$selected}>{$spcs}$name</div>";
					$level--;
					godeepSubmission($id,$level,$spcs,$now);
				}
			}
		}
		submit_mylinks($subop);
	break;
	
	//News
	case "news":
		submit_news($subop);
	break;
}

?>