Przedszkolak
Postów: 62 Ostrzeżeń: 1
Data rejestracji: 28.10.2007 12:36
|
Wgrałem mod dodający galerię dla każdego użytkownika (możliwość tworzenia albumów i dodawania zdjęć). Problem w tym, że chciałbym aby pola "Tytuł (album_title)" i "Miniatura (album_thumb)" były obowiązkowe. Jak to zrobić?
Oto plik:userphotoalbums.php
<?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) 2002 - 2008 Nick Jones
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| USER's PHOTO ALBUMS for PHP-Fusion 7.00
| Filename: userphotoalbums.php
| Author: Sergei Gushchin (garry)
| e-mail:
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at http://www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
require_once "../maincore.php";
if (iSUPERADMIN) {
require_once THEMES."templates/admin_header.php";
} else {
require_once THEMES."templates/header.php";
}
require_once INCLUDES."photo_functions_include.php";
require_once INCLUDES."bbcode_include.php";
include LOCALE.LOCALESET."admin/photoalbums.php";
//if (!in_array(1, explode(".", iUSER_GROUPS))) redirect("../index.php");
define("SAFEMODE", @ini_get("safe_mode") ? true : false);
if (!defined("iUSERAUTH") || $_GET['uid'] != iUSERAUTH) redirect("../index.php");
if (isset($_GET['album_id']) && !isnum($_GET['album_id'])) redirect(FUSION_SELF.$uidlink);
if (!isset($_GET['rowstart']) || !isnum($_GET['rowstart'])) $_GET['rowstart'] = 0;
if (!isset($_GET['action'])) $_GET['action'] = "";
if (isset($_POST['cancel'])) {
redirect(FUSION_SELF.$uidlink);
}
//
if ($_GET['action']=="refresh") {
$i = 1; $k = 1;
$result = dbquery("SELECT album_id FROM ".DB_USERPHOTO_ALBUMS." WHERE album_user='".$userdata['user_id']."' ORDER BY album_order");
while ($data = dbarray($result)) {
$result2 = dbquery("UPDATE ".DB_USERPHOTO_ALBUMS." SET album_order='$i' WHERE album_id='".$data['album_id']."'");
$result2 = dbquery("SELECT photo_id FROM ".DB_USERPHOTOS." WHERE album_id='".$data['album_id']."' ORDER BY photo_order");
while ($data2 = dbarray($result2)) {
$result3 = dbquery("UPDATE ".DB_USERPHOTOS." SET photo_order='$k' WHERE photo_id='".$data2['photo_id']."'");
$k++;
}
$i++; $k = 1;
}
redirect(FUSION_SELF.$uidlink);
}
if (isset($_GET['status'])) {
if ($_GET['status'] == "savean") {
$title = $locale['400'];
$message = "<b>".$locale['410']."</b>";
} elseif ($_GET['status'] == "saveau") {
$title = $locale['401'];
$message = "<b>".$locale['411']."</b>";
} elseif ($_GET['status'] == "saveae") {
$title = $locale['403'];
$message = "<b>".$locale['414']."</b><br />\n";
if ($_GET['error'] == 1) { $message = $locale['415']; }
elseif ($_GET['error'] == 2) { $message = sprintf($locale['416'], parsebytesize($settings['photo_max_b'])); }
elseif ($_GET['error'] == 3) { $message = $locale['417']; }
elseif ($_GET['error'] == 4) { $message = sprintf($locale['418'], $settings['photo_max_w'], $settings['photo_max_h']); }
} elseif ($_GET['status'] == "delt") {
$title = $locale['401'];
$message = "<b>".$locale['412']."</b>";
} elseif ($_GET['status'] == "dely") {
$title = $locale['401'];
$message = "<b>".$locale['413']."</b>";
} elseif ($_GET['status'] == "deln") {
$title = $locale['403'];
$message = "<b>".$locale['403']."</b>";
}
opentable($title);
echo "<div align='center'>".$message."</div>\n";
closetable();
tablebreak();
}
if (isset($_POST['cancel'])) {
redirect(FUSION_SELF.$uidlink);
}
if ($_GET['action'] == "deletethumb") {
if (iSUPERADMIN) {
$data1 = dbquery("SELECT album_thumb,album_order FROM ".DB_USERPHOTO_ALBUMS." WHERE album_id='".$_GET['album_id']."'");
} else {
$data1 = dbquery("SELECT album_thumb,album_order FROM ".DB_USERPHOTO_ALBUMS." WHERE album_id='".$_GET['album_id']."' AND album_user='".$userdata['user_id']."'");
}
if (dbrows($data1) != 0) {
$data = dbarray($data1);
$result = dbquery("UPDATE ".DB_USERPHOTO_ALBUMS." SET album_thumb='$album_thumb' WHERE album_id='".$_GET['album_id']."'");
@unlink(PHOTOS.$data['album_thumb']);
redirect(FUSION_SELF.$uidlink."&status=delt&album_id=".$_GET['album_id']);
} else { redirect(FUSION_SELF.$uidlink);}
} elseif ($_GET['action'] == "delete") {
if (dbcount("(album_id)", DB_USERPHOTOS, "album_id='".$_GET['album_id']."'")) {
redirect(FUSION_SELF.$uidlink."&status=deln");
} else {
if (iSUPERADMIN) {
$data1 = dbquery("SELECT album_thumb,album_order FROM ".DB_USERPHOTO_ALBUMS." WHERE album_id='".$_GET['album_id']."'");
} else {
$data1 = dbquery("SELECT album_thumb,album_order FROM ".DB_USERPHOTO_ALBUMS." WHERE album_id='".$_GET['album_id']."' AND album_user='".$userdata['user_id']."'");
}
if (dbrows($data1) != 0) {
$data = dbarray($data1);
$result = dbquery("UPDATE ".DB_USERPHOTO_ALBUMS." SET album_order=(album_order-1) WHERE album_order>'".$data['album_order']."'");
$result = dbquery("DELETE FROM ".DB_USERPHOTO_ALBUMS." WHERE album_id='".$_GET['album_id']."'");
if ($data['album_thumb']) @unlink(PHOTOS.$data['album_thumb']);
if (!SAFEMODE) rmdir(PHOTOS."useralbum_".$_GET['album_id']);
redirect(FUSION_SELF.$uidlink."&status=dely");
} else { redirect(FUSION_SELF.$uidlink);}
}
} elseif ($_GET['action'] == "mup") {
if (!isnum($_GET['order'])) redirect(FUSION_SELF.$uidlink);
$data = dbarray(dbquery("SELECT album_id FROM ".DB_USERPHOTO_ALBUMS." WHERE album_order='".$_GET['order']."'"));
$result = dbquery("UPDATE ".DB_USERPHOTO_ALBUMS." SET album_order=album_order+1 WHERE album_id='".$data['album_id']."'");
$result = dbquery("UPDATE ".DB_USERPHOTO_ALBUMS." SET album_order=album_order-1 WHERE album_id='".$_GET['album_id']."'");
$rowstart = $_GET['order'] > $settings['thumbs_per_page'] ? ((ceil($_GET['order'] / $settings['thumbs_per_page'])-1)*$settings['thumbs_per_page']) : "0";
redirect(FUSION_SELF.$uidlink."&rowstart=$rowstart");
} elseif ($_GET['action'] == "mdown") {
if (!isnum($_GET['order'])) redirect(FUSION_SELF.$uidlink);
$data = dbarray(dbquery("SELECT album_id FROM ".DB_USERPHOTO_ALBUMS." WHERE album_order='".$_GET['order']."'"));
$result = dbquery("UPDATE ".DB_USERPHOTO_ALBUMS." SET album_order=album_order-1 WHERE album_id='".$data['album_id']."'");
$result = dbquery("UPDATE ".DB_USERPHOTO_ALBUMS." SET album_order=album_order+1 WHERE album_id='".$_GET['album_id']."'");
$rowstart = $_GET['order'] > $settings['thumbs_per_page'] ? ((ceil($_GET['order'] / $settings['thumbs_per_page'])-1)*$settings['thumbs_per_page']) : "0";
redirect(FUSION_SELF.$uidlink."&rowstart=$rowstart");
} elseif (isset($_POST['save_album'])) {
$error = "";
$album_title = stripinput($_POST['album_title']);
$album_access = isnum($_POST['album_access']) ? $_POST['album_access'] : "101";
$album_order = isnum($_POST['album_order']) ? $_POST['album_order'] : "";
if (!SAFEMODE && $_GET['action'] != "edit") {
$result = dbarray(dbquery("SHOW TABLE STATUS LIKE '".DB_USERPHOTO_ALBUMS."'"));
$album_id = $result['Auto_increment'];
@mkdir(PHOTOS."useralbum_".$album_id, 0777);
@copy(IMAGES."index.php", PHOTOS."useralbum_".$album_id."/index.php");
}
if (is_uploaded_file($_FILES['album_pic_file']['tmp_name'])) {
$album_types = array(".gif",".jpg",".jpeg",".png");
$album_pic = $_FILES['album_pic_file'];
$album_ext = strtolower(strrchr($album_pic['name'],"."));
if (!preg_match("/^[-0-9A-Z_\.\[\]\s]+$/i", $album_pic['name'])) {
$error = 1;
} elseif ($album_pic['size'] > $settings['photo_max_b']){
$error = 2;
} elseif (!in_array($album_ext, $album_types)) {
$error = 3;
} else {
@unlink(PHOTOS."temp".$album_ext);
move_uploaded_file($album_pic['tmp_name'], PHOTOS."temp".$album_ext);
chmod(PHOTOS."temp".$album_ext, 0644);
$imagefile = @getimagesize(PHOTOS."temp".$album_ext);
if ($imagefile[0] > $settings['photo_max_w'] || $imagefile[1] > $settings['photo_max_h']) {
$error = 4;
@unlink(PHOTOS."temp".$album_ext);
} else {
$album_thumb = image_exists(PHOTOS, $album_pic['name']);
createthumbnail($imagefile[2], PHOTOS."temp".$album_ext, PHOTOS.$album_thumb, $settings['thumb_w'], $settings['thumb_h']);
@unlink(PHOTOS."temp".$album_ext);
}
}
}
if (!$error) {
if ($_GET['action'] == "edit") {
$old_album_order = dbresult(dbquery("SELECT album_order FROM ".$db_prefix."photoalbums WHERE album_id='".$_GET['album_id']."'"),0);
if ($album_order > $old_album_order) {
$result = dbquery("UPDATE ".$db_prefix."photoalbums SET album_order=(album_order-1) WHERE album_order>'$old_album_order' AND album_order<='$album_order'");
} elseif ($album_order < $old_album_order) {
$result = dbquery("UPDATE ".$db_prefix."photoalbums SET album_order=(album_order+1) WHERE album_order<'$old_album_order' AND album_order>='$album_order'");
}
$result = dbquery("UPDATE ".DB_USERPHOTO_ALBUMS." SET album_title='$album_title',".(isset($album_thumb)?" album_thumb='$album_thumb',":"")." album_order='$album_order' WHERE album_id='".$_GET['album_id']."'");
$rowstart = $album_order > $settings['thumbs_per_page'] ? ((ceil($album_order / $settings['thumbs_per_page'])-1)*$settings['thumbs_per_page']) : "0";
redirect(FUSION_SELF.$uidlink."&status=saveau&rowstart=$rowstart");
} else {
if (!$album_order) $album_order = dbresult(dbquery("SELECT MAX(album_order) FROM ".DB_USERPHOTO_ALBUMS.""), 0) + 1;
$result = dbquery("UPDATE ".DB_USERPHOTO_ALBUMS." SET album_order=(album_order+1) WHERE album_order>='$album_order'");
$result = dbquery("INSERT INTO ".DB_USERPHOTO_ALBUMS." (album_title, album_thumb, album_user, album_order, album_datestamp) VALUES ('$album_title', '$album_thumb', '".$userdata['user_id']."', '$album_order', '".time()."')");
$rowstart = $album_order > $settings['thumbs_per_page'] ? ((ceil($album_order / $settings['thumbs_per_page'])-1)*$settings['thumbs_per_page']) : "0";
redirect(FUSION_SELF.$uidlink."&status=savean&rowstart=$rowstart");
}
} else {
redirect(FUSION_SELF.$uidlink."&status=saveae&error=$error");
}
} else {
if ($_GET['action'] == "edit") {
if (iSUPERADMIN) {
$result = dbquery("SELECT * FROM ".DB_USERPHOTO_ALBUMS." WHERE album_id='".$_GET['album_id']."'");
} else {
$result = dbquery("SELECT * FROM ".DB_USERPHOTO_ALBUMS." WHERE album_id='".$_GET['album_id']."' AND album_user='".$userdata['user_id']."'");
}
if (dbrows($result) != 0) {
$data = dbarray($result);
$album_title = $data['album_title'];
$album_thumb = $data['album_thumb'];
$album_access = $data['album_access'];
$album_order = $data['album_order'];
$formaction = FUSION_SELF.$uidlink."&action=edit&album_id=".$_GET['album_id'];
opentable($locale['401']);
} else { redirect(FUSION_SELF.$uidlink);}
} else {
$album_id = "";
$album_title = "";
$album_thumb = "";
$album_access = "";
$album_order = "";
$formaction = FUSION_SELF.$uidlink;
opentable($locale['400']);
}
$access_opts = ""; $sel = "";
$user_groups = getusergroups();
while(list($key, $user_group) = each($user_groups)){
$sel = ($album_access == $user_group['0'] ? " selected" : "");
$access_opts .= "<option value='".$user_group['0']."'$sel>".$user_group['1']."</option>\n";
}
echo "<form name='inputform' method='post' action='$formaction' enctype='multipart/form-data'>
<table align='center' cellspacing='0' cellpadding='0'>
<tr>
<td class='tbl'>".$locale['440']."</td>
<td class='tbl'><input type='textbox' name='album_title' value='$album_title' maxlength='100' class='textbox' style='width:330px;'></td>
</tr>
<tr>
<td valign='top' class='tbl'>".$locale['444'];
if ($_GET['action'] && $album_thumb && file_exists(PHOTOS.$album_thumb)) {
echo "<br /><br />\n<a class='small' href='".FUSION_SELF.$uidlink."&action=deletethumb&album_id=".$_GET['album_id']."'>".$locale['469']."</a></td>
<td class='tbl'><img src='".PHOTOS.$album_thumb."' alt='album_thumb'>";
} else {
echo "</td>\n<td class='tbl'><input type='file' name='album_pic_file' class='textbox' style='width:250px;'>";
}
echo "</td>
</tr>
<tr>
<td colspan='2' align='center' class='tbl'><br />
<input type='submit' name='save_album' value='".$locale['445']."' class='button'>\n";
if ($_GET['action']) {
echo "<input type='submit' name='cancel' value='".$locale['433']."' class='button'>\n";
}
echo "</td>\n</tr>\n</table>\n</form>\n";
closetable();
}
tablebreak();
opentable($locale['402']);
if (iSUPERADMIN) {
$rows = dbcount("(album_id)", DB_USERPHOTO_ALBUMS);
} else {
$rows = dbcount("(album_id)", DB_USERPHOTO_ALBUMS, "album_user='".$userdata['user_id']."'");
}
if ($rows) {
if (iSUPERADMIN) {
$result = dbquery(
"SELECT ta.*, tu.user_id,user_name FROM ".DB_USERPHOTO_ALBUMS." ta
LEFT JOIN ".DB_USERS." tu ON ta.album_user=tu.user_id
ORDER BY album_order LIMIT ".$_GET['rowstart'].",".$settings['thumbs_per_page']
);
} else {
$result = dbquery(
"SELECT ta.*, tu.user_id,user_name FROM ".DB_USERPHOTO_ALBUMS." ta
LEFT JOIN ".DB_USERS." tu ON ta.album_user=tu.user_id
WHERE album_user='".$userdata['user_id']."' ORDER BY album_order LIMIT ".$_GET['rowstart'].",".$settings['thumbs_per_page']
);
}
$counter = 0; $k = ($_GET['rowstart'] == 0 ? 1 : $_GET['rowstart'] + 1);
echo "<table cellpadding='0' cellspacing='1' width='100%'>\n<tr>\n";
while ($data = dbarray($result)) {
$up = ""; $down = "";
if ($rows != 1){
$orderu = $data['album_order'] - 1;
$orderd = $data['album_order'] + 1;
if ($k == 1){
$down = " ·\n<a href='".FUSION_SELF.$uidlink."&rowstart=".$_GET['rowstart']."&action=mdown&order=$orderd&album_id=".$data['album_id']."'><img src='".THEME."images/right.gif' alt='".$locale['467']."' title='".$locale['467']."' border='0' style='vertical-align:middle'></a>\n";
}elseif ($k < $rows){
$up = "<a href='".FUSION_SELF.$uidlink."&rowstart=".$_GET['rowstart']."&action=mup&order=$orderu&album_id=".$data['album_id']."'><img src='".THEME."images/left.gif' alt='".$locale['466']."' title='".$locale['466']."' border='0' style='vertical-align:middle'></a> ·\n";
$down = " ·\n<a href='".FUSION_SELF.$uidlink."&rowstart=".$_GET['rowstart']."&action=mdown&order=$orderd&album_id=".$data['album_id']."'><img src='".THEME."images/right.gif' alt='".$locale['467']."' title='".$locale['467']."' border='0' style='vertical-align:middle'></a>\n";
} else {
$up = "<a href='".FUSION_SELF.$uidlink."&rowstart=".$_GET['rowstart']."&action=mup&order=$orderu&album_id=".$data['album_id']."'><img src='".THEME."images/left.gif' alt='".$locale['466']."' title='".$locale['466']."' border='0' style='vertical-align:middle'></a> ·\n";
}
}
if ($counter != 0 && ($counter % $settings['thumbs_per_row'] == 0)) echo "</tr>\n<tr>\n";
echo "<td align='center' valign='top' class='tbl'>\n";
echo "<b>".$data['album_title']."</b><br /><br />\n<a href='userphotos.php".$uidlink."&album_id=".$data['album_id']."'>";
if ($data['album_thumb'] && file_exists(PHOTOS.$data['album_thumb'])){
echo "<img src='".PHOTOS.$data['album_thumb']."' alt='".$locale['460']."' border='0'>";
} else {
echo $locale['461'];
}
echo "</a><br /><br />\n<span class='small'>".$up;
echo "<a href='".FUSION_SELF.$uidlink."&action=edit&album_id=".$data['album_id']."'>".$locale['468']."</a> ·\n";
echo "<a href='".FUSION_SELF.$uidlink."&action=delete&album_id=".$data['album_id']."'>".$locale['469']."</a> ".$down;
echo "<br /><br />\n".$locale['462'].showdate("shortdate", $data['album_datestamp'])."<br />\n";
echo $locale['463']."<a href='".BASEDIR."profile.php?lookup=".$data['user_id']."'>".$data['user_name']."</a><br />\n";
echo $locale['464'].getgroupname($data['album_access'])."<br />\n";
echo $locale['465'].dbcount("(photo_id)", DB_USERPHOTOS, "album_id='".$data['album_id']."'")."</span><br />\n";
echo "</td>\n";
$counter++; $k++;
}
echo "</tr>\n<tr>\n<td align='center' colspan='".$settings['thumbs_per_row']."' class='tbl2'><a href='".FUSION_SELF.$uidlink."&action=refresh'>".$locale['470']."</a></td>\n</tr>\n</table>\n";
if ($rows > $settings['thumbs_per_page']) echo "<div align='center' style='margin-top:5px;'>\n".makePageNav($_GET['rowstart'],$settings['thumbs_per_page'],$rows,3,FUSION_SELF.$uidlink."&")."\n</div>\n";
}else{
echo "<center>".$locale['471']."</center>\n";
}
closetable();
require_once THEMES."templates/footer.php";
?>
Edytowane przez babilon dnia 25.06.2009 20:14:42
|