【php开源代码栏目提醒】:网学会员为广大网友收集整理了,blog.admin.php,希望对大家有所帮助!
<?php
if($_REQUEST['act'] == "add") {
// no need to calculate a table name, as we will not be
// creating new tables for each blog any longer.
$err = "";
if(($_REQUEST['type'] == 2) and (count($_REQUEST['luser']) == 0)) {
$err = "Must pick atleast one user for this blog!";
}
if(($_REQUEST['type'] == 3) and (count($_REQUEST['luser']) != 1)) {
$err = "Private Blog must have one user!";
}
if($err == "") {
require_once("class.BlogServer.php");
$blogServer = new BlogServer();
$blogInfo = $blogServer->createBlog($_REQUEST['blogtitle'], $_REQUEST['tagline'], $_REQUEST['type'], $_REQUEST['luser'], $_REQUEST['badmin']);
$blogUsers = $blogInfo->getBlogUsers();
$to = "To:";
foreach ($blogUsers as $blogUser) {
$to .= $blogUser->userEmail.",";
}
$mesg = "The Blog admin has created a new blog, ".$_REQUEST['blogtitle'].", and has allowed you to contribute. The next time you log in, you will be able to contribute to ".$_REQUEST['blogtitle'].". Enjoy!\n";
mail($to,"New Blog Creation",$mesg,"From: $adminemail\nReply-to: $adminemail");
echo "<tr><td colspan=2>Blog ".$_REQUEST['blogtitle']." created!!!!</td></tr>\n";
} else {
echo "<tr><td colspan=2><b>$err</b></td></tr>\n";
}
$head = 'Add';
$action = 'add';
$blogtitle = '';
$type_id = '';
$blogadmin = '';
$tagline = '';
} elseif($_REQUEST['act'] == "delete") {
$blogInfo =& new BlogInfo($_REQUEST['blog']);
$title = $blogInfo->getBlogTitle();
require("class.BlogServer.php");
$blogServer = new BlogServer();
$blogServer->deleteBlogById($_REQUEST['blog']);
$blogInfo = NULL;
echo "<tr><td colspan=2><b>博客 ".$title." 删除成功!</b></td></tr>\n";
$head = 'Add';
$action = 'add';
$blogtitle = '';
$type_id = '';
$blogadmin = '';
$tagline = '';
} elseif($_REQUEST['act'] == "update") {
$err = "";
if(($_REQUEST['type'] == 2) and (count($_REQUEST['acl']) == 0)) {
$err = "Must pick atleast one user for this blog!";
}
if(($_REQUEST['type'] == 3) and (count($_REQUEST['acl']) != 1)) {
$err = "Private Blog must have one user!";
}
if($err == "") {
if($_REQUEST['blogtitle'] != $_REQUEST['oldtitle']) {
$sql = "select count(*) as count from blog_list where title='".escape($_REQUEST['blogtitle'])."'";
$res = $db->Execute($sql);
$found = $res->fields['count'];
}
if(!$found) {
$sql = "update blog_list set title='".escape($_REQUEST['blogtitle'])."',type_id=".$_REQUEST['type'].", admin=".$_REQUEST['badmin'].", tagline='".escape($_REQUEST['tagline'])."' where blog_id=".$_REQUEST['bid'];
$res = $db->Execute($sql);
$sql = "delete from blog_acl where blog_id=".$_REQUEST['bid'];
$res = $db->Execute($sql);
for($i=0; $i<count($_REQUEST['acl']); $i++) {
$sql = "SELECT id from blog_users where id='".$_REQUEST['acl'][$i]."'";
$res = $db->Execute($sql);
$sql = "insert into blog_acl (user_id,blog_id) values (".$res->fields['id'].",".$_REQUEST['bid'].")";
$res = $db->Execute($sql);
}
echo "<tr><td colspan=2><b>博客 $blogtitle 更新成功!</b></td></tr>\n";
} else {
echo "<tr><td colspan=2><b>Blog titled $blogtitle already exists!</b></td></tr>\n";
}
} else {
echo "<tr><td colspan=2><b>$err</b></td></tr>\n";
}
$head = 'Add';
$action = 'add';
$blogtitle = '';
$type_id = '';
$blogadmin = '';
$tagline = '';
} elseif($_REQUEST['act'] == 'edit') {
$sql = "select * from blog_list where blog_id=".$_REQUEST['blog'];
$res = $db->Execute($sql);
$blogtitle = $res->fields['title'];
$type_id = $res->fields['type_id'];
$blogadmin = $res->fields['admin'];
$tagline = $res->fields['tagline'];
$head = "Edit";
$action = "update";
} else {
$head = 'Add';
$action = 'add';
}
?>
<tr>
<td valign=top>
<table>
<tr>
<td class=header>
<b><?=$head?> 博客</b>
</td>
</tr>
<tr>
<td>
<form action="admin.php" name=modblog method=POST>
<table>
<tr>
<td valign=top>
博客标题: <input type=text size=16 maxlength=32 name=blogtitle value="<?= $blogtitle; ?>"><p>
</td>
<td valign=top>
博客类型:
<select name=type>
<?php
$sql = "SELECT type_id,description from blog_types";
$res = $db->Execute($sql);
while(!$res->EOF) {
echo "<option value=\"".$res->fields['type_id']."\"";
if($res->fields['type_id'] == $type_id) {
echo "SELECTED";
}
echo ">".$res->fields['description']."\n";
$res->MoveNext();
}
?>
</select>
</td>
</tr>
<tr>
<td colspan=2>
Tagline: <input type=text size=16 maxlength=128 name=tagline value="<?=$tagline?>">
</td>
</tr>
<tr>
<td colspan=2>
博客主人:
<select name="badmin">
<?php
$sql = "SELECT blog_users.id,blog_users.name from blog_users";
if($_REQUEST['act'] == 'edit') {
$sql .= ", blog_acl where blog_acl.blog_id=".$_REQUEST['blog']." and blog_acl.user_id=blog_users.id";
}
$res = $db->Execute($sql);
while(!$res->EOF) {
echo "<option value=\"".$res->fields['id']."\"";
if($blogadmin == $res->fields['id']) {
echo " SELECTED";
}
echo ">".$res->fields['name']."\n";
$res->MoveNext();
}
?>
</select>
</td>
</tr>
<tr>
<td valign=top colspan=2>
<table>
<tr>
<tr>
<td>所有用户<br>
<select name="luser[]" size=5 multiple>
<?php
$sql = "SELECT * from blog_users";
$res = $db->Execute($sql);
while(!$res->EOF) {
echo "<option value=\"".$res->fields['id']."\">".$res->fields['name']."\n";
$res->MoveNext();
}
?>
</td>
<?php if($_REQUEST['act'] == 'edit'): ?>
<td valign=middle>
<input class=search type=button value=">>" onClick="javascript:addNames()"><p>
<input class=search type=button value="<<" onClick="javascript:removeNames()">
</td>
<td><?=$blogtitle?> 管理人员<br>
<select name="acl[]" size=5 multiple>
<?php
$count = 0;
$sql = "SELECT user_id from blog_acl where blog_id=".$_REQUEST['blog'];
$res = $db->Execute($sql);
while(!$res->EOF) {
if(($res->fields['user_id'] == "") and ($count == 0)) {
break;
}
$sql2 = "select * from blog_users where id=".$res->fields['user_id'];
$res2 = $db->Execute($sql2);
echo "<option value=\"".$res2->fields['id']."\">".$res2->fields['name']."</option>\n";
$count++;
$res->MoveNext();
}
if($count == 0) {
echo "<option value=\"null\">没有用户可选择</option>\n";
}
?>
</select>
</td>
<?php endif; ?>
</tr>
</table>
</td>
</tr>
</table>
<input type=hidden name=blogid value="<?=$blogid?>">
<input type=hidden name=oldtitle value="<?=$blogtitle?>">
<input type=hidden name=bid value="<?=$_REQUEST['blog']?>">
上一篇:
block_infotype.php
下一篇:
关于高职院校公共机房的管理与维护