Employee could update data after approved by their boss

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
kelapamuda
User
Posts: 4

Employee could update data after approved by their boss

Post by kelapamuda »

How to do this:
Employee could update their own data , but it update, after their boss approved. So after the boss approved then the data is updated. Is it possible to do this? How? Thank you very much


mobhar
User
Posts: 11717

Post by mobhar »

You could do this by using "Row_Updated" server event to insert the updated data to another table. You need then to provide the temporary table that will hold the new values, and when the boss approves, just update the original table with the data from temporary table.

Please read "Server Events and Client Scripts" topic from PHPMaker Help menu for more info and examples.


kelapamuda
User
Posts: 4

Post by kelapamuda »

Thanks, i already read the Help and googling too, but still not found examples, is there any examples?


mobhar
User
Posts: 11717

Post by mobhar »

For example, in "Row_Updated" you may execute the following SQL to insert the new value into the temporary table (employees_temp), and keep the old value in the current table (employees). Assume the EmployeeID field is varchar or string field type and it's a primary key.

if (CurrentUserLevel() == 1 && ($rsold["Address"] != $rsnew["Address"])) { // assume level 1 is staff, and the address is changed
// insert the new value into temporary table
ew_Execute("INSERT INTO employees_temp (EmployeeID, Address) VALUES ('".$rsold["EmployeeID"]."', '".$rsnew["Address"]."')");
// update the current table back with the old value
ew_Execute("UPDATE employees SET Address = '".$rsold["Address"]."' WHERE EmployeeID = '".$rsold["EmployeeID"]."'");
$this-setSuccessMessage("Congrats, your new address will be updated after it has been approved by your boss!");
}

// In addition, when boss approves, then update the current table with the new value that derived from temporary table, as follows:

if (CurrentUserLevel() == 2) { // assume level 2 is boss (you need to add your own logic here how to check the data is ready to be approved by the boss)
// get the new value from temporary table
$val_Address = ew_ExecuteScalar("SELECT Address FROM employees_temp WHERE EmployeeID = " . $rsold["EmployeeID"]);
if (!empty($val_Address)) {
// if exists, then update the current table with the new value
ew_Execute("UPDATE employees SET Address = '".$val_Address."' WHERE EmployeeID = '".$rsold["EmployeeID"]."'");
// you may also delete the data in the temporary table afterwards (if necessary):
ew_Execute("DELETE * FROM employees_temp WHERE EmployeeID = '".$rsold["EmployeeID"]."'")
$this->setSuccessMessage("Congrats, your new employee's address has been approved.");
}
}

That is just a simple example with the simple table. Assume the "employees" and "employees_temp" tables schema are the same, and user only change his/her Address. You may of course adjust it to your needs, for example, by adding/implementing the logic how to determine the status of data when it has been changed by your employees and ready to approve by the boss.


mobhar
User
Posts: 11717

Post by mobhar »

Sorry, typing too fast...

This code:
$val_Address = ew_ExecuteScalar("SELECT Address FROM employees_temp WHERE EmployeeID = " . $rsold["EmployeeID"]);

should be:
$val_Address = ew_ExecuteScalar("SELECT Address FROM employees_temp WHERE EmployeeID = '" . $rsold["EmployeeID"] . "'");


Post Reply