$(document).ready(function (){ //grab all header rows $('#property_results_table thead th').each(function(column) { $(this).addClass('sortable') $(this).click(function() { //console.log('started sort'); $('#property_results_table').hide() var findSortKey = function(var_cell) { return var_cell.find('.sort-key').text().toUpperCase() + ' ' + var_cell.text().toUpperCase(); }; // Reverse the sort order var sortDirection =$(this).find('span').attr('data-sortorder') == 1 ? -1 : 1; //get the rows with data for sorting var var_rows = $('#property_results_table tbody tr').get(); //loop through all the rows and find $.each(var_rows, function(index, row) { row.sortKey = findSortKey($(row).children('td').eq(column)); }); var colheader = $('#property_results_table thead').find('th').eq(column).find('div.header_row_liner').text().trim(); //Sort an address 'naturally', i.e. 100 Main St < 200 Main St < 1000 Main St. function naturalSorter(as, bs){ var a, b, a1, b1, i= 0, n, L, rx=/(\.\d+)|(\d+(\.\d+)?)|([^\d.]+)|(\.\D+)|(\.$)/g; if(as=== bs) return 0; a= as.toLowerCase().match(rx); b= bs.toLowerCase().match(rx); L= a.length; while(ib1? 1:-1; } } return b[i]? -1:0; } //compare and sort the rows alphabetically var_rows.sort(function(a, b) { console.log('a.sortKey:' + a.sortKey + ' / b.sortKey:' + b.sortKey); a.sortKey = a.sortKey.trim(); b.sortKey = b.sortKey.trim(); //Sort mm/dd/yyyy columns. if(colheader == 'Contract Close of Escrow Date' || colheader == 'Estimated COE Date') { if (a.sortKey.trim() === '' || a.sortKey === null || typeof a.sortKey === 'undefined') { return 1;//Always drop to bottom; } if (b.sortKey.trim() == '' || b.sortKey === null || typeof b.sortKey === 'undefined') { return -1;//Always drop to bottom; } var aSortKey = trim(a.sortKey); var aDD = aSortKey.substring(3, 5); var aMM = aSortKey.substring(0, 2); var aYYYY = aSortKey.substring(6); aSortKey = aYYYY.concat(aMM).concat(aDD); var bSortKey = trim(b.sortKey); var bDD = bSortKey.substring(3, 5); var bMM = bSortKey.substring(0, 2); var bYYYY = bSortKey.substring(6); bSortKey = bYYYY.concat(bMM).concat(bDD); if(sortDirection == '1') { return aSortKey - bSortKey; } else { return bSortKey - aSortKey; } } //Sort columns of format $###,###,###.##. if(colheader == 'Current List Price') { var aSortKey = trim(a.sortKey); aSortKey = aSortKey.substring(1, aSortKey.length); aSortKey = aSortKey.replace(new RegExp(',', 'g'), ''); var bSortKey = trim(b.sortKey); bSortKey = bSortKey.substring(1, bSortKey.length); bSortKey = bSortKey.replace(new RegExp(',', 'g'), ''); if(sortDirection == '1') { return aSortKey - bSortKey; } else { return bSortKey - aSortKey; } } //Handle 'empty' cases; always drop 'empty' cases to bottom; if (a.sortKey.trim() === '' || a.sortKey === null || typeof a.sortKey === 'undefined') { return 1; } if (b.sortKey.trim() == '' || b.sortKey === null || typeof b.sortKey === 'undefined') { return -1; } if (a.sortKey < b.sortKey) { return -sortDirection; } else if (a.sortKey > b.sortKey) { return sortDirection; } else return 0; }); //add the rows in the correct order to the bottom of the table table_body = $('#property_results_table tbody'); $.each(var_rows, function(index, row) { table_body.append(row); row.sortKey = null; }); //identify the column sort order $('#property_results_table th span').addClass('hidden').removeClass('active'); var var_sortHead = $('#property_results_table th').filter(':nth-child(' + (column + 1) + ')').find('span'); var_sortHead.removeClass('hidden').addClass('active'); if (sortDirection == 1) { var_sortHead.attr('data-sortorder', 1) var_sortHead.removeClass('ui-icon-triangle-1-n').addClass('ui-icon-triangle-1-s'); } else { var_sortHead.attr('data-sortorder', -1); var_sortHead.removeClass('ui-icon-triangle-1-s').addClass('ui-icon-triangle-1-n'); } //identify the column to be sorted by table_body.removeClass('sorted') .filter(':nth-child(' + (column + 1) + ')') .addClass('sorted'); var var_rows_selector = $('#property_results_table tbody tr'); var_rows_selector.removeClass('bgmint'); var_rows_selector.filter(':even').addClass('bgmint'); $('#property_results_table').show(); }); }); // Find the active column and do initial sort $('#property_results_table th').find('.active').parent().trigger('click'); } ) "; echo ""; } function myviews_display_masterheader_return() { ob_start(); $master_header_nondisplay = myviews_display_masterheader(); $null = ob_get_clean(); unset($null); return $master_header_nondisplay; } function myviews_display_masterheader() { if (is_developer() && $_GET[killmyviews]) { unset($_SESSION['myviews']); echo " click to reload last page "; ddie("Developer, you made this die on purpose. Cookie Monster says: don't forget to eat cookie! "); } // Master Header will hold all the columns from different sources with the same parameters $master_header = array(); global $display_assignmentmethod; global $searcharray; global $csv_export; global $csv_row_cnt; global $prop_roles; // Add the static information $master_header[] = array("type" => "static", "key" => "static_view", "label" => "View", "class" => "skip", "sortable" => 0, "addcsv" => 0, "centered" => 1); if (clientcompanyid() ) ''; if (!clientcompanyid() && !client_portal() && !companyid() && !staffid()) //Added restriction to prevent master users from seeing column since it just shows their own company name for each property. $master_header[] = array("type" => "static", "key" => "static_company", "label" => "Company", "class" => "", "sortable" => 0, "addcsv" => 1, "centered" => 0); if (vendorid()) $master_header[] = array("type" => "static", "key" => "static_reason", "label" => "Display Reason", "class" => "", "sortable" => 0, "addcsv" => 1, "centered" => 0); $master_header[] = array("type" => "static", "key" => "static_quicklinks", "label" => "Quick Links", "class" => "skip", "sortable" => 0, "addcsv" => 0, "centered" => 1); if($_SESSION['myviews']['displaycolumns'] ) foreach ($_SESSION['myviews']['displaycolumns'] as $k=>$column) { if ($column[myviewscolumntype] == "special" && $column[myviewscolumnkey] == "propertyphoto") $master_header[] = array("type" => $column[myviewscolumntype], "key" => $column[myviewscolumnkey], "label" => "", "class" => "hideable_column ", "sortable" => 0, "addcsv" => 0, "centered" => 1); } if(companyid() && !client_portal() && $showacquisitionsagentside) { if(is_mlsagentincompany()) { $master_header[] = array("type" => "static", "key" => "static_acquisitionnotes", "label" => "Acquisition Notifications", "class" => "skip", "sortable" => 0, "addcsv" => 0, "centered" => 1); $companymlsagent=true; } $directofferdetailslabel='Acquisition Details'; if($_GET[legendselect]=='propertyinescrow') $directofferdetailslabel='Escrow Details'; if($_GET[legendselect]=='propertyclosed') $directofferdetailslabel='Closing Details'; $master_header[] = array("type" => "static", "key" => "static_directofferdetails", "label" => "$directofferdetailslabel", "class" => "skip", "sortable" => 0, "addcsv" => 0, "centered" => 1); if($companymlsagent) $master_header[] = array("type" => "static", "key" => "static_acquisitionofferdate", "label" => "Offer Date", "class" => "skip", "sortable" => 0, "addcsv" => 0, "centered" => 1); } // Go through the myview displaycolumns if($_SESSION['myviews']['displaycolumns'] ) $agentgoups = db_query("select groupname , lower(groupname) as shortname from tblgroup where 0=0 and group_companyid in (0,-1, ".companyid().") ",1,0,shortname); if (is_array($_SESSION['myviews']['displaycolumns'])) foreach ($_SESSION['myviews']['displaycolumns'] as $k=>$column) { if ($column[myviewscolumntype] == "propertyfield") $master_header[] = array("type" => $column[myviewscolumntype], "key" => $column[myviewscolumnkey], "label" => $_SESSION[myviews][columnslabels][$column[myviewscolumnkey]][label], "class" => "hideable_column ", "sortable" => 1, "addcsv" => 1, "centered" => 0); elseif ($column[myviewscolumntype] == "propertyextension") $master_header[] = array("type" => $column[myviewscolumntype], "key" => $column[myviewscolumnkey], "label" => $_SESSION[myviews][columnslabels][$column[myviewscolumnkey]][label], "class" => "hideable_column ", "sortable" => 1, "addcsv" => 1, "centered" => 0); elseif ($column[myviewscolumntype] == "special" && $column[myviewscolumnkey] == "searchedcolumns") { if (is_array($searcharray[searchfield]) && !empty($searcharray[searchfield])) foreach ($searcharray[searchfield] as $search_key => $searchvalue) { // Skip if they didn't type a search value if ($searchvalue == "") continue; $master_header[] = array("type" => $column[myviewscolumntype], "key" => "searchedcolumns_".$search_key, "label" => $_SESSION[myviews][columnslabels][$search_key][label], "class" => "", "sortable" => 1, "addcsv" => 1, "centered" => 0); } } elseif ($column[myviewscolumntype] == "agentgroup" && companyid() && !client_portal() ) { if ($agentgoups[$column[myviewscolumnkey]]){ $master_header[] = array("type" => $column[myviewscolumntype], "key" => "searchedcolumns_".$search_key, "label" => $agentgoups[$column[myviewscolumnkey]][groupname], "class" => "", "sortable" => 1, "addcsv" => 1, "centered" => 0); } } elseif ($column[myviewscolumntype] == "special" && $column[myviewscolumnkey] == "propertyphoto") ; //Handled in loop above to put photo next to quicklinks. elseif ($column[myviewscolumntype] == "special" && $column[myviewscolumnkey] == "listingagentphone" && is_mlsagent()) $master_header[] = array("type" => $column[myviewscolumntype], "key" => $column[myviewscolumnkey], "label" => "Acq MLS Listing Agent", "class" => "", "sortable" => 1, "addcsv" => 1, "centered" => 0); elseif ($column[myviewscolumntype] == "special" && $column[myviewscolumnkey] == "assignto") $master_header[] = array("type" => $column[myviewscolumntype], "key" => $column[myviewscolumnkey], "label" => "Assigned To", "class" => "hideable_column ", "sortable" => 1, "addcsv" => 1, "centered" => 0); elseif ($column[myviewscolumntype] == "special" && $column[myviewscolumnkey] == "offers") $master_header[] = array("type" => $column[myviewscolumntype], "key" => $column[myviewscolumnkey], "label" => "Offers", "class" => "hideable_column ", "sortable" => 1, "addcsv" => 1, "centered" => 0); elseif ($column[myviewscolumntype] == "special" && $column[myviewscolumnkey] == "tasks") $master_header[] = array("type" => $column[myviewscolumntype], "key" => $column[myviewscolumnkey], "label" => "Tasks", "class" => "hideable_column ", "sortable" => 1, "addcsv" => 1, "centered" => 0); else $master_header[] = array("type" => $column[myviewscolumntype], "key" => $column[myviewscolumnkey], "label" => $_SESSION[myviews][columnslabels][$column[myviewscolumnkey]][label], "class" => "hideable_column ", "sortable" => 1, "addcsv" => 1, "centered" => 0); } if (clientcompanyid() ) { // Add the static columns on the end if($display_assignmentmethod) $master_header[] = array("type" => "static", "key" => "static_assignmentmethod", "label" => $display_assignmentmethod[assignmentmethodname], "class" => "", "sortable" => 1, "addcsv" => 1, "centered" => 0); // -- These are set in my views change columns now } // Display the header echo ""; foreach ($master_header as $k=>$head) { if($head['key']=='clientcompanyclientid') //Removing Client column at client request in task 22686 Mac { unset($master_header[$k]); continue; } echo "
"; echo $head[label]; if ($head[sortable]) echo sort_header_jquery_sort_return($head[key]); elseif ($head['class'] != "skip") echo close_only_header($head[key]); echo "
"; } echo ""; // Write to the csv $isfirst = 1; foreach ($master_header as $k=>$head) { if (!$head[addcsv]) continue; if ($isfirst == 1) { $isfirst = 0; $csv_export[$csv_row_cnt] = '"'.$head[label].'"'; } else $csv_export[$csv_row_cnt] .= ',"'.$head[label].'"'; } return $master_header; } function myviews_display_properties($master_header, $properties) { // Note: You'll need to deal with the way you retrieve the value depending on which side is using it // Client side formats the $properties using: // $property[] = fields are in root array // $property[extensions] = Property Extentions are in sub array // // Broker side $properties has // $property[] = fields are in root array // $property[extensions] = Property Extentions are in sub array // global $csv_export; global $display_assignmentmethod; global $csv_row_cnt; $property_page_hoa = array(); $property_page_offices = array(); if (companyid() && !client_portal()){ foreach ($properties as $key=>$val) $prop[$val[propertyid]]=$val[propertyid]; if (count($prop)){ $tofferstatus = db_query("select propertyid , (case when (select offercounterid from tbloffercounter where offerid = (select offerid from tbloffer where propertyid = tblproperty.propertyid and (tbloffer.offerstatus ilike 'New' or tbloffer.offerstatus is null or tbloffer.offerstatus='') limit 1) order by offercounterid desc limit 1) >0 then 'In Negotiation' else (select (case when offerid>0 then (case when (tbloffer.offerstatus ilike 'New' or tbloffer.offerstatus is null or tbloffer.offerstatus='') then 'New' else tbloffer.offerstatus end) else '' end) as offerstatus from tbloffer where tblproperty.propertyid = propertyid order by offerid desc limit 1) end) as offerstatus from tblproperty where propertyid in (" . implode ("," , $prop) . ") order by propertyid asc",1,0,propertyid); foreach ($tofferstatus as $propid => $data){ if ($data[offerstatus]) $offerstatus[$propid]=$data[offerstatus]; } unset($tofferstatus); $tallagentsinproperties = db_query("select (select stafffname || ' ' ||stafflname from tblstaff where staffid=tblpropertygroupstaff.staffid) as name , groupname as group ,propertyid from tblpropertygroupstaff join ( select lower(groupname) as groupname , groupid from tblgroup where 0=0 and group_companyid in (0,-1, ".companyid().") ) as tblgroup using (groupid) where propertyid in (" . implode (",",$prop) . ") and staffid >0 and groupid <>7"); unset ($prop); foreach ($tallagentsinproperties as $key=>$data){ $out[$data[propertyid]][$data[group]]=$data[name]; } } unset ($tallagentsinproperties); foreach ($properties as $key=>$property){ if ($out[$property[pid]]){ if (is_array($out[$key])) $properties[$key]=array_merge($properties[$key],$out[$key]); } } unset($out); } // To reduce sql hits get HOA and Office Locations here $display_hoa = 0; $display_offices = 0; foreach($master_header as $k=>$head) { if ($head[key] == hoaid || $head[key] == hoa2id || $head[key] == hoa3id) $display_hoa = 1; if ($head[key] == officelocationid) $display_offices = 1; if ($head[key] == utility_list) $display_utilities = 1; } if (!empty($properties)) { foreach ($properties as $k=>$prop) { if ($prop[propertytransactiontype]) $properties[$k][propertytransactiontype] = ucwords($prop[propertytransactiontype]); if (db_number($prop[hoaid]) > 0) $hoaid_arr[] = $prop[hoaid]; if (db_number($prop[hoa2id]) > 0) $hoaid_arr[] = $prop[hoa2id]; if (db_number($prop[hoa3id]) > 0) $hoaid_arr[] = $prop[hoa3id]; if (db_number($prop[extension][hoaid][propertyextensionentryvalue]) > 0) $hoaid_arr[] = $prop[extension][hoaid][propertyextensionentryvalue]; if (db_number($prop[extension][hoa2id][propertyextensionentryvalue]) > 0) $hoaid_arr[] = $prop[extension][hoaid][propertyextensionentryvalue]; if (db_number($prop[extension][hoa3id][propertyextensionentryvalue]) > 0) $hoaid_arr[] = $prop[extension][hoaid][propertyextensionentryvalue]; if (db_number($prop[officelocationid]) > 0) $officeid_arr[] = $prop[officelocationid]; } if ($display_hoa && !empty($hoaid_arr)) { $hoaid_arr = array_unique($hoaid_arr); $property_page_hoa = hoa_get_hoaname_array($hoaid_arr); } if ($display_offices && !empty($officeid_arr)) { $officeid_arr = array_unique($officeid_arr); $sql = "select * from tblofficelocation where officelocationid in ( ". implode(',', $officeid_arr) ." ) "; if(companyid()) $sql.=" and companyid = ".companyid(); elseif(accountid()) $sql.=" and accountid = ".accountid(); $sql.=" order by officelocationid "; $property_page_offices = db_query($sql,1,0,officelocationid); } } // Get the list of extensions that have customfield display function if (clientcompanyid() || client_portal() ) { $sql = "select propertyextensionkey as key, customfieldtypelayout, customfieldtypeattr1label from tblclientcompanypropertyextension join tblpropertyextension using (propertyextensionid) join tblcustomfieldtype using(customfieldtypeid) where customfieldtypelayout != '' union select myviewscolumnlabelfield as key, myviewscolumnlabellayout as customfieldtypelayout, myviewscolumnlabelattr1label as customfieldtypeattr1label from tblmyviewscolumnlabel where myviewscolumnlabellayout != '' "; } else { if(is_mlsagentincompany()) $companymlsagent=true; $sql = "select propertyextensionkey as key, customfieldtypelayout, customfieldtypeattr1label from tblpropertyextension join tblcustomfieldtype using(customfieldtypeid) where customfieldtypelayout != '' union select myviewscolumnlabelfield as key, myviewscolumnlabellayout as customfieldtypelayout, myviewscolumnlabelattr1label as customfieldtypeattr1label from tblmyviewscolumnlabel where myviewscolumnlabellayout != ''"; } $customfieldlayout = db_query($sql,1,0, key); $customfieldtypeinfo=get_customfieldtypeinfo(); global $customfield_viewonly_nextonly; // We need to determine if the client company allowed the agent to view their property extension if ( client_portal()) $current_available_columns = myviews_get_availablecolumns(); $myviews_propertyids_array = array(); $myviews_propertyids_csv = ""; if(is_array($properties) && !empty($properties)) foreach($properties as $key => $property) $myviews_propertyids_array[$property[clientcompanypropertyid]] = db_number($property[clientcompanypropertyid]); $myviews_propertyids_csv = implode (",",$myviews_propertyids_array); echo ""; if(is_array($properties) && !empty($properties)) { // Optimizations.... so we dont run same queries over and over.... unset($tmppids); foreach ($properties as $key=>$property) $tmppids [$property[clientcompanyid]] = $property[clientcompanyid]; $tmppids = array_filter( $tmppids, 'strlen' ); // remove empty $conf = "'clientpropertysubstatus','clientpropertystatus'"; $sql = "select clientcompanyid, configextensionshortname, configextensionentryvalue from tblconfigextension join tblconfigextensionentry using (configextensionid) where configextensionshortname in (".$conf.")"; $tst = implode(",",$tmppids); if (!empty($tst)) $sql .= "and clientcompanyid in (".implode(",",$tmppids).")"; $tmp = db_query($sql); foreach ($tmp as $key=>$val) $optconfext[$val[clientcompanyid]][$val[configextensionshortname]] = $val[configextensionentryvalue]; } if (is_array($properties)) foreach ($properties as $propid=>$propdata) { if ($propdata[imageid]) $propimages[$propdata[imageid]]=$propdata[imageid]; if($propdata[propertyinescrow] || $propdata[propertyclosed]) $inescroworclosed[$propdata[propertyid]]=0; if($propdata[clientid]) $clientidarr[$propdata[clientid]]=$propdata[clientid]; } if (array_search('propertyphoto', array_column($master_header, 'key',''))>0) { if (!empty($propimages)) { $pimg = array_column(db_query("select imageid, imagefilename from tblimage where imageid in (" . implode ("," , $propimages) .")"),"imagefilename","imageid"); foreach($pimg as $id=>$fname) { if (!$id) continue; $folder = "/photos" . getrelativephotodir($id); $rel = $_SERVER['DOCUMENT_ROOT'] . $folder; if (file_exists($rel . "tn" . "supertiny" . "_tn_" . $fname) ) $propimages[$id] = $folder . "tn" . "supertiny" . "_tn_" . $fname; else $propimages[$id] = get_photo_thumbnail_url($id,"supertiny"); } unset ($pimg,$folder,$rel); } } else $propimages = array(); if($inescroworclosed) { $inescroworclosedlist=db_number_list(implode(',',array_keys($inescroworclosed))); $sql="select propertyid , offerid , clientcompanyname from tblavailablepropertyentry join tbloffer using(offerid, propertyid) join tblclientcompany using(clientcompanyid) where propertyid in ($inescroworclosedlist) and lower(offerstatus)='accepted' and offervoiddate is null "; $acceptedofferqry=db_query($sql,1,0,propertyid); } $canviewacquisitions=get_listclientcompanyids_canviewacquisitions(); if(is_array($properties) && !empty($properties) && clientcompanyid() && !client_portal()) { $propertyidlist=array_keys($properties); $propertyidlist=implode(',', $propertyidlist); $sql="select * , delegationfromclientcompanypropertyid as clientcompanypropertyid from tbldelegation d join tblclientcompany c on (d.delegationsisterclientcompanyid=c.clientcompanyid) where 0=0 and delegationfromclientcompanypropertyid in (".db_number_list($propertyidlist).") "; $delegatedqry=db_query($sql); if($delegatedqry) { foreach($delegatedqry as $delegatedinfo) $delegated[$delegatedinfo['clientcompanypropertyid']][$delegatedinfo['delegationid']]=$delegatedinfo; } $sql="select * , delegationtoclientcompanypropertyid as clientcompanypropertyid from tbldelegation where 0=0 and delegationtoclientcompanypropertyid in (".db_number_list($propertyidlist).") "; $delegatee=db_query($sql,1,0,'clientcompanypropertyid'); } if(is_array($properties) && !empty($properties) && !client_portal() && !clientcompanyid()) { $properties=properties_addescrowclosed($properties, 'propertyidnotkey'); $propertyidlist=array_keys($properties); $propertyidlist=implode(',', $propertyidlist); $message_count=message_count($propertyidlist); if(is_mlsagent()) { $sql="select propertyid ,(select propertyextensionentryvalue from tblpropertyextensionentry where tape.propertyid=propertyid and propertyextensionkey = 'propertylistingagent') as propertylistingagent , (select mlsmapvalue from tblpropertyextensionentry join tblmlsmap on(propertyextensionentryvalue=mlsmapkey) where tape.propertyid=propertyid and propertyextensionkey = 'propertyextensionofficecode' and mlsmapshortname='officephone' and staffid=".staffid().") as propertylistingagentphone from (select propertyid from tblproperty where propertyid in (".db_number_list($propertyidlist).")) tape "; $listingagentinfo=db_query($sql,1,0,propertyid); } ?> 0){ $pdatasql .= "\n,(CASE WHEN propertyextensionentryvalue::integer > 0 AND propertyextensionkey = 'propertyextensionassetmanagerid' THEN (SELECT assetmanagername from tblassetmanager where assetmanagerid = propertyextensionentryvalue::integer) ELSE '' END) as propertyextensionassetmanagerid"; $pdatasqlcriteria[] = "propertyextensionassetmanagerid"; } if (array_search('propertyextensionclosingattorneyclientid', array_column($master_header, 'key',''))>0){ $pdatasql .= "\n,(CASE WHEN propertyextensionentryvalue::integer > 0 AND propertyextensionkey = 'propertyextensionclosingattorneyclientid' THEN (SELECT (CASE WHEN (clientfname IS NOT NULL AND clientlname IS NOT NULL) THEN clientfname || ' ' || clientlname ELSE (CASE WHEN clientcompanyname IS NOT NULL THEN clientcompanyname END) END) FROM tblclient WHERE clientid = propertyextensionentryvalue::integer) ELSE '' END) as propertyextensionclosingattorneyclientid"; $pdatasqlcriteria[] = "propertyextensionclosingattorneyclientid"; } if (array_search('propertyextensionclosingattorney', array_column($master_header, 'key',''))>0){ $pdatasql .= "\n,(CASE WHEN propertyextensionentryvalue::integer > 0 AND propertyextensionkey = 'propertyextensionclosingattorney' THEN (SELECT (CASE WHEN contactcname IS NOT NULL THEN contactcname ELSE (CASE WHEN clientid > 0 THEN (SELECT clientcompanyname from tblclient where tblclient.clientid =tblcontact.clientid ) END) END) FROM tblcontact WHERE contactid = propertyextensionentryvalue::integer) ELSE '' END) as propertyextensionclosingattorney"; $pdatasqlcriteria[] = "propertyextensionclosingattorney"; } if (array_search('propertyextensiontitleofficerclientid', array_column($master_header, 'key',''))>0){ $pdatasql .= "\n,(CASE WHEN propertyextensionentryvalue::integer > 0 AND propertyextensionkey = 'propertyextensiontitleofficerclientid' THEN (SELECT (CASE WHEN (clientfname IS NOT NULL AND clientlname IS NOT NULL) THEN clientfname || ' ' || clientlname ELSE (CASE WHEN clientcompanyname IS NOT NULL THEN clientcompanyname END) END) FROM tblclient WHERE clientid = propertyextensionentryvalue::integer) ELSE '' END) as propertyextensiontitleofficerclientid"; $pdatasqlcriteria[] = "propertyextensiontitleofficerclientid"; } $pdatasql .= " FROM tblpropertyextensionentry WHERE propertyid in (" . db_number_list( array_keys($properties)) . ") and propertyextensionkey = ANY (ARRAY['" . implode ("','" , $pdatasqlcriteria) . "']) ) as Q WHERE 0=0"; if (!empty($pdatasqlcriteria)){ foreach ($pdatasqlcriteria as $key) $pdatasql .="\n OR " . $key ." IS NOT NULL"; $t = db_query($pdatasql); foreach ($t as $k=>$data){ $d = $data; unset ($d['propertyid']); $propextradata[$data['propertyid']] = $d; } unset ($t,$d); } $ret_acqrevert = array(); $ret_acqrevert = app_get ('ret_acqrevert'); if(is_array($properties) && !empty($properties)) foreach($properties as $key => $property) { // Row counter for csv $csv_row_cnt ++; // Only flush if we aren't download the csv file if (!$_GET[exportcsv]) flush(); if($property[propertyisacquisition] == 1) { if($property[propertyinescrow]) $rowclass='greengrad'; elseif($property[propertyclosed]) $rowclass='graygrad'; elseif ($ret_acqrevert [$property[propertyid]] ==1 ) $rowclass='redgrad'; else $rowclass='bluegrad'; $addstyle="class='".$rowclass."'" ; if(!$showacquisitionsagentside) { $rowclass=alternate_class(bgmint,propertyrow); $addstyle=$rowclass; } } elseif($property[propertyisacquisition] == 0) { $rowclass=alternate_class(bgmint,propertyrow); $addstyle=$rowclass; } echo ""; foreach($master_header as $k_head => $head) { timetrack_stop(columnloop,$head[key]); timetrack_start(columnloop,$head[key]); $value = ""; unset($notallowedtoview); if (!accountid()){ if ($current_available_columns && $head[type] == "propertyextension" && is_array($current_available_columns) && !empty($current_available_columns)) { if (!$current_available_columns[ $head[key] ][allowedby][ $property[clientcompanyid] ]) { $notallowedtoview = 1; } } } if (!$notallowedtoview) { // Custom processing goes here if ($head[key] == "static_view") { // the research modal needs to be a max of 90% of screen width and height if (externaluserinviteid()) $value = "".button(view).""; else if (clientcompanyid()) { $value = "
".button(view).""; $value.=""; if(has_access(addeditproperty)) $value .= " ".button(edit)." "; echo ""; } else if (accountstaffid()) { // MDM Adding this section so AMC Vendors can have myviews.* $value = "".button(view).""; $value.=""; if($property['propertyid']) $value="".button(view).""; } elseif (client_portal()) { $value = "".button(view).""; $value.=""; } elseif (companyid() || vendorid()) { $verb=has_access(addeditproperty)?"Edit":"View"; if(has_access(viewproperty) || has_access(addeditproperty)) $value .= " ". button(view,$verb." Property") . " "; $value.=" "; } elseif(clientcompanyinvestor()) { $value = "".button(view,'View Property').""; $value.=""; } } elseif ($head[key] == "static_edit") { // Companyid side has the edit button in the static_view if (externaluserinviteid()) $value = "".button(edit).""; elseif (clientcompanyid()) { $value = " ".button(edit)." "; } } elseif ($head[key] == "static_quicklinks") { if(clientcompanyid() || strstr($_SERVER['REQUEST_URI'],'clientproperty') ) $propid=$property[clientcompanypropertyid]; else $propid=$property[pid]; if(!accountstaffid() || (accountstaffid() && !$property['propertyid'])) echo str_replace('REPLACEPROPERTYID', $propid, $quicklinktemplate); else echo "
(Direct Agent Assignment Property)
"; } elseif ($head[key] == "static_acquisitionnotes") { $value=""; if(($property[propertyisacquisition] == 1) && $companymlsagent) { $countmsg=$message_count[$property[propertyid]]; if($property[offers]) { $inserthidden=0; $messageonclick="javascript:sendnewmessage(this)"; if($countmsg[all]) $messageonclick="javascript:showmessages('$property[propertyid]')"; $value="
"; if ($countmsg[all]) { $inserthidden=$property[propertyid]; $value.=" ".db_number($countmsg['new'])." / $countmsg[all] "; } $value.="
"; } } } elseif ($head[key] == "static_acquisitionofferdate") { $value=""; if($property[offers] && $companymlsagent) { $max_offerid = max( array_keys( $property[offers] ) ); $newestoffer=$property[offers][$max_offerid]; if(!$newestoffer[offercounterid] && ($offer[offerstatus] == 'Rejected' || $offer[offerstatus] == 'Accepted' )) $value=dttime_format($newestoffer[offerlaststatusdate]); elseif($newestoffer[offercounterid]) $value=dttime_format($newestoffer[offercountercreateddate]); elseif(!$offer[offerstatus]) $value=dttime_format($newestoffer[offerentered]); } } elseif ($head[key] == "listingagentphone") { $value=""; if(is_mlsagent()) $value=$listingagentinfo[$property[propertyid]][propertylistingagent]."
".$listingagentinfo[$property[propertyid]][propertylistingagentphone]; } elseif ($head[key] == "static_directofferdetails") { if($acceptedofferqry[$propid][offerid]) { if($property[propertyclosed]) { $value="
".get_completeddirectofferdetailsratio('closing', $acceptedofferqry[$propid][offerid])."
"; } else if($property[propertyinescrow]) { $value="
".get_completeddirectofferdetailsratio('escrow', $acceptedofferqry[$propid][offerid])."
"; } } elseif($property[offers]) { $offeronclick="onclick=\"window.location.href='/property_viewedit.php?view=$propid&page=offers'\""; $offeraddclass="detailnoaction"; $offertext="Multiple Offers"; $offerextras= " extra_propertyid='$propid' extra_propname = '$property[propertyaddress]
$property[propertycity] $property[propertystate]' extra_listprice ='$property[propertyextensionlistprice]' extra_image='".get_photo_thumbnail_url($property["imageid"])."' "; if(count($property[offers]==1)) { $offertext="View Offer"; $offeraddclass="detailaction"; $currentpropertyofferinfo=reset($property[offers]); $offerextras.=" extra_offerid='$currentpropertyofferinfo[offerid]'"; $offeronclick="onclick=\"javascript:loadmodalfromurl_params2('_propertydirectoffer.php?',this,'$offertext','$propid', 650)\""; if($currentpropertyofferinfo[offercounterid]) { $offertext="Counter Offer"; $offerextras.=" extra_counterofferid='$currentpropertyofferinfo[offercounterid]'"; if($currentpropertyofferinfo[offerstatus]=="Counter Accepted") $offeronclick="onclick=\"window.location.href='/property_viewedit.php?view=$propid&offerid=".$currentpropertyofferinfo[offerid]."&page=offers'\""; elseif($currentpropertyofferinfo[offercounterbyagent]) $offeraddclass="detailnoaction"; } if(strtolower($currentpropertyofferinfo[offerstatus])=="rejected") $offeraddclass="detailnoaction"; } $offerextras.= " value='$offertext' "; $value=" $offertext "; } else $value=" "; } elseif ($head[key] == "propertyphoto" ) { $thumb = $propimages[$property[imageid]]; if (!$thumb) $value ="
 
"; else $value =""; } elseif ($head[type] == "special" && $head[key] == "assignto") { if(!isset($static_assignto_cache)) { if(client_portal() || clientcompanyid()) { $sql = "select clientcompanypropertyassignmentid, clientcompanypropertyid, assignname, clientcompanypropertyassignmentrevokeddate, clientcompanypropertyassignmentcompleteddate, clientcompanypropertyassignmentdenieddate, clientcompanypropertyassignmentaccepteddate, clientcompanypropertyassignmentexpired from tblclientcompanypropertyassignment join vw_assigntypes using(accountstaffid, externaluserid, staffid, assignmentaliasclientstaffid) left join (select loginid,companyid from tbllogin) as tbllg using(loginid) join tblassignmentmethod using (assignmentmethodid) where clientcompanypropertyid in ( $myviews_propertyids_csv )"; if( companyid() ) $sql .= " and companyid = ".companyid(); if( accountstaffid() ) { $sql .= " and accountstaffid in ( select accountstaffid from tblaccountstaff where officelocationid in ( select officelocationid from tblaccountstaff where accountstaffid = ".accountstaffid()." ) )"; } if( externaluserid() ) $sql .= " and externaluserid = ".externaluserid(); if(clientcompanyid() && $_SESSION[login][assignedtome]) $sql .= " and tblclientcompanypropertyassignment.assignmentaliasclientstaffid = ".clientstaffid(); $assignto = db_query($sql,1,0,clientcompanypropertyassignmentid); } $static_assignto_cache = array(); if($assignto) { foreach($assignto as $row) { $static_assignto_cache[$row[clientcompanypropertyid]][] = $row ; } } } $qry = $static_assignto_cache[$property[clientcompanypropertyid]]; if (!empty($qry)) { $assign_count = get_assignmentstatuscount_names($qry); $assignmentviewerorsetter = (companyid() || (clientcompanyid() && $_SESSION[login][assignedtome])) ? 1 : (clientcompanyid() ? 2 : 0); $value = " ".assignmentstatus_get($assign_count,$property[clientcompanypropertyid])." "; } if(accountstaffid() && $property['propertyid']) $value="".$_SESSION['login']['accountstafffname']." ".$_SESSION['login']['accountstafflname'].""; } elseif ($head[key] == "static_assignmentmethod") { $sql = "select * from tblclientcompanypropertyassignment join tblstaff using(staffid) join tbllogin using(staffid) where clientcompanypropertyid = $property[clientcompanypropertyid] and assignmentmethodid = $display_assignmentmethod[assignmentmethodid] and clientcompanypropertyassignmentrevokeddate is null and clientcompanypropertyassignmentdenieddate is null and clientcompanypropertyassignmentcompleteddate is null"; $qryag = db_query($sql); foreach($qryag as $assignment) $value .= "
".display_loginprofileimage_thumbnail($assignment[loginid])." ".get_login_info($assignment[loginid])."

"; } elseif ($head[type] == "special" && $head[key] == "offers") { if(!isset($static_offers_cache)) { $negotiations = clientnegotiation_get(); foreach($negotiations as $row) $static_offers_cache[$row[clientcompanypropertyid]][]=$row ; } $qry = $static_offers_cache[$property[clientcompanypropertyid]]; $new = 0; $negotiating = 0; $rejected = 0; $held = 0; $accepted2 = 0; if($qry) { foreach($qry as $key => $negotiation) { $status = clientnegotiation_status($negotiation); switch($status) { case 'New': $new++; break; case 'Negotiating': $negotiating++; break; case 'Rejected': $rejected++; break; case 'Held': $held++; break; case 'Accepted': $accepted2++; break; } } } // ONLY SHOW OFFERS IF THE ASSIGNMENT HAS BEEN ACCEPTED AND IT HAS OFFERS ENABLED if(clientcompanypropertyassignment_companyhaslisting($property['clientcompanypropertyid'], 1, 1)) if($new || $negotiating || $rejected || $held || $accepted2){ $value = "
" . $new . "
" . $negotiating . "
" . $rejected . "
" . $held . "
" . $accepted2 . "
"; } else $value = "No Offers"; else $value = ""; } elseif ($head[type] == "special" && $head[key] == "tasks") { if(!isset($static_tasks_cache)) { $sql = "select count(1) as cnt , clientcompanypropertyid , get_clienttask_statuskey(clienttaskduedate, clienttaskcompleteddate, clienttaskcompleteapproveddate, clienttaskrevokeddate, clienttaskholddate::date) as statuskey from tblclienttask join tblclientcompanypropertyassignment using(clientcompanypropertyassignmentid,clientcompanypropertyid) join tblclientcompanyproperty using(clientcompanypropertyid) "; if(companyid()||externaluserid()||accountstaffid()) $sql .=" join tbllogin using(staffid,externaluserid,accountstaffid) "; $sql.=" where 0=0 "; if(companyid()) $sql .= " and companyid = ".companyid(); if(accountid()) $sql .= " and companyid = ".companyid(); if(clientcompanyid()) $sql .= " and tblclientcompanyproperty.clientcompanyid = ".clientcompanyid(); if(accountid() && has_customization("corporateaccount") ) { //this corporate account gets to see all properties for all assigments for all subs $sql.=" and accountstaffid in (select accountstaffid from tblaccountstaff join tblaccount using(accountid) where 0 = 0 "; if( !account_hasparent(accountid())) $sql.=" and accountparentaccountid = ".accountid()." "; else $sql.=" and accountid = ".accountid()." "; $sql.= " ) "; } elseif(accountstaffid()) { $sql .= " and accountstaffid in ( select accountstaffid from tblaccountstaff where officelocationid in ( select officelocationid from tblaccountstaff where accountstaffid = ".accountstaffid()." ) )"; } $sql.=" and clienttaskcompleteddate is null -- all open and clientcompanypropertyid in ( $myviews_propertyids_csv ) group by clientcompanypropertyid ,get_clienttask_statuskey(clienttaskduedate, clienttaskcompleteddate, clienttaskcompleteapproveddate, clienttaskrevokeddate, clienttaskholddate::date) "; $qry = db_query($sql); if (clientcompanyid()) { $schedsql = " select count(1) as cnt , clientcompanypropertyid , 'scheduled' as statuskey from tblclienttaskschedule join tblclientcompanypropertyassignment using(clientcompanypropertyassignmentid,clientcompanypropertyid) join tblclientcompanyproperty using(clientcompanypropertyid) where 0=0 and tblclientcompanyproperty.clientcompanyid = ".clientcompanyid()." and clientcompanypropertyid in ( {$myviews_propertyids_csv} ) and clienttaskschedulerecurlastdate is null and staffid > 0 group by clientcompanypropertyid"; $schedqry = db_query($schedsql); $tasksqlqry[schedsql] = htmlpre($schedsql); $tasksqlqry[schedqry] = $schedqry; if ($schedqry) foreach ($schedqry as $scheduled) $qry[] = $scheduled; } $tasksqlqry[sql] = htmlpre($sql); $tasksqlqry[qry] = $qry; $static_tasks_cache = array(); foreach($qry as $row) { $static_tasks_cache[$row[clientcompanypropertyid]][$row[statuskey]]=$row ; } } //CACHING ALGORITHIM, if more than 10 lookups are done on the property, then a lookup of ALL properties is done and cached since the query is less than 200 MS to run on 1000+ props. $qry = $static_tasks_cache[$property[clientcompanypropertyid]]; $value = "
".get_legend(clienttask,$qry,cnt,statuskey,minilegend)."
"; } elseif ($head[key] == "clientcompanyid" || $head[key] == "clientid") { if(!isset($static_clientcompanyid_cache)) { if ($head[key]=="clientid" && !client_portal() && companyid()) { $clientidlist="0"; if(is_array($clientidarr)) $clientidlist=db_number_list(array_keys($clientidarr)); $sql = "select clientid, clientcompanyname from tblclient where clientid in ($clientidlist)"; unset($clientidarr); } else $sql = "select clientcompanyid, clientcompanyname from tblclientcompany"; $qry = db_query($sql); $static_clientcompanyid_cache = array(); foreach($qry as $row) { if ($row[clientid]) $static_clientcompanyid_cache[$row[clientid]]=$row[clientcompanyname] ; else $static_clientcompanyid_cache[$row[clientcompanyid]]=$row[clientcompanyname] ; } } //CACHING ALGORITHIM, if more than 27 lookups are done on the property, then a lookup of ALL properties is done and cached since the query is less than 200 MS to run on 1000+ props. if ($head[key]=="clientid" && companyid() && !client_portal()) $qry = $static_clientcompanyid_cache[$property[clientid]]; else $qry = $static_clientcompanyid_cache[$property[clientcompanyid]]; $value = $qry; } elseif ($head[key] == "static_company") $value = $property[companyname]; elseif ($head[key] == "static_reason") { $value = $property[vendor_display_reason]; } elseif ($head[key] == "clientcompanypropertyaddress") { $value = "$property[clientcompanypropertyaddress]"; if($property[clientcompanypropertynotebiddingboard]) $value .="NOTE PLATFORM"; if(!client_portal()) { if($delegated[$property[clientcompanypropertyid]]) { $sisterclientcompanynames = ''; $delegationpulleddate = false; $delegatedtitle = ''; $delegatedtocount = 0; foreach($delegated[$property[clientcompanypropertyid]] as $key=>$delegatedproperty) { $sisterclientcompanyname = $delegatedproperty[clientcompanyname]; if($delegatedproperty[delegationpulleddate]) { $delegatedtitle .= "Delegation removed from ".$sisterclientcompanyname."\n"; $delegationpulleddate = true; } else { $delegatedtitle .= "Delegated to ".$sisterclientcompanyname."\n"; ++$delegatedtocount; } } $delegatedtitle = substr($delegatedtitle,0,-1); if(!$delegationpulleddate) $value .=" "; elseif($delegatedtocount != 0) $value .=" "; } if($delegatee[$property['clientcompanypropertyid']]) { $delegateearr=$delegatee[$property['clientcompanypropertyid']]; $adddelegateeicon=""; if(!$delegateearr['delegationpulleddate'] && !$delegateearr['delegationcompleteddate']) { $adddelegateeicon=" "; if($delegateearr['delegationreaddate']) $adddelegateeicon=" "; } $value .=$adddelegateeicon; } } } elseif ($head[key] == "propertyaddress") { $value = "" . $property['propertyaddress'] . ""; if($companymlsagent) { if($property[propertyexternalid]) $value .= " "; elseif(($property[propertyisacquisition]==1) || ($property[propertyisrevertedacquisition]==1)) $value .= " "; } if(is_featuredagent() || has_access('canchangepropertyfeatured')) if($property[propertyfeatured_staffid]>0) $value .= " Featured Property "; if($property[clientcompanypropertyid]) $value .= genesismark(-1,$property[clientcompanypropertyid]); } elseif ($head[type] == "propertyfield" && $head[key] == "portfolioid") { if (clientcompanyid()) { // We are getting the propertyname in clientproperty.php if ($property[portfolioname]) $value = $property[portfolioname]; } } elseif ($head[type] == "propertyfield" && $head[key] == "clientcompanyclientid") { $value = $property[clientcompanyclientname]; } elseif ($head[type] == "propertyfield" && $head[key] == "clientcompanypropertylistingagent_clientid") { $value = $property[clientcompanypropertylistingagent_clientname]; if(!$value && $property[clientcompanypropertysellerlistingagent_contactname]) $value = $property[clientcompanypropertysellerlistingagent_contactname]; } elseif ($head[key] == "hoaid" || $head[key] == "hoa2id" || $head[key] == "hoa3id") { $entryvalue = ( strlen($property[extension][$head[key]][propertyextensionentryvalue]) > 0 ? $property[extension][$head[key]][propertyextensionentryvalue] : $property[$head[key]] ); if ($entryvalue > 0) $value = $property_page_hoa[$entryvalue][hoaname]; } elseif ($head[type] == "propertyfield" && $head[key] == "officelocationid") { $value = $property_page_offices[$property[$head[key]]][officelocationname]; } // These are placeholders for future customization. Anything with IDs must be processed to get the actual value elseif ($head[type] == "propertyfield" && $head[key] == "xxxx1") ; elseif ($head[type] == "propertyfield" && $head[key] == "xxxx2") ; elseif ($head[type] == "propertyextension" && $head[key] == "xxxx1") ; elseif ($head[type] == "propertyextension" && $head[key] == "xxxx2") ; elseif ($head[key] == "propertyextensionclosingattorneyclientid"){ $value = $propextradata[$property['propertyid']]['propertyextensionclosingattorneyclientid']; }elseif ($head[key] == "propertyextensionclosingattorney"){ $value = $propextradata[$property['propertyid']]['propertyextensionclosingattorney']; }elseif ($head[key] == "propertyextensionassetmanagerid"){ $value = $propextradata[$property['propertyid']]['propertyextensionassetmanagerid']; }elseif ($head[key] == "propertyextensiontitleofficerclientid"){ $value = $propextradata[$property['propertyid']]['propertyextensiontitleofficerclientid']; }elseif ($head[type] == "clientrole" && strpos($head[key], "crole_") !== false) { if(!isset($special_croles_cache)) { if (clientcompanyid() || client_portal()) { $sql = "select clientcompanypropertycroleid, clientcompanypropertyid, croleid, crolename, clientcompanyclientid, contactcname from tblclientcompanypropertycrole join tblcrole using (croleid) join tblcontact using (contactid) where clientcompanypropertyid in ( $myviews_propertyids_csv ) "; } $special_croles_cache = array(); $qry = db_query($sql); foreach($qry as $row) { $key_name = strtolower("crole_".get_plain_name($row[crolename])); $special_croles_cache[$row[clientcompanypropertyid]][$key_name] = $row ; } } $qry = $special_croles_cache[$property[clientcompanypropertyid]][$head[key]]; $value = $qry[contactcname]; } elseif ($head[type] == "special" && strpos($head[key], "role_") !== false) { if(!isset($special_roles_cache)) { if (clientcompanyid() || client_portal()) { $sql = "select clientcompanypropertyroleid, clientcompanypropertyid, roleid, clientstaffid, rolename, clientstafffname||' '||clientstafflname as name from tblclientcompanypropertyrole join tblrole using (roleid) join tblclientstaff using (clientstaffid) where clientcompanypropertyid in ( $myviews_propertyids_csv ) "; } $qry = db_query($sql); $special_roles_cache=array(); foreach($qry as $row) { $key_name = strtolower("role_".get_plain_name($row[rolename])); $special_roles_cache[$row[clientcompanypropertyid]][$key_name] = $row ; } } $qry = $special_roles_cache[$property[clientcompanypropertyid]][$head[key]]; $value = $qry[name]; } elseif ($head[type] == "special" && strpos($head[key], "searchedcolumns_") !== false) { $entrykey = str_replace("searchedcolumns_", "", $head[key]); // If the value is in extension subarray then use that or find the value in the root array $entryvalue = ($property[extension][$entrykey][propertyextensionentryvalue]?$property[extension][$entrykey][propertyextensionentryvalue]:$property[$entrykey]); if ($customfieldlayout[$head[key]]) { $func = "customfield_".$customfieldlayout[$head[key]][customfieldtypelayout]; if(function_exists($func)) // Display Contacts requires additional parameters if (strpos($func, "display_contact_name") !== false) $value = $func($entryvalue, $customfieldlayout[$head[key]][customfieldtypelayout], 1); else $value = $func($entryvalue); else $value = $entryvalue; } else $value = $entryvalue; } elseif (companyid() && !client_portal() && $head[type]=='agentgroup') { $value = $property[strtolower($head[label])]; } elseif ($head[key] == "offerstatus" && companyid() && !client_portal() ){ if ($offerstatus[$property[propertyid]]) $value = $offerstatus[$property[propertyid]]; } elseif ($head[type] == "propertyfield") { // Broker side has property fields that use customfield_display functions // If the value is in extension subarray then use that or find the value in the root array $entryvalue = ( strlen($property[extension][$head[key]][propertyextensionentryvalue]) > 0 ? $property[extension][$head[key]][propertyextensionentryvalue] : $property[$head[key]] ); if ($customfieldlayout[$head[key]]) { $func = "customfield_".$customfieldlayout[$head[key]][customfieldtypelayout]; if(function_exists($func)) // Display Contacts requires additional parameters if (strpos($func, "display_contact") !== false) $value = $func($entryvalue, $property, 1); else $value = $func($entryvalue); else $value = $entryvalue; } else $value = $entryvalue; } elseif ($head[type] == "propertyextension") { // If the value is in extension subarray then use that or find the value in the root array $entryvalue = ( strlen($property[extension][$head[key]][propertyextensionentryvalue]) > 0 ? $property[extension][$head[key]][propertyextensionentryvalue] : $property[$head[key]] ); if (!trim($entryvalue) && clientcompanyid()) { $tabledata = db_firstval("select ( case when( select propertytabcategorytype from tbltabcategorypropertyextension join tblpropertytabcategory using (propertytabcategoryid) where propertyextensionid = (select propertyextensionid from tblpropertyextension where propertyextensionkey = " . db_tick( $head[key] ) . ") and tbltabcategorypropertyextension.clientcompanyid = " . clientcompanyid() . " and propertytabcategorytype = 'table' limit 1) = 'table' then (select array (select propertyextensionentryvalue from tblpropertyextensionentry where propertyextensionkey ilike " . db_tick( $head[key] . "_%" ) . " and clientcompanypropertyid = " . db_number($property['clientcompanypropertyid']) . " )) end ) as value"); if ($tabledata) { $entryvalue = str_replace (array('{','}'),'',$tabledata); if (trim($entryvalue)) $entryvalue = "
  1. " . str_replace(",","
  2. ", $entryvalue) . "
"; } } if ($customfieldlayout[$head[key]]) { $func = "customfield_".$customfieldlayout[$head[key]][customfieldtypelayout]; if(function_exists($func)) // Display Contacts requires additional parameters if (strpos($func, "display_contact") !== false) $value = $func($entryvalue, $property, 1); else $value = $func($entryvalue); else $value = $entryvalue; } else { if($customfieldtypeinfo[$head[key]]['customfieldtypename'] && $customfieldtypeinfo[$head[key]][customfieldtypename]!='ob') { $customfield_viewonly_nextonly=1; $value = customfield_return( $customfieldtypeinfo[$head[key]]['customfieldtypename'] ,$head[key] ,$entryvalue ,$customfieldtypeinfo[$head[key]]['customfieldtypeattr1label'] ,$customfieldtypeinfo[$head[key]]['customfieldtypeattr2label'] ,$customfieldtypeinfo[$head[key]]['customfieldtypeattr3label'] ,$customfieldtypeinfo[$head[key]]['customfieldtypeattr4label'] ); } else $value = $entryvalue; } } } if ($head[key] == 'clientcompanypropertystatus2') if (!(clientcompanyid() || $optconfext[$property[clientcompanyid]][clientpropertysubstatus] == 'y')) $value = ""; if ($head[key] == 'clientcompanypropertystatus') if (!(clientcompanyid() || $optconfext[$property[clientcompanyid]][clientpropertystatus] == 'y')) $value = ""; // Display the value if($head[key] != 'static_quicklinks') { echo "$value"; } // Write to the csv if ($head[addcsv]) { $insert_comma = ""; if ($csv_export[$csv_row_cnt] != "") $insert_comma = ","; $csv_export[$csv_row_cnt] .= $insert_comma.'"'.trim(replace_multiple_spaces(strip_tags(preg_replace("/'/", "", $value)))).'"'; } } echo ""; if(is_array($properties) && !empty($properties) && !client_portal() && !clientcompanyid() && $companymlsagent) { echo "   "; } // Run only on client side if (client_portal()) echo ""; } if(is_array($properties) && !empty($properties) && !client_portal() && !clientcompanyid() && $companymlsagent) echo ""; echo ""; } function myviews_get_availablecolumns($filterbyallowedit = 0) { $array = array(); global $oversetup; // This is for over to setup defaults if ($filterbyallowedit) $sql_allowedit = " and myviewscolumnlabelallowedit = 1"; $sql = ""; if (clientcompanyid() || (is_admin() && $oversetup=='2')) { $sql = "select column_name as key, 'propertyfield' as type, 'basicinfo' as propertycategoryid, 'Basic Information' as propertycategoryname from information_schema.columns c join tblmyviewscolumnlabel mvcl on mvcl.myviewscolumnlabelfield = c.column_name where table_name = 'tblclientcompanyproperty' and myviewscolumnlabelallow = 1 and myviewscolumnlabelclientside = 1 $sql_allowedit "; } elseif (accountstaffid()) { //MDM Adding this section so AMC Vendors can have myviews.* $sql = "select column_name as key, 'propertyfield' as type, 'basicinfo' as propertycategoryid, 'Basic Information' as propertycategoryname from information_schema.columns c join tblmyviewscolumnlabel mvcl on mvcl.myviewscolumnlabelfield = c.column_name where table_name = 'tblclientcompanyproperty' and myviewscolumnlabelallow = 1 --and myviewscolumnlabelvisibletocompany = 1 --account staff $sql_allowedit "; } elseif (client_portal() || (is_admin() && $oversetup=='3')) $sql = "select column_name as key, 'propertyfield' as type, 'basicinfo' as propertycategoryid, 'Basic Information' as propertycategoryname from information_schema.columns c join tblmyviewscolumnlabel mvcl on mvcl.myviewscolumnlabelfield = c.column_name where table_name = 'tblclientcompanyproperty' and myviewscolumnlabelallow = 1 --and myviewscolumnlabelclientside = 1 and myviewscolumnlabelvisibletocompany = 1 $sql_allowedit "; elseif (companyid() || is_admin()) $sql = "select column_name as key, 'propertyfield' as type, 'basicinfo' as propertycategoryid, 'Basic Information' as propertycategoryname from information_schema.columns c join tblmyviewscolumnlabel mvcl on mvcl.myviewscolumnlabelfield = c.column_name where table_name = 'tblproperty' and myviewscolumnlabelallow = 1 and myviewscolumnlabelbrokerside = 1 $sql_allowedit "; elseif (vendorid()) $sql = "select column_name as key, 'propertyfield' as type, 'basicinfo' as propertycategoryid, 'Basic Information' as propertycategoryname from information_schema.columns c join tblmyviewscolumnlabel mvcl on mvcl.myviewscolumnlabelfield = c.column_name where table_name = 'tblproperty' and myviewscolumnlabelallow = 1 and myviewscolumnlabelvisibletovendor = 1 $sql_allowedit "; else { dlog(myviews, "sql select will not run because could not detect the user type."); return array(); } $propertyfieldarr = db_query($sql,1,0, key); $res[sql] = htmlpre($sql); //for debugging only, free to dump if needed if (is_array($propertyfieldarr) && !empty($propertyfieldarr)) $array = array_merge($array, $propertyfieldarr); if(client_portal() && !clientcompanyid() || (is_admin() && $oversetup=='3')) //MUST only restrict if they are in the client_portal - MB { $sql =" select distinct propertyextensionid from tblpropertyextensionvisableassignmentmethodentry join tblclientcompanypropertyassignment using(assignmentmethodid) join tblclientcompanyproperty using(clientcompanypropertyid, clientcompanyid) where clientcompanypropertyassignmentaccepteddate is not null"; if(!accountstaffid()) { $sql .=" and clientcompanypropertyassignmentrevokeddate is null and clientcompanypropertyassignmentexpired is null "; } if(companyid()) $sql.=" and staffid in (select staffid from tbllogin where companyid = ".companyid().") and staffid <>0"; elseif(accountstaffid()) { $sql.=" and accountstaffid in ( select accountstaffid from tblaccountstaff where officelocationid in ( select officelocationid from tblaccountstaff where accountstaffid = ".accountstaffid()." ) )"; } elseif(externaluserid()) $sql.=" and externaluserid = ".externaluserid(); $qryrestrict = db_query($sql,1,0,propertyextensionid); if(is_array($qryrestrict)) $restrictarr = array_keys($qryrestrict); } // Get the property extensions $sql = ""; if (clientcompanyid()) { $sql = " select distinct propertyextensionkey as key, propertyextensionid as extid, propertytabname || ': ' ||propertytabcategorydisplayname||': '|| propertyextensionlabel as label, 'propertyextension' as type, (case when tblpropertytabcategory.propertycategoryid = 0 then tblpropertytabcategory.propertytabcategoryid else tblpropertytabcategory.propertycategoryid end) as propertycategoryid, coalesce((select propertycategorydisplayname from tblpropertycategory where propertycategoryid = tblpropertytabcategory.propertycategoryid),propertytabcategorydisplayname) as propertycategoryname from tbltabcategorypropertyextension join tblpropertyextension e using (propertyextensionid) join tblpropertytabcategory using(propertytabcategoryid) join tblpropertytab using (propertytabid) join tblcustomfieldtype using(customfieldtypeid) -- join (select * from tblclientcompanypropertyextension where clientcompanyid in (-1," . clientcompanyid() . ") ) as tblclientcompanypropertyextension using (propertyextensionid) where 0=0 and tbltabcategorypropertyextension.clientcompanyid in (-1,".clientcompanyid().") union select distinct(propertyextensionkey) as key,propertyextensionid as extid, propertyextensionlabel as label, 'propertyextension' as type, tblpropertycategory.propertycategoryid as propertycategoryid, propertycategorydisplayname as propertycategoryname from tblclientcompanypropertyextension join tblpropertyextension using (propertyextensionid) join tblcustomfieldtype using(customfieldtypeid) join tblpropertycategory using (propertycategoryid) where tblclientcompanypropertyextension.clientcompanyid in (-1 ," . clientcompanyid() . ") and ( propertyextensionhiddenfromcolumns != 1 or propertyextensionhiddenfromcolumns is null ) order by propertycategoryname, label asc "; } elseif(accountstaffid()) { //MDM Adding this section so AMC Vendors can have myviews.* $sql = " select distinct propertyextensionkey as key , propertyextensionid as extid , propertytabname || ': ' ||propertytabcategorydisplayname||': '|| propertyextensionlabel as label , 'propertyextension' as type , (case when tblpropertytabcategory.propertycategoryid = 0 then tblpropertytabcategory.propertytabcategoryid else tblpropertytabcategory.propertycategoryid end) as propertycategoryid , coalesce((select propertycategorydisplayname from tblpropertycategory where propertycategoryid = tblpropertytabcategory.propertycategoryid),propertytabcategorydisplayname) as propertycategoryname , tabcategorypropertyextensionvisibletocompany as clientcompanypropertyextensionvisibletocompany from tbltabcategorypropertyextension join tblpropertyextension e using (propertyextensionid) join tblpropertytabcategory using(propertytabcategoryid) join tblpropertytab using (propertytabid) join tblcustomfieldtype using(customfieldtypeid) where 0=0 and tbltabcategorypropertyextension.clientcompanyid in ( select distinct clientcompanyid from tblclientcompanypropertyassignment join tblclientcompanyproperty using (clientcompanypropertyid) where accountstaffid in ( select accountstaffid from tblaccountstaff where officelocationid in ( select officelocationid from tblaccountstaff where accountstaffid = ".accountstaffid()." ) ) --and clientcompanypropertyassignmentrevokeddate is null --and clientcompanypropertyassignmentcompleteddate is null --and clientcompanypropertyassignmentexpired is null --and clientcompanypropertyassignmentdenieddate is null and clientcompanypropertyassignmentaccepteddate is not null ) union select distinct(propertyextensionkey) as key , propertyextensionid as extid , propertyextensionlabel as label , 'propertyextension' as type , tblpropertycategory.propertycategoryid as propertycategoryid, propertycategorydisplayname as propertycategoryname , clientcompanypropertyextensionvisibletocompany from tblclientcompanypropertyextension join tblpropertyextension using (propertyextensionid) join tblcustomfieldtype using(customfieldtypeid) join tblpropertycategory using (propertycategoryid) where tblclientcompanypropertyextension.clientcompanyid in ( select distinct clientcompanyid from tblclientcompanypropertyassignment join tblclientcompanyproperty using (clientcompanypropertyid) where accountstaffid in ( select accountstaffid from tblaccountstaff where officelocationid in ( select officelocationid from tblaccountstaff where accountstaffid = ".accountstaffid()." ) ) --and clientcompanypropertyassignmentrevokeddate is null --and clientcompanypropertyassignmentcompleteddate is null --and clientcompanypropertyassignmentexpired is null --and clientcompanypropertyassignmentdenieddate is null and clientcompanypropertyassignmentaccepteddate is not null ) and ( propertyextensionhiddenfromcolumns != 1 or propertyextensionhiddenfromcolumns is null ) order by propertycategoryname, label asc "; } elseif (client_portal() || (is_admin() && $oversetup=='3')) { $sql = "select propertyextensionkey as key , propertyextensionid as extid , propertyextensionlabel as label , 'propertyextension' as type , propertycategoryid, propertycategorydisplayname as propertycategoryname , clientcompanypropertyextensionvisibletocompany from tblclientcompanypropertyextension join tblpropertyextension using (propertyextensionid) join tblcustomfieldtype using(customfieldtypeid) join tblpropertycategory using (propertycategoryid) where 0=0 "; if (is_admin() && $oversetup=='3') $sql .=" \n and propertyextensionclientuse = 1"; else $sql .="\n and clientcompanyid in ( select distinct clientcompanyid from tblclientcompanypropertyassignment join tblclientcompanyproperty using (clientcompanypropertyid) where staffid = ".staffid()." and clientcompanypropertyassignmentexpired is null ) and ( propertyextensionhiddenfromcolumns != 1 or propertyextensionhiddenfromcolumns is null ) "; $sql .=" \n order by propertycategoryname, propertyextensionlabel asc"; } elseif (companyid() || is_admin()) { //tag $sql = "select propertyextensionkey as key, propertyextensionlabel as label, 'propertyextension' as type, propertycategoryid, propertycategoryname from tblpropertycategory join tblpropertyextension using (propertycategoryid) join (select propertyextensionid from tblpropertyextensionenable where propertyextensionenable_companyid in (0," . companyid() . ") group by propertyextensionid ) as tblpropertyextensionenable using (propertyextensionid) where propertyextensionclientuse < 2 and ( propertyextensionhiddenfromcolumns <> 1 or propertyextensionhiddenfromcolumns is null ) and propertyextensionhidefromcompany <1 and propertycategorycompanyinvisible =0 and propertyextensionkey ilike 'propertyextension%'"; if ($oversetup == 'companyexten') { $sql.=" and propertyextensionhidefromcompany != 1 and propertycategorycompanyinvisible != 1 "; } if (companyid()) $sql.=" and propertyextensionhidefromcompany <>1"; $sql.=" order by propertycategoryrank,propertyextensionlabel "; } elseif(vendorid()) $sql = "select propertyextensionkey as key, propertyextensionid as extid, propertyextensionlabel as label, 'propertyextension' as type, propertycategoryid, propertycategoryname from tblclientcompanypropertyextension join tblpropertyextension using (propertyextensionid) join tblcustomfieldtype using(customfieldtypeid) join tblpropertycategory using (propertycategoryid) where clientcompanyid in ( select distinct clientcompanyid from tblclientcompanypropertyassignment join tblclientcompanyproperty using (clientcompanypropertyid) where staffid = ".staffid()." and clientcompanypropertyassignmentexpired is null ) and ( propertyextensionhiddenfromcolumns != 1 or propertyextensionhiddenfromcolumns is null ) --and clientcompanypropertyextensionvisibletocompany = 1 order by propertycategoryname, propertyextensionlabel asc"; // Important list of all extensions sql. vl. $duplicatesql=$sql; $allowedbyarr = db_query($sql,1,0, key); $propertyextensionarr = $allowedbyarr; if(is_array($restrictarr) && is_array($propertyextensionarr)){ foreach($propertyextensionarr as $ky=>$peaextension) { if(!in_array($peaextension['extid'],$restrictarr) && !$peaextension['clientcompanypropertyextensionvisibletocompany']) unset($propertyextensionarr[$ky]); } } if (is_array($propertyextensionarr) && !empty($propertyextensionarr)) $array = array_merge($array,$propertyextensionarr); // Get the fields to move into different category $sql = ""; if (clientcompanyid()) { $sql = "select myviewscolumnlabelfield as key, myviewscolumnlabelname as label, 'propertyfield' as type, propertycategoryid, propertycategoryname from tblmyviewscolumnlabel lab join tblpropertycategory cat on lab.myviewscolumnlabelmovecategory = cat.propertycategoryid where myviewscolumnlabelallow = 1 and myviewscolumnlabelclientside = 1 order by propertycategoryrank,myviewscolumnlabelname "; } elseif(accountstaffid()) { //MDM Adding this section so AMC Vendors can have myviews. $sql = "select myviewscolumnlabelfield as key, myviewscolumnlabelname as label, 'propertyfield' as type, propertycategoryid, propertycategoryname from tblmyviewscolumnlabel lab join tblpropertycategory cat on lab.myviewscolumnlabelmovecategory = cat.propertycategoryid where myviewscolumnlabelallow = 1 --and myviewscolumnlabelvisibletoinviteuser = 1 order by propertycategoryrank,myviewscolumnlabelname "; } elseif (client_portal()) { $sql = "select myviewscolumnlabelfield as key, myviewscolumnlabelname as label, 'propertyfield' as type, propertycategoryid, propertycategoryname from tblmyviewscolumnlabel lab left join tblpropertycategory cat on (lab.myviewscolumnlabelmovecategory = cat.propertycategoryid) where myviewscolumnlabelallow = 1 --and myviewscolumnlabelclientside = 1 and myviewscolumnlabelvisibletocompany = 1 order by propertycategoryrank,myviewscolumnlabelname "; } elseif ((is_admin() || companyid()) && !client_portal()) { $sql = "select myviewscolumnlabelfield as key, myviewscolumnlabelname as label, 'propertyfield' as type, propertycategoryid, propertycategoryname from tblmyviewscolumnlabel lab join tblpropertycategory cat on lab.myviewscolumnlabelmovecategory = cat.propertycategoryid where myviewscolumnlabelallow = 1 and myviewscolumnlabelbrokerside = 1 order by propertycategoryrank,myviewscolumnlabelname "; } elseif(vendorid()) $sql = "select myviewscolumnlabelfield as key, myviewscolumnlabelname as label, 'propertyfield' as type, propertycategoryid, propertycategoryname from tblmyviewscolumnlabel lab join tblpropertycategory cat on lab.myviewscolumnlabelmovecategory = cat.propertycategoryid where myviewscolumnlabelallow = 1 and myviewscolumnlabelclientside = 1 and myviewscolumnlabelvisibletocompany = 1 order by propertycategoryrank,myviewscolumnlabelname "; $movecategoryarr = db_query($sql,1,0, key); if (is_array($movecategoryarr) && !empty($movecategoryarr)) $array = array_merge($array, $movecategoryarr); // NOTE: FOR SPECIAL FIELDS YOU'LL ALSO NEED TO ADD THE LABEL IN myviews_get_columnslabels() FUNCTION if (clientcompanyid()) { $array[offers][key] = "offers"; $array[offers][type] = "special"; $array[offers][propertycategoryid] = "special"; $array[offers][propertycategoryname] = "Special Columns"; $array[offers][label] = "Offers Summary"; $array[tasks][key] = "tasks"; $array[tasks][type] = "special"; $array[tasks][propertycategoryid] = "special"; $array[tasks][propertycategoryname] = "Special Columns"; $array[tasks][label] = "Tasks Summary"; } if (clientcompanyid() || client_portal() || (is_admin() && $oversetup=='3' ) ) { $array[assignto][key] = "assignto"; $array[assignto][type] = "special"; $array[assignto][propertycategoryid] = "special"; $array[assignto][propertycategoryname] = "Special Columns"; $array[assignto][label] = "Assigned To Summary"; } if(accountstaffid() || (is_admin() && $oversetup =='5')) { $array[tasks][key] = "tasks"; $array[tasks][type] = "special"; $array[tasks][propertycategoryid] = "special"; $array[tasks][propertycategoryname] = "Special Columns"; $array[tasks][label] = "Tasks Summary"; } if ((companyid() || is_admin()) && !client_portal() && in_array($oversetup, array('7','8')) ) { $array[searchedcolumns][key] = "searchedcolumns"; $array[searchedcolumns][type] = "special"; $array[searchedcolumns][propertycategoryid] = "special"; $array[searchedcolumns][propertycategoryname] = "Special Columns"; $array[searchedcolumns][label] = "Columns Searched On"; } if (vendorid()) { $array[assignto][key] = "assignto"; $array[assignto][type] = "special"; $array[assignto][propertycategoryid] = "special"; $array[assignto][propertycategoryname] = "Special Columns"; $array[assignto][label] = "Assigned To Summary"; } if(is_mlsagent()) { $array[listingagentphone][key] = "listingagentphone"; $array[listingagentphone][type] = "special"; $array[listingagentphone][propertycategoryid] = "special"; $array[listingagentphone][propertycategoryname] = "Special Columns"; $array[listingagentphone][label] = "Acq MLS Listing Agent"; } if (companyid() && !client_portal()) $agenttypes = myviews_get_propertyagenttypes(1,0,0); if(is_array($agenttypes) && is_array($array)) $array = array_merge($array, $agenttypes); $propertyroles = myviews_get_propertyroles(1, 0, 0); if(is_array($propertyroles) && is_array($array)) $array = array_merge($array, $propertyroles); $propertyroles = myviews_get_propertyclientroles(1, 0, 0); if(is_array($propertyroles) && is_array($array)) $array = array_merge($array, $propertyroles); $array[propertyphoto][key] = "propertyphoto"; $array[propertyphoto][type] = "special"; $array[propertyphoto][propertycategoryid] = "special"; $array[propertyphoto][propertycategoryname] = "Special Columns"; $array[propertyphoto][label] = "Property Photo"; // Get a list of which client company allowed to view the propertyextension if(client_portal() || accountstaffid()) { $allowedbyarr = db_query($duplicatesql,1,0); if(is_array($restrictarr) && is_array($allowedbyarr)){ foreach($allowedbyarr as $ky=>$abaextension) { if(!in_array($abaextension[propertyextensionid],$restrictarr) && !$abaextension[clientcompanypropertyextensionvisibletocompany]) unset($allowedbyarr[$ky]); } } if (is_array($allowedbyarr) && !empty($allowedbyarr)) foreach ($allowedbyarr as $k=>$value) $array[$value[key]][allowedby][$value[clientcompanyid]] = $value[clientcompanyid]; } $res[merge] = $array; //for debugging only, free to dump if needed return $array; } function myviews_get_defaultcolumns() { $default = array(); // Always check externaluserinviteid() at top because they will always have clientcompanyid or companyid if (clientcompanyid()) { $sql = " select myviewscolumnlabelfield as myviewscolumnkey, 'propertyfield' as myviewscolumntype, myviewscolumnlabelrank + 20 as myviewscolumnsorder from tblmyviewscolumnlabel where myviewscolumnlabelclientside = 1 and myviewscolumnlabelshowbydefault = 1 union select propertyextensionkey as myviewscolumnkey, 'propertyextension' as myviewscolumntype, propertyextensionrank + 100 as myviewscolumnsorder from tblclientcompanypropertyextension join tblpropertyextension using (propertyextensionid) join tblcustomfieldtype using(customfieldtypeid) join tblpropertycategory using (propertycategoryid) where clientcompanyid = ".clientcompanyid()." and propertycategoryclientinvisible = 0 and ( propertyextensionhiddenfromcolumns != 1 or propertyextensionhiddenfromcolumns is null ) and clientcompanypropertyextensiondisplayintable = 1 order by myviewscolumnsorder"; $default = db_query($sql); // Check if client has any extensions they want to be in front $sql = "select propertyextensionkey from tblclientcompanypropertyextensioncolumn join tblpropertyextension using (propertyextensionid) where clientcompanyid = ".clientcompanyid(); $extension_overwrite = db_query($sql); } elseif (accountid() || $_SESSION[myviews][oversetup]==5) { //MDM Adding this section so AMC Vendors can have myviews. $sql = " select myviewscolumnlabelfield as myviewscolumnkey, 'propertyfield' as myviewscolumntype, myviewscolumnlabelrank as myviewscolumnsorder from tblmyviewscolumnlabel where myviewscolumnlabelshowbydefault = 1 and myviewscolumnlabelclientside = 1 union select propertyextensionkey as myviewscolumnkey, 'propertyextension' as myviewscolumntype, propertyextensionrank + 100 as myviewscolumnsorder from tblclientcompanypropertyextension join tblpropertyextension using (propertyextensionid) join tblcustomfieldtype using(customfieldtypeid) join tblpropertycategory using (propertycategoryid) where clientcompanyid in ( select distinct clientcompanyid from tblclientcompanypropertyassignment join tblclientcompanyproperty using (clientcompanypropertyid) where accountstaffid in ( select accountstaffid from tblaccountstaff where officelocationid in ( select officelocationid from tblaccountstaff where accountstaffid = ".accountstaffid()." ) ) and clientcompanypropertyassignmentaccepteddate is not null ) and propertycategoryclientinvisible = 0 and ( propertyextensionhiddenfromcolumns != 1 or propertyextensionhiddenfromcolumns is null ) and clientcompanypropertyextensiondisplayintable = 1 order by myviewscolumnsorder, myviewscolumnkey asc"; $default = db_query($sql); } elseif (client_portal() || $_SESSION[myviews][oversetup]==3) { $sql = " select myviewscolumnlabelfield as myviewscolumnkey, 'propertyfield' as myviewscolumntype, myviewscolumnlabelrank as myviewscolumnsorder from tblmyviewscolumnlabel where 0=0 and myviewscolumnlabelvisibletocompany = 1 union select propertyextensionkey as myviewscolumnkey, 'propertyextension' as myviewscolumntype, propertyextensionrank + 100 as myviewscolumnsorder from tblclientcompanypropertyextension join tblpropertyextension using (propertyextensionid) join tblcustomfieldtype using(customfieldtypeid) join tblpropertycategory using (propertycategoryid) where clientcompanyid in ( select distinct clientcompanyid from tblclientcompanypropertyassignment join tblclientcompanyproperty using (clientcompanypropertyid) where staffid = ".staffid()." and clientcompanypropertyassignmentexpired is null ) and propertycategoryclientinvisible = 0 and ( propertyextensionhiddenfromcolumns != 1 or propertyextensionhiddenfromcolumns is null ) and clientcompanypropertyextensiondisplayintable = 1 order by myviewscolumnsorder, myviewscolumnkey asc"; $default = db_query($sql); // Check if client has any extensions they want to be in front $sql = " select propertyextensionkey from tblclientcompanypropertyextensioncolumn join tblpropertyextension using (propertyextensionid) where clientcompanypropertyextensioncolumnallowagent = 1"; $extension_overwrite = db_query($sql); if(is_array($restrictarr) && is_array($extension_overwrite)){ foreach($extension_overwrite as $ky=>$eoextension) { if(!in_array($eoextension[propertyextensionid],$restrictarr) && !$eoextension[clientcompanypropertyextensionvisibletocompany]) unset($extension_overwrite[$ky]); } } } elseif (vendorid()) { $sql = " select myviewscolumnlabelfield as myviewscolumnkey, 'propertyfield' as myviewscolumntype, myviewscolumnlabelrank as myviewscolumnsorder from tblmyviewscolumnlabel where myviewscolumnlabelbrokerside = 1 and myviewscolumnlabelshowbydefault = 1 and myviewscolumnlabelvisibletovendor = 1 order by myviewscolumnsorder, myviewscolumnkey "; $default = db_query($sql); } else { $sql = " select myviewscolumnlabelfield as myviewscolumnkey, 'propertyfield' as myviewscolumntype, myviewscolumnlabelrank as myviewscolumnsorder from tblmyviewscolumnlabel where myviewscolumnlabelbrokerside = 1 and myviewscolumnlabelshowbydefault = 1 union select propertyextensionkey as myviewscolumnkey, 'propertyextension' as myviewscolumntype, propertyextensionrank + 100 as myviewscolumnsorder from tblpropertycategory join tblpropertyextension using (propertycategoryid) where propertyextensionclientuse < 2 and ( propertyextensionhiddenfromcolumns != 1 or propertyextensionhiddenfromcolumns is null ) and propertyextensionkey ilike 'propertyextension%' and propertyextensionshowbydefault = 1 order by myviewscolumnsorder, myviewscolumnkey "; $default = db_query($sql); } $counter = 0; if (is_array($extension_overwrite) && !empty($extension_overwrite)) foreach ($extension_overwrite as $k=>$overwrite) { $is_found = 0; foreach($default as $default_k=>$default_row) { if ($default_row[myviewscolumnkey] == $overwrite[propertyextensionkey]) { $default[$default_k][myviewscolumnsorder] = $counter; $is_found = 1; $counter ++; } } if (!$is_found) { unset($overwrite_arr); $overwrite_arr[myviewscolumnkey] = $overwrite[propertyextensionkey]; $overwrite_arr[myviewscolumntype] = "propertyextension"; $overwrite_arr[myviewscolumnsorder] = $counter; $default[] = $overwrite_arr; $counter ++; } } $default = db_sort($default, myviewscolumnsorder, "asc"); $propertyroles = myviews_get_propertyroles(0, 1, 0); if(is_array($propertyroles) && is_array($default)) $default = array_merge($default, $propertyroles); $propertyroles = myviews_get_propertyclientroles(0, 1, 0); if(is_array($propertyroles) && is_array($default)) $default = array_merge($default, $propertyroles); if (companyid() && !client_portal()) $agenttypes = myviews_get_propertyagenttypes(0,1,0); if(is_array($agenttypes) && is_array($array)) $array = array_merge($array, $agenttypes); $propertyphoto[myviewscolumnkey] = "propertyphoto"; $propertyphoto[myviewscolumntype] = "special"; $propertyphoto[myviewscolumnsorder] = "-100"; // put in the first position $default[] = $propertyphoto; if ((clientcompanyid() || client_portal()) ) { $assignto[myviewscolumnkey] = "assignto"; $assignto[myviewscolumntype] = "special"; $assignto[myviewscolumnsorder] = "1000"; // put in the end $default[] = $assignto; } if (clientcompanyid() ) { $offers[myviewscolumnkey] = "offers"; $offers[myviewscolumntype] = "special"; $offers[myviewscolumnsorder] = "1001"; // put in the end $default[] = $offers; $tasks[myviewscolumnkey] = "tasks"; $tasks[myviewscolumntype] = "special"; $tasks[myviewscolumnsorder] = "1002"; // put in the end $default[] = $tasks; } if(accountid() && has_customization("corporateaccount") && !account_hasparent(accountid()) ) { $tasks[myviewscolumnkey] = "tasks"; $tasks[myviewscolumntype] = "special"; $tasks[myviewscolumnsorder] = "1002"; // put in the end $default[] = $tasks; } $default = db_sort($default, myviewscolumnsorder, "asc"); return $default; } function myviews_get_propertyagenttypes($format_availablecolumns = 0, $format_defaultcolumns = 0, $format_columnslabels = 0) { // use this function to retrieve the property roles to be consistent through out myviews if (!$format_availablecolumns && !$format_defaultcolumns && !$format_columnslabels) { d("Hey Dev, you must pass atleast one of the parameters for myviews_get_propertyclientroles()"); return; } if (companyid()) { $sql = "select * from tblgroup where groupid <>7 and group_companyid in (0,-1, ".companyid().") "; } $groupsarr=array(); if($sql) $groupsarr = db_query($sql); $array = array(); $counter = 50; if (!empty($groupsarr)) { foreach ($groupsarr as $k=>$group) { $key_name = strtolower($group[groupname]); if ($format_availablecolumns) { $array[$key_name][key] = $key_name; $array[$key_name][type] = "agentgroup"; $array[$key_name][propertycategoryid] = "propertygroupstaff"; $array[$key_name][propertycategoryname] = "Property Group Staff"; $array[$key_name][label] = $group[groupname]; } if ($format_defaultcolumns) { $default_array = array(); $default_array[myviewscolumnkey] = $key_name; $default_array[myviewscolumntype] = "agentgroup"; $array[$key_name][propertycategoryid] = "propertygroupstaff"; $array[$key_name][propertycategoryname] = "Property Group Staff"; $default_array[myviewscolumnsorder] = "$counter"; // put in the middle $array[] = $default_array; $counter++; } if ($format_columnslabels) { $array[$key_name][key] = $key_name; $array[$key_name][type] = "agentgroup"; $array[$key_name][propertycategoryid] = "propertygroupstaff"; $array[$key_name][propertycategoryname] = "Property Group Staff"; $array[$key_name][label] = $group[groupname]; } } } return $array; } function myviews_get_propertyclientroles($format_availablecolumns = 0, $format_defaultcolumns = 0, $format_columnslabels = 0) { // use this function to retrieve the property roles to be consistent through out myviews if (!$format_availablecolumns && !$format_defaultcolumns && !$format_columnslabels) { d("Hey Dev, you must pass at least one of the parameters for myviews_get_propertyclientroles()"); return; } if (clientcompanyid()) { $sql = "select distinct crolename from tblcrole where clientcompanyid = ".clientcompanyid()." and croleinactive is NULL order by crolename "; } $crolesarr=array(); if($sql) $crolesarr = db_query($sql); $array = array(); $counter = 50; if (is_array($crolesarr) && !empty($crolesarr)) { foreach ($crolesarr as $k=>$crole) { $key_name = strtolower("crole_".get_plain_name($crole[crolename])); if ($format_availablecolumns) { $array[$key_name][key] = $key_name; $array[$key_name][type] = "clientrole"; $array[$key_name][propertycategoryid] = "clientrole"; $array[$key_name][propertycategoryname] = "Client Role"; $array[$key_name][label] = $crole[crolename]; } if ($format_defaultcolumns) { $default_array = array(); $default_array[myviewscolumnkey] = $key_name; $default_array[myviewscolumntype] = "clientrole"; $default_array[myviewscolumnsorder] = "$counter"; // put in the middle $array[] = $default_array; $counter++; } if ($format_columnslabels) { $array[$key_name][key] = $key_name; $array[$key_name][label] = $crole[crolename]; } } } return $array; } function myviews_get_propertyroles($format_availablecolumns = 0, $format_defaultcolumns = 0, $format_columnslabels = 0) { // use this function to retrieve the property roles to be consistent through out myviews if (!$format_availablecolumns && !$format_defaultcolumns && !$format_columnslabels) { d("Hey Dev, you must pass at least one of the parameters for myviews_get_propertyroles()"); return; } $sql = ""; if (externaluserinviteid()) { if (clientcompanyid()) { $sql = "select distinct rolename from tblrole where rolepropertyworking = 1 and roleshowinexternaluserpropertylist = 1 and clientcompanyid = ".clientcompanyid()." order by rolename "; } elseif(companyid()) { ddie('implement this code for broker side.'); } } elseif (clientcompanyid()) { if ($format_availablecolumns || $format_columnslabels) { $sql = "select distinct rolename from tblrole where rolepropertyworking = 1 and clientcompanyid = ".clientcompanyid()." order by rolename"; } if($format_defaultcolumns) { $sql = "select distinct rolename from tblrole where rolepropertyworking = 1 and roleshowonpropertylist = 1 and clientcompanyid = ".clientcompanyid()." order by rolename"; } } elseif (accountstaffid()) { //MDM Adding this section so AMC Vendors can have myviews.* if ($format_availablecolumns || $format_columnslabels) { $sql = " select distinct rolename from tblrole where rolepropertyworking = 1 and clientcompanyid in ( select distinct clientcompanyid from tblclientcompany join tblclientcompanyproperty using (clientcompanyid) join tblclientcompanypropertyassignment using (clientcompanypropertyid) where accountstaffid in ( select accountstaffid from tblaccountstaff where officelocationid in ( select officelocationid from tblaccountstaff where accountstaffid = ".accountstaffid()." ) ) and clientcompanypropertyassignmentaccepteddate is not null ) order by rolename "; } if ($format_defaultcolumns) { $sql = "select distinct rolename from tblrole where rolepropertyworking = 1 and roleshowonpropertylist = 1 --and roleshowingenesispropertylist = 1 --and roleshowingenesisbasicinfo = 1 and clientcompanyid in ( select distinct clientcompanyid from tblclientcompany join tblclientcompanyproperty using (clientcompanyid) join tblclientcompanypropertyassignment using (clientcompanypropertyid) where accountstaffid in ( select accountstaffid from tblaccountstaff where officelocationid in ( select officelocationid from tblaccountstaff where accountstaffid = ".accountstaffid()." ) ) --and clientcompanypropertyassignmentrevokeddate is null --and clientcompanypropertyassignmentcompleteddate is null --and clientcompanypropertyassignmentexpired is null --and clientcompanypropertyassignmentdenieddate is null and clientcompanypropertyassignmentaccepteddate is not null ) order by rolename "; } } elseif (client_portal() && staffid()) { if ($format_availablecolumns || $format_columnslabels) { $sql = "select distinct rolename from tblrole where rolepropertyworking = 1 and roleshowingenesisbasicinfo = 1 and clientcompanyid in ( select distinct clientcompanyid from tblclientcompany join tblclientcompanyproperty using (clientcompanyid) join tblclientcompanypropertyassignment using (clientcompanypropertyid) where staffid = ".staffid()." ) order by rolename "; } if ($format_defaultcolumns) { $sql = "select distinct rolename from tblrole where rolepropertyworking = 1 and roleshowonpropertylist = 1 and roleshowingenesispropertylist = 1 and roleshowingenesisbasicinfo = 1 and clientcompanyid in ( select distinct clientcompanyid from tblclientcompany join tblclientcompanyproperty using (clientcompanyid) join tblclientcompanypropertyassignment using (clientcompanypropertyid) where staffid = ".staffid()." ) order by rolename "; } } else return array(); $rolesarr=array(); if($sql) $rolesarr = db_query($sql); $array = array(); $counter = 50; if (is_array($rolesarr) && !empty($rolesarr)) foreach ($rolesarr as $k=>$role) { $key_name = strtolower("role_".get_plain_name($role[rolename])); if ($format_availablecolumns) { $array[$key_name][key] = $key_name; $array[$key_name][type] = "special"; $array[$key_name][propertycategoryid] = "special"; $array[$key_name][propertycategoryname] = "Special Columns"; $array[$key_name][label] = $role[rolename]; } if ($format_defaultcolumns) { $default_array = array(); $default_array[myviewscolumnkey] = $key_name; $default_array[myviewscolumntype] = "special"; $default_array[myviewscolumnsorder] = "$counter"; // put in the middle $array[] = $default_array; $counter ++; } if ($format_columnslabels) { $array[$key_name][key] = $key_name; $array[$key_name][label] = $role[rolename]; } } return $array; } function myviews_get_columnslabels() { // Retrieves all the keys to labels $sql = "select myviewscolumnlabelfield as key, myviewscolumnlabelname as label from tblmyviewscolumnlabel union select propertyextensionkey as key, propertyextensionlabel as label from tblpropertyextension where propertyextensionkey ilike 'propertyextension%' "; $labelarr = db_query($sql,1,0,key); // Role Labels $role_label = myviews_get_propertyroles(0,0,1); if (is_array($role_label) && is_array($labelarr)) $labelarr = array_merge($role_label, $labelarr); // Client Role Labels $crole_label = myviews_get_propertyclientroles(0,0,1); if (is_array($crole_label) && is_array($labelarr)) $labelarr = array_merge($crole_label, $labelarr); // Assignment Type Labels $sql = " select distinct assignmentmethodname from tblassignmentmethod order by assignmentmethodname "; $assignarr = db_query($sql); if (is_array($assignarr) && !empty($assignarr)) foreach($assignarr as $k=>$value) { $key = strtolower("assignmentmethod_".get_plain_name($value[assignmentmethodname])); $labelarr[$key][key] = $key; $labelarr[$key][label] = $value[assignmentmethodname]; } // Custom Labels $labelarr[searchedcolumns][key] = "searchedcolumns"; $labelarr[searchedcolumns][label] = "Columns Searched On"; $labelarr[propertyphoto][key] = "propertyphoto"; $labelarr[propertyphoto][label] = "Property Photo"; $labelarr[assignto][key] = "assignto"; $labelarr[assignto][label] = "Assigned To Summary"; $labelarr[offers][key] = "offers"; $labelarr[offers][label] = "Offers Summary"; $labelarr[tasks][key] = "tasks"; $labelarr[tasks][label] = "Tasks Summary"; $labelarr[special_daysininventory][key] = "special_daysininventory"; $labelarr[special_daysininventory][label] = "Days in Inventory"; $labelarr[special_daysonmarket][key] = "special_daysonmarket"; $labelarr[special_daysonmarket][label] = "Days on Market"; // Override any values from configextensions foreach ($labelarr as $k=>$label) $labelarr[$k][label] = get_configextensionlabel($label[key], $label[label]); return $labelarr; } function myviews_extract_session() { if($_SESSION['myviews']) { if($_GET['sortby'] && ($_SESSION['myviews']['sorting']['sortby'] != $_GET['sortby'] || $_SESSION['myviews']['sorting']['sortorder'] != $_GET['sortorder'])) { if($_SESSION['myviews']['selected']) $_SESSION['myviews']['modified'] = 1; $_SESSION['myviews']['sorting']['sortby'] = $_GET['sortby']; $_SESSION['myviews']['sorting']['sortorder'] = $_GET['sortorder']; } else if($_SESSION['myviews']['sorting']['sortby']) { $_GET['sortby'] = $_SESSION['myviews']['sorting']['sortby']; $_GET['sortorder'] = $_SESSION['myviews']['sorting']['sortorder']; } if(!$_SESSION['myviews']['hidden_cols']) $_SESSION['myviews']['hidden_cols'] = array(); if(empty($_SESSION['myviews']['displaycolumns'])) $_SESSION['myviews']['displaycolumns'] = myviews_get_defaultcolumns(); if($_SESSION['myviews']['search']) { foreach($_SESSION['myviews']['search'] as $key => $val) { if(!$_GET[$key]) // this if added by michael, this global overrid of the GET function gave precedance to the SESSION over what is requested on in the URL of the specific page, until I put this if in. $_GET[$key] = $val; } } } } function myviews_force_activate($myviewsid){ unset($_SESSION['myviews']); $_SESSION['myviews']['selected']=$myviewsid; myviews_view($myviewsid); if(empty($_SESSION['myviews']['columnslabels'])) $_SESSION['myviews']['columnslabels'] = myviews_get_columnslabels(); return; } function myviews_content($myviewsid = '') { // BASED ON THE TYPE OF USER, SET A DEFAULT MYVIEWSID TO USE if(!$_SESSION['myviews']['selected']) { if (accountid() && has_customization("corporateaccount") && !account_hasparent(accountid()) ) $myviewsid =5; elseif (client_portal() && !accountid() && !$myviewsid ) $myviewsid =3; else if (clientcompanyid() && !$myviewsid ) { $myviewsid = db_firstval("select myviewsid from tblmyviews where myviewsclientcompanyid =".clientcompanyid()); if(!$myviewsid) $myviewsid =2; } else if (companyid() ) { //first look and see if the master account has created a default for the company $mu_loginid = db_firstval("select loginid from tbllogin where companyid = " . companyid() ." and staffid =0 "); $myviewsid = db_firstval("select myviewsid from tblmyviews where loginid = " . $mu_loginid . " and myviewsname ilike 'default' and myviewsbrokerside = 1 and myviewsclientcompanyid = 0 and trim(myviewsname)<>'' "); //if the master account did not create a default then use the system wide default if(!$myviewsid) { $myviewsid = 7; //rio pro if(riooffice()) $myviewsid = 8; // rio office } } } if (!$myviewsid) $myviewsid = $_SESSION['myviews']['selected']; if($myviewsid) myviews_force_activate($myviewsid); $views = myviews_get(); //set the cookie below based on the user logged in, then next time the user logged in, this cookie is reviewed to give them quick access to th if($myviewsid) echo ""; elseif($_SESSION['myviews']['selected']) echo ""; // here we display myviews select box ?>
My Views *
$displaycolumn) { $found = 0; if (is_array($current_available_columns) && !empty($current_available_columns)) foreach($current_available_columns as $available_k=>$available) { if ($displaycolumn['myviewscolumnkey'] == $available['key']) $found = 1; } if (!$found) { if (clientcompanyid() && $displaycolumn['myviewscolumntype']=='propertyfield' && strpos($displaycolumn['myviewscolumnkey'] ,"clientcompany") ===false ) { $_SESSION['myviews']['displaycolumns'][$selected_k]['myviewscolumnkey'] = "clientcompany" . $_SESSION['myviews']['displaycolumns'][$selected_k]['myviewscolumnkey']; } else { unset($_SESSION['myviews']['displaycolumns'][$selected_k]); } } } } elseif (empty($_SESSION['myviews']['columnslabels'])) $_SESSION['myviews']['columnslabels'] = myviews_get_columnslabels(); $_SESSION['myviews'][broker_side] = myviews_is_broker_side(); // Don't echo anything in order to init the myviews for master header display if ($do_not_echo) return; ?>