2 /************************************************************************
3 phone_number.php - Copyright duhlman
5 /usr/share/apps/umbrello/headings/heading.php
7 This file was generated on %date% at %time%
8 The original location of this file is /home/duhlman/uml-generated-code/prescription.php
9 **************************************************************************/
11 define("TYPE_HOME",1);
12 define("TYPE_WORK",2);
13 define("TYPE_CELL",3);
14 define("TYPE_EMERGENCY",4);
17 require_once("ORDataObject.class.php");
23 class PhoneNumber
extends ORDataObject
{
30 var $type_array = array("","Home", "Work", "Cell" , "Emergency" , "Fax");
33 * Constructor sets all Prescription attributes to their default value
35 function PhoneNumber($id = "",$foreign_id = "") {
37 $this->foreign_id
= $foreign_id;
38 $this->country_code
= "+1";
41 $this->type
= TYPE_HOME
;
42 $this->_table
= "phone_numbers";
49 function factory_phone_numbers($foreign_id = "") {
50 if (empty($foreign_id)) {
51 $foreign_id= "like '%'";
54 $foreign_id= " = '" . mysql_real_escape_string(strval($foreign_id)) . "'";
56 $phone_numbers = array();
57 $p = new PhoneNumber();
58 $sql = "SELECT id FROM " . $p->_table
. " WHERE foreign_id " .$foreign_id . " ORDER BY type";
59 //echo $sql . "<bR />";
60 $results = sqlQ($sql);
62 while ($row = mysql_fetch_array($results) ) {
63 $phone_numbers[] = new PhoneNumber($row['id']);
65 return $phone_numbers;
68 function set_id ($id) {
76 function foreign_id ($id) {
77 $this->foreign_id
= $id;
80 function get_foreign_id () {
81 return $this->foreign_id
;
84 function set_country_code ($ccode) {
85 $this->country_code
= $ccode;
88 function get_country_code () {
89 return $this->country_code
;
91 function set_area_code ($acode) {
92 $this->area_code
= $acode;
95 function get_area_code () {
96 return $this->area_code
;
99 function set_number ($num) {
100 $this->number
= $num;
103 function get_number () {
104 return $this->number
;
108 function set_type ($type) {
112 function get_type () {
116 function set_prefix ($prefix) {
117 $this->prefix
= $prefix;
120 function get_prefix () {
121 return $this->prefix
;
124 function get_phone_display() {
125 if (is_numeric($this->area_code
) && is_numeric($this->prefix
) && is_numeric($this->number
)) {
126 // return "(" . $this->area_code . ") " . $this->prefix . "-" . $this->number;
127 return $this->area_code
. "-" . $this->prefix
. "-" . $this->number
;
132 function set_phone($num) {
133 if (strlen($num) == 10 && is_numeric($num)) {
134 $this->area_code
= substr ($num,0,3);
135 $this->prefix
= substr ($num,3,3);
136 $this->number
= substr ($num,6,4);
138 elseif (strlen($num) == 12) {
139 $nums = split("-",$num);
140 if (count($nums) == 3) {
141 $this->area_code
= $nums[0];
142 $this->prefix
= $nums[1];
143 $this->number
= $nums[2];
146 elseif (strlen($num) == 14 && substr($num,0,1) == "(") {
147 $nums[0] = substr($num,1,3);
148 $nums[1] = substr($num,6,3);
149 $nums[2] = substr($num,10,4);
151 foreach ($nums as $n) {
152 if (!is_numeric($n)) {
157 if (count($nums) == 3) {
158 $this->area_code
= $nums[0];
159 $this->prefix
= $nums[1];
160 $this->number
= $nums[2];
165 function toString($html = false) {
167 . "ID: " . $this->id
."\n"
168 . "FID: " . $this->foreign_id
."\n"
169 . $this->country_code
. " (" . $this->area_code
. ") " . $this->prefix
. "-" . $this->number
. " " . $this->type_array
[$this->type
];
171 return nl2br($string);
178 function persist($fid ="") {
180 $this->foreign_id
= $fid;
185 } // end of PhoneNumber
186 /*$p = new PhoneNumber(1);
188 $p = new PhoneNumber(true);
190 $ps = PhoneNumber::factory_phone_numbers(55);
192 echo $p->toString(true);