-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.process_items.php
More file actions
252 lines (243 loc) · 6.93 KB
/
Copy pathaction.process_items.php
File metadata and controls
252 lines (243 loc) · 6.93 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
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
<?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
Processes form-submission from admin brackets tab
*/
if(isset($params['cancel']) || empty($params['selitems']))
$this->Redirect($id,'defaultadmin');
elseif(isset($params['clone']))
{
if (!$this->CheckAccess('admod'))
$this->Redirect($id,'defaultadmin','',
array('tmt_message'=>$this->PrettyMessage('lackpermission',FALSE)));
$vals = array_flip($params['selitems']); //convert strings
$vals = array_flip($vals);
if($vals)
{
$funcs = new tmtClone();
$res = $funcs->CloneBracket($this,$vals);
if($res !== TRUE)
$this->Redirect($id,'defaultadmin','',
array('tmt_message'=>$this->PrettyMessage($res,FALSE)));
}
}
elseif(isset($params['group'])) //begin grouping process
{
$tplvars = array(
'start_form' => $this->CreateFormStart($id,'process_items',$returnid),
'end_form' => $this->CreateFormEnd(),
'hidden' => $this->CreateInputHidden($id,'selitems',implode(';',$params['selitems'])),
'title' => $this->Lang('title_bracketsgroup')
);
$options = $this->GetGroups();
if($options)
{
foreach($options as &$row)
$row = $row['name'];
unset($row);
$options = array_flip($options);
}
else
$options = array($this->Lang('groupdefault')=>0); //ensure something exists
$options = array($this->Lang('select_one')=>-1) + $options;
$tplvars += array(
'chooser' => $this->CreateInputDropdown($id,'togroup',$options,-1,-1),
'apply' => $this->CreateInputSubmitDefault($id,'apply',$this->Lang('apply')),
'cancel' => $this->CreateInputSubmit($id,'cancel', $this->Lang('cancel')),
'help' => NULL //$this->Lang('help_bracketsgroup'))
);
tmtTemplate::Process($this,'onepage.tpl',$tplvars);
return;
}
elseif(isset($params['apply'])) //selected group
{
$gid = (int)$params['togroup']; //new group choice
if($gid != -1)
{
$vals = array_flip(explode(';',$params['selitems'])); //convert strings
$vals = array_flip($vals);
$vc = count($vals);
$fillers = str_repeat('?,',$vc-1).'?';
$pref = cms_db_prefix();
$sql = 'UPDATE '.$pref.'module_tmt_brackets SET groupid=? WHERE bracket_id IN ('.$fillers.')';
array_unshift($vals,$gid);
$db->Execute($sql,$vals);
}
}
elseif(isset($params['delete_item'])) //delete selected bracket(s)
{
if (!$this->CheckAccess('admod'))
$this->Redirect($id,'defaultadmin','',
array('tmt_message'=>$this->PrettyMessage('lackpermission',FALSE)));
$vals = array_flip($params['selitems']); //convert strings
$vals = array_flip($vals);
if($vals)
{
$funcs = new tmtDelete();
$funcs->DeleteBracket($this,$vals);
}
}
elseif(isset($params['notify']))
{
$vals = array_flip($params['selitems']); //convert strings
$vals = array_flip($vals);
if($vals)
{
$vc = count($vals);
$fillers = str_repeat('?,',$vc-1).'?';
$pref = cms_db_prefix();
$sql = 'SELECT match_id,bracket_id FROM '.$pref.'module_tmt_matches WHERE bracket_id IN ('.$fillers.
') AND flags=0 AND status<'.Tourney::MRES.
' AND playwhen IS NOT NULL AND ((teamA IS NOT NULL AND teamA>0) OR (teamB IS NOT NULL AND teamB>0))';
$matches = $db->GetAssoc($sql,$vals);
if($matches)
{
$allmsg = '';
$sql = 'UPDATE '.$pref.'module_tmt_matches SET status='.Tourney::TOLD.' WHERE match_id=?';
$funcs = new tmtComm($this);
foreach($matches as $mid=>$bid)
{
list($res,$errmsg) = $funcs->TellTeams((int)$bid,$mid,1); //1 >> announcement template
if($res)
$db->Execute($sql,array($mid));
elseif($errmsg)
{
if($allmsg)
$allmsg .= '<br />';
$allmsg .= $errmsg;
}
}
if($allmsg)
$this->Redirect($id,'defaultadmin','',
array('tmt_message'=>$this->PrettyMessage($allmsg,FALSE,FALSE,FALSE)));
}
}
}
elseif(isset($params['print']))
{
$vals = array_flip($params['selitems']); //convert strings
$vals = array_flip($vals);
if($vals)
{
$pref = cms_db_prefix();
$sql = 'SELECT * FROM '.$pref.'module_tmt_brackets WHERE bracket_id=?';
$sql2 = 'UPDATE '.$pref.'module_tmt_brackets SET chartbuild = 1 WHERE bracket_id=?';
$sch = new tmtSchedule();
$lyt = new tmtLayout();
$message = '';
$onefile = (count($vals) == 1);
if($onefile)
$zip = FALSE;
else
{
//charts in nominal tmp directory (ignore where runtime-root actually is)
$fn = 'brackets-charts-'.implode('-',$vals).'.zip';
$fp = cms_join_path($config['root_path'],'tmp',$fn);
$zip = new ZipArchive();
if($zip->open($fp,ZipArchive::CREATE) !== TRUE)
{
$message = $this->PrettyMessage('err_zip',FALSE);
$this->Redirect($id,'defaultadmin','',array('tmt_message'=>$message));
}
}
foreach($vals as $bid)
{
$bdata = $db->GetRow($sql,array($bid));
//refresh the matches table, if necessary
switch ($bdata['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;
}
$bdata['chartbuild'] = 1; //tell downstream that rebuild is needed
list($chartfile,$errkey) = $lyt->GetChart($this,$bdata,FALSE,0);
if($chartfile)
{
//force refresh next time
$db->Execute($sql2,array($bid));
if(!$onefile && is_file($chartfile))
{
$zip->addFile($chartfile,basename($chartfile));
//cannot delete $chartfile yet
}
}
else
{
if(!$message)
$message = $this->PrettyMessage('err_chart',FALSE);
$message .= '<br />'.$bdata['name'];
if($errkey)
$message .= ': '.$this->Lang($errkey);
}
}
unset($sch);
unset($lyt);
if($onefile)
{
if($chartfile && is_file($chartfile))
{
//export $chartfile
$content = file_get_contents($chartfile);
$fn = basename($chartfile);
$ft = 'application/pdf';
}
else
$content = FALSE;
}
elseif($zip)
{
$zip->close();
if(is_file($fp))
{
$content = file_get_contents($fp);
unlink($fp);
$ft = 'application/zip';
}
else
$content = FALSE;
}
if($content)
{
@ob_clean();
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate,post-check=0,pre-check=0');
header('Cache-Control: private',FALSE);
header('Content-Description: File Transfer');
header('Content-Type: '.$ft);
header('Content-Length: '.strlen($content));
header('Content-Disposition: attachment; filename="'.$fn.'"');
echo $content;
if(!$message)
exit;
$this->Redirect($id,'defaultadmin','',array('tmt_message'=>$message));
}
}
}
elseif(isset($params['export']))
{
$vals = array_flip($params['selitems']); //convert strings
$vals = array_flip($vals);
if($vals)
{
$funcs = new tmtXML();
$res = $funcs->ExportXML($this,$params['selitems']);
if ($res === TRUE)
exit;
$this->Redirect($id,'defaultadmin','',
array('tmt_message'=>$this->PrettyMessage($res,FALSE)));
}
}
$this->Redirect($id,'defaultadmin');
?>