3 require_once 'connect.db.inc.php';
5 //next two are required to include 'profil.func.inc.php'
6 require_once 'xorg.inc.php';
7 $page = new XorgPage(null
);
9 require_once 'profil.func.inc.php';
11 $globals->debug
= 0; //do not store backtraces
15 // Import from auth_user_quick
16 echo "\nImporting mobile phone numbers from auth_user_quick...\n";
17 $phones = XDB
::iterRow("SELECT user_id, profile_mobile_pub, profile_mobile FROM auth_user_quick WHERE profile_mobile <> ''");
18 while (list($uid, $pub, $phone) = $phones->next()) {
19 $fmt_phone = format_phone_number($phone);
22 $display = format_display_number($fmt_phone, $error);
23 if (!XDB
::execute("INSERT INTO telephone (uid, link_type, link_id, tel_id, tel_type, search_tel, display_tel, pub)
24 VALUES ({?}, 'user', 0, 0, 'mobile', {?}, {?}, {?})", $uid, $fmt_phone, $display, $pub)) {
25 echo "WARNING: insert of profile mobile phone number failed for user $uid.\n";
32 // Import from entreprises
33 echo "\nImporting professional phone numbers from entreprises...\n";
34 $phones = XDB
::iterator("SELECT uid, entrid, tel, fax, mobile, tel_pub FROM entreprises ORDER BY uid");
35 while ($row = $phones->next()) {
36 $request = "INSERT INTO telephone (uid, link_type, link_id, tel_id, tel_type, search_tel, display_tel, pub)
37 VALUES ({?}, 'pro', {?}, {?}, {?}, {?}, {?}, {?})";
38 $fmt_fixed = format_phone_number($row['tel']);
39 $fmt_mobile = format_phone_number($row['mobile']);
40 $fmt_fax = format_phone_number($row['fax']);
43 $disp_fixed = format_display_number($fmt_fixed, $error);
44 if (!XDB
::execute($request, $row['uid'], $row['entrid'], 0, 'fixed', $fmt_fixed, $disp_fixed, $row['tel_pub'])) {
45 echo 'WARNING: insert of professional fixed phone number failed for user ' . $row['uid'] . ' and entreprise ' . $row['entrid'] . ".\n";
49 if ($fmt_mobile != '')
51 $disp_mobile = format_display_number($fmt_mobile, $error);
52 if (!XDB
::execute($request, $row['uid'], $row['entrid'], 1, 'mobile', $fmt_mobile, $disp_mobile, $row['tel_pub'])) {
53 echo 'WARNING: insert of professional mobile number failed for user ' . $row['uid'] . ' and entreprise ' . $row['entrid'] . ".\n";
59 $disp_fax = format_display_number($fmt_fax, $error);
60 if (!XDB
::execute($request, $row['uid'], $row['entrid'], 2, 'fax', $fmt_fax, $disp_fax, $row['tel_pub'])) {
61 echo 'WARNING: insert of professional fax number failed for user ' . $row['uid'] . ' and entreprise ' . $row['entrid'] . ".\n";
69 echo "\nImporting personnal phone numbers from tels...\n";
70 $phones = XDB
::iterator("SELECT uid, adrid, telid, tel_type, tel_pub, tel FROM tels");
71 $conversions = array();
73 while ($row = $phones->next()) {
74 $fmt_phone = format_phone_number($row['tel']);
75 if ($fmt_phone != '') {
76 $display = format_display_number($fmt_phone, $error);
77 $guess_type = guess_phone_type($row['tel_type'], $fmt_phone);
79 switch ($guess_type) {
83 if (!XDB
::execute("INSERT INTO telephone (uid, link_type, link_id, tel_id, tel_type, search_tel, display_tel, pub)
84 VALUES ({?}, 'address', {?}, {?}, {?}, {?}, {?}, {?})",
85 $row['uid'], $row['adrid'], $row['telid'], $guess_type, $fmt_phone, $display, $row['tel_pub'])) {
86 echo 'WARNING: insert of address phone number failed for user ' . $row['uid'] . ', address ' . $row['adrid']
87 . ' and telephone id ' . $row['telid'] . ".\n";
90 if ($row['tel_type'] == 'Autre') {
92 } else if (!isset($conversions[$row['tel_type']])) {
93 $conversions[$row['tel_type']] = $guess_type;
98 echo 'WARNING: conflict for user ' . $row['uid'] . ', address ' . $row['adrid']
99 . ' and telephone id ' . $row['telid'] . ': type = "' . $row['tel_type']
100 . '", number = "' .$fmt_phone . "\"\n";
105 echo 'WARNING: unknown phone type (' . $row['tel_type'] . ') for user ' . $row['uid'] . ', address ' . $row['adrid']
106 . ' and telephone id ' . $row['telid'] . "\n";
112 echo "\nSummary of automatic phone type conversion\n";
113 foreach ($conversions as $old => $new) {
114 echo "* $old => $new\n";
116 echo "There was also $autre_count conversions from old type 'Autre' to a new one determined by the phone number.\n";
122 echo "\n----------------------------------------------------------------------\n"
123 . " There is $warnings phone numbers that couldn't be imported.\n"
124 . " They need to be manually inserted.\n";
126 echo "\nAfter solving any import problem and checking automatic conversions,\n"
127 . "you can drop useless columns and tables by these requests:\n"
128 . "DROP TABLE IF EXISTS `tels`;\n"
129 . "ALTER TABLE `auth_user_quick` DROP COLUMN `profile_mobile`;\n"
130 . "ALTER TABLE `auth_user_quick` DROP COLUMN `profile_mobile_pub`;\n"
131 . "ALTER TABLE `entreprises` DROP COLUMN `tel`;\n"
132 . "ALTER TABLE `entreprises` DROP COLUMN `fax`;\n"
133 . "ALTER TABLE `entreprises` DROP COLUMN `mobile`;\n"
134 . "ALTER TABLE `entreprises` DROP COLUMN `tel_pub`;\n";
137 // auxilliary functions
139 function guess_phone_type($str_type, $phone)
141 $str_type = strtolower(trim($str_type));
143 // special case for phone type 'autre', guessing by phone number
144 if ($str_type == 'autre') {
145 if (substr($phone, 3) == '336') {
152 if ((strpos($str_type, 'mob') !== false
) ||
(strpos($str_type, 'cell') !== false
) ||
(strpos($str_type, 'port') !== false
)) {
153 if (substr($phone, 3) == '336' ||
substr($phone, 2) != '33') {
154 return 'mobile'; //for France check if number is a mobile one
159 if (strpos($str_type, 'fax') !== false
) {
160 if(substr($phone, 3) == '336') {
166 if ((strpos($str_type, 'fixe') !== false
) ||
(strpos($str_type, 'tél') !== false
) ||
(strpos($str_type, 'tel') !== false
)) {
167 if(substr($phone, 3) == '336') {
177 /* vim:set et sw=4 sts=4 ts=4: */