DaDaBIK
This forum is devoted to the discussion about the software DaDaBIK database front-end
the PHP Database application generator for MySQL, PostgreSQL and SQLite; also available for Wordpress.

Welcome! Log In Create A New Profile

Advanced

Approval

Posted by Yoanna 
Yoanna
Approval
February 08, 2005 01:36PM
Hi!
Is there a possibility to kind of approve Datas? I would like to have two tables, one for the public an one internal. The public Table should only show Datas that are approved or released. But the internal one shuold show all the Datas. This should be possible by one flag right? Does anyone have a solution for this?

Thanks!
Yoanna
Debbie S
Re: Approval
February 19, 2005 06:30AM
Yoanna

Sorry for not replying sooner -- I was racking my brain trying to think of something and then it hit me while I was at work today doing some updates in one of my installations deleting records.

In this case, when a record is deleted, I have that record moved to another table within the database and leave it stored there until they request that the information be restored (I added this hack after a couple of oops, I shouldn't have had you remove that requests and I got tired of repeatedly re-entering data). This could work for what you want by moving (or with a slight modification, just copy it) from a table that only the admin can edit into the table that the public can see. You just make sure that the admin table is set to only allow users to insert records and nothing else.

You would have two tables then - one for approved viewable data and one for admin to review and approve.

If you are interested in this mod, let me know and I will bring the files home with me on Monday (they are on my work servers and I forgot to send the info home) or sooner if they fix my FTP access before then. Once I have the files, I can provide you with more details for the code and table set-up, etc.

Debbie
(Latest version of DaDaBIK when this message was posted: 3.1 Beta)
Tom
Re: Approval
April 02, 2005 11:51AM
I'm also interested in this approval feature, because I'd like to control what information is entered to the database.

Debbie S
Re: Approval
April 05, 2005 12:22AM
Tom

I simply added the bold parts (note the second part of the query has added '1' to make the delete part of the function work - the entire portion shown below can be cut and pasted) to my delete_record function in business_logic.php -- this moves the selected record from the active table into the "public" table (shown in italics):

function delete_record ($table_name, $where_field, $where_value)
// goal: delete one record
{
global $conn, $quote;//INSERT INTO table_b SELECT * FROM table_a WHERE
$sql = "INSERT INTO removed SELECT * FROM ".$quote.$table_name.$quote." WHERE ".$quote.$where_field.$quote." = '".$where_value."' LIMIT 1";
display_sql($sql);

// execute the select query
$res_contacts = execute_db($sql, $conn);


global $conn, $quote;
$sql1 = "DELETE FROM ".$quote.$table_name.$quote." WHERE ".$quote.$where_field.$quote." = '".$where_value."' LIMIT 1";
display_sql($sql1);

// execute the select query
$res_contacts1 = execute_db($sql1, $conn);

} // end function delete_record

Debbie
(Latest version of DaDaBIK when this message was posted: 3.2 Beta)
azamkl
Re: Approval
April 15, 2005 03:46AM
By inserting the bold text as explained by Debbie (for the 'function delete_record'), the 'approval method' will works..? or is it i need to create the appropriate tables my self.? Could you please explain it in details?

I've tried to work around as what Debbie has posted, but it didn't work :-(

Debbie S
Re: Approval
April 18, 2005 05:21AM
azamkl

Yes -- you will have to create a table where you want the approved records to go. This table will also have to be installed and managed by DaDaBIK.

If you have records being entered into 'table1' and want to have approved records moved to 'table2', the code above will show 'table2' as the table to move the records to. Both these tables must exist in your database and installed by DaDaBIK.

Debbie
(Latest version of DaDaBIK when this message was posted: 3.2 Beta)
Pieter
Re: Approval
May 24, 2005 01:14AM
Okay, so now I have two questions.

If I add this code, and click delete on a record in table1, it will move the data to table2, right? What if I really DO want to delete a record?

In table2, when I click delete, will it delete or move the record? (to... ?)

And, last but not least. I would like to send an email to the record i move from table1 to table2, saying 'You are approved!' (emaildress in field 'email'. Is this easy to implement?

Thank you!
Debbie S
Re: Approval
May 24, 2005 03:13PM
Pieter

If you want to retain the delete function as is, then I'd suggest creating a separate function to move records. Don't have the time right now to test it out, perhaps in the next couple days.

As for the email part, another user managed to get some email thing worked out. Don't remember the post title, but you could try searching for email record or something like that.

Will post once I've tested the separate move function.

Debbie
(Latest version of DaDaBIK when this message was posted: 3.2 Beta)
Pieter
Re: Approval
May 24, 2005 08:32PM
And again, thank you very much!

I am looking forward to your code. And if I can ever help with translating or something, no problem...

:-)

Pieter
Re: Approval
May 25, 2005 11:55AM
OK, i found the e-mail topic. Have some questions though, but I will ask these later, when I can see it all together... Thanks!
Debbie S
Re: Approval
May 28, 2005 06:39PM
To have separate approve and delete functions, insert the following code into the files as noted (inserted code is shown in bold):

*****
business_logic.php :: Immediately after the following code (starting on or about line 2355):
$results_table .= "&where_field=".urlencode($where_field)."&where_value=".urlencode($where_value)."\"><img border=\"0\" src=\"".$delete_icon."\" alt=\"".$submit_buttons_ar["delete"]."\" title=\"".$submit_buttons_ar["delete"]."\" hspace=\"2\"></a>";

$results_table .= "<a class=\"onlyscreen\"";
$results_table .= " href=\"".$dadabik_main_file."?table_name=".urlencode($table_name)."&function=move";

if($results_type == "search"winking smiley {
$results_table .= "&where_clause=".urlencode($where_clause)."&page=".$page."&order=".urlencode($order)."&order_type=".$order_type;
}

$results_table .= "&where_field=".urlencode($where_field)."&where_value=".urlencode($where_value)."\">Approve</a>";

} // end if

If you wish to have an icon display for the approve, you can change the "Approve" text to whatever image you wish.

*****
business_logic.php :: Use the code further up in the post to copy the record and delete at the same time and change the name of that function to function move_record and insert the original code for the function delete_record below it:

function delete_record ($table_name, $where_field, $where_value)
// goal: delete one record
{
global $conn, $quote;//INSERT INTO table_b SELECT * FROM table_a WHERE
$sql = "DELETE FROM ".$quote.$table_name.$quote." WHERE ".$quote.$where_field.$quote." = '".$where_value."' LIMIT 1";
display_sql($sql);

// execute the select query
$res_contacts = execute_db($sql, $conn);

} // end function delete_record


If you do not want to move and delete at the same time, remove the delete portion of the function move_record.

*****
index.php :: Here you have to create a move function to make the above code work. Copy the existing 'case "delete";' portion (approx lines 714 to 735) and paste immediately after the delete 'break;' line. Make the changes as shown in bold below:

case "move":
if ($enable_delete == "1"winking smiley {

$location_url = $site_url.$dadabik_main_file.'?table_name='.urlencode($table_name).'&function=search&where_clause='.urlencode($where_clause);
if(isset($page) && isset($order) && isset($order_type)) {
$location_url .= '&page='.$page.'&order='.urlencode($order).'&order_type='.$order_type;
}
else{
$location_url .= '&page=0';
}

if( $enable_authentication === 0 || $enable_delete_authorization === 0 || current_user_is_owner($where_field, $where_value, $table_name, $fields_labels_ar)){
move_record ($table_name, $where_field, $where_value);
} // end if
else {
$location_url .= '&just_delete_no_authorization=1';
} // end else

header('Location: '.$location_url);
} // end if
break;


You will now see in your results table separate icons/words for delete and approve. Of course, if you want to go further and create icon and text variables like the edit, delete and details functions, you can add that information into the config.php and appropriate language files, etc.

Debbie
(Latest version of DaDaBIK when this message was posted: 3.2 Beta)
Debbie S
Re: Approval
May 29, 2005 09:11PM
Hello everyone!

Forgot to add to above post that if you want to use an icon for the move function, and you are using a variable like the edit, delete and details image calls do, you have to add that variable to the "global" line of the function build_results_table:

global $submit_buttons_ar, $normal_messages_ar, $edit_target_window, $delete_icon, $edit_icon, $details_icon, $move_icon, $enable_edit, $enable_delete, $enable_details, $conn, $quote, $ask_confirmation_delete, $word_wrap_col, $word_wrap_fix_width, $alias_prefix, $dadabik_main_file;

Debbie
(Latest version of DaDaBIK when this message was posted: 3.2 Beta)
Pieter
Re: Approval
May 29, 2005 09:24PM
GREAT! Thank you very, very much!

Now I would like to send an e-mail to the e-mail-field in the database when I click the approve button. Can I use the e-mail function in the e-mailtopic?
Pieter
Re: Approval
May 29, 2005 09:35PM
Look, I found this code. How can I implement it? Or is this code not of any use?

I now have a working move function. It moves the record to the other database. But, I want to send an e-mail saying 'Hi $name, You are approved!' to the e-mailadress in the email-field in the database, and i would like to use the name-field of the dbase. I guess I should add the mail code to the move-function, but I don't know how to get the e-mail and name values from the record being moved. I'd really appreciate any help. Thanks!

This is the code I found.

// get the record being edited
$result = mysql_query("select * from TABLE where id = '$where_value'",$conn);

// display the results
if ($result){
$numOfRows = mysql_num_rows ($result);
for ($i = 0;
$i < $numOfRows;
$i++)
{
//find the result fields equal to email and inv_name
$email = mysql_result ($result, $i, "email"winking smiley;
$inv_name = mysql_result ($result, $i, "inv_name"winking smiley;

// now the send email script
$adminaddr="$email";

mail($adminaddr, 'Updated Record',
"Greetings Admin,
A user $inv_name has posted new record details to our database. Please check it.
Thank you,
Systems "winking smiley;
Debbie S
Re: Approval
June 24, 2005 02:18PM
Pieter

Sorry it's taken so long to get back to you -- I must have missed this post. From what I can see of the script snippet above, you'd just have to replace the values in the code with those that match your particular database installation. The email you wish to send mail to would be contained in the field you've designated as the email address field.

I've never used the script myself, so if you need further assistance with this in particular, the best thing would be to contact the user who posted this solution in the forums.

Debbie
(Latest version of DaDaBIK when this message was posted: 4.0 alpha)
Re: Approval
March 15, 2006 11:49PM
hi, I have added the above archive function to my database, it archives from table1 to table2 ok. but delete does not work in either table. When I click delete the 'delete confirm' box pops up, then when 'ok' is selected, the whole table disappears, when browser is refreshed, table reappears but the item selected for deletion is still present in the table.
so basically... archive is working. Delete not working
snippet taken from business_logic.php:

function move_record ($table_name, $where_field, $where_value)
// goal: move one record
{
global $conn, $quote;
//INSERT INTO archive SELECT * FROM table_a WHERE
$sql = "INSERT INTO archive SELECT * FROM ".$quote.$table_name.$quote." WHERE ".$quote.$where_field.$quote." = '".$where_value."' LIMIT 1";
display_sql($sql);

// execute the select query
$res_contacts = execute_db($sql, $conn);

global $conn, $quote;
$sql1 = "DELETE FROM ".$quote.$table_name.$quote." WHERE ".$quote.$where_field.$quote." = '".$where_value."' LIMIT 1";
display_sql($sql1);

// execute the select query
$res_contacts1 = execute_db($sql1, $conn);

} // end function move_record

function delete_record ($table_name, $where_field, $where_value)
// goal: delete one record
{
global $conn, $quote;//INSERT INTO table_b SELECT * FROM table_a WHERE
$sql = "DELETE FROM ".$quote.$table_name.$quote." WHERE ".$quote.$where_field.$quote." = '".$where_value."' LIMIT 1";
display_sql($sql);

// execute the select query
$res_contacts = execute_db($sql, $conn);

} // end function delete_record
Re: Approval
January 06, 2012 11:37AM
Hi Debbie,

I am hoping to use the information in this post to create a simple move record function that allows me to move a record from an 'enquiry' table to a 'booking' table (and then deletes the record from the 'enquiry' table). However, because I am using Dadabik v4.3, the code has actually changed quite a bit (especially the current 'delete_record' function) and I am not completely sure if I sure proceed with these instructions. Do you have, or know of a more concise and easily understood explanation for v4.3?

I want the move record to be separate from the current delete record function, but I also only want the move record to ONLY be available when viewing the 'enquiry' table and not on the other tables in my database. Is this possible?

Thanks in advance!
Re: Approval
January 07, 2012 12:22AM
I can understand all the other changes required, except for changing the delete_record function. This is the current v4.3 delete_record function I am working with (untouched from installation):

function delete_record ($table_name, $where_field, $where_value, $fields_labels_ar)
// goal: delete one record
{
global $conn, $quote, $upload_directory, $delete_files_when_delete_record;

$sql_delete = "DELETE FROM ".$quote.$table_name.$quote." WHERE ".$quote.$where_field.$quote." = '".$where_value."'";
display_sql($sql);

if ($delete_files_when_delete_record === 1){

$fields_containing_files_ar = array(); // the names of the fields which contain files, if any

$files_to_delete_ar = array(); // here the name of the uploaded files to delete, if any

foreach ($fields_labels_ar as $fields_labels_ar_element){
if ($fields_labels_ar_element['type_field'] === 'generic_file' || $fields_labels_ar_element['type_field'] === 'image_file'){ // check if the field is a file field
$fields_containing_files_ar[] = $fields_labels_ar_element['name_field'];
} // end if
} // end foreach

$fields_count = count($fields_containing_files_ar);

if ($fields_count > 0){
$sql = "SELECT ";
foreach ($fields_containing_files_ar as $fields_containing_files_ar_element){
$sql .= $fields_containing_files_ar_element.", ";
} // end foreach
$sql = substr($sql, 0, -2);
$sql .= " FROM ".$quote.$table_name.$quote." WHERE ".$quote.$where_field.$quote." = '".$where_value."'";

// execute the delete query
$res = execute_db($sql, $conn);

$row = fetch_row_db($res);

for ($i=0; $i<$fields_count; $i++){
$files_to_delete_ar[] = $row[$i];
} // end for

foreach($files_to_delete_ar as $files_to_delete_ar_element){
if (is_file($upload_directory.$files_to_delete_ar_element)){ // for security
unlink($upload_directory.$files_to_delete_ar_element); // delete the file
} // end if
} // end foreach

} // end if

} // end if

// execute the delete query
$res_delete = execute_db($sql_delete, $conn);

} // end function delete_record


How would I adapt this function so that I can make the code additions as in the post near the top, then copy and rename as move_record function and ensure those $sql statements that the post instructs to change to $sql1 (and any others - as there are several more in v4.3 than there were in v3.2)?? Any help greatly appreciated.
Re: Approval
January 24, 2012 09:48PM
Hi,

I have managed to get this 'move' function working, using the code in the posts above. However, I now have another problem:

The created 'move' link next to each record only works when 'delete' is enabled in the table, which I don't wan't (but need the record to be deleted from Table A after moving to Table B, which it does presently); I tried moving the code outside of the 'if ($enable_delete)' statement shown below (my additions in bold, to the v4.3 business_logic.php file) but it stopped working (the code below does work but obviously only when 'delete is enabled on the admin page for Table A).


if ($enable_delete == "1"winking smiley{ // display the delete icon
$results_table .= "<a class=\"onlyscreen\"";
if ( $ask_confirmation_delete == 1) {
$results_table .= " onclick=\"if (!confirm('".str_replace('\'', '\\\'', $normal_messages_ar['confirm_delete?'])."')){ return false;}\"";
}
$results_table .= " href=\"".$dadabik_main_file."?table_name=".urlencode($table_name)."&function=delete";
/*
if($results_type == "search"winking smiley {
$results_table .= "&where_clause=".urlencode($where_clause)."&page=".$page."&order=".urlencode($order)."&order_type=".$order_type;
}
*/
if ($is_items_table === 1) {
$results_table .= "&master_table_name=".urlencode($master_table_name)."&master_table_function=".$master_table_function."&master_table_where_field=".urlencode($master_table_where_field)."&master_table_where_value=".urlencode($master_table_where_value)."&is_items_table=1";
} // end if

$results_table .= "&where_field=".urlencode($where_field)."&where_value=".urlencode($where_value)."\">Delete</a>&nbsp;";



// My addition 07/01/12
$results_table .= "<a class=\"onlyscreen\"";
$results_table .= " href=\"".$dadabik_main_file."?table_name=".urlencode($table_name)."&function=move";

if($results_type == "search"winking smiley {
$results_table .= "&where_clause=".urlencode($where_clause)."&page=".$page."&order=".urlencode($order)."&order_type=".$order_type;
}

$results_table .= "&where_field=".urlencode($where_field)."&where_value=".urlencode($where_value)."\">Move</a>&nbsp;";

// end my addition

} // end if

So I tried moving the code in bold above to just outside the IF statement directly above this line, but then the 'move' link, when clicked, doesn't appear to do anything other than make the screen flash and make the current records html table disappear from the screen (and no debugging statements appeared either - have debugging set to on).

So can anyone give me any pointers or assistance in ensuring this 'move' function works when 1) The source Table A and destination Table B both have 'delete' disabled and 2) It still deletes the record from Table A after copy and move (can I even delete when delete is not enabled on Admin page??).

Thanks,

Matt
Re: Approval
January 24, 2012 11:39PM
OK, I have managed to make this work almost exactly how I want it to. The only thing I need now is to be able to enable/disable move via the admin control panel. I had a play and tried adding the $enable_move to pretty much everywhere I found other enable/disable commands in the php files but I obviously didn't find them all - I managed to create a tickbox for move next to the other enable/disable checkboxes on the admin page but when checked and the enable button was clicked, it didn't update anything.

If anyone else has added a new function to the admin page or knows what files I need to search to make the changes, I would be very grateful for any pointers!
Sorry, only registered users may post in this forum.

Click here to login