Beispiel #1
0
function getUserRoleForLayer($layer_tablename) {
  $user = $GLOBALS['user'];
  $user_roles = $user->roles;
  $layer_roles = array("admin", "member", "validator");
  if($user->uid) {
    if(in_array(SITE_ADMIN_ROLE, $user_roles)) {
      return "admin";
    }
    foreach($layer_roles as $layer_role) {
      $role = $layer_tablename . " " . $layer_role;
      if(in_array($role, $user_roles)) {
        return $layer_role;
      }
    }
    $participation_type = getLayerParticipationType($layer_tablename);
    if($participation_type == 2 || $participation_type == 3) {
      return "member";
    }
  }
  return "";
}
Beispiel #2
0
function get_link_table_entries($layer_tablename, $row_id, $link_tablename) {
  $arr_result=array();
  $column_names=array();
  $arr_mlocate=array();
  $r=1;

  $participation_type=getLayerParticipationType($layer_tablename);

  $table_info=GetTableColsOfType($link_tablename, 'link', 'italics');
  $italics_columns=$table_info['italics_columns'];

  $query="select description, linked_column, layer_column from \"Meta_LinkTable\" where link_tablename = '%s'";
  $result=db_query($query, $link_tablename);
  if(!$result) {
    //Error occured
    $arr_result['error']='Error fetching data from DB';
  }
  else {

    $obj=db_fetch_object($result);
    $link_description=$obj->description;
    $linked_column=str_replace("'", "", $obj->linked_column);
    $layer_column=str_replace("'", "", $obj->layer_column);

    $linked_value= - 1;

    $col_info=getDBColDesc($link_tablename);

    $global_resource_mapping=getResourceTableMapping($link_tablename);

    $query='SELECT "%s".* FROM "%s", "%s" where "%s"."%s" = "%s"."%s" and "%s".' . AUTO_DBCOL_PREFIX . 'id = %d';
    $query_args=array($link_tablename, $link_tablename, $layer_tablename, $link_tablename, $linked_column, $layer_tablename, $layer_column, $layer_tablename, $row_id);
    $result=db_query($query, $query_args);
    if(!$result) {
      //Error occured
      $arr_result['error']='Error fetching links';
    }
    else {
      $arr_result['description']=($metalink[$link]['description'] == "" ? '' : $metalink[$link]['description']);

      foreach($col_info as $key=>$val) {
        if(substr($key, 0, strlen(AUTO_DBCOL_PREFIX)) != AUTO_DBCOL_PREFIX) {
          $column_names[$key]=($col_info[$key] == "" ? str_replace(" ", " ", $key) : str_replace(" ", " ", $col_info[$key]));
        }
      }
      if($participation_type == 1 || $participation_type == 2 || $participation_type == 3) {
        $column_names['created_by']='Created By';
        $column_names['created_date']='Created Date';
        $column_names['modified_by']='Modified By';
        $column_names['modified_date']='Modified Date';
      }
      $arr_result['col_names']=$column_names;

      $tbody="";
      $i=0;
      $r=0;
      $data=array();
      while($obj=db_fetch_object($result)) {
        if($i == 0) {
          $linked_value=$obj-> {
            $linked_column
          };
          $i+=1;
        }

        $row=array();
        $rw=array();
        foreach($obj as $key=>$value) {
          if((($participation_type == 1 || $participation_type == 2 || $participation_type == 3) && ($key == AUTO_DBCOL_PREFIX . "created_by" || $key == AUTO_DBCOL_PREFIX . "created_date" || $key == AUTO_DBCOL_PREFIX . "modified_by" || $key == AUTO_DBCOL_PREFIX . "modified_date"))) {
            switch($key) {
              case AUTO_DBCOL_PREFIX . 'created_by':
                $rw['created_by']='<a href="' . $base_path . 'user/' . $value . '" target="_blank">' . getUserName($value) . '</a>';
                break;

              case AUTO_DBCOL_PREFIX . 'modified_by':
                $rw['modified_by']='<a href="' . $base_path . 'user/' . $value . '" target="_blank">' . getUserName($value) . '</a>';
                break;

              case AUTO_DBCOL_PREFIX . 'created_date':
                $rw['created_date']=($value == '' ? '&nbsp;' : str_replace(" ", "&nbsp;", $value));
                break;

              case AUTO_DBCOL_PREFIX . 'modified_date':
                $rw['modified_date']=($value == '' ? '&nbsp;' : str_replace(" ", "&nbsp;", $value));
                break;
            }
          }
          elseif(substr($key, 0, strlen(AUTO_DBCOL_PREFIX)) != AUTO_DBCOL_PREFIX) {
            if(array_key_exists($key, $global_resource_mapping)) {
              if($value == "") {
                $val='&nbsp;';
              }
              else {
                $href="{$base_path}ml_orchestrator.php?action=getResourceTableEntry&resource_tablename=" . urlencode($global_resource_mapping[$key]['resource_tablename']) . "&resource_column=" . urlencode($global_resource_mapping[$key]['resource_column']) . "&value=" . urlencode($value);
                $val=($value == '' ? '&nbsp;' : "<a id='a_{$value}' name='" . $global_resource_mapping[$key]['resource_tablename'] . "' href='{$href}' class='jTip1' onClick='javascript:showAjaxLinkPopup(this.href, this.name);return false;'>" . str_replace(" ", "&nbsp;", $value) . "</a>");
              }
            }
            elseif(strpos($italics_columns, "'{$key}'") !== FALSE) {
              $val=($value == '' ? '&nbsp;' : '<i>' . str_replace(" ", "&nbsp;", $value) . '</i>');
            }
            else {
              $val=($value == '' ? '&nbsp;' : str_replace(" ", "&nbsp;", $value));
            }
            $row[$key]=$val;
          }
        }
        $row=array_merge($row, $rw);
        $data[]=$row;
        $r++;
      }
      $arr_result['data_count']=$r;
      $arr_result['data']=$data;
      if($i == 0) {
        $arr_result['no_record']="Sorry! No records found.";
      }
      if(userHasAddLinkedDataPerm($layer_tablename)) {
        $arr_result['add_linked_data_lnk']=$base_path . 'ml_orchestrator.php?action=getLinkTableSchema&link_tablename=' . $link_tablename . '&linked_column=' . $linked_column . '&linked_value=' . $linked_value;
      }
      $arr_result['link_tablename']=$link_tablename;
      $arr_result['linked_column']=$linked_column;
      $arr_result['linked_value']=$linked_value;

      print json_encode($arr_result);
    }
  }
}