|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Project name: InFood |
| 4 | + * File-name: recipes.php |
| 5 | + * Author: Jacob Liscom |
| 6 | + * Version: 13.2.0 |
| 7 | +**/ |
| 8 | + |
| 9 | +//include_once dirname(__FILE__)."/modules/core/Common.php"; |
| 10 | +//OO code |
| 11 | +class NoteBook{ |
| 12 | + /** |
| 13 | + * Constructor |
| 14 | + * @param mode - the mode for the reviewer |
| 15 | + * @param id - the id of and existing class if a subFolder. Default value is null |
| 16 | + */ |
| 17 | + public function NoteBook($id = NULL){ |
| 18 | + if($id!=NULL) |
| 19 | + $this->subFolder($id);//TODO |
| 20 | + else |
| 21 | + $this->root(); |
| 22 | + } |
| 23 | + |
| 24 | + /** |
| 25 | + * Displays the root folder contents |
| 26 | + */ |
| 27 | + private function root(){ |
| 28 | + echo " <script type=\"text/javascript\"> |
| 29 | + setButton0(\"\"); |
| 30 | + setButton1(\"New Folder\"); |
| 31 | + setButton2(\"Find\"); |
| 32 | + setURL(\"./\",\"OpenNote\"); |
| 33 | + </script>"; |
| 34 | + |
| 35 | + //echo the label for the page |
| 36 | + self::folderTitle("Home",false); |
| 37 | + |
| 38 | + $result = Core::query("SELECT id, parrentFolderID, name FROM folder WHERE parrentFolderID IS NULL AND userID=? ORDER BY name",array(Authenticater::getUserID())); |
| 39 | + foreach($result as $row) |
| 40 | + echo self::boxFactory($row["id"], "folder green", $row["name"], null,"Folder"); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Display sub folder |
| 45 | + * @param id - the id of the sub folder |
| 46 | + */ |
| 47 | + public function subFolder($id){ |
| 48 | + |
| 49 | + $query = Core::query("SELECT id, parrentFolderID, name FROM folder WHERE id = ? AND userID=? ORDER BY name",array($id, Authenticater::getUserID())); |
| 50 | + |
| 51 | + if(!count($query)) |
| 52 | + return; |
| 53 | + |
| 54 | + echo sprintf(" <script type=\"text/javascript\"> |
| 55 | + setButton0(\"New Note\"); |
| 56 | + setButton1(\"New Folder\"); |
| 57 | + setButton2(\"Find\"); |
| 58 | + setURL(\"index.php?folderID=%d\",\"%s\"); |
| 59 | + </script>", $query[0]["id"], $query[0]["name"]); |
| 60 | + |
| 61 | + //echo this foldersID for future reference |
| 62 | + echo sprintf("<folder id=\"folder\" folderID=\"%d\"></list>",$query[0]["id"]); |
| 63 | + |
| 64 | + |
| 65 | + //echo the label for the page |
| 66 | + self::folderTitle($query[0]["name"],true); |
| 67 | + |
| 68 | + //get all the folders |
| 69 | + $folders = Core::query("SELECT id, parrentFolderID, name FROM folder WHERE parrentFolderID = ? and userID=? ORDER BY name", array($id,Authenticater::getUserID())); |
| 70 | + foreach($folders as $row) |
| 71 | + echo self::boxFactory($row["id"], "folder green", $row["name"], null,"Folder"); |
| 72 | + |
| 73 | + //get all the notes |
| 74 | + $folders = Core::query("SELECT n.id, n.title |
| 75 | + FROM note n |
| 76 | + WHERE n.folderID = ? |
| 77 | + AND (n.originNoteID IS NULL OR n.id IN (SELECT MAX(id) FROM note WHERE originNoteID=n.originNoteID)) |
| 78 | + AND (SELECT COUNT(*) FROM note WHERE originNoteID = n.id)=0 |
| 79 | + AND userID=? |
| 80 | + ORDER BY n.title", |
| 81 | + array($id,Authenticater::getUserID()));//bascally get notes that id is null and have not been overwriten or are the latest |
| 82 | + foreach($folders as $row) |
| 83 | + echo self::boxFactory($row["id"], "note", $row["title"], null,null,"Note"); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * echos the folder list |
| 88 | + * @param folderList - a array of all the folders |
| 89 | + */ |
| 90 | + public static function getFolderList(){ |
| 91 | + $root = Core::query("SELECT id, parrentFolderID, name FROM folder WHERE parrentFolderID IS NULL AND userID=? ORDER BY name",array(Authenticater::getUserID())); |
| 92 | + if(count($root)==0) |
| 93 | + return; |
| 94 | + |
| 95 | + self::startSubTree(); |
| 96 | + foreach ($root as $rootFolder) |
| 97 | + self::getChildren($rootFolder["id"],$rootFolder["name"]); |
| 98 | + self::endSubTree(); |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * This method prints the folder passed in and finds all children and prints them |
| 103 | + * @param folderID - the folder to find children for |
| 104 | + * @param name - the name of the folder to find children for |
| 105 | + */ |
| 106 | + private static function getChildren($folderID, $name){ |
| 107 | + self::startTreeEntry(); |
| 108 | + self::treeEntryFactory($folderID, $name); //print self |
| 109 | + |
| 110 | + $result = Core::query("SELECT id, parrentFolderID, name FROM folder WHERE parrentFolderID=? AND userID=? ORDER BY name",array($folderID,Authenticater::getUserID())); |
| 111 | + if(count($result)>0){//do I have any children |
| 112 | + self::startSubTree();//great line them up |
| 113 | + |
| 114 | + foreach($result as $child) |
| 115 | + self::getChildren($child["id"],$child["name"]); |
| 116 | + |
| 117 | + self::endSubTree(); |
| 118 | + } |
| 119 | + |
| 120 | + self::endTreeEntry(); |
| 121 | + } |
| 122 | + |
| 123 | + /** |
| 124 | + * creates a new folder |
| 125 | + * @param parrentID - the id of the parent folder. |
| 126 | + * @param name - the title of folder |
| 127 | + */ |
| 128 | + public static function newFolder($parentID =null,$name){ |
| 129 | + Core::query("INSERT INTO folder(parrentFolderID,name, userID) VALUES(?,?,?)",array($parentID,$name,Authenticater::getUserID())); |
| 130 | + |
| 131 | + //update the view |
| 132 | + echo " <script type=\"text/javascript\"> |
| 133 | + getFolderList(); |
| 134 | + </script>"; |
| 135 | + new NoteBook($parentID); |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * delete a new folder |
| 140 | + * @param $id - the id of the folder to delete. |
| 141 | + */ |
| 142 | + public static function removeFolder($id){ |
| 143 | + $parrent = Core::query("SELECT parrentFolderID, name, userID FROM folder WHERE id=? AND userID=?;",array($id,Authenticater::getUserID())); |
| 144 | + Core::query("DELETE FROM folder WHERE id=? AND userID=?;",array($id,Authenticater::getUserID())); |
| 145 | + |
| 146 | + //update the view |
| 147 | + echo " <script type=\"text/javascript\"> |
| 148 | + getFolderList(); |
| 149 | + </script>"; |
| 150 | + new NoteBook($parrent[0]["parrentFolderID"]); |
| 151 | + } |
| 152 | + |
| 153 | + /** |
| 154 | + * change a folders parrent |
| 155 | + * @param folderID - the folder id to change the parrent of |
| 156 | + * @param newParrentID - the new parrent of the folder |
| 157 | + */ |
| 158 | + public static function moveFolder($folderID, $newParrentID){ |
| 159 | + $parrent = Core::query("UPDATE folder SET parrentFolderID = ? WHERE id=? AND userID=?;",array($newParrentID,$folderID,Authenticater::getUserID())); |
| 160 | + } |
| 161 | + |
| 162 | + /** |
| 163 | + * @param id - the id of the box |
| 164 | + * @param color/class - the color/class code to format the box |
| 165 | + * @param title - the title string |
| 166 | + * @param desc - the description |
| 167 | + * @return - return a box html to go into the box container |
| 168 | + */ |
| 169 | + private static function boxFactory($id=null, $color=null, $title=null,$desc=null,$left=null,$right=null){ |
| 170 | + return " |
| 171 | + <div class=\"box $color startHidden\" boxID=\"$id\"> |
| 172 | + <h2> |
| 173 | + $title |
| 174 | + </h2> |
| 175 | + <p class=\"box_description\">$desc</p> |
| 176 | + <p class=\"options\"> |
| 177 | + $left |
| 178 | + <span class=\"right\">$right</span> |
| 179 | + </p> |
| 180 | + </div> |
| 181 | + |
| 182 | + <script type=\"text/javascript\"> |
| 183 | + $(\"[boxID=$id]\").fadeIn(fadeSpeedLong*Math.random()+200); |
| 184 | + </script>"; |
| 185 | + } |
| 186 | + |
| 187 | + /** |
| 188 | + * @param folderID - the folder id to print the entry for |
| 189 | + * @param title - the title of the folder to print |
| 190 | + */ |
| 191 | + private static function treeEntryFactory($folderID, $title){ |
| 192 | + echo "<a class=\"customButton folder\" folderID=\"$folderID\">$title</a>"; |
| 193 | + } |
| 194 | + |
| 195 | + /** |
| 196 | + * start a tree entry |
| 197 | + */ |
| 198 | + private static function startTreeEntry(){ |
| 199 | + echo "<li>"; |
| 200 | + } |
| 201 | + |
| 202 | + /** |
| 203 | + * close a entry tag |
| 204 | + */ |
| 205 | + private static function endTreeEntry(){ |
| 206 | + echo "</li>"; |
| 207 | + } |
| 208 | + |
| 209 | + /** |
| 210 | + * start a sub tree |
| 211 | + */ |
| 212 | + private static function startSubTree(){ |
| 213 | + echo "<ul>"; |
| 214 | + } |
| 215 | + |
| 216 | + /** |
| 217 | + * close a sub tree |
| 218 | + */ |
| 219 | + private static function endSubTree(){ |
| 220 | + echo "</ul>"; |
| 221 | + } |
| 222 | + |
| 223 | + /** |
| 224 | + * @param title - the title for the folder |
| 225 | + * @param remove - weather to show the remove button |
| 226 | + * echos the title block |
| 227 | + */ |
| 228 | + private static function folderTitle($title, $remove){ |
| 229 | + $button=""; |
| 230 | + if($remove) |
| 231 | + $button="<button id=\"removeFolder\" class=\"customButton\">X</button>"; |
| 232 | + |
| 233 | + echo sprintf( |
| 234 | + "<div id=\"folderTitleBar\"> |
| 235 | + <div id=\"folderTitle\">%s</div> |
| 236 | + %s |
| 237 | + </div>",$title,$button); |
| 238 | + } |
| 239 | +} |
| 240 | +?> |
0 commit comments