. */ /** * @brief manage contacts doubloons * * * @file * @author Laurent Giovannoni * @date $date$ * @version $Revision$ * @ingroup admin */ $admin = new core_tools(); $admin->test_admin('admin_contacts', 'apps'); $func = new functions(); $db = new dbquery(); $db->connect(); $db2 = new dbquery(); $db2->connect(); //delete old contacts with enabled = 'N' $db->query("delete from contacts where enabled = 'N'"); $_SESSION['m_admin'] = array(); /****************Management of the location bar ************/ $init = false; if (isset($_REQUEST['reinit']) && $_REQUEST['reinit'] == "true") { $init = true; } $level = ""; if ( isset($_REQUEST['level']) && ( $_REQUEST['level'] == 2 || $_REQUEST['level'] == 3 || $_REQUEST['level'] == 4 || $_REQUEST['level'] == 1 ) ) { $level = $_REQUEST['level']; } $page_path = $_SESSION['config']['businessappurl'] . 'index.php?page=manage_doubloons&admin=contacts'; $page_label = _MANAGE_DOUBLOONS; $page_id = "manage_doubloons"; $admin->manage_location_bar($page_path, $page_label, $page_id, $init, $level); /***********************************************************/ $color = array('#DFE3E0','#EAF2F1','#CDDCDA','#A8BCB9'); function randomColor($lastColor) { if ($lastColor <> 0) { $val = rand(0, $lastColor - 1); } else { $val = 3; } return $val; } echo '

' . _MANAGE_DOUBLOONS . '

'; echo '
'; //TODO: ENABLE THIS FUNCTION FOR ALL COLLECTION USING CONTACTS //doubloons by society $selectDoubloonsBySociety = "SELECT contact_id, society, lower(society) as lowsoc, " . "is_corporate_person, lastname, firstname, " . "address_num, address_street, address_town " . "from contacts " . "WHERE lower(society) in (" . "SELECT lower(society) FROM contacts GROUP BY lower(society) " . " HAVING Count(*) > 1 and lower(society) <> '') " . "order by lower(society)"; $htmlTabSoc = ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $tabSoc = array(); $socCompare = ''; $colorToUse = ''; $colorNumber = '2'; $db->query($selectDoubloonsBySociety); $cptSoc = 0; while($lineDoublSoc = $db->fetch_object()) { if ($lineDoublSoc->contact_id <> '') { $cptSoc++; //USE AJAX REQUEST TO KNOW IF RES ATTACHED /*$selectResAttached = "select res_id from res_view_letterbox where " . "exp_contact_id = " . $lineDoublSoc->contact_id . " or " . "dest_contact_id = " . $lineDoublSoc->contact_id . " order by res_id";*/ //$db2->query($selectResAttached); /*array_push($tabSoc, array('contact_id' => $lineDoublSoc->contact_id, 'society' => $lineDoublSoc->society, 'lastname' => $lineDoublSoc->lastname, 'firstname' => $lineDoublSoc->firstname, 'address_num' => $lineDoublSoc->address_num, 'address_street' => $lineDoublSoc->address_street, 'address_town' => $lineDoublSoc->address_town, ) );*/ if ($socCompare == $lineDoublSoc->lowsoc) { //echo 'doublon
'; } else { //echo 'new doublon
'; $colorNumber = randomColor($colorNumber); $colorToUse = $color[$colorNumber]; } $socCompare = $lineDoublSoc->lowsoc; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; $htmlTabSoc .= ''; } } //$func->show_array($tabSoc); $htmlTabSoc .= '
' . _DOUBLOONS_BY_SOCIETY . '
 ' . _ID . '' . _SOCIETY . '' . _IS_CORPORATE_PERSON . '' . _LASTNAME . '' . _FIRSTNAME . '' . _ADDRESS . ' 
' . $lineDoublSoc->contact_id . '' . $lineDoublSoc->society . '' . $lineDoublSoc->is_corporate_person . '' . $lineDoublSoc->lastname . '' . $lineDoublSoc->firstname . '' . $lineDoublSoc->address_num; $htmlTabSoc .= ' ' . $lineDoublSoc->address_street; $htmlTabSoc .= ' ' . $lineDoublSoc->address_town . '
'; if ($cptSoc == 0) { echo _NO_SOCIETY_DOUBLOONS . '
'; } else { echo $htmlTabSoc; } /***********************************************************************/ //doubloons by name $selectDoubloonsByName = "SELECT contact_id, lower(lastname||' '||firstname) as lastname_firstname, society, " . "is_corporate_person, lastname, firstname, " . "address_num, address_street, address_town " . "from contacts " . "WHERE lower(lastname||' '||firstname) in (" . "SELECT lower(lastname||' '||firstname) as lastname_firstname FROM contacts GROUP BY lastname_firstname " . " HAVING Count(*) > 1 and lower(lastname||' '||firstname) <> ' ') " . "order by lower(lastname||' '||firstname)"; $htmlTabName = ''; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; $tabName = array(); $nameCompare = ''; $colorToUse = ''; $colorNumber = '2'; $db->query($selectDoubloonsByName); $cptName = 0; while($lineDoublName = $db->fetch_object()) { if ($lineDoublName->contact_id <> '') { $cptName++; //USE AJAX REQUEST TO KNOW IF RES ATTACHED /*$selectResAttached = "select res_id from res_view_letterbox where " . "exp_contact_id = " . $lineDoublName->contact_id . " or " . "dest_contact_id = " . $lineDoublName->contact_id . " order by res_id";*/ //$db2->query($selectResAttached); /*array_push($tabName, array('contact_id' => $lineDoublName->contact_id, 'society' => $lineDoublName->society, 'lastname' => $lineDoublName->lastname, 'firstname' => $lineDoublName->firstname, 'address_num' => $lineDoublName->address_num, 'address_street' => $lineDoublName->address_street, 'address_town' => $lineDoublName->address_town, ) );*/ if ($nameCompare == $lineDoublName->lastname_firstname) { //echo 'doublon
'; } else { //echo 'new doublon
'; $colorNumber = randomColor($colorNumber); $colorToUse = $color[$colorNumber]; } $nameCompare = $lineDoublName->lastname_firstname; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; $htmlTabName .= ''; } } //$func->show_array($tabName); $htmlTabName .= '
' . _DOUBLOONS_BY_NAME . '
 ' . _ID . '' . _LASTNAME . '' . _FIRSTNAME . '' . _SOCIETY . '' . _IS_CORPORATE_PERSON . '' . _ADDRESS . ' 
' . $lineDoublName->contact_id . '' . $lineDoublName->lastname . '' . $lineDoublName->firstname . '' . $lineDoublName->society . '' . $lineDoublName->is_corporate_person . '' . $lineDoublName->address_num; $htmlTabName .= ' ' . $lineDoublName->address_street; $htmlTabName .= ' ' . $lineDoublName->address_town . '
'; if ($cptName == 0) { echo _NO_NAME_DOUBLOONS . '
'; } else { echo $htmlTabName; } echo '
';