value (database column name) expensename => cexpenseapprovalname, expenseamount => cexpenseapprovalnte ); //to setup new event and actions /* insert new events into tblworkflowevent insert new filter types into tblworkflowfiltertype (new config1 entries for filter types must be setup below (search workflowtriggerfiltertypeconfig1) insert new action types into tblworkflowtriggeractiontype (each fieldtype in each action type can be setup like the examples in the database, new types must be setup with new functions called workflowaction_configure_field_xxxxxxx) */ function workflowaction_validate($actionarr) { $type=$actionarr[workflowtriggeractiontypeshortname]; $actiontype=get_workflowtriggeractiontype($type); foreach($actiontype[params] as $i=>$param) { $value=$actionarr[$param[datafield]]; $fieldtpe = $param[config][fieldtype]; if($param[config][params][notrequired]) continue ; if($param[config][params][required] && !$value ) $msg .="$param[label] must be selected
"; else { $func = "workflowaction_validate_$fieldtpe"; if(function_exists($func)) { $thismsg=$func($param[config][params],$value); if($thismsg) $msg.="$param[label]: $thismsg
"; }else d("Can not validate $type. no function $func() defined"); } } return $msg; } function workflowaction_configure($actionarr, $prefix, $autohide = 0,$eventshortname="") { global $configureactioncount; $configureactioncount++; if($configureactioncount>1) $displaycount=$configureactioncount; $type=$actionarr[workflowtriggeractiontypeshortname]; $actiontype=get_workflowtriggeractiontype($type); if($configureactioncount == 1){ ?> "; $out.=""; $out.="
Configure Action $displaycount: $actiontype[workflowtriggeractiontypename]
"; foreach($actiontype[params] as $i=>$param){ $value = $actionarr[$param[datafield]]; if($value) $foundvalue=1; if($param[label]||$param[config]) $out.="
$param[label]: " . workflowaction_configure_field("{$prefix}[$param[datafield]]",$param[config],$value,$eventshortname) . "
"; } if($foundvalue)//only allow deletion if ONE value was found in the array $out .="
".button(delete)." Remove Action
"; $out .= "
"; /* d(actiontype,$actiontype); d(param1,$param1); d(param2,$param2); d(actionarr,$actionarr); d(type,$type); */ //useful for debugging //$prop = get_clientcompanyproperty($clientcompanypropertyid); //$events = get_workflowtriggers($eventshortname,array()); return $out; } function workflowaction_configure_field($fieldname,$config,$value,$eventshortname) { //d($value,value); //d($fieldname,filedname); //d($eventshortname,evshortname); $fieldtype = $config[fieldtype]; $params=$config[params]; $functionname = ""; $out="$fieldname:$fieldtype(".print_r($params,true)."):$value"; if(function_exists("workflowaction_configure_field_$fieldtype")) $functionname= "workflowaction_configure_field_$fieldtype"; elseif(function_exists("$fieldtype")) $functionname= "$fieldtype"; else ddie("invalid workflowaction_field: no function named: workflowaction_configure_field_$fieldtype($fieldname,'".print_r($params,true)."',$value,$eventshortname)"); $out = $functionname($fieldname,$params,$value,$eventshortname); return $out; } function get_workflowtriggeractiontype($type) { $sql ="select * from tblworkflowtriggeractiontype where 0=0 "; if(is_numeric($type)) $sql .=" and workflowtriggeractiontypeid = ". db_number($type); else $sql .=" and workflowtriggeractiontypeshortname = ". db_tick($type); $actiontype = db_first($sql); for($i=1;$i<=4;$i++) { $label = $actiontype["workflowtriggeractiontypedatalabel$i"]; $configname = "workflowtriggeractiontypeconfig$i"; $config = $actiontype[$configname]; $datafield = "workflowtriggeractiondata$i"; $params = trim(list_allbutfirst($config,"|")); $fieldtype = trim(list_first($config,"|")); if($params == $config) $params=''; //d(config,$config); if($params) { //d(here,$params); $params = explode("|",$params); foreach($params as $k=>$param) { $pexp = explode("=",$param); if(count($pexp)>1) { $params[$pexp[0]]=$pexp[1]; unset($params[$k]); } else { $params[$pexp[0]]=$pexp[0]; unset($params[$k]); } } } if($label||$config) { $config=array(); $config[fieldtype] = $fieldtype; $config[params] = $params; $actiontype[params][$i]=array( label=>$label ,config=>$config ,datafield=>$datafield ); } // $out.="$label: ".workflowaction_configure_field("{$prefix}[$fieldname]",$config,$value).""; } d('wf_action_type: '.$type,$actiontype); return $actiontype; } function workflowaction_display($param1, $param2="") { if(is_array($param1)) { $actionarr=$param1; $type=$param[workflowtriggeractiontypeshortname]; } else { $type=$param1; $actionarr=$param2; } //d(display,$type); //$prop = get_clientcompanyproperty($clientcompanypropertyid); //$events = get_workflowtriggers($eventshortname,array()); } function get_company_workflowtriggers($workflowevent, $clientcompanyid) { if(!$clientcompanyid || !is_numeric($clientcompanyid)) ddie("Invalid clientcompanyid passed as third parameter."); //lets lookup all of the triggers for this workflowevent. $sql = "select * from tblworkflowtrigger where workfloweventid = $workflowevent[workfloweventid] and clientcompanyid = $clientcompanyid"; $triggers = db_query($sql); foreach($triggers as $k=>$trigger) {//build the actions $sql = " select * from tblworkflowtriggeraction join tblworkflowtriggeractiontype using(workflowtriggeractiontypeid) where workflowtriggerid = $trigger[workflowtriggerid] order by workflowtriggeractiontyperank, workflowtriggeractiontypeshortname "; $triggers[$k][actions] = db_query($sql); $sql = " select * from tblworkflowtriggerfilter join tblworkflowtriggerfiltertype using(workflowtriggerfiltertypeid) where workflowtriggerid = $trigger[workflowtriggerid]"; $triggers[$k][filters] = db_query($sql); } return $triggers; } function get_workflowtriggers($eventshortname,$filterarray ,$admin=0) { if(clientcompanyid()) $clientcompanyid=clientcompanyid(); else $clientcompanyid = $filterarray[clientcompanyid]; if(!$clientcompanyid) ddie("invalid clientcompanyid", debug_backtrace()); $event=db_first("select * from tblworkflowevent where workfloweventshortname='".db_col($eventshortname)."'"); if(!$event[workfloweventid]) ddie("Invalid Event Called eventshortname:'$eventshortname', not found"); if(!is_array($filterarray)) ddie("Invalid get_workflowtriggers '$eventshortname', second parameter must be an array (empty array for return all triggers for event"); $qry = db_query("select * from tblworkflowtrigger left join tblworkflowtriggerfilter using (workflowtriggerid) left join tblworkflowtriggerfiltertype using (workflowtriggerfiltertypeid) where workfloweventid = $event[workfloweventid] and clientcompanyid = $clientcompanyid order by workflowtriggername asc"); $triggers=array(); foreach($qry as $row) { if(!$triggers[$row[workflowtriggerid]]) $triggers[$row[workflowtriggerid]] = $row; if($row[workflowtriggerfiltertypeid]) $triggers[$row[workflowtriggerid]][filters][] = $row; } unset($qry); foreach($triggers as $tkey=>$trigger) { $notfound=""; if($trigger[filters]) foreach($trigger[filters] as $filter) { $type = $filter[workflowtriggerfiltertypeshortname]; if(!$type) ddie("Configuations issue, somehow the type does not existin in this array",$filter); if(!$admin && !isset($filterarray[$type])) ddie("Configuration issue, the '$type' keys was not set in the filterarray, it must be set in order for us to know for sure whether we are filtering correctly",$filterarray); if($filter[workflowtriggerfiltervalue] === "" || strtolower(trim($filter['workflowtriggerfiltervalue'])) == "blank" )//the criteria is blank, the filter means allow all of these continue; if(strtolower(trim($filter['workflowtriggerfiltervalue'])) == "notblank" )//the criteria is not blank, the filter means allow all of these continue; if($filter[workflowtriggerfiltervalue] === "0")//the criteria is 0, the filter means allow all of these continue; if(strtolower($filter[workflowtriggerfiltervalue])=="all")//the criteria is "all", the filter means allow all of these continue; if(!$filterarray[$type])// the key is set, but it does not have a value, we are going to skip it. continue; $found_single=0; foreach(explode(',',$filter[clientcompanyclientid]) as $checkid)//loop through each of the filters to find the correct value if($checkid == $filterarray[$type]) //check each indifidually $found_single=1; if(!$found_single) $notfound="Did not find $type in $filter[clientcompanyclientid]"; } unset($triggers[$tkey]); if($notfound) continue; $outtriggers[] = $trigger; } return $outtriggers; } function workflowtriggerfiltertype_selector($name,$filtertype,$value) { if($_POST[filtertypes]) { $value=""; if($_POST[$name][$filtertype[workflowtriggerfiltertypeid]]) $value = implode(",",$_POST[$name][$filtertype[workflowtriggerfiltertypeid]]); } $name="{$name}[$filtertype[workflowtriggerfiltertypeid]]"; $boxid="box_$filtertype[workflowtriggerfiltertypeshortname]"; $classname="class_$filtertype[workflowtriggerfiltertypeshortname]"; if(!is_array($filtertype)) ddie("Invalid call to workflowtriggerfiltertype_selector(\$filtertype,\$value): \$filtertype is not an array"); //d(wftrf_selector,$filtertype); extract($filtertype); $qrydata=array(); if($workflowtriggerfiltertypeconfig1=='tbl') { $sql = " select $workflowtriggerfiltertypeconfig3 as id , $workflowtriggerfiltertypeconfig4 as value , * from $workflowtriggerfiltertypeconfig2 where clientcompanyid = ".clientcompanyid(); $qrydata=db_query($sql,1,0,id); foreach($qrydata as $id=>$row) { $skip=0; foreach($row as $field=>$datavalue) if(strstr($field,inactive) && $datavalue) $skip=1; if(!$skip) $qrydata2[$id]=$row[value]; } $qrydata=$qrydata2; unset($qrydata2); } if($workflowtriggerfiltertypeconfig1=='mlist') { $qrydata = get_mlistitems($workflowtriggerfiltertypeconfig2); } if($workflowtriggerfiltertypeconfig1=='list') { $qrydata = array(); foreach(explode(',',$workflowtriggerfiltertypeconfig2) as $item) { $qrydata[strtolower($item)] = strtoupper($item); } } if($workflowtriggerfiltertypeshortname=='tasklineitem') { $textbox=1; } $blankarr["[BLANK]"] = "BLANK"; $blankarr["[NOTBLANK]"] = "NOTBLANK"; //loop through the data array and put it after the blank array if($qrydata||$textbox) { foreach($qrydata as $ky=>$val) $blankarr[$ky]=$val; $qrydata=$blankarr; } else $qrydata=array(); $values=explode(',',$value); if($values) { foreach($values as $v) { if($qrydata[$v]) $vlist[$v]=checked; } } if($textbox) // lineitems for this type are radio { ?> All\n"; if($qrydata){ foreach($qrydata as $id=>$option) { $exclude[]=$option; echo "
$option
\n"; if (!$active){ $active = ($value==$option ? 1 : null); } if ($value == $option) unset($value); } } $exclude[]="on,"; $value = str_replace($exclude,"",$value); echo "
\n"; }else{ $allselected=""; $disp=''; if(!count($vlist)&&(!$value)) { $allselected=checked; $disp='none'; } echo " All\n"; if($qrydata){ foreach($qrydata as $id=>$option) { echo "
$option
\n"; } } } } ///////////////////////SELECTORS function workflowaction_configure_field_crole_selector($name,$params,$value,$eventshortname) { if(is_numeric($value)) ;//$value=unserialize($value); elseif(!is_array($value)) $value=unserialize($value); if(is_array($params)) foreach($params as $param) $params[$param]=$param; /* if($params[propertyroles] ||$params[propertyroleparents] ) { $addsql.=" and (rolepropertyworking = 1 "; if($params[propertyroleparents]) $addsql.=" or rolepropertyrestrictions = ".db_tick(VISIBLETOSUBS); $addsql.=")"; } */ //need to add something here that allows us to also display the 'parents' of propertyworking roles $croles = db_query("select croleid as id, crolename as value from tblcrole where clientcompanyid = ".clientcompanyid(). " and croleinactive is null $addsql order by crolename"); if($params[multiple]) $out = customfield_return("checkboxes",$name,$value,$croles); else $out = customfield_return("sqldropdown",$name,$value,$croles); return $out; } function workflowaction_configure_field_role_selector($name,$params,$value,$eventshortname) { if(is_numeric($value)) ;//$value=unserialize($value); elseif(!is_array($value)) $value=unserialize($value); if(is_array($params)) foreach($params as $param) $params[$param]=$param; if($params[propertyroles] ||$params[propertyroleparents] ) { $addsql.=" and (rolepropertyworking = 1 "; if($params[propertyroleparents]) $addsql.=" or rolepropertyrestrictions = ".db_tick(VISIBLETOSUBS); $addsql.=")"; } //need to add something here that allows us to also display the 'parents' of propertyworking roles $roles = db_query("select roleid as id, rolename as value from tblrole where clientcompanyid = ".clientcompanyid(). " $addsql order by rolename"); if($params[multiple]) $out = customfield_return("checkboxes",$name,$value,$roles); else $out = customfield_return("sqldropdown",$name,$value,$roles); return $out; } function workflowaction_configure_field_staff_selector($name,$params,$value,$eventshortname) { if(!is_array($value)) $value=unserialize($value); $sql = "select clientstaffid as id, clientstafffname||' '||clientstafflname as value from tblclientstaff join tbllogin using(clientstaffid) where logininactive is null and clientcompanyid = ".clientcompanyid()." order by clientstafffname, clientstafflname"; $qrystaff = db_query($sql); foreach($qrystaff as $staff) $staffs[$staff[id]]=$staff[value]; //sort($staffs); $out = customfield_return("checkboxes_key",$name,$value,$staffs); return $out; } function workflowaction_configure_field_textbox($name,$params,$value,$eventshortname) { //innova($name,$value); if($params[0]) $out.="$params[0]
"; $out.=""; if($params[1]) $out.="
$params[1]"; return $out; } function workflowaction_configure_field_task_builder($name,$params,$value,$eventshortname) { global $count; $count++; if(!is_array($value)) $value=unserialize($value); $fieldselect=array(); //get a list of property extension keys/labels for the recur rules below $origfieldselect = getpropertyextensionkeylabel(clientcompanyid()); if(is_array($origfieldselect)) { $k=0; foreach($origfieldselect as $fieldlabel=>$fieldinfo) { $fieldselect[$k]['id']=$fieldlabel; $fieldselect[$k]['value']=$fieldlabel; $k++; } } $sql="SELECT mlisttypeshortname as id , '——' || mlisttypename as value FROM tblmlisttype left join tblclientcompany using(clientcompanyid) where 0=0 and (clientcompanyid <= 0 or tblclientcompany.clientcompanyid is not null) and clientcompanyid=".clientcompanyid()." order by mlisttypename"; $mlisttype=db_query($sql); foreach($mlisttype as $mlisttypekey=>$mlisttypevalue) $fieldselect[]=$mlisttypevalue; $out="
"; if($value[taskname]) $taskname=$value[taskname]; $assignment = ' '; $cstaffsql = " select clientstaffid, clientstafffname, clientstafflname from tbllogin join tblclientstaff using (clientstaffid) where clientcompanyid = ".clientcompanyid()." and clientstaffid > 0"; $cstaffres = db_query($cstaffsql); if ($cstaffres) { $assignment = ""; } $out.=" "; $sql = "select tasktemplateid as id ,tasktemplatename as value from tbltasktemplate join tbltasktemplateclientcompany using (tasktemplateid) where tbltasktemplateclientcompany.clientcompanyid = ".clientcompanyid()." and tasktemplateinactivedate is null"; $out.=" "; $delaydays=array(); for($dday=2;$dday<31;$dday++) $delaysdaysopts[$dday]="in ".$dday." days"; $delaysdaysopts[''] = "Immediately"; $delaysdaysopts[1] = "in 1 day"; $delaysdaysopts[60] = "in 60 days"; $delaysdaysopts[90] = "in 90 days"; for($rday=1;$rday<91;$rday++) $recurringdaysopts[$rday]=$rday." Days"; $recurringdaysopts[''] = 'Never'; $classname = "recurringonly_".$count; $out.=" "; $recurringrules=count($value[recurrules]); if($recurringrules==0) $recurringrules=1; for($i=0;$i<$recurringrules;$i++) { $out.=" "; } $qry = db_query($sql); $qry[] = array(id=>0,value=>'No Template'); if($qry) { $rndcnt = "selector_".rand(10000,9999999).time(); $out.=""; } $out.="
Tasks are only assigned to Agents with Active Property Assignments
Task Name
Assign New Task to Assigned Agent  
Assign Only to Internal Staff {$assignment}
Automatically Approve Tasks Completed by Agents
Task Description "; $out.= innova_return($name.'[taskdescr]',$value[taskdescr]); // $out.="
Days Til Due ".customfield_return('select box',"{$name}[taskdays]",$value[taskdays],'1,2,3,4,5,6,7,10,14,30,60,90')."     Create this task:
".customfield_return('select box',"{$name}[delaydays]",$value[delaydays], $delaysdaysopts)."    
Recurring ".customfield_return('select box', "{$name}[recurringyesno]", $value[recurringyesno], 'yn', '', "onchange=\"recurringcheck($(this).val(),'".$classname."')\" onload=\"recurringcheck($(this).val(),'".$classname."')\"")."
Task Template ".customfield_return(sqldropdown,"{$name}[tasktemplateid]",$value[tasktemplateid],$qry,"", " style='width:100%;' class='$rndcnt' onchange=\" $(this).closest('tr').find('.previewbutton').show('fade') \" ")."
A 'new task assigned' email will be automatically be sent to this assigned agent
"; $out.="
"; //d(out, $out); return $out; } function workflowaction_configure_field_email($name,$params,$value,$eventshortname) { $debug_param[params] = $params; $debug_param[value] = $value; //d("function workflowaction_configure_field_email(\$name=$name,\$params,\$value,\$eventshortname=$eventshortname)", $debug_param); if(!is_array($value)) $value=unserialize($value); $from=$value[from]; $showsubject=1; if($params[nosubject]) $showsubject=0; $subject = $params[subject]; $out="
"; $out.=""; if($value[subject]) $subject=$value[subject]; if($showsubject) $out.=""; elseif($subject) $out.=""; if($params[0]) $out.="$params[0]
"; $out.=""; if($params[1]) $out.="
$params[1]"; if($params[attachmergepdf]) { $attachmergepdf=""; if($value[attachmergepdf]=="on") $attachmergepdf="checked"; $out.=""; } $out.="
From Address
Subject
Subject$subject
Body"; $out.= innova_return($name.'[body]',$value[body]); $out.= "
Attach Merged PDF to E-Mail
"; if($params[propertyfields]) { $variables[address]="The street address of the property"; $variables[city]="The city of the property"; $variables[state]="The state of the property"; $variables[zip]="The zip code of the property"; $variables[fulladdress]="The full address (street,city,state zip) of the property"; $variables[propertystatus]="The status of the property"; $variables[assignmenttype]="The Assignment Type of the property"; $sql = "select * from tblpropertyextension join tblclientcompanypropertyextension using(propertyextensionid) where propertyextensionclientuse = 1 and propertyextensiondisplayinbasicinfo = 1 and clientcompanyid = ".clientcompanyid(); $qryv=db_query($sql); foreach($qryv as $row) { $rep = str_replace("propertyextension","",$row[propertyextensionkey]); if($variables[$rep]) $rep = $row[propertyextensionkey]; $variables[$rep] = $row[propertyextensionlabel]; } } if($params[assignmentfields]) { $variables[agentname]="The Name of the Assigned Agent"; $variables[assignmentmethod]="The Method of the Property Assignment"; $variables[assignmentexpirationdate]="The date the assignment will expire if not accepted"; } if($params[expensefields]) { $variables[expensename]="The name of the expense"; $variables[expenseamount]="The amount of the expense"; } if ($_GET[type] == 'clienttaskapproved' || $_GET[type] == 'clientpretaskaccepted') { if ($params[clientpretask]) { $variables['lineitem']="The line item name"; $variables['workordernumber']="The work order number for the task"; $variables['expectedclientprice']="The expected price for the client"; $variables['expectedvendorprice']="The expected price for the vendor"; //$variables['actualclientprice'] = ""; //may be re-introduced later //$variables['actualvendorprice'] = ""; //may be re-introduced later } } if($variables) { $out.="Customize the contents of your email by placing these variables in the body of your message
Variables:"; foreach($variables as $variable =>$vdesc) { if (trim($vdesc) != '') $sep = '- '; $out.="
  ##$variable  $sep$vdesc"; } } $out.="
"; $out.="".button(config,'Email Replacement List')." Email Replacement List"; return $out; } function workflowaction_configure_field_mlist_item_selector($name,$params,$value,$eventshortname) { return customfield_return(mlist,$name,$value,$params[0]); } function workflowaction_configure_field_wysiwyg($name,$params,$value,$eventshortname) { //d(name,$name); //d(params,$params); //d(value,$value); //d(eventshortname,$eventshortname); //$out=workflowaction_configure_field_pdfwysiwyg($name,$params,$value,$eventshortname); $out= innova_return($name,$value); $out.="".button(config,'Merge PDF Replacement List')." Merge PDF Replacement List"; return $out; } function workflowaction_configure_field_pdfwysiwyg($name,$params,$value,$eventshortname) { //d(name,$name); //d(params,$params); //d(value,$value); if(!is_array($value)) { $oldvalue=$value; $value=unserialize($value); if(!isset($value[header])) $value[body]=$oldvalue; } if(isset($value[autopagenumber]) && $value[autopagenumber]=='on') $autopatenumberchecked='checked'; if(isset($value[autodate]) && $value[autodate]=='on') $autodatechecked='checked'; //d(eventshortname,$eventshortname); $descwidth=10; $inputwidth=100-$descwidth; $out=""; $out.=""; $out.=""; $out.=""; $out.=""; $out.=""; $out.=""; $out.=""; $out.=""; $out.=""; $out.=""; $out.=""; $out.=""; $out.=""; $out.=""; $out.=""; $out.=""; $out.=""; $out.=""; $out.="
Header: "; $out.= innova_return($name.'[header]',$value['header']); $out.="
Body: "; $out.= innova_return($name.'[body]',$value[body]); $out.="
Footer: "; $out.= innova_return($name.'[footer]',$value[footer]); $out.="
".button(config,'Merge PDF Replacement List')." Merge PDF Replacement List"; $out.="
".button(config,'Preview Replacement Document')." Preview Replacement Document (This may take several moments) "; $out.="
"; $out.="
"; $out.="
Header height: "; $out.="px"; $out.="
Footer height: "; $out.="px"; $out.="
Auto Footer Page Numbering: "; $out.=""; $out.="
Auto Footer Date: "; $out.=""; $out.="
"; $out.=""; return $out; } function workflowaction_validate_wysiwyg($params,$value) { if($value) return ""; else return "Invalid Document. Text is required."; } function workflowaction_validate_pdfwysiwyg($params,$value) { //d(value,$value); if(!is_array($value)) { $value=unserialize($value); } if(!$value[body]) return "Invalid Document. Body Text is required."; if($value[header] && ( !is_numeric($value[hheight]) || ($value[hheight] <1 )) ) return "Invalid Document. If you have Header text then the Header height must be a number > 0."; if($value[footer] && ( !is_numeric($value[fheight]) || ($value[fheight] <1) ) ) return "Invalid Document. If you have Footer text then the Footer height must be a number > 0."; $originalvalue=serialize($value); // Get a temp name $currenttime=date("mdYHis"); //$addrand=rand(1,99); $pdffilename="Preview_mergepdf_".$currenttime.".pdf"; $pdffilename=websafe_filename($pdffilename); //d(pdffilename,$pdffilename); //$dest_path = sys_get_temp_dir()."/"; $dest_path = "tmp_pdf/"; $pdffilename=$dest_path.$pdffilename; $mergearray=array(); //To test the html we don't have to do the replacements. pdf_mergetofile($originalvalue,$mergearray,$pdffilename,'preview'); if(has_message(error)) return "Invalid HTML"; return ""; } function workflowaction_validate_role_selector($params,$value) { if($value) return ""; else return "Invalid Role Selected"; } function workflowaction_validate_crole_selector($params,$value) { if($value) return ""; else return "Invalid Client Role Selected"; } function workflowaction_validate_email($params,$value) { if(!is_array($value)) $value=unserialize($value); if($params[nosubject]) $value[subject]=1; if(!$value[subject]&&!$value[body]) $out.="Invalid Subject and Body"; elseif(!$value[body]) $out.="Invalid Body"; elseif(!$value[from] || !is_email($value[from])) $out.="Invalid From Address"; elseif(!$value[subject]) $out.="Invalid Subject "; return $out; } function workflowaction_validate_task_builder($params, $value) { if(!is_array($value)) $value=unserialize($value); if(!$value[taskname]) $out.="Invalid Task Name"; elseif(!$value[taskdescr]) $out.="Invalid Description "; elseif($value[taskassigned] == 'internal' && !$value[taskassignedstaff]) $out.="Selection of internal staff is required"; return $out; } function get_workflowevent($shortname) { $workflowevents = get_workflowevents(); return $workflowevents[$shortname]; } function get_workflowevents() { global $global_workflowevents; if(!$global_workflowevents) $global_workflowevents = db_query("select * from tblworkflowevent",1,0,workfloweventshortname); return $global_workflowevents; } function workflowevent($shortname, $idtype, $id, $fieldname = '', $comparevalue = '') { global $global_workfloweventkey; $global_workfloweventkey=date('mdYHis')."_".rand(1,99); $workflowevent = get_workflowevent($shortname); if(!$workflowevent) ddie("Configuration Issue, workflowevents[$shortname] not a valid workflow event :workfloweventkey: $global_workfloweventkey"); //we are gonna lookup some data about this event based on the $idtype if($workflowevent[workfloweventhas_clientcompanypropertyassignment] && !$workflowevent[workfloweventhas_clientcompanyproperty] && $idtype != clientcompanypropertyassignment ) { ddie("Configuration Error, Calling workflowevents[$shortname] which is listed with a property assignment, however not \$idtype=$idtype but needs to be for the assignment :workfloweventkey: $global_workfloweventkey"); } if($idtype == 'clientpretask') { $sql = "select * , tblclientcompany.clientcompanyid as ccid , tblclientcompanyproperty.clientcompanypropertyid , clientpretaskworkordernumber workordernumber , lineitemname lineitem from tblclientpretask join tblclientcompanypropertyassignment using (clientcompanypropertyassignmentid, clientcompanypropertyid) join tblclientcompanyproperty using(clientcompanypropertyid) join tblclientcompany using(clientcompanyid) join tblassignmentmethod using(assignmentmethodid,clientcompanyid) join vw_assigntypes using(accountstaffid, externaluserid, staffid, assignmentaliasclientstaffid) left join (select lineitemname clientpretaskname, * from tbllineitemcategoryentry) tbllineitemcategoryentry using (clientpretaskname,clientcompanyid) where clientpretaskid = ".db_number($id); $data = db_query($sql); } elseif($idtype == clientcompanypropertyassignment) { $sql = "select * , tblclientcompany.clientcompanyid as ccid , tblclientcompanyproperty.clientcompanypropertyid from tblclientcompanypropertyassignment join tblclientcompanyproperty using(clientcompanypropertyid) join tblclientcompany using(clientcompanyid) join tblassignmentmethod using(assignmentmethodid,clientcompanyid) join vw_assigntypes using(accountstaffid, externaluserid, staffid, assignmentaliasclientstaffid) where clientcompanypropertyassignmentid = ".db_number($id); $data = db_query($sql); //create the first assignent which might be used by one or more of the triggers below } elseif($idtype == clientcompanyproperty) { $sql = " select * , tblclientcompany.clientcompanyid as ccid , tblclientcompanyproperty.clientcompanypropertyid from tblclientcompanyproperty join tblclientcompany using(clientcompanyid) left join -- internalized select makes sure only accepted, unrevoked, uncomplete and un expired (select * from tblclientcompanypropertyassignment where clientcompanypropertyassignmentaccepteddate is not null and clientcompanypropertyassignmentrevokeddate is null and clientcompanypropertyassignmentcompleteddate is null and clientcompanypropertyassignmentexpired is null ) tblclientcompanypropertyassignment using(clientcompanypropertyid) left join tblassignmentmethod using(assignmentmethodid) left join vw_assigntypes using(accountstaffid, externaluserid, staffid, assignmentaliasclientstaffid) left join (select *, clientstaffid as assignmentaliasclientstaffid from tbllogin) as tbllogin using(staffid, accountstaffid, externaluserid, assignmentaliasclientstaffid) where clientcompanypropertyid = ".db_number($id); $data = db_query($sql); } elseif($idtype == notebiddingboardinvite) { $sql = " select * , tblclientcompany.clientcompanyid as ccid , tblclientcompanyproperty.clientcompanypropertyid from tblnotebiddingboardinvite join tblclientcompanyproperty using(clientcompanypropertyid) join tblclientcompany using(clientcompanyid) left join tblclientcompanypropertyassignment using(clientcompanypropertyid) left join tblassignmentmethod using(assignmentmethodid) left join vw_assigntypes using(accountstaffid, externaluserid, staffid, assignmentaliasclientstaffid) left join (select *, clientstaffid as assignmentaliasclientstaffid from tbllogin) as tbllogin using(staffid, accountstaffid, externaluserid, assignmentaliasclientstaffid) where notebiddingboardinviteid = ".db_number($id). " " ; $data = db_query($sql); } elseif($idtype == cexpenseapproval) { $sql = " select * , clientcompanyid as ccid from tblcexpenseapproval join tblclientcompanyproperty using (clientcompanypropertyid) where cexpenseapprovalid = ".db_number($id). " " ; $data = db_query($sql); } elseif($idtype == clientoffer) { $sql = "select * , tblclientcompany.clientcompanyid as ccid , tblclientcompanyproperty.clientcompanypropertyid , (select propertyextensionentryvalue from tblpropertyextensionentry where propertyextensionkey = 'propertyextensionloannumber' and clientcompanypropertyid = tblclientcompanyproperty.clientcompanypropertyid ) as loannumber from tblclientcompanypropertyassignment join tblclientcompanyproperty using(clientcompanypropertyid) join tblclientcompany using(clientcompanyid) join tblassignmentmethod using(assignmentmethodid) join vw_assigntypes using(accountstaffid, externaluserid, staffid, assignmentaliasclientstaffid) join tblclientnegotiation using(clientcompanypropertyassignmentid) join tblclientoffer using (clientnegotiationid) where clientofferid = ".db_number($id); $data = db_query($sql); } else { ddie("Configuration Issue, workflowevents[$shortname] does not have an \$idtype:$idtype ($id) - $sql :workfloweventkey: $global_workfloweventkey"); } d('data sql', $sql); dlog('workflowevent_data', "$shortname: idtype: $idtype: workfloweventkey: $global_workfloweventkey \n sql:".$sql); dlog('workflowevent_data', "$shortname: idtype: $idtype: workfloweventkey: $global_workfloweventkey \n data:".print_r($data,true)); d(datab, $data); foreach($data as $k=>$row) $data[$k] = workflow_preprocessdata($data[$k]); d(data, $data); // if(is_developer()) // set_message("DEVELOPER ONLY NOTE: Data: ".basename(__file__)." (".__line__."): data: ".print_r($data, true). " :workfloweventkey: $global_workfloweventkey" ); if(!$data[0][ccid]) ddie("Trying to execute a workfloevent[$shortname], however no data found for $idtype:$id - check for archived / vaulted properties :workfloweventkey: $global_workfloweventkey, ".htmlpre($sql)); $triggers = get_company_workflowtriggers($workflowevent,$data[0][ccid]); foreach($triggers as $trigger) { $tmpdata = $data; // for each trigger, create a temp set of data to loop through and evaluate d('tmpdata',$tmpdata); foreach($trigger[filters] as $filter) { global $global_workflowtriggerkey; $global_workflowtriggerkey = 't'.date('mdYHis')."_".rand(1,99); //loop through all filters, if any fail, the we skip this trigger ///this evaluation should probably be put in a function, it will likely be called from other places... $evalvalue = $filter[workflowtriggerfiltervalue1]; if(!$evalvalue) // if there is not value set for this field, that means they did not set this filter, we should continue continue; if($filter['workflowtriggerfiltertypeeventrestriction']) { $workflowtriggerfiltertypeeventrestriction=explode(',',$filter['workflowtriggerfiltertypeeventrestriction']); if(!(in_array($shortname, $workflowtriggerfiltertypeeventrestriction))) continue; } // Case insensitive flag $caseinsensitive = 0; if ($filter['workflowtriggerfiltertypecaseinsesitive'] == 1) $caseinsensitive = 1; //get the fields that we are going to be evaluating agains if(in_array($filter[workflowtriggerfiltertypeconfig1], array('tbl','list','textbox')) ) $evalfield = $filter[workflowtriggerfiltertypeconfig3]; elseif($filter[workflowtriggerfiltertypeconfig1] == 'mlist') $evalfield = $filter[workflowtriggerfiltertypeconfig2]; else ddie("INVALID WORKFLOWTRIGGERFILTERTYPECONFIG1: $filter[workflowtriggerfiltertypeconfig1], NOT SUPPORTED :workfloweventkey: $global_workfloweventkey , workflowtriggerkey: $global_workflowtriggerkey"); if ($caseinsensitive) $evalarray = explode(',',strtolower($evalvalue)); else $evalarray = explode(',',$evalvalue); if($filter[workflowtriggerfiltertypepreprocessfunction]) array_walk($evalarray, $filter[workflowtriggerfiltertypepreprocessfunction]);//Call preprocessing function on each value in array. //now that we have the field and value to compare, //lets loop through the tempdata, //and if the filters do not match we remove the $tempdata row foreach($tmpdata as $k =>$row) { if(!isset( $row[$evalfield])) //this may mean we have an invalid field name $evalfield = str_replace("clientproperty",clientcompanyproperty,$evalfield) ; if(!isset( $row[$evalfield])) //this may mean we have an invalid field name $evalfield = str_replace("client",clientcompanyproperty,$evalfield) ; if(!isset( $row[$evalfield])) d("Cound not find $evalfield",$row); // this could be a developer errror.... if($filter[workflowtriggerfiltertypepreprocessfunction]) { $preprocessfunction = $filter[workflowtriggerfiltertypepreprocessfunction]; $preprocessfunction($row[$evalfield]);//Call preprocessing function on field. } if(!in_array($row[$evalfield],$evalarray,true)) { //no exact match if(in_array("[BLANK]",$evalarray) && !$row[$evalfield]) { ; } elseif(in_array("[NOTBLANK]",$evalarray) && $row[$evalfield]) { ; } elseif ($caseinsensitive && (in_array(strtolower($row[$evalfield]),$evalarray,true))){ ; } else { dlog('workflowevent', "$shortname: $filter[workflowfiltertypename] :NO MATCH: $evalfield (".$row[$evalfield]."): not in ".print_r($evalarray,true)." :workfloweventkey: $global_workfloweventkey, _workflowtriggerkey: $global_workflowtriggerkey"); unset($tmpdata[$k]) ; //clear out this index so it will not be used in the actions } } } } if(!$tmpdata) { dlog('workflowevent', "$shortname: did not run $trigger[workflowtriggername] | not tmpdata :workfloweventkey: $global_workfloweventkey"); continue; } $data = $tmpdata; //if a fieldname is being updated, that we should compare against a the selected field name, skip if they dont match if($fieldname && $trigger[workflowtriggerdata1]) { //if there is a $fieldname passed in, then this means the system should //compare this against the workflow trigger data1 and make sure they match. //if they do not match then we need to skip. if($fieldname!=$trigger[workflowtriggerdata1]) { dlog('workflowevent', "$shortname: did not run $trigger[workflowtriggername] | fieldnames not equal ($fieldname!=$trigger[workflowtriggerdata1]) : $global_workfloweventkey"); continue; } } //if a fieldname is being updated, and matches a field name field name, and we only want to allow certain values, only run the trigger if they match if ($fieldname && $trigger[workflowtriggerdata1] && $trigger[workflowtriggerdata2] ) { if(is_array($comparevalue)) $comparevalue= $comparevalue[$trigger[workflowtriggerdata1]]; // Check if value matches the parameter $trigger_stop = 1; $matches = explode(",", $trigger[workflowtriggerdata2]); foreach($matches as $k=>$value) { d("strstr($value, $comparevalue)"); if (strstr($value, $comparevalue)) $trigger_stop = 0; //we found a match, do not stop } if ($trigger_stop) { dlog('workflowevent', "$shortname: did not run $trigger[workflowtriggername] __MATCH_NOT_FOUND__ | :$fieldname $value, $comparevalue $trigger[workflowtriggerdata2]: $global_workfloweventkey"); continue; } } dlog('workflowevent', "$shortname: RUNNING $trigger[workflowtriggername] with ".count($trigger[actions])." actions [workflowevent('$shortname','$idtype', '$id')] count(data): ".count($data)." :workfloweventkey: $global_workfloweventkey"); dlog('workflowevent_data', "$shortname: RUNNING $trigger[workflowtriggername] with ".count($trigger[actions])." actions [workflowevent('$shortname','$idtype', '$id')] count(data) :workfloweventkey: $global_workfloweventkey \n data:".print_r($data,true)); workflowtrigger_execute($trigger,$data); } if(!$triggers) dlog('workflowevent', "$shortname: no triggers found to run [workflowevent('$shortname','$idtype', '$id')] :workfloweventkey: $global_workfloweventkey"); $ret = ob_get_clean(); return $ret; } function workflowtrigger_execute($trigger,$data) { global $global_workfloweventkey, $global_workflowtriggerkey; if(!$trigger[actions]) dlog('workflowevent',"No actions to process for $trigger[workflowtriggername], returning without processing any actions :workfloweventkey: $global_workfloweventkey, workflowtriggerkey: $global_workflowtriggerkey"); foreach($trigger[actions] as $action) { $actontype = $action[workflowtriggeractiontypeshortname]; workflowaction_execute($action,$data) ; } } function workflowaction_execute($action,$data) { global $global_workfloweventkey, $global_workflowtriggerkey; d(action,$action); d(data,$data); $type= $action[workflowtriggeractiontypeshortname]; $config1= $action[workflowtriggeractiontypeconfig1]; $config2= $action[workflowtriggeractiontypeconfig2]; $config3= $action[workflowtriggeractiontypeconfig3]; $config4= $action[workflowtriggeractiontypeconfig4]; $data1= $action[workflowtriggeractiondata1]; $data2= $action[workflowtriggeractiondata2]; $data3= $action[workflowtriggeractiondata3]; $data4= $action[workflowtriggeractiondata4]; $func = "workflowaction_execute_$type"; if (($type == 'mergepdf' || strstr($type, 'email')) && is_array($data[0])) $data[0] = array_merge($data[0], get_tasktemplatereplacementarray(0, 0, $data[0][clientcompanyid], $data[0][clientcompanypropertyid])); if(!function_exists($func)) ddie("DEVELOPER ERROR: You must setup a function called $func($config1,$config2,$config3,$config4) to _inc/functions_workflow.php to handle this action",$action); dlog('workflowevent',"$func($data,$data1,$data2, $data3, $data4,$action); :workfloweventkey: $global_workfloweventkey, workflowtriggerkey: $global_workflowtriggerkey"); //important decision point here, we need to at some poitn figure out how many times we run each of theses actions, right now we will run it for as many times as we get data results back. //this could result in some duplicate actions //for now if workflowtriggeractiontypeperassignment is set to 1, we run it once for every assignment //else / if it worflowtriggeractiontypeperproperty is set, we only run once. if($action[workflowtriggeractiontypeperassignment]) { foreach($data as $datarow) { if($datarow[clientcompanypropertyassignmentid]) //only execute if we have a property assignment in place, there is a possiblity that we are trying to execute an action even though there is not an assignemtn at all. $func($datarow,$data1,$data2, $data3, $data4,$action); } } else $func(array_shift($data),$data1,$data2, $data3, $data4,$action); } function workflowaction_execute_taskagent($data,$roleid, $taskdef ,$unused3,$unused4,$arr) { global $global_workfloweventkey, $global_workflowtriggerkey; if($roleid) $role = db_first("select * from tblrole where roleid = ".db_number($roleid)); $task = unserialize($taskdef); if ($task[taskassigned] && $task[taskassignedstaff]) { //run internal only assignment method using clientcompanyid // If we dont have CCID get it from clientcompanyproperty id. // If we dont have CCPID die. if (!db_number($data['clientcompanyid'])){ if(db_number($data['clientcompanypropertyid'])) $data['clientcompanyid'] = db_firstval("SELECT clientcompanyid FROM tblclientcompanyproperty WHERE clientcompanypropertyid = " . db_number($data['clientcompanypropertyid'])); else { developer_error("Internal Assignment workflow: Unable to extrapolate Client Company id."); ddie("SYSTEM ERROR. Please Notify RIO Support ERR:FWF" . __LINE__); } } $assignmentmethodid = internalonlyassignmentmethod($data['clientcompanyid']); //check client company property assignment for staffid $sql = " select * from tblclientcompanypropertyassignment where clientcompanypropertyid = ".$data['clientcompanypropertyid']." and assignmentaliasclientstaffid = ".$task['taskassignedstaff']." and assignmentmethodid = {$assignmentmethodid} "; $qry = db_first($sql); //if we do not have active assignment for him $ccpai = $qry[clientcompanypropertyassignmentid]; if ($ccpai) { $sql = ' update tblclientcompanypropertyassignment set clientcompanypropertyassignmentaccepteddate = now() , clientcompanypropertyassignmentdenieddate = null , clientcompanypropertyassignmentdeniedby = 0 , clientcompanypropertyassignmentrevokeddate = null , clientcompanypropertyassignmentrevokedby = 0 , clientcompanypropertyassignmentcompleteddate = null , clientcompanypropertyassignmentexpired = null , clientcompanypropertyassignmentexpiredby = 0 where clientcompanypropertyassignmentid = '.db_number($ccpai); db_exec($sql); } else //create assignment { $ccpai = db_firstval("SELECT nextval('tblclientcompanypropertyassig_clientcompanypropertyassignme_seq') as id"); $sql = " insert into tblclientcompanypropertyassignment ( clientcompanypropertyassignmentid , clientcompanypropertyid , assignmentaliasclientstaffid , assignmentmethodid , clientcompanypropertyassignmentcreatedby , clientcompanypropertyassignmentaccepteddate , clientcompanypropertyassignmentdenieddate , clientcompanypropertyassignmentdeniedby , clientcompanypropertyassignmentrevokeddate , clientcompanypropertyassignmentrevokedby , clientcompanypropertyassignmentcompleteddate , clientcompanypropertyassignmentexpired , clientcompanypropertyassignmentexpiredby , staffid ) values ( {$ccpai} , ".db_number($data['clientcompanypropertyid'])." , ".db_number($task['taskassignedstaff'])." , ".db_number($assignmentmethodid)." , 0 , now() , null , 0 , null , 0 , null , null , 0 , 0 )"; db_exec($sql); } $data[clientcompanypropertyassignmentid] = $ccpai; $data[clientcompanypropertyassignmentaccepteddate] = date("Y-m-d H:i:s"); unset($data[clientcompanypropertyassignmentrevokeddate],$data[clientcompanypropertyassignmentcompleteddate], $data[clientcompanypropertyassignmentexpired]); } //in several cases we would skip creating a task //if the agent has not accepted the assignment yet //if the assignment has been completed, revoked or expired if ($data['clientpretaskid']>0){ // We need to fix pretask data here // [clientpretaskname] => Initial Property Review // [clientpretaskworkordernumber] => WI15126069 // [clientpretaskworkorderstatus] => Accepted $taskextra['clienttaskworkordernumber'] = $data['clientpretaskworkordernumber']; $taskextra['clienttaskworkorderstatus'] = $data['clientpretaskworkorderstatus']; $taskextra['clientpretaskid'] = $data['clientpretaskid']; $task['taskname'] = $data['clientpretaskworkordernumber'] . " - " . $task['taskname']; // If there is duedate value in pretask we use it, othervise we use workflow data. if ($data['clientpretaskduedate']){ $duedays = get_numberofdaysfromdate($data['clientpretaskduedate']); if ($duedays > 0 ) $task['taskdays'] = 0; // Task was supposed to be done. else if ($duedays < 0) $task['taskdays'] = abs($duedays); } } if(!$data[clientcompanypropertyassignmentaccepteddate]) return; if($data[clientcompanypropertyassignmentrevokeddate]) return; if($data[clientcompanypropertyassignmentcompleteddate]) return; if($data[clientcompanypropertyassignmentexpired]) return; d(datadata, $data); if ($task[delaydays] < 1) $task[delaydays] = 0; $is_delayedtask = ($task[delaydays] > 0); $is_recurringtask = ($task[recurringyesno] == 'y' && $task[recurdays] > 0); if ($is_delayedtask || $is_recurringtask) { $taskdata[clienttaskschedulecreatedby] = loginid(); $taskdata[clienttaskschedulename] = $task[taskname]; $taskdata[clienttaskscheduledescr] = $task[taskdescr]; $taskdata[clienttaskscheduleautoapprove] = $task[taskautoapprove]; $taskdata[clienttaskscheduleduedays] = $task[taskdays]; $taskdata[clienttaskschedulefirstdate] = date("m/d/Y", strtotime("+".$task[delaydays]." day")); $taskdata[clienttaskschedulerecurdays] = $task[recurdays]; $taskdata[clienttaskschedulerecurlastdate] = ($is_delayedtask)?"NULL":"now()"; $taskdata[clienttaskschedulerecurrules] = serialize($task[recurrules]); $taskdata[clientcompanypropertyid] = $data[clientcompanypropertyid]; $taskdata[tasktemplateid] = $task[tasktemplateid]; $taskdata[workflowtriggeractionid] = $arr[workflowtriggeractionid]; $taskdata[roleid] = $roleid; $taskdata[clientcompanypropertyassignmentid] = $data[clientcompanypropertyassignmentid]; dlog('workflowevent',"workflow_createscheduledtask($taskdata[roleid],$taskdata[clientcompanypropertyid],$taskdata[clientcompanypropertyassignmentid],$taskdata[clienttaskschedulename],$taskdata[clienttaskscheduledescr],$taskdata[clienttaskscheduleduedays],$taskdata[tasktemplateid], '', '', $taskdata[clienttaskscheduleautoapprove]"); workflow_createscheduledtask($taskdata); //ddie(scheduled); } if (!$is_delayedtask) { d('########################task',$task); dlog('workflowevent',"clienttask_create($roleid,$data[clientcompanypropertyid],$data[clientcompanypropertyassignmentid],$task[taskname],\$task[taskdescr],$task[taskdays],$task[tasktemplateid], '', '', $task[taskautoapprove]); :workfloweventkey: $global_workfloweventkey, workflowtriggerkey: $global_workflowtriggerkey"); clienttask_create($roleid,$data[clientcompanypropertyid],$data[clientcompanypropertyassignmentid],$task[taskname],$task[taskdescr],$task[taskdays],$task[tasktemplateid], '', '', $task[taskautoapprove],$taskextra); // ddie(clienttask_create); } } function workflowaction_execute_notificationemailtoassignedcrole($data,$tocroleid, $emaildef ,$unused3,$data4,$arr) { // d(fromroleid,$fromroleid); // if($tocroleid) // $tocrole = db_first("select * from tblcrole where croleid = ".db_number($tocroleid)); $email = unserialize($emaildef); //d(__LINE__." email",$email); if($tocroleid) $to = db_firstval("select contactemail from tblclientcompanypropertycrole join tblcrole using(croleid) join tblcontact using(contactid) where clientcompanypropertyid = ".db_number($data[clientcompanypropertyid])." and croleid = ".db_number($tocroleid)); if($email[attachmergepdf]=="on") $attachmentmergepdfdocuments=workflowaction_getmergepdfdocuments($data); //d(fromrole,$fromrole); $email[body]=str_replace("\n","
",$email[body]); $data[agentname]=$data[assignname]; $data[assignmentexpirationdate] = longdttime_format($data[clientcompanypropertyassignmentexpiremarkeddate]); $data[assignmentmethod]=$data[assignmentmethodname]; $data[assignmentmethod]=$data[assignmentmethodname]; $data[fulladdress] = "$data[clientcompanypropertyaddress]\n$data[clientcompanypropertycity] $data[clientcompanypropertystate] $data[clientcompanypropertyzip]"; foreach($data as $field=>$val) { //set_message("debug: ".basename(__file__)." (".__line__."): key: ".$field." value: ".$val); $field = str_replace(clientcompany,'',$field); $email[subject] = str_replace('##'.$field,$val,$email[subject]); $email[body] = str_replace('##'.$field,$val,$email[body]); $field = str_replace(property,'',$field); $email[subject] = str_replace('##'.$field,$val,$email[subject]); $email[body] = str_replace('##'.$field,$val,$email[body]); } global $expensemap; foreach ($expensemap as $subkey => $dbkey) { $email[subject] = str_replace('##'.$subkey,$data[$dbkey],$email[subject]); $email[body] = str_replace('##'.$subkey,$data[$dbkey],$email[body]); } if(strstr($email[subject],"##") || strstr($email[body],"##") && $data[clientcompanypropertyid]) { //if we still have some variables that have not yet been populated, look up the value in the property extension entry table $sql = "select e.propertyextensionkey , propertyextensionentryvalue from tblpropertyextension e join tblpropertyextensionentry v on (e.propertyextensionkey = v.propertyextensionkey and clientcompanypropertyid = ".db_number($data[clientcompanypropertyid]).") "; $qryv=db_query($sql); foreach($qryv as $row) { $val = $row[propertyextensionentryvalue]; $field = str_replace(propertyextension,'',$row[propertyextensionkey]); $email[subject] = str_replace('##'.$field,$val,$email[subject]); $email[body] = str_replace('##'.$field,$val,$email[body]); $field = $row[propertyextensionkey]; // set_message($field, success); $email[subject] = str_replace('##'.$field,$val,$email[subject]); $email[body] = str_replace('##'.$field,$val,$email[body]); } } d(is_emails($to)); //d($body); if(!is_email($email[from])) $email[from] = "noreply@riogenesis.com"; //html_mail_enable_devsite(); d(__line__."to: ",$to); d(__line__."from: ",$email[from]); d(__line__."subject: ",$email[subject]); d(__line__."body: ",$email[body]); // exit; if(is_emails($to)) html_mail($to,$email[from],$email[subject],$email[body],$attachmentmergepdfdocuments); else d(__INVALID_EMAIL_ADDRESSES_NOT_SENT__________); if (is_developer()) { if(is_array($attachmentmergepdfdocuments)) { $displayattachmentmergepdfdocuments=implode(",",$attachmentmergepdfdocuments); set_message("debug client role email sent: ".basename(__file__)." (".__line__."): from : ".$email[from]. " subject: ".$email[subject]." attachmentids: ".$displayattachmentmergepdfdocuments); } else set_message("debug client role email sent: ".basename(__file__)." (".__line__."): from : ".$email[from]. " subject: ".$email[subject]." No Attachments"); } } function workflowaction_execute_notificationemailtoassigned($data,$fromroleid, $emaildef ,$unused3,$data4,$arr) { // d(fromroleid,$fromroleid); if($fromroleid) $fromrole = db_first("select * from tblrole where roleid = ".db_number($fromroleid)); $email = unserialize($emaildef); //d(__LINE__." email",$email); if($email[attachmergepdf]=="on") $attachmentmergepdfdocuments=workflowaction_getmergepdfdocuments($data); //d(fromrole,$fromrole); $email[body]=str_replace("\n","
",$email[body]); $fromclient = 1; $data[agentname]=$data[assignname]; $data[assignmentexpirationdate] = longdttime_format($data[clientcompanypropertyassignmentexpiremarkeddate]); $data[assignmentmethod]=$data[assignmentmethodname]; $data[assignmentmethod]=$data[assignmentmethodname]; $data[fulladdress] = "$data[clientcompanypropertyaddress]\n$data[clientcompanypropertycity] $data[clientcompanypropertystate] $data[clientcompanypropertyzip]"; d('replace data', $data); foreach($data as $field=>$val) { //set_message("debug: ".basename(__file__)." (".__line__."): key: ".$field." value: ".$val); $field = str_replace(clientcompany,'',$field); $email[subject] = str_replace('##'.$field,$val,$email[subject]); $email[body] = str_replace('##'.$field,$val,$email[body]); $field = str_replace(property,'',$field); $email[subject] = str_replace('##'.$field,$val,$email[subject]); $email[body] = str_replace('##'.$field,$val,$email[body]); } global $expensemap; foreach ($expensemap as $subkey => $dbkey) { $email[subject] = str_replace('##'.$subkey,$data[$dbkey],$email[subject]); $email[body] = str_replace('##'.$subkey,$data[$dbkey],$email[body]); } // ** tag ** // if (is_developer()) set_message("debug email assigned: ".basename(__file__)." (".__line__."): ".print_r($email, true)); if(strstr($email[subject],"##") || strstr($email[body],"##") && $data[clientcompanypropertyid]) { $sql = "select e.propertyextensionkey , propertyextensionentryvalue from tblpropertyextension e join tblpropertyextensionentry v on (e.propertyextensionkey = v.propertyextensionkey and clientcompanypropertyid = ".db_number($data[clientcompanypropertyid]).") "; $qryv=db_query($sql); foreach($qryv as $row) { $val = $row[propertyextensionentryvalue]; $field = str_replace(propertyextension,'',$row[propertyextensionkey]); $email[subject] = str_replace('##'.$field,$val,$email[subject]); $email[body] = str_replace('##'.$field,$val,$email[body]); $field = $row[propertyextensionkey]; //set_message($field, success); $email[subject] = str_replace('##'.$field,$val,$email[subject]); $email[body] = str_replace('##'.$field,$val,$email[body]); } //might be needed someday in case someone puts some unknown variables in , but not yet } clientmessage_create($fromclient,$fromrole[roleid],$data[clientcompanypropertyid],$data[clientcompanypropertyassignmentid],0,$email[from],$email[subject],$email[body],$attachmentmergepdfdocuments); // ** tag ** // if (is_developer()) { if(is_array($attachmentmergepdfdocuments)) { $displayattachmentmergepdfdocuments=implode(",",$attachmentmergepdfdocuments); set_message("debug email sent: ".basename(__file__)." (".__line__."): from : ".$email[from]. " subject: ".$email[subject]." attachmentids: ".$displayattachmentmergepdfdocuments); } else set_message("debug email sent: ".basename(__file__)." (".__line__."): from : ".$email[from]. " subject: ".$email[subject]." No Attachments"); } } function workflowaction_execute_clientpropertystatus($data, $clientcompanypropertystatus, $data2, $data3, $data4, $action){ clientcompanyproperty_set_column($data['clientcompanypropertyid'],'clientcompanypropertystatus',$clientcompanypropertystatus); } function workflowaction_execute_notificationemailtointernal($data, $data1, $data2, $data3, $data4, $action) { //d(__LINE__,$data); //d(__LINE__,$data1); //d(__LINE__,$data2); //d(__LINE__,$data3); //d(__LINE__,$data4); $data1 = unserialize($data1); $data2 = unserialize($data2); $data3 = unserialize($data3); $roles = $data2; $clientstaffemails = ''; if($data1) { foreach($data1 as $clientstaffid) { $clientstaff = clientstaff_get($clientstaffid); if($clientstaffemails != '') $clientstaffemails .= ','; $clientstaffemails .= $clientstaff['clientstaffemail']; } } if($roles && !is_array($roles)) $roles = explode($roles); if($roles) { //d($roles); foreach($roles as $roleid){ $clientstaffid = get_clientcompanypropertyrole_clientstaffid($data[clientcompanypropertyid],$roleid); $clientstaff = clientstaff_get($clientstaffid); //d($clientstaffid, $clientstaff); if(!$clientstaff['clientstaffemail']) continue;//dont add them to the list if there is not address // this fixed a bug where one of the roles was niot asssigned and so no email address was available and a comma was added to the end of the email address list and that failed the html_mail requirements and stopped sending mail //d($clientstaffid, $clientstaff); if($clientstaffemails != '') $clientstaffemails .= ','; $clientstaffemails .= $clientstaff['clientstaffemail']; } } $to = $clientstaffemails; $from = $data3['from']; //d(to,$to); $subject = $data3['subject']; $body = $data3['body']; $data['fulladdress'] = $data['clientcompanypropertyaddress'] . " " . $data['clientcompanypropertycity'] . ", " . $data['clientcompanypropertystate'] . " " . $data['clientcompanypropertyzip']; //d(__LINE__." data3",$data3); if($data3[attachmergepdf]=="on") $attachmentmergepdfdocuments=workflowaction_getmergepdfdocuments($data); foreach($data as $field=>$val){ $field = str_replace(clientcompany,'',$field); $subject = str_replace('##'.$field,$val,$subject); $body = str_replace('##'.$field,$val,$body); $field = str_replace(property,'',$field); $subject = str_replace('##'.$field,$val,$subject); $body = str_replace('##'.$field,$val,$body); } global $expensemap; foreach ($expensemap as $subkey => $dbkey) { $subject = str_replace('##'.$subkey,$data[$dbkey],$subject); $body = str_replace('##'.$subkey,$data[$dbkey],$body); } if(strstr($subject,"##") || strstr($body,"##") && $data[clientcompanypropertyid]) { //if we still have some variables that have not yet been populated, look up the value in the property extension entry table $sql = "select * from tblpropertyextensionentry where clientcompanypropertyid = $data[clientcompanypropertyid] "; $qryv=db_query($sql); foreach($qryv as $row) { $val = $row[propertyextensionentryvalue]; $field = str_replace(propertyextension,'',$row[propertyextensionkey]); $subject = str_replace('##'.$field,$val,$subject); $body = str_replace('##'.$field,$val,$body); $field = $row[propertyextensionkey]; $subject = str_replace('##'.$field,$val,$subject); $body = str_replace('##'.$field,$val,$body); } } //d(is_emails($to)); //d($body); if(!is_email($from)) $from = "noreply@riogenesis.com"; //html_mail_enable_devsite(); //d(__line__."to: ",$to); //d(__line__."from: ",$from); //d(__line__."subject: ",$subject); //d(__line__."body: ",$body); // exit; // ** tag ** // if (is_developer()) set_message("debug email internal: ".basename(__file__)." (".__line__."): ".$subject." ".$body); if(is_emails($to)) html_mail($to,$from,$subject,$body,$attachmentmergepdfdocuments); else d(__INVALID_EMAIL_ADDRESSES_NOT_SENT__________); } function workflowaction_getmergepdfdocuments($data) { global $global_workfloweventkey,$global_workflowtriggerkey; //d(__LINE__." workflowaction_getmergepdfdocuments: ",$data); if(!$data || (!$data[propertyid] && !$data[clientcompanypropertyid])) return false; $property = "property"; $propertyid = $data[propertyid]; if ($data[clientcompanypropertyid]) { $property = "clientcompanyproperty"; $propertyid = $data[clientcompanypropertyid]; } $sql="select * from tbldocument where ".$property."id=".db_number($propertyid)." and documenttype='mergepdf' and documentworkfloweventkey = ".db_tick($global_workflowtriggerkey); //d(__LINE__." SQL:",$sql); $mergedocuments=db_query($sql,1,0,documentid); d(mergedocuments,$mergedocuments); if(is_array($mergedocuments) && count($mergedocuments)>0) { $displaylist=implode(",", array_keys($mergedocuments)); $returnlist=array_keys($mergedocuments); d(__LINE__." Attachment List Array: ",$returnlist); if (is_developer()) set_message("debug workflowaction_getmergepdfdocuments : ".basename(__file__)." (".__line__."): documentlist: ".$displaylist."."); return $returnlist; } return false; } function workflowaction_execute_notificationemailtonotebiddingboardinvite($data, $data1, $data2, $data3, $data4, $action) { global $global_workfloweventkey; //d(__LINE__,$data); //d(__LINE__,$data1); //d(__LINE__,$data2); //d(__LINE__,$data3); //d(__LINE__,$data4); $data1 = unserialize($data1); $data2 = unserialize($data2); $data3 = unserialize($data3); if($data[notebiddingboardinviteselectedby]) { $sql = "select clientstaffemail from tblclientstaff join tbllogin using(clientstaffid) where loginid = ".db_number($data[notebiddingboardinviteselectedby]); //d(__LINE__,$sql); $to = db_query($sql,1,0,clientstaffemail); if(!$to || (count($to) && !$to[clientstaffemail])) { $sql = "select clientcompanyemail from tblclientcompany join tbllogin using(clientcompanyid) where loginid = ".db_number($data[notebiddingboardinviteselectedby]); $to = db_query($sql,1,0,clientcompanyemail); } } else exit_wrapper(); //d(to,$to); $to = implode(",",array_keys($to)); $from = $data2['from']; //d(to,$to); $subject = $data2['subject']; $body = $data2['body']; $data['fulladdress'] = $data['clientcompanypropertyaddress'] . " " . $data['clientcompanypropertycity'] . ", " . $data['clientcompanypropertystate'] . " " . $data['clientcompanypropertyzip']; //d(__LINE__." data2",$data2); if($data2[attachmergepdf]=="on") $attachmentmergepdfdocuments=workflowaction_getmergepdfdocuments($data); foreach($data as $field=>$val){ $field = str_replace(clientcompany,'',$field); $subject = str_replace('##'.$field,$val,$subject); $body = str_replace('##'.$field,$val,$body); $field = str_replace(property,'',$field); $subject = str_replace('##'.$field,$val,$subject); $body = str_replace('##'.$field,$val,$body); } global $expensemap; foreach ($expensemap as $subkey => $dbkey) { $subject = str_replace('##'.$subkey,$data[$dbkey],$subject); $body = str_replace('##'.$subkey,$data[$dbkey],$body); } if(strstr($subject,"##") || strstr($body,"##") && $data[clientcompanypropertyid]) { //if we still have some variables that have not yet been populated, look up the value in the property extension entry table $sql = "select * from tblpropertyextensionentry where clientcompanypropertyid = $data[clientcompanypropertyid] "; $qryv=db_query($sql); foreach($qryv as $row) { $val = $row[propertyextensionentryvalue]; $field = str_replace(propertyextension,'',$row[propertyextensionkey]); $subject = str_replace('##'.$field,$val,$subject); $body = str_replace('##'.$field,$val,$body); $field = $row[propertyextensionkey]; $subject = str_replace('##'.$field,$val,$subject); $body = str_replace('##'.$field,$val,$body); } } d(is_emails($to)); //d($body); if(!is_email($from)) $from = "noreply@riogenesis.com"; //html_mail_enable_devsite(); d(__line__."to: ",$to); d(__line__."from: ",$from); d(__line__."subject: ",$subject); d(__line__."body: ",$body); // exit; // ** tag ** // if (is_developer()) set_message("debug email internal: ".basename(__file__)." (".__line__."): ".$subject." ".$body); if(is_emails($to)) html_mail($to,$from,$subject,$body,$attachmentmergepdfdocuments); else d(__INVALID_EMAIL_ADDRESSES_NOT_SENT__________); } function workflowaction_execute_propertystatus($data, $clientcompanypropertystatus, $data2, $data3, $data4, $action) { //Update the agents copy of the property to 'Pulled' status if no more assignments for this property. (This function is executed from the trigger: propertystatus) d("==data==",$data); //d("==workflowaction_execute_propertystatus==",$clientcompanypropertystatus); $sql = "select * from tblclientcompanypropertyassignment join tbllogin using(staffid) where clientcompanypropertyid = ".db_number($data[clientcompanypropertyid]) ." and companyid = ".db_number($data[companyid])." and clientcompanypropertyassignmentcompleteddate is null and clientcompanypropertyassignmentrevokeddate is null and clientcompanypropertyassignmentexpired is null and clientcompanypropertyassignmentdenieddate is null"; $asgnmntqry = db_query($sql,0,1); if($asgnmntqry) return; //There are still outstanding assignments for this property within this company $sql = "select propertyextensionentryid,propertyid from tblproperty join tblpropertyextensionentry using(propertyid) where tblproperty.clientcompanypropertyid = ".db_number($data[clientcompanypropertyid]) ." and companyid = ".db_number($data[companyid])." and propertyextensionkey = 'propertyextensionstatus'"; $propqry = db_first($sql); $sql = "update tblpropertyextensionentry set propertyextensionentryvalue = 'Pulled' where propertyextensionentryid = ".db_number($propqry[propertyextensionentryid]); db_exec($sql,1); //find tasks to be created as a result of the status change $sql = "select * from tblmastertask mt join tblmastertaskcompany using(mastertaskid) where tblmastertaskcompany.companyid = ".db_number($data[companyid])." and (mt.companyid = 0 or mt.companyid = ".db_number($data[companyid]).") and mastertaskfieldname = 'propertyextensionstatus' and mastertaskfieldvalue = 'Pulled'"; $qrymt = db_query($sql,0,1); if (is_array($qrymt)) { foreach($qrymt as $k=>$mt) { $clientlist=""; if($mt[mastertaskclientidlist]) { $qryc = db_first("select group_concat(clientcompanyname) as clientlist from tblclient where clientid in ($mt[mastertaskclientidlist]) and companyid = ".db_number($data[companyid])); $clientlist = $qryc[clientlist]; $mt[clientlist]=$clientlist; } $mtarr[$mt[mastertaskfieldname]][] = $mt; } } //d(__LINE__,$mtarr); //exit; if($mtarr) foreach($mtarr as $field =>$mts) { foreach($mts as $mt) { $grps=""; if($mt[mastertaskcompanyassignedstaffgroups]) { $qryg = db_first("select group_concat(groupname) as grps from tblgroup where groupid in ($mt[mastertaskcompanyassignedstaffgroups])"); $grps = $qryg[grps]; } $staffids = $mt[mastertaskcompanyassignedstaffids]; $duedate = date("m/d/Y",dateadd('d',$mt[mastertaskdeadlinedays],time() )); //d(mt, $mt); //exit; if($grps||$staffids) { //in rare circiumstances, $grps is empy because the admin selected a task but did not assigne it, just skip this. $taskid = create_task($propqry[propertyid],$mt[mastertaskname],$mt[mastertaskid],$mt[mastertaskdescription],$duedate,$grps,$grps,'newtaskassigned',$staffids,$staffids) ; if($mt[mastertaskrecurring]) { $sql = "update tbltask set taskrecurring = 1, taskrecurdays = 0$mt[mastertaskrecurdays] where taskid = $taskid"; db_exec($sql); } } } } } function pdf_mergetofile($wysiwygdata1,$mergearray,$filename,$setpreviewmessages='') { global $global_workfloweventkey; //d(mergearr,$mergearray); dlog('mergepdf',"pdf_mergetofile START workfloweventkey: $global_workfloweventkey"); $originalwysiwygdata1=$wysiwygdata1; if (!is_array($wysiwygdata1)) $wysiwygdata1=unserialize($wysiwygdata1); if($wysiwygdata1[body]) $html=$wysiwygdata1[body]; else $html=$originalwysiwygdata1; $wysiwygheader=$wysiwygdata1[header]; $wysiwygfooter=$wysiwygdata1[footer]; $hheight=$wysiwygdata1[hheight]; if(!$hheight) $hheight=20; $fheight=$wysiwygdata1[fheight]; if(!$fheight) $fheight=45; else $fheight+=25; if($autopagenumber || $autodate) { if($fheight<45) $fheight=45; } if($wysiwygheader) $backtop="backtop='".$hheight."px'"; if($wysiwygfooter || $autopagenumber || $autodate) $backbottom="backbottom='".$fheight."px'"; if($wysiwygdata1[autopagenumber] && $wysiwygdata1[autopagenumber]=='on') $autopagenumber='page;'; if($wysiwygdata1[autodate] && $wysiwygdata1[autodate]=='on') $autodate='date;'; if($autopagenumber || $autodate) $autofooter="footer='".$autopagenumber.$autodate."'"; if(!$html) { if($setpreviewmessages=='preview') { set_message("Preview Error: Invalid HTML for pdf merge to file.",error); return; } else { if(is_developer()) set_message("DEVELOPER ERROR: pdf_mergetofile Invalid HTML for pdf merge to file. workfloweventkey: $global_workfloweventkey"); ddie("Error: Invalid HTML for pdf merge to file."); } } if(!is_array($mergearray)) { if($setpreviewmessages=='preview') { set_message("Preview Error: Invalid merge array for pdf merge to file.",error); return; } else { if(is_developer()) set_message("DEVELOPER ERROR: pdf_mergetofile Invalid merge array for pdf merge to file. workfloweventkey: $global_workfloweventkey"); ddie("Error: Invalid merge array for pdf merge to file."); } } if(!$filename) { if($setpreviewmessages=='preview') { set_message("Preview Error: Invalid filename for pdf merge to file.",error); return; } else { if(is_developer()) set_message("DEVELOPER ERROR: pdf_mergetofile Invalid filename for pdf merge to file. workfloweventkey: $global_workfloweventkey"); ddie("Error: Invalid filename for pdf merge to file."); } } //d(wysiwygheader,$wysiwygheader); //d(wysiwygfooter,$wysiwygfooter); $pageconfig=""; if($wysiwygheader) { $pageconfig.=""; $pageconfig.=$wysiwygheader; $pageconfig.=""; } if($wysiwygfooter) { $pageconfig.=""; $pageconfig.=$wysiwygfooter; $pageconfig.=""; } $pageconfig.=$html.""; $html=$pageconfig; //$html="

Header Goes Here Line 1

Header Goes Here Line 2

Page Footer Goes Here Line 1

".$html; //d(html,$html); //d(mergearray,$mergearray); //d(filename,$filename); //This section was put in as a hotfix on live to add some keys when there wasn't an assignment for them. Shouldn't be necessary after migration because of additional functionality. $assigns = clientcompanyproperty_getadditionaldata(-1); if(is_array($assigns)) foreach($assigns as $assignkey=>$assignvalue) { if(!in_array($assignkey,array_keys($mergearray))) $mergearray[$assignkey]="_"; } if(is_array($mergearray)) { uksort($mergearray, "keylengthcompare"); $mergearray[pagebreak]="
"; foreach($mergearray as $replacementkey=>$replacementvalue) { if(!$replacementkey) continue; //echo "replacementkey: $replacementkey replacementvalue: $replacementvalue
"; //$html=str_replace("##".$replacementkey, $replacementvalue, $html); if($setpreviewmessages!='preview' && (substr($replacementkey,0, 8)=='assigned') && (!$replacementvalue && $replacementvalue!==0)) $replacementvalue='_'; $replacementkey=str_replace('/', '\/', $replacementkey); $replacementkey=str_replace('^', '\^', $replacementkey); $replacementkey=str_replace('$', '\$', $replacementkey); $replacementkey=str_replace('[', '\[', $replacementkey); $replacementkey=str_replace(']', '\]', $replacementkey); $replacementkey=str_replace('|', '\|', $replacementkey); $replacementkey=str_replace('(', '\(', $replacementkey); $replacementkey=str_replace(')', '\)', $replacementkey); $replacementkey=str_replace('.', '\.', $replacementkey); $replacementkey= preg_replace("/\s/",'\s', $replacementkey); if(is_null(@preg_replace("/##".$replacementkey."(\b)/",$replacementvalue."\$1", $html))) { $errmessagesubject="DEVELOPER ERROR: pdf_mergetofile error in preg_replace for replacementkey:$replacementkey replacementvalue:$replacementvalue :workfloweventkey: $global_workfloweventkey"; dlog('workflowevent',$errmessagesubject); developer_error($errmessagesubject); continue; } $html= preg_replace("/##".$replacementkey."(\b)/",$replacementvalue."\$1", $html); $html= preg_replace("/##".$replacementkey."(##)/",$replacementvalue."\$1", $html); } if($setpreviewmessages=='preview') { $replacewith="NOT_REPLACED"; $html= preg_replace("/(##assigned[\w]*##)/",$replacewith."\$1", $html); $html= preg_replace("/(##assigned[\w]*\b)/",$replacewith."\$1", $html); $html= preg_replace("/(##[\w]*\b)/",$replacewith."\$1", $html); } else { $replacewith='_'; $html= preg_replace("/##assigned[\w]*(##)/",$replacewith."\$1", $html); $html= preg_replace("/##assigned[\w]*(\b)/",$replacewith."\$1", $html); if($setpreviewmessages!='preview') $replacewith=''; $html= preg_replace("/##[\w]*(\b)/",$replacewith."\$1", $html); } } //d(html,$html); //echo htmlentities($documenttext)."
"; //echo "$documenttext
"; require_once('html2pdf_v4.03/html2pdf.class.php'); $html2pdf = new HTML2PDF('P', 'Letter', 'en'); $html2pdf->pdf->SetDisplayMode('fullpage'); $html=pdf_cleanup_html($html); d(html,$html); //$html2pdf->writeHTML($html); try { //this fix is in _inc/functions_workflow, _inc/functions_clienttask, ajax_clienttaskpdf, and schedule/task2pdf $html = preg_replace('/calibri/i', 'helvetica', $html); $html2pdf->writeHTML($html); } catch(HTML2PDF_exception $e) { if($setpreviewmessages=='preview') { $errormsg="Preview Error: Invalid html in WYSIWYG. Check for large borders, incorrect html tags or html 4.01 errors in the source"; if(is_developer()) $errormsg.=": $e"; set_message($errormsg,error); return; } else { dlog('workflowevent',"pdf_mergetofile error writingHTML: ".$e." workfloweventkey: $global_workfloweventkey"); //ddie("DEVELOPER ERROR: pdf_mergetofile error writingHTML Message: ".$e,$html); $errmessagesubject="DEVELOPER ERROR: pdf_mergetofile writingHTML workfloweventkey: $global_workfloweventkey"; $errmessagebody="$e
".htmlentities($html); developer_error($errmessagesubject,$errmessagebody); } } //$html2pdf->Output($filename, 'F'); try { $html2pdf->Output($filename, 'F'); } catch(HTML2PDF_exception $e) { if($setpreviewmessages=='preview') { $errormsg="Preview Error: Invalid html in WYSIWYG. Check for large borders, incorrect html tags or html 4.01 errors in the source"; if(is_developer()) $errormsg.=": $e"; set_message($errormsg,error); return; } else { dlog('workflowevent',"pdf_mergetofile error with Output: ".$e." :workfloweventkey: $global_workfloweventkey"); //ddie("DEVELOPER ERROR: pdf_mergetofile error writingHTML Message: ".$e,$html); $errmessagesubject="DEVELOPER ERROR: pdf_mergetofile error with Output :workfloweventkey: $global_workfloweventkey"; $errmessagebody="$e
".htmlentities($html);; developer_error($errmessagesubject,$errmessagebody); } } if(!file_exists($filename)) if($setpreviewmessages=='preview') { $errormsg="Preview Error: Invalid html in WYSIWYG. Check for large borders, incorrect html tags or html 4.01 errors in the source"; if(is_developer()) $errormsg.=": $e"; set_message($errormsg,error); return; } else { if(is_developer()) set_message("DEVELOPER ERROR: pdf_mergetofile PDF file output but does not exist for pdf merge to file. workfloweventkey: $global_workfloweventkey"); ddie("Error: PDF file output but does not exist for pdf merge to file."); } dlog('mergepdf',"pdf_mergetofile END workfloweventkey: $global_workfloweventkey"); } function workflowaction_execute_mergepdf($data, $wysiwygdata1, $unused2, $unused3, $unused4, $action) { d("workflowaction_execute_mergepdf"); //d("data",$data); //d(action,$action); //d(wysiwygdata1,$wysiwygdata1); $currenttime=date("mdYHis"); //$addrand=rand(1,99); $pdffilename=$action[workflowtriggeractiontypename]."_".$currenttime.".pdf"; $pdffilename=websafe_filename($pdffilename); //d(pdffilename,$pdffilename); // Get a temp name $thistempname = tempnam(sys_get_temp_dir(),"mergepdf").".pdf"; //d(thistempname,$thistempname); pdf_mergetofile($wysiwygdata1,$data,$thistempname); $_FILES[mergepdf][name] = $pdffilename; $_FILES[mergepdf][type] = ""; $_FILES[mergepdf][tmp_name] = $thistempname; $_FILES[mergepdf][error] = 0; $_FILES[mergepdf][size] = 0; $property = "property"; $propertyid = $data[propertyid]; if ($data[clientcompanypropertyid]) { $property = "clientcompanyproperty"; $propertyid = $data[clientcompanypropertyid]; } global $global_workflowtriggerkey; $docid = process_customfield_documentupload_type($propertyid, $property ,mergepdf, mergepdf,0,0,'','',$global_workflowtriggerkey); d(mergepdfdocid,$docid); if (is_developer()) set_message("debug execute merge pdf : ".basename(__file__)." (".__line__."): new mergedpdf created with docid: ".$docid."."); } function workflow_options_propertyattribute($propertyettrib = '',$propertyettrib2 = '') { $availablefields = myviews_get_availablecolumns(); $propertyextensions = array(); if (is_array($availablefields) && !empty($availablefields)) foreach ($availablefields as $k=>$value) { if ($value[type] == 'propertyextension') $propertyextensions[] = array('id' => $value[key], 'value' => $value[label]); } $out = customfield_return('sqldropdown',workflowtriggerdata1,$propertyettrib,$propertyextensions,'[select property attribute]'); //d(propertyextensions,$propertyextensions); $out .= "
Trigger if new value matches comma delimited list:
"; $out .= customfield_return('textbox',workflowtriggerdata2,$propertyettrib2); return $out; } function workflow_options_validate_propertyattribute($isrequired = 0) { if ($isrequired && empty($_POST[workflowtriggerdata1])) set_message("You must select the required options.", error); } function workflow_preprocessdata($row) { $row['actualvendorprice'] = 0; $row['actualclientprice'] = 0; $row['expectedvendorprice'] = 0; $row['expectedclientprice'] = 0; foreach($row as $col=>$val) { if(!$val) continue; //date processing to show valid dttime_formats. if(substr($col,-4)=='date') $val = dttime_format($val); elseif(substr($col,-7)=='created') $val = dttime_format($val); elseif(substr($col,-7)=='updated') $val = dttime_format($val); elseif(substr($col,-2)=='by') $val = get_login_info($val); elseif(substr($col,-11) == propertyzip) $row[region] = getregion_fromzip($val); //added with Region filter to allow filtering by region (urban, rural, remote) see _inc/zip_regions.txt; elseif(substr($col,-9)=='contactid') { //$tablename=substr($col, 0,strlen($col)-2); $sql = "select COALESCE(contactcname, '') || COALESCE(contactname, '') as contactreplacement from tblcontact where contactid=".db_number($val); $contactreplacement=db_firstval($sql); if($contactreplacement) $val=$contactreplacement; else $val=''; } elseif($col=='clientpretaskname') { $row['lineitem'] = $val; } elseif($col=='clienttaskvendorprice') { $row['actualvendorprice'] = $val; $row['expectedvendorprice'] = ""; if($row['clienttaskbilleddate']) $row['expectedvendorprice'] = $val; } elseif($col=='clienttaskclientprice') { $row['actualclientprice'] = $val; $row['expectedclientprice'] = ""; if($row['clienttaskbilleddate']) $row['expectedclientprice'] = $val; } $val = str_replace("00:00:00","",$val); // replace this string from date entries $val = trim($val); $row[$col] = $val; } if($row['clientpretaskid'] && !$row['clienttaskbilleddate']) { $val = get_specificlineitempricing($row[lineitemcategoryentryid], getregion_fromzip($row['clientcompanypropertyzip']), $row['clientcompanyclientid']); if ($val) { $row['expectedvendorprice'] = $val['lineitempricingvendorprice']; $row['expectedclientprice'] = $val['lineitempricingclientprice']; } } if($row[clientcompanypropertyid] && is_numeric($row[clientcompanypropertyid])) { $arradd=clientcompanyproperty_getadditionaldata($row[clientcompanypropertyid]); if(is_array($arradd)) $row=array_merge($row,$arradd); } return $row; } function workflow_createscheduledtask($taskdata) { $sql = " insert into tblclienttaskschedule ( clienttaskschedulecreatedby , clienttaskschedulename , clienttaskscheduledescr , clienttaskscheduleautoapprove , clienttaskscheduleduedays , clienttaskschedulefirstdate , clienttaskschedulerecurdays , clienttaskschedulerecurlastdate , clienttaskschedulerecurrules , clientcompanypropertyid , tasktemplateid , workflowtriggeractionid , roleid , clientcompanypropertyassignmentid ) values ( ".db_number($taskdata[clienttaskschedulecreatedby])." , ".db_tick($taskdata[clienttaskschedulename])." , ".db_tick($taskdata[clienttaskscheduledescr])." , ".db_number($taskdata[clienttaskscheduleautoapprove])." , ".db_number($taskdata[clienttaskscheduleduedays])." , ".db_date($taskdata[clienttaskschedulefirstdate])." , ".db_number($taskdata[clienttaskschedulerecurdays])." , ".db_date($taskdata[clienttaskschedulerecurlastdate])." , ".db_tick($taskdata[clienttaskschedulerecurrules])." , ".db_number($taskdata[clientcompanypropertyid])." , ".db_number($taskdata[tasktemplateid])." , ".db_number($taskdata[workflowtriggeractionid])." , ".db_number($taskdata[roleid])." , ".db_number($taskdata[clientcompanypropertyassignmentid])." ) "; if (trim($sql) != '') db_exec($sql,1); } function getpropertyextensionkeylabel($clientcompanyid = 0, $clientcompanypropertyid = 0) { if ($clientcompanyid > 0) $clientcompanyidsql = db_number($clientcompanyid); else if ($clientcompanypropertyid > 0) $clientcompanyidsql = "(select clientcompanyid from tblclientcompanyproperty where clientcompanypropertyid = ".db_number($clientcompanypropertyid).")"; else return ''; $sql = " select distinct(propertyextensionkey), propertyextensionlabel from tblpropertyextensionentry join tblpropertyextension using (propertyextensionkey) where clientcompanypropertyid in ( select clientcompanypropertyid from tblclientcompanyproperty where clientcompanyid = {$clientcompanyidsql} and clientcompanypropertycloseddate is null and clientcompanyid > 0 )"; $propextens = db_query($sql); if (!$propextens) return ''; $fieldselect = array(); foreach ($propextens as $extens) $fieldselect[$extens[propertyextensionlabel]] = $extens[propertyextensionkey]; return $fieldselect; } function get_serializedworkflow($clientcompanyid, $workfloweventshortname, &$message='') { if (trim($clientcompanyid) == '') return false; if (trim($workfloweventshortname) == '') return false; $sql = " select workflowtriggerid from tblworkflowtrigger where workfloweventid = ( select workfloweventid from tblworkflowevent where workfloweventshortname = ".db_tick($workfloweventshortname)." ) and clientcompanyid = ".db_number($clientcompanyid); $qry = db_query($sql,1,0,workflowtriggerid); d(qry, $qry); if (!qry) { $message = "Error: No workflow triggers found"; return false; } return implode(',', array_keys($qry)); } function set_serializedworkflow($clientcompanyid, $workfloweventshortname, $ids, &$message='') { if (trim($clientcompanyid) == '') return false; if (trim($workfloweventshortname) == '') return false; if (trim($ids) == '') return false; $triggerids = explode(',', $ids); d(triggers, $triggerids); //loop over the triggers if ($triggerids) foreach ($triggerids as $id) { $event = db_first("select workfloweventshortname, workfloweventname from tblworkflowevent join tblworkflowtrigger using (workfloweventid) where workflowtriggerid = ".$id); if ($event[workfloweventshortname] != $workfloweventshortname) { $message = "Error: Attempting to import workflow triggers intended for event '{$event[workfloweventname]}' into the current workflow event."; return false; } //get a new triggerid $trigid = db_nextid('workflowtrigger'); //insert the new trigger if this doesn't exist already $trigsql = " insert into tblworkflowtrigger (workflowtriggerid, clientcompanyid, workflowtriggername, workflowtriggercreateddate, workflowtriggercreatedby, workflowtriggerdata1, workflowtriggerdata2, workfloweventid) select {$trigid}, ".db_number($clientcompanyid).", workflowtriggername, now(), 0, workflowtriggerdata1, workflowtriggerdata2, workfloweventid from tblworkflowtrigger where workflowtriggerid = ".db_number($id); db_exec($trigsql); copy_mapstore(workflowtriggerid, $id, $trigid); copy_tablewhere(workflowtriggeraction,"workflowtriggerid = ".db_number($id)); $updsql = "update tblworkflowtriggeraction set workflowtriggeractioncreatedby = 0, workflowtriggeractioncreateddate = now() where workflowtriggerid = ".$trigid; db_exec($updsql); copy_tablewhere(workflowtriggerfilter,"workflowtriggerid = ".db_number($id)); $updsql = "update tblworkflowtriggerfilter set workflowtriggerfiltercreatedby = 0, workflowtriggerfiltercreateddate = now() where workflowtriggerid = ".$trigid; db_exec($updsql); } return 'import'; }