function fz_serialize_ini_array($assoc_arr, $has_sections = false) { $content = ""; if ($has_sections) { foreach ($assoc_arr as $section => $values) { $content .= "\n[{$section}]\n" . fz_serialize_ini_array($values); } } else { foreach ($assoc_arr as $key => $value) { if (is_array($value)) { foreach ($value as $v) { $content .= "{$key}[] = \"{$v}\"\n"; } } if (is_numeric($value)) { $content .= "{$key} = {$value}\n"; } else { if ($value != "") { $content .= "{$key} = \"{$value}\"\n"; } } } } return $content; }
/** * */ public function configureAction() { $config = fz_config_get(); // $locales_choices = array(); foreach (glob(option('root_dir') . '/i18n/*', GLOB_ONLYDIR) as $lc) { $locales_choices[basename($lc)] = basename($lc); } $errors = array(); $notifs = array(); // If request is post, check for errors if (request_is_post()) { // prevent unchecked input from being transformed to true when merging config $_POST['config']['looknfeel']['show_credit'] = array_key_exists('show_credit', $_POST['config']['looknfeel']) ? 1 : 0; $config = merge_config($_POST['config'], $config); // checking rights $this->checkRights($errors, $config); // Checking database connection $this->checkDatabaseConf($errors, $config); // If Upload monitoring lib is selected check if it's installed if ($config['app']['progress_monitor'] != '') { $progressMonitor = $config['app']['progress_monitor']; $progressMonitor = new $progressMonitor(); if (!$progressMonitor->isInstalled()) { $errors[] = array('title' => 'Your system is not configured for ' . get_class($progressMonitor), 'msg' => 'Read <a href="http://github.com/UAPV/FileZ/blob/master/doc/INSTALL.markdown" target="_blank">the INSTALL file</a> for help'); } } // Is CAS authentication, check requirements if ($config['app']['auth_handler_class'] == 'Fz_Controller_Security_Cas' && !function_exists('curl_init')) { $errors[] = array('title' => 'PHP extension "cURL" is required for CAS authentication but is not installed', 'msg' => 'Use php5-curl on debian to install it'); } // Checking User factory connection if ($config['app']['user_factory_class'] == 'Fz_User_Factory_Ldap') { $this->checkUserFactoryLdapConf($errors, $config); } // do not check user factory if database. //elseif ($config['app']['user_factory_class'] == 'Fz_User_Factory_Database') // $this->checkUserFactoryDatabaseConf ($errors, $config); // Checking email $this->checkEmailConf($errors, $config); // If no errors or if the user ignored them, save the config and create // the database if (empty($errors) || array_key_exists('ignore_errors', $_POST)) { //$errors = array (); // Reset errors. // Try to save the file or display it $configFile = option('root_dir') . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'filez.ini'; if (!fz_config_save($config, $configFile)) { $errors[] = array('title' => 'Can\'t save filez.ini.', 'msg' => 'Put the following code in the file "' . $configFile . '" :<textarea cols="60" rows="50">' . fz_serialize_ini_array($config, true) . '</textarea>'); } else { $notifs[] = 'Created file "' . $configFile . '"'; } try { $this->initDatabase(); $notifs[] = 'Database configured.<br/><br/> A default admin account has been created. Login ("<tt>admin</tt>" / "<tt>filez</tt>") and choose a new password.'; } catch (Exception $e) { $errors[] = array('title' => 'Can\'t initialize the database (' . $e->getMessage() . ')', 'msg' => 'Check your database configuration in config/filez.ini and re-run the SQL script "' . $initDbScript . '".'); } set('errors', $errors); set('notifs', $notifs); return html('install/finished.php'); } if (!empty($errors)) { set('errors', $errors); } } set('config', $config); set('locales_choices', $locales_choices); return html('install/index.php'); }