[기능] 포인트 선물하기 > 정보공유

본문 바로가기

정보공유

일반글
그누보드팁

[기능] 포인트 선물하기

페이지 정보

게시물QR코드

본문

그누보드의 기본기능중 "사이드뷰" 기능이 있습니다.

"사이드뷰" 기능은 아래의 그림과 같이 회원아이디를 클릭 하였을때에 펼쳐지는 메뉴입니다.

5dd43898d2d32c40212f0ca11a49192f_1496136086_7367.png 

메뉴중에는 기본적으로 쪽지보내기, 메일보내기, 자기소개보기, 해당아아디 게시물 검색 등 여러가지 기능이 있습니다.

하지만 기본 제공하는 기능에서는 포인트선물 기능은 없는데

커뮤니티의 웹사이트에서 자주 사용되는 포인트 선물 기능을 추가 해보도록 하겠습니다.

 

우선 www/lib/common.lib.php 파일 get_sideview()함수의 쪽지보내기 아래쪽에

포인트선물 소스코드를 추가 하겠습니다.

<?php

/* www/lib/common.lib.php */

 

if($mb_id)

$str2 .= "<a href=\"".G5_BBS_URL."/memo_form.php?me_recv_mb_id=".$mb_id."\" onclick=\"win_big_memo(this.href); return false;\">쪽지보내기</a>\n";

if($mb_id)

$str2 .= "<a href=\"".G5_BBS_URL."/point_gift.php?mb_id=".$mb_id."\" onclick=\"win_point(this.href); return false;\">포인트선물</a>\n";

?>

기존에 get_sideview()함수에 있는 쪽지보내기 아래쪽에 포인트선물 소스코드를 추가하시면

아래와 같이 "사이드뷰" 기능에 "포인트선물" 이라는 메뉴가 추가 되었을겁니다.

5dd43898d2d32c40212f0ca11a49192f_1496136099_7098.png  

 

그리고 www/extend/user.config.php 파일에 새로 생성한 함수를 추가 하겠습니다.

<?php

/* www/lib/common.lib.php */

 

// SNS식 날짜표기 추가 (gnuwiz)

function sns_date($d) { 

$_timestamp = array(86400*365, 86400*31, 86400, 3600, 60, 1); 

$_timetitle = array("년전", "개월전", "일전", "시간전", "분전", "초전"); 

$d = strtotime($d); 

 

foreach($_timestamp as $key => $value) 

if($d <= time() - $value) return (int)((time() - $d)/$_timestamp[$key]).$_timetitle[$key]; 

}

?>

 

www/bbs/경로에 point_gift.php 파일을 하나 생성해주고

아래와 같이 해당 파일 소스코드 내용을 작성합니다.

<?php

/* www/bbs/point_gift.php */

 

include_once('./_common.php');

 

if (!$member['mb_id'])

    alert_close('회원만 이용하실 수 있습니다.');


if (!$member['mb_open'] && $is_admin != 'super' && $member['mb_id'] != $mb_id)

    alert_close('자신의 정보를 공개하지 않으면 다른분의 정보를 조회할 수 없습니다.\\n\\n정보공개 설정은 회원정보수정에서 하실 수 있습니다.');


$mb = get_member($mb_id);


if ($mb['mb_id'] == $member['mb_id'])

    alert_close('본인에게 포인트 선물하실 수 없습니다.');


if (!$mb['mb_open'] && $is_admin != 'super' && $member['mb_id'] != $mb_id)

    alert_close('정보공개를 하지 않았습니다.');


if($mb['mb_id']){

$g5['title'] = $mb['mb_nick'].'님에게 포인트 선물';

}else{

$g5['title'] = '포인트 선물';

}


include_once(G5_PATH.'/head.sub.php');


if($mb['mb_id']){

$sql_common = " from {$g5['point_table']} where mb_id = '".$member['mb_id']."' and po_rel_id = '".$mb['mb_id']."' and po_rel_table = '@GIFT' ";

}else{

$sql_common = " from {$g5['point_table']} where mb_id = '".$member['mb_id']."' and po_rel_table = '@GIFT' ";

}

$sql_order = " order by po_id desc ";


$sql = " select count(*) as cnt {$sql_common} ";

$row = sql_fetch($sql);

$total_count = $row['cnt'];


$page_rows = 5;

if ($page < 1) { $page = 1; } // 페이지가 없으면 첫 페이지 (1 페이지)

$total_page  = ceil($total_count / $page_rows);  // 전체 페이지 계산

$from_record = ($page - 1) * $page_rows; // 시작 열을 구함




