function get_user_collections($user, $find = "", $order_by = "name", $sort = "ASC", $fetchrows = -1, $auto_create = true)
 {
     global $usergroup;
     # Returns a list of user collections.
     $sql = "";
     $keysql = "";
     $extrasql = "";
     if ($find == "!shared") {
         # only return shared collections
         $sql = " where (public='1' or c.ref in (select distinct collection from user_collection where user<>'{$user}' union select distinct collection from external_access_keys))";
     } elseif (strlen($find) == 1 && !is_numeric($find)) {
         # A-Z search
         $sql = " where c.name like '{$find}%'";
     } elseif (strlen($find) > 1 || is_numeric($find)) {
         $keywords = split_keywords($find);
         $keyrefs = array();
         $keysql = "";
         for ($n = 0; $n < count($keywords); $n++) {
             $keyref = resolve_keyword($keywords[$n], false);
             if ($keyref !== false) {
                 $keyrefs[] = $keyref;
             }
             $keysql .= " join collection_keyword k" . $n . " on k" . $n . ".collection=ref and (k" . $n . ".keyword='{$keyref}')";
             //$keysql="or keyword in (" . join (",",$keyrefs) . ")";
         }
         //$sql.="and (c.name rlike '$search' or u.username rlike '$search' or u.fullname rlike '$search' $spcr )";
     }
     # Include themes in my collecions?
     # Only filter out themes if $themes_in_my_collections is set to false in config.php
     global $themes_in_my_collections;
     if (!$themes_in_my_collections) {
         if ($sql == "") {
             $sql = " where ";
         } else {
             $sql .= " and ";
         }
         $sql .= " (length(c.theme)=0 or c.theme is null) ";
     }
     global $anonymous_login, $username, $anonymous_user_session_collection;
     if (isset($anonymous_login) && $username == $anonymous_login && $anonymous_user_session_collection) {
         // Anonymous user - only get the user's own collections that are for this session - although we can still join to get collections that have been specifically shared with the anonymous user
         if ($sql == "") {
             $extrasql = " where ";
         } else {
             $extrasql .= " and ";
         }
         $rs_session = get_rs_session_id(true);
         $extrasql .= " (c.session_id='" . $rs_session . "')";
     }
     $order_sort = "";
     if ($order_by != "name") {
         $order_sort = " order by {$order_by} {$sort}";
     }
     $return = "select * from (select c.*,u.username,u.fullname,count(r.resource) count from user u join collection c on u.ref=c.user and c.user='******' left outer join collection_resource r on c.ref=r.collection {$sql} {$extrasql} group by c.ref\n\tunion\n\tselect c.*,u.username,u.fullname,count(r.resource) count from user_collection uc join collection c on uc.collection=c.ref and uc.user='******' and c.user<>'{$user}' left outer join collection_resource r on c.ref=r.collection left join user u on c.user=u.ref {$sql} group by c.ref\n\tunion\n\tselect c.*,u.username,u.fullname,count(r.resource) count from usergroup_collection gc join collection c on gc.collection=c.ref and gc.usergroup='{$usergroup}' and c.user<>'{$user}' left outer join collection_resource r on c.ref=r.collection left join user u on c.user=u.ref {$sql} group by c.ref) clist {$keysql} group by ref {$order_sort}";
     $return = sql_query($return);
     if ($order_by == "name") {
         if ($sort == "ASC") {
             usort($return, 'collections_comparator');
         } else {
             if ($sort == "DESC") {
                 usort($return, 'collections_comparator_desc');
             }
         }
     }
     // To keep My Collection creation consistent: Check that user has at least one collection of his/her own  (not if collection result is empty, which may include shares),
     $hasown = false;
     for ($n = 0; $n < count($return); $n++) {
         if ($return[$n]['user'] == $user) {
             $hasown = true;
         }
     }
     if (!$hasown && $auto_create && $find == "") {
         # No collections of one's own? The user must have at least one My Collection
         global $usercollection;
         $name = get_mycollection_name($user);
         $usercollection = create_collection($user, $name, 0, 1);
         // make not deletable
         set_user_collection($user, $usercollection);
         # Recurse to send the updated collection list.
         return get_user_collections($user, $find, $order_by, $sort, $fetchrows, false);
     }
     return $return;
 }
                $deleted_usercoll = true;
            }
        }
    }
    # Get count of collections
    $c = get_user_collections($userref);
    # If the user has just deleted the collection they were using, select a new collection
    if ($deleted_usercoll && count($c) > 0) {
        # Select the first collection in the dropdown box.
        $usercollection = $c[0]["ref"];
        set_user_collection($userref, $usercollection);
    }
    # User has deleted their last collection? add a new one.
    if (count($c) == 0) {
        # No collections to select. Create them a new collection.
        $name = get_mycollection_name($userref);
        $usercollection = create_collection($userref, $name);
        set_user_collection($userref, $usercollection);
    }
    refresh_collection_frame($usercollection);
}
hook('customcollectionmanage');
$removeall = getvalescaped("removeall", "");
if ($removeall != "") {
    remove_all_resources_from_collection($removeall);
    refresh_collection_frame($usercollection);
}
include "../include/header.php";
?>
  <div class="BasicsBox">
    <h2>&nbsp;</h2>
