Beispiel #1
0
function get_edit_form($op, $review_r, $HTTP_VARS)
{
    global $PHP_SELF;
    $formContents = "";
    $formContents .= "<form action=\"{$PHP_SELF}\" method=\"POST\">";
    $formContents .= "<table>";
    $compulsory_ind = 'N';
    if (get_opendb_config_var('item_review', 'comment_compulsory') === TRUE) {
        $compulsory_ind = 'Y';
    }
    $formContents .= get_input_field("comment", NULL, get_opendb_lang_var('review'), "htmlarea(55,10)", $compulsory_ind, $review_r['comment'], TRUE);
    // We are now able to configure this in the database.
    $attribute_type_r = fetch_attribute_type_r('S_RATING');
    $attribute_type_r['compulsory_ind'] = 'N';
    if (get_opendb_config_var('item_review', 'rating_compulsory') == TRUE) {
        $attribute_type_r['compulsory_ind'] = 'Y';
    }
    $formContents .= get_item_input_field("rating", $attribute_type_r, NULL, $review_r['rating']);
    $formContents .= "</table>";
    if (get_opendb_config_var('widgets', 'enable_javascript_validation') !== FALSE) {
        $onclick_event = "if(!checkForm(this.form)){return false;}else{this.form.submit();}";
    } else {
        $onclick_event = "this.form.submit();";
    }
    $formContents .= format_help_block(array('img' => 'compulsory.gif', 'text' => get_opendb_lang_var('compulsory_field'), id => 'compulsory'));
    $formContents .= "<input type=\"button\" class=\"button\" onclick=\"{$onclick_event}\" value=\"" . get_opendb_lang_var('save_review') . "\">\n\t\t<input type=\"hidden\" name=\"op\" value=\"{$op}\">\n\t\t<input type=\"hidden\" name=\"sequence_number\" value=\"" . $review_r['sequence_number'] . "\">\n\t\t<input type=\"hidden\" name=\"item_id\" value=\"" . $HTTP_VARS['item_id'] . "\">\n\t\t<input type=\"hidden\" name=\"instance_no\" value=\"" . $HTTP_VARS['instance_no'] . "\">\n\t\t</form>";
    return $formContents;
}
Beispiel #2
0
function fetch_alt_item_id_attribute_type_r()
{
    $attribute_type_r = fetch_attribute_type_r(ifempty(get_opendb_config_var('borrow.checkout', 'alt_id_attribute_type'), 'S_ITEM_ID'));
    // just for S_ITEM_ID s_attribute_type
    if ($attribute_type_r['input_type'] == 'hidden') {
        $attribute_type_r['input_type'] = 'number';
        $attribute_type_r['input_type_arg1'] = '10';
        $attribute_type_r['input_type_arg2'] = '10';
    }
    // need to be able to to checkout action - so this cannot be compulsory
    $attribute_type_r['compulsory_ind'] = 'N';
    return $attribute_type_r;
}
Beispiel #3
0
function get_ilcc_derived_prompt($item_listing_column_conf_r)
{
    switch ($item_listing_column_conf_r['column_type']) {
        case 's_field_type':
            switch ($item_listing_column_conf_r['s_field_type']) {
                case 'ITEMTYPE':
                    return get_opendb_lang_var('type');
                case 'ITEM_ID':
                    $v_attribute_type_r = fetch_attribute_type_r('S_ITEM_ID');
                    return $v_attribute_type_r['prompt'];
                    break;
                case 'TITLE':
                    return get_opendb_lang_var('title');
                    break;
                case 'OWNER':
                    return get_opendb_lang_var('owner');
                    break;
                case 'CATEGORY':
                    return get_opendb_lang_var('category');
                    break;
                case 'STATUSTYPE':
                    return get_opendb_lang_var('status');
                    break;
                case 'STATUSCMNT':
                    return get_opendb_lang_var('status_comment');
                    break;
                case 'RATING':
                    $v_attribute_type_r = fetch_attribute_type_r('S_RATING');
                    return $v_attribute_type_r['prompt'];
                    break;
            }
            break;
        case 'action_links':
            return get_opendb_lang_var('action');
            break;
        case 'borrow_status':
            return get_opendb_lang_var('borrow_status');
            break;
        case 's_attribute_type':
            if (strlen($item_listing_column_conf_r['s_attribute_type']) > 0) {
                $v_attribute_type_r = fetch_attribute_type_r($item_listing_column_conf_r['s_attribute_type']);
                return $v_attribute_type_r['prompt'];
            } else {
                return NULL;
            }
            break;
    }
    //else
    return NULL;
}
Beispiel #4
0
function build_review_stats()
{
    $avgrate = fetch_review_rating();
    if ($avgrate > 0) {
        echo "<h3>" . get_opendb_lang_var('review_stats') . "</h3>";
        echo "<dl class=\"reviewStats\">";
        $num_review = fetch_review_cnt();
        echo "<dt>" . get_opendb_lang_var('review(s)') . "</dt>";
        echo "<dd>" . $num_review . "</dd>";
        echo "<dt>" . get_opendb_lang_var('average_rating') . "</dt>";
        $attribute_type_r = fetch_attribute_type_r("S_RATING");
        echo "<dd>" . get_display_field($attribute_type_r['s_attribute_type'], NULL, 'review()', $avgrate, FALSE) . "</dd>";
        echo "</dl>";
    }
}
Beispiel #5
0
 /**
 	modify display_mask so that all {variable} are replaced with
 	references to the array indexes returned.
 */
 function _parse_field_mask(&$display_mask)
 {
     $i = 0;
     $array_of_vars = NULL;
     $inside_variable = 0;
     $variable = '';
     $new_display_mask = '';
     for ($i = 0; $i < strlen($display_mask); $i++) {
         if ($inside_variable > 0) {
             // if closing bracket
             if ($display_mask[$i] == '}') {
                 // indicate close of reference.
                 $inside_variable--;
                 // only if we have encountered final closing bracket!
                 if ($inside_variable == 0) {
                     if (strlen($variable) > 0) {
                         // constrain to legal function names here.
                         $function_r = prc_function_spec($variable, true);
                         // so we get a clean func definition for each $variable.
                         unset($func);
                         // only legal function names.
                         if (is_array($function_r)) {
                             // will actually define the particular arguments here.
                             switch ($function_r['type']) {
                                 case 'if':
                                     // if(varname[<|<=|>=|>|==|!=]value, "title_mask")
                                     $func['type'] = $function_r['type'];
                                     //'if'
                                     // parse the condition.
                                     $this->_parse_if_condition($function_r['args'][0], $func);
                                     $func['if_mask_elements'] = $this->_parse_field_mask($function_r['args'][1]);
                                     // remember parse_field_mask resets the argument to {1}, {2}, etc.
                                     $func['if_mask'] = $function_r['args'][1];
                                     if (count($function_r['args']) > 2) {
                                         $func['else_mask_elements'] = $this->_parse_field_mask($function_r['args'][2]);
                                         // remember parse_field_mask resets the argument to {1}, {2}, etc.
                                         $func['else_mask'] = $function_r['args'][2];
                                     }
                                     $array_of_vars[] = $func;
                                     break;
                                 case 'switch':
                                     // switch(value, case, result[, case, result[,...][, default])
                                     $func['type'] = $function_r['type'];
                                     //'if'
                                     $func['varname'] = $function_r['args'][0];
                                     $j = 1;
                                     while ($j + 1 < count($function_r['args'])) {
                                         $case = $function_r['args'][$j++];
                                         $result['mask_elements'] = $this->_parse_field_mask($function_r['args'][$j]);
                                         $result['mask'] = $function_r['args'][$j];
                                         $func['cases'][] = array('case' => $case, 'result' => $result);
                                         $j++;
                                     }
                                     // a default element
                                     if ($j < count($function_r['args'])) {
                                         $result['mask_elements'] = $this->_parse_field_mask($function_r['args'][$j]);
                                         $result['mask'] = $function_r['args'][$j];
                                         $func['default_case'] = $result;
                                     }
                                     $array_of_vars[] = $func;
                                     break;
                                 case 'ifdef':
                                     $func['type'] = $function_r['type'];
                                     //'ifdef'
                                     $func['varname'] = $function_r['args'][0];
                                     // now do the mask
                                     $func['if_mask_elements'] = $this->_parse_field_mask($function_r['args'][1]);
                                     // remember parse_field_mask resets the argument to {1}, {2}, etc.
                                     $func['if_mask'] = $function_r['args'][1];
                                     if (count($function_r['args']) > 2) {
                                         $func['else_mask_elements'] = $this->_parse_field_mask($function_r['args'][2]);
                                         // remember parse_field_mask resets the argument to {1}, {2}, etc.
                                         $func['else_mask'] = $function_r['args'][2];
                                     }
                                     $array_of_vars[] = $func;
                                     break;
                                 case 'theme_img':
                                     // only supports one level deep for the prompt_expression (second argument).
                                     $func['value'] = NULL;
                                     $func['type'] = $function_r['type'];
                                     $func['img'] = $function_r['args'][0];
                                     $func['title_mask_elements'] = $this->_parse_field_mask($function_r['args'][1]);
                                     // if not an array, then expand
                                     if (!is_array($func['title_mask_elements'])) {
                                         $func['title_mask_elements'][] = $function_r['args'][1];
                                         $func['title_mask'] = '{0}';
                                     } else {
                                         // this will cause the widget to be rendered, but no help entry
                                         // will be added to the listings page, because the $this->_opendb_title_mask_macro_rs
                                         // has not been updated.
                                         $func['title_mask'] = $function_r['args'][1];
                                     }
                                     $array_of_vars[] = $func;
                                     break;
                                 case 'config_var_key':
                                     // config_var_keyid(name, value)
                                     $func['type'] = $function_r['type'];
                                     $func['name'] = $function_r['args'][0];
                                     $tmp_parsed_arg = $this->_parse_field_mask($function_r['args'][1]);
                                     if (is_array($tmp_parsed_arg)) {
                                         $func['value'] = array('mask' => $function_r['args'][1], 'elements' => $tmp_parsed_arg);
                                     } else {
                                         $func['value'] = $function_r['args'][1];
                                     }
                                     $array_of_vars[] = $func;
                                     break;
                                 case 'config_var_value':
                                     // config_var_value(name, keyid)
                                     $func['type'] = $function_r['type'];
                                     $func['name'] = $function_r['args'][0];
                                     $tmp_parsed_arg = $this->_parse_field_mask($function_r['args'][1]);
                                     if (is_array($tmp_parsed_arg)) {
                                         $func['key'] = array('mask' => $function_r['args'][1], 'elements' => $tmp_parsed_arg);
                                     } else {
                                         $func['key'] = $function_r['args'][1];
                                     }
                                     $array_of_vars[] = $func;
                                     break;
                                 default:
                                     // for unknown functions - copy the type, and expand any embedded
                                     // mask definitions.
                                     $func['type'] = $function_r['type'];
                                     for ($j = 0; $j < count($function_r['args']); $j++) {
                                         $tmp_parsed_arg = $this->_parse_field_mask($function_r['args'][$j]);
                                         if (is_array($tmp_parsed_arg)) {
                                             $func['args'][] = array('mask' => $function_r['args'][$j], 'elements' => $tmp_parsed_arg);
                                         } else {
                                             $func['args'][] = $function_r['args'][$j];
                                         }
                                     }
                                     $array_of_vars[] = $func;
                                     break;
                             }
                         } else {
                             if ($variable == 'title' || $variable == 's_item_type' || $variable == 's_status_type' || $variable == 'item_id' || $variable == 'instance_no') {
                                 $array_of_vars[] = $variable;
                             } else {
                                 $index_of_sep = strrpos($variable, '.');
                                 if ($index_of_sep !== false) {
                                     $s_attribute_type = strtoupper(substr($variable, 0, $index_of_sep));
                                     $option = substr($variable, $index_of_sep + 1);
                                     if ($option == 'display_type') {
                                         $attribute_r = fetch_attribute_type_r($s_attribute_type);
                                         $array_of_vars[] = array('s_attribute_type' => $s_attribute_type, 'option' => $option, 'display_type' => $attribute_r['display_type'], 'display_type_arg1' => $attribute_r['display_type_arg1'], 'display_type_arg2' => $attribute_r['display_type_arg2'], 'display_type_arg3' => $attribute_r['display_type_arg3'], 'display_type_arg4' => $attribute_r['display_type_arg4'], 'display_type_arg5' => $attribute_r['display_type_arg5'], 'prompt' => $attribute_r['prompt']);
                                     } else {
                                         $array_of_vars[] = array('s_attribute_type' => $s_attribute_type, 'option' => $option);
                                     }
                                 } else {
                                     $array_of_vars[] = array('s_attribute_type' => strtoupper($variable), 'option' => 'value');
                                 }
                             }
                         }
                         // add a {array_reference} to display_mask.
                         $new_display_mask .= '{' . (count($array_of_vars) - 1) . '}';
                     }
                     $variable = '';
                 } else {
                     $variable .= '}';
                 }
             } else {
                 if ($display_mask[$i] == '{') {
                     $inside_variable++;
                     $variable .= '{';
                 } else {
                     $variable .= $display_mask[$i];
                 }
             }
         } else {
             if ($display_mask[$i] != '{') {
                 $new_display_mask .= $display_mask[$i];
             } else {
                 $inside_variable++;
             }
         }
     }
     // return parsed mask (via pass-by-reference) back to caller.
     $display_mask = $new_display_mask;
     // return array of parsed sections as well.
     return $array_of_vars;
 }
