/wp-content/plugins/wp-shopping-cart/google_base_functions.php

https://github.com/alx/barceloneta · PHP · 566 lines · 350 code · 75 blank · 141 comment · 25 complexity · 33adbab244403914b7372c32299317a8 MD5 · raw file

  1. <?php
  2. /* Our Google Base API developer key. */
  3. $developerKey = "ABQIAAAA6ggeUfjN1SpHwYsrpccTGhRuQWnos65R7rFyIjvnCKH4e1YArxSdx2HKFtraZCwQgrQplEXLG99isg";
  4. /* The items feed URL, used for queries, insertions and batch commands. */
  5. $itemsFeedURL = "http://www.google.com/base/feeds/items";
  6. /* Parsed recipe entries from a query. */
  7. $parsedEntries = array();
  8. /* Are we currently parsing an XML ENTRY tag? */
  9. $foundEntry = false;
  10. /* Current XML element being processed. */
  11. $curElement = "";
  12. /* Types of cuisine the user may select when inserting a recipe. */
  13. $cuisines = array('African', 'American', 'Asian', 'Caribbean', 'Chinese', 'French', 'Greek', 'Indian', 'Italian', 'Japanese', 'Jewish', 'Mediterranean', 'Mexican', 'Middle Eastern', 'Moroccan', 'North American', 'Spanish', 'Thai', 'Vietnamese', 'Other');
  14. /**
  15. * Creates the XML content used to insert a new recipe.
  16. */
  17. function buildInsertXML($name,$price,$description) {
  18. $result = "<?xml version='1.0'?>" . "\n";
  19. // $result .= "<entry xmlns='http://www.w3.org/2005/Atom'" . " xmlns:g='http://base.google.com/ns/1.0'>" . "\n";
  20. // $result .= "<category scheme='http://base.google.com/categories/itemtypes'" . " term='Products'/>" . "\n";
  21. // $result .= "<title type='text'>" . 'pizza' . "</title>" . "\n";
  22. // // $result .= "<g:cuisine>" . 'Chinese' . "</g:cuisine>" . "\n";
  23. // $result .= "<g:item_type type='text'>Recipes</g:item_type>" . "\n";
  24. // // $result .= "<g:cooking_time type='intUnit'>" . $_POST['time_val'] . " " . $_POST['time_units'] . "</g:cooking_time>" . "\n";
  25. // // $result .= "<g:main_ingredient type='text'>" . $_POST['main_ingredient'] . "</g:main_ingredient>" . "\n";
  26. // // $result .= "<g:serving_count type='number'>" . $_POST['serves'] . "</g:serving_count>" . "\n";
  27. // $result .= "<content>" . 'whatever'. "</content>" . "\n";
  28. // $result .= "</entry>" . "\n";
  29. $result .= "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:g='http://base.google.com/ns/1.0'>
  30. <category scheme='http://base.google.com/categories/itemtypes' term='Products'/>
  31. <g:item_type type='text'>Products</g:item_type>
  32. <g:price type='floatUnit'> ".$price."</g:price>
  33. <title type='text'>".$name."</title>
  34. <content>".$description."</content>
  35. </entry>";
  36. return $result;
  37. }
  38. /**
  39. * Creates the XML content used to perform a batch delete.
  40. */
  41. function buildBatchXML() {
  42. $counter = 0;
  43. $result = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
  44. $result .= '<feed xmlns="http://www.w3.org/2005/Atom"' . "\n";
  45. $result .= ' xmlns:g="http://base.google.com/ns/1.0"' . "\n";
  46. $result .= ' xmlns:batch="http://schemas.google.com/gdata/batch">' . "\n";
  47. foreach($_POST as $key => $value) {
  48. if(substr($key, 0, 5) == "link_") {
  49. $counter++;
  50. $result .= '<entry>' . "\n";
  51. $result .= '<id>' . $value . '</id>' . "\n";
  52. $result .= '<batch:operation type="delete"/>' . "\n";
  53. $result .= '<batch:id>' . $counter . '</batch:id>' . "\n";
  54. $result .= '</entry>' . "\n";
  55. }
  56. }
  57. $result .= '</feed>' . "\n";
  58. return $result;
  59. }
  60. /**
  61. * Exchanges the given single-use token for a session
  62. * token using AuthSubSessionToken, and returns the result.
  63. */
  64. function exchangeToken($token) {
  65. $ch = curl_init(); /* Create a CURL handle. */
  66. curl_setopt($ch, CURLOPT_URL, "https://www.google.com/accounts/AuthSubSessionToken");
  67. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  68. curl_setopt($ch, CURLOPT_FAILONERROR, true);
  69. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  70. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: AuthSub token="' . $token . '"'));
  71. $result = curl_exec($ch); /* Execute the HTTP command. */
  72. curl_close($ch);
  73. $splitStr = split("=", $result);
  74. return trim($splitStr[1]);
  75. }
  76. /**
  77. * Performs a query for all of the user's items using the
  78. * items feed, then parses the resulting XML with the
  79. * startElement, endElement and characterData functions
  80. * (below).
  81. */
  82. function getItems($token) {
  83. $ch = curl_init(); /* Create a CURL handle. */
  84. global $developerKey, $itemsFeedURL;
  85. curl_setopt($ch, CURLOPT_URL, $itemsFeedURL . "?");
  86. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  87. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/atom+xml', 'Authorization: AuthSub token="' . trim($token) . '"', 'X-Google-Key: key=' . $developerKey));
  88. $result = curl_exec($ch); /* Execute the HTTP command. */
  89. curl_close($ch);
  90. /* Parse the resulting XML. */
  91. $xml_parser = xml_parser_create();
  92. xml_set_element_handler($xml_parser, "startElement", "endElement");
  93. xml_set_character_data_handler($xml_parser, "characterData");
  94. xml_parse($xml_parser, $result);
  95. xml_parser_free($xml_parser);
  96. }
  97. /**
  98. * Inserts a new recipe by performing an HTTP POST to the
  99. * items feed.
  100. */
  101. function postItem($name,$price,$description, $token='') {
  102. $ch = curl_init(); /* Create a CURL handle. */
  103. global $developerKey, $itemsFeedURL;
  104. /* Set cURL options. */
  105. curl_setopt($ch, CURLOPT_URL, $itemsFeedURL);
  106. curl_setopt($ch, CURLOPT_POST, true);
  107. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  108. curl_setopt($ch, CURLOPT_FAILONERROR, true);
  109. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: AuthSub token="' . $token . '"', 'X-Google-Key: key=' . $developerKey, 'Content-Type: application/atom+xml'));
  110. $xml=buildInsertXML($name,$price,$description);
  111. // exit($xml);
  112. curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
  113. $result = curl_exec($ch); /* Execute the HTTP request. */
  114. curl_close($ch); /* Close the cURL handle. */
  115. // exit($result);
  116. return $result;
  117. }
  118. /**
  119. * Updates an existing recipe by performing an HTTP PUT
  120. * on its feed URI, using the updated values a PUT data.
  121. */
  122. function updateItem() {
  123. $ch = curl_init(); /* Create a CURL handle. */
  124. global $developerKey;
  125. /* Prepare the data for HTTP PUT. */
  126. $putString = buildInsertXML();
  127. $putData = tmpfile();
  128. // exit("=======><pre>".var_dump($putData)."</pre>");
  129. fwrite($putData, $putString);
  130. fseek($putData, 0);
  131. /* Set cURL options. */
  132. curl_setopt($ch, CURLOPT_URL, $_POST['link']);
  133. curl_setopt($ch, CURLOPT_PUT, true);
  134. curl_setopt($ch, CURLOPT_INFILE, $putData);
  135. curl_setopt($ch, CURLOPT_INFILESIZE, strlen($putString));
  136. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  137. curl_setopt($ch, CURLOPT_FAILONERROR, true);
  138. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: AuthSub token="' . $_POST['token'] . '"', 'X-Google-Key: key=' . $developerKey, 'Content-Type: application/atom+xml'));
  139. $result = curl_exec($ch); /* Execute the HTTP request. */
  140. fclose($putData); /* Close and delete the temp file. */
  141. curl_close($ch); /* Close the cURL handle. */
  142. return $result;
  143. }
  144. /**
  145. * Deletes a recipe by performing an HTTP DELETE (a custom
  146. * cURL request) on its feed URI.
  147. */
  148. function deleteItem() {
  149. $ch = curl_init();
  150. global $developerKey;
  151. /* Set cURL options. */
  152. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
  153. curl_setopt($ch, CURLOPT_URL, $_POST['link']);
  154. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  155. curl_setopt($ch, CURLOPT_FAILONERROR, true);
  156. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: AuthSub token="' . $_POST['token'] . '"', 'X-Google-Key: key=' . $developerKey));
  157. $result = curl_exec($ch); /* Execute the HTTP request. */
  158. curl_close($ch); /* Close the cURL handle. */
  159. return $result;
  160. }
  161. /**
  162. * Deletes all recipes by performing an HTTP POST to the
  163. * batch URI.
  164. */
  165. function batchDelete() {
  166. $ch = curl_init(); /* Create a CURL handle. */
  167. global $developerKey, $itemsFeedURL;
  168. /* Set cURL options. */
  169. curl_setopt($ch, CURLOPT_URL, $itemsFeedURL . "/batch");
  170. curl_setopt($ch, CURLOPT_POST, true);
  171. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  172. curl_setopt($ch, CURLOPT_FAILONERROR, true);
  173. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: AuthSub token="' . $_POST['token'] . '"', 'X-Google-Key: key=' . $developerKey, 'Content-Type: application/atom+xml'));
  174. curl_setopt($ch, CURLOPT_POSTFIELDS, buildBatchXML());
  175. $result = curl_exec($ch); /* Execute the HTTP request. */
  176. curl_close($ch); /* Close the cURL handle. */
  177. return $result;
  178. }
  179. /**
  180. * Callback function for XML start tags parsed by
  181. * xml_parse.
  182. */
  183. function startElement($parser, $name, $attrs) {
  184. global $curElement, $foundEntry, $parsedEntries;
  185. $curElement = $name;
  186. if($curElement == "ENTRY") {
  187. $foundEntry = true;
  188. $parsedEntries[count($parsedEntries)] = array();
  189. } else if($foundEntry && $curElement == "LINK") {
  190. $parsedEntries[count($parsedEntries) - 1][$attrs["REL"]] = $attrs["HREF"];
  191. }
  192. }
  193. /**
  194. * Callback function for XML end tags parsed by
  195. * xml_parse.
  196. */
  197. function endElement($parser, $name) {
  198. global $curElement, $foundEntry, $parsedEntries;
  199. if($name == "ENTRY") {
  200. $foundEntry = false;
  201. }
  202. }
  203. /**
  204. * Callback function for XML character data parsed by
  205. * xml_parse.
  206. */
  207. function characterData($parser, $data) {
  208. global $curElement, $foundEntry, $parsedEntries;
  209. if($foundEntry) {
  210. $parsedEntries[count($parsedEntries) - 1][strtolower($curElement)] = $data;
  211. }
  212. }
  213. /**
  214. * We arrive here when the user first comes to the form. The first step is
  215. * to have them get a single-use token.
  216. */
  217. function showIntroPage() {
  218. global $itemsFeedURL;
  219. $next_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
  220. $redirect_url = 'https://www.google.com/accounts/AuthSubRequest?session=1';
  221. $redirect_url .= '&next=';
  222. $redirect_url .= urlencode($next_url);
  223. $redirect_url .= "&scope=";
  224. $redirect_url .= urlencode($itemsFeedURL);
  225. print '<html>' . "\n";
  226. print '<head><title>PHP 4 Demo: Google Base data API</title>' . "\n";
  227. print '<link rel="stylesheet" type="text/css" href="http://code.google.com/css/dev_docs.css">' . "\n";
  228. print '</head>' . "\n";
  229. print '<body><center>' . "\n";
  230. print '<table style="width:50%;">' . "\n";
  231. print '<tr>' . "\n";
  232. print '<th colspan="2" style="text-align:center;">PHP 4 Demo: Google Base data API</th>' . "\n";
  233. print '</tr>' . "\n";
  234. print '<tr><td>Before you get started, please <a href="' . $redirect_url . '">sign in</a> to your personal Google Base account.</td></tr>' . "\n";
  235. print '</table>' . "\n";
  236. print '</center></body></html>' . "\n";
  237. }
  238. /**
  239. * Prints the table of recipes the user has already entered
  240. * on the left-hand side of the page.
  241. */
  242. function showRecipeListPane($token) {
  243. global $parsedEntries;
  244. print '<td style="width:50%; text-align:center; vertical-align:top">' . "\n";
  245. print '<table>' . "\n";
  246. print '<tr><th colspan="5" style="text-align:center">Recipes you have added</th></tr>' . "\n";
  247. getItems($token);
  248. if(count($parsedEntries) == 0) {
  249. print '<tr><td colspan="5" style="text-align:center"><i>(none)</i></td></tr>' . "\n";
  250. } else {
  251. print '<tr>' . "\n";
  252. print '<td style="text-align:center"><i>Name</i></td>' . "\n";
  253. print '<td style="text-align:center"><i>Cuisine</i></td>' . "\n";
  254. print '<td style="text-align:center"><i>Serves</i></td>' . "\n";
  255. print '<td colspan="2" style="text-align:center"><i>Actions</i></td>' . "\n";
  256. print '</tr>' . "\n";
  257. for($i = 0; $i < count($parsedEntries); $i++) {
  258. print '<tr>' . "\n";
  259. print '<td align="left" valign="top"><b><a href="' .
  260. $parsedEntries[$i]['alternate'] . '">' .
  261. $parsedEntries[$i]['title'] . '</a></b></td>' . "\n";
  262. print '<td style="text-align:center;vertical-align:top">' .
  263. $parsedEntries[$i]['g:cuisine'] . '</td>' . "\n";
  264. print '<td style="text-align:center;vertical-align:top">' .
  265. $parsedEntries[$i]['g:serving_count'] . '</td>' . "\n";
  266. /* Create an Edit button for each existing recipe. */
  267. print '<td style="text-align:center;vertical-align:top">' . "\n";
  268. print '<form method="post" action="' . $_SERVER['PHP_SELF'] .
  269. '" style="margin-top:0;margin-bottom:0;">' . "\n";
  270. print '<input type="hidden" name="action" value="edit">' . "\n";
  271. print '<input type="hidden" name="token" value="' . $token . '">' . "\n";
  272. foreach ($parsedEntries[$i] as $key => $value) {
  273. print '<input type="hidden" name="' . $key . '" value="' .
  274. $value . '">' . "\n";
  275. }
  276. print '<input type="submit" value="Edit">' . "\n";
  277. print '</form>' . "\n";
  278. print '</td>' . "\n";
  279. /* Create a Delete button for each existing recipe. */
  280. print '<td style="text-align:center; vertical-align:top">' . "\n";
  281. print '<form method="post" action="' . $_SERVER['PHP_SELF'] .
  282. '" style="margin-top:0;margin-bottom:0;">' . "\n";
  283. print '<input type="hidden" name="action" value="delete">' . "\n";
  284. print '<input type="hidden" name="token" value="' . $token . '">' . "\n";
  285. print '<input type="hidden" name="link" value="' .
  286. $parsedEntries[$i]['id'] . '">' . "\n";
  287. print '<input type="submit" value="Delete">' . "\n";
  288. print '</form>' . "\n";
  289. print '</td>' . "\n";
  290. print '</tr>' . "\n";
  291. }
  292. }
  293. /* Create a "Delete all" button" to demonstrate batch requests. */
  294. print '<tr><td colspan="5" style="text-align:center">' . "\n";
  295. print '<form method="post" action="' . $_SERVER['PHP_SELF'] .
  296. '" style="margin-top:0;margin-bottom:0">' . "\n";
  297. print '<input type="hidden" name="action" value="delete_all">' . "\n";
  298. print '<input type="hidden" name="token" value="' . $token . '">' . "\n";
  299. for($i = 0; $i < count($parsedEntries); $i++) {
  300. print '<input type="hidden" name="link_' . $i . '" value="' .
  301. $parsedEntries[$i]['id'] . '">' . "\n";
  302. }
  303. print '<input type="submit" value="Delete All"';
  304. if(count($parsedEntries) == 0) {
  305. print ' disabled="true"';
  306. }
  307. print '></form></td></tr>' . "\n";
  308. print '</table>' . "\n";
  309. print '</td>' . "\n";
  310. }
  311. /**
  312. * Prints a small form allowing the user to insert a new
  313. * recipe.
  314. */
  315. function showRecipeInsertPane($token) {
  316. global $cuisines;
  317. print '<td valign="top" width="50%">' . "\n";
  318. print '<table width="100%">' . "\n";
  319. print '<tr><th colspan="2" style="text-align:center">Insert a new recipe</th></tr>' . "\n";
  320. print '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">' . "\n";
  321. print '<input type="hidden" name="action" value="insert">' . "\n";
  322. print '<input type="hidden" name="token" value="' . $token . '">' . "\n";
  323. print '<tr><td align="right">Title:</td>' . "\n";
  324. print '<td><input type="text" name="recipe_title" class="half">' .
  325. '</td></tr>' . "\n";
  326. print '<tr><td align="right">Main ingredient:</td>' . "\n";
  327. print '<td><input type="text" name="main_ingredient" class="half">' .
  328. '</td></tr>' . "\n";
  329. print '<tr><td align="right">Cuisine:</td>' . "\n";
  330. print '<td><select name="cuisine" class="half">' . "\n";
  331. foreach ($cuisines as $curCuisine) {
  332. print '<option value=' . $curCuisine . '>' . $curCuisine .
  333. '</option>' . "\n";
  334. }
  335. print '</select></td></tr>' . "\n";
  336. print '<tr><td align="right">Cooking Time:</td>' .
  337. '<td><input type="text" name="time_val" size=2 maxlength=2>&nbsp;' .
  338. '<select name="time_units"><option value="minutes">minutes</option>' .
  339. '<option value="hours">hours</option></select></td></tr>' . "\n";
  340. print '<tr><td align="right">Serves:</td>' . "\n";
  341. print '<td><input type="text" name="serves" size=2 maxlength=3></td></tr>' .
  342. "\n";
  343. print '<tr><td align="right">Recipe:</td>' . "\n";
  344. print '<td><textarea class="full" name="recipe_text"></textarea></td></tr>' .
  345. "\n";
  346. print '<td>&nbsp;</td><td><input type="submit" value="Submit"></td>' . "\n";
  347. print '</form></tr></table>' . "\n";
  348. print '</td>' . "\n";
  349. }
  350. /**
  351. * Shows a menu allowing the user to update an existing
  352. * recipe with the Base API update feature.
  353. */
  354. function showEditMenu() {
  355. global $cuisines;
  356. $splitCookingTime = split(" ", $_POST['g:cooking_time']);
  357. print '<html>' . "\n";
  358. print '<head><title>PHP 4 Demo: Google Base data API</title>' . "\n";
  359. print '<link rel="stylesheet" type="text/css" href="http://code.google.com/css/dev_docs.css">' . "\n";
  360. print '</head>' . "\n";
  361. print '<body><center>' . "\n";
  362. print '<table style="width:50%">' . "\n";
  363. print '<tr><th colspan="2" style="text-align:center">Edit recipe:</th></tr>' . "\n";
  364. print '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">' . "\n";
  365. print '<input type="hidden" name="action" value="update">' . "\n";
  366. print '<input type="hidden" name="link" value="' .
  367. $_POST['edit'] . '">' . "\n";
  368. print '<input type="hidden" name="token" value="' .
  369. $_POST['token'] . '">' . "\n";
  370. print '<tr><td align="right">Title:</td>' . "\n";
  371. print '<td><input type="text" name="recipe_title" class="half" value="'
  372. . $_POST['title'] . '"></td></tr>' . "\n";
  373. print '<tr><td align="right">Main ingredient:</td>' . "\n";
  374. print '<td><input type="text" name="main_ingredient" value="'
  375. . $_POST['g:main_ingredient'] . '" class="half"></td></tr>' . "\n";
  376. print '<tr><td align="right">Cuisine:</td>' . "\n";
  377. print '<td><select name="cuisine" class="half">' . "\n";
  378. foreach ($cuisines as $curCuisine) {
  379. print '<option value="' . $curCuisine . '"';
  380. if($curCuisine == $_POST['g:cuisine']) {
  381. print ' selected="selected"';
  382. }
  383. print '>' . $curCuisine . "</option>\n";
  384. }
  385. print '</select></td></tr>' . "\n";
  386. print '<tr><td align="right">Cooking Time:</td>' .
  387. '<td><input type="text" name="time_val" size=2 maxlength=2 value="' .
  388. $splitCookingTime[0] . '">&nbsp;' . "\n";
  389. print '<select name="time_units">' . "\n";
  390. if($splitCookingTime[1] == "minutes") {
  391. print '<option value="minutes" selected="selected">minutes</option>' .
  392. "\n";
  393. print '<option value="hours">hours</option>' . "\n";
  394. } else {
  395. print '<option value="minutes">minutes</option>' . "\n";
  396. print '<option value="hours" selected="selected">hours</option>' .
  397. "\n";
  398. }
  399. print '</select></td></tr>' . "\n";
  400. print '<tr><td align="right">Serves:</td>' . "\n";
  401. print '<td><input type="text" name="serves" value="' .
  402. $_POST['g:serving_count'] . '" size=2 maxlength=3></td></tr>' . "\n";
  403. print '<tr><td align="right">Recipe:</td>' . "\n";
  404. print '<td><textarea class="full" name="recipe_text">' .
  405. $_POST['content'] . '</textarea></td></tr>' . "\n";
  406. print '<td>&nbsp;</td><td><input type="submit" value="Update"></td>' . "\n";
  407. print '</form></tr></table>' . "\n";
  408. print '</body></html>' . "\n";
  409. }
  410. /**
  411. * Displays both the "List of current recipes" and
  412. * "Insert a new recipe" panels in a single table.
  413. */
  414. function showMainMenu($tableTitle, $sessionToken) {
  415. print '<html>' . "\n";
  416. print '<head><title>PHP 4 Demo: Google Base data API</title>' . "\n";
  417. print '<link rel="stylesheet" type="text/css" href="http://code.google.com/css/dev_docs.css">' . "\n";
  418. print '</head>' . "\n";
  419. print '<body><center>' . "\n";
  420. print '<table style="width: 75%;text-align:center">' . "\n";
  421. print '<tr>' . "\n";
  422. print '<th colspan="2" style="text-align:center">PHP 4 Demo: Google Base data API' . "\n";
  423. print '</tr>' . "\n";
  424. print '<tr><td colspan="2" align="center">' . $tableTitle . '</td></tr>' . "\n";
  425. print '<tr>' . "\n";
  426. // Create the two sub-tables.
  427. showRecipeListPane($sessionToken);
  428. showRecipeInsertPane($sessionToken);
  429. // Add a "Sign out" link.
  430. print '<tr><th colspan="2" style="text-align: center">Or click here to' . ' <a href="http://www.google.com/accounts/Logout">sign out</a>' . ' of your Google account.</th></tr>' . "\n";
  431. // Close the master table.
  432. print '</table>' . "\n";
  433. print '</center></body></html>' . "\n";
  434. }
  435. /**
  436. * We arrive here after the user first authenticates and we get back
  437. * a single-use token.
  438. */
  439. function showFirstAuthScreen() {
  440. $singleUseToken = $_GET['token'];
  441. $sessionToken = exchangeToken($singleUseToken);
  442. if(!$sessionToken) {
  443. showIntroPage();
  444. } else {
  445. $tableTitle = 'Here\'s your <b>single use token:</b> <code>' . $singleUseToken . '</code>' . "\n" . '<br>And here\'s the <b>session token:</b> <code>' . $sessionToken . '</code>';
  446. showMainMenu($tableTitle, $sessionToken);
  447. }
  448. }
  449. /**
  450. * Main logic. Take action based on the GET and POST
  451. * parameters, which reflect whether the user has
  452. * authenticated and which action they want to perform.
  453. */
  454. // if(count($_GET) == 1 && array_key_exists('token', $_GET)) {
  455. // showFirstAuthScreen();
  456. // } else {
  457. // if(count($_POST) == 0) {
  458. // showIntroPage();
  459. // } else {
  460. // if($_POST['action'] == 'insert') {
  461. // if(postItem()) {
  462. // showMainMenu('Recipe inserted!', $_POST['token']);
  463. // } else {
  464. // showMainMenu('Recipe insertion failed.', $_POST['token']);
  465. // }
  466. // } else if($_POST['action'] == 'delete') {
  467. // if(deleteItem()) {
  468. // showMainMenu('Recipe deleted.', $_POST['token']);
  469. // } else {
  470. // showMainMenu('Recipe deletion failed.', $_POST['token']);
  471. // }
  472. // } else if($_POST['action'] == 'delete_all') {
  473. // if(batchDelete()) {
  474. // showMainMenu('All recipes deleted.', $_POST['token']);
  475. // } else {
  476. // showMainMenu('Batch deletion failed.', $_POST['token']);
  477. // }
  478. // } else if($_POST['action'] == 'edit') {
  479. // showEditMenu();
  480. // } else if($_POST['action'] == 'update') {
  481. // if(updateItem()) {
  482. // showMainMenu('Recipe successfully updated.', $_POST['token']);
  483. // } else {
  484. // showMainMenu('Recipe update failed.', $_POST['token']);
  485. // }
  486. // } else {
  487. // showIntroPage();
  488. // }
  489. // }
  490. // }
  491. ?>