Difference between revisions of "SAM V2:customization"

From AMACWiki
Jump to: navigation, search
(How to Add a Field to a Table and Form)
(How to Add a Field to a Table and Form)
Line 150: Line 150:
 
</pre>
 
</pre>
  
8.  In the samv2 directory, the programs dbadd.php and dbsave.php need to be changed to write the field to database.  In each you would modify the case statement for disabilities as this is the table you are working with.  You must create a variable $evaluator_name would would be set equal to $_POST[‘evaluator_name’] as this is the name of the HTML input field in add.php and edit.php.  In dbadd.php, modify the $sql variable and update the INSERT statement to include evaluator_name.  
+
8.  In the samv2 directory, the programs dbadd.php and dbsave.php need to be changed to write the field to database.  In each you would modify the case statement for disabilities as this is the table you are working with.  You must create a variable $evaluator_name would would be set equal to $_POST[‘evaluator_name’] as this is the name of the HTML input field in add.php and edit.php.  In dbadd.php, modify the $sql variable and update the INSERT statement to include evaluator_name.  In dbsave.php, modify the $sql variable and update the UPDATE statement to include evaluator_name.
  
 
<pre>
 
<pre>
Line 169: Line 169:
 
   break;
 
   break;
 
</pre>
 
</pre>
 
In dbsave.php, modify the $sql variable and update the UPDATE statement to include evaluator_name.
 
  
 
<pre>
 
<pre>

Revision as of 13:36, 17 May 2011

Since SAM V2 is open-source software, it is easily customized with a working knowledge of HTML, PHP, MySQL, and the SAM source code/database structure.

Tables Names and Directory Structure

  Table Name Subdirectory Name
Student students student
Disabilities disabilities disability
Accommodations accommodations accommodation
Consents consent_types consent
Referrals referrals referral
Case Notes case_notes case
Tasks tasks task
Documentation documentation doc
Tests tests test
Class Schedules class_schedules schedule
Orders orders order

How to Add a Field to a Table and Form

1. Add the field to the underlying table in MySQL. For example, to add a field called evaluator_name to the disabilities table, you would execute a SQL statement similar to:

alter table disabilities add column evaluator_name varchar(50) … 

Or you could use the MySQL workbench to alter the table.

2. In the disability subdirectory, you will need to modify the programs add.php, edit.php, view.php, and list.php to handle the new evaluator_name field.

3. In add.php, you would add a table row for the new field with 2 table columns, one for the field label, and one for the input of the value for evaluator_name.

<tr>
   <td align="right"><label for="evaluator_name"><strong>Evaluator Name</strong></label></td>
   <td>
      <input type="text" name="evaluator_name" />
   </td>
</tr>

4. If the field requires validation, then the validateForm javascript function should be modified to perform validation. For example, to make the evaluator_name field required, add:

if(theForm.evaluator_name.value == "") {
   alert('Please enter a value for the "Evaluator Name" field.');
   theForm.evaluator_name.focus();
   return (false);
}

5. In edit.php, the same changes made to add.php must be made. In addition, a variable must be created called $evaluator_name that reads the $row[‘evaluator_name’] returned in $results and this variable should be displayed as the value for the HTML input field for evaluator_name.

<?php 
if (isset($i)) {
   $result = mysql_query("SELECT * FROM disabilities WHERE uid = '$i'");
   $row = mysql_fetch_array($result);
   $sid = $row['sid'];
   $disability = $row['disability'];
   $specification = $row['specification'];
   $type = $row['type'];
   $evaluator_name = $row['evaluator_name'];
   ...
?>
...
<tr>
   <td align="right"><label for="evaluator_name"><strong>Evaluator Name</strong></label></td>
   <td>
      <input type="text" name="evaluator_name" value="<?php echo $evaluator_name; ?>" />
   </td>
</tr>

6. In view.php, a variable must be created called $evaluator_name that reads the $row[‘evaluator_name’] returned in $results. This is the same change made in edit.php detailed in step 5. A table row for the new field needs to be created with 2 table columns, one for the label and one to display the $evaluator_name field without allowing input.

<tr>  
   <td align="right"><strong>Evaluator Name</strong></td>
   <td bgcolor="#f0f0f0"><?php echo $evaluator_name; ?></td>
</tr>

7. If the field should be displayed in the default list view, then list.php should be modified to select the field in the MySQL query into $result. The display table should have to be modified to add a <th> column for Evaluator Name, display $row[‘evaluator_name’], and increase the results colspan by 1.

echo "<table class='size8'><tr><th>view</th><th>Disability</th><th>Specification</th><th>Type</th><th>Expiration Date</th><th>Evaluator Name</th></tr>";
$result = mysql_query("SELECT uid, disability, specification, type, expiration, evaluator_name FROM disabilities WHERE sid = '$i' ORDER BY disability");
$i = 0;
while($row = mysql_fetch_array($result)) {
   $i += 1;
   if($i % 2 == 0) {         $c = '#f0f0f0';
   }
   else { 
      $c = '#ffffff';
   }      $expiration = $row['expiration'];      if($expiration!="") {
      $expiration = substr($expiration,5,2) . '-' . substr($expiration,8,2) . '-' . substr($expiration,0,4);
   }
   echo "<tr bgcolor=".$c."><td><a href='disability.php?a=view&i=" . $row['uid'] . "'>view</a></td><td>" . $row['disability'] . "</td><td>" . 
$row['specification'] . "</td><td>" . $row['type'] . "</td><td>". $expiration . "</td><td>" . $row['evaluator_name'] . "</td></tr>";
}
echo "<tr><td colspan='6'>Results ".$i;

8. In the samv2 directory, the programs dbadd.php and dbsave.php need to be changed to write the field to database. In each you would modify the case statement for disabilities as this is the table you are working with. You must create a variable $evaluator_name would would be set equal to $_POST[‘evaluator_name’] as this is the name of the HTML input field in add.php and edit.php. In dbadd.php, modify the $sql variable and update the INSERT statement to include evaluator_name. In dbsave.php, modify the $sql variable and update the UPDATE statement to include evaluator_name.

case 'disabilities':
   $disability = $_POST['disability'];
   $specification = $_POST['specification'];
   $type = $_POST['type'];
   $expiration = $_POST['expiration'];
   $evaluator_name = $_POST['evaluator_name'];
   $notes = $_POST['notes'];
   $sql = "INSERT INTO disabilities (sid, disability, specification, type, expiration, evaluator_name, notes, updated_by) VALUES ('$i', '$disability', '$specification', '$type', ";
   if($expiration=="") {
      $sql = $sql . "NULL";
   } else {
      $sql = $sql . "str_to_date('$expiration','%m-%d-%Y')";
   }
   $sql = $sql . ", '$evaluator_name', '$notes', '$_SESSION[username]')";
   break;
case 'disabilities':
   $disability = $_POST['disability'];
   $specification = $_POST['specification'];
   $type = $_POST['type'];
   $expiration = $_POST['expiration'];
   $evaluator_name = $_POST['evaluator_name'];
   $notes = $_POST['notes'];
   $sql = "UPDATE disabilities SET disability = '$disability', specification = '$specification', type = '$type', expiration = ";
   if($expiration=="") {
      $sql = $sql . "NULL";
   } else {
      $sql = $sql . "str_to_date('$expiration','%m-%d-%Y')";
   }
   $sql = $sql . ", evaluator_name = '$evaluator_name', notes = '$notes', last_updated = now(), updated_by = '$_SESSION[username]' WHERE uid = '$i'";
   break;