您的位置:首页 > 数据库 > Memcache

memcache php 缓存父子节点树 部门组织结构 省市地区下拉列表 常用信息

2012-07-16 18:47 441 查看
//首先从数据库中获取父子节点树

function region_array( $DEPT_PARENT, $DEPARTMENT = array( ), $DEPT_LEVEL = 0 )

{

global $connection;

global $DEPT_LINE;

$DEPT_LINE1 = $DEPT_LINE;

$DEPT_LINE .= "│";

$COUNT = 0;

++$DEPT_LEVEL;

$query = "SELECT region_id,region_name,parent_id from osg_region where parent_id='".$DEPT_PARENT."' order by region_id";

$cursor = exequery( $connection, $query );

while ( $ROW = mysql_fetch_array( $cursor ) )

{

++$COUNT;

$DEPT_ID = $ROW['region_id'];

//$DEPT_NO = $ROW['DEPT_NO'];

$DEPT_NAME = $ROW['region_name'];

$DEPT_PARENT = $ROW['parent_id'];

//$IS_ORG = $ROW['IS_ORG'];

$DEPT_NAME = str_replace( "\"", "\\\"", $DEPT_NAME );

if ( array_key_exists( $DEPT_PARENT, $DEPARTMENT ) )

{

$DEPT_LONG_NAME = $DEPARTMENT[$DEPT_PARENT]['DEPT_LONG_NAME']."/".$DEPT_NAME;

}

else

{

$DEPT_LONG_NAME = $DEPT_NAME;

}

$POSTFIX = _( " " );

if ( $COUNT == mysql_num_rows( $cursor ) )

{

$DEPT_LINE = substr( $DEPT_LINE, 0, 0 - strlen( $POSTFIX ) ).$POSTFIX;

}

if ( $COUNT == mysql_num_rows( $cursor ) )

{

$DEPT_LINE2 = $DEPT_LINE1."└";

}

else

{

$DEPT_LINE2 = $DEPT_LINE1."├";

}

$DEPARTMENT[$DEPT_ID] = array(

"DEPT_NAME" => $DEPT_NAME,

"DEPT_PARENT" => $DEPT_PARENT,

//"DEPT_NO" => $DEPT_NO,

"DEPT_LEVEL" => $DEPT_LEVEL,

"DEPT_LONG_NAME" => $DEPT_LONG_NAME,

//"IS_ORG" => $IS_ORG

);

$DEPARTMENT_STR .= " \"".$DEPT_ID."\" => array(\"DEPT_NAME\" => \"{$DEPT_NAME}\", \"DEPT_PARENT\" => {$DEPT_PARENT}, \"DEPT_NO\" => \"{$DEPT_NO}\", \"DEPT_LEVEL\" => {$DEPT_LEVEL}, \"DEPT_LONG_NAME\" => \"{$DEPT_LONG_NAME}\", \"IS_ORG\" => \"{$IS_ORG}\",
\"DEPT_LINE\" => \"{$DEPT_LINE2}\"),\n";

$DEPARTMENT_STR .= dept_array( $DEPT_ID, $DEPARTMENT, $DEPT_LEVEL );

}

$DEPT_LINE = $DEPT_LINE1;

return $DEPARTMENT_STR;

}

// 设置memcache缓存

function cache_region( )

{

global $td_cache;

global $SYS_REGION;

$DEPARTMENT_STR = "\$SYS_DEPARTMENT=array(\n".substr( region_array( 0 ), 0, -2 )."\n);";

eval( $DEPARTMENT_STR );

include_once( "inc/cache/Cache.php" );

$td_cache->set( "SYS_DEPARTMENT", $SYS_REGION, 0 );

include_once( "inc/utility_cache.php" );

cache_org_xml( );

}

//动态节点树

function my_region_tree( $DEPT_ID, $DEPT_CHOOSE, $POST_OP, $NO_CHILD_DEPT = 0 )

{

global $connection;

global $SYS_REGION;

if ( is_array( $POST_OP ) )

{

$DEPT_PRIV = $POST_OP['DEPT_PRIV'];

$DEPT_ID_STR = $POST_OP['DEPT_ID_STR'];

}

if ( $DEPT_ID == 0 )

{

$LEVEL = 0;

}

$DEPT_PRIV_ID_STR = my_dept_priv_id( $DEPT_PRIV, $DEPT_ID_STR );

reset( &$SYS_DEPARTMENT );

while ( $DEPT = current( &$SYS_DEPARTMENT ) )

{

$ID = key( &$SYS_DEPARTMENT );

if ( $ID == $DEPT_ID )

{

$LEVEL = $DEPT['DEPT_LEVEL'];

}

if ( !isset( $LEVEL ) || $ID != $DEPT_ID )

{

next( &$SYS_DEPARTMENT );

}

else

{

if ( $NO_CHILD_DEPT && $NO_CHILD_DEPT == $ID )

{

do

{

} while ( $DEPT_NEXT = next( &$SYS_DEPARTMENT ) && !( $DEPT_NEXT['DEPT_LEVEL'] <= $SYS_DEPARTMENT[$NO_CHILD_DEPT]['DEPT_LEVEL'] ) );

prev( &$SYS_DEPARTMENT );

}

if ( $DEPT['DEPT_LEVEL'] <= $LEVEL && $ID != $DEPT_ID )

{

break;

}

$DEPT_NAME = $DEPT['DEPT_NAME'];

$DEPT_NAME = htmlspecialchars( $DEPT_NAME );

if ( !$POST_OP && find_id( $DEPT_PRIV_ID_STR, $ID ) )

{

$OPTION_TEXT .= "<option ";

if ( $ID == $DEPT_CHOOSE )

{

$OPTION_TEXT .= "selected ";

}

$OPTION_TEXT .= "value=".$ID.">".$DEPT['DEPT_LINE'].$DEPT_NAME."</option>\n";

}

next( &$SYS_DEPARTMENT );

}

}

reset( &$SYS_DEPARTMENT );

return $OPTION_TEXT;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: