/** * @throws FolderIDMissingException */ public static function add_value_item($type_array, $category_array, $holder_class, $holder_id, $position_id) { global $user, $regional; if (class_exists($holder_class)) { $item_holder = new $holder_class($holder_id); if ($item_holder instanceof ItemHolderInterface) { $folder_id = $item_holder->get_item_holder_value("folder_id", $position_id); } } if (is_numeric($folder_id)) { if (count($type_array) != 1 and !$_POST['type_id']) { $result = array(); $counter = 0; if (count($type_array) == 0) { $value_obj = Value::get_instance(null); $value_type_array = ValueType::list_entries(); foreach ($value_type_array as $key => $value) { $value_type = new ValueType($value); $result[$counter]['value'] = $value; $result[$counter]['content'] = $value_type->get_name(); $counter++; } } else { foreach ($type_array as $key => $value) { $value_type = new ValueType($value); $result[$counter]['value'] = $value; $result[$counter]['content'] = $value_type->get_name(); $counter++; } } } elseif (count($type_array) != 1 and $_POST['type_id']) { $type_id = $_POST['type_id']; } else { $type_id = $type_array[0]; } if (!$type_id) { $template = new HTMLTemplate("data/value_select_list.html"); $paramquery = $_GET; $paramquery['nextpage'] = "1"; $params = http_build_query($paramquery, '', '&'); $template->set_var("params", $params); $template->set_var("select", $result); if ($_POST['keywords']) { $template->set_var("keywords", $_POST['keywords']); } else { $template->set_var("keywords", ""); } if ($_POST['description']) { $template->set_var("description", $_POST['description']); } else { $template->set_var("description", ""); } $template->output(); } else { $value_type = new ValueType($type_id); $template = new HTMLTemplate("data/value_add.html"); $template->set_var("decimal_separator", $regional->get_decimal_separator()); $template->set_var("thousand_separator", $regional->get_thousand_separator()); $template->set_var("session_id", $_GET['session_id']); $template->set_var("folder_id", $folder_id); $template->set_var("type_id", $type_id); $template->set_var("get_array", serialize($_GET)); if ($_GET['retrace']) { $template->set_var("retrace", "index.php?" . http_build_query(Retrace::resolve_retrace_string($_GET['retrace']))); } else { $template->set_var("retrace", "index.php?username="******"&session_id=" . $_GET['session_id']); } $template->set_var("title", $value_type->get_name()); require_once "value_form.io.php"; $value_form_io = new ValueFormIO(null, $type_id, $folder_id); $value_form_io->set_field_class("DataValueAddValues"); $template->set_var("value", $value_form_io->get_content()); if ($_POST['keywords']) { $template->set_var("keywords", $_POST['keywords']); } else { $template->set_var("keywords", ""); } if ($_POST['description']) { $template->set_var("description", $_POST['description']); } else { $template->set_var("description", ""); } $template->output(); } } else { throw new FolderIDMissingException(); } }
/** * @param integer $page * @return string * @throws BaseAssistantRequestedPageNotExistsException */ public static function get_content($page) { global $session, $user; switch ($page) { case "0": $template = new HTMLTemplate("project/new_project_page_0.html"); return $template->get_string(); break; case "1": $template = new HTMLTemplate("project/new_project_page_1.html"); if ($session->read_value("PROJECT_TYPE") == 1 or $session->read_value("PROJECT_TYPE") == 2) { $project_organ_unit = $session->read_value("PROJECT_ORGANISATION_UNIT"); $template->set_var("organunit", true); $result = array(); $counter = 0; $organisation_unit_array = OrganisationUnit::list_entries(); if (is_array($organisation_unit_array) and count($organisation_unit_array) >= 1) { foreach ($organisation_unit_array as $key => $value) { $organisation_unit = new OrganisationUnit($value); if ($organisation_unit->is_permission($user->get_user_id()) and $organisation_unit->get_stores_data() == true) { $result[$counter]['value'] = $value; $result[$counter]['content'] = $organisation_unit->get_name(); if ($project_organ_unit == $value) { $result[$counter]['selected'] = "selected"; } else { $result[$counter]['selected'] = ""; } $result[$counter]['disabled'] = ""; $counter++; } } } if (!$result) { $result[$counter]['value'] = "0"; $result[$counter]['content'] = "NO ORGANISATION UNIT FOUND!"; $result[$counter]['selected'] = ""; $result[$counter]['disabled'] = "disabled='disabled'"; } $template->set_var("option", $result); } else { $project_toid = $session->read_value("PROJECT_TOID"); $template->set_var("organunit", false); $result = array(); $counter = 0; $project = new Project(null); $project_array = $project->get_project_tree(); if (is_array($project_array) and count($project_array) >= 1) { foreach ($project_array as $key => $value) { $project = new Project($value['id']); for ($i = 1; $i <= $value['layer']; $i++) { $pre_content .= " "; } $result[$counter]['value'] = $value['id']; $result[$counter]['content'] = $pre_content . "" . $project->get_name(); if ($project_toid == $value['id']) { $result[$counter]['selected'] = "selected"; } else { $result[$counter]['selected'] = ""; } $result[$counter]['disabled'] = ""; $counter++; unset($pre_content); } } else { $result[$counter]['value'] = "0"; $result[$counter]['content'] = "NO PROJECT FOUND!"; $result[$counter]['selected'] = ""; $result[$counter]['disabled'] = "disabled='disabled'"; } $template->set_var("option", $result); } return $template->get_string(); break; case "2": $project_name = $session->read_value("PROJECT_NAME"); $project_desc = $session->read_value("PROJECT_DESCRIPTION"); $template = new HTMLTemplate("project/new_project_page_2.html"); if ($project_name) { $template->set_var("project_name", $project_name); } else { $template->set_var("project_name", ""); } if ($project_desc) { $template->set_var("project_description", $project_desc); } else { $template->set_var("project_description", ""); } return $template->get_string(); break; case "3": $project_template = $session->read_value("PROJECT_TEMPLATE"); $template = new HTMLTemplate("project/new_project_page_3.html"); $result = array(); $counter = 0; $project_template_array = ProjectTemplateCat::list_entries(); if (is_array($project_template_array)) { foreach ($project_template_array as $key => $value) { $project_template_cat = new ProjectTemplateCat($value); $result[$counter]['value'] = "0"; $result[$counter]['content'] = $project_template_cat->get_name(); $result[$counter]['selected'] = ""; $result[$counter]['disabled'] = "disabled='disabled'"; $counter++; $project_template_sub_array = ProjectTemplate::list_entries_by_cat_id($value); if (is_array($project_template_sub_array)) { foreach ($project_template_sub_array as $sub_key => $sub_value) { $project_sub_template = new ProjectTemplate($sub_value); if (($session->read_value("PROJECT_TYPE") == 1 or $session->read_value("PROJECT_TYPE") == 3) and $project_sub_template->get_parent_template() == false) { $result[$counter]['value'] = $sub_value; $result[$counter]['content'] = " " . $project_sub_template->get_name(); if ($project_template == $sub_value) { $result[$counter]['selected'] = "selected"; } else { $result[$counter]['selected'] = ""; } $result[$counter]['disabled'] = ""; $counter++; } elseif (($session->read_value("PROJECT_TYPE") == 2 or $session->read_value("PROJECT_TYPE") == 4) and $project_sub_template->get_parent_template() == true) { $result[$counter]['value'] = $sub_value; $result[$counter]['content'] = " " . $project_sub_template->get_name(); if ($project_template == $sub_value) { $result[$counter]['selected'] = "selected"; } else { $result[$counter]['selected'] = ""; } $result[$counter]['disabled'] = ""; $counter++; } } } unset($project_template_sub_array); } } else { $result[$counter]['value'] = "0"; $result[$counter]['content'] = "NO TEMPLATES FOUND!"; $result[$counter]['selected'] = ""; $result[$counter]['disabled'] = "disabled='disabled'"; } $template->set_var("option", $result); return $template->get_string(); break; case "4": $project_template = $session->read_value("PROJECT_TEMPLATE"); $project_template_data_type = $session->read_value("PROJECT_TEMPLATE_DATA_TYPE"); $project_template_data_array = $session->read_value("PROJECT_TEMPLATE_DATA_ARRAY"); $project_template_obj = new ProjectTemplate($project_template); $required_array = $project_template_obj->get_required_requirements(); if (is_array($required_array) and count($required_array) >= 1) { $value_type_id = 0; $sample_count = 0; $is_value = false; $is_sample = false; foreach ($required_array as $key => $value) { if ($value['xml_element'] == "item") { if ($value['type'] == "value") { $is_value = true; } } if ($value['xml_element'] == "type" and !$value['close'] and $is_value == true) { $value_type_id = $value['id']; } } if ($is_value == true) { $template = new HTMLTemplate("project/new_project_page_4_value.html"); require_once "core/modules/data/io/value_form.io.php"; $value_form_io = new ValueFormIO(null, $value_type_id, null, $project_template_data_array); $value_form_io->set_field_class("ProjectCreateAssistantField"); $template->set_var("content", $value_form_io->get_content()); $template->set_var("project_template_data_type_id", $value_type_id); return $template->get_string(); } else { $template = new HTMLTemplate("project/new_project_page_4_error.html"); return $template->get_string(); } } else { $template = new HTMLTemplate("project/new_project_page_4_error.html"); return $template->get_string(); } break; case "5": $template = new HTMLTemplate("project/new_project_page_5.html"); $project_template = new ProjectTemplate($session->read_value("PROJECT_TEMPLATE")); $template->set_var("project_name", $session->read_value("PROJECT_NAME")); $template->set_var("project_template", $project_template->get_name()); $template->set_var("project_description", $session->read_value("PROJECT_DESCRIPTION")); $template->set_var("content", ""); return $template->get_string(); break; default: throw new BaseAssistantRequestedPageNotExistsException(); break; } }
/** * @param string $get_array * @param string $type_array * @return string * @throws ItemTypeRequiredException */ public static function add_as_item_window($get_array, $type_array, $folder_id) { global $regional; if ($get_array) { $_GET = unserialize($get_array); } if ($type_array) { $type_array = unserialize($type_array); } if (is_array($type_array) and count($type_array) == 1) { if (is_numeric($folder_id)) { $type_id = $type_array[0]; $template = new HTMLTemplate("data/value_add_item_window.html"); if ($_GET['parent'] and is_numeric($_GET['parent_id'])) { $array['container'] = "#ValueItemAddWindow" . $_GET['parent_key'] . "-" . $_GET['parent_id'] . "-" . $_GET['key']; } else { $array['container'] = "#ValueItemAddWindow" . $_GET['key']; } require_once "core/modules/data/io/value_form.io.php"; $value_form_io = new ValueFormIO(null, $type_id, $folder_id); $value_form_io->set_field_class("DataValueAddValues"); $template->set_var("value", $value_form_io->get_content()); $array['continue_caption'] = "Add"; $array['cancel_caption'] = "Cancel"; $array['content_caption'] = "Add Values"; $array['height'] = 350; $array['width'] = 400; $array['content'] = $template->get_string(); $continue_handler_template = new JSTemplate("data/js/value_add_item_window.js"); $continue_handler_template->set_var("session_id", $_GET['session_id']); $continue_handler_template->set_var("type_id", $type_id); $continue_handler_template->set_var("folder_id", $folder_id); $continue_handler_template->set_var("get_array", $get_array); $continue_handler_template->set_var("container_id", $array['container']); $array['continue_handler'] = $continue_handler_template->get_string(); $script_template = new JSTemplate("data/js/value_add_item_window_onclick.js"); $script_template->set_var("decimal_separator", $regional->get_decimal_separator()); $script_template->set_var("thousand_separator", $regional->get_thousand_separator()); $array['open_handler'] = $script_template->get_string(); return json_encode($array); } else { throw new FolderIDMissingException(); } } else { throw new ItemTypeRequiredException(); } }
/** * @param integer $page * @return string * @throws BaseAssistantRequestPageNotExistsException */ public static function get_content($page) { global $session, $user; switch ($page) { case "1": $sample_organ_unit = $session->read_value("SAMPLE_ORGANISATION_UNIT"); $template = new HTMLTemplate("sample/new_sample_page_1.html"); $result = array(); $counter = 0; $organisation_unit_array = OrganisationUnit::list_entries(); foreach ($organisation_unit_array as $key => $value) { $organisation_unit = new OrganisationUnit($value); if ($organisation_unit->is_permission($user->get_user_id()) and $organisation_unit->get_stores_data() == true) { $result[$counter]['value'] = $value; $result[$counter]['content'] = $organisation_unit->get_name(); if ($sample_organ_unit == $value) { $result[$counter]['selected'] = "selected"; } else { $result[$counter]['selected'] = ""; } $result[$counter]['disabled'] = ""; $counter++; } } if (!$result) { $result[$counter]['value'] = "0"; $result[$counter]['content'] = "NO ORGANISATION UNIT FOUND!"; $result[$counter]['selected'] = ""; $result[$counter]['disabled'] = "disabled='disabled'"; } $template->set_var("option", $result); return $template->get_string(); break; case "2": $sample_template = $session->read_value("SAMPLE_TEMPLATE"); $type_array = $session->read_value("SAMPLE_ITEM_TYPE_ARRAY"); $template = new HTMLTemplate("sample/new_sample_page_2.html"); if (!is_array($type_array) or count($type_array) == 0) { $type_array = null; } $result = array(); $counter = 0; $sample_template_array = SampleTemplate::list_entries(); if (is_array($sample_template_array)) { foreach ($sample_template_array as $key => $value) { if ($type_array == null or in_array($value, $type_array)) { $sample_sub_template = new SampleTemplate($value); $result[$counter]['value'] = $value; $result[$counter]['content'] = $sample_sub_template->get_name(); if ($sample_template == $value) { $result[$counter]['selected'] = "selected"; } else { $result[$counter]['selected'] = ""; } $result[$counter]['disabled'] = ""; $counter++; } } } else { $result[$counter]['value'] = "0"; $result[$counter]['content'] = "NO TEMPLATES FOUND!"; $result[$counter]['selected'] = ""; $result[$counter]['disabled'] = "disabled='disabled'"; } $template->set_var("option", $result); if ($session->is_value("ADD_ITEM_TEMP_KEYWORDS_" . $_GET['idk_unique_id']) == true) { $template->set_var("keywords", $session->read_value("ADD_ITEM_TEMP_KEYWORDS_" . $_GET['idk_unique_id'])); } else { $template->set_var("keywords", ""); } if ($session->is_value("ADD_ITEM_TEMP_DESCRIPTION_" . $_GET['idk_unique_id']) == true) { $template->set_var("description", $session->read_value("ADD_ITEM_TEMP_DESCRIPTION_" . $_GET['idk_unique_id'])); } else { $template->set_var("description", ""); } return $template->get_string(); break; case "3": $sample_template = $session->read_value("SAMPLE_TEMPLATE"); $sample_name = $session->read_value("SAMPLE_NAME"); $sample_manufacturer = $session->read_value("SAMPLE_MANUFACTURER_ID"); $sample_manufacturer_name = $session->read_value("SAMPLE_MANUFACTURER_NAME"); $sample_location = $session->read_value("SAMPLE_LOCATION"); $sample_expiry = $session->read_value("SAMPLE_EXPIRY"); $sample_expiry_warning = $session->read_value("SAMPLE_EXPIRY_WARNING"); $sample_description = $session->read_value("SAMPLE_DESCRIPTION"); $sample_template_obj = new SampleTemplate($sample_template); $information_fields = $sample_template_obj->get_information_fields(); $template = new HTMLTemplate("sample/new_sample_page_3.html"); if ($information_fields['manufacturer']['name'] and $information_fields['manufacturer']['requirement'] != "optional") { $template->set_var("check_manufacturer", true); } else { $template->set_var("check_manufacturer", false); } if ($information_fields['expiry']['name'] and $information_fields['expiry']['requirement'] != "optional") { $template->set_var("check_expiry", true); } else { $template->set_var("check_expiry", false); } if ($information_fields['location']['name'] and $information_fields['location']['requirement'] != "optional") { $template->set_var("check_location", true); } else { $template->set_var("check_location", false); } if ($sample_name) { $template->set_var("name", $sample_name); } else { $template->set_var("name", ""); } if ($information_fields['manufacturer']['name']) { require_once "core/modules/manufacturer/io/manufacturer.io.php"; $template->set_var("show_manufacturer", true); $template->set_var("manufacturer_html", ManufacturerIO::dialog()); } else { $template->set_var("show_manufacturer", false); $template->set_var("manufacturer_html", ""); } if ($information_fields['expiry']['name']) { $template->set_var("show_expiry", true); } else { $template->set_var("show_expiry", false); } if ($information_fields['location']['name']) { $template->set_var("show_location", true); $result = array(); $counter = 0; $sample_location_array = Location::list_entries(); if (is_array($sample_location_array) and count($sample_location_array) >= 1) { foreach ($sample_location_array as $key => $value) { $sample_location_obj = new Location($value); $result[$counter]['value'] = $value; $result[$counter]['content'] = $sample_location_obj->get_name(true); if ($sample_location == $value) { $result[$counter]['selected'] = "selected"; } else { $result[$counter]['selected'] = ""; } $counter++; } } else { $result[$counter]['value'] = "0"; $result[$counter]['content'] = "NO LOCATIONS FOUND!"; } $template->set_var("location", $result); } else { $template->set_var("show_location", false); } if ($sample_manufacturer) { $template->set_var("manufacturer", $sample_manufacturer); } else { $template->set_var("manufacturer", ""); } if ($sample_manufacturer_name) { $template->set_var("manufacturer_name", $sample_manufacturer_name); } else { $template->set_var("manufacturer_name", ""); } if ($sample_expiry) { $template->set_var("expiry", $sample_expiry); } else { $template->set_var("expiry", ""); } if ($sample_expiry_warning) { $template->set_var("expiry_warning", $sample_expiry_warning); } else { $template->set_var("expiry_warning", (int) Registry::get_value("sample_default_expiry_warning")); } if ($sample_description) { $template->set_var("desc", $sample_description); } else { $template->set_var("desc", ""); } return $template->get_string(); break; case "4": $sample_add_role = $session->read_value("SAMPLE_ADD_ROLE"); $sample_add_item_holder_class = $session->read_value("SAMPLE_ADD_ITEM_HOLDER_CLASS"); $sample_add_item_holder_id = $session->read_value("SAMPLE_ADD_ITEM_HOLDER_ID"); $sample_template = $session->read_value("SAMPLE_TEMPLATE"); $sample_template_data_type = $session->read_value("SAMPLE_TEMPLATE_DATA_TYPE"); $sample_template_data_type_id = $session->read_value("SAMPLE_TEMPLATE_DATA_TYPE_ID"); $sample_template_data_array = $session->read_value("SAMPLE_TEMPLATE_DATA_ARRAY"); $sample_template_obj = new SampleTemplate($sample_template); $required_array = $sample_template_obj->get_required_requirements(); if (is_array($required_array) and count($required_array) >= 1) { $value_type_id = 0; $sample_count = 0; $is_value = false; $is_sample = false; foreach ($required_array as $key => $value) { if ($value['xml_element'] == "item") { if ($value['type'] == "value") { $is_value = true; } elseif ($value['type'] == "parentsample") { $is_sample = true; $sample_count++; } } if ($value['xml_element'] == "type" and !$value['close'] and $is_value == true) { $value_type_id = $value['id']; } } if ($is_value == true xor $is_sample == true) { if ($is_value == true) { $template = new HTMLTemplate("sample/new_sample_page_4_value.html"); require_once "core/modules/data/io/value_form.io.php"; $value_form_io = new ValueFormIO(null, $value_type_id, null, $sample_template_data_array); $value_form_io->set_field_class("SampleCreateAssistantField"); $template->set_var("content", $value_form_io->get_content()); $template->set_var("template_data_type_id", $value_type_id); return $template->get_string(); } else { $template = new HTMLTemplate("sample/new_sample_page_4_sample.html"); if ($sample_count > 0) { $result = array(); if ($sample_add_role == "item" and is_numeric($sample_add_item_holder_id) and class_exists($sample_add_item_holder_class)) { $item_holder_list_sql = $sample_add_item_holder_class::get_item_list_sql($sample_add_item_holder_id); if ($item_holder_list_sql) { $sample_array = Sample::list_samples_by_item_sql_list($item_holder_list_sql); } else { $sample_array = Sample::list_user_related_samples($user->get_user_id()); } } else { $sample_array = Sample::list_user_related_samples($user->get_user_id()); } for ($i = 0; $i <= $sample_count - 1; $i++) { $result[$i]['id'] = $i + 1; if ($sample_template_data_type == "sample") { if ($sample_template_data_array['sample-' . $result[$i]['id'] . '']) { $selected_id = $sample_template_data_array['sample-' . $result[$i]['id'] . '']; } } if (is_array($sample_array) and count($sample_array) >= 1) { $counter = 0; foreach ($sample_array as $key => $value) { $sample = new Sample($value); $result[$i][$counter]['value'] = $value; $result[$i][$counter]['content'] = $sample->get_name(); if ($selected_id == $value) { $result[$i][$counter]['selected'] = "selected"; } else { $result[$i][$counter]['selected'] = ""; } $counter++; } } else { $result[$i][0]['value'] = 0; $result[$i][0]['content'] = "You have no samples"; $result[$i][0]['selected'] = ""; } unset($selected_id); } $template->set_var("sample", $result); } return $template->get_string(); } } else { $template = new HTMLTemplate("sample/new_sample_page_4_error.html"); return $template->get_string(); } } else { $template = new HTMLTemplate("sample/new_sample_page_4_error.html"); return $template->get_string(); } break; case "5": $sample_organ_unit = $session->read_value("SAMPLE_ORGANISATION_UNIT"); $sample_template = $session->read_value("SAMPLE_TEMPLATE"); $sample_name = $session->read_value("SAMPLE_NAME"); $sample_manufacturer = $session->read_value("SAMPLE_MANUFACTURER_ID"); $sample_manufacturer_name = $session->read_value("SAMPLE_MANUFACTURER_NAME"); $sample_location = $session->read_value("SAMPLE_LOCATION"); $sample_expiry = $session->read_value("SAMPLE_EXPIRY"); $sample_expiry_warning = $session->read_value("SAMPLE_EXPIRY_WARNING"); $sample_description = $session->read_value("SAMPLE_DESCRIPTION"); $template = new HTMLTemplate("sample/new_sample_page_5.html"); $organisation_unit = new OrganisationUnit($sample_organ_unit); $template->set_var("sample_organisation_unit", $organisation_unit->get_name()); $sample_template_obj = new SampleTemplate($sample_template); $template->set_var("sample_template", $sample_template_obj->get_name()); $template->set_var("sample_name", $sample_name); if ($sample_manufacturer) { $template->set_var("sample_manufacturer", $sample_manufacturer_name); } else { $template->set_var("sample_manufacturer", false); } if ($sample_location) { $sample_location_obj = new Location($sample_location); $template->set_var("sample_location", $sample_location_obj->get_name(true)); } else { $template->set_var("sample_location", false); } if ($sample_expiry) { $template->set_var("sample_date_of_expiry", $sample_expiry); } else { $template->set_var("sample_date_of_expiry", false); } if ($sample_desc) { $sample_desc_display = str_replace("\n", "<br />", $sample_desc); $template->set_var("sample_description", $sample_desc_display); } else { $template->set_var("sample_description", "<span class='italic'>None</span>"); } return $template->get_string(); break; default: throw new BaseAssistantRequestedPageNotExistsException(); break; } }