// Format shortname=>display value; Since php does not support constant as array.. we gonna make global
global $CLIENTCOMPANYWORKORDERLIST;
$CLIENTCOMPANYWORKORDERLIST = array('bid'=>'BID REQUEST','order'=>'ORDER'); // Used by clientcompany NRES we will probably move this to Database at some point
define('ACCEPTDECLINETASK','Task Accept/Decline');
// Multibyte version of the unserialize function
function mb_unserialize($s)
{
$out = unserialize($s);
if ($out === false)
$out = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $s);
return $out;
}
function get_clienttask($clienttaskid)
{
if(!($clienttaskid>0))
return array();
$tasks = get_clienttasks(-1, array(clienttaskid=>$clienttaskid));
$qry = array_shift($tasks);
if($qry[tasktemplateid])
{
$fields = db_query("
select *
from tbltasktemplatefield
where tasktemplateid = $qry[tasktemplateid]
and tasktemplatefieldinactive is null",1,0,tasktemplatefieldid);
$qry[tasktemplatefields] = $fields;
$fields_values = db_query("
select tasktemplatefieldid, tasktemplatefieldentryvalue, tasktemplatefieldentryid
from tbltasktemplatefieldentry
join tbltasktemplatefield using (tasktemplatefieldid)
where clienttaskid = ".db_number($clienttaskid)."
and tasktemplatefieldentryid is not null
and tasktemplatefieldinactive is null",1,0,tasktemplatefieldid);
if ($fields_values)
{
foreach($fields_values as $k=>$value)
{
$qry[tasktemplatefields][$k][tasktemplatefieldid] = $k;
$qry[tasktemplatefields][$k][tasktemplatefieldentryid] = $value[tasktemplatefieldentryid];
if($value[tasktemplatefieldentryvalue])
$qry[tasktemplatefields][$k][tasktemplatefieldentryvalue] = mb_unserialize($value[tasktemplatefieldentryvalue]);
}
}
}
return $qry;
}
function get_clienttasks($active,$filters="")
{
global $chosentaskallmytab;
if ($_SESSION[login][assignedtome])
$assignedtome = "on";
if($filters['restrictfilter']=="tasksassignedtome")
$assignedtome = "on";
if(is_array($filters))
extract($filters);
//getting the staff ids of everyone in the company
if(companyid())
$stafflist = get_company_staffidlist(companyid());
if($clienttaskid)
$fulltask=1;
else
$fulltask=0; // we do not have to get the entire task, which will save some major memory
$sql = "select ";
if($fulltask)
$sql .= " * ";
else
{
$sql .= "
tblclienttask.*
, a.clientcompanypropertyaddress
, a.clientcompanypropertycity
, a.clientcompanypropertystate
, a.clientcompanypropertyzip
, a.clientcompanypropertyid
, b.clientcompanyname
, tblclientcompanypropertyassignment.*
, tblassignmentmethod.assignmentmethodname
, tbllogin.companyid
, tbllogin.loginid
, assignfname as stafffname
, assignlname as stafflname
, assignname
, assignemail
, portfolioname
, (select propertyextensionentryvalue from tblpropertyextensionentry where propertyextensionkey = 'propertyextensionloannumber' and clientcompanypropertyid = tblclienttask.clientcompanypropertyid) as loannumber
, (
select 1
from tblclientcompanypropertyrole
join tblrole using(roleid)
where clientcompanypropertyid = a.clientcompanypropertyid
and tblclientcompanypropertyrole.clientstaffid = ".clientstaffid()."
and tblclienttask.clienttaskresponsability = tblrole.roleid --only lookup the role that the current user is assiged to
limit 1
) as myresponsibility
";
}
$sql.= "
, get_clienttask_statuskey(clienttaskduedate, clienttaskcompleteddate, clienttaskcompleteapproveddate, clienttaskrevokeddate, clienttaskholddate::date) as statuskey
, get_daysuntil(coalesce(clienttaskcompleteddate,clienttaskduedate)) as daysleft
, tblclientpretask.clientpretaskname as clientpretaskname
from tblclienttask
join tblclientcompanyproperty a using(clientcompanypropertyid)
join tblclientcompany b on(a.clientcompanyid = b.clientcompanyid)
join tblclientcompanypropertyassignment using(clientcompanypropertyid,clientcompanypropertyassignmentid)
join tblassignmentmethod using(assignmentmethodid)
join vw_assigntypes using(staffid, accountstaffid, externaluserid, assignmentaliasclientstaffid)
join (select *, clientstaffid as assignmentaliasclientstaffid from tbllogin) as tbllogin using(staffid, accountstaffid, externaluserid, assignmentaliasclientstaffid)
left join tblportfolio using(portfolioid)
left join tblclientpretask using (clientpretaskid, clientcompanypropertyid, clientcompanypropertyassignmentid)
where 0=0 ";
if(client_portal() && companyid())
$sql.= " and a.clientcompanypropertyhide is null
and (
clientcompanypropertyassignmentrevokeddate is null
or (
clientcompanypropertyassignmentrevokeddate is not null
and (clientcompanypropertyassignmentrevokeddate + interval '30 days') > now()
)
)
";
if($active>0)
{
if(!clientcompanyid() && !$_POST[batch] && !$statusfilter)
{
if(!$statusfilter || ($statusfilter!='complete'))
$sql.= " and clienttaskcompleteddate is null
";
if(!$statusfilter || ($statusfilter!='pulled_incomplete'))
$sql.= " and clienttaskrevokeddate is null
";
}
if(clientcompanyid() && !$_POST[batch])
{
if(!$statusfilter || ($statusfilter!='complete'))
$sql.= " and clienttaskcompleteapproveddate is null";
if(!$statusfilter || ($statusfilter!='pulled_incomplete'))
$sql.= " and clienttaskrevokeddate is null";
}
}
if(staffid() && $restrictfilter=="my" )
{
$sql.= " and tblclientcompanypropertyassignment.staffid = " .staffid();
}
if($assignmentmethodid>0)
$sql.=" and tblassignmentmethod.assignmentmethodid = ".db_number($assignmentmethodid);
if($assignedtome == 'on' && clientstaffid() && !clientcompanyid())
{
$sql .= "
and clientcompanypropertyid in
(
select clientcompanypropertyid
from tblclientcompanypropertyassignment
where assignmentaliasclientstaffid = ".clientstaffid()."
and clientcompanypropertyassignmentdenieddate is null
and clientcompanypropertyassignmentrevokeddate is null
and clientcompanypropertyassignmentexpired is null
) ";
}
if(companyid() && !$_POST[batch])
$sql.=" and tbllogin.companyid = ".companyid();
if(accountid() && has_customization("corporateaccount") )
{
//this corporate account gets to see all properties for all assigments for all subs
$sql.="
and tblclientcompanypropertyassignment.accountstaffid in
(
select accountstaffid
from tblaccountstaff
join tblaccount using(accountid)
where 0 = 0 ";
if( !account_hasparent(accountid()))
$sql .= " and accountparentaccountid = ".accountid()." ";
else
$sql .= " and accountid = ".accountid()." ";
$sql .= "
) ";
}
elseif(accountstaffid() && !$_POST[batch])
$sql.=" and tblclientcompanypropertyassignment.accountstaffid = ".accountstaffid();
if((externaluserid() && !clientcompanyid()) && !$_POST[batch])
$sql.=" and tblclientcompanypropertyassignment.externaluserid = ". externaluserid();
if(!$_GET[retask])
{
if($assignedtome=='on' && clientstaffid())
$sql.=" and assignmentaliasclientstaffid = ".clientstaffid();
elseif(clientcompanyid())
$sql.=" and tblclienttask.clientcompanyid = ".clientcompanyid();
/*
if(clientstaffid() && $chosentaskallmytab=='my')
; // $sql.=" and assignmentaliasclientstaffid = ".clientstaffid();
else
;
if(clientcompanyid())
$sql.=" and tblclienttask.clientcompanyid = ".clientcompanyid();
// else
*/
}
if($clientcompanypropertyid)
$sql.=" and clientcompanypropertyid = $clientcompanypropertyid";
if(strtolower($assignedto)==all)
$assignedto=0;
if(strtolower($assignedto)==me)
$assignedto=loginid();
if($clienttaskid>0)
$sql .=" and clienttaskid = ".db_number($clienttaskid);
if(staffid())
{
if(has_access('viewableproperties', 'Broker') && officelocationid()) //If Broker in an office only allow them to see tasks assigned to users in their office.
{
$sql.=" and tbllogin.staffid in
(
select staffid
from tblstaff
where officelocationid=".officelocationid()."
)
";
}
elseif(!has_access('viewstafftasks')) //you are not allowed access to every one
$sql .=" and tbllogin.staffid = ".staffid();
elseif ($restrictfilter == 'assigned' ) //if the user selected to only show the ones assigned to my self
$sql .=" and tbllogin.staffid = ".staffid();
elseif(officelocationid())//Restrict anyone that did not hit one of the other cases in this if statement that is in an office to only allow them to see tasks assigned to users in their office.
{
$sql.=" and tbllogin.staffid in
(
select staffid
from tblstaff
where officelocationid=".officelocationid()."
)
";
}
}
if($restrictfilter==alert||$restrictfilter==my || $chosentaskallmytab=="my")
{
$sql.="
and clienttaskrevokeddate is null
and
(
(clienttaskcompleteddate is not null and clienttaskcompleteapproveddate is null) -- all tasks awaiting approval
or (clienttaskcompleteddate is null and clienttaskduedate::date<=now()::date) -- all past due tasks
) ";
}
//Removing tasks that have been revked before being accepted.
$sql.="
and
(
clienttasktitle <> 'Task Accept/Decline'
or clientcompanypropertyassignmentrevokeddate is null
) ";
if(clientcompanyid() && !$_POST[batch])
{
$sql .= ($assignedtome != 'on') ? " and a.clientcompanyid = " . clientcompanyid() : "";
$rolepropertyrestriction_staffidlist = get_rolepropertyrestriction_stafflist(clientstaffid());
if($rolepropertyrestriction_staffidlist)
{
if ($_SESSION[login][assignedtome])
{
$sql.="
and
(
exists (select count(1) from tblclientcompanypropertyrole where clientcompanypropertyid = a.clientcompanypropertyid and clientstaffid in($rolepropertyrestriction_staffidlist))
or exists (select count(1) from tblclientcompanyproperty join tblclientcompanypropertyassignment using (clientcompanypropertyid) join tblassignmentaliasclientstaff using (assignmentaliasclientstaffid) where assignmentaliasclientstaffid = ".clientstaffid().")
) ";
}
else
{
$sql.="
and exists (select count(1) from tblclientcompanypropertyrole where clientcompanypropertyid = a.clientcompanypropertyid and clientstaffid in (".$rolepropertyrestriction_staffidlist."))";
}
}
}
if($portfolioidfilter) {
if($portfolioidfilter=='-1') {
$sql = " select * from ($sql) t where t.portfolioname =''";
} else {
$temppartsql = " select portfolioname from tblportfolio where portfolioid = $portfolioidfilter";
$sql = " select * from ($sql) t where t.portfolioname in (".$temppartsql.")";
}
}
if($statusfilter) {
$sql = " select *
from ($sql) t
where 0=0
and (
t.statuskey = '$statusfilter'
";
if(companyid() && $statusfilter=='complete')
$sql.= "
or t.statuskey = 'pending'
";
$sql.= "
)
";
}
if((clientstaffid() && $restrictfilter=="my" ) || (!accountstaffid() && $chosentaskallmytab=="my"))
{
$sql = " select * from ($sql) t where myresponsibility = 1";
}
if($s) {
$sql = " select *
from ($sql) t
where 0=0
and (
t.clienttasktitle ilike '%". db_col($s) ."%'
";
if(client_portal() && !accountid())
$sql.="
or t.clientcompanypropertyaddress ilike '%". db_col($s) ."%'
";
$sql.="
)
";
}
if(strtolower($assignedby)==all)
$assignedby=0;
if(strtolower($assignedby)==me)
$assignedby=loginid();
$qryt = db_query($sql,1,0,clienttaskid);
$statuses[onhold]="On Hold";
$statuses[pastdue]="Past Due";
$statuses[warning]="Warning";
$statuses[pending]="Pending Approval";
$statuses[complete]="Completed";
$statuses[open]="Open";
$statuses[pulled_incomplete]="Pulled Incomplete";
$statuses[scheduled]="Scheduled";
$status_priorities[pending]="1";
$status_priorities[pastdue]="2";
$status_priorities[warning]="3";
$status_priorities[scheduled]="4";
$status_priorities[open]="5";
$status_priorities[onhold]="6";
$status_priorities[complete]="7";
$status_priorities[pulled_incomplete]="8";
if(companyid()) //if you are the company, you dont need to ever know about a 'pending' status, as far as you are concerned it is complete
foreach($qryt as $k=>$row)
if($row[statuskey]==pending)
$qryt[$k][statuskey] = complete;
foreach($qryt as $k=>$row)
{
if($chosentaskallmytab=="alerttasks" && $row[status] =="open" )
{
unset($qryt[$k]);
continue;
}
$qryt[$k][status_priority] = $status_priorities[$row[statuskey]];
$qryt[$k][status] = $statuses[$row[statuskey]];
}
foreach($qryt as $k=>&$row)
{
$row[assignedname] = get_clienttaskassignname_fromarray($row);
}
if(!$fulltask)
$qryt = db_sort($qryt,daysleft,0);
else
$qryt = db_sort($qryt,status_priority,0);
return $qryt;
}
function get_clienttaskscheduled($clientcompanypropertyid=0,$filters=array())
{
//checked in under the wrong task (18688), comment to add a change and check in with (18524)
if (!clientcompanyid())
return false;
$sql = "
select tblclienttaskschedule.*
, a.clientcompanypropertyaddress
, a.clientcompanypropertycity
, a.clientcompanypropertystate
, a.clientcompanypropertyzip
, a.clientcompanypropertyid
, b.clientcompanyname
, tblclientcompanypropertyassignment.*
, tblassignmentmethod.assignmentmethodname
, tbllogin.companyid
, tbllogin.loginid
, assignfname as stafffname
, assignlname as stafflname
, assignname
, assignemail
, portfolioname
, (select propertyextensionentryvalue from tblpropertyextensionentry where propertyextensionkey = 'propertyextensionloannumber' and clientcompanypropertyid = tblclienttaskschedule.clientcompanypropertyid) as loannumber
, (
select 1
from tblclientcompanypropertyrole
join tblrole using(roleid)
where clientcompanypropertyid = a.clientcompanypropertyid
and tblclientcompanypropertyrole.clientstaffid = 0
and tblclienttaskschedule.roleid = tblrole.roleid --only lookup the role that the current user is assiged to
limit 1
) as myresponsibility
, 'scheduled' as statuskey
, 'Scheduled' as status
, get_daysuntil(clienttaskschedulefirstdate) as daysleft
from tblclienttaskschedule
join tblclientcompanyproperty a using(clientcompanypropertyid)
join tblclientcompany b on(a.clientcompanyid = b.clientcompanyid)
join tblclientcompanypropertyassignment using(clientcompanypropertyid,clientcompanypropertyassignmentid)
join tblassignmentmethod using(assignmentmethodid)
join vw_assigntypes using(staffid, accountstaffid, externaluserid, assignmentaliasclientstaffid)
join (select *, clientstaffid as assignmentaliasclientstaffid from tbllogin) as tbllogin using(staffid, accountstaffid, externaluserid, assignmentaliasclientstaffid)
left join tblportfolio using(portfolioid)
where clienttaskschedulerecurlastdate is null
and a.clientcompanyid = ".clientcompanyid();
if ($clientcompanypropertyid > 0)
$sql .= "
and clientcompanypropertyid = ".$clientcompanypropertyid;
if(count($filters))
{
//d(clientstaffid());
foreach($filters as $filterk=>$filtersearchval)
{
if($filterk=="assignmentmethodid")
{
$sql.=" and tblassignmentmethod.assignmentmethodname='".get_assignment_methodname($filtersearchval)."'";
}
if($filterk == "assignedtome" && $filtersearchval == "on")
{
$sql.=" and assignmentaliasclientstaffid=".clientstaffid();
}
}
}
$clienttaskscheduled = db_query($sql);
//d($sql,"scheduledtask with filters");
return $clienttaskscheduled;
}
function get_assignment_methodname($assignmentmethodid)
{
$sql="select assignmentmethodname from tblassignmentmethod where assignmentmethodid=".db_number($assignmentmethodid);
$ret=db_first($sql);
return $ret['assignmentmethodname'];
}
function get_clienttaskstatusname($key)
{
$statuses[pastdue]="Past Due";
$statuses[warning]="Warning";
$statuses[pending]="Pending Approval";
$statuses[complete]="Completed";
$statuses[open]="Open";
$statuses[pulled_incomplete]="Pulled Incomplete";
$statuses[scheduled]="Scheduled";
return $statuses[$key];
}
/**
* @name get_tasktemplate
* @param integer $id
* @param unknown $values
* @param integer $forcetemplate
* @return multitype:|unknown
*/
function get_tasktemplate($id,$values,$forcetemplate=0, $overrideclientcompanycheck=0)
{
if(!$clientcompanyid||!clientcompanyid() )
$clientcompanyid = clientcompanyid();
if(is_array($id))
{
$qry = $id;
$id=$qry[tasktemplateid];
}
else
{
$sql = "select * from tbltasktemplate where tasktemplateid = ".db_number($id);
if(clientcompanyid() && !$overrideclientcompanycheck)
{
$sql = "select tasktemplateid as id
,tasktemplatename as value
from tbltasktemplate
join tbltasktemplateclientcompany using (tasktemplateid)
where (tbltasktemplateclientcompany.clientcompanyid = ".clientcompanyid();
if(clientcompanyinvestor())
$sql.=" or tasktemplateinvestor = 1 ";
$sql.="
)
and tasktemplateinactivedate is null ";
if(!$forcetemplate)
$sql .=" and tbltasktemplateclientcompany.tasktemplateid = ".db_number($id);
}
$qry= db_first($sql);
}
if($values)
{
$valuelist = implode(',',array_keys($values));
}
if(!$qry)
return array();
$template=$qry;
$sql = "select * from tbltasktemplatefield
where tasktemplateid = ".db_number($id);
if($valuelist)
$sql .= " and tasktemplatefieldid in ($valuelist) ";
else
$sql.=" and tasktemplatefieldinactive is null ";
$sql.=" order by tasktemplatefieldrank ";
$qry= db_query($sql);
//d($sql,$qry);
$template[fields]=$qry;
return $template;
}
/**
* @name display_tasktemplate_rows
* @param unknown $tasktemplate
* @param unknown $values
* @param string $extra
* @param number $taskid
* @return unknown
* @example DO NOT PUT d() in this function it will break JS
*/
function display_tasktemplate_rows($tasktemplate, $values, $extra = "", $taskid=0, $overrideclientcompanycheck=0)
{
//d(__LINE__, $tasktemplate);
//d(__LINE__,$extra);
if ($extra[skip_me])
return true;
if(!$tasktemplate||!is_array($tasktemplate)||!$tasktemplate[fields])
{
$tasktemplate = get_tasktemplate($tasktemplate,$values,1,$overrideclientcompanycheck);
}
// we will need to check to see if the values change for each of the
// dependanton filed ids and the dependson , so lets get an array of all ids which have special handling
//d($tasktemplate);
$specialhandlingdependedon=array();
$specialhandlingdependsonothersfields=array();
//show/hide row depending on value of another column
if ($tasktemplate[fields]) foreach($tasktemplate[fields] as $fieldname)
{
if($fieldname[tasktemplatefielddependentonid])
$havefieldsdependentonme[$fieldname[tasktemplatefielddependentonid]]++; //mark that a field has dependent fields (so it should fire an onchange event
}
//end show/hide row depending on value of another column
disable_d_start(); // THIS MUST BE HERE
if($tasktemplate[fields]&& is_array($tasktemplate[fields]))
foreach($tasktemplate[fields] as $field)
{
$actionaction = "";
$dataattr="";
$value = $values[$field[tasktemplatefieldid]][tasktemplatefieldentryvalue];
$isdependant=0;
$isdependedon=0;
$addaction="";
$action="";
$required="";
$display_required = "";
if ($field[tasktemplatefieldrequired])
{
$required=" required=1 ";
$display_required = "*";
}
$extra1=array();
if ($field['tasktemplatefieldsortalphaoverride'])
$extra1['disable_sort']=1;
// This is to make sure that the clienttask information is passed so that clienttasks uploads works
$attr2 = array();
if ($field[tasktemplatefieldtype] == "photoaddendum")
{
if (is_array($field[tasktemplatefieldattr2]))
$attr2 = array_merge($attr2,$field[tasktemplatefieldattr2]);
$attr2[clientcompanypropertyid] = $extra[clientcompanypropertyid];
$attr2[clienttaskid] = $extra[clienttaskid];
$attr2[albumname] = $field[tasktemplatefieldlabel]." ".date_format(date_create($extra[clienttaskcreateddate]), "m-d-Y");
//d(album_name,$attr2[albumname]);
$attr2[viewonly] = $extra[viewonly];
}
else
$attr2 = $field[tasktemplatefieldattr2];
if($field[tasktemplatefieldtype]=="fillablepdf")
{
//d(tasktemplate,$tasktemplate);
//d(clienttask, $clienttask);
//d(fillable, $field);
//d(value,$value);
$attr2[clienttaskid] = $extra[clienttaskid];
$attr2[tasktemplatefieldid] = $field[tasktemplatefieldid];
// The value is the tasktemplatefieldversionid. You must save when the agent is viewing the task for the first time.
// so that we can track which version of the pdf the agent is filling out and uploading.
if (empty($value) && companyid())
{
$sql = "select tasktemplatefieldversionid
from tbltasktemplatefieldversion join tbldocument using (documentid)
where tbltasktemplatefieldversion.tasktemplatefieldid = ".db_number($field[tasktemplatefieldid])."
order by tasktemplatefieldversionid desc
limit 1";
$docid = db_first($sql);
$value = $docid[tasktemplatefieldversionid];
if ($field[tasktemplatefieldentryid])
$sql = "update tbltasktemplatefieldentry set tasktemplatefieldentryvalue = ".db_tick(serialize($value))." where clienttaskid = ".db_number($attr2[clienttaskid])." and tasktemplatefieldid = $field[tasktemplatefieldid]";
else
$sql = "insert into tbltasktemplatefieldentry (clienttaskid, tasktemplatefieldid, tasktemplatefieldentryvalue)
values ($extra[clienttaskid], $field[tasktemplatefieldid], ".db_tick(serialize($value)).")
";
db_exec($sql,1);
//d(update_fillable_version, $sql);
}
}
// -- dont assign to propertyattrivutes it breaks the propertyextensions where the value is only the first character
if($field[tasktemplatefieldattr1]=="utility_list" || $field[tasktemplatefieldattr1]=="hoaid" || $field[tasktemplatefieldattr1]=="hoa2id" || $field[tasktemplatefieldattr1]=="hoa3id")
{
$value[clientcompanypropertyid] = $extra[clientcompanypropertyid];
$_POST = $value;
}
if($field[tasktemplatefieldtype]=="mini_html_form")
{
global $autosaveable;
$autosaveable=1;
}
//show/hide row depending on value of another column
$dep = "";
$depdata = "";
if($field[tasktemplatefielddependentonid])
{
/*f(!strlen($field[tasktemplatefielddependentonvalue]))
$matchonvalue="blank";
else
$matchonvalue=$field[tasktemplatefielddependentonvalue];*/
$dep .= " ttdependent ttdependentonid-$field[tasktemplatefielddependentonid]";
$depdata=" data-ttdependentonvalue='$field[tasktemplatefielddependentonvalue]'";
}
if($havefieldsdependentonme[$field[tasktemplatefieldid]])
{
//create a function that can run at load time, as well as at field change time
//to hide or display 'depended columns
$dep.=" ttdependentonme ";
$rnd=rand(10000,99999999999999).time();
echo " ";
}
//end show/hide row depending on value of another column
if($field[tasktemplatefieldsinglecolumndisplay])
{
$bgcolor=alternate_class(bgmint,$dep);
echo "
";
echo "
$field[tasktemplatefieldlabel] ".$display_required;
if($field[tasktemplatefieldhelp]&&loginid())
echo button(help,$field[tasktemplatefieldhelp]);
if($field[tasktemplatefielddescr]&&loginid())
echo " $field[tasktemplatefielddescr]";
echo "
";
//d(step_a);
//d(__line__,$field);
//d($field[tasktemplatefieldtype],$field);
global $customfield_clientcompanyid_override;
$customfield_clientcompanyid_override=$property;
customfield($field[tasktemplatefieldtype]
,"tasktemplatefield_$field[tasktemplatefieldid]"
,$value
, $field[tasktemplatefieldattr1]
, $attr2
, $field[tasktemplatefieldattr3]
, $actionaction.$dataattr.$required
, ""
, $extra1
);
echo " |
";
//mdm added
if($field[tasktemplatefieldtype]=="documentupload") {
if(!$value)
echo "| ".get_replacementtemplatefilelink($field[tasktemplatefieldattr2], $taskid, 0)." |
";
}
}
else
{
$bgcolor=alternate_class(bgmint,$dep);
echo "
";
if($field[tasktemplatefieldhelp])
echo "".button(help,$field[tasktemplatefieldhelp])."";
echo "$field[tasktemplatefieldlabel]".$display_required;
if($field[tasktemplatefielddescr])
echo " $field[tasktemplatefielddescr]";
echo " | ";
//customfield_obstart("tasktemplatefield_$field[tasktemplatefieldid]");
echo "
";
//d(step_b,$field);
//d("f_ct".__line__,$value);
//d($field[tasktemplatefieldtype]);
//d(extra,$extra);
//d(monkey_step1_value,$attr2);
//d ("f_ct_type".__line__,$field);
//customfield_obend();
//d(tasktemplatefieldattr1, $field[tasktemplatefieldattr1]);
if($field['tasktemplatefieldtype'] == "clienttaskbid")
$attr2 = db_first ("SELECT * FROM tblclienttask WHERE clienttaskid =" . db_number ($taskid));
//d($field['tasktemplatefieldtype'] . '> attr2',$attr2);
customfield($field[tasktemplatefieldtype]
, "tasktemplatefield_$field[tasktemplatefieldid]"
, $value
, $field[tasktemplatefieldattr1]
, $attr2
, $field[tasktemplatefieldattr3]
, $actionaction.$dataattr.$required
, ""
, $extra1
);
if($havefieldsdependentonme[tasktemplatefieldid])
{
echo " ";
}
//echo $actionaction;
echo " | ";
echo "
";
//mdm added
if($field[tasktemplatefieldtype]=="documentupload") {
if(!$value)
echo " | ".get_replacementtemplatefilelink($field[tasktemplatefieldattr2], $taskid, 0)." |
";
}
}
}
d($tasktemplate);
echo "
$myout = ob_get_clean();
disable_d_end();
return $myout;
}
function display_tasktemplate_rows_pdf($clienttask, $photosperrow=0)
{
$addpagebreak='';
if(!$photosperrow)
$photosperrow=3;
else
$addpagebreak="";
$tasktemplate = get_tasktemplate($clienttask[tasktemplateid],$clienttask[tasktemplatefields]);
ob_start();
if($tasktemplate[fields] && is_array($tasktemplate[fields]))
foreach($tasktemplate[fields] as $field)
{
// Each field gets a table except for mini html form
echo "";
if ($field[tasktemplatefieldtype] != "mini_html_form" ){
if ($closetable)
echo $addpagebreak;
echo "";
$closetable =1;
}
$ctvalue = $clienttask[tasktemplatefields][$field[tasktemplatefieldid]][tasktemplatefieldentryvalue];
$display_required = "";
if ($field[tasktemplatefieldrequired])
$display_required = "*";
// We're going to skip html mini form because it's processed by client already
if ($field[tasktemplatefieldtype] == "mini_html_form")
{
// Pdf doesn't take into account the on the size attribute. We need to concert the size to width.
if ($_POST["mini_form_html_tasktemplatefield_$field[tasktemplatefieldid]"])
{
require_once("simple_html_dom.php");
$dom_html = str_get_html($_POST["mini_form_html_tasktemplatefield_$field[tasktemplatefieldid]"]);
foreach($dom_html->find('input') as $input)
{
if (!isset($input->size) && $input->type == 'text')
{ $input->style = "width:80px;"; }
else
{
if ($input->size <= 2 && $input->type == 'text') { $input->style = "width:18px;"; }
elseif ($input->size <= 3 && $input->type == 'text') { $input->style = "width:20px;"; }
elseif ($input->size <= 5 && $input->type == 'text') { $input->style = "width:25px;"; }
elseif ($input->size <= 10 && $input->type == 'text') { $input->style = "width:35px;"; }
elseif ($input->size <= 12 && $input->type == 'text') { $input->style = "width:38px;"; }
elseif ($input->size <= 15 && $input->type == 'text') { $input->style = "width:50px;"; }
elseif ($input->size <= 30 && $input->type == 'text') { $input->style = "width:100px;"; }
elseif ($input->size <= 50 && $input->type == 'text') { $input->style = "width:150px;"; }
elseif ($input->size <= 100 && $input->type == 'text') { $input->style = "width:250px;"; }
}
// Spaces in value break the radio buttons
if ($input->type == 'radio' || $input->type == 'checkbox')
$input->value = str_replace(" ", "_", $input->value);
}
foreach($dom_html->find('select') as $input)
{
if (!isset($input->size))
{ $input->style = "width:150px;"; }
else
{
if ($input->size <= 15) { $input->style = "width:50px;"; }
elseif ($input->size <= 30) { $input->style = "width:100px;"; }
elseif ($input->size <= 50) { $input->style = "width:150px;"; }
elseif ($input->size <= 100) { $input->style = "width:250px;"; }
}
}
echo $dom_html->save();
}
else
{
if (is_developer())
echo "Hey Dev. The html code was not found in POST.";
}
}
// We're going to skip photoaddendum and display the photos directly
// because customfield writes html that we don't want
elseif ($field[tasktemplatefieldtype] == "photoaddendum")
{
echo "
";
if($field[tasktemplatefieldhelp])
echo "".button(help,$field[tasktemplatefieldhelp])."";
echo $field[tasktemplatefieldlabel].$display_required;
if($field[tasktemplatefielddescr])
echo " $field[tasktemplatefielddescr]";
echo " | ";
echo "
";
echo "";
$attr2[clientcompanypropertyid] = $clienttask[clientcompanypropertyid];
$attr2[clienttaskid] = $clienttask[clienttaskid];
$attr2[albumname] = $field[tasktemplatefieldlabel]." ".date_format(date_create($clienttask[clienttaskcreateddate]), "m-d-Y");
$sql = "select * from tblimage
where clienttaskid = ".db_number($attr2[clienttaskid])."
and clientcompanypropertyid = ".db_number($attr2[clientcompanypropertyid])."
and photogroupnames = ".db_tick($attr2[albumname])."
order by imagetitle";
$imgarr = db_query($sql);
$img_count = 0;
if (empty($imgarr))
echo "| No photos uploaded yet. | ";
else
echo "";
foreach ($imgarr as $k=>$img)
{
if (!file_exists($_SERVER[DOCUMENT_ROOT].'/photos/'.getrelativephotodir($img[imageid]).$img[imagefilename]))
continue;
$picinfo = getimagesize ('photos/'.getrelativephotodir($img[imageid]).$img[imagefilename]);
if ($picinfo !== false) {
$x = $picinfo [0];
$y = $picinfo [1];
}
unset ($newwidth);
if ($x<300){
$dif= 300 % $x;
$newy = $y*$diff;
if ($newy>800 && $y<800)
$newwidth=$x;
if ($y>800){
$diff = 800 % $y;
$newwidth = $x*$diff;
}
}
if (!$newwidth)
$newwidth = 300;
echo "."$img[imagefilename]) $img[imagetitle] | ";
$img_count = $img_count + 1;
// Insert new row
if ($img_count >= $photosperrow)
{
echo " |
"; // This will prevent PDF error "The content of a TD tag does not fit on only one page action: 1".
$img_count = 0;
}
}
if (!empty($imgarr))
echo " ";
echo " ";
echo " | ";
echo "
";
}
else
{
if($field[tasktemplatefieldtype]=="fillablepdf")
{
$fillarr = array();
$fillarr[clienttaskid] = $clienttask[clienttaskid];
$fillarr[tasktemplatefieldid] = $field[tasktemplatefieldid];
if (is_array($field[tasktemplatefieldattr2]))
$field[tasktemplatefieldattr2] = array_merge($field[tasktemplatefieldattr2], $fillarr);
else
$field[tasktemplatefieldattr2] = $fillarr;
}
if($field[tasktemplatefieldattr1]=="utility_list" || $field[tasktemplatefieldattr1]=="hoa3id")
$_POST=$value;
if($field['tasktemplatefieldsinglecolumndisplay'])
{
echo "
";
echo "
$field[tasktemplatefieldlabel] ".$display_required;
if($field[tasktemplatefieldhelp]&&loginid())
echo button(help,$field[tasktemplatefieldhelp]);
if($field[tasktemplatefielddescr]&&loginid())
echo " $field[tasktemplatefielddescr]";
echo "
";
customfield($field[tasktemplatefieldtype],"tasktemplatefield_$field[tasktemplatefieldid]",$value
, $field[tasktemplatefieldattr1]
, $field[tasktemplatefieldattr2]
, $field[tasktemplatefieldattr3]);
echo " |
";
}
else
{
unset ($closetable);
if($field['tasktemplatefieldtype'] == "clienttaskbid"){
$field['tasktemplatefieldattr2'] = $clienttask;
ob_start();
ob_start();
echo "";
}
echo "
";
if($field['tasktemplatefieldhelp'])
echo "" . button('help', $field['tasktemplatefieldhelp']) . "";
echo $field['tasktemplatefieldlabel'] . $display_required;
if($field['tasktemplatefielddescr'])
echo " $field[tasktemplatefielddescr]";
echo " | ";
echo "";
$value = $clienttask['tasktemplatefields'][$field['tasktemplatefieldid']]['tasktemplatefieldentryvalue'];
customfield($field[tasktemplatefieldtype],"tasktemplatefield_$field[tasktemplatefieldid]",$value
, $field[tasktemplatefieldattr1]
, $field[tasktemplatefieldattr2]
, $field[tasktemplatefieldattr3]);
if($field['tasktemplatefieldtype'] == "clienttaskbid"){
echo ob_get_clean();
}
echo " | ";
echo "
";
}
}
if ($field[tasktemplatefieldtype] != "mini_html_form")
echo "
";
}
$template = ob_get_clean();
require_once("simple_html_dom.php");
$html = str_get_html($template);
foreach($html->find('textarea') as $r){
if ($r->value && !trim($r->innertext))
$r->innertext = pdfhtmlsafe($r->value);
}
$template = $html->save();
unset($html); //destory object.
return $template;
}
function get_tasktemplate_preview($tasktemplate, $taskid=0)
{
if($tasktemplate||!is_array($tasktemplate)||!$tasktemplate[fields])
{
$tasktemplate =get_tasktemplate($tasktemplate,array());
d(task_template,$tasktemplate);
}
ob_start();
echo "
Task Template Preview: $tasktemplate[tasktemplatename]
$tasktemplate[tasktemplateinstr]
";
$ret = display_tasktemplate_rows($tasktemplate,array(), $taskid);
echo $ret;
if(!$ret)
echo "| No fields setup for this template |
";
echo "
";
$template = ob_get_clean();
return $template;
}
function clienttask_create($roleid,$clientcompanypropertyid, $clientcompanypropertyassignmentid,$taskname, $taskdescr,$taskdays,$tasktemplateid,$completeroleserial="",$approvedroleserial="", $autoapprove="",$taskextra=array(), $clientpretaskid=0)
{
d('taskname',$taskname);
if(!$clientcompanypropertyassignmentid)
return;
if(!$clientcompanypropertyid)
ddie('attempting to clienttask_create() without a clientcompanypropertyid');
if(!is_numeric($taskdays))
$taskdays=3; //default the number of days to three
$createdby = loginid();
if(companyid())
$createdby = 0;
$extrafields = "";
$extradata = "";
if (!empty($taskextra)){
foreach ($taskextra as $k=>$data){
if (trim($k) == 'clientpretaskid'){
$clientpretaskid = db_number($data);
unset ($taskextra[$k]); // Remove this key so we dont duplicate.
}
}
$extrafields = "," . implode(",", array_keys($taskextra));
$extradata = ",'" . implode("','", $taskextra) . "'"; // Since we dont know what kind of data is passed we are going to use ticks
}
if ($clientpretaskid > 0)
{
$extrafields .= ",clientpretaskid";
$extradata .= ",".db_number($clientpretaskid);
}
$clienttaskid = db_nextid('clienttask');
$sql = "
insert into tblclienttask
(clienttaskid, clientcompanyid, clientcompanypropertyid, clientcompanypropertyassignmentid, clienttaskcreatedby, clienttasktitle
,clienttaskdescription,clienttaskduedate,tasktemplateid,clienttaskcompletionrole,clienttaskapprovedrole, clienttaskautoapprove, clienttaskresponsability" . $extrafields .")
values
($clienttaskid, (select clientcompanyid from tblclientcompanyproperty
where clientcompanypropertyid = $clientcompanypropertyid)
, $clientcompanypropertyid
, $clientcompanypropertyassignmentid
, " . db_number($createdby) . "
, " . db_tick($taskname) . "
, " . db_tick($taskdescr) . "
, now() + interval '$taskdays days'
, " . db_number($tasktemplateid) . "
, " . db_tick($completeroleserial) . "
, " . db_tick($approvedroleserial) . "
, " . db_number($autoapprove) . "
, " . db_number($roleid) . $extradata . ")";
db_exec($sql,1);
d(clienttask_create, $sql);
$clienttask = get_clienttask($clienttaskid);
$backtrace = debug_backtrace(false);
array_reverse($backtrace);
$backdetails[]="Backtrace:";
foreach($backtrace as $func)
{
$last = $func[file];
$linenumber = $func[line];
$path_parts = pathinfo($last);
$backdetails[]= "- > $path_parts[basename]:$linenumber";
}
$outdetails = implode("",$backdetails);
dlog(clienttask,"Created $clienttaskid via $_SERVER[REQUEST_METHOD]: ($roleid,$clientcompanypropertyid, $clientcompanypropertyassignmentid,'$taskname', '$taskdescr',$taskdays,$tasktemplateid,'$completeroleserial','$approvedroleserial', $autoapprove ||$outdetails ");
//need to create a message that is sent out as part of this task creation, probably going to need to extend this significatnly to allow for custom types of tasks that are created with attachments and templates
//this is gonna give more involved messages
d(clienttask,$clienttask);
$em = get_email(clienttaskassigned);
$emailtext = email_replace_arr($em[emailtext],$clienttask);
$emailsubject = email_replace_arr($em[emailsubject],$clienttask);
$fromclient=1;
d(email_arr,$em);
clientmessage_create($fromclient,$roleid,$clientcompanypropertyid,$clientcompanypropertyassignmentid,$clienttaskid,$em[emailfrom],$emailsubject,$emailtext,$attachments);
}
function clienttask_complete($clienttaskid=0)
{
// check to see if task should be completed
if($clienttaskid)
{
$sql = "select * from tbltaskrequirement t
join tblclienttask using(clienttaskid)
where t.clienttaskid = ".db_number($clienttaskid);
$requirementqry = db_query($sql,0,1);
d(requirementqry,$requirementqry);
d(tasktemplateid,$requirementqry[0][tasktemplateid]);
$sql = "select documenttitle from tbldocument where clienttaskid = ".db_number($clienttaskid);
$docsqry = db_query($sql,0,1);
d(docsqry,$docsqry);
foreach($requirementqry as $rk => $requirement)
{
foreach($docsqry as $dk => $dtitle)
{
if($requirement[taskrequirementattribute1] == "uploadadditionaldoc")
unset($requirementqry[$rk]);
elseif($requirement[taskrequirementtitle] == $dtitle[documenttitle])
unset($requirementqry[$rk]);
}
}
$sql = "select * from tblimage where clienttaskid = ".db_number($clienttaskid);
$imgqry = db_query($sql,0,1);
d(imgqry,$imgqry);
foreach($requirementqry as $rk => $requirement)
{
foreach($imgqry as $dk => $dtitle)
{
if($requirement[taskrequirementtitle] == $dtitle[photogroupnames])
unset($requirementqry[$rk]);
}
}
$sql = "select * from tblclienttask
join tbltasktemplatefield using (tasktemplateid)
left join tbltasktemplatefieldentry using (clienttaskid,tasktemplatefieldid)
where clienttaskid = " . db_number ($clienttaskid) . "
and tasktemplatefieldinactive is null";
$fieldentryarr = db_query($sql);
d(sql,$sql);
d(fieldentryarr,$fieldentryarr);
// By default set to yes
$has_met_requirements = 1;
d($fieldentryarr);
foreach($fieldentryarr as $fk =>$field)
{
if ($field[tasktemplatefieldrequired] || strtolower(trim($field[tasktemplatefieldtype])) =='mini_html_form')
{
// There is a requirement so make sure that they meet it
$has_met_requirements = 0;
d("----- START VALIDATION -----");
$valid_function = "tasktemplatefield_validate_{$field[tasktemplatefieldtype]}";
$extra = array();
$extra[clienttaskid] = db_number($clienttaskid);
$extra[clientcompanypropertyid] = $field[clientcompanypropertyid];
d (field,$field);
if (strtolower(trim($field[tasktemplatefieldtype])) =='mini_html_form'){
$custommessages["repairs_item_grand_price"]="REPAIRS ITEM:Grand Total for All Repairs If it does not apply, please put N/A (not applicable) to complete this task.";
d('mini_html_form_validation');
$tasktemplatefieldid = $field[tasktemplatefieldid];
$clientcompanyid = db_firstval("select clientcompanyid from tblclienttask where clienttaskid = ".db_number($clienttaskid));
d('required:',get_minihtml_required_fileds($tasktemplatefieldid,$clientcompanyid));
foreach (get_minihtml_required_fileds($tasktemplatefieldid,$clientcompanyid) as $key=>$val){
if (!$_POST[$val[tasktemplaterequiredfieldhtmlfieldname]]){
if ($custommessages[$val[tasktemplaterequiredfieldhtmlfieldname]])
set_message("Please Fill Required Form Field: ".$custommessages[$val[tasktemplaterequiredfieldhtmlfieldname]],error);
else
set_message("Please Fill Required Form Field: ".str_replace("_"," ",$val[tasktemplaterequiredfieldhtmlfieldname]),error);
}
}
}
if ($field[tasktemplatefieldtype] == 'photoaddendum')
$extra[photogroupnames] = $field[tasktemplatefieldlabel]." ".date_format(date_create($field[clienttaskcreateddate]), "m-d-Y");
if (function_exists($valid_function))
{
$skipvalidation=compare_values_fordependantfields_andskipvalidation($field[tasktemplatefieldid],$field[tasktemplatefieldtype],$field[tasktemplatefieldentryvalue],$field[tasktemplateid],$_POST);
if($skipvalidation)
$has_met_requirements=1;
else
$has_met_requirements = $valid_function($field[tasktemplatefieldtype], $field[tasktemplatefieldentryvalue], $field[tasktemplatefieldattr1], $field[tasktemplatefieldattr2], $field[tasktemplatefieldattr3], $extra,$field[tasktemplatefieldid],$field[tasktemplatefieldlabel]);
}
else
{
$skipvalidation=compare_values_fordependantfields_andskipvalidation($field[tasktemplatefieldid],$field[tasktemplatefieldtype],$field[tasktemplatefieldentryvalue],$field[tasktemplateid],$_POST);
if($skipvalidation)
$has_met_requirements=1;
else
$has_met_requirements = tasktemplatefield_validate_simplevalues($field[tasktemplatefieldtype], $field[tasktemplatefieldentryvalue], $field[tasktemplatefieldattr1], $field[tasktemplatefieldattr2], $field[tasktemplatefieldattr3], $extra,$field[tasktemplatefieldid],$field[tasktemplatefieldlabel]);
}
d(has_met_requirements, $has_met_requirements);
d("----- END VALIDATION -----");
if (!$has_met_requirements)
{
d("set the message!!");
set_message("Please fill out: $field[tasktemplatefieldlabel]", error);
break;
}
}
}
if (!has_message(error))
if(count($requirementqry) < 1 && $has_met_requirements)
{
$completeclienttask = get_clienttask($clienttaskid);
// Complete and auto approve
if ($completeclienttask[clienttaskautoapprove])
{
$sql = "update tblclienttask
set clienttaskcompleteddate = coalesce(clienttaskcompleteddate,now())
, clienttaskcompleteapproveddate = now()
, clienttaskcompletedby = case when clienttaskcompletedby = 0 then ".loginid()." else clienttaskcompletedby end
where clienttaskid = ".db_number($clienttaskid);
}
else
{
$sql = "update tblclienttask
set clienttaskcompleteddate = coalesce(clienttaskcompleteddate,now())
, clienttaskcompletedby = case when clienttaskcompletedby = 0 then ".loginid()." else clienttaskcompletedby end
where clienttaskid = ".db_number($clienttaskid);
}
db_exec($sql,1);
// Get the names to email
$sql = "select *
from tblclienttask
join tblclientcompanyproperty using (clientcompanypropertyid)
where clienttaskid = ".db_number($clienttaskid);
$clientaskqry = db_first($sql);
$unserial = unserialize($clientaskqry[clienttaskcompletionrole]);
if (count($unserial) > 1)
{
$eml = db_first("select * from tblemail where emailshortname = 'taskcompletenotification'");
$subject = email_replace_var($eml[emailsubject],"clienttaskname",$clientaskqry[clienttasktitle]);
$body = email_replace_var($eml[emailtext],"clienttaskname",$clientaskqry[clienttasktitle]);
$body = email_replace_var($body,"clientcompanypropertyaddress",$clientaskqry[clientcompanypropertyaddress]);
$body = email_replace_var($body,"link","https://$_SERVER[HTTP_HOST]");
foreach($unserial as $clientstaffid){
$sql = "select clientstaffemail from tblclientstaff where clientstaffid = ".db_number($clientstaffid);
$staffqry = db_first($sql);
if (!$staffqry)
continue;
if (!$staffqry[clientstaffemail])
continue;
html_mail($staffqry[clientstaffemail],$eml[emailfrom],$subject,$body);
}
}
return 1;
}
else
d('-----=task_has_more_requirements=--------');
}
}
function get_clienttask_documentlist($clienttaskid)
{
if(!db_number($clienttaskid))
return;
$sql = "select documentid,1 as pretty from tbldocument where clienttaskid = $clienttaskid and documentvoideddate is null";
$qry=db_query($sql);
ob_start();
foreach($qry as $row)
echo "
".customfield_display_documentupload($row);
$out=ob_get_clean();
return $out;
}
function tasktemplatefield_validate_mini_html_form($fieldname, $value, $attr1="", $attr2="", $attr3="", $extra="" )
{
d(validate_mini_html_form);
return 1; // not validating yet so return true
return 0;
}
function tasktemplatefield_validate_documentupload($fieldname, $value, $attr1="", $attr2="", $attr3="", $extra="" )
{
d(validate_documentupload);
d(doc_value,$value);
if (!is_numeric($value))
$value = unserialize($value);
if (!is_numeric($value) && $value <= 1)
return 0;
$sql = "select count(1) as doccount
from tbldocument
where documentid = ".db_number($value);
$count = db_first($sql);
d(doc_sql,$sql);
d(doccount, $count);
if ($count[doccount] > 0)
return 1;
return 0;
}
function tasktemplatefield_validate_fillablepdf($fieldname, $value, $attr1="", $attr2="", $attr3="", $extra="" )
{
d(validate_fillablepdf);
if (unserialize($value) == "")
return 0;
$sql = "select count(1) as doccount
from tbltasktemplatefieldrevision join tbldocument using (documentid)
where tbltasktemplatefieldrevision.tasktemplatefieldversionid = ".db_number(unserialize($value))."
and tbltasktemplatefieldrevision.clienttaskid = ".db_number($extra[clienttaskid])."
";
$count = db_first($sql);
d(doc_sql,$sql);
d(doccount, $count);
if ($count[doccount] > 0)
return 1;
return 0;
}
function tasktemplatefield_validate_photoaddendum($fieldname, $value, $attr1="", $attr2="", $attr3="", $extra="",$fieldid=0,$fieldlabel="" )
{
d(validate_photoaddendum);
d(field,$field);
$sql = "select count(1) as imgcount from tblimage
where clienttaskid = ".db_number($extra[clienttaskid])."
and clientcompanypropertyid = ".db_number($extra[clientcompanypropertyid])."
and photogroupnames = ".db_tick($extra[photogroupnames]);
$imgarr = db_first($sql);
d(img_sql,$sql);
d(_validate_imgcount, $imgarr);
if ($imgarr[imgcount] > 0)
return 1;
return 0;
}
function tasktemplatefield_validate_propertyextension($fieldname, $value, $attr1="", $attr2="", $attr3="", $extra="" )
{
d(validate_propertyextension);
// Utility and HOA are arrays. Validate here
if($attr1==utility_list || $attr1==hoaid || $attr1==hoa2id || $attr1==hoa3id)
{
if(!is_array($value))
$value = unserialize($value);
if(is_array($value))
foreach($value as $k=>$myvalue)
{
d(___check_____, $k);
// Override certain values that break the validation
// because value exists even if the form hasn't been filled
if($k == "propertyhoaassessment" && $myvalue == 0)
;
elseif($k == "propertyextensionhoaassessment" && $myvalue == 0)
;
elseif($k == "propertyextensionhoa2signrestriction" && $myvalue == 0)
;
elseif (trim($myvalue) != "")
{
d(value_that_exited_validation, $myvalue);
return 1; // Found a value
}
}
}
else
{
if ($value != "" && unserialize($value) != "")
return 1;
}
return 0;
}
function compare_values_fordependantfields_andskipvalidation($filedid,$fieldtype,$fieldvalue,$tasktemplateid,$postedvals)
{
// get the task template and find this field
$sql = "select *
from tbltasktemplate
join tbltasktemplateclientcompany using (tasktemplateid)
join tbltasktemplatefield using (tasktemplateid)
where 0=0
and tasktemplateinactivedate is null
and tasktemplateid =$tasktemplateid
";
$qry = db_query($sql);
// check for dependencies
foreach($qry as $templatefieldnum=>$templatefielddata)
{
if($templatefielddata[tasktemplatefieldid]==$filedid)
{
if($templatefielddata[tasktemplatefielddependentonid])
{
$postedcompval=$postedvals["tasktemplatefield_".$templatefielddata[tasktemplatefielddependentonid]];
$visibleifvalueis=$templatefielddata[tasktemplatefielddependentonvalue];
if($postedcompval==$visibleifvalueis)
return 0; // this filed is visible and should be validated
else
return 1;//this filed is hidden and should not be validated
}
}
}
}
function tasktemplatefield_validate_simplevalues($fieldtype, $value, $attr1="", $attr2="", $attr3="", $extra="" ,$fieldid=0,$fieldlabel="")
{
if ($value != "" && unserialize($value) != "")
return 1;
return 0;
}
function sendholdmail($shortname,$taskinfo)
{
$companyemail = $taskinfo[staffemail];
$arr['stafffname'] = $taskinfo[stafffname];
$arr['clienttasktitle'] = $taskinfo[clienttasktitle];
$arr['clientcompanyname'] = $taskinfo[clientcompanyname];
$arr['clientcompanypropertyaddress'] = $taskinfo[clientcompanypropertyaddress];
$sql = "select * from tblemail where emailshortname = ".db_tick($shortname);
$eml = db_first($sql);
$subject = email_replace_arr($eml[emailsubject],$arr);
$body = email_replace_arr($eml[emailtext],$arr);
if($eml[emailccaddress])
html_mail_cc($companyemail,$eml[emailccaddress],$eml[emailfrom],$subject,$body);
else
html_mail($companyemail,$eml[emailfrom],$subject,$body);
}
/**
* @name procestaskextensions
* @param array clienttask
* @param array myextensions
* @useage This function determines if there are any extensions for this task property. If so it will update the extensions in the database for this property. If a myextensions array is passed in it will only update those extensions listed.
* @uses functions_clientproperty.php for processing valuations.
*
*/
function procestaskextensions($clienttask,$myextensions=FALSE)
{
//create a list of extensions to update db with
if(!$clienttask[tasktemplatefields] || !clientcompanyid()) //run only if we have extensions and it has been called by client
return false;
$extensionkey="";
$uparray = array();
if(is_array($myextensions) && $myextensions) //build array of values to be upadted
{
foreach($myextensions as $extension => $eval) //have to find the entries with tasktemplatefield_xx to get the actual fieldname
{
if(substr($extension,0,17) == "tasktemplatefield")
{
$parts = explode("_",$extension);
$extension = $clienttask[tasktemplatefields][$parts[1]][tasktemplatefieldattr1];
$uparray[$extension] = $eval;
}
}
}
else
{
foreach ($clienttask[tasktemplatefields] as $key=>$searchextension)
{
if (is_array($searchextension[tasktemplatefieldentryvalue]))
{
foreach($searchextension[tasktemplatefieldentryvalue] as $fld=>$val)
$uparray[$fld] = $val;
}
else
{
$uparray[$searchextension[tasktemplatefieldattr1]] = $searchextension[tasktemplatefieldentryvalue];
}
}
}
//build array of extension values already in the database
$sql = "select * from tblpropertyextensionentry
where clientcompanypropertyid=".db_number($clienttask[clientcompanypropertyid]);
$propertyextensions = db_query($sql,1,0,propertyextensionkey);
foreach ($propertyextensions as $key => $row)
{
$extensionsinuse[$row[propertyextensionkey]] = $row[propertyextensionentryid];
}
$extra1[clienttaskid]=$clienttask[clienttaskid];
d(uparray,$uparray);
if($uparray)
{
foreach ($uparray as $key=>$value){
if (is_array($value))
$out[$key]=implode(",",$value);
else
$out[$key]=$value;
}
unset($uparray);
$uparray=$out;
unset($out);
d(uparray,$uparray);
clientcompanyproperty_set_propertyextension($clienttask[clientcompanypropertyid],$uparray,0,$extra1);
}
/**
* Here we going to process html_mini_form mapped extensions
* This is extension to the function
* @uses functions_clientproperty.php
* @see clientcompanyproperty_set_propertyextension function for more info.
*/
d(clienttask,$clienttask);
$clientcompanypropertyid = $clienttask[clientcompanypropertyid];
foreach ($clienttask[tasktemplatefields] as $field=>$data){
if ($data[tasktemplatefieldtype] == 'mini_html_form'){
$tasktemplateid = $data[tasktemplateid];
$tasktemplatefieldentryvalue = $data[tasktemplatefieldentryvalue];
$tasktemplatefieldid = $data[tasktemplatefieldid];
$formdata=1;
}
}
if ($formdata){
// Ok we got html form
$my_propertyextensions = array(); // initialize empty array
$fieldmap = get_tasktemplatehtmlfieldmap($tasktemplateid,clientcompanyid());
d(fieldmap,$fieldmap);
foreach ($fieldmap as $key=>$value){
if (preg_match("@^db_@",$value[tasktemplatefieldmapminihtmlformfieldname])){
$column = preg_replace("@^db_@","",$value[tasktemplatefieldmapminihtmlformfieldname]);
$tbval = $clienttask[$column];
d(value,$value);
$my_propertyextensions[$value[propertyextensionkey]]=$tbval;
unset($column,$tbval);
}else
$my_propertyextensions[$value[propertyextensionkey]]=$tasktemplatefieldentryvalue[$value[tasktemplatefieldmapminihtmlformfieldname]];
}
d(extensions,$my_propertyextensions);
// This will overwrite any data that is in client task with what was entered on approval screen
foreach ($my_propertyextensions as $key=>$val){
if ($_POST[$key]){
if (is_array ($_POST[$key]))
$_POST[$key]=implode(",",$_POST[$key]);
$my_propertyextensions[$key]=$_POST[$key];
}
}
/*****
* Rules check
* 1. Don't update this attribute existing value
* 2. Don't update if any field in category has a value
*/
$rule1 = get_extensionshavevalues($tasktemplatefieldid,clientcompanyid(),$clientcompanypropertyid);
foreach ($my_propertyextensions as $key=>$value){
if ( array_key_exists($key,$rule1)){
unset($my_propertyextensions[$key]);
}
}
d(rule,$rule1);
d(rule1,$my_propertyextensions);
$rule2 = get_dontupdatecatrule(clientcompanyid(),$tasktemplatefieldid,$clientcompanypropertyid);
// No we filter by rule 2
if (is_array($rule2) && !empty($rule2)){
foreach ($rule2 as $category=>$data){
foreach ($propertyextensions as $key=>$value){
if ($data[propertyextensionkey] == $key)
unset($my_propertyextensions[$key]); // remove extension
}
}
}
d(rule,$rule2);
d(rule2,$my_propertyextensions);
d(extra,$extra1);
// Since we are passing whole array of extensions updated value is not been used. we going to remove any extensins that are not in that array.
//foreach ($my_propertyextensions as $propertyexten=>$val){
if ($my_propertyextensions)
clientcompanyproperty_set_propertyextension($clientcompanypropertyid,$my_propertyextensions,0,$extra1);
}
}
/**
* @name procestaskreq
* @param array clienttask
* @param array doc
* @useage This function determines if there are any required documents for this task. If so it will copy the documents so the client has a copy. If a doc array is passed in it will only copy the documents listed to the client.
*
*/
function procestaskreq($clienttask,$doc=FALSE) {
// If the document was requested to be listed under the Documents tab, copy it.
if($doc) {
foreach($doc as $docnum => $one)
{
$sql = "select * from tbldocument where documentid = ".db_number($docnum);
$sourcesql = db_first($sql);
if(!$sourcesql[documentid])
return false;
$dirname = getrelativedocumentdir($sourcesql[documentid]);
$pathname = "$_SERVER[DOCUMENT_ROOT]/document/$dirname";
$docfile = $pathname.$sourcesql[documentname];
copy($docfile, "/tmp/".$sourcesql[documentname]); //copy the document so the original isn't deleted
// copy the document to the genesis side
$extarray[propertyextensionextra1] = $sourcesql[documentdescription];
$extarray[title] = $sourcesql[documenttitle];
$extarray[documenttype] = $sourcesql[documenttype];
$extarray[documentgroup] = $sourcesql[documentgroup];
$clientdocid = save_file_to_document($clienttask[clientcompanypropertyid], "clientcompanyproperty", "/tmp/".$sourcesql[documentname], $extarray);
}
} else {
$taskreqarr = get_taskrequirements($clienttask[clienttaskid]);
if($taskreqarr)
{
foreach($taskreqarr as $trk=>$requirement)
{
if($requirement[taskrequirementtype] == document)
{
$sql = "select * from tbldocument where documentid = ".db_number($requirement[documentid]);
$sourcesql = db_first($sql);
if(!$sourcesql[documentid])
return false;
$dirname = getrelativedocumentdir($sourcesql[documentid]);
$pathname = "$_SERVER[DOCUMENT_ROOT]/document/$dirname";
$docfile = $pathname.$sourcesql[documentname];
if (!is_file($docfile))
return false; // This will prevent us from attempting to copy bad or empty document.
copy($docfile, "/tmp/".$sourcesql[documentname]); //copy the document so the original isn't deleted
// copy the document to the genesis side
$extarray[propertyextensionextra1] = $sourcesql[documentdescription];
$extarray[title] = $sourcesql[documenttitle];
$extarray[documenttype] = $sourcesql[documenttype];
$extarray[documentgroup] = $sourcesql[documentgroup];
$clientdocid = save_file_to_document($clienttask[clientcompanypropertyid], "clientcompanyproperty", "/tmp/".$sourcesql[documentname], $extarray);
}
}
}
}
return true;
}
function get_assignedcompanyname($staffid,$accountstaffid,$externaluserid,$assignmentaliasclientstaffid)
{
if(!$staffid && !$accountstaffid && !$externaluserid && !$assignmentaliasclientstaffid)
ddie("Invalid ids.");
if($accountstaffid) {
$sql = "select accountname from tblaccount join tblaccountstaff using(accountid) where accountstaffid = ".$accountstaffid;
$accountname = db_firstval($sql);
if($accountname)
return $accountname;
}elseif($assignmentaliasclientstaffid){
return db_firstval("SELECT clientcompanyname FROM tblclientcompany WHERE clientcompanyid = (SELECT clientcompanyid FROM tbllogin WHERE clientstaffid = " . $assignmentaliasclientstaffid . ")");
}elseif($externaluserid) {
$sql = "select externalusercompanyname from tblexternaluser where externaluserid = ".$externaluserid;
$externalusercompanyname = db_firstval($sql);
//d("externaluserid:$externaluserid sql:$sql",$externalusercompanyname);
if($externalusercompanyname)
return $externalusercompanyname;
}elseif($staffid) {
$sql = "select companyid
, clientcompanyid
from tbllogin where staffid= ".$staffid;
$qry = db_first($sql);
//d("staffid: $staffid, sql:$sql",$qry);
if($qry[companyid])
$sql = "select companyname from tblcompany where companyid = ".db_number($qry[companyid]);
else
$sql = "select clientcompanyname as companyname from tblclientcompany where clientcompanyid = ".db_number($qry[clientcompanyid]);
$qry = db_first($sql);
if($qry[companyname])
return $qry[companyname];
}
return "";
}
function keylengthcompare($a, $b)
{
$a=strlen($a);
$b=strlen($b);
if($a == $b)
return 0;
return ($a > $b ? -1 : 1);
}
function get_tasktemplatereplacementarray($taskid=0, $viewpartial=0, $clientcompanyids="", $clientcompanypropertyid=0)
{
$hasclientcompanyids=FALSE;
$specialattributevalue='-1';
if($taskid) {
$clienttask = get_clienttask($taskid);
$specialattributevalue="";
}
elseif($clientcompanypropertyid)
$specialattributevalue="";
if(!$clientcompanyids && $clienttask)
$clientcompanyids=$clienttask[clientcompanyid];
if($clientcompanyids && $clientcompanyids!="")
$hasclientcompanyids=TRUE;
$sql= "select column_name
from information_schema.columns
where table_name = 'tblclientcompanyproperty' order by column_name";
$replaceqry=db_query($sql,1,0,column_name);
$replaceqrynewarr=array();
//d("replaceqry: ", $replaceqry);
foreach($replaceqry as $replacekey=>$replacevalue) {
$replaceqrynewarr[str_replace('clientcompanyproperty', '', $replacekey)]='';
//$replaceqrynewarr[str_replace('clientcompanyproperty', 'property', $replacekey)]='';
}
if($hasclientcompanyids) {
$sql = "select distinct propertyextensionkey, propertycategoryid , propertyextensionlabel
from tblpropertyextension
left join tblclientcompanypropertyextension using (propertyextensionid)
left join tbltabcategorypropertyextension using(propertyextensionid)
where propertyextensionkey ilike 'property%'
and (tblclientcompanypropertyextension.clientcompanyid IN ($clientcompanyids)
or tbltabcategorypropertyextension.clientcompanyid IN ($clientcompanyids) )
";
$sql.= " order by propertyextensionkey";
} else {
$sql = "select propertyextensionkey, propertycategoryid, propertyextensionlabel
from tblpropertyextension
where propertyextensionkey ilike 'property%' ";
if($viewpartial)
$sql.= " and propertyextensionclientuse>0
and exists(select 1 from tblclientcompanypropertyextension where propertyextensionid = tblpropertyextension.propertyextensionid) ";
$sql.= " order by propertyextensionkey";
}
$extensionentry=db_query($sql,1,0,propertyextensionkey);
foreach ($extensionentry as $extensionentrykey=>$extensionentryvalue) {
$extensionentrykey = str_replace("propertyextension","",$extensionentrykey);
if($hasclientcompanyids)
$replaceqrynewarr[$extensionentrykey]=$extensionentryvalue[propertycategoryid];
else
$replaceqrynewarr[$extensionentrykey]='';
}
$replaceqrynewarr[currentdate]=dttime_format(time());
//$replaceqrynewarr[assignedagentcompanyname]=$specialattributevalue;
if($hasclientcompanyids)
{
$sql= "select distinct crolename
from tblcrole
where clientcompanyid in ($clientcompanyids)
order by crolename
";
$qrycrole = db_query($sql);
foreach($qrycrole as $role)
{
$cname=$role[crolename];
$cname = strtolower($cname);
$cname = str_replace(' ','',$cname);
$replaceqrynewarr[assignedclientrole.$cname]=$specialattributevalue;
}
$sql= "select distinct rolename
from tblrole
where clientcompanyid in ($clientcompanyids)
and rolepropertyworking=1
order by rolename
";
$qrycrole = db_query($sql);
foreach($qrycrole as $role)
{
$cname=$role[rolename];
$cname = strtolower($cname);
$cname = str_replace(' ','',$cname);
$replaceqrynewarr[assignedstaffrole.$cname]=$specialattributevalue;
}
$sql= "select distinct assignmentmethodname
from tblassignmentmethod
where tblassignmentmethod.clientcompanyid in ($clientcompanyids)
and assignmentmethodinactivedate is null
";
$ams = db_query($sql);
foreach($ams as $am)
{
$amname=$am[assignmentmethodname];
$amname = strtolower($amname);
$amname = str_replace(' ','',$amname);
$amname = str_replace("'",'',$amname);
$amname = str_replace('"','',$amname);
$kam = 'assigned'.$amname;
$replaceqrynewarr[$kam.name]=$specialattributevalue;
$replaceqrynewarr[$kam.companyname]=$specialattributevalue;
$replaceqrynewarr[$kam.phone]=$specialattributevalue;
$replaceqrynewarr[$kam.email]=$specialattributevalue;
}
}
ksort($replaceqrynewarr);
//print_r($replaceqrynewarr);
if($taskid || $clientcompanypropertyid)
{
//print_r($clienttask);
//die("died in function get_tasktemplatereplacementarray");
/* //Commented out the following section because assignedagentcompanyname was replaced with a method that pulls the company name for each type of assignment.
$sql = "select tl.companyid
, tl.clientcompanyid
from tblclienttask
left join tblclientcompanypropertyassignment using(clientcompanypropertyassignmentid)
left join tbllogin tl using(staffid)
where clienttaskid=$taskid";
$qry = db_query($sql);
if($qry[0][companyid])
$sql = "select companyname from tblcompany where companyid = ".db_number($qry[0][companyid]);
else
$sql = "select clientcompanyname as companyname from tblclientcompany where clientcompanyid = ".db_number($qry[0][clientcompanyid]);
$qry = db_query($sql);
//d("qry: ",$qry[0][companyname]);
$replaceqrynewarr[assignedagentcompanyname]=$qry[0][companyname];
*/
$ccpid = ($taskid)?$clienttask[clientcompanypropertyid]:$clientcompanypropertyid;
$sql= "select distinct rolename
, clientstafffname
, clientstafflname
from tblclientcompanypropertyrole
join tblrole using(roleid)
join tblclientstaff using(clientstaffid)
where clientcompanypropertyid = $ccpid
";
$qrycrole = db_query($sql);
foreach($qrycrole as $role)
{
$cname=$role[rolename];
$cname = strtolower($cname);
$cname = str_replace(' ','',$cname);
$replaceqrynewarr[assignedstaffrole.$cname]= $role[clientstafffname].' '.$role[clientstafflname];
}
$sql= "select distinct crolename
, contactname
, contactcname
from tblclientcompanypropertycrole
join tblcrole using(croleid)
join tblcontact using(contactid)
where clientcompanypropertyid = $ccpid
";
$qrycrole = db_query($sql);
foreach($qrycrole as $role)
{
$cname=$role[crolename];
$cname = strtolower($cname);
$cname = str_replace(' ','',$cname);
$replaceqrynewarr[assignedclientrole.$cname]= $role[contactname].' '.$role[contactcname];
}
//Removed this line because it was restricting assignments by current user and so no external or accountstaff info was being pulled for other assignments.
//$assigns = clientcompanypropertyassignment_get($clienttask[clientcompanypropertyid],'','',1);
$sql = "select *
, COALESCE(
(select staffphone from tblstaff ts where c.assigntype = 'staff' and ts.staffid =c.assigned)
, (select accountstaffphone from tblaccountstaff tas where c.assigntype = 'accountstaff' and tas.accountstaffid =c.accountstaffid)
, (select externaluserphone from tblexternaluser teu where c.assigntype = 'externaluser' and teu.externaluserid =c.externaluserid)
, ' '
) as assignphone
from tblclientcompanypropertyassignment a
join tblclientcompanyproperty b using(clientcompanypropertyid)
join vw_assigntypes c using(accountstaffid, staffid, externaluserid, assignmentaliasclientstaffid)
join tblassignmentmethod d using (assignmentmethodid)
where clientcompanypropertyid = ".$ccpid."
and d.clientcompanyid=b.clientcompanyid
and clientcompanypropertyassignmentexpired is null
and clientcompanypropertyassignmentrevokeddate is null
and clientcompanypropertyassignmentaccepteddate is not null
and clientcompanypropertyassignmentaccepteddate in
(
select max (clientcompanypropertyassignmentaccepteddate) as clientcompanypropertyassignmentaccepteddate
from tblclientcompanypropertyassignment ta
join tblclientcompanyproperty tb using(clientcompanypropertyid)
join vw_assigntypes tc using(accountstaffid, staffid, externaluserid, assignmentaliasclientstaffid)
join tblassignmentmethod td using (assignmentmethodid)
where clientcompanypropertyid = ".$ccpid."
and td.clientcompanyid=tb.clientcompanyid
and clientcompanypropertyassignmentexpired is null
and clientcompanypropertyassignmentrevokeddate is null
and clientcompanypropertyassignmentaccepteddate is not null
group by assignmentmethodid
)";
$assigns = db_query($sql);
//d(assigns,$assigns);
//print_r($assigns);
//die("Died in get_tasktemplatereplacementarray");
foreach($assigns as $assign)
{
//print_r($assign);
$amname=$assign[assignmentmethodname];
$amname = strtolower($amname);
$amname = str_replace(' ','',$amname);
$amname = str_replace("'",'',$amname);
$amname = str_replace('"','',$amname);
$kam = 'assigned'.$amname;
$replaceqrynewarr[$kam.name]=$assign[assignname];
$replaceqrynewarr[$kam.phone]=$assign[assignphone];
$replaceqrynewarr[$kam.email]=$assign[assignemail];
$replaceqrynewarr[$kam.companyname]=get_assignedcompanyname($assign[staffid],$assign[accountstaffid],$assign[externaluserid], $assign[assignmentaliasclientstaffid]);
// $replaceqrynewarr[$kam.fax]=$assign[assignfax]; //shouldn't work until we have fax.
}
//die("Died in get_tasktemplatereplacementarray");
$sql= "select * from tblclientcompanyproperty where clientcompanypropertyid=$ccpid";
$extensionentry=db_first($sql);
if ($extensionentry)
foreach ($extensionentry as $extensionentrykey=>$extensionentryvalue)
{
$replaceqrynewarr[$extensionentrykey]=$extensionentryvalue;
$replaceqrynewarr[str_replace('clientcompanyproperty', '', $extensionentrykey)]=$extensionentryvalue;
$replaceqrynewarr[str_replace('clientcompanyproperty', 'property', $extensionentrykey)]=$extensionentryvalue;
}
//ksort($replaceqrynewarr);
//foreach($replaceqrynewarr as $key=>$value)
// echo "key: $key value: $value
";
$sql = "select * from tblpropertyextensionentry where clientcompanypropertyid = $ccpid";
$extensionentry=db_query($sql,1,0,propertyextensionkey);
if ($extensionentry)
foreach ($extensionentry as $extensionentrykey=>$arr)
{
$replaceqrynewarr[$extensionentrykey] = $arr[propertyextensionentryvalue];
$replaceqrynewarr[str_replace('propertyextension','',$extensionentrykey)] = $arr[propertyextensionentryvalue];
}
if ($clienttask)
{
foreach($clienttask as $col =>$value)
if( strstr($col,'clientcompanyproperty') == $col || strstr($col,'name') == 'name' )
{
$replaceqrynewarr[$col] = $value;
$replaceqrynewarr[str_replace('clientcompanyproperty','',$col)] = $value;
$replaceqrynewarr[str_replace('clientcompanyproperty','property',$col)] = $value;
}
foreach($clienttask[tasktemplatefields] as $id =>$field)
if($clienttask[tasktemplatefieldtype] == 'propertyextension')
$replaceqrynewarr[$field[tasktemplatefieldattr1]] = $field[tasktemplatefieldentryvalue];
}
else
{
foreach ($replaceqrynewarr as $key => $value)
{
//if this key begins with this
if (strpos($key,'clientcompanyproperty') == 0)
$replaceqrynewarr[str_replace('clientcompanyproperty','',$key)] = $value;
}
}
}
unset($replaceqrynewarr['']);
ksort($replaceqrynewarr);
if($_GET[debug])
{
d(replaceqrynewarr, $replaceqrynewarr);
ddie(DIES_FOR_DEBUG);
}
return $replaceqrynewarr;
}
function replacetextwithvalue($documenttext, $replacementarr, $replacewith=false) {
//d($replacementarr,"Replcaement Array");
//echo "
$documenttext";
//print_r($replacementarr);
//echo "
";
//die("died in function replacetextwithvalue");
if(is_array($replacementarr)) {
foreach($replacementarr as $replacementkey=>$replacementvalue) {
//echo "replacementkey: $replacementkey replacementvalue: $replacementvalue
";
if($replacewith) {
$documenttext=str_replace("##$replacementkey", $replacewith, $documenttext);
$cckey = str_replace("propertyextension",$replacementkey,"");
if(($cckey!=="") && $cckey != $replacementkey)
$documenttext=str_replace("##$cckey", $replacewith, $documenttext);
$cckey = str_replace("clientcompany",$replacementkey,"");
if(($cckey!=="") && $cckey != $replacementkey)
$documenttext=str_replace("##$cckey", $replacewith, $documenttext);
$pkey = str_replace("property",$cckey,"");
if(($cckey!=="") && $cckey != $pkey)
$documenttext=str_replace("##$pkey", $replacewith, $documenttext);
} else {
$documenttext=str_replace("##$replacementkey", $replacementvalue, $documenttext);
$cckey = str_replace("propertyextension",$replacementkey,"");
if(($cckey!=="") && $cckey != $replacementkey)
$documenttext=str_replace("##$cckey", $replacementvalue, $documenttext);
$cckey = str_replace("clientcompany",$replacementkey,"");
if(($cckey!=="") && $cckey != $replacementkey)
$documenttext=str_replace("##$cckey", $replacementvalue, $documenttext);
$pkey = str_replace("property",$cckey,"");
if(($cckey!=="") && $cckey != $pkey)
$documenttext=str_replace("##$pkey", $replacementvalue, $documenttext);
}
}
}
//echo "
$documenttext";
//print_r($replacementarr);
//echo "
";
//die("died in function replacetextwithvalue");
return $documenttext;
}
//function replacetextintemplate($urlpath, $documentid, $taskid, $property=0, $clientcompanyproperty=0)
function replacetextintemplate($urlpath, $documentid, $taskid)
{
//echo "in customfield_replacetextintemplate: $urlpath documentid: $documentid taskid:$taskid
";
$currenttime=time();
$addrand=rand(1,99);
if(!$urlpath || $urlpath=="")
return false;
$replacementarr=get_tasktemplatereplacementarray($taskid);
//if($replacementarr)
//print_r($replacementarr);
//echo "
";
uksort($replacementarr, "keylengthcompare");
if(strtolower(substr($urlpath, -6, 6)) == ".vhtml") {
//echo "
found .vhtml file
";
$outdir="/data/web/temp/";
$templatefilename=basename($urlpath);
$newfilename=substr_replace($templatefilename, "$currenttime$addrand.pdf", -6, 6);
$documenttext=file_get_contents($urlpath);
$documenttext=replacetextwithvalue($documenttext, $replacementarr);
//echo htmlentities($documenttext)."
";
//echo "$documenttext
";
require_once('html2pdf_v4.03/html2pdf.class.php');
$html2pdf = new HTML2PDF('P', 'Letter', 'en');
$html2pdf->pdf->SetDisplayMode('fullpage');
//$html2pdf->writeHTML(substr($documenttext,4));
//this fix is in _inc/functions_workflow, _inc/functions_clienttask, ajax_clienttaskpdf, and schedule/task2pdf
$documenttext = preg_replace('/calibri/i', 'helvetica', $documenttext);
$html2pdf->writeHTML($documenttext);
$html2pdf->Output($outdir.$newfilename, 'F');
if(file_exists("$outdir$newfilename")) {
return "$outdir$newfilename";
} else
return $urlpath;
} elseif(strtolower(substr($urlpath, -5, 5)) == ".docx") {
//echo "
found docx file $_SERVER[DOCUMENT_ROOT]
";
$outdir="/data/web/temp/";
$tempdirname=$outdir."docx_".$currenttime."_".$addrand;
@mkdir_wrapper($tempdirname);
if(!file_exists($tempdirname))
return $urlpath;
$tempfilename=basename($urlpath);
$newfilename=substr_replace($tempfilename, "$currenttime$addrand.docx", -5, 5);
$tempfilenamezip=$tempfilename.".zip";
$tempfilepath="$tempdirname/$tempfilename";
$tempfilepathzip="$tempdirname/$tempfilenamezip";
exec("cp $urlpath $tempfilepathzip");
exec("unzip $tempfilepathzip -d $tempdirname");
exec("rm $tempfilepathzip");
$documenttextfile="$tempdirname/word/document.xml";
if(!file_exists($documenttextfile))
return $urlpath;
$documenttext=file_get_contents($documenttextfile);
//echo "$documenttext
";
$documenttext=replacetextwithvalue($documenttext, $replacementarr);
//echo "$documenttext
";
//die("died in function replacetextintemplate");
$handle = fopen($documenttextfile, "w");
if (!fwrite($handle, $documenttext))
return $urlpath;
exec("cd $tempdirname; /usr/bin/zip -ur -9 $tempfilepath .;");
exec("mv $tempfilepath $outdir$newfilename");
exec("rm -r $tempdirname");
if(file_exists("$outdir$newfilename")) {
$newfilepath=$outdir.$newfilename;
return $newfilepath;
} else
return $urlpath;
} elseif(strtolower(substr($urlpath, -4, 4)) == ".pdf") {
return $urlpath;
} else
return $urlpath;
}
function get_replacementtemplatefilelink($documentid, $taskid, $pretty=0) {
//echo "in function get_replacementtemplatefilelink: documentid: $documentid property: $property clientcompanyproperty: $clientcompanyproperty
";
//print_r($taskid);
//echo "
";
if($documentid && is_numeric($documentid))
{
//$qry = db_query("select *, case when coalesce(documenttitle,'') = '' then notesubject else documenttitle end as title from tbldocument left join tblnote on(notedocument1 = documentid) where documentid = $value");
$qry = db_query("select *, documenttitle as title from tbldocument where documentid = $documentid");
if(!$qry[0][documenttitle])
{
$qry1 = db_first("select notesubject from tblnote where notedocument1 = $documentid");
$qry[0][title] = $qry1[notesubject];
}
if(!$qry)
return " document $documentid deleted";
$urlpath = "/document/".getrelativedocumentdir($qry[0][documentid])."/{$qry[0][documentname]}";
$displayfilename=str_replace(".vhtml", ".pdf", $qry[0][documentname]);
$ext = explode('.',$displayfilename);
$ext = $ext[count($ext)-1];
$addedtext = icon(strtolower($ext));
$title = $qry[0][title];
$fullurlpath=$_SERVER[DOCUMENT_ROOT].$urlpath;
if(!file_exists($fullurlpath)) {
return "Invalid File Uploaded ($documentid)";
}
if(!$title)
$title = $qry[0][documentname];
$title = list_first($title,"-");
if($pretty)
{
$out = "Download: $addedtext$title";
}
else
{
$out = "Download: $addedtext{$displayfilename}";
}
return $out;
}
elseif($documentid)
return "Invalid File Uploaded ($documentid)";
else
return "No File Uploaded";
}
//FUNCTION :: read a docx file and return the string
function readDocx($filePath) {
// Create new ZIP archive
$zip = new ZipArchive;
$dataFile = 'word/document.xml';
// Open received archive file
if (true === $zip->open($filePath)) {
// If done, search for the data file in the archive
if (($index = $zip->locateName($dataFile)) !== false) {
// If found, read it to the string
$data = $zip->getFromIndex($index);
// Close archive file
$zip->close();
// Load XML from a string
// Skip errors and warnings
$xml = DOMDocument::loadXML($data, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING);
// Return data without XML formatting tags
$contents = explode('\n',strip_tags($xml->saveXML()));
$text = '';
foreach($contents as $i=>$content) {
$text .= $contents[$i];
}
return $text;
}
$zip->close();
}
// In case of failure return empty string
return "";
}
/**
* This function handles the extraction of the XML file data used to construct the HTML This function was added for changing a docx to HTML to pdf. The process isn't finished yet.
* @return Bool True on success
* @since 1.0
* @modified 1.2.3
*/
function extractxml($xml){
//$xmlFile = $this->tempDir."/word/document.xml";
//$xml = file_get_contents($xmlFile);
if($xml == false){
return false;
}
$xml = mb_convert_encoding($xml, 'UTF-8', mb_detect_encoding($xml));
//echo htmlentities($xml);
//exit;
$parser = xml_parser_create('UTF-8');
$data = array();
xml_parse_into_struct($parser, $xml, $data);
//echo "";
//print_r($data);
//echo "";
$html4output = "";
$i = 0;//var of post part id
$h1 = 0;//var of heading 1s done
$listflag=0;
$listtype="";
$listlevel=0;
$prid="";
foreach($data as $key => $value){
// echo "
Data: ".print_r($value);
if(is_array($value)){
switch ($value['tag']) {
case "W:P"://the paragrah begins
if($value['type'] == "open"){
/*
if($data[$key+1][tag]=='W:PPR' && $data[$key+2][tag]=='W:NUMPR') {
if($data[$key+3][attributes]['W:VAL']==0 && $data[$key+4][attributes]['W:VAL']==1 ) {
if($listflag==0) {
$listflag=1;
$listlevel++;
$listtype[$listlevel]="number";
$html4output .= "";
$prid=$data[$key][attributes]['W:RSIDR'];
} elseif($listtype[$listlevel]=="number" ) {
$listflag=0;
$listlevel--;
$html4output .= "
";
}elseif($listflag==1 && $listtype[$listlevel]!="number") {
$listlevel--;
$html4output .= "";
while ($listtype[$listlevel]=="number"){
$listlevel--;
}
}
}
elseif($data[$key+3][attributes]['W:VAL']>0 || ($data[$key+3][attributes]['W:VAL']==0 && $data[$key+4][attributes]['W:VAL']!=1)) {
if($listflag==0) {
$listflag=1;
$listlevel++;
$listtype[$listlevel]="other";
$html4output .= "";
$prid=$data[$key][attributes]['W:RSIDR'];
} elseif($listflag==1 && $listtype[$listlevel]!="other") {
$listlevel++;
$listtype[$listlevel]="other";
$html4output .= "";
$prid=$data[$key][attributes]['W:RSIDR'];
}elseif($listflag==1 && $listtype[$listlevel]=="other" && ($data[$key+3][attributes]['W:VAL']==0 && $data[$key+4][attributes]['W:VAL']==1)) {
$listlevel--;
$html4output .= "
";
while ($listtype[$listlevel]=="other"){
$listlevel--;
}
}
} elseif($listtype[$listlevel]=="other" ) {
$listflag=0;
$listlevel--;
$html4output .= "
";
}
}
*/
if($data[$key+1][tag]=='W:PPR' && $data[$key+2][tag]=='W:NUMPR') {
if($data[$key+3][attributes]['W:VAL']==0 && $data[$key+4][attributes]['W:VAL']==1 ) {
if($listflag==0) {
$listflag=1;
$listlevel++;
$listtype[$listlevel]="number";
$html4output .= "";
$prid=$data[$key][attributes]['W:RSIDR'];
} elseif($listtype[$listlevel]=="number" ) {
$listflag=0;
$listlevel--;
$html4output .= "
";
}elseif($listflag==1 && $listtype[$listlevel]!="number") {
$listlevel--;
$html4output .= "";
while ($listtype[$listlevel]=="number"){
$listlevel--;
}
}
}
elseif($data[$key+3][attributes]['W:VAL']>0 || ($data[$key+3][attributes]['W:VAL']==0 && $data[$key+4][attributes]['W:VAL']!=1)) {
if($listflag==0) {
$listflag=1;
$listlevel++;
$listtype[$listlevel]="other";
$html4output .= "";
$prid=$data[$key][attributes]['W:RSIDR'];
} elseif($listflag==1 && $listtype[$listlevel]!="other") {
$listlevel++;
$listtype[$listlevel]="other";
$html4output .= "";
$prid=$data[$key][attributes]['W:RSIDR'];
}elseif($listflag==1 && $listtype[$listlevel]=="other" && ($data[$key+3][attributes]['W:VAL']==0 && $data[$key+4][attributes]['W:VAL']==1)) {
$listlevel--;
$html4output .= "
";
while ($listtype[$listlevel]=="other"){
$listlevel--;
}
}
} elseif($listtype[$listlevel]=="other" ) {
$listflag=0;
$listlevel--;
$html4output .= "
";
}
}
if ($prid!=$data[$key][attributes]['W:RSIDR']){
if ($listtype[$listlevel]=="other" ) {
$listlevel--;
$html4output .= "";
if ($listlevel<1)
$listflag=0;
}else{
$listlevel--;
$html4output .= "";
if ($listlevel<1)
$listflag=0;
}
}
if($listflag>0)
$html4output .= "";
else
$html4output .= "";
} elseif($value['type'] == "close"){
if($listflag>0)
$html4output .= "
";
else
$html4output .= $outarr[tagclosep]."";
$outarr[tagclosep] = "";
}
break;
case "W:JC"://word style for bold
if($value['type'] == "complete"){
if($outarr[tagcloset] == ""){
break;
}
$html4output .= "";//return the text (add spaces after)
$outarr[tagcloset] = "";
}
break;
/*
case "W:NUMPR"://the center begins
if($value['type'] == "open"){
if($listflag==1)
$html4output .= "";
else
$html4output .= "";
} elseif($value['type'] == "close"){
$html4output .= "";
}
break;
*/
case "W:TBL"://the table is initiated
if($value['type'] == "open"){
$html4output .= "";
} elseif($value['type'] == "close"){
$html4output .= "
";
}
break;
case "W:TR"://the table row is initiated
if($value['type'] == "open"){
$html4output .= "";
} elseif($value['type'] == "close"){
$html4output .= "
";
}
break;
case "W:TC"://the table cell is initiated
if($value['type'] == "open"){
$html4output .= "";
} elseif($value['type'] == "close"){
$html4output .= " | ";
}
break;
case "W:HYPERLINK"://the hyperlink is initiated
if($value['type'] == "open"){
if(array_key_exists('R:ID', $value['attributes'])){
$rid = $value['attributes']['R:ID'];
$path = $outarr[rels][$rid][0];
$target = $outarr[rels][$rid][3];
} else {
$target = false;
}
//now determine which type of link it is
if(strtolower($target) == "external"){
//outarr is an external link to a website
$html4output .= "";
} elseif(isset($value['attributes']['W:ANCHOR'])){
$html4output .= "";
}
} elseif($value['type'] == "close"){
$html4output .= "";
}
break;
case "A:BLIP"://the image data
if($value['type'] == "open" || $value['type'] == "complete"){
$rid = $value['attributes']['R:EMBED'];
$imagepath = $outarr[rels][$rid][1];
if(array_key_exists(2,$outarr[rels][$rid])){
$imagebigpath = $outarr[rels][$rid][2];
} else {
$imagebigpath = false;
}
if($outarr->keepOriginalImage == true && $imagebigpath){
$html4output .= "
";
} else {
$html4output .= "
";
}
}
break;
case "W:T":
if($value['type'] == "complete"){
$html4output .= $value['value'].$outarr[tagcloset];//return the text (add spaces after)
$outarr[tagcloset] = "";
}
break;
case "W:COLOR":
if($value['type'] == "complete" && $outarr[allowColor]){
$html4output .= "";//add colored text
$outarr[tagcloset] = "";
}
break;
case "V:TEXTPATH":
if($value['type'] == "complete"){
if(array_key_exists('STRING',$value['attributes'])){
$html4output .= $value['attributes']['STRING'];//add word art text (this is also important)
}
}
break;
case "W:PSTYLE"://word styles used for headings etc.
if($value['type'] == "complete"){
if($value['attributes']['W:VAL'] == "Heading1"){
// -- || Determine if should split or not here || -- //
if($outarr[split]){
//the document may be split
if($h1 > 0){
//it should split if there already have been an heading 1
$outarr[output][$i] = $html4output;
$i++;
$html4output = "";//it should start on a paragraph
}
}//then just continue an add the H1 tag
$html4output .= "
";
$h1++;
$outarr[tagclosep] = "
";
}elseif($value['attributes']['W:VAL'] == "Heading2"){
$html4output .= "";
$outarr[tagclosep] = "
";
}elseif($value['attributes']['W:VAL'] == "Heading3"){
$html4output .= "";
$outarr[tagclosep] = "
";
}
}
break;
case "W:B"://word style for bold
if($value['type'] == "complete"){
if($outarr[tagcloset] == ""){
break;
}
$html4output .= "";//return the text (add spaces after)
$outarr[tagcloset] = "";
}
break;
case "W:I"://word style for italics
if($value['type'] == "complete"){
if($outarr[tagcloset] == ""){
break;
}
$html4output .= "";//return the text (add spaces after)
$outarr[tagcloset] = "";
}
break;
case "W:U"://word style for underline
if($value['type'] == "complete"){
if($outarr[tagcloset] == ""){
break;
}
$html4output .= "";//return the text (add spaces after)
$outarr[tagcloset] = "";
}
break;
case "W:STRIKE"://word style for strike-throughs
if($value['type'] == "complete"){
if($outarr[tagcloset] == ""){
break;
}
$html4output .= "";//return the text (add spaces after)
$outarr[tagcloset] = "";
}
break;
case "W:VERTALIGN": //word style for super- and subscripts
if($value['type'] == "complete"){
if($value['attributes']['W:VAL'] == "subscript"){
$html4output .= "";
$outarr[tagcloset] = "";
}elseif($value['attributes']['W:VAL'] == "superscript"){
$html4output .= "";
$outarr[tagcloset] = "";
}
}
break;
case "W:BOOKMARKSTART": //word style for bookmarks/internal links
if($value['type'] == "complete"){
$html4output .= "";
}
break;
default:
break;
}
//echo " $html4output
";
}
}
//echo "| ";
//echo " ";
//echo $html4output."
";
//echo " |
";
//echo "";
//echo "". htmlentities($html4output)."
";
//echo htmlentities($html4output);
//$outarr[output][] = $html4output;//this should output the last part to the output var
//$outarr[status] = "Contents Extracted...";
if(!$html4output){
return false;
}
return $html4output;
}
/**
* @name get_inputboxname
* @param string $data
* @param array $types
* @explain param $types[input][type]='checkbox' will only look for checkbox type.
* @example
* $myformfield = get_inputboxname($myform) this will return array of all input fields
* $types[textarea][type]='text';
* $myformfield = get_inputboxname($myform,$types); This one will return only textarea types.
* @return boolean
*/
function get_inputboxnames($data,$types='',$labelsonly=0){
//if (!$data || trim($data)=='')
// return false;
// For future use if we ever implement golabl debug flag
if (is_developer() && 1==0){
d('data: ',$data);
d('types: ',$types);
}
/******
* Variables
* $def_types are default types we can extract
*/
$def_types[input][type] = 'text,checkbox,radio';
$def_types[select][type] = 'select';
$def_types[textarea][type] = 'text';
if (trim($types)!='' || (is_array($types) && !empty($types))){
if (is_array($types)){
foreach ($types as $type=>$value){
if (is_array($def_types[strtolower($type)])){
foreach (explode(",",$def_types[$type][type]) as $dtype)
if (strstr(preg_replace('/[\'|\"]/i',"",strtolower($value)),$dtype))
$tmptype[$dtype] =$dtype;
}
$ourtype[$type][type] = implode(",",$tmptype);
unset($tmptype);
}
}else{
// Not an array it's csv list
foreach ($def_types as $type=>$val){
foreach(explode(",",preg_replace('/[\'|\"]/i',"",strtolower($types))) as $input){
if (strstr($val,$input))
$tmptype[$input] = $input;
}
$ourtype[$type][type] = implode(",",$tmptype);
unset($tmptype);
}
}
}
if (is_array($ourtype)){
unset($def_types); //make sure its empty in order to recreate it.
$def_types = $ourtype;
unset($ourtype);
}
// from now on $def_types has list of fileds to extract
//if (is_developer && $_SESSION[developer][debug_functions]==1){
// d('data: ',$data);
// d('types: ',$def_types);
//}
if (!class_exists('simple_html_dom')) // check is class loaded already
include_once ('simple_html_dom.php');
$html = new simple_html_dom();
$html ->load($data);
$reuslt[] = array();
// Phase 1. find all fileds and pull html out
foreach ($def_types as $tag=>$type){
if (strstr($type[type],",")){
foreach (explode(",",$type[type]) as $t){
if ($t=='radio'){
// Radio box is tricky it requre us to read before and after the box
foreach($html->find($tag.'[type='.$t.']') as $r)
{
$radio_name = "";
if ($r->label)
$radio_name = $r->label;
elseif($labelsonly)
continue; //if this is for ones with labels only, we'll skipp it if it doesnt have a label
if (!$radio_name && ($rtag != $r->name || !$rtag))
{
$datapos = strpos($data,$r->outertext); // begins here
$radio_name = trim (htmlentities(strrev(substr(strrev(substr($data,0,$datapos)),0,strpos(strrev(substr($data,0,$datapos)),">")))));
if (!trim($radio_name)==' ')
$radio_name = preg_replace("/_/",' ',$r->name);
$i=0;
}
$datapos = strpos($data,$r->outertext)+strlen($r->outertext);
$optvalue = htmlentities(substr($data,$datapos,strpos(substr($data,$datapos),"<")));
$result[$tag][$t][$r->name][name] = $radio_name;
$result[$tag][$t][$r->name]['optvalue_'.$i] = $optvalue;
$rtag = $r->name;
$i++;
}
}else
{
foreach($html->find($tag.'[type='.$t.']') as $r)
{
if (!$r->label)
{
if($labelsonly)
continue; //if this is for ones with labels only, we'll skipp it if it doesnt have a label
$datapos = strpos($data,$r->outertext);
$tname = trim (htmlentities(strrev(substr(strrev(substr($data,0,$datapos)),0,strpos(strrev(substr($data,0,$datapos)),">")))));
}
else
$tname = $r->label;
$result[$tag][$t][$r->name] = (trim($tname)=='' ? preg_replace("/_/",' ',$r->name) : $tname);
}
}
}
}else{
//d(textarea,$tag);
if($tag == 'textarea'){
foreach($html->find($tag) as $r)
{
$datapos = strpos($data,$r->outertext);
if (!$r->label){
$tname = trim (htmlentities(strrev(substr(strrev(substr($data,0,$datapos)),0,strpos(strrev(substr($data,0,$datapos)),">")))));
}else
$tname = $r->label;
$result[$tag][$r->name]=(trim($tname)=='' ? preg_replace("/_/",' ',$r->name) : $tname);
}
/* }else if ($tag == 'select'){
foreach($html->find($tag.'[type='.$type.']') as $r){
$result[$tag][$type][$r->name] = $r->outertext;
}*/
}
}
}
unset($html,$def_types); // Release memory
// For future use...
if (is_developer && $_SESSION[developer][debug_functions]==1){
d('return: ',$result);
}
return $result;
}
/**
* @name get_tasktemplatehtmlfieldmap
* @param integer $tasktemplateid
* @param integer $clientcompanyid
* @return boolean|array
*/
function get_tasktemplatehtmlfieldmap($tasktemplateid,$clientcompanyid=0){
if (!$clientcompanyid && clientcompanyid())
$clientcompanyid = clientcompanyid();
if (!$clientcompanyid || db_number($clientcompanyid) ==0)
return false;
if (!$tasktemplateid || db_number($tasktemplateid)==0)
return false;
// At this point we know that input data is correct
$sql = "select *,tblpropertyextension.propertyextensionlabel
from tbltasktemplatefieldmap
left join tblpropertyextension using (propertyextensionid)
where tasktemplatefieldid = (SELECT tasktemplatefieldid
FROM tbltasktemplatefield
WHERE tasktemplateid = ".db_number($tasktemplateid)."
AND tasktemplatefieldtype = 'mini_html_form'
ORDER BY tasktemplatefieldrank
LIMIT 1
)
and clientcompanyid = ".db_number($clientcompanyid);
// d($sql);
$fieldlist = db_query($sql);
return $fieldlist;
}
/**
* @name get_clienttasktitle
* @param integer $clienttaskid
* @return string
* @example echo get_clienttasktitle($clienttaskid);
*/
function get_clienttasktitle($clienttaskid){
if (db_number($clienttaskid)==0)
return false;
return ucwords(strtolower(db_firstval("select clienttasktitle from tblclienttask where clienttaskid =".db_number($clienttaskid))));
}
/***
* @name get_clienttaskassignedagent
* @param integer $clienttaskid
* @return string
* @example echo get_clienttaskassignedagent($clienttaskid);
*/
function get_clienttaskassignedagent($clienttaskid){
if (db_number($clienttaskid)==0)
return false;
return get_login_info(db_firstval("select clienttaskcompletedby from tblclienttask where clienttaskid =".db_number($clienttaskid)));
}
/**
* @name get_clienttaskpdf
* @param integer $clienttaskid
* @return integer
*/
function get_clienttaskpdf($clienttaskid){
if (db_number($clienttaskid)==0)
return false;
return db_firstval("select documentid from tbldocument where clienttaskid=".db_number($clienttaskid)." and documenttype ='taskpdf' ");
}
/**
* @name get_dontupdatecatrule
* @param unknown $clientcompanyid
* @param unknown $tasktemplatefieldid
* @param unknown $clientcompanypropertyid
* @return boolean|array $out
*/
function get_dontupdatecatrule($clientcompanyid,$tasktemplatefieldid,$clientcompanypropertyid){
if (db_number($clientcompanyid)==0 || db_number($tasktemplatefieldid) ==0 || db_number($clientcompanypropertyid)==0)
return false;
// now since we got both clientcompanyid and tasktemplategfield id we run this little query
$sql = "select propertyextensionid,propertyextensionkey,propertycategoryid
from tblclientcompanypropertyextension
left join (select propertyextensionid,propertyextensionkey, propertycategoryid from tblpropertyextension ) as tblpropertyextension using (propertyextensionid)
where 0=0
and clientcompanyid =".db_number($clientcompanyid)."
and propertycategoryid in (select propertycategoryid
from (select propertyextensionid, propertycategoryid from tblpropertyextension ) as tblpropertyextension
join (select propertyextensionid
, tasktemplatefieldid
, tasktemplatefieldmapdontupdateincategory
from tbltasktemplatefieldmap
where clientcompanyid = ".db_number($clientcompanyid)."
and tabcategorypropertyextensionid=0) as tbltasktemplatefieldmap using(propertyextensionid)
where 0=0
and tasktemplatefieldid = ".db_number($tasktemplatefieldid)."
and tasktemplatefieldmapdontupdateincategory =1
)";
// Tab categories below , propertycategoryid is hard coded to be 0
$sql .="
union
select propertyextensionid,propertyextensionkey,0 as propertycategoryid
from tbltabcategorypropertyextension
left join (select propertyextensionid,propertyextensionkey, propertycategoryid from tblpropertyextension ) as tblpropertyextension using (propertyextensionid)
where propertytabcategoryid in (select propertytabcategoryid
from tbltabcategorypropertyextension
join (select tabcategorypropertyextensionid , tasktemplatefieldid , tasktemplatefieldmapdontupdateincategory from tbltasktemplatefieldmap where clientcompanyid = ".db_number($clientcompanyid).") as tbltasktemplatefieldmap using(tabcategorypropertyextensionid)
where 0=0
and tasktemplatefieldid = ".db_number($tasktemplatefieldid)."
and tasktemplatefieldmapdontupdateincategory =1
)
order by propertycategoryid desc";
// d(catsql,$sql);
$qry = db_query($sql);
// Now format output
$getqry = array(); // initialize
$out = array(); // initialize
if (empty($qry))
return false; // No data exit.
foreach ($qry as $key=>$value){
$out[$value[propertycategoryid]][propertyextensionid] = $value[propertyextensionid];
$out[$value[propertycategoryid]][propertyextensionkey] = $value[propertyextensionkey];
$getqry[$value[propertyextensionkey]]=$value[propertyextensionkey];
}
unset($qry);
$sql = "select propertyextensionkey
from (select * from tblpropertyextensionentry where clientcompanypropertyid = ".db_number($clientcompanypropertyid).") as tblpropertyextensionentry
where propertyextensionkey in ('".implode("','",$getqry)."')
and propertyextensionentryvalue is not null
and trim(propertyextensionentryvalue)<>''";
$qry = db_query($sql,1,0,'propertyextensionkey');
//d(__line__,$qry);
d(out,$out);
unset($getqry);
$out1=$out;
if (is_array($out1))
foreach ($out1 as $key=>$value){
if (!array_key_exists ($value[propertyextensionkey],$qry))
unset($out1[$key]);
}
if (count($out) == count($out1))
return false; // return nothing since there is nothing to filter by.
else{
unset($out,$sql,$qry); // clean up.
return $out1;
}
}
/**
* @name get_extensionshavevalues
* @param unknown $tasktemplatefieldid
* @param unknown $clietcompanyid
* @param unknown $clientcompanypropertyid
* @return boolean | array
*/
function get_extensionshavevalues($tasktemplatefieldid,$clientcompanyid,$clientcompanypropertyid){
if (db_number($tasktemplatefieldid)==0 | db_number($clientcompanyid) ==0 | db_number($clientcompanypropertyid) ==0)
return false;
$sql ="select propertyextensionkey from (select propertyextensionkey, propertyextensionentryvalue,clientcompanypropertyid from tblpropertyextensionentry) as tblpropertyextensionentry
where 0=0
and propertyextensionkey in (select propertyextensionkey
from (select propertyextensionid,propertyextensionkey from tblpropertyextension ) as tblpropertyextension
join (select propertyextensionid
, tasktemplatefieldid
, tasktemplatefieldmapdontupdatevalue
from tbltasktemplatefieldmap
where clientcompanyid = ".db_number($clientcompanyid).") as tbltasktemplatefieldmap using(propertyextensionid)
where 0=0
and tasktemplatefieldid = ".db_number($tasktemplatefieldid)."
and tasktemplatefieldmapdontupdatevalue =1
)
and propertyextensionentryvalue is not null
and clientcompanypropertyid = ".db_number($clientcompanypropertyid)."
order by propertyextensionkey desc";
//d(sqlvals,$sql);
return db_query($sql,1,0,'propertyextensionkey');
}
function get_clienttaskassignname_fromarray($arr)
{
if($arr[stafffname].$arr[stafflname])
$val = $arr[stafffname]." ".$arr[stafflname];
elseif($arr[accountstafffname].$arr[accountstafflname])
$val = $arr[accountstafffname]." ".$arr[accountstafflname];
elseif($arr[externaluserfname].$arr[externaluserlname])
$val = $arr[externaluserfname]." ".$arr[externaluserlname];
elseif($arr[assignmentaliasclientstafffname].$arr[assignmentaliasclientstafflname])
$val = $arr[assignmentaliasclientstafffname]." ".$arr[assignmentaliasclientstafflname];
return $val;
}
/**
* @name update_minihtml_field_required
* @param [integer] $tasktemplateid
* @param [integer] $clientcompanyid
* @param [string] $htmlfiledname
* @param number $set
* @return boolean
*/
function update_minihtml_field_required($tasktemplatefieldid,$clientcompanyid,$htmlfiledname,$set=0){
if (!db_number($clientcompanyid) || !db_number($tasktemplatefieldid) || trim(db_col($htmlfiledname))=='')
return false;
$id = db_firstval("select tasktemplaterequiredfieldid from tbltasktemplaterequiredfield where tasktemplatefieldid =".db_number($tasktemplatefieldid)." and clientcompanyid=".db_number($clientcompanyid)." and tasktemplaterequiredfieldhtmlfieldname =".db_tick(strtolower($htmlfiledname)));
if ($id>0){
if ($set!=0)
db_exec("update tbltasktemplaterequiredfield set tasktemplaterequiredfieldrequired=".db_number($set)." where tasktemplaterequiredfieldid=".db_number($id));
else
db_exec("delete from tbltasktemplaterequiredfield where tasktemplaterequiredfieldid=".db_number($id)); // Not storing 0
}else
if ($set!=0) // Again not storing 0 values
db_exec("insert into tbltasktemplaterequiredfield (tasktemplatefieldid,clientcompanyid,tasktemplaterequiredfieldhtmlfieldname,tasktemplaterequiredfieldrequired)
VALUES (".db_number($tasktemplatefieldid).",".db_number($clientcompanyid).",".db_tick($htmlfiledname).",".db_number($set).")");
return true;
}
/**
* @name check_minihtml_field_required
* @param [integer] $tasktemplateid
* @param [integer] $clientcompanyid
* @param [string] $htmlfiledname
* @return boolean
*/
function check_minihtml_field_required($tasktemplatefieldid,$clientcompanyid,$htmlfiledname){
if (!db_number($clientcompanyid) || !db_number($tasktemplatefieldid) || trim(db_col($htmlfiledname))=='')
return false;
if (db_firstval("select tasktemplaterequiredfieldrequired from tbltasktemplaterequiredfield where tasktemplatefieldid =".db_number($tasktemplatefieldid)." and clientcompanyid=".db_number($clientcompanyid)." and tasktemplaterequiredfieldhtmlfieldname =".db_tick(strtolower($htmlfiledname)))<>0)
return true;
else
return false;
}
/**
* @name get_minihtml_required_fileds
* @param [integer] $tasktemplatefieldid
* @param [integer] $clientcompanyid
* @return [array] list of all field names
*/
function get_minihtml_required_fileds($tasktemplatefieldid,$clientcompanyid){
//d('sql:',"select tasktemplaterequiredfieldhtmlfieldname from tbltasktemplaterequiredfield where clientcompanyid=".db_number($clientcompanyid)." and tasktemplatefieldid=".db_number($tasktemplatefieldid));
return db_query("select tasktemplaterequiredfieldhtmlfieldname from tbltasktemplaterequiredfield where clientcompanyid=".db_number($clientcompanyid)." and tasktemplatefieldid=".db_number($tasktemplatefieldid));
}