| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
// Edit existing icons ... |
|---|
| 6 |
if (isset($_POST['action']) && $_POST['action'] == "icons:edit" && logged_on) { |
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
if (isset($_POST['defaulticon'])) { |
|---|
| 11 |
$icondefault = (int) $_POST['defaulticon']; |
|---|
| 12 |
if ($icondefault == -1) { |
|---|
| 13 |
db_query("update users set icon = -1 where ident = " . $_SESSION['userid']); |
|---|
| 14 |
$_SESSION['icon'] = "default.png"; |
|---|
| 15 |
} else { |
|---|
| 16 |
$iconfilename = db_query("select filename from icons where ident = $icondefault and owner = " . $_SESSION['userid']); |
|---|
| 17 |
if (sizeof($iconfilename) == 1) { |
|---|
| 18 |
$iconfilename = $iconfilename[0]->filename; |
|---|
| 19 |
$_SESSION['icon'] = $iconfilename; |
|---|
| 20 |
db_query("update users set icon = $icondefault where ident = " . $_SESSION['userid']); |
|---|
| 21 |
} |
|---|
| 22 |
} |
|---|
| 23 |
} |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
if (isset($_POST['description']) && sizeof($_POST['description'] > 0)) { |
|---|
| 28 |
foreach($_POST['description'] as $iconid => $newdescription) { |
|---|
| 29 |
$iconid = (int) $iconid; |
|---|
| 30 |
$newdescription = addslashes($newdescription); |
|---|
| 31 |
$result = db_query("select description from icons where ident = $iconid and owner = " . $_SESSION['userid']); |
|---|
| 32 |
if (sizeof($result) > 0) { |
|---|
| 33 |
if ($result[0]->description != $newdescription) { |
|---|
| 34 |
db_query("update icons set description = '$newdescription' where ident = $iconid"); |
|---|
| 35 |
} |
|---|
| 36 |
} |
|---|
| 37 |
} |
|---|
| 38 |
} |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
if (isset($_POST['icons_delete'])) { |
|---|
| 43 |
if (sizeof($_POST['icons_delete']) > 0) { |
|---|
| 44 |
foreach($_POST['icons_delete'] as $delete_icon) { |
|---|
| 45 |
$delete_icon = (int) $delete_icon; |
|---|
| 46 |
$result = db_query("select filename from icons where ident = $delete_icon and owner = " . $_SESSION['userid']); |
|---|
| 47 |
if (sizeof($result) == 1) { |
|---|
| 48 |
db_query("delete from icons where ident = $delete_icon"); |
|---|
| 49 |
@unlink(path . "_icons/data/" . $result[0]->filename); |
|---|
| 50 |
} |
|---|
| 51 |
if ($result[0]->filename = $_SESSION['icon']) { |
|---|
| 52 |
db_query("update users set icon = -1 where ident = " . $_SESSION['userid']); |
|---|
| 53 |
$_SESSION['icon'] = "default.png"; |
|---|
| 54 |
} |
|---|
| 55 |
} |
|---|
| 56 |
$messages[] = "Your selected icons were deleted."; |
|---|
| 57 |
} |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
if (isset($_POST['action']) && $_POST['action'] == "icons:add" && logged_on) { |
|---|
| 64 |
|
|---|
| 65 |
if (isset($_POST['icondescription']) && isset($_POST['icondefault']) |
|---|
| 66 |
&& isset($_FILES['iconfile']['name'])) { |
|---|
| 67 |
|
|---|
| 68 |
$messages[] = "Attempting to upload icon file ..."; |
|---|
| 69 |
|
|---|
| 70 |
$ok = true; |
|---|
| 71 |
$templocation = $_FILES['iconfile']['tmp_name']; |
|---|
| 72 |
|
|---|
| 73 |
if ($_FILES['iconfile']['size'] >= 30000 || $_FILES['iconfile']['size'] == 0) { |
|---|
| 74 |
$messages[] = "The uploaded icon file was too large. The limit is 30k."; |
|---|
| 75 |
$ok = false; |
|---|
| 76 |
} |
|---|
| 77 |
if ($ok == true) { |
|---|
| 78 |
$numicons = db_query("select count(ident) as numicons from icons where owner = " . $_SESSION['userid']); |
|---|
| 79 |
$numicons = (int) $numicons[0]->numicons; |
|---|
| 80 |
if ($numicons >= $_SESSION['icon_quota']) { |
|---|
| 81 |
$ok = false; |
|---|
| 82 |
$messages[] = "You have already met your icon quota. You must delete some icons before you can upload any new ones."; |
|---|
| 83 |
} |
|---|
| 84 |
} |
|---|
| 85 |
if ($ok == true) { |
|---|
| 86 |
$imageattr = @getimagesize($templocation); |
|---|
| 87 |
if ($imageattr == false) { |
|---|
| 88 |
$ok = false; |
|---|
| 89 |
$messages[] = "The uploaded icon file was invalid. Please ensure you are using JPEG, GIF or PNG files."; |
|---|
| 90 |
} |
|---|
| 91 |
} |
|---|
| 92 |
if ($ok == true) { |
|---|
| 93 |
if ($imageattr[0] > 100 || $imageattr[1] > 100) { |
|---|
| 94 |
$ok = false; |
|---|
| 95 |
$messages[] = "The uploaded icon file was too large. Files must have maximum dimensions of 100x100."; |
|---|
| 96 |
} |
|---|
| 97 |
} |
|---|
| 98 |
if ($ok == true && ($imageattr[2] > 3 || $imageattr[2] < 1)) { |
|---|
| 99 |
$message[] = "The uploaded icon file was in an image format other than JPEG, GIF or PNG. These are unsupported at present."; |
|---|
| 100 |
} else if ($ok == true) { |
|---|
| 101 |
switch($imageattr[2]) { |
|---|
| 102 |
case "1": $file_extension = ".gif"; |
|---|
| 103 |
break; |
|---|
| 104 |
case "2": $file_extension = ".jpg"; |
|---|
| 105 |
break; |
|---|
| 106 |
case "3": $file_extension = ".png"; |
|---|
| 107 |
break; |
|---|
| 108 |
} |
|---|
| 109 |
$save_file = $_SESSION['userid'] . "_" . time() . $file_extension; |
|---|
| 110 |
$save_location = path . "_icons/data/" . $save_file; |
|---|
| 111 |
if (move_uploaded_file($_FILES['iconfile']['tmp_name'], $save_location)) { |
|---|
| 112 |
|
|---|
| 113 |
@chmod($save_location,0644); |
|---|
| 114 |
$filedescription = addslashes($_POST['icondescription']); |
|---|
| 115 |
db_query("insert into icons set filename = '$save_file', owner = " . $_SESSION['userid'] . ", description = '$filedescription'"); |
|---|
| 116 |
if ($_POST['icondefault'] == "yes") { |
|---|
| 117 |
$ident = (int) db_id(); |
|---|
| 118 |
db_query("update users set icon = $ident where ident = " . $_SESSION['userid']); |
|---|
| 119 |
$_SESSION['icon'] = $save_file; |
|---|
| 120 |
} |
|---|
| 121 |
$messages[] = "Your icon was uploaded successfully."; |
|---|
| 122 |
|
|---|
| 123 |
} else { |
|---|
| 124 |
$messages[] = "An unknown error occurred when saving your icon. If this problem persists, please let us know and we'll do all we can to fix it quickly."; |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
} |
|---|
| 128 |
|
|---|
| 129 |
} |
|---|
| 130 |
|
|---|
| 131 |
} |
|---|
| 132 |
|
|---|
| 133 |
?> |
|---|