Przedszkolak
Postów: 10
Data rejestracji: 27.02.2011 21:16
|
Potrzebował bym modyfikacji kodu w pliku "announcements.php" tak aby dodatkowo po kliknięciu na dodaj ogłoszenie wyświetlało się zwykłe zabezpieczenie Captcha. Próbowałem przenieść jakoś część kodu z plików contact.php i register.php ale coś mi nie wychodzi :|.
Kod:<?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) 2002 - 2010 Nick Jones
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Annouuncements infusion
| Author: Mateusz Sieprawski
| Email:
| Web:
+--------------------------------------------------------+
| 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";
require_once THEMES."templates/header.php";
include INFUSIONS."announcements/infusion_db.php";
require_once INCLUDES."bbcode_include.php";
if (file_exists(INFUSIONS."announcements/locale/".$settings['locale'].".php")) {
include INFUSIONS."announcements/locale/".$settings['locale'].".php";
}
else {
include INFUSIONS."announcements/locale/English.php";
}
// przydatne funkcje
function ciach($string, $lenght) {
if(strlen($string) > $lenght) {
$string = substr($string, 0, $lenght);
$string .= "...";
return $string;
}
else {
return $string;
}
}
function getUser($id) {
$count = dbcount("(user_id)", DB_USERS, "user_id='".$id."'");
if($count > 0) {
$sql = dbquery("SELECT * FROM `".DB_USERS."` WHERE `user_id` = '".$id."'");
$user = dbarray($sql);
return $user['user_name'];
}
else {
return false;
}
}
function getAnnCat($id) {
global $locale;
$information = $locale['ANN_017'];
$count = dbcount("(id)", ANNS_CATS, "id='".$id."'");
if($count > 0) {
$sql = dbquery("SELECT * FROM `".ANNS_CATS."` WHERE `id` = '".$id."'");
$cat = dbarray($sql);
return $cat['title'];
}
else {
return $information.": id = ".$id;
}
}
function getExtension($filename) {
$table = explode(".", $filename);
$count = count($table);
$extension = $table[$count-1];
return $extension;
}
function getFilename($filename) {
$table = explode(".", $filename);
$count = count($table);
$number = 0;
$we = "";
while($count > 1) {
if($count == 2) {
$we .= $table[$number];
}
else {
$we .= $table[$number].".";
}
$count--;
$number++;
}
return $we;
}
function scaleImage($location, $maxw=NULL, $maxh=NULL, $style=NULL){
$img = @getimagesize($location);
if($img){
$w = $img[0];
$h = $img[1];
$dim = array('w','h');
foreach($dim AS $val){
$max = "max{$val}";
if(${$val} > ${$max} && ${$max}){
$alt = ($val == 'w') ? 'h' : 'w';
$ratio = ${$alt} / ${$val};
${$val} = ${$max};
${$alt} = ${$val} * $ratio;
}
}
if($style == NULL) {
return("<img src='{$location}' alt='image' width='{$w}' height='{$h}' />");
}
else {
return("<img src='{$location}' alt='image' width='{$w}' height='{$h}' class='image-slider' />");
}
}
}
// zaladowanie bilbioteki jquery
echo '<script type="text/javascript" src="'.INFUSIONS.'announcements/js/jquery-1.4.2.min.js"></script>';
// zaladowanie biblioteki UI do jquery
echo '<script type="text/javascript" src="'.INFUSIONS.'announcements/js/jquery-ui-1.8.4.custom.min.js"></script>';
// zaladowanie colorbox'a
echo '<script type="text/javascript" src="'.INFUSIONS.'announcements/js/jquery.colorbox-min.js"></script>';
// zaladowanie pliku odpowiedzialnego za upload
echo '<script type="text/javascript" src="'.INFUSIONS.'announcements/js/jquery.MultiFile.js"></script>';
// zaladowanie pliku sterujacego akcjami javascript
echo '<script type="text/javascript" src="'.INFUSIONS.'announcements/js/main.js"></script>';
// zaladowanie pliku ze stylami colorbox'a
echo '<link rel="stylesheet" href="'.INFUSIONS.'announcements/colorbox.css" type="text/css" media="all" />';
// zaladowanie pliku ze stylami biblioteki UI
echo '<link rel="stylesheet" href="'.INFUSIONS.'announcements/jquery-ui-1.8.4.custom.css" type="text/css" media="all" />';
?>
<script type="text/javascript">
$(function() {
var availableTags = [
<?php
$sql = dbquery("SELECT DISTINCT `title` FROM `".ANNS."`");
while($tag = dbarray($sql)) {
echo '"'.$tag['title'].'",';
}
?>];
$("#tags").autocomplete({
source: availableTags
});
$("a[rel='mini-gallery']").colorbox({
transition: "fade",
close: "<?php echo $locale['ANN_060']; ?>",
next: "<?php echo $locale['ANN_061']; ?>",
previous: "<?php echo $locale['ANN_062']; ?>",
current: "",
scalePhotos: true,
maxWidth: "800px",
maxHeight: "600px"
});
$("#accordion").accordion();
});
</script>
<script type="text/javascript">
function checkData() {
var data_missing = false;
var form_ann = document.forms["inputform_ann"];
var message = "";
if(form_ann.title.value == "") {
message += "<?php echo $locale['ANN_013']; ?>\n";
data_missing = true;
}
if(form_ann.body.value == "") {
message += "<?php echo $locale['ANN_032']; ?>\n";
data_missing = true;
}
if(form_ann.author.value == "") {
message += "<?php echo $locale['ANN_043']; ?>\n";
data_missing = true;
}
if(form_ann.phone.value == "") {
message += "<?php echo $locale['ANN_034']; ?>\n";
data_missing = true;
}
if(!data_missing) {
return true;
}
else {
alert("<?php echo $locale['ANN_048']; ?>\n" + message);
return false;
}
}
</script>
<?php
if(isSet($_POST['save_ann'])) {
$add_ann = 1;
$how_much_files = 0;
$title = mysql_escape_string(stripinput($_POST['title']));
$cat_id = mysql_escape_string(stripinput($_POST['cat_id']));
$author = mysql_escape_string(stripinput($_POST['author']));
$body = mysql_escape_string(stripinput($_POST['body']));
$phone = mysql_escape_string(stripinput($_POST['phone']));
$email = mysql_escape_string(stripinput($_POST['email']));
foreach ($_FILES['photos']['error'] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$filename = mysql_escape_string(stripinput($_FILES['photos']['name'][$key]));
$extension = getExtension($filename);
if(($extension !== "jpg") && ($extension !== "jpeg") && ($extension !== "png") && ($extension !== "gif") && ($extension !== "bmp")) {
$add_ann = 0;
}
$how_much_files++;
}
else {
$add_ann = 1;
$how_much_files++;
}
}
if(($add_ann == 1) && ($how_much_files < 6)) {
$sql = dbquery("INSERT INTO `".ANNS."` VALUES (NULL, '".$cat_id."', '".$title."', '".$body."', '".$email."', '".$phone."', '".$author."', '".time()."')");
if($sql) {
$ann_id_photo = mysql_insert_id();
$information = $locale['ANN_045']."<a href='".INFUSIONS."announcements/announcements.php?show_ann=".$ann_id_photo."'>".$locale['ANN_051']."</a>";
foreach ($_FILES['photos']['error'] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$filename = mysql_escape_string(stripinput($_FILES['photos']['name'][$key]));
$filename_tmp = mysql_escape_string(stripinput($_FILES['photos']['tmp_name'][$key]));
$filesize = $_FILES['photos']['size'][$key] / 1024;
$bad_chars = array('Ä…', 'Ĺź', 'Ĺ›', 'Ĺş', 'Ä™', 'ć', 'Ĺ„', 'Ăł', 'Ĺ‚', 'Îą', 'Îś', 'Ď‚', 'Ď', 'χ', 'ε', 'δ', 'Ď', 'Ď', 'φ', 'ω', 'Ď„', 'Îł', 'β', 'Ď…', 'η', 'ν', 'θ', 'Îľ', 'Îź', 'Îą', 'Îş', 'Îż', 'λ', 'Ď€', 'Α', 'Ζ', 'ÎŁ', 'Χ', 'Ε', 'Δ', 'Ψ', 'ÎĄ', 'ÎŚ', 'Ω', 'Τ', 'Γ', 'Î’', 'ÎĄ', 'Η', 'Îť', 'Î', 'Ξ', 'Îś', 'Ι', 'Κ', 'Îź', 'Λ', 'Î ');
$good_chars = array('a', 'z', 's', 'z', 'e', 'c', 'n', 'o', 'l', 'a', 'z', 'w', 's', 'x', 'e', 'd', 'c', 'r', 'f', 'v', 't', 'g', 'b', 'y', 'u', 'n', 'u', 'j', 'm', 'i', 'k', 'o', 'l', 'p', 'A', 'Z', 'S', 'X', 'E', 'D', 'C', 'P', 'F', 'O', 'T', 'G', 'B', 'Y', 'H', 'N', 'U', 'J', 'M', 'I', 'K', 'O', 'L', 'P');
$filename = str_replace($bad_chars, $good_chars, $filename);
$extension = getExtension($filename);
$filename_we = getFilename($filename);
if(file_exists(ANNS_IMAGES.$filename)) {
while(file_exists(ANNS_IMAGES.$filename_we.".".$extension)) {
$filename_we .= rand(10, 99);
}
}
$filename = $filename_we.".".$extension;
$dir = ANNS_IMAGES.$filename;
if(move_uploaded_file($_FILES['photos']['tmp_name'][$key], $dir)) {
chmod($dir, 0644);
$sql = dbquery("INSERT INTO `".ANNS_PHOTOS."` VALUES (NULL, '".$ann_id_photo."', '".$filename."', '".time()."')");
}
}
}
}
}
elseif($add_ann == 0) {
$information = $locale['ANN_063'];
}
elseif($how_much_files > 5) {
$information = $locale['ANN_064'];
}
else {
$information = $locale['ANN_065'];
}
}
if(isSet($information)) {
opentable($locale['ANN_018']);
echo '<div style="width: 100%; text-align: center;padding: 10px 10px 10px 10px;"><b>'.$information.'</b></div>';
closetable();
}
echo "<div id='add_ann_form' style='display: none'>";
opentable($locale['ANN_042']);
echo "<form onSubmit='return checkData();' enctype='multipart/form-data' name='inputform_ann' action='".FUSION_SELF."' method='POST'>";
echo "<table cellspacing='0' cellpadding='0' class='tbl-border center' style='padding: 10px 10px 10px 10px;'>";
echo "<tr>";
echo "<td class='tbl1'>".$locale['ANN_013']."</td>";
echo "<td class='tbl1'><input type='text' class='textbox' style='width: 200px;' name='title' /></td>";
echo "</tr>";
echo "<tr>";
echo "<td class='tbl1'>".$locale['ANN_014']."</td>";
echo "<td class='tbl1'><select class='textbox' style='width: 200px;' name='cat_id'>";
$sql_cat = dbquery("SELECT * FROM `".ANNS_CATS."`");
while($cat = dbarray($sql_cat)) {
echo "<option value='".$cat['id']."'>".$cat['title']."</option>";
}
echo "</select></td>";
echo "</tr>";
echo "<tr>";
echo "<td class='tbl1'>".$locale['ANN_043']."</td>";
echo "<td class='tbl1'>";
if(iMEMBER) {
echo "<input type='hidden' name='author' value='".$userdata['user_id']."' />".$userdata['user_name'];
}
else {
echo "<input type='text' class='textbox' style='width: 200px;' name='author' />";
}
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class='tbl1' valign='top'>".$locale['ANN_032']."</td>";
echo "<td class='tbl1'><textarea class='textbox' style='width: 200px; height: 90px;' name='body'></textarea>";
echo display_bbcodes("200px;", "body", "inputform_ann", "smiley|b|u|url|color");
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class='tbl1'>".$locale['ANN_033']."</td>";
echo "<td class='tbl1'><input type='text' class='textbox' style='width: 200px;' name='email' /></td>";
echo "</tr>";
echo "<tr>";
echo "<td class='tbl1'>".$locale['ANN_034']."</td>";
echo "<td class='tbl1'><input type='text' class='textbox' style='width: 200px;' name='phone' /></td>";
echo "</tr>";
echo "<tr>";
echo "<td class='tbl1' valign='top'>".$locale['ANN_036']."</td>";
echo "<td class='tbl1'>";
echo "<input type='file' class='multi' maxlength='8' accept='gif|jpg|bmp|jpeg|png|php' name='photos[]' id='photos' />";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class='tbl1'></td>";
echo "<td class='tbl1' style='text-align: right;'><input type='submit' class='button' name='save_ann' value='".$locale['ANN_029']."' /></td>";
echo "</tr>";
echo "</table>";
echo "</form>";
closetable();
echo "</div>";
if(isSet($_GET['show_ann'])) {
$id = mysql_escape_string(stripinput($_GET['show_ann']));
if(isnum($id)) {
$count = dbcount("(id)", ANNS, "id='".$id."'");
if($count > 0) {
opentable($locale['ANN_046']);
$sql = dbquery("SELECT * FROM `".ANNS."` WHERE `id` = '".$id."'");
$ann = dbarray($sql);
if(!getUser($ann['author'])) {
$author = $ann['author'];
}
else {
$author = '<a href="'.BASEDIR.'profile.php?lookup='.$ann['author'].'">'.getUser($ann['author']).'</a>';
}
$category = getAnnCat($ann['cat_id']);
echo '<table cellspacing="1" cellpadding="0" class="tbl-border center" style="margin-top: 30px;margin-bottom: 30px;">';
echo '<tr>';
echo '<td colspan="4" style="padding-left: 10px;"><h2>'.$ann['title'].'</h2></td>';
echo '</tr>';
echo '<tr>';
echo '<td class="tbl2">'.$locale['ANN_013'].'</td><td class="tbl2">'.$ann['title'].'</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="tbl1">'.$locale['ANN_014'].'</td><td class="tbl1">'.$category.'</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="tbl2">'.$locale['ANN_008'].'</td><td class="tbl2">'.strftime("%d/%m/%Y %H:%M", $ann['date']).'</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="tbl1">'.$locale['ANN_032'].'</td><td class="tbl1">'.parsesmileys(parseubb(nl2br($ann['body']))).'</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="tbl2">'.$locale['ANN_043'].'</td><td class="tbl2">'.$author.'</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="tbl1">'.$locale['ANN_033'].'</td><td class="tbl1">'.$ann['email'].'</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="tbl2">'.$locale['ANN_034'].'</td><td class="tbl2">'.$ann['phone'].'</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="tbl1">'.$locale['ANN_036'].'</td>';
echo '<td class="tbl1">';
$photos = dbcount("(id)", ANNS_PHOTOS, "ann_id='".$ann['id']."'");
if($photos > 0) {
echo '<div id="accordion">';
$sql = dbquery("SELECT * FROM `".ANNS_PHOTOS."` WHERE `ann_id` = '".$ann['id']."'");
$image = 1;
while($photo = dbarray($sql)) {
echo '<h3><a href="#">'.$locale['ANN_047'].' '.$image.'</a></h3>';
echo "<div>";
echo "<center><a href='".ANNS_IMAGES.$photo['photo']."' rel='mini-gallery'>".scaleImage(ANNS_IMAGES.$photo['photo'], 350, 200, 1)."</a></center>\n";
echo "<p>";
echo $locale['ANN_008'].": <b>".strftime("%d/%m/%Y", $photo['date'])." ".strftime("%H:%M", $photo['date'])."</b>";
echo "</p>";
echo "</div>";
$image++;
}
echo '</div>';
}
else {
echo $locale['ANN_039'];
}
echo '</td>';
echo '</tr>';
echo '</table>';
closetable();
}
else {
$information = $locale['ANN_052'];
}
}
}
opentable($locale['ANN_040']);
$count = dbcount("(id)", ANNS_CATS);
if($count > 0) {
$count = dbcount("(id)", ANNS);
if($count > 0) {
echo '<center><div style="margin-bottom: 10px;margin-top: 10px;padding-left: 20px;"><a href="#" id="add_ann">'.$locale['ANN_042'].'</a></center>';
echo '<table cellspacing="1" cellpadding="0" class="tbl2 center" style="margin-top: 30px;padding-left: 30px;padding-right: 30px;padding-top: 10px;padding-bottom: 10px;">';
echo '<tr><td>';
echo '<form action="'.FUSION_SELF.'" method="GET">';
echo $locale['ANN_053'].'<input id="tags" type="text" name="ann_title" class="textbox" style="margin-left: 20px;width: 150px;" />';
echo '<select name="ann_cat" class="textbox" style="width: 150px; margin-left: 10px;">';
$sql = dbquery("SELECT * FROM `".ANNS_CATS."`");
while($cat = dbarray($sql)) {
echo '<option value="'.$cat['id'].'">'.$cat['title'].'</option>';
}
echo '</select>';
echo '<input type="submit" class="button" value="'.$locale['ANN_053'].'" style="margin-left: 10px;" name="search" />';
echo '</form>';
echo '</td></tr>';
echo '</table>';
echo '<table cellspacing="1" cellpadding="0" class="tbl-border center" style="margin-top: 30px;">';
echo '<tr>';
echo '<td colspan="4" style="padding-left: 10px;"><h2>'; if(isSet($_POST['search'])) { echo $locale['ANN_054']; } else { echo $locale['ANN_040']; } echo '</h2></td>';
echo '</tr>';
echo '<tr>';
echo '<td class="tbl2"><b>'.$locale['ANN_013'].'</b></td>';
echo '<td class="tbl2"><b>'.$locale['ANN_014'].'</b></td>';
echo '<td class="tbl2"><b>'.$locale['ANN_043'].'</b></td>';
echo '<td class="tbl2"><b>'.$locale['ANN_008'].'</b></td>';
echo '</tr>';
if(isSet($_GET['search'])) {
if(isSet($_GET['rowstart'])) {
$rowstart = $_GET['rowstart'];
}
else {
$rowstart = 0;
}
$text = mysql_escape_string(stripinput($_GET['ann_title']));
$cat_id = mysql_escape_string(stripinput($_GET['ann_cat']));
$sql_count = dbquery("SELECT * FROM `".ANNS."` WHERE `title` LIKE '%".$text."%' AND `cat_id` = '".$cat_id."' ORDER BY `title` DESC");
$sql = dbquery("SELECT * FROM `".ANNS."` WHERE `title` LIKE '%".$text."%' AND `cat_id` = '".$cat_id."' ORDER BY `title` DESC LIMIT ".$rowstart.",10");
$found = mysql_num_rows($sql_count);
$color = 1;
while($ann = dbarray($sql)) {
if(!getUser($ann['author'])) {
$author = $ann['author'];
}
else {
$author = '<a href="'.BASEDIR.'profile.php?lookup='.$ann['author'].'">'.getUser($ann['author']).'</a>';
}
$category = getAnnCat($ann['cat_id']);
echo '<tr>';
echo '<td class="tbl'; if($color%2) { echo 1; } else { echo 2; } echo '"><a href="'.FUSION_SELF.'?show_ann='.$ann['id'].'">'.$ann['title'].'</a></td>';
echo '<td class="tbl'; if($color%2) { echo 1; } else { echo 2; } echo '">'.$category.'</td>';
echo '<td class="tbl'; if($color%2) { echo 1; } else { echo 2; } echo '">'.$author.'</td>';
echo '<td class="tbl'; if($color%2) { echo 1; } else { echo 2; } echo '">'.strftime("%d/%m/%Y %H:%M", $ann['date']).'</td>';
echo '</tr>';
$color++;
}
if($found == 0) {
echo '<tr><td colspan="4" style="padding: 10px 10px 10px 10px;">'.$locale['ANN_055'].'</td></tr>';
}
echo '</table>';
if($found > 10) {
echo "<div style='width: 100%;text-align: right; margin-top: 20px;'>".makepagenav($rowstart, 10, $found, 3, "?ann_title=".$text."&ann_cat=".$cat_id."&search&")."</div>";
}
}
else {
if(isSet($_GET['rowstart'])) {
$rowstart = $_GET['rowstart'];
}
else {
$rowstart = 0;
}
$color = 1;
$sql = dbquery("SELECT * FROM `".ANNS."` ORDER BY `date` DESC LIMIT ".$rowstart.",10");
while($ann = dbarray($sql)) {
if(!getUser($ann['author'])) {
$author = $ann['author'];
}
else {
$author = '<a href="'.BASEDIR.'profile.php?lookup='.$ann['author'].'">'.getUser($ann['author']).'</a>';
}
$category = getAnnCat($ann['cat_id']);
echo '<tr>';
echo '<td class="tbl'; if($color%2) { echo 1; } else { echo 2; } echo '"><a href="'.FUSION_SELF.'?show_ann='.$ann['id'].'">'.$ann['title'].'</a></td>';
echo '<td class="tbl'; if($color%2) { echo 1; } else { echo 2; } echo '">'.$category.'</td>';
echo '<td class="tbl'; if($color%2) { echo 1; } else { echo 2; } echo '">'.$author.'</td>';
echo '<td class="tbl'; if($color%2) { echo 1; } else { echo 2; } echo '">'.strftime("%d/%m/%Y %H:%M", $ann['date']).'</td>';
echo '</tr>';
$color++;
}
echo '</table>';
$count = dbcount("(id)", ANNS);
if($count > 10) {
echo "<div style='width: 100%;text-align: right; margin-top: 20px;'>".makepagenav($rowstart, 10, $count, 3)."</div>";
}
}
}
else {
echo '<center><div style="margin-bottom: 10px;margin-top: 10px;padding-left: 20px;"><a href="#" id="add_ann">'.$locale['ANN_042'].'</a></center>';
echo '<div style="width: 100%; text-align: center;padding: 10px 10px 10px 10px;"><b>'.$locale['ANN_012'].'</b></div>';
}
}
else {
echo '<div style="width: 100%; text-align: center;padding: 10px 10px 10px 10px;"><b>'.$locale['ANN_041'].'</b></div>';
}
closetable();
require_once THEMES."templates/footer.php";
?>
|