예제 #1
0
파일: export.php 프로젝트: horrabin/opendb
function fetch_export_item_rs($s_item_type, $owner_id, $restrict_status_type_r = NULL)
{
    $query = "SELECT DISTINCT i.id as item_id, i.title, i.s_item_type " . "FROM user u, item i, item_instance ii, s_status_type sst " . "WHERE u.user_id = ii.owner_id AND i.id = ii.item_id AND sst.s_status_type = ii.s_status_type ";
    if (strlen($owner_id) > 0) {
        $query .= "AND ii.owner_id = '{$owner_id}' ";
    }
    // can only export items for active users.
    $query .= "AND u.active_ind = 'Y' ";
    if (strlen($s_item_type) > 0) {
        $query .= "AND i.s_item_type = '{$s_item_type}'";
    }
    if (is_not_empty_array($restrict_status_type_r)) {
        $query .= 'AND sst.s_status_type IN(' . format_sql_in_clause($restrict_status_type_r) . ')';
    }
    // Not the status_type restriction could override this, but thats fine leave it as is.
    if (!is_user_granted_permission(PERM_ITEM_ADMIN)) {
        $query .= " AND ( sst.hidden_ind = 'N' OR ii.owner_id = '" . get_opendb_session_var('user_id') . "') ";
    }
    $result = db_query($query);
    if ($result && db_num_rows($result) > 0) {
        return $result;
    } else {
        return FALSE;
    }
}
예제 #2
0
function fetch_item_type_for_item_types_rs($item_type_r, $is_lookup = FALSE)
{
    $query = "SELECT s_item_type" . ($is_lookup ? " as value" : "") . ", ifnull(stlv.value, description) " . ($is_lookup ? "display" : "description") . " \n\t\t\tFROM s_item_type \n\t\t\tLEFT JOIN s_table_language_var stlv\n\t\t\tON stlv.language = '" . get_opendb_site_language() . "' AND\n\t\t\tstlv.tablename = 's_item_type' AND\n\t\t\tstlv.columnname = 'description' AND\n\t\t\tstlv.key1 = s_item_type \n\t\t\tWHERE s_item_type IN (" . format_sql_in_clause($item_type_r) . ") \n\t\t\tORDER BY order_no, s_item_type";
    $result = db_query($query);
    if ($result && db_num_rows($result) > 0) {
        return $result;
    } else {
        return FALSE;
    }
}
예제 #3
0
파일: review.php 프로젝트: horrabin/opendb
function fetch_review_rating($item_id = NULL)
{
    if ($item_id) {
        $query = "SELECT r.rating FROM review r ";
        if (get_opendb_config_var('item_review', 'include_other_title_reviews') === TRUE) {
            $item_r = fetch_item_r($item_id);
            $query .= ", item i " . "WHERE r.item_id = i.id AND (i.id = {$item_id} OR i.title = '" . addslashes($item_r['title']) . "')";
            if (get_opendb_config_var('item_review', 'other_title_reviews_restrict_to_item_type_group') !== FALSE) {
                // first of all we need to get the groups this item belongs to, then we need
                // to get the list of all other s_item_type's that are in those groups.
                $item_type_group_r = fetch_item_type_groups_for_item_type_r($item_r['s_item_type']);
                if (is_array($item_type_group_r)) {
                    $item_type_r = fetch_item_types_for_group_r($item_type_group_r[0]);
                    // only use first one.
                    if (is_array($item_type_r)) {
                        $query .= " AND i.s_item_type IN (" . format_sql_in_clause($item_type_r) . ")";
                    }
                }
            }
        } else {
            $query .= "WHERE r.item_id = {$item_id}";
        }
    } else {
        $query = "SELECT rating FROM review";
    }
    $result = db_query($query);
    if ($result && db_num_rows($result) > 0) {
        // Initialise.
        $total = 0;
        $number = 0;
        while ($review_r = db_fetch_assoc($result)) {
            $total = $total + $review_r['rating'];
            $number++;
        }
        db_free_result($result);
        if ($number == 0) {
            return 0;
        } else {
            return $total / $number;
        }
    }
    //else
    return FALSE;
}
예제 #4
0
파일: item.php 프로젝트: horrabin/opendb
/**
* 	NOTE: PRIVATE FUNCTION.

	Will return the FROM and WHERE clauses for a selection from the item table.
	
	If $owner_id defined, will limit to only items owned by owner_id
	If $s_item_type defined, will limit to only items of that type.
	If $category defined, will limit to only items of that category.
	If $letter defined will limit to item.title starting with that letter.
	If $interest_level defined will limit to items with that interest level or higher.
	
	@param $HTTP_VARS['...'] variables supported: 
		owner_id, s_item_type, s_item_type[], s_item_type_group, title, title_match, category,
		rating, attribute_type, lookup_attribute_val, attribute_val, attr_match, 
		update_on, datetimemask, update_on_days, letter, start_item_id
		s_status_type[], status_comment, not_s_status_type[], interest_level
*/
function from_and_where_clause($HTTP_VARS, $column_display_config_rs = NULL, $query_type = 'LISTING')
{
    // For checking whether count (DISTINCT ...) is supported, and thus
    // whether we have to do any special processing!
    $from_r[] = 'item i';
    $from_r[] = 'item_instance ii';
    $where_r[] = 'ii.item_id = i.id';
    // only parent items should ever be listed.
    //
    // Owner restriction
    //
    if (strlen($HTTP_VARS['owner_id']) > 0) {
        $where_r[] = 'ii.owner_id = \'' . $HTTP_VARS['owner_id'] . '\'';
    } else {
        if (strlen($HTTP_VARS['not_owner_id']) > 0) {
            //For not showing current user items.
            $where_r[] = 'ii.owner_id <> \'' . $HTTP_VARS['not_owner_id'] . '\'';
        }
    }
    //
    // Item Type / Item Type group restriction
    //
    if (!is_array($HTTP_VARS['s_item_type']) && strlen($HTTP_VARS['s_item_type']) > 0) {
        $where_r[] = 'i.s_item_type = \'' . $HTTP_VARS['s_item_type'] . '\'';
    } else {
        if (strlen($HTTP_VARS['s_item_type_group']) > 0) {
            $from_r[] = 's_item_type_group_rltshp sitgr';
            $where_r[] = 'sitgr.s_item_type = i.s_item_type';
            $where_r[] = 'sitgr.s_item_type_group = \'' . $HTTP_VARS['s_item_type_group'] . '\'';
        } else {
            if (is_not_empty_array($HTTP_VARS['s_item_type'])) {
                $where_r[] = 'i.s_item_type IN(' . format_sql_in_clause($HTTP_VARS['s_item_type']) . ')';
            }
        }
    }
    $from_r[] = 's_status_type sst';
    $where_r[] = 'sst.s_status_type = ii.s_status_type';
    //
    // Status Type restriction
    //
    if (is_not_empty_array($HTTP_VARS['s_status_type'])) {
        $where_r[] = 'sst.s_status_type IN(' . format_sql_in_clause($HTTP_VARS['s_status_type']) . ')';
    } else {
        if ($HTTP_VARS['s_status_type'] != 'ALL' && strlen($HTTP_VARS['s_status_type']) > 0) {
            $where_r[] = 'sst.s_status_type = \'' . $HTTP_VARS['s_status_type'] . '\'';
        }
    }
    // no need for such a restriction if current user is item admin
    if (!is_user_granted_permission(PERM_ITEM_ADMIN)) {
        $where_r[] = "( sst.hidden_ind = 'N' OR ii.owner_id = '" . get_opendb_session_var('user_id') . "') ";
    }
    //
    // User and Status type restriction
    //
    if (strcmp($HTTP_VARS['owner_id'], get_opendb_session_var('user_id')) !== 0) {
        // not current user
        $from_r[] = 'user u';
        $where_r[] = 'u.user_id = ii.owner_id';
        $where_r[] = 'u.active_ind = \'Y\'';
    }
    //
    // Status Comment restriction
    //
    if (strlen($HTTP_VARS['status_comment']) > 0) {
        // Escape only the single quote!
        $HTTP_VARS['status_comment'] = str_replace("'", "\\'", $HTTP_VARS['status_comment']);
        if ($HTTP_VARS['status_comment_match'] != 'exact') {
            $parser = new BooleanParser();
            $statements = $parser->parseBooleanStatement($HTTP_VARS['status_comment']);
            if (is_array($statements)) {
                $where_r[] = build_boolean_clause($statements, 'ii.status_comment', $HTTP_VARS['status_comment_match'], 'AND', $HTTP_VARS['status_comment_case']);
            }
        } else {
            if (is_null($HTTP_VARS['status_comment_case'])) {
                $where_r[] = 'ii.status_comment = \'' . $HTTP_VARS['status_comment'] . '\'';
            } else {
                $where_r[] = 'BINARY ii.status_comment = \'' . $HTTP_VARS['status_comment'] . '\'';
            }
        }
    }
    //
    // Title restriction
    //
    if (strlen($HTTP_VARS['title']) > 0) {
        // Escape only the single quote!
        $HTTP_VARS['title'] = str_replace("'", "\\'", $HTTP_VARS['title']);
        if ($HTTP_VARS['title_match'] != 'exact') {
            $parser = new BooleanParser();
            $statements = $parser->parseBooleanStatement($HTTP_VARS['title']);
            if (is_array($statements)) {
                $where_r[] = build_boolean_clause($statements, 'i.title', $HTTP_VARS['title_match'], 'AND', $HTTP_VARS['title_case']);
            }
        } else {
            if (is_null($HTTP_VARS['title_case'])) {
                $where_r[] = 'i.title = \'' . $HTTP_VARS['title'] . '\'';
            } else {
                $where_r[] = 'BINARY i.title = \'' . $HTTP_VARS['title'] . '\'';
            }
        }
    } else {
        if (strlen($HTTP_VARS['letter']) > 0) {
            // Numeric match.
            if ($HTTP_VARS['letter'] == '#') {
                $where_r[] = 'ASCII(LEFT(title,1)) BETWEEN ASCII(\'0\') AND ASCII(\'9\')';
            } else {
                $where_r[] = 'UPPER(LEFT(i.title,1)) = \'' . strtoupper($HTTP_VARS['letter']) . '\'';
            }
        }
    }
    //
    // Last Updated support
    //
    if (strlen($HTTP_VARS['update_on']) > 0) {
        if (strlen($HTTP_VARS['datetimemask']) > 0) {
            $timestamp = get_timestamp_for_datetime($HTTP_VARS['update_on'], $HTTP_VARS['datetimemask']);
            if ($timestamp !== FALSE) {
                $where_r[] = 'ii.update_on >= FROM_UNIXTIME(' . $timestamp . ')';
            } else {
                // by default get items from 1 day ago, if update_on can not be parsed correctly.
                $where_r[] = 'TO_DAYS(ii.update_on) >= (TO_DAYS(now())-1)';
            }
        } else {
            $where_r[] = 'ii.update_on >= \'' . $HTTP_VARS['update_on'] . '\'';
        }
    } else {
        if (is_numeric($HTTP_VARS['update_on_days'])) {
            // GIve us all records updated in the last however many days.
            $where_r[] = 'TO_DAYS(ii.update_on) >= (TO_DAYS(now())-' . $HTTP_VARS['update_on_days'] . ')';
        }
    }
    //
    // Item Attribute listing/restriction
    //
    if (is_array($column_display_config_rs)) {
        for ($i = 0; $i < count($column_display_config_rs); $i++) {
            if ($column_display_config_rs[$i]['column_type'] == 's_attribute_type') {
                if ($column_display_config_rs[$i]['search_attribute_ind'] != 'y') {
                    // either LISTING or COUNT
                    if ($query_type != 'COUNT') {
                        $left_join = 'LEFT JOIN item_attribute ia' . $i . ' ON ' . 'ia' . $i . '.item_id = i.id AND (ia' . $i . '.instance_no = 0 OR ia' . $i . '.instance_no = ii.instance_no) AND ia' . $i . '.s_attribute_type = \'' . $column_display_config_rs[$i]['s_attribute_type'] . '\' AND ia' . $i . '.attribute_no = 1';
                        // So we can work out which search attribute types to display
                        if (is_numeric($column_display_config_rs[$i]['order_no'])) {
                            $left_join .= ' AND ia' . $i . '.order_no = ' . $column_display_config_rs[$i]['order_no'];
                        }
                        $left_join_from_r[] = $left_join;
                    }
                } else {
                    // search attribute
                    $from_r[] = 'item_attribute ia' . $i;
                    // now do the where clause.
                    $where_r[] = 'ia' . $i . '.item_id = i.id AND (ia' . $i . '.instance_no = 0 OR ia' . $i . '.instance_no = ii.instance_no) AND ia' . $i . '.s_attribute_type = \'' . $column_display_config_rs[$i]['s_attribute_type'] . '\'';
                    // AND ia'.$i.'.attribute_no = 1';
                    if (strlen($column_display_config_rs[$i]['attribute_val']) > 0 && $column_display_config_rs[$i]['attribute_val'] != '%' && $column_display_config_rs[$i]['attr_match'] != 'exact') {
                        $parser = new BooleanParser();
                        $statements = $parser->parseBooleanStatement(strtoupper(str_replace("'", "\\'", $column_display_config_rs[$i]['attribute_val'])));
                        if (is_array($statements)) {
                            if ($column_display_config_rs[$i]['lookup_attribute_ind'] == 'Y') {
                                $where_r[] = build_boolean_clause($statements, 'ia' . $i . '.lookup_attribute_val', 'plain', 'AND', $HTTP_VARS['attr_case']);
                            } else {
                                $where_r[] = build_boolean_clause($statements, 'ia' . $i . '.attribute_val', $column_display_config_rs[$i]['attr_match'], 'AND', $HTTP_VARS['attr_case']);
                            }
                        }
                    } else {
                        if (strlen($column_display_config_rs[$i]['lookup_attribute_val']) > 0 && $column_display_config_rs[$i]['lookup_attribute_val'] != '%' && $column_display_config_rs[$i]['lookup_attribute_ind'] == 'Y') {
                            $value = str_replace("'", "\\'", $column_display_config_rs[$i]['lookup_attribute_val']);
                            $where_r[] = 'ia' . $i . '.lookup_attribute_val = \'' . str_replace('\\_', '_', $value) . '\'';
                        } else {
                            if (strlen($column_display_config_rs[$i]['attribute_val']) > 0 && $column_display_config_rs[$i]['attribute_val'] != '%') {
                                if (starts_with($column_display_config_rs[$i]['attribute_val'], '"') && ends_with($column_display_config_rs[$i]['attribute_val'], '"')) {
                                    $column_display_config_rs[$i]['attribute_val'] = substr($column_display_config_rs[$i]['attribute_val'], 1, -1);
                                }
                                $value = strtoupper(str_replace("'", "\\'", $column_display_config_rs[$i]['attribute_val']));
                                $where_r[] = 'UPPER(ia' . $i . '.attribute_val) = \'' . str_replace('\\_', '_', $value) . '\'';
                            }
                        }
                    }
                    if (strlen($HTTP_VARS['attr_update_on']) > 0) {
                        if (strlen($HTTP_VARS['datetimemask']) > 0) {
                            $timestamp = get_timestamp_for_datetime($HTTP_VARS['attr_update_on'], $HTTP_VARS['datetimemask']);
                            if ($timestamp !== FALSE) {
                                $where_r[] = 'ia' . $i . '.update_on >= FROM_UNIXTIME(' . $timestamp . ')';
                            } else {
                                // by default get items from 1 day ago, if update_on can not be parsed correctly.
                                $where_r[] = 'TO_DAYS(ia' . $i . '.update_on) >= (TO_DAYS(now())-1)';
                            }
                        } else {
                            $where_r[] = 'ia' . $i . '.update_on >= \'' . $HTTP_VARS['attr_update_on'] . '\'';
                        }
                    } else {
                        if (is_numeric($HTTP_VARS['attr_update_on_days'])) {
                            // GIve us all records updated in the last however many days.
                            $where_r[] = 'TO_DAYS(ia' . $i . '.update_on) >= (TO_DAYS(now())-' . $HTTP_VARS['attr_update_on_days'] . ')';
                        }
                    }
                }
            } else {
                if ($column_display_config_rs[$i]['column_type'] == 's_field_type') {
                    if ($column_display_config_rs[$i]['s_field_type'] == 'CATEGORY') {
                        $from_r[] = 's_item_attribute_type catsiat';
                        $from_r[] = 's_attribute_type catsat';
                        $where_r[] = 'catsiat.s_item_type = i.s_item_type AND catsat.s_attribute_type = catsiat.s_attribute_type AND catsat.s_field_type = \'CATEGORY\'';
                        $left_join_clause = 'LEFT JOIN item_attribute catia ON ' . 'catia.item_id = i.id AND (catia.instance_no = 0 OR catia.instance_no = ii.instance_no) AND catia.s_attribute_type = catsiat.s_attribute_type AND catia.order_no = catsiat.order_no';
                        if (strlen($HTTP_VARS['category']) > 0 || strcasecmp($HTTP_VARS['attr_match'], 'category') === 0 && strlen($HTTP_VARS['attribute_val']) > 0) {
                            // Support specifying $attribute_val for $category where $attr_match=="category"!
                            // If item_type && item_type_group are not set!
                            if (strlen($HTTP_VARS['attribute_type']) > 0 && !is_array($HTTP_VARS['s_item_type']) && strlen($HTTP_VARS['s_item_type']) == 0 && strlen($HTTP_VARS['s_item_type_group']) == 0) {
                                $where_r[] = 'catsat.s_attribute_type = \'' . $HTTP_VARS['attribute_type'] . '\'';
                            }
                            // Escape single quotes only.
                            $value = strtoupper(str_replace("'", "\\'", ifempty($HTTP_VARS['category'], $HTTP_VARS['attribute_val'])));
                            $where_r[] = 'UPPER(catia.lookup_attribute_val) = \'' . str_replace('\\_', '_', $value) . '\'';
                        } else {
                            $left_join_clause .= ' AND catia.attribute_no = 1';
                        }
                        $left_join_from_r[] = $left_join_clause;
                    } else {
                        if ($column_display_config_rs[$i]['s_field_type'] == 'INTEREST') {
                            // can only restrict interest level if its displayed as a column
                            if (strlen($HTTP_VARS['interest_level']) > 0) {
                                $where_r[] = "it.item_id = ii.item_id AND it.instance_no = ii.instance_no AND it.user_id = '" . get_opendb_session_var('user_id') . "'" . " AND it.level >= " . $HTTP_VARS['interest_level'];
                                $from_r[] = "user_item_interest it";
                            } else {
                                $left_join_from_r[] = "LEFT JOIN user_item_interest it ON it.item_id = i.id AND it.instance_no = ii.instance_no AND it.user_id = '" . get_opendb_session_var('user_id') . "'";
                            }
                        }
                    }
                }
            }
        }
    }
    // If attribute_val specified without a attribute_type, then do a loose join to item_attribute table,
    // only on attribute_val column.
    if (strlen($HTTP_VARS['attribute_type']) == 0 && (strlen($HTTP_VARS['attribute_val']) > 0 || strlen($HTTP_VARS['attr_update_on']) > 0 || strlen($HTTP_VARS['attr_update_on_days']) > 0)) {
        $from_r[] = 'item_attribute ia';
        // now do the where clause.
        $where_r[] = 'ia.item_id = i.id ';
        //AND ia.attribute_no = 1';
        if ($HTTP_VARS['attr_match'] != 'exact') {
            $parser = new BooleanParser();
            $statements = $parser->parseBooleanStatement(strtoupper(str_replace("'", "\\'", $HTTP_VARS['attribute_val'])));
            if (is_array($statements)) {
                if (is_lookup_attribute_type($HTTP_VARS['attribute_type'])) {
                    $where_r[] = build_boolean_clause($statements, 'ia.lookup_attribute_val', 'plain', 'AND', $HTTP_VARS['attr_case']);
                } else {
                    $where_r[] = build_boolean_clause($statements, 'ia.attribute_val', $HTTP_VARS['attr_match'], 'AND', $HTTP_VARS['attr_case']);
                }
            }
        } else {
            // attr_match = 'exact'
            if (is_lookup_attribute_type($HTTP_VARS['attribute_type'])) {
                $value = str_replace("'", "\\'", $HTTP_VARS['attribute_val']);
                $where_r[] = 'ia.lookup_attribute_val = \'' . str_replace('\\_', '_', $value) . '\'';
            } else {
                $value = str_replace("'", "\\'", $HTTP_VARS['attribute_val']);
                if (is_null($HTTP_VARS['attr_case'])) {
                    $where_r[] = '( ia.attribute_val = \'' . str_replace('\\_', '_', $value) . '\' OR ' . 'ia.attribute_val LIKE \'% ' . $value . ' %\' OR ' . 'ia.attribute_val LIKE \'' . $value . ' %\' OR ' . 'ia.attribute_val LIKE \'% ' . $value . '\')';
                } else {
                    $where_r[] = '( BINARY ia.attribute_val = \'' . str_replace('\\_', '_', $value) . '\' OR ' . 'ia.attribute_val LIKE BINARY \'% ' . $value . ' %\' OR ' . 'ia.attribute_val LIKE BINARY \'' . $value . ' %\' OR ' . 'ia.attribute_val LIKE BINARY \'% ' . $value . '\')';
                }
            }
        }
        if (strlen($HTTP_VARS['attr_update_on']) > 0) {
            if (strlen($HTTP_VARS['datetimemask']) > 0) {
                $timestamp = get_timestamp_for_datetime($HTTP_VARS['attr_update_on'], $HTTP_VARS['datetimemask']);
                if ($timestamp !== FALSE) {
                    $where_r[] = 'ia.update_on >= FROM_UNIXTIME(' . $timestamp . ')';
                } else {
                    // by default get items from 1 day ago, if update_on can not be parsed correctly.
                    $where_r[] = 'TO_DAYS(ia.update_on) >= (TO_DAYS(now())-1)';
                }
            } else {
                $where_r[] = 'ia.update_on >= \'' . $HTTP_VARS['attr_update_on'] . '\'';
            }
        } else {
            if (is_numeric($HTTP_VARS['attr_update_on_days'])) {
                // GIve us all records updated in the last however many days.
                $where_r[] = 'TO_DAYS(ia.update_on) >= (TO_DAYS(now())-' . $HTTP_VARS['attr_update_on_days'] . ')';
            }
        }
    }
    //
    // Review restrictions
    //
    if (strlen($HTTP_VARS['rating']) > 0) {
        $where_r[] = 'r.item_id = i.id AND r.rating >= ' . $HTTP_VARS['rating'];
        $from_r[] = 'review r';
    }
    //
    // Item ID range restriction (Used by Import script)
    //
    if (strlen($HTTP_VARS['item_id_range']) > 0) {
        $where_r[] = 'i.id IN (' . expand_number_range($HTTP_VARS['item_id_range']) . ')';
    }
    //
    // Now build the SQL query
    //
    if (is_array($from_r)) {
        $from_clause = '';
        for ($i = 0; $i < count($from_r); $i++) {
            if (strlen($from_clause) > 0) {
                $from_clause .= ', ';
            }
            $from_clause .= $from_r[$i];
        }
        $query .= 'FROM (' . $from_clause . ') ';
    }
    if (is_array($left_join_from_r)) {
        $left_join_from_clause = '';
        for ($i = 0; $i < count($left_join_from_r); $i++) {
            if (strlen($left_join_from_clause) > 0) {
                $left_join_from_clause .= ' ';
            }
            $left_join_from_clause .= $left_join_from_r[$i];
        }
        $query .= $left_join_from_clause . ' ';
    }
    if (is_array($where_r)) {
        $where_clause = '';
        for ($i = 0; $i < count($where_r); $i++) {
            if (strlen($where_clause) > 0) {
                $where_clause .= ' AND ';
            }
            $where_clause .= $where_r[$i];
        }
        $query .= 'WHERE ' . $where_clause;
    }
    return $query;
}
예제 #5
0
function fetch_sfieldtype_attribute_type_rs($s_field_type, $orderby = "s_attribute_type", $order = "asc")
{
    $query = "SELECT s_attribute_type, s_field_type, description, prompt, input_type, display_type, site_type FROM s_attribute_type ";
    if (is_array($s_field_type)) {
        $query .= "WHERE s_field_type IN(" . format_sql_in_clause($s_field_type) . ") ";
    } else {
        $query .= "WHERE s_field_type = '{$s_field_type}' ";
    }
    $query .= "ORDER BY {$orderby} {$order}";
    $result = db_query($query);
    if ($result && db_num_rows($result) > 0) {
        return $result;
    } else {
        return FALSE;
    }
}
예제 #6
0
/**
	Its possible to specify an array of content groups
*/
function fetch_file_type_extensions_r($content_group)
{
    if (!is_array($content_group) && strlen($content_group) > 0) {
        $content_group_r[] = $content_group;
    } else {
        if (is_array($content_group)) {
            $content_group_r =& $content_group;
        }
    }
    $query = "SELECT sfte.extension\n\tFROM \ts_file_type sft,\n\t\t\ts_file_type_extension sfte \n\tWHERE\tsft.content_type = sfte.content_type";
    if (is_array($content_group_r)) {
        $query .= " AND sft.content_group IN(" . format_sql_in_clause($content_group_r) . ")";
    }
    $extensions_r = array();
    $results = db_query($query);
    if ($results && db_num_rows($results) > 0) {
        while ($extensions_rs = db_fetch_assoc($results)) {
            $extensions_r[] = strtolower($extensions_rs['extension']);
        }
        db_free_result($results);
    }
    return $extensions_r;
}
예제 #7
0
파일: user.php 프로젝트: horrabin/opendb
function fetch_user_cnt($user_role_permissions = NULL, $user_role_permissions_mode = INCLUDE_ROLE_PERMISSIONS, $current_user_mode = INCLUDE_CURRENT_USER, $restrict_users_mode = EXCLUDE_DEACTIVATED_USER)
{
    $query = "SELECT COUNT(u.user_id) AS count FROM user u";
    // List all users who can borrow records.
    $user_permissions_clause = format_sql_in_clause($user_role_permissions);
    if ($user_permissions_clause != NULL) {
        $query .= ", s_role_permission srp ";
        $where_clause .= "sr.role_name = srp.role_name \n\t\t\t\tAND srp.permission_name ";
        if ($user_role_permissions_mode == EXCLUDE_ROLE_PERMISSIONS) {
            $where_clause .= "NOT ";
        }
        $where_clause .= "IN({$user_permissions_clause}) ";
    }
    if ($current_user_mode == EXCLUDE_CURRENT_USER) {
        if (strlen($where_clause) > 0) {
            $where_clause .= " AND ";
        }
        $where_clause .= "u.user_id != '" . get_opendb_session_var('user_id') . "' ";
    }
    if ($restrict_users_mode == EXCLUDE_DEACTIVATED_USER) {
        if (strlen($where_clause) > 0) {
            $where_clause .= " AND ";
        }
        $where_clause .= "u.active_ind = 'Y' ";
    } else {
        if ($restrict_users_mode == INCLUDE_ACTIVATE_USER) {
            if (strlen($where_clause) > 0) {
                $where_clause .= " AND ";
            }
            $where_clause .= "u.active_ind = 'X' ";
        }
    }
    if (strlen($where_clause) > 0) {
        $query .= " WHERE {$where_clause}";
    }
    $result = db_query($query);
    if ($result && db_num_rows($result) > 0) {
        $found = db_fetch_assoc($result);
        db_free_result($result);
        if ($found !== FALSE) {
            return $found['count'];
        }
    }
    return FALSE;
}
예제 #8
0
/**
* The $site_plugin_attributes_r will consist of array entries, each identified by a 
* alphakey.  The value may in fact be another array and this has to be handled
* appropriately.
*/
function get_expanded_and_mapped_site_plugin_item_variables_r($site_type, $s_item_type, $site_item_attributes_r)
{
    $query = "SELECT variable, s_attribute_type, lookup_attribute_val_restrict_ind " . "FROM s_site_plugin_s_attribute_type_map " . "WHERE site_type = '" . $site_type . "' ";
    $query .= "AND (s_item_type = '*' OR s_item_type = '" . $s_item_type . "') AND ";
    $query .= "(s_item_type_group = '*' ";
    $item_type_group_arr = fetch_item_type_groups_for_item_type_r($s_item_type);
    if (is_array($item_type_group_arr)) {
        $query .= "OR s_item_type_group IN (" . format_sql_in_clause($item_type_group_arr) . ")) ";
    } else {
        $query .= ") ";
    }
    $query .= "ORDER BY variable, s_attribute_type";
    $new_attributes_r = array();
    // cache this, so we can check if lookup_attribute_val_restrict_ind = 'Y'
    $lookup_attribute_val_restrict_ind = array();
    $mapped_attributes_r = array();
    $results = db_query($query);
    if ($results && db_num_rows($results) > 0) {
        $variable = NULL;
        while ($attribute_type_map_r = db_fetch_assoc($results)) {
            $value = NULL;
            $variable = $attribute_type_map_r['variable'];
            if (isset($site_item_attributes_r[$variable])) {
                $value = $site_item_attributes_r[$variable];
                // at least one direct mapping - title should not be flagged - as there is requirement for multiple mappings
                if ($variable != 'title') {
                    $mapped_attributes_r[] = $variable;
                }
            }
            $key = strtolower($attribute_type_map_r['s_attribute_type']);
            if ($value !== NULL) {
                if (isset($new_attributes_r[$key])) {
                    if (!is_array($new_attributes_r[$key])) {
                        $new_attributes_r[$key] = array($new_attributes_r[$key]);
                    }
                    if (is_array($value)) {
                        $new_attributes_r[$key] = array_merge($new_attributes_r[$key], $value);
                    } else {
                        $new_attributes_r[$key][] = $value;
                    }
                } else {
                    $new_attributes_r[$key] = $value;
                }
            }
            if ($attribute_type_map_r['lookup_attribute_val_restrict_ind'] == 'Y') {
                $lookup_attribute_val_restrict_ind_r[$key] = 'Y';
            }
        }
        db_free_result($results);
    }
    // now for any variables that do not have a mapping, add them to the $new_attributes_r
    reset($site_item_attributes_r);
    while (list($key, $value) = @each($site_item_attributes_r)) {
        $key = strtolower($key);
        if (isset($new_attributes_r[$key])) {
            $oldValue = NULL;
            // we want the direct mapping attributes first.
            if (is_array($new_attributes_r[$key])) {
                $oldValue = $new_attributes_r[$key];
            } else {
                $oldValue[] = $new_attributes_r[$key];
            }
            unset($new_attributes_r[$key]);
            if (is_array($value)) {
                $new_attributes_r[$key] = $value;
            } else {
                $new_attributes_r[$key][] = $value;
            }
            while (list(, $value) = each($oldValue)) {
                if (!in_array($value, $new_attributes_r[$key])) {
                    $new_attributes_r[$key][] = $value;
                }
            }
        } else {
            if (!in_array($key, $mapped_attributes_r)) {
                $new_attributes_r[$key] = $value;
            }
        }
    }
    $site_item_attributes_r = NULL;
    // now we need to check to see if any lookup mappings exist for each
    // of the attribute values, and update the $value's appropriately.
    reset($new_attributes_r);
    while (list($key, $value) = @each($new_attributes_r)) {
        // temporary UPPER so we can work with actual s_attribute_type records in database
        $s_attribute_type = strtoupper($key);
        if (is_lookup_attribute_type($s_attribute_type)) {
            $values_r = NULL;
            // if a lookup attribute type, we want to make sure that the $value's
            // are all arrays anyway, so lets do that check each time.
            if (is_array($value)) {
                $values_r = $value;
            } else {
                $values_r[] = $value;
            }
            $results = fetch_site_plugin_s_attribute_type_lookup_map_rs($site_type, $s_attribute_type);
            if ($results) {
                $found_entries_r = array();
                $new_values_r = array();
                while ($lookup_map_r = db_fetch_assoc($results)) {
                    for ($i = 0; $i < count($values_r); $i++) {
                        if (strcasecmp($values_r[$i], $lookup_map_r['value']) === 0) {
                            $found_entries_r[] = $values_r[$i];
                            if (!in_array($lookup_map_r['lookup_attribute_val'], $new_values_r)) {
                                $new_values_r[] = $lookup_map_r['lookup_attribute_val'];
                            }
                        }
                    }
                }
                db_free_result($results);
                // now process all back into $values_r
                for ($i = 0; $i < count($values_r); $i++) {
                    if (!in_array($values_r[$i], $found_entries_r) && !in_array($values_r[$i], $new_values_r)) {
                        $new_values_r[] = $values_r[$i];
                    }
                }
                $values_r = $new_values_r;
            }
            //if($results)
            // now reassign back.
            $site_item_attributes_r[strtolower($s_attribute_type)] = $values_r;
        } else {
            // the next process prefers arrays to deal with, even if single element
            $site_item_attributes_r[strtolower($s_attribute_type)] = $value;
        }
    }
    //
    // now that we have expanded mappings, we need to map to s_item_attribute_type order number mappings
    //
    $new_attributes_r = $site_item_attributes_r;
    $site_item_attributes_r = NULL;
    // now we want to expand the $new_attributes_r, so we have a set of
    // variables that include the order_no $fieldname type format.
    $results = fetch_item_attribute_type_rs($s_item_type, NULL, 's_attribute_type');
    if ($results) {
        // this will be set if array encountered, but not lookup value.
        $processing_s_attribute_type = FALSE;
        while ($attribute_type_r = db_fetch_assoc($results)) {
            $variable = strtolower($attribute_type_r['s_attribute_type']);
            if (isset($new_attributes_r[$variable])) {
                $fieldname = get_field_name($attribute_type_r['s_attribute_type'], $attribute_type_r['order_no']);
                if (is_not_empty_array($new_attributes_r[$variable])) {
                    // TODO: Consider adding values not found in the lookup table to the s_attribute_type_lookup.
                    if (is_lookup_attribute_type($attribute_type_r['s_attribute_type'])) {
                        $lookup_attribute_val_restrict_ind = $lookup_attribute_val_restrict_ind_r[strtolower($attribute_type_r['s_attribute_type'])];
                        // here is where we want some sanity checking of the options
                        $value_r = $new_attributes_r[$variable];
                        $lookup_value_r = array();
                        for ($i = 0; $i < count($value_r); $i++) {
                            $raw_value = trim($value_r[$i]);
                            if (strlen($raw_value) > 0) {
                                $value = fetch_attribute_type_lookup_value($attribute_type_r['s_attribute_type'], $raw_value);
                                if ($value !== FALSE) {
                                    $lookup_value_r[] = $value;
                                } else {
                                    if ($lookup_attribute_val_restrict_ind != 'Y') {
                                        // do not include if restricted to lookup values
                                        $lookup_value_r[] = $raw_value;
                                    }
                                }
                            }
                        }
                        $site_item_attributes_r[$fieldname] = array_unique($lookup_value_r);
                    } else {
                        // This indicates we have a repeated s_attribute_type, and so should act appropriately.
                        if ($processing_s_attribute_type != NULL && $attribute_type_r['s_attribute_type'] == $processing_s_attribute_type) {
                            $site_item_attributes_r[$fieldname] = $new_attributes_r[$variable][0];
                            // remove it
                            array_splice($new_attributes_r[$variable], 0, 1);
                        } else {
                            if (count($new_attributes_r[$variable]) > 1) {
                                // this is the first occurence of the s_attribute_type, so lets see if its repeated at least once.
                                if (is_numeric(fetch_s_item_attribute_type_next_order_no($s_item_type, $attribute_type_r['s_attribute_type'], $attribute_type_r['order_no']))) {
                                    $site_item_attributes_r[$fieldname] = $new_attributes_r[$variable][0];
                                    // remove it
                                    array_splice($new_attributes_r[$variable], 0, 1);
                                    $processing_s_attribute_type = $attribute_type_r['s_attribute_type'];
                                } else {
                                    // otherwise just copy the whole thing.
                                    $site_item_attributes_r[$fieldname] = $new_attributes_r[$variable];
                                    unset($new_attributes_r[$variable]);
                                }
                            } else {
                                $site_item_attributes_r[$fieldname] = $new_attributes_r[$variable][0];
                                unset($new_attributes_r[$variable]);
                            }
                        }
                    }
                } else {
                    if (!is_array($new_attributes_r[$variable])) {
                        $site_item_attributes_r[$fieldname] = $new_attributes_r[$variable];
                        unset($new_attributes_r[$variable]);
                    }
                }
            } else {
                if ($attribute_type_r['s_field_type'] == 'TITLE' && isset($new_attributes_r['title'])) {
                    // in case developer forgot to setup title mapping.
                    $fieldname = get_field_name($attribute_type_r['s_attribute_type'], $attribute_type_r['order_no']);
                    $site_item_attributes_r[$fieldname] = $new_attributes_r['title'];
                }
            }
        }
        //while
        db_free_result($results);
    }
    return $site_item_attributes_r;
}
예제 #9
0
function is_exists_borrowed_item($status = NULL)
{
    $query = "SELECT 'X' FROM borrowed_item ";
    if (is_array($status)) {
        $query .= "WHERE status IN(" . format_sql_in_clause($status) . ") ";
    } else {
        if ($status !== NULL) {
            $query .= "WHERE status = '" . $status . "' ";
        }
    }
    $query .= "LIMIT 0,1";
    $result = db_query($query);
    if ($result && db_num_rows($result) > 0) {
        db_free_result($result);
        return TRUE;
    } else {
        return FALSE;
    }
}
예제 #10
0
function fetch_value_match_attribute_type_lookup_rs($s_attribute_type, $value_array, $order_by = 'value', $order = 'asc')
{
    $query = "SELECT satl.value, IF(LENGTH(IFNULL(stlv.value, display))>0,IFNULL(stlv.value, display),satl.value) AS display, img, checked_ind " . "FROM s_attribute_type_lookup satl\n\t\t\tLEFT JOIN s_table_language_var stlv\n\t\t\tON stlv.language = '" . get_opendb_site_language() . "' AND\n\t\t\tstlv.tablename = 's_attribute_type_lookup' AND\n\t\t\tstlv.columnname = 'display' AND\n\t\t\tstlv.key1 = s_attribute_type AND\n\t\t\tstlv.key2 = satl.value \n\t\t\tWHERE satl.s_attribute_type = '" . $s_attribute_type . "' AND satl.value IN (" . format_sql_in_clause($value_array) . ") " . "ORDER BY satl.order_no, {$order_by} {$order}";
    $result = db_query($query);
    if ($result && db_num_rows($result) > 0) {
        return $result;
    } else {
        return FALSE;
    }
}