phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] setup setup_demo.php templates/base/setup_demo.tpl


From: Dave Hall
Subject: [Phpgroupware-cvs] setup setup_demo.php templates/base/setup_demo.tpl
Date: Fri, 20 Oct 2006 13:40:28 +0000

CVSROOT:        /sources/phpgroupware
Module name:    setup
Changes by:     Dave Hall <skwashd>     06/10/20 13:40:28

Modified files:
        .              : setup_demo.php 
        templates/base : setup_demo.tpl 

Log message:
        make this a little more user freindly and fix the username root PEBKAC 
bug

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/setup/setup_demo.php?cvsroot=phpgroupware&r1=1.40&r2=1.41
http://cvs.savannah.gnu.org/viewcvs/setup/templates/base/setup_demo.tpl?cvsroot=phpgroupware&r1=1.1&r2=1.2

Patches:
Index: setup_demo.php
===================================================================
RCS file: /sources/phpgroupware/setup/setup_demo.php,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -b -r1.40 -r1.41
--- setup_demo.php      3 Oct 2006 14:04:58 -0000       1.40
+++ setup_demo.php      20 Oct 2006 13:40:28 -0000      1.41
@@ -5,12 +5,13 @@
        * @copyright Copyright (C) 2000-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
        * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
        * @package setup
-       * @version $Id: setup_demo.php,v 1.40 2006/10/03 14:04:58 Caeies Exp $
+       * @version $Id: setup_demo.php,v 1.41 2006/10/20 13:40:28 skwashd Exp $
        */
 
        // Little file to setup a demo install
 
