<?php

namespace auth;

class oauthapps
{
    /**
     * 获取某个一行用的全部信息（给授权页用的）
     * @param $client_id
     * @return false|mixed
     */
    public function info($client_id){
        global $authsql;
        return $authsql->get('oauth_clients',"*",[
            "client_id"=>$client_id
        ]);
    }

    /**
     * 应用列表
     * @return string
     */
    public function lists(){
        global $authsql;
        $info=$authsql->select('oauth_clients',"*");
        $infonum=count($info);
        $appinfo='';
        for ($i=0;$i<$infonum;$i++){
            $appinfo=$appinfo.'<tr><td>
                <input type="checkbox" /></td>
                <td>'.$info[$i]['id'].'</td>
                <td>'.$info[$i]['name'].'</td>
                <td>'.$info[$i]['client_id'].'</td>
                <td>'.$info[$i]['client_secret'].'</td>
                <td>'.$info[$i]['redirect_uri'].'</td>
                <td>
                <div class="am-btn-toolbar">
                <div class="am-btn-group am-btn-group-xs">
                <a href="/oauth2/auth.php?response_type=code&client_id='.$info[$i]['client_id'].'&redirect_uri='.urlencode('http://'.$info[$i]['redirect_uri'].'/index.php?type=submit').'&scope=base&state=123" target="_blank" class="am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> 前往授权页</a>
                <a href="./appedit.html?client_id='.$info[$i]['client_id'].'" class="am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> 编辑</a>
                <a href="./appsubmit.html?m=del&id='.$info[$i]['id'].'" class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"><span class="am-icon-pencil-square-o"></span> 删除</a>';
            $appinfo=$appinfo.'</div></div></td></tr>';
        }
        return $appinfo;
    }
}