-
Notifications
You must be signed in to change notification settings - Fork 28
/
admin_group_edit.php
280 lines (242 loc) · 7.39 KB
/
admin_group_edit.php
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
<?php
require_once("bootstrap.inc.php");
require_once("include_pouet/box-modalmessage.php");
require_once("include_pouet/box-group-submit.php");
require_once("include_pouet/pouet-box-editbase.php");
if ($currentUser && !$currentUser->CanEditItems())
{
redirect("groups.php?which=".(int)$_GET["which"]);
exit();
}
class PouetBoxAdminEditGroup extends PouetBoxSubmitGroup
{
public $id;
public $group;
function __construct( $id )
{
parent::__construct();
$this->id = (int)$id;
$this->group = PouetGroup::Spawn( $this->id );
$this->title = "edit this group: ". $this->group->RenderLong();
}
use PouetForm;
function Commit($data)
{
global $groupID;
$a = array();
$a["name"] = trim($data["name"]);
$a["acronym"] = $data["acronym"];
$a["disambiguation"] = $data["disambiguation"];
$a["web"] = $data["website"];
$a["csdb"] = (int)$data["csdbID"];
// $a["zxdemo"] = $data["zxdemoID"];
$a["demozoo"] = (int)$data["demozooID"];
SQLLib::UpdateRow("groups",$a,"id=".$this->id);
gloperator_log( "group", $this->id, "group_edit" );
return array();
}
function LoadFromDB()
{
parent::LoadFromDB();
$group = $this->group;
$this->fields["name"]["value"] = $group->name;
$this->fields["acronym"]["value"] = $group->acronym;
$this->fields["disambiguation"]["value"] = $group->disambiguation;
$this->fields["website"]["value"] = $group->web;
$this->fields["csdbID"]["value"] = $group->csdb;
//$this->fields["zxdemoID"]["value"] = $group->zxdemo;
$this->fields["demozooID"]["value"] = $group->demozoo;
}
}
///////////////////////////////////////////////////////////////////////////////
class PouetBoxAdminEditGroupAffil extends PouetBoxEditConnectionsBase
{
public $id;
public $types;
public $group;
public static $slug = "BoardAffil";
function __construct( $group )
{
parent::__construct();
$this->uniqueID = "pouetbox_groupeditaffil";
$this->group = $group;
$this->id = $group->id;
$this->title = "board affiliations links";
$this->headers = array("board","type");
$row = SQLLib::selectRow("DESC affiliatedboards type");
$this->types = enum2array($row->Type);
$s = new BM_Query();
$s->AddField("affiliatedboards.id");
$s->AddField("affiliatedboards.type");
$s->AddTable("affiliatedboards");
$s->attach(array("affiliatedboards"=>"board"),array("boards as board"=>"id"));
$s->AddField("affiliatedboards_board.id as affiliatedboards_board_id");
$s->AddWhere(sprintf_esc("`group`=%d",$this->group->id));
$this->data = $s->perform();
}
use PouetForm;
function Commit($data)
{
if (@$data["delBoardAffil"])
{
SQLLib::Query("delete from affiliatedboards where id=".(int)$data["delBoardAffil"]);
gloperator_log( "group", (int)$this->group->id, "group_affil_del" );
return array();
}
$a = array();
$a["board"] = $data["board"];
$a["type"] = $data["type"];
if (@$data["editBoardAffilID"])
{
SQLLib::UpdateRow("affiliatedboards",$a,"id=".(int)$data["editBoardAffilID"]);
$a["id"] = $data["editBoardAffilID"];
gloperator_log( "group", (int)$this->group->id, "group_affil_edit", array("id"=>$a["id"]) );
}
else
{
$a["group"] = $this->group->id;
$a["id"] = SQLLib::InsertRow("affiliatedboards",$a);
gloperator_log( "group", (int)$this->group->id, "group_affil_add", array("id"=>$a["id"]) );
}
if (@$data["partial"])
{
$o = toObject($a);
$o->board = PouetBoard::Spawn($a["board"]);
$this->RenderNormalRow($o);
$this->RenderNormalRowEnd($o);
exit();
}
return array();
}
function RenderEditRow($row = null)
{
echo " <td><input name='board' value='"._html($row?$row->board->id:"")."'/></td>\n";
// echo " <td><input name='type' value='"._html($row->type)."'/></td>\n";
echo " <td><select name='type'>\n";
foreach($this->types as $v)
printf("<option%s>%s</option>",($row&&$row->type==$v)?" selected='selected'":"",_html($v));
echo "</select></td>\n";
}
function RenderNormalRow($v)
{
echo " <td>"._html($v->board->name)."</td>\n";
echo " <td>"._html($v->type)."</td>\n";
}
function RenderBody()
{
parent::RenderBody();
?>
<script>
<!--
document.observe("dom:loaded",function(){
InstrumentAdminEditorForAjax( $("pouetbox_groupeditaffil"), "groupBoardAffil", {
onRowLoad: function(tr){
new Autocompleter(tr.down("[name='board']"), {"dataUrl":"./ajax_boards.php"});
}
} );
});
//-->
</script>
<?php
}
}
///////////////////////////////////////////////////////////////////////////////
class PouetBoxAdminDeleteGroup extends PouetBox
{
public $group;
public $checkString;
function __construct( $group )
{
parent::__construct();
$this->uniqueID = "pouetbox_groupdelete";
$this->classes[] = "errorbox";
$this->group = $group;
global $verificationStrings;
$this->checkString = $verificationStrings[ array_rand($verificationStrings) ];
$this->title = "delete this group: ".$group->RenderLong();
}
use PouetForm;
function Validate($data)
{
if ($data["check"] != $data["checkOrig"])
return array("wrong verification string !");
return array();
}
function Commit($data)
{
$this->group->Delete();
gloperator_log( "group", (int)$this->group->id, "group_delete", get_object_vars($this->group) );
return array();
}
function RenderBody()
{
echo "<div class='content'/>";
echo " <p>To make sure you want to delete <b>this</b> group, type \"".$this->checkString."\" here:</p>";
echo " <input name='checkOrig' type='hidden' value='"._html($this->checkString)."'/>";
echo " <input id='check' name='check' autocomplete='no'/>";
echo "</div>";
echo "<div class='foot'/>";
echo " <input type='submit' value='Submit' />";
echo "</div>";
?>
<script>
document.observe("dom:loaded",function(){
$("pouetbox_groupdelete").up("form").observe("submit",function(e){
if ($F("check") != "<?=_js($this->checkString)?>")
{
alert("Enter the verification string!");
e.stop();
return;
}
if (!confirm("ARE YOU REALLY SURE YOU WANT TO DELETE \"<?=_js($this->group->name)?>\"?!"))
e.stop();
});
});
</script>
<?php
}
}
$boxen = array(
"PouetBoxAdminEditGroupAffil",
);
if(@$_GET["partial"] && $currentUser && $currentUser->CanEditItems())
{
// ajax responses
$group = new stdClass();
$group->id = $_GET["which"];
foreach($boxen as $class)
{
$box = new $class( $group );
$box->RenderPartialResponse();
}
exit();
}
$form = new PouetFormProcessor();
$form->SetSuccessURL( "groups.php?which=".(int)$_GET["which"], true );
$box = new PouetBoxAdminEditGroup( $_GET["which"] );
if ($box->group)
{
$form->Add( "group", $box );
$form->Add( "groupaffil", new PouetBoxAdminEditGroupAffil( $box->group ) );
$form->Add( "groupdelete", new PouetBoxAdminDeleteGroup( $box->group ) );
if ($currentUser && $currentUser->CanEditItems())
$form->Process();
$TITLE = "edit a group: ".$box->group->name;
}
require_once("include_pouet/header.php");
require("include_pouet/menu.inc.php");
echo "<div id='content'>\n";
if (get_login_id())
{
$form->Display();
}
else
{
require_once("include_pouet/box-login.php");
$box = new PouetBoxLogin();
$box->Render();
}
echo "</div>\n";
require("include_pouet/menu.inc.php");
require_once("include_pouet/footer.php");
?>