| | |
| | | 'gender', 'maidenname', 'spouse', 'email', 'phone', 'address', |
| | | 'birthday', 'anniversary', 'website', 'im', 'notes', 'photo'); |
| | | |
| | | const SEPARATOR = ','; |
| | | |
| | | |
| | | /** |
| | | * Object constructor |
| | |
| | | |
| | | if ($read_vcard) |
| | | $sql_arr = $this->convert_db_data($sql_arr); |
| | | else |
| | | $sql_arr['email'] = preg_split('/,\s*/', $sql_arr['email']); |
| | | else { |
| | | $sql_arr['email'] = explode(self::SEPARATOR, $sql_arr['email']); |
| | | $sql_arr['email'] = array_map('trim', $sql_arr['email']); |
| | | } |
| | | |
| | | // make sure we have a name to display |
| | | if (empty($sql_arr['name'])) { |
| | |
| | | |
| | | $where = $and_where = array(); |
| | | $mode = intval($mode); |
| | | $WS = ' '; |
| | | $AS = self::SEPARATOR; |
| | | |
| | | foreach ($fields as $idx => $col) { |
| | | // direct ID search |
| | | if ($col == 'ID' || $col == $this->primary_key) { |
| | | $ids = !is_array($value) ? explode(',', $value) : $value; |
| | | $ids = !is_array($value) ? explode(self::SEPARATOR, $value) : $value; |
| | | $ids = $this->db->array2list($ids, 'integer'); |
| | | $where[] = 'c.' . $this->primary_key.' IN ('.$ids.')'; |
| | | continue; |
| | |
| | | // fulltext search in all fields |
| | | else if ($col == '*') { |
| | | $words = array(); |
| | | foreach (explode(" ", self::normalize_string($value)) as $word) { |
| | | foreach (explode($WS, self::normalize_string($value)) as $word) { |
| | | switch ($mode) { |
| | | case 1: // strict |
| | | $words[] = '(' . $this->db->ilike('words', $word.' %') |
| | | . ' OR ' . $this->db->ilike('words', '% '.$word.' %') |
| | | . ' OR ' . $this->db->ilike('words', '% '.$word) . ')'; |
| | | $words[] = '(' . $this->db->ilike('words', $word . '%') |
| | | . ' OR ' . $this->db->ilike('words', '%' . $WS . $word . $WS . '%') |
| | | . ' OR ' . $this->db->ilike('words', '%' . $WS . $word) . ')'; |
| | | break; |
| | | case 2: // prefix |
| | | $words[] = '(' . $this->db->ilike('words', $word.'%') |
| | | . ' OR ' . $this->db->ilike('words', '% '.$word.'%') . ')'; |
| | | $words[] = '(' . $this->db->ilike('words', $word . '%') |
| | | . ' OR ' . $this->db->ilike('words', '%' . $WS . $word . '%') . ')'; |
| | | break; |
| | | default: // partial |
| | | $words[] = $this->db->ilike('words', '%'.$word.'%'); |
| | | $words[] = $this->db->ilike('words', '%' . $word . '%'); |
| | | } |
| | | } |
| | | $where[] = '(' . join(' AND ', $words) . ')'; |
| | |
| | | if (in_array($col, $this->table_cols)) { |
| | | switch ($mode) { |
| | | case 1: // strict |
| | | $where[] = $this->db->quoteIdentifier($col).' = '.$this->db->quote($val); |
| | | $where[] = '(' . $this->db->quoteIdentifier($col) . ' = ' . $this->db->quote($val) |
| | | . ' OR ' . $this->db->ilike($col, $val . $AS . '%') |
| | | . ' OR ' . $this->db->ilike($col, '%' . $AS . $val . $AS . '%') |
| | | . ' OR ' . $this->db->ilike($col, '%' . $AS . $val) . ')'; |
| | | break; |
| | | case 2: // prefix |
| | | $where[] = $this->db->ilike($col, $val.'%'); |
| | | $where[] = '(' . $this->db->ilike($col, $val . '%') |
| | | . ' OR ' . $this->db->ilike($col, $AS . $val . '%') . ')'; |
| | | break; |
| | | default: // partial |
| | | $where[] = $this->db->ilike($col, '%'.$val.'%'); |
| | | $where[] = $this->db->ilike($col, '%' . $val . '%'); |
| | | } |
| | | } |
| | | // vCard field |
| | |
| | | foreach (explode(" ", self::normalize_string($val)) as $word) { |
| | | switch ($mode) { |
| | | case 1: // strict |
| | | $words[] = '(' . $this->db->ilike('words', $word.' %') |
| | | . ' OR ' . $this->db->ilike('words', '% '.$word.' %') |
| | | . ' OR ' . $this->db->ilike('words', '% '.$word) . ')'; |
| | | $words[] = '(' . $this->db->ilike('words', $word . $WS . '%') |
| | | . ' OR ' . $this->db->ilike('words', '%' . $AS . $word . $WS .'%') |
| | | . ' OR ' . $this->db->ilike('words', '%' . $AS . $word) . ')'; |
| | | break; |
| | | case 2: // prefix |
| | | $words[] = '(' . $this->db->ilike('words', $word.'%') |
| | | . ' OR ' . $this->db->ilike('words', ' '.$word.'%') . ')'; |
| | | $words[] = '(' . $this->db->ilike('words', $word . '%') |
| | | . ' OR ' . $this->db->ilike('words', $AS . $word . '%') . ')'; |
| | | break; |
| | | default: // partial |
| | | $words[] = $this->db->ilike('words', '%'.$word.'%'); |
| | | $words[] = $this->db->ilike('words', '%' . $word . '%'); |
| | | } |
| | | } |
| | | $where[] = '(' . join(' AND ', $words) . ')'; |
| | |
| | | } |
| | | else { |
| | | $record += $sql_arr; |
| | | $record['email'] = preg_split('/,\s*/', $record['email']); |
| | | $record['email'] = explode(self::SEPARATOR, $record['email']); |
| | | $record['email'] = array_map('trim', $record['email']); |
| | | } |
| | | |
| | | return $record; |
| | |
| | | $key = $col; |
| | | if (!isset($save_data[$key])) |
| | | $key .= ':home'; |
| | | if (isset($save_data[$key])) |
| | | $out[$col] = is_array($save_data[$key]) ? join(',', $save_data[$key]) : $save_data[$key]; |
| | | if (isset($save_data[$key])) { |
| | | if (is_array($save_data[$key])) |
| | | $out[$col] = join(self::SEPARATOR, $save_data[$key]); |
| | | else |
| | | $out[$col] = $save_data[$key]; |
| | | } |
| | | } |
| | | |
| | | // save all e-mails in database column |
| | | $out['email'] = join(", ", $vcard->email); |
| | | $out['email'] = join(self::SEPARATOR, $vcard->email); |
| | | |
| | | // join words for fulltext search |
| | | $out['words'] = join(" ", array_unique(explode(" ", $words))); |
| | |
| | | function delete($ids, $force=true) |
| | | { |
| | | if (!is_array($ids)) |
| | | $ids = explode(',', $ids); |
| | | $ids = explode(self::SEPARATOR, $ids); |
| | | |
| | | $ids = $this->db->array2list($ids, 'integer'); |
| | | |
| | |
| | | function undelete($ids) |
| | | { |
| | | if (!is_array($ids)) |
| | | $ids = explode(',', $ids); |
| | | $ids = explode(self::SEPARATOR, $ids); |
| | | |
| | | $ids = $this->db->array2list($ids, 'integer'); |
| | | |
| | |
| | | function add_to_group($group_id, $ids) |
| | | { |
| | | if (!is_array($ids)) |
| | | $ids = explode(',', $ids); |
| | | $ids = explode(self::SEPARATOR, $ids); |
| | | |
| | | $added = 0; |
| | | $exists = array(); |
| | |
| | | function remove_from_group($group_id, $ids) |
| | | { |
| | | if (!is_array($ids)) |
| | | $ids = explode(',', $ids); |
| | | $ids = explode(self::SEPARATOR, $ids); |
| | | |
| | | $ids = $this->db->array2list($ids, 'integer'); |
| | | |