Skip to content

Commit

Permalink
加入複製活動功能
Browse files Browse the repository at this point in the history
  • Loading branch information
tadlearn committed Jul 17, 2021
1 parent 7da6304 commit 8601ed7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
38 changes: 38 additions & 0 deletions class/Tad_signup_actions.php
Expand Up @@ -238,4 +238,42 @@ public static function get_all($only_enable = true, $auto_key = false)
return $data_arr;
}

//複製活動
public static function copy($id)
{
global $xoopsDB, $xoopsUser;
if (!$_SESSION['tad_signup_adm']) {
redirect_header($_SERVER['PHP_SELF'], 3, "您沒有權限使用此功能");
}

$action = self::get($id);
$uid = $xoopsUser->uid();
$end_date = date('Y-m-d 17:30:00', strtotime('+2 weeks'));
$action_date = date('Y-m-d 09:00:00', strtotime('+16 days'));

$sql = "insert into `" . $xoopsDB->prefix("tad_signup_actions") . "` (
`title`,
`detail`,
`action_date`,
`end_date`,
`number`,
`setup`,
`uid`,
`enable`
) values(
'{$action['title']}_copy',
'{$action['detail']}',
'{$action_date}',
'{$end_date}',
'{$action['number']}',
'{$action['setup']}',
'{$uid}',
'0'
)";
$xoopsDB->queryF($sql) or Utility::web_error($sql, __FILE__, __LINE__);

//取得最後新增資料的流水編號
$id = $xoopsDB->getInsertId();
return $id;
}
}
6 changes: 6 additions & 0 deletions index.php
Expand Up @@ -93,6 +93,12 @@
redirect_header($_SERVER['PHP_SELF'] . "?id=$action_id", 3, "成功設定錄取狀態!");
exit;

// 複製活動
case 'tad_signup_actions_copy':
$new_id = Tad_signup_actions::copy($id);
header("location: {$_SERVER['PHP_SELF']}?op=tad_signup_actions_edit&id=$new_id");
exit;

default:
if (empty($id)) {
Tad_signup_actions::index();
Expand Down
1 change: 1 addition & 0 deletions templates/op_tad_signup_actions_index.tpl
Expand Up @@ -22,6 +22,7 @@
<td>
<{if $smarty.session.tad_signup_adm}>
<a href="index.php?op=tad_signup_actions_edit&id=<{$action.id}>" class="btn btn-sm btn-warning"><i class="fa fa-pencil" aria-hidden="true"></i> 編輯活動</a>
<a href="index.php?op=tad_signup_actions_copy&id=<{$action.id}>" class="btn btn-sm btn-info"><i class="fa fa-copy" aria-hidden="true"></i> 複製活動</a>
<{/if}>

<{if $action.number > $action.signup|@count && $xoops_isuser && $action.end_date|strtotime >= $smarty.now}>
Expand Down

0 comments on commit 8601ed7

Please sign in to comment.