public function updateResource() { $rid = $this->resourceId(); // resource does not exist - create it if ($rid == 0) { $rid = create_resource($this->type); } else { update_resource_type($rid, $this->type); } foreach ($this->fields as $k => $v) { update_field($rid, $k, $v); } if (file_exists($this->filename)) { $extension = explode(".", $this->filename); if (count($extension) > 1) { $extension = trim(strtolower($extension[count($extension) - 1])); } else { $extension = ""; } $path = get_resource_path($rid, true, "", true, $extension); copy($this->filename, $path); create_previews($rid, false, $extension); # add file extension sql_query("update resource set file_extension='" . escapeString($extension) . "' where ref='" . escapeString($rid) . "'"); } # add resource to collection (if the collection exists) if ($this->collection != null) { $col_ref = sql_value("select ref as value from collection where name='" . escapeString($this->collection) . "'", 0); if (isset($col_ref)) { add_resource_to_collection($rid, $col_ref); } } # set access rights if ($this->access != null) { sql_query("update resource set access='" . escapeString($this->access) . "' where ref='" . escapeString($rid) . "'"); } }
function update_resource($r,$path,$type,$title,$ingest=false) { # Update the resource with the file at the given path # Note that the file will be used at it's present location and will not be copied. global $syncdir,$staticsync_prefer_embedded_title; update_resource_type($r, $type); # Work out extension based on path $extension=explode(".",$path);$extension=trim(strtolower(end($extension))); # file_path should only really be set to indicate a staticsync location. Otherwise, it should just be left blank. if ($ingest){$file_path="";} else {$file_path=escape_check($path);} # Store extension/data in the database sql_query("update resource set archive=0,file_path='".$file_path."',file_extension='$extension',preview_extension='$extension',file_modified=now() where ref='$r'"); # Store original filename in field, if set if (!$ingest) { # This file remains in situ; store the full path in file_path to indicate that the file is stored remotely. global $filename_field; if (isset($filename_field)) { $s=explode("/",$path); $filename=end($s); update_field($r,$filename_field,$filename); } } else { # This file is being ingested. Store only the filename. $s=explode("/",$path); $filename=end($s); global $filename_field; if (isset($filename_field)) { update_field($r,$filename_field,$filename); } # Move the file global $syncdir; $destination=get_resource_path($r,true,"",true,$extension); $result=rename($syncdir . "/" . $path,$destination); if ($result===false) { # The rename failed. The file is possibly still being copied or uploaded and must be ignored on this pass. # Delete the resouce just created and return false. delete_resource($r); return false; } chmod($destination,0777); } # generate title and extract embedded metadata # order depends on which title should be the default (embedded or generated) if ($staticsync_prefer_embedded_title) { update_field($r,8,$title); extract_exif_comment($r,$extension); } else { extract_exif_comment($r,$extension); update_field($r,8,$title); } # Ensure folder is created, then create previews. get_resource_path($r,false,"pre",true,$extension); # Generate previews/thumbnails (if configured i.e if not completed by offline process 'create_previews.php') global $enable_thumbnail_creation_on_upload; if ($enable_thumbnail_creation_on_upload) {create_previews($r,false,$extension);} # Pass back the newly created resource ID. return $r; }
if (strpos($postname, "exif_option_") !== false) { $uploadparams .= "&" . urlencode($postname) . "=" . urlencode($postvar); $exif_override = true; } } if ($exif_override) { $uploadparams .= "&exif_override=true"; } } hook("editbeforesave"); # save data if (!$multiple) { # Upload template: Change resource type $resource_type = getvalescaped("resource_type", ""); if ($resource_type != "" && !checkperm("XU{$resource_type}")) { update_resource_type($ref, $resource_type); $resource = get_resource_data($ref, false); # Reload resource data. } $save_errors = save_resource_data($ref, $multiple); if ($embedded_data_user_select) { $no_exif = getval("exif_option", ""); } else { $no_exif = getval("no_exif", ""); } $autorotate = getval("autorotate", ""); if ($upload_collection_name_required) { if (getvalescaped("entercolname", "") == "" && getval("collection_add", "") == -1) { if (!is_array($save_errors)) { $save_errors = array(); }
sql_query("update resource_type set name='" . $name . "',config_options='" . $config_options . "', allowed_extensions='" . $allowed_extensions . "',tab_name='" . $tab . "' where ref='{$ref}'"); redirect(generateURL($baseurl_short . "pages/admin/admin_resource_types.php", $url_params)); } if (getval("delete", "") != "") { $targettype = getvalescaped("targettype", ""); # Check for resources of this type $affectedresources = sql_array("select ref value from resource where resource_type='{$ref}' and ref>0", 0); if (count($affectedresources) > 0 && $targettype == "") { //User needs to confirm a new resource type $confirm_delete = true; } else { //If we have a target type, move the current resources to the new resource type if ($targettype != "" && $targettype != $ref) { include "../../include/resource_functions.php"; foreach ($affectedresources as $affectedresource) { update_resource_type($affectedresource, $targettype); } } // Delete the resource type sql_query("delete from resource_type where ref='{$ref}'"); redirect(generateURL($baseurl_short . "pages/admin/admin_resource_types.php", $url_params)); } } # Fetch data $restypedata = sql_query("\n\tselect \n\t\tref,\n\t\tname,\n\t\torder_by,\n\t\tconfig_options,\n\t\tallowed_extensions,\n\t\ttab_name\n from\n\t\tresource_type\n\twhere\n ref='{$ref}'\n\torder by name"); $restypedata = $restypedata[0]; include "../../include/header.php"; ?> <div class="BasicsBox"> <p> <a href="<?php
echo "<br><br>" . $keyfield["value"] . ": No resource found."; # Add a new resource and set the key field $ref = create_resource($resource["attributes"]["TYPE"]); update_field($ref, $keyfield["attributes"]["REF"], $keyfield["value"]); } else { # Existing resource found. echo "<br><br>" . $keyfield["value"] . ": Existing resource."; } # Update metadata fields $fields = get_nodes_by_tag("FIELD", $resource["id"]); foreach ($fields as $field) { echo "<br>" . $field["attributes"]["REF"] . "=" . $field["value"]; update_field($ref, $field["attributes"]["REF"], $field["value"]); } # Update resource type update_resource_type($ref, $resource["attributes"]["TYPE"]); # Update file, if specified $filenames = get_nodes_by_tag("FILENAME", $resource["id"]); if (count($filenames) == 1) { $filename = $filenames[0]["value"]; echo "<br>Processing file: " . $filename; if (!file_exists($filename)) { echo "<br/>File does not exist!"; } else { # Get path $extension = explode(".", $filename); if (count($extension) > 1) { $extension = trim(strtolower($extension[count($extension) - 1])); } else { $extension = ""; }
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); $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) { # 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 = (double) $location[0]; $geo_long = (double) $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"); }