예제 #3
0
function get_user_collections($user,$find="",$order_by="name",$sort="ASC",$fetchrows=-1,$auto_create=true)
	{
	# Returns a list of user collections.
	$sql="";
	$keysql="";
	if (strlen($find)==1 && !is_numeric($find))
		{
		# A-Z search
		$sql=" where c.name like '$find%'";
		}
	elseif (strlen($find)>1 || is_numeric($find))
		{  
		$keywords=split_keywords($find);
		$keyrefs=array();
		$keysql="";
		for ($n=0;$n<count($keywords);$n++)
			{
			$keyref=resolve_keyword($keywords[$n],false);
			if ($keyref!==false) {$keyrefs[]=$keyref;}

			$keysql.=" join collection_keyword k" . $n . " on k" . $n . ".collection=ref and (k" . $n . ".keyword='$keyref')";	
			//$keysql="or keyword in (" . join (",",$keyrefs) . ")";
			}

 
		//$sql.="and (c.name rlike '$search' or u.username rlike '$search' or u.fullname rlike '$search' $spcr )";
		}
    
    # Include themes in my collecions? 
    # Only filter out themes if $themes_in_my_collections is set to false in config.php
   	global $themes_in_my_collections;
   	if (!$themes_in_my_collections)
   		{
		if ($sql==""){$sql=" where ";} else {$sql.=" and ";}	
   		$sql.=" (length(c.theme)=0 or c.theme is null) ";
   		}
   
	$order_sort="";
	if ($order_by!="name"){$order_sort=" order by $order_by $sort";}
   
	$return="select * from (select c.*,u.username,u.fullname,count(r.resource) count from user u join collection c on u.ref=c.user and c.user='******' left outer join collection_resource r on c.ref=r.collection $sql group by c.ref
	union
	select c.*,u.username,u.fullname,count(r.resource) count from user_collection uc join collection c on uc.collection=c.ref and uc.user='******' and c.user<>'$user' left outer join collection_resource r on c.ref=r.collection left join user u on c.user=u.ref $sql group by c.ref) clist $keysql $order_sort";

	$return=sql_query($return);
	
	if ($order_by=="name"){
		if ($sort=="ASC"){usort($return, 'collections_comparator');}
		else if ($sort=="DESC"){usort($return,'collections_comparator_desc');}
	}
	
	// To keep My Collection creation consistent: Check that user has at least one collection of his/her own  (not if collection result is empty, which may include shares), 
	$hasown=false;
	for ($n=0;$n<count($return);$n++){
		if ($return[$n]['user']==$user){
			$hasown=true;
		}
	}
	if ($find!=""){$hasown=true;} // if doing a search in collections, assume My Collection already exists (to avoid creating new collections due to an empty search result).

	if (!$hasown && $auto_create)
		{
		# No collections of one's own? The user must have at least one My Collection
		global $usercollection;
		$name=get_mycollection_name($user);
		$usercollection=create_collection ($user,$name,0,1); // make not deletable
		set_user_collection($user,$usercollection);
		
		# Recurse to send the updated collection list.
		return get_user_collections($user,$find,$order_by,$sort,$fetchrows,false);
		}

	return $return;
	}