/** Constructor, creates the exporting object and the correct subclass based on the param $filter */ function Export($filter = 'XML') { global $db_table_courses, $db_table_bases, $db_table_ethnicity, $db_table_prep_time, $db_table_difficulty, $db_table_units, $db_table_locations; $this->useFilter = $filter; // Look up the field values $this->courses = DBUtils::createList(DBUtils::fetchColumn($db_table_courses, 'course_desc', 'course_id', 'course_desc'), 'course_id', 'course_desc'); $this->bases = DBUtils::createList(DBUtils::fetchColumn($db_table_bases, 'base_desc', 'base_id', 'base_desc'), 'base_id', 'base_desc'); $this->ethnicity = DBUtils::createList(DBUtils::fetchColumn($db_table_ethnicity, 'ethnic_desc', 'ethnic_id', 'ethnic_desc'), 'ethnic_id', 'ethnic_desc'); $this->prep_times = DBUtils::createList(DBUtils::fetchColumn($db_table_prep_time, 'time_desc', 'time_id', 'time_desc'), 'time_id', 'time_desc'); $this->difficulty = DBUtils::createList(DBUtils::fetchColumn($db_table_difficulty, 'difficult_desc', 'difficult_id', 'difficult_desc'), 'difficult_id', 'difficult_desc'); $this->units = DBUtils::createList(DBUtils::fetchColumn($db_table_units, 'unit_desc', 'unit_id', 'unit_desc'), 'unit_id', 'unit_desc'); $this->locations = DBUtils::createList(DBUtils::fetchColumn($db_table_locations, 'location_desc', 'location_id', 'location_desc'), 'location_id', 'location_desc'); }
<tr> <th colspan = "2"> <?php if ($ingredient_id) { echo $LangUI->_('Edit Ingredient'); } else { echo $LangUI->_('Add Ingredient'); } ?> </th> </tr> <?php $units = Units::getAllUnits(); // Load the units $rc_locations = DBUtils::fetchColumn($db_table_locations, 'location_desc', 'location_id', 'location_desc'); $locations = DBUtils::createList($rc_locations, 'location_id', 'location_desc'); $liqsol = array("FALSE" => $LangUI->_('Liquid'), "TRUE" => $LangUI->_('Solid')); $ingredient_name = ""; $ingredient_desc = ""; $ingredient_unit = ""; $ingredient_loc = ""; $ingredient_solid = ""; $coreingredient_id = ""; $coreingredient_Name = ""; if ($ingredient_id) { $ingredient_name = $ingredients->fields['ingredient_name']; $ingredient_desc = $ingredients->fields['ingredient_desc']; $ingredient_unit = $ingredients->fields['ingredient_unit']; $ingredient_loc = $ingredients->fields['ingredient_location']; $ingredient_solid = $ingredients->fields['ingredient_solid']; if ($ingredient_solid == $DB_LINK->false) {
$dbDate = DBUtils::dbDate($date); // get the date in ISO format so that we have the key if ($SMObj->getUserLoginID() == NULL) { die($LangUI->_('You must be logged in to use the Meal Planner!')); } // Create a new meal plan object $MPObj = new MealPlan($date); $MPObj->load($dbDate, $dbDate); //just want this one day $minshow = 4; // Min number of empty fields to show $defaultServings = 2; // The default number of servings // Read in a list of Meals and recipes $rc = DBUtils::fetchColumn($db_table_meals, 'meal_name', 'meal_id', 'meal_id'); $mealList = DBUtils::createList($rc, 'meal_id', 'meal_name'); ?> <script type="text/javascript"> $(document).ready(function() { $(".ui-widget").find("input[id^='recipeAuto_']").each(function() { $(this).autocomplete({ source: "index.php?m=recipes&a=get&format=no", minLength: 1, select: function(event, ui) { var $target = $(event.target); var recipeIdName = getOtherFromName($target.attr("id"), "recipeId"); var mealType = getOtherFromName($target.attr("id"), "meal_id"); $(recipeIdName).val(ui.item.id); $(mealType).attr("required", ""); }
/** Gets the meals for a given day and puts it into html and returns it as a string @param $date The date to get (ISO Format) @param $format The format to put it in, maily big=1, small=2, mobile=3 @return String with HTML in it */ function getMeals($date, $format) { global $DB_LINK, $db_table_meals; $output = ""; // If there is nothing to get, don't bother, just return if (!isset($this->mealplanItems[$date])) { return ""; } // Get the list of all the meal types (breakfast, lunch...) if (count($this->mealList) == 0) { // we have to load the list of meals now $rc = DBUtils::fetchColumn($db_table_meals, 'meal_name', 'meal_id', 'meal_id'); $this->mealList = DBUtils::createList($rc, 'meal_id', 'meal_name'); } // Now that we know there is something to get foreach ($this->mealList as $k => $v) { $count = 0; $str = ""; foreach ($this->mealplanItems[$date] as $item) { if ($item['meal'] == $k) { // add this one · if ($format == 1 || $format == 2) { $str .= '<li><a href="index.php?m=recipes&a=view&recipe_id=' . $item['id'] . '">' . $item['name'] . "</a>\n"; } else { if ($format == 3) { $str = '<li><a href="index.php?m=recipes&a=view_mob&recipe_id=' . $item['id'] . '">' . $item['name'] . "</a></li>"; } } $count++; } } if ($count) { if ($format == 1 || $format == 2) { $output .= "{$v}<ul>" . $str . "</ul>"; } else { if ($format == 3) { $output .= '<li data-role="list-divider">' . $v . "</li>\n{$str}"; } } } } return $output; }
/** Imports all of the recipes currently loaded (do a parseDataFile first) */ function importData() { global $LangUI, $DB_LINK, $SMObj, $db_table_recipes, $db_table_ingredients, $db_table_related_recipes; // Iterate through all the recipes and create them foreach ($this->importRecipes as $item) { $recipeObj = $item[0]; $recipeObj->user = $SMObj->getUserID(); $id = $recipeObj->insert(); $order = 0; // order the ingredients foreach ($item[1] as $ingObj) { if ($ingObj != NULL) { // See if the ingredient exists $sql = "SELECT ingredient_id FROM {$db_table_ingredients} WHERE ingredient_name=? and ingredient_user=?"; $stmt = $DB_LINK->Prepare($sql); $rc = $DB_LINK->Execute($stmt, array($ingObj->name, $SMObj->getUserID())); // Error check DBUtils::checkResult($rc, NULL, NULL, $sql); if ($rc->RecordCount() == 0) { // Note: lots of defaults are guessed if this option is taken $ingObj->solid = $DB_LINK->true; $ingObj->price = '0.00'; $ingObj->user = $SMObj->getUserID(); // Create the Ingredient and then set the ID $ing_id = $ingObj->insert(); } else { $ing_id = $rc->fields['ingredient_id']; } // Map the ingredient $ingObj->id = $ing_id; // We have an ID set it. $ingObj->recipe_id = $id; // Set the Recipe ID as well $ingObj->order = $order; // Set the order of the ingredient // Insert the mapping $ingObj->insertMap(); $order++; } } } // Now we can link in the related recipes... $this->recipes = DBUtils::createList(DBUtils::fetchColumn($db_table_recipes, 'recipe_name', 'recipe_id', 'recipe_name'), 'recipe_name', 'recipe_id'); foreach ($this->relatedRecipes as $link) { if ($this->recipes[$link[0]] != NULL && $this->recipes[$link[1]] != NULL) { $sql = "INSERT INTO {$db_table_related_recipes} (related_parent, related_child, related_required) VALUES (?, ?, ?)"; $stmt = $DB_LINK->Prepare($sql); $rc = $DB_LINK->Execute($stmt, array($this->recipes[$link[0]], $this->recipes[$link[1]], $link[2])); DBUtils::checkResult($rc, NULL, NULL, $sql); echo $LangUI->_('Linking') . ": '" . $link[0] . "' " . $LangUI->_('to') . " '" . $link[1] . "'<br />"; } } }