![]() |
|---|
| [ Index ] |
Source Code Reference for V1.00 |
[Summary view] [Print] [Text view]
1 <?php /* $Id: index.php 141 2008-04-05 16:41:20Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/contacts/index.php $ */ 2 if (!defined('W2P_BASE_DIR')) { 3 die('You should not access this file directly.'); 4 } 5 6 $AppUI->savePlace(); 7 8 if (!$canAccess) { 9 $AppUI->redirect('m=public&a=access_denied'); 10 } 11 12 $perms = &$AppUI->acl(); 13 14 $countries = w2PgetSysVal('GlobalCountries'); 15 16 // To configure an aditional filter to use in the search string 17 $additional_filter = ''; 18 // retrieve any state parameters 19 if (isset($_GET['where'])) { 20 $AppUI->setState('ContIdxWhere', $_GET['where']); 21 } 22 if (isset($_GET['search_string'])) { 23 $AppUI->setState('ContIdxWhere', '%' . $_GET['search_string']); 24 // Added the first % in order to find instrings also 25 $additional_filter = 'OR contact_first_name like \'%' . $_GET['search_string'] . '%\' 26 OR contact_last_name like \'%' . $_GET['search_string'] . '%\' 27 OR CONCAT(contact_first_name, \' \', contact_last_name) like \'%' . $_GET['search_string'] . '%\' 28 OR company_name like \'%' . $_GET['search_string'] . '%\' 29 OR contact_notes like \'%' . $_GET['search_string'] . '%\' 30 OR contact_email like \'%' . $_GET['search_string'] . '%\''; 31 } 32 $where = $AppUI->getState('ContIdxWhere') ? $AppUI->getState('ContIdxWhere') : '%'; 33 34 $orderby = 'contact_first_name'; 35 36 //To Bruce: Clean updatekeys based on datediff to warn about long waiting. 37 $days_for_update = 5; 38 $q = new DBQuery; 39 $q->addTable('contacts'); 40 $q->addUpdate('contact_updatekey', ''); 41 $q->addWhere('(TO_DAYS(NOW()) - TO_DAYS(contact_updateasked) >=' . $days_for_update . ')'); 42 $q->exec(); 43 $q->clear(); 44 45 require_once $AppUI->getModuleClass('companies'); 46 $company =& new CCompany; 47 $allowedCompanies = $company->getAllowedSQL($AppUI->user_id); 48 49 require_once $AppUI->getModuleClass('departments'); 50 $department =& new CDepartment; 51 $allowedDepartments = $department->getAllowedSQL($AppUI->user_id); 52 53 // Pull First Letters 54 $let = ":"; 55 $search_map = array($orderby, 'contact_first_name', 'contact_last_name'); 56 foreach ($search_map as $search_name) { 57 $q = new DBQuery; 58 $q->addTable('contacts'); 59 $q->addQuery('DISTINCT UPPER(SUBSTRING(' . $search_name . ',1,1)) as L'); 60 $q->addWhere('contact_private=0 OR (contact_private=1 AND contact_owner=' . $AppUI->user_id . ') OR contact_owner IS NULL OR contact_owner = 0'); 61 $arr = $q->loadList(); 62 if (count($allowedCompanies)) { 63 $comp_where = implode(' AND ', $allowedCompanies); 64 $q->addWhere('( (' . $comp_where . ') OR contact_company = 0 )'); 65 } 66 if (count($allowedDepartments)) { 67 $dpt_where = implode(' AND ', $allowedDepartments); 68 $q->addWhere('( (' . $dpt_where . ') OR contact_department = 0 )'); 69 } 70 foreach ($arr as $L) { 71 $let .= $L['L']; 72 } 73 } 74 75 // optional fields shown in the list (could be modified to allow breif and verbose, etc) 76 $showfields = array( // "test" => "concat(contact_first_name,' ',contact_last_name) as test", why do we want the name repeated? 77 'contact_address1' => 'contact_address1', 'contact_address2' => 'contact_address2', 'contact_city' => 'contact_city', 'contact_state' => 'contact_state', 'contact_zip' => 'contact_zip', 'contact_country' => 'contact_country', 'contact_company' => 'contact_company', 'company_name' => 'company_name', 'dept_name' => 'dept_name', 'contact_phone' => 'contact_phone', 'contact_phone2' => 'contact_phone2', 'contact_mobile' => 'contact_mobile', 'contact_fax' => 'contact_fax', 'contact_email' => 'contact_email'); 78 79 // assemble the sql statement 80 $q = new DBQuery; 81 $q->addQuery('contact_id, contact_order_by'); 82 $q->addQuery($showfields); 83 $q->addQuery('contact_first_name, contact_last_name, contact_phone, contact_title'); 84 $q->addQuery('contact_updatekey, contact_updateasked, contact_lastupdate'); 85 $q->addQuery('user_id'); 86 $q->addTable('contacts', 'a'); 87 $q->leftJoin('companies', 'b', 'a.contact_company = b.company_id'); 88 $q->leftJoin('departments', '', 'contact_department = dept_id'); 89 $q->leftJoin('users', '', 'contact_id = user_contact'); 90 $q->addWhere('(contact_first_name LIKE \'' . $where . '%\' OR contact_last_name LIKE \'' . $where . '%\' ' . $additional_filter . ')'); 91 $q->addWhere(' 92 (contact_private=0 93 OR (contact_private=1 AND contact_owner=' . $AppUI->user_id . ') 94 OR contact_owner IS NULL OR contact_owner = 0 95 )'); 96 if (count($allowedCompanies)) { 97 $comp_where = implode(' AND ', $allowedCompanies); 98 $q->addWhere('( (' . $comp_where . ') OR contact_company = 0 )'); 99 } 100 if (count($allowedDepartments)) { 101 $dpt_where = implode(' AND ', $allowedDepartments); 102 $q->addWhere('( (' . $dpt_where . ') OR contact_department = 0 )'); 103 } 104 $q->addOrder('contact_first_name'); 105 $q->addOrder('contact_last_name'); 106 107 $carr[] = array(); 108 $carrWidth = 4; 109 $carrHeight = 4; 110 111 $rows = array(); 112 $rows = $q->loadList(); 113 $res = $q->exec(); 114 if (count($rows)) { 115 $rn = count($rows); 116 } else { 117 echo db_error(); 118 $rn = 0; 119 } 120 $t = floor($rn / $carrWidth); 121 122 if ($rn < ($carrWidth * $carrHeight)) { 123 $i = 0; 124 for ($y = 0; $y < $carrWidth; $y++) { 125 $x = 0; 126 while (($x < $carrHeight) && ($row = $rows[$i])) { 127 $carr[$y][] = $row; 128 $x++; 129 $i++; 130 } 131 } 132 } else { 133 $i = 0; 134 for ($y = 0; $y <= $carrWidth; $y++) { 135 $x = 0; 136 while (($x < $t) && ($row = $rows[$i])) { 137 $carr[$y][] = $row; 138 $x++; 139 $i++; 140 } 141 } 142 } 143 144 $tdw = floor(100 / $carrWidth); 145 146 /** 147 * Contact search form 148 */ 149 // Let's remove the first '%' that we previously added to ContIdxWhere 150 $default_search_string = w2PformSafe(substr($AppUI->getState('ContIdxWhere'), 1, strlen($AppUI->getState('ContIdxWhere'))), true); 151 152 $form = '<form action="./index.php" method="get">' . $AppUI->_('Search for') . ' 153 <input type="text" class="text" name="search_string" value="' . $default_search_string . '" /> 154 <input type="hidden" name="m" value="contacts" /> 155 <input type="submit" value=">" /> 156 <a href="./index.php?m=contacts&search_string=">' . $AppUI->_('Reset search') . '</a> 157 </form>'; 158 // En of contact search form 159 160 $a2z = '<table cellpadding="2" cellspacing="1" border="0">'; 161 $a2z .= '<tr>'; 162 $a2z .= '<td width="100%" align="right">' . $AppUI->_('Show') . ': </td>'; 163 $a2z .= '<td><a href="./index.php?m=contacts&where=0">' . $AppUI->_('All') . '</a></td>'; 164 for ($c = 65; $c < 91; $c++) { 165 $cu = chr($c); 166 $cell = strpos($let, $cu) > 0 ? '<a href="?m=contacts&where=' . $cu . '">' . $cu . '</a>' : '<font color="#999999">' . $cu . '</font>'; 167 $a2z .= '<td>' . $cell . '</td>'; 168 } 169 $a2z .= '</tr><tr><td colspan="28">' . $form . '</td></tr></table>'; 170 171 // setup the title block 172 173 // what purpose is the next line for? Commented out by gregorerhardt, Bug #892912 174 // $contact_id = $carr[$z][$x]["contact_id"]; 175 176 $titleBlock = new CTitleBlock('Contacts', 'monkeychat-48.png', $m, $m . '.' . $a); 177 $titleBlock->addCell($a2z); 178 if ($canEdit) { 179 $titleBlock->addCell('<input type="submit" class="button" value="' . $AppUI->_('new contact') . '">', '', '<form action="?m=contacts&a=addedit" method="post">', '</form>'); 180 $titleBlock->addCrumb('?m=contacts&a=csvexport&suppressHeaders=1', 'CSV Download'); 181 $titleBlock->addCrumb('?m=contacts&a=vcardimport&dialog=0', 'Import vCard'); 182 } 183 $titleBlock->show(); 184 185 // TODO: Check to see that the Edit function is separated. 186 187 188 ?> 189 <script language="javascript"> 190 // Callback function for the generic selector 191 function goProject( key, val ) { 192 var f = document.modProjects; 193 if (val != '') { 194 f.project_id.value = key; 195 f.submit(); 196 } 197 } 198 </script> 199 <form action="./index.php" method='get' name="modProjects"> 200 <input type='hidden' name='m' value='projects' /> 201 <input type='hidden' name='a' value='view' /> 202 <input type='hidden' name='project_id' /> 203 </form> 204 <?php 205 if (function_exists('styleRenderBoxTop')) { 206 echo styleRenderBoxTop(); 207 } 208 ?> 209 <table width="100%" border="0" cellpadding="1" cellspacing="0" class="contacts"> 210 <tr> 211 <?php 212 for ($z = 0; $z < $carrWidth; $z++) { 213 ?> 214 <td valign="top" align="left" width="<?php echo $tdw; ?>%"> 215 <table width="100%" cellspacing="2" cellpadding="1"> 216 <?php 217 for ($x = 0, $x_cmp = @count($carr[$z]); $x < $x_cmp; $x++) { 218 ?> 219 <tr> 220 <td> 221 <table width="100%" cellspacing="0" cellpadding="1" class="std"> 222 <tr> 223 <?php $contactid = $carr[$z][$x]['contact_id']; ?> 224 <th style="text-align:left" nowrap="nowrap" width="50%"> 225 <a href="./index.php?m=contacts&a=view&contact_id=<?php echo $contactid; ?>"><strong><?php echo ($carr[$z][$x]['contact_title'] ? $carr[$z][$x]['contact_title'] . ' ' : '') . $carr[$z][$x]['contact_first_name'] . ' ' . $carr[$z][$x]['contact_last_name']; ?></strong></a> 226 </th> 227 <th style="text-align:right" nowrap="nowrap" width="50%"> 228 <?php if ($carr[$z][$x]['user_id']) { 229 echo '<a href="./index.php?m=admin&a=viewuser&user_id=' . $carr[$z][$x]['user_id'] . '">' . w2PshowImage('icons/users.gif', '', '', $m, 'This Contact is also a User, click to view its details.') . '</a>'; 230 } 231 ?> 232 <a href="?m=contacts&a=vcardexport&suppressHeaders=true&contact_id=<?php echo $contactid; ?>" ><?php echo w2PshowImage('vcard.png', '', '', $m, 'export vCard of this contact'); ?></a> 233 <a href="?m=contacts&a=addedit&contact_id=<?php echo $contactid; ?>"><?php echo w2PshowImage('icons/pencil.gif', '', '', $m, 'edit this contact'); ?></a> 234 <?php 235 $q->clear(); 236 $q = new DBQuery; 237 $q->addTable('projects'); 238 $q->addQuery('count(project_id)'); 239 $q->addWhere('project_contacts LIKE \'' . $carr[$z][$x]['contact_id'] . ',%\' OR project_contacts LIKE \'%,' . $carr[$z][$x]['contact_id'] . ',%\' OR project_contacts LIKE \'%,' . $carr[$z][$x]['contact_id'] . '\' OR project_contacts LIKE \'' . $carr[$z][$x]['contact_id'] . '\''); 240 241 $res = $q->exec(); 242 $projects_contact = $q->fetchRow(); 243 $q->clear(); 244 if ($projects_contact[0] > 0) 245 echo '<a href="" onclick=" window.open(\'./index.php?m=public&a=selector&dialog=1&callback=goProject&table=projects&user_id=' . $carr[$z][$x]['contact_id'] . '\', \'selector\', \'left=50,top=50,height=250,width=400,resizable\');return false;">' . w2PshowImage('projects.png', '', '', $m, 'click to view projects associated with this contact') . '</a>'; 246 if ($carr[$z][$x]['contact_updateasked'] && (!$carr[$z][$x]['contact_lastupdate'] || $carr[$z][$x]['contact_lastupdate'] == 0) && $carr[$z][$x]['contact_updatekey']) { 247 $last_ask = new CDate($carr[$z][$x]['contact_updateasked']); 248 $df = $AppUI->getPref('SHDATEFORMAT'); 249 $df .= ' ' . $AppUI->getPref('TIMEFORMAT'); 250 echo w2PshowImage('log-info.gif', null, null, 'info', 'Waiting for Contact Update Information. (Asked on: ' . $last_ask->format($df) . ')'); 251 } elseif ($carr[$z][$x]['contact_updateasked'] && (!$carr[$z][$x]['contact_lastupdate'] || $carr[$z][$x]['contact_lastupdate'] == 0) && !$carr[$z][$x]['contact_updatekey']) { 252 $last_ask = new CDate($carr[$z][$x]['contact_updateasked']); 253 $df = $AppUI->getPref('SHDATEFORMAT'); 254 $df .= ' ' . $AppUI->getPref('TIMEFORMAT'); 255 echo w2PshowImage('log-error.gif', null, null, 'info', 'Waiting for too long! (Asked on ' . $last_ask->format($df) . ')'); 256 } elseif ($carr[$z][$x]['contact_lastupdate'] && !$carr[$z][$x]['contact_updatekey']) { 257 $last_ask = new CDate($carr[$z][$x]['contact_lastupdate']); 258 $df = $AppUI->getPref('SHDATEFORMAT'); 259 $df .= ' ' . $AppUI->getPref('TIMEFORMAT'); 260 echo w2PshowImage('log-notice.gif', null, null, 'info', 'Update sucessfully done on: ' . $last_ask->format($df) . ''); 261 } else { 262 } 263 ?> 264 </th> 265 </tr> 266 <tr> 267 <?php 268 reset($showfields); 269 $s = ''; 270 while (list($key, $val) = each($showfields)) { 271 if (strlen($carr[$z][$x][$key]) > 0) { 272 if ($val == 'contact_email') { 273 $s .= '<tr><td class="hilite" colspan="2"><a href="mailto:' . $carr[$z][$x][$key] . '" class="mailto">' . $carr[$z][$x][$key] . '</a></td></tr>'; 274 } elseif ($val == 'contact_company' && is_numeric($carr[$z][$x][$key])) { 275 //Don't do a thing 276 } elseif ($val == 'company_name') { 277 $s .= '<tr><td width="35%"><strong>' . $AppUI->_('Company') . ':</strong></td><td class="hilite" width="65%">' . $carr[$z][$x][$key] . '</td></tr>'; 278 } elseif ($val == 'dept_name') { 279 $s .= '<tr><td width="35%"><strong>' . $AppUI->_('Department') . ':</strong></td><td class="hilite" width="65%">' . $carr[$z][$x][$key] . '</td></tr>'; 280 } elseif ($val == 'contact_phone') { 281 $s .= '<tr><td width="35%"><strong>' . $AppUI->_('Work Phone') . ':</strong></td><td class="hilite" width="65%">' . $carr[$z][$x][$key] . '</td></tr>'; 282 } elseif ($val == 'contact_phone2') { 283 $s .= '<tr><td width="35%"><strong>' . $AppUI->_('Home Phone') . ':</strong></td><td class="hilite" width="65%">' . $carr[$z][$x][$key] . '</td></tr>'; 284 } elseif ($val == 'contact_mobile') { 285 $s .= '<tr><td width="35%"><strong>' . $AppUI->_('Mobile Phone') . ':</strong></td><td class="hilite" width="65%">' . $carr[$z][$x][$key] . '</td></tr>'; 286 } elseif ($val == 'contact_fax') { 287 $s .= '<tr><td width="35%"><strong>' . $AppUI->_('Fax') . ':</strong></td><td class="hilite" width="65%">' . $carr[$z][$x][$key] . '</td></tr>'; 288 } elseif ($val == 'contact_country' && $carr[$z][$x][$key]) { 289 $s .= '<tr><td class="hilite" colspan="2">' . ($countries[$carr[$z][$x][$key]] ? $countries[$carr[$z][$x][$key]] : $carr[$z][$x][$key]) . '<br /></td></tr>'; 290 } elseif ($val != 'contact_country') { 291 $s .= '<tr><td class="hilite" colspan="2">' . $carr[$z][$x][$key] . '<br /></td></tr>'; 292 } 293 } 294 } 295 echo $s; 296 ?> 297 </table> 298 </td> 299 </tr> 300 <?php } ?> 301 </table> 302 </td> 303 <?php } ?> 304 </tr> 305 </table>
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 |