Beispiel #1
0
function getPopupUIMenu($layer_tablename, $row_id, $layer_name, $feature_title) {
  $menu=array();
  $base_path=$GLOBALS['base_path'];
  if((isset($_SESSION['popup_layer_tablename']) && $_SESSION['popup_layer_tablename'] != $layer_tablename) || ((isset($_SESSION['popup_row_id']) && $_SESSION['popup_row_id'] != $row_id))) {
    if(isset($_SESSION['popup_menu'])) {
      unset($_SESSION['popup_menu']);
    }
    unset($_SESSION['popup_layer_tablename']);
    unset($_SESSION['popup_row_id']);
  }
  $_SESSION['popup_layer_tablename']=$layer_tablename;
  $_SESSION['popup_row_id']=$row_id;
  if(!isset($_SESSION['popup_menu']) || $_SESSION['popup_menu'] != "") {
    $user=$GLOBALS['user'];

    $menu['divId']="divPopupPane";
    $menu['ulId']="ulPopupUIMenu";

    /* details tab */
    $details_lnk="{$base_path}ml_orchestrator.php?action=getLayerDataDetails&row_id={$row_id}&layer_tablename={$layer_tablename}&hasmenu=1";
    $menu['details_id']='layerDetails';
    $menu['details_lnk']=$details_lnk;
    $menu['details_title']='Details';

    /* end details tab */

    /* edit details */
    if(userHasEditLayerDataPerm($layer_tablename, $row_id)) {
      $liID="editFeatureDetails";
      $lnk="{$base_path}ml_orchestrator.php?action=getLayerTableSchema&layer_tablename={$layer_tablename}&id={$row_id}";
      $title="Edit Details";
      $menu['editDetails_id']=$liID;
      $menu['editDetails_lnk']=$lnk;
      $menu['editDetails_title']=$title;
    }
    /* end edit details */

    /* drupal node */
    $query='SELECT ' . AUTO_DBCOL_PREFIX . 'nid FROM "%s" where ' . AUTO_DBCOL_PREFIX . 'id = %d';
    $result=db_query($query, $layer_tablename, $row_id);
    if(!$result) {
    }
    else {
      $obj=db_fetch_object($result);
      $nid=$obj-> {
        AUTO_DBCOL_PREFIX . 'nid'
      };
      if($nid) {
        /* if drupal node is assigned, show it and comments. */
        $liID="drupalNode";
        $lnk="{$base_path}node/" . $nid . "/popup";
        $title="More Details";
        $menu['moreDetails_id']=$liID;
        $menu['moreDetails_lnk']=$lnk;
        $menu['moreDetails_title']=$title;
        if(node_access('update', node_load($nid))) {
          $liID="drupalEditDetails";
          $lnk="{$base_path}node/{$nid}/edit/popup";
          $title="Edit More Details";

          $menu['editMoreDetails_id']=$liID;
          $menu['editMoreDetails_lnk']=$lnk;
          $menu['editMoreDetails_title']=$title;
        }
        if($user->uid) {
          $liID="drupalAddComments";
          $lnk="{$base_path}comment/reply/$nid#comment-form";
          $title="Add Comments";
          $menu['addComments_id']=$liID;
          $menu['addComments_lnk']=$lnk;
          $menu['addComments_title']=$title;
        }
      }
      else {
        if($user->uid && user_access("create node_mlocate_feature")) {
          $liID="drupalAddMoreDetails";
          $lnk="{$base_path}node/add/node-mlocate-feature/popup?layer_tablename={$layer_tablename}&point_id={$row_id}";
          $title="Add More Details";
          $menu['addMoreDetails_id']=$liID;
          $menu['addMoreDetails_lnk']=$lnk;
          $menu['addMoreDetails_title']=$title;
        }
      }
    }
    /* end drupal node */

    /* charts */
    $liID="featureCharts";
    $menu['charts_id']=$liID;
    /* end charts */

    /* media */
    $columns_arr=array();
    $columns_arr[]="media_columns";
    $metainfo=get_values_metatable($layer_tablename, $row_id, TABLE_TYPE_LAYER, $columns_arr);
    $media_columns=$metainfo['media_columns'];
    if($media_columns != "") {
      $cols=explode(",", $media_columns);
      foreach($cols as $col) {
        $col=str_replace("'", "", $col);
        $col=trim($col);
        $title=strtoupper(substr($col, 0, 1)) . substr($col, 1);
        $lnk="{$base_path}ml_orchestrator.php?action=getMedia&id={$row_id}&layer_tablename={$layer_tablename}&media_column={$col}";
        $liID='media_' . $col;
        $menu[$col . '_media_id']=$liID;
        $menu[$col . '_media_lnk']=$lnk;
        $menu[$col . '_media_title']=$title;
      }
    }

    /* end media */

    /* link tables info */
    $link_tablenames=getLinkTableNames($layer_tablename);
    $i=1;
    foreach($link_tablenames as $link) {
      $tablename=$link['tablename'];
      $liID="linkedData_{$i}";
      $title=$link['name'];
      if($title == "") {
        $title="Linked Data {$i}";
      }
      $lnk="{$base_path}ml_orchestrator.php?action=getLinkTableEntries&layerdata_id={$row_id}&layer_tablename={$layer_tablename}&link_tablename={$tablename}";
      $arr_linktable[$title . '_liId']=$liID;
      $arr_linktable[$title . '_lnk']=$lnk;
      $arr_linktable[$title . '_title']=$title;
      $i++;
    }
    if(sizeof($link_tablenames) != 0) {
      $menu['linktable']=$link_tablenames;
    }
    else {
      $menu['linktable']="";
    }
    /* end link tables info */

    $_SESSION['popup_menu']=$menu;
  }
  else {
    $menu=$_SESSION['popup_menu'];
  }
  return $menu;
}
Beispiel #2
0
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);
    }
  }
}