📄 edit.php
字号:
<?
class CModule extends CUserApp
{
function execute()
{
$this->checkLogin();
if($this->input[sendadd]) $this->addObject();
elseif($this->input[sendedit]) $this->editObject();
elseif(!empty($this->input[delete])) $this->deleteObject();
else $this->showEdit();
}
function showEdit()
{
$header = $this->Header("新增/修改软件");
$adminMenu = $this->getAdminMenu();
$aSoft = new CSoft;
$aSoft->open();
$banner = $this->printBanner($this->input[categoryid], $this->input[classid], "admin.php?modules=main");
$id = $this->input[id];
//动作
$sendname = "sendadd";
if(!empty($this->input[id]))
{
if(!$aSoft->find($this->input[id])) $this->showMsg("对不起,您要编辑的目标ID非法!", "");
$sendname = "sendedit";
}
//提交者
if(empty($aSoft->username)) $curUser = $this->sess[PDUserName];
else $curUser = $aSoft->username;
//推荐程度
for ($i=0; $i<=5; $i++)
{
if ($aSoft->grade == $i) $grade .= "<option value='".$i."' selected>".$i." 颗星</option>\n";
else $grade .= "<option value='$i'>$i 颗星</option>\n";
}
//更新日期
if (!empty($id)) $date = date($this->set[dateformat], $aSoft->updatetime);
else $date = date($this->set[dateformat], time());
//程序分类
$aCategory = new CCategory;
$aClass = new CClass;
$aCategory->open();
$aClass->open();
$aCategory->moveFirst();
for($i = 0; $i < $aCategory->getRecordCount(); $i++)
{
$category .= "<option>----".$aCategory->category_name."----</option>\n";
$cid = $aCategory->getAbsolutePosition();
$posList = $aClass->FilterByCategory($cid);
for($j = 0; $j < count($posList); $j ++)
{
$aClass->setAbsolutePosition($posList[$j]);
if($aSoft->class_id == $posList[$j] ) $category .= "<option value='".$posList[$j]."' selected>".$aClass->class_name."</option>\n";
else $category .= "<option value='".$posList[$j]."'>".$aClass->class_name."</option>\n";
}
$aCategory->moveNext();
}
$aCategory->close();
$aClass->close();
//程序简介
$brief = str_replace("<br>","\r\n",$aSoft->brief);
//是否推荐
if($aSoft->cancomment == "1") $comment = "<input type=checkbox name=cancomment checked value=1>";
else $comment = "<input type=checkbox name=cancomment value=1>";
//是否显示
if($aSoft->canshow == "1" || $id == "") $canshow = "<input type=checkbox name=canshow checked value=1>";
else $canshow = "<input type=checkbox name=canshow value=1>";
eval("\$this->output(\"".$this->getTemplate("adminEdit")."\");");
$aSoft->close();
}
function addObject()
{
if ($this->input[name]=="" || $this->input[brief]=="" || $this->input[down1]=="") $this->showMsg("\"程序名称\", \"程序简介\" 或 \"下载地址1\" 不能为空!", "");
if ($this->input[sort2id] < "0" || $this->input[sort2id] > "999999999") $this->showMsg("您没有选择分类或只选择大类!", "");
$timenow = time();
$aSoft = new CSoft;
$aSoft->open();
$aClass = new CClass;
$aClass->open();
if(!$aClass->find($this->input[sort2id])) $this->showMsg("所先小类ID非法!", "");
$category_id = $aClass->class_category_id;
//更新大类数量
$aCategory = new CCategory;
$aCategory->open();
if(!$aCategory->find($category_id)) $this->showMsg("所先大类ID非法!", "");
$aCategory->category_total = $aCategory->category_total + 1;
$aCategory->update();
$aCategory->close();
//更新小类数量
$aClass->class_total = $aClass->class_total + 1;
$aClass->update();
$aClass->close();
$aSoft->appendNew();
$aSoft->name = $this->input[name];
$aSoft->updatetime = $timenow;
$aSoft->size = $this->input[size];
$aSoft->empower = $this->input[empower];
$aSoft->os = $this->input[os];
$aSoft->grade = $this->input[grade];
$aSoft->viewnum = 0;
$aSoft->downnum = 0;
$brief = stripslashes($this->input[brief]);
$brief = $this->safeChars($brief);
$aSoft->homepage = $this->input[homepage];
$aSoft->demo = $this->input[demo];
$aSoft->brief = $brief;
$aSoft->img = $this->input[img];
$aSoft->category_id = $category_id;
$aSoft->class_id = $this->input[sort2id];
$aSoft->down1 = $this->input[down1];
$aSoft->down2 = $this->input[down2];
$aSoft->down3 = $this->input[down3];
$aSoft->down4 = $this->input[down4];
$aSoft->down5 = $this->input[down5];
$aSoft->cancomment = $this->input[cancomment];
$aSoft->username = $this->input[username];
$aSoft->keywords = $this->input[keywords];
$aSoft->canshow = $this->input[canshow];
$aSoft->update();
$aSoft->close();
$this->showMsg("恭喜,您的软件已添加成功!", "admin.php");
}
function editObject()
{
if ($this->input[name]=="" || $this->input[brief]=="" || $this->input[down1]=="") $this->showMsg("\"程序名称\", \"程序简介\" 或 \"下载地址1\" 不能为空!", "");
if ($this->input[sort2id] < "0" || $this->input[sort2id] > "999999999") $this->showMsg("您没有选择分类或只选择大类!", "");
$aSoft = new CSoft;
$aSoft->open();
if(!$aSoft->find($this->input[id])) $this->showMsg("对不起,您要删除的目标ID非法!", "");
$aSoft->name = $this->input[name];
$aSoft->size = $this->input[size];
$aSoft->empower = $this->input[empower];
$aSoft->os = $this->input[os];
$aSoft->grade = $this->input[grade];
$brief = stripslashes($this->input[brief]);
$brief = $this->safeChars($brief);
$aSoft->homepage = $this->input[homepage];
$aSoft->demo = $this->input[demo];
$aSoft->brief = $brief;
$aSoft->img = $this->input[img];
//处理大类及类别数量
if($aSoft->class_id != $this->input[sort2id])
{
$aClass = new CClass;
$aClass->open();
$aCategory = new CCategory;
$aCategory->open();
//更新原大类小类的数量
if(!$aCategory->find($aSoft->category_id)) $this->showMsg("对不起,目标的原大类ID非法!", "");
$aCategory->category_total = $aCategory->category_total - 1;
$aCategory->update();
if(!$aClass->find($aSoft->class_id)) $this->showMsg("对不起,目标原小类ID非法!", "");
$aClass->class_total = $aClass->class_total - 1;
$aClass->update();
//查找新小类所属的大类
if(!$aClass->find($this->input[sort2id])) $this->showMsg("对不起,您选择的新的小类ID非法!", "");
//修改目标的类另
$aSoft->category_id = $aClass->class_category_id;
$aSoft->class_id = $this->input[sort2id];
//修改新大类小类的数量
$aClass->class_total = $aClass->class_total + 1;
$aClass->update();
if(!$aCategory->find($aSoft->category_id)) $this->showMsg("对不起,目标的新大类ID非法!", "");
$aCategory->category_total = $aCategory->category_total + 1;
$aCategory->update();
$aClass->close();
$aCategory->close();
//考,这么麻烦,累死我了:))
}
$aSoft->down1 = $this->input[down1];
$aSoft->down2 = $this->input[down2];
$aSoft->down3 = $this->input[down3];
$aSoft->down4 = $this->input[down4];
$aSoft->down5 = $this->input[down5];
$aSoft->cancomment = $this->input[cancomment];
$aSoft->username = $this->input[username];
$aSoft->keywords = $this->input[keywords];
$aSoft->canshow = $this->input[canshow];
$aSoft->update();
$aSoft->close();
$this->showMsg("恭喜,您的目标已修改成功!", "admin.php");
}
function deleteObject()
{
$aSoft = new CSoft;
$aSoft->open();
if(!$aSoft->find($this->input[delete])) $this->showMsg("对不起,你要删除的目标ID非法!", "");
$aClass = new CClass;
$aClass->open();
if(!$aClass->find($aSoft->class_id)) $this->showMsg("此目标的小类ID非法!", "");
$aClass->class_total = $aClass->class_total - 1;
$aClass->update();
$aClass->close();
$aCategory = new CCategory;
$aCategory->open();
if(!$aCategory->find($aSoft->category_id)) $this->showMsg("此目标的大类ID非法!", "");
$aCategory->category_total = $aCategory->category_total - 1;
$aCategory->update();
$aCategory->close();
$aSoft->delete();
$aSoft->close();
//删除评论
$aReview = new CReview;
$aReview->open();
$flag = $aReview->moveFirst();
while($flag)
{
if($aReview->soft_id == $this->input[delete]) $aReview->delete();
$flag = $aReview->moveNext();
}
$aReview->close();
$this->showMsg("恭喜,您的目标及评论已删除成功!", "admin.php");
}
}// end class
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -