<?
/**
 * Bechu-Basic Skin for Gnuboard4
 *
 * Copyright (c) 2008 Choi Jae-Young <www.miwit.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

if (!defined("_GNUBOARD_")) exit; // °³º° ÆäÀÌÁö Á¢±Ù ºÒ°¡

$wr_39 = "$Filter_00|$Filter_01|$Filter_02|$Filter_03|$Filter_04|$Filter_05|$Filter_06|$Filter_07|$Filter_08|$Filter_09|$Filter_10|$Filter_11|$Filter_12|$Filter_13|$Filter_14|$Filter_15|$Filter_16|$Filter_17|$Filter_18|$Filter_19|$Filter_20|$Filter_21|$Filter_22|$Filter_23|$Filter_24|$Filter_25|$Filter_26|$Filter_27|$Filter_28|$Filter_29|$Filter_30|$Filter_31|$Filter_32|$Filter_33|$Filter_34|$Filter_35|$Filter_36|$Filter_37|"; 
$sql39 = " update $write_table set wr_39 = '$wr_39' where wr_id = '$wr_id' ";
sql_query($sql39);

$wr_40 = "$pro_name_00|$pro_name_01|$pro_name_02|$pro_name_03|$pro_name_04|$pro_name_05|$pro_name_06|$pro_name_07|$pro_name_08|$pro_name_09|$pro_name_10|$pro_name_11|$pro_name_12|$pro_name_13|$pro_name_14|$pro_name_15|$pro_name_16|$pro_name_17|$pro_name_18|$pro_name_19|$pro_name_20|$pro_name_21|$pro_name_22|$pro_name_23|$pro_name_24|$pro_name_25|$pro_name_26|$pro_name_27|$pro_name_28|$pro_name_29|$pro_name_30|$pro_name_31|$pro_name_32|$pro_name_33|$pro_name_34|$pro_name_35|$pro_name_36|$pro_name_37|$pro_name_38|$pro_name_39|$pro_name_40|$pro_name_41|$pro_name_42|$pro_name_43|$pro_name_44|$pro_name_45|$pro_name_46|$pro_name_47|$pro_name_48|$pro_name_49|$pro_name_50|"; 
$sql40 = " update $write_table set wr_40 = '$wr_40' where wr_id = '$wr_id' ";
sql_query($sql40);

@set_time_limit (0); 
@ini_set ("memory_limit", "20M"); 


// CCL Á¤º¸ ¾÷µ¥ÀÌÆ®
$wr_ccl = "";
if ($wr_ccl_by == "by") { $wr_ccl .= "by"; }
if ($wr_ccl_nc == "nc") { $wr_ccl .= $wr_ccl ? "-": ""; $wr_ccl .= "nc"; }
if ($wr_ccl_nd == "nd") { $wr_ccl .= $wr_ccl ? "-": ""; $wr_ccl .= "nd"; }
if ($wr_ccl_nd == "sa") { $wr_ccl .= $wr_ccl ? "-": ""; $wr_ccl .= "sa"; }
sql_query("update $write_table set wr_ccl = '$wr_ccl' where wr_id = '$wr_id'");

// Â©¹æ ¾÷µ¥ÀÌÆ®
if ($mw_basic[cf_zzal]) {
    sql_query("update $write_table set wr_zzal = '$wr_zzal' where wr_id = '$wr_id'");
}

// °ü·Ã±Û ¾÷µ¥ÀÌÆ®
if ($mw_basic[cf_related]) {
    sql_query("update $write_table set wr_related = '$wr_related' where wr_id = '$wr_id'");
}

// ÄÚ¸àÆ® Çã¶ô
if ($mw_basic[cf_comment_ban] && $mw_basic[cf_comment_ban_level] <= $member[mb_level]) {
    sql_query("update $write_table set wr_comment_ban = '$wr_comment_ban' where wr_id = '$wr_id'");
}

// ·Î±×³²±è
if ($w == "u" && $mw_basic[cf_post_history]) {
    $wr_name2 = $board[bo_use_name] ? $member[mb_name] : $member[mb_nick];
    $sql = "insert into $mw[post_history_table]
               set bo_table = '$bo_table'
                   ,wr_id = '$wr_id'
                   ,wr_parent = '$write[wr_parent]'
                   ,mb_id = '$member[mb_id]'
                   ,ph_name = '$wr_name2'
                   ,ph_option = '$write[wr_option]'
                   ,ph_subject = '".addslashes($write[wr_subject])."'
                   ,ph_content = '".addslashes($write[wr_content])."'
                   ,ph_ip = '$_SERVER[REMOTE_ADDR]'
                   ,ph_datetime = '$g4[time_ymdhis]'";
    sql_query($sql);
}

// Áö¾÷·Î´õ
if ($mw_basic[cf_guploader] == "1" && $is_member) // ½Ì±Û¸ðµå
{
    $sql = "select * from $mw[guploader_table] where bo_table = '$bo_table' and mb_id = '$member[mb_id]' and bf_ip = '$_SERVER[REMOTE_ADDR]' order by bf_no";
    $qry = sql_query($sql, false);
    for ($i=0; $row=sql_fetch_array($qry); $i++) {
        $source = "$g4[path]/data/guploader/$row[bf_file]";
        $dest = "$g4[path]/data/file/$bo_table/$row[bf_file]";
        @copy($source, $dest);
        @unlink($source);
        sql_query("insert into $g4[board_file_table]
                   set bo_table = '$bo_table'
                     , wr_id = '$wr_id'
                     , bf_no = '$i'
                     , bf_source = '$row[bf_source]'
                     , bf_file = '$row[bf_file]'
                     , bf_filesize = '$row[bf_filesize]'
                     , bf_width = '$row[bf_width]'
                     , bf_height = '$row[bf_height]'
                     , bf_type = '$row[bf_type]'
                     , bf_datetime = '$row[bf_datetime]'");
    }
    sql_query("delete from $mw[guploader_table] where bo_table = '$bo_table' and mb_id = '$member[mb_id]' and bf_ip = '$_SERVER[REMOTE_ADDR]'", false);
}

// ¿øº» °­Á¦ ¸®»çÀÌÂ¡
if ($mw_basic[cf_original_width] && $mw_basic[cf_original_height]) {
    $sql = "select * from $g4[board_file_table] where bo_table = '$bo_table' and wr_id = '$wr_id' and bf_width > 0  order by bf_no";
    $qry = sql_query($sql);
    while ($row = sql_fetch_array($qry)) {
        $file = "$file_path/$row[bf_file]";
        mw_make_thumbnail($mw_basic[cf_original_width], $mw_basic[cf_original_height], $file, $file, true);
        $size = getImageSize($file);
        sql_query("update $g4[board_file_table] set bf_width = '$size[0]', bf_height = '$size[1]'
            where bo_table = '$bo_table' and wr_id = '$wr_id' and bf_no = '$row[bf_no]'");
    }
}

// ¼¶³×ÀÏ »ý¼º, ¹«Á¶°Ç »ý¼ºÀ¸·Î º¯°æ (1.0.6)
//if ($mw_basic[cf_type] != "list") {

// Ã¹¹øÂ° Ã·ºÎÀÌ¹ÌÁö º»¹® Ãâ·Â ¾ÈÇÒ½Ã (1.1.2);
// »èÁ¦ (1.2.5);
/*if ($mw_basic[cf_img_1_noview]) {
    $file = mw_get_first_file($bo_table, $wr_id, true);
    if (!empty($file)) {
        $source_file = "$file_path/{$file[bf_file]}";
        $dest_file = "$thumb_path/{$wr_id}"; 
        @copy($source_file, $dest_file);
    }
}
else
{*/
    $thumb_file = "";
    $file = mw_get_first_file($bo_table, $wr_id, true);
    if (!empty($file)) {
        $source_file = "$file_path/{$file[bf_file]}";
        $thumb_file = "$thumb_path/{$wr_id}";
        mw_make_thumbnail($mw_basic[cf_thumb_width], $mw_basic[cf_thumb_height], $source_file, $thumb_file, $mw_basic[cf_thumb_keep]);
        if ($mw_basic[cf_thumb2_width])
            @mw_make_thumbnail($mw_basic[cf_thumb2_width], $mw_basic[cf_thumb2_height], $source_file, "{$thumb2_path}/{$wr_id}", $mw_basic[cf_thumb2_keep]);
        if ($mw_basic[cf_thumb3_width])
            @mw_make_thumbnail($mw_basic[cf_thumb3_width], $mw_basic[cf_thumb3_height], $source_file, "{$thumb3_path}/{$wr_id}", $mw_basic[cf_thumb3_keep]);
    } else {
        $thumb_file = "$thumb_path/{$wr_id}";
        preg_match("/<img.*src=\\\"(.*)\\\"/iUs", stripslashes($wr_content), $match);
        if ($match[1]) {
            $match[1] = str_replace($g4[url], "..", $match[1]);
            if (file_exists($match[1])) {
                mw_make_thumbnail($mw_basic[cf_thumb_width], $mw_basic[cf_thumb_height], $match[1], $thumb_file, $mw_basic[cf_thumb_keep]);
                if ($mw_basic[cf_thumb2_width])
                    @mw_make_thumbnail($mw_basic[cf_thumb2_width], $mw_basic[cf_thumb2_height], $match[1], "{$thumb2_path}/{$wr_id}", $mw_basic[cf_thumb2_keep]);
                if ($mw_basic[cf_thumb3_width])
                    @mw_make_thumbnail($mw_basic[cf_thumb3_width], $mw_basic[cf_thumb3_height], $match[1], "{$thumb3_path}/{$wr_id}", $mw_basic[cf_thumb3_keep]);
            }
        } else {
            @unlink($thumb_file);
        }
    }
