Logo Search packages:      
Sourcecode: davical version File versions  Download package

RSCDSUser::RenderRelationshipsTo ( ef,
title = null 
)

Render the user's relationships to other users & resources

Returns:
string The string of html to be output

Present an extra editable row at the bottom of the browse.

We only allow individuals to link to groups at this stage.

Definition at line 156 of file RSCDSUser.php.

Referenced by Render().

                                                       {
    global $session, $c;

    if ( $title == null ) $title = i18n("Relationships to this user");
    $browser = new Browser("");

    $browser->AddHidden( 'user_link', "'<a href=\"$c->base_url/usr.php?user_no=' || user_no || '\">' || fullname || '</a>'" );
    $browser->AddColumn( 'fullname', translate('Linked From'), 'left', '##user_link##' );
    $browser->AddColumn( 'rt_name', translate('Relationship') );
    $browser->AddHidden( 'confers' );
    $browser->AddColumn( 'email', translate('EMail') );
    if ( $ef->EditMode ) { // && $session->AllowedTo("MaintainRelationships") ) {
      $browser->AddColumn( 'delete', translate('Delete'), 'centre', '', "'<a class=\"\" href=\"$c->base_url/usr.php?edit=1&user_no=$this->user_no&action=delete_relationship&from_user=' || user_no || '\">Delete</a>'" );
    }

    $browser->SetJoins( 'relationship NATURAL JOIN relationship_type rt LEFT JOIN usr ON (from_user = user_no)' );
    $browser->SetWhere( "to_user = $this->user_no" );

    if ( isset( $_GET['o']) && isset($_GET['d']) ) {
      $browser->AddOrder( $_GET['o'], $_GET['d'] );

      if ( $_GET['o'][0] != 'fullname' ) $browser->AddOrder( 'fullname', 'A', 0, 1 );
    }
    else {
      $browser->AddOrder( 'rt_name', 'A', 1 );
      $browser->AddOrder( 'fullname', 'A', 0, 1 );
    }

    $browser->RowFormat( "<tr onMouseover=\"LinkHref(this,1);\" title=\"".translate("Click to display that user")."\" class=\"r%d\">\n", "</tr>\n", '#even' );
    $browser->SetTranslatable( array('rt_name') );
    $browser->DoQuery();

    /**
    * Present an extra editable row at the bottom of the browse.
    */
    if ( $ef->EditMode ) { // && $session->AllowedTo("MaintainRelationships") ) {
      $sql = <<<EOSQL
SELECT user_no, fullname FROM usr
 WHERE NOT EXISTS ( SELECT 0 FROM relationship WHERE (from_user = usr.user_no AND to_user = $this->user_no))
   AND user_no != $this->user_no
EOSQL;
      if ( isset($this->roles['Group']) ) {
        /**
        * We only allow individuals to link to groups at this stage.
        */
        $sql .= 'AND NOT EXISTS (SELECT 1 FROM role_member WHERE role_no = 2 AND user_no=usr.user_no)';
      }

      if ( ! isset($this->roles['Group']) )
        $nullvalue = translate( "--- select a user, group or resource ---" );
      else
        $nullvalue = translate( "--- select a user or resource ---" );
      $person_selection = $ef->DataEntryField( "", "lookup", "relate_to",
                                array("title" => translate("Select the user, resource or group to relate this user to"),
                                      "_null" => $nullvalue,
                                      "_sql"  => $sql ) );

      $relationship_type_selection = $ef->DataEntryField( "", "lookup", "relate_as",
                                array("title" => translate("Select the type of relationship from this user"),
                                      "_null" => translate("--- select a relationship type ---"),
                                      "_sql"  => "SELECT rt_id, rt_name FROM relationship_type " ) );

      $browser->AddRow( array(
                      'user_link' => $person_selection,
                      'rt_name' => $relationship_type_selection,  /* Since 'fullname' is formatted to display this value */
                      'delete' => sprintf('<input type="submit" name="submit" value="%s" class="fsubmit">', htmlspecialchars(translate("Add Relationship")))
                     ) );
    }

    $html = ( $title == "" ? "" : $ef->BreakLine(translate($title)) );
    $html .= "<tr><td>&nbsp;</td><td>\n";
    $html .= $browser->Render();
    $html .= "</td></tr>\n";

    return $html;
  }

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index