function is_valid_item_type_structure($s_item_type) { if (is_exists_item_type($s_item_type)) { if (fetch_sfieldtype_item_attribute_type($s_item_type, 'TITLE')) { if (fetch_sfieldtype_item_attribute_type($s_item_type, 'STATUSTYPE')) { if (fetch_sfieldtype_item_attribute_type($s_item_type, 'STATUSCMNT')) { if (fetch_sfieldtype_item_attribute_type($s_item_type, 'CATEGORY')) { if (get_opendb_config_var('borrow', 'enable') !== FALSE && get_opendb_config_var('borrow', 'duration_support') !== FALSE) { if (fetch_sfieldtype_item_attribute_type($s_item_type, 'DURATION')) { // At this point all the required s_field_type mappings have been provided. return TRUE; } } else { // At this point $borrow functionality is not enabled, so we do not // have to do anymore testing. return TRUE; } } } } } } //else return FALSE; }
function check_item_type_structure($s_item_type, &$error) { if (is_exists_item_type($s_item_type)) { $missing_s_field_types = NULL; if (!fetch_sfieldtype_item_attribute_type($s_item_type, 'TITLE')) { $missing_s_field_types[] = 'TITLE'; } if (!fetch_sfieldtype_item_attribute_type($s_item_type, 'STATUSTYPE')) { $missing_s_field_types[] = 'STATUSTYPE'; } if (!fetch_sfieldtype_item_attribute_type($s_item_type, 'STATUSCMNT')) { $missing_s_field_types[] = 'STATUSCMNT'; } if (!fetch_sfieldtype_item_attribute_type($s_item_type, 'CATEGORY')) { $missing_s_field_types[] = 'CATEGORY'; } if (get_opendb_config_var('borrow', 'enable') !== FALSE && get_opendb_config_var('borrow', 'duration_support') !== FALSE) { if (!fetch_sfieldtype_item_attribute_type($s_item_type, 'DURATION')) { $missing_s_field_types[] = 'DURATION'; } } if (is_not_empty_array($missing_s_field_types)) { $error = array('error' => 'The following Field Type attribute relationships are missing.', 'detail' => $missing_s_field_types); return FALSE; } else { // No errors so no problem. return TRUE; } } else { // no message if s_item_type does not even exist. return FALSE; } }
function build_item_category_chart_data($s_item_type) { $category_attribute_type = fetch_sfieldtype_item_attribute_type($s_item_type, 'CATEGORY'); if ($category_attribute_type) { $results = fetch_attribute_type_lookup_rs($category_attribute_type, 'order_no, value ASC'); if ($results) { while ($attribute_type_r = db_fetch_assoc($results)) { $num_total = fetch_category_item_cnt($attribute_type_r['value'], $s_item_type); if ($num_total > 0) { $data[] = array('display' => $attribute_type_r['display'], 'value' => $num_total); } } db_free_result($results); } } return $data; }
function encode_search_javascript_arrays(&$item_type_rs, &$arrayOfUniqueCategories, &$item_attribute_type_rs) { $buffer = ""; $arrayOfCategoryTypes = array(); $arrayOfUniqueAttributes = array(); $itemTypeBlock = ""; $attrTypeSelect = ""; $jsArrayOfAttributes = ""; $jsArrayOfAttributesCount = 0; $itemresults = fetch_item_type_rs(); while ($item_type_r = db_fetch_assoc($itemresults)) { $results = fetch_item_attribute_type_rs($item_type_r['s_item_type'], NULL, 'prompt'); // For the case where we have a s_item_type with no attributes associated with it! if ($results) { while ($item_attribute_type_r = db_fetch_assoc($results)) { // Do not include any attributes which do not exist as item attributes if ($item_attribute_type_r['s_field_type'] != 'TITLE' && $item_attribute_type_r['s_field_type'] != 'DURATION' && $item_attribute_type_r['s_field_type'] != 'STATUSTYPE' && $item_attribute_type_r['s_field_type'] != 'STATUSCMNT' && $item_attribute_type_r['s_field_type'] != 'ITEM_ID') { // Only unique attributes should be added to attribute options object. if (!is_array($arrayOfUniqueAttributes) || !in_array($item_attribute_type_r['s_attribute_type'], $arrayOfUniqueAttributes)) { // This array, is only so we can make sure that we have unique attributes only! $arrayOfUniqueAttributes[] = $item_attribute_type_r['s_attribute_type']; $jsArrayOfUniqueAttributes .= "\narrayOfAttributes[{$jsArrayOfAttributesCount}] = new LookupAttribute(\"\",\"" . $item_attribute_type_r['s_attribute_type'] . "\",\"" . $item_attribute_type_r['s_attribute_type'] . " - " . $item_attribute_type_r['description'] . "\");"; $item_attribute_type_rs[] = $item_attribute_type_r; } $jsArrayOfAttributes .= "\narrayOfAttributes[{$jsArrayOfAttributesCount}] = new LookupAttribute(\"" . $item_type_r['s_item_type'] . "\",\"" . $item_attribute_type_r['s_attribute_type'] . "\",\"" . $item_attribute_type_r['s_attribute_type'] . " - " . $item_attribute_type_r['description'] . "\");"; $jsArrayOfAttributesCount++; } } } // Get the category_attribute_type for this item_type $category_attribute_type = fetch_sfieldtype_item_attribute_type($item_type_r['s_item_type'], 'CATEGORY'); // We need this list further down, to work out which of the lookup items are actually categories. $arrayOfCategoryTypes[] = $category_attribute_type; $item_type_rs[] = $item_type_r; } // Give us the whole s_attribute_type_lookup table, whoo baby... $jsArrayOfLookupValues = ""; $jsArrayOfLookupValuesCount = 0; $attresults = fetch_attribute_type_lookup_rs(NULL, 's_attribute_type ASC'); while ($attribute_type_r = db_fetch_assoc($attresults)) { if ($attribute_type_r['s_field_type'] != 'ADDRESS' && $attribute_type_r['s_field_type'] != 'S_RATING') { if (in_array($attribute_type_r['s_attribute_type'], $arrayOfCategoryTypes) && (!is_array($arrayOfUniqueCategories) || !in_array($attribute_type_r['value'], $arrayOfUniqueCategories))) { $arrayOfUniqueCategories[$attribute_type_r['value']] = $attribute_type_r['display']; } $jsArrayOfLookupValues .= "\narrayOfLookupValues[{$jsArrayOfLookupValuesCount}] = new LookupAttribute(\"" . $attribute_type_r['s_attribute_type'] . "\",\"" . $attribute_type_r['value'] . "\",\"" . $attribute_type_r['display'] . "\");"; $jsArrayOfLookupValuesCount++; } } $buffer .= "\n\narrayOfLookupValues = new Array({$jsArrayOfLookupValuesCount});"; $buffer .= $jsArrayOfLookupValues; $buffer .= "\n\narrayOfAttributes = new Array({$jsArrayOfAttributesCount});"; $buffer .= $jsArrayOfAttributes; $arrayOfUniqueCategoryValues = ""; $arrayOfUniqueCatValuesCount = 0; // Now sort all values into alphabetical order! if (is_array($arrayOfUniqueCategories)) { asort($arrayOfUniqueCategories); reset($arrayOfUniqueCategories); while (list($value, $display) = each($arrayOfUniqueCategories)) { $arrayOfUniqueCatValues .= "\narrayOfUniqueCatValues[{$arrayOfUniqueCatValuesCount}] = new LookupAttribute('',\"{$value}\",\"{$display}\");"; $arrayOfUniqueCatValuesCount++; } } // Now wrap and return return "\n<script language=\"JavaScript\">\n<!-- // hide from stupid browsers\n" . $buffer . "\n// -->\n</script>\n"; }
/** * @param $borrowed_item_rs Items that this action will be performed against. It may actually * be an array of 'sequence_number' values, in which case the borrow * record for the sequence_number will be fetched. * @param $HTTP_VARS * */ function more_information_form($op, $borrowed_item_rs, $HTTP_VARS, $email_notification = TRUE) { global $PHP_SELF; $duration_attr_type = NULL; $default_borrow_duration = NULL; echo "\n<form action=\"{$PHP_SELF}\" method=\"POST\">"; // In case no detail is required. echo "\n<input type=\"hidden\" name=\"more_info_requested\" value=\"true\">"; // Pass all http variables onto next instance... // Includes empty fields... echo get_url_fields($HTTP_VARS, NULL, NULL); // Display the items to be operated on. if (is_not_empty_array($borrowed_item_rs)) { echo "<div id=\"moreInfoListing\">"; // no pagination. $HTTP_VARS['items_per_page'] = ''; $listingObject = new HTML_Listing($PHP_SELF, $HTTP_VARS); $listingObject->setIncludeHrefLinks(TRUE); $listingObject->setIncludeFooter(FALSE); $listingObject->startListing(); $listingObject->addHeaderColumn(get_opendb_lang_var('type')); $listingObject->addHeaderColumn(get_opendb_lang_var('title')); if ($op == 'reserve' || $op == 'cancel_reserve' || $op == 'quick_check_out') { $listingObject->addHeaderColumn(get_opendb_lang_var('owner')); } else { if ($op == 'check_in') { $listingObject->addHeaderColumn(get_opendb_lang_var('borrower')); } } if (get_opendb_config_var('borrow', 'duration_support')) { if ($op == 'check_out' || $op == 'quick_check_out') { $listingObject->addHeaderColumn(get_opendb_lang_var('borrow_duration')); } } //initialise $max_overdue_duration = NULL; $default_borrow_duration = NULL; reset($borrowed_item_rs); while (list(, $borrowed_item_r) = each($borrowed_item_rs)) { $listingObject->startRow(); // If only a sequence_number, we need to fetch the borrow record. if (!is_array($borrowed_item_r) && is_numeric($borrowed_item_r)) { $borrowed_item_r = fetch_borrowed_item_r($borrowed_item_r); } // TODO - add borrowed item history this to be displayed as readonly. //$results = fetch_borrowed_item_hist_rs($borrowed_item_r['sequence_number']); $item_r = fetch_item_instance_r($borrowed_item_r['item_id'], $borrowed_item_r['instance_no']); $listingObject->addItemTypeImageColumn($item_r['s_item_type']); $listingObject->addTitleColumn($item_r); if ($op == 'reserve' || $op == 'cancel_reserve' || $op == 'quick_check_out') { $listingObject->addUserNameColumn($item_r['owner_id'], array('bi_sequence_number' => $borrowed_item_r['sequence_number'])); } else { if ($op == 'check_in') { $listingObject->addUserNameColumn($borrowed_item_r['borrower_id'], array('bi_sequence_number' => $borrowed_item_r['sequence_number'])); } } if (get_opendb_config_var('borrow', 'duration_support')) { if ($op == 'check_out' || $op == 'quick_check_out') { if (is_numeric($item_r['borrow_duration'])) { // todo - change $duration_attr_type_r = fetch_sfieldtype_item_attribute_type_r($item_r['s_item_type'], 'DURATION'); $listingObject->addDisplayColumn($duration_attr_type_r['s_attribute_type'], NULL, $duration_attr_type_r['display_type'], $item_r['borrow_duration']); } else { $listingObject->addColumn(get_opendb_lang_var('undefined')); } } } // While we are here, we are going to calculate the default duration value. // We want to choose the least duration value. If any of the items use a // different s_attribute_type for duration, then we should not try to get // a default value. This is indicated by the $duration_attr_type===FALSE // if we have encountered a difference. if (get_opendb_config_var('borrow', 'duration_support') && $duration_attr_type !== FALSE) { $new_duration_attr_type = fetch_sfieldtype_item_attribute_type($item_r['s_item_type'], 'DURATION'); if ($duration_attr_type == NULL) { $duration_attr_type = $new_duration_attr_type; } else { if ($duration_attr_type !== $new_duration_attr_type) { // Different s_attribute_type's for DURATION, so cannot display Duration chooser. $duration_attr_type = FALSE; } } if ($duration_attr_type !== FALSE) { if ($op == 'check_out' || $op == 'quick_check_out') { // The default borrow duration should be the least amount of days or undefined // if no records have a borrow duration. if ($default_borrow_duration === NULL) { $default_borrow_duration = $item_r['borrow_duration']; } else { if ($default_borrow_duration !== '') { // Undefined empty value. if (is_numeric($default_borrow_duration) && is_numeric($item_r['borrow_duration']) && $item_r['borrow_duration'] < $default_borrow_duration) { $default_borrow_duration = $item_r['borrow_duration']; } } } } else { if ($op == 'extension') { if ($borrowed_item_r['total_duration'] > $borrowed_item_r['borrow_duration']) { $tmp_overdue_duration = $borrowed_item_r['total_duration'] - $borrowed_item_r['borrow_duration']; } // We want to get the max overdue duration, so we can give the User granting the extension a // default, that will bring all selected items back into non-overdue status. if (!is_numeric($max_overdue_duration) || $max_overdue_duration < $tmp_overdue_duration) { $max_overdue_duration = $tmp_overdue_duration; } } } } } //if(get_opendb_config_var('borrow', 'duration_support') && $duration_attr_type!==FALSE) $listingObject->endRow(); } //while(list(,$borrowed_item_r) = each($borrowed_item_rs)) $listingObject->endListing(); echo "</div>"; } echo "<table class=\"moreInfo\">"; // Do not display this more information section unless email is enabled. if (is_valid_opendb_mailer() && $email_notification !== FALSE) { echo get_input_field("more_information", NULL, get_opendb_lang_var('more_information'), "textarea(50,10)", "N", NULL, TRUE); } // Include a Borrower ID select, minus the current user. if ($op == 'quick_check_out') { if (strlen($HTTP_VARS['borrower_id']) == 0 || !is_user_granted_permission(PERM_USER_BORROWER, $HTTP_VARS['borrower_id'])) { $current_user_mode = EXCLUDE_CURRENT_USER; if (get_opendb_config_var('borrow', 'owner_self_checkout') !== FALSE) { $current_user_mode = INCLUDE_CURRENT_USER; } $results = fetch_user_rs(PERM_USER_BORROWER, INCLUDE_ROLE_PERMISSIONS, $current_user_mode, EXCLUDE_DEACTIVATED_USER, 'fullname', 'ASC'); if ($results) { echo format_field(get_opendb_lang_var('borrower'), custom_select('borrower_id', $results, '%fullname% (%user_id%)', 1, NULL, 'user_id')); } else { echo format_field(get_opendb_lang_var('borrower'), get_opendb_lang_var('no_records_found')); } } } //Only for check_out/quick_check_out operations - makes no sense otherwise! if (get_opendb_config_var('borrow', 'duration_support') !== FALSE && ($op == 'check_out' || $op == 'quick_check_out' || $op == 'extension')) { // Display default borrow duration. if (strlen($duration_attr_type) > 0) { $duration_attr_type_r = fetch_attribute_type_r($duration_attr_type); // We have to find the matching DURATION lookup value, which is at least // as many days as the max_overdue value, or the highest possible // duration value, if none found as large as the $max_overdue_duration if ($op == 'extension') { $default_borrow_duration = NULL; $result = fetch_attribute_type_lookup_rs($duration_attr_type_r['s_attribute_type'], 'order_no, value ASC'); if ($result) { while ($lookup_r = db_fetch_assoc($result)) { if (is_numeric($lookup_r['value']) && (!is_numeric($max_overdue_duration) || is_numeric($max_overdue_duration) && $max_overdue_duration <= $lookup_r['value'])) { $default_borrow_duration = $lookup_r['value']; break; } // backup, in case we need to use outside while loop $lookup_r2 = $lookup_r; } db_free_result($result); // If still null, then set to the largest option if ($default_borrow_duration == NULL) { $default_borrow_duration = $lookup_r2['value']; } } } if ($op != 'extension' && strlen(get_opendb_lang_var('default_borrow_duration')) > 0 && is_array($borrowed_item_rs)) { $duration_attr_type_r['prompt'] = get_opendb_lang_var('default_borrow_duration'); } $duration_attr_type_r['compulsory_ind'] = 'N'; echo get_item_input_field("default_borrow_duration", $duration_attr_type_r, NULL, $op != 'quick_check_out' ? $default_borrow_duration : NULL); // Not appropriate for extension operation if ($op == 'check_out' || $op == 'quick_check_out') { echo get_input_field("override_item_duration", NULL, get_opendb_lang_var('override_item_duration'), "simple_checkbox(" . ($default_borrow_duration === NULL ? "CHECKED" : "") . ")", "N", "Y", TRUE); } } else { //otherwise tell checkout to use item_instance borrow duration instead. if ($op == 'check_out' || $op == 'quick_check_out') { echo "\n<input type=\"hidden\" name=\"override_item_duration\" value=\"N\">"; } } } echo "</table>"; echo "<input type=\"submit\" class=\"submit\" value=\"" . get_opendb_lang_var('submit') . "\">"; echo "</form>"; echo format_help_block(get_opendb_lang_var('more_information_help')); }