Location: PHPKode > projects > PhpMyInventory > pmi281/admin_software_types.php
  checkPermissions(1, 1800);

// Has the form been submitted
if ($btnSubmit) {
    $strManufacturer  = validateText("Manufacturer", $txtManufacturer, 2, 50, TRUE, FALSE);
    $strName          = validateText("Product Name", $txtName, 2, 50, TRUE, FALSE);
    $strVersion       = validateText("Version", $txtVersion, 1, 20, TRUE, FALSE);
    $strLicense       = cleanFormInput($radLicense);
    If ($strLicense) {
        $requireNumLicenses = TRUE;
    $intLicenses      = validateNumber("# of Licenses", $txtLicenses, 1, 10, $requireNumLicenses);
    If ($intLicenses AND !$strLicense) {
        fillError("Please select a license type to describe your # of licenses.");
    $bolOS            = validateChoice("Operating System (yes/no)", $radOS);
    $bolMovable       = validateChoice("Can Be Reassigned (yes/no)", $radMovable);

    // are required fields were filled out
    if  (!$strError) {
        // Pick the proper sql statement to query the database
        if ($type_id) {
            $strSQL = "UPDATE software_types SET Name='$strName',Maker='$strManufacturer',
              licenseType=".makeNull($strLicense, TRUE).", numLicenses=".makeNull($intLicenses)."
              WHERE accountID=$accountID AND id=$type_id";
            $strError = "Record updated successfully.";
        } else {
            $strSQL = "INSERT INTO software_types (Name,Maker,Version,operatingSystem,canBeMoved,
              licenseType,numLicenses,accountID) VALUES ('$strName','$strManufacturer','$strVersion',
              '$bolOS','$bolMovable',".makeNull($strLicense, TRUE).",".makeNull($intLicenses).",$accountID)";
            $strError = "Record created successfully.";
        $result = dbquery($strSQL);

        $type_id          = "";
        $strManufacturer  = "";
        $strName          = "";
        $strVersion       = "";
        $strLicense       = "";
        $intLicenses      = "";
        $bolOS            = "";
        $bolMovable       = "";

// If we are deleting, delete the softwares tied to the asset
} elseif ($delete AND $sessionSecurity < 1) {

  $strSQL = "DELETE FROM software WHERE type_id=$type_id AND accountID=$accountID";
  // do the delete
  $result = dbquery($strSQL);

  $strSQL = "DELETE FROM software_types WHERE id=$type_id AND accountID=$accountID";
  $result = dbquery($strSQL);

  $strError = "Record deleted successfully.";

// If you're editing load the vars
if ($type_id) {

  $strSQL = "SELECT * FROM software_types WHERE id=$type_id AND accountID=$accountID";
  $result = dbquery($strSQL);

  $this            = mysql_fetch_array($result);

  $type_id         = $this["id"];
  $strName         = $this["Name"];
  $strManufacturer = $this["Maker"];
  $strVersion      = $this["Version"];
  $bolOS           = $this["operatingSystem"];
  $bolMovable      = $this["canBeMoved"];
  $strLicense      = $this["licenseType"];
  $intLicenses     = $this["numLicenses"];

if ($type_id) {
    $titlePrefix = "Edit";
    $addInstead = "&nbsp; (<a href='admin_software_types.php'>Add new type</a>)";
} else {
    $titlePrefix = "Add";

writeHeader("$titlePrefix a Software Type");
<table border='0' cellpadding='4' cellspacing='0'>
  <tr><td colspan='2'><i>Explanation of Software Type Attributes</i>:</td></tr>
    <td width='122' valign='top'><u>License Type</u></td>
    <td>Software often comes with a "license" - this explicitly states how many people or systems
        are legally entitled to use the software, based on the amount you paid for it. A <i>Per User</i> 
        license is one that limits how many people can use the software; a "Per System" license limits
        how many systems the software may be installed on. Note: If your license allows you to use this 
        software with no limits, simply disregard the "license type" and "# of license" attributes.</td>
    <td width='122' valign='top'><u># of Licenses</u></td>
    <td>If you indicate that a software type has a <i>Per User</i> or <i>Per System</i> license, 
        you must state how many licenses you own. PMI will then prompt you if you ever reach
        your license limit (or exceed it), based on the type and number of licenses.</td>
    <td width='122' valign='top'><u>Operating System</u></td>
    <td>Software that is categorized as an "operating system" will usually appear at the top
        of software lists in your inventory. The <a href='admin_hardware.php'>add system</a> page 
        also has a special interface for adding operating systems, to save you time.</td>
    <td width='122' valign='top'><u>Can Be Reassigned</u></td>
    <td>Selecting <i>No</i> for "Can Be Reassigned" prevents software of this type from being moved 
from the system it is first assigned to. This is useful when a software license agreement does not allow 
software to be used with any system other than the one it was purchased for. You can undo the restriction 
later on, simply by updating the software type and changing the answer to <i>Yes</i>.</td>

<font color='ff0000'>*</font> Indicates a required field.<p>

<FORM METHOD="post" ACTION="<? echo $PHP_SELF?>">
 <table border='0' cellpadding='3' cellspacing='0' width='430'>
    <td width='135'><font color='ff0000'>*</font> Manufacturer:
      <INPUT TYPE="hidden" NAME="type_id" VALUE="<? echo $type_id; ?>">
    <td width='300'><INPUT SIZE="30" MAXLENGTH="50" TYPE="Text" NAME="txtManufacturer" VALUE="<? echo antiSlash($strManufacturer); ?>"></td>
    <td width='135'><font color='ff0000'>*</font> Product Name:</td>
    <td width='300'><INPUT SIZE="30" MAXLENGTH="50" TYPE="Text" NAME="txtName" VALUE="<? echo antiSlash($strName); ?>"></td>
    <td width='135'><font color='ff0000'>*</font> Version:</td>
    <td width='300'><INPUT SIZE="10" MAXLENGTH="20" TYPE="Text" NAME="txtVersion" VALUE="<? echo antiSlash($strVersion); ?>"></td>
    <td width='135'>License Type:</td>
    <td width='300'>
      <INPUT TYPE="radio" NAME="radLicense" VALUE="peruser" <?=writeChecked("peruser", $strLicense);?>> Per User 
      <INPUT TYPE="radio" NAME="radLicense" VALUE="persystem" <?=writeChecked("persystem", $strLicense);?>> Per System
    <td width='135'># of Licenses:</td>
    <td width='300'><INPUT SIZE="7" MAXLENGTH="10" TYPE="Text" NAME="txtLicenses" VALUE="<? echo antiSlash($intLicenses); ?>"></td>
    <td width='135'><font color='ff0000'>*</font> Operating System?</td>
    <td width='300'>
      <INPUT TYPE="radio" NAME="radOS" VALUE="1" <?=writeChecked("1", $bolOS);?>> Yes 
      <INPUT TYPE="radio" NAME="radOS" VALUE="0" <?=writeChecked("0", $bolOS);?>> No
    <td width='135'><font color='ff0000'>*</font> Can Be Reassigned?</td>
    <td width='300'>
      <INPUT TYPE="radio" NAME="radMovable" VALUE="1" <?=writeChecked("1", $bolMovable);?>> Yes 
      <INPUT TYPE="radio" NAME="radMovable" VALUE="0" <?=writeChecked("0", $bolMovable);?>> No

  <tr><td colspan='2'>&nbsp;</td></tr>

  <tr><td colspan='2'><INPUT TYPE="submit" NAME="btnSubmit" VALUE="Enter Information">&nbsp;</td></tr>

  // display all known software types
  echo "<b>Software Types in Inventory</b> $addInstead<p>";
  $hw = "SELECT * FROM software_types WHERE accountID=$accountID ORDER BY Maker ASC";
  $sql = dbquery($hw);
  $results = mysql_num_rows($sql);

  if ($results > 0) {
  <table border='0' cellpadding='4' cellspacing='0'>
  <TR class='title'>
     <TD><b>Manufacturer</b> &nbsp; </TD>
     <TD><b>Name</b> &nbsp; </TD>
     <TD><b>Version</b> &nbsp; </TD>
     <TD><b>Action</b> &nbsp; </TD></TR>
    while ($result = mysql_fetch_array($sql)) {
      $type_id    = $result['id'];
      $strName    = $result['Name'];
      $strMaker   = $result['Maker'];
      $strVersion = $result['Version'];
<TR class='<? echo alternateRowColor(); ?>'>
    <TD><? echo $strMaker; ?> &nbsp; </TD>
    <TD><? echo $strName; ?> &nbsp; </TD>
    <TD><? echo $strVersion; ?>&nbsp; </TD>
       <A HREF="admin_software_types.php?type_id=<? echo $type_id; ?>">Edit</A>
<? If ($sessionSecurity < 1) { ?>
       <A HREF="admin_software_types.php?type_id=<? echo $type_id; ?>&delete=yes" onClick="return warn_on_submit('Are you sure you want to delete this software type? All instances of it will disappear (permanently) from the database.');">Delete</A>
<? } ?>
  echo "</table>";

Return current item: PhpMyInventory