function getSchema($layer_tablename){ //get column names except custom columns global $table_cols; global $col_type; $query = "select column_name,data_type from information_schema.columns where table_name='%s' AND column_name not like '".AUTO_DBCOL_PREFIX."%'"; $result = db_query($query,$layer_tablename); if(!$result) { } else { while($obj = db_fetch_object($result)) { $cols .= "'".$obj->column_name."',"; $col_type[$obj->column_name] = $obj->data_type; } } $cols = substr($cols,0,(strlen($cols)-1)); $col_info = getDBColDesc($layer_tablename,$cols); //get layer_type $query = "select layer_type from \"Meta_Layer\" where layer_tablename = '%s'"; $result = db_query($query,$layer_tablename); if(!$result) { } else { while($obj = db_fetch_object($result)) { $layer_type = $obj->layer_type; } } if(isset($_REQUEST['action'])){ $table_cols = $col_info; } else { $table_cols = $cols; } return $layer_type; }
function getGRMappedTableColumns($xmlDoc, &$rootNode, $paramsNode) { $tableNode = $paramsNode->getElementsByTagName('table')->item(0); $tablename = $tableNode->nodeValue; $table_type = $tableNode->getAttribute('type'); if($tablename == null || $tablename == '' || $table_type == null || $table_type == '') { setError($xmlDoc, $rootNode, "Required parameters not set."); return; } else { $query = "select table_column from \"Global_Resource_Mapping\" where tablename = '%s' and table_type = '%s'"; $result = db_query($query, array($tablename, $table_type)); if(!$result) { setError($xmlDoc, $rootNode, "Error fetching data."); } else { setNoError($xmlDoc, $rootNode); $arr_cols = array(); while($obj = db_fetch_object($result)) { $arr_cols[] = $table_column = $obj->table_column; } addXMLChildNode($xmlDoc, $rootNode, "table", null, array("tablename" => $tablename, "table_type" => $table_type, 'columns' => implode(",", array_keys(getDBColDesc($tablename))), "mapped_columns" => implode(",", $arr_cols))); } } }
function getColumnsForLayerOfType($xmlDoc, &$rootNode, $paramsNode) { $layer_tablename = $paramsNode->getElementsByTagName('layer_tablename')->item(0)->nodeValue; $column_type = $paramsNode->getElementsByTagName('column_type')->item(0)->nodeValue; if($layer_tablename == null || $layer_tablename == '' || $column_type == null || $column_type == '') { setError($xmlDoc, $rootNode, "Required parameters not set."); return; } else { $col_db_info = getDBColDesc($layer_tablename, null, $column_type, false); getTableColDesc($layer_tablename, 'layer', $col_db_info, $xmlDoc, $rootNode, false); $cols = array(); foreach($col_db_info as $key => $val) { if(substr($key, 0, strlen(AUTO_DBCOL_PREFIX)) != AUTO_DBCOL_PREFIX) { $cols[] = $key; } } $colsinfo = getStartEndDatesForColumns($layer_tablename, $cols); $colnodes = $xmlDoc->getElementsByTagName('column'); $i = 0; foreach ($colnodes as $colnode) { $colname = $colnode->getAttribute('name'); $colnode->removeAttribute('type'); $colnode->setAttribute('startdate', $colsinfo[$colname]['startdate']); $colnode->setAttribute('enddate', $colsinfo[$colname]['enddate']); $i++; } } }
function getDODForPolygon($table,$BBOX){ $col_info = getDBColDesc($table); echo '<table id="dataPresentation">'; $j=0; $str=''; $query = "SELECT *,astext(ST_PointOnSurface(".AUTO_DBCOL_PREFIX."topology)) as centroid FROM \"%s\" where ".AUTO_DBCOL_PREFIX."topology && setSRID('BOX3D(%s)'::box3d, (select srid from geometry_columns where f_table_name = '%s')) "; $query_args = array($table, $BBOX, $table); $result_db = db_query($query, $query_args); while ($obj = db_fetch_object($result_db)) { if($j==0) { echo '<thead align=center>'; $firstrow ='<tr id="tbl_cols" align=center onClick=HighlightFeature(this,\'#c9cc99\',\''. $table .'\'); >'; foreach($obj as $key => $value) { switch($key) { case AUTO_DBCOL_PREFIX.'topology' : break; case AUTO_DBCOL_PREFIX.'created_by': break; case AUTO_DBCOL_PREFIX.'modified_by': break; case AUTO_DBCOL_PREFIX.'layer_id' : break; case AUTO_DBCOL_PREFIX.'validated_by': break; case AUTO_DBCOL_PREFIX.'validated_date': break; case AUTO_DBCOL_PREFIX.'status' : break; case AUTO_DBCOL_PREFIX.'nid': break; case AUTO_DBCOL_PREFIX.'topology' : break; case AUTO_DBCOL_PREFIX.'created_date': break; case AUTO_DBCOL_PREFIX.'modified_date': break; case AUTO_DBCOL_PREFIX.'id': echo '<th class ="hidecol" align=center>'.($col_info[$key] == "" ? str_replace(" ", " ", $key) : str_replace(" ", " ",$col_info[$key])).'</th>'; $firstrow.= '<td align=center>'.str_replace(" "," " ,$value ).'</td>'; break; case'centroid': echo '<th class ="hidecol" align=center>'.($col_info[$key] == "" ? str_replace(" ", " ", $key) : str_replace(" ", " ",$col_info[$key])).'</th>'; $firstrow.= '<td align=center>'.str_replace(" "," " ,$value ).'</td>'; break; default: echo '<th align=center>'.($col_info[$key] == "" ? str_replace(" ", " ", $key) : str_replace(" ", " ",$col_info[$key])).'</th>'; $firstrow.= '<td align=center>'.str_replace(" "," " ,$value ).'</td>'; break; } } $firstrow .= '</tr>'; echo '</thead>'; echo $firstrow; $j += 1; } else { $str.= '<tr align=center onClick=HighlightFeature(this,\'#c9cc99\',\''. $table .'\'); >'; foreach($obj as $key => $value) { switch($key) { case AUTO_DBCOL_PREFIX.'created_by': break; case AUTO_DBCOL_PREFIX.'modified_by': break; case AUTO_DBCOL_PREFIX.'topology': break; case AUTO_DBCOL_PREFIX.'layer_id' : break; case AUTO_DBCOL_PREFIX.'validated_by': break; case AUTO_DBCOL_PREFIX.'validated_date': break; case AUTO_DBCOL_PREFIX.'status' : break; case AUTO_DBCOL_PREFIX.'topology' : break; case AUTO_DBCOL_PREFIX.'nid': break; case AUTO_DBCOL_PREFIX.'created_date': break; case AUTO_DBCOL_PREFIX.'modified_date': break; case'centroid': $str.= '<td align=center>'.str_replace(" "," " ,$value ).'</td>'; break; default: $str.= '<td align=center>'.str_replace(" "," " ,$value ).'</td>'; break; } } $str.= '</tr>'; } } print_r($str); echo '</table> '; }
function getTableAttribForLayerInfo($tablename, $skip_cols=array()) { $attr=""; $col_info=getDBColDesc($tablename); foreach($col_info as $col=>$desc) { if(!in_array($col, $skip_cols)) { if(substr($col, 0, 7) != AUTO_DBCOL_PREFIX) { $attr.="<li>" . (($desc == "" ? $col : $desc)) . "</li>"; } } } return $attr; }
function getFeatureInfo($xmlDoc, &$rootNode, $paramsNode) { $layer_tablename = $paramsNode->getElementsByTagName('layer_tablename')->item(0)->nodeValue; $row_id = $paramsNode->getElementsByTagName('row_id')->item(0)->nodeValue; if(($layer_tablename == null || $layer_tablename == '') || ($row_id == null || $row_id == '')) { setError($xmlDoc, $rootNode, "Required parameters not set."); return; } else { $col_db_info = getDBColDesc($layer_tablename); $columns_arr = array(); $columns_arr[] = 'layer_name'; $columns_arr[] = 'layer_type'; $columns_arr[] = 'title_column'; $columns_arr[] = 'license'; $columns_arr[] = 'attribution'; $columns_arr[] = 'summary_columns'; $columns_arr[] = 'media_columns'; $columns_arr[] = 'video_columns'; $columns_arr[] = 'nid'; $metainfo = get_values_metatable($layer_tablename, $layer_id, TABLE_TYPE_LAYER, $columns_arr); $layer_name = $metainfo['layer_name']; $layer_title_column = str_replace("'", "", $metainfo['title_column']); $layer_license = $metainfo['license']; $layer_attribution = $metainfo['attribution']; $summary_columns_arr = explode(",", str_replace("'", "", $metainfo['summary_columns'])); $media_columns = $metainfo['media_columns']; $media_columns_arr = array(); if($media_columns != NULL && $media_columns != '') { $media_columns_arr = explode(",", str_replace("'", "", $metainfo['media_columns'])); } $video_columns_arr = array(); $video_columns = $metainfo['video_columns']; if($video_columns != NULL && $video_columns != '') { $video_columns_arr = explode(",", str_replace("'", "", $metainfo['video_columns'])); } $lyr_nid = $metainfo['nid']; $attribs_res = array(); $images = array(); $videos = array(); $title = ""; $created_by = ""; $created_date = ""; $modified_by = ""; $modified_date = ""; $validated_by = ""; $validated_date = ""; $validated = ""; $attribution = ""; $nid = 0; $teaser = ""; $query = 'select * from "%s" where '.AUTO_DBCOL_PREFIX.'id = %d;'; $result = db_query($query, array($layer_tablename, $row_id)); if (!$result) { setError($xmlDoc, $rootNode, "Error fetching information."); } else { if ($arr = db_fetch_array($result)) { $base_path = base_path(); foreach ($arr as $key => $val) { if($key == $layer_title_column) { $title = $val; } if(in_array($key, $media_columns_arr)) { if($val != NULL) { $arr = explode(",", $val); $label = $col_db_info[$key] == '' ? $key : $col_db_info[$key]; foreach($arr as $v) { $images[] = array('value' => $base_path.'sites/default/files/images/'.$layer_tablename.'/'.$v, 'label' => $label . ': ' . $v); } } } if(in_array($key, $video_columns_arr)) { if($val != NULL) { $arr = explode(",", $val); $label = $col_db_info[$key] == '' ? $key : $col_db_info[$key]; foreach($arr as $v) { $videos[] = array('value' => $base_path.'sites/default/files/videos/'.$layer_tablename.'/'.$v, 'label' => $label . ': ' . $v); } } } switch($key) { case AUTO_DBCOL_PREFIX.'created_by': if($val) { $created_by = getUserName($val); } break; case AUTO_DBCOL_PREFIX.'created_date': $created_date = $val; break; case AUTO_DBCOL_PREFIX.'modified_by': if($val) { $modified_by = getUserName($val); } break; case AUTO_DBCOL_PREFIX.'modified_date': $modified_date = $val; break; case AUTO_DBCOL_PREFIX.'validated_by': if($val) { $validated_by = getUserName($val); } break; case AUTO_DBCOL_PREFIX.'validated_date': $validated_date = $val; break; case AUTO_DBCOL_PREFIX.'status': $validated = $val; break; case AUTO_DBCOL_PREFIX.'attribution': $attribution = $val; break; case AUTO_DBCOL_PREFIX.'nid': $nid = $val; break; case AUTO_DBCOL_PREFIX.'id': case AUTO_DBCOL_PREFIX.'layer_id': case AUTO_DBCOL_PREFIX.'topology': break; default: if(count($summary_columns_arr) > 0) { if(!in_array($key, $media_columns_arr) && !in_array($key, $video_columns_arr)) { $attribs_res[$key] = array('key' => $key, 'value' => $val, 'label' => ($col_db_info[$key] == '' ? $key : $col_db_info[$key]), 'summary_column' => (in_array($key, $summary_columns_arr) == true) ? '1' : '0'); } } else { if(!in_array($key, $media_columns_arr) && !in_array($key, $video_columns_arr)) { $attribs_res[$key] = array('key' => $key, 'value' => $val, 'label' => ($col_db_info[$key] == '' ? $key : $col_db_info[$key])); } } break; } } } } setNoError($xmlDoc, $rootNode); $lyrNode = addXMLChildNode($xmlDoc, $rootNode, "layer", null, array('name' => $layer_name, 'tablename' => $layer_tablename, 'row_id' => $row_id, 'nid' => $lyr_nid)); $infoNode = addXMLChildNode($xmlDoc, $lyrNode, "info"); addXMLChildNode($xmlDoc, $infoNode, "title", $title); if($nid) { $node = node_load($nid); $ntitle = $node->title; $nbody = $node->body; $nbody .= ' <font color="#0000FF"><i><a href="'.base_path().'node/'.$nid.'" target="_blank">(more...)</a></i></font>'; addXMLChildNode($xmlDoc, $infoNode, "narrative", $nbody, array('nid' => $nid, 'title' => $ntitle)); } else { addXMLChildNode($xmlDoc, $infoNode, "narrative", null, array('nid' => $nid)); } addXMLChildNode($xmlDoc, $infoNode, "created", null, array('by' => $created_by, 'date' => $created_date)); addXMLChildNode($xmlDoc, $infoNode, "modified", null, array('by' => $modified_by, 'date' => $modified_date)); if($validated) { addXMLChildNode($xmlDoc, $infoNode, "validated", null, array('by' => $validated_by, 'date' => $validated_date)); } addXMLChildNode($xmlDoc, $infoNode, "attribution", $attribution); $license = getCCLicenseHTMLForSummary($layer_license); if($license != $layer_license){ $url = 'http://i.creativecommons.org/l/' . $license[0] . '/3.0/'; addXMLChildNode($xmlDoc, $infoNode, "license", $license[0], array('url' => $url, 'img' => $url . $license[1] . '.png')); } else { addXMLChildNode($xmlDoc, $infoNode, "license", $license); } if(userHasEditLayerDataPerm($layer_tablename, $row_id)) { addXMLChildNode($xmlDoc, $infoNode, "userHasEditLayerDataPerm", "1"); } else { addXMLChildNode($xmlDoc, $infoNode, "userHasEditLayerDataPerm", "0"); } $user = $GLOBALS['user']; if($user->uid && user_access("create node_mlocate_feature")) { addXMLChildNode($xmlDoc, $infoNode, "userHasEditDrupalNodePerm", "1"); } else { addXMLChildNode($xmlDoc, $infoNode, "userHasEditDrupalNodePerm", "0"); } $base_path = base_path(); $mediaNode = addXMLChildNode($xmlDoc, $lyrNode, "media"); if(count($media_columns_arr) > 0) { $imagesNode = addXMLChildNode($xmlDoc, $mediaNode, "images"); foreach ($images as $im) { addXMLChildNode($xmlDoc, $imagesNode, "image", null, $im); } } if(count($video_columns_arr) > 0) { $videosNode = addXMLChildNode($xmlDoc, $mediaNode, "videos"); foreach ($videos as $vd) { addXMLChildNode($xmlDoc, $videosNode, "video", null, $vd); } } $attribsNode = addXMLChildNode($xmlDoc, $lyrNode, "attribs"); foreach ($attribs_res as $attrib) { addXMLChildNode($xmlDoc, $attribsNode, "attrib", null, $attrib); } } }
function getLinkColDesc($xmlDoc, &$rootNode, $paramsNode) { $link_tablename = $paramsNode->getElementsByTagName('link_tablename')->item(0)->nodeValue; if($link_tablename == null || $link_tablename == '') { setError($xmlDoc, $rootNode, "Required parameters not set."); return; } else { $col_db_info = getDBColDesc($link_tablename); getTableColDesc($link_tablename, 'link', $col_db_info, $xmlDoc, $rootNode); } }