Location: PHPKode > projects > PhpMyInventory > pmi281/Includes/userFunctions.inc.php
<?
  # functions.inc.php *must* be included in a page before this file.

  Function buildUserSelect($intUserID, $showSpare, $intObjectID="", $forceIndependent="") {
      global $accountID;
      # $strSQL   = "SELECT count(*) FROM tblSecurity";
      # $result   = dbquery($strSQL);
      # $row      = mysql_fetch_row($result);
      # $numUsers = $row[0];
      # mysql_free_result($result);

      # If ($numUsers > 70) {

      # } Else {
           If ($intObjectID == "") {
               $strSQL = "SELECT id, firstName, middleInit, lastName FROM tblSecurity WHERE accountID=$accountID ORDER BY lastName";
               $spareText = "system";
           } Else {
               $strSQL = "SELECT DISTINCT s.id, s.firstName, s.middleInit, s.lastName FROM hardware as h, tblSecurity as s ";
               $strSQL .= "WHERE s.id=h.userID AND s.accountID=$accountID";
               $spareText = "part";
           }
           $strReturnString = "<select name='cboUser' size='1'>\n";
           $strReturnString .= "<option value=''>&nbsp;</option>\n";
           if ($showSpare) {
                $strReturnString .= "<option value='spare'>** Make this a spare $spareText **</option>\n";
                if ($intObjectID == "" OR $forceIndependent) {
                    $strReturnString .= "<option value='independent'>** Make this an independent system **</option>\n";
                }
                $showDivider = TRUE;
           }
           if ($intObjectID != "") {
                $strSQLx = "SELECT count(*) FROM hardware WHERE sparePart='1' AND accountID=$accountID";
                $resultx = dbquery($strSQLx);
                $rowx = mysql_fetch_row($resultx);
                If ($rowx[0] > 0) {
                    $strReturnString .= "<option value='sparesystem'>** Assign to a spare system **</option>\n";
                    $showDivider = TRUE;
                }
                mysql_free_result($resultx);

                $strSQLx = "SELECT count(*) FROM hardware WHERE sparePart='2' AND accountID=$accountID";
                $resultx = dbquery($strSQLx);
                $rowx = mysql_fetch_row($resultx);
                If ($rowx[0] > 0) {
                    $strReturnString .= "<option value='independentSystem'>** Assign to an independent system **</option>\n";
                    $showDivider = TRUE;
                }
                mysql_free_result($resultx);
           }

           If ($showDivider) {
               $strReturnString .= "<option value=''>&nbsp;</option>\n";
           }

           $result = dbquery($strSQL);
           while ($row = mysql_fetch_array($result)) {
                $strReturnString .= "<option value='".$row['id']."' ".writeSelected($row['id'], $intUserID).">";
                $strReturnString .= buildName($row["firstName"], $row["middleInit"], $row["lastName"], 0);
                $strReturnString .= "</option>\n";
           }
           $strReturnString .= "</select>\n";
      # }
      Return $strReturnString;
  }

  Function buildSystemSelect($intUserID, $intSystemID) {
      global $accountID;
      If ($intUserID == "sparesystem") { # build list of all spare systems
          $strSQL = "SELECT ht.type_desc, h.serial_num, h.pk_asset FROM hw_types as ht, hardware as h
            WHERE h.sparePart='1' AND h.type=ht.type_pk AND ht.accountID=$accountID
            ORDER BY ht.type_desc ASC";
      } ElseIf ($intUserID == "independentSystem") { # build list of all independent systems
          $strSQL = "SELECT ht.type_desc, h.serial_num, h.pk_asset FROM hw_types as ht, hardware as h
            WHERE h.sparePart='2' AND h.type=ht.type_pk AND ht.accountID=$accountID
            ORDER BY ht.type_desc ASC";
      } ElseIf ($intUserID != "") { # build list of all systems associated with userID
          $strSQL = "SELECT ht.type_desc, h.serial_num, h.pk_asset FROM hw_types as ht, hardware as h,
            tblSecurity as s WHERE s.id=h.userID AND h.type=ht.type_pk AND h.userID=$intUserID AND
            ht.accountID=$accountID ORDER BY ht.type_desc ASC";
      }
      
      If ($intUserID != "") {
          $result = dbquery($strSQL);

          $strReturnString = "<select name='cboSystem' size='1'>\n";
          $strReturnString .= "<option value=''>&nbsp;</option>\n";
          while ($row = mysql_fetch_array($result)) {
              $strReturnString .= "<option value='".$row['pk_asset']."' ".writeSelected($row['pk_asset'], $intSystemID).">";
              $strReturnString .= $row['type_desc']."&nbsp; - &nbsp;asset ID: ".$row['pk_asset']." &nbsp;-&nbsp; serial #: ".$row['serial_num'];
              $strReturnString .= "</option>\n";
          }
          $strReturnString .= "</select>\n";
          Return $strReturnString;
      }
  }

  // $intObjectID = the ID of target object, if anything OTHER than a system.
  Function buildUserSystemSelect($intUserID, $intSystemID, $intObjectID = "") {
      global $SCRIPT_NAME, $fromSystem, $spare;
      If (!$intUserID) {
            If ($fromSystem) {
                $showSpare = TRUE;
            }
            echo "Select a user:<p>";
            echo "<form method='post' action='$SCRIPT_NAME'>";
            echo buildUserSelect($intUserID, $showSpare, $intObjectID);
            echo "<input type='hidden' name='objectID' value='$intObjectID'>";
            echo "<input type='hidden' name='fromSystem' value='$fromSystem'>";
            echo "<input type='hidden' name='spare' value='$spare'>";
            echo "<p><input type='submit' value='Submit' name='btnSubmit1'>";
            echo "</form>";
      } ElseIf (!$intSystemID AND ($intUserID != "spare")) {
            echo "Select a system:<p>";
            echo "<form method='post' action='$SCRIPT_NAME'>";
            echo buildSystemSelect($intUserID, $intSystemID);
            echo "<input type='hidden' name='objectID' value='$intObjectID'>";
            echo "<input type='hidden' name='cboUser' value='$intUserID'>";
            echo "<input type='hidden' name='fromSystem' value='$fromSystem'>";
            echo "<input type='hidden' name='spare' value='$spare'>";
            echo "<p><input type='submit' value='Submit' name='btnSubmit2'>";
            echo "</form>";
      }
  }
?>
Return current item: PhpMyInventory