コード例 #1
0
ファイル: AgentManager.php プロジェクト: Symbiota/Symbiota
 public function loadArrayKeyValueSearch($searchTermArray)
 {
     $returnvalue = array();
     $and = '';
     $wherebit = 'WHERE ';
     foreach ($searchTermArray as $fieldname => $searchTerm) {
         if ($this->hasField($fieldname)) {
             $operator = '=';
             // change to a like search if a wildcard character is present
             if (!(strpos($searchTerm, '%') === false)) {
                 $operator = 'like';
             }
             if (!(strpos($searchTerm, '_') === false)) {
                 $operator = 'like';
             }
             if ($searchTerm == '[NULL]') {
                 $wherebit .= "{$and} ({$fieldname} is null or {$fieldname}='') ";
             } else {
                 $wherebit .= "{$and} {$fieldname} {$operator} ? ";
                 $types = $types . $this->MySQLiFieldType($fieldname);
             }
             $and = ' and ';
         }
     }
     $sql = "SELECT agentteamid FROM agentteams {$wherebit}";
     if ($wherebit == '') {
         $this->error = 'Error: No search terms provided';
     } else {
         $statement = $this->conn->prepare($sql);
         $vars = array();
         $vars[] = $types;
         $i = 0;
         foreach ($searchTermArray as $value) {
             $varname = 'bind' . $i;
             // create a variable name
             ${$varname} = $value;
             // using that variable name store the value
             $vars[] =& ${$varname};
             // add a reference to the variable to the array
             $i++;
         }
         //$vars[] contains $types followed by references to variables holding each value in $searchTermArray.
         call_user_func_array(array($statement, 'bind_param'), $vars);
         //$statement->bind_param($types,$names);
         $statement->execute();
         $statement->bind_result($id);
         $ids = array();
         while ($statement->fetch()) {
             $ids[] = $id;
         }
         // double loop to allow all data to be retrieved before preparing a new statement.
         $statement->close();
         for ($i = 0; $i < count($ids); $i++) {
             $obj = new agentteams();
             $obj->load($ids[$i]);
             $returnvalue[] = $obj;
             $result = true;
         }
         if ($result === false) {
             $this->error = mysqli_error($this->conn);
         }
     }
     return $returnvalue;
 }
コード例 #2
0
ファイル: handler.php プロジェクト: Symbiota/Symbiota
function deleteAgentTeams($agentteamid = NULL)
{
    global $clientRoot;
    $result = "";
    $am = new AgentManager();
    if ($am->isAgentEditor()) {
        if (strlen($agentteamid) > 0) {
            $toDelete = new agentteams();
            $toDelete->setagentteamid($agentteamid);
            if ($toDelete->delete()) {
                $result = "Deleted.";
            } else {
                $result = "Error in deleting agent team record. " . $toDelete->errorMessage();
            }
        } else {
            $result = "No agent teams specified to delete.";
        }
    } else {
        $result = "You aren't authorized to edit agent records.";
    }
    return $result;
}