示例#1
0
function HookFlickr_theme_publishThemesRender_actions_add_collection_option($top_actions, $options)
{
    global $getthemes, $m, $lang, $baseurl_short;
    $theme = $getthemes[$m];
    // these aren't really set on themes.php
    $result = get_collection_resources($theme['ref']);
    $count_result = count($result);
    $c = count($options);
    if ($count_result > 0) {
        $lang_string = $lang["publish_to_flickr"];
        $unpublished = sql_value("select count(*) value from resource join collection_resource on resource.ref=collection_resource.resource where collection_resource.collection='" . $theme["ref"] . "' and flickr_photo_id is null", 0);
        if ($unpublished > 0) {
            $lang_string .= " <strong>(" . ($unpublished == 1 ? $lang["unpublished-1"] : str_replace("%number", $unpublished, $lang["unpublished-2"])) . ")</strong>";
        }
        $data_attribute['url'] = sprintf('%splugins/flickr_theme_publish/pages/sync.php?theme=%s', $baseurl_short, urlencode($theme["ref"]));
        $options[$c]['value'] = 'flickr_publish';
        $options[$c]['label'] = $lang_string;
        $options[$c]['data_attr'] = $data_attribute;
        return $options;
    }
}
示例#2
0
function check_access_key_collection($collection, $key)
{
    if ($collection == "" || !is_numeric($collection)) {
        return false;
    }
    $r = get_collection_resources($collection);
    if (count($r) == 0) {
        return false;
    }
    for ($n = 0; $n < count($r); $n++) {
        # Verify a supplied external access key for all resources in a collection
        if (!check_access_key($r[$n], $key)) {
            return false;
        }
    }
    # Set the 'last used' date for this key
    sql_query("update external_access_keys set lastused=now() where collection='{$collection}' and access_key='{$key}'");
    return true;
}
function relate_to_collection($ref, $collection)
{
    # Relates every resource in $collection to $ref
    $colresources = get_collection_resources($collection);
    sql_query("delete from resource_related where resource='{$ref}' and related in ('" . join("','", $colresources) . "')");
    sql_query("insert into resource_related(resource,related) values ({$ref}," . join("),(" . $ref . ",", $colresources) . ")");
}
else
	{
	foreach($collectionstoshare as $collection)
		{			
		$ref=$collection["ref"];		
	
		# Get min access to this collection
		$minaccess=collection_min_access($ref);
		
		if ($minaccess>=1 && !$restricted_share) # Minimum access is restricted or lower and sharing of restricted resources is not allowed. The user cannot share this collection.
			{
			$show_error=true;
			$error = str_replace("%collectionname%", i18n_get_collection_name($collection), $lang["collection-name"]) . "\n" . $lang["restrictedsharecollection"];
			}
			
		if (count(get_collection_resources($ref))==0) # Sharing an empty collection?
			{
			$show_error=true;
			$error = str_replace("%collectionname%", i18n_get_collection_name($collection), $lang["collection-name"]) . "\n" . $lang["cannotshareemptycollection"];
			}
		
		}
	
	$access=getvalescaped("access","");
	$expires=getvalescaped("expires","");
		
	if (getvalescaped("generateurl","")=="")
		{ ?>
									
			<div class="VerticalNav">
示例#5
0
function save_request($request)
	{
	# Use the posted form to update the request
	global $applicationname,$baseurl,$lang,$request_senduserupdates;
		
	$status=getvalescaped("status","",true);
	$expires=getvalescaped("expires","");
	$currentrequest=get_request($request);
	$oldstatus=$currentrequest["status"];
	$assigned_to=getvalescaped("assigned_to","");
	$reason=getvalescaped("reason","");
	$reasonapproved=getvalescaped("reasonapproved","");
	
	
	# --------------------- User Assignment ------------------------
	# Has the assigned_to value changed?
	if ($currentrequest["assigned_to"]!=$assigned_to && checkperm("Ra"))
		{
		if ($assigned_to==0)
			{
			# Cancel assignment
			sql_query("update request set assigned_to=null where ref='$request'");
			}
		else
			{
			# Update and notify user
			sql_query("update request set assigned_to='$assigned_to' where ref='$request'");

			$message=$lang["requestassignedtoyoumail"] . "\n\n$baseurl/?q=" . $request . "\n";
			$assigned_to_user=get_user($assigned_to);
			send_mail($assigned_to_user["email"],$applicationname . ": " . $lang["requestassignedtoyou"],$message);
			$userconfirmmessage=str_replace("%",$assigned_to_user["fullname"] . " (" . $assigned_to_user["email"] . ")" ,$lang["requestassignedtouser"]);
			if ($request_senduserupdates){send_mail($currentrequest["email"],$applicationname . ": " . $lang["requestupdated"] . " - $request",$userconfirmmessage);}
			}
		}
	
	
	# Has either the status or the expiry date changed?
	if (($oldstatus!=$status || $expires!=$currentrequest["expires"]) && $status==1)
		{
		# --------------- APPROVED -------------
		# Send approval e-mail
		$message=$lang["requestapprovedmail"] . "\n\n" . $lang["approvalreason"]. ": " . $reasonapproved . "\n\n" ;
		$message.="$baseurl/?c=" . $currentrequest["collection"] . "\n";
		if ($expires!="")
			{
			# Add expiry time to message.
			$message.=$lang["requestapprovedexpires"] . " " . nicedate($expires) . "\n\n";
			}
		$reasonapproved=str_replace(array("\\r","\\n"),"\n",$reasonapproved);$reasonapproved=str_replace("\n\n","\n",$reasonapproved); # Fix line breaks.
		send_mail($currentrequest["email"],$applicationname . ": " . $lang["requestcollection"] . " - " . $lang["resourcerequeststatus1"],$message);
		
		# Mark resources as full access for this user
		foreach (get_collection_resources($currentrequest["collection"]) as $resource)
			{
			open_access_to_user($currentrequest["user"],$resource,$expires);
			}
		}

	if ($oldstatus!=$status && $status==2)	
		{
		# --------------- DECLINED -------------
		# Send declined e-mail

		$reason=str_replace(array("\\r","\\n"),"\n",$reason);$reason=str_replace("\n\n","\n",$reason); # Fix line breaks.
		$message=$lang["requestdeclinedmail"] . "\n\n" . $lang["declinereason"] . ": ". $reason . "\n\n$baseurl/?c=" . $currentrequest["collection"] . "\n";
		send_mail($currentrequest["email"],$applicationname . ": " . $lang["requestcollection"] . " - " . $lang["resourcerequeststatus2"],$message);

		# Remove access that my have been granted by an inadvertant 'approved' command.
		foreach (get_collection_resources($currentrequest["collection"]) as $resource)
			{
			remove_access_to_user($currentrequest["user"],$resource);
			}

		}

	if ($oldstatus!=$status && $status==0)
		{
		# --------------- PENDING -------------
		# Moved back to pending. Delete any permissions set by a previous 'approve'.
		foreach (get_collection_resources($currentrequest["collection"]) as $resource)
			{
			remove_access_to_user($currentrequest["user"],$resource);
			}
		}

	# Save status
	sql_query("update request set status='$status',expires=" . ($expires==""?"null":"'$expires'") . ",reason='$reason',reasonapproved='$reasonapproved' where ref='$request'");

	if (getval("delete","")!="")
		{
		# Delete the request - this is done AFTER any e-mails have been sent out so this can be used on approval.
		sql_query("delete from request where ref='$request'");
		return true;		
		}

	}
示例#6
0
function save_resource_data_multi($collection)
	{
	# Save all submitted data for collection $collection, this is for the 'edit multiple resources' feature
	# Loop through the field data and save (if necessary)
	$list=get_collection_resources($collection);

	$tmp = hook("altercollist", "", array("save_resource_data_multi", $list)); if(is_array($tmp)) { if(count($tmp)>0) $list = $tmp; else return true; } // alter the collection list to spare some when saving multiple, if you need

	$ref=$list[0];
	$fields=get_resource_field_data($ref,true);
	global $auto_order_checkbox;
	$expiry_field_edited=false;

	for ($n=0;$n<count($fields);$n++)
		{
		if (getval("editthis_field_" . $fields[$n]["ref"],"")!="" || hook("save_resource_data_multi_field_decision","",array($fields[$n]["ref"])))
			{
			if ($fields[$n]["type"]==2)
				{
				# construct the value from the ticked boxes
				$val=","; # Note: it seems wrong to start with a comma, but this ensures it is treated as a comma separated list by split_keywords(), so if just one item is selected it still does individual word adding, so 'South Asia' is split to 'South Asia','South','Asia'.
				$options=trim_array(explode(",",$fields[$n]["options"]));
				if ($auto_order_checkbox) {sort($options);}
				
				for ($m=0;$m<count($options);$m++)
					{
					$name=$fields[$n]["ref"] . "_" . md5($options[$m]);
					if (getval($name,"")=="yes")
						{
						if ($val!=",") {$val.=",";}
						$val.=$options[$m];
						}
					}
				}
			elseif ($fields[$n]["type"]==4 || $fields[$n]["type"]==6 || $fields[$n]["type"]==10)
				{
				# date/expiry date type, construct the value from the date dropdowns
				$val=sprintf("%04d", getvalescaped("field_" . $fields[$n]["ref"] . "-y",""));
				if ((int)$val<=0) 
					{
					$val="";
					}
				elseif (($field=getvalescaped("field_" . $fields[$n]["ref"] . "-m",""))!="") 
					{
					$val.="-" . $field;
					if (($field=getvalescaped("field_" . $fields[$n]["ref"] . "-d",""))!="") 
						{
						$val.="-" . $field;
						if (($field=getval("field_" . $fields[$n]["ref"] . "-h",""))!="")
							{
							$val.=" " . $field . ":";
							if (($field=getvalescaped("field_" . $fields[$n]["ref"] . "-i",""))!="") 
								{
									$val.=$field;
								} 
							else 
								{
									$val.="00";
								}
							}
						}
					}
				}
			elseif ($fields[$n]["type"] == 3)
				{
				$val=getvalescaped("field_" . $fields[$n]["ref"],"");				
				// if it doesn't already start with a comma, add one
				if (substr($val,0,1) != ',')
					{
					$val = ','.$val;
					}
				}
			else
				{
				$val=getvalescaped("field_" . $fields[$n]["ref"],"");
				}
			$origval=$val;
			# Loop through all the resources and save.
			for ($m=0;$m<count($list);$m++)
				{
				$ref=$list[$m];
				$resource_sql="";

				# Work out existing field value.
				$existing=escape_check(sql_value("select value from resource_data where resource='$ref' and resource_type_field='" . $fields[$n]["ref"] . "'",""));
				
				# Find and replace mode? Perform the find and replace.
				if (getval("modeselect_" . $fields[$n]["ref"],"")=="FR")
					{
					$val=str_replace
						(
						getvalescaped("find_" . $fields[$n]["ref"],""),
						getvalescaped("replace_" . $fields[$n]["ref"],""),
						$existing
						);
					}
				
				# Append text/option(s) mode?
				if (getval("modeselect_" . $fields[$n]["ref"],"")=="AP")
					{
					if ($fields[$n]["type"]!=2 && $fields[$n]["type"]!=3)
						{
						# Automatically append a space when appending text types.
						$val=$existing . " " . $origval;
						}
					else
						{
						# Checkbox/dropdown types can just append immediately (a comma will already be present at the beginning of $origval).
						$val=$existing . $origval;
						}
					}
					
				# Prepend text/option(s) mode?
				if (getval("modeselect_" . $fields[$n]["ref"],"")=="PP"){
					global $filename_field;
					if ($fields[$n]["ref"]==$filename_field){
						$val=rtrim($origval,"_")."_".trim($existing); // use an underscore if editing filename.
					}
					else {
						# Automatically append a space when appending text types.
						$val=$origval . " " . $existing;
					}
				}
					
				# Remove text/option(s) mode?
				if (getval("modeselect_" . $fields[$n]["ref"],"")=="RM")
					{
					$val=str_replace($origval,"",$existing);
					}
					
				$val=strip_leading_comma($val);		
				#echo "<li>existing=$existing, new=$val";
				if ($existing!=str_replace("\\","",$val))
					{
					# This value is different from the value we have on record.
					
					# Write this edit to the log.
					resource_log($ref,'m',$fields[$n]["ref"],"",$existing,$val);
		
					# Expiry field? Set that expiry date(s) have changed so the expiry notification flag will be reset later in this function.
					if ($fields[$n]["type"]==6) {$expiry_field_edited=true;}
				
					# If this is a 'joined' field we need to add it to the resource column
					$joins=get_resource_table_joins();
					if (in_array($fields[$n]["ref"],$joins)){
						sql_query("update resource set field".$fields[$n]["ref"]."='".escape_check($val)."' where ref='$ref'");
					}		
						
					# Purge existing data and keyword mappings, decrease keyword hitcounts.
					sql_query("delete from resource_data where resource='$ref' and resource_type_field='" . $fields[$n]["ref"] . "'");
					
					# Insert new data and keyword mappings, increase keyword hitcounts.
					sql_query("insert into resource_data(resource,resource_type_field,value) values('$ref','" . $fields[$n]["ref"] . "','" . escape_check($val) . "')");
		
					$oldval=$existing;
					$newval=$val;
					
					if ($fields[$n]["type"]==3)
						{
						# Prepend a comma when indexing dropdowns
						$newval="," . $val;
						$oldval="," . $oldval;
						}
					
					if ($fields[$n]["keywords_index"]==1)
						{
						# Date field? These need indexing differently.
						$is_date=($fields[$n]["type"]==4 || $fields[$n]["type"]==6); 
						remove_keyword_mappings($ref,i18n_get_indexable($oldval),$fields[$n]["ref"],$fields[$n]["partial_index"],$is_date);
						add_keyword_mappings($ref,i18n_get_indexable($newval),$fields[$n]["ref"],$fields[$n]["partial_index"],$is_date);
						}
					}
				}
			}
		}
		
	# Also save related resources field
	if (getval("editthis_related","")!="")
		{
		$related=explode(",",getvalescaped("related",""));
		# Make sure all submitted values are numeric
		$ok=array();for ($n=0;$n<count($related);$n++) {if (is_numeric(trim($related[$n]))) {$ok[]=trim($related[$n]);}}

		for ($m=0;$m<count($list);$m++)
			{
			$ref=$list[$m];
			sql_query("delete from resource_related where resource='$ref' or related='$ref'"); # remove existing related items
			if (count($ok)>0) {sql_query("insert into resource_related(resource,related) values ($ref," . join("),(" . $ref . ",",$ok) . ")");}
			}
		}

	# Also update archive status
	if (getval("editthis_status","")!="")
		{
		$notifyrefs=array();
		for ($m=0;$m<count($list);$m++)
			{
			$ref=$list[$m];
			$archive=getvalescaped("archive",0);
			$oldarchive=sql_value("select archive value from resource where ref='$ref'",0);
			
			if ($oldarchive!=$archive)
				{
				sql_query("update resource set archive='" . $archive . "' where ref='$ref'");

				# Log
				resource_log($ref,"s",0,"",$oldarchive,$archive);

				if ($oldarchive==-2 && $archive==-1)
					{
					# Notify the admin users of this change.
					$notifyrefs[]=$ref;
					}
				}
			}
		if (count($notifyrefs)>0)
			{
			# Notify the admin users of any submitted resources.
			notify_user_contributed_submitted($notifyrefs);
			}
		}
	
	# Expiry field(s) edited? Reset the notification flag so that warnings are sent again when the date is reached.
	if ($expiry_field_edited)
		{
		if (count($list)>0)
			{
			sql_query("update resource set expiry_notification_sent=0 where ref in (" . join(",",$list) . ")");
			}
		}
	
	# Also update access level
	if (getval("editthis_access","")!="")
		{
		for ($m=0;$m<count($list);$m++)
			{
			$ref=$list[$m];
			$access=getvalescaped("access",0);
			$oldaccess=sql_value("select access value from resource where ref='$ref'","");
			
			if ($access!=$oldaccess)
				{
				sql_query("update resource set access='$access' where ref='$ref'");
				
				resource_log($ref,"a",0,"",$oldaccess,$access);
				}
			
			# For access level 3 (custom) - also save custom permissions
			if ($access==3) {save_resource_custom_access($ref);}
			}
		}
	
	# Update resource type?
	if (getval("editresourcetype","")!="")
		{
		for ($m=0;$m<count($list);$m++)
			{
			$ref=$list[$m];
			update_resource_type($ref,getvalescaped("resource_type",""));
			}
		}
		
	# Update location?
	if (getval("editlocation","")!="")
		{
		$location=explode(",",getvalescaped("location",""));
		if (count($list)>0) 
			{
			if (count($location)==2)
				{
				$geo_lat=(float)$location[0];
				$geo_long=(float)$location[1];
				sql_query("update resource set geo_lat=$geo_lat,geo_long=$geo_long where ref in (" . join(",",$list) . ")");
				}
			elseif (getvalescaped("location","")=="")
				{
				sql_query("update resource set geo_lat=null,geo_long=null where ref in (" . join(",",$list) . ")");
				}
			}
		}

	# Update mapzoom?
	if (getval("editmapzoom","")!="")
		{
		$mapzoom=getvalescaped("mapzoom","");
		if (count($list)>0)
			{
			if ($mapzoom!="")
				{
				sql_query("update resource set mapzoom=$mapzoom where ref in (" . join(",",$list) . ")");
				}
			else
				{
				sql_query("update resource set mapzoom=null where ref in (" . join(",",$list) . ")");
				}
			}
		}

	hook("saveextraresourcedata","",array($list));
		
	# Update XML metadata dump file for all edited resources.
	for ($m=0;$m<count($list);$m++)
		{
		update_xml_metadump($list[$m]);
		}
	
	hook("aftersaveresourcedata");	
	}
示例#7
0
			alert("<?php 
            echo $lang["resourcenotinresults"];
            ?>
");
			</script>
			<?php 
        }
    }
}
$collection = getvalescaped("collection", "", true);
if ($collection != "") {
    # If editing multiple items, use the first resource as the template
    $multiple = true;
    $edit_autosave = false;
    # Do not allow auto saving for batch editing.
    $items = get_collection_resources($collection);
    if (count($items) == 0) {
        $error = $lang['error-cannoteditemptycollection'];
        error_alert($error);
        exit;
    }
    # check editability
    if (!allow_multi_edit($collection)) {
        $error = $lang['error-permissiondenied'];
        error_alert($error);
        exit;
    }
    $ref = $items[0];
} else {
    $multiple = false;
}
# if bypass sharing page option is on, redirect to e-mail
if ($bypass_share_screen) {
    header('Location:collection_email.php?ref=' . $ref);
}
$collection = get_collection($ref);
# Process deletion of access keys
if (getval("deleteaccess", "") != "") {
    delete_collection_access_key($ref, getvalescaped("deleteaccess", ""));
}
# Get min access to this collection
$minaccess = collection_min_access($ref);
if ($minaccess >= 1 && !$restricted_share) {
    $show_error = true;
    $error = $lang["restrictedsharecollection"];
}
if (!$collection_allow_empty_share && count(get_collection_resources($ref)) == 0) {
    $show_error = true;
    $error = $lang["cannotshareemptycollection"];
}
include "../include/header.php";
?>


