1

Topic: Duplicating entries

Hi,

Is there currently an easy way to duplicate entries in the database?  For example, if we already have a chemical stored in one location, and we obtain another bottle to keep in a different location, are we stuck with copying all the fields manually? 

Thanks,

Katie

2

Re: Duplicating entries

It can be done with some significant editing of the code; see instructions below. I will soon release a new version incorporating these changes.

1) Edit interface_creator/business_logic.php

A) You have to edit the function 'build_form'. It's a long function.

* Look for first instances of 'case "update":' Below that block ('case...break;'), add -

    case 'copy':
    $function = 'copy';
    break;

* Look for all of the next two instances of 'case "update":' Below 'case "update"' add -

  case "copy":
  
* Look for all instances, except one, of '$form_type == "update"'. Edit it so it becomes -

  $form_type == "update" or $form_type == "copy"
  
The one instance where you should not do this is under -

case "generic_file":
case "image_file":

B) Next, edit function 'build_results_table'

* At very beginning, look for global $... $enable_edit...;' After '$enable_edit, ', add -

  $enable_insert,
  
* Further down, look for 'if ($enable_details == "1"){ // display the details icon'. Scroll down till you find the '{ // end if' for this block. Below, add -

  if ($enable_details == "1" and $enable_insert == "1"){ // display the copy icon
    $results_table .= "<a class=\"onlyscreen\" href=\"";
    if ($edit_target_window == 'blank') // popup
    {
    $results_table .= $dadabik_short_file;
    }
    else
    {
    $results_table .= $dadabik_main_file;
    }
    $results_table .= "?table_name=".urlencode($table_name)."&amp;function=copy&amp;where_field=".urlencode($where_field)."&amp;where_value=".urlencode($where_value)."\"";
    if ($edit_target_window == 'blank') // popup
    {
    $results_table .= " onclick=\"javascript:window.open('".$dadabik_short_file."?table_name=".urlencode($table_name)."&amp;function=copy&amp;where_field=".urlencode($where_field)."&amp;where_value=".urlencode($where_value)."', 'new','".$popup_parameters."'); return false;\"";
    }
    $results_table .= " title=\"".$submit_buttons_ar["copy"]."\">+<sup>+</sup></a>";
    } // end if

2) Edit config.php

* Look under 'submit_buttons_ar' for '    "insert"    => "Insert a new entry like this",' Below, add -

    "copy"    => "Insert a new entry",

* Look under 'normal_messages_ar' for '"insert_record" => "Insert a new entry",' Below, add -

    "insert_record_copy" => "Insert a new entry similar to another",

* Look under 'error_messages_ar' for '    "no_authorization_view" => "You don't have the authorization to view this record.",' Below, add -

    "no_authorization_copy" => "You don't have the authorization to copy this record.",
    
3) Edit interface_creator/index_short.php, index_long.php and index.php

You have to edit towards the end of the switch($function) block. Find ' } // end switch $function ' and before it, add -

 case "copy":
 if ($enable_insert == "1" && ($enable_authentication === 0 || $enable_browse_authorization === 0 || current_user_is_owner($where_field, $where_value, $table_name, $fields_labels_ar))) {
 // build the details select query
 $sql = "select * from ".$quote.$table_name.$quote." where ".$quote.$table_name.$quote.'.'.$quote.$where_field.$quote." = '".$where_value."'";
 display_sql($sql);
 txt_out("<h3>".strtoupper($table_name)."<br />".$normal_messages_ar["insert_record_copy"]."</h3>");
 if (required_field_present($fields_labels_ar)){ // at least one required field
  txt_out($normal_messages_ar["required_fields_red"],"normal_messages_form");
 } // end if
 // execute the select query
 $res_details = execute_db($sql, $conn);
 $form_type = "copy";
 // display the form
 $form = build_form($table_name, $action, $fields_labels_ar, $form_type, $res_details, $where_field, $where_value);
 echo $form;
 } // end if enable_insert
 else {
 txt_out("<p>".$error_messages_ar["no_authorization_copy"]."</p>");
 } // end else
 break;
 
4) Edit all .php files in modules/, such as chemicals.php. All are edited in a similar way. An example is given below for cell-lines.php. Do the same way for other files, each time ensuring the 'table_name' is file-specific
 
* Look for 'Delete</a>');}' and edit to change it to -

 </a> | <a href="../interface_creator/index_short.php?table_name=cell-lines&amp;function=copy&amp;where_field=id&amp;where_value='.$row["id"].'" onclick="return popitup(\'../interface_creator/index_short.php?table_name=cell-lines&amp;function=copy&amp;where_field=id&amp;where_value='.$row["id"].'\')"> Copy</a>');}

3

Re: Duplicating entries

The new version of LabStoRe (1.5) incorporating these and other changes has been released.