PDA

View Full Version : 4.1.0 Phonenumber field dont show 0



Peter Jonsson
September 17, 2012, 02:47 PM
So, i really want to use the new phonenumber field in 4.1.0 but i cant use it because it removes the 0 if i use 0 at the start of the phonenumber.

Tried to change the field to text but that makes the field broken. Are there any way of making it display the 0 if a 0 are used ?

(0589) 0786945 will look like this (589) 786945. Theres got to be a way around this.

Are Sweden the only country that can have zeros as a start of a phonenumber ?

Chris Brown
September 17, 2012, 10:19 PM
So, i really want to use the new phonenumber field in 4.1.0 but i cant use it because it removes the 0 if i use 0 at the start of the phonenumber.

Tried to change the field to text but that makes the field broken. Are there any way of making it display the 0 if a 0 are used ?

(0589) 0786945 will look like this (589) 786945. Theres got to be a way around this.

Are Sweden the only country that can have zeros as a start of a phonenumber ?

uk have zero at start of phone number aswell, but i havnt tried the new phone number field as yet

Morgan Bohman
September 18, 2012, 04:35 AM
I can confirm that it is not working with a zero in the beginning of the number.

Petrache Nicolae
September 18, 2012, 03:27 PM
i was told that this bug is fixed in the new version but seems is not....
Romania has all numbers with 0 as first number so we will have to wait for a real fix of this bug or still use the text fild wich was a "temporary solution till 4.1".

Steffen Buschkemper
September 19, 2012, 10:38 AM
Hi @ All

i think the better solution is the country phone code instead of 0 - e.g. for Germany +49 .
I will work on this solution for automatic fill in this country codes in the first field.

Best regards
Steffen

Morgan Bohman
September 19, 2012, 01:58 PM
@Steffen the zero we are talking about is the area code and in Sweden we use that all the time and it is common practise.

Steffen Buschkemper
September 19, 2012, 02:12 PM
Hi Morgan,

let me unterstand this. For example: the country code for Sweden is +46.
Please give me an example number.

Steffen Buschkemper
September 19, 2012, 02:17 PM
my examples for sweden

City: Alfta
Area Code: 271
Dialing Code: +46 271

Morgan Bohman
September 19, 2012, 02:21 PM
In Sweden for local call that would be 0271 - 123456

Steffen Buschkemper
September 19, 2012, 02:30 PM
Thats right and in germany also the same.
If you call in an local area e.g. sweden with +46 it will the same as 0.
You can also call as +46 271 123456 it is the same as 0271 - 123456.
In germany for example we have 0375 but i can also call with +49 375.
There will be no problems. Its an international standart.
You can test it in your country.

Morgan Bohman
September 19, 2012, 02:45 PM
Yes I know that this works, but people in Sweden, commonly, doesn't use that, in some companies yes. I don't wont to use that on my site as there should be a solution with the zero, most every web page has that.=)

Steffen Buschkemper
September 19, 2012, 02:49 PM
The Flynax team has implement the international standart. And i think thats great.
The Flynax Script has multilanguage and it is not only for local areas. If you make business in europe and has more users in many countries there will be this the best way.

Morgan Bohman
September 19, 2012, 03:30 PM
I think that this will follow the standard that are common in the region, as it is with i.e. Windows. There you could set locale. I will not do business in other countries but if one should place a listing from Germany, you could enter +4X as your country code and (xxx) for your area code, followed by your number.
So lets have a field which is included in the General Setup for the script where you could set your locale.

Steffen Buschkemper
September 19, 2012, 06:11 PM
Hi Morgan,

I cant give you a solution.
Sorry!

Morgan Bohman
September 19, 2012, 08:15 PM
Hi Steffen,
It's alright, thanks for trying.

Peter Jonsson
September 21, 2012, 05:52 PM
Well, someone(flynax) has to have an solution. How do other websites do ?

Mike
September 22, 2012, 10:04 AM
I have the solution: few changes to the code required.

Would you like me to post changes here? three files and two places in each file to change (5 lines in each place to change)

It's better if you submit a ticket with remark "to Mike, about 0 in phone" :)

Steffen Buschkemper
September 22, 2012, 11:30 AM
Hi Mike!
I have also a solution...
Let us see it is the same..

Open includes/classes/reefless.class.php

Find the function parsePhone at line 705



