Esempio n. 1
0
function find_similar_addresses(&$info, &$address)
{
    $addressObj = new address($info['database']);
    $addressObj->group_id = $info['group'];
    $addressObj->street1 = $address['street1'];
    $addressObj->city = $address['city'];
    $address_data = $addressObj->Find();
    //$addresses_result = query("SELECT * FROM `".$info['database']."`.address_book WHERE street1 = '".$address['street1']."' AND city = '".$address['city']."' AND group_id = '".$info['group']."'");
    $found_similar = false;
    if ($address_data != 0) {
        foreach ($address_data as $address_result) {
            if ($address_result['name'] == $address['name']) {
                $found_similar = true;
                $address['id'] = $address_result['id'];
            }
        }
    }
    return $found_similar;
}
Esempio n. 2
0
 function autocomplete()
 {
     $data = "";
     if ($_POST['type'] == 'source') {
         $param = $_POST["term"];
         switch ($_POST['dest']) {
             case 'address':
                 $address = new address($this->user['database']);
                 $address->group_id = $this->user['group'];
                 $address->name = $param;
                 $result = $address->Find();
                 $i = 0;
                 if (count($result)) {
                     foreach ($result as $row) {
                         $name = $row['name'];
                         $city = $row['city'];
                         $add_id = $row['id'];
                         $data[$i] = array("id" => $i, "value" => $name, "label" => $name . " (" . $city . ")", "add_id" => $add_id);
                         $i++;
                     }
                 }
                 break;
             case 'province':
                 $auto_xml = file_get_contents($this->user['folder'] . "/templates/autocomplete.xml");
                 $xml = new SimpleXMLElement($auto_xml);
                 $param = strtolower($param);
                 $auto_data = $xml->province->{$_POST}['mod']->xpath("*[contains(translate(text(), 'ABCDEFGHJIKLMNOPQRSTUVWXYZ', 'abcdefghjiklmnopqrstuvwxyz'),'" . $param . "') or \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t contains(translate(name(), 'ABCDEFGHJIKLMNOPQRSTUVWXYZ', 'abcdefghjiklmnopqrstuvwxyz'),'" . $param . "')]");
                 $i = 0;
                 foreach ($auto_data as $prov) {
                     $data[$i] = array("id" => $i, "value" => $prov->getName(), "label" => $prov->getName() . " (" . $prov . ")");
                     $i++;
                 }
                 break;
         }
     } else {
         switch ($_POST['dest']) {
             case 'address':
                 $id_array = explode('_', $_POST['input_id']);
                 $id = "#" . $id_array[0] . '_' . $id_array[1] . '_';
                 $address = new address($this->user['database'], $_POST['add_id']);
                 $row = $address->toArray();
                 $addressData = array();
                 foreach ($row as $key => $value) {
                     if ($key == 'province') {
                         $addressData[$id . 'province'] = $value;
                     } else {
                         $addressData[$id . $key] = $value;
                     }
                 }
                 $data = array("data" => $addressData);
                 break;
         }
     }
     echo json_encode($data);
 }