Viewing file: index.php (14.82 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?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>");
}
if (isset($_GET['op'])) { $op = inCode($_GET['op']); } else { $op = ""; }
if (isset($_GET['id'])) { $id = inCode($_GET['id']); } else { $id = ""; }
if (isset($_GET['ok'])) { $ok = inCode($_GET['ok']); } else { $ok = false; }
if (isset($_POST['argomento'])) { $argomento = inCode($_POST['argomento']); } else { $argomento = ""; }
if (isset($_POST['nome'])) { $nome = eregi_replace("[/_']","-",inCode($_POST['nome'])); } else { $nome = ""; }
if (isset($_POST['descrizione'])) { $descrizione = inCode($_POST['descrizione']); } else { $descrizione = ""; }
if (isset($_POST['testo'])) { $testo = inCode($_POST['testo']); } else { $testo = ""; }
if (isset($_POST['tags'])) { $tags = inCode($_POST['tags']); } else { $tags = ""; }
if (isset($_POST['enabled'])) { $enabled = inCode($_POST['enabled']); } else { $enabled = ""; }
$usecomments = (isset($_POST['usecomments'])) ? intval($_POST['usecomments']) : 0 ;
$language = (isset($_POST['language'])) ? intval($_POST['language']) : 0 ;
if (isset($_GET['pg'])) { $pg = inCode($_GET['pg']); } else { $pg = 1; }
$ofsppg = 30; //Items per page
$ofsbgn = ($pg*$ofsppg)-$ofsppg;
function guiList($ofsbgn,$ofsppg,$pg) {
global $dblink,$siteConfig;
$n = 0;
echo "<table width='100%' align='center' cellspacing='1' cellpadding='0' class='std_nicetable'>";
echo "<thead>\n";
echo "<tr><td>"._TITLE_."</td><td width='25%'>"._TAGS_."</td><td width='15%'>"._LANGUAGE_."</td><td width='15%'>"._AUTHOR_."</td><td width='1%'> </td></tr>\n";
echo "</thead>\n";
echo "<tbody>\n";
if ($result = $dblink->get_list("SELECT g.*,DATE_FORMAT(g.data, '".$siteConfig['timestamp']."') as data,l.language AS languagetxt FROM memht_guide AS g LEFT JOIN memht_content_languages AS l ON g.language = l.id ORDER BY g.id DESC LIMIT $ofsbgn,$ofsppg")) {
foreach ($result as $row) {
$id = intval($row['id']);
$argomento = intval($row['argomento']);
$nome = outCode($row['nome']);
$autore = outCode($row['autore']);
$data = $row['data'];
$hits = intval($row['hits']);
$language = outCode($row['languagetxt']);
$enabled = intval($row['enabled']);
if ($language=="") { $language = _GLOBAL_; }
if ($enabled!="1") { $off = "<img src='images/off.gif' alt='"._OFF_."' title='"._OFF_."'>"; } else { $off = ""; }
$class = (($n++%2)!=0) ? "hlight" : "clean" ;
echo "<tr><td class='$class'><a href='index.php?page=guide&op=readGuide&id=$id&title=".mem_urlencode($nome)."' title='$nome'><b>$nome</b></a></td><td class='$class' id='info'>";
if ($result = $dblink->get_list("SELECT tag FROM memht_tags WHERE whr=2 AND cid=$id ORDER BY tag")) {
foreach ($result as $row) {
echo "<span style='padding: 0 4px;'><a href=\"index.php?page=tags&op=list&tag=".mem_urlencode(outCode($row['tag']))."\" title=\"".outCode($row['tag'])."\" target='_blank'>".outCode($row['tag'])."</a></span>";
}
}
echo "</td><td class='$class'>$language</td><td class='$class'>$autore</td><td width='1%' class='$class' nowrap><a href='admin.php?page=guide&op=editGuide&id=$id' title='"._MODIFY_."'><img src='images/edit.gif' alt='Edit' border='0'></a> <a href='admin.php?page=guide&op=deleteGuide&id=$id' title='"._DELETE_."'><img src='images/delete.gif' alt='Delete' border='0'></a> $off</td></tr>\n";
}
} else {
echo "<tr><td align='center' id='errorText' colspan='5' class='clean'><b>"._NOGUIDES_."</b></td></tr>";
}
echo "</table>";
//Pages
include_once("inc/class/paginationSystem.class.php");
$ps = new paginationSystem();
$ps->items = $ofsppg;
$ps->actpg = $pg;
$ps->query = "SELECT id FROM memht_guide";
$ps->url = "admin.php?page=guide&op=showGuides&pg={{N}}";
$ps->show();
}
function add($argomento,$nome,$descrizione,$testo,$tags,$usecomments,$language,$enabled,$ok=false) {
global $dblink,$userInfo,$tzNOW;
if (!$ok) {
echo "<table width='100%' align='center' cellspacing='0' cellpadding='1'>";
echo "<form name='form_guide' method='post' action='admin.php?page=guide&op=addGuide&ok=true'>";
echo "<tr><td width='25%'><b>"._TITLE_."</b><td><input type='text' name='nome' size='40' maxlength='255'>\n";
echo "<tr><td><b>"._ARGUMENT_."</b><td>\n";
echo "<select name='argomento'>\n";
//Lista argomenti
$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>\n";
echo "<tr><td valign='top'><b>"._DESCRIPTION_."</b></td><td>";
textarea("descrizione","100%","200px",1,"fulladmin");
echo "</td></tr><tr><td valign='top'><b>"._TEXT_."</b></td><td><div id='info'>"._PAGEBREAK_."</div>";
textarea("testo","100%","600px",1,"fulladmin");
echo "</td></tr>\n";
echo "<tr><td><b>"._TAGS_."</b></td><td><input type='text' name='tags' size='40' maxlength='255'> <span id='info'>("._SEPARATEDBYCOMMAS_.")</span></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>\n";
echo "<tr><td><b>"._COMMENTSENABLED_."</b></td><td>";
echo "<select name='usecomments'>\n";
echo "<option value='1' selected>"._YES_."</option>\n";
echo "<option value='0'>"._NO_."</option>\n";
echo "</select></td></tr>\n";
echo "<tr><td><b>"._ENABLED_."</b></td><td>";
echo "<select name='enabled'>\n";
echo "<option value='1' selected>"._YES_."</option>\n";
echo "<option value='0'>"._NO_."</option>\n";
echo "</select></td></tr>\n";
echo "<tr><td colspan='2'><input type='submit' name='Submit' value='"._ADD_."'></td></tr>\n";
echo "</form>\n";
echo "</table>\n";
} else {
$save = true;
if ($nome=="") { $save = false; $msg = _TITLE_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
if ($testo=="") { $save = false; $msg = _TEXT_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
if ($save) {
if (memRunHooks('AddGuide',array($nome,$argomento,$descrizione,$testo,$userInfo['user'],$userInfo['email'],$language))) {
$dblink->query("INSERT INTO memht_guide (id,argomento,nome,descrizione,testo,autore,email,data,usecomments,language,enabled)
VALUES (null,'$argomento','$nome','$descrizione','$testo','".$userInfo['user']."','".$userInfo['email']."',$tzNOW,'$usecomments','$language','$enabled')");
if ($tags!="") {
$row = $dblink->get_row("SELECT id FROM memht_guide ORDER BY id DESC LIMIT 1");
$lastid = intval($row['id']);
$tags = explode(",",$tags);
foreach ($tags as $tag) {
$dblink->query("INSERT INTO memht_tags (tag,cid,whr) VALUES ('".inCode(trim($tag))."','$lastid','2')");
}
}
memRunHooks('AddGuideEnd',array($nome,$argomento,$descrizione,$testo,$userInfo['user'],$userInfo['email'],$language));
}
echo "<meta http-equiv='refresh' content='0;URL=admin.php?page=guide'>";
} else {
echo "<div align='center' id='errorText'><b>$msg</b></div>";
}
}
}
function edit($argomento,$nome,$descrizione,$testo,$tags,$usecomments,$language,$enabled,$ok=false,$id) {
global $dblink;
$id = intval($id);
if (!$ok) {
$row_edit = $dblink->get_row("SELECT * FROM memht_guide WHERE id=$id");
$nargomento = intval($row_edit['argomento']);
$nnome = outCode($row_edit['nome']);
$ndescrizione = outCode($row_edit['descrizione']);
$ntesto = outCode($row_edit['testo']);
$nlanguage = intval($row_edit['language']);
$usecomments = intval($row_edit['usecomments']);
$nenabled = intval($row_edit['enabled']);
if ($result = $dblink->get_list("SELECT tag FROM memht_tags WHERE whr=2 AND cid=$id")) {
$ntags = array();
foreach ($result as $row) {
$ntags[] = outCode($row['tag']);
}
$ntags = implode(",",$ntags);
} else {
$ntags = "";
}
echo "<table width='100%' align='center' cellspacing='0' cellpadding='1'>";
echo "<form name='form_guide' method='post' action='admin.php?page=guide&op=editGuide&id=$id&ok=true'>";
echo "<tr><td width='25%'><b>"._TITLE_."</b><td><input type='text' name='nome' size='40' maxlength='255' value=\"$nnome\">\n";
echo "<tr><td><b>"._ARGUMENT_."</b><td>\n";
echo "<select name='argomento'>\n";
//Lista argomenti
$result = $dblink->get_list("SELECT * FROM memht_argomenti ORDER BY nome");
foreach ($result as $row) {
$aid = intval($row['id']);
$nome = outCode($row['nome']);
if ($nargomento==$aid) {
echo "<option value='$aid' selected>$nome</option>\n";
} else {
echo "<option value='$aid'>$nome</option>\n";
}
}
echo "</select>\n";
echo "<tr><td valign='top'><b>"._DESCRIPTION_."</b></td><td>";
textarea("descrizione","100%","200px",1,"fulladmin",$ndescrizione);
echo "</td></tr><tr><td valign='top'><b>"._TEXT_."</b></td><td><div id='info'>"._PAGEBREAK_."</div>";
textarea("testo","100%","600px",1,"fulladmin",$ntesto);
echo "</td></tr>\n";
echo "<tr><td><b>"._TAGS_."</b></td><td><input type='text' name='tags' value=\"$ntags\" size='40' maxlength='255'> <span id='info'>("._SEPARATEDBYCOMMAS_.")</span></td></tr>\n";
echo "<tr><td><b>"._LANGUAGE_."</b></td><td>\n";
echo "<select name='language'>\n";
$selected = ($nlanguage==0) ? " selected" : "" ;
echo "<option value='0'{$selected}>"._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']);
$selected = ($nlanguage==$lid) ? " selected" : "" ;
echo "<option value='$lid'{$selected}>$llanguage</option>\n";
}
echo "</select>\n";
echo "<tr><td><b>"._COMMENTSENABLED_."</b></td><td>";
echo "<select name='usecomments'>\n";
if ($usecomments==1) {
echo "<option value='1' selected>"._YES_."</option>\n";
echo "<option value='0'>"._NO_."</option>\n";
} else {
echo "<option value='1'>"._YES_."</option>\n";
echo "<option value='0' selected>"._NO_."</option>\n";
}
echo "</select></td></tr>\n";
echo "<tr><td><b>"._ENABLED_."</b></td><td>";
echo "<select name='enabled'>\n";
if ($nenabled==1) {
echo "<option value='1' selected>"._YES_."</option>\n";
echo "<option value='0'>"._NO_."</option>\n";
} else {
echo "<option value='1'>"._YES_."</option>\n";
echo "<option value='0' selected>"._NO_."</option>\n";
}
echo "</select></td></tr>\n";
echo "<tr><td colspan='2'><input type='submit' name='Submit' value='"._MODIFY_."'>\n";
echo "</form>\n";
echo "</table>\n";
} else {
$save = true;
if ($nome=="") { $save = false; $msg = _TITLE_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
if ($testo=="") { $save = false; $msg = _TEXT_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
if ($save) {
$dblink->query("UPDATE memht_guide SET argomento='$argomento',nome='$nome',testo='$testo',descrizione='$descrizione',language='$language',usecomments='$usecomments',enabled='$enabled' WHERE id=$id");
$dblink->query("DELETE FROM memht_tags WHERE whr=2 AND cid=$id");
if ($tags!="") {
$tags = explode(",",$tags);
foreach ($tags as $tag) {
$dblink->query("INSERT INTO memht_tags (tag,cid,whr) VALUES ('".inCode(trim($tag))."','$id','2')");
}
}
echo "<meta http-equiv='refresh' content='0;URL=admin.php?page=guide'>";
} else {
echo "<div align='center' id='errorText'><b>$msg</b></div>";
}
}
}
function delete($id,$ok=false) {
global $dblink;
if ($ok) {
$dblink->query("DELETE FROM memht_guide WHERE id=$id");
$dblink->query("DELETE FROM memht_comments WHERE whr=2 AND wid=$id");
$dblink->query("DELETE FROM memht_ratings WHERE whr=2 AND wid=$id");
$dblink->query("DELETE FROM memht_tags WHERE whr=2 AND cid=$id");
echo "<meta http-equiv='refresh' content='0;URL=admin.php?page=guide'>";
} else {
echo "<div align='center'><b>"._SUREDELETEGUIDE_."</b><br><a href='admin.php?page=guide&op=deleteGuide&id=$id&ok=true' title='"._YES_."'>"._YES_."</a> - <a href='admin.php?page=guide' title='"._NO_."'>"._NO_."</a></div>";
}
}
require_once("admin/inc/inc_header.php");
admin_page_title($page);
openTable();
echo "<div align='center' class='box'>";
echo "<a href='admin.php?page=guide' title='"._LIST_."'><img src='admin/icons/list.png' border='0' title='"._LIST_."' align='top'> "._LIST_."</a>";
echo " - <a href='admin.php?page=guide&op=addGuide' title='"._ADD_."'><img src='admin/icons/add.png' border='0' title='"._ADD_."' align='top'> "._ADD_."</a>";
echo "</div>";
closeTable();
openTable();
switch($op) {
case "addGuide":
add($argomento,$nome,$descrizione,$testo,$tags,$usecomments,$language,$enabled,$ok);
break;
case "deleteGuide":
delete($id,$ok);
break;
case "editGuide":
edit($argomento,$nome,$descrizione,$testo,$tags,$usecomments,$language,$enabled,$ok,$id);
break;
default:
case "showGuides":
guiList($ofsbgn,$ofsppg,$pg);
break;
}
closeTable();
require_once("admin/inc/inc_footer.php");
?>
|