-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.addedit_comp.php
More file actions
206 lines (197 loc) · 6.34 KB
/
Copy pathaction.addedit_comp.php
File metadata and controls
206 lines (197 loc) · 6.34 KB
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
<?php
/*
This file is part of CMS Made Simple module: Tourney.
Copyright (C) 2014-2016 Tom Phane <tpgww@onepost.net>
Refer to licence and other details at the top of file Tourney.module.php
More info at http://dev.cmsmadesimple.org/projects/tourney
*/
if (!$this->CheckAccess())
$this->Redirect($id,'defaultadmin','',
array('tmt_message'=>$this->PrettyMessage('lackpermission',FALSE)));
if(isset($params['cancel']))
$this->Redirect($id,'defaultadmin','');
/*
Arrive here following adminpanel add or edit click, or one of the various actions
initiated from the page setup and displayed here
Determine whether to add a new comp
*/
$add = FALSE;
if (isset($params['real_action']))
{
//back here after operation initiated from previous iteration (and with js enabled)
if (empty($params['bracket_id']))
{
$this->Redirect($id,'defaultadmin','',array('tmt_message'=>$this->PrettyMessage($params['real_action'],FALSE))); //TODO DEBUG
if (0) //TODO $params['real_action'] == ?)
$add = TRUE;
}
if (strpos($params['real_action'],'move') === 0)
{
//strip off the [teamid]
$tmp = $params['real_action'];
$pos = strpos($tmp,'[');
$movetid = substr($tmp,$pos+1,-1);
$params['real_action'] = substr($tmp,0,$pos);
}
}
elseif(isset($params['action']))
{
//add|edit initiated from adminpanel (or others if js disabled)
if (empty($params['bracket_id']))
{
$params['real_action'] = 'add';
$add = TRUE;
}
else
$params['real_action'] = 'edit';
}
else
$this->Redirect($id,'defaultadmin','',array('tmt_message'=>$this->PrettyMessage('err_system',FALSE)));
$tab = $this->GetActiveTab($params);
$message = (!empty($params['tmt_message'])) ? $params['tmt_message'] : FALSE;
if ($add)
{
$funcs = new tmtData();
$data = $funcs->GetBracketData($this,'add',$id);
unset($funcs);
//save initial (non-default) data for bracket
$args = array(
'bracket_id' => $data->bracket_id,
'type' => Tourney::KOTYPE, //$data->type is empty string
'seedtype' => $data->seedtype,
'fixtype' => $data->fixtype,
'teamsize' => $data->teamsize,
'atformat' => $data->atformat,
'final' => $data->final,
'semi' => $data->semi,
'quarter' => $data->quarter,
'eighth' => $data->eighth,
'roundname' => $data->roundname,
'versus' => $data->versus,
'defeated' => $data->defeated,
'tied' => $data->tied,
'bye' => $data->bye,
'forfeit' => $data->forfeit,
'nomatch' => $data->nomatch,
'timezone' => $data->timezone,
'playgap' => $data->playgap,
'playgaptype' => $data->playgaptype,
'available' => $data->available,
'placegap' => $data->placegap,
'placegaptype' => $data->placegaptype);
$fields = implode(',',array_keys($args));
$fillers = str_repeat('?,',count($args)-1).'?';
$sql = 'INSERT INTO '.cms_db_prefix().'module_tmt_brackets ('.$fields.') VALUES ('.$fillers.');';
$db->Execute($sql,array_values($args));
if ($data->motemplate)
tmtTemplate::Set($this,'mailout_'.$data->bracket_id.'_template',$data->motemplate);
if($data->mcanctemplate)
tmtTemplate::Set($this,'mailcancel_'.$data->bracket_id.'_template',$data->mcanctemplate);
if($data->mreqtemplate)
tmtTemplate::Set($this,'mailrequest_'.$data->bracket_id.'_template',$data->mreqtemplate);
if ($data->mitemplate)
tmtTemplate::Set($this,'mailin_'.$data->bracket_id.'_template',$data->mitemplate);
if ($data->totemplate)
tmtTemplate::Set($this,'tweetout_'.$data->bracket_id.'_template',$data->totemplate);
if($data->tcanctemplate)
tmtTemplate::Set($this,'tweetcancel_'.$data->bracket_id.'_template',$data->tcanctemplate);
if($data->treqtemplate)
tmtTemplate::Set($this,'tweetrequest_'.$data->bracket_id.'_template',$data->treqtemplate);
if ($data->titemplate)
tmtTemplate::Set($this,'tweetin_'.$data->bracket_id.'_template',$data->titemplate);
if ($data->chttemplate)
tmtTemplate::Set($this,'chart_'.$data->bracket_id.'_template',$data->chttemplate);
}
else
{
$bid = (int)$params['bracket_id'];
switch ($params['real_action'])
{
case 'result_view':
case 'match_view':
break;
case 'connect':
$ob = $this->GetModuleInstance('Notifier');
if($ob)
{
$ob->DoAction('start',$id,array());
}
//if still here, some problem occurred
$params['real_action'] = 'edit';
break;
case 'movedown':
case 'moveup':
$pref = cms_db_prefix();
$sql = 'SELECT displayorder FROM '.$pref.'module_tmt_teams WHERE bracket_id=? AND team_id=?';
$from = $db->GetOne($sql,array($bid,$movetid));
if($from)
{
$to = ($params['real_action']=='moveup') ? $from-1 : $from+1;
if($to > 0)
{
$sql = 'UPDATE '.$pref.'module_tmt_teams SET displayorder='.$from.' WHERE bracket_id=? AND displayorder='.$to;
$db->Execute($sql,array($bid));
$sql = 'UPDATE '.$pref.'module_tmt_teams SET displayorder='.$to.' WHERE bracket_id=? AND team_id=?';
$db->Execute($sql,array($bid,(int)$movetid));
}
}
$params['real_action'] = 'edit';
break;
default:
//refresh matches if appropriate
$pref = cms_db_prefix();
$sql = 'SELECT COUNT(match_id) AS num FROM '.$pref.'module_tmt_matches WHERE bracket_id=? AND flags=0';
if ($db->GetOne($sql,array($bid)))
{
$sch = new tmtSchedule();
$sql = 'SELECT type FROM '.$pref.'module_tmt_brackets WHERE bracket_id=?';
$type = $db->GetOne($sql,array($bid));
switch ($type)
{
case Tourney::DETYPE:
$sch->UpdateDEMatches($this,$bid);
break;
case Tourney::RRTYPE:
$sch->NextRRMatches($this,$bid);
break;
default:
//case Tourney::KOTYPE:
$sch->UpdateKOMatches($this,$bid);
break;
}
unset($sch);
}
}
$funcs = new tmtData();
$data = $funcs->GetBracketData($this,$params['real_action'],$id,$bid,$params);
unset($funcs);
if (isset ($params['tmt_message']))
$message = $params['tmt_message'];
}
if ($data) {
if ($params['real_action'] == 'view')
$data->readonly = 1;
$tplvars = array();
//script accumulators populated downstream
$jsfuncs = NULL;
$jsloads = NULL;
$jsincs = NULL;
$funcs = new tmtEditSetup();
$funcs->Setup($this,$tplvars,$jsfuncs,$jsloads,$jsincs,$data,$id,$returnid,$tab,$message);
unset($funcs);
unset($data);
$jsall = tmtUtils::MergeJS($jsincs,$jsfuncs,$jsloads);
unset($jsincs);
unset($jsfuncs);
unset($jsloads);
tmtTemplate::Process($this,'addedit_comp.tpl',$tplvars);
if ($jsall) {
echo $jsall;
}
} else {
if (!empty($message))
$message .= '<br />/<br />'.$this->Lang('err_missing');
else
$message = $this->PrettyMessage('err_missing',FALSE);
$this->Redirect($id,'defaultadmin','',array('tmt_message'=>$message));
}