/** * NewGroup adds a new group based on some POST-Variables * It needs the POST-Variables groupname and max_credit. ID is done by MySQL's * auto-incrementing id. Additionally it will add Priceclasses for the group. * * @todo Update the description * @see GroupManager */ function NewGroup() { require_once PATH_ACCESS . '/PriceClassManager.php'; $pcManager = new PriceClassManager(); /** * Add a new group to the MySQL-table */ if (isset($_POST['groupname'], $_POST['max_credit'])) { /** * add Group */ $groupname = $_POST['groupname']; $max_credit = $_POST['max_credit']; //error-checking if (!isset($groupname) || $groupname == '') { $this->groupInterface->dieError($this->msg['err_inp_groupname']); } if ($this->groupManager->existsGroupName($groupname)) { $this->groupInterface->dieError($this->msg['err_group_exists']); } if (!isset($max_credit) || $max_credit == '' || !preg_match('/\\A^[0-9]{0,2}((,|\\.)[0-9]{2})?\\z/', $max_credit)) { $this->groupInterface->dieError($this->msg['err_inp_max_credit'] . ' ' . $max_credit); } $max_credit = str_replace(',', '.', $max_credit); /** * add Priceclasses belonging to the group */ if (isset($_POST['n_price'])) { /** Fetches the Priceclasses from the Server. For every Priceclass-ID there is a POST-Variable from the * create_group-form with name and ID. */ try { $priceclasses = $pcManager->getAllPriceClassesPooled(); } catch (MySQLVoidDataException $e) { $this->groupInterface->dieMsg(sprintf($this->msg['fin_add_group_wo_pc'], $groupname, $max_credit)); } catch (Exception $e) { $this->groupInterface->dieError($this->msg['err_fetch_pc']); } //pc_to_add_arr: If a problem happens during the adding-loop, we need to be safe that no entries are added yet $pc_to_add_arr = array(); $standard_price = $_POST['n_price']; //check standardprice-input try { inputcheck($standard_price, 'credits', 'StandardPreis'); } catch (Exception $e) { $this->groupInterface->dieError($this->msg['err_inp_price'] . ' in:' . $e->getFieldName()); } //add the priceclasses foreach ($priceclasses as $priceclass) { try { $pc_id = $priceclass['pc_ID']; $pc_name = $_POST['pc_name' . $pc_id]; $pc_price = $_POST['pc_price' . $pc_id]; //groupID will be added after the data-checking, so the next ID of MySQL's Autoincrement is the groupID $group_id = $this->groupManager->getNextAutoIncrementID(); if (!isset($pc_price) || !$pc_price || $pc_price == '') { $pc_price = $standard_price; } try { //check for correct input of price inputcheck($pc_price, 'credits', $pc_name); } catch (WrongInputException $e) { $this->groupInterface->dieError($this->msg['err_inp_price'] . ' in:' . $e->getFieldName()); } $pc_to_add_arr[] = array('name' => $pc_name, 'gid' => $group_id, 'pc_price' => $pc_price, 'pid' => $pc_id); } catch (Exception $e) { $this->groupInterface->dieError('A Priceclass with the ID ' . $pc_id . ' could not be added: ' . $e->getMessage()); } } } /** * finish adding Group and Priceclass */ try { $this->groupManager->addGroup($groupname, $max_credit); } catch (Exception $e) { $this->groupInterface->dieError($this->msg['err_add_group']); } if (isset($_POST['n_price'])) { foreach ($pc_to_add_arr as $pc_to_add) { try { $pcManager->addPriceClass($pc_to_add['name'], $pc_to_add['gid'], $pc_to_add['pc_price'], $pc_to_add['pid']); } catch (Exception $e) { $this->groupInterface->dieError($this->msg['err_add_pc']); } } } $this->groupInterface->dieMsg(sprintf($this->msg['fin_add_group'], $groupname, $max_credit)); } else { try { $pc_arr = $pcManager->getAllPriceClassesPooled(); } catch (MySQLVoidDataException $e) { $pc_arr = false; } $this->groupInterface->NewGroup($pc_arr); } }
/** * This function shows the createMeal-Form with the variables already filled out */ function DuplicateMeal($name, $description, $pc_ID, $date, $max_orders) { require_once PATH_ACCESS . '/PriceClassManager.php'; $pcManager = new PriceClassManager(); try { $pc_arr = $pcManager->getAllPriceClassesPooled(); } catch (Exception $e) { $this->mealInterface->dieError($this->msg['err_no_pc'] . $e->getMessage()); } $pc_ids = array(); $pc_names = array(); foreach ($pc_arr as $pc) { $pc_ids[] = $pc['pc_ID']; $pc_names[] = $pc['name']; } $this->mealInterface->DuplicateMeal($pc_ids, $pc_names, $name, $description, $pc_ID, $max_orders, $date); }