PageRenderTime 59ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/include/elements.php

https://github.com/PaitoAnderson/MexicanBaker
PHP | 582 lines | 431 code | 144 blank | 7 comment | 77 complexity | a52db9448fa5280a2886818bf598de33 MD5 | raw file
  1. <?php
  2. function post($postid) {
  3. $pagetitle = "Post Title #" . $postid;
  4. $postbody = "";
  5. $postdesc = "";
  6. $post = "SELECT Post.PstTitle, Post.PstBody, Authors.AthFirstName, Authors.AthLastName, Post.PstDate, Post.PstDescription, Post.PstUrl, Credits.CreditType, Post.CreditName, Post.CreditURL, Post.Metatags, Authors.AID, Credits.CID, Post.PstActive, Post.PstHomePage, Post.PostCat FROM Post, Authors, Credits WHERE PID = " . $postid . " and Post.AuthorID = Authors.AID and Post.CreditID = Credits.CID";
  7. $result = mysql_query($post) or die(mysql_error());
  8. if(mysql_num_rows($result) == 0){
  9. $error = "1";
  10. };
  11. while ($row = mysql_fetch_array($result)) {
  12. $postdata = $row["PstTitle"] . "|" . $row["PstBody"] . "|" . $row["RecipeID"] . "|" . $row["AthFirstName"] . " " . $row["AthLastName"] . "|" . $row["PstDate"] . "|" . $row["PstDescription"] . "|" . $row["PstUrl"] . "|" . $row["CreditType"] . "|" . $row["CreditName"] . "|" . $row["CreditURL"] . "|" . $row["Metatags"] . "|" . $row["AID"] . "|" . $row["CID"] . "|" . $row["PstActive"] . "|" . $row["PstHomePage"] . "|" . $row["PostCat"];
  13. };
  14. return $postdata;
  15. };
  16. function posts($thispage, $perpage) {
  17. //Pagination Logic
  18. $pageend = ($thispage * $perpage);
  19. $pagestart = $pageend - $perpage;
  20. $postdata = "";
  21. $posts = "SELECT Post.PstTitle, Post.PstBody, Authors.AthFirstName, Authors.AthLastName, Post.PstDate, Post.PstDescription, Post.PstUrl, Credits.CreditType, Post.CreditName, Post.CreditURL, Post.Metatags, Authors.AID, Credits.CID, Post.PID FROM Post, Authors, Credits WHERE Post.AuthorID = Authors.AID and Post.CreditID = Credits.CID and Post.PstActive = 'Y' ORDER BY Post.PstDate DESC LIMIT " . $pagestart . "," . $pageend;
  22. $result = mysql_query($posts) or die(mysql_error());
  23. while ($row = mysql_fetch_array($result)) {
  24. $postdata = $postdata . $row["PstTitle"] . "|" . $row["PstBody"] . "|" . $row["RecipeID"] . "|" . $row["AthFirstName"] . " " . $row["AthLastName"] . "|" . $row["PstDate"] . "|" . $row["PstDescription"] . "|" . $row["PstUrl"] . "|" . $row["CreditType"] . "|" . $row["CreditName"] . "|" . $row["CreditURL"] . "|" . $row["Metatags"] . "|" . $row["AID"] . "|" . $row["CID"] . "|" . $row["PID"] . "|-|";
  25. };
  26. return $postdata;
  27. };
  28. function getSlides() {
  29. $slides = "SELECT `PID`, `PstTitle`, `PstURL` FROM `Post` WHERE `PstActive` = 'Y' and `PstHomePage` = 'Y' ORDER BY `PID` DESC";
  30. $result = mysql_query($slides) or die(mysql_error());
  31. $slidedata = "<div id=\"slides\">";
  32. while ($row = mysql_fetch_array($result)) {
  33. //$slidedata = $slidedata . "<a href=\"/post/" . $row["PID"] . "/" . $row["PstURL"] . "\" title=\"\"><img src=\"/images/posts/" . $row["PID"] . "/presentation.jpg\" width=\"950\" height=\"350\" alt=\"" . $row["PstTitle"] . "\"></a><div class=\"caption\"><p>" . $row["PstTitle"] . "</p></div>";
  34. $slidedata = $slidedata . "<a href=\"/post/" . $row["PID"] . "/" . $row["PstURL"] . "\" title=\"\"><img src=\"/images/posts/" . $row["PID"] . "/presentation.jpg\" alt=\"" . $row["PstTitle"] . "\"></a>";
  35. };
  36. $slidedata = $slidedata . "</div>";
  37. return $slidedata;
  38. }
  39. function postgroups($postid) {
  40. $sql = "SELECT Groups.GrpTitle FROM Groups, PostGroups WHERE PostGroups.PostID = " . $postid . " and Groups.GID = PostGroups.GroupID";
  41. $result = mysql_query($sql) or die(mysql_error());
  42. while ($row = mysql_fetch_array($result)) {
  43. If ($grouplist == "") {
  44. $grouplist = $grouplist . $row["GrpTitle"];
  45. } else {
  46. $grouplist = $grouplist . "|" . $row["GrpTitle"];
  47. };
  48. };
  49. return $grouplist;
  50. };
  51. function draftList() {
  52. $draftdata = "";
  53. $sql = "SELECT `PID`, `PstTitle` FROM `Post` WHERE `PstActive` = 'N' ORDER BY PID DESC";
  54. $result = mysql_query($sql) or die(mysql_error());
  55. while ($row = mysql_fetch_array($result)) {
  56. $draftdata = $draftdata . $row["PID"] . "|" . $row["PstTitle"] . "|-|";
  57. };
  58. return $draftdata;
  59. }
  60. function presentationPic($postid) {
  61. $filename = "/home/mexicanbaker/images/posts/" . $postid . "/presentation.jpg";
  62. if (file_exists($filename)) {
  63. return true;
  64. } else {
  65. return false;
  66. };
  67. };
  68. function postPic($postid, $imgid) {
  69. $filename = "/home/mexicanbaker/images/posts/" . $postid . "/image" . $imgid . ".jpg";
  70. if (file_exists($filename)) {
  71. return true;
  72. } else {
  73. return false;
  74. };
  75. };
  76. function postcount() {
  77. $sql = "SELECT `PID` FROM `Post` WHERE `PstActive` = 'Y'";
  78. $result = mysql_query($sql) or die(mysql_error());
  79. $numcount = mysql_num_rows($result);
  80. return $numcount;
  81. };
  82. function commentcount($postid) {
  83. $sql = "SELECT `CID` FROM `Comments` WHERE `PostID` = $postid";
  84. $result = mysql_query($sql) or die(mysql_error());
  85. $numcount = mysql_num_rows($result);
  86. return $numcount;
  87. };
  88. function commenthtml($postid) {
  89. $sql = "SELECT `ComBody`,`CommentDate`,`ComName`,`ComEmail`,`ComWebsite`,`CID` FROM `Comments` WHERE `PostID` = " . $postid . " AND `Hidden` = 'N' ORDER BY `CID` ASC";
  90. $result = mysql_query($sql) or die(mysql_error());
  91. while ($row = mysql_fetch_array($result)) {
  92. $commentout .= "<li class='comment'><article>";
  93. $commentout .= "<img alt='' src='" . get_gravatar($row["ComEmail"],50,"mm","g",false) . "' class='avatar' height='50' width='50'>";
  94. $commentout .= "<div class='comment-meta'>";
  95. $commentout .= "<h5 class='author'><cite class='fn'>";
  96. if (strlen($row["ComWebsite"]) > 0) {
  97. if (preg_match("#https?://#", $row['ComWebsite']) === 0) {
  98. $commentout .= "<a class='coollink' target='_blank' href='http://" . $row["ComWebsite"] . "'>" . $row["ComName"] . "</a>";
  99. } else {
  100. $commentout .= "<a class='coollink' target='_blank' href='" . $row["ComWebsite"] . "'>" . $row["ComName"] . "</a>";
  101. }
  102. } else {
  103. $commentout .= $row["ComName"];
  104. };
  105. if ($_SESSION['auth'] == "1") {
  106. $commentout .= "<span class='hidecomment'><a target='_blank' href='/include/comment.php?type=hide&post_id=" . $row["CID"] . "'>Hide Comment</a></span>";
  107. }
  108. $commentout .= "</cite></h5><p class='date2'><time pubdate='' datetime='" . date('Y-m-d\TH:i:sP', strtotime($row["CommentDate"])) . "'>". date('F d, Y H:i', strtotime($row["CommentDate"])) ."</time></p></div>";
  109. $commentout .= "<div class='comment-body'><p>" . $row['ComBody'] . "</p></div></article></li>";
  110. };
  111. return $commentout;
  112. };
  113. function recipehtml($postid, $posttitle, $recipeorder) {
  114. $sql = "SELECT RcpTitle, Difficulty, PrepTime, CookTime, Servings, PrepInstructions, RID FROM Recipe WHERE PostID = " . $postid . " and RcpOrder = " . $recipeorder;
  115. $result = mysql_query($sql) or die(mysql_error());
  116. while ($row = mysql_fetch_array($result)) {
  117. $rcptitle = $row["RcpTitle"];
  118. $difficulty = $row["Difficulty"];
  119. $preptime = $row["PrepTime"];
  120. $cooktime = $row["CookTime"];
  121. $servings = $row["Servings"];
  122. $prepinstructions = $row["PrepInstructions"];
  123. $recipeid = $row["RID"];
  124. };
  125. if (strlen($rcptitle) == 0) {
  126. $rcptitle = $posttitle;
  127. }
  128. $sql = "SELECT RecipeItems.TextLine FROM Recipe, RecipeItems WHERE RecipeItems.RecipeID = Recipe.RID and Recipe.PostID = " . $postid . " and Recipe.RcpOrder = " . $recipeorder . " Order By RecipeItems.RIID Desc";
  129. $result = mysql_query($sql) or die(mysql_error());
  130. $recipeout = "</p><div class='recipecard' itemscope itemtype=\"http://data-vocabulary.org/Recipe\">";
  131. $recipeout .= "<p class='postbody recipeprintbutton'><a target='_blank' href='/print/" . $recipeid . "'>PRINT</a>";
  132. $recipeout .= "<h2 itemprop=\"name\">" . $rcptitle . "</h2>";
  133. $preptimes = explode(":", $preptime);
  134. $cooktimes = explode(":", $cooktime);
  135. $recipeout .= "<span class='recipedetails'>DIFFICULTY: " . diffLabel($difficulty) . " &#149; PREP TIME: <time datetime=\"PT" . $preptimes[0] . "H" . $preptimes[1] . "M\" itemprop=\"preptime\">" . $preptime . "</time> &#149; COOK TIME: <time datetime=\"PT" . $cooktimes[0] . "H" . $cooktimes[1] . "M\" itemprop=\"cookTime\">" . $cooktime . "</time> &#149; SERVINGS: " . $servings . "</span><br /><br />";
  136. $recipeout .= "<h2>INGREDIENTS:</h2><ul>";
  137. while ($row = mysql_fetch_array($result)) {
  138. if(stristr($row["TextLine"], '<b>') === FALSE) {
  139. $recipeout .= "<li itemprop=\"ingredient\" itemscope itemtype=\"http://data-vocabulary.org/RecipeIngredient\"><span itemprop=\"name\">" . $row["TextLine"] . "</span></li>";
  140. } else {
  141. $recipeout .= "<li itemprop=\"ingredient\" itemscope itemtype=\"http://data-vocabulary.org/RecipeIngredient\" style='list-style:none;'><span itemprop=\"name\">" . $row["TextLine"] . "</span></li>";
  142. }
  143. };
  144. $recipeout .= "</ul><br /><h2>PREPARATION:</h2><p class='postbody' itemprop=\"instructions\">";
  145. $recipeout .= $prepinstructions;
  146. $recipeout .= "</p></div><p class='postbody'>";
  147. return $recipeout;
  148. }
  149. function recipeprint($recipeid) {
  150. $sql = "SELECT R.RcpTitle, P.PstTitle, R.Difficulty, R.PrepTime, R.CookTime, R.Servings, R.PrepInstructions FROM Recipe R, Post P WHERE (R.PostID = P.PID) AND R.RID = " . $recipeid;
  151. $result = mysql_query($sql) or die(mysql_error());
  152. while ($row = mysql_fetch_array($result)) {
  153. $rcptitle = $row["RcpTitle"];
  154. $posttitle = $row["PstTitle"];
  155. $difficulty = $row["Difficulty"];
  156. $preptime = $row["PrepTime"];
  157. $cooktime = $row["CookTime"];
  158. $servings = $row["Servings"];
  159. $prepinstructions = $row["PrepInstructions"];
  160. };
  161. if (strlen($rcptitle) == 0) {
  162. $rcptitle = $posttitle;
  163. }
  164. $sql = "SELECT RecipeItems.TextLine FROM RecipeItems WHERE RecipeItems.RecipeID = " . $recipeid . " Order By RecipeItems.RIID Desc";
  165. $result = mysql_query($sql) or die(mysql_error());
  166. $recipeout .= "<title>Mexican Baker - " . $rcptitle . "</title></head><body onload='window.print();'>";
  167. $recipeout .= "<div class='recipecard2'>";
  168. $recipeout .= "<p class='postbody recipeprintbutton'>";
  169. $recipeout .= "<h2>Mexican Baker - " . $rcptitle . "</h2>";
  170. $recipeout .= "<span class='recipedetails'>DIFFICULTY: " . diffLabel($difficulty) . " <br /> PREP TIME: " . $preptime . " <br /> COOK TIME: " . $cooktime . " <br /> SERVINGS: " . $servings . "</span><br />";
  171. $recipeout .= "<h2>INGREDIENTS:</h2><ul>";
  172. while ($row = mysql_fetch_array($result)) {
  173. if(stristr($row["TextLine"], '<b>') === FALSE) {
  174. $recipeout .= "<li>" . $row["TextLine"] . "</li>";
  175. } else {
  176. $recipeout .= "<li style='list-style:none;'>" . $row["TextLine"] . "</li>";
  177. }
  178. };
  179. $recipeout .= "</ul><h2>PREPARATION:</h2><p class='postbody'>";
  180. $recipeout .= nl2br($prepinstructions);
  181. $recipeout .= "</p></div>";
  182. return $recipeout;
  183. }
  184. function recipecount($postid) {
  185. $sql = "SELECT `RID` FROM `Recipe` WHERE `PostID` = " . $postid . ";";
  186. $result = mysql_query($sql) or die(mysql_error());
  187. $numcount = mysql_num_rows($result);
  188. return $numcount;
  189. };
  190. function creditoption($cid) {
  191. $sql = "SELECT `CID`, `CreditType` FROM Credits";
  192. $result = mysql_query($sql) or die(mysql_error());
  193. $creditout = "<select style='padding:0px;height:19px;width:100px;' id='selCredit' name='selCredit'>";
  194. while ($row = mysql_fetch_array($result)) {
  195. $creditout .= "<option value='" . $row["CID"] . "'";
  196. if ($cid == $row["CID"]) {
  197. $creditout .= " selected";
  198. };
  199. $creditout .= ">" . $row["CreditType"] . "</option>";
  200. };
  201. $creditout .= "</select>";
  202. return $creditout;
  203. };
  204. function authoroption($aid) {
  205. $sql = "SELECT `AID`, `AthFirstName`, `AthLastName` FROM Authors WHERE AthActive = 'Y'";
  206. $result = mysql_query($sql) or die(mysql_error());
  207. $authorout = "<select style='padding:0px;height:19px;width:100px;' id='selAuthor' name='selAuthor'>";
  208. while ($row = mysql_fetch_array($result)) {
  209. $authorout = $authorout . "<option value='" . $row["AID"] . "'";
  210. if ($aid == $row["AID"]) {
  211. $authorout = $authorout . " selected";
  212. };
  213. $authorout = $authorout . ">" . $row["AthFirstName"] . " " . $row["AthLastName"] . "</option>";
  214. };
  215. $authorout = $authorout . "</select>";
  216. return $authorout;
  217. };
  218. function authorhtml($aid) {
  219. $sql = "SELECT `AthDesc`, `AthEmail`, `AthFirstName`, `AthLastName` FROM Authors WHERE AID = " . $aid .";";
  220. $result = mysql_query($sql) or die(mysql_error());
  221. while ($row = mysql_fetch_array($result)) {
  222. $authorname = $row["AthFirstName"] . " " . $row["AthLastName"];
  223. $authorout .= "<div class='abouttheauthor' itemscope itemtype=\"http://data-vocabulary.org/Person\">";
  224. $authorout .= "<div class='atapic'><img src='http://www.gravatar.com/avatar/";
  225. $authorout .= md5(strtolower(trim($row["AthEmail"])));
  226. $authorout .= "?s=100&d=mm&r=g' alt='" . $authorname . "' /></div><div class='atatext'><h2 itemprop=\"name\">";
  227. $authorout .= $authorname . "</h2><p>" . $row["AthDesc"] . "</p></div></div>";
  228. };
  229. return $authorout;
  230. }
  231. function catoption($catid) {
  232. $sql = "SELECT `CATID`, `CatTitle` FROM Categories WHERE CatActive = 'Y'";
  233. $result = mysql_query($sql) or die(mysql_error());
  234. $catout = "<select style='padding:0px;height:19px;width:100px;' id='selCat' name='selCat'>";
  235. while ($row = mysql_fetch_array($result)) {
  236. $catout = $catout . "<option value='" . $row["CATID"] . "'";
  237. if ($catid == $row["CATID"]) {
  238. $catout = $catout . " selected";
  239. };
  240. $catout = $catout . ">" . $row["CatTitle"] . "</option>";
  241. };
  242. $catout = $catout . "</select>";
  243. return $catout;
  244. };
  245. function yesno($yesorno, $fieldname) {
  246. $stringout = "<select style='padding:0px;height:19px;width:50px;' id='" . $fieldname . "' name='" . $fieldname . "'>";
  247. //Yes
  248. $stringout = $stringout . "<option value='Y'";
  249. if ($yesorno == 'Y') {
  250. $stringout = $stringout . " selected";
  251. };
  252. $stringout = $stringout . ">Yes</option>";
  253. //No
  254. $stringout = $stringout . "<option value='N'";
  255. if ($yesorno == 'N') {
  256. $stringout = $stringout . " selected";
  257. };
  258. $stringout = $stringout . ">No</option>";
  259. $stringout = $stringout . "</select>";
  260. return $stringout;
  261. };
  262. function isloggedin() {
  263. if ($_SESSION['auth'] != "1") {
  264. header("Location: index.php");
  265. return False;
  266. } else {
  267. return True;
  268. }
  269. }
  270. function newPostNumber() {
  271. $sql = "SELECT Max(`PID`) As 'NextPID' FROM `Post`";
  272. $result = mysql_query($sql) or die(mysql_error());
  273. while ($row = mysql_fetch_array($result)) {
  274. $currentPostId = $row["NextPID"];
  275. };
  276. return $currentPostId + 1;
  277. }
  278. function newRecipeNumber() {
  279. $sql = "SELECT Max(`RID`) As 'NextRID' FROM `Recipe`";
  280. $result = mysql_query($sql) or die(mysql_error());
  281. while ($row = mysql_fetch_array($result)) {
  282. $currentPostId = $row["NextRID"];
  283. };
  284. return $currentPostId + 1;
  285. }
  286. function recipeExists($postid, $index) {
  287. $sql = "SELECT `RID` FROM `Recipe` WHERE `PostID` = $postid AND `RcpOrder` = $index";
  288. $result = mysql_query($sql) or die(mysql_error());
  289. $numcount = mysql_num_rows($result);
  290. if ($numcount > 0) {
  291. while ($row = mysql_fetch_array($result)) {
  292. return $row["RID"];
  293. };
  294. } else {
  295. return "FALSE";
  296. };
  297. }
  298. function recipeExistsID($recipeid) {
  299. $sql = "SELECT `RID` FROM `Recipe` WHERE `RID` = $recipeid";
  300. $result = mysql_query($sql) or die(mysql_error());
  301. $numcount = mysql_num_rows($result);
  302. if ($numcount > 0) {
  303. return true;
  304. } else {
  305. return false;
  306. };
  307. }
  308. function formatpostbody($postid, $postbody, $posttitle, $continue) {
  309. if ($continue) {
  310. $postbody = substr($postbody, 0, strpos($postbody, "%continue%"));
  311. //$postbody = stristr($postbody, "%continue%", true); //PHP 5.3
  312. } else {
  313. $postbody = str_replace("%continue%","",$postbody);
  314. }
  315. for ($i = 1; $i <= 25; $i++) {
  316. $postbody = str_replace("%img". $i . "%", imgsForDetailView($postid, $posttitle, $i), $postbody);
  317. }
  318. for ($i = 1; $i <= recipecount($postid); $i++) {
  319. $postbody = str_replace("%recipe". $i . "%", recipehtml($postid, $posttitle, $i), $postbody);
  320. }
  321. $postbody = nl2br($postbody);
  322. return $postbody;
  323. };
  324. function validate($email, $pass) {
  325. $sql = "SELECT `AthFirstName` FROM Authors WHERE AthEmail = '" . sqlQuotes($email) . "' and AthPass = '" . sqlQuotes($pass) . "'";
  326. $result = mysql_query($sql) or die(mysql_error());
  327. $validate = "FAILED";
  328. while ($row = mysql_fetch_array($result)) {
  329. $validate = $row["AthFirstName"];
  330. };
  331. return $validate;
  332. };
  333. //RECIPE EDITOR FUNCTIONS
  334. $ingredientsDropDownHtml = ""; //TODO: Implement this to save SQL Calls.
  335. function numDropDown($num, $selected) {
  336. $numbers = array("0","1","2","3","4","5","6","7","8","9","10","11","12");
  337. $numDropDown = "<select id='number" . $num . "' name='number" . $num . "'>";
  338. foreach ($numbers as &$value) {
  339. $numDropDown = $numDropDown . "<option value='" . $value . "'";
  340. if ($selected == $value) {
  341. $numDropDown = $numDropDown . " selected";
  342. }
  343. $numDropDown = $numDropDown . ">" . $value . " </option>";
  344. };
  345. $numDropDown = $numDropDown . "</select>";
  346. return $numDropDown;
  347. }
  348. function quantityDropDown($num, $selected) {
  349. //$fractions = array("1/8","1/7","1/6","1/5","1/4","1/3","1/2","2/7","2/5","2/3","3/8","3/7","3/5","3/4","4/7","4/5","5/8","5/7","5/6","6/7","7/8");
  350. $fractions = array("1/8","1/4","1/3","1/2","2/3","3/8","3/4","5/8","7/8");
  351. $quantityDropDown = "<select id='quantity" . $num . "' name='quantity" . $num . "'>";
  352. $quantityDropDown = $quantityDropDown . "<option value=''>0</option>";
  353. foreach ($fractions as &$value) {
  354. $numbervalue = number_format(factionToDec($value), 2, '.', '');
  355. $quantityDropDown = $quantityDropDown . "<option value='" . $numbervalue . "'";
  356. if (strval($selected) == strval($numbervalue)) {
  357. $quantityDropDown = $quantityDropDown . " selected";
  358. }
  359. $quantityDropDown = $quantityDropDown . ">" . decToFraction2($numbervalue) . " </option>";
  360. };
  361. $quantityDropDown = $quantityDropDown . "</select>";
  362. return $quantityDropDown;
  363. }
  364. function diffDropDown($selected) {
  365. $difficulty = array("E","M","H");
  366. $diffDropDown = "<select id='difficulty' name='difficulty'>";
  367. foreach ($difficulty as &$value) {
  368. $diffDropDown = $diffDropDown . "<option value='" . $value . "'";
  369. if ($selected == $value) {
  370. $diffDropDown = $diffDropDown . " selected";
  371. }
  372. $diffDropDown = $diffDropDown . ">" . diffLabel($value) . " </option>";
  373. };
  374. $diffDropDown = $diffDropDown . "</select>";
  375. return $diffDropDown;
  376. }
  377. function diffLabel($diffSet) {
  378. switch ($diffSet) {
  379. case "E":
  380. return "EASY";
  381. break;
  382. case "M":
  383. return "MEDIUM";
  384. break;
  385. case "H":
  386. return "HARD";
  387. break;
  388. }
  389. }
  390. function servingsDropDown($servingsNum) {
  391. $servingsDeopDown = "<select id='servings' name='servings'>";
  392. for ($i = 1; $i <= 30; $i++) {
  393. $servingsDeopDown = $servingsDeopDown . "<option value='" . $i . "'";
  394. if ($servingsNum == $i) {
  395. $servingsDeopDown = $servingsDeopDown . " selected";
  396. }
  397. $servingsDeopDown = $servingsDeopDown . ">" . $i . " </option>";
  398. }
  399. $servingsDeopDown = $servingsDeopDown . "</select>";
  400. return $servingsDeopDown;
  401. }
  402. function unitsDropDown($num, $selected) {
  403. $sql = "SELECT `UID`, `UntName` FROM Units WHERE UntActive = 'Y' ORDER BY `UntName`";
  404. $result = mysql_query($sql) or die(mysql_error());
  405. $ingout = "<select id='unit" . $num . "' name='unit" . $num . "'>";
  406. while ($row = mysql_fetch_array($result)) {
  407. $ingout = $ingout . "<option value='" . $row["UID"] . "'";
  408. if ($selected == $row["UID"]) {
  409. $ingout = $ingout . " selected";
  410. };
  411. $ingout = $ingout . ">" . $row["UntName"] . "</option>";
  412. };
  413. $ingout = $ingout . "</select>";
  414. return $ingout;
  415. };
  416. function ingredientsDropDown($num, $selected) {
  417. $sql = "SELECT `IID`, `IngName` FROM Ingredients WHERE IngActive = 'Y' ORDER BY `IngName`";
  418. $result = mysql_query($sql) or die(mysql_error());
  419. $ingout = "<select id='ingredient" . $num . "' name='ingredient" . $num . "'>";
  420. $ingout = $ingout . "<option value=''> - SELECT - </option>";
  421. while ($row = mysql_fetch_array($result)) {
  422. $ingout = $ingout . "<option value='" . $row["IID"] . "'";
  423. if ($selected == $row["IID"]) {
  424. $ingout = $ingout . " selected";
  425. };
  426. $ingout = $ingout . ">" . $row["IngName"] . "</option>";
  427. };
  428. $ingout = $ingout . "</select>";
  429. return $ingout;
  430. };
  431. function sqlQuotes($string)
  432. {
  433. return str_replace("'", "''", $string);
  434. }
  435. ?>