if (!defined('DP_BASE_DIR')) { die('You should not access this file directly.'); } $AppUI->savePlace(); if (!$canAccess) { $AppUI->redirect('m=public&a=access_denied'); } $perms =& $AppUI->acl(); $q = new DBQuery(); $search_string = dPgetCleanParam($_GET, 'search_string', null); // To configure an aditional filter to use in the search string $additional_filter = ''; // retrieve any state parameters if ($search_string) { $AppUI->setState('ContIdxWhere', $search_string); $get_search = $q->quote_sanitised('%' . $search_string . '%'); $additional_filter = "contact_first_name LIKE " . $get_search . " OR contact_last_name LIKE " . $get_search . " OR company_name LIKE " . $get_search . " OR contact_notes LIKE " . $get_search . " OR contact_email LIKE " . $get_search; } else { if (isset($_GET['where'])) { $AppUI->setState('ContIdxWhere', $_GET['where']); } } $where = $q->quote_sanitised($AppUI->getState('ContIdxWhere') ? $AppUI->getState('ContIdxWhere') . '%' : '%'); // Pull First Letters $let = ":"; $search_map = array('contact_order_by', 'contact_first_name', 'contact_last_name'); foreach ($search_map as $search_name) { $q->addTable('contacts', 'c'); $q->leftJoin('users', 'u', 'u.user_contact=c.contact_id'); $q->addQuery('DISTINCT UPPER(SUBSTRING(' . $search_name . ',1,1)) as L, user_id'); $q->addWhere('contact_private = 0 OR (contact_private = 1 AND contact_owner = ' . $AppUI->user_id . ') OR contact_owner IS NULL OR contact_owner = 0');
// retrieve list of records $q = new DBQuery(); $q->addTable('companies', 'c'); $q->addQuery('c.company_id, c.company_name, c.company_type, c.company_description' . ', count(distinct p.project_id) as countp' . ', count(distinct p2.project_id) as inactive' . ', con.contact_first_name, con.contact_last_name'); $q->addJoin('projects', 'p', 'c.company_id = p.project_company AND p.project_status <> 7'); $q->addJoin('users', 'u', 'c.company_owner = u.user_id'); $q->addJoin('contacts', 'con', 'u.user_contact = con.contact_id'); $q->addJoin('projects', 'p2', 'c.company_id = p2.project_company AND p2.project_status = 7'); if (count($allowedCompanies) > 0) { $q->addWhere('c.company_id IN (' . implode(',', array_keys($allowedCompanies)) . ')'); } if ($companiesType) { $q->addWhere('c.company_type = ' . $company_type_filter); } if ($search_string != '') { $q->addWhere("c.company_name LIKE " . $q->quote_sanitised('%' . $search_string . '%')); } if ($owner_filter_id > 0) { $q->addWhere('c.company_owner = ' . $owner_filter_id); } $q->addGroup('c.company_id'); $q->addOrder($orderby . ' ' . $orderdir); $rows = $q->loadList(); ?> <table width="100%" border="0" cellpadding="2" cellspacing="1" class="tbl" summary="company list"> <tr> <td nowrap="nowrap" width="60" align="right"> <?php echo $AppUI->_('sort by'); ?> : </td> <th nowrap="nowrap">