Projekt

Obecné

Profil

1083 dzolo
<?php defined('SYSPATH') or die('No direct script access.');
/*
* This file is part of open source system FreeNetIS
* and it is released under GPLv3 licence.
*
* More info about licence can be found:
* http://www.gnu.org/licenses/gpl-3.0.html
*
* More info about project can be found:
* http://www.freenetis.org/
*
*/
176 michalklim
1215 dzolo
// url for registration to FreenetIS.org
define('REGISTER_URL', 'http://dev.freenetis.org/register.php');

1083 dzolo
/**
* Controller performs installation of FreeNetIS
*
* @package Controller
*/
176 michalklim
class Installation_Controller extends Controller
{
752 dzolo
/**
* Array of countries, index corresponds to id of country in table countries
* @var array
*/
1083 dzolo
private static $COUNTRIES = array
(
752 dzolo
'1' => 'Afghanistan',
'2' => 'Albania',
'3' => 'Algeria',
'4' => 'American Samoa',
'5' => 'Andorra',
'6' => 'Angola',
'7' => 'Anguilla',
'8' => 'Antarctica',
'9' => 'Antigua and Barbuda',
'10' => 'Argentina',
'11' => 'Armenia',
'12' => 'Aruba',
'13' => 'Australia',
'14' => 'Austria',
'15' => 'Azerbaijan',
'16' => 'Bahamas',
'17' => 'Bahrain',
'18' => 'Bangladesh',
'19' => 'Barbados',
'20' => 'Belarus',
'21' => 'Belgium',
'22' => 'Belize',
'23' => 'Benin',
'24' => 'Bermuda',
'25' => 'Bhutan',
'26' => 'Bolivia',
'27' => 'Bosnia and Herzegovina',
'28' => 'Botswana',
'29' => 'Brazil',
'30' => 'British Indian Ocean Territory',
'31' => 'British Virgin Islands',
'32' => 'Brunei',
'33' => 'Bulgaria',
'34' => 'Burkina Faso',
'35' => 'Burma (Myanmar)',
'36' => 'Burundi',
'37' => 'Cambodia',
'38' => 'Cameroon',
'39' => 'Canada',
'40' => 'Cape Verde',
'41' => 'Cayman Islands',
'42' => 'Central African Republic',
'43' => 'Chad',
'44' => 'Chile',
'45' => 'China',
'46' => 'Christmas Island',
'47' => 'Cocos (Keeling) Islands',
'48' => 'Colombia',
'49' => 'Comoros',
'50' => 'Cook Islands',
'51' => 'Costa Rica',
'52' => 'Croatia',
'53' => 'Cuba',
'54' => 'Cyprus',
'55' => 'Czech Republic',
'56' => 'Democratic Republic of the Congo',
'57' => 'Denmark',
'58' => 'Djibouti',
'59' => 'Dominica',
'60' => 'Dominican Republic',
'61' => 'Ecuador',
'62' => 'Egypt',
'63' => 'El Salvador',
'64' => 'Equatorial Guinea',
'65' => 'Eritrea',
'66' => 'Estonia',
'67' => 'Ethiopia',
'68' => 'Falkland Islands',
'69' => 'Faroe Islands',
'70' => 'Fiji',
'71' => 'Finland',
'72' => 'France',
'73' => 'French Polynesia',
'74' => 'Gabon',
'75' => 'Gambia',
'76' => 'Georgia',
'77' => 'Germany',
'78' => 'Ghana',
'79' => 'Gibraltar',
'80' => 'Greece',
'81' => 'Greenland',
'82' => 'Grenada',
'83' => 'Guam',
'84' => 'Guatemala',
'85' => 'Guinea',
'86' => 'Guinea-Bissau',
'87' => 'Guyana',
'88' => 'Haiti',
'89' => 'Holy See (Vatican City)',
'90' => 'Honduras',
'91' => 'Hong Kong',
'92' => 'Hungary',
'93' => 'Iceland',
'94' => 'India',
'95' => 'Indonesia',
'96' => 'Iran',
'97' => 'Iraq',
'98' => 'Ireland',
'99' => 'Isle of Man',
'100' => 'Israel',
'101' => 'Italy',
'102' => 'Ivory Coast',
'103' => 'Jamaica',
'104' => 'Japan',
'105' => 'Jersey',
'106' => 'Jordan',
'107' => 'Kazakhstan',
'108' => 'Kenya',
'109' => 'Kiribati',
'110' => 'Kuwait',
'111' => 'Kyrgyzstan',
'112' => 'Laos',
'113' => 'Latvia',
'114' => 'Lebanon',
'115' => 'Lesotho',
'116' => 'Liberia',
'117' => 'Libya',
'118' => 'Liechtenstein',
'119' => 'Lithuania',
'120' => 'Luxembourg',
'121' => 'Macau',
'122' => 'Macedonia',
'123' => 'Madagascar',
'124' => 'Malawi',
'125' => 'Malaysia ',
'126' => 'Maldives',
'127' => 'Mali',
'128' => 'Malta',
'129' => 'Marshall Islands',
'130' => 'Mauritania',
'131' => 'Mauritius',
'132' => 'Mayotte',
'133' => 'Mexico',
'134' => 'Micronesia',
'135' => 'Moldova',
'136' => 'Monaco',
'137' => 'Mongolia ',
'138' => 'Montenegro ',
'139' => 'Montserrat',
'140' => 'Morocco',
'141' => 'Mozambique',
'142' => 'Namibia ',
'143' => 'Nauru',
'144' => 'Nepal',
'145' => 'Netherlands',
'146' => 'Netherlands Antilles',
'147' => 'New Caledonia',
'148' => 'New Zealand ',
'149' => 'Nicaragua',
'150' => 'Niger',
'151' => 'Nigeria',
'152' => 'Niue',
'153' => 'Norfolk Island',
'154' => 'North Korea',
'155' => 'Northern Mariana Islands',
'156' => 'Norway',
'157' => 'Oman',
'158' => 'Pakistan',
'159' => 'Palau',
'160' => 'Panama',
'161' => 'Papua New Guinea',
'162' => 'Paraguay',
'163' => 'Peru ',
'164' => 'Philippines',
'165' => 'Pitcairn Islands',
'166' => 'Poland',
'167' => 'Portugal',
'168' => 'Puerto Rico',
'169' => 'Qatar',
'170' => 'Republic of the Congo',
'171' => 'Romania',
'172' => 'Russia',
'173' => 'Rwanda',
'174' => 'Saint Barthelemy',
'175' => 'Saint Helena',
'176' => 'Saint Kitts and Nevis',
'177' => 'Saint Lucia',
'178' => 'Saint Martin',
'179' => 'Saint Pierre and Miquelon',
'180' => 'Saint Vincent and the Grenadines',
'181' => 'Samoa',
'182' => 'San Marino',
'183' => 'Sao Tome and Principe',
'184' => 'Saudi Arabia',
'185' => 'Senegal',
'186' => 'Serbia',
'187' => 'Seychelles',
'188' => 'Sierra Leone',
'189' => 'Singapore',
'190' => 'Slovakia',
'191' => 'Slovenia',
'192' => 'Solomon Islands',
'193' => 'Somalia',
'194' => 'South Africa',
'195' => 'South Korea',
'196' => 'Spain',
'197' => 'Sri Lanka',
'198' => 'Sudan',
'199' => 'Suriname',
'200' => 'Svalbard',
'201' => 'Swaziland',
'202' => 'Sweden',
'203' => 'Switzerland',
'204' => 'Syria',
'205' => 'Taiwan',
'206' => 'Tajikistan',
'207' => 'Tanzania',
'208' => 'Thailand',
'209' => 'Timor-Leste',
'210' => 'Togo',
'211' => 'Tokelau',
'212' => 'Tonga',
'213' => 'Trinidad and Tobago',
'214' => 'Tunisia',
'215' => 'Turkey',
'216' => 'Turkmenistan',
'217' => 'Turks and Caicos Islands',
'218' => 'Tuvalu',
'219' => 'Uganda',
'220' => 'Ukraine',
'221' => 'United Arab Emirates',
'222' => 'United Kingdom',
'223' => 'United States',
'224' => 'Uruguay',
'225' => 'US Virgin Islands',
'226' => 'Uzbekistan',
'227' => 'Vanuatu',
'228' => 'Venezuela',
'229' => 'Vietnam',
'230' => 'Wallis and Futuna',
'231' => 'Western Sahara',
'232' => 'Yemen',
'233' => 'Zambia',
'234' => 'Zimbabwe'
);
632 michalklim
330 jsvitak
/**
* Function shows installation dialog. To show it must exist empty database freenetis and user with the
* same name. After form validation it creates member representing association, his primary user,
* first bank account and many double-entry accounts required for accounting.
*/
176 michalklim
public function index()
{
466 jsvitak
// check if the database is empty
632 michalklim
if ($this->settings->get('db_schema_version'))
1258 dzolo
url::redirect('members/show/'.$this->session->get('member_id'));
900 michalklim
/**
* finds default currency and country from lang
* @todo do it better, maybe from some special table
*/
switch (Config::get('lang'))
{
// language is czech
case 'cs':
$currency = 'CZK';
$country_id = 55;
break;
default:
$currency = 'USD';
$country_id = 223;
break;
}

466 jsvitak
// form
1258 dzolo
$form = new Forge('installation');
1083 dzolo
354 jsvitak
// login
1083 dzolo
1258 dzolo
$form->group('Login data');
1083 dzolo
$form->input('login')
1258 dzolo
->label(__('Username'). ':')
1083 dzolo
->rules('required|length[3,50]')
->value('admin')
1212 dzolo
->help(help::hint('login_name'))
1083 dzolo
->callback(array($this, 'valid_username'));

$form->password('password')
->rules('required|length[3,50]')
1212 dzolo
->class('password')
->title(url_lang::lang('help.password'));
1083 dzolo
$form->password('confirm_password')
->rules('required|length[3,50]')
->matches($form->password);

354 jsvitak
// association
1083 dzolo
1258 dzolo
$form->group('Association information');
1083 dzolo
$form->input('name')
1137 dzolo
->label(__('Name of the association').':')
1083 dzolo
->rules('required|length[3,30]');

$form->date('foundation')
1137 dzolo
->label(__('Date of foundation').':')
1083 dzolo
->years(date('Y')-100, date('Y'))
->rules('required');

$form->input('street')
->rules('required|length[1,200]');

$form->input('street_number')
->rules('required|length[1,50]|valid_numeric');

$form->input('town')
->rules('required|length[1,200]');

$form->input('quarter')
->rules('length[1,50]');

$form->input('zip_code')
->rules('required|length[5,10]');

$form->input('phone')
1258 dzolo
->rules('required|length[9,9]|valid_phone');
1083 dzolo
$form->input('email')
1212 dzolo
->rules('required|valid_email|length[3,50]');
1083 dzolo
354 jsvitak
// bank account
1083 dzolo
1258 dzolo
$form->group(
__('The first bank account information') . ' ' .
help::hint('bank_accounts_of_association')
);
1083 dzolo
$form->input('account_name')
1137 dzolo
->label(__('Account name').':')
1083 dzolo
->rules('required|length[3,50]');
1258 dzolo
1083 dzolo
$form->input('account_nr')
1137 dzolo
->label(__('Account number').':')
1083 dzolo
->rules('required|length[3,50]|valid_numeric');

$form->input('bank_nr')
1137 dzolo
->label(__('Bank code').':')
1083 dzolo
->rules('required|length[3,10]|valid_numeric');

1258 dzolo
$form->input('IBAN');
1083 dzolo
1258 dzolo
$form->input('SWIFT');
1083 dzolo
354 jsvitak
// fees
1083 dzolo
1258 dzolo
$form->group('Fees');
1083 dzolo
$form->input('entrance_fee')
1212 dzolo
->rules('valid_numeric')
->help(help::hint('entrance_fee'));
1083 dzolo
$form->input('regular_member_fee')
1137 dzolo
->label(__('Monthly member fee').':')
1083 dzolo
->rules('valid_numeric');

$form->input('transfer_fee')
->rules('valid_numeric');

$form->input('penalty')
->rules('valid_numeric');

485 jsvitak
// system
1083 dzolo
1258 dzolo
$form->group('System');
1083 dzolo
$form->input('title')
1137 dzolo
->label(__('Page title').':')
1083 dzolo
->value('Freenetis')
->rules('required');

$form->dropdown('default_country')
1137 dzolo
->label(__('Country').':')
1083 dzolo
->rules('required')
->options(self::$COUNTRIES)
->selected($country_id);

$form->input('currency')
->rules('required')
->value($currency);

$form->radio('clean_urls')
1137 dzolo
->label(__('Clean URLs').':')
1083 dzolo
->options(array
(
1137 dzolo
'1' => __('Yes'),
'0' => __('No')
1083 dzolo
))->default(1);

1212 dzolo
$link = html::anchor('http://www.freenetis.org', 'FreeNetIS.org', array
(
'target' => '_blank'
));

$form->checkbox('register_install')
->label(__('Register to %s', $link))
->help(help::hint('register_install'))
->checked(TRUE);

354 jsvitak
// submit button
1083 dzolo
$form->submit('submit')
1137 dzolo
->value(__('Install'));
1083 dzolo
261 jsvitak
special::required_forge_style($form, ' *', 'required');
1083 dzolo
// valid post?
176 michalklim
if ($form->validate())
{
1258 dzolo
$form_data = array_map('htmlspecialchars', $form->as_array());

354 jsvitak
// this executes all queries that upgrade database structure
261 jsvitak
$this->upgrade_sql();
632 michalklim
426 michalklim
$town_model = new Town_Model();
$street_model = new Street_Model();

330 jsvitak
// first member is special, it represents association
176 michalklim
$member = new Member_Model();
1083 dzolo
$member->registration = NULL;
$member->name = $form_data["name"];
426 michalklim
// address
1083 dzolo
$town = $town_model->get_town(
$form_data["zip_code"],
$form_data["town"],
$form_data["quarter"]
);

1254 dzolo
$street = $street_model->get_street($form_data["street"], $town->id);
750 michalklim
$address_point_model = new Address_point_Model();
1083 dzolo
$address_point = $address_point_model->get_address_point(
$form_data['default_country'],
$town->id, $street->id,
$form_data['street_number']
);
750 michalklim
// address point doesn't exist exist, create it
1083 dzolo
if (!$address_point->id)
750 michalklim
{
$address_point->save();
}

426 michalklim
$member->address_point_id = $address_point->id;

324 jsvitak
$enum_type = new Enum_type_Model();
$member->type = $enum_type->get_type_id('Honorary member');
261 jsvitak
$member->entrance_date = date("Y-m-d", $form_data["foundation"]);
176 michalklim
$member->save();
1083 dzolo
330 jsvitak
// every member has its one primary user of type "member"
176 michalklim
$user = new User_Model();
$user->member_id = $member->id;
261 jsvitak
$user->name = $form_data["login"];
$user->surname = $form_data["login"];
354 jsvitak
$user->birthday = date("Y-m-d", $form_data["foundation"]);
176 michalklim
$user->login = $form_data["login"];
749 michalklim
$user->password = sha1($form_data["password"]);
311 jsvitak
$user->type = User_Model::$member;
1083 dzolo
$user->application_password = security::generate_password();
176 michalklim
$user->save();
1083 dzolo
1172 dzolo
// add user to access list as admin
$groups_aro_map = new Groups_aro_map_Model();
$groups_aro_map->aro_id = $user->id;
$groups_aro_map->group_id = Aro_group_Model::ADMINS;
$groups_aro_map->save();

839 dzolo
// users telephone
$contact = new Contact_Model();
$contact->type = Contact_Model::TYPE_PHONE;
$contact->value = $form_data['phone'];
$contact->save_throwable();
1083 dzolo
839 dzolo
$contact->add($user);
$contact->save_throwable();
1083 dzolo
839 dzolo
$phone_country = new Country_Model($form_data['default_country']);
$contact->add($phone_country);
$contact->save_throwable();
$contact->clear();
1083 dzolo
839 dzolo
// users email
if (! empty($form_data['email']))
{
$contact->type = Contact_Model::TYPE_EMAIL;
$contact->value = $form_data['email'];
$contact->save_throwable();
$contact->add($user);
$contact->save_throwable();
}
1083 dzolo
330 jsvitak
// association has at least one real bank account
$bank_account = new Bank_account_Model();
$bank_account->name = $form_data["account_name"];
$bank_account->member_id = $member->id;
$bank_account->account_nr = $form_data["account_nr"];
$bank_account->bank_nr = $form_data["bank_nr"];
$bank_account->IBAN = $form_data["IBAN"];
$bank_account->SWIFT = $form_data["SWIFT"];
1083 dzolo
$bank_account->save();

330 jsvitak
// these three double-entry accounts are related to one bank account through relation table
// double-entry bank account
$doubleentry_bank_account = new Account_Model();
$doubleentry_bank_account->member_id = $member->id;
352 jsvitak
$doubleentry_bank_account->name = $form_data["account_name"];
330 jsvitak
$doubleentry_bank_account->account_attribute_id = Account_attribute_Model::$bank;
1137 dzolo
$doubleentry_bank_account->comment = __('Bank accounts');
950 michalklim
$doubleentry_bank_account->add($bank_account);
330 jsvitak
$doubleentry_bank_account->save();
1083 dzolo
330 jsvitak
// double-entry account of bank fees
$bank_fees_account = new Account_Model();
$bank_fees_account->member_id = $member->id;
1137 dzolo
$bank_fees_account->name = $form_data["account_name"].' - '.__('Bank fees');
330 jsvitak
$bank_fees_account->account_attribute_id = Account_attribute_Model::$bank_fees;
1137 dzolo
$bank_fees_account->comment = __('Bank fees');
1210 michalklim
$bank_fees_account->add($bank_account);
330 jsvitak
$bank_fees_account->save();
1083 dzolo
330 jsvitak
// double-entry account of bank interests
$bank_interests_account = new Account_Model();
$bank_interests_account->member_id = $member->id;
1137 dzolo
$bank_interests_account->name = $form_data["account_name"].' - '.__('Bank interests');
330 jsvitak
$bank_interests_account->account_attribute_id = Account_attribute_Model::$bank_interests;
1137 dzolo
$bank_interests_account->comment = __('Bank interests');
1210 michalklim
$bank_interests_account->add($bank_account);
330 jsvitak
$bank_interests_account->save();
1083 dzolo
330 jsvitak
// other double entry accounts independent of bank account
// double-entry cash account
291 jsvitak
$cash_account = new Account_Model();
$cash_account->member_id = $member->id;
1137 dzolo
$cash_account->name = __('Cash');
291 jsvitak
$cash_account->account_attribute_id = Account_attribute_Model::$cash;
1137 dzolo
$cash_account->comment = __('Cash');
291 jsvitak
$cash_account->save();
1083 dzolo
330 jsvitak
// double-entry operating account
261 jsvitak
$operating_account = new Account_Model();
$operating_account->member_id = $member->id;
1137 dzolo
$operating_account->name = __('Operating account');
282 jsvitak
$operating_account->account_attribute_id = Account_attribute_Model::$operating;
1137 dzolo
$operating_account->comment = __('Operating account');
261 jsvitak
$operating_account->save();
1083 dzolo
330 jsvitak
// double-entry infrastructure account
261 jsvitak
$infrastructure_account = new Account_Model();
$infrastructure_account->member_id = $member->id;
1137 dzolo
$infrastructure_account->name = __('Infrastructure account');
282 jsvitak
$infrastructure_account->account_attribute_id = Account_attribute_Model::$infrastructure;
1137 dzolo
$infrastructure_account->comment = __('Infrastructure account');
261 jsvitak
$infrastructure_account->save();
1083 dzolo
330 jsvitak
// double-entry account of purchasers
311 jsvitak
$purchasers_account = new Account_Model();
$purchasers_account->member_id = $member->id;
1137 dzolo
$purchasers_account->name = __('Purchasers account');
311 jsvitak
$purchasers_account->account_attribute_id = Account_attribute_Model::$purchasers;
1137 dzolo
$purchasers_account->comment = __('Purchasers account');
1083 dzolo
$purchasers_account->save();

330 jsvitak
// double-entry account of suppliers
261 jsvitak
$suppliers_account = new Account_Model();
$suppliers_account->member_id = $member->id;
1137 dzolo
$suppliers_account->name = __('Suppliers account');
282 jsvitak
$suppliers_account->account_attribute_id = Account_attribute_Model::$suppliers;
1137 dzolo
$suppliers_account->comment = __('Suppliers account');
261 jsvitak
$suppliers_account->save();
1083 dzolo
330 jsvitak
// double-entry account of received member fees
291 jsvitak
$fees_account = new Account_Model();
$fees_account->member_id = $member->id;
1137 dzolo
$fees_account->name = __('Received member fees');
293 jsvitak
$fees_account->account_attribute_id = Account_attribute_Model::$member_fees;
1137 dzolo
$fees_account->comment = __('Received member fees');
1083 dzolo
$fees_account->save();

354 jsvitak
// interval of fee availability
$from = date("Y-m-d", $form_data["foundation"]);
$to = "9999-12-31 23:59:59";
791 michalklim
354 jsvitak
// entrance fee
$entrance_fee = new Fee_Model();
$entrance_fee->fee = $form_data['entrance_fee'];
$entrance_fee->from = $from;
$entrance_fee->to = $to;
$entrance_fee->type_id = $enum_type->get_type_id('entrance fee');
$entrance_fee->save();
1083 dzolo
791 michalklim
// default entrance fee
$default_entrance_fee = new Members_fee_Model();
$default_entrance_fee->fee_id = $entrance_fee->id;
$default_entrance_fee->member_id = $member->id;
$default_entrance_fee->activation_date = $from;
$default_entrance_fee->deactivation_date = $to;
$default_entrance_fee->priority = 1;
$default_entrance_fee->save();
1083 dzolo
354 jsvitak
// regular member fee
$regular_member_fee = new Fee_Model();
$regular_member_fee->fee = $form_data['regular_member_fee'];
$regular_member_fee->from = $from;
$regular_member_fee->to = $to;
$regular_member_fee->type_id = $enum_type->get_type_id('regular member fee');
$regular_member_fee->save();
1083 dzolo
791 michalklim
// default regular member fee
$default_regular_member_fee = new Members_fee_Model();
$default_regular_member_fee->fee_id = $regular_member_fee->id;
$default_regular_member_fee->member_id = $member->id;
$default_regular_member_fee->activation_date = $from;
$default_regular_member_fee->deactivation_date = $to;
$default_regular_member_fee->priority = 1;
$default_regular_member_fee->save();
1083 dzolo
// transfer fee
354 jsvitak
$transfer_fee = new Fee_Model();
$transfer_fee->fee = $form_data['transfer_fee'];
$transfer_fee->from = $from;
$transfer_fee->to = $to;
$transfer_fee->type_id = $enum_type->get_type_id('transfer fee');
$transfer_fee->save();
1083 dzolo
791 michalklim
// default transfer fee
$default_transfer_fee = new Members_fee_Model();
$default_transfer_fee->fee_id = $transfer_fee->id;
$default_transfer_fee->member_id = $member->id;
$default_transfer_fee->activation_date = $from;
$default_transfer_fee->deactivation_date = $to;
$default_transfer_fee->priority = 1;
$default_transfer_fee->save();
1083 dzolo
354 jsvitak
// penalty
$penalty = new Fee_Model();
$penalty->fee = $form_data['penalty'];
$penalty->from = $from;
$penalty->to = $to;
$penalty->type_id = $enum_type->get_type_id('penalty');
$penalty->save();
1083 dzolo
791 michalklim
// default transfer fee
$default_penalty = new Members_fee_Model();
$default_penalty->fee_id = $penalty->id;
$default_penalty->member_id = $member->id;
$default_penalty->activation_date = $from;
$default_penalty->deactivation_date = $to;
$default_penalty->priority = 1;
$default_penalty->save();

485 jsvitak
// system settings
632 michalklim
$this->settings->set('title', $form_data['title']);
$this->settings->set('currency', $form_data['currency']);
752 dzolo
$this->settings->set('default_country', $form_data['default_country']);
632 michalklim
791 michalklim
// saves special (read-only) types of fee
$fee_model = new Fee_Model();
1083 dzolo
$special_types = array
(
1 => "Membership interrupt",
2 => "Fee-free regular member",
3 => "Non-member",
4 => "Honorary member"
);
791 michalklim
foreach ($special_types as $id => $name)
{
$fee_model->clear();
$fee_model->readonly = 1;
$fee_model->fee = 0;
$fee_model->from = $from;
$fee_model->to = $to;
$fee_model->type_id = $enum_type->get_type_id('regular member fee');
$fee_model->name = $name;
$fee_model->special_type_id = $id;
$fee_model->save();
}

900 michalklim
// array for store error
$errors = array();

632 michalklim
$clean_urls = ($form_data['clean_urls'] && server::is_mod_rewrite_enabled());

// set base domain
$this->settings->set('domain', server::http_host());

// set subdirectory
$suffix = substr(server::script_name(),0,-9);
$this->settings->set('suffix', $suffix);
1212 dzolo
// send registration data
if ($form_data['register_install'])
{
1215 dzolo
@file_get_contents(
REGISTER_URL .
'?name=' . urlencode($form_data["name"]) .
'&email=' . urlencode($form_data["email"]) .
'&address=' . urlencode($address_point->__toString())
);
1212 dzolo
}
632 michalklim
$view = new View('installation_done');

// want clean urls
if ($clean_urls)
{
900 michalklim
// it is not re-install
if (!file_exists('.htaccess'))
632 michalklim
{
900 michalklim
// load .htaccess sample file
$htaccessFile = file('.htaccess-sample');
foreach ($htaccessFile as $line_num => $line)
632 michalklim
{
900 michalklim
// find line with RewriteBase
if (preg_match("/^RewriteBase (.+)/", $line, $matches))
{
// and set there our suffix (subdirectory)
1107 dzolo
$htaccessFile[$line_num] = preg_replace(
"/^(RewriteBase )(.+)/",
'${1}'.$suffix, $line
);
900 michalklim
}
632 michalklim
}

1107 dzolo
// root directory is not writable, only generate code
// and howto to create config file by user
900 michalklim
if (!is_writable('.'))
{
$errors['writable'] = TRUE;
632 michalklim
900 michalklim
$textarea = '';
foreach ($htaccessFile as $line)
$textarea .= htmlentities ($line);

1083 dzolo
$view->textarea = '<textarea cols="90" rows="15">';
$view->textarea .= $textarea.'</textarea>';
900 michalklim
}
// root directory is writable, create .htacess
else
632 michalklim
{
900 michalklim
$handle = @fopen('.htaccess', 'w');
747 michalklim
900 michalklim
if (!$handle)
$errors['fopen'] = TRUE;
else
{
foreach($htaccessFile as $line )
fwrite($handle, $line);
fclose($handle);

if (!@chmod('.htaccess', 0666))
$errors['chmod'] = TRUE;
}
}
632 michalklim
}
900 michalklim
// no errors
if (!count($errors))
{
// remove index.php from urls
$this->settings->set('index_page', 0);
}
632 michalklim
}

900 michalklim
$view->errors = $errors;
1212 dzolo
$view->render(TRUE);
632 michalklim
}
else
{
$view = new View('installation');
1137 dzolo
$view->title = __('Installation');
632 michalklim
$view->form = $form->html();
$view->render(TRUE);
}
176 michalklim
}
330 jsvitak
1083 dzolo
/**
* Function checks validity of username.
*
* @param object $input
*/
1258 dzolo
public static function valid_username($input = NULL)
746 bonerek
{
1258 dzolo
// validators cannot be accessed
if (empty($input) || !is_object($input))
{
self::error(PAGE);
}

746 bonerek
if (preg_match('/^[a-z]{1}[a-z0-9]+$/',$input->value) == 0)
{
1083 dzolo
$input->add_error(
1137 dzolo
'required', __(
'Login must contains only a-z and 0-9 and ' .
1083 dzolo
'starts with literal.'
)
);
746 bonerek
}
}
1083 dzolo
176 michalklim
}