⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 category.inc.php

📁 采用模块化开发
💻 PHP
字号:
<?php
defined('IN_PHPCMS') or exit('Access Denied');
require_once PHPCMS_ROOT.'/include/tree.class.php';
require_once PHPCMS_ROOT.'/admin/include/category_module.class.php';
$module = $mod;
$tree = new tree;
require_once PHPCMS_ROOT.'/include/module.func.php';
require_once PHPCMS_ROOT.'/'.$mod.'/include/formselect.func.php';
require MOD_ROOT.'/include/urlrule.inc.php';
$catid = isset($catid) ? intval($catid) : 0;
$cat = new category_module($mod, $catid);
$submenu = array
(
	array($LANG['manage_index'], '?mod='.$mod.'&file='.$file.'&action=manage'),
	array($LANG['add_category'], '?mod='.$mod.'&file='.$file.'&action=add'),
	array($LANG['join_category'], '?mod='.$mod.'&file='.$file.'&action=join'),
	array($LANG['update_category_cache'], '?mod='.$mod.'&file='.$file.'&action=updatecache'),
	array($LANG['category_data_repair'], '?mod='.$mod.'&file='.$file.'&action=repair'),
);
$menu = adminmenu($LANG['category_manage'],$submenu);
$action = $action ? $action : 'manage';
switch($action)
{
	case 'add':
		if($dosubmit)
		{
		    if(!$category['catname']) showmessage($LANG['category_name_not_null']);
			if($category['islink']==1 && !$category['catdir']) showmessage($LANG['category_dir_not_null']);
			if($category['catdir']=='web') showmessage($LANG['choose_othor_dir']);
			if($category['islink']==0 && !$category['linkurl']) showmessage($LANG['external_category_linkurl_not_null']);
			
			$category['urlruleid'] = $category['ishtml'] ? $category['cat_html_urlruleid'] : $category['cat_php_urlruleid'];
			
            unset($category['cat_html_urlruleid'],$category['cat_php_urlruleid']);
			$setting['arrgroupid_browse'] = isset($arrgroupid_browse) && is_array($arrgroupid_browse) ? implode(',',$arrgroupid_browse) : "";
            $setting['arrgroupid_view'] = isset($arrgroupid_view) && is_array($arrgroupid_view) ? implode(',',$arrgroupid_view) : "";
            $setting['arrgroupid_add'] = isset($arrgroupid_add) && is_array($arrgroupid_add) ? implode(',',$arrgroupid_add) : "";
			if(!$category['islink'])
			{
				$r = $db->get_one("select catid from ".TABLE_CATEGORY." where catdir='$category[catdir]' and module='$module' ");
				if($r) showmessage($LANG['category_dir_same_in_one_channel']);
            }
            $cat->add($category, $setting);
	        showmessage($LANG['operation_success'], '?mod='.$mod.'&file='.$file.'&action=updatecache&forward='.urlencode($forward));
		}
		else
	    {
			$arrgroupid_browse = showgroup("checkbox","arrgroupid_browse[]");
			$arrgroupid_view = showgroup("checkbox","arrgroupid_view[]");
			$arrgroupid_add = showgroup("checkbox","arrgroupid_add[]");
			$parentid = category_select('category[parentid]',$LANG['no_as_top_category'],$catid);
            $templateid = showtpl($module,'category','setting[templateid]');
            $listtemplateid = showtpl($module,'category_list','setting[listtemplateid]');
		    $skinid = showskin('setting[skinid]','yp');
            $defaultitemtemplate = showtpl($module,'content','setting[defaultitemtemplate]');
		    $defaultitemskin = showskin('setting[defaultitemskin]','yp');
			$page_select = page_select(0,"onchange='document.myform.linkurl.value=this.value'");
			$cat_html_urlrule = yp_urlrule_select('category[cat_html_urlruleid]','html','cat');
			$cat_php_urlrule = yp_urlrule_select('category[cat_php_urlruleid]','php','cat');
		    include admintpl('category_add');
		}
		break;

	case 'edit':
		$catid = intval($catid);
		if(!$catid) showmessage($LANG['illegal_parameters']);
		$setting['arrgroupid_browse'] = isset($arrgroupid_browse) && is_array($arrgroupid_browse) ? implode(',',$arrgroupid_browse) : "";
		$setting['arrgroupid_view'] = isset($arrgroupid_view) && is_array($arrgroupid_view) ? implode(',',$arrgroupid_view) : "";
		$setting['arrgroupid_add'] = isset($arrgroupid_add) && is_array($arrgroupid_add) ? implode(',',$arrgroupid_add) : "";
		if($dosubmit)
		{
		    if(!$category['catname']) showmessage($LANG['category_name_not_null']);
            $category['urlruleid'] = $category['ishtml'] ? $category['cat_html_urlruleid'] : $category['cat_php_urlruleid'];
            unset($category['cat_html_urlruleid'],$category['cat_php_urlruleid']);
            
            $cat->edit($category, $setting);

			if($createtype_application)
			{
				$ishtml = $category['ishtml'];
				$htmldir = $category['htmldir'];
				$prefix = $category['prefix'];
				$urlruleid = $category['urlruleid'];
				$item_htmldir = $category['item_htmldir'];
				$item_prefix = $category['item_prefix']; 
                $item_html_urlruleid = $category['item_html_urlruleid'];
                $item_php_urlruleid = $category['item_php_urlruleid'];
				$item_urlruleid = $ishtml ? $category['item_html_urlruleid'] : $category['item_php_urlruleid'];
				$arrchildid = $CATEGORY[$catid]['arrchildid'];
				$db->query("UPDATE ".TABLE_CATEGORY." SET ishtml=$ishtml,urlruleid=$urlruleid,htmldir='$htmldir',prefix='$prefix',item_htmldir='$item_htmldir',item_prefix='$item_prefix',item_html_urlruleid=$item_html_urlruleid,item_php_urlruleid=$item_php_urlruleid WHERE catid IN($arrchildid)");
				$forward = '?mod=phpcms&file=linkurl&action=updatecategory&updatecategory=1&module='.$mod.'&catid='.$catid;
            }

			showmessage($LANG['operation_success'], '?mod='.$mod.'&file='.$file.'&action=updatecache&forward='.urlencode($forward));
		}
		else
	    {
			$category = $cat->get_info();
            @extract(new_htmlspecialchars($category));           
			$arrgroupid_browse = showgroup("checkbox","arrgroupid_browse[]",$arrgroupid_browse);
			$arrgroupid_view = showgroup("checkbox","arrgroupid_view[]",$arrgroupid_view);
			$arrgroupid_add = showgroup("checkbox","arrgroupid_add[]",$arrgroupid_add);
			$oldparentid = $parentid;
			$parentid = category_select('category[parentid]',$LANG['no_as_top_category'],$parentid);
		    $skinid = showskin('setting[skinid]',$skinid);
            $templateid = showtpl($module,'category','setting[templateid]',$templateid);
            $listtemplateid = showtpl($module,'category_list','setting[listtemplateid]',$listtemplateid);
            $defaultitemtemplate = showtpl($module,'content','setting[defaultitemtemplate]',$defaultitemtemplate);
		    $defaultitemskin = showskin('setting[defaultitemskin]',$defaultitemskin);
		    $cat_html_urlruleid = $ishtml ? $urlruleid : $MOD['cat_html_urlruleid'];
		    $cat_php_urlruleid = $ishtml ? $MOD['cat_php_urlruleid'] : $urlruleid;		    
		    $cat_html_urlrule = yp_urlrule_select('category[cat_html_urlruleid]','html','cat',$cat_html_urlruleid);
			$item_html_urlrule = yp_urlrule_select('category[item_html_urlruleid]','html','item',$item_html_urlruleid);
			$cat_php_urlrule = yp_urlrule_select('category[cat_php_urlruleid]','php','cat',$cat_php_urlruleid);
			$item_php_urlrule = yp_urlrule_select('category[item_php_urlruleid]','php','item',$item_php_urlruleid);
		    include admintpl('category_edit');
		}
		break;

     case 'recycle':
		 $forward = '?mod=yp&file=category&action=manage';
		 $module = $mod;
		 $catid = intval($catid);
		 $r=$db->get_one("SELECT arrchildid FROM ".TABLE_CATEGORY." WHERE catid=$catid");
		 $arrchildid = $r['arrchildid'];
		 $db->query("UPDATE ".TABLE_YP_PRODUCT." SET status=-1 WHERE catid IN ($arrchildid)");
		 showmessage($LANG['operation_success'], $forward);
		 break;

     case 'repair':

        $cat->repair();

        showmessage($LANG['operation_success'], $forward);
		break;

     case 'delete':
		 $forward = '?mod=yp&file=category&action=manage';
		 $module = $mod;
		 $catid = intval($catid);
		 $r = $db->get_one("SELECT * FROM ".TABLE_CATEGORY." WHERE catid=$catid");
		 if(!$r) showmessage($LANG['illegal_parameters'], $forward);

         $cat->delete();
		 showmessage($LANG['operation_success'], $forward);
		 break;

	case 'join':

	    if($dosubmit)
		{
		   $targetcatid = intval($targetcatid);
		   $sourcecatid = intval($sourcecatid);
           if(!$targetcatid || !$sourcecatid) showmessage($LANG['parameters_error'], $forward);
		   if($targetcatid == $sourcecatid) showmessage($LANG['source_not_same_as_distinct_category'],$forward);

           $target = $cat->get_info($targetcatid);
           if($target['child']==1 && $target['enableadd']==0) showmessage($LANG['distinct_category_has_child_banned_add_information']);

           if($target['arrparentid'])
		   {
              $arrparentid = explode(",", $r['arrparentid']);
              if(in_array($sourcecatid,$arrparentid)) showmessage($LANG['distinct_is_the_child_of_source_category_cannot_join']);
           }

           $source = $cat->get_info($sourcecatid);
		  
           $cat->join($sourcecatid, $targetcatid);
		   showmessage($LANG['operation_success'], $forward);
		}
		else
		{
			$category_source = category_select('sourcecatid', $LANG['please_select'], $catid);
			$category_target = category_select('targetcatid', $LANG['please_select'], $catid);

			include admintpl('category_join');
		}
		break;

    case 'listorder':
		$cat->listorder($listorder);
		showmessage($LANG['operation_success'], $forward);
        break;

	case 'updatecache':
		
		$catids = cache_categorys($mod);
	    foreach($catids as $catid)
	    {
			$cat->update_linkurl($catid);
		    cache_category($catid);
	    }
		showmessage($LANG['category_cache_update_success'], $forward,40000);
		break;

	case 'manage':
		$list = $cat->get_list();

		if(is_array($list))
	    {
			$categorys = array();
			foreach($list as $catid => $category)
			{
				$module = $mod;
				$islink = $category['islink'] ? '<font color="blue">'.$LANG['external_category'].'</font>' : $LANG['internal_category'];
				$linkurl = linkurl($category['linkurl']);
				$catdir = $category['islink'] ? "<a href='$linkurl' title='".$LANG['click_view']."' target='_blank'>".str_cut($linkurl,20)."</a>" : "<a href='$linkurl' title='".$LANG['click_view']."' target='_blank'>".$category['catdir']."</a>";
				$categorys[$category['catid']] = array('id'=>$category['catid'],'parentid'=>$category['parentid'],'name'=>$category['catname'],'islink'=>$islink,'catdir'=>$catdir,'listorder'=>$category['listorder'],'style'=>$category['style'],'mod'=>$mod,'file'=>$file,'addhref'=>'');
			}
			$str = "<tr align='center' align='center' onmouseout=this.style.backgroundColor='#F1F3F5' onmouseover=this.style.backgroundColor='#BFDFFF' bgColor='#F1F3F5'>
						<td><input name='listorder[\$id]' type='text' size='3' value='\$listorder'></td>
						<td>\$id</td>
						<td align='left'>\$spacer<a href='?mod=\$mod&file=\$file&action=edit&catid=\$id&parentid=\$parentid'><span style='\$style'>\$name</span></a></td>
						<td>\$islink</td>
						<td>\$catdir</td>
						<td></td>
						<td><a href='?mod=\$mod&file=\$file&action=add&catid=\$id'>".$LANG['add_child_category']."</a> | <a href='?mod=\$mod&file=\$file&action=edit&catid=\$id&parentid=\$parentid'>".$LANG['edit']."</a> | <a href=javascript:confirmurl('?mod=\$mod&file=\$file&action=recycle&catid=\$id','".$LANG['confirm_clear_category_info']."') >".$LANG['clear']."</a> | <a href=javascript:confirmurl('?mod=\$mod&file=\$file&action=delete&catid=\$id','".$LANG['confirm_delete_category']."')>".$LANG['delete']."</a></td></tr>";
			$tree->tree($categorys);
			$categorys = $tree->get_tree(0,$str);
		}
		include admintpl('category');
		break;
}
?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -