/** * Generates the CSV content of the metadata for resources passed in the array * * @param $resources * @return string */ function generateResourcesMetadataCSV(array $resources) { global $lang; $return = ''; $csv_field_headers = array(); $resources_fields_data = array(); foreach ($resources as $resource) { foreach (get_resource_field_data($resource['ref'], false, true, -1, getval("k", "") != "") as $field_data) { if ($field_data['name'] == '') { die('Please check field ID ' . $field_data['ref'] . ' and make sure its "' . $lang['property-shorthand_name'] . '" is set!'); } $csv_field_headers[$field_data['name']] = $field_data['title']; $resources_fields_data[$resource['ref']][$field_data['name']] = $field_data['value']; } } $csv_field_headers = array_unique($csv_field_headers); // Header $return = '"' . $lang['resourceids'] . '","' . implode('","', $csv_field_headers) . "\"\n"; // Results $csv_row = ''; foreach ($resources_fields_data as $resource_id => $resource_fields) { // First column will always be Resource ID $csv_row = $resource_id . ','; // Field values foreach ($csv_field_headers as $column_header => $column_header_title) { if (!array_key_exists($column_header, $resource_fields)) { $csv_row .= '"",'; continue; } foreach ($resource_fields as $field_name => $field_value) { if ($column_header == $field_name) { $csv_row .= '"' . tidylist(i18n_get_translated($field_value)) . '",'; } } } $csv_row .= "\n"; $return .= $csv_row; } return $return; }
/** * Generates the CSV content of the metadata for resources passed in the array * * @param $resources * @return string */ function generateResourcesMetadataCSV(array $resources) { global $lang; $return = ''; $csv_field_headers = array(); $resources_fields_data = array(); foreach ($resources as $resource) { foreach (get_resource_field_data($resource['ref'], false, true, -1, getval("k", "") != "") as $field_data) { $csv_field_headers[$field_data['resource_type_field']] = $field_data['title']; $resources_fields_data[$resource['ref']][$field_data['resource_type_field']] = $field_data['value']; } } $csv_field_headers = array_unique($csv_field_headers); // Header $return = '"' . $lang['resourceids'] . '","' . implode('","', $csv_field_headers) . "\"\n"; // Results $csv_row = ''; foreach ($resources_fields_data as $resource_id => $resource_fields) { // First column will always be Resource ID $csv_row = $resource_id . ','; // Field values foreach ($csv_field_headers as $column_header => $column_header_title) { if (!array_key_exists($column_header, $resource_fields)) { $csv_row .= '"",'; continue; } foreach ($resource_fields as $field_name => $field_value) { if ($column_header == $field_name) { $csv_row .= '"' . str_replace(array("\\n", "\\r", "\""), "//", tidylist(i18n_get_translated($field_value))) . '",'; } } } $csv_row .= "\n"; $return .= $csv_row; } return $return; }
$filename = $prefix_filename_string . $ref . "_" . $size . "." . $pextension; } if (hook("downloadfilenamealt")) { $filename = hook("downloadfilenamealt"); } #Add resource data/collection_resource data to text file if ($zipped_collection_textfile == true && $includetext == "true") { if ($size == "") { $sizetext = ""; } else { $sizetext = "-" . $size; } if ($subbed_original) { $sizetext = '(' . $lang['substituted_original'] . ')'; } $fields = get_resource_field_data($ref); $commentdata = get_collection_resource_comment($ref, $collection); if (count($fields) > 0) { $text .= ($sizetext == "" ? "" : $sizetext) . " " . $filename . "\r\n-----------------------------------------------------------------\r\n"; $text .= $lang["resourceid"] . ": " . $ref . "\r\n"; for ($i = 0; $i < count($fields); $i++) { $value = $fields[$i]["value"]; $title = str_replace("Keywords - ", "", $fields[$i]["title"]); if (trim($value) != "" && trim($value) != ",") { $text .= wordwrap("* " . $title . ": " . i18n_get_translated($value) . "\r\n", 65); } } if (trim($commentdata['comment']) != "") { $text .= wordwrap($lang["comment"] . ": " . $commentdata['comment'] . "\r\n", 65); } if (trim($commentdata['rating']) != "") {
echo $list[$n]; ?> "><?php echo $list[$n]; ?> </a> <?php } } ?> </p></body></html><?php } if ($ref != "") { # Resource view $resource = get_resource_data($ref); $resourcedata = get_resource_field_data($ref); $access = get_resource_access($ref); if (!in_array($access, $spider_access)) { exit("Access denied"); } if ($resource["has_image"] == 1) { $thumbnail = get_resource_path($ref, false, "col", false, $resource["preview_extension"]); } else { $thumbnail = $baseurl . "/gfx/type" . $resource["resource_type"] . "_col.gif"; } ?> <html><head> <meta name="country" content="<?php echo TidyList($resource["field3"]); ?> ">
document.getElementById('messagetext').focus(); }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert('<?php echo $lang["error"]; ?> \n' + textStatus); } }); } </script> <?php } hook("pageevaluation"); # Load resource field data $fields = get_resource_field_data($ref, false, !hook("customgetresourceperms"), -1, $k != "", $use_order_by_tab_view); //Check if we want to use a specified field as a caption below the preview if (isset($display_field_below_preview) && is_int($display_field_below_preview)) { $df = 0; foreach ($fields as $field) { if ($field["fref"] == $display_field_below_preview) { $displaycondition = check_view_display_condition($fields, $df); if ($displaycondition) { $previewcaption = $fields[$df]; // Remove from the array so we don't display it twice unset($fields[$df]); //Reorder array $fields = array_values($fields); } } $df++;
function reindex_resource($ref) { global $index_contributed_by; # Reindex a resource. Delete all resource_keyword rows and create new ones. # Delete existing keywords sql_query("delete from resource_keyword where resource='$ref'"); # Index fields $data=get_resource_field_data($ref,false,false); # Fetch all fields and do not use permissions. for ($m=0;$m<count($data);$m++) { if ($data[$m]["keywords_index"]==1) { #echo $data[$m]["value"]; $value=$data[$m]["value"]; if ($data[$m]["type"]==3 || $data[$m]["type"]==2) { # Prepend a comma when indexing dropdowns $value="," . $value; } # Date field? These need indexing differently. $is_date=($data[$m]["type"]==4 || $data[$m]["type"]==6); add_keyword_mappings($ref,i18n_get_indexable($value),$data[$m]["ref"],$data[$m]["partial_index"],$is_date); } } # Also index contributed by field, unless disabled if ($index_contributed_by) { $resource=get_resource_data($ref); $userinfo=get_user($resource["created_by"]); add_keyword_mappings($ref,$userinfo["username"] . " " . $userinfo["fullname"],-1); } # Always index the resource ID as a keyword remove_keyword_mappings($ref, $ref, -1); add_keyword_mappings($ref, $ref, -1); hook("afterreindexresource","all",array($ref)); }
if (getval("copyfrom", "") != "") { # Copy from function $copyfrom = getvalescaped("copyfrom", ""); $copyfrom_access = get_resource_access($copyfrom); # Check access level if ($copyfrom_access != 2) { $use = $copyfrom; $original_fields = get_resource_field_data($ref, $multiple, true, -1, "", $tabs_on_edit); } } if (getval("metadatatemplate", "") != "") { $use = getvalescaped("metadatatemplate", ""); $original_fields = get_resource_field_data($ref, $multiple, true, -1, "", $tabs_on_edit); } # Load resource data $fields = get_resource_field_data($use, $multiple, !hook("customgetresourceperms"), $originalref, "", $tabs_on_edit); # if this is a metadata template, set the metadata template title field at the top if (isset($metadata_template_resource_type) && isset($metadata_template_title_field) && $resource["resource_type"] == $metadata_template_resource_type) { # recreate fields array, first with metadata template field $x = 0; for ($n = 0; $n < count($fields); $n++) { if ($fields[$n]["resource_type"] == $metadata_template_resource_type) { $newfields[$x] = $fields[$n]; $x++; } } # then add the others for ($n = 0; $n < count($fields); $n++) { if ($fields[$n]["resource_type"] != $metadata_template_resource_type) { $newfields[$x] = $fields[$n]; $x++;
} #Add resource data/collection_resource data to text file if ($zipped_collection_textfile == true && $includetext == "true") { if ($size == "") { $sizetext = ""; } else { $sizetext = "-" . $size; } if ($subbed_original) { $sizetext = '(' . $lang['substituted_original'] . ')'; } if ($k === '') { $fields = get_resource_field_data($ref); } else { // External shares should take into account fields that are not meant to show in that case $fields = get_resource_field_data($ref, false, true, -1, true); } $commentdata = get_collection_resource_comment($ref, $collection); if (count($fields) > 0) { $text .= ($sizetext == "" ? "" : $sizetext) . " " . $filename . "\r\n-----------------------------------------------------------------\r\n"; $text .= $lang["resourceid"] . ": " . $ref . "\r\n"; for ($i = 0; $i < count($fields); $i++) { $value = $fields[$i]["value"]; $title = str_replace("Keywords - ", "", $fields[$i]["title"]); if (trim($value) != "" && trim($value) != ",") { $text .= wordwrap("* " . $title . ": " . i18n_get_translated($value) . "\r\n", 65); } } if (trim($commentdata['comment']) != "") { $text .= wordwrap($lang["comment"] . ": " . $commentdata['comment'] . "\r\n", 65); }
# Check access level if ($copyfrom_access!=2) # Do not allow confidential resources (or at least, confidential to that user) to be copied from { $use=$copyfrom; $original_fields=get_resource_field_data($ref,$multiple,true); } } if (getval("metadatatemplate","")!="") { $use=getvalescaped("metadatatemplate",""); } # Load resource data $fields=get_resource_field_data($use,$multiple,true,$originalref); # if this is a metadata template, set the metadata template title field at the top if (isset($metadata_template_resource_type)&&(isset($metadata_template_title_field)) && $resource["resource_type"]==$metadata_template_resource_type){ # recreate fields array, first with metadata template field $x=0; for ($n=0;$n<count($fields);$n++){ if ($fields[$n]["resource_type"]==$metadata_template_resource_type){ $newfields[$x]=$fields[$n]; $x++; } } # then add the others for ($n=0;$n<count($fields);$n++){
function save_proposed_changes($ref) { global $userref, $auto_order_checkbox, $multilingual_text_fields, $languages, $language; # Loop through the field data and save (if necessary) $errors = array(); $fields = get_resource_field_data($ref, false); $resource_data = get_resource_data($ref); for ($n = 0; $n < count($fields); $n++) { 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"])); 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 type, construct the value from the date/time 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 ($multilingual_text_fields && ($fields[$n]["type"] == 0 || $fields[$n]["type"] == 1 || $fields[$n]["type"] == 5)) { # Construct a multilingual string from the submitted translations $val = getvalescaped("field_" . $fields[$n]["ref"], ""); $val = "~" . $language . ":" . $val; reset($languages); foreach ($languages as $langkey => $langname) { if ($language != $langkey) { $val .= "~" . $langkey . ":" . getvalescaped("multilingual_" . $n . "_" . $langkey, ""); } } } 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 { # Set the value exactly as sent. $val = getvalescaped("field_" . $fields[$n]["ref"], ""); } # Check for regular expression match if (trim(strlen($fields[$n]["regexp_filter"])) >= 1 && strlen($val) > 0) { if (preg_match("#^" . $fields[$n]["regexp_filter"] . "\$#", $val, $matches) <= 0) { global $lang; debug($lang["information-regexp_fail"] . ": -" . "reg exp: " . $fields[$n]["regexp_filter"] . ". Value passed: " . $val); if (getval("autosave", "") != "") { exit; } $errors[$fields[$n]["ref"]] = $lang["information-regexp_fail"] . " : " . $val; continue; } } $error = hook("additionalvalcheck", "all", array($fields, $fields[$n])); if ($error) { global $lang; $errors[$fields[$n]["ref"]] = $error; continue; } if (str_replace("\r\n", "\n", $fields[$n]["value"]) !== str_replace("\r\n", "\n", unescape($val))) { # This value is different from the value we have on record. # Add this to the proposed changes table for the user sql_query("insert into propose_changes_data(resource,user,resource_type_field,value) values('{$ref}','{$userref}','" . $fields[$n]["ref"] . "','" . escape_check($val) . "')"); } } return true; }
# Fetch resource data. $resource = get_resource_data($ref); # Load resource data $proposefields = get_resource_field_data($ref, false, true); // Save data if (getval("save", "") != "") { if ($editaccess) { // Actually save the data save_resource_data($ref, false); daily_stat("Resource edit", $ref); // send email to change proposer with link $acceptedchanges = array(); $acceptedchangescount = 0; $deletedchanges = array(); $deletedchangescount = 0; $proposefields = get_resource_field_data($ref, false, true); // Get updated data after save so we can send email with values for ($n = 0; $n < count($proposefields); $n++) { # Has this field been accepted? if (getval("accept_change_" . $proposefields[$n]["ref"], "") != "") { $acceptedchanges[$acceptedchangescount]["field"] = $proposefields[$n]["title"]; $acceptedchanges[$acceptedchangescount]["value"] = $proposefields[$n]["value"]; $acceptedchangescount++; // remove this from the list of proposed changes sql_query("delete from propose_changes_data where user='******' and resource_type_field='" . $proposefields[$n]["ref"] . "'"); } # Has this field been deleted? if (getval("delete_change_" . $proposefields[$n]["ref"], "") != "") { foreach ($proposed_changes as $proposed_change) { if ($proposed_change["resource_type_field"] == $proposefields[$n]["ref"]) { $deletedchanges[$deletedchangescount]["field"] = $proposefields[$n]["title"];
# fetch the current search (for finding similar matches) $search = getvalescaped("search", ""); $order_by = getvalescaped("order_by", "relevance"); $offset = getvalescaped("offset", 0, true); $restypes = getvalescaped("restypes", ""); if (strpos($search, "!") !== false) { $restypes = ""; } $archive = getvalescaped("archive", 0, true); $starsearch = getvalescaped("starsearch", ""); $default_sort = "DESC"; if (substr($order_by, 0, 5) == "field") { $default_sort = "ASC"; } $sort = getval("sort", $default_sort); $metadata = get_resource_field_data($ref, false, true, -1, getval("k", "") != ""); $filename = $ref; $download = getval("download", "") != ""; $download_file_type = getval('fileType_option', ''); $language = getval('language', 'en'); // Process text file download if ($download && $download_file_type == 'text') { header("Content-type: application/octet-stream"); header("Content-disposition: attachment; filename=" . $lang["metadata"] . "_" . $filename . ".txt"); foreach ($metadata as $metadata_entry) { if (!empty($metadata_entry['value'])) { // This is the field title - the function got this by joining to the resource_type_field in the sql query echo $metadata_entry['title'] . ': '; // This is the value for the field from the resource_data table echo tidylist(i18n_get_translated($metadata_entry['value'])) . "\r\n"; }
{ ?> <script src="<?php echo $baseurl_short?>lib/js/metadata_report.js" type="text/javascript"></script> <?php } if ($direct_download && !$save_as){ ?> <iframe id="dlIFrm" frameborder=0 scrolling="auto" <?php if ($debug_direct_download){?>width="600" height="200"<?php } else { ?>width="0" height="0"<?php } ?>> This browser can not use IFRAME. </iframe> <?php } hook("pageevaluation"); # Load resource field data $fields=get_resource_field_data($ref,false,true,-1,$k!="",$use_order_by_tab_view); # Load edit access level (checking edit permissions - e0,e-1 etc. and also the group 'edit filter') $edit_access=get_edit_access($ref,$resource["archive"],$fields); if ($k!="") {$edit_access=0;} ?> <!--Panel for record and details--> <div class="RecordBox"> <div class="RecordPanel"> <div class="RecordHeader"> <?php if (!hook("renderinnerresourceheader")) { ?> <?php
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; }
$acceptedfields[]=$proposed_change["resource_type_field"]; } } // Actually save the data save_resource_data($ref,false,$acceptedfields); daily_stat("Resource edit",$ref); // send email to change proposer with link $acceptedchanges=array(); $acceptedchangescount=0; $deletedchanges=array(); $deletedchangescount=0; $proposefields=get_resource_field_data($ref,false,true); // Get updated data after save so we can send email with values for ($n=0;$n<count($proposefields);$n++) { # Has this field been accepted? if (getval("accept_change_" . $proposefields[$n]["ref"],"")!="") { debug("propose_changes - accepted proposed change for field " . $proposefields[$n]["title"]); $acceptedchanges[$acceptedchangescount]["field"]=$proposefields[$n]["title"]; $acceptedchanges[$acceptedchangescount]["value"]=$proposefields[$n]["value"]; $acceptedchangescount++; // remove this from the list of proposed changes sql_query("delete from propose_changes_data where user='******' and resource_type_field='" . $proposefields[$n]["ref"] . "'"); } # Has this field been deleted? if (getval("delete_change_" . $proposefields[$n]["ref"],"")!="") {