-
Notifications
You must be signed in to change notification settings - Fork 28
/
account.php
689 lines (614 loc) · 20.1 KB
/
account.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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
<?php
require_once("bootstrap.inc.php");
require_once("include_generic/countries.inc.php");
require_once("include_pouet/box-modalmessage.php");
$COUNTRIES = array_merge(array(""),$COUNTRIES);
$avatars = glob(POUET_CONTENT_LOCAL."avatars/*.gif");
$success = null;
$namesNumeric = array(
// numbers
"indextopglops" => "front page - top glops",
"indextopprods" => "front page - top prods (recent)",
"indextopkeops" => "front page - top prods (all-time)",
"indexoneliner" => "front page - oneliner",
"indexlatestadded" => "front page - latest added",
"indexlatestreleased" => "front page - latest released",
"indexojnews" => "front page - bitfellas news",
"indexlatestcomments" => "front page - latest comments",
"indexlatestparties" => "front page - latest parties",
"indexbbstopics" => "front page - bbs topics",
"indexwatchlist" => "front page - watchlist",
"bbsbbstopics" => "bbs page - bbs topics",
"prodlistprods" => "prodlist page - prods",
"userlistusers" => "userlist page - users",
"searchprods" => "search page - prods",
"userlogos" => "user page - logos",
"userprods" => "user page - prods",
"usergroups" => "user page - groups",
"userparties" => "user page - parties",
"userscreenshots" => "user page - screenshots",
"usernfos" => "user page - nfos",
"usercomments" => "user page - comments",
"userrulez" => "user page - rulez",
"usersucks" => "user page - sucks",
"commentshours" => "comments page - hours",
"topicposts" => "topic page - posts",
);
$namesSwitch = array(
//select
"logos" => "logos",
"topbar" => "top bar",
"bottombar" => "bottom bar",
"indexcdc" => "front page - cdc",
"indexsearch" => "front page - search",
"indexstats" => "front page - stats",
"indexlinks" => "front page - links",
"indexplatform" => "front page - show platform icons",
"indextype" => "front page - show type icons",
"indexwhoaddedprods" => "front page - who added prods",
"indexwhocommentedprods" => "front page - who commented prods",
"topichidefakeuser" => "bbs page - hide fakeuser",
"prodhidefakeuser" => "prod page - hide fakeuser",
"displayimages" => "[img][/img] tags should be displayed as...",
"indexbbsnoresidue" => "residue threads on the front page are...",
);
class PouetBoxAccount extends PouetBox
{
public $formifier;
public $maxCDCs;
public $cdcs;
public $ims;
public $user;
public $fieldsPouet;
public $fieldsOtherSites;
public $fieldsCDC;
public $imTypes;
public $fieldsIM;
public $sceneID;
function __construct()
{
parent::__construct();
$this->uniqueID = "pouetbox_account";
$this->title = "e-e-e-edit your account";
$this->formifier = new Formifier();
$this->maxCDCs = 20;
}
function LoadFromDB()
{
global $COUNTRIES;
$this->cdcs = array();
$query = new BM_Query( "users" );
$query->AddExtendedFields();
// foreach(PouetUser::getExtendedFields() as $v)
// $query->AddField("users.".$v);
$query->AddWhere(sprintf_esc("users.id = %d",get_login_id()));
$query->SetLimit(1);
$s = new BM_Query();
$s->AddTable("users_im");
$s->AddWhere(sprintf_esc("users_im.userID = %d",get_login_id()));
$this->ims = $s->perform();
$s = $query->perform();
$this->user = reset( $s );
$rows = SQLLib::SelectRows(sprintf_esc("select cdc from users_cdcs where user=%d",get_login_id()));
foreach($rows as $r)
$this->cdcs[] = $r->cdc;
$this->fieldsPouet = array(
"nickname"=>array(
"info"=>"how do you look on IRC ?",
"required"=>true,
"value"=>$this->user->nickname,
"maxlength"=>16,
),
"avatar"=>array(
"info"=>"your faaaaaaace is like a song",
"required"=>true,
"value"=>$this->user->avatar,
"type"=>"avatar",
"infoAfter"=>"<span id='avatarCount'></span> (<a href='submit_avatar.php'>upload new</a>) <span id='randomAvatar'></span> <span id='avatarPicker'></span>",
)
);
$this->fieldsOtherSites = array(
"slengpung"=>array(
"info"=>"your slengpung id, if you have one",
"value"=>$this->user->slengpung,
"type"=>"number",
),
"csdb"=>array(
"info"=>"your csdb id, if you have one",
"value"=>$this->user->csdb,
"type"=>"number",
),
"zxdemo"=>array(
"info"=>"your zxdemo id, if you have one",
"value"=>$this->user->zxdemo,
"type"=>"number",
),
"demozoo"=>array(
"info"=>"your demozoo id, if you have one",
"value"=>$this->user->demozoo,
"type"=>"number",
),
);
$this->fieldsCDC = array();
$glop = POUET_CDC_MINGLOP;
for ($x=1; $x < $this->maxCDCs; $x++)
{
/*
$cdcText = array(
"your favorite",
"you love this when you're drunk",
"the one on that weird platform",
"",
"",
"",
"",
"",
"",
"",
);
*/
if ($this->user->glops >= $glop)
{
$this->fieldsCDC["cdc".$x] = array(
"value" => @$this->cdcs[$x-1],
"name" => "coup de coeur ".$x." (".$glop." glöps)",
//"info" => $cdcText[$x], // is this cool?
);
$glop *= 2;
}
else
{
break;
}
}
$this->fieldsCDC["cdc".($x-1)]["infoAfter"] = sprintf("you currently have %d glöps and need %d more for the next cdc !",$this->user->glops,$glop - $this->user->glops);
$row = SQLLib::SelectRow("DESC users_im im_type");
$this->imTypes = enum2array($row->Type);
$this->ims[] = new stdClass();
$this->fieldsIM = array();
$n = 0;
foreach($this->ims as $im)
{
$this->fieldsIM["im_type".$n] = array(
//"info"=>"the one you really use",
"name"=>"contact type",
"type"=>"select",
"value"=>@$im->im_type,
"fields"=>$this->imTypes,
);
$this->fieldsIM["im_id".$n] = array(
//"info"=>"buuuuuuuuuuuuuuuu .... hiho !",
"name"=>"contact address",
"value"=>@$im->im_id,
"maxlength"=>255,
);
$n++;
}
$this->sceneID = $this->user->GetSceneIDData(false);
global $namesNumeric;
global $namesSwitch;
if ($_POST)
{
foreach($_POST as $k=>$v)
{
if (@$this->fieldsPouet[$k]) $this->fieldsPouet[$k]["value"] = $v;
if (@$this->fieldsOtherSites[$k]) $this->fieldsOtherSites[$k]["value"] = $v;
if (@$this->fieldsCDC[$k]) $this->fieldsCDC[$k]["value"] = $v;
}
}
}
function ParsePostLoggedIn( $data )
{
global $currentUser;
$errors = array();
// cdc bit
$cdcUnique = array();
$glop = POUET_CDC_MINGLOP;
for ($x=1; $x < $this->maxCDCs; $x++)
{
if ($this->user->glops >= $glop && $data["cdc".$x])
{
$cdcUnique[] = $data["cdc".$x];
}
$glop *= 2;
}
$cdcUnique = array_unique($cdcUnique);
SQLLib::Query(sprintf_esc("delete from users_cdcs where user = %d",get_login_id()));
foreach($cdcUnique as $c)
{
$a = array();
$a["user"] = get_login_id();
$a["cdc"] = $c;
SQLLib::InsertRow("users_cdcs",$a);
}
// im bit
global $IM_TYPES;
SQLLib::Query(sprintf_esc("delete from users_im where userID = %d",get_login_id()));
for ($n = 0; $n < count($this->imTypes); $n++)
{
$a = array();
$a["userID"] = get_login_id();
$a["im_type"] = @$data["im_type".$n];
$imUser = @$data["im_id".$n];
if (@$IM_TYPES[$a["im_type"]])
{
if (preg_match("/".$IM_TYPES[$a["im_type"]]["capture"]."/",$imUser,$m))
{
$imUser = $m[1];
}
else
{
continue;
}
}
$a["im_id"] = $imUser;
if ($a["im_type"] && $a["im_id"])
{
SQLLib::InsertRow("users_im",$a);
}
}
// pouet bit
global $avatars;
$sql = array();
foreach ($this->fieldsPouet as $k=>$v)
{
if ($k == "nickname" && !trim($data[$k])) continue;
//if (trim($data[$k]))
$sql[$k] = trim($data[$k]);
}
foreach ($this->fieldsOtherSites as $k=>$v)
{
$sql[$k] = (int)trim($data[$k]);
}
if (!$sql["avatar"] || !file_exists(POUET_CONTENT_LOCAL . "avatars/".$sql["avatar"]))
$sql["avatar"] = basename( $avatars[ array_rand($avatars) ] );
SQLLib::UpdateRow("users",$sql,"id=".(int)get_login_id());
if ($currentUser->nickname != $data["nickname"])
{
$a = array();
$a["user"] = $currentUser->id;
$a["nick"] = $currentUser->nickname;
SQLLib::InsertRow("oldnicks",$a);
}
// customizer bit
global $avatars;
global $success;
if (!$errors) $success = "modifications complete!";
return $errors;
}
use PouetForm;
function ParsePostMessage( $data )
{
if (!get_login_id())
return array("You have to be logged in!");
$errors = array();
$data["nickname"] = strip_tags($data["nickname"]);
$data["nickname"] = trim($data["nickname"]);
if (strlen($data["nickname"]) < 2)
{
$errors[] = "nick too short!";
return $errors;
}
if (!$errors)
{
$this->LoadFromDB();
$errors = $this->ParsePostLoggedIn( $data );
}
// $this->LoadFromDB();
return $errors;
}
function Render()
{
global $currentUser;
echo "\n\n";
echo "<div class='pouettbl' id='".$this->uniqueID."'>\n";
echo " <h2>".$this->title."</h2>\n";
// sceneid
echo " <div class='accountsection content'>\n";
echo " <div class='formifier'>\n";
echo " <div class=\"row\">\n";
echo " <label>your current profile:</label>\n";
echo " <p>".$currentUser->PrintLinkedAvatar()." ".$currentUser->PrintLinkedName()."</p>\n";
echo " </div>\n";
echo " <div class=\"row\">\n";
echo " <label>first name:</label>\n";
echo " <p><b>"._html(@$this->sceneID["first_name"])."</b> (<a href='https://id.scene.org/profile/'>edit</a>)</p>\n";
echo " </div>\n";
echo " <div class=\"row\">\n";
echo " <label>last name:</label>\n";
echo " <p><b>"._html(@$this->sceneID["last_name"])."</b> (<a href='https://id.scene.org/profile/'>edit</a>)</p>\n";
echo " </div>\n";
echo " <div class=\"row\">\n";
echo " <label>password:</label>\n";
echo " <p><a href='https://id.scene.org/profile/'>change</a></p>\n";
echo " </div>\n";
echo " </div>\n";
echo " </div>\n";
echo " <h2>pouët things</h2>\n";
echo " <div class='accountsection content'>\n";
$this->formifier->RenderForm( $this->fieldsPouet );
echo " </div>\n";
if ($this->fieldsIM)
{
echo " <h2>contact details</h2>\n";
echo " <div class='accountsection content account-ims'>\n";
echo " <p class='infoAfter'>note: whatever you specify here will be hidden for users who are logged out</p>\n";
$this->formifier->RenderForm( $this->fieldsIM );
echo " </div>\n";
}
echo " <h2>other sites</h2>\n";
echo " <div class='accountsection content'>\n";
$this->formifier->RenderForm( $this->fieldsOtherSites );
echo " </div>\n";
if ($this->fieldsCDC)
{
echo " <h2>coup de coeurs</h2>\n";
echo " <div class='accountsection content account-cdcs'>\n";
$this->formifier->RenderForm( $this->fieldsCDC );
echo " </div>\n";
}
echo " <div class='foot'><input type='submit' value='Submit' /></div>";
echo "</div>\n";
}
};
class PouetBoxAccountModificationRequests extends PouetBox
{
public $requests;
function __construct( )
{
parent::__construct();
$this->uniqueID = "pouetbox_accountreq";
$this->title = "your most recent modification requests";
}
use PouetForm;
function LoadFromDB()
{
global $currentUser;
$s = new BM_Query();
$s->AddTable("modification_requests");
$s->AddField("modification_requests.id");
$s->AddField("modification_requests.requestType");
$s->AddField("modification_requests.itemID");
$s->AddField("modification_requests.itemType");
$s->AddField("modification_requests.requestBlob");
$s->AddField("modification_requests.requestDate");
$s->AddField("modification_requests.approved");
$s->AddField("modification_requests.comment");
//$s->Attach(array("modification_requests"=>"gloperatorID"),array("users as gloperator"=>"id"));
$s->Attach(array("modification_requests"=>"itemID"),array("prods as prod"=>"id"));
$s->Attach(array("modification_requests"=>"itemID"),array("groups as group"=>"id"));
$s->AddWhere(sprintf_esc("userID = %d",$currentUser->id));
$s->AddOrder("requestDate desc");
$s->SetLimit( @$_GET["limit"] ?: 10 );
$this->requests = $s->perform();
}
function Render()
{
global $REQUESTTYPES;
echo "<table id='".$this->uniqueID."' class='boxtable'>\n";
echo " <tr>\n";
echo " <th colspan='4'>".$this->title."</th>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <th>date</th>\n";
echo " <th>item</th>\n";
echo " <th>request</th>\n";
echo " <th>approved?</th>\n";
echo " </tr>\n";
foreach($this->requests as $r)
{
echo " <tr>\n";
echo " <td>".$r->requestDate."</td>\n";
echo " <td>".$r->itemType.": ";
switch ($r->itemType)
{
case "prod": if ($r->prod) echo $r->prod->RenderSingleRowShort(); break;
case "group": if ($r->group) echo $r->group->RenderLong(); break;
}
echo "</td>\n";
if ($REQUESTTYPES[$r->requestType])
echo " <td>".$REQUESTTYPES[$r->requestType]::Describe()."</td>\n";
else
echo " <td>unknown request type</td>";
echo " <td>";
if ( $r->approved === NULL ) echo "<b>pending</b>";
else if ( $r->approved == 0 ) echo "<b>no</b> :: "._html($r->comment);
else if ( $r->approved == 1 ) echo "<b>yes</b>";
echo "</td>\n";
echo " </tr>\n";
}
echo "</table>\n";
}
}
class PouetBoxAccountProdAwardSuggestions extends PouetBox
{
public $votes;
function __construct( )
{
parent::__construct();
$this->uniqueID = "pouetbox_accountawardsug";
$this->title = "your current award recommendations";
}
use PouetForm;
function LoadFromDB()
{
global $AWARDSSUGGESTIONS_EVENTS;
global $AWARDSSUGGESTIONS_CATEGORIES;
$cats = array();
$date = date("Y-m-d");
foreach($AWARDSSUGGESTIONS_CATEGORIES as $category)
{
$event = $AWARDSSUGGESTIONS_EVENTS[$category->eventID];
if ($event->votingStartDate <= $date && $date <= $event->votingEndDate)
{
$cats[] = (int)$category->id;
}
}
global $currentUser;
if ($cats)
{
$s = new BM_Query();
$s->AddTable("awardssuggestions_votes");
$s->AddField("awardssuggestions_votes.categoryID");
$s->AddWhere(sprintf("userID = %d and categoryID in (%s)",$currentUser->id,implode(",",$cats)));
$s->Attach(array("awardssuggestions_votes"=>"prodID"),array("prods as prod"=>"id"));
$this->votes = $s->perform();
}
}
function Render()
{
global $AWARDSSUGGESTIONS_EVENTS;
global $AWARDSSUGGESTIONS_CATEGORIES;
if (!$this->votes)
{
return;
}
echo "<table id='".$this->uniqueID."' class='boxtable'>\n";
echo " <tr>\n";
echo " <th colspan='4'>".$this->title."</th>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <th>category</th>\n";
echo " <th>prod</th>\n";
echo " </tr>\n";
foreach($this->votes as $v)
{
$category = $AWARDSSUGGESTIONS_CATEGORIES[$v->categoryID];
$event = $AWARDSSUGGESTIONS_EVENTS[$category->eventID];
echo " <tr>\n";
echo " <td>"._html($event->name)." - "._html($category->name)."</td>\n";
echo " <td>".$v->prod->RenderSingleRowShort(). "</td>\n";
echo " </tr>\n";
}
echo "</table>\n";
}
};
///////////////////////////////////////////////////////////////////////////////
if (!get_login_id())
{
require_once("include_pouet/header.php");
require("include_pouet/menu.inc.php");
$message = new PouetBoxModalMessage(false,true);
$message->classes[] = "errorbox";
$message->title = "An error has occured:";
$message->message = "You need to be logged in for this!";
$message->Render();
}
else
{
$form = new PouetFormProcessor();
//if (!get_login_id())
// $form->successMessage = "registration complete! a confirmation mail will be sent to your address soon - you can't login until you confirmed your email address!";
$form->SetSuccessURL( "user.php?who=".$currentUser->id, true );
$account = new PouetBoxAccount();
$form->Add( "account", $account );
$form->Add( "accountReq", new PouetBoxAccountModificationRequests() );
$form->Add( "accountAwardSug", new PouetBoxAccountProdAwardSuggestions() );
$form->Process();
$TITLE = "account!";
require_once("include_pouet/header.php");
require("include_pouet/menu.inc.php");
echo "<div id='content'>\n";
$form->Display();
echo "</div>\n";
?>
<script>
<!--
document.observe("dom:loaded",function(){
if (!$("avatarlist"))
return;
var updateAvatarCount = function()
{
var avatar = $("avatar").options[ $("avatar").selectedIndex ].value;
new Ajax.Request("ajax_avatar.php",{
"parameters" : {"avatar":avatar},
"onException": function(r, e) { throw e; },
"onSuccess": function(transport)
{
if (transport.responseJSON && transport.responseJSON.avatarCount)
{
var c = parseInt(transport.responseJSON.avatarCount,10);
if (c == 0)
{
$("avatarCount").update("(this avatar is unique !)");
}
else if (c == 1)
{
$("avatarCount").update("(only one other person uses this avatar !)");
}
else
{
$("avatarCount").update("(this avatar is used by "+c+" other people !)");
}
}
},
});
}
var updateAvatar = function()
{
$("avatarimg").src = "<?=POUET_CONTENT_URL?>avatars/" + $("avatar").options[ $("avatar").selectedIndex ].value;
updateAvatarCount();
}
var img = new Element("img",{"id":"avatarimg","width":16,"height":16});
$("avatarlist").insertBefore(img,$("avatar"));
updateAvatar();
$("avatarlist").observe("change",updateAvatar);
$("avatarlist").observe("keyup",updateAvatar);
$("randomAvatar").update("(<a href='#'>pick random</a>)")
$("randomAvatar").down("a").observe("click",function(ev){
ev.stop();
$("avatar").selectedIndex = Math.floor( Math.random() * $("avatar").options.length );
updateAvatar();
});
var div = new Element("div",{"id":"avatarPickerPalette"})
$("avatarPicker").parentNode.insert(div);
div.insert( new Element("a",{"href":"#"}).observe("click",function(e){
regeneratePalette();
}).update("show more") );
div.insert( new Element("a",{"href":"#","id":"avatarPickerClose"}).observe("click",function(e){
$("avatarPickerPalette").hide();
}).update("close") );
div.insert( new Element("div",{"id":"paletteAvatars"}) );
var regeneratePalette = function()
{
$("paletteAvatars").update();
for (var i=0; i<100; i++)
{
var src = $("avatar").options[ Math.floor( Math.random() * $("avatar").options.length ) ].value;
var img = new Element("img",{"src":"<?=POUET_CONTENT_URL?>avatars/" + src,"data-src":src,"title":src});
$("paletteAvatars").insert( img );
img.observe("click",function(ev){
$("avatar").value = ev.element().getAttribute("data-src");
updateAvatar();
$("avatarPickerPalette").hide();
});
}
}
regeneratePalette();
$("avatarPicker").update("(<a href='#'>show picker</a>)")
$("avatarPickerPalette").hide();
$("avatarPicker").down("a").observe("click",function(ev){
ev.stop();
$("avatarPickerPalette").show();
});
for (var i=1; i<<?=$account->maxCDCs?>; i++)
{
if (!$("cdc"+i)) continue;
new Autocompleter($("cdc"+i), {
"dataUrl":"./ajax_prods.php",
"width":320,
"processRow": function(item) {
var s = item.name.escapeHTML();
if (item.groupName) s += " <small class='group'>" + item.groupName.escapeHTML() + "</small>";
return s;
}
});
}
});
//-->
</script>
<?php
}
require("include_pouet/menu.inc.php");
require_once("include_pouet/footer.php");
?>