![]() |
|---|
| [ Index ] |
Source Code Reference for V1.00 |
[Summary view] [Print] [Text view]
1 <?php /* $Id: contacts.class.php 135 2008-04-04 13:49:13Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/contacts/contacts.class.php $ */ 2 if (!defined('W2P_BASE_DIR')) { 3 die('You should not access this file directly.'); 4 } 5 6 /** 7 * @package web2Project 8 * @subpackage modules 9 * @version $Revision: 135 $ 10 */ 11 12 require_once ($AppUI->getSystemClass('w2p')); 13 require_once ($AppUI->getSystemClass('libmail')); 14 15 /** 16 * Contacts class 17 */ 18 class CContact extends CW2pObject { 19 /** 20 @var int */ 21 var $contact_id = null; 22 /** 23 @var string */ 24 var $contact_first_name = null; 25 /** 26 @var string */ 27 var $contact_last_name = null; 28 var $contact_order_by = null; 29 var $contact_title = null; 30 var $contact_job = null; 31 var $contact_birthday = null; 32 var $contact_company = null; 33 var $contact_department = null; 34 var $contact_type = null; 35 var $contact_email = null; 36 var $contact_email2 = null; 37 var $contact_phone = null; 38 var $contact_phone2 = null; 39 var $contact_fax = null; 40 var $contact_mobile = null; 41 var $contact_address1 = null; 42 var $contact_address2 = null; 43 var $contact_city = null; 44 var $contact_state = null; 45 var $contact_zip = null; 46 var $contact_url = null; 47 var $contact_icq = null; 48 var $contact_aol = null; 49 var $contact_yahoo = null; 50 var $contact_msn = null; 51 var $contact_jabber = null; 52 var $contact_skype = null; 53 var $contact_google = null; 54 var $contact_notes = null; 55 var $contact_project = null; 56 var $contact_country = null; 57 var $contact_icon = null; 58 var $contact_owner = null; 59 var $contact_private = null; 60 var $contact_updatekey = null; 61 var $contact_lastupdate = null; 62 var $contact_updateasked = null; 63 64 function CContact() { 65 $this->CW2pObject('contacts', 'contact_id'); 66 } 67 68 function check() { 69 if ($this->contact_id === null) { 70 return 'contact id is NULL'; 71 } 72 // ensure changes of state in checkboxes is captured 73 $this->contact_private = intval($this->contact_private); 74 $this->contact_owner = intval($this->contact_owner); 75 return null; // object is ok 76 } 77 78 function canDelete(&$msg, $oid = null, $joins = null) { 79 global $AppUI; 80 if ($oid) { 81 // Check to see if there is a user 82 $q = new DBQuery; 83 $q->addTable('users'); 84 $q->addQuery('count(user_id) as user_count'); 85 $q->addWhere('user_contact = ' . (int)$oid); 86 $user_count = $q->loadResult(); 87 if ($user_count > 0) { 88 $msg = $AppUI->_('contactsDeleteUserError'); 89 return false; 90 } 91 } 92 return parent::canDelete($msg, $oid, $joins); 93 } 94 95 function isUser($oid = null) { 96 global $AppUI; 97 98 if (!$oid) { 99 $oid = $this->contact_id; 100 } 101 102 if ($oid) { 103 // Check to see if there is a user 104 $q = new DBQuery; 105 $q->addTable('users'); 106 $q->addQuery('count(user_id) as user_count'); 107 $q->addWhere('user_contact = ' . (int)$oid); 108 $user_count = $q->loadResult(); 109 if ($user_count > 0) { 110 return true; 111 } else { 112 return false; 113 } 114 } else { 115 return false; 116 } 117 } 118 119 function is_alpha($val) { 120 // If the field consists solely of numerics, then we return it as an integer 121 // otherwise we return it as an alpha 122 123 $numval = strtr($val, '012345678', '999999999'); 124 if (count_chars($numval, 3) == '9') { 125 return false; 126 } 127 return true; 128 } 129 130 function getCompanyID() { 131 $q = new DBQuery; 132 $q->addTable('companies'); 133 $q->addQuery('company_id'); 134 $q->addWhere('company_name = ' . (int)$this->contact_company); 135 $company_id = $q->loadResult(); 136 $q->clear(); 137 return $company_id; 138 } 139 140 function getCompanyName() { 141 $q = new DBQuery; 142 $q->addTable('companies'); 143 $q->addQuery('company_name'); 144 $q->addWhere('company_id = ' . (int)$this->contact_company); 145 $company_name = $q->loadResult(); 146 $q->clear(); 147 return $company_name; 148 } 149 150 function getCompanyDetails() { 151 $result = array('company_id' => 0, 'company_name' => ''); 152 if (!$this->contact_company) { 153 return $result; 154 } 155 156 $q = new DBQuery; 157 $q->addTable('companies'); 158 $q->addQuery('company_id, company_name'); 159 if ($this->is_alpha($this->contact_company)) { 160 $q->addWhere('company_name = ' . $q->quote($this->contact_company)); 161 } else { 162 $q->addWhere('company_id = ' . (int)$this->contact_company); 163 } 164 $result = $q->loadHash(); 165 $q->clear(); 166 return $result; 167 } 168 169 function getDepartmentDetails() { 170 $result = array('dept_id' => 0, 'dept_name' => ''); 171 if (!$this->contact_department) { 172 return $result; 173 } 174 $q = new DBQuery; 175 $q->addTable('departments'); 176 $q->addQuery('dept_id, dept_name'); 177 if ($this->is_alpha($this->contact_department)) { 178 $q->addWhere('dept_name = ' . $q->quote($this->contact_department)); 179 } else { 180 $q->addWhere('dept_id = ' . (int)$this->contact_department); 181 } 182 $result = $q->loadHash(); 183 $q->clear(); 184 return $result; 185 } 186 187 function getUpdateKey() { 188 $q = new DBQuery; 189 $q->addTable('contacts'); 190 $q->addQuery('contact_updatekey'); 191 $q->addWhere('contact_id = ' . (int)$this->contact_id); 192 $updatekey = $q->loadResult(); 193 $q->clear(); 194 return $updatekey; 195 } 196 197 function updateNotify() { 198 global $AppUI, $w2Pconfig, $locale_char_set; 199 $df = $AppUI->getPref('SHDATEFORMAT'); 200 $df .= ' ' . $AppUI->getPref('TIMEFORMAT'); 201 202 $mail = new Mail; 203 204 $mail->Subject('Hello', $locale_char_set); 205 206 if ($this->contact_email) { 207 $q = new DBQuery; 208 $q->addTable('companies'); 209 $q->addQuery('company_id, company_name'); 210 $q->addWhere('company_id = ' . (int)$this->contact_company); 211 $contact_company = $q->loadHashList(); 212 $q->clear(); 213 214 $body = "Dear: $this->contact_title $this->contact_first_name $this->contact_last_name,"; 215 $body .= "\n\nIt was very nice to visit you and " . $contact_company[$this->contact_company] . ". Thank you for all the time that you spent with me."; 216 $body .= "\n\nI have entered the data from your business card into my contact data base so that we may keep in touch."; 217 $body .= "\n\nWe have implemented a system which allows you to view the information that I've recorded and give you the opportunity to correct it or add information as you see fit. Please click on this link to view what I've recorded..."; 218 $body .= "\n\n" . $AppUI->_('URL') . ": " . W2P_BASE_URL . "/updatecontact.php?updatekey=$this->contact_updatekey"; 219 $body .= "\n\nI assure you that the information will be held in strict confidence and will not be available to anyone other than me. I realize that you may not feel comfortable filling out the entire form so please supply only what you're comfortable with."; 220 $body .= "\n\nThank you. I look forward to seeing you again, soon."; 221 $body .= "\n\nBest Regards,"; 222 $body .= "\n\n$AppUI->user_first_name $AppUI->user_last_name"; 223 // print_r($contact_company); 224 // print_r($body); 225 $mail->Body($body, isset($GLOBALS['locale_char_set']) ? $GLOBALS['locale_char_set'] : ''); 226 } 227 228 if ($mail->ValidEmail($this->contact_email)) { 229 $mail->To($this->contact_email, true); 230 $mail->Send(); 231 } 232 return ''; 233 } 234 235 /** 236 ** Overload of the w2PObject::getAllowedRecords 237 ** to ensure that the allowed projects are owned by allowed companies. 238 ** 239 ** @author handco <handco@sourceforge.net> 240 ** @see w2PObject::getAllowedRecords 241 **/ 242 243 function getAllowedRecords($uid, $fields = '*', $orderby = '', $index = null, $extra = null) { 244 global $AppUI; 245 require_once ($AppUI->getModuleClass('companies')); 246 require_once ($AppUI->getModuleClass('departments')); 247 $oCpy = new CCompany(); 248 249 $aCpies = $oCpy->getAllowedRecords($uid, 'company_id, company_name'); 250 if (count($aCpies)) { 251 $buffer = '(contact_company IN (' . implode(',', array_keys($aCpies)) . ') OR contact_company IS NULL OR contact_company = \'\' OR contact_company = 0)'; 252 253 //Department permissions 254 $oDpt = new CDepartment(); 255 $aDpts = $oDpt->getAllowedRecords($uid, 'dept_id, dept_name'); 256 if (count($aDpts)) { 257 $dpt_buffer = '(contact_department IN (' . implode(',', array_keys($aDpts)) . ') OR contact_department = 0)'; 258 } else { 259 // There are no allowed departments, so allow projects with no department. 260 $dpt_buffer = '(contact_department = 0)'; 261 } 262 263 if ($extra['where'] != '') { 264 $extra['where'] = $extra['where'] . ' AND ' . $buffer . ' AND ' . $dpt_buffer; 265 } else { 266 $extra['where'] = $buffer . ' AND ' . $dpt_buffer; 267 } 268 } else { 269 // There are no allowed companies, so don't allow projects. 270 if ($extra['where'] != '') { 271 $extra['where'] = $extra['where'] . ' AND (contact_company IS NULL OR contact_company = \'\' OR contact_company = 0) '; 272 } else { 273 $extra['where'] = 'contact_company IS NULL OR contact_company = \'\' OR contact_company = 0'; 274 } 275 } 276 return parent::getAllowedRecords($uid, $fields, $orderby, $index, $extra); 277 } 278 } 279 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 7 03:00:01 2009 | Cross-referenced by PHPXref 0.7 |