$min_point = 100; // 최소 포인트 이상 입력해야 선물 가능

$point_mon = 0; //선물 수수료 설정


$action_url = https_url(G5_INTERFACE_DIR)."/point_gift_update.php";


include_once($member_skin_path.'/point_gift.skin.php');

include_once(G5_PATH.'/tail.sub.php');

?>

 

추가적으로 같은 경로에 php파일을 하나더 생성 하겠습니다.

위와 같이 www/bbs/경로에 point_gift_update.php 파일을 하나 생성해주고

아래와 같이 해당 파일 소스코드 내용을 작성합니다.

<?php

/* www/bbs/point_gift_update.php */

 

include_once('./_common.php');

 

$mb_id = trim($_POST["mb_id"]);


$mb = get_member($mb_id);

$me_send_point = trim($_POST["me_send_point"]);


if (!$mb['mb_id'])

    alert_close('가입된 회원아이디가 아닙니다.');


  $tmp_row = sql_fetch(" select max(me_id) as max_me_id from {$g5['memo_table']} ");

  $me_id = $tmp_row['max_me_id'] + 1;


  // 쪽지 INSERT

    $content = "쪽지 메세지\r\n\r\n".$_POST['me_memo']."\r\n\r\n".$mb['mb_nick']."님께 포인트 ".$me_send_point."점 를 보내드렸습니다. 자세한 사항은 포인트 내역을 참조하세요."; 

    

  $me_sql = " insert into {$g5['memo_table']} ( me_id, me_recv_mb_id, me_send_mb_id, me_send_datetime, me_memo ) values ( '$me_id', '{$mb[mb_id]}', '{$member['mb_id']}', '".G5_TIME_YMDHIS."', '".$content."' ) ";

  sql_query($me_sql);


  // 실시간 쪽지 알림 기능

  $sql = " update {$g5['member_table']} set mb_memo_call = '{$member['mb_id']}' where mb_id = '$recv_mb_id' ";

  sql_query($sql);


  //포인트 선물보냄

  insert_point($mb['mb_id'], $me_send_point, $mb['mb_nick'].'님께 포인트 '.$me_send_point.'점 받음', '@gift_passive', $member['mb_id'], G5_TIME_YMD);

  insert_point($member['mb_id'], - $me_send_point, $mb['mb_nick'].'님께 포인트 -'.$me_send_point.'점 보냄', '@gift', $mb['mb_id'], G5_TIME_YMD);

    

alert("$mb_id 님에게 포인트 선물 완료.");

?>

 

point_gift.skin.php , point_gift_update.php 파일을 생성 하셨다면

마지막으로 포인트선물을 클릭 하였을때 팝업창이 나타나도록

회원가입 스킨경로/point_gift.skin.php 파일을 생성 합니다.

<?php

/* 회원가입 스킨경로/point_gift.skin.php */

 

if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가


// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨

add_stylesheet('<link rel="stylesheet" href="'.$member_skin_url.'/style.css">', 0);

?>


<div id="point" class="new_win">

    <h1 id="win_title"><?php echo $g5['title'] ?></h1>

</div>

<div class="tbl_frm01 tbl_wrap">

    <form action="<?php echo $action_url ?>" name=fmemoform method=post onsubmit="return fmemoform_submit(this);" autocomplete="off">


    <table>

    <tbody>

    <tr>

        <th scope="row"><label for="me_send_point">보낼 아이디<strong class="sound_only">필수</strong></label></th>

        <td>

            <input type="text" name="mb_id" id="mb_id" value="<?php echo $mb_id ?>" required class="frm_input required" size="20" maxlength="255">

        </td>

    </tr>

    <tr>

        <th scope="row"><label for="me_send_point">보낼 포인트<strong class="sound_only">필수</strong></label></th>

        <td>

            <input type="text" name="me_send_point" id="me_send_point" required class="frm_input required" size="20" maxlength="255">

            <span class="frm_info">현재 포인트 <?php echo number_format($member['mb_point']) ?>점

        </td>

    </tr>

    <tr>

        <th scope="row"><label for="me_memo">쪽지 내용<strong class="sound_only">필수</strong></label></th>

        <td>

            <textarea id="me_memo" name="me_memo" maxlength="10000" required class="required" title="쪽지"></textarea>

        </td>

    </tr>

    </tbody>

    </table>


    <div class="btn_confirm" style="margin:10px 0 10px 0;">

        <input type="submit" value="포인트 보내기" id="btn_submit" accesskey="s" class="btn_submit">

    </div>

    </form>

</div>

<script language="JavaScript">

