-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpersonadd.php
35 lines (35 loc) · 860 Bytes
/
personadd.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
include '../../core/inc.php';
include 'db/cognizdb.php';
function depunctuate($str){
$pattern = '/(\'|\&)/';
$replace = '_';
$out = preg_replace($pattern, $replace, $str);
$pattern = '/(\+)/';
$replace = '';
$out = preg_replace($pattern, $replace, $out);
return $out;
}
function insert_person($name,$ins,$db){
$id = strtolower($name);
$id = depunctuate($id);
$id = str_replace(' ','-',$id);
$name = str_replace('+','',$name);
$checksum = hash("crc32b", $name.'+'.$ins.'+'.time());
$id = $id.'-'.$checksum;
$up = "INSERT IGNORE INTO persons (id, name, ins) VALUES (?,?,?)";
$i_p = $db->prepare($up);
$i_p->execute(array($id,$name,$ins));
}
$q = $_GET['q'] ?? '';
$g = explode('|', $q);
if ($g[0] && $g[1]){
$n = $g[0];
$i = $g[1];
if(strstr($n,',')||strstr($n,', ')){
$l = explode(',',$n);
$n = ltrim($l[1]).' '.$l[0];
}
insert_person($n,$i,$cdb);
}
?>