function parsePhone( $string = false, $field = false )
{
global $config, $lang;

preg_match('/(c:([0-9]+))?\|?(a:([0-9]+))?\|(n:([0-9]+))?\|?(e:([0-9]+))?/', $string, $matches);

if ( !$matches )
return false;

$out['code'] = $matches[2];
$out['area'] = $matches[4];
$out['number'] = $matches[6];
$out['ext'] = $matches[8];

if ( $field )
{
if ( $field['Opt1'] && $out['code'] )
{
$phone = '+'. $out['code'] .' ';
}
if ( $out['area'] )
{
$phone .= "({$out['area']}) ";
}
if ( $out['number'] )
{
$phone .= $this -> flStrSplit($out['number'], 4, '-');
}
if ( $field['Opt2'] && $out['ext'] )
{
$phone .= ' '. $lang['phone_ext_out'] . $out['ext'];
}
return $phone;
}

return $out;
}



and change it with this code



function parsePhone( $string = false, $field = false )
{
global $config, $lang;

preg_match('/(c:([0-9]+))?\|?(a:([0-9]+))?\|(n:([0-9]+))?\|?(e:([0-9]+))?/', $string, $matches);

if ( !$matches )
return false;

$out['code'] = $matches[2];
$out['area'] = $matches[4];
$out['number'] = $matches[6];
$out['ext'] = $matches[8];

if ( $field )
{
if ( $field['Opt1'] && $out['code'] )
{
$phone = '+'. $out['code'] .' ';
}
if ($field['Opt1'] && $out['code'])
{
$phone .= "({$out['area']}) ";
}
else
{
$phone = '(0' . "{$out['area']}) ";
}
if ( $out['number'] )
{
$phone .= $this -> flStrSplit($out['number'], 4, '-');
}
if ( $field['Opt2'] && $out['ext'] )
{
$phone .= ' '. $lang['phone_ext_out'] . $out['ext'];
}
return $phone;
}

return $out;
}

Steffen Buschkemper
September 22, 2012, 11:47 AM
Open in admin/tpl/blocks/fields/add_edit_form.tpl

find this part at line 345



<tr>
<td class="name">{$lang.field_preview}</td>
<td class="field">
<div style="padding: 0 0 10px 0;">
<span class="phone_code_prev hide">+ <input disabled="disabled" type="text" maxlength="4" style="width: 30px;text-align: center;" /> -</span>
<input disabled="disabled" id="phone_area_input" type="text" maxlength="5" style="width: 40px;text-align: center;" />
- <input disabled="disabled" id="phone_number_input" type="text" maxlength="9" style="width: 80px;" /></span>
<span class="phone_ext hide">/ <input disabled="disabled" type="text" maxlength="4" style="width: 35px;" /></span>
</div>
<div>
<span class="phone_code_prev hide">+ xxx</span>
<span id="phone_area_preview">(xxxx)</span>
<span id="phone_number_preview">123-4567</span>
<span class="phone_ext hide">{$lang.phone_ext_out}22</span>
</div>
</td>
</tr>


and change this code with follow



<tr>
<td class="name">{$lang.field_preview}</td>
<td class="field">
<div style="padding: 0 0 10px 0;">
<span class="phone_code_prev hide">+ <input disabled="disabled" type="text" maxlength="4" style="width: 30px;text-align: center;" /> -</span>
(0) <input disabled="disabled" id="phone_area_input" type="text" maxlength="5" style="width: 40px;text-align: center;" />
- <input disabled="disabled" id="phone_number_input" type="text" maxlength="9" style="width: 80px;" /></span>
<span class="phone_ext hide">/ <input disabled="disabled" type="text" maxlength="4" style="width: 35px;" /></span>
</div>
<div>
<span class="phone_code_prev hide">+ xxx</span>
<span id="phone_area_preview">(xxxx)</span>
<span id="phone_number_preview">123-4567</span>
<span class="phone_ext hide">{$lang.phone_ext_out}22</span>
</div>
</td>
</tr>

Steffen Buschkemper
September 22, 2012, 12:07 PM
Open in templates/general_modern/tpl/blocks/profile_account.tpl

find the follow code @ line 113



{else}
<input type="text" name="account[{$field.Key}][area]" {if $fVal.$fKey.area}value="{$fVal.$fKey.area}"{/if} maxlength="{$field.Default}" size="{$field.Default}" class="wauto ta-center numeric" />
{/if}


and change it with the follow code



