jhylands

graph1.php

Apr 8th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.85 KB | None | 0 0
  1. <?php
  2. include 'head.php';
  3. if(isset($logIn)){
  4. if($logIn!="admin"){
  5. echo "<h1>Error:7 # you can not access this page</h1><p>Please <a href='index.php'>click here</a> to go back to where you should be.";
  6. exit(404);
  7. }}
  8. function getListForJavascript($table,$column){
  9. //include a connection to the database
  10. include 'scripts/sql.php';
  11. //get each of what the user wants from the db (that should be fine
  12. //put the summarised questions in an array [$questionID][$series]
  13. //compress the first dimention of the array removing blank rows [$x][$series] = $y
  14. //update the image using ajax request
  15. //get list of teachers
  16. $QRY = "SELECT * FROM " . $table;
  17. $results = mysqli_query($con,$QRY);
  18. $firstRound = true;
  19. $accumulator = "('";
  20. while($row = mysqli_fetch_array($results)){
  21.     if($firstRound){
  22.     $accumulator = $accumulator . $row[$column] . "'";
  23.     $firstRound=false;
  24.     }else{
  25.     $accumulator = $accumulator . ",'" . $row[$column] . "'";
  26.     }
  27. }
  28. mysqli_close($con);
  29. return $accumulator . ")";
  30. }
  31. $teacherList = getListForJavascript("teachers","Name");
  32. $subjectList = getListForJavascript("subjects","Subject");
  33. $classList = getListForJavascript("class","Code");
  34. //get list of years
  35. include 'scripts/sql.php';
  36. $QRY = "SELECT * FROM main ORDER BY 'annum' ASC LIMIT 1";
  37. $results = mysqli_query($con,$QRY);
  38. while($row = mysqli_fetch_array($results)){
  39.     $firstYear = $row['Annum'];
  40.     break;
  41. }
  42. $dateList = "('" . $firstYear . "'";
  43. for($i=$firstYear;$i<=date("Y");$i++){
  44.     $dateList = $dateList . ",'" . $i . "'";
  45. }
  46. $dateList = $dateList . ")";
  47.  
  48. //GENERTAING QUESTIONS ARRAY
  49. //include a connection to the database
  50. include 'scripts/sql.php';
  51. //request all of the questions
  52. $QRY = "SELECT * FROM questions";
  53. //retrives the results of the SQL query
  54. $results = mysqli_query($con,$QRY);
  55. //inishiate a counter to count through the response from the database
  56. $i=0;
  57. //define a string that will become an array in the javascript later on in the page
  58. //the first string contains a CSV of the questions in plain text
  59. $askedQuestionsArray = "";
  60. //the second string contains a CSV of the questionsID's for reference in the next stage of the form
  61. $askedQuestionIDArray = "";
  62. //retrive the rows of the response from the SQL query
  63. while($row = mysqli_fetch_array($results)){
  64. /*'questions' table format
  65. _________________________________
  66. PID     |PRIMARY KEY, INTEGER   |
  67. Question|STRING                 |
  68. ---------------------------------
  69. */
  70.     //store each row of the reponse in an array for use later in producing a drop down of all the questions
  71.     $Questions[$i] = $row;
  72.     //if the first row then don't put a comma before the response
  73.     if($i==0){
  74.     //add the response to the strings
  75.     $askedQuestionIDArray = '"' . $row['PID'] . '"';
  76.     $askedQuestionsArray = $askedQuestionsArray . '"' . $row['Question'] . '"';
  77.     }else{
  78.     //otherwise add the response to the string with a comma preceeding the response
  79.     $askedQuestionIDArray = $askedQuestionIDArray . ',"' . $row['PID'] . '"';
  80.     $askedQuestionsArray = $askedQuestionsArray . ',"' . $row['Question'] . '"';
  81.     }
  82.     //increase the counter
  83.     $i++;
  84. }
  85. //CREATE QUESTIONS DROPDOWN
  86. //inishiate the string to hold the questions drop down html
  87. $QuestionsDropDown = "<select id='questionNumber'>";
  88. //add the individual questions
  89. if(isset($Questions)){
  90.     //if there are questions
  91.     for($n=0;$n<(count($Questions)-1);$n++){
  92.         $QuestionsDropDown = $QuestionsDropDown . "<option value='" . $Questions[$n]['PID'] . "' >" . $Questions[$n]['Question'] . "</option>";
  93.     }
  94.     $QuestionsDropDown = $QuestionsDropDown . "</select>";
  95. }
  96. //GENERATING ADD ROW HTML
  97. //inishiate a string containing the html row of the table allowing users to add another row
  98. $addRowScript = "<tr id='addrow'><td colspan='4'><form id='addRowExtraInfo'>" . $QuestionsDropDown . "</form><input type='button' value='Add Question' onclick='addRow()'/></select></td></tr>";
  99.  
  100. //this is the end of the main PHP the rest of the PHP on the page is intertwined in the HTML and javascript
  101.  
  102. ?>
  103. <script type="text/javascript" src="scripts/jscolor.js"></script>
  104. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></scripts>
  105. <script>/*
  106. function produceImage(){
  107.    
  108.     var yaxis=document.getElementById('summary').value;
  109.     var errCol=document.getElementById(''ErrCol').value;
  110.     $.post("scripts/graphcreator.php",{type:type,value:value,color:color,Xaxis:xaxis,Yaxis:yaxis,ErrCol:errCol},function(data,status){alert("Data: " + data);});
  111. }
  112. //change the second select option based on first selection
  113. var teacherList = new Array<?php echo $teacherList; ?>;
  114. var subjectList = new Array<?php echo $subjectList; ?>;
  115. var classList = new Array<?php echo $classList; ?>;
  116. var yearList = new Array('All years','Lower school (years:7,8,9,10,11)','KS3 (years:7,8,9)','KS4 (years:10,11)','Sixth form (years:12,13)'<?php for($i=7;$i<=13;$i++){echo ",'Year " . $i . "'";}?>);
  117. var annumList = new Array<?php echo $dateList; ?>;
  118. function mainChange(){
  119.     var mainDrop = document.getElementById('mainDropDown');
  120.     switch(mainDrop.options[mainDrop.selectedIndex].value){
  121.     case "ClassID":
  122.         classList = bubbleSort(classList);
  123.         createOption(classList);
  124.         break;
  125.     case "TeacherID":
  126.         createOption(teacherList);
  127.         break;
  128.     case "SubjectID":
  129.         createOption(subjectList);
  130.         break;
  131.     case "Annum":
  132.         createOption(annumList);
  133.         break;
  134.     }
  135. }
  136. //include array of the possible columns given that the limits are entry or class
  137. //include an array of the questions that where asked
  138. var questions = Array(<?php echo $askedQuestionsArray; ?>);
  139. //include an array of those questions PID's for later reference
  140. var questionID = Array(<?php echo $askedQuestionIDArray; ?>);
  141. //elements array to contain all of the headers
  142. var elementsS = new Array();
  143. var elementsX = new Array();
  144. //variable to store the html code for adding a row script
  145. var addRowHTML = "<?php echo $addRowScript; ?>";
  146. //function to redraw the table when there is a change
  147. function drawTableX(){
  148.     //geth the table object as a local varibale to make it easy to make ajustmants to
  149.     var table = document.getElementById("tableOfX");
  150.     //inishiate a string used to build the innerHTML of the table from the information in the elements array
  151.     var strBuild="<tr><td>Bar name</td><td>Question</td><td>Remove bar</td></tr>";
  152.     //cycle through each of the columns building its corraspondinf row of the table
  153.     for(i=0;i<elements.length;i++){
  154.         //the name box is an input box so that the text heading a column can be changed
  155.         strBuild = strBuild + "<tr><td><p name='element" + i + "' id='element" + i + "'>Q";
  156.         strBuild = strBuild + elements[i].value;
  157.         strBuild = strBuild + "</p>";
  158.         strBuild = strBuild + "</td><td><p>";
  159.         strBuild = strBuild + elements[i].text;
  160.         strBuild = strBuild + "</p></td><td>";
  161.         //include the option to move this column,heading (row in this table) or deleat it
  162.         strBuild = strBuild + "<input type='button' value='Remove bar' onclick='deleteRowX(" + i + ")' />";
  163.         strBuild = strBuild + "</td></tr>";
  164.     }
  165.     //add a row so that the user is able to add and additional row
  166.     strBuild = strBuild + addRowHTML;
  167.     //put the newly created table body in the body of the table
  168.     table.innerHTML = strBuild;
  169. }
  170. /*
  171. //function to redraw the table when there is a change
  172. function drawTableS(){
  173.     //geth the table object as a local varibale to make it easy to make ajustmants to
  174.     var table = document.getElementById("tableOfS");
  175.     //inishiate a string used to build the innerHTML of the table from the information in the elements array
  176.     var strBuild="<tr><td>Colour</td><td>Series</td><td>Remove Series</td></tr>";
  177.     //cycle through each of the columns building its corraspondinf row of the table
  178.     for(i=0;i<elements.length;i++){
  179.         //the name box is an input box so that the text heading a column can be changed
  180.         strBuild = strBuild + "<tr><td style='width:100%;hight:100%;background-color:" + elementsS[i].color + ";'></td>";
  181.         strBuild = strBuild + "<td><p>";
  182.         strBuild = strBuild + elements[i].type + "->" + elements[i].value;//the description column
  183.         strBuild = strBuild + "</p></td><td>";
  184.         //include the option to move this column,heading (row in this table) or deleat it
  185.         strBuild = strBuild + "<input type='button' value='Delete series' onclick='deleteRowS(" + i + ")' />";
  186.         strBuild = strBuild + "</td></tr>";
  187.     }
  188.     //add a row so that the user is able to add and additional row
  189.     strBuild = strBuild + addRowHTML;
  190.     //put the newly created table body in the body of the table
  191.     table.innerHTML = strBuild;
  192. }*/
  193.  
  194. //function to remove a column at the users request
  195. function deleteRowX(rowId){
  196.     //remove the row in the elements array
  197.     elementsX.splice(rowId,1);
  198.     //redraw the table with the element removed from the 'elements' array
  199.     drawTableX();
  200. }
  201. */
  202. //add row to the table
  203. function addRow(){
  204.     //count the number of elements already in the array so that we know what index to add the next one to
  205.     var index = elementsX.length;
  206.     elementsX[index] = new Object();
  207.     var questionChoice = document.getElementById('questionNumber');
  208.     elementsX[index].title = "Q" + questionChoice.options[questionChoice.selectedIndex].value;
  209.     elementsX[index].type= questionChoice.options[questionChoice.selectedIndex].value;
  210.     elementsX[index].description = questionChoice.options[questionChoice.selectedIndex].text;
  211.     //redraw the table with the ammendments
  212.     drawTableX();
  213. }/*
  214. //function to remove a column at the users request
  215. function deleteRowS(rowId){
  216.     //remove the row in the elements array
  217.     elementsX.splice(rowId,1);
  218.     //redraw the table with the element removed from the 'elements' array
  219.     drawTableS();
  220. }
  221. //add row to the table
  222. function addRowS(){
  223.     //count the number of elements already in the array so that we know what index to add the next one to
  224.     var index = elementsS.length;
  225.     elementsS[index] = new Object();
  226.     var questionChoice = document.getElementById('questionNumber');
  227.     elementsS[index].title = "Q" + questionChoice.options[questionChoice.selectedIndex].value;
  228.     elementsS[index].type= questionChoice.options[questionChoice.selectedIndex].value;
  229.     elementsS[index].description = questionChoice.options[questionChoice.selectedIndex].text;
  230.     //redraw the table with the ammendments
  231.     drawTableS();
  232. }*/
  233. </script>
  234. <table width="100%">
  235. <tr>
  236.     <td rowspan="4" style="vertical-align:text-top;" width="50%"><h2>Preview</h2><img src="temp.png" width="100%"></td>
  237.     <td id="siriesBox" rowspan="2" style="vertical-align:text-top;" width="25%"><h1>Siries:</h1>
  238. <table id="tableOfS" width="100%" border="1"><tr><td>Colour</td><td>Series</td><td>Remove series</td></tr></table>
  239.     </td>
  240.     <td><h2>Error bar colours</h2>
  241.     <label for="ErrCol">Select a color for the error bars:</label><input id="ErrCol" name="ErrCol" val="FFFFFF" class="color" /></td>
  242. </tr>
  243. <tr>
  244.     <td><p>Y axis label:<select id="summary"><option value="sum">Values added up</option><option value="avg">Average answer</option></select></td>
  245. </tr><tr>
  246.     <td id="questionBox"  style="vertical-align:text-top;"><h1>X-axis</h1><p>Please select the questions you wish to display on the x-axis</p><br />
  247.     <table id="tableOfX" border="1"><tbody><tr><td>Bar name</td><td>Quesion</td><td>Remove row</td></tr><tr id="addrow"><td colspan="4"><form id="addRowExtraInfoX"><?php echo $QuestionsDropDown; ?></form><input type="button" value="Add Question" onclick="addRow()"></td></tr></tbody></table>
  248.     </td>
  249.     <td style="vertical-align:text-top;"><h2>Add siries</h2>
  250.     <select id="mainDropDown" onchange="mainChange()"><option>Select a type</option><option value="ClassID">class</option><option value="year">Year</option><option value="TeacherID">Teacher</option><option value="SubjectID">Subject</option><option value="Annum">Annum</option></select><br />
  251.     <div id="secondOptionBlock"></select></div><br />
  252.     <label for="siriesColor">Select the bar color for this siries:</label><input id="siriesColor" name="siriesColor" value="9999FF" class="color" /><br />
  253.     <input type='button' value="Add series" onclick="addFilter();" /></td>
  254.     </td>
  255. </tr>
  256. </table>
  257. <?php
  258. include 'foot.php';
  259. ?>
Advertisement
Add Comment
Please, Sign In to add comment