Ejemplo n.º 1
0
 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 agentlinksid FROM agentlinks {$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 agentlinks();
             $obj->load($ids[$i]);
             $returnvalue[] = $obj;
             $result = true;
         }
         if ($result === false) {
             $this->error = mysqli_error($this->conn);
         }
     }
     return $returnvalue;
 }
Ejemplo n.º 2
0
function deleteAgentLinks($agentlinksid = NULL)
{
    global $clientRoot;
    $result = "";
    $am = new AgentManager();
    if ($am->isAgentEditor()) {
        if (strlen($agentlinksid) > 0) {
            $toDelete = new agentlinks();
            $toDelete->setagentlinksid($agentlinksid);
            if ($toDelete->delete()) {
                $result = "Deleted.";
            } else {
                $result = "Error in deleting agent links record. " . $toDelete->errorMessage();
            }
        } else {
            $result = "No agent links specified to delete.";
        }
    } else {
        $result = "You aren't authorized to edit agent records.";
    }
    return $result;
}