{else}
{if $field.Opt1}
<input type="text" name="account[{$field.Key}][area]" {if $fVal.$fKey.area}value="{$fVal.$fKey.area}"{/if} maxlength="{$field.Default}" size="{$field.Default}" class="wauto ta-center numeric" />
{else}
<span style="color:#5881A0; font-size:15px;">( 0</span> <input type="text" name="account[{$field.Key}][area]" {if $fVal.$fKey.area}value="{$fVal.$fKey.area}"{/if} maxlength="{$field.Default}" size="{$field.Default}" class="wauto ta-center numeric" /> <span style="color:#5881A0; font-size:15px;">)</span>
{/if}{/if}


This solution is only for sites they need only local numbers and area number has 0 at first.

Mike
September 22, 2012, 12:28 PM
I think it will add 0 to all phone numbers ?

My solution is different, it just shows 0 if user typed it and don't show when didn't type.
Problem is that when phone number is saved script converts it to integer data type (0123 will be 123) etc. area, code and number itself.
So number stored in database without 0, my solution is remove conversion to integer.

Steffen Buschkemper
September 22, 2012, 12:58 PM
Hi Mike,

ok Mike i think your solution is better.
Can you add your code in this thread for all?

Best regards
Steffen

Mike
September 24, 2012, 04:24 AM
Ok, sure. Sorry didn't do it already..

At first list of files and functions to be changed, everywhere changes are the same.

includes/classes/rlListings.class.php function edit, function add

includes/classes/rlAccount.class.php function registration, function editAccount

includes/classes/admin/rlListings.class.php function edit, function add

So 6 functions, in each function there is code to handle phone field:



case 'phone':
$out = '';

/* code */
if ( $value['Opt1'] )
{
$code = (int)substr($data[$fk]['code'], 0, $value['Default']);
$out = 'c:'. $code .'|';
}

/* area */
$area = (int)$data[$fk]['area'];
$out .= 'a:'. $area . '|';

/* number */
$number = (int)substr($data[$fk]['number'], 0, $value['Values']);
$out .= 'n:'. $number;

/* extension */
if ( $value['Opt2'] )
{
$ext = (int)$data[$fk]['ext'];
$out .= '|e:'. $ext;
}

$listing[$fk] = $out;

break;


you have to remove the (int) modifier so peace of code will be like below




case 'phone':
$out = '';

/* code */
if ( $value['Opt1'] )
{
$code = substr($data[$fk]['code'], 0, $value['Default']);
$out = 'c:'. $code .'|';
}

/* area */
$area = $data[$fk]['area'];
$out .= 'a:'. $area . '|';

/* number */
$number = substr($data[$fk]['number'], 0, $value['Values']);
$out .= 'n:'. $number;

/* extension */
if ( $value['Opt2'] )
{
$ext = $data[$fk]['ext'];
$out .= '|e:'. $ext;
}

$listing[$fk] = $out;

break;



We are sorry for inconveniences, it will be changed in the next update.

Peter Jonsson
September 24, 2012, 04:54 AM
Awsome, thanks Mike!

Will try it out when i wake up, to tired now :)

Morgan Bohman
September 24, 2012, 05:02 AM
Confirmed working, thanks a lot Mike!

Steffen Buschkemper
September 24, 2012, 04:52 PM
Thank you Mike!

Viktor
October 1, 2012, 06:21 AM
Hello all,

if you want use 0 in code or in number please open file: ftp:includes>>classes>>rlListings.class.php
find method 'create' and code in at line from ~151 to ~179 :


case 'phone':
$out = '';

/* code */
if ( $value['Opt1'] )
{
$code = (int)substr($data[$fk]['code'], 0, $value['Default']);
$out = 'c:'. $code .'|';
}

/* area */
$area = (int)$data[$fk]['area'];
$out .= 'a:'. $area . '|';

/* number */
$number = (int)substr($data[$fk]['number'], 0, $value['Values']);
$out .= 'n:'. $number;

/* extension */
if ( $value['Opt2'] )
{
$ext = (int)$data[$fk]['ext'];
$out .= '|e:'. $ext;
}

$listing[$fk] = $out;

break;

and replace to:



case 'phone':
$out = '';

/* code */
if ( $value['Opt1'] )
{
//$code = (int)substr($data[$fk]['code'], 0, $value['Default']);
$code = $data[$fk]['code'];
$out = 'c:'. $code .'|';
}

/* area */
$area = (int)$data[$fk]['area'];
$area = $data[$fk]['area'];
$out .= 'a:'. $area . '|';

/* number */
//$number = (int)substr($data[$fk]['number'], 0, $value['Values']);
$number = $data[$fk]['number'];
$out .= 'n:'. $number;

