CREATE TABLE `polls` ( `ID` int(11) NOT NULL auto_increment, `title` varchar(255) NOT NULL, PRIMARY KEY (`ID`) ) ENGINE=MyISAM; CREATE TABLE `poll_questions` ( `ID` int(11) NOT NULL auto_increment, `ID_poll` int(11) NOT NULL, `poll_question` varchar(255) NOT NULL, PRIMARY KEY (`ID`) ) ENGINE=MyISAM; CREATE TABLE `poll_options` ( `ID` int(11) NOT NULL auto_increment, `ID_question` int(11) NOT NULL, `ID_poll` int(11) NOT NULL, `poll_option` varchar(255) NOT NULL, PRIMARY KEY (`ID`) ) ENGINE=MyISAM; CREATE TABLE `poll_answers` ( `ID` int(11) NOT NULL auto_increment, `ID_option` int(11) NOT NULL, `ID_question` int(11) NOT NULL, `ID_poll` int(11) NOT NULL, `visitor_ip` varchar(32) NOT NULL, PRIMARY KEY (`ID`) ) ENGINE=MyISAM;
<?php
$getsurveys = new Pagination();
$getsurveys->start = ($_GET['start']) ? $_GET['start'] : '0';
$getsurveys->filePath = 'index.php';
$getsurveys->select_what = '*';
$getsurveys->the_table = 'polls';
$getsurveys->add_query = 'ORDER BY ID DESC';
$getsurveys->limit = 5;
$surveys = $getsurveys->getQuery(TRUE);
$bg1 = "t9"; // color one
$bg2 = "t10"; // color two
$row_count = 0;
$i = (($_GET['start']) ? $_GET['start'] : '0')+1;
$content = ' <table width="100%" border="0" cellspacing="0" cellpadding="0" class="t0">'."\n";
$content .= ' <tr>'."\n";
$content .= ' <td class="t1"><div align="center"><b>No.</b></div></td>'."\n";
$content .= ' <td class="t2"><div align="center"><b>Title</b></div></td>'."\n";
$content .= ' <td class="t3"><div align="center"><b>Answers</b></div></td>'."\n";
$content .= ' <td class="t4"><div align="center"><b>Action</b></div></td>'."\n";
$content .= ' </tr>'."\n";
if(mysql_num_rows($surveys)>0)
{
$row = mysql_fetch_assoc($surveys);
do {
$row_color = ($row_count % 2) ? $bg1 : $bg2;
$content .= ' <tr>'."\n";
$content .= ' <td class="t5 '.$row_color.'">'."\n";
$content .= ' <div align="center">'.$i++.'</div></td>'."\n";
$content .= ' <td class="t6 '.$row_color.'">'."\n";
$content .= ' <div align="left"><a href="view_survey.php?ID='.$row['ID'].'" target="_blank">'.$row['title'].'</a>'."\n";
$content .= ' <img src="images/add.png" width="16" height="16" border="0" align="bottom" class="cat_img" onclick="MM_effectSlide(\'survey_'.$row['ID'].'\', 700, \'0%\', \'100%\', true, false, true)" />'."\n";
$content .= '</div>'."\n";
$content .= '<div style="height:25px">'."\n";
$content .= '<div class="q_form" id="survey_'.$row['ID'].'">'."\n";
$content .= ' <form action="'.selfURL().'" method="POST">'."\n";
$content .= ' <input type="hidden" name="ID_survey" value="'.$row['ID'].'" size="32" />'."\n";
$content .= ' <input type="text" name="new_question" value="" size="32" />'."\n";
$content .= ' <input type="submit" name="add_question" value="Add question" />'."\n";
$content .= ' </form>'."\n";
$content .= '</div>'."\n";
$content .= '</div>'."\n";
$getQuestions = mysql_query("SELECT * FROM poll_questions WHERE ID_poll = '".$row['ID']."'");
if(mysql_num_rows($getQuestions)>0)
{
$row_questions = mysql_fetch_assoc($getQuestions);
$q = 1;
do {
$content .= ' <div style="padding-left:100px;">'."\n";
$content .= ' '.$q++.' : '.$row_questions['poll_question'].''."\n";
$content .= ' <a href="javascript:void(0);" title="add option">'."\n";
$content .= ' <img src="images/add.png" width="16" height="16" border="0" onclick="MM_effectSlide(\''.$row_questions['ID'].'\', 700, \'0%\', \'100%\', true, false, true)" />'."\n";
$content .= ' </a>'."\n";
$content .= ' <a href="javascript:popUp(\'chart.php?ID='.$row_questions['ID'].'\');" title="take survey">'."\n";
$content .= ' <img src="images/chart.png" width="16" height="16" border="0" />'."\n";
$content .= ' </a>'."\n";
$content .= ' <a href="javascript:void(0);" title="delete">'."\n";
$content .= ' <img src="images/delete.png" width="16" height="16" border="0" onClick="xajax_admin_action_questions(\'delete\', \''.$row_questions['ID'].'\');" />'."\n";
$content .= ' </a>'."\n";
$getOptions = mysql_query("SELECT * FROM poll_options WHERE ID_question = '".$row_questions['ID']."'");
if(mysql_num_rows($getOptions)>0)
{
$row_options = mysql_fetch_assoc($getOptions);
do {
$content .= ' <div style="padding-left:30px; height:18px">'."\n";
$content .= '→'.$row_options['poll_option'];
$content .= ' <a href="javascript:void(0);" title="delete">'."\n";
$content .= ' <img src="images/delete.png" width="16" height="16" border="0" onClick="xajax_admin_action_options(\'delete\', \''.$row_options['ID'].'\');" />'."\n";
$content .= ' </a>'."\n";
$content .= ' </div>'."\n";
} while ($row_options = mysql_fetch_assoc($getOptions));
}
$content .= '<div style="height:25px">'."\n";
$content .= '<div class="q_form" id="'.$row_questions['ID'].'">'."\n";
$content .= ' <form action="'.selfURL().'" method="POST" class="form">'."\n";
$content .= ' <input type="hidden" name="ID_question" value="'.$row_questions['ID'].'" size="32" />'."\n";
$content .= ' <input type="hidden" name="ID_poll" value="'.$row['ID'].'" size="32" />'."\n";
$content .= ' <input type="text" name="new_option" value="" size="32" />'."\n";
$content .= ' <input type="submit" name="add_option" value="Add option" />'."\n";
$content .= ' </form>'."\n";
$content .= '</div>'."\n";
$content .= '</div>'."\n";
$content .= ' </div>'."\n";
} while ($row_questions = mysql_fetch_assoc($getQuestions));
}
$content .= ' </td>'."\n";
$content .= ' <td class="t7 '.$row_color.'">'."\n";
$content .= ' <div align="center">'.getSurveyAnswers($row['ID']).'</div></td>'."\n";
$content .= ' <td class="t8 '.$row_color.'">'."\n";
$content .= ' <div align="center">'."\n";
$content .= ' <form name="form'.$row['ID'].'" id="form'.$row['ID'].'" class="form" >'."\n";
$content .= ' <input name="id_survey" type="hidden" value="'.$row['ID'].'" />'."\n";
$content .= ' <div align="center">'."\n";
if(checkSurvey($row['ID'])):
$content .= ' <a href="javascript:popUp(\'survey.php?ID='.$row['ID'].'\');" title="take survey">'."\n";
$content .= ' <img src="images/survey.png" width="16" height="16" border="0" />'."\n";
$content .= ' </a>'."\n";
$content .= ' <a href="charts.php?ID='.$row['ID'].'" title="view results" target="_blank">'."\n";
$content .= ' <img src="images/chart.png" width="16" height="16" border="0" />'."\n";
$content .= ' </a>'."\n";
$content .= ' <a href="javascript:popUp(\'code.php?ID='.$row['ID'].'\');" title="get the code">'."\n";
$content .= ' <img src="images/code.png" width="16" height="16" border="0" />'."\n";
$content .= ' </a>'."\n";
endif;
$content .= ' <a href="javascript:void(0);" title="delete">'."\n";
$content .= ' <img src="images/delete.png" width="16" height="16" border="0" onClick="xajax_admin_action(\'delete\', \''.$row['ID'].'\');" />'."\n";
$content .= ' </a>'."\n";
$content .= ' </div>'."\n";
$content .= ' </form>'."\n";
$content .= ' </div></td>'."\n";
$content .= ' </tr>'."\n";
$row_count++;
} while ($row = mysql_fetch_assoc($surveys));
$content .= '</table>'."\n";
echo $content;
echo $getsurveys->paginate();
}
else {
echo '<div align="center" style="margin:200px auto auto auto;">No surveys defined</div>';
}
?>
<?php
if(checkSurvey($_GET['ID']))
{
$getQuestions = mysql_query("SELECT poll_questions.ID AS ID, poll_questions.poll_question AS poll_question FROM poll_questions WHERE poll_questions.ID_poll='".mysql_real_escape_string($_GET['ID'])."' AND NOT EXISTS(SELECT poll_answers.ID FROM poll_answers WHERE poll_answers.ID_question = poll_questions.ID AND poll_answers.visitor_ip = '".getIP()."')");
if(mysql_num_rows($getQuestions)>0)
{
$row_questions = mysql_fetch_assoc($getQuestions);
echo $row_questions['poll_question']. '<br /><hr />';
$getOptions = mysql_query("SELECT * FROM poll_options WHERE ID_question = '".mysql_real_escape_string($row_questions['ID'])."' ORDER BY ID ASC") or die(mysql_error());
$row_options = mysql_fetch_assoc($getOptions);
do {
echo '<br /><input type="radio" name="answer" id="'.$row_options['ID'].'" value="'.$row_options['ID'].'" onClick="xajax_insert_answer(\''.$row_options['ID'].'\', \''.$_GET['ID'].'\', \''.$row_questions['ID'].'\');" /><label for="'.$row_options['ID'].'">'.$row_options['poll_option'].'</label>';
} while ($row_options = mysql_fetch_assoc($getOptions));
}
else {
echo 'Thank you for taking this survey! You may <a href="'.$url.'charts.php?ID='.$_GET['ID'].'" title="view survey results" target="_blank">view results</a>';
}
}
else {
echo 'This poll has no questions or options to questions';
}
?>
No. |
Attachments |
Downloads |
|
|
1 |
PHP survey script An archive containing the PHP survey script files. Uploaded on: 2007-09-21 | 07:56 am |
386 |
|