romyslal som nad cyklom while ale neviem kde ho zakomponovat
to dalsie by som asi uz vedel ako spravit
Dakujem vsetkym
Kód: Vybrať všetko
<?
/* Admin tool for the Ajax poller script */
require_once ("include/functions.php");
require_once ("include/config.php");
dbconn();
print("<form action=\"".$_SERVER["PHP_SELF"]."?user=".$CURUSER["uid"]."&code=".$CURUSER["random"]."&do=poller\" method=\"post\">");
$id = "";
if(isset($_POST['ID']))$id = $_POST['ID']; // Opened by form submission
if(isset($_GET['id']))$id = $_GET['id']; // Opened from list
if(isset($_GET['votes']))$votes = $_GET['votes']; // Opened from list
if(isset($_GET['voters']))$voters = $_GET['voters']; // Opened from list
if(isset($_POST['active']))$active = $_POST['active']; // Opened from list
if(isset($_POST['cancel']))$id = "";
if(isset($_POST['delete'])){
$pollObj = new poll();
$pollObj->deletePoll($_POST['ID']);
}
if(isset($_POST['save'])){
$pollObj = new poll();
if(empty($_POST['ID'])){ // new poll
if(isset($_POST['pollerTitle'])){
$id = ($pollObj->createNewPoller($_POST['pollerTitle'],$_POST['userid'],$active));
for($no=0;$no<count($_POST['pollOption']);$no++){
if(!empty($_POST['pollOption'][$no])){
$pollObj->addPollerOption($_POST['pollOption'][$no],$no);
}
}
}
else{
$error_message = "".POLL_TITLE_MISSING."";
}
}else{ // Update existing poll
$pollObj->setId($_POST['ID']); // Setting id
if(isset($_POST['pollerTitle'])) $pollObj->setPollerTitle($_POST['pollerTitle']);
if(isset($_POST['active'])) $pollObj->setPollerActive($_POST['active']);
foreach($_POST['pollOption'] as $key=>$value){
if(!empty($_POST['existing_pollOption'][$key])) $pollObj->setOptionData($_POST['existing_pollOption'][$key],$_POST['existing_pollOrder'][$key],$key);
}
$maxOrder = $pollObj->getMaxOptionOrder() + 1;
for($no=0;$no<count($_POST['pollOption']);$no++){
if(!empty($_POST['pollOption'][$no])){
$pollObj->addPollerOption($_POST['pollOption'][$no],$maxOrder);
$maxOrder++;
}
}
}
}
// Show a list of all the polls
if(!isset($_POST['new']) && empty($id) && !isset($votes)){
block_begin("".POLLING_SYSTEM." - ".CURRENT_POLLS."");
//print header row for polls
print("
<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"5\">
<tr>
<td class=\"header\" align=\"center\" style=\"white-space: nowrap;\">".ID."</td>
<td class=\"header\" align=\"center\" style=\"white-space: nowrap;\">".POLL_STARTED."</td>
<td class=\"header\" align=\"center\" style=\"white-space: nowrap;\">".POLL_ENDED."</td>
<td class=\"header\" align=\"center\" style=\"white-space: nowrap;\">".POLL_LASTED."</td>
<td class=\"header\" align=\"center\" style=\"white-space: nowrap;\">".POLL_TITLE."</td>
<td class=\"header\" align=\"center\" style=\"white-space: nowrap;\">".POLL_BY."</td>
<td class=\"header\" align=\"center\" style=\"white-space: nowrap;\">".POLL_ACTIVE."</td>
<td class=\"header\" align=\"center\" style=\"white-space: nowrap;\">".POLL_VOTES."</td>
</tr>");
//mysql query to select all information on polls in the database
$res = mysql_query("SELECT poller.*, username, prefixcolor, suffixcolor, COUNT(memberID) FROM poller LEFT JOIN users ON poller.starterID=users.id LEFT JOIN users_level on users.id_level=users_level.id_level LEFT JOIN poller_vote on poller.id=poller_vote.pollerID GROUP BY poller.ID DESC");
while($inf = mysql_fetch_array($res)){
//background color for the current active poll
$bold = "normal";
if ($inf["active"]== "yes") $bold = "bold";
//link color for number of votes
$votescolor = linkcolor($inf["COUNT(memberID)"]);
//ending date color for inactive polls
if ($inf["endDate"] == "0")
$endDate = "<span style=\"color:green\">".POLL_STILL_ACTIVE."</span>";
else
$endDate = "<span style=\"color:red\">".get_date_time($inf["endDate"])."</span>";
//find out how long a poll has been active
if ($inf["endDate"] >= "1")
{
$lasted = $inf["endDate"]-$inf["startDate"];
$duration = DateFormat($lasted);
}
else
$duration = "<span style=\"color:green\">".POLL_STILL_ACTIVE."</span>";
//color for poll state (active or not)
if ($inf["active"] == "yes")
$active = "<span style=\"color:#009900\">".YES."</span>";
else
$active = "<span style=\"color:orange\">".NO."</span>";
//votes per day
$elapseddays = max(1, round( ( time() - $inf["startDate"] ) / 86400 ));
$votes_per_day = number_format(round($inf["COUNT(memberID)"] / $elapseddays,2),2);
//link for votes page
if ($inf["COUNT(memberID)"] == "0")
$vote = "<span style=\"color:".linkcolor($inf["COUNT(memberID)"])."\">".$inf["COUNT(memberID)"]."</span>";
else
$vote = "<a href=\"".$_SERVER['PHP_SELF']."?user=".$CURUSER["uid"]."&code=".$CURUSER["random"]."&do=poller&votes=".$inf["ID"]."&voters=".$inf["COUNT(memberID)"]."\"><span style=\"color:".linkcolor($inf["COUNT(memberID)"])."\">".$inf["COUNT(memberID)"]." (".$votes_per_day."/den)</span></a>";
//print information row about poll
print("
<tr>
<td class=\"lista\" align=\"center\" style=\"font-weight:$bold; white-space: nowrap;\">".$inf["ID"]."</td>
<td class=\"lista\" align=\"center\" style=\"font-weight:$bold; white-space: nowrap;\">".get_date_time($inf["startDate"])."</td>
<td class=\"lista\" align=\"center\" style=\"font-weight:$bold; white-space: nowrap;\">".$endDate."</td>
<td class=\"lista\" align=\"center\" style=\"font-weight:$bold; white-space: nowrap;\">".$duration."</td>
<td class=\"lista\" align=\"center\" style=\"font-weight:$bold; white-space: nowrap;\"><a href=\"".$_SERVER['PHP_SELF']."?user=".$CURUSER["uid"]."&code=".$CURUSER["random"]."&do=poller&id=".$inf["ID"]."\">".$inf["pollerTitle"]."</a></td>
<td class=\"lista\" align=\"center\" style=\"font-weight:$bold; white-space: nowrap;\"><a href=\"userdetails.php?id=".$inf["starterID"]."\">".StripSlashes($inf["prefixcolor"].$inf["username"].$inf["suffixcolor"])."</a></td>
<td class=\"lista\" align=\"center\" style=\"font-weight:$bold; white-space: nowrap;\">".$active."</td>
<td class=\"lista\" align=\"center\" style=\"font-weight:$bold; white-space: nowrap;\">".$vote."</td>
</tr>");
}
print("
</table>");
print("
<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\">
<tr>
<td class=\"header\" align=\"center\"><input type=\"submit\" name=\"new\" value=\"".POLL_NEW."\" class=\"formButton\" /></td>
</tr>
</table>\n");
block_end();
print("<br />");
}
/***
* Show a new poll or edit a poll
***/
if(isset($_POST['new']) || !empty($id))
{
$pollObj = new poll();
if(!empty($id)){
$pollObj->getDataById($id);
$pollerOptions = $pollObj->getOptionsAsArray();
$votes = $pollObj->getVotesAsArray();
$title = "".$pollObj->pollerTitle."";
if($pollObj->active == "yes")
$check1 = "checked";
if($pollObj->active == "no")
$check2 = "";
}else{
$pollerOptions = array();
$votes = array();
$title = "".POLL_START_NEW."";
$check1 = "checked";
$check2 = "";
}
block_begin("".POLLING_SYSTEM." - ".$title."");
print("<input type=\"hidden\" name=\"ID\" value=\"".$pollObj->ID."\" />");
print("
<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\">
<tr>
<td class=\"header\" align=\"center\" style=\"white-space:nowrap;\"><label for=\"pollerTitle\">".POLL_TITLE.":</label><input type=\"hidden\" name=\"userid\" value=\"".$CURUSER["uid"]."\" /></td>
<td class=\"lista\" align=\"center\" style=\"white-space:nowrap;\"><input type=\"text\" size=\"60\" maxlength=\"55\" id=\"pollerTitle\" name=\"pollerTitle\" value=\"".$pollObj->pollerTitle."\" /> <label for=\"active_yes\"> ".POLL_ACTIVE_TRUE ." <input type=\"radio\" name=\"active\" value=\"yes\" id=\"active_yes\" ".$check1." /></label> <label for=\"active_no\"> ".POLL_ACTIVE_FALSE." <input type=\"radio\" name=\"active\" id=\"active_no\" value=\"no\" ".$check2." /></label></td>
</tr>
</table>");
print("
<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\">
<tr>");
if(!isset($_POST['new']))
{
print("
<td class=\"header\" align=\"center\">".POLL_OPTION."</td>
<td class=\"header\" align=\"center\">".POLL_VOTES."</td>
<td class=\"header\" align=\"center\">".POLL_MOVE."</td>
");
}
else
{
print("<td class=\"header\" align=\"center\">".POLL_OPTIONS."</td>");
}
print("</tr>");
foreach($pollerOptions as $key=>$value)
{
print("<tr id=\"option$key\">
<td class=\"lista\" align=\"center\"><input type=\"text\" maxlength=\"255\" size=\"50\" name=\"existing_pollOption".$key."\" value=\"".$pollerOptions[$key][0]."\" /></td>
<td class=\"lista\" align=\"center\">".(isset($votes[$key])?$votes[$key]:0)."<input type=\"hidden\" id=\"existing_pollOrder".$key."\" name=\"existing_pollOrder".$key."\" value=\"".$pollerOptions[$key][1]."\" /></td>
<td class=\"lista\" align=\"center\"><a href=\"#down\" onclick=\"moveDown('$key');return false\">".POLL_MOVE."</a></td>
</tr>");
}
if(empty($id))
{
$countInputs = 10;
}
else
{
$countInputs = 3;
print("<tr>
<td colspan=\"4\" class=\"header\" align=\"center\">".POLL_NEW_OPTIONS."</td>
</tr>");
}
for($no=0;$no<$countInputs;$no++){
print("<tr>
<td colspan=\"4\" class=\"lista\" align=\"center\"><input type=\"text\" maxlength=\"255\" size=\"50\" name=\"pollOption[$no]\" /></td>
</tr>");
}
print("
</table>");
print("
<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td class=\"header\" align=\"center\"><input type=\"submit\" name=\"save\" value=\"".POLL_SAVE."\" class=\"formButton\" /></td>
<td class=\"header\" align=\"center\"><input type=\"submit\" name=\"cancel\" value=\"".POLL_CANCEL."\" class=\"formButton\" /></td>");
if(!empty($id))
print("
<td class=\"header\" align=\"center\"><input type=\"submit\" name=\"delete\" value=\"".POLL_DELETE."\" onclick=\"return confirm('".POLL_DEL_CONFIRM."')\" class=\"formButton\" /></td>");
print("
</tr>
</table>\n");
block_end();
print("<br />");
}
/***
* Show poll voters
***/
if(isset($votes) && !isset($_POST['new']) && empty($id))
{
//Per Page Listing Limitation Start - 7:29 PM 3/22/2007
$count = $voters;
$perpage = $GLOBALS["votesppage"];
list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, "".$_SERVER['PHP_SELF']."?user=".$CURUSER["uid"]."&code=".$CURUSER["random"]."&do=poller&votes=".$votes."&voters=".$voters."&".$addparams);
//Per Page Listing Limitation Stop
//mysql query to select all information on polls in the database
$resource = mysql_query("SELECT poller_vote.*, username, prefixcolor, suffixcolor, optionText, defaultChecked FROM poller_vote LEFT JOIN users ON poller_vote.memberID=users.id LEFT JOIN users_level on users.id_level=users_level.id_level LEFT JOIN poller_option on poller_vote.optionID=poller_option.ID WHERE poller_vote.pollerID='".$votes."' GROUP BY poller_vote.voteDate ".$limit."");
block_begin("".POLLING_SYSTEM." - ".POLL_VOTERS."");
//print headers
print("
<table border=\"0\" width=\"100%\">");
//Per Page Listing Limitation Start - 7:35 PM 3/22/2007
if ($count > $perpage)
print("
<tr>
<td class=\"lista\" align=\"center\" colspan=\"4\"><br />".$pagertop."</td>
</tr>");
//Per Page Listing Limitation Stop
print("
<tr>
<td class=\"header\" align=\"center\">".POLL_OPTION."</td>
<td class=\"header\" align=\"center\">".POLL_IP_ADDRESS."</td>
<td class=\"header\" align=\"center\">".POLL_DATE."</td>
<td class=\"header\" align=\"center\">".POLL_USER."</td>
</tr>");
while($results = mysql_fetch_array($resource))
{
//background color for checked poll option
$bold = "normal";
if ($CURUSER["uid"] == $results["memberID"]) $bold = "bold";
//
if (!$results["username"])
$user = "".POLL_ACCOUNT_DEL."";
else
$user = "<a href=\"userdetails.php?id=".$results["memberID"]."\">".StripSlashes($results["prefixcolor"].$results["username"].$results["suffixcolor"])."</a>";
//print rows with voters
print("<tr>
<td class=\"lista\" align=\"center\" style=\"font-weight:$bold;\">".$results["optionText"]."</td>
<td class=\"lista\" align=\"center\" style=\"font-weight:$bold;\">".long2ip($results["ipAddress"])."</td>
<td class=\"lista\" align=\"center\" style=\"font-weight:$bold;\">".get_date_time($results["voteDate"])."</td>
<td class=\"lista\" align=\"center\" style=\"font-weight:$bold;\">".$user."</td>
</tr>");
}
//Per Page Listing Limitation Start - 7:35 PM 3/22/2007
if ($count > $perpage)
print("
<tr>
<td class=\"lista\" align=\"center\" colspan=\"4\"><br />".$pagerbottom."</td>
</tr>");
//Per Page Listing Limitation Stop
print("<tr>
<td class=\"header\" align=\"center\" colspan=\"4\"><input type=\"submit\" name=\"cancel\" value=\"".POLL_BACK."\" class=\"formButton\" /></td>
</tr>");
print("
</table>\n");
block_end();
print("<br />");
}
print("</form>");
?>Kód: Vybrať všetko
if(isset($_POST['save'])){
$pollObj = new poll();
if(empty($_POST['ID'])){ // new poll
if(isset($_POST['pollerTitle'])){
$id = ($pollObj->createNewPoller($_POST['pollerTitle'],$_POST['userid'],$active));
for($no=0;$no<count($_POST['pollOption']);$no++){
if(!empty($_POST['pollOption'][$no])){
$pollObj->addPollerOption($_POST['pollOption'][$no],$no);
}
}
}
else{
$error_message = "".POLL_TITLE_MISSING."";
}