public function index() { $url = get_url(); //获取当前页面的URL地址 $memb = M('Member'); if (IS_POST) { $idarr = I('post.idarr'); $where = array('vip_id' => array('in', $idarr)); $res = $memb->where($where)->delete(); if ($res) { echo "<script>window.location.href=" . $url . ";</script>"; } else { echo "<script>alert('删除失败');window.history.go(-1);</script>"; } } $current = I('get.page', 1); $limit = 20; $art = ($current - 1) * $limit; $fir = strpos($url, 'page'); if ($fir) { $purl = mb_substr($url, 0, $fir - 1); } else { $purl = $url; } $count = $memb->count(); $show = list_page($current, $limit, $count, $purl); $vip = $memb->order('vip_addtime DESC')->limit($art, $limit)->select(); $data = array('vip' => $vip, 'show' => $show); $this->assign($data); $this->display(); }
function new_age() { $msg = M('Message'); $limit = $_POST['limit']; $current = I('get.page', 1); $art = ($current - 1) * $limit; $url = get_url(); //获取当前页面的URL地址 $fir = strpos($url, 'page'); if ($fir) { $purl = mb_substr($url, 0, $fir - 1); } else { $purl = $url; } $count = $msg->count(); $show = list_page($current, $limit, $count, $purl); $msg = $msg->order('msg_addtime DESC')->limit($art, $limit)->select(); foreach ($msg as $key => $val) { $msg[$key]['msg_ctitle'] = str_cut($val['msg_content'], 0, 21); } $data = array('msg' => $msg, 'show' => $show); echo json_encode($data); }
public function comment() { if (IS_GET) { $aid = I('get.aid'); $cmt = M('Artcomment'); $current = I('get.page', 1); $limit = 10; $art = ($current - 1) * $limit; $url = get_url(); //获取当前页面的URL地址 $fir = strpos($url, 'page'); if ($fir) { $purl = mb_substr($url, 0, $fir - 1); } else { $purl = $url; } $count = $cmt->count(); $res = $cmt->where(array('cmt_art_id' => $aid))->limit($art, $limit)->select(); $reply = M('Artcmt_reply'); $rep = $reply->select(); foreach ($res as $key => $val) { $res[$key]['cmt_ctitle'] = str_cut($val['cmt_content'], 0, 21); foreach ($rep as $k => $v) { if ($v['reply_cmtid'] == $val['cmt_id']) { $res[$key]['cmt_reply'][] = $v; } } } $show = list_page($current, $limit, $count, $purl); // print_r($res);die; $data = array('cmt' => $res, 'show' => $show); $this->assign($data); $this->display(); } if (IS_POST) { // print_r(I('post.idarr'));die; $id = I('post.idarr'); $cmt = M('Artcomment'); $reply = M('Artcmt_reply'); $cres = $cmt->where(array('cmt_id' => array('in', $id)))->delete(); $rres = $reply->where(array('reply_cmtid' => array('in', $id)))->delete(); $url = get_url(); if ($cres) { echo "<script>window.location.href='" . $url . "';</script>"; exit; } else { echo "<script>alert('删除失败');window.location.href='" . $url . "';</script>"; exit; } } }
function cms_list($type, $nodeid, $num, $substr, $tableid, $tplname = 'list.default.html', $articleID) { global $db, $SYS_ENV, $table, $iWPC, $db_config, $cmsware; $PageMode = false; /** 初始化调用节点sql */ if (empty($nodeid)) { //所有节点 $list_where = ''; } elseif (preg_match("/^[0-9]+,[0-9]+/", $nodeid)) { //多个节点 $list_where .= " AND i.NodeID IN({$nodeid})"; } elseif (preg_match("/^all-[0-9]+/", $nodeid)) { //根节点并包括所有子节点 $nodeid = str_replace("all-", '', $nodeid); $NodeInfo = $iWPC->loadNodeInfo($nodeid); if ($NodeInfo[notExist]) { echo '<B>Error:</B>The NodeID <font color=#FF0000></font> you have set does not exist!'; return false; } $More = cms_getNodeUrl($NodeInfo); $nodeid = str_replace('%', ',', $NodeInfo[SubNodeID]); $list_where .= " AND i.NodeID IN({$nodeid})"; } else { //单一一个节点 $NodeInfo = $iWPC->loadNodeInfo($nodeid); if ($NodeInfo[notExist]) { echo '<B>Error:</B>The NodeID <font color=#FF0000></font> you have set does not exist!'; return false; } $More = CMSware::cms_getNodeUrl($NodeInfo); $list_where = " AND i.NodeID='{$nodeid}'"; } /* Add by Daniel,2004.7.21,增加调用指定文章id的查询参数串 */ if (empty($articleID)) { //所有节点 $list_assign = ''; } else { //单一一个节点 $list_assign = " AND i.ContentID='{$articleID}'"; } /* Add end by Daniel,2004.7.21 */ /** 初始化调用数量sql */ if (empty($num)) { $list_limit = ' '; } elseif (preg_match("/^[0-9]+,[0-9]+\$/", $num)) { list($start, $offset) = explode(",", $num); $list_limit = " Limit {$start},{$offset} "; } elseif (preg_match("/^page-[0-9]+\$/", $num)) { $offset = str_replace("page-", '', $num); $offset = (int) $offset; $PageMode = true; } elseif (preg_match("/^[0-9]+\$/", $num)) { $list_limit = " Limit 0,{$num} "; } else { die("<font color =red >Fatal Error!</font> 你的调用语法书写有误,请返回修改!"); } /** 初始化排序字段sql */ if (!empty($orderby)) { $list_orderby = " ORDER BY i.Top DESC,i.{$orderby} "; } else { $list_orderby = " ORDER BY i.Top DESC,i.PublishDate "; } /** 初始化排序sql */ if (!empty($order)) { $list_order = " {$order} "; } else { $list_order = " DESC "; } /** 预设TableID */ if (empty($tableid)) { if (!empty($NodeInfo)) { $tableid = $NodeInfo[TableID]; } } $table_name = $db_config['table_pre'] . $db_config['table_content_pre'] . '_' . $tableid; if ($PageMode) { $sql_num = "SELECT Count(*) as TotalNum FROM {$table->content_index} i,{$table->content_index} i2 ,{$table_name} c where (UNIX_TIMESTAMP() >= i.PublishDate) AND i.ParentIndexID=i2.IndexID AND i.IndexID =c.IndexID AND i2.State=1 AND i.State!=-1 AND i2.Type!=3 {$list_where} {$list_assign} "; $result = $db->getRow($sql_num); $TotalNum = $result[TotalNum]; $TotalPage = ceil($result[TotalNum] / $offset); $SYS_ENV[tpl_pagelist][run] = "yes"; if (empty($SYS_ENV[tpl_pagelist][page])) { $SYS_ENV[tpl_pagelist][page] = 0; } $start = $SYS_ENV[tpl_pagelist][page] * $offset; $SYS_ENV[tpl_pagelist][page] = $SYS_ENV[tpl_pagelist][page] + 1; if ($start + $offset >= $TotalNum) { $SYS_ENV[tpl_pagelist][run] = "no"; } $list_limit = "Limit {$start},{$offset}"; $list_page = list_page($TotalPage, $SYS_ENV[tpl_pagelist][page], $SYS_ENV[tpl_pagelist][filename]); $cmsware['page'] = array('TotalNum' => $TotalNum, 'TotalPage' => $TotalPage, 'CurrentPage' => $SYS_ENV[tpl_pagelist][page], 'PageList' => $list_page); //print_r($cmsware); } $sql_query = "SELECT i2.NodeID,i2.ContentID,i2.State,i2.URL,i.IndexID,i.PublishDate,i.Type,c.* FROM {$table->content_index} i,{$table->content_index} i2 ,{$table_name} c where (UNIX_TIMESTAMP() >= i.PublishDate) AND i.ParentIndexID=i2.IndexID AND i2.ContentID =c.ContentID AND i2.State=1 AND i.State!=-1 AND i2.Type!=3 {$list_where} {$list_assign} {$list_orderby} {$list_order} {$list_limit}"; //echo $sql;exit; $result = $db->Execute($sql_query); while (!$result->EOF) { $data[] = $result->fields; $result->MoveNext(); } /** 开始进行调用类型判断 */ switch ($type) { case 'node': break; case 'new': break; case 'hot': break; case 'comment': break; } $template = new kTemplate(); $template->caching = false; //$template->register_prefilter("CMS_TPL_Prefilter"); $template->template_dir = $SYS_ENV[templatePath] . '/ssi/'; $template->compile_dir = SYS_PATH . 'sysdata/templates_c/'; $template->assign('List', $data); $template->assign('More', $More); $template->display($tplname); //debug($data); //return $data; }
function testPage() { global $q_page; $add_item = array("a" => 1, "b" => 2); echo list_page($q_page, 33444, 10, array(), $add_item, "#abc"); }