Difference between revisions of "SAM V2:customization"

From AMACWiki
Jump to: navigation, search
(Blanked the page)
 
Line 1: Line 1:
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 border="1">
 
<tr>
 
<th>&nbsp;</th>
 
<th>Table Name</th>
 
<th>Subdirectory Name</th>
 
</tr>
 
<tr>
 
<td>Student</td>
 
<td>students</td>
 
<td>student</td>
 
</tr>
 
<tr>
 
<td>Disabilities</td>
 
<td>disabilities</td>
 
<td>disability</td>
 
</tr>
 
<tr>
 
<td>Accommodations</td>
 
<td>accommodations</td>
 
<td>accommodation</td>
 
</tr>
 
<tr>
 
<td>Consents</td>
 
<td>consent_types</td>
 
<td>consent</td>
 
</tr>
 
<tr>
 
<td>Referrals</td>
 
<td>referrals</td>
 
<td>referral</td>
 
</tr>
 
<tr>
 
<td>Case Notes</td>
 
<td>case_notes</td>
 
<td>case</td>
 
</tr>
 
<tr>
 
<td>Tasks</td>
 
<td>tasks</td>
 
<td>task</td>
 
</tr>
 
<tr>
 
<td>Documentation</td>
 
<td>documentation</td>
 
<td>doc</td>
 
</tr>
 
<tr>
 
<td>Tests</td>
 
<td>tests</td>
 
<td>test</td>
 
</tr>
 
<tr>
 
<td>Class Schedules</td>
 
<td>class_schedules</td>
 
<td>schedule</td>
 
</tr>
 
<tr>
 
<td>Orders</td>
 
<td>orders</td>
 
<td>order</td>
 
</tr>
 
</table>
 
 
==How to Add a Field to a Table and Form==
 
 
'''For purposes of this example, a field called evaluator_name will be added to the documentation table and user interface.  This general process can be followed to add any field to any table.  The only changes would be the field name, table name, and subdirectory used.'''
 
 
1. Add the field to the underlying table in MySQL.  For example, to add a field called evaluator_name to the documentation table, you would execute a SQL statement similar to:
 
 
<pre>alter table documentation add column evaluator_name varchar(50) … </pre>
 
 
Or you could use the MySQL workbench to alter the table.
 
 
2. In the doc 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.
 
 
<pre>
 
<tr>
 
  <td align="right"><label for="evaluator_name"><strong>Evaluator Name</strong></label></td>
 
  <td>
 
      <input type="text" name="evaluator_name" />
 
  </td>
 
</tr>
 
</pre>
 
 
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:
 
 
<pre>
 
if(theForm.evaluator_name.value == "") {
 
  alert('Please enter a value for the "Evaluator Name" field.');
 
  theForm.evaluator_name.focus();
 
  return (false);
 
}
 
</pre>
 
 
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.
 
 
<pre>
 
<?php
 
