function clientstaff_contactcard($clientstaffid,$hide=0){
if (!$clientstaffid)
return false;
return contactcard(0,$hide,$clientstaffid);
}
function staff_contactcard($staffid, $hide = 0){
if (!$staffid)
return false;
return contactcard($staffid,$hide,0);
}
function is_active_company($companyid)
{
$sql="select companyinactive from tblcompany where companyid=".db_number($companyid);
$res=db_first($sql);
//d($sql,'$sql');
if($res[companyinactive]!=null || $res[companyinactive]!="")
return 0;
return 1;
}
function is_active_clientcompany($clientcompanyid)
{
$sql="select clientcompanyinactivedate from tblclientcompany where clientcompanyid=".db_number($clientcompanyid);
$res=db_first($sql);
//d($sql,'$sql');
if($res[clientcompanyinactivedate]!=null || $res[clientcompanyinactivedate]!="")
return 0;
return 1;
}
/**
* @name contactcard
* @param unknown $staffid
* @param number $hide
* @param number $clientstaffid
* this was extended by VL see MTX 17122
*/
//d(nodiff);
function contactcard($staffid, $hide = 0, $clientstaffid=0){
//d(staffid,$staffid);
//d(clientstaff,$clientstaffid);
if (!$staffid && !$clientstaffid)
return;
global $staff_contactcard_count;
$staff_contactcard_count++;
if (!$clientstaffid>0){
$sql = "select *
from tblstaff
join tbllogin
using (staffid)
where staffid = " . db_number($staffid);
}
else // we are doing this for clientcompany
{
$sql = " select clientstaffid as staffid
, clientstafffname as stafffname
, clientstafflname as stafflname
, clientstaffphone as staffphone
, clientstaffcell as staffcell
, clientstaffextension as staffextension
, clientstaffemail as staffemail
, loginid
from tblclientstaff
join (select loginid,clientstaffid from tbllogin where logininactive is null) as tbllogin using (clientstaffid)
where clientstaffid =".db_number($clientstaffid);
}
$staff = db_first($sql);
//d(sql,$staff);
if($staff_contactcard_count == 1){
?>
} ?>
}
function get_clientcompany($id)
{
if(!$id)
return array();
else
$out= db_first("select * from tblclientcompany where clientcompanyid = ".db_number($id));
$out[companyname] = $out[clientcompanyname];
return $out;
}
function get_staff_name($id)
{
global $get_staff_name_cache;
//d($id);
if($get_staff_name_cache[$id])
return $get_staff_name_cache[$id];
if(!$id)
return "";
$sql = "select stafffname||' '||stafflname as name from tblstaff
join tbllogin using(staffid)
where staffid = ".db_number($id);
//d($sql);
$qry= db_first($sql);
if($qry)
$get_staff_name_cache[$id]=$qry[name];
else
return "none";
return $qry[name];
}
function get_staff_email($id)
{
//d($id);
if(!$id)
return "";
$sql = "select staffemail from tblstaff join tbllogin using(staffid) where staffid = ".db_number($id);
//d($sql);
$qry= db_first($sql);
return $qry[staffemail];
}
function get_company_staffidlist($companyid)
{
//d($id);
if(companyid())
$companyid = companyid();
if(!$companyid)
return "";
$sql = "select group_concat(staffid) as stafflist from tblstaff join tbllogin using(staffid) where companyid = ".$companyid;
$qry= db_first($sql);
if(!$qry[stafflist])
$qry[stafflist]=0;
return $qry[stafflist];
}
function client_portal($setval=null)
{
//for companyid() users only set and return whether we are in the client_portal
// this allows for customization of the header/navigation etc for this different most
if(accountid())
;//account users are in the portal
elseif(externaluserid() && !clientcompanyid()) //external userid could be client_portal or not, but never when they are clientcompanyid()
; // external users are in the portal
elseif(companyid())
; // the company i sin th portal
elseif(clientcompanyid() && isset($_GET[assignedtome]))
; // a client company looking at property or tasks with the 'Assigned to Me' filter should be in the portal.
else
{
unset($_SESSION[login][client_portal]);
return; //no one else is in the portal
}
if($setval!==null)
{
$_SESSION[login][client_portal]=$setval;
}
return $_SESSION[login][client_portal];
}
define(ASSIGNEDTOME, 'assignedtome');
define(VISIBLETOSUBS, 'visibletosubs');
function role_onlyviewassigned()
{
set_roles();
}
function get_rolepropertyrestriction_stafflist($clientstaffid=0)
{
if(!$clientstaffid)
$clientstaffid=clientstaffid();
if(!$clientstaffid)
return "";
if(!get_rolepropertyrestriction($clientstaffid))
return 0;
if(get_rolepropertyrestriction($clientstaffid)==ASSIGNEDTOME)
return clientstaffid();
if(get_rolepropertyrestriction($clientstaffid)==VISIBLETOSUBS)
return get_sub_clientstaffidlist($clientstaffid);
else
return "ERROR: ".get_rolepropertyrestriction();
}
function has_rolepropertyrestriction($clientstaffid=0)
{
/* this funciton is used to determine whether the staff member has an restrictions on the properties they can see */
/* initially used to restrict the methods that they can use to do bulk actions on properties */
if(!$clientstaffid)
$clientstaffid=clientstaffid();
if(get_rolepropertyrestriction($clientstaffid)==ASSIGNEDTOME)
return ASSIGNEDTOME;
if(get_rolepropertyrestriction($clientstaffid)==VISIBLETOSUBS)
return VISIBLETOSUBS;
return false;
}
function get_clientcompanyclient_documentlist($clientcompanyclientid)
{
if(!db_number($clientcompanyclientid))
return;
$sql = "select documentid,1 as pretty from tbldocument where clientcompanyclientid = $clientcompanyclientid and documentvoideddate is null";
$qry=db_query($sql);
d($sql,$qry);
ob_start();
foreach($qry as $row)
echo "
".customfield_display_documentupload($row);
$out=ob_get_clean();
return $out;
}
function get_clientcompanyclient($clientcompanyclientid)
{
if(!db_number($clientcompanyclientid))
return array();
$sql = "select * from tblclientcompanyclient where clientcompanyclientid = ".db_number($clientcompanyclientid);
$out = db_first($sql);
if($out[clientcompanyclientescalation])
$out[clientcompanyclientescalation] = unserialize($out[clientcompanyclientescalation]);
return $out;
}
function get_client_documentlist($clientid)
{
if(!db_number($clientid))
return;
$sql = "select documentid,1 as pretty from tbldocument where clientid = $clientid and documentvoideddate is null";
$qry=db_query($sql);
//d($sql,$qry);
ob_start();
foreach($qry as $row)
echo "
".customfield_display_documentupload($row);
$out=ob_get_clean();
return $out;
}
function get_investorbyclientcompanyid($clientcompanyid)
{
return db_first('select * from tblclientcompany left join tblinvestor using(clientcompanyid) where clientcompanyid = '.db_number($clientcompanyid));
}
function fax_toemailaddress($number)
{
if(!$number)
ddie("Invalid number passed to fax_toemailaddress(), \$number='$number'");
if(!defined("OUTGOINGFAXEMAILADDRESS"))
ddie("Invalid call to fax_toemailaddress(), user does not have an OUTGOINGFAXEMAILADDRESS setup, how did they get here");
$em = OUTGOINGFAXEMAILADDRESS;
$em = str_replace('NUMBER',$number,$em);
return $em;
}
function fax_fromemailaddress($clientcompanyid=0)
{
if(clientcompanyid())
$clientcompanyid = clientcompanyid();
if($clientcompanyid)
{
$com = get_clientcompany($clientcompanyid);
$companyname = strtolower(list_first($com[clientcompanyname]," "));
$email = "$companyname-".$clientcompanyid."-ccfax@i.riogenesis.com";
return $email;
}
ddie("invalid call to fax_fromemailaddress()");
}
function get_accountpackage($companyids)
{
global $PACKAGEBASE_DESCRIPTIONS;
$accounttype = '';
if ($companyids)
{
$compsql = "
select companybpoassistantonly
, companyriooffice
, companyprofessional
, packagename
, companyid
, (
select addonsubpackagename
from tblcompanyaddon
join tbladdonsubpackage using (addonsubpackageid)
where companyid = tblcompany.companyid
order by addonsubpackageid desc
limit 1
) addonsubpackagename
from tblcompany
left join tblcompanypackage using (companyid)
left join tblpackage using (packageid)
left join
(
select companyid, count(1) companyprofessional
from tbladdon
join tblcompanyaddon using (addonid)
where companyaddonpaidthru > now()";
if(!is_devsite())
$compsql .= "
and addondevsiteonly = 0";
$compsql .= "
group by companyid
) tblprofessional using (companyid)
where companyid in (".db_number_list($companyids).")";
$comp = db_first($compsql);
if($comp[companybpoassistantonly])
$accounttype = "BPO Assistant {$comp[addonsubpackagename]}";
else if($comp[companyriooffice])
$accounttype = (!$comp['packagename'])?"RIO Office":$comp['packagename'];
else if(is_genesisonly($comp['companyid']))
$accounttype = $PACKAGEBASE_DESCRIPTIONS['genesisonly'];
else if(($comp[companyprofessional] && !is_genesisonly($comp['companyid'])) || ($comp[packagename] && $comp[packagename] == 'Classic'))
$accounttype = "Professional";
else if(!$accounttype && $comp[packagename])
$accounttype = $comp[packagename] ;
}
return $accounttype;
}
function is_developercompany($companyid)
{
$co=get_company($companyid);
$viewcloakedmode=FALSE;
if(has_customization('canviewcloakedaccounts') || $_SESSION['viewcloaked'])
$viewcloakedmode=TRUE;
if($co[companydeveloper])
if(!$viewcloakedmode || ($viewcloakedmode && $co[companycloaked]!=1))
return 1;
return false;
}
function is_clientcompany($companyid)
{
if(db_query("select clientcompanyid from tblclientcompany where clientcompanyid=".$companyid))
return 1;
return 0;
}
function get_staff_active_assignments($staffid)
{
$sql="select
taskid,taskassignid,staffid,taskcreatedby,taskname,taskcompleteddate,taskinactivateddate,taskstaffcompleteddate,taskstaffassigneddate
from tbltaskassign
join tbltask using (taskid)
where 0=0
and taskinactivateddate is null
and taskstaffcompleteddate is null
and taskcompleteddate is null
and taskstaffassigneddate is not null
and staffid=".db_number($staffid);
$res=db_query($sql);
//d($sql,$res);
return $res;
}
function get_staff_active_clienttaskassignments($staffid)
{
$sql="select
clienttaskid
,clienttaskcreatedby
,clienttaskcompleteddate
,clienttaskresponsability
from tblclienttask
join tblclientcompanypropertyassignment using (clientcompanypropertyassignmentid,clientcompanypropertyid)
where 0=0
and clienttaskrevokeddate is null
and clienttaskcompleteddate is null
and clientcompanypropertyassignmentrevokeddate is null
and staffid=".db_number($staffid);
$res=db_query($sql);
//d($sql,'Assignment query');
return $res;
}
function get_clientstaff_active_assignments($staffid)
{
$sql="select
clienttaskid
,clienttaskcreatedby
,clienttaskcompleteddate
,clienttaskresponsability
from tblclienttask
where 0=0
and clienttaskrevokeddate is null
and clienttaskcompleteddate is null
and clienttaskresponsability=".db_number($staffid);
$res=db_query($sql);
//d($sql,'Assignment query');
return $res;
}
function staff_emailaddress_fromlogin($loginid)
{
$qry="select staffemail from tblstaff join tbllogin using (staffid) where loginid=".db_number($loginid);
//d($qry,'$qry');
$res=db_first($qry);
return $res[staffemail];
}
function clientstaff_emailaddress_fromlogin($loginid)
{
$qry="select clientstaffemail from tblclientstaff join tbllogin using (clientstaffid) where loginid=".db_number($loginid);
//d($qry,'$qry');
$res=db_first($qry);
return $res[clientstaffemail];
}
function staff_inactivate($loginid)
{
if($loginid==0)
{
d("You passed a 0 for the login id into staff_inactivate","Notice");
return;
}
$sql="update tbllogin set logininactive=now() where loginid=".db_number($loginid);
d($sql,'Logion Deactivation');
db_exec($sql);
//echo "Would have run this query: [Inactivate Staff]
$sql
";
}
function company_deactivate_processing($companyid)
{
/*Firsat we will see if this is a company or clientcompany
*
* this function will check to see if this company is inactive,
* once company is verified inactive, loop through staff within the company and set the inactivedate for each
*
*Loop over tasks and check for any assigned to staff within this deactivated company - cancel any found
* - send email to the assigner (AMC) with notice that the task must be reassigned as the assignee is no longer active.
*/
// company or client cmpany
if(is_company($companyid))
$processingprefix="company";
else if(is_clientcompany($companyid))
$processingprefix="clientcompany";
$companystaff=get_company_staff($companyid);
if(is_array($companystaff))
foreach($companystaff as $costaffid=>$staffdata)
{
$staffloginids[$costaffid]=$staffdata['loginid'];
$activestaffassignments=get_staff_active_assignments($costaffid);
if($activestaffassignments)
$assignments[$costaffid]=$activestaffassignments;
$activestaffclienttaskassignments=get_staff_active_clienttaskassignments($costaffid);
if($activestaffclienttaskassignments)
$clienttaskassignments[$costaffid]=$activestaffclienttaskassignments;
staff_inactivate($staffdata['loginid']);
}
// **************************************** Company task Assignments
//d('$assignments',$assignments);
//d('$clienttaskassignments',$clienttaskassignments);
if(is_array($assignments))
foreach($assignments as $staffid=>$assignment)
{
//d($assignmentdata,'$assignmentdata');
if(is_array($assignment) && !empty($assignment))
{
foreach($assignment as $assignmentkey=>$assignmentdata)
{
if((isset($assignmentdata[taskcompleteddate]) && $assignmentdata[taskcompleteddate]!="") ||
(isset($assignmentdata[taskinactivateddate]) && $assignmentdata[taskinactivateddate]!="") ||
(isset($assignmentdata[taskvendorcompleteddate]) && $assignmentdata[taskvendorcompleteddate]!="") ||
(isset($assignmentdata[taskstaffcompleteddate]) && $assignmentdata[taskstaffcompleteddate]!=""))
continue;
else
$allassignments[$staffid][]=get_task_foruser($assignmentdata[taskid],$companyid);
}
}
}
//d('$allassignments',$allassignments);
/*
We now ave an array of the tasks which are assigned to each staff member of this company (which is or will be inactive)
- we will loop over and set an inactivated date on each
- we will get the assigner and send an email to them regarding the inactive task which now needs to be reassigned.
*/
if(is_array($allassignments))
foreach($allassignments as $kk=>$taskdata)
{
if(is_array($taskdata))
{
foreach($taskdata as $tk=>$taskinfo)
{
//d('inactivating task:',$taskinfo[taskid]);
task_inactivate($taskinfo[taskid]);
//Tasks are assigned within the same company that is being inactivated so email not needed. //$mailsend=task_assigner_notify_taskinactivated($taskinfo,$kk);
}
}
}
// **************************************** Client Company Task Assignments
if(is_array($clienttaskassignments))
foreach($clienttaskassignments as $staffid=>$clienttaskassignment)
{
//d('$clienttaskassignment',$clienttaskassignment);
if(is_array($clienttaskassignment) && !empty($clienttaskassignment))
{
foreach($clienttaskassignment as $clienttaskassignmentkey=>$clienttaskassignmentdata)
{
if($clienttaskassignmentdata['clienttaskcompleteddate'])
continue;
else
{
$sql="select clienttaskid as taskid
, clienttasktitle as clienttaskname
, clienttaskcreatedby
, clientcompanypropertyaddress
, clientcompanypropertycity
, clientcompanypropertystate
, clientcompanypropertyzip
, clientcompanypropertycreatedby
, clientcompanypropertyupdatedby
, clientcompanypropertyassignmentid
, staffid
from tblclienttask
join tblclientcompanyproperty using(clientcompanypropertyid)
join tblclientcompanypropertyassignment using(clientcompanypropertyassignmentid, clientcompanypropertyid)
where clienttaskid=".db_number($clienttaskassignmentdata[clienttaskid])."
and staffid=".db_number($staffid)."
";
//d('$pulltaskinfosql',$sql);
$clienttaskastask=db_first($sql);
if($clienttaskastask)
$allclienttaskassignments[$staffid][]=$clienttaskastask;
}
}
}
}
//d('$allclienttaskassignments',$allclienttaskassignments);
/*
We now ave an array of the tasks which are assigned to each staff member of this company (which is or will be inactive)
- we will loop over and set an inactivated date on each
- we will get the assigner and send an email to them regarding the inactive task which now needs to be reassigned.
*/
if(is_array($allclienttaskassignments))
foreach($allclienttaskassignments as $kk=>$clienttaskdata)
{
if(is_array($clienttaskdata))
{
foreach($clienttaskdata as $ctk=>$clienttaskinfo)
{
if(db_number($clienttaskinfo['clientcompanypropertyassignmentid']))
{
//d('inactivating clientcompanypropertyassignmentid:',$clienttaskinfo['clientcompanypropertyassignmentid']);
$sql="update tblclientcompanypropertyassignment
set clientcompanypropertyassignmentrevokeddate=now()
, clientcompanypropertyassignmentrevokedby=0
where clientcompanypropertyassignmentid=".db_number($clienttaskinfo['clientcompanypropertyassignmentid'])."
";
//d('$ccpa revoke sql',$sql);
db_exec($sql);
}
if(db_number($clienttaskinfo['taskid']))
{
d('inactivating clienttaskid:',$clienttaskinfo['taskid']);
$sql="update tblclienttask
set clienttaskrevokeddate=now()
where clienttaskid=".db_number($clienttaskinfo['taskid'])."
";
//d('ct revoke sql',$sql);
db_exec($sql);
}
$mailsend=task_assigner_notify_taskinactivated($clienttaskinfo,$kk,1);
}
}
}
}