<div class="BasicsBox"> 
<form method=post id="collectionform" action="collection_share.php">
<input type="hidden" name="ref" id="ref" value="<?php 
echo $ref;
?>
">
<input type="hidden" name="deleteaccess" id="deleteaccess" value="">
<input type="hidden" name="generateurl" id="generateurl" value="">
示例#9
0
// clear cookie for new search
# Most sorts such as popularity, date, and ID should be descending by default,
# but it seems custom display fields like title or country should be the opposite.
$default_sort = "DESC";
if (substr($order_by, 0, 5) == "field") {
    $default_sort = "ASC";
}
$sort = getvalescaped("sort", $default_sort);
setcookie("saved_sort", $sort);
$revsort = $sort == "ASC" ? "DESC" : "ASC";
## If displaying a collection
# Enable/disable the reordering feature. Just for collections for now.
$allow_reorder = false;
# get current collection resources to pre-fill checkboxes
if ($use_checkboxes_for_selection) {
    $collectionresources = get_collection_resources($usercollection);
}
$hiddenfields = getvalescaped("hiddenfields", "");
# fetch resource types from query string and generate a resource types cookie
if (getvalescaped("resetrestypes", "") == "") {
    $restypes = getvalescaped("restypes", "");
} else {
    $restypes = "";
    reset($_POST);
    reset($_GET);
    foreach (array_merge($_GET, $_POST) as $key => $value) {
        $hiddenfields = array();
        //$hiddenfields=explode(",",$hiddenfields);
        if ($key == "rttickall" && $value == "on") {
            $restypes = "";
            break;
示例#10
0
    $topurl = "pages/" . $default_home_page;
    if ($use_theme_as_home) {
        $topurl = "pages/themes.php";
    }
    if ($use_recent_as_home) {
        $topurl = "pages/search.php?search=" . urlencode("!last" . $recent_search_quantity);
    }
}
/* end hook replacetopurl */
if (getval("c", "") != "") {
    # quick redirect to a collection (from e-mails, keep the URL nice and short)
    $c = getvalescaped("c", "");
    $topurl = "pages/search.php?search=" . urlencode("!collection" . $c) . "&k=" . $k;
    if ($k != "") {
        # External access user... set top URL to first resource
        $r = get_collection_resources($c);
        if (count($r) > 0) {
            # Fetch collection data
            $cinfo = get_collection($c);
            if ($cinfo === false) {
                exit("Collection not found.");
            }
            if ($feedback_resource_select && $cinfo["request_feedback"]) {
                $topurl = "pages/collection_feedback.php?collection=" . $c . "&k=" . $k;
            } else {
                $topurl = "pages/search.php?search=" . urlencode("!collection" . $c) . "&k=" . $k;
            }
        }
    }
}
if (getval("r", "") != "") {
        ?>
/pages/tools/update_previews.php?ref=<?php 
        echo $ref + 1;
        ?>
&previewbased=<?php 
        echo $previewbased;
        ?>
"/>
    	<?php 
    } else {
        ?>
    	Done.	
    	<?php 
    }
} else {
    $collection = get_collection_resources($collectionid);
    if (!is_array($collection)) {
        echo "Collection id returned no resources.";
        die;
    }
    if (!(is_numeric($ref) && $ref > 0)) {
        $ref = $collection[0];
        $key = 0;
    } else {
        $key = array_search($ref, $collection);
    }
    if (update_preview($ref)) {
        ?>
        <img src="<?php 
        echo get_resource_path($ref, false, "pre", false);
        ?>
function managed_collection_request($ref, $details, $ref_is_resource = false)
{
    # Request mode 1
    # Managed via the administrative interface
    # An e-mail is still sent.
    global $applicationname, $email_from, $baseurl, $email_notify, $username, $useremail, $userref, $lang, $request_senduserupdates, $watermark, $filename_field, $view_title_field, $access, $resource_type_request_emails, $manage_request_admin;
    # Has a resource reference (instead of a collection reference) been passed?
    # Manage requests only work with collections. Create a collection containing only this resource.
    if ($ref_is_resource) {
        $admin_mail_template = "emailresourcerequest";
        $user_mail_template = "emailuserresourcerequest";
        $resourcedata = get_resource_data($ref);
        $templatevars['thumbnail'] = get_resource_path($ref, true, "thm", false, "jpg", $scramble = -1, $page = 1, $watermark ? $access == 1 ? true : false : false);
        # Allow alternative configuration settings for this resource type
        resource_type_config_override($resourcedata['resource_type']);
        if (!file_exists($templatevars['thumbnail'])) {
            $templatevars['thumbnail'] = "../gfx/" . get_nopreview_icon($resourcedata["resource_type"], $resourcedata["file_extension"], false);
        }
        $templatevars['url'] = $baseurl . "/?r=" . $ref;
        if (isset($filename_field)) {
            $templatevars["filename"] = $lang["fieldtitle-original_filename"] . ": " . get_data_by_field($ref, $filename_field);
        }
        if (isset($resourcedata["field" . $view_title_field])) {
            $templatevars["title"] = $resourcedata["field" . $view_title_field];
        }
        $c = create_collection($userref, $lang["request"] . " " . date("ymdHis"));
        add_resource_to_collection($ref, $c);
        $ref = $c;
        # Proceed as normal
    } else {
        $admin_mail_template = "emailcollectionrequest";
        $user_mail_template = "emailusercollectionrequest";
        $collectiondata = get_collection($ref);
        $templatevars['url'] = $baseurl . "/?c=" . $ref;
        if (isset($collectiondata["name"])) {
            $templatevars["title"] = $collectiondata["name"];
        }
    }
    # Fomulate e-mail text
    $templatevars['username'] = $username;
    $templatevars["useremail"] = $useremail;
    $userdata = get_user($userref);
    $templatevars["fullname"] = $userdata["fullname"];
    $message = "";
    reset($_POST);
    foreach ($_POST as $key => $value) {
        if (strpos($key, "_label") !== false) {
            # Add custom field
            $setting = trim($_POST[str_replace("_label", "", $key)]);
            if ($setting != "") {
                $message .= $value . ": " . $setting . "\n\n";
            }
        }
    }
    if (trim($details) != "") {
        $message .= $lang["requestreason"] . ": " . newlines($details) . "\n\n";
    } else {
        return false;
    }
    # Add custom fields
    $c = "";
    global $custom_request_fields, $custom_request_required;
    if (isset($custom_request_fields)) {
        $custom = explode(",", $custom_request_fields);
        # Required fields?
        if (isset($custom_request_required)) {
            $required = explode(",", $custom_request_required);
        }
        for ($n = 0; $n < count($custom); $n++) {
            if (isset($required) && in_array($custom[$n], $required) && getval("custom" . $n, "") == "") {
                return false;
                # Required field was not set.
            }
            $message .= i18n_get_translated($custom[$n]) . ": " . getval("custom" . $n, "") . "\n\n";
        }
    }
    # Create the request
    global $request_query;
    $request_query = "insert into request(user,collection,created,request_mode,status,comments) values ('{$userref}','{$ref}',now(),1,0,'" . escape_check($message) . "')";
    global $notify_manage_request_admin, $assigned_to_user;
    $notify_manage_request_admin = false;
    // Manage individual requests of resources:
    hook('autoassign_individual_requests', '', array($userref, $ref, $message, isset($collectiondata)));
    if (isset($manage_request_admin) && !isset($collectiondata)) {
        $query = sprintf("\n                    SELECT DISTINCT r.resource_type AS value\n                      FROM collection_resource AS cr\n                INNER JOIN resource r ON cr.resource = r.ref\n                     WHERE cr.collection = '%s';\n            ", $ref);
        $request_resource_type = sql_value($query, 0);
        if ($request_resource_type != 0 && array_key_exists($request_resource_type, $manage_request_admin)) {
            $request_query = sprintf("\n                    INSERT INTO request(\n                                            user,\n                                            collection,\n                                            created,\n                                            request_mode,\n                                            `status`,\n                                            comments,\n                                            assigned_to\n                                       )\n                         VALUES (\n                                     '%s',\n                                     '%s',\n                                     NOW(),\n                                     1,\n                                     0,\n                                     '%s',\n                                     '%s'\n                                );\n                ", $userref, $ref, escape_check($message), $manage_request_admin[$request_resource_type]);
            $assigned_to_user = get_user($manage_request_admin[$request_resource_type]);
            $notify_manage_request_admin = true;
        }
    }
    // Manage collection requests:
    hook('autoassign_collection_requests', '', array($userref, isset($collectiondata) ? $collectiondata : array(), $message, isset($collectiondata)));
    if (isset($manage_request_admin) && isset($collectiondata)) {
        $all_r_types = get_resource_types();
        foreach ($all_r_types as $r_type) {
            $all_resource_types[] = $r_type['ref'];
        }
        $resources = get_collection_resources($collectiondata['ref']);
        // Get distinct resource types found in this collection:
        $resource_types = array();
        $collection_resources_by_type = array();
        foreach ($resources as $resource_id) {
            $resource_data = get_resource_data($resource_id);
            $resource_types[$resource_id] = $resource_data['resource_type'];
            // Create a list of resource IDs based on type to separate them into different collections:
            $collection_resources_by_type[$resource_data['resource_type']][] = $resource_id;
        }
        // Split into collections based on resource type:
        foreach ($collection_resources_by_type as $collection_type => $collection_resources) {
            // Store all resources of unmanaged type in one collection which will be sent to the system administrator:
            if (!isset($manage_request_admin[$collection_type])) {
                $collections['not_managed'] = create_collection($userref, $collectiondata['name'] . ' for unmanaged types');
                foreach ($collection_resources as $collection_resource_id) {
                    add_resource_to_collection($collection_resource_id, $collections['not_managed']);
                }
                continue;
            }
            $collections[$collection_type] = create_collection($userref, $collectiondata['name'] . ' for type ' . $collection_type);
            foreach ($collection_resources as $collection_resource_id) {
                add_resource_to_collection($collection_resource_id, $collections[$collection_type]);
            }
        }
        if (isset($collections) && count($collections) > 1) {
            foreach ($collections as $request_resource_type => $collection_id) {
                $assigned_to = '';
                $assigned_to_user['email'] = $email_notify;
                if (array_key_exists($request_resource_type, $manage_request_admin)) {
                    $assigned_to = $manage_request_admin[$request_resource_type];
                    $assigned_to_user = get_user($manage_request_admin[$request_resource_type]);
                }
                $request_query = sprintf("\n                        INSERT INTO request(\n                                                user,\n                                                collection,\n                                                created,\n                                                request_mode,\n                                                `status`,\n                                                comments,\n                                                assigned_to\n                                           )\n                             VALUES (\n                                         '%s',\n                                         '%s',\n                                         NOW(),\n                                         1,\n                                         0,\n                                         '%s',\n                                         '%s'\n                                    );\n                    ", $userref, $collection_id, escape_check($message), $assigned_to);
                if (trim($assigned_to) == '') {
                    $request_query = sprintf("\n                        INSERT INTO request(\n                                                user,\n                                                collection,\n                                                created,\n                                                request_mode,\n                                                `status`,\n                                                comments\n                                           )\n                             VALUES (\n                                         '%s',\n                                         '%s',\n                                         NOW(),\n                                         1,\n                                         0,\n                                         '%s'\n                                    );\n                    ", $userref, $collection_id, escape_check($message));
                }
                sql_query($request_query);
                $request = sql_insert_id();
                // Send the mail:
                $email_message = $lang['requestassignedtoyoumail'] . "\n\n" . $baseurl . "/?q=" . $request . "\n";
                send_mail($assigned_to_user['email'], $applicationname . ': ' . $lang['requestassignedtoyou'], $email_message);
                unset($email_message);
            }
            $notify_manage_request_admin = false;
        } else {
            $ref = implode('', $collections);
        }
    }
    if (hook('bypass_end_managed_collection_request', '', array(!isset($collectiondata), $ref, $request_query, $message, $templatevars, $assigned_to_user, $admin_mail_template, $user_mail_template))) {
        return true;
    }
    sql_query($request_query);
    $request = sql_insert_id();
    $templatevars["request_id"] = $request;
    $templatevars["requesturl"] = $baseurl . "/?q=" . $request;
    $templatevars["requestreason"] = $message;
    hook("afterrequestcreate", "", array($request));
    # Automatically notify the admin who was assigned the request:
    if (isset($manage_request_admin) && $notify_manage_request_admin) {
        $message = $lang['requestassignedtoyoumail'] . "\n\n" . $baseurl . "/?q=" . $request . "\n";
        send_mail($assigned_to_user['email'], $applicationname . ': ' . $lang['requestassignedtoyou'], $message);
    }
    # Check if alternative request email notification address is set, only valid if collection contains resources of the same type
    $admin_notify_email = $email_notify;
    if (isset($resource_type_request_emails)) {
        $requestrestypes = array_unique(sql_array("select r.resource_type as value from collection_resource cr left join resource r on cr.resource=r.ref where cr.collection='{$ref}'"));
        if (count($requestrestypes) == 1 && isset($resource_type_request_emails[$requestrestypes[0]])) {
            $admin_notify_email = $resource_type_request_emails[$requestrestypes[0]];
        }
    }
    # Send the e-mail
    $userconfirmmessage = $lang["requestsenttext"] . "<br /><br />{$message}<br /><br />" . $lang["clicktoviewresource"] . "<br />{$baseurl}/?c={$ref}";
    $message = $lang["user_made_request"] . "<br /><br />" . $lang["username"] . ": " . $username . "<br />{$message}<br /><br />";
    $message .= $lang["clicktoviewresource"] . "<br />{$baseurl}/?q={$request}";
    send_mail($admin_notify_email, $applicationname . ": " . $lang["requestcollection"] . " - {$ref}", $message, $useremail, $useremail, $admin_mail_template, $templatevars);
    if ($request_senduserupdates) {
        send_mail($useremail, $applicationname . ": " . $lang["requestsent"] . " - {$ref}", $userconfirmmessage, $email_from, $email_notify, $user_mail_template, $templatevars);
    }
    # Increment the request counter
    sql_query("update resource set request_count=request_count+1 where ref='{$ref}'");
    return true;
}
示例#13
0
function HookAutoassign_mrequestsAllAutoassign_collection_requests($user_ref, $collection_data, $message, $manage_collection_request)
{
    global $manage_request_admin, $assigned_to_user, $email_notify, $lang, $baseurl, $applicationname, $request_query, $notify_manage_request_admin;
    // Do not process this any further as this should only handle collection requests
    if (!$manage_collection_request) {
        return false;
    }
    $resources = get_collection_resources($collection_data['ref']);
    $mapped_fields = get_mapped_fields();
    $collection_resources_by_assigned_user = array();
    $collections = array();
    // Build the collections map between asigned user and resources the collection should contain
    foreach ($resources as $resource) {
        $resource_data = get_resource_field_data($resource);
        $assigned_administrator = 0;
        $resource_not_assigned = true;
        foreach ($resource_data as $r_data) {
            if (in_array($r_data['ref'], $mapped_fields)) {
                $assigned_administrator = get_mapped_user_by_field($r_data['ref'], $r_data['value']);
                if ($assigned_administrator === 0) {
                    $collection_resources_by_assigned_user['not_managed'][] = $resource;
                } else {
                    $collection_resources_by_assigned_user[$assigned_administrator][] = $resource;
                }
                $resource_not_assigned = false;
                break;
            }
        }
        if ($resource_not_assigned && !isset($manage_request_admin)) {
            $collection_resources_by_assigned_user['not_managed'][] = $resource;
        }
    }
    // Create collections based on who is supposed to handle the request
    foreach ($collection_resources_by_assigned_user as $assigned_user_id => $collection_resources) {
        if ($assigned_user_id === 'not_managed') {
            $collections['not_managed'] = create_collection($user_ref, $collection_data['name'] . ' request for unmanaged resources');
            foreach ($collection_resources as $collection_resource_id) {
                add_resource_to_collection($collection_resource_id, $collections['not_managed']);
            }
            continue;
        }
        $user = get_user($assigned_user_id);
        $collections[$assigned_user_id] = create_collection($user_ref, $collection_data['name'] . ' request - managed by ' . $user['email']);
        foreach ($collection_resources as $collection_resource_id) {
            add_resource_to_collection($collection_resource_id, $collections[$assigned_user_id]);
        }
        // Attach assigned admin to this collection
        add_collection($user['ref'], $collections[$assigned_user_id]);
    }
    if (!empty($collections)) {
        foreach ($collections as $assigned_to => $collection_id) {
            $assigned_to_user = get_user($assigned_to);
            $request_query = sprintf("\n                    INSERT INTO request(\n                                            user,\n                                            collection,\n                                            created,\n                                            request_mode,\n                                            `status`,\n                                            comments,\n                                            assigned_to\n                                       )\n                         VALUES (\n                                     '%s',  # user\n                                     '%s',  # collection\n                                     NOW(), # created\n                                     1,     # request_mode\n                                     0,     # status\n                                     '%s',  # comments\n                                     '%s'   # assigned_to\n                                );\n                ", $user_ref, $collection_id, escape_check($message), $assigned_to);
            if ($assigned_to === 'not_managed' || !$assigned_to_user) {
                $assigned_to_user['email'] = $email_notify;
                $request_query = sprintf("\n                        INSERT INTO request(\n                                                user,\n                                                collection,\n                                                created,\n                                                request_mode,\n                                                `status`,\n                                                comments\n                                           )\n                             VALUES (\n                                         '%s',  # user\n                                         '%s',  # collection\n                                         NOW(), # created\n                                         1,     # request_mode\n                                         0,     # status\n                                         '%s'   # comments\n                                    );\n                    ", $user_ref, $collection_id, escape_check($message), $assigned_to);
            }
            sql_query($request_query);
            $request = sql_insert_id();
            // Send the mail:
            $email_message = $lang['requestassignedtoyoumail'] . "\n\n" . $baseurl . "/?q=" . $request . "\n";
            send_mail($assigned_to_user['email'], $applicationname . ': ' . $lang['requestassignedtoyou'], $email_message);
            unset($email_message);
        }
        $notify_manage_request_admin = false;
    }
    // If we've got this far, make sure auto assigning managed requests based on resource types won't overwrite this
    unset($manage_request_admin);
    return true;
}
<?php 
// Get collections under the theme
$collectionstoshare = get_themes($themes, $subthemes);
if (count($collectionstoshare) < 1) {
    $show_error = true;
    $error = $lang["cannotshareemptythemecategory"];
} else {
    foreach ($collectionstoshare as $collection) {
        $ref = $collection["ref"];
        # Get min access to this collection
        $minaccess = collection_min_access($ref);
        if ($minaccess >= 1 && !$restricted_share) {
            $show_error = true;
            $error = str_replace("%collectionname%", i18n_get_collection_name($collection), $lang["collection-name"]) . "\n" . $lang["restrictedsharecollection"];
        }
        if (count(get_collection_resources($ref)) == 0) {
            $show_error = true;
            $error = str_replace("%collectionname%", i18n_get_collection_name($collection), $lang["collection-name"]) . "\n" . $lang["cannotshareemptycollection"];
        }
    }
    $access = getvalescaped("access", "");
    $expires = getvalescaped("expires", "");
    if (getvalescaped("generateurl", "") == "") {
        ?>
									
			<div class="VerticalNav">

			<li><a id="emaillink" onClick="var _href=jQuery('#emaillink').attr('href');var subthemes=document.getElementById('subthemes').checked;jQuery('#emaillink').attr('href',_href + '&subthemes=' + subthemes);return CentralSpaceLoad(this,true);" href="<?php 
        echo $baseurl_short . "pages/collection_email.php" . $linksuffix . "&catshare=true\">" . $lang["email_theme_category"];
        ?>
</a></li>
    }
    // Create a copy of the collection for admin:
    $admin_copy = create_collection(-1, $lang['send_collection_to_admin_emailedcollectionname']);
    copy_collection($collection_id, $admin_copy);
    $collection_id = $admin_copy;
    // Get the user (or username) of the contributor:
    $user = get_user($userref);
    if (isset($user) && trim($user['fullname']) != '') {
        $user = $user['fullname'];
    } else {
        $user = $user['username'];
    }
    // Get details about the collection:
    $collection = get_collection($collection_id);
    $collection_name = $collection['name'];
    $resources_in_collection = count(get_collection_resources($collection_id));
    // Build mail and send it:
    $subject = $applicationname . ': ' . $lang['send_collection_to_admin_emailsubject'] . $user;
    $message = $user . $lang['send_collection_to_admin_usercontributedcollection'] . "\n\n";
    $message .= $baseurl . '/pages/search.php?search=!collection' . $collection_id . "\n\n";
    $message .= $lang['send_collection_to_admin_additionalinformation'] . "\n\n";
    $message .= $lang['send_collection_to_admin_collectionname'] . $collection_name . "\n\n";
    $message .= $lang['send_collection_to_admin_numberofresources'] . $resources_in_collection . "\n\n";
    send_mail($email_notify, $subject, $message, '', '');
    exit;
}
global $php_path, $relate_on_upload, $enable_related_resources;
if ($relate_on_upload && $enable_related_resources && getval("uploaded_refs", "") != "") {
    $resource_refs = getval("uploaded_refs", "");
    $stringlist = "";
    foreach ($resource_refs as $k => $v) {