ListTask.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. define('EmpireCMSAdmin','1');
  3. require("../../class/connect.php");
  4. require("../../class/db_sql.php");
  5. require("../../class/functions.php");
  6. require "../".LoadLang("pub/fun.php");
  7. $link=db_connect();
  8. $empire=new mysqlquery();
  9. $editor=1;
  10. //验证用户
  11. $lur=is_login();
  12. $logininid=$lur['userid'];
  13. $loginin=$lur['username'];
  14. $loginrnd=$lur['rnd'];
  15. $loginlevel=$lur['groupid'];
  16. $loginadminstyleid=$lur['adminstyleid'];
  17. //ehash
  18. $ecms_hashur=hReturnEcmsHashStrAll();
  19. //验证权限
  20. CheckLevel($logininid,$loginin,$classid,"task");
  21. //返回秒组合
  22. function ReturnTogMins($min){
  23. $count=count($min);
  24. if($count==0)
  25. {
  26. return ',';
  27. }
  28. $str=',';
  29. for($i=0;$i<$count;$i++)
  30. {
  31. $str.=$min[$i].',';
  32. }
  33. return $str;
  34. }
  35. //增加计划任务
  36. function AddTask($add,$userid,$username){
  37. global $empire,$dbtbpre;
  38. if(empty($add['taskname'])||empty($add['filename']))
  39. {
  40. printerror('EmptyTaskname','');
  41. }
  42. //验证权限
  43. CheckLevel($userid,$username,$classid,"task");
  44. if(strstr($add['filename'],'/')||strstr($add['filename'],"\\"))
  45. {
  46. printerror('ErrorTaskFilename','');
  47. }
  48. $userid=(int)$add['userid'];
  49. $isopen=(int)$add['isopen'];
  50. $add['dominute']=ReturnTogMins($add['min']);
  51. $add['taskname']=hRepPostStr($add['taskname'],1);
  52. $add['filename']=hRepPostStr($add['filename'],1);
  53. $add['doweek']=hRepPostStr($add['doweek'],1);
  54. $add['doday']=hRepPostStr($add['doday'],1);
  55. $add['dohour']=hRepPostStr($add['dohour'],1);
  56. $add['dominute']=hRepPostStr($add['dominute'],1);
  57. $sql=$empire->query("insert into {$dbtbpre}enewstask(taskname,userid,isopen,filename,lastdo,doweek,doday,dohour,dominute) values('$add[taskname]',$userid,$isopen,'$add[filename]',0,'$add[doweek]','$add[doday]','$add[dohour]','$add[dominute]');");
  58. if($sql)
  59. {
  60. $id=$empire->lastid();
  61. //操作日志
  62. insert_dolog("id=$id&taskname=$add[taskname]&filename=$add[filename]");
  63. printerror('AddTaskSuccess','AddTask.php?enews=AddTask'.hReturnEcmsHashStrHref2(0));
  64. }
  65. else
  66. {
  67. printerror('DbError',"");
  68. }
  69. }
  70. //修改计划任务
  71. function EditTask($add,$userid,$username){
  72. global $empire,$dbtbpre;
  73. $id=(int)$add['id'];
  74. if(!$id||empty($add['taskname'])||empty($add['filename']))
  75. {
  76. printerror('EmptyTaskname','');
  77. }
  78. //验证权限
  79. CheckLevel($userid,$username,$classid,"task");
  80. if(strstr($add['filename'],'/')||strstr($add['filename'],"\\"))
  81. {
  82. printerror('ErrorTaskFilename','');
  83. }
  84. $userid=(int)$add['userid'];
  85. $isopen=(int)$add['isopen'];
  86. $add['dominute']=ReturnTogMins($add['min']);
  87. $add['taskname']=hRepPostStr($add['taskname'],1);
  88. $add['filename']=hRepPostStr($add['filename'],1);
  89. $add['doweek']=hRepPostStr($add['doweek'],1);
  90. $add['doday']=hRepPostStr($add['doday'],1);
  91. $add['dohour']=hRepPostStr($add['dohour'],1);
  92. $add['dominute']=hRepPostStr($add['dominute'],1);
  93. $sql=$empire->query("update {$dbtbpre}enewstask set taskname='$add[taskname]',userid=$userid,isopen=$isopen,filename='$add[filename]',doweek='$add[doweek]',doday='$add[doday]',dohour='$add[dohour]',dominute='$add[dominute]' where id=$id");
  94. if($sql)
  95. {
  96. //操作日志
  97. insert_dolog("id=$id&taskname=$add[taskname]&filename=$add[filename]");
  98. printerror('EditTaskSuccess','ListTask.php'.hReturnEcmsHashStrHref2(1));
  99. }
  100. else
  101. {
  102. printerror('DbError',"");
  103. }
  104. }
  105. //删除计划任务
  106. function DelTask($add,$userid,$username){
  107. global $empire,$dbtbpre;
  108. $id=(int)$add['id'];
  109. if(!$id)
  110. {
  111. printerror('EmptyDelTaskId','');
  112. }
  113. //验证权限
  114. CheckLevel($userid,$username,$classid,"task");
  115. $r=$empire->fetch1("select taskname,filename from {$dbtbpre}enewstask where id=$id");
  116. $sql=$empire->query("delete from {$dbtbpre}enewstask where id=$id");
  117. if($sql)
  118. {
  119. //操作日志
  120. insert_dolog("id=$id&taskname=$r[taskname]&filename=$r[filename]");
  121. printerror('DelTaskSuccess','ListTask.php'.hReturnEcmsHashStrHref2(1));
  122. }
  123. else
  124. {
  125. printerror('DbError',"");
  126. }
  127. }
  128. $enews=$_POST['enews'];
  129. if(empty($enews))
  130. {$enews=$_GET['enews'];}
  131. if($enews)
  132. {
  133. hCheckEcmsRHash();
  134. }
  135. if($enews=="AddTask")
  136. {
  137. AddTask($_POST,$logininid,$loginin);
  138. }
  139. elseif($enews=="EditTask")
  140. {
  141. EditTask($_POST,$logininid,$loginin);
  142. }
  143. elseif($enews=="DelTask")
  144. {
  145. DelTask($_GET,$logininid,$loginin);
  146. }
  147. else
  148. {}
  149. $search=$ecms_hashur['ehref'];
  150. $page=(int)$_GET['page'];
  151. $page=RepPIntvar($page);
  152. $start=0;
  153. $line=20;//每页显示条数
  154. $page_line=20;//每页显示链接数
  155. $offset=$page*$line;//总偏移量
  156. $query="select id,taskname,isopen,lastdo,doweek,doday,dohour,dominute from {$dbtbpre}enewstask";
  157. $totalquery="select count(*) as total from {$dbtbpre}enewstask";
  158. $num=$empire->gettotal($totalquery);//取得总条数
  159. $query=$query." order by id desc limit $offset,$line";
  160. $sql=$empire->query($query);
  161. $returnpage=page2($num,$line,$page_line,$start,$page,$search);
  162. ?>
  163. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  164. <html>
  165. <head>
  166. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  167. <link href="../adminstyle/<?=$loginadminstyleid?>/adminstyle.css" rel="stylesheet" type="text/css">
  168. <title>管理计划任务</title>
  169. </head>
  170. <body>
  171. <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
  172. <tr>
  173. <td width="50%" height="25">位置:<a href='ListTask.php<?=$ecms_hashur['whehref']?>'>管理计划任务</a></td>
  174. <td><div align="right" class="emenubutton">
  175. <input type="button" name="Submit" value="增加计划任务" onclick="self.location.href='AddTask.php?enews=AddTask<?=$ecms_hashur['ehref']?>';">&nbsp;&nbsp;
  176. <input type="button" name="Submit" value="运行计划任务页面" onclick="window.open('../task.php<?=$ecms_hashur['whhref']?>');">
  177. </div></td>
  178. </tr>
  179. </table>
  180. <br>
  181. <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
  182. <tr class="header">
  183. <td width="6%" height="25"> <div align="center">ID</div></td>
  184. <td width="25%" height="25"> <div align="center">任务名称</div></td>
  185. <td width="15%" height="25">
  186. <div align="center">分钟</div></td>
  187. <td width="5%">
  188. <div align="center">小时</div></td>
  189. <td width="5%">
  190. <div align="center">星期</div></td>
  191. <td width="5%"><div align="center">日</div></td>
  192. <td width="17%"><div align="center">最后执行时间</div></td>
  193. <td width="5%"><div align="center">状态</div></td>
  194. <td width="17%" height="25"> <div align="center">操作</div></td>
  195. </tr>
  196. <?php
  197. while($r=$empire->fetch($sql))
  198. {
  199. $r['doweek']=','.$r['doweek'].','!=',*,'&&$r['doweek']==0?7:$r['doweek'];
  200. $lastdo=$r['lastdo']?date("Y-m-d H:i",$r['lastdo']):'---';
  201. if(strlen($r['dominute'])>26)
  202. {
  203. $r['dominute']=substr($r['dominute'],0,23).'...';
  204. }
  205. ?>
  206. <tr bgcolor="#FFFFFF" onmouseout="this.style.backgroundColor='#ffffff'" onmouseover="this.style.backgroundColor='#C3EFFF'">
  207. <td height="25"> <div align="center">
  208. <?=$r['id']?>
  209. </div></td>
  210. <td height="25"> <div align="center">
  211. <?=$r['taskname']?>
  212. </div></td>
  213. <td height="25"><div align="center"><?=$r['dominute']?></div></td>
  214. <td><div align="center"><?=$r['dohour']?></div></td>
  215. <td><div align="center"><?=$r['doweek']?></div></td>
  216. <td><div align="center"><?=$r['doday']?></div></td>
  217. <td><div align="center"><?=$lastdo?></div></td>
  218. <td><div align="center"><?=$r['isopen']==1?'开启':'关闭'?></div></td>
  219. <td height="25"> <div align="center">[<a href="../task.php?ecms=TodoTask&id=<?=$r[id]?><?=$ecms_hashur['href']?>" onclick="return confirm('确认要执行?');">执行</a>]
  220. [<a href="AddTask.php?enews=EditTask&id=<?=$r[id]?><?=$ecms_hashur['ehref']?>">修改</a>]&nbsp;[<a href="ListTask.php?enews=DelTask&id=<?=$r[id]?><?=$ecms_hashur['href']?>" onclick="return confirm('确认要删除?');">删除</a>]</div></td>
  221. </tr>
  222. <?
  223. }
  224. ?>
  225. <tr bgcolor="#FFFFFF">
  226. <td height="25" colspan="9">&nbsp;&nbsp;&nbsp;
  227. <?=$returnpage?>
  228. </td>
  229. </tr>
  230. </table>
  231. </body>
  232. </html>
  233. <?
  234. db_close();
  235. $empire=null;
  236. ?>