2001-07-30 17:59:25 +02:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
2004-01-27 21:49:25 +01:00
|
|
|
* eGroupWare *
|
|
|
|
* http://www.egroupware.org *
|
2001-07-30 17:59:25 +02:00
|
|
|
* -------------------------------------------- *
|
|
|
|
* This program is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU General Public License as published by the *
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your *
|
|
|
|
* option) any later version. *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
// Little file to setup a demo install
|
|
|
|
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_info'] = array(
|
|
|
|
'flags' => array(
|
|
|
|
'noheader' => True,
|
|
|
|
'nonavbar' => True,
|
|
|
|
'currentapp' => 'home',
|
|
|
|
'noapi' => True
|
|
|
|
));
|
2001-12-11 05:36:40 +01:00
|
|
|
include('./inc/functions.inc.php');
|
2001-07-30 17:59:25 +02:00
|
|
|
|
|
|
|
// Authorize the user to use setup app and load the database
|
|
|
|
// Does not return unless user is authorized
|
2005-03-04 13:40:28 +01:00
|
|
|
if(!$GLOBALS['egw_setup']->auth('Config') || get_var('cancel',Array('POST')))
|
2001-09-17 04:23:41 +02:00
|
|
|
{
|
2001-12-11 05:36:40 +01:00
|
|
|
Header('Location: index.php');
|
2001-09-17 04:23:41 +02:00
|
|
|
exit;
|
2001-07-30 17:59:25 +02:00
|
|
|
}
|
2001-12-11 05:36:40 +01:00
|
|
|
|
2002-04-29 21:49:24 +02:00
|
|
|
if(!get_var('submit',Array('POST')))
|
2001-12-11 05:36:40 +01:00
|
|
|
{
|
2005-03-04 13:40:28 +01:00
|
|
|
$tpl_root = $GLOBALS['egw_setup']->html->setup_tpl_dir('setup');
|
2002-08-12 01:54:58 +02:00
|
|
|
$setup_tpl = CreateObject('setup.Template',$tpl_root);
|
2001-12-11 05:36:40 +01:00
|
|
|
$setup_tpl->set_file(array(
|
|
|
|
'T_head' => 'head.tpl',
|
|
|
|
'T_footer' => 'footer.tpl',
|
|
|
|
'T_alert_msg' => 'msg_alert_msg.tpl',
|
|
|
|
'T_login_main' => 'login_main.tpl',
|
|
|
|
'T_login_stage_header' => 'login_stage_header.tpl',
|
|
|
|
'T_setup_demo' => 'setup_demo.tpl'
|
|
|
|
));
|
|
|
|
$setup_tpl->set_block('T_login_stage_header','B_multi_domain','V_multi_domain');
|
|
|
|
$setup_tpl->set_block('T_login_stage_header','B_single_domain','V_single_domain');
|
2001-09-17 04:23:41 +02:00
|
|
|
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_setup']->html->show_header(lang('Demo Server Setup'));
|
2001-09-17 04:23:41 +02:00
|
|
|
|
2001-12-11 05:36:40 +01:00
|
|
|
$setup_tpl->set_var('action_url','setup_demo.php');
|
2003-12-29 22:12:37 +01:00
|
|
|
$setup_tpl->set_var('description',lang('<b>This will create 1 admin account and 3 demo accounts</b><br>The username/passwords are: demo/guest, demo2/guest and demo3/guest.'));
|
2004-01-26 04:17:55 +01:00
|
|
|
$setup_tpl->set_var('lang_deleteall',lang('Delete all existing SQL accounts, groups, ACLs and preferences (normally not necessary)?'));
|
2003-12-29 22:12:37 +01:00
|
|
|
|
2001-12-11 05:36:40 +01:00
|
|
|
$setup_tpl->set_var('detailadmin',lang('Details for Admin account'));
|
|
|
|
$setup_tpl->set_var('adminusername',lang('Admin username'));
|
|
|
|
$setup_tpl->set_var('adminfirstname',lang('Admin first name'));
|
|
|
|
$setup_tpl->set_var('adminlastname',lang('Admin last name'));
|
|
|
|
$setup_tpl->set_var('adminpassword',lang('Admin password'));
|
|
|
|
$setup_tpl->set_var('adminpassword2',lang('Re-enter password'));
|
|
|
|
$setup_tpl->set_var('create_demo_accounts',lang('Create demo accounts'));
|
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
$setup_tpl->set_var('lang_submit',lang('Save'));
|
|
|
|
$setup_tpl->set_var('lang_cancel',lang('Cancel'));
|
2001-12-11 05:36:40 +01:00
|
|
|
$setup_tpl->pparse('out','T_setup_demo');
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_setup']->html->show_footer();
|
2001-12-11 05:36:40 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Posted admin data */
|
2002-04-29 21:49:24 +02:00
|
|
|
$passwd = get_var('passwd',Array('POST'));
|
|
|
|
$passwd2 = get_var('passwd2',Array('POST'));
|
|
|
|
$username = get_var('username',Array('POST'));
|
|
|
|
$fname = get_var('fname',Array('POST'));
|
|
|
|
$lname = get_var('lname',Array('POST'));
|
2001-12-11 05:36:40 +01:00
|
|
|
|
2002-03-03 22:53:00 +01:00
|
|
|
if($passwd != $passwd2)
|
2001-12-11 05:36:40 +01:00
|
|
|
{
|
|
|
|
echo lang('Passwords did not match, please re-enter') . '.';
|
|
|
|
exit;
|
|
|
|
}
|
2002-03-03 22:53:00 +01:00
|
|
|
if(!$username)
|
2001-12-11 05:36:40 +01:00
|
|
|
{
|
|
|
|
echo lang('You must enter a username for the admin') . '.';
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_setup']->loaddb();
|
2001-12-11 05:36:40 +01:00
|
|
|
/* Begin transaction for acl, etc */
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_setup']->db->transaction_begin();
|
2001-12-11 05:36:40 +01:00
|
|
|
|
2004-01-26 04:17:55 +01:00
|
|
|
if($_POST['delete_all'])
|
2003-12-29 22:12:37 +01:00
|
|
|
{
|
|
|
|
/* Now, clear out existing tables */
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_setup']->db->query('DELETE FROM phpgw_accounts');
|
|
|
|
$GLOBALS['egw_setup']->db->query('DELETE FROM phpgw_preferences');
|
|
|
|
$GLOBALS['egw_setup']->db->query('DELETE FROM phpgw_acl');
|
2003-12-29 22:12:37 +01:00
|
|
|
}
|
2001-12-11 05:36:40 +01:00
|
|
|
/* Create the demo groups */
|
2005-03-04 13:40:28 +01:00
|
|
|
$defaultgroupid = (int)$GLOBALS['egw_setup']->add_account('Default','Default','Group',False,False);
|
|
|
|
$admingroupid = (int)$GLOBALS['egw_setup']->add_account('Admins','Admin','Group',False,False);
|
2004-07-13 00:06:13 +02:00
|
|
|
|
|
|
|
if (!$defaultgroupid || !$admingroupid)
|
|
|
|
{
|
|
|
|
echo '<p><b>'.lang('Error in group-creation !!!')."</b></p>\n";
|
|
|
|
echo '<p>'.lang('click <a href="index.php">here</a> to return to setup.')."</p>\n";
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_setup']->db->transaction_abort();
|
2004-07-13 00:06:13 +02:00
|
|
|
exit;
|
|
|
|
}
|
2001-07-30 17:59:25 +02:00
|
|
|
|
2002-04-15 00:12:59 +02:00
|
|
|
/* Group perms for the default group */
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_setup']->add_acl(array('addressbook','calendar','infolog','email','preferences','manual'),'run',$defaultgroupid);
|
2004-03-21 17:11:51 +01:00
|
|
|
|
|
|
|
// give admin access to all apps, to save us some support requests
|
|
|
|
$all_apps = array();
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_setup']->db->query('SELECT app_name FROM phpgw_applications WHERE app_enabled<3');
|
|
|
|
while ($GLOBALS['egw_setup']->db->next_record())
|
2004-03-21 17:11:51 +01:00
|
|
|
{
|
2005-03-04 13:40:28 +01:00
|
|
|
$all_apps[] = $GLOBALS['egw_setup']->db->f('app_name');
|
2004-03-21 17:11:51 +01:00
|
|
|
}
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_setup']->add_acl($all_apps,'run',$admingroupid);
|
2003-05-18 18:51:45 +02:00
|
|
|
|
|
|
|
function insert_default_prefs($accountid)
|
|
|
|
{
|
2003-09-09 00:21:22 +02:00
|
|
|
$defaultprefs = array(
|
2003-12-19 13:34:45 +01:00
|
|
|
'common' => array(
|
|
|
|
'maxmatchs' => 15,
|
|
|
|
'template_set' => 'idots',
|
|
|
|
'theme' => 'idots',
|
|
|
|
'navbar_format' => 'icons',
|
|
|
|
'tz_offset' => 0,
|
|
|
|
'dateformat' => 'Y/m/d',
|
|
|
|
'timeformat' => '24',
|
|
|
|
'lang' => get_var('ConfigLang',Array('POST','COOKIE'),'en'),
|
|
|
|
'default_app' => 'calendar',
|
|
|
|
'currency' => '$',
|
|
|
|
'show_help' => True,
|
2004-08-13 23:04:59 +02:00
|
|
|
'max_icons' => 12,
|
2003-09-09 00:21:22 +02:00
|
|
|
),
|
2003-12-19 13:34:45 +01:00
|
|
|
'calendar' => array(
|
|
|
|
'workdaystarts' => 9,
|
|
|
|
'workdayends' => 17,
|
|
|
|
'weekdaystarts' => 'Monday',
|
|
|
|
'defaultcalendar' => 'day',
|
2003-09-09 00:21:22 +02:00
|
|
|
'planner_start_with_group' => $GLOBALS['defaultgroupid'],
|
|
|
|
),
|
|
|
|
);
|
2003-05-18 18:51:45 +02:00
|
|
|
|
|
|
|
foreach ($defaultprefs as $app => $prefs)
|
|
|
|
{
|
2005-03-24 14:15:12 +01:00
|
|
|
// only insert them, if they not already exist
|
|
|
|
$GLOBALS['egw_setup']->db->select('phpgw_preferences','*',array(
|
|
|
|
'preference_owner' => $accountid,
|
|
|
|
'preference_app' => $app,
|
|
|
|
),__LINE__,__FILE__);
|
|
|
|
if (!$GLOBALS['egw_setup']->db->next_record())
|
|
|
|
{
|
|
|
|
$GLOBALS['egw_setup']->db->insert('phpgw_preferences',array(
|
|
|
|
'preference_value' => serialize($prefs)
|
|
|
|
),array(
|
|
|
|
'preference_owner' => $accountid,
|
|
|
|
'preference_app' => $app,
|
|
|
|
),__LINE__,__FILE__);
|
|
|
|
}
|
2003-05-18 18:51:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
insert_default_prefs(-2); // set some default prefs
|
2002-04-15 00:12:59 +02:00
|
|
|
|
|
|
|
/* Creation of the demo accounts is optional - the checkbox is on by default. */
|
2002-04-29 21:49:24 +02:00
|
|
|
if(get_var('create_demo',Array('POST')))
|
2001-12-11 05:36:40 +01:00
|
|
|
{
|
2003-12-29 22:12:37 +01:00
|
|
|
// Create 3 demo accounts
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_setup']->add_account('demo','Demo','Account','guest');
|
|
|
|
$GLOBALS['egw_setup']->add_account('demo2','Demo2','Account','guest');
|
|
|
|
$GLOBALS['egw_setup']->add_account('demo3','Demo3','Account','guest');
|
2001-12-11 05:36:40 +01:00
|
|
|
}
|
2001-09-17 04:23:41 +02:00
|
|
|
|
2003-12-29 22:12:37 +01:00
|
|
|
/* Create records for administrator account, with Admins as primary and Default as additional group */
|
2005-03-04 13:40:28 +01:00
|
|
|
$accountid = $GLOBALS['egw_setup']->add_account($username,$fname,$lname,$passwd,'Admins',True);
|
2004-07-13 00:06:13 +02:00
|
|
|
if (!$accountid)
|
|
|
|
{
|
|
|
|
echo '<p><b>'.lang('Error in admin-creation !!!')."</b></p>\n";
|
|
|
|
echo '<p>'.lang('click <a href="index.php">here</a> to return to setup.')."</p>\n";
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_setup']->db->transaction_abort();
|
2004-07-13 00:06:13 +02:00
|
|
|
exit;
|
|
|
|
}
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_setup']->add_acl('phpgw_group',$admingroupid,$accountid);
|
|
|
|
$GLOBALS['egw_setup']->add_acl('phpgw_group',$defaultgroupid,$accountid);
|
2002-03-03 22:53:00 +01:00
|
|
|
|
2004-01-17 17:39:40 +01:00
|
|
|
/* Clear the access log, since these are all new users anyway */
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_setup']->db->query('DELETE FROM phpgw_access_log');
|
2004-01-17 17:39:40 +01:00
|
|
|
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_setup']->db->transaction_commit();
|
2001-12-11 05:36:40 +01:00
|
|
|
|
|
|
|
Header('Location: index.php');
|
|
|
|
exit;
|
|
|
|
}
|
2001-07-30 17:59:25 +02:00
|
|
|
?>
|