//}
//}

// ¿øº» ¿öÅÍ¸¶Å©
for ($i=0, $m=sizeof($watermark_files); $i<$m; $i++) // ±âÁ¸ ¿øÅÍ¸¶Å© ÆÄÀÏ »èÁ¦
    unlink($watermark_files[$i]);

if ($mw_basic[cf_watermark_use] && file_exists($mw_basic[cf_watermark_path]))
{
    $sql = "select * from $g4[board_file_table] where bo_table = '$bo_table' and wr_id = '$wr_id' and bf_width > 0  order by bf_no";
    $qry = sql_query($sql);
    while ($row = sql_fetch_array($qry))
        mw_watermark_file("$file_path/$row[bf_file]");
}

// ¸ÞÀÏ¹ß¼Û »ç¿ë (¼öÁ¤±ÛÀº ¹ß¼ÛÇÏÁö ¾ÊÀ½)
if (!($w == "u" || $w == "cu") && $config[cf_email_use])
{
    $emails = explode("\n", $mw_basic[cf_email]);

    if (count($emails) > 0)
    {
        $wr_subject = get_text(stripslashes($wr_subject));

        $tmp_html = 0;
        if (strstr($html, "html1"))
            $tmp_html = 1;
        else if (strstr($html, "html2"))
            $tmp_html = 2;

        $wr_content = conv_content(stripslashes($wr_content), $tmp_html);

        $warr = array( ""=>"ÀÔ·Â", "u"=>"¼öÁ¤", "r"=>"´äº¯", "c"=>"ÄÚ¸àÆ®", "cu"=>"ÄÚ¸àÆ® ¼öÁ¤" );
        $str = $warr[$w];

        $subject = "'{$board[bo_subject]}' °Ô½ÃÆÇ¿¡ {$str}±ÛÀÌ ¿Ã¶ó¿Ô½À´Ï´Ù.";
        $link_url = "$g4[url]/$g4[bbs]/board.php?bo_table=$bo_table&wr_id=$wr_id&$qstr";

        include_once("$g4[path]/lib/mailer.lib.php");

        ob_start();
        include ("$g4[bbs_path]/write_update_mail.php");
        $content = ob_get_contents();
        ob_end_clean();

        foreach ($emails as $email)
        {
            $email = trim($email);
            if (!$email) continue;
            if ($email == "test@test.com") continue;
            mailer($wr_name, $wr_email, $email, $subject, $content, 1);
	    write_log("$g4[path]/data/mail.log", "$email\n");
        }
    }
}

