| 1 |
<?php defined('SYSPATH') or die('No direct script access.'); |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
class Form_Phonenumber_Core extends Form_Input { |
|---|
| 13 |
|
|---|
| 14 |
protected $data = array |
|---|
| 15 |
( |
|---|
| 16 |
'name' => '', |
|---|
| 17 |
'class' => 'phone_number', |
|---|
| 18 |
); |
|---|
| 19 |
|
|---|
| 20 |
protected $protect = array('type'); |
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
protected $parts = array |
|---|
| 24 |
( |
|---|
| 25 |
'area_code' => '', |
|---|
| 26 |
'exchange' => '', |
|---|
| 27 |
'last_four' => '', |
|---|
| 28 |
); |
|---|
| 29 |
|
|---|
| 30 |
public function __construct($name) |
|---|
| 31 |
{ |
|---|
| 32 |
|
|---|
| 33 |
$this->data['name'] = $name; |
|---|
| 34 |
} |
|---|
| 35 |
|
|---|
| 36 |
public function __call($method, $args) |
|---|
| 37 |
{ |
|---|
| 38 |
if (isset($this->parts[substr($method, 0, -1)])) |
|---|
| 39 |
{ |
|---|
| 40 |
|
|---|
| 41 |
$this->parts[substr($method, 0, -1)] = $args; |
|---|
| 42 |
return $this; |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
return parent::__call($method, $args); |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
public function html_element() |
|---|
| 49 |
{ |
|---|
| 50 |
|
|---|
| 51 |
$data = $this->data; |
|---|
| 52 |
|
|---|
| 53 |
$input = ''; |
|---|
| 54 |
foreach ($this->parts as $type => $val) |
|---|
| 55 |
{ |
|---|
| 56 |
isset($data['value']) OR $data['value'] = ''; |
|---|
| 57 |
$temp = $data; |
|---|
| 58 |
$temp['name'] = $this->data['name'].'['.$type.']'; |
|---|
| 59 |
$offset = (strlen($data['value']) == 10) ? 0 : 3; |
|---|
| 60 |
switch ($type) |
|---|
| 61 |
{ |
|---|
| 62 |
case 'area_code': |
|---|
| 63 |
if (strlen($data['value']) == 10) |
|---|
| 64 |
{ |
|---|
| 65 |
$temp['value'] = substr($data['value'], 0, 3); |
|---|
| 66 |
} |
|---|
| 67 |
else |
|---|
| 68 |
$temp['value'] = ''; |
|---|
| 69 |
$temp['class'] = 'area_code'; |
|---|
| 70 |
$input .= form::input(array_merge(array('value' => $val), $temp)).'-'; |
|---|
| 71 |
break; |
|---|
| 72 |
case 'exchange': |
|---|
| 73 |
$temp['value'] = substr($data['value'], (3-$offset), 3); |
|---|
| 74 |
$temp['class'] = 'exchange'; |
|---|
| 75 |
$input .= form::input(array_merge(array('value' => $val), $temp)).'-'; |
|---|
| 76 |
break; |
|---|
| 77 |
case 'last_four': |
|---|
| 78 |
$temp['value'] = substr($data['value'], (6-$offset), 4); |
|---|
| 79 |
$temp['class'] = 'last_four'; |
|---|
| 80 |
$input .= form::input(array_merge(array('value' => $val), $temp)); |
|---|
| 81 |
break; |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
return $input; |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
protected function load_value() |
|---|
| 90 |
{ |
|---|
| 91 |
if (is_bool($this->valid)) |
|---|
| 92 |
return; |
|---|
| 93 |
|
|---|
| 94 |
$data = $this->input_value($this->name, $this->data['name']); |
|---|
| 95 |
|
|---|
| 96 |
$this->data['value'] = $data['area_code'].$data['exchange'].$data['last_four']; |
|---|
| 97 |
} |
|---|
| 98 |
} |
|---|