'spot', 2 => 'event', 4 => 'feature', 5 => 'area');
$og_image = '';
$entry_flag = 0;
$result_flag = 0;
$info_flag = 0;
$lotte_num = 0;
$sort = 2;
$vect = 'D';
$cat = "";
$preview = (isset($preview))? $preview: 0;
$pv_mode = ($preview == 1)? '_pre': '';
$pv_url = ($preview == 1)? 'index_pre.shtml': '';
$template_file = 'corner/present/home/index.tpl';
/* PHPエラー表示設定 */
ini_set("display_errors", LOCOMILL_DISPLAY_ERROR);
/* Locomillクラスインスタンス生成 */
if ($err_str === "") {
try {
$locomill = new Locomill($_COOKIE);
} catch (LocomillError $e) {
$err_str .= $e->get_exception();
}
}
/* 出力準備 */
$smarty = new SmartyEx();
$smarty->prepare();
/* マイプロフィール */
include('common/myprofile.inc');
/* Presentクラスインスタンス生成 */
if ($err_str === "") {
try {
$present = new Present($locomill->get_db());
} catch (PresentError $e) {
$err_str .= $e->get_exception();
}
}
/* PresentItemクラスインスタンス生成 */
if ($err_str === "") {
try {
$present_item = new PresentItem($locomill->get_db());
} catch (PresentItemError $e) {
$err_str .= $e->get_exception();
}
}
/* PresentEntryクラスインスタンス生成 */
if ($err_str === "") {
try {
$present_entry = new PresentEntry($locomill->get_db());
} catch (PresentEntryError $e) {
$err_str .= $e->get_exception();
}
}
/* Spotクラスインスタンス生成 */
if ($err_str === "") {
try {
$spot = new Spot($locomill->get_db());
} catch (SpotError $e) {
$err_str .= $e->get_exception();
}
}
/* Eventクラスインスタンス生成 */
if ($err_str === "") {
try {
$event = new Event($locomill->get_db());
} catch (EventError $e) {
$err_str .= $e->get_exception();
}
}
/* Featureクラスインスタンス生成 */
if ($err_str === "") {
try {
$feature = new Feature($locomill->get_db());
} catch (FeatureError $e) {
$err_str .= $e->get_exception();
}
}
/* Areaクラスインスタンス生成 */
if ($err_str === "") {
try {
$area = new Area($locomill->get_db());
$area_top = $area->get_area_top();
} catch (AreaError $e) {
$err_str .= $e->get_exception();
}
}
/* Memberクラスインスタンス生成 */
if ($err_str === "") {
try {
$member = new Member($locomill->get_db());
} catch (MemberError $e) {
$err_str .= $e->get_exception();
}
}
/* MemberMaster04クラスインスタンス生成 */
if ($err_str === "") {
try {
$avatar_image = new MemberMaster04($locomill->get_db());
} catch (MemberMaster04Error $e) {
$err_str .= $e->get_exception();
}
}
/* Request値の検証 */
if ($err_str === "") {
if (isset($_POST) === true && empty($_POST) === false) {
$rq = $_POST;
} else if (isset($_GET) === true && empty($_GET) === false) {
$rq = $_GET;
}
if (!empty($rq['id'])) {
$present_id = $rq['id'];
}
if (isset($rq['view']) && $rq['view'] == "info") {
$info_flag = 1;
}
if (isset($rq['sort']) && preg_match("/^[0-9]+$/", $rq['sort'])) {
$sort = $rq['sort'];
}
if (isset($rq['vect']) && ($rq['vect'] == 'A' || $rq['vect'] == 'D')) {
$vect = $rq['vect'];
}
if (isset($rq['cat']) && preg_match("/^[0-9]+$/", $rq['cat'])) {
$cat = $rq['cat'];
}
}
/* プレゼントデータ取得 */
if ($err_str === "") {
try {
$present_data = $present->get_data($present_id);
if ($preview == 0 && ($present_data['enable'] == 2 || $now < $present_data['display_01_stamp'])) {
throw new PresentError("・指定のデータに整合性がありません。
");
}
$entry_flag = ($present_data['start_stamp'] <= $now && $now < $present_data['end_stamp'])? 1: 0;
$result_flag = ($present_data['is_dispose'] == 2 && $present_data['display_02_stamp'] < $now)? 1: 0;
$is_open = ($info_flag == 1 || ($present_data['start_stamp'] <= $now && $now < $present_data['end_stamp']))? 1: 0;
if ($result_flag == 1 && $info_flag != 1) {
$present_data['entry_num'] = $present_entry->get_record_num($present_data['id']); // 当選者発表のときだけ応募数を取得
} else {
$present_data['entry_num'] = 0;
}
$present_data['entry_term'] = date('Y/m/d H:i', $present_data['start_stamp']) . '~' . (($present_data['end_stamp'] != mktime(0, 0, 0, 12, 31, 2037))? date('Y/m/d H:i', $present_data['end_stamp']): '');
if (!empty($present_data['category'])) {
$c_array = explode(",", $present_data['category']);
foreach ($c_array AS $k => $v) {
$category_array[$k + 1] = $v;
}
} else {
$category_array = array();
}
// 応募条件・プレゼント
$present_data['conditions_text'] = '';
if ($result_flag == 1 && $info_flag != 1) {
// 当選者発表・情報確認画面では参照しない
} elseif ($present_data['conditions_flg'] == 2 || $present_data['conditions2_flg'] == 2) {
if ($present_data['conditions_flg'] == 2) {
$flg = false;
if ($is_login == 1) {
foreach ($conditions_array AS $type_id => $type_name) {
if (!$flg && !empty($present_data['conditions_' . $type_name . '_ids'])) {
foreach ($present_data['conditions_' . $type_name . '_ids'] AS $parent_id) {
if (!empty($parent_id)) {
// 掲載前でもOK
$wlist = array();
$wlist[] = sprintf('`member_id` = %d', $login_user_id);
$wlist[] = sprintf('`parent_id` = %d', $parent_id);
$wlist[] = sprintf('`type` = %d', $type_id);
$wlist[] = sprintf('(`entry_stamp` BETWEEN %d AND %d)', $present_data['conditions_start_stamp'], $present_data['conditions_end_stamp']);
$sql = sprintf('SELECT `id` FROM `kuchikomi_tbl` WHERE %s LIMIT 1', implode(' AND ', $wlist));
// echo $sql;
$result = $locomill->get_db()->query($sql);
if ($result !== false) {
if (0 < $locomill->get_db()->num($result)) {
$flg = true;
}
$locomill->get_db()->free($result);
}
}
}
}
}
}
if (!$flg) {
$conditions_text = array();
foreach ($conditions_array AS $type_id => $type_name) {
if (!empty($present_data['conditions_' . $type_name . '_ids'])) {
foreach ($present_data['conditions_' . $type_name . '_ids'] AS $parent_id) {
if (!empty($parent_id)) {
if ($type_id == 1) {
try {
$spot_data = $spot->get_data($parent_id);
if ($spot_data['enable'] == 1 && $spot_data['is_closed'] != 1 && $spot_data['start_stamp'] <= $now && $now <= $spot_data['end_stamp']) {
$conditions_text[] = sprintf('%s', $spot_data['id'], htmlspecialchars($spot_data['name_01']));
}
unset($spot_data);
} catch (SpotError $e) {
}
} elseif ($type_id == 2) {
try {
$event_data = $event->get_data($parent_id);
if ($event_data['enable'] == 1 && $event_data['rsv_int_03'] != 3 && $event_data['start_stamp'] <= $now && $now <= $event_data['end_stamp']) {
$conditions_text[] = sprintf('%s', $event_data['id'], htmlspecialchars($event_data['name_01']));
}
unset($event_data);
} catch (EventError $e) {
}
} elseif ($type_id == 4) {
try {
$document_data = $feature->get_document($parent_id);
$feature_data = $feature->get_data($document_data['feature_id']);
if ($document_data['enable'] == 1 && $document_data['open_stamp'] <= $now_date && $now_date <= $document_data['close_stamp'] &&
$feature_data['enable'] == 1 && $feature_data['open_stamp'] <= $now_date && $now_date <= $feature_data['close_stamp']) {
$conditions_text[] = sprintf('%s', $document_data['id'], htmlspecialchars($document_data['title_01']));
}
unset($document_data, $feature_data);
} catch (FeatureError $e) {
}
} elseif ($type_id == 5) {
try {
$area_03_data = $area->get_data('area_master_03_tbl', $parent_id);
if ($area_03_data['enable'] == 1) {
$conditions_text[] = sprintf('%s', (isset($area_top[$area_03_data['id']])? sprintf('/%s/', $area_top[$area_03_data['id']]): sprintf('/area/list/index_medium.shtml?t=A3&id=%d', $area_03_data['id'])), htmlspecialchars($area_03_data['name']));
}
unset($area_03_data);
} catch (AreaError $e) {
}
}
}
}
}
}
if (!empty($conditions_text)) {
$present_data['conditions_text'] .= sprintf('%s ~ %sに %s にクチコミを投稿すると応募可能になります。
', date('Y/n/j H:i', $present_data['conditions_start_stamp']), date('Y/n/j H:i', $present_data['conditions_end_stamp']), implode(' または ', $conditions_text));
}
}
}
if ($present_data['conditions2_flg'] == 2) {
$flg = false;
if ($is_login == 1) {
if (!$flg && !empty($present_data['conditions2_research_ids'])) {
foreach ($present_data['conditions2_research_ids'] AS $parent_id) {
if (!empty($parent_id)) {
$wlist = array();
$wlist[] = sprintf('`a_customer_id` = %d', $login_user_id);
$wlist[] = sprintf('`a_r_id` = %d', $parent_id);
$wlist[] = "`del_datetime` = '0000-00-00 00:00:00'";
$sql = sprintf('SELECT `a_id` FROM `research_answer_data` WHERE %s LIMIT 1', implode(' AND ', $wlist));
// echo $sql;
$result = $locomill->get_db()->query($sql);
if ($result !== false) {
if (0 < $locomill->get_db()->num($result)) {
$flg = true;
}
$locomill->get_db()->free($result);
}
}
}
}
}
if (!$flg) {
$conditions_text = array();
if (!empty($present_data['conditions2_research_ids'])) {
foreach ($present_data['conditions2_research_ids'] AS $parent_id) {
if (!empty($parent_id)) {
$sql = sprintf('SELECT `r_id`,`r_name` FROM `research_basis_data` WHERE `r_id` = %d LIMIT 1', $parent_id);
// echo $sql;
$result = $locomill->get_db()->query($sql);
if ($result !== false) {
if (0 < $locomill->get_db()->num($result)) {
$row = $locomill->get_db()->fetch_array($result);
$conditions_text[] = sprintf('%s', $row['r_id'], CriptPW('rid'.$row['r_id']), htmlspecialchars($row['r_name']));
}
$locomill->get_db()->free($result);
}
}
}
}
if (!empty($conditions_text)) {
$present_data['conditions_text'] .= sprintf('%s アンケートに回答すると応募可能になります。
', implode(' または ', $conditions_text));
}
}
}
}
} catch (PresentError $e) {
$err_str .= $e->get_exception();
}
}
/* プレゼント賞品データ取得 */
if ($err_str === "") {
try {
$wlist = array();
$wlist[] = sprintf('`present_id` = %d', $locomill->get_db()->escape($present_id));
if ($preview == 0) {
$wlist[] = '`enable` = 1';
if ($result_flag != 1) {
$wlist[] = sprintf('(%d BETWEEN `start_stamp` AND `end_stamp`)', $now);
}
}
if (!empty($cat)) {
$wlist[] = sprintf("`category_01` = '%s'", $locomill->get_db()->escape($category_array[$cat]));
}
$vecter = ($vect == 'D')? ' DESC': ' ASC';
$odlist = array();
if ($sort == 2) {
$odlist[] = sprintf('`start_stamp` %s', $vecter);
$odlist[] = sprintf('`entry_stamp` %s', $vecter);
} else {
$odlist[] = sprintf('`name_01` %s', $vecter);
$odlist[] = sprintf('`update_stamp` %s', $vecter);
}
$sql = sprintf('SELECT `id` FROM `present_item_tbl` WHERE %s ORDER BY %s', implode(' AND ', $wlist), implode(', ', $odlist));
// echo $sql;
$result = $locomill->get_db()->query($sql);
if ($result !== false) {
if ($locomill->get_db()->num($result) > 0) {
while ($row = $locomill->get_db()->fetch_array($result)) {
$present_item_array[$row['id']] = $row;
}
} else {
$present_item_array = array();
}
}
$locomill->get_db()->free($result);
if (!empty($present_item_array)) {
$num = 0;
foreach ($present_item_array AS $k => $v) {
try {
$v = $present_item->get_data($v['id']);
} catch (PresentItemError $e) {
continue;
}
$temp = array();
$temp['id'] = $v['id'];
$temp['name'] = $v['name_01'];
$comment = $v['comment'];
$comment = str_replace("\n", "
", $comment);
$comment = href_branch($comment);
$temp['comment'] = $comment;
if (!empty($v['image_01']['up_name'])) {
$temp['image'] = "/img" . LOCOMILL_UPIMG_PRESENT_ITEM_PATH . "/" . $v['image_01']['up_name'];
} else {
$temp['image'] = ""; //LOCOMILL_UPIMG_NOIMAGE_PATH;
}
if (empty($og_image)) {
$og_image = $temp['image'];
}
$temp['spot_name'] = '';
$temp['url'] = '';
try {
$spot_data = $spot->get_data($v['spot_id']);
$temp['spot_name'] = $spot_data['name_01'];
if ($spot_data['enable'] == 1 && $now <= $spot_data['end_stamp']) {
$temp['url'] = "/spot/home/?id=" . $v['spot_id'];
}
} catch (SpotError $e) {
$spot_data = array();
}
$temp['num'] = $v['lottery_max'];
$lotte_num += $v['lottery_max'];
$temp['num_txt'] = $v['lottery_max_txt'];
$temp['is_check_dup'] = $present_data['is_check_dup'];
if ($info_flag !== 1) {
$pid = ($present_data['is_check_dup'] == 2)? $v['id']: 0;
$temp['entry_num'] = $login_user_id? $present_entry->get_record_num($present_id, $pid, true, 0, $login_user_id): 0;
} else {
$temp['entry_num'] = 0;
}
// 当選者発表のときだけ当選者情報を取得
$temp['entry'] = array();;
$temp['l_num'] = 0;
if ($result_flag == 1 && $info_flag != 1) {
try {
$present_entry_array = $present_entry->get_data_array_by_parent($v['id'], 2, 1);
} catch (PresentEntryError $e) {
$present_entry_array = array();
}
$num2 = 0;
if (!empty($present_entry_array)) {
foreach ($present_entry_array AS $j => $w) {
$temp2 = array();
$num2++;
$temp2['id'] = sprintf("%03d", $num2);
if ($w['prefect'] == LOCOMILL_AREA_01_DEFAULT_ID) {
$temp2['area'] = $area->get_name("area_master_03_tbl", $w['city']);
} else {
$temp2['area'] = $area->get_name("area_master_01_tbl", $w['prefect']);
}
try {
$memdata = $member->get_data($w['member_id']);
} catch (MemberError $e) {
$memdata = array();
}
if ($memdata['enable'] == 1) {
$temp2['url'] = "/member/home/?id=" . $w['member_id'];
$temp2['avatar_nickname'] = $memdata['avatar_nickname'];
} else {
$temp2['url'] = "";
$temp2['avatar_nickname'] = $w['avatar_nickname'];
}
try {
$imgdata = $avatar_image->get_data($memdata['avatar_icon']);
} catch (MemberMaster04Error $e) {
$imgdata = array();
}
if (!empty($imgdata['image_01']['up_name']) && file_exists(UPIMG_BASE_PATH . LOCOMILL_UPIMG_MEMBER_MASTER_04_01_PATH . '/' . $imgdata['image_01']['up_name'])) {
$temp2['myimage'] = "/img" . LOCOMILL_UPIMG_MEMBER_MASTER_04_01_PATH . "/" . $imgdata['image_01']['up_name'];
} else {
$temp2['myimage'] = "/common/img/toto.gif";
}
$temp['entry'][$num2] = $temp2;
}
}
$temp['l_num'] = (!empty($num2))? $num2: 0;
}
// 応募条件・賞品
$temp['conditions_text'] = '';
if ($result_flag == 1 && $info_flag != 1) {
// 当選者発表・情報確認画面では参照しない
} elseif ($v['conditions_flg'] == 2 || $v['conditions2_flg'] == 2) {
if ($v['conditions_flg'] == 2) {
$flg = false;
if ($is_login == 1) {
foreach ($conditions_array AS $type_id => $type_name) {
if (!$flg && !empty($v['conditions_' . $type_name . '_ids'])) {
foreach ($v['conditions_' . $type_name . '_ids'] AS $parent_id) {
if (!empty($parent_id)) {
// 掲載前でもOK
$wlist = array();
$wlist[] = sprintf('`member_id` = %d', $login_user_id);
$wlist[] = sprintf('`parent_id` = %d', $parent_id);
$wlist[] = sprintf('`type` = %d', $type_id);
$wlist[] = sprintf('(`entry_stamp` BETWEEN %d AND %d)', $v['conditions_start_stamp'], $v['conditions_end_stamp']);
$sql = sprintf('SELECT `id` FROM `kuchikomi_tbl` WHERE %s LIMIT 1', implode(' AND ', $wlist));
// echo $sql;
$result = $locomill->get_db()->query($sql);
if ($result !== false) {
if (0 < $locomill->get_db()->num($result)) {
$flg = true;
}
$locomill->get_db()->free($result);
}
}
}
}
}
}
if (!$flg) {
$conditions_text = array();
foreach ($conditions_array AS $type_id => $type_name) {
if (!empty($v['conditions_' . $type_name . '_ids'])) {
foreach ($v['conditions_' . $type_name . '_ids'] AS $parent_id) {
if (!empty($parent_id)) {
if ($type_id == 1) {
try {
$spot_data = $spot->get_data($parent_id);
if ($spot_data['enable'] == 1 && $spot_data['is_closed'] != 1 && $spot_data['start_stamp'] <= $now && $now <= $spot_data['end_stamp']) {
$conditions_text[] = sprintf('%s', $spot_data['id'], htmlspecialchars($spot_data['name_01']));
}
unset($spot_data);
} catch (SpotError $e) {
}
} elseif ($type_id == 2) {
try {
$event_data = $event->get_data($parent_id);
if ($event_data['enable'] == 1 && $event_data['rsv_int_03'] != 3 && $event_data['start_stamp'] <= $now && $now <= $event_data['end_stamp']) {
$conditions_text[] = sprintf('%s', $event_data['id'], htmlspecialchars($event_data['name_01']));
}
unset($event_data);
} catch (EventError $e) {
}
} elseif ($type_id == 4) {
try {
$document_data = $feature->get_document($parent_id);
$feature_data = $feature->get_data($document_data['feature_id']);
if ($document_data['enable'] == 1 && $document_data['open_stamp'] <= $now_date && $now_date <= $document_data['close_stamp'] &&
$feature_data['enable'] == 1 && $feature_data['open_stamp'] <= $now_date && $now_date <= $feature_data['close_stamp']) {
$conditions_text[] = sprintf('%s', $document_data['id'], htmlspecialchars($document_data['title_01']));
}
unset($document_data, $feature_data);
} catch (FeatureError $e) {
}
} elseif ($type_id == 5) {
try {
$area_03_data = $area->get_data('area_master_03_tbl', $parent_id);
if ($area_03_data['enable'] == 1) {
$conditions_text[] = sprintf('%s', (isset($area_top[$area_03_data['id']])? sprintf('/%s/', $area_top[$area_03_data['id']]): sprintf('/area/list/index_medium.shtml?t=A3&id=%d', $area_03_data['id'])), htmlspecialchars($area_03_data['name']));
}
unset($area_03_data);
} catch (AreaError $e) {
}
}
}
}
}
}
if (!empty($conditions_text)) {
$temp['conditions_text'] .= sprintf('%s ~ %sに %s にクチコミを投稿すると応募可能になります。
', date('Y/n/j H:i', $v['conditions_start_stamp']), date('Y/n/j H:i', $v['conditions_end_stamp']), implode(' または ', $conditions_text));
}
}
}
if ($v['conditions2_flg'] == 2) {
$flg = false;
if ($is_login == 1) {
if (!$flg && !empty($v['conditions2_research_ids'])) {
foreach ($v['conditions2_research_ids'] AS $parent_id) {
if (!empty($parent_id)) {
$wlist = array();
$wlist[] = sprintf('`a_customer_id` = %d', $login_user_id);
$wlist[] = sprintf('`a_r_id` = %d', $parent_id);
$wlist[] = "`del_datetime` = '0000-00-00 00:00:00'";
$sql = sprintf('SELECT `a_id` FROM `research_answer_data` WHERE %s LIMIT 1', implode(' AND ', $wlist));
// echo $sql;
$result = $locomill->get_db()->query($sql);
if ($result !== false) {
if (0 < $locomill->get_db()->num($result)) {
$flg = true;
}
$locomill->get_db()->free($result);
}
}
}
}
}
if (!$flg) {
$conditions_text = array();
if (!empty($v['conditions2_research_ids'])) {
foreach ($v['conditions2_research_ids'] AS $parent_id) {
if (!empty($parent_id)) {
$sql = sprintf('SELECT `r_id`,`r_name` FROM `research_basis_data` WHERE `r_id` = %d LIMIT 1', $parent_id);
// echo $sql;
$result = $locomill->get_db()->query($sql);
if ($result !== false) {
if (0 < $locomill->get_db()->num($result)) {
$row = $locomill->get_db()->fetch_array($result);
$conditions_text[] = sprintf('%s', $row['r_id'], CriptPW('rid'.$row['r_id']), htmlspecialchars($row['r_name']));
}
$locomill->get_db()->free($result);
}
}
}
}
if (!empty($conditions_text)) {
$temp['conditions_text'] .= sprintf('%s アンケートに回答すると応募可能になります。
', implode(' または ', $conditions_text));
}
}
}
}
$present_01_array[$v['id']] = $temp;
$num++;
}
$item_num = $num;
}
} catch (PresentItemError $e) {
$present_item_array = array();
}
}
/* 変数の準備 */
$smarty->assign_ex("PRESENT_DATA", $present_data);
$smarty->assign_ex("PRESENT_ID", $present_id);
$smarty->assign_ex("ITEM_NUM", $item_num, 0);
$smarty->assign_ex("LOTTE_NUM", $lotte_num, 0);
$smarty->assign_ex("ENTRY_FLAG", $entry_flag);
$smarty->assign_ex("INFO_FLAG", $info_flag);
$smarty->assign_ex("RESULT_FLAG", $result_flag);
$smarty->assign_ex("IS_OPEN", $is_open);
// プレゼントデータ配列
$smarty->assign_ex("PRESENT_01_ARRAY", $present_01_array);
if (empty($og_image)) {
$og_image = '/common/images/ogimg.png';
}
$smarty->assign_ex("OG_IMAGE", $og_image);
$smarty->assign_ex("CAT", $cat);
$smarty->assign_ex("SORT", $sort);
$smarty->assign_ex("VECT", $vect);
$smarty->assign_ex("CATEGORY_ARRAY", $category_array);
// プレビュー
$smarty->assign("PREVIEW", $preview);
$smarty->assign("PV_MODE", $pv_mode);
// プレビューモード
$smarty->assign("PV_MODE_GET_VALUE", $preview);
// イマココ
$imakoko = getTopicsPath('corner');
$imakoko[] = array('/corner/present/list/', 'プレゼントマニア');
if ($err_str === "") {
$imakoko[] = array(sprintf('/corner/present/home/?id=%d', $present_id), $present_data['name_01']);
}
$smarty->assign("IMAKOKO_ARRAY", $imakoko);
// 最新情報
include('common/whatsnew.inc');
/* 広告系 */
$the_corner_id = 43; // プレゼントマニア:43
$adver_param = array("terminal_type" => 1,
"corner_id" => $the_corner_id);
$adver_b_type = array(1, 7);
include('common/banners.inc');
// エラー文字列
$smarty->assign("ERR_STR", $err_str);
if (!empty($err_str) || $preview == 1) {
header("HTTP/1.0 404 Not Found");
}
/* 出 力 */
if ($err_str === "") {
if ($result_flag == 1 && $info_flag != 1) {
$template_file = 'corner/present/home/index_result.tpl';
}
}
$smarty->display($template_file);