/* extension */
if ( $value['Opt2'] )
{
//$ext = (int)$data[$fk]['ext'];
$ext = $data[$fk]['ext'];
$out .= '|e:'. $ext;
}

$listing[$fk] = $out;

break;


then in this file in method 'edit' find code at line from ~451 to ~478:


case 'phone':
$out = '';

/* code */
if ( $value['Opt1'] )
{
$code = (int)substr($data[$fk]['code'], 0, $value['Default']);
$out = 'c:'. $code .'|';
}

/* area */
$area = (int)$data[$fk]['area'];
$out .= 'a:'. $area . '|';

/* number */
$number = (int)substr($data[$fk]['number'], 0, $value['Values']);
$out .= 'n:'. $number;

/* extension */
if ( $value['Opt2'] )
{
$ext = (int)$data[$fk]['ext'];
$out .= '|e:'. $ext;
}

$listing['fields'][$fk] = $out;

break;


and replace to:



case 'phone':
$out = '';

/* code */
if ( $value['Opt1'] )
{
//$code = (int)substr($data[$fk]['code'], 0, $value['Default']);
$code = $data[$fk]['code'];
$out = 'c:'. $code .'|';
}

/* area */
//$area = (int)$data[$fk]['area'];
$area = $data[$fk]['area'];
$out .= 'a:'. $area . '|';

/* number */
//$number = (int)substr($data[$fk]['number'], 0, $value['Values']);
$number = $data[$fk]['number'];
$out .= 'n:'. $number;

/* extension */
if ( $value['Opt2'] )
{
//$ext = (int)$data[$fk]['ext'];
$ext = $data[$fk]['ext'];
$out .= '|e:'. $ext;
}

$listing['fields'][$fk] = $out;

break;

Petrache Nicolae
October 23, 2013, 09:04 AM
does this work? becouse i have added the code and than i entered user account and updated again the phone numer by adding 0 and after save i see that the 0 is still not saved

John
October 23, 2013, 10:52 AM
Hello Guys,
To be honest I don't like Mike's solution because it isn't sql injection protected, here the code:


case 'phone':
$out = '';

/* code */
if ( $value['Opt1'] )
{
$code = $this -> rlValid -> xSql(substr($data[$fk]['code'], 0, $value['Default']));
$out = 'c:'. $code .'|';
}

/* area */
$area = $this -> rlValid -> xSql($data[$fk]['area']);
$out .= 'a:'. $area . '|';

/* number */
$number = $this -> rlValid -> xSql(substr($data[$fk]['number'], 0, $value['Values']));
$out .= 'n:'. $number;

if ( !$area || !$number )
break;

/* extension */
if ( $value['Opt2'] )
{
$ext = $this -> rlValid -> xSql($data[$fk]['ext']);
$out .= '|e:'. $ext;
}

$listing[$fk] = $out;

break;


This fix added to 4.2 update.

John

Petrache Nicolae
October 23, 2013, 12:39 PM
well, let's hope that 4.2 will be the lucky number, becouse we had phone field from 4.0 not working properly, we were promissed that 4.1 will fix it and surprise surprise...we talk about 4.2 now.

Petrache Nicolae
October 23, 2013, 03:10 PM
Hello Guys,
To be honest I don't like Mike's solution because it isn't sql injection protected, here the code:


case 'phone':
$out = '';

/* code */
if ( $value['Opt1'] )
{
$code = $this -> rlValid -> xSql(substr($data[$fk]['code'], 0, $value['Default']));
$out = 'c:'. $code .'|';
}

/* area */
$area = $this -> rlValid -> xSql($data[$fk]['area']);
$out .= 'a:'. $area . '|';

/* number */
$number = $this -> rlValid -> xSql(substr($data[$fk]['number'], 0, $value['Values']));
$out .= 'n:'. $number;

if ( !$area || !$number )
break;

/* extension */
if ( $value['Opt2'] )
{
$ext = $this -> rlValid -> xSql($data[$fk]['ext']);
$out .= '|e:'. $ext;
}

$listing[$fk] = $out;

break;


This fix added to 4.2 update.

John

Hello John. I have replaced the codes in those 3 files, so 6 changes in total. Have tried to edit an existing account and the 0 is not saved.
have created a new account and added the same number and i see now that the script doesn't check if the number is already used or not as for email (this is wrong) and olso, after i saved it, i went into account and there the phone area was blank....i added again the number and again was saved without 0. what do i miss?