-       $GLOBALS['phpgw_info']['flags'] = array(
+       $GLOBALS['phpgw_info']['flags'] = array
+       (
                'noheader'   => True,
                'nonavbar'   => True,
                'currentapp' => 'home',
@@ -42,19 +43,25 @@
         */
        function add_account($username, $first, $last, $passwd, $type='u')
        {
+               $person_id = 0;
                if($type=='u')
                {
-                       $addressmaster_id = -3; 
+                       $addressmaster_id = -3;//default value
                        $contacts = CreateObject('phpgwapi.contacts');
-                       $principal = array('per_prefix'     => $username,
+                       $principal = array
+                       (
                                           'per_first_name' => $first,
                                           'per_last_name'  => $last,
                                           'access'         => 'public',
-                                          'owner'          => 
$addressmaster_id);
+                               'owner'                         => 
$addressmaster_id,
+                               'preferred_org'         => 0,
+                               'preferred_address'     => 0
+                       );
                        $contact_type = 
$contacts->search_contact_type('Persons');
                        $person_id = $contacts->add_contact($contact_type, 
$principal);
                }
-               $account_info = array(
+               $account_info = array
+               (
                        'account_type'      => $type,
                        'account_lid'       => $username,
                        'account_passwd'    => $passwd,
@@ -72,80 +79,46 @@
                return $account_id;
        }
 
-       $GLOBALS['phpgw_setup']->loaddb();
-       if(!get_var('submit',Array('POST')))
+       /**
+        * Insert default preferences
+        * 
+        * @param int $accountid the account
+        * @param int $defaultgroupid the primary group id
+        */
+       function insert_default_prefs($accountid, $defaultgroupid)
        {
-               $tpl_root = 
$GLOBALS['phpgw_setup']->html->setup_tpl_dir('setup');
-               $setup_tpl = CreateObject('phpgwapi.Template',$tpl_root);
-               $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');
-               $setup_tpl->set_var('lang_cookies_must_be_enabled', 
lang('<b>NOTE:</b> You must have cookies enabled to use setup and header 
admin!') );
-
-               $GLOBALS['phpgw_setup']->html->show_header(lang('Demo Server 
Setup'));
-
-               $setup_tpl->set_var('action_url','setup_demo.php');
-
-               /* detect whether anything will be deleted before alerting */
-               $phpgw_setup->db->query("select config_value FROM phpgw_config 
WHERE config_name='account_repository'");
-               $phpgw_setup->db->next_record();
-               $account_repository = $phpgw_setup->db->f(0);
+               $defaultprefs = 
unserialize('a:3:{s:6:"common";a:10:{s:9:"maxmatchs";s:2:"15";s:12:"template_set";s:5:"idots";s:5:"theme";s:5:"idots";s:13:"navbar_format";s:14:"text_and_icons";s:9:"tz_offset";s:0:"";s:10:"dateformat";s:5:"Y/m/d";s:10:"timeformat";s:2:"24";s:4:"lang";s:2:"en";s:11:"default_app";s:0:"";s:8:"currency";s:1:"$";}s:11:"addressbook";a:1:{s:0:"";s:4:"True";}s:8:"calendar";a:4:{s:13:"workdaystarts";s:1:"9";s:11:"workdayends";s:2:"17";s:13:"weekdaystarts";s:6:"Monday";s:15:"defaultcalendar";s:9:"month.php";}}');
+               $defaultprefs['common']['show_help'] = '1';
+               $defaultprefs['calendar']['planner_start_with_group'] = 
$defaultgroupid;
 
-               $account_creation_notice = lang('This will create an admin 
account and (optionally) 3 demo accounts.<br />The username/passwords are: 
demo/guest, demo2/guest and demo3/guest.<br />');
-               if ($account_repository == 'sql')
-               {
-                       $phpgw_setup->db->query("select count(*) from 
phpgw_accounts");
-                       $phpgw_setup->db->next_record();
-                       $number_of_accounts = (int) $phpgw_setup->db->f(0);
-                       if ($number_of_accounts>0)
+               foreach ($defaultprefs as $app => $prefs)
                        {
-                               $account_creation_notice .= lang('<b>!!!THIS 
WILL DELETE ALL EXISTING ACCOUNTS!!!</b><br />');
+                       $prefs = addslashes(serialize($prefs));
+                       $GLOBALS['phpgw_setup']->db->query("INSERT INTO 
phpgw_preferences(preference_owner,preference_app,preference_value) 
VALUES($accountid,'$app','$prefs')",__FILE__,__LINE__);
                        }
                }
-               $setup_tpl->set_var('description', $account_creation_notice);
-               $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'));
 
-               $setup_tpl->set_var('lang_submit',lang('Save'));
-               $setup_tpl->set_var('lang_cancel',lang('Cancel'));
-               $setup_tpl->pparse('out','T_setup_demo');
-               $GLOBALS['phpgw_setup']->html->show_footer();
-       }
-       else
-       {
-               /* Posted admin data */
-               $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'));
+       $passwd         = $passwd2 = '';
+       $username       = '';
+       $fname          = '';
+       $lname          = '';
+       $create_demo = true;
 
-               if($passwd != $passwd2)
-               {
-                       echo lang('Passwords did not match, please re-enter') . 
'.';
-                       exit;
-               }
-               if(!$username)
+       $errors = array();
+       $GLOBALS['phpgw_setup']->loaddb();
+       if ( isset($_POST['submit']) && $_POST['submit'] )
                {
-                       echo lang('You must enter a username for the admin') . 
'.';
-                       exit;
-               }
+               /* Posted admin data */
+               $passwd         = $_POST['passwd'];
+               $passwd2        = $_POST['passwd2'];
+               $username       = $_POST['username'];
+               $fname          = $_POST['fname'];
+               $lname          = $_POST['lname'];
+               $create_demo = isset($_POST['create_demo']) && 
$_POST['create_demo'];
 
+               // We do this here so the denied accounts array is available - 
these is some expense in this, but it is a run once in a lifetime function - 
skwashd Nov2006
                /* Load up some configured values */
-               // fips added 'group_min_id', 'group_max_id', 'account_min_id' 
, 'account_max_id'
-               $GLOBALS['phpgw_setup']->db->query("SELECT 
config_name,config_value FROM phpgw_config WHERE config_name LIKE 'ldap%' OR 
config_name='account_repository' OR config_name='group_min_id' OR 
config_name='group_max_id' OR config_name='account_min_id' OR 
config_name='account_max_id'",__LINE__,__FILE__);
+               $GLOBALS['phpgw_setup']->db->query("SELECT 
config_name,config_value FROM phpgw_config WHERE config_name LIKE 'ldap%' OR 
config_name LIKE '%_id' OR config_name='account_repository'",__LINE__,__FILE__);
                while ($GLOBALS['phpgw_setup']->db->next_record())
                {
                        $config[$GLOBALS['phpgw_setup']->db->f('config_name')] 
= $GLOBALS['phpgw_setup']->db->f('config_value');
@@ -166,34 +139,6 @@
                $GLOBALS['phpgw_info']['server']['group_max_id']                
        = isset($config['group_max_id']) ? $config['group_max_id'] : 999;
                unset($config);
 
-
-               /**
-               * phpGroupWare dummy class
-               * @package setup
-               * @ignore
-               /
-               class phpgw
-               {
-                       /**
-                       * Database
-                       * @var object
-                       /
-                       var $db;
-
-                       /**
-                       * Common
-                       * @var object
-                        /
-                       var $common;
-
-                       /**
-                        * Accounts
-                        * @var object
-                        /
-                       var $accounts;
-               }
-               */
-
                $GLOBALS['phpgw'] = new phpgw;
                $GLOBALS['phpgw']->db       = $GLOBALS['phpgw_setup']->db;
                $GLOBALS['phpgw']->common   = CreateObject('phpgwapi.common');
@@ -205,17 +150,33 @@
                        exit;
                }
 
+               if ( $passwd == '' || $passwd2 == '' )
+               {
+                       $errors[] = lang('Password can not be empty');
+               }
+               
+               if ( $passwd != $passwd2 )
+               {
+                       $errors[] = lang('Passwords did not match, please 
re-enter');
+               }
+
+               if ( !$username )
+               {
+                       $errors[] = lang('You must enter a username for the 
admin');
+               }
+               else if ( 
isset($GLOBALS['phpgw_info']['server']['global_denied_users'][$username]) )
+               {
+                       $errors[] = lang('You can not use %1 as the admin 
username, please try again with another username', $username);
+                       $username = lang('changeme');
+               }
+
+               if ( !count($errors) )
+               {
                // Begin transaction for acl, etc
                $GLOBALS['phpgw_setup']->db->transaction_begin();
 
                // Now, clear out existing tables
                $contacts_to_delete = 
$GLOBALS['phpgw']->accounts->get_account_with_contact();
-//             $GLOBALS['phpgw_setup']->db->query('SELECT person_id from 
phpgw_accounts WHERE person_id is not null');
-//             $contacts_to_delete=array();
-//             while ($GLOBALS['phpgw_setup']->db->next_record())
-//             {
-//                     $contacts_to_delete[] = 
$GLOBALS['phpgw_setup']->db->f('person_id');
-//             }
                $GLOBALS['phpgw_setup']->db->query('DELETE FROM 
phpgw_accounts');
                $GLOBALS['phpgw_setup']->db->query('DELETE FROM 
phpgw_preferences');
                $GLOBALS['phpgw_setup']->db->query('DELETE FROM phpgw_acl');
@@ -223,7 +184,7 @@
                $contacts = CreateObject('phpgwapi.contacts');
                if(is_array($contacts_to_delete))
                {
-                       foreach(@$contacts_to_delete as $contact_id)
+                               foreach($contacts_to_delete as $contact_id)
                        {
                                $contacts->delete($contact_id, '', False);
                        }
@@ -233,9 +194,6 @@
                $defaultgroupid = 
intval(add_account('Default','Default','Group',$passwd,'g'));
                $admingroupid   = intval(add_account('Admins','Admin', 
'Group',$passwd,'g'));
 
-               // Create the addressmaster record
-               
//add_account('addressmaster','addressmaster','addressmaster','addressmaster');
-
                // Group perms for the default group
                $GLOBALS['phpgw_setup']->db->query("INSERT INTO 
phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) 
VALUES('addressbook','run'," . $defaultgroupid . ", 1)");
                $GLOBALS['phpgw_setup']->db->query("INSERT INTO 
phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) 
VALUES('filemanager','run'," . $defaultgroupid . ", 1)");
@@ -250,53 +208,20 @@
                $GLOBALS['phpgw_setup']->db->query("INSERT INTO 
phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('hrm','run'," 
. $defaultgroupid . ", 1)");
                $GLOBALS['phpgw_setup']->db->query("INSERT INTO 
phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('sms','run'," 
. $defaultgroupid . ", 1)");
 
-               /**
-                * Insert default preferences
-                * 
-                * @param $accountid
-                */
-               function insert_default_prefs($accountid)
-               {
-                       $defaultprefs = 
unserialize('a:3:{s:6:"common";a:10:{s:9:"maxmatchs";s:2:"15";s:12:"template_set";s:5:"idots";s:5:"theme";s:5:"idots";s:13:"navbar_format";s:14:"text_and_icons";s:9:"tz_offset";s:0:"";s:10:"dateformat";s:5:"Y/m/d";s:10:"timeformat";s:2:"24";s:4:"lang";s:2:"en";s:11:"default_app";s:0:"";s:8:"currency";s:1:"$";}s:11:"addressbook";a:1:{s:0:"";s:4:"True";}s:8:"calendar";a:4:{s:13:"workdaystarts";s:1:"9";s:11:"workdayends";s:2:"17";s:13:"weekdaystarts";s:6:"Monday";s:15:"defaultcalendar";s:9:"month.php";}}');
-                       $defaultprefs['common']['show_help'] = '1';
-                       $defaultprefs['calendar']['planner_start_with_group'] = 
$defaultgroupid;
-
-                       foreach ($defaultprefs as $app => $prefs)
-                       {
-                               $prefs = addslashes(serialize($prefs));
-                               $GLOBALS['phpgw_setup']->db->query("INSERT INTO 
phpgw_preferences(preference_owner,preference_app,preference_value) 
VALUES($accountid,'$app','$prefs')",__FILE__,__LINE__);
-                       }
-               }
-
-
-               insert_default_prefs(-2);       // set some default prefs
+                       insert_default_prefs(-2, $defaultgroupid);      // set 
some default prefs
 
                /* Creation of the demo accounts is optional - the checkbox is 
on by default. */
-               if(get_var('create_demo',Array('POST')))
+                       if ( $create_demo )
+                       {
+                               foreach ( array('demo', 'demo2', 'demo3') as 
$lid )
                {
                        /* Create records for demo accounts */
-                       $accountid = 
add_account('demo','Demo','Account','guest');
+                                       $accountid = add_account($lid, 'Demo', 
'Account', 'guest');
 
-                       /* User permissions based on group membership with 
additional user perms for the messenger and infolog apps */
+                                       /* User permissions based on group 
membership with additional user perm to deny password change for demo users  */
                        $GLOBALS['phpgw_setup']->db->query("INSERT INTO 
phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) 
VALUES('preferences','changepassword', " . $accountid . ",0)");
                        $GLOBALS['phpgw_setup']->db->query("INSERT INTO 
phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) 
VALUES('phpgw_group', '" . $defaultgroupid."'," . $accountid . ",1)");
-                       $GLOBALS['phpgw_setup']->db->query("INSERT INTO 
phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) 
VALUES('messenger','run'," . $accountid . ", 1)");
-                       $GLOBALS['phpgw_setup']->db->query("INSERT INTO 
phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) 
VALUES('infolog','run'," . $accountid . ", 1)");
-
-                       $accountid = 
add_account('demo2','Demo2','Account','guest');
-
-                       /* User permissions based solely on group membership */
-                       $GLOBALS['phpgw_setup']->db->query("INSERT INTO 
phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) 
VALUES('preferences','changepassword', ".$accountid.", 0)");
-                       $GLOBALS['phpgw_setup']->db->query("INSERT INTO 
phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) 
VALUES('phpgw_group','" . $defaultgroupid . "'," . $accountid . ",1)");
-
-                       $accountid = 
add_account('demo3','Demo3','Account','guest');
-
-                       /* User-specific perms, no group membership */
-                       $GLOBALS['phpgw_setup']->db->query("INSERT INTO 
phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) 
VALUES('preferences','changepassword', " . $accountid . ",0)");
-                       $GLOBALS['phpgw_setup']->db->query("INSERT INTO 
phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) 
VALUES('addressbook','run', " . $accountid . ", 1)");
-                       $GLOBALS['phpgw_setup']->db->query("INSERT INTO 
phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) 
VALUES('calendar','run', " . $accountid . ", 1)");
-                       $GLOBALS['phpgw_setup']->db->query("INSERT INTO 
phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) 
VALUES('notes','run', " . $accountid . ", 1)");
-                       $GLOBALS['phpgw_setup']->db->query("INSERT INTO 
phpgw_acl(acl_appname,acl_location,acl_account,acl_rights) VALUES('todo','run', 
" . $accountid . ", 1)");
+                               }
                }
 
                /* Create records for administrator account */
@@ -320,4 +245,64 @@
                Header('Location: index.php');
                exit;
        }
+       }
+       
+       if( !isset($_POST['submit']) || count($errors) )
+       {
+               $tpl_root = 
$GLOBALS['phpgw_setup']->html->setup_tpl_dir('setup');
+               $setup_tpl = CreateObject('phpgwapi.Template',$tpl_root);
+               $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');
+               $setup_tpl->set_var('lang_cookies_must_be_enabled', 
lang('<b>NOTE:</b> You must have cookies enabled to use setup and header 
admin!') );
+
+               $GLOBALS['phpgw_setup']->html->show_header(lang('Demo Server 
Setup'));
+
+               $setup_tpl->set_var('action_url','setup_demo.php');
+
+               /* detect whether anything will be deleted before alerting */
+               $phpgw_setup->db->query("select config_value FROM phpgw_config 
WHERE config_name='account_repository'");
+               $phpgw_setup->db->next_record();
+               $account_repository = $phpgw_setup->db->f(0);
+
+               $account_creation_notice = lang('This will create an admin 
account and (optionally) 3 demo accounts.<br />The username/passwords are: 
demo/guest, demo2/guest and demo3/guest.<br />');
+               if ($account_repository == 'sql')
+               {
+                       $phpgw_setup->db->query("select count(*) from 
phpgw_accounts");
+                       $phpgw_setup->db->next_record();
+                       $number_of_accounts = (int) $phpgw_setup->db->f(0);
+                       if ($number_of_accounts>0)
+                       {
+                               $account_creation_notice .= lang('<b>!!!THIS 
WILL DELETE ALL EXISTING ACCOUNTS!!!</b><br />');
+                       }
+               }
+               $setup_tpl->set_var(array
+               (
+                       'errors'                        => count($errors) ? 
('<div class="msg">'.implode("<br>\n", $errors).'</div>') : '',
+                       'description'           => $account_creation_notice,
+                       'detailadmin'           => lang('Details for Admin 
account'),
+                       'adminusername'         => lang('Admin username'),
+                       'adminfirstname'        => lang('Admin first name'),
+                       'adminlastname'         => lang('Admin last name'),
+                       'adminpassword'         => lang('Admin password'),
+                       'adminpassword2'        => lang('Re-enter password'),
+                       'create_demo_accounts' => lang('Create demo accounts'),
+                       'lang_submit'           => lang('Save'),
+                       'lang_cancel'           => lang('Cancel'),
+                       'val_username'          => $username,
+                       'val_fname'                     => $fname,
+                       'val_lname'                     => $lname,
+                       'checked_demo'          => $create_demo ? ' checked' : 
''
+               ));
+
+               $setup_tpl->pparse('out','T_setup_demo');
+               $GLOBALS['phpgw_setup']->html->show_footer();
+       }
 ?>

Index: templates/base/setup_demo.tpl
===================================================================
RCS file: /sources/phpgroupware/setup/templates/base/setup_demo.tpl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- templates/base/setup_demo.tpl       30 Dec 2004 11:35:10 -0000      1.1
+++ templates/base/setup_demo.tpl       20 Oct 2006 13:40:28 -0000      1.2
@@ -1,4 +1,5 @@
 <!-- BEGIN setup_demo -->
+{errors}
 <table cellspacing="0" cellpadding="2" style="{border: 1px solid #000000; 
width: 100%}">
   <tr>
     <td>{description}</td>
@@ -12,15 +13,15 @@
         <table border="0">
           <tr>
             <td>{adminusername}</td>
-            <td><input type="text" name="username"></td>
+            <td><input type="text" name="username" value="{val_username}"></td>
           </tr>
           <tr>
             <td>{adminfirstname}</td>
-            <td><input type="text" name="fname"></td>
+            <td><input type="text" name="fname" value="{val_fname}"></td>
           </tr>
           <tr>
             <td>{adminlastname}</td>
-            <td><input type="text" name="lname"></td>
+            <td><input type="text" name="lname" value="{val_lname}"></td>
           </tr>
           <tr>
             <td>{adminpassword}</td>
@@ -32,7 +33,7 @@
           </tr>
           <tr>
             <td>{create_demo_accounts}</td>
-            <td><input type="checkbox" name="create_demo" checked></td>
+            <td><input type="checkbox" name="create_demo" {checked_demo}></td>
           </tr>
           <tr>
             <td><input type="submit" name="submit" value="{lang_submit}"> </td>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]