function fmemoform_submit(f)

{

  if (f.me_send_point.value.length > 0) { 

    for (i = 0; i < f.me_send_point.value.length; i++) { 

      if (f.me_send_point.value.charAt(i) < '0' || f.me_send_point.value.charAt(i) > '9') { 

        alert(f.me_send_point.value.charAt(i) + "는 숫자가 아닙니다. 숫자만 입력하세요!"); 

        f.me_send_point.value = ""; 

        f.me_send_point.focus(); 

      return false;

      } 

    } 

  } 

  if (f.me_send_point.value < 100 || f.me_send_point.value > <?php echo $member[mb_point] ?>) { 

    alert("포인트 100점 보다 크고 <?php echo number_format($member[mb_point]) ?>점 보다 작아야 합니다."); 

    f.me_send_point.value = ""; 

    f.me_send_point.focus(); 

    return false;

  } 


  document.getElementById("btn_submit").disabled = "disabled";


  return true;

}

</script>


<div id="point" class="new_win">

    <h1 id="win_title"><?php echo $g5['title'] ?></h1>


    <div class="tbl_head01 tbl_wrap">

        <table>

        <caption>포인트 사용내역 목록</caption>

        <thead>

        <tr>

            <th scope="col">일시</th>

            <th scope="col">내용</th>

            <th scope="col">만료일</th>

            <th scope="col">지급포인트</th>

            <th scope="col">사용포인트</th>

        </tr>

        </thead>

        <tbody>

        <?php

        $sum_point1 = $sum_point2 = $sum_point3 = 0;


        $sql = " select *

                    {$sql_common}

                    {$sql_order}

                    limit {$from_record}, {$page_rows} ";

        $result = sql_query($sql);

        for ($i=0; $row=sql_fetch_array($result); $i++) {

            $point1 = $point2 = 0;

            if ($row['po_point'] > 0) {

                $point1 = '+' .number_format($row['po_point']);

                $sum_point1 += $row['po_point'];

            } else {

                $point2 = number_format($row['po_point']);

                $sum_point2 += $row['po_point'];

            }


            $po_content = $row['po_content'];


            $expr = '';

            if($row['po_expired'] == 1)

                $expr = ' txt_expired';

        ?>

        <tr>

            <td class="td_datetime"><?php echo $row['po_datetime']; ?></td>

            <td><?php echo $po_content; ?></td>

            <td class="td_date<?php echo $expr; ?>">

                <?php if ($row['po_expired'] == 1) { ?>

                만료<?php echo substr(str_replace('-', '', $row['po_expire_date']), 2); ?>

                <?php } else echo $row['po_expire_date'] == '9999-12-31' ? '&nbsp;' : $row['po_expire_date']; ?>

            </td>

            <td class="td_numbig"><?php echo $point1; ?></td>

            <td class="td_numbig"><?php echo $point2; ?></td>

        </tr>

        <?php

        }


        if ($i == 0)

            echo '<tr><td colspan="5" class="empty_table">자료가 없습니다.</td></tr>';

        else {

            if ($sum_point1 > 0)

                $sum_point1 = "+" . number_format($sum_point1);

            $sum_point2 = number_format($sum_point2);

        }

        ?>

        </tbody>

        <tfoot>

        <tr>

            <th scope="row" colspan="3">소계</th>

            <td><?php echo $sum_point1; ?></td>

            <td><?php echo $sum_point2; ?></td>

        </tr>

        <tr>

            <th scope="row" colspan="3">보유포인트</th>

            <td colspan="2"><?php echo number_format($member['mb_point']); ?></td>

        </tr>

        </tfoot>

        </table>

    </div>


    <?php echo get_paging(G5_IS_MOBILE ? $config['cf_mobile_pages'] : $config['cf_write_pages'], $page, $total_page, $_SERVER['SCRIPT_NAME'].'?'.$qstr.'&amp;page='); ?>


    <div class="win_btn"><button type="button" onclick="javascript:window.close();">창닫기</button></div>

</div>

 

이렇게 총 3개의 php파일을 생성했다면 아래와 같이 포인트선물 기능이 정상적으로 동작 하겠습니다.

5dd43898d2d32c40212f0ca11a49192f_1496136114_5246.png
 

댓글목록

등록된 댓글이 없습니다.

  • Addr.부산광역시 동구 중앙대로 319, 9층 L4호(초량동, 부산YMCA빌딩) Email. gnuwiz@naver.com
  • BR. 625-68-00172 TRC. 2019-부산해운대-1186 TEL. 0507-1382-2790
All rights reserved.