The integration between WebCalendar and Drupal is working pretty good now (after some travail - of my own doing). The one feature of Webcalendar 1.1.x that I really wanted, however, was the remote publishing feature. I have tried several ways but can't get remote publishing working properly. I can publish to a webcalendar install, just not when it is integrated with Drupal.

Has anyone else had success with this. I can subscribe to calendars that are integrated in Drupal, but I can't publish to them. I've tried use both Sunbird and iCal clients and neither worked (with both clean urls on and off). This leads to believe (perhaps foolishly) that there is something in the integration piece or with Drupal that is causing issues.

Any successes in doing this? Any ideas?

Comments

jaredwiltshire’s picture

Yeah I tried to use this the other day as well. Unfortunately icalclient.php is hardcoded to authenticate against the WebCalendar database. I may be able include a modified version at a later date.

hintbw’s picture

Title: icalclient.php function doesn't work correctly » icalclient.php function doesn't work correctly -RESOLVED
Status: Active » Needs review

Jared,

Fortunately I decided to dive into the code tonight and see if I couldn't get the functionality that I needed. I succeeded and am now able to publish to my WebCalendar embedded in Drupal. Here are the relevant code snippets:

The first is an additional function that had to be ported to the user-app-drupal.php file. This can simply be placed at the bottom of the user-app-drupal.php file and included for future releases of the module (once the code has been tested of course).

/**
 * Check to see if a given login/password is valid.
 *
 * If invalid, the error message will be placed in $error. If true the webcal user will be placed in the returned variable.
 *
 * @param string $login    User login
 * @param string $password User password
 * @param bool $#silent  if truem do not return any $error
 *
 * @return string Webcal username on True, returns bool FALSE otherwise
 *
 * @global string Error message
 */
function user_valid_login ( $login, $password, $silent=false ) {
  global $error, $app_user_table, $app_session_table;
  global $app_host, $app_login, $app_pass, $app_db, $app_same_db;
  global $c, $db_host, $db_login, $db_password, $db_database;
  $ret = false;
  
  if ($app_same_db != '1') {
  	$c = dbi_connect($app_host, $app_login, $app_pass, $app_db);
  }
  $res = dbi_execute ( "SELECT name, uid FROM $app_user_table WHERE name = ? AND pass = ?" , array ( $login , md5( $password ) ) );
  if ( $res ) {
    $row = dbi_fetch_row ( $res );
    if ( $row && $row[0] != '' ) {
      // MySQL seems to do case insensitive matching, so double-check
      // the login.
      if ( $row[0] == $login ) {
        $ret = $row[1]; //found login & password
      } else if ( ! $silent ) {
        $error = translate ( 'Invalid login', true ) . ': ' .
          translate( 'incorrect password', true );
      }
    } else if ( ! $silent ) {
      	$error = translate ( 'Invalid login', true );
     	 	// Could be no such user or bad password
      	// Check if user exists, so we can tell.
      	$res2 = dbi_execute ( "SELECT name, uid FROM $app_user_table WHERE name = ?" , array ( $login ) );
      	if ( $res2 ) {
        	$row = dbi_fetch_row ( $res2 );
        	if ( $row && ! empty ( $row[0] ) ) {
          	// got a valid username, but wrong password
          	$error = translate ( 'Invalid login', true ) . ': ' .
           	 translate( 'incorrect password', true );
        	} else {
          	// No such user.
          	$error = translate ( 'Invalid login', true) . ': ' .
            translate( 'no such user', true );
        	}
        	dbi_free_result ( $res2 );
      	}
    	}
   	 dbi_free_result ( $res );
  	} else if ( ! $silent ) {
    $error = db_error();
  }
  // if application is in a separate db, we have to connect back to the webcal db
  if ($app_same_db != '1') {
  	$c = dbi_connect($db_host, $db_login, $db_password, $db_database);
	}
		return $ret;
}

The other issue that had to be resolved was in the icalclient.php file, I have highlighted where the changed lines are. It would probably be worthwhile to produce an icalclient.php file that drupal users can simply drop in a replace (similar to what we have to do with the login-app.php file).

unset ($_ENV['REMOTE_USER']);
if ( empty ( $login ) ) {
  if (!isset($_SERVER['PHP_AUTH_USER'])) {
    unset($_SERVER['PHP_AUTH_PW']);
    header('WWW-Authenticate: Basic realm="' . $appStr . '"' );
    header('HTTP/1.0 401 Unauthorized');
    exit;

  } else {
    $valid_login = ( user_valid_login ( $_SERVER['PHP_AUTH_USER'],
      $_SERVER['PHP_AUTH_PW'], false ) );
    if($valid_login) {
      $login = $valid_login;
    } else {

      unset($_SERVER['PHP_AUTH_USER']);
      unset($_SERVER['PHP_AUTH_PW']);
      //TODO should be able code this better to eliminate duplicate code
      header('WWW-Authenticate: Basic realm="' . $appStr . '"' );
      header('HTTP/1.0 401 Unauthorized');
      exit;
    } 
  }
}
jaredwiltshire’s picture

Looks great. I'll review it and commit to CVS soon.

jaredwiltshire’s picture

Title: icalclient.php function doesn't work correctly -RESOLVED » iCalendar publishing doesnt work
Category: support » bug

Sorry for the hugely long delay..

I'll be looking at this today.

jaredwiltshire’s picture

Status: Needs review » Fixed

Fixed in CVS.

Username is the users uid.

Anonymous’s picture

Status: Fixed » Closed (fixed)