Viewing file: index.php (21.75 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>");
}
$op = (isset($_GET['op'])) ? inCode($_GET['op']) : "" ;
$id = (isset($_GET['id'])) ? intval($_GET['id']) : 0 ;
$ok = (isset($_GET['ok'])) ? inCode($_GET['ok']) : false ;
$category = (isset($_POST['category'])) ? intval($_POST['category']) : 0 ;
$title = (isset($_POST['title'])) ? eregi_replace("[/_']","-",inCode($_POST['title'])) : "" ;
$home_text = (isset($_POST['home_text'])) ? inCode($_POST['home_text']) : "" ;
$full_text = (isset($_POST['full_text'])) ? inCode($_POST['full_text']) : "" ;
$author = (isset($_POST['author'])) ? inCode($_POST['author']) : "" ;
$usecomments = (isset($_POST['usecomments'])) ? intval($_POST['usecomments']) : 0 ;
$tags = (isset($_POST['tags'])) ? inCode($_POST['tags']) : "" ;
$enabled = (isset($_POST['enabled'])) ? intval($_POST['enabled']) : 0 ;
$numposts = (isset($_POST['numposts'])) ? intval($_POST['numposts']) : 0 ;
$language = (isset($_POST['language'])) ? intval($_POST['language']) : 0 ;
$pg = (isset($_GET['pg'])) ? intval($_GET['pg']) : 1 ;
$ofsppg = 30; //Items per page
$ofsbgn = ($pg*$ofsppg)-$ofsppg;
function blogList($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><b>"._TITLE_."</b></td><td width='15%'><b>"._TAGS_."</b></td><td width='15%'>"._LANGUAGE_."</td><td width='15%'><b>"._CATEGORY_."</b></td><td width='15%'><b>"._AUTHOR_."</b></td><td width='1%'> </td></tr>";
echo "</thead>\n";
echo "<tbody>\n";
if ($result = $dblink->get_list("SELECT b.*,l.language AS languagetxt FROM memht_blog_posts AS b LEFT JOIN memht_content_languages AS l ON b.language = l.id ORDER BY b.id DESC LIMIT $ofsbgn,$ofsppg")) {
foreach ($result as $row) {
$id = intval($row['id']);
$category = intval($row['category']);
$title = outCode($row['title']);
$author = outCode($row['author']);
$language = outCode($row['languagetxt']);
$enabled = intval($row['enabled']);
if ($language=="") { $language = _GLOBAL_; }
$crow = $dblink->get_row("SELECT name FROM memht_blog_categories WHERE id=$category");
$category = outCode($crow['name']);
$off = ($enabled==0) ? "<img src='images/off.gif' alt='"._OFF_."' title='"._OFF_."'>" : "<img src='images/on.gif' alt='"._ON2_."' title='"._ON2_."'>" ;
$class = (($n++%2)!=0) ? "hlight" : "clean" ;
echo "<tr>";
echo "<td class='$class'><a href='index.php?page=blog&id=$id&title=".mem_urlencode($title)."' title='$title'><b>$title</b></a></td><td class='$class' id='info'>";
if ($result = $dblink->get_list("SELECT tag FROM memht_tags WHERE whr=5 AND cid=$id ORDER BY tag")) {
echo "<span style='padding:0 4px;'>";
foreach ($result as $row) {
echo " <a href=\"index.php?page=tags&op=list&tag=".mem_urlencode(outCode($row['tag']))."\" title=\"".outCode($row['tag'])."\" target='_blank'>".outCode($row['tag'])."</a>";
}
echo "</span>";
}
echo "</td>";
echo "<td class='$class'>$language</td><td id='info' class='$class'><i>$category</i></td>";
echo "<td id='info' class='$class'><i>$author</i></td>";
echo "<td width='5%' class='$class' align='right' nowrap><a href='admin.php?page=blog&op=edit&id=$id' title='"._MODIFY_."'><img src='images/edit.gif' alt='Edit' border='0'></a> <a href='admin.php?page=blog&op=delete&id=$id' title='"._DELETE_."'><img src='images/delete.gif' alt='Delete' border='0'></a> <a href='admin.php?page=blog&op=switch&id=$id' title='"._ON_OFF_."'><img src='images/on_off.gif' alt='On off' border='0'></a> $off</td></tr>\n";
}
} else {
echo "<tr><td align='center' id='errorText' class='clean' colspan='6'><b>"._EMPTY_."</b></td></tr>";
}
echo "</tbody>\n";
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_blog_posts";
$ps->url = "admin.php?page=blog&pg={{N}}";
$ps->show();
}
function add($category,$title,$home_text,$full_text,$author,$usecomments,$language,$tags,$enabled,$ok=false) {
global $dblink,$userInfo,$tzNOW;
if (!$ok) {
echo "<table width='100%' align='center' cellspacing='0' cellpadding='1'>";
echo "<form name='form' method='post' action='admin.php?page=blog&op=add&ok=true'>";
echo "<tr><td width='25%'><b>"._TITLE_."</b></td><td><input type='text' name='title' size='40' maxlength='255'></td></tr>\n";
echo "<tr><td><b>"._CATEGORY_."</b></td><td>\n";
echo "<select name='category'>\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 valign='top'><b>"._HOMETEXT_."</b></td><td>";
textarea("home_text","100%","400px",1,"fulladmin");
echo "</td></tr>\n";
echo "<tr><td valign='top'><b>"._TEXT_."</b></td><td>";
textarea("full_text","100%","600px",1,"fulladmin");
echo "</td></tr>\n";
echo "<tr><td><b>"._AUTHOR_."</b></td><td><input type='text' name='author' size='40' maxlength='255'> <span id='info'>("._LEAVE_EMPTY_FOR_DEFAULT_VALUE_.": ".$userInfo['user'].")</span></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 ($title=="") { $save = false; $msg = _TITLE_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
if ($home_text=="") { $save = false; $msg = _HOMETEXT_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
if ($author=="") { $author = $userInfo['user']; }
if ($save) {
if (memRunHooks('AddBlogPost',array($title,$category,$home_text,$full_text,$author,$language))) {
$dblink->query("INSERT INTO memht_blog_posts (id,category,title,home_text,full_text,author,date,usecomments,language,enabled)
VALUES (null,'$category','$title','$home_text','$full_text','$author',$tzNOW,'$usecomments','$language','$enabled')");
if ($tags!="") {
$row = $dblink->get_row("SELECT id FROM memht_blog_posts 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','5')");
}
}
memRunHooks('AddBlogPostEnd',array($title,$category,$home_text,$full_text,$author,$language));
}
echo "<meta http-equiv='refresh' content='0;URL=admin.php?page=blog'>";
} else {
echo "<div align='center' id='errorText'><b>$msg</b></div>";
}
}
}
function edit($id,$category,$title,$home_text,$full_text,$author,$usecomments,$language,$tags,$enabled,$ok=false) {
global $dblink,$tzNOW;
if (!$ok) {
$row = $dblink->get_row("SELECT * FROM memht_blog_posts WHERE id=$id");
$category = intval($row['category']);
$title = outCode($row['title']);
$home_text = outCode($row['home_text']);
$full_text = outCode($row['full_text']);
$author = outCode($row['author']);
$language = intval($row['language']);
$usecomments = intval($row['usecomments']);
$enabled = intval($row['enabled']);
if ($result = $dblink->get_list("SELECT tag FROM memht_tags WHERE whr=5 AND cid='$id'")) {
$tags = array();
foreach ($result as $row) {
$tags[] = outCode($row['tag']);
}
$tags = implode(",",$tags);
} else {
$tags = "";
}
echo "<table width='100%' align='center' cellspacing='0' cellpadding='1'>";
echo "<form name='form' method='post' action='admin.php?page=blog&op=edit&id=$id&ok=true'>";
echo "<tr><td width='25%'><b>"._TITLE_."</b></td><td><input type='text' name='title' value=\"$title\" size='40' maxlength='255'></td></tr>\n";
echo "<tr><td><b>"._CATEGORY_."</b></td><td>\n";
echo "<select name='category'>\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']);
$selected = ($category==$cid) ? " selected" : "" ;
echo "<option value='$cid'{$selected}>$name</option>\n";
}
echo "</select></td></tr>\n";
echo "<tr><td valign='top'><b>"._HOMETEXT_."</b></td><td>";
textarea("home_text","100%","400px",1,"fulladmin",$home_text);
echo "</td></tr>\n";
echo "<tr><td valign='top'><b>"._TEXT_."</b></td><td>";
textarea("full_text","100%","600px",1,"fulladmin",$full_text);
echo "</td></tr>\n";
echo "<tr><td><b>"._AUTHOR_."</b></td><td><input type='text' name='author' value=\"$author\" size='40' maxlength='255'></td></tr>\n";
echo "<tr><td><b>"._TAGS_."</b></td><td><input type='text' name='tags' value=\"$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";
$selected = ($language==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 = ($language==$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 ($enabled==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_."'></td></tr>\n";
echo "</form>\n";
echo "</table>\n";
} else {
$save = true;
if ($title=="") { $save = false; $msg = _TITLE_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
if ($home_text=="") { $save = false; $msg = _HOMETEXT_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
if ($author=="") { $author = $userInfo['user']; }
if ($save) {
$dblink->query("UPDATE memht_blog_posts SET category='$category',title='$title',home_text='$home_text',full_text='$full_text',author='$author',language='$language',usecomments='$usecomments',enabled='$enabled' WHERE id=$id");
$dblink->query("DELETE FROM memht_tags WHERE whr=5 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','5')");
}
}
echo "<meta http-equiv='refresh' content='0;URL=admin.php?page=blog'>";
} else {
echo "<div align='center' id='errorText'><b>$msg</b></div>";
}
}
}
function delete($id,$ok=false) {
global $dblink;
$id = intval($id);
if ($ok) {
$dblink->query("DELETE FROM memht_blog_posts WHERE id=$id");
$dblink->query("DELETE FROM memht_comments WHERE whr=5 AND wid=$id");
$dblink->query("DELETE FROM memht_ratings WHERE whr=5 AND wid=$id");
$dblink->query("DELETE FROM memht_tags WHERE whr=5 AND cid=$id");
echo "<meta http-equiv='refresh' content='0;URL=admin.php?page=blog'>";
} else {
echo "<div align='center'><b>"._SUREDELETE_."</b><br><a href='admin.php?page=blog&op=delete&id=$id&ok=true' title='"._YES_."'>"._YES_."</a> - <a href='admin.php?page=blog' title='"._NO_."'>"._NO_."</a></div>";
}
}
function changeStatus($id) {
global $dblink;
$id = intval($id);
$row = $dblink->get_row("SELECT enabled FROM memht_blog_posts WHERE id=$id");
$enabled = intval($row['enabled']);
$newstatus = ($enabled==1) ? 0 : 1 ;
$dblink->query("UPDATE memht_blog_posts SET enabled='$newstatus' WHERE id=$id");
echo "<meta http-equiv='refresh' content='0;URL=admin.php?page=blog'>";
}
function catList() {
global $dblink;
$n = 0;
echo "<table width='100%' align='center' cellspacing='1' cellpadding='0' class='std_nicetable'>";
echo "<thead>\n";
echo "<tr><td><b>"._NAME_."</b></td><td width='1%'> </td></tr>\n";
echo "</thead>\n";
echo "<tbody>\n";
if ($result = $dblink->get_list("SELECT id,name FROM memht_blog_categories ORDER BY name")) {
foreach ($result as $row) {
$id = intval($row['id']);
$name = outCode($row['name']);
$class = (($n++%2)!=0) ? "hlight" : "clean" ;
echo "<tr><td class='$class'><b>$name</b></td><td width='5%' class='$class' align='right' nowrap><a href='admin.php?page=blog&op=editCat&id=$id' title='"._MODIFY_."'><img src='images/edit.gif' alt='Edit' border='0'></a> <a href='admin.php?page=blog&op=deleteCat&id=$id' title='"._DELETE_."'><img src='images/delete.gif' alt='Delete' border='0'></a></td></tr>\n";
}
} else {
echo "<tr><td align='center' id='errorText' colspan='2' class='clean'><b>"._EMPTY_."</b></td></tr>";
}
echo "</tbody>\n";
echo "</table>";
}
function addCat($title,$ok=false) {
global $dblink;
if (!$ok) {
echo "<table width='100%' align='center' cellspacing='0' cellpadding='1'>\n";
echo "<form name='form' method='post' action='admin.php?page=blog&op=addCat&ok=true'>";
echo "<tr><td width='25%'><b>"._CATEGORYNAME_."</b><td><input type='text' name='title' size='40' maxlength='255'>\n";
echo "<tr><td colspan='2'><input type='submit' name='Submit' value='"._ADD_."'>\n";
echo "</form>\n";
echo "</table>\n";
} else {
$save = true;
if ($title=="") { $save = false; $msg = _CATEGORYNAME_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
if ($save) {
$dblink->query("INSERT INTO memht_blog_categories (id,name) VALUES (null,'$title')");
echo "<meta http-equiv='refresh' content='0;URL=admin.php?page=blog&op=categories'>";
} else {
echo "<div align='center' id='errorText'><b>$msg</b></div>";
}
}
}
function editCat($id,$title,$ok=false) {
global $dblink;
$id = intval($id);
if (!$ok) {
$row = $dblink->get_row("SELECT name FROM memht_blog_categories WHERE id=$id");
$title = outCode($row['name']);
echo "<table width='100%' align='center' cellspacing='0' cellpadding='1'>\n";
echo "<form name='form' method='post' action='admin.php?page=blog&op=editCat&id=$id&ok=true'>";
echo "<tr><td width='25%'><b>"._CATEGORYNAME_."</b><td><input type='text' name='title' value=\"$title\" size='40' maxlength='255'>\n";
echo "<tr><td colspan='2'><input type='submit' name='Submit' value='"._MODIFY_."'>\n";
echo "</form>\n";
echo "</table>\n";
} else {
$save = true;
if ($title=="") { $save = false; $msg = _CATEGORYNAME_." ".strtolower(_FIELD_)." ".strtolower(_REQUIRED_); }
if ($save) {
$dblink->query("UPDATE memht_blog_categories SET name='$title' WHERE id=$id");
echo "<meta http-equiv='refresh' content='0;URL=admin.php?page=blog&op=categories'>";
} else {
echo "<div align='center' id='errorText'><b>$msg</b></div>";
}
}
}
function deleteCat($id,$ok=false) {
global $dblink;
if ($ok) {
$dblink->query("DELETE FROM memht_blog_categories WHERE id=$id");
$result = $dblink->get_list("SELECT id FROM memht_blog_posts WHERE category=$id");
foreach ($result as $row) {
$id = intval($row['id']);
$dblink->query("DELETE FROM memht_blog_posts WHERE id=$id");
$dblink->query("DELETE FROM memht_comments WHERE whr=5 AND wid=$id");
$dblink->query("DELETE FROM memht_ratings WHERE whr=5 AND wid=$id");
$dblink->query("DELETE FROM memht_tags WHERE whr=5 AND cid=$id");
}
echo "<meta http-equiv='refresh' content='0;URL=admin.php?page=blog&op=categories'>";
} else {
echo "<div align='center'><b>"._SUREDELETE_."</b><br><a href='admin.php?page=blog&op=deleteCat&id=$id&ok=true' title='"._YES_."'>"._YES_."</a> - <a href='admin.php?page=blog' title='"._NO_."'>"._NO_."</a></div>";
}
}
function configuration($numposts,$ok=false) {
global $dblink;
if ($dblink->get_num("SELECT * FROM memht_blog_configuration")==0) { $dblink->query("INSERT INTO memht_blog_configuration (numposts) VALUES ('15')"); }
if (!$ok) {
$row = $dblink->get_row("SELECT * FROM memht_blog_configuration");
$numposts = intval($row['numposts']);
echo "<table width='100%' align='center' cellspacing='0' cellpadding='1'>\n";
echo "<form name='form' method='post' action='admin.php?page=blog&op=config&ok=true'>";
echo "<tr><td width='25%'><b>"._NUMPOSTS_."</b> ("._PERPAGE_.")<td><input type='text' name='numposts' value=\"$numposts\" size='10' maxlength='255'>\n";
echo "<tr><td colspan='2'><input type='submit' name='Submit' value='"._SAVE_."'>\n";
echo "</form>\n";
echo "</table>\n";
} else {
if ($numposts<=0) { $numposts = 15; }
$dblink->query("UPDATE memht_blog_configuration SET numposts='$numposts'");
echo "<meta http-equiv='refresh' content='0;URL=admin.php?page=blog&op=config'>";
}
}
require_once("admin/inc/inc_header.php");
admin_page_title($page);
openTable();
echo "<div align='center' class='box'>";
echo "<a href='admin.php?page=blog' title='"._LIST_."'><img src='admin/icons/messages.png' border='0' title='"._LIST_."' align='top'> "._LIST_."</a>";
echo " - <a href='admin.php?page=blog&op=add' title='"._ADD_."'><img src='admin/icons/add.png' border='0' title='"._ADD_."' align='top'> "._ADD_."</a>";
echo " - <a href='admin.php?page=blog&op=categories' title='"._SHOW_CATEGORIES_."'><img src='admin/icons/category.png' border='0' title='"._SHOW_CATEGORIES_."' align='top'> "._SHOW_CATEGORIES_."</a>";
echo " - <a href='admin.php?page=blog&op=addCat' title='"._ADD_CATEGORY_."'><img src='admin/icons/addcategory.png' border='0' title='"._ADD_CATEGORY_."' align='top'> "._ADD_CATEGORY_."</a>";
echo " - <a href='admin.php?page=blog&op=config' title='"._CONFIGURATION_."'><img src='admin/icons/config.png' border='0' title='"._CONFIGURATION_."' align='top'> "._CONFIGURATION_."</a>";
echo "</div>";
closeTable();
openTable();
switch($op) {
case "add":
add($category,$title,$home_text,$full_text,$author,$usecomments,$language,$tags,$enabled,$ok);
break;
case "edit":
edit($id,$category,$title,$home_text,$full_text,$author,$usecomments,$language,$tags,$enabled,$ok);
break;
case "delete":
delete($id,$ok);
break;
case "switch":
changeStatus($id);
break;
case "categories":
catList();
break;
case "addCat":
addCat($title,$ok);
break;
case "editCat":
editCat($id,$title,$ok);
break;
case "deleteCat":
deleteCat($id,$ok);
break;
case "config":
configuration($numposts,$ok);
break;
default:
blogList($ofsbgn,$ofsppg,$pg);
break;
}
closeTable();
require_once("admin/inc/inc_footer.php");
?>
|