function create_from_external($obj_id, $obj_type) { if ($obj_type == TYPE_DISH) { $obj = new dish($obj_id); foreach ($obj->ingredients() as $ingredid) { $err = $this->create_from_external($ingredid, TYPE_INGREDIENT); if ($err && $err != ERR_OBJECT_ALREADY_EXISTS) { return $err; } } foreach ($obj->dispingredients() as $ingredid) { $err = $this->create_from_external($ingredid, TYPE_INGREDIENT); if ($err && $err != ERR_OBJECT_ALREADY_EXISTS) { return $err; } } } elseif ($obj_type == TYPE_INGREDIENT) { $obj = new ingredient($obj_id); } else { return ERR_NO_TYPE_SPECIFIED; } if ($this->find_external($obj_id, $obj_type)) { return ERR_OBJECT_ALREADY_EXISTS; } $input_data['name'] = $obj->name(); $input_data['ref_type'] = $obj_type; $input_data['ref_id'] = $obj_id; $err = $this->insert($input_data); return $err; }
function list_rows($arr, $row) { global $tpl; global $display; $col = 0; if (!$this->disable_mass_delete) { $display->rows[$row][$col] = '<input type="checkbox" name="delete[]" value="' . $arr['id'] . '">'; $display->width[$row][$col] = '1%'; $col++; } elseif ($arr['table_id'] == TABLE_DISHES) { $dish = new dish($arr['id']); if (count($dish->ingredients()) || count($dish->dispingredients())) { $display->rows[$row][$col] = '<input type="checkbox" name="edit[]" value="' . $arr['id'] . '">'; } else { $display->rows[$row][$col] = ' '; } $display->width[$row][$col] = '1%'; $col++; } else { $display->rows[$row][$col] = ' '; $display->width[$row][$col] = '1%'; $col++; } foreach ($arr as $field => $value) { if (isset($this->hide) && in_array($field, $this->hide)) { continue; } switch ($arr['table_id']) { case TABLE_INGREDIENTS: $obj = new ingredient(); break; case TABLE_DISHES: $obj = new dish(); break; case TABLE_CATEGORIES: $obj = new category(); break; case TABLE_TABLES: $obj = new table(); break; case TABLE_USERS: $obj = new user(); break; case TABLE_VAT_RATES: $obj = new vat_rate(); break; case TABLE_PRINTERS: $obj = new printer(); break; case TABLE_STOCK_OBJECTS: $obj = new stock_object(); break; case TABLE_STOCK_DISHES: $obj = new dish(); break; } if (method_exists($obj, 'form')) { $link = $obj->file . '?class=' . get_class($obj) . '&command=edit&data[id]=' . $arr['id']; } else { $link = ''; } $display->rows[$row][$col] = $value; if ($link && $field == 'name') { $display->links[$row][$col] = $link; } if ($link) { $display->clicks[$row][$col] = 'redir(\'' . $link . '\');'; } $col++; } }