4 require('./connect.db.inc.php');
5 require_once('profil.func.inc.php');
7 $globals->debug
= 0; //do not store backtraces
10 function do_update_by_block($values)
12 // Update display_tel by block
13 // Because there is no mysql update syntax for multiple updates in one query
14 // we use a multiple insert syntax which will fail because the key already exist
15 // and then update the display_tel
16 XDB
::execute("INSERT INTO profile_phones (uid, link_type, link_id, tel_id ,tel_type,
17 search_tel, display_tel, pub, comment)
18 VALUES " . $values . "
19 ON DUPLICATE KEY UPDATE display_tel = VALUES(display_tel)");
22 $res = XDB
::query("SELECT DISTINCT phonePrefix
24 WHERE phonePrefix IS NOT NULL");
25 $prefixes = $res->fetchColumn();
26 foreach ($prefixes as $i => $prefix) {
27 $res = XDB
::query("SELECT phoneFormat
29 WHERE phonePrefix = {?} AND phoneFormat != '' LIMIT 1",
31 if ($res->numRows() > 0) {
32 $format = $res->fetchOneCell();
33 //Build regexp for mysql query
34 $len = strlen($format);
37 for ($i = 0; $i < $len; $i++
) {
52 //Appends the char after escaping it if necessary
53 $escape = array('[', ']', '{', '}', '(', ')', '*', '+', '?', '.', '^', '$', '|', '\\');
54 if (in_array($char, $escape)) {
55 $regexp .= '[' . $char . ']';
61 //allows additionnal spaces and numbers
64 for ($i = 0; $i < $nbPar; $i++
) {
68 $res = XDB
::iterator("SELECT uid, link_type, link_id, tel_id, tel_type, search_tel,
69 display_tel, pub, comment
71 WHERE search_tel LIKE {?} AND display_tel NOT REGEXP {?}",
72 $prefix . '%', $regexp);
73 if ($res->numRows() > 0)
75 //To speed up the update of phone numbers, theses updates are grouped by block of 1000
78 while ($phone = $res->next()) {
79 $disp = format_display_number($phone['search_tel'], $error, array('format' => $format, 'phoneprf' => $prefix));
83 $values .= "('" . addslashes($phone['uid']) . "', '" . addslashes($phone['link_type'])
84 . "', '" . addslashes($phone['link_id'])
85 . "', '" . addslashes($phone['tel_id']) . "', '" . addslashes($phone['tel_type'])
86 . "', '" . addslashes($phone['search_tel']) . "', '" . addslashes($disp)
87 . "', '" . addslashes($phone['pub']) . "', '" . addslashes($phone['comment']) . "')";
90 do_update_by_block($values);
96 do_update_by_block($values);
102 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: