<?php

/* 
 * 我的钱包
 * author:ZuoLei 
 * date:2016-4-22 13:07:35
 */
if(!defined('IN_DISCUZ')){
    exit('Access Denied');
}
global $_G;

$type = $_GET['type'];
if ($type == 'total') {
    if(!$_G['uid']){
        echo odz_error('not_loggedin');exit;
    }
    $user_credits = array();
    foreach($_G['setting']['extcredits'] as $key => $val){
        $user_credits[] = array(
            'name' => $val['title'],
            'value' => getuserprofile('extcredits'.$key).$val['unit']);
    }
    $get_credits = array('get_credits_name'=>odz_lang('get_credits'),'url'=>'http://' . $_SERVER ["HTTP_HOST"] . dirname ( $_SERVER ["PHP_SELF"] ) . '/index.php?mod=my_wallet&type=detail');
    $total_credits = $_G['member']['credits'];
    $credits_rule = strip_tags(str_replace('*','X',$_G['setting']['creditsformulaexp']));
    odz_result ( array (
        'total_credits' => $total_credits,
        'user_credits' => $user_credits,
        'credits_rule' => $credits_rule,
        'get_credits' => $get_credits
    ) );
} elseif ($type == 'detail') {
    $rulelist = array (
        odz_lang ( 'mobile_credit_rule1' ),
        odz_lang ( 'mobile_credit_rule2' ),
        odz_lang ( 'mobile_credit_rule3' ),
        odz_lang ( 'mobile_credit_rule4' ),
    );
  
    $extcredits = $_G ['setting'] ['extcredits'];

    $rules = C::t ( 'common_credit_rule' )->fetch_all_rule ();
    foreach ( $rules as $k => $v ) {
        foreach ( $rulelist as $key => $rule ) {
            if ($v ['rulename'] == $rule) {
                if($v ['rewardnum'] == 0){
                    $rewardtip = odz_lang('rewardnum');
                }else{
                    $rewardtip = $v['rewardnum'].odz_lang('cycletype_number');
                }
                $v['cycletype_name'] = cycletype($v['cycletype']).",$rewardtip";
                $v['img_src'] = get_pic($v['action']);
                $credit_rule[] = $v;
            }
        }
    }

    //站长后台文章积分分享设置
    $setting = get_mocuz_setting(array('integral_article_share','integral_share_switch'));

    $share = unserialize($setting['integral_article_share']);

    $share_switch = $setting['integral_share_switch'];
    $score = $share['score'];
    $title = $extcredits[$share['type']]['title'];
    $article_share = array(
        'rulename'=> odz_lang('mobile_credit_rule5'),
        'cycletype_name' => odz_lang('credit_type_name'),
        'title' => $title,
        'score' => $score
        );
   // print_r($credit_rule);
    include './template/zhuanjf.php';
}
//奖励周期
function cycletype($num) {
    switch ($num) {
        case 0 :
                $type = odz_lang('cycletype_one');
                break;
        case 1 :
                $type = odz_lang('cycletype_two');
                break;
        case 2 :
                $type = odz_lang('cycletype_three');
                break;
        case 3 :
                $type = odz_lang('cycletype_four');
                break;
        case 4 :
                $type = odz_lang('cycletype_five');
                break;
        default :
                $type = odz_lang('cycletype_error');
    }
    return $type;
}
//赚取积分图片
function get_pic($action){
    switch($action){
        case "daylogin" :
            $src = "credit_everyday.png";
            break;
        case "digest" :
            $src = "credit_essence.png";
            break;
        case "reply" :
            $src = "credit_reply.png";
            break;
        case "post" :
            $src = "credit_subject.png";
            break;
        default :
            $src = '';
    }
    return $src;
}
