.
*/
/**
* @brief Contains functions to manage contacts
*
*
* @file
* @date $date$
* @version $Revision$
* @ingroup apps
*/
abstract class contacts_v2_Abstract extends Database
{
/**
* Return the contacts data in sessions vars
*
* @param string $mode add or up
*/
public function contactinfo($mode)
{
// return the user information in sessions vars
$func = new functions();
$_SESSION['m_admin']['contact']['IS_CORPORATE_PERSON'] =
$_REQUEST['is_corporate'];
if ($_SESSION['m_admin']['contact']['IS_CORPORATE_PERSON'] == 'Y') {
$_SESSION['m_admin']['contact']['SOCIETY'] = $func->wash(
$_REQUEST['society'], 'no', _STRUCTURE_ORGANISM . ' ', 'yes', 0, 255
);
$_SESSION['m_admin']['contact']['LASTNAME'] = '';
$_SESSION['m_admin']['contact']['FIRSTNAME'] = '';
$_SESSION['m_admin']['contact']['FUNCTION'] = '';
$_SESSION['m_admin']['contact']['TITLE'] = '';
} else {
$_SESSION['m_admin']['contact']['LASTNAME'] = $func->wash(
$_REQUEST['lastname'], 'no', _LASTNAME, 'yes', 0, 255
);
$_SESSION['m_admin']['contact']['FIRSTNAME'] = $func->wash(
$_REQUEST['firstname'], 'no', _FIRSTNAME, 'no', 0, 255
);
if ($_REQUEST['society'] <> '') {
$_SESSION['m_admin']['contact']['SOCIETY'] = $func->wash(
$_REQUEST['society'], 'no', _STRUCTURE_ORGANISM . ' ', 'yes', 0, 255
);
} else {
$_SESSION['m_admin']['contact']['SOCIETY'] = '';
}
if ($_REQUEST['function'] <> '') {
$_SESSION['m_admin']['contact']['FUNCTION'] = $func->wash(
$_REQUEST['function'], 'no', _FUNCTION . ' ', 'yes', 0, 255
);
} else {
$_SESSION['m_admin']['contact']['FUNCTION'] = '';
}
if ($_REQUEST['title'] <> '') {
$_SESSION['m_admin']['contact']['TITLE'] = $func->wash(
$_REQUEST['title'], 'no', _TITLE2 . ' ', 'yes', 0, 255
);
} else {
$_SESSION['m_admin']['contact']['TITLE'] = '';
}
}
if ($_REQUEST['society_short'] <> '') {
$_SESSION['m_admin']['contact']['SOCIETY_SHORT'] = $func->wash(
$_REQUEST['society_short'], 'no', _SOCIETY_SHORT . ' ', 'yes', 0, 32
);
} else {
$_SESSION['m_admin']['contact']['SOCIETY_SHORT'] = '';
}
$_SESSION['m_admin']['contact']['CONTACT_TYPE'] = $func->wash(
$_REQUEST['contact_type'], 'no', _CONTACT_TYPE . ' ', 'yes', 0, 255
);
if ($_REQUEST['comp_data'] <> '') {
$_SESSION['m_admin']['contact']['OTHER_DATA'] = $func->wash(
$_REQUEST['comp_data'], 'no', _COMP_DATA . ' ', 'yes', 0, 255
);
} else {
$_SESSION['m_admin']['contact']['OTHER_DATA'] = '';
}
if (isset($_REQUEST['owner']) && $_REQUEST['owner'] <> '') {
if (preg_match('/\((.|\s|\d|\h|\w)+\)$/i', $_REQUEST['owner']) == 0) {
$_SESSION['error'] = _CREATE_BY . ' ' . _WRONG_FORMAT . '.
'
. _USE_AUTOCOMPLETION;
} else {
$_SESSION['m_admin']['contact']['OWNER'] = str_replace(
')', '', substr($_REQUEST['owner'],
strrpos($_REQUEST['owner'],'(')+1)
);
$_SESSION['m_admin']['contact']['OWNER'] = $func->wash(
$_SESSION['m_admin']['contact']['OWNER'], 'no',
_CREATE_BY . ' ', 'yes', 0, 32
);
}
} else {
$_SESSION['m_admin']['contact']['OWNER'] = '';
}
$_SESSION['m_admin']['contact']['order'] = $_REQUEST['order'];
$_SESSION['m_admin']['contact']['order_field'] = $_REQUEST['order_field'];
$_SESSION['m_admin']['contact']['what'] = $_REQUEST['what'];
$_SESSION['m_admin']['contact']['start'] = $_REQUEST['start'];
}
public function is_exists($mode, $mycontact){
$query = $this->query_contact_exists($mode);
$db = new Database();
$stmt = $db->query($query['query'], $query['params']);
if($stmt->rowCount() > 0){
if($mode <> 'up'){
$_SESSION['error'] = _THE_CONTACT.' '._ALREADY_EXISTS;
}
if($mycontact == 'iframe'){
$path_contacts_confirm = $_SESSION['config']['businessappurl'] . 'index.php?display=false&page=contacts_v2_confirm&popup';
} else {
$path_contacts_confirm = $_SESSION['config']['businessappurl'] . 'index.php?page=contacts_v2_confirm';
}
header(
'location: ' . $path_contacts_confirm.'&mode='.$mode.'&mycontact='.$mycontact
);
exit;
}
}
public function query_contact_exists($mode){
$query = '';
if($_SESSION['m_admin']['contact']['IS_CORPORATE_PERSON'] == 'N'){
$query = "SELECT contact_id, contact_type, society, contact_firstname, contact_lastname, contact_enabled FROM view_contacts
WHERE lower(contact_firstname) = lower(?)
and lower(contact_lastname) = lower(?)";
$arrayPDO = array($_SESSION['m_admin']['contact']['FIRSTNAME'], $_SESSION['m_admin']['contact']['LASTNAME']);
} else if ($_SESSION['m_admin']['contact']['IS_CORPORATE_PERSON'] == 'Y'){
$query = "SELECT contact_id, contact_type, society, contact_firstname, contact_lastname, contact_enabled FROM view_contacts
WHERE lower(society) = lower(?)";
$arrayPDO = array($_SESSION['m_admin']['contact']['SOCIETY']);
}
if ($mode == 'up'){
$query .= " and contact_id <> ?";
$arrayPDO = array_merge($arrayPDO, array($_SESSION['m_admin']['contact']['ID']));
}
return array("query" => $query, "params" => $arrayPDO);
}
/**
* Add ou modify contact in the database
*
* @param string $mode up or add
*/
public function addupcontact($mode, $admin = true, $confirm = 'N', $mycontact = 'N')
{
$db = new Database();
// add ou modify users in the database
if($confirm == 'N'){
$this->contactinfo($mode);
}
if (empty($_SESSION['error']) && $confirm == 'N') {
$this->is_exists($mode, $mycontact);
}
$order = $_SESSION['m_admin']['contact']['order'];
$order_field = $_SESSION['m_admin']['contact']['order_field'];
$what = $_SESSION['m_admin']['contact']['what'];
$start = $_SESSION['m_admin']['contact']['start'];
if ($mode == 'add') {
$path_contacts = $_SESSION['config']['businessappurl']
. 'index.php?page=contact_addresses_add&order='
. $order . '&order_field=' . $order_field . '&start='
. $start . '&what=' . $what;
} else {
$path_contacts = $_SESSION['config']['businessappurl']
. 'index.php?page=contacts_v2&order='
. $order . '&order_field=' . $order_field . '&start='
. $start . '&what=' . $what;
}
$path_contacts_add_errors = $_SESSION['config']['businessappurl']
. 'index.php?page=contacts_v2_add';
$path_contacts_up_errors = $_SESSION['config']['businessappurl']
. 'index.php?page=contacts_v2_up';
if (! $admin) {
if ($mode == 'add') {
$path_contacts = $_SESSION['config']['businessappurl']
. 'index.php?page=contact_addresses_add&mycontact=Y&order='
. $order . '&order_field=' . $order_field . '&start='
. $start . '&what=' . $what;
} else {
$path_contacts = $_SESSION['config']['businessappurl']
. 'index.php?page=my_contacts&dir=my_contacts&load&order='
. $order . '&order_field=' . $order_field . '&start='
. $start . '&what=' . $what;
}
$path_contacts_add_errors = $_SESSION['config']['businessappurl']
. 'index.php?page=my_contact_add&dir='
. 'my_contacts&load';
$path_contacts_up_errors = $_SESSION['config']['businessappurl']
. 'index.php?page=my_contact_up&dir='
. 'my_contacts&load';
}
if ($mycontact == 'iframe') {
if ($mode == 'add') {
$path_contacts = $_SESSION['config']['businessappurl']
. 'index.php?display=false&dir=my_contacts&page=create_address_iframe';
$path_contacts_add_errors = $_SESSION['config']['businessappurl']
. 'index.php?display=false&dir=my_contacts&page=create_contact_iframe';
} else if ($mode == 'up') {
$path_contacts = $_SESSION['config']['businessappurl']
. 'index.php?display=false&dir=my_contacts&page=info_contact_iframe&contactid='.$_SESSION['contact']['current_contact_id'].'&addressid='.$_SESSION['contact']['current_address_id'].'&created=Y';
$path_contacts_up_errors = $_SESSION['config']['businessappurl']
. 'index.php?display=false&dir=my_contacts&page=info_contact_iframe&contactid='.$_SESSION['contact']['current_contact_id'].'&addressid='.$_SESSION['contact']['current_address_id'];
}
}
if (! empty($_SESSION['error'])) {
if ($mode == 'up') {
if (! empty($_SESSION['m_admin']['contact']['ID'])) {
header(
'location: ' . $path_contacts_up_errors . '&id='
. $_SESSION['m_admin']['contact']['ID']
);
exit;
} else {
header('location: ' . $path_contacts);
exit;
}
}
if ($mode == 'add') {
header('location: ' . $path_contacts_add_errors);
exit;
}
} else {
if ($mode == 'add') {
if($_SESSION['user']['UserId'] == 'superadmin'){
$entity_id = 'SUPERADMIN';
} else {
$entity_id = $_SESSION['user']['primaryentity']['id'];
}
$query = 'INSERT INTO ' . $_SESSION['tablename']['contacts_v2']
. ' ( contact_type, lastname , firstname , society , society_short, function , '
. 'other_data,'
. " title, is_corporate_person, user_id, entity_id, creation_date) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, current_timestamp)";
$db->query($query, array($_SESSION['m_admin']['contact']['CONTACT_TYPE'], $_SESSION['m_admin']['contact']['LASTNAME'], $_SESSION['m_admin']['contact']['FIRSTNAME']
, $_SESSION['m_admin']['contact']['SOCIETY'], $_SESSION['m_admin']['contact']['SOCIETY_SHORT'], $_SESSION['m_admin']['contact']['FUNCTION'], $_SESSION['m_admin']['contact']['OTHER_DATA']
, $_SESSION['m_admin']['contact']['TITLE'], $_SESSION['m_admin']['contact']['IS_CORPORATE_PERSON'], $_SESSION['user']['UserId'], $entity_id));
if($_SESSION['history']['contactadd'])
{
$stmt = $db->query("SELECT contact_id, creation_date FROM ".$_SESSION['tablename']['contacts_v2']
." WHERE lastname = ? and firstname = ? and society = ? and function = ? and is_corporate_person = ? order by creation_date desc"
, array($_SESSION['m_admin']['contact']['LASTNAME'], $_SESSION['m_admin']['contact']['FIRSTNAME'], $_SESSION['m_admin']['contact']['SOCIETY']
, $_SESSION['m_admin']['contact']['FUNCTION'], $_SESSION['m_admin']['contact']['IS_CORPORATE_PERSON']));
$res = $stmt->fetchObject();
$id = $res->contact_id;
if($_SESSION['m_admin']['contact']['IS_CORPORATE_PERSON'] == 'Y')
{
$msg = _CONTACT_ADDED.' : '.functions::protect_string_db($_SESSION['m_admin']['contact']['SOCIETY']);
}
else
{
$msg = _CONTACT_ADDED.' : '.functions::protect_string_db($_SESSION['m_admin']['contact']['LASTNAME'].' '.$_SESSION['m_admin']['contact']['FIRSTNAME']);
}
require_once('core'.DIRECTORY_SEPARATOR.'class'.DIRECTORY_SEPARATOR.'class_history.php');
$hist = new history();
$hist->add($_SESSION['tablename']['contacts_v2'], $id,"ADD",'contacts_v2_add',$msg, $_SESSION['config']['databasetype']);
}
$stmt = $db->query("SELECT contact_id, creation_date FROM ".$_SESSION['tablename']['contacts_v2']
." WHERE lastname = ? and firstname = ? and society = ? and function = ? and is_corporate_person = ? order by creation_date desc"
, array($_SESSION['m_admin']['contact']['LASTNAME'], $_SESSION['m_admin']['contact']['FIRSTNAME'], $_SESSION['m_admin']['contact']['SOCIETY']
, $_SESSION['m_admin']['contact']['FUNCTION'], $_SESSION['m_admin']['contact']['IS_CORPORATE_PERSON']));
$res = $stmt->fetchObject();
$id = $res->contact_id;
$_SESSION['contact']['current_contact_id'] = $id;
$_SESSION['info'] = _CONTACT_ADDED;
header("location: ".$path_contacts);
exit;
}
elseif($mode == "up")
{
$query = "UPDATE ".$_SESSION['tablename']['contacts_v2']
." SET update_date = current_timestamp, contact_type = ?, lastname = ?, firstname = ?,society = ?,society_short = ?,function = ?, other_data = ?, title = ?, is_corporate_person = ?";
$query .= " WHERE contact_id = ?";
$arrayPDO = array($_SESSION['m_admin']['contact']['CONTACT_TYPE'], $_SESSION['m_admin']['contact']['LASTNAME'], $_SESSION['m_admin']['contact']['FIRSTNAME']
, $_SESSION['m_admin']['contact']['SOCIETY'], $_SESSION['m_admin']['contact']['SOCIETY_SHORT'], $_SESSION['m_admin']['contact']['FUNCTION']
, $_SESSION['m_admin']['contact']['OTHER_DATA'], $_SESSION['m_admin']['contact']['TITLE'], $_SESSION['m_admin']['contact']['IS_CORPORATE_PERSON'], $_SESSION['m_admin']['contact']['ID']);
$db->query($query, $arrayPDO);
if($_SESSION['history']['contactup'])
{
if($_SESSION['m_admin']['contact']['IS_CORPORATE_PERSON'] == 'Y')
{
$msg = _CONTACT_MODIFIED.' : '.functions::protect_string_db($_SESSION['m_admin']['contact']['SOCIETY']);
}
else
{
$msg = _CONTACT_MODIFIED.' : '.functions::protect_string_db($_SESSION['m_admin']['contact']['LASTNAME'].' '.$_SESSION['m_admin']['contact']['FIRSTNAME']);
}
require_once('core'.DIRECTORY_SEPARATOR.'class'.DIRECTORY_SEPARATOR.'class_history.php');
$hist = new history();
$hist->add($_SESSION['tablename']['contacts_v2'], $_SESSION['m_admin']['contact']['ID'],"UP",'contacts_v2_up',$msg, $_SESSION['config']['databasetype']);
}
$this->clearcontactinfos();
$_SESSION['info'] = _CONTACT_MODIFIED;
if (isset($_SESSION['fromContactTree']) && $_SESSION['fromContactTree'] == "yes") {
unset($_SESSION['fromContactTree']);
header("location: ".$_SESSION['config']['businessappurl']. 'index.php?page=view_tree_contacts');
exit();
} else {
header("location: ".$path_contacts);
exit();
}
}
}
}
/**
* Form to modify a contact v2
*
* @param $string $mode up or add
* @param int $id $id of the contact to change
*/
public function formcontact($mode,$id = "", $admin = true, $iframe = false)
{
$db = new Database();
if (preg_match("/MSIE 6.0/", $_SERVER["HTTP_USER_AGENT"]))
{
$browser_ie = true;
$display_value = 'block';
}
elseif(preg_match('/msie/i', $_SERVER["HTTP_USER_AGENT"]) && !preg_match('/opera/i', $_SERVER["HTTP_USER_AGENT"]) )
{
$browser_ie = true;
$display_value = 'block';
}
else
{
$browser_ie = false;
$display_value = 'table-row';
}
$func = new functions();
$state = true;
if(!isset($_SESSION['m_admin']['contact']))
{
$this->clearcontactinfos();
}
if( $mode <> "add")
{
$query = "SELECT * FROM ".$_SESSION['tablename']['contacts_v2']." WHERE contact_id = ?";
$stmt = $db->query($query, array($id));
if($stmt->rowCount() == 0)
{
$_SESSION['error'] = _THE_CONTACT.' '._ALREADY_EXISTS;
$state = false;
}
else
{
$_SESSION['m_admin']['contact'] = array();
$line = $stmt->fetchObject();
$_SESSION['m_admin']['contact']['ID'] = $line->contact_id;
$_SESSION['m_admin']['contact']['TITLE'] = functions::show_string($line->title);
$_SESSION['m_admin']['contact']['LASTNAME'] = functions::show_string($line->lastname);
$_SESSION['m_admin']['contact']['FIRSTNAME'] = functions::show_string($line->firstname);
$_SESSION['m_admin']['contact']['SOCIETY'] = functions::show_string($line->society);
$_SESSION['m_admin']['contact']['SOCIETY_SHORT'] = functions::show_string($line->society_short);
$_SESSION['m_admin']['contact']['FUNCTION'] = functions::show_string($line->function);
$_SESSION['m_admin']['contact']['OTHER_DATA'] = functions::show_string($line->other_data);
$_SESSION['m_admin']['contact']['IS_CORPORATE_PERSON'] = functions::show_string($line->is_corporate_person);
$_SESSION['m_admin']['contact']['CONTACT_TYPE'] = $line->contact_type;
$_SESSION['m_admin']['contact']['OWNER'] = $line->user_id;
if($admin && !empty($_SESSION['m_admin']['contact']['OWNER']))
{
$stmt = $db->query("SELECT lastname, firstname FROM ".$_SESSION['tablename']['users']." WHERE user_id = ?",
array($_SESSION['m_admin']['contact']['OWNER']));
$res = $stmt->fetchObject();
$_SESSION['m_admin']['contact']['OWNER'] = $res->lastname.', '.$res->firstname.' ('.$_SESSION['m_admin']['contact']['OWNER'].')';
}
}
}
else if($mode == 'add' && !isset($_SESSION['m_admin']['contact']['IS_CORPORATE_PERSON']))
{
$_SESSION['m_admin']['contact']['IS_CORPORATE_PERSON'] = 'Y';
}
require_once("apps".DIRECTORY_SEPARATOR.$_SESSION['config']['app_id'].DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."class_business_app_tools.php");
$business = new business_app_tools();
$tmp = $business->get_titles();
$titles = $tmp['titles'];
if($iframe != true){
echo '