<?php
namespace Passport\Lib;

use Dever;

class Manage
{
	# 同步将其他地方的分类更新为system
    public function updateSystem($id, $name, $param)
    {
    	$name = Dever::param('name', $param);
    	$data['name'] = $name;
        $info = Dever::db('passport/system')->one($id);
        if (!$info) {
        	Dever::db('passport/system')->insert($data);
        } else {
        	$data['where_id'] = $info['id'];
            $data['state'] = Dever::param('state', $param);
            if (!$name) {
                unset($data['name']);
            };
        	Dever::db('passport/system')->update($data);
        }
        return $info;
    }

    public function show($id)
    {
        $db = Dever::db('passport/user');
        $user = $db->one($id);

        $config = $db->config;

        if ($user['avatar']) {
            $table['头像'] = '<img src="'.$user['avatar'].'" width="150" />';
        }

        if ($user['area']) {
            $table['地区'] = $user['area'];
        }

        if ($user['address']) {
            $table['详细地址'] = $user['address'];
        }

        if ($user['source_type']) {
            $table['来源'] = $config['source_type'][$user['source_type']];
        }

        if ($user['profession']) {
            $profession = Dever::db('passport/profession')->one($user['profession']);
            $table['职业'] = $profession['name'];
        }

        if ($user['sex']) {
            $table['性别'] = $config['sex'][$user['sex']];
        }

        if ($user['wechat']) {
            $table['微信号'] = $user['wechat'];
        }

        if ($user['email']) {
            $table['邮箱'] = $user['email'];
        }

        if (Dever::project('invite')) {
            $invite = Dever::db('invite/code')->one(array('uid' => $user['id']));
            if ($invite) {
                $table['邀请码'] = $invite['value'];
            }
        }

        return Dever::table($table);
    }
}
