function is_activedisplay($name, $tabsname, $propertyid=0) { if ($name) { if ($name == "tabdisplay") $colname = "propertytabdisableisdisabled"; else if ($name == "taskdisplay") $colname = "propertytabdisabletaskdisplay"; else if ($name == "notesdisplay") $colname = "propertytabdisablenotesdisplay"; if ($colname) { if ($propertyid) $clientcompanyid = get_clientcompanyidfromclientproperty($propertyid); if (!$clientcompanyid) $clientcompanyid = clientcompanyid(); $sql = "select ".$colname." from tblpropertytabdisable a join tblpropertytab using (propertytabid) where propertytabshortname = '".db_col($tabsname)."' and a.clientcompanyid ='".db_number($clientcompanyid)."'"; $chck = db_first($sql); if ($chck[$colname]) return FALSE; else return TRUE; } } return false; } function is_activetab($tabsname,$propertyid=0) { //this makes it so this function will work for when the company uses it if ($propertyid) $clientcompanyid = get_clientcompanyidfromclientproperty($propertyid); if (!$clientcompanyid) $clientcompanyid = clientcompanyid(); $sql = "select propertytabdisableisdisabled from tblpropertytabdisable a join tblpropertytab using (propertytabid) where propertytabshortname = '".db_col($tabsname)."' and a.clientcompanyid ='".db_number($clientcompanyid)."'"; $chck = db_first($sql); if ($chck[propertytabdisableisdisabled]) return FALSE; else return TRUE; } function is_activetaskdisplay($tabsname, $propertyid=0) { if ($propertyid) $clientcompanyid = get_clientcompanyidfromclientproperty($propertyid); if (!$clientcompanyid) $clientcompanyid = clientcompanyid(); $sql = "select propertytabdisabletaskdisplay from tblpropertytabdisable a join tblpropertytab using (propertytabid) where propertytabshortname = '".db_col($tabsname)."' and a.clientcompanyid ='".db_number($clientcompanyid)."'"; $chck = db_first($sql); if ($chck[propertytabdisabletaskdisplay]) return FALSE; else return TRUE; } /** * @name get_tabfieldtypes * @comment returns array of all custom field names * @return array filedtypes [customfieldtypeid][customfieldtypename] */ function get_tabfieldtypes() { $fieldtypes = db_query("select customfieldtypeid, customfieldtypename from tblcustomfieldtype order by customfieldtypeid"); foreach ($fieldtypes as $f=>$fields){ $f_tmp[$fields[customfieldtypeid]]= ucwords(sub_ftypename($fields[customfieldtypename])); } unset($fieldtypes); return $f_tmp; } /** * @name sub_ftypename * @param [string] $name * @return [string] $name */ function sub_ftypename ($name){ $substtitue = array("ob"=>"Custom","mlist"=>"Configured List"); if($substtitue[strtolower($name)]) $name = $substtitue[strtolower($name)]; unset($substtitue); return $name; } /** * @name gettab_names() * @return array Available tabs * @version v1.0.1 added support for Genesis */ function gettab_names($clientcompanyidlist="") { if (client_portal()) $clientid = get_clientcompanyidfromclientproperty($_GET[view]); if (externaluserid()) { $clientid = clientcompanyid(); } elseif (clientcompanyid()) $clientid = clientcompanyid(); if($clientcompanyidlist && $clientcompanyidlist!="") { $hasclientcompanyidlist=TRUE; unset($clientid); } $sql = "select propertytabname as label, propertytabshortname as url "; if(!clientcompanyid() && !$clientid) $sql.=" , propertytabid"; else { $sql.=" , coalesce (tblpropertytab.propertytabid,tblpropertytabdisable.propertytabid) as propertytabid ,tblpropertytabdisable.propertytabdisableid , tblpropertytabdisable.propertytabdisableisdisabled , propertytabenablerule as enablerule "; } $sql.=" from tblpropertytab "; if ($clientid) $sql .= " left join tblpropertytabdisable on (tblpropertytab.propertytabid = tblpropertytabdisable.propertytabid and tblpropertytabdisable.clientcompanyid = '".db_number($clientid)."')"; $sql .= " where 0=0"; if($clientid) $sql.=" and (tblpropertytab.clientcompanyid = '-1' or tblpropertytab.clientcompanyid = ".$clientid." or coalesce(propertytabenablerule,'') <> '')"; elseif($hasclientcompanyidlist) $sql.=" and (tblpropertytab.clientcompanyid = '-1' or tblpropertytab.clientcompanyid IN (".$clientcompanyidlist.") or coalesce(propertytabenablerule,'') <> '')"; else $sql.=" and (companyid = '-1' or coalesce(propertytabenablerule,'') <> '') "; $sql .= " and tblpropertytab.propertytabid >'0' order by tblpropertytab.propertytabid"; $sqltabs = db_query($sql); foreach($sqltabs as $k=>$row) if($row[propertytabenablerule] && !eval("return $row[propertytabenablerule];")) unset($sqltabs[$k]); return $sqltabs; } function get_all_tab_names() { $sql = "select *, propertytabname as name, propertytabshortname as url from tblpropertytab where 0=0 "; $sqltabs = db_query($sql); return $sqltabs; } /** * is_tab ($tabshortname) returns TRUE or FALSE * @param string $tabshortname tab short name * @return bool TRUE OR FALSE */ function is_tab($tabshortname) { $tab = db_first("select propertytabname from tblpropertytab where propertytabshortname='".db_col($tabshortname)."' and (clientcompanyid = '-1' or clientcompanyid = '".db_number(clientcompanyid())."')"); if ($tab[propertytabname]) return true; return false; } /** * tab_nav_tabs ($tabs) * @param array $tabs list of tabs * @return html navigation tabs */ function tab_nav_tabs($tabs) { $style = " "; if (!$tabs) return FALSE; echo $style; echo "
"; return true; } } /** * gettab_categories ($tabname) * @param string $tabname is tab's short name * @return array $active_categories */ function gettab_categories($tabname,$tabcategoryid=0,$cliencompanypropertyid = 0,$useid=0) { global $sisterassign; if (client_portal() || $sisterassign) $assignedproperty = 1; if ( $assignedproperty && $cliencompanypropertyid) { $clientcompanyid = get_clientcompanyidfromclientproperty($cliencompanypropertyid); }else $clientcompanyid = clientcompanyid(); $sql = "select coalesce(propertycategoryname, propertytabcategoryname) as shortname, coalesce(propertycategorydisplayname, propertytabcategorydisplayname) as name ,* from tblpropertytabcategory join tblpropertytab using (propertytabid) left join tblpropertycategory using (propertycategoryid) where 0=0 "; if ($clientcompanyid) $sql .= " and tblpropertytabcategory.clientcompanyid = '".db_number($clientcompanyid)."'"; if (!$tabcategoryid && $clientcompanyid && strtolower($tabname) == "property" ) // if they specified the tabcategory, that means we can't just skip it because it is invisible $sql .=" and (propertycategoryclientinvisible =0 or propertycategoryclientinvisible is null) ";// -- in case the category does not exist"; if (!$clientcompanyid) $sql .= " and tblpropertytabcategory.clientcompanyid = '0'"; if (!$useid) $sql .= " and propertytabshortname = lower ('".$tabname."')"; else { $sql .="and propertytabid = '".$tabname."'"; } if ($tabcategoryid) $sql .= " and propertytabcategoryid = '".$tabcategoryid."'"; $sql .= " order by propertytabcategoryrank"; $active_categories = db_query($sql); return $active_categories; } /** * get_clientcompantyidfromclientproperty($clientcompanypropertyid) * @var integer $clientcompanypropertyid * @return integer $clientcompanyid */function get_clientcompanyidfromclientproperty ($clientcompanypropertyid) { $ccid = db_first("select clientcompanyid from tblclientcompanyproperty where clientcompanypropertyid = '".db_number($clientcompanypropertyid)."'"); $clientcompanyid = $ccid[clientcompanyid]; return $clientcompanyid; } /** * gettab_allcustomextensions($core=0) * @param integer $core if set will only return extension id as id and extension label as value * @return array $allcustomextensions */ function gettab_allcustomextensions($core=0){ $select = "*"; if ($core) $select = " propertyextensionid as id, propertyextensionlabel as value "; $sql = "select distinct ".$select." from tbltabcategorypropertyextension join tblpropertyextension using (propertyextensionid) where 0 = 0"; if (clientcompanyid()) $sql .= "and clientcompanyid = '".db_number(clientcompanyid())."'"; if (companyid()) $sql .= "and companyid = '".db_number(companyid())."'"; $allcustomextensions = db_query($sql); return $allcustomextensions; } /** * gettab_extensions ($tabname,$clientpropertyid,$propertyid) * @param string $tabname as tab short name * @param integer $clientpropertyid as clientcompanypropertyid * @param integer propertyid as propertyid * @return array $all_extensions */ function get_amctype_tabs_defaultexclude($type,$clientcompanyid=0) { $disabledbydefault=array(); // update to get this date from the table if(clientcompanyid()) $clicoid=clientcompanyid(); $sql="select * from tblvendortypetabexclusion where 0=0"; if(!$clientcompanyid && $clicoid) $sql.=" and clientcompanyid=".$clicoid.""; else if($clientcompanyid && !$clicoid) $sql.=" and clientcompanyid=".db_number($clientcompanyid).""; else if(!$clientcompanyid && !$clicoid) $sql.=" and clientcompanyid=0 "; $sql.=" and vendortypetabexclusionexternalusertype=".db_number($type); $res=db_query($sql); if(!$res) { $sql="select * from tblvendortypetabexclusion where 0=0 "; $sql.=" and clientcompanyid=0 "; $sql.=" and vendortypetabexclusionexternalusertype=".db_number($type); $res=db_query($sql); } if($res) { foreach($res as $rowk=>$row) { if($row['vendortypetabexclusion_tabonoff']) $disabledbydefault[]=$row['vendortypetabexclusionshortname']; } } return $disabledbydefault; } function get_amctype_tabs($type,$clientcompanyid=0,$tabsarray=array()) { $disabled=get_amctype_tabs_defaultexclude($type,$clientcompanyid); $alltabs= $tabsarray; if(count($tabsarray)) { foreach($alltabs as $tabshort=>$tablabel) { $cntr++; if(!in_array($tabshort,$disabled)) { $retarr[$cntr][name]=$tablabel; $retarr[$cntr][shortname]=$tabshort; $retarr[$cntr][enabled]=1; $retarr[$cntr][data]=$tab; } } } else { $alltabs= get_all_tab_names(); foreach($alltabs as $tab) { $cntr++; if(!in_array($tab[propertytabshortname],$disabled)) { $retarr[$cntr][name]=$tab[propertytabname]; $retarr[$cntr][shortname]=$tab[propertytabshortname]; $retarr[$cntr][enabled]=1; $retarr[$cntr][data]=$tab; } else { $retarr[$cntr][name]=$tab[propertytabname]; $retarr[$cntr][shortname]=$tab[propertytabshortname]; $retarr[$cntr][enabled]=0; $retarr[$cntr][data]=$tab; } } } return $retarr; } function gettab_extensions ($tabname="",$clientpropertyid = 0,$propertyid = 0,$include_cfdata=0, $clientcompanyidlist="") { global $sisterassign; if (client_portal() || $sisterassign) $assignedproperty = 1; if ($include_cfdata !='1') unset($include_cfdata); if ($assignedproperty && $clientpropertyid) { $clientcompanyid = get_clientcompanyidfromclientproperty($clientpropertyid); }else $clientcompanyid = clientcompanyid(); if($clientcompanyidlist && $clientcompanyidlist!="") { $hasclientcompanyidlist=TRUE; unset($clientcompanyid); } $tabname = trim(strtolower($tabname)); if ($clientcompanyid) { $sql = " select * , case when exists (select 1 from tblclientcompanypropertyextension where propertyextensionid = tbltabcategorypropertyextension.propertyextensionid) or exists (select 1 from tbltabcategorypropertyextension t join tblpropertytabcategory using(propertytabcategoryid) where propertytabid = 0 and propertyextensionid = tbltabcategorypropertyextension.propertyextensionid) then 1 else 0 end as enableddetailpage "; if ($clientpropertyid || $include_cfdata) $sql .= ", coalesce (e.propertyextensionkey,q.propertyextensionkey) as propertyextensionkey"; $sql .= ",(case when tabcategorypropertyextensionrank is null then 1000 else tabcategorypropertyextensionrank end) as clientcompanypropertyextensionrank from tbltabcategorypropertyextension join tblpropertytabcategory using(propertytabcategoryid) join tblpropertytab using (propertytabid) join tblpropertyextension e using (propertyextensionid)"; if ($clientpropertyid || $include_cfdata) $sql .= " left join tblpropertyextensionentry q on (q.propertyextensionkey = e.propertyextensionkey and clientcompanypropertyid ='".db_number($clientpropertyid)."' ) left join tblcustomfieldtype using (customfieldtypeid) "; $sql .= " where 0=0"; if ($tabname) $sql .= " and propertytabshortname in (".db_tick_list($tabname).")"; $sql .= " and tbltabcategorypropertyextension.clientcompanyid = '".db_number($clientcompanyid)."'"; } elseif($hasclientcompanyidlist) { $sql = " select * from tbltabcategorypropertyextension join tblpropertytabcategory using(propertytabcategoryid) join tblpropertytab using (propertytabid) join tblpropertyextension e using (propertyextensionid)"; if( $include_cfdata) $sql .= " join tblcustomfieldtype using (customfieldtypeid) "; $sql .= " where 0=0"; if ($tabname) $sql .= " and propertytabshortname in (".db_tick_list($tabname).")"; $sql .= " and tbltabcategorypropertyextension.clientcompanyid IN (".db_number_list($clientcompanyidlist).")"; } else { $sql ="select * from tbltabcategorypropertyextension join tblpropertytabcategory using(propertytabcategoryid) join tblpropertytab using (propertytabid) join tblpropertyextension using (propertyextensionid)"; if ($propertyid) { $sql .= " join tblpropertyextensionenable on (tbltabcategorypropertyextension.tabcategorypropertyextensionid=tblpropertyextensionenable.tabcategorypropertyextensionid) "; } $sql .= " left join tblcustomfieldtype using (customfieldtypeid) where propertytabshortname in (".db_tick_list($tabname).") and tbltabcategorypropertyextension.clientcompanyid = '0' "; if ($propertyid) { $sql .=" and propertyextensionenableassignmenttype=(select propertyassignmenttype from tblproperty where propertyid = ".db_number($propertyid).") and propertyextensionenable_enabled = 1 "; if (companyid()) { $sql.= " and ( ( coalesce(propertyextensionenable_companyid, 0) = 0 and not exists ( select 1 from tblpropertyextensionenable tpee where tpee.propertyextensionid = tblpropertyextensionenable.propertyextensionid and propertyextensionenable_companyid = ".companyid()." and propertyextensionenableview is null ) ) or propertyextensionenable_companyid = ".companyid()." )"; } else $sql.= " and propertyextensionenable_companyid = 0 "; } } if($hasclientcompanyidlist) $sql .= " order by propertyextensionkey"; else $sql .= " order by tabcategorypropertyextensionrank"; $all_extensions = db_query($sql); return $all_extensions; } /** * get_allavailablecategories() * @return array $availcategories id,value sorted alphabetically * */ function get_allavailablecategories() { $sql = "select propertycategoryid as id, propertycategorydisplayname as value from tblpropertycategory where 0=0 "; if (clientcompanyid()) $sql .=" and propertycategoryclientinvisible='0' "; $sql .=" order by propertycategorydisplayname"; $availcategories = db_query($sql); return $availcategories; } function gettab_addexistingextensions($currenttab){ $exludelist = gettab_extensions(trim($currenttab)); if (trim($currenttab)=="property"){ if ($clientcompanyid) { $sql = "select coalesce (a.propertyextensionid,b.propertyextensionid) as propertyextensionid from tblpropertyextension a left join tblclientcompanypropertyextension b on (a.propertyextensionid = b.propertyextensionid and clientcompanyid = '".db_number($clientcompanyid)."') where (propertyextensionclientuse = 1 or (propertyextensionclientuse ='2' and clientcompanyid = '".db_number($clientcompanyid)."')) and propertycategoryid > 0"; $sql.=" order by propertycategoryid "; }else{ $sql = " select a.propertyextensionid from tblpropertyextension a join tblpropertycategory using(propertycategoryid) join tblcustomfieldtype using (customfieldtypeid) where propertyextensionclientuse < 2 and propertycategoryid > 0"; $sql.=" order by propertycategoryrank,propertyextensionrank"; } $allextensions = db_query($sql); foreach ($allextensions as $ekey=>$eval){ $shexcludelist[$eval[propertyextensionid]]= $eval[propertyextensionid]; } } $tabs = db_query(" select * from tblpropertytab"); $outarray[$i][id] = " "; $outarray[$i][value] = "-- Custom Extensions --"; $outarray[$i][label] = 1; $i++; foreach ($tabs as $t=>$tab){ $tabcategories = gettab_categories(trim($tab[propertytabshortname])); $tabextensions = gettab_extensions(trim($tab[propertytabshortname])); if (trim($tab[propertytabshortname]) == trim($currenttab)) continue; if (is_array($tabcategories) && empty($tabcategories)) continue; $outarray[$i][id] = " "; $outarray[$i][value] = $tab[propertytabname]." Tab"; $outarray[$i][label] = 1; $i++; $k=$i; foreach ($tabcategories as $tc=>$category){ //skip tab categories that are of type table if($category[propertytabcategorytype]==table) // we do not want to display as an option, any of the cateogories that have the type table. continue; $outarray[$i][id] = " "; $outarray[$i][value] = $category[name]; $outarray[$i][label] = 1; $i++; $j=$i; foreach ($tabextensions as $te=>$textension){ if ($textension[propertytabcategoryid] == $category[propertytabcategoryid]){ if (is_array($shexcludelist) && !empty($shexcludelist)){ if (array_key_exists($textension[propertyextensionid], $shexcludelist)){ continue; } } $outarray[$i][id] = $textension[propertyextensionid]; $outarray[$i][value] = $textension[propertyextensionlabel]; $i++; } } if ($j>=$i){ $i--; } } if ($k>=$i) $i--; } foreach ($outarray as $okey=>$outval){ foreach ($exludelist as $exkey=>$exval){ if ($exval[propertyextensionid] == $outval[id]) unset ($outarray[$okey]); } } return $outarray; } /** * get_allavailablecustomcategories() * @return array $availcustomcategories id,value sorted alpha */ function get_allavailablecustomcategories(){ $sql = "select propertytabcategoryid as id, propertytabcategorydisplayname as value from tblpropertytabcategory where propertycategoryid = 0 and propertytabid=0 and clientcompanyid = '".clientcompanyid()."' order by propertytabcategorydisplayname"; $availcustomcategories = db_query($sql); return $availcustomcategories; } /** * tabget_available_extensions($category,$includeorphans,$clientcompanyid) * @param intger $includeorphans tells it to include all extensions created by this company that may be orphaned * @param string $category as category short name * @param integer $clientcompanyid nedded if in genesis * @param string $currenttab * @param integer $changeorder needed to order extensions so it is easier to find them in dropdown box. * @return array $outarray */ function tabget_available_extensions($category=0,$includeorphans=0,$clientcompanyid=0,$currenttab='', $changeorder=0) { if (!$clientcompanyid) $clientcompanyid = clientcompanyid(); if ($includeorphans) { $outarray = gettab_addexistingextensions($currenttab); foreach ($outarray as $outkey=>$outval){ $excludelist[$outval[id]] ="'".db_number($outval[id])."'"; } foreach (gettab_extensions($currenttab) as $okey=>$oval){ $excludelist[$oval[propertyextensionid]] ="'".db_number($oval[propertyextensionid])."'"; } $excludelist = implode(",",$excludelist); } if ($clientcompanyid) { $sql = "select *,coalesce (a.propertyextensionid,b.propertyextensionid) as propertyextensionid from tblpropertyextension a left join tblclientcompanypropertyextension b on (a.propertyextensionid = b.propertyextensionid and clientcompanyid = '".db_number($clientcompanyid)."') where (propertyextensionclientuse = 1 or (propertyextensionclientuse ='2' and clientcompanyid = '".db_number($clientcompanyid)."')) and propertycategoryid > 0"; if ($excludelist) $sql .=" and a.propertyextensionid not in (".$excludelist.")"; if($changeorder) $sql .= ' order by propertycategoryid, case when clientcompanypropertyextensionrank is null then 1000 else clientcompanypropertyextensionrank end, propertyextensionrank'; else $sql.=" order by propertycategoryid "; }else{ $sql = " select * from tblpropertyextension a join tblpropertycategory using(propertycategoryid) join tblcustomfieldtype using (customfieldtypeid) where propertyextensionclientuse < 2 and propertycategoryid > 0"; if ($excludelist) $sql .=" and a.propertyextensionid not in (".$excludelist.")"; $sql.=" order by propertycategoryrank,propertyextensionrank"; } $extensions = db_query($sql); $i=0; foreach ($extensions as $ekey=>$extension){ $includecategories[$extension[propertycategoryid]] ="'".$extension[propertycategoryid]."'"; } $includecategories = implode(",",$includecategories); $sql = "select * from tblpropertycategory where 0=0 "; if (clientcompanyid()) $sql .=" and propertycategoryclientinvisible='0' "; if ($category) $sql .= " and propertycategoryname = '".$category."' "; else if ($includecategories) $sql .= " and propertycategoryid in (".$includecategories.")"; if($changeorder) $sql .= ' order by propertycategoryname'; else $sql .= ' order by propertycategoryrank'; $categories = db_query($sql); if($outarray) { $key = end($outarray); $i = key($key); $i++; } else $i=0; $outarray[$i][id] = " "; $outarray[$i][value] = " -- Property Details Extensions --"; $outarray[$i][label] = 1; $i++; unset ($j); if (trim($currenttab)!= 'property') { foreach ($categories as $cat=>$category) { $outarray[$i][id] = " "; $outarray[$i][value] = $category[propertycategorydisplayname]; $outarray[$i][label] = 1; $i++; $j=$i; foreach ($extensions as $ext=>$extension) { if ($extension[propertycategoryid] == $category[propertycategoryid]) { $outarray[$i][id] = $extension[propertyextensionid]; $outarray[$i][value] = $extension[propertyextensionlabel]; $i++; } } if ($i == $j) $i--; } } return $outarray; } /** * tab_addcategory ($tab,$category) function * @param string $tab tab short name * @param string $category category short name or new category name * @return true if category is been added and set_message (with error,ok, warning) status */ function tab_addcategory ($tab,$category) { $tabshortname = $tab; $categoryname = $category; if (get_plain_name($tabshortname) != $tabshortname) set_message ("Developer error: Invalid tab short name",error); if (get_plain_name($categoryname) != $categoryname) $newcategory=1; if (!has_message()) // no errors at this point lets do lookup in database { $tabqry = db_first("select * from tblpropertytab where propertytabshortname ='".$tabshortname."'"); $categoryqry = db_first ("select * from tblpropertycategory where categoryname ='".get_plain_name($categoryname)."'"); // now check are we trying to duplicate category on this tab. This should not be possible, however.... $chkqry = db_first("select * from tblpropertytabcategory where propertytabid = '".$tabqry[propertytabid]."' and clientcompanyid = '".db_number(clientcompanyid())."'"); if ($chkqry) { set_message ("Category already exists on this tab. You cannot duplicate categories on same tab!", error); return FALSE; } elseif ($categoryqry && $tabqry) { $sql = "insert into tblpropertytabcategory (propertycategoryid ,companyid ,clientcompanyid ,propertytabid ,propertytabcategoryrank ) values ( '".db_number ($categoryqry[propertycategoryid])."' ,'".db_number (companyid())."' ,'".db_number (clientcompanyid())."' ,'".db_number ($tabqry[propertytabid])."' ,'99' )"; db_exec($sql); set_message("Category added successfully.",ok); return TRUE; } elseif (($tabqry && !$categoryqry) || $newcategory) // we are adding new category. { $categoryshortname = get_plain_name($categoryname); $categorydisplayname = db_col($categoryname); $sql = "insert into tblpropertytabcategory (propertytabid ,propertytabcategoryrank ,propertytabcategoryname ,propertytabcategorydisplayname ,propertycategoryid ,companyid ,clientcompanyid ) values ( '".db_number($tabqry[propertytabid])."' ,'99' ,'".db_col($categoryshortname)."' ,'".db_col($categorydisplayname)."' ,'0' ,'0' ,'".db_number(clientcompanyid())."')"; db_exec ($sql); set_message ("New Category Successfully Added.",ok); return TRUE; } set_message ("Developer Error: ft_code: ".__LINE__."!",error); return FALSE; } return FALSE; } /** * function display_edit_property_tab ($tab,$propertyid,$edit,$companyid) * @param string $tab tab shortname * @param integer $propertyid Propertyid * @param integer $edit If set then in edit mode * @param integer $companyid companyid or 1 * @return bool False if bad data was passed in */ function display_edit_property_tab ($tab,$propertyid,$edit=0,$companyid=0) { GLOBAL $customfield_viewonly; global $sisterassign; if (!$companyid) { if (!is_activetab($tab,$propertyid)){ return FALSE; } if (!$tab || !$propertyid) return FALSE; // EXIT if (!clientcompanyid()) $company = 1; if (client_portal() || $sisterassign) $categories = gettab_categories($tab,0,$propertyid); else $categories = gettab_categories($tab); $tabextensions = gettab_extensions ($tab,$propertyid); if ((client_portal() || $sisterassign )&& $propertyid) { $clientcompanyid = get_clientcompanyidfromclientproperty($propertyid); }else $clientcompanyid = clientcompanyid(); // GET CLIENTCOMPANY PROPERTY $sql = "select * ,(select imageid from tblimage where clientcompanypropertyid = tblclientcompanyproperty.clientcompanypropertyid and imagedefault=1 limit 1) as imageid from tblclientcompanyproperty join tblclientcompany using(clientcompanyid) left join tblportfolio using (portfolioid, clientcompanyid) left join tblclientcompanyclient using (clientcompanyclientid, clientcompanyid) where 0 = 0"; if(clientcompanyid() && !$sisterassign) { $sql .= " and tblclientcompanyproperty.clientcompanyid = " . clientcompanyid(); $rolepropertyrestriction_staffidlist = get_rolepropertyrestriction_stafflist(clientstaffid()); if($rolepropertyrestriction_staffidlist) $sql.=" and exists (select 1 from tblclientcompanypropertyrole where clientcompanypropertyid = tblclientcompanyproperty.clientcompanypropertyid and clientstaffid in($rolepropertyrestriction_staffidlist))"; } if(companyid()) { $sql .= " and exists (select 1 from tblclientcompanypropertyassignment join tbllogin using (staffid) where tblclientcompanyproperty.clientcompanypropertyid = tblclientcompanypropertyassignment.clientcompanypropertyid and tbllogin.companyid = " . companyid() . " and clientcompanypropertyassignmentdenieddate is null and clientcompanypropertyassignmentexpired is null and staffid != 0 "; $sql.=")"; } $sql .= " and clientcompanypropertyid = " . db_number($propertyid); $property = db_query($sql); // GET ALL CLIENT COMPANY PROPERTY EXTENSIONS AVAILABLE $sql = "select * from tblpropertyextensionentry where clientcompanypropertyid = " . $propertyid; $pextensions = db_query($sql,'','','propertyextensionkey'); $property = $property[0]; $property[extension] = $pextensions; foreach($pextensions as $key=>$keyarr) $pextension_bykey[$key] = $keyarr[propertyextensionentryvalue]; if(!has_access('addeditproperty') || $sisterassign) unset($edit); if(!$edit) unset ($_POST[tabsave]); if ($_POST[tabsave]) { foreach(db_query("select * from tblpropertyextension e join tblcustomfieldtype using(customfieldtypeid) ") as $k=>$row) { $fn = "process_customfield_{$row[customfieldtypelayout]}"; $fn2 = "process_customfield_display_{$row[customfieldtypename]}"; if(function_exists($fn) ) $custom_processing[$row[propertyextensionkey]] =$row[customfieldtypelayout]; elseif(function_exists($fn2)) $custom_processing[$row[propertyextensionkey]] = "display_".$row[customfieldtypename]; else continue; $custom_extensions_array[$row[propertyextensionkey]] = $row; } // UPDATE EXTENSIONS foreach($_POST as $key => $data) { if(strstr($key,'propertyextension')|| $key=='hoaid' || $key=='hoa2id' || $key=='hoa3id'){ if (is_array($data)) { foreach($data as $k=>$ind) //remove all blanks submitted if(!$ind) unset($data[$k]); $data = implode(',',$data); //and create a comma delimited list of the ones submitted } $ekey = list_first($key,"_"); // get the name of the field, without underscores, since these indicate that the field is on multiple rows if($custom_processing[$ekey]) { $fn = "process_customfield_{$custom_processing[$ekey]}"; if(!function_exists($fn)) ddie("CONFIGURATION ISSUE: missing function $fn($data) before saving property_viewedit.php:".__LINE__); $data = $fn($propertyid, $key, $data, $custom_extensions_array[$key]); } if($data !== false) // if this is false the custom processing must have told us NOT to update clientcompanyproperty_set_propertyextension($property[clientcompanypropertyid], $key, $data); } } if($_POST[propertyrole]) { foreach($_POST[propertyrole] as $roleid => $clientstaffid) { update_clientcompanypropertyrole($propertyid,$roleid,$clientstaffid); } } set_message('Property successfully saved.','ok-messages'); message_redirect('','/clientproperty.php?view=' . $_POST['clientcompanypropertyid'] . '&page='.$_POST[tab].'&action=view'); } if(!clientcompanyid() || $sisterassign) { if($property[clientcompanyid] ) { $sql =" select distinct propertyextensionid from tblpropertyextensionvisableassignmentmethodentry join tblclientcompanypropertyassignment using(assignmentmethodid) where clientcompanyid = ".db_number($property[clientcompanyid])." and clientcompanypropertyid = ".db_number($property[clientcompanypropertyid])." and clientcompanypropertyassignmentexpired is null and clientcompanypropertyassignmentrevokeddate is null and clientcompanypropertyassignmentaccepteddate is not null "; if(companyid()) $sql.=" and staffid in (select staffid from tbllogin where companyid = ".companyid().") and staffid <>0"; elseif(accountstaffid()) $sql.=" and accountstaffid = ".accountstaffid(); elseif(externaluserid()) $sql.=" and externaluserid = ".externaluserid(); $qryrestrict = db_query($sql,1,0,propertyextensionid); } if(is_array($qryrestrict)) $restrictarr = array_keys($qryrestrict); if(!is_array($restrictarr)) $restrictarr=array(); if($tabextensions) foreach($tabextensions as $ky=>$textension) { if(!in_array($textension[propertyextensionid],$restrictarr) && !$textension[tabcategorypropertyextensionvisibletocompany]) unset($tabextensions[$ky]); } } ?> if (empty($categories)){ if(client_portal() && !accountid()) { set_message('Information not available: Please contact your client','notice'); display_messages(); } if(accountid()) { set_message('Information not available: Please contact your client if this information is needed.','notice'); display_messages(); } else ;//include('inc_clientpropertycomingsoon.php'); //Removed at client request. May put back in in the future. Mac return; } if (is_array($categories)) { $split = round (count ($categories) /2); $rowcnt = 0; ?>