Voting Modul von Kummer for acquire
Verfasst: Fr 20. Aug 2004, 09:39
Ich habe das Voting modul von Kummer (Du machst eine klasse Arbeit mein Guter, mußte mal gesagt werden) ein wenig erweitert. Das Modul generiert die benötigte Tabelle selbst in der DB mit dem dort gewählten Prefix. und es wird eine Dynamisch erzeugte Grafik angezeigt. Zu sehen auf
http://www.thilo-sommer.de/playground/f ... 1&client=1
Modul Input:
Modul Output:
Und dann noch die Datei für die Grafik: muss heißen: stat.bar.php und sollte im Mandantenverzeichnis gespeichert werden.
In diesem Sinne....
http://www.thilo-sommer.de/playground/f ... 1&client=1
Modul Input:
Code: Alles auswählen
/***********************************************
* CONTENIDO MODUL - INPUT
*
* Modulname : w3concepts.voting.v1.1
* Author : Andreas Kummer
* Copyright : mumprecht & kummer w3concepts
* Created : 21-07-2004
* Modified : 10-08-2004 by Peter Beauvain
************************************************/
// configuration
$cfg["tab"]["vote"] = $cfg['sql']['sqlprefix']."_vote"; // for syntax reasons only
if($db->query("SELECT * FROM ".$cfg["tab"]["vote"]." WHERE pk_voting = 1")) {
// do something table exists
echo "Works...";
} else {
echo "error-> table: ".$cfg["tab"]["vote"]." does not exist<br>";
// init table creation
$sql= "CREATE TABLE ".$cfg["tab"]["vote"]." (
pk_voting int(10) unsigned NOT NULL auto_increment,
fk_idart int(10) unsigned NOT NULL default '0',
ip varchar(15) NOT NULL default '',
time date NOT NULL default '0000-00-00',
vote tinyint(4) NOT NULL default '0',
PRIMARY KEY (pk_voting)
) TYPE=MyISAM;";
if ($db->query($sql)) {
// table successfully created
echo "init-> created table: ".$cfg["tab"]["vote"]."<br>";
} else {
echo "error-> table: ".$cfg["tab"]["vote"]."<br>";
}
}
echo "<table cellspacing=\"0\" cellpadding=\"10\" border=\"0\"><tr valign=\"top\">";
echo "<tr><td>Voting einschalten:</td>";
if ("CMS_VALUE[0]" == 1) {
echo "<td><div><input type=\"radio\" name=\"CMS_VAR[0]\" value=\"1\" checked=\"checked0\"/> ja</div>
<div><input type=\"radio\" name=\"CMS_VAR[0]\" value=\"0\" /> nein</div></td></tr>";
} else {
echo "<td><div><input type=\"radio\" name=\"CMS_VAR[0]\" value=\"1\" /> ja</div>
<div><input type=\"radio\" name=\"CMS_VAR[0]\" value=\"0\" checked=\"checked0\"/> nein</div></td></tr>";
}
echo "</table>";
Code: Alles auswählen
<h2>Artikel bewerten:</h2>
<?php
/***********************************************
* CONTENIDO MODUL - OUTPUT
*
* Modulname : w3concepts.form.v1
* Author : Andreas Kummer
* Copyright : mumprecht & kummer w3concepts
* Created : 20-08-2004
* Modified : 20-08-2004
************************************************/
$cfg["tab"]["vote"] = $cfg['sql']['sqlprefix']."_vote"; // for syntax reasons only
class w3form {
var $email, $aufgedroeselt, $form, $formularFeld;
function w3form() {
}
// PRIVATE
function sendEmail() {
$this->aufdroeseln($this->suppress('sent'));
$this->generateEmailMessage();
mail($this->email['adresses'],$this->email['subject'],$this->email['message'],"From: {$this->email['from']['name']} <{$this->email['from']['email']}>\nReply-To: {$this->email['from']['email']}\nX-Mailer: PHP/" . phpversion());
}
// PRIVATE
function aufdroeseln($aufzudroeseln,$prefix = '') {
foreach ($aufzudroeseln as $key => $value) {
if (is_array($value)) {
$this->aufdroeseln($value,$key." ");
} else {
$this->aufgedroeselt["{$prefix}{$key}"] = $value;
}
}
}
// PRIVATE
function add2Message($key,$value) {
if (strlen($key) > 25 OR strlen($value) > 54) {
$this->email['message'] .= "$key\n$value\n";
} else {
$this->email['message'] .= $key;
$this->email['message'] .= str_repeat(' ',25-strlen($key));
$this->email['message'] .= "$value\n";
}
}
// PRIVATE
function generateEmailMessage() {
if ($this->aufgedroeselt) foreach ($this->aufgedroeselt as $key => $value) {
$this->add2Message($key,$value);
}
}
// PRIVATE
function suppress() {
$suppress = func_get_args();
foreach ($_POST as $key => $value) {
if (array_search($key,$suppress) === false) $fields[$key] = $value;
}
return $fields;
}
// PUBLIC
function addEmailAdress($email) {
if (empty($this->emailAdresses)) {
$this->email['adresses'] .= "$email";
} else {
$this->email['adresses'] .= ", $email";
}
}
// PUBLIC
function setEmailSubject($subject) {
$this->email['subject'] = $subject;
}
// PUBLIC
function setEmailFrom($email,$name) {
$this->email['from']['email'] = $email;
$this->email['from']['name'] = $name;
}
// PUBLIC
function setForm($form) {
$this->form['form'] = $form;
}
// PUBLIC
function setAnswer($answer) {
$this->form['answer'] = $answer;
}
// PUBLIC
function setBackgroundError($color) {
$this->form['colorError'] = $color;
}
// PRIVATE
function formularInterpretation(&$formular) {
$felder = split('###',$formular);
for ($i=1;$i<count($felder);$i=$i+2) {
$attributte = split(';',trim($felder[$i]));
foreach ($attributte as $attribut) {
$namewert = split(':',trim($attribut));
if ($namewert[0] != 'option' && $namewert[0] != 'optionvalue') {
$feld["{$felder[$i]}"]["{$namewert[0]}"] = $namewert[1];
} else {
$feld["{$felder[$i]}"]["{$namewert[0]}"][] = $namewert[1];
}
}
}
return $feld;
}
// PRIVATE
function formularAusgabe($sent = false) {
echo '<form id="searchform" action="" method="post">';
echo '<input type="hidden" name="sent" value="true" />';
$formular = $this->form['form'];
$formulardaten = $this->formularInterpretation(&$formular);
$formular = split('###',$formular);
foreach ($formular as $formularteil) {
if (!empty($formulardaten["{$formularteil}"])) {
$this->formularFeld($formulardaten["{$formularteil}"],$sent);
} else {
echo $formularteil;
}
}
echo '</form>';
}
// PRIVATE
function formularFeld($attribute,$sent) {
$parameter = "name=\"{$attribute['name']}\"";
if ($sent && !$this->formularFeldKorrekt(&$attribute)) $style ="style=\"background-color:{$this->form['colorError']};\"";
switch ($attribute['type']) {
case 'select':
case 'password':
case 'text':
if (!empty($attribute['size'])) $parameter .= " size=\"{$attribute['size']}\"";
break;
}
switch ($attribute['type']) {
case 'textarea':
case 'text':
if (!empty($attribute['size'])) $parameter .= " size=\"{$attribute['size']}\"";
if (!empty($attribute['value'])) $value = $attribute['value'];
if (!empty($_POST["{$attribute['name']}"])) $value = $_POST["{$attribute['name']}"];
break;
}
switch ($attribute['type']) {
case 'text':
echo "<input type=\"text\" $parameter value=\"$value\" $style />";
break;
case 'password':
echo "<input type=\"password\" $parameter value=\"$value\" $style />";
break;
case 'textarea':
echo "<textarea name=\"{$attribute['name']}\" cols=\"";
echo (empty($attribute['cols']))?('20'):($attribute['cols']);
echo "\" rows=\"";
echo (empty($attribute['rows']))?('2'):($attribute['rows']);
echo "\" wrap=\"virtual\" $style>$value</textarea>";
break;
case 'select':
echo "<select $parameter $style>";
for ($i=0;$i<count($attribute['option']);$i++) {
if (!empty($attribute['optionvalue'][$i])) {
if (!empty($_POST["{$attribute['name']}"]) && $_POST["{$attribute['name']}"] == $attribute['optionvalue'][$i]) {
echo "<option value=\"{$attribute['optionvalue'][$i]}\" selected=\"selected\">{$attribute['option'][$i]}</option>\n";
} else {
if (empty($_POST["{$attribute['name']}"]) && !empty($attribute['optionvalue'][$i]) && $attribute['optionvalue'][$i] == $attribute['value']) {
echo "<option value=\"{$attribute['optionvalue'][$i]}\" selected=\"selected\">{$attribute['option'][$i]}</option>\n";
} else {
echo "<option value=\"{$attribute['optionvalue'][$i]}\">{$attribute['option'][$i]}</option>\n";
}
}
} else {
if (!empty($_POST["{$attribute['name']}"]) && $_POST["{$attribute['name']}"] == $attribute['option'][$i]) {
echo "<option selected=\"selected\">{$attribute['option'][$i]}</option>\n";
} else {
if (empty($_POST["{$attribute['name']}"]) && $attribute['option'][$i] == $attribute['value']) {
echo "<option selected=\"selected\">{$attribute['option'][$i]}</option>\n";
} else {
echo "<option>{$attribute['option'][$i]}</option>\n";
}
}
}
}
echo "</select>";
break;
case 'checkbox':
$formularbezeichner = preg_split('[\[|\]]',$attribute['name']);
if ($sent) {
if ($_POST["{$formularbezeichner[0]}"]["{$formularbezeichner[1]}"] == $attribute['value']) {
echo "<input type=\"checkbox\" $parameter value=\"{$attribute['value']}\" checked=\"checked\"/>";
} else {
echo "<input type=\"checkbox\" $parameter value=\"{$attribute['value']}\"/>";
}
} else {
if (!empty($attribute['selected']) && $attribute['selected'] == 'true') {
echo "<input type=\"checkbox\" $parameter value=\"{$attribute['value']}\" checked=\"checked\"/>";
} else {
echo "<input type=\"checkbox\" $parameter value=\"{$attribute['value']}\"/>";
}
}
break;
case 'radio':
if (!empty($_POST["{$attribute['name']}"])) {
if ($_POST["{$attribute['name']}"] == $attribute['value']) {
echo "<input type=\"radio\" $parameter value=\"{$attribute['value']}\" checked=\"checked\"/>";
} else {
echo "<input type=\"radio\" $parameter value=\"{$attribute['value']}\" />";
}
} else {
if (!empty($attribute['selected']) && $attribute['selected'] == 'true') {
echo "<input type=\"radio\" $parameter value=\"{$attribute['value']}\" checked=\"checked\"/>";
} else {
echo "<input type=\"radio\" $parameter value=\"{$attribute['value']}\"/>";
}
}
break;
}
}
// PRIVATE
function formularVollstaendig() {
$formular = $this->form['form'];
$felder = $this->formularInterpretation(&$formular);
foreach ($felder as $feld) {
if (!$this->formularFeldKorrekt(&$feld)) return false;
}
return true;
}
// PRIVATE
function success() {
$this->sendEmail();
echo $this->form['answer'];
}
// PRIVATE
function formularFeldKorrekt(&$feld) {
// prüfung, ob pflichtfeld vorhanden
if (!empty($feld['mandatory']) && $feld['mandatory'] == 'true' && empty($_POST["{$feld['name']}"])) return false;
// wenn das formularfeld kein pflichtfeld und nicht vorhanden ist, true zurück geben
if (empty($_POST["{$feld['name']}"])) return true;
// regular expression prüfungen
if (!empty($feld['valid']) && $feld['valid'] == 'simpletext' && !eregi("^[ öäüéàèâêîça-z0-9-]*$",$_POST["{$feld['name']}"])) return false;
if (!empty($feld['valid']) && $feld['valid'] == 'text' && !eregi("^[ .,;!?()öäüéàèâêîça-z0-9-]*$",$_POST["{$feld['name']}"])) return false;
if (!empty($feld['valid']) && $feld['valid'] == 'integer' && !eregi("^[0-9]*$",$_POST["{$feld['name']}"])) return false;
if (!empty($feld['valid']) && $feld['valid'] == 'float' && !eregi("^[0-9]*[.]{0,1}[0-9]*$",$_POST["{$feld['name']}"])) return false;
if (!empty($feld['valid']) && $feld['valid'] == 'date' && !eregi("^[0-9]{1,2}.[0-9]{1,2}.[0-9]{2}$",$_POST["{$feld['name']}"])) return false;
if (!empty($feld['valid']) && $feld['valid'] == 'email' && !eregi("^[öäüéàèâêîç_a-z0-9-]+(\.[öäüéàèâêîç_a-z0-9-]+)*@[öäüéàèâêîça-z0-9-]+(\.[öäüéàèâêîça-z0-9-]+)*$",$_POST["{$feld['name']}"])) return false;
// grössenbereich bei integer und float prüfen
if (!empty($feld['minvalue']) && $_POST["{$feld['name']}"] < $feld['minvalue']) return false;
if (!empty($feld['maxvalue']) && $_POST["{$feld['name']}"] > $feld['maxvalue']) return false;
// längenbereich bei allen typen prüfen
if (!empty($feld['minlength']) && strlen($_POST["{$feld['name']}"]) < $feld['minlength']) return false;
if (!empty($feld['maxlength']) && strlen($_POST["{$feld['name']}"]) > $feld['maxlength']) return false;
return true;
}
//PUBLIC
function process() {
if (!isset($_POST['sent'])) {
$this->formularAusgabe();
} elseif ($this->formularVollstaendig()) {
$this->success($value);
} else {
$this->formularAusgabe(true);
}
}
}
class voting extends w3form {
var $idart;
function success() {
global $cfg;
$db = new DB_Contenido;
$db->query("SELECT pk_voting FROM ".$cfg["tab"]["vote"]." WHERE
ip = '{$_SERVER['REMOTE_ADDR']}'
AND DATE_ADD(time,INTERVAL 1 HOUR) > NOW()
AND fk_idart = {$this->idart}
");
if (!$db->next_record()) {
$db->query("INSERT INTO ".$cfg["tab"]["vote"]." (fk_idart,ip,time,vote)
VALUES
({$this->idart},'{$_SERVER['REMOTE_ADDR']}',NOW(),{$_POST['vote']})
");
$this->showResult();
echo $this->form['answer'];
} else {
$this->showResult();
echo $this->form['doubleVoteAnswer'];
}
}
function setIdart($idart) {
$this->idart = $idart;
}
function setDoubleVoteAnswer($answer) {
$this->form['doubleVoteAnswer'] = $answer;
}
function showResult() {
$db = new DB_Contenido;
$db->query("
SELECT AVG(vote) AS average, count(*) AS anzahl FROM con_vote
WHERE
fk_idart = {$GLOBALS['idart']}
");
if ($db->next_record()) {
$anzahl = $db->f("anzahl");
$average = number_format($db->f("average"),1);
echo "
<table style=\"width:170px\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td style=\"background-color:#335577; width:15px; color:white; text-align:center\"></td>
<td style=\"padding-top:3px; padding-left:4px; padding-bottom:3px; \">";
// ---- Hier einbauen ----
if ( $average > 0 )
{
echo " Dieser Artikel wurde bisher <strong>$anzahl</strong> mal mit durchschnittlich <strong>$average</strong> bewertet<br />";
} else {
echo "Dieser Beitrag erhielt noch <b>keine Bewertung</b>";
}
// Dieser Artikel wurde bisher $anzahl mal mit durchschnittlich $average bewertet (auf einer Skala von 1 bis 5).
echo "<br />";
?>
<img src="stat.bar.php?average=<?php print $average; ?>" border="0" alt="<?php print ceil(($average - 1) * 25); ?> %" width="100" height="15" title="<?php print ceil(($average - 1) * 25); ?> %">
<?
echo " </td></tr>
</table>
";
// ---- Ende ----
}
}
function process() {
if (!isset($_POST['sent'])) {
$this->showResult();
$this->formularAusgabe();
} elseif ($this->formularVollstaendig()) {
$this->success($value);
} else {
$this->formularAusgabe(true);
}
}
}
if ("CMS_VALUE[0]" == 1) {
$formular = new voting();
$formular->setIdart($idart);
$formular->setForm('
<table style="width:170px;" cellpadding="0" cellspacing="0">
<tr>
<td> </td>
</tr>
<tr style="border: 0px;">
<td width:"170" style="font-size: 11px; border: 0px; border-left:15px; border-color: #335577; border-style: solid; padding-top:3px; padding-left:4px; ">
<strong>Artikelbewertung</strong>
</td></tr>
<tr>
<td width:"170" style="font-size: 11px; border: 0px; border-left:15px; border-color: #335577; border-style: solid; padding-top:3px; padding-left:4px; ">
Wie beurteilen Sie diesen Artikel?
</td></tr>
<tr>
<td width:"170" style="font-size: 10px; border: 0px; border-left:15px; border-color: #335577; border-style: solid; padding-top:3px; padding-left:4px; ">
###name:vote; valid:integer; type:select; minvalue:1; option:bitte auswählen; option:sehr gut; option:gut; option:brauchbar; option:schlecht; option:sehr schlecht; optionvalue:0; optionvalue:5; optionvalue:4; optionvalue:3; optionvalue:2; optionvalue:1###
</td></tr>
<tr>
<td width:"170" style="font-size: 10px; border: 0px; border-left:15px; border-color: #335577; border-style: solid; padding-top:3px; padding-left:4px; ">
<input type="submit" value="bewerten" class="button" />
</td></tr>
</table>
');
$formular->setAnswer('
<table style="width:170px" cellpadding="0" cellspacing="0">
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td style="background-color:#335577; width:15px; color:white; text-align:center"></td>
<td style="padding-top:3px; padding-left:4px; ">
<strong>Vielen Dank</strong>
</td></tr>
<tr>
<td style="background-color:#335577; width:15px; color:white; text-align:center"></td>
<td style="padding-top:3px; padding-left:4px; padding-bottom:3px; ">
Vielen Dank, dass Sie an der Bewertung dieses Artikels teilgenommen haben. Ihre Stimme ist
erfolgreich eingegangen und findet sich im angezeigten Resultat repräsentiert.
</td></tr>
</table>
');
$formular->setDoubleVoteAnswer('
<table style="width:170px" cellpadding="0" cellspacing="0">
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td style="background-color:#335577; width:15px; color:white; text-align:center"></td>
<td style="padding-top:3px; padding-left:4px; ">
<strong>Mehrfachteilnahme</strong>
</td></tr>
<tr>
<td style="background-color:#335577; width:15px; color:white; text-align:center"></td>
<td style="padding-top:3px; padding-left:4px; padding-bottom:3px; ">
In der Datenbank liegt bereits ein Eintrag mit Ihrer IP-Adresse für diesen Artikel vor. Ihre Stimmabgabe
muss deshalb ignoriert werden.
</td></tr>
</table>
');
$formular->process();
}
?>
Code: Alles auswählen
<?php
header ("Content-type: image/png");
$image = @imagecreate (100, 15);
$backgroundColor = imagecolorallocate ($image, 255, 255, 255);
$textColor = imagecolorallocate ($image, 0, 0, 0);
$text = $average;
$average = $_REQUEST["average"];
$average = ceil(($average - 1) * 25);
if ($average < 25) {
$textColor = imagecolorallocate ($image, 255, 0, 0);
}
elseif ($average > 75) {
$textColor = imagecolorallocate ($image, 0, 128, 0);
$barColor = imagecolorallocate ($image, 182, 253, 44);
imagefilledrectangle ($image, 0, 0, round(($average/100)*100), 15, $barColor);
}
elseif ($average <= 75 AND $average >= 25) {
$barColor = imagecolorallocate ($image, 50, 189, 50);
imagefilledrectangle ($image, 0, 0, round(($average/100)*100), 15, $barColor);
}
imagestring ($image, 2, 1, 1, " ".$text." von 5", $textColor);
$rand = ImageColorAllocate ($image,187,187,170);
//imageline($image,0,0,100,0,$hellblau);
$polygon_werte=array(0,0,99,0,99,14,0,14);
imagepolygon($image,$polygon_werte,4,$rand);
ImagePNG ($image);
?>
In diesem Sinne....