[763] | 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 | |
---|
| 13 | // Little file to setup a demo install |
---|
| 14 | |
---|
| 15 | $GLOBALS['phpgw_info']['flags'] = array( |
---|
| 16 | 'noheader' => True, |
---|
| 17 | 'nonavbar' => True, |
---|
| 18 | 'currentapp' => 'home', |
---|
| 19 | 'noapi' => True |
---|
| 20 | ); |
---|
| 21 | include('./inc/functions.inc.php'); |
---|
| 22 | |
---|
| 23 | // Authorize the user to use setup app and load the database |
---|
| 24 | // Does not return unless user is authorized |
---|
| 25 | if(!$GLOBALS['phpgw_setup']->auth('Config') || get_var('cancel',Array('POST'))) |
---|
| 26 | { |
---|
| 27 | Header('Location: index.php'); |
---|
| 28 | exit; |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | if(!get_var('submit',Array('POST'))) |
---|
| 32 | { |
---|
| 33 | $tpl_root = $GLOBALS['phpgw_setup']->html->setup_tpl_dir('setup'); |
---|
| 34 | $setup_tpl = CreateObject('setup.Template',$tpl_root); |
---|
| 35 | $setup_tpl->set_file(array( |
---|
| 36 | 'T_head' => 'head.tpl', |
---|
| 37 | 'T_footer' => 'footer.tpl', |
---|
| 38 | 'T_alert_msg' => 'msg_alert_msg.tpl', |
---|
| 39 | 'T_login_main' => 'login_main.tpl', |
---|
| 40 | 'T_login_stage_header' => 'login_stage_header.tpl', |
---|
| 41 | 'T_setup_demo' => 'setup_demo.tpl' |
---|
| 42 | )); |
---|
| 43 | $setup_tpl->set_block('T_login_stage_header','B_multi_domain','V_multi_domain'); |
---|
| 44 | $setup_tpl->set_block('T_login_stage_header','B_single_domain','V_single_domain'); |
---|
| 45 | |
---|
| 46 | $GLOBALS['phpgw_setup']->html->show_header(lang('Demo Server Setup')); |
---|
| 47 | |
---|
| 48 | $setup_tpl->set_var('action_url','setup_demo.php'); |
---|
| 49 | $setup_tpl->set_var('description',lang('<b>This will create the Admin account</b>')); |
---|
| 50 | $setup_tpl->set_var('lang_deleteall',lang('Delete all existing SQL accounts, groups, ACLs and preferences (normally not necessary)?')); |
---|
| 51 | |
---|
| 52 | $setup_tpl->set_var('detailadmin',lang('Details for Admin account')); |
---|
| 53 | $setup_tpl->set_var('adminusername',lang('Admin username')); |
---|
| 54 | $setup_tpl->set_var('adminfirstname',lang('Admin first name')); |
---|
| 55 | $setup_tpl->set_var('adminlastname',lang('Admin last name')); |
---|
| 56 | $setup_tpl->set_var('adminpassword',lang('Admin password')); |
---|
| 57 | $setup_tpl->set_var('adminpassword2',lang('Re-enter password')); |
---|
| 58 | $setup_tpl->set_var('create_demo_accounts',lang('Create demo accounts')); |
---|
| 59 | |
---|
| 60 | $setup_tpl->set_var('lang_submit',lang('Save')); |
---|
| 61 | $setup_tpl->set_var('lang_cancel',lang('Cancel')); |
---|
| 62 | $setup_tpl->pparse('out','T_setup_demo'); |
---|
| 63 | $GLOBALS['phpgw_setup']->html->show_footer(); |
---|
| 64 | } |
---|
| 65 | else |
---|
| 66 | { |
---|
| 67 | /* Posted admin data */ |
---|
| 68 | $passwd = get_var('passwd',Array('POST')); |
---|
| 69 | $passwd2 = get_var('passwd2',Array('POST')); |
---|
| 70 | $username = get_var('username',Array('POST')); |
---|
| 71 | $fname = get_var('fname2',Array('POST')); |
---|
| 72 | $lname = get_var('lname',Array('POST')); |
---|
| 73 | |
---|
| 74 | if($passwd != $passwd2) |
---|
| 75 | { |
---|
| 76 | echo lang('Passwords did not match, please re-enter') . '.'; |
---|
| 77 | exit; |
---|
| 78 | } |
---|
| 79 | if(!$username) |
---|
| 80 | { |
---|
| 81 | echo lang('You must enter a username for the admin') . '.'; |
---|
| 82 | exit; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | $GLOBALS['phpgw_setup']->loaddb(); |
---|
| 86 | /* Begin transaction for acl, etc */ |
---|
| 87 | $GLOBALS['phpgw_setup']->db->transaction_begin(); |
---|
| 88 | |
---|
| 89 | if($_POST['delete_all']) |
---|
| 90 | { |
---|
| 91 | /* Now, clear out existing tables */ |
---|
| 92 | $GLOBALS['phpgw_setup']->db->query('DELETE FROM phpgw_accounts'); |
---|
| 93 | $GLOBALS['phpgw_setup']->db->query('DELETE FROM phpgw_preferences'); |
---|
| 94 | $GLOBALS['phpgw_setup']->db->query('DELETE FROM phpgw_acl'); |
---|
| 95 | } |
---|
| 96 | /* Create the demo groups */ |
---|
| 97 | $defaultgroupid = (int)$GLOBALS['phpgw_setup']->add_account('Default','Default','Group',False,False); |
---|
| 98 | $admingroupid = (int)$GLOBALS['phpgw_setup']->add_account('Admins','Admin','Group',False,False); |
---|
| 99 | |
---|
| 100 | if (!$defaultgroupid || !$admingroupid) |
---|
| 101 | { |
---|
| 102 | echo '<p><b>'.lang('Error in group-creation !!!')."</b></p>\n"; |
---|
| 103 | echo '<p>'.lang('click <a href="index.php">here</a> to return to setup.')."</p>\n"; |
---|
| 104 | $GLOBALS['phpgw_setup']->db->transaction_abort(); |
---|
| 105 | exit; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | /* Group perms for the default group */ |
---|
| 109 | $GLOBALS['phpgw_setup']->add_acl(array('addressbook','calendar','infolog','email','preferences','manual'),'run',$defaultgroupid); |
---|
| 110 | |
---|
| 111 | // give admin access to all apps, to save us some support requests |
---|
| 112 | $all_apps = array(); |
---|
| 113 | $GLOBALS['phpgw_setup']->db->query('SELECT app_name FROM phpgw_applications WHERE app_enabled<3'); |
---|
| 114 | while ($GLOBALS['phpgw_setup']->db->next_record()) |
---|
| 115 | { |
---|
| 116 | $all_apps[] = $GLOBALS['phpgw_setup']->db->f('app_name'); |
---|
| 117 | } |
---|
| 118 | $GLOBALS['phpgw_setup']->add_acl($all_apps,'run',$admingroupid); |
---|
| 119 | |
---|
| 120 | function insert_default_prefs($accountid) |
---|
| 121 | { |
---|
| 122 | # Modificacoes para o Expresso Livre |
---|
| 123 | $defaultprefs = array( |
---|
| 124 | 'common' => array( |
---|
| 125 | 'maxmatchs' => 20, |
---|
| 126 | 'template_set' => 'celepar', |
---|
| 127 | 'theme' => 'celepar', |
---|
| 128 | 'navbar_format' => 'icons', |
---|
| 129 | 'tz_offset' => 0, |
---|
| 130 | 'dateformat' => 'd/m/Y', |
---|
| 131 | 'timeformat' => '24', |
---|
| 132 | 'country' => 'BR', |
---|
| 133 | 'lang' => 'pt-br', |
---|
| 134 | 'show_currentusers' => False, |
---|
| 135 | 'currency' => 'R$', |
---|
| 136 | 'account_selection' => 'selectbox', |
---|
| 137 | 'account_display' => 'firstall', |
---|
| 138 | 'show_help' => False, |
---|
| 139 | 'start_and_logout_icons'=> 'yes', |
---|
| 140 | 'max_icons' => '10', |
---|
| 141 | 'auto_hide_sidebox' => True, |
---|
| 142 | 'click_or_onmouseover' => 'click', |
---|
| 143 | 'disable_slider_effects'=> True, |
---|
| 144 | 'disable_pngfix' => False, |
---|
| 145 | 'show_generation_time' => False, |
---|
| 146 | ), |
---|
| 147 | 'calendar' => array( |
---|
| 148 | 'workdaystarts' => 7, |
---|
| 149 | 'workdayends' => 17, |
---|
| 150 | 'interval' => '30', |
---|
| 151 | 'weekdaystarts' => 'Monday', |
---|
| 152 | 'defaultcalendar' => 'day', |
---|
| 153 | 'planner_start_with_group' => $GLOBALS['defaultgroupid'], |
---|
| 154 | ), |
---|
| 155 | ); |
---|
| 156 | |
---|
| 157 | foreach ($defaultprefs as $app => $prefs) |
---|
| 158 | { |
---|
| 159 | $prefs = $GLOBALS['phpgw_setup']->db->db_addslashes(serialize($prefs)); |
---|
| 160 | $GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_preferences(preference_owner,preference_app,preference_value) VALUES($accountid,'$app','$prefs')",__FILE__,__LINE__); |
---|
| 161 | } |
---|
| 162 | } |
---|
| 163 | insert_default_prefs(-1); // set some default prefs (Expresso Livre) |
---|
| 164 | |
---|
| 165 | /* Creation of the demo accounts is optional - the checkbox is on by default. */ |
---|
| 166 | if(get_var('create_demo',Array('POST'))) |
---|
| 167 | { |
---|
| 168 | // Create 3 demo accounts |
---|
| 169 | $GLOBALS['phpgw_setup']->add_account('demo','Demo','Account','guest'); |
---|
| 170 | $GLOBALS['phpgw_setup']->add_account('demo2','Demo2','Account','guest'); |
---|
| 171 | $GLOBALS['phpgw_setup']->add_account('demo3','Demo3','Account','guest'); |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | /* Create records for administrator account, with Admins as primary and Default as additional group */ |
---|
| 175 | $accountid = $GLOBALS['phpgw_setup']->add_account($username,$fname,$lname,$passwd,'Admins',True); |
---|
| 176 | if (!$accountid) |
---|
| 177 | { |
---|
| 178 | echo '<p><b>'.lang('Error in admin-creation !!!')."</b></p>\n"; |
---|
| 179 | echo '<p>'.lang('click <a href="index.php">here</a> to return to setup.')."</p>\n"; |
---|
| 180 | $GLOBALS['phpgw_setup']->db->transaction_abort(); |
---|
| 181 | exit; |
---|
| 182 | } |
---|
| 183 | $GLOBALS['phpgw_setup']->add_acl('phpgw_group',$admingroupid,$accountid); |
---|
| 184 | $GLOBALS['phpgw_setup']->add_acl('phpgw_group',$defaultgroupid,$accountid); |
---|
| 185 | |
---|
| 186 | /* Clear the access log, since these are all new users anyway */ |
---|
| 187 | $GLOBALS['phpgw_setup']->db->query('DELETE FROM phpgw_access_log'); |
---|
| 188 | |
---|
| 189 | $GLOBALS['phpgw_setup']->db->transaction_commit(); |
---|
| 190 | |
---|
| 191 | Header('Location: index.php'); |
---|
| 192 | exit; |
---|
| 193 | } |
---|
| 194 | ?> |
---|