remove obsolete frame divider images
[openemr.git] / library / classes / PhoneNumber.class.php
blob5aab8575cca68d850d0a4a46c2822d53a29b55f1
1 <?php
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);
15 define("TYPE_FAX",5);
17 require_once("ORDataObject.class.php");
19 /**
20 * class Address
23 class PhoneNumber extends ORDataObject{
24 var $id;
25 var $foreign_id;
26 var $country_code;
27 var $area_code;
28 var $prefix;
29 var $number;
30 var $type_array = array("","Home", "Work", "Cell" , "Emergency" , "Fax");
32 /**
33 * Constructor sets all Prescription attributes to their default value
35 function PhoneNumber($id = "",$foreign_id = "") {
36 $this->id = $id;
37 $this->foreign_id = $foreign_id;
38 $this->country_code = "+1";
39 $this->prefix = "";
40 $this->number = "";
41 $this->type = TYPE_HOME;
42 $this->_table = "phone_numbers";
43 if ($id != "") {
44 $this->populate();
49 function factory_phone_numbers($foreign_id = "") {
50 if (empty($foreign_id)) {
51 $foreign_id= "like '%'";
53 else {
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);
61 //echo "sql: $sql";
62 while ($row = mysql_fetch_array($results) ) {
63 $phone_numbers[] = new PhoneNumber($row['id']);
65 return $phone_numbers;
68 function set_id ($id) {
69 $this->id = $id;
72 function get_id () {
73 return $this->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) {
109 $this->type = $type;
112 function get_type () {
113 return $this->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;
128 return "";
131 function set_phone($num) {
132 if (strlen($num) == 10 && is_numeric($num)) {
133 $this->area_code = substr ($num,0,3);
134 $this->prefix = substr ($num,3,3);
135 $this->number = substr ($num,6,4);
137 elseif (strlen($num) == 12) {
138 $nums = split("-",$num);
139 if (count($nums) == 3) {
140 $this->area_code = $nums[0];
141 $this->prefix = $nums[1];
142 $this->number = $nums[2];
145 elseif (strlen($num) == 14 && substr($num,0,1) == "(") {
146 $nums[0] = substr($num,1,3);
147 $nums[1] = substr($num,6,3);
148 $nums[2] = substr($num,10,4);
150 foreach ($nums as $n) {
151 if (!is_numeric($n)) {
152 return false;
156 if (count($nums) == 3) {
157 $this->area_code = $nums[0];
158 $this->prefix = $nums[1];
159 $this->number = $nums[2];
164 function toString($html = false) {
165 $string .= "\n"
166 . "ID: " . $this->id."\n"
167 . "FID: " . $this->foreign_id."\n"
168 . $this->country_code . " (" . $this->area_code . ") " . $this->prefix . "-" . $this->number . " " . $this->type_array[$this->type];
169 if ($html) {
170 return nl2br($string);
172 else {
173 return $string;
177 function persist($fid ="") {
178 if (!empty($fid)) {
179 $this->foreign_id = $fid;
181 parent::persist();
184 } // end of PhoneNumber
185 /*$p = new PhoneNumber(1);
186 echo $p->toString();
187 $p = new PhoneNumber(true);
189 $ps = PhoneNumber::factory_phone_numbers(55);
190 foreach($ps as $p) {
191 echo $p->toString(true);