Esempio n. 1
0
     if ($HTTP_VARS['op'] == 'my_borrowed' || $HTTP_VARS['op'] == 'my_history') {
         $listingObject->addTitleColumn($borrowed_item_r);
     } else {
         $listingObject->addTitleColumn($borrowed_item_r);
     }
 }
 // Owner/Borrower
 if ($HTTP_VARS['op'] == 'my_reserve_basket' || $HTTP_VARS['op'] == 'my_borrowed' || $HTTP_VARS['op'] == 'my_reserved' || $HTTP_VARS['op'] == 'my_history' || $HTTP_VARS['op'] == 'all_borrowed' || $HTTP_VARS['op'] == 'all_reserved') {
     $listingObject->addUserNameColumn($borrowed_item_r['owner_id'], array('bi_sequence_number' => $borrowed_item_r['sequence_number']));
 }
 if ($HTTP_VARS['op'] == 'owner_reserved' || $HTTP_VARS['op'] == 'owner_borrowed' || $HTTP_VARS['op'] == 'my_item_history' || get_opendb_config_var('borrow', 'include_borrower_column') !== FALSE && ($HTTP_VARS['op'] == 'all_borrowed' || $HTTP_VARS['op'] == 'all_reserved')) {
     $listingObject->addUserNameColumn($borrowed_item_r['borrower_id'], array('bi_sequence_number' => $borrowed_item_r['sequence_number']));
 }
 // Checked Out status!
 if ($HTTP_VARS['op'] == 'owner_reserved' || $HTTP_VARS['op'] == 'my_reserved' || $HTTP_VARS['op'] == 'all_reserved') {
     if (is_item_borrowed($borrowed_item_r['item_id'], $borrowed_item_r['instance_no'])) {
         $listingObject->addThemeImageColumn('borrowed.gif', get_opendb_lang_var('borrowed'), get_opendb_lang_var('borrowed'), 'borrowed_item');
     } else {
         $listingObject->addThemeImageColumn('reserved.gif', get_opendb_lang_var('reserved'), get_opendb_lang_var('reserved'), 'borrowed_item');
     }
 } else {
     if ($HTTP_VARS['op'] == 'my_item_history' || $HTTP_VARS['op'] == 'my_history') {
         if ($borrowed_item_r['status'] == 'X') {
             $listingObject->addColumn(get_opendb_lang_var('cancelled'));
         } else {
             if ($borrowed_item_r['status'] == 'R') {
                 $listingObject->addThemeImageColumn('reserved.gif', get_opendb_lang_var('reserved'), get_opendb_lang_var('reserved'), 'borrowed_item');
             } else {
                 if ($borrowed_item_r['status'] == 'C') {
                     $listingObject->addColumn(get_opendb_lang_var('checked_in'));
                 } else {
Esempio n. 2
0
function is_item_instance_checkoutable($item_instance_r, &$errors)
{
    if (!is_item_borrowed($item_instance_r['item_id'], $item_instance_r['instance_no'])) {
        $status_type_r = fetch_status_type_r($item_instance_r['s_status_type']);
        if ($status_type_r['borrow_ind'] == 'Y') {
            return TRUE;
        } else {
            if (is_array($status_type_r)) {
                $errors[] = get_opendb_lang_var('s_status_type_items_cannot_be_borrowed', 's_status_type_desc', $status_type_r['description']);
            } else {
                $errors[] = get_opendb_lang_var('invalid_s_status_type', 's_status_type', $item_instance_r['s_status_type']);
            }
        }
    } else {
        $errors[] = get_opendb_lang_var('item_is_already_checked_out');
    }
    //else
    return FALSE;
}
Esempio n. 3
0
/**
	@selected will be currently selected record.

	$borrow_duration is the item_instance.borrow_duration value in all cases, the rest of the values to do
	with borrow duration will be calculated.
*/
function get_item_status_row($class, $item_r, $selected)
{
    global $HTTP_VARS;
    global $PHP_SELF;
    global $titleMaskCfg;
    $rowcontents = "\n<tr class=\"{$class}\"><td";
    if ($selected) {
        $rowcontents .= " class=\"currentItemInstance\">" . $item_r['instance_no'] . "</span>";
    } else {
        $rowcontents .= "><a href=\"{$PHP_SELF}?item_id={$item_r['item_id']}&instance_no={$item_r['instance_no']}\">" . $item_r['instance_no'] . "</a>";
    }
    $rowcontents .= "\n</td>";
    $page_title = $titleMaskCfg->expand_item_title($item_r);
    $page_title = remove_enclosing_quotes($page_title);
    $rowcontents .= "<td>" . get_list_username($item_r['owner_id'], $HTTP_VARS['mode'], $page_title, get_opendb_lang_var('back_to_item'), 'item_display.php?item_id=' . $item_r['item_id'] . '&instance_no=' . $item_r['instance_no']) . "</td>";
    $status_type_r = fetch_status_type_r($item_r['s_status_type']);
    // ---------------------- Borrow,Reserve,Cancel,Edit,Delete,etc operations here.
    $action_links_rs = NULL;
    if (is_user_granted_permission(PERM_ITEM_OWNER) && get_opendb_session_var('user_id') === $item_r['owner_id'] || is_user_granted_permission(PERM_ITEM_ADMIN)) {
        $action_links_rs[] = array(url => 'item_input.php?op=edit&item_id=' . $item_r['item_id'] . '&instance_no=' . $item_r['instance_no'], img => 'edit.gif', text => get_opendb_lang_var('edit'));
        // Checks if any legal site plugins defined for $item_r['s_item_type']
        if (is_item_legal_site_type($item_r['s_item_type'])) {
            $action_links_rs[] = array(url => 'item_input.php?op=site-refresh&item_id=' . $item_r['item_id'] . '&instance_no=' . $item_r['instance_no'], img => 'refresh.gif', text => get_opendb_lang_var('refresh'));
        }
        if ($status_type_r['delete_ind'] == 'Y' && !is_item_reserved_or_borrowed($item_r['item_id'], $item_r['instance_no'])) {
            $action_links_rs[] = array(url => 'item_input.php?op=delete&item_id=' . $item_r['item_id'] . '&instance_no=' . $item_r['instance_no'], img => 'delete.gif', text => get_opendb_lang_var('delete'));
        }
    }
    if (is_user_granted_permission(array(PERM_USER_BORROWER, PERM_ADMIN_BORROWER))) {
        if (get_opendb_config_var('borrow', 'enable') !== FALSE) {
            if (get_opendb_config_var('borrow', 'quick_checkout') !== FALSE && $status_type_r['borrow_ind'] == 'Y' && is_user_allowed_to_checkout_item($item_r['item_id'], $item_r['instance_no'])) {
                if (!is_item_borrowed($item_r['item_id'], $item_r['instance_no'])) {
                    $action_links_rs[] = array(url => 'item_borrow.php?op=quick_check_out&item_id=' . $item_r['item_id'] . '&instance_no=' . $item_r['instance_no'], img => 'quick_check_out.gif', text => get_opendb_lang_var('quick_check_out'));
                }
            }
            // Check if already in reservation session variable.
            if (get_opendb_config_var('borrow', 'reserve_basket') !== FALSE && is_item_in_reserve_basket($item_r['item_id'], $item_r['instance_no'])) {
                $action_links_rs[] = array(url => 'borrow.php?op=delete_from_my_reserve_basket&item_id=' . $item_r['item_id'] . '&instance_no=' . $item_r['instance_no'], img => 'delete_reserve_basket.gif', text => get_opendb_lang_var('delete_from_reserve_list'));
            } else {
                if (is_item_reserved_or_borrowed($item_r['item_id'], $item_r['instance_no'])) {
                    if (is_item_reserved_by_user($item_r['item_id'], $item_r['instance_no'])) {
                        $action_links_rs[] = array(url => 'item_borrow.php?op=cancel_reserve&item_id=' . $item_r['item_id'] . '&instance_no=' . $item_r['instance_no'], img => 'cancel_reserve.gif', text => get_opendb_lang_var('cancel_reservation'));
                    } else {
                        if (!is_item_borrowed_by_user($item_r['item_id'], $item_r['instance_no'])) {
                            if ($status_type_r['borrow_ind'] == 'Y' && (get_opendb_config_var('borrow', 'allow_reserve_if_borrowed') !== FALSE || !is_item_borrowed($item_r['item_id'], $item_r['instance_no'])) && (get_opendb_config_var('borrow', 'allow_multi_reserve') !== FALSE || !is_item_reserved($item_r['item_id'], $item_r['instance_no']))) {
                                if (get_opendb_config_var('borrow', 'reserve_basket') !== FALSE) {
                                    $action_links_rs[] = array(url => 'borrow.php?op=update_my_reserve_basket&item_id=' . $item_r['item_id'] . '&instance_no=' . $item_r['instance_no'], img => 'add_reserve_basket.gif', text => get_opendb_lang_var('add_to_reserve_list'));
                                } else {
                                    $action_links_rs[] = array(url => 'item_borrow.php?op=reserve&item_id=' . $item_r['item_id'] . '&instance_no=' . $item_r['instance_no'], img => 'reserve_item.gif', text => get_opendb_lang_var('reserve_item'));
                                }
                            }
                        }
                    }
                } else {
                    if ($status_type_r['borrow_ind'] == 'Y') {
                        if (get_opendb_config_var('borrow', 'reserve_basket') !== FALSE) {
                            $action_links_rs[] = array(url => 'borrow.php?op=update_my_reserve_basket&item_id=' . $item_r['item_id'] . '&instance_no=' . $item_r['instance_no'], img => 'add_reserve_basket.gif', text => get_opendb_lang_var('add_to_reserve_list'));
                        } else {
                            $action_links_rs[] = array(url => 'item_borrow.php?op=reserve&item_id=' . $item_r['item_id'] . '&instance_no=' . $item_r['instance_no'], img => 'reserve_item.gif', text => get_opendb_lang_var('reserve_item'));
                        }
                    }
                }
            }
        }
    }
    if (is_item_borrowed($item_r['item_id'], $item_r['instance_no']) && is_user_allowed_to_checkin_item($item_r['item_id'], $item_r['instance_no'])) {
        $action_links_rs[] = array(url => 'item_borrow.php?op=check_in&item_id=' . $item_r['item_id'] . '&instance_no=' . $item_r['instance_no'], img => 'check_in_item.gif', text => get_opendb_lang_var('check_in_item'));
    }
    if ($item_r['owner_id'] == get_opendb_session_var('user_id') || is_user_granted_permission(PERM_ADMIN_BORROWER)) {
        if (is_exists_item_instance_history_borrowed_item($item_r['item_id'], $item_r['instance_no'])) {
            $action_links_rs[] = array(url => 'borrow.php?op=my_item_history&item_id=' . $item_r['item_id'] . '&instance_no=' . $item_r['instance_no'], img => 'item_history.gif', text => get_opendb_lang_var('item_history'));
        }
    }
    $rowcontents .= "\n<td>";
    $rowcontents .= ifempty(format_action_links($action_links_rs), get_opendb_lang_var('not_applicable'));
    $rowcontents .= "</td>";
    // Item Status Image.
    $rowcontents .= "\n<td>";
    $rowcontents .= theme_image($status_type_r['img'], $status_type_r['description'], "s_status_type");
    $rowcontents .= "</td>";
    // If a comment is allowed and defined, add it in.
    $rowcontents .= "\n<td>";
    if ($status_type_r['status_comment_ind'] == 'Y' || get_opendb_session_var('user_id') === $item_r['owner_id'] || is_user_granted_permission(PERM_ITEM_ADMIN)) {
        $rowcontents .= ifempty(nl2br($item_r['status_comment']), "&nbsp;");
        // support newlines in this field
    } else {
        $rowcontents .= get_opendb_lang_var('not_applicable');
    }
    $rowcontents .= "</td>";
    if (get_opendb_config_var('borrow', 'enable') !== FALSE) {
        if (get_opendb_config_var('borrow', 'include_borrower_column') !== FALSE) {
            $rowcontents .= "\n<td>";
            if (is_item_borrowed($item_r['item_id'], $item_r['instance_no'])) {
                $rowcontents .= get_list_username(fetch_item_borrower($item_r['item_id'], $item_r['instance_no']), NULL, $page_title, get_opendb_lang_var('back_to_item'), 'item_display.php?item_id=' . $item_r['item_id'] . '&instance_no=' . $item_r['instance_no']);
            } else {
                $rowcontents .= get_opendb_lang_var('not_applicable');
            }
            $rowcontents .= "</td>";
        }
        // Borrow Status Image.
        $rowcontents .= "\n<td>";
        if (is_item_borrowed($item_r['item_id'], $item_r['instance_no'])) {
            $rowcontents .= theme_image("borrowed.gif", get_opendb_lang_var('borrowed'), "borrowed_item");
        } else {
            if (is_item_reserved($item_r['item_id'], $item_r['instance_no'])) {
                $rowcontents .= theme_image("reserved.gif", get_opendb_lang_var('reserved'), "borrowed_item");
            } else {
                $rowcontents .= get_opendb_lang_var('not_applicable');
            }
        }
        $rowcontents .= "</td>";
        if (get_opendb_config_var('borrow', 'duration_support') !== FALSE) {
            // 'Due Back' functionality.
            $rowcontents .= "\n<td>";
            if (is_item_borrowed($item_r['item_id'], $item_r['instance_no'])) {
                $due_date = fetch_item_duedate_timestamp($item_r['item_id'], $item_r['instance_no']);
                if (strlen($due_date) > 0) {
                    $rowcontents .= get_localised_timestamp(get_opendb_config_var('borrow', 'date_mask'), $due_date);
                } else {
                    $rowcontents .= get_opendb_lang_var('undefined');
                }
            } else {
                if (is_numeric($item_r['borrow_duration'])) {
                    $duration_attr_type_r = fetch_sfieldtype_item_attribute_type_r($item_r['s_item_type'], 'DURATION');
                    $rowcontents .= get_item_display_field($item_r, $duration_attr_type_r, $item_r['borrow_duration'], FALSE);
                } else {
                    $rowcontents .= get_opendb_lang_var('undefined');
                }
            }
            $rowcontents .= "</td>";
        }
    }
    $rowcontents .= "\n</tr>";
    return $rowcontents;
}
Esempio n. 4
0
function handle_item_instance_update($item_r, $status_type_r, $HTTP_VARS, &$errors)
{
    if (is_not_empty_array($item_r)) {
        if ($item_r['owner_id'] == get_opendb_session_var('user_id') || is_user_granted_permission(PERM_ITEM_ADMIN)) {
            $update_status_type = $HTTP_VARS['s_status_type'];
            // Do not allow use of default s_status_type, it needs to be explicitly specified.
            if (strlen($update_status_type) > 0 && $item_r['s_status_type'] != $update_status_type) {
                $update_status_type_r = fetch_status_type_r($update_status_type);
            } else {
                // Otherwise s_status_type is not being udated
                $update_status_type = $status_type_r['s_status_type'];
                $update_status_type_r = $status_type_r;
                // current s_status_type
            }
            // If $update_status_type_r not defined, then we are not updating the s_status_type, only the status_comment
            if ($item_r['s_status_type'] == $update_status_type || is_update_status_type_valid($item_r['item_id'], $item_r['instance_no'], $item_r['owner_id'], $status_type_r, $update_status_type_r, $errors)) {
                // assume validation attribute function converts borrow duration to a single element array.
                if (is_array($HTTP_VARS['borrow_duration']) && count($HTTP_VARS['borrow_duration']) == 1) {
                    $borrow_duration = $HTTP_VARS['borrow_duration'][0];
                } else {
                    $borrow_duration = $HTTP_VARS['borrow_duration'];
                }
                $borrow_duration = ifempty($borrow_duration, $item_r['borrow_duration']);
                if (!is_numeric($borrow_duration)) {
                    $borrow_duration = FALSE;
                    // Not defined, so do not update
                }
                $status_comment = $HTTP_VARS['status_comment'];
                // trigger change owner processing at this point.
                if (strlen($HTTP_VARS['owner_id']) && $HTTP_VARS['owner_id'] != $item_r['owner_id']) {
                    if ($status_type_r['change_owner_ind'] == 'Y') {
                        if (!is_item_borrowed($item_r['item_id'], $item_r['instance_no'])) {
                            if (!update_item_instance_owner($item_r['item_id'], $item_r['instance_no'], $item_r['owner_id'], $HTTP_VARS['owner_id'])) {
                                $errors = array('error' => get_opendb_lang_var('item_instance_owner_not_changed'));
                            }
                        } else {
                            $errors = array('error' => get_opendb_lang_var('item_instance_owner_not_changed'));
                        }
                    } else {
                        $errors = array('error' => get_opendb_lang_var('operation_not_avail_change_owner'), 'detail' => '');
                    }
                }
                if (update_item_instance($item_r['item_id'], $item_r['instance_no'], $update_status_type, $status_comment, $borrow_duration)) {
                    handle_item_attributes('updateinstance', $item_r, $HTTP_VARS, $errors);
                    return TRUE;
                } else {
                    $db_error = db_error();
                    $errors = array('error' => get_opendb_lang_var('item_instance_not_updated'), 'detail' => $db_error);
                    return FALSE;
                }
            } else {
                return FALSE;
            }
        } else {
            $errors = array('error' => get_opendb_lang_var('cannot_update_item_not_owned'), detail => '');
            opendb_logger(OPENDB_LOG_WARN, __FILE__, __FUNCTION__, 'User attempted to update item instance they do not own', $item_r);
            return FALSE;
        }
    } else {
        //if(is_not_empty_array($item_r))
        $errors = array('error' => get_opendb_lang_var('item_not_found'), 'detail' => '');
        return FALSE;
    }
}
Esempio n. 5
0
/**
*/
function handle_checkout($sequence_number, $borrow_duration, $more_information, &$errors)
{
    $item_r = fetch_borrowed_item_r($sequence_number);
    if (!is_user_allowed_to_checkout_item($item_r['item_id'], $item_r['instance_no'])) {
        $errors = get_opendb_lang_var('not_owner_of_item');
        return FALSE;
    } else {
        if (is_item_borrowed($item_r['item_id'], $item_r['instance_no'])) {
            $errors = get_opendb_lang_var('item_is_already_checked_out');
            return FALSE;
        } else {
            if ($item_r['status'] != 'R') {
                $errors = get_opendb_lang_var('borrowed_item_not_found');
                return FALSE;
            }
        }
    }
    if (check_out_item($sequence_number, $borrow_duration, $more_information)) {
        return TRUE;
    } else {
        return FALSE;
    }
}