[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare * 4 * http://www.egroupware.org * 5 * -------------------------------------------- * 6 * This program is free software; you can redistribute it and/or modify it * 7 * under the terms of the GNU General Public License as published by the * 8 * Free Software Foundation; either version 2 of the License, or (at your * 9 * option) any later version. * 10 \**************************************************************************/ 11 12 /* $Id: admin_account.php 20295 2006-02-15 12:31:25Z $ */ 13 14 // Little file to setup a demo install 15 16 $GLOBALS['egw_info'] = array( 17 'flags' => array( 18 'noheader' => True, 19 'nonavbar' => True, 20 'currentapp' => 'home', 21 'noapi' => True 22 )); 23 include ('./inc/functions.inc.php'); 24 25 // Authorize the user to use setup app and load the database 26 // Does not return unless user is authorized 27 if(!$GLOBALS['egw_setup']->auth('Config') || get_var('cancel',Array('POST'))) 28 { 29 Header('Location: index.php'); 30 exit; 31 } 32 $GLOBALS['egw_setup']->loaddb(true); 33 34 $error = ''; 35 if ($_POST['submit']) 36 { 37 /* Posted admin data */ 38 $passwd = get_var('passwd',Array('POST')); 39 $passwd2 = get_var('passwd2',Array('POST')); 40 $username = get_var('username',Array('POST')); 41 $fname = get_var('fname',Array('POST')); 42 $lname = get_var('lname',Array('POST')); 43 44 if($passwd != $passwd2 || !$username) 45 { 46 $error = '<p>'.lang('Passwords did not match, please re-enter') . ".</p>\n"; 47 } 48 if(!$username) 49 { 50 $error = '<p>'.lang('You must enter a username for the admin') . ".</p>\n"; 51 } 52 } 53 if(!$_POST['submit'] || $error) 54 { 55 $tpl_root = $GLOBALS['egw_setup']->html->setup_tpl_dir('setup'); 56 $setup_tpl = CreateObject('setup.Template',$tpl_root); 57 $setup_tpl->set_file(array( 58 'T_head' => 'head.tpl', 59 'T_footer' => 'footer.tpl', 60 'T_alert_msg' => 'msg_alert_msg.tpl', 61 'T_login_main' => 'login_main.tpl', 62 'T_login_stage_header' => 'login_stage_header.tpl', 63 'T_admin_account' => 'admin_account.tpl' 64 )); 65 $setup_tpl->set_block('T_login_stage_header','B_multi_domain','V_multi_domain'); 66 $setup_tpl->set_block('T_login_stage_header','B_single_domain','V_single_domain'); 67 68 $GLOBALS['egw_setup']->html->show_header(lang('Create admin account')); 69 70 $setup_tpl->set_var(array( 71 'error' => $error, 72 'username' => $username, 73 'fname' => $fname, 74 'lname' => $lname, 75 )); 76 $setup_tpl->set_var('action_url','admin_account.php'); 77 $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.')); 78 $setup_tpl->set_var('lang_deleteall',lang('Delete all existing SQL accounts, groups, ACLs and preferences (normally not necessary)?')); 79 80 $setup_tpl->set_var('detailadmin',lang('Details for Admin account')); 81 $setup_tpl->set_var('adminusername',lang('Admin username')); 82 $setup_tpl->set_var('adminfirstname',lang('Admin first name')); 83 $setup_tpl->set_var('adminlastname',lang('Admin last name')); 84 $setup_tpl->set_var('adminpassword',lang('Admin password')); 85 $setup_tpl->set_var('adminpassword2',lang('Re-enter password')); 86 $setup_tpl->set_var('create_demo_accounts',lang('Create demo accounts')); 87 88 $setup_tpl->set_var('lang_submit',lang('Save')); 89 $setup_tpl->set_var('lang_cancel',lang('Cancel')); 90 $setup_tpl->pparse('out','T_admin_account'); 91 $GLOBALS['egw_setup']->html->show_footer(); 92 } 93 else 94 { 95 /* Begin transaction for acl, etc */ 96 $GLOBALS['egw_setup']->db->transaction_begin(); 97 98 if($_POST['delete_all']) 99 { 100 /* Now, clear out existing tables */ 101 foreach(array($GLOBALS['egw_setup']->accounts_table,$GLOBALS['egw_setup']->prefs_table,$GLOBALS['egw_setup']->acl_table,'egw_access_log') as $table) 102 { 103 $GLOBALS['egw_setup']->db->delete($table,'1=1',__LINE__,__FILE__); 104 } 105 } 106 /* Create the demo groups */ 107 $defaultgroupid = (int)$GLOBALS['egw_setup']->add_account('Default','Default','Group',False,False); 108 $admingroupid = (int)$GLOBALS['egw_setup']->add_account('Admins','Admin','Group',False,False); 109 110 if (!$defaultgroupid || !$admingroupid) 111 { 112 echo '<p><b>'.lang('Error in group-creation !!!')."</b></p>\n"; 113 echo '<p>'.lang('click <a href="index.php">here</a> to return to setup.')."</p>\n"; 114 $GLOBALS['egw_setup']->db->transaction_abort(); 115 exit; 116 } 117 118 /* Group perms for the default group */ 119 $GLOBALS['egw_setup']->add_acl(array('addressbook','calendar','infolog','felamimail','preferences','home','manual'),'run',$defaultgroupid); 120 121 // give admin access to all apps, to save us some support requests 122 $all_apps = array(); 123 $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->applications_table,'app_name','app_enabled < 3',__LINE__,__FILE__); 124 while ($GLOBALS['egw_setup']->db->next_record()) 125 { 126 $all_apps[] = $GLOBALS['egw_setup']->db->f('app_name'); 127 } 128 $GLOBALS['egw_setup']->add_acl($all_apps,'run',$admingroupid); 129 130 function insert_default_prefs($accountid) 131 { 132 $defaultprefs = array( 133 'common' => array( 134 'maxmatchs' => 15, 135 'template_set' => 'idots', 136 'theme' => 'idots', 137 'navbar_format' => 'icons', 138 'tz_offset' => 0, 139 'dateformat' => 'Y/m/d', 140 'timeformat' => '24', 141 'lang' => get_var('ConfigLang',Array('POST','COOKIE'),'en'), 142 'default_app' => 'calendar', 143 'currency' => '$', 144 'show_help' => True, 145 'max_icons' => 12, 146 ), 147 'calendar' => array( 148 'workdaystarts' => 9, 149 'workdayends' => 17, 150 'weekdaystarts' => 'Monday', 151 'defaultcalendar' => 'day', 152 'planner_start_with_group' => $GLOBALS['defaultgroupid'], 153 ), 154 ); 155 156 foreach ($defaultprefs as $app => $prefs) 157 { 158 // only insert them, if they not already exist 159 $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->prefs_table,'*',array( 160 'preference_owner' => $accountid, 161 'preference_app' => $app, 162 ),__LINE__,__FILE__); 163 if (!$GLOBALS['egw_setup']->db->next_record()) 164 { 165 $GLOBALS['egw_setup']->db->insert($GLOBALS['egw_setup']->prefs_table,array( 166 'preference_value' => serialize($prefs) 167 ),array( 168 'preference_owner' => $accountid, 169 'preference_app' => $app, 170 ),__LINE__,__FILE__); 171 } 172 } 173 } 174 insert_default_prefs(-2); // set some default prefs 175 176 /* Creation of the demo accounts is optional - the checkbox is on by default. */ 177 if(get_var('create_demo',Array('POST'))) 178 { 179 // Create 3 demo accounts 180 $GLOBALS['egw_setup']->add_account('demo','Demo','Account','guest'); 181 $GLOBALS['egw_setup']->add_account('demo2','Demo2','Account','guest'); 182 $GLOBALS['egw_setup']->add_account('demo3','Demo3','Account','guest'); 183 } 184 185 /* Create records for administrator account, with Admins as primary and Default as additional group */ 186 $accountid = $GLOBALS['egw_setup']->add_account($username,$fname,$lname,$passwd,'Admins',True); 187 if (!$accountid) 188 { 189 echo '<p><b>'.lang('Error in admin-creation !!!')."</b></p>\n"; 190 echo '<p>'.lang('click <a href="index.php">here</a> to return to setup.')."</p>\n"; 191 $GLOBALS['egw_setup']->db->transaction_abort(); 192 exit; 193 } 194 $GLOBALS['egw_setup']->add_acl('phpgw_group',$admingroupid,$accountid); 195 $GLOBALS['egw_setup']->add_acl('phpgw_group',$defaultgroupid,$accountid); 196 197 $GLOBALS['egw_setup']->db->transaction_commit(); 198 199 Header('Location: index.php'); 200 exit; 201 } 202 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |