|
From: paul c. <pdc...@bl...> - 2010-08-27 19:54:25
|
Feel free to make it conform to any 'house style'.Ive tested it for what
i want to do and it seems to work.
changes to user_maint.php
a bit of php to create another button and dropdown menu next to the
Add/Update Employee/Contractor. The button is done with php as its
easier to remove or put some sort of if statement before ( just delete
all the php)
<input type="button" name="addupdate" value="Add/Update
Employee/Contractor" onclick="javascript:addUser()"
class="bottom_panel_button">
<?php
echo "<input type=\"button\" name=\"cloneUser\" value=\"Clone this
user\" onclick=\"javascript:onClone()\" class=\"bottom_panel_button\"> " ;
echo "<select name=\"cloneFromUser\">\n";
list($qh,$num) = dbQuery("SELECT * FROM $USER_TABLE WHERE
username!='guest' ORDER BY status desc, last_name, first_name");
while ($data = dbResult($qh))
{
$firstNameField = empty($data["first_name"]) ? " ":
$data["first_name"];
$lastNameField = empty($data["last_name"]) ? " ":
$data["last_name"];
$usernameField = empty($data["username"]) ? " ":
$data["username"];
echo "<option value=\"$usernameField\">$usernameField</option>\n";
}
echo "</select>";
?>
</td>
</tr>
</table>
changes to user_action.php
else if ($action == "addupdate") becomes
else if ($action == "addupdate" || $action == "cloneUser" )
the final else becomes this . It does the stuff for a new user and then
if the choice is cloneUser it looks at timesheet_assignments and
timesheet_task_assignments and takes the data for the user to clone from
and adds it to the database tables with the new username.
else
{
dbquery("INSERT INTO $USER_TABLE (username, level, password,
first_name, ".
"last_name, email_address, time_stamp,
status) " .
"VALUES
('$username',$level,$DATABASE_PASSWORD_FUNCTION('$password'),'$first_name',".
"'$last_name','$email_address',0,'$status')");
dbquery("INSERT INTO $ASSIGNMENTS_TABLE VALUES (1,'$username',
1)"); // add default project.
dbquery("INSERT INTO $TASK_ASSIGNMENTS_TABLE VALUES
(1,'$username', 1)"); // add default task
//create a time string for >>now<<
$today_stamp = date("Y-m-d H:i:00");
dbquery("INSERT INTO $ALLOWANCE_TABLE VALUES (NULL,'$username',
'$today_stamp', 0, 0.0)"); // add default allowance
if ($action == "cloneUser" )
{
$sql = "SELECT * FROM $TASK_ASSIGNMENTS_TABLE WHERE
username = '".$_REQUEST['cloneFromUser']."' AND `task_id` !=1 AND
`proj_id` !=1";
list($qh,$num) = dbQuery($sql);
while ($data = dbResult($qh))
{
$t_id=$data['task_id'];$p_id=$data['proj_id'];
$sql="INSERT INTO $TASK_ASSIGNMENTS_TABLE VALUES
('$t_id','$username','$p_id')";
dbQuery($sql);
}
list($qh,$num) = dbQuery(" SELECT * FROM $ASSIGNMENTS_TABLE WHERE
username = '".$_REQUEST['cloneFromUser']."' AND `proj_id` !=1 ");
while ($data = dbResult($qh))
{
$p_id=$data['proj_id'];
dbquery("INSERT INTO $ASSIGNMENTS_TABLE VALUES
('$p_id','$username', 1)");
}
}
}
}
//redirect back to the user management page
|