1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
|
<?php error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING );
header("Progma:no-cache"); header("Cache: no-cache"); header("Cache-Control:no-cache,must-revalidate"); header("Expires:Mon, 26 Jul 1997 05:00:00 GMT"); date_default_timezone_set("Asia/Seoul");
//session_save_path("./data/session"); session_cache_limiter("no-cache, must-revalidate");
ini_set("session.cache_expire", 1440); // 세션 캐쉬 보관시간 (분) ini_set("session.gc_maxlifetime", 108000); // session data의 garbage collection 존재 기간을 지정 (초) ini_set("session.gc_probability", 1); // session.gc_probability는 session.gc_divisor와 연계하여 gc(쓰레기 수거) 루틴의 시작 확률을 관리합니다. 기본값은 1입니다. 자세한 내용은 session.gc_divisor를 참고하십시오. ini_set("session.gc_divisor", 100); // session.gc_divisor는 session.gc_probability와 결합하여 각 세션 초기화 시에 gc(쓰레기 수거) 프로세스를 시작할 확률을 정의합니다. 확률은 gc_probability/gc_divisor를 사용하여 계산합니다. 즉, 1/100은 각 요청시에 GC 프로세스를 시작할 확률이 1%입니다. session.gc_divisor의 기본값은 100입니다.
function j3_path() { $result['path'] = str_replace('\\', '/', dirname(__FILE__)); $tilde_remove = preg_replace('/^\/\~[^\/]+(.*)$/', '$1', $_SERVER['SCRIPT_NAME']); $document_root = str_replace($tilde_remove, '', $_SERVER['SCRIPT_FILENAME']); $root = str_replace($document_root, '', $result['path']); $port = $_SERVER['SERVER_PORT'] != 80 ? ':'.$_SERVER['SERVER_PORT'] : ''; $http = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on') ? 's' : '') . '://'; $user = str_replace(str_replace($document_root, '', $_SERVER['SCRIPT_FILENAME']), '', $_SERVER['SCRIPT_NAME']); $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME']; if(isset($_SERVER['HTTP_HOST']) && preg_match('/:[0-9]+$/', $host)) $host = preg_replace('/:[0-9]+$/', '', $host); $result['url'] = $http.$host.$port.$user.$root; return $result; }
$j3_path_array = j3_path();
$j3_path = $j3_path_array['path']; $j3_shop_path = $j3_path."/shop"; $j3_shopm_path = $j3_path."/shopm"; $j3_adm_path = $j3_path."/adm"; $j3_data_path = $j3_path."/data"; $j3_css_path = $j3_path."/css"; $j3_img_path = $j3_path."/img"; $j3_imgm_path = $j3_path."/imgm"; $j3_js_path = $j3_path."/js"; $j3_lib_path = $j3_path."/lib"; $j3_skin_path = $j3_path."/skin"; $j3_skinm_path = $j3_path."/skinm";
$j3_url = $j3_path_array['url']; $j3_shop_url = $j3_url."/shop"; $j3_shopm_url = $j3_url."/shopm"; $j3_adm_url = $j3_url."/adm"; $j3_data_url = $j3_url."/data"; $j3_css_url = $j3_url."/css"; $j3_img_url = $j3_url."/img"; $j3_imgm_url = $j3_url."/imgm"; $j3_js_url = $j3_url."/js"; $j3_lib_url = $j3_url."/lib"; $j3_skin_url = $j3_url."/skin"; $j3_skinm_url = $j3_url."/skinm";
session_save_path($j3_data_path."/session");
@session_start();
define('G5_ESCAPE_FUNCTION', 'sql_escape_string'); //header('Content-Type: text/html; charset=utf-8');
// multi-dimensional array에 사용자지정 함수적용 function array_map_deep($fn, $array) { if(is_array($array)) { foreach($array as $key => $value) { if(is_array($value)) { $array[$key] = array_map_deep($fn, $value); } else { $array[$key] = call_user_func($fn, $value); } } } else { $array = call_user_func($fn, $array); }
return $array; }
// SQL Injection 대응 문자열 필터링 function sql_escape_string($str) { if(defined('G5_ESCAPE_PATTERN') && defined('G5_ESCAPE_REPLACE')) { $pattern = G5_ESCAPE_PATTERN; $replace = G5_ESCAPE_REPLACE;
if($pattern) $str = preg_replace($pattern, $replace, $str); }
$str = call_user_func('addslashes', $str);
return $str; }
$ext_arr = array ('PHP_SELF', '_ENV', '_GET', '_POST', '_FILES', '_SERVER', '_COOKIE', '_SESSION', '_REQUEST', 'HTTP_ENV_VARS', 'HTTP_GET_VARS', 'HTTP_POST_VARS', 'HTTP_POST_FILES', 'HTTP_SERVER_VARS', 'HTTP_COOKIE_VARS', 'HTTP_SESSION_VARS', 'GLOBALS'); $ext_cnt = count($ext_arr); for ($i=0; $i<$ext_cnt; $i++) { // POST, GET 으로 선언된 전역변수가 있다면 unset() 시킴 if (isset($_GET[$ext_arr[$i]])) unset($_GET[$ext_arr[$i]]); if (isset($_POST[$ext_arr[$i]])) unset($_POST[$ext_arr[$i]]); }
//============================================================================== // SQL Injection 등으로 부터 보호를 위해 sql_escape_string() 적용 //------------------------------------------------------------------------------ // magic_quotes_gpc 에 의한 backslashes 제거 if (get_magic_quotes_gpc()) { $_POST = array_map_deep('stripslashes', $_POST); $_GET = array_map_deep('stripslashes', $_GET); $_COOKIE = array_map_deep('stripslashes', $_COOKIE); $_REQUEST = array_map_deep('stripslashes', $_REQUEST); }
// sql_escape_string 적용 $_POST = array_map_deep(G5_ESCAPE_FUNCTION, $_POST); $_GET = array_map_deep(G5_ESCAPE_FUNCTION, $_GET); $_COOKIE = array_map_deep(G5_ESCAPE_FUNCTION, $_COOKIE); $_REQUEST = array_map_deep(G5_ESCAPE_FUNCTION, $_REQUEST); //==============================================================================
foreach($_GET as $key=>$val){ //$_GET[$key] = urldecode($val); } foreach($_POST as $key=>$val){ //$_POST[$key] = urldecode($val); } $_COOKIE['qstr'] = urldecode($_COOKIE['qstr']); @extract($_GET); @extract($_POST); @extract($_SERVER); @extract($_SESSION);
//============================================================================== // SESSION 설정 //------------------------------------------------------------------------------
define('G5_TABLE_PREFIX', 'g5_');
define('G5_SERVER_TIME', time()); define('G5_TIME_YMDHIS', date('Y-m-d H:i:s', G5_SERVER_TIME)); define('G5_TIME_YMD', substr(G5_TIME_YMDHIS, 0, 10)); define('G5_TIME_HIS', substr(G5_TIME_YMDHIS, 11, 8)); define('G5_ESCAPE_FUNCTION', 'sql_escape_string');
/*define('G5_DIR_PERMISSION', 0755); // 디렉토리 생성시 퍼미션 define('G5_FILE_PERMISSION', 0644); // 파일 생성시 퍼미션*/ define('G5_DIR_PERMISSION', 0707); // 디렉토리 생성시 퍼미션 define('G5_FILE_PERMISSION', 0606); // 파일 생성시 퍼미션
define('G5_MOBILE_AGENT', 'phone|samsung|lgtel|mobile|[^A]skt|nokia|blackberry|android|sony');
include($j3_path."/dbconfig.php"); include($j3_path."/j3_include.php"); include($j3_lib_path."/common2.lib.php"); include($j3_lib_path."/shop.custom.lib.php"); // 개별 쇼핑몰별 설정이나 라이브러리 저장용 //include($j3_path."/dbupdate.php"); // DB변경시 처리할 파일
$sql = "select * from options "; $res = mysql_query($sql,$connect_j3); while($info=mysql_fetch_array($res)){ $options[$info['optname']] = $info['optvalue']; }
$sql = "select * from user_config where menu_name = 'shop_config' "; // 기본환경 $res = mysql_query($sql,$connect_j3); while($info=mysql_fetch_array($res)){ $config[$info['config_key']] = $info['config_val']; }
$sql = "select * from user_config where menu_name = 'shop_config_shop' "; // 쇼핑몰환경 $res = mysql_query($sql,$connect_j3); while($info=mysql_fetch_array($res)){ $configshop[$info['config_key']] = $info['config_val']; } $configshop['ob_script'] = ""; // 스크립트 처리용 ob
$sql = "select * from offices where code = '{$configshop['office_code']}' "; // 사업장 정보 가져오기 $ores = mysql_query($sql,$connect_j3); $oinfo = mysql_fetch_object($ores); foreach($oinfo as $key=>$val){ $configshop[$key] = $val; }
if($config['customer_office']=='1' && $id_ccode!='' && $admin_page!="Y"){ // 거래처에 따른 사업장번호를 변경하도록 처리 $configshop['office_code'] = customer_ocode($id_ccode); }
if($config['login_free']=='1'){ // 거래처 사업장 로그인 관계없이 로그인시 처리용/관리자 거래처 리스트용 $ocode_where = ""; } else { $ocode_where = " and ocode = '{$configshop['office_code']}' "; }
if($config['domain_www']=='www0'){ // www 제거 처리시 $v = substr($_SERVER['SERVER_NAME'],0,4); if($v=='www.'){ $vv = str_replace("www.","",$_SERVER['SERVER_NAME']); $vvv = "http://{$vv}{$_SERVER['SCRIPT_NAME']}"; echo "<meta http-equiv=\"refresh\" content=\"0;url={$vvv}\">"; exit; } }
if($config['domain_www']=='www1'){ // www 사용 처리시 $v = substr($_SERVER['SERVER_NAME'],0,4); if($v!='www.'){ $vv = "www.".$_SERVER['SERVER_NAME']; $vvv = "http://{$vv}{$_SERVER['SCRIPT_NAME']}"; echo "<meta http-equiv=\"refresh\" content=\"0;url={$vvv}\">"; exit; } }
$configshop['store_code'] = 1; // 창고번호는 일단 1로 세팅
//echo $config['ssl_domain'];
include($j3_lib_path."/PHPMailer5/PHPMailerAutoload.php"); // phpmailer 5 모듈 그누보드 2.0 모듈하고 몇몇 명령어나 대소문자나 기타 틀림
if($b_table!=''){ $table_name = "shop_write_".$b_table; }
// 쇼핑몰 기반의 재고 체크 : 수발주(쇼핑몰 주문)의 매출 포함 if($configshop['jego_disp_type']=='0'){ // 쇼핑몰 재고 $jego_get_table_sql = "select a.pcode, ocode, if(s.p_jegomax=1,9999,floor(qty-ifnull(b.sale_ord_qty,0))) as jego from stock_current a inner join product_s s on a.pcode = s.pcode left join (select pcode, sum(qty-out_tot_qty-cancel_qty) as sale_ord_qty from sale_ord_d a inner join sale_ord_m b on a.midx = b.midx and b.ocode = '{$configshop['office_code']}' inner join sale_ord_s c on a.midx = c.midx and c.ord_cancel <> '1' group by pcode) b on a.pcode = b.pcode where ocode = '{$configshop['office_code']}' and a.scode = '{$configshop['store_code']}' "; // 천년3 재고에서 수주의 매출(납품)로 안넘어간것만 재고 빼서 처리
$jego_get_box_sql = "select parent_pcode, if(s.p_jegomax=1,9999,floor((qty-ifnull(od.sell_qty,0))/child_qty)-sale_ord_qty) as box_qty, sale_ord_qty from product_set a inner join stock_current b on a.child_pcode = b.pcode and ocode = '{$configshop['office_code']}' and scode = '{$configshop['store_code']}' inner join product_s s on s.pcode = a.parent_pcode left join (select pcode, sum(qty-out_tot_qty-cancel_qty) as sell_qty from sale_ord_d a group by pcode) od on a.child_pcode = od.pcode left join (select pcode, sum(qty-out_tot_qty-cancel_qty) as sale_ord_qty from sale_ord_d a inner join sale_ord_m b on a.midx = b.midx and b.ocode = '{$configshop['office_code']}' inner join sale_ord_s c on a.midx = c.midx and c.ord_cancel <> '1' group by pcode) c on c.pcode = a.parent_pcode where 1";
$jego_get_set_sql = "select a.code, min(b.s_qty)-b.sale_ord_qty as jego from product_m a inner join (select a.parent_pcode, a.child_pcode, a.child_qty, s.qty, floor((s.qty-ifnull(od.sell_qty,0))/a.child_qty) as s_qty, ifnull(od.sell_qty,0), sale_ord_qty from product_set a inner join product_d d on a.child_pcode = d.pcode and d.ocode = '{$configshop['office_code']}' inner join stock_current s on d.pcode = s.pcode and d.ocode = s.ocode and s.scode = '{$configshop['store_code']}' left join (select pcode, sum(qty-out_tot_qty-cancel_qty) as sell_qty from sale_ord_d a group by pcode) od on a.child_pcode = od.pcode left join (select pcode, sum(qty-out_tot_qty-cancel_qty) as sale_ord_qty from sale_ord_d a inner join sale_ord_m b on a.midx = b.midx and b.ocode = '{$configshop['office_code']}' inner join sale_ord_s c on a.midx = c.midx and c.ord_cancel <> '1' group by pcode ) ss on ss.pcode = a.parent_pcode) b on a.code = b.parent_pcode where set_yn = 1"; } else { // 천년3 재고 $jego_get_table_sql = "select a.pcode, a.ocode, if(s.p_jegomax=1,9999,floor(qty)) as jego from stock_current a inner join product_s s on a.pcode = s.pcode where ocode = '{$configshop['office_code']}' and scode = '{$configshop['store_code']}' ";
$jego_get_box_sql = "select a.parent_pcode, if(s.p_jegomax=1,9999,floor(qty/child_qty)) as box_qty from product_set a inner join stock_current b on a.child_pcode = b.pcode inner join product_s s on s.pcode = a.parent_pcode where ocode = '{$configshop['office_code']}' and scode = '{$configshop['store_code']}' ";
$jego_get_set_sql = "select a.code, min(b.s_qty) as jego from product_m a inner join (select a.parent_pcode, a.child_pcode, a.child_qty, s.qty, floor(s.qty/a.child_qty) as s_qty from product_set a inner join product_d d on a.child_pcode = d.pcode and d.ocode = '{$configshop['office_code']}' inner join stock_current s on d.pcode = s.pcode and d.ocode = s.ocode and s.scode = '{$configshop['store_code']}' ) b on a.code = b.parent_pcode where set_yn = 1"; }
//_pr($jego_get_box_sql);
// 품절상품들 pcode 리스트 만드는 구문 $sql = "select a.code as pcode, ifnull(aaa.jego,0) as jego from product_m a inner join product_d b on a.code = b.pcode and b.ocode = '1' inner join product_s c on a.code = c.pcode left join ({$jego_get_table_sql}) aaa on a.code = aaa.pcode and b.ocode = aaa.ocode "; $res = mysql_query($sql,$connect_j3); $soldout_pcode_list = ""; $not_soldout_pcode_list = ""; while($info=mysql_fetch_array($res)){ $prod_jego[$info['pcode']] = $info['jego']; if($info['jego']*1<=0){ $soldout_pcode_list = $soldout_pcode_list.$info['pcode'].","; } if($info['jego']*1>0){ $not_soldout_pcode_list = $not_soldout_pcode_list.$info['pcode'].","; } } $soldout_pcode_list = substr($soldout_pcode_list,0,strlen($soldout_pcode_list)-1); $not_soldout_pcode_list = substr($not_soldout_pcode_list,0,strlen($not_soldout_pcode_list)-1); // 품절상품들 pcode 리스트 만드는 구문 끝
// 천년3 기반의 재고 계산용 : 수발주 매출은 포함안함 $cs3_jego_get_table_sql = "select pcode, ocode, stock_mng_yn, floor(sb_qty+se_qty+buy_qty-sale_qty) as jego from (select a.pcode, a.ocode, ifnull(b.qty,0) as sb_qty, ifnull(c.qty,0) as se_qty, ifnull(d.qty,0) as buy_qty, ifnull(e.qty,0) as sale_qty, a.stock_mng_yn from (select a.code as pcode, b.ocode, a.stock_mng_yn from product_m a left join product_d b on a.code = b.pcode) a left join stock_begin b on a.pcode = b.pcode and a.ocode = b.ocode left join (select pcode, ocode, ifnull(sum(qty),0) as qty from stock_edit group by pcode, ocode) c on a.pcode = c.pcode and a.ocode = c.ocode left join (select b.pcode, a.ocode, ifnull(sum(b.qty),0) as qty from buy_m a left join buy_d b on a.midx = b.midx group by b.pcode, a.ocode) d on a.pcode = d.pcode and a.ocode = d.ocode left join (select b.pcode, a.ocode, ifnull(sum(b.qty),0) as qty from sale_m a left join sale_d b on a.midx = b.midx group by b.pcode, a.ocode) e on a.pcode = e.pcode and a.ocode = e.ocode ) aa where 1=1 and aa.ocode = '{$configshop['office_code']}' and pcode = '[pcode]' ";
if($id!='' && $id_code!=''){ $is_admin = true; }
if($configshop['pg_service']=='uplus'){ if(is_mobile()){ $path = $j3_shopm_url; } else { $path = $j3_shop_url; } $pay_url = "{$path}/xpay/payreq_crossplatform.php"; }
// 자동 수령완료 처리 작업 deli_comp_auto();
//if(is_mobile()){ echo "모바일"; }
//$id_ccode = "86"; // 임시 거래처 세팅 if($_GET['device']!=''){ if($_GET['device']=='mobile'){ $_SESSION['device'] = $_GET['device']; } else { $_SESSION['device'] = ""; } } else if($_SESSION['device']=='mobile'){
} else if(is_mobile()){ $_SESSION['device'] = "mobile"; }
if($config['mobile_domain']!='' && is_mobile()){ // 모바일도메인이 세팅되어 있고 모바일인 경우 if($config['mobile_domain']==$_SERVER['SERVER_NAME']){ $mode_mobile = "mobile"; } else { goto_url("http://".$config['mobile_domain']); exit; } } else if($config['mobile_domain']!=''){ if($config['mobile_domain']==$_SERVER['SERVER_NAME']){ // PC에서 모바일 도메인을 바로 쳐서 들어가는경우 $mode_mobile = "mobile"; } }
if(strpos(".".$_SERVER['SCRIPT_NAME'],"/shop/")>0){ // PC 디렉토리일경우 PC 환경 처리 $_SESSION['device'] = ""; $mode_mobile==''; } if(strpos(".".$_SERVER['SCRIPT_NAME'],"/shopm/")>0){ // 기기나 파라메터가 들어가도 모바일 디렉토리일경우 모바일 환경 처리 $_SESSION['device'] = "mobile"; }
if($admin_page <> "Y" ){ // 어드민 페이지 아닐때만 모바일 관련 적용 if($_SESSION['device']=='mobile' || $mode_mobile=='mobile'){ $is_mobile = '1'; } } if($is_mobile=='1'){ $j3_shopp_url = $j3_shop_url; $j3['j3_shopp_url'] = $j3_shop_url;
$j3_imgp_url = $j3_img_url; $j3['j3_imgp_url'] = $j3_img_url; $j3_shop_url = $j3_shopm_url; $j3['j3_shop_url'] = $j3_shopm_url;
$j3_img_url = $j3_imgm_url; $j3['j3_img_url'] = $j3_imgm_url; } else { $j3_shopp_url = $j3_shop_url; $j3['j3_shopp_url'] = $j3_shop_url;
$j3_imgp_url = $j3_img_url; $j3['j3_imgp_url'] = $j3_img_url; }
$j3['app_id'] = $app_id;
if(strpos($_SERVER['SCRIPT_NAME'],"index.php")>0){ $is_index_page = true; include($j3_path."/visit.inc.php"); } else { $is_index_page = false; }
if(strpos($_SERVER['SCRIPT_NAME'],"mypage.php")>0 || strpos($_SERVER['SCRIPT_NAME'],"orderform.php")>0){ cust_cur_point_cal($id_ccode); // 쇼핑몰 포인트 재계산 } if($admin_page!='Y'){ $cinfo = customer_info_get($id_ccode); // 고객 정보 }
if($_SESSION['sess_id']==''){ $_SESSION['sess_id'] = $_COOKIE['PHPSESSID']; }
if($id_ccode=='' && $configshop['guest_buy']=='1'){ $id_ccode = '0'; }
if(!table_field_ck("shop_cart", "ev_code")){ // 장바구니 이벤트 코드 추가 $sql = "ALTER TABLE `shop_cart` ADD COLUMN `ev_code` INT NULL DEFAULT '0' COMMENT '이벤트코드' AFTER `opt_mode`;"; @mysql_query($sql,$connect_j3);
// 장바구니 이벤트 유니크 인덱스 변경 $sql = "ALTER TABLE `shop_cart` DROP INDEX `uk_cart`, ADD UNIQUE INDEX `uk_cart` (`od_id`, `ccode`, `pcode`, `opt_pcode`, `opt_mode`, `ocode`, `ev_code`);"; @mysql_query($sql,$connect_j3); } ?>
|