[144] | 1 | <?php |
---|
| 2 | require 'classes/master.php'; //should be at top of every page |
---|
| 3 | |
---|
| 4 | /* So far, the entire page works based on sessions. |
---|
| 5 | * We want it to load the database stuff into the session on user load, and only write back to database when you exit the page. |
---|
| 6 | * Is this possible with the current db model? |
---|
| 7 | * |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | // Reset session, for debug purposes only! |
---|
| 11 | if (isset($_POST['resetSession'])) { |
---|
| 12 | unset($_SESSION['steps']); |
---|
| 13 | $_SESSION['selectedStep'] = null; |
---|
| 14 | } |
---|
| 15 | |
---|
| 16 | // Clear entire pipeline, confirm checkbox checked! |
---|
| 17 | if (isset($_POST['clearPipeline']) && isset($_POST['confirmClear'])) { |
---|
| 18 | unset($_SESSION['steps']); |
---|
| 19 | $_SESSION['steps'] = array(); |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | // Upon first page load, generate a placeholder array of Steps. (Only string at the moment!) |
---|
| 23 | if (!isset($_SESSION['steps'])) { |
---|
| 24 | $_SESSION['steps'] = array("Questionnaire 1", "Questionnaire 2", "Notice 1", "Application 1", "Dashboard 1"); |
---|
| 25 | $_SESSION['selectedStep'] = null; |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | // if user clicked "remove" button |
---|
| 29 | if (isset($_POST['removeStep'])) { |
---|
| 30 | if (isset($_POST['pipelineContents'])) { // if a step has been selected |
---|
| 31 | $toBeRemoved = $_POST['pipelineContents']; |
---|
| 32 | $tempArray = array(); |
---|
| 33 | foreach ($_SESSION['steps'] as $step) { |
---|
| 34 | if ($step != $toBeRemoved) { |
---|
| 35 | $tempArray[] = $step; |
---|
| 36 | } |
---|
| 37 | } |
---|
| 38 | $_SESSION['steps'] = $tempArray; |
---|
| 39 | unset($tempArray); |
---|
| 40 | unset($toBeRemoved); |
---|
| 41 | $_SESSION['selectedStep'] = null; |
---|
| 42 | } |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | /* |
---|
| 46 | * |
---|
| 47 | * Object creating code |
---|
| 48 | * |
---|
| 49 | */ |
---|
| 50 | |
---|
| 51 | // Questionnaire |
---|
| 52 | if (isset($_POST['createQuestionnaire'])) { |
---|
| 53 | $n = 1; |
---|
| 54 | while (in_array("Questionnaire $n", $_SESSION['steps'])) { |
---|
| 55 | $n++; |
---|
| 56 | } |
---|
| 57 | $_SESSION['steps'][] = "Questionnaire $n"; |
---|
| 58 | $_SESSION['selectedStep'] = "Questionnaire $n"; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | // Notice |
---|
| 62 | if (isset($_POST['createNotice'])) { |
---|
| 63 | $n = 1; |
---|
| 64 | while (in_array("Notice $n", $_SESSION['steps'])) { |
---|
| 65 | $n++; |
---|
| 66 | } |
---|
| 67 | $_SESSION['steps'][] = "Notice $n"; |
---|
| 68 | $_SESSION['selectedStep'] = "Notice $n"; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | // Application |
---|
| 72 | if (isset($_POST['createApplication'])) { |
---|
| 73 | $n = 1; |
---|
| 74 | while (in_array("Application $n", $_SESSION['steps'])) { |
---|
| 75 | $n++; |
---|
| 76 | } |
---|
| 77 | $_SESSION['steps'][] = "Application $n"; |
---|
| 78 | $_SESSION['selectedStep'] = "Application $n"; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | // Dashboard |
---|
| 82 | if (isset($_POST['createDashboard'])) { |
---|
| 83 | $n = 1; |
---|
| 84 | while (in_array("Dashboard $n", $_SESSION['steps'])) { |
---|
| 85 | $n++; |
---|
| 86 | } |
---|
| 87 | $_SESSION['steps'][] = "Dashboard $n"; |
---|
| 88 | $_SESSION['selectedStep'] = "Dashboard $n"; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | /* |
---|
| 92 | * |
---|
| 93 | * Move up/down code |
---|
| 94 | * |
---|
| 95 | */ |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | if (isset($_POST['moveUp'])) { // if user clicked "Move up" button |
---|
| 99 | if (isset($_POST['pipelineContents'])) { // if user has selected a pipeline step |
---|
| 100 | $arrayCopy = $_SESSION['steps']; // copy session contents to local variable, to prevent messing up the session by accident |
---|
| 101 | $key = array_search($_POST['pipelineContents'], $arrayCopy); // find key of target entry in array |
---|
| 102 | $_SESSION['selectedStep'] = $arrayCopy[$key]; |
---|
| 103 | moveEntry($arrayCopy, $key, -1); |
---|
| 104 | $_SESSION['steps'] = $arrayCopy; |
---|
| 105 | } |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | if (isset($_POST['moveDown'])) { // if user clicked "Move up" button |
---|
| 109 | if (isset($_POST['pipelineContents'])) { // if user has selected a pipeline step |
---|
| 110 | $arrayCopy = $_SESSION['steps']; // copy session contents to local variable, to prevent messing up the session by accident |
---|
| 111 | $key = array_search($_POST['pipelineContents'], $arrayCopy); // find key of target entry in array |
---|
| 112 | $_SESSION['selectedStep'] = $arrayCopy[$key]; |
---|
| 113 | moveEntry($arrayCopy, $key, 1); |
---|
| 114 | $_SESSION['steps'] = $arrayCopy; |
---|
| 115 | } |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | function moveEntry(&$array, $key, $dir) { |
---|
| 119 | if ($dir == -1) { // move up |
---|
| 120 | if ($key > 0) { |
---|
| 121 | $reverseArray = array_reverse(array_slice($array, $key - 1, 2, true)); // make a reversed array of the two entries, preserving keys |
---|
| 122 | array_splice($array, $key - 1, 2, $reverseArray); // replace the given range in the oldArray with the reversed Array |
---|
| 123 | } |
---|
| 124 | } else if ($dir == 1) { // move down |
---|
| 125 | if ($key < count($array) - 1) { |
---|
| 126 | $reverseArray = array_reverse(array_slice($array, $key, 2, true)); // make a reversed array of the two entries, preserving keys |
---|
| 127 | array_splice($array, $key, 2, $reverseArray); // replace the given range in the oldArray with the reversed Array |
---|
| 128 | } |
---|
| 129 | } |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | /* |
---|
| 133 | * |
---|
| 134 | * Edit code |
---|
| 135 | * |
---|
| 136 | */ |
---|
| 137 | |
---|
| 138 | if (isset($_POST['editStep'])) { |
---|
| 139 | editStep($_POST['pipelineContents']); |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | function editStep($step) { |
---|
| 143 | $_SESSION['activeStep'] = $step; |
---|
| 144 | switch (strtolower(substr($step, 0, strlen($step) - 2))) { |
---|
| 145 | case "questionnaire": |
---|
| 146 | redirect("editQuestionnaire.php?UID=$step->uid"); |
---|
| 147 | break; |
---|
| 148 | case "notice": |
---|
| 149 | redirect("editNotice.php?UID=$step->uid"); |
---|
| 150 | break; |
---|
| 151 | case "application": |
---|
| 152 | redirect("editApplication.php?UID=$step->uid"); |
---|
| 153 | break; |
---|
| 154 | case "dashboard": |
---|
| 155 | redirect("editDashboard.php?UID=$step->uid"); |
---|
| 156 | break; |
---|
| 157 | default: |
---|
| 158 | die("Invalid or no step type selected!"); |
---|
| 159 | break; |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | ?> |
---|
| 163 | <!-- |
---|
| 164 | To change this template, choose Tools | Templates |
---|
| 165 | and open the template in the editor. |
---|
| 166 | --> |
---|
| 167 | <!DOCTYPE html> |
---|
| 168 | <html> |
---|
| 169 | <head> |
---|
| 170 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
---|
| 171 | <title></title> |
---|
| 172 | <?php new StyleSheet("awesome"); ?> |
---|
| 173 | <script type="text/javascript" src="js/menu.js"></script> |
---|
| 174 | <script type="text/javascript" src="js/jquery.js"></script> |
---|
| 175 | <script type="text/javascript" src="js/editorScripts.js"></script> |
---|
| 176 | </head> |
---|
| 177 | <body onLoad="IsItemSelected(document.mainForm.pipelineContents, document.mainForm.editStep);"> |
---|
| 178 | <div id="header"> |
---|
| 179 | <?php new Logo(); ?> |
---|
| 180 | </div> |
---|
| 181 | |
---|
| 182 | <div id="wrapper"> |
---|
| 183 | <div id="content"> |
---|
| 184 | <form name ="mainForm" action="pipelineEditor_1.php" method="POST"> |
---|
| 185 | <fieldset> |
---|
| 186 | <select name="pipelineContents" style="width: 300px;" size="8" onChange="IsItemSelected(this, document.mainForm.editStep);"> |
---|
| 187 | <?php |
---|
| 188 | foreach ($_SESSION['steps'] as $step) { |
---|
| 189 | echo '<option value="' . $step . '" '; |
---|
| 190 | if ($step == $_SESSION['selectedStep']) { |
---|
| 191 | echo 'selected ="selected"'; |
---|
| 192 | } |
---|
| 193 | echo '>' . $step . '</option>' . "\n"; |
---|
| 194 | } |
---|
| 195 | ?> |
---|
| 196 | |
---|
| 197 | |
---|
| 198 | </select> |
---|
| 199 | <input type="submit" name="editStep" value="Edit" disabled="true"/> |
---|
| 200 | <input type="submit" name="removeStep" value="Remove" /> |
---|
| 201 | <input type="submit" name="moveUp" value="Move up" /> |
---|
| 202 | <input type="submit" name="moveDown" value="Move down" /> |
---|
| 203 | <input type="submit" name="clearPipeline" value="Clear pipeline" disabled="true"/> |
---|
| 204 | <input type="checkbox" name="confirmClear" onClick="IsCheckEnabled(this, document.mainForm.clearPipeline)"/> Really delete all? |
---|
| 205 | |
---|
| 206 | |
---|
| 207 | </fieldset> |
---|
| 208 | |
---|
| 209 | <fieldset> |
---|
| 210 | Add: |
---|
| 211 | <input type="submit" name="createQuestionnaire" value="Questionnaire" /> |
---|
| 212 | <input type="submit" name ="createNotice" value="Notice" /> |
---|
| 213 | <input type="submit" name="createApplication" value="Application" /> |
---|
| 214 | <input type="submit" name="createDashboard" value="Dashboard" /> |
---|
| 215 | </fieldset> |
---|
| 216 | |
---|
| 217 | <fieldset> |
---|
| 218 | <label>Debug</label> |
---|
| 219 | <input type="submit" name="resetSession" value="Reset Session" /> |
---|
| 220 | </fieldset> |
---|
| 221 | </form> |
---|
| 222 | </div> |
---|
| 223 | </body> |
---|
| 224 | </html> |
---|