// SMS Àü¼Û
if ($w == "" && $mw_basic[cf_sms_id] && $mw_basic[cf_sms_pw] && trim($mw_basic[cf_hp]) && $is_admin != "super")
{
    $strDest = array();
    $hps = explode("\r\n", $mw_basic[cf_hp]);
    foreach ($hps as $hp) {
        $hp = mw_get_hp($hp, 0);
        if (trim($hp)) {
            $strDest[] = $hp;
        }
    }
    $strCallBack = "0000";
    $strData = "{$board[bo_subject]} °Ô½ÃÆÇ¿¡ {$wr_name} ´ÔÀÌ ±ÛÀ» ¿Ã¸®¼Ì½À´Ï´Ù.";
    include("$board_skin_path/mw.proc/mw.proc.sms.php");
}

//ÄÁÅÙÃ÷ °¡°Ý ¹× »ç¿ëµµ¸ÞÀÎ
if ($mw_basic[cf_contents_shop]) {
    sql_query("update $write_table set wr_contents_price = '$wr_contents_price', wr_contents_domain = '$wr_contents_domain' where wr_id = '$wr_id'");
}

// ÂªÀº ±ÛÁÖ¼Ò »ç¿ë
if ($mw_basic[cf_umz]) {
    $url = "$g4[url]/$g4[bbs]/board.php?bo_table=$bo_table&wr_id=$wr_id";
    $umz = umz_get_url($url);
    sql_query("update $write_table set wr_umz = '$umz' where wr_id = '$wr_id'");
}

// Á¦¸ñ ½ºÅ¸ÀÏ
if ($mw_basic[cf_subject_style] && $mw_basic[cf_subject_style_level] <= $member[mb_level]) {
    sql_query("update $write_table set wr_subject_font = '$wr_subject_font', wr_subject_color = '$wr_subject_color' where wr_id = '$wr_id'");
}

// ¼³¹® 
if ($mw_basic[cf_vote] && $mw_basic[cf_vote_level] <= $member[mb_level])
{
    $tmp = array();
    for ($i=0, $m=sizeof($vt_item); $i<$m; $i++) {
        if (trim($vt_item[$i])) {
            $tmp[] = strip_tags(trim($vt_item[$i]));
        }
    }
    $vt_item = $tmp;
    if ($w == "" && sizeof($vt_item)) {
        $sql = "insert into $mw[vote_table] set bo_table = '$bo_table', wr_id = '$wr_id', vt_edate = '$vt_edate', vt_point = '$vt_point'";
        $qry = sql_query($sql);
        $vt_id = mysql_insert_id();

        for ($i=0, $m=sizeof($vt_item); $i<$m; $i++) {
            $sql = "insert into $mw[vote_item_table] set vt_id = '$vt_id', vt_num = '$i', vt_item = '{$vt_item[$i]}'";
            $qry = sql_query($sql);
        }
    }
    //else if ($w == "u" && sizeof($vt_item)) {
    else if ($w == "u") {

        $sql = "select vt_id from $mw[vote_table] where bo_table = '$bo_table' and wr_id = '$wr_id'";
        $row = sql_fetch($sql);
        if (!$row) {
            $sql = "insert into $mw[vote_table] set bo_table = '$bo_table', wr_id = '$wr_id', vt_edate = '$vt_edate', vt_point = '$vt_point'";
            $qry = sql_query($sql);
            $vt_id = mysql_insert_id();
        } else {
            $vt_id = $row[vt_id];

            $sql = "update $mw[vote_table] set vt_edate = '$vt_edate', vt_point = '$vt_point' where bo_table = '$bo_table' and wr_id = '$wr_id'";
            $qry = sql_query($sql);
        }

        for ($i=0, $m=sizeof($vt_item); $i<$m; $i++) {
            $sql = "select * from $mw[vote_item_table] where vt_id = '$vt_id' and vt_num = '$i'";
            $row = sql_fetch($sql);

            if ($row) {
                $sql = "update $mw[vote_item_table] set vt_item = '{$vt_item[$i]}' where vt_id = '$vt_id' and vt_num = '$i' ";
                $qry = sql_query($sql);
            } else {
                $sql = "insert into $mw[vote_item_table] set vt_id = '$vt_id', vt_num = '$i', vt_item = '{$vt_item[$i]}'";
                $qry = sql_query($sql);
            }
        }
        $sql = "delete from $mw[vote_item_table] where vt_id = '$vt_id' and vt_num >= '$i'";
        $qry = sql_query($sql);

        $sql = "delete from $mw[vote_log_table] where vt_id = '$vt_id' and vt_num >= '$i'";
        $qry = sql_query($sql);

        if (!$i) sql_query("delete from $mw[vote_table] where vt_id = '$vt_id'");
    }
    else if (!sizeof($vt_item)) {
        $sql = "delete from $mw[vote_table] where vt_id = '$vt_id'";
        $qry = sql_query($sql);

        $sql = "delete from $mw[vote_item_table] where vt_id = '$vt_id'";
        $qry = sql_query($sql);

        $sql = "delete from $mw[vote_log_table] where vt_id = '$vt_id'";
        $qry = sql_query($sql);
    }
}

// ¸®¿öµå
if ($mw_basic[cf_reward])
{
    $sql_common = "bo_table = '$bo_table'";
    $sql_common.= ", wr_id = '$wr_id'";
    $sql_common.= ", re_site = '$re_site'";
    $sql_common.= ", re_point = '$re_point'";
    $sql_common.= ", re_url = '$re_url'";
    $sql_common.= ", re_edate = '$re_edate'";

    if ($w == "") {
        $sql = "insert into $mw[reward_table] set $sql_common, re_status = '1'";
        $qry = sql_query($sql);
    } else {
        $sql = "update $mw[reward_table] set $sql_common, re_status = '$re_status' where bo_table = '$bo_table' and wr_id = '$wr_id'";
        $qry = sql_query($sql);
    }
}

// ÀÍ¸í
if ($mw_basic[cf_anonymous]) {
    sql_query(" update $write_table set wr_anonymous = '$wr_anonymous' where wr_id = '$wr_id' ");
}

// ±ÛÀÐ±â ·¹º§
if ($mw_basic[cf_read_level] && $mw_basic[cf_read_level_own] <= $member[mb_level]) {
    sql_query(" update $write_table set wr_read_level = '$wr_read_level' where wr_id = '$wr_id' ");
}

// ¿©ºÐÇÊµå wr_11 ~ wr_40±îÁö È®Àå
for($i = 'wr_11'; $i <= 'wr_40'; $i++) $arr[] = "{$i} = '{$$i}'"; 
$sql11  = " update $write_table set " . implode(', ', $arr) . " where wr_id = '$wr_id' "; 
sql_query($sql11); 

?>