if (isset($i)) {
 
  $result = mysql_query("SELECT sid, filename, notes, evaluator_name FROM documentation WHERE uid = '$i'");
 
  $row = mysql_fetch_array($result);
 
  $sid = $row['sid'];
 
  $filename = $row['filename'];
 
  $notes = $row['notes'];
 
  $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>
 
</pre>
 
 
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.
 
 
<pre>
 
<tr> 
 
  <td align="right"><strong>Evaluator Name</strong></td>
 
  <td bgcolor="#f0f0f0"><?php echo $evaluator_name; ?></td>
 
</tr>
 
</pre>
 
 
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.
 
 
<pre>
 
echo "<table class='size8'><tr><th>view</th><th>Document</th><th>Evaluator Name</th></tr>";
 
$result = mysql_query("SELECT uid, filename, evaluator_name FROM documentation WHERE sid = '$i' ORDER BY filename");
 
$i = 0;
 
while($row = mysql_fetch_array($result)) {
 
  $i += 1;
 
  if($i % 2 == 0) {
 
      $c = '#f0f0f0';
 
  }
 
  else {
 
      $c = '#ffffff';
 
  }
 
  echo "<tr bgcolor=".$c."><td><a href='doc.php?a=view&i=" . $row['uid'] . "'>view</a></td>
 
<td><a href=\"dbdownload.php?t=documentation&i=" . $row['uid'] . "\" target=\"_download\">". $row['filename'] . "</a></td><td>" . $row['evaluator_name'] . "</td></tr>";
 
}
 
echo "<tr><td colspan='3'>Results ".$i;
 
 
</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 documentation 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>
 
case 'documentation':
 
  $notes = $_POST['notes'];
 
  $evaluator_name = $_POST['evaluator_name'];
 
  if($_FILES['userfile']['size'] > 0) {
 
      $filename = $_FILES['userfile']['name'];
 
      $tmpname = $_FILES['userfile']['tmp_name'];
 
      $filesize = $_FILES['userfile']['size'];
 
      $filetype = $_FILES['userfile']['type'];
 
      $fp = fopen($tmpname, 'r');
 
      $content = fread($fp, filesize($tmpname));
 
      fclose($fp);
 
      $content = addslashes($content);
 
      if(!get_magic_quotes_gpc()) {
 
        $filename = addslashes($filename);
 
      }
 
      $sql = "INSERT INTO documentation (sid, filename, filesize, filetype, content, notes, evaluator_name, updated_by)
 
VALUES ('$i', '$filename', '$filesize', '$filetype', '$content', '$notes', '$evaluator_name', '$_SESSION[username]')";
 
  }
 
  break;
 
 
</pre>
 
 
<pre>
 
case 'documentation':
 
  $notes = $_POST['notes'];
 
  $evaluator_name = $_POST['evaluator_name'];
 
  if($_FILES['userfile']['size'] > 0) {
 
      $filename = $_FILES['userfile']['name'];
 
      $tmpname = $_FILES['userfile']['tmp_name'];
 
      $filesize = $_FILES['userfile']['size'];
 
      $filetype = $_FILES['userfile']['type'];
 
      $fp = fopen($tmpname, 'r');
 
      $content = fread($fp, filesize($tmpname));
 
      fclose($fp);
 
      $content = addslashes($content);
 
      if(!get_magic_quotes_gpc()) {
 
        $filename = addslashes($filename);
 
      }
 
      $sql = "UPDATE documentation SET filename = '$filename', filesize = '$filesize', filetype = '$filetype', content = '$content',
 
notes = '$notes', evaluator_name = '$evaluator_name', last_updated = now(), updated_by = '$_SESSION[username]' WHERE uid = '$i'";
 
  } else {
 
      $sql = "UPDATE documentation SET notes = '$notes', evaluator_name = '$evaluator_name', last_updated = now(),
 
updated_by = '$_SESSION[username]' WHERE uid = '$i'";
 
  }
 
  break;
 
</pre>
 
 
==How to Remove a Field from a Table and Form==
 
 
To remove a field, the reverse process as outlined above would be used.  The field would be dropped from the table in the MySQL schema, and all references to the field removed from the code in the add.php, edit.php, view.php, list.php, dbadd.php, and dbsave.php programs.
 
 
==How to Unrequire a Field==
 
 
To change the validation of a field (make a required field unrequired), the validation code in validateForm would be removed in the programs add.php and edit.php.  For example, to unrequire an attached document when adding or editing document records, change validateForm and remove the code:
 
 
<pre>
 
if(theForm.userfile.value == "") {
 
  alert('Please attach a file.');
 
  theForm.userfile.focus();
 
  return (false);
 
}
 
</pre>
 
 
==How to Modify the Accommodation Letters==
 
 
To edit the format of the accommodation letters, modify the programs notification.php and notification2.php.  In general requires editing the HTML table code that contains the letter verbiage.  Table rows and cells can be added for static text and a logo image can be added with the <img> tag.
 

Latest revision as of 10:50, 19 May 2015