* @copyright Catalyst .Net Ltd, Morphoss Ltd
* @license http://gnu.org/copyleft/gpl.html GNU GPL v2
*/
require("User.php");
require_once("classBrowser.php");
require_once("auth-functions.php");
$c->stylesheets[] = "$c->base_url/css/browse.css";
$c->scripts[] = "$c->base_url/js/browse.js";
/**
* A class for viewing and maintaining DAViCal User records
*
* @package davical
*/
class DAViCalUser extends User
{
var $delete_collection_confirmation_required;
/**
* Constructor - nothing fancy as yet.
*/
function DAViCalUser( $id , $prefix = "") {
global $c;
$this->delete_collection_confirmation_required = null;
parent::User( $id, $prefix );
if ( $this->user_no == 0 && isset($c->template_usr) && is_array($c->template_usr) ) {
foreach( $c->template_usr AS $k => $v ) {
$this->Set($k,$v);
}
}
}
/**
* Render the form / viewer as HTML to show the user
* @return string An HTML fragment to display in the page.
*/
function Render($title = "" ) {
global $c;
$html = "";
dbg_error_log("User", ":Render: type=$this->WriteType, edit_mode=$this->EditMode" );
$ef = new EntryForm( $_SERVER['REQUEST_URI'], $this->Values, $this->EditMode );
$ef->NoHelp(); // Prefer this style, for the moment
$html = '
";
if ( $ef->EditMode ) {
$html .= '';
$html .= $ef->EndForm();
}
return $html;
}
/**
* Render input file to import ics in calendar user
*
* @return string The string of html to be output
*/
function RenderImportIcs( $ef, $title = null ) {
if ( !$ef->EditMode ) return;
if ( $title == null ) $title = i18n("Import ICS file to new collection");
$html = ( $title == "" ? "" : $ef->BreakLine(translate($title)) );
$html .= sprintf( "
%s
\n", translate("WARNING: all events in this path will be deleted before inserting all of the ics file"));
$html .= $ef->DataEntryLine( translate("Calendar"), "%s", "text", "path_ics",
array( "size" => 20,
"title" => translate("set the path to store your ics ex:home if you get it by caldav.php/me/home/"),
"help" => translate("WARNING: all events in this path will be deleted before inserting all of the ics file")
)
, $this->prefix );
$html .= $ef->DataEntryLine( translate("Your .ics calendar"), "%s", "file", "ics_file",
array( "size" => 20, "title" => translate("Upload your .ics calendar in ical format ")), $this->prefix );
return $html;
}
/**
* Render the user's relationships to other users & resources
*
* @return string The string of html to be output
*/
function RenderRelationshipsFrom( $ef, $title = null ) {
global $session, $c;
if ( $title == null ) $title = i18n("Relationships from this user");
$browser = new Browser("");
$browser->AddHidden( 'user_link', "'base_url/usr.php?user_no=' || user_no || '\">' || fullname || ''" );
$browser->AddColumn( 'rt_name', translate('Relationship') );
$browser->AddColumn( 'fullname', translate('Linked To'), 'left', '##user_link##' );
$browser->AddHidden( 'confers' );
$browser->AddColumn( 'email', translate('EMail') );
$browser->SetJoins( 'relationship NATURAL JOIN relationship_type rt LEFT JOIN usr ON (to_user = user_no)' );
$browser->SetWhere( "from_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' );
$browser->AddOrder( 'fullname', 'A', 0, 1 );
}
if ( $c->enable_row_linking ) {
$browser->RowFormat( "
\n";
return $html;
}
/**
* Render the user's relationships to other users & resources
*
* @return string The string of html to be output
*/
function RenderRelationshipsTo( $ef, $title = null ) {
global $session, $c;
if ( $title == null ) $title = i18n("Relationships to this user");
$browser = new Browser("");
$browser->AddHidden( 'user_link', "'base_url/usr.php?user_no=' || user_no || '\">' || fullname || ''" );
$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', '', "'base_url/usr.php?edit=1&user_no=$this->user_no&action=delete_relationship&from_user=' || user_no || '\">Delete'" );
}
$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( "
\n", "
\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") ) {
if ( isset($this->roles['Group']) ) {
/**
* We only allow individuals to link to groups at this stage.
*/
$groupsql = 'AND NOT EXISTS (SELECT 1 FROM role_member WHERE role_no = 2 AND user_no=usr.user_no)';
}
else $groupsql = '';
$sql = <<user_no))
AND user_no != $this->user_no $groupsql ORDER BY fullname
EOSQL;
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('', htmlspecialchars(translate("Add Relationship")))
) );
}
$html = ( $title == "" ? "" : $ef->BreakLine(translate($title)) );
$html .= "
\n";
$html .= $browser->Render();
$html .= "
\n";
return $html;
}
/**
* Render the user's collections
*
* @return string The string of html to be output
*/
function RenderCollections( $ef, $title = null ) {
global $session, $c;
if ( $title == null ) $title = i18n("This user's collections");
$browser = new Browser("");
$browser->AddHidden( 'collection_link', "'base_url/collection.php?user_no=' || user_no || '&dav_name=' || dav_name || '\">' || dav_name || ''" );
$browser->AddColumn( 'dav_name', translate('Collection Path'), 'left', '##collection_link##' );
$browser->AddColumn( 'is_calendar', translate('Is a Calendar?'), 'centre', '', "CASE WHEN is_calendar THEN 'Yes' ELSE 'No' END" );
$browser->AddColumn( 'created', translate('Created On'), 'centre', '', "to_char(created,'YYYY-MM-DD HH24:MI')" );
$browser->AddColumn( 'modified', translate('Changed On'), 'centre', '', "to_char(created,'YYYY-MM-DD HH24:MI')" );
if ( $ef->EditMode ) {
$browser->AddColumn( 'TRUE', translate('Action'), 'left', "base_url/usr.php?user_no=$this->user_no&dav_name=##URL:dav_name##&action=delete_collection\">Delete" );
}
$browser->SetJoins( 'collection LEFT JOIN usr USING (user_no)' );
$browser->SetWhere( "collection.user_no = $this->user_no" );
if ( isset( $_GET['o']) && isset($_GET['d']) ) {
$browser->AddOrder( $_GET['o'], $_GET['d'] );
}
else
$browser->AddOrder( 'dav_name', 'A' );
$browser->RowFormat( "