steffen: server/kolab-webadmin/kolab-webadmin/www/admin/distributionlist index.php, NONE, 1.1 list.php, NONE, 1.1
cvs at intevation.de
cvs at intevation.de
Mon May 17 17:24:29 CEST 2004
Author: steffen
Update of /kolabrepository/server/kolab-webadmin/kolab-webadmin/www/admin/distributionlist
In directory doto:/tmp/cvs-serv23429/kolab-webadmin/www/admin/distributionlist
Added Files:
index.php list.php
Log Message:
new webinterface for the kolab server
--- NEW FILE: index.php ---
<?php
/*
(c) 2004 Klarlvdalens Datakonsult AB
(c) 2003 Tassilo Erlewein <tassilo.erlewein at erfrakon.de>
(c) 2003 Martin Konold <martin.konold at erfrakon.de>
This program is Free Software under the GNU General Public License (>=v2).
Read the file COPYING that comes with this packages for details.
*/
require_once('admin/include/mysmarty.php');
require_once('admin/include/headers.php');
require_once('admin/include/authenticate.php');
$errors = array();
/**** Authentication etc. ***/
$sidx = 'distlist';
if( $auth->group() != 'maintainer' && $auth->group() != 'admin') {
array_push($errors, "Error: You don't have Permissions to access this Menu");
}
require_once('admin/include/menu.php');
/**** Submenu for current page ***/
$menuitems[$sidx]['selected'] = 'selected';
/**** Extract data from LDAP ***/
// Get all entries & dynamically split the letters with growing entries
if( !$errors ) {
if (isset($_SESSION['base_dn'])) $base_dn = $_SESSION['base_dn'];
else $base_dn = 'k=kolab';
$filter = "(&(cn=*)(objectclass=groupOfNames))";
$result = ldap_search($ldap->connection, $base_dn, $filter);
if( $result ) {
$count = ldap_count_entries($ldap->connection, $result);
$title = "Manage Distribution Lists ($count Lists)";
$template = 'distlistall.tpl';
ldap_sort($ldap->connection,$result,'cn');
$entry = ldap_first_entry($ldap->connection, $result);
while( $entry ) {
$attrs = ldap_get_attributes($ldap->connection, $entry);
$dn = ldap_get_dn($ldap->connection,$entry);
$cn = $attrs['cn'][0];
$deleteflag = $attrs['deleteflag'][0];
$homeserver = 'not yet implemented';
$entries[] = array( 'dn' => $dn,
'cn' => $cn,
'deleted' => $deleteflag );
$entry = ldap_next_entry( $ldap->connection,$entry );
}
}
}
/**** Insert into template and output ***/
$smarty =& new MySmarty();
$smarty->assign( 'errors', $errors );
$smarty->assign( 'uid', $auth->uid() );
$smarty->assign( 'group', $auth->group() );
$smarty->assign( 'page_title', $menuitems[$sidx]['title'] );
$smarty->assign( 'entries', $entries );
$smarty->assign( 'menuitems', $menuitems );
$smarty->assign( 'submenuitems',
array_key_exists('submenu',
$menuitems[$sidx])?$menuitems[$sidx]['submenu']:array() );
$smarty->assign( 'maincontent', $template );
$smarty->display('page.tpl');
/*
Local variables:
mode: php
indent-tabs-mode: t
tab-width: 4
buffer-file-coding-system: utf-8
End:
*/
?>
--- NEW FILE: list.php ---
<?php
require_once('admin/include/mysmarty.php');
require_once('admin/include/headers.php');
require_once('admin/include/authenticate.php');
require_once('admin/include/form.class.php');
/**** Authentication etc. ***/
$errors = array();
$messages = array();
$sidx = 'distlist';
$contenttemplate = 'formcontainer.tpl';
$valid_actions = array('firstsave','save','modify','create','delete','kill');
if( $auth->group() != 'maintainer' && $auth->group() != 'admin') {
array_push($errors, "Error: You don't have Permissions to access this Menu");
}
require_once('admin/include/menu.php');
function checkemaillist( $form, $key, $value ) {
if( $key == 'members' ) {
$lst = array_unique( array_filter( array_map( 'trim', preg_split( '/\n/', $value ) ), 'strlen') );
foreach( $lst as $a ) {
if( !ereg('.*@.*', $a ) ) return 'Invalid email address syntax';
}
}
return '';
}
function fill_form_for_modify( &$form, &$ldap_object ) {
if (is_array($ldap_object['cn'])) $cn = $ldap_object['cn'][0];
else $cn = $ldap_object['cn'];
$form->entries['cn']['value'] = $cn;
$form->entries['action']['value'] = 'save';
$m = $ldap_object['member'];
unset( $m['count'] );
$form->entries['members']['value'] = join("\r\n", $m);
}
/**** Submenu for current page ***/
$menuitems[$sidx]['selected'] = 'selected';
$heading = '';
/**** Form/data handling ***/
if (!empty($_REQUEST['action']) &&
in_array($_REQUEST['action'],$valid_actions)) $action = trim($_REQUEST['action']);
else array_push($errors, "Error: need valid action to proceed");
$dn="";
if (!empty($_REQUEST['dn'])) $dn = trim($_REQUEST['dn']);
if (!$errors && $auth->group() != 'maintainer' && $auth->group() != 'admin')
array_push($errors, "Error: You don't have the required Permissions");
$entries = array( 'cn' => array( 'name' => 'List Name',
'validation' => 'notempty',
'comment' => 'Required' ),
'members' => array( 'name' => 'Members',
'type' => 'textarea',
'comment' => 'One address per line',
'validation' => 'checkemaillist'));
$entries['action'] = array( 'name' => 'action',
'type' => 'hidden' );
if( $action == 'modify' || $action == 'delete' ) {
if( $_REQUEST['dn'] ) {
$dn = $_REQUEST['dn'];
} else {
array_push($errors, "Error: DN required for $action operation");
}
}
$form =& new KolabForm( 'vcard', 'createaddr.tpl', $entries );
if( !$errors ) {
switch( $action ) {
case 'create':
$form->entries['action']['value'] = 'firstsave';
$heading = 'Add Distribution List';
$content = $form->outputForm();
break;
case 'firstsave':
case 'save':
if( $form->isSubmitted() ) {
if( !$form->validate() ) {
$form->setValues();
$content = $form->outputForm();
} else {
$sf_root = $_SESSION['base_dn'];
$ldap_object = array('objectClass' => 'groupOfNames');
$cn = trim($_POST['cn']);
$ldap_object['cn'] = $cn;
if ($action == "save") {
if (!$errors) {
if (!empty($ldap_object['cn'])) $newdn = "cn=".$ldap_object['cn'].",".$sf_root;
else $newdn = $dn;
if (strcmp($dn,$newdn) != 0) {
if (($result=ldap_read($ldap->connection,$dn,"(objectclass=*)")) &&
($entry=ldap_first_entry($ldap->connection,$result)) &&
($oldattrs=ldap_get_attributes($ldap->connection,$entry))) {
if (!ldap_add($ldap->connection,$newdn, $ldap_object)
|| !ldap_delete($ldap->connection,$dn)) {
array_push($errors, "LDAP Error: could not rename ".$dn.
" to ".$newdn." ".ldap_error($ldap->connection));
} else {
$messages[] = 'Shared folder updated';
}
$dn = $newdn;
} else array_push($errors,"LDAP Error: could not read ".$dn." ".ldap_error($ldap->connection));
} else {
if (!ldap_modify($ldap->connection, $dn, $ldap_object))
array_push($errors, "LDAP Error: could not modify object ".$dn." ".ldap_error($ldap->connection));
else $messages[] = 'Shared folder updated';
}
}
} else {
if (!$errors) {
$dn = "cn=".$ldap_object['cn'].",".$sf_root;
if ($dn && !ldap_add($ldap->connection, $dn, $ldap_object))
array_push($errors, "LDAP Error: could not add object ".$dn." ".ldap_error($ldap->connection));
else $messages[] = 'Shared folder '.$cn.' added';
}
if ($errors) {
//print("<div class=\"maintitle\"> Create New Address Book Entry </div>\n");
$form->entries['action']['value'] = 'create';
break;
}
}
$form->entries['action']['value'] = 'save';
$form->entries['dn'] = array( 'type' => 'hidden', 'value' => $dn );
$form->entries['cn']['attrs'] = 'readonly';
$heading = 'Modify Distribution List';
fill_form_for_modify( $form, $ldap_object );
$content = $form->outputForm();
}
}
break;
case 'modify':
$result = $ldap->search( $dn, '(objectClass=groupOfNames)' );
if( $result ) {
$ldap_object = ldap_get_entries( $ldap->connection, $result );
if( $ldap_object['count'] == 1 ) {
fill_form_for_modify( $form, $ldap_object[0] );
$form->entries['action']['value'] = 'save';
$form->entries['dn'] = array( 'type' => 'hidden', 'value' => $dn );
$form->entries['cn']['attrs'] = 'readonly';
$heading = 'Modify Distribution List';
$content = $form->outputForm();
} else {
array_push($errors, "Error: Multiple results returned for DN $dn");
}
}
break;
case 'delete':
$result = $ldap->search( $dn, '(objectClass=sharedfolder)' );
if( $result ) {
$ldap_object = ldap_get_entries( $ldap->connection, $result );
if( $ldap_object['count'] == 1 ) {
fill_form_for_modify( $form, $ldap_object[0] );
$form->entries['action']['value'] = 'kill';
foreach( $form->entries as $key => $val ) {
$form->entries[$key]['attrs'] = 'readonly';
}
$form->submittext = 'Delete';
$heading = 'Delete Shared Folder';
$content = $form->outputForm();
} else {
array_push($errors, "Error: Multiple results returned for DN $dn");
}
}
break;
case 'kill':
if (!$errors) {
$ldap_object = array();
$ldap_object['deleteflag'] = 'TRUE';
if( ldap_modify($ldap->connection, $dn, $ldap_object) ) {
$messages[] = 'Shared folder '.$_REQUEST['cn'].' marked for deletion';
$heading = 'Entry Deleted';
$contenttemplate = 'sfdeleted.tpl';
} else {
array_push($errors, "LDAP Error: could mark ".$dn." for deletion: ".ldap_error($link));
}
}
break;
}
}
/**** Insert into template and output ***/
$smarty =& new MySmarty();
$smarty->assign( 'errors', $errors );
$smarty->assign( 'heading', $heading );
$smarty->assign( 'uid', $auth->uid() );
$smarty->assign( 'group', $auth->group() );
$smarty->assign( 'page_title', $menuitems[$sidx]['title'] );
$smarty->assign( 'menuitems', $menuitems );
$smarty->assign( 'submenuitems',
array_key_exists('submenu',
$menuitems[$sidx])?$menuitems[$sidx]['submenu']:array() );
$smarty->assign( 'heading', $heading );
$smarty->assign( 'form', $content );
if( isset( $dn ) ) $smarty->assign( 'dn', $dn );
if( count($messages)>0) $smarty->assign( 'messages', $messages );
$smarty->assign( 'maincontent', $contenttemplate );
$smarty->display('page.tpl');
/*
Local variables:
mode: php
indent-tabs-mode: t
tab-width: 4
buffer-file-coding-system: utf-8
End:
*/
?>
More information about the commits
mailing list