Beispiel #6
0
function fetch_cached_attribute_type_r($s_attribute_type)
{
    global $_OPENDB_DB_CACHE;
    if (!is_array($_OPENDB_DB_CACHE['s_attribute_type']) || !is_array($_OPENDB_DB_CACHE['s_attribute_type'][$s_attribute_type])) {
        $_OPENDB_DB_CACHE['s_attribute_type'][$s_attribute_type] = fetch_attribute_type_r($s_attribute_type);
    }
    return $_OPENDB_DB_CACHE['s_attribute_type'][$s_attribute_type];
}
Beispiel #7
0
function get_item_review_block($item_r)
{
    $buffer .= "<h3>" . get_opendb_lang_var('review(s)') . "</h3>";
    $result = fetch_review_rs($item_r['item_id']);
    if ($result) {
        $buffer .= "<ul>";
        while ($review_r = db_fetch_assoc($result)) {
            $action_links = NULL;
            $buffer .= "<li>";
            // even if already review author its possible to revoke rights to
            // edit / modify own reviews by revoking the PERM_USER_REVIEWER grant!
            if (is_user_granted_permission(PERM_ADMIN_REVIEWER) || is_user_granted_permission(PERM_USER_REVIEWER) && is_review_author($review_r['sequence_number'])) {
                $action_links_rs = NULL;
                if (get_opendb_config_var('item_review', 'update_support') !== FALSE) {
                    $action_links[] = array(url => "item_review.php?op=edit&sequence_number=" . $review_r['sequence_number'] . "&item_id=" . $item_r['item_id'] . "&instance_no=" . $item_r['instance_no'], text => get_opendb_lang_var('edit'));
                }
                if (get_opendb_config_var('item_review', 'delete_support') !== FALSE) {
                    $action_links[] = array(url => "item_review.php?op=delete&sequence_number=" . $review_r['sequence_number'] . "&item_id=" . $item_r['item_id'] . "&instance_no=" . $item_r['instance_no'], text => get_opendb_lang_var('delete'));
                }
                $buffer .= format_footer_links($action_links);
            }
            $buffer .= "<p class=\"author\">";
            $buffer .= get_opendb_lang_var('on_date_name_wrote_the_following', array('date' => get_localised_timestamp(get_opendb_config_var('item_display', 'review_datetime_mask'), $review_r['update_on']), 'fullname' => fetch_user_name($review_r['author_id']), 'user_id' => $review_r['author_id']));
            $buffer .= "</p>";
            $buffer .= "<p class=\"comments\">" . nl2br(trim($review_r['comment']));
            if ($review_r['item_id'] != $item_r['item_id']) {
                $buffer .= "<span class=\"reference\">" . get_opendb_lang_var('review_for_item_type_title', array('s_item_type' => $review_r['s_item_type'], 'item_id' => $review_r['item_id'])) . "</span>";
            }
            $buffer .= "</p>";
            $average = $review_r['rating'];
            $attribute_type_r = fetch_attribute_type_r("S_RATING");
            $buffer .= "<span class=\"rating\">" . get_display_field($attribute_type_r['s_attribute_type'], NULL, 'review()', $average, FALSE) . "</span>";
            $buffer .= "</li>";
        }
        //while
        $buffer .= "</ul>";
    } else {
        $buffer .= '<p>' . get_opendb_lang_var('no_item_reviews') . '</p>';
    }
    $action_links = NULL;
    if (is_user_granted_permission(PERM_USER_REVIEWER)) {
        $action_links[] = array(url => "item_review.php?op=add&item_id=" . $item_r['item_id'] . "&instance_no=" . $item_r['instance_no'], text => get_opendb_lang_var('review'));
        $buffer .= format_footer_links($action_links);
    }
    return $buffer;
}
Beispiel #8
0
 echo "<div class=\"tabContainer\">";
 echo "<ul class=\"tabMenu\" id=\"tab-menu\">";
 echo "<li id=\"menu-details\" class=\"first activeTab\" onclick=\"return activateTab('details')\">" . get_opendb_lang_var('details') . "</li>";
 echo "<li id=\"menu-instance_info\" onclick=\"return activateTab('instance_info')\">" . get_opendb_lang_var('instance_info') . "</li>";
 if (get_opendb_config_var('item_review', 'enable') !== FALSE) {
     echo "<li id=\"menu-reviews\" onclick=\"return activateTab('reviews')\">" . get_opendb_lang_var('review(s)') . "</li>";
 }
 echo "</ul>";
 echo "<div id=\"tab-content\">";
 echo "<div class=\"tabContent\" id=\"details\">";
 if (get_opendb_config_var('item_review', 'enable') !== FALSE) {
     $average = fetch_review_rating($item_r['item_id']);
     if ($average !== FALSE) {
         echo "<p class=\"rating\">";
         echo get_opendb_lang_var('rating') . ": ";
         $attribute_type_r = fetch_attribute_type_r('S_RATING');
         echo get_display_field($attribute_type_r['s_attribute_type'], NULL, 'review()', $average, FALSE);
         echo "</p>";
     }
 }
 $results = fetch_item_attribute_type_rs($item_r['s_item_type'], 'not_instance_field_types');
 if ($results) {
     echo "<table>";
     while ($item_attribute_type_r = db_fetch_assoc($results)) {
         if (has_role_permission($item_attribute_type_r['view_perm'])) {
             $display_type = trim($item_attribute_type_r['display_type']);
             if ($HTTP_VARS['mode'] == 'printable' && $item_attribute_type_r['printable_ind'] != 'Y' || strlen($display_type) == 0 && $item_attribute_type_r['input_type'] == 'hidden') {
                 // We allow the get_display_field to handle hidden variable, in case at some stage
                 // we might want to change the functionality of 'hidden' to something other than ignore.
                 $display_type = 'hidden';
             }
Beispiel #9
0
 echo "\n<form name=\"search\" method=\"GET\" action=\"listings.php\">";
 echo "\n<input type=\"hidden\" name=\"datetimemask\" value=\"" . get_opendb_config_var('search', 'datetime_mask') . "\">";
 echo "\n<input type=\"hidden\" name=\"search_list\" value=\"y\">";
 echo "<table class=\"searchForm\">";
 echo format_field(get_opendb_lang_var('title'), "\n<input type=\"text\" class=\"text\" id=\"search-title\" size=\"50\" name=\"title\">" . "\n<ul class=\"searchInputOptions\">" . "\n<li><input type=\"radio\" class=\"radio\" name=\"title_match\" value=\"word\">" . get_opendb_lang_var('word_match') . "</li>" . "\n<li><input type=\"radio\" class=\"radio\" name=\"title_match\" value=\"partial\" CHECKED>" . get_opendb_lang_var('partial_match') . "</li>" . "\n<li><input type=\"radio\" class=\"radio\" name=\"title_match\" value=\"exact\">" . get_opendb_lang_var('exact_match') . "</li>" . "\n<li><input type=\"checkbox\" class=\"checkbox\" name=\"title_case\" value=\"case_sensitive\">" . get_opendb_lang_var('case_sensitive') . "</li>" . "\n</ul>");
 if (@count($category_type_rs) > 1) {
     $catTypeSelect = "<select name=\"category\" id=\"search-category\">" . "\n<option value=\"\">-------------- " . get_opendb_lang_var('all') . " --------------";
     reset($category_type_rs);
     while (list($value, $display) = each($category_type_rs)) {
         $catTypeSelect .= "\n<option value=\"{$value}\">{$display}";
     }
     $itemTypeBlock .= "</select>";
     echo format_field(get_opendb_lang_var('category'), $catTypeSelect);
 }
 if (get_opendb_config_var('item_review', 'enable') !== FALSE) {
     $attribute_type_r = fetch_attribute_type_r("S_RATING");
     $attribute_type_r['compulsory_ind'] = 'N';
     echo get_item_input_field("rating", $attribute_type_r, NULL, NULL);
     //value
 }
 if (@count($item_type_rs) > 1) {
     $itemTypeSelect = "<select name=\"s_item_type\" id=\"search-itemtype\" onChange=\"populateList(this.options[this.options.selectedIndex].value, this.form.attribute_type, arrayOfAttributes, true, '------------- " . get_opendb_lang_var('all') . " -------------', false);\">" . "\n<option value=\"\">-------------- " . get_opendb_lang_var('all') . " --------------";
     reset($item_type_rs);
     while (list(, $item_type_r) = each($item_type_rs)) {
         $itemTypeSelect .= "\n<option value=\"" . $item_type_r['s_item_type'] . "\" >" . $item_type_r['s_item_type'] . " - " . $item_type_r['description'];
     }
     $itemTypeBlock .= "</select>";
     echo format_field(get_opendb_lang_var('item_type'), $itemTypeSelect);
 }
 $attrTypeSelect = "<select name=\"attribute_type\" id=\"search-attributetype\" onChange=\"populateList(this.options[this.options.selectedIndex].value, this.form['lookup_attribute_val'], arrayOfLookupValues, false, '" . get_opendb_lang_var('use_the_value_field') . " ---->', true);\">" . "\n<option value=\"\">-------------- " . get_opendb_lang_var('all') . " --------------";
 @reset($item_attribute_type_rs);
Beispiel #10
0
function get_field_default_value($s_attribute_type)
{
    $attribute_type_r = fetch_attribute_type_r($s_attribute_type);
    $value = NULL;
    switch ($attribute_type_r['input_type']) {
        case 'text':
            $value = $attribute_type_r['input_type_arg3'];
            break;
        case 'number':
            $value = $attribute_type_r['input_type_arg2'];
            break;
        case 'filtered':
            $value = $attribute_type_r['input_type_arg4'];
            break;
        case 'checkbox':
            if ($attribute_type_r['input_type_arg3'] == $attribute_type_r['input_type_arg1'] || $attribute_type_r['input_type_arg3'] == $attribute_type_r['input_type_arg2']) {
                $value = $attribute_type_r['input_type_arg3'];
            }
            break;
    }
    return $value;
}
Beispiel #11
0
/**
* Return array of attribute_val's for $s_attribute_type, $order_no, $item_id, $instance_no
*/
function fetch_attribute_val_r($item_id, $instance_no, $s_attribute_type, $order_no = NULL)
{
    $query = "SELECT item_id, instance_no, s_attribute_type, order_no, attribute_no, lookup_attribute_val, attribute_val FROM item_attribute " . "WHERE item_id = '{$item_id}' AND " . "s_attribute_type = '{$s_attribute_type}'";
    if (is_numeric($instance_no)) {
        $query .= " AND (instance_no = 0 OR instance_no = {$instance_no}) ";
    }
    // Only add order_no where condition if order_no defined, otherwise we
    // will return the first instance of s_attribute_type.
    if (is_numeric($order_no)) {
        $query .= " AND order_no = '{$order_no}'";
    }
    $query .= " ORDER BY attribute_no";
    $results = db_query($query);
    if ($results && db_num_rows($results) > 0) {
        $attribute_type_r = fetch_attribute_type_r($s_attribute_type);
        $attribute_val_r = NULL;
        while ($item_attribute_r = db_fetch_assoc($results)) {
            if ($attribute_type_r['lookup_attribute_ind'] == 'Y') {
                $attribute_val_r[] = $item_attribute_r['lookup_attribute_val'];
            } else {
                if ($attribute_type_r['file_attribute_ind'] != 'Y') {
                    $attribute_val_r[] = $item_attribute_r['attribute_val'];
                } else {
                    //if($attribute_type_r['file_attribute_ind'] == 'Y')
                    $attribute_val_r[] = $item_attribute_r['attribute_val'];
                }
            }
        }
        db_free_result($results);
        return $attribute_val_r;
    } else {
        return FALSE;
    }
}
Beispiel #12
0
/**
 * @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'));
}