Ok
Next chapter in this. This is all still along the line of cheap and dirty but working. A quick but not perfect solution.
Here is what I have done now.
The field I want to have auto filled when the table is opened has been set to read only manually. NOT USING APPGINI to do this. Here is how that is done.
Take a look at the attached code below and you will see where I have added the
readonly. The rest is left the same and by doing it using this method it allows quick changes. This is done in the template file for the table.
(The other reason is this table has fields I need the end user to see but not be able to change. Another exact same template file exists which only certain groups can access and allows them to change fields. For example: A confirmed field. I cannot have an end user confirming/approving their own entry. But, I do need them to know when it has been confirmed. When a supervisor confirms the entry an email is sent to the end user letting them know and they can look at the record again to see it is checked off if they wish. It also allows for searching all confirmed/approved records. I also use this for a registration database when the registration has been confirmed. The organizer checks confirmed).
Code: Select all
<div class="form-group">
<label for="name" class="control-label col-lg-3">Name<span class="text-danger"><%%TRANSLATION(*)%%></span></label>
<div class="col-lg-4">
<input tabindex="1" maxlength="40" type="text" class="form-control" name="name" id="name" value="<%%VALUE(name)%%>" required readonly="readonly" />
</div>
</div>
I left the
required qualifier in there to insure it is filled in. (Would mess things up if missing).
Next I changed the header file a tiny bit. Remember this is cheap and dirty so it is not perfect but works fine. Refinements will come when I have rest of system done and can get down to the fine points of proper design. But, again, it works.
To the header.php file I added in:
Just look for the
body tag and add in your function you want to run after the word body.
This will then run my function after the page is loaded. I then
duplicated and renamed this file headerinci.php. The inci just refers to my table incident report. The next step is my php file to get the info I want. I want to pull the first and last names from the table which contains this info. (Users are forced to fill this table in with their info before they get more access.)
(Yes I can do a bunch of this in the hook file but doing it this way for now was a lot faster as I am under the gun time wise)
Here is my php file to get the data from the table with the user first and last name. (Again this is cheap and dirty code but it works and most should be able to follow the logic I hope)
Code: Select all
<?php
$currDir=dirname(__FILE__);
include("$currDir/lib.php");
$mid = getLoggedMemberID();
mysql_connect("[b]localhost[/b]", "[b]user[/b]", "[b]pass[/b]") or die(mysql_error());
mysql_select_db("[b]dbname[/b]") or die(mysql_error());
$result1 = mysql_query("SELECT * FROM membership_userrecords WHERE memberID = '$mid'") or die(mysql_error());
while($row1 = mysql_fetch_array($result1)){
$p1 = $row1["pkValue"];
}
$result2 = mysql_query("SELECT * FROM employee_info WHERE id = '$p1'") or die(mysql_error());
while($row2 = mysql_fetch_array($result2)){
$f1 = $row2["first_name"];
$f2 = $row2["last_name"];
$f3 = ($f1 . " " . $f2);
echo $f3;
}
?>
Okay here is how the above works. Again this is not elegant but it does work. Since the entire system is in a closed environment, at this point, I can be a tiny bit lax on security.
First part is to get the logged members id
Next is the access to the database - this is the mysql_connect
Next is the first query which gets the only record and its pkvalue. (There can only be one record. The app does not allow a user to have more than one member record. Makes sense, why would a user need two records with their member info. If changes are needed just change the first one)
Next the second query uses the pkvalue to get the member record and extract their first name and last name from the record then joins them together.
Next I need to make sure this table view file open the correct header file. So find the line in the file yourtablename_view.php that looks like this:
Code: Select all
if(!$headerCode){
include_once("$currDir/headerinci.php"); //changes made here
}else{
ob_start(); include_once("$currDir/header.php"); $dHeader=ob_get_contents(); ob_end_clean();
echo str_replace('<%%HEADER%%>', $dHeader, $headerCode);
}
In the above you can see where I
added inci after header and before .php
This will insure the correct header file is loaded. (Yes I know I can do this with hooks but at this point I needed to do it this way for cheap and dirty reasons).
Then see my previous post in this thread and also add in the code function ajaxFunction.... as described in that post.
I know this is probably clear as mud but I am doing it between taking breaks from doing the work for my client. Hope this works for someone. My app is up and running and starting tomorrow it is going live. All of this works and has passed the necessary tests today by the client. Refinements and making pretty start tomorrow.
Enjoy (and I hope it is able to be understood but if not....)
Any questions just ask.
Alan