コード例 #1
0
 /**
  * Creates dictionary file in localization path
  *
  * @param string $dictionary_name
  */
 function createTranslationFile($dictionary_name)
 {
     $dictionary_file = Languages::getDictionaryPath($dictionary_name);
     if (!is_file($dictionary_file)) {
         return false;
     }
     // if
     $translation_file = Languages::getTranslationPath($this, $dictionary_name);
     if (!folder_is_writable(dirname($translation_file))) {
         return false;
     }
     // if
     if (is_file($translation_file)) {
         return true;
     }
     // if
     $dictionary = Languages::getDictionary($dictionary_name);
     $translation = array();
     if (is_foreachable($dictionary)) {
         foreach ($dictionary as $dictionary_word) {
             $translation[$dictionary_word] = '';
         }
         // foreach
     }
     // if
     $result = file_put_contents($translation_file, "<?php return " . var_export($translation, true) . " ?>");
     if (!$result) {
         return false;
     }
     // if
     return true;
 }
コード例 #2
0
 /**
  * Execute environment checks
  *
  * @access public
  * @param void
  * @return boolean
  */
 function execute()
 {
     $all_ok = true;
     // Check PHP version
     if (version_compare(PHP_VERSION, '5.0.2', 'ge')) {
         $this->addToChecklist('PHP version is ' . PHP_VERSION, true);
     } else {
         $this->addToChecklist('You PHP version is ' . PHP_VERSION . '. PHP 5.0.2 or newer is required', false);
         $all_ok = false;
     }
     // if
     foreach ($this->check_extensions as $extension_name) {
         if (extension_loaded($extension_name)) {
             $this->addToChecklist("'{$extension_name}' extension is loaded", true);
         } else {
             $this->addToChecklist("'{$extension_name}' extension is not loaded", false);
             $all_ok = false;
         }
         // if
     }
     // if
     if (is_array($this->check_is_writable)) {
         foreach ($this->check_is_writable as $relative_folder_path) {
             $check_this = INSTALLATION_PATH . $relative_folder_path;
             $is_writable = false;
             if (is_file($check_this)) {
                 $is_writable = file_is_writable($check_this);
             } elseif (is_dir($check_this)) {
                 $is_writable = folder_is_writable($check_this);
             }
             // if
             if ($is_writable) {
                 $this->addToChecklist("{$relative_folder_path} is writable", true);
             } else {
                 $this->addToChecklist("{$relative_folder_path} is not writable", false);
                 $all_ok = false;
             }
             // if
         }
         // foreach
     }
     // if
     $this->setContentFromTemplate('checks.php');
     if (ini_get('zend.ze1_compatibility_mode')) {
         $this->addToChecklist('zend.ze1_compatibility_mode is set to On. This can cause some strange problems. It is strongly suggested to turn this value to Off (in your php.ini file)', false);
     }
     // if
     if ($all_ok) {
         return $this->isSubmited();
     }
     // if
     $this->setNextDisabled(true);
     return false;
 }
コード例 #3
0
 /**
  * Function that opens zip file for writing
  *
  * @param string $zip_filename
  */
 function open($zip_filename)
 {
     $this->zip_filename = $zip_filename;
     if (!$this->fail_safe_method) {
         return $this->zip_file->open($zip_filename, ZIPARCHIVE::OVERWRITE);
     } else {
         if (is_file($zip_filename)) {
             return file_is_writable($zip_filename);
         } else {
             return folder_is_writable(dirname($zip_filename));
         }
         // if
     }
     // if
 }
コード例 #4
0
 /**
  * Index - main page for project exporter
  *
  * @param void
  * @return null
  */
 function index()
 {
     $is_writable = folder_is_writable(PROJECT_EXPORT_PATH);
     if (!$is_writable) {
         $this->wireframe->addPageMessage(lang("Folder <strong>:folder</strong> is not writable", array("folder" => PROJECT_EXPORT_PATH)), PAGE_MESSAGE_ERROR);
         $this->smarty->assign(array('is_writable' => false));
     } else {
         $exportable_modules = array();
         event_trigger('on_project_export', array(&$exportable_modules, &$this->active_project));
         require_once PROJECT_EXPORTER_MODULE_PATH . '/models/ProjectExporterOutputBuilder.class.php';
         $output_builder = new ProjectExporterOutputBuilder($this->active_project, $this->smarty, null);
         if (is_file($output_builder->getOutputArchivePath())) {
             $this->wireframe->addPageMessage(lang('Previous project archive already exists. You can download it using following <a href=":link"><strong>link</strong></a>', array('link' => assemble_url('project_exporter_download_export', array('project_id' => $this->active_project->getId())))), PAGE_MESSAGE_INFO);
         }
         // if
         $this->smarty->assign(array('visibility_normal_caption' => lang('Only the data clients can'), 'visibility_private_caption' => lang('All project data, including data marked as private'), 'exportable_modules' => $exportable_modules, "project" => $this->active_project, 'export_project_url' => assemble_url('project_exporter', array('project_id' => $this->active_project->getId())), 'submitted' => false, 'is_writable' => true));
         js_assign('download_url', assemble_url('project_exporter_download_export', array('project_id' => $this->active_project->getId())));
         js_assign('download_ftp_url', PROJECT_EXPORT_PATH . '/project_' . $this->active_project->getId() . '/');
     }
 }
コード例 #5
0
 /**
  * Construct invoices controller
  *
  * @param Request $request
  * @return InvoicesController
  */
 function __construct($request)
 {
     parent::__construct($request);
     if (!$this->logged_user->getSystemPermission('can_manage_invoices')) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     // Warning message about invoices folder existance / writability
     if (is_dir(INVOICES_WORK_PATH)) {
         if (!folder_is_writable(INVOICES_WORK_PATH)) {
             $this->wireframe->addPageMessage(lang('/work/invoices exists, but it is not writable. PDF files will not be generated'), 'error');
         }
         // if
     } else {
         $this->wireframe->addPageMessage(lang('/work/invoices folder does not exist. PDF files will not be generated!'), 'error');
     }
     // if
     $invoice_id = $this->request->getId('invoice_id');
     if ($invoice_id) {
         $this->active_invoice = Invoices::findById($invoice_id);
     }
     // if
     $this->wireframe->addBreadCrumb(lang('Invoices'), assemble_url('invoices'));
     if (instance_of($this->active_invoice, 'Invoice')) {
         $this->wireframe->addBreadCrumb($this->active_invoice->getName(), $this->active_invoice->getViewUrl());
     } else {
         $this->active_invoice = new Invoice();
     }
     // if
     if (Invoice::canAdd($this->logged_user)) {
         $add_invoice_url = assemble_url('invoices_add');
         $this->wireframe->addPageAction(lang('New Invoice'), $add_invoice_url);
     } else {
         $add_invoice_url = false;
     }
     // if
     $this->wireframe->current_menu_item = 'invoicing';
     $this->smarty->assign(array('active_invoice' => $this->active_invoice, 'add_invoice_url' => $add_invoice_url, 'drafts_count' => Invoices::countDrafts()));
     js_assign('invoicing_precision', INVOICE_PRECISION);
 }
コード例 #6
0
 /**
  * Execute the script
  *
  * @param void
  * @return boolean
  */
 function execute()
 {
     define('ROOT', realpath(dirname(__FILE__) . '/../../../'));
     // ---------------------------------------------------
     //  Load config
     // ---------------------------------------------------
     $config_is_set = (require_once INSTALLATION_PATH . '/config/config.php');
     if (!$config_is_set) {
         $this->printMessage('Valid config file was not found!', true);
         return false;
     } else {
         $this->printMessage('Config file found and loaded.');
     }
     // if
     // ---------------------------------------------------
     //  Check for version match (pre-0.7.0 had no version?)
     // ---------------------------------------------------
     if (defined('PRODUCT_VERSION') && PRODUCT_VERSION !== '0.6') {
         $this->printMessage('This upgrade script can be used only to upgrade 0.6 to 0.7', true);
         return false;
     }
     // if
     // ---------------------------------------------------
     //  Check if files and folders are writable
     // ---------------------------------------------------
     foreach ($this->check_is_writable as $relative_path) {
         $path = ROOT . $relative_path;
         if (is_file($path)) {
             if (file_is_writable($path)) {
                 $this->printMessage("File '{$relative_path}' exists and is writable");
             } else {
                 $this->printMessage("File '{$relative_path}' is not writable", true);
                 return false;
             }
             // if
         } elseif (is_dir($path)) {
             if (folder_is_writable($path)) {
                 $this->printMessage("Folder '{$relative_path}' exists and is writable");
             } else {
                 $this->printMessage("Folder '{$relative_path}' is not writable", true);
                 return false;
             }
             // if
         } else {
             $this->printMessage("'{$relative_path}' does not exists on the system", true);
             return false;
         }
         // if
     }
     // foreach
     // ---------------------------------------------------
     //  Check if extensions are loaded
     // ---------------------------------------------------
     foreach ($this->check_extensions as $extension_name) {
         if (extension_loaded($extension_name)) {
             $this->printMessage("Extension '{$extension_name}' is loaded");
         } else {
             $this->printMessage("Extension '{$extension_name}' is not loaded", true);
             return false;
         }
         // if
     }
     // foreach
     // ---------------------------------------------------
     //  Connect to database
     // ---------------------------------------------------
     if ($this->database_connection = mysql_connect(DB_HOST, DB_USER, DB_PASS)) {
         if (mysql_select_db(DB_NAME, $this->database_connection)) {
             $this->printMessage('Upgrade script has connected to the database.');
         } else {
             $this->printMessage('Failed to select database ' . DB_NAME);
             return false;
         }
         // if
     } else {
         $this->printMessage('Failed to connect to database');
         return false;
     }
     // if
     // ---------------------------------------------------
     //  Check MySQL version
     // ---------------------------------------------------
     $mysql_version = mysql_get_server_info($this->database_connection);
     if ($mysql_version && version_compare($mysql_version, '4.1', '>=')) {
         $constants['DB_CHARSET'] = 'utf8';
         @mysql_query("SET NAMES 'utf8'", $this->database_connection);
         tpl_assign('default_collation', $default_collation = 'collate utf8_unicode_ci');
         tpl_assign('default_charset', $default_charset = 'DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci');
     } else {
         tpl_assign('default_collation', $default_collation = '');
         tpl_assign('default_charset', $default_charset = '');
     }
     // if
     tpl_assign('table_prefix', TABLE_PREFIX);
     // ---------------------------------------------------
     //  Check test query
     // ---------------------------------------------------
     $test_table_name = TABLE_PREFIX . 'test_table';
     $test_table_sql = "CREATE TABLE `{$test_table_name}` (\n        `id` int(10) unsigned NOT NULL auto_increment,\n        `name` varchar(50) {$default_collation} NOT NULL default '',\n        PRIMARY KEY  (`id`)\n      ) ENGINE=InnoDB {$default_charset};";
     if (@mysql_query($test_table_sql, $this->database_connection)) {
         $this->printMessage('Test query has been executed. Its safe to proceed with database migration.');
         @mysql_query("DROP TABLE `{$test_table_name}`", $this->database_connection);
     } else {
         $this->printMessage('Failed to executed test query. MySQL said: ' . mysql_error($this->database_connection), true);
         return false;
     }
     // if
     //return ;
     // ---------------------------------------------------
     //  Execute migration
     // ---------------------------------------------------
     $total_queries = 0;
     $executed_queries = 0;
     $upgrade_script = tpl_fetch(get_template_path('db_migration/onion'));
     if ($this->executeMultipleQueries($upgrade_script, $total_queries, $executed_queries, $this->database_connection)) {
         $this->printMessage("Database schema transformations executed (total queries: {$total_queries})");
     } else {
         $this->printMessage('Failed to execute DB schema transformations. MySQL said: ' . mysql_error(), true);
         return false;
     }
     // if
     if (!$this->importMessageComments()) {
         return false;
     }
     // if
     if (!$this->importProjectDocuments()) {
         return false;
     }
     // if
     $this->cleanApplicationLogs();
     $this->fixConfigFile();
     $this->printMessage('ProjectPier has been upgraded. You are now running ProjectPier 0.7. Enjoy!');
 }
コード例 #7
0
 /**
 * Set log_file value
 *
 * @param string $value
 * @return null
 * @throws FileNotWriableError If file exists and is not writable
 * @throws DirDnxError If file does not exists and parent directory does not exists
 * @throws DirNotWritableError If file does not exists, but parent exists and is not writable
 */
 function setLogFile($value) {
   $file_path = $value;
   if(is_file($file_path)) {
     if(!file_is_writable($file_path)) {
       throw new FileNotWriableError($file_path);
     } // if
   } else {
     $folder_path = dirname($file_path);
     if(!is_dir($folder_path)) {
       throw new DirDnxError($folder_path);
     } // if
     if(!folder_is_writable($folder_path)) {
       throw new DirNotWritableError($folder_path);
     } // if
   } // if
   $this->log_file = $value;
 } // setLogFile
コード例 #8
0
 /**
  * Execute upgrade script that is responsible for upgrade process from installed version to target version
  *
  * @param string $version_from
  * @param string $to_version
  * @return null
  */
 function upgrade($version_from, $version_to)
 {
     $scripts = $this->getScripts();
     // check if version_to exists and there's a path from current version to version_to.
     if (is_array($scripts)) {
         // scripts are sorted according to the "to" upgrade version
         $exists = false;
         $current = $version_from;
         foreach ($scripts as $script) {
             if ($script->worksFor($current)) {
                 $current = $script->getVersionTo();
                 if (version_compare($current, $version_to) == 0) {
                     $exists = true;
                     break;
                 }
             }
         }
         // foreach
         if (!$exists) {
             $this->printMessage("There is no upgrade path from version {$version_from} to {$version_to}.");
             return;
         }
         // include config file
         $config_is_set = @(include_once INSTALLATION_PATH . '/config/config.php');
         if (!$config_is_set) {
             $this->printMessage('Valid config file was not found!', true);
             return false;
         } else {
             $this->printMessage('Config file found and loaded.');
         }
         // if
         // check preconditions
         $write_checks = array();
         $ext_checks = array();
         foreach ($scripts as $script) {
             if (version_compare($script->getVersionTo(), $version_from) > 0 && version_compare($script->getVersionTo(), $version_to) <= 0) {
                 $write_checks = array_merge($write_checks, $script->getCheckIsWritable());
                 $ext_checks = array_merge($ext_checks, $script->getCheckExtensions());
             }
             // if
         }
         // foreach
         $write_checks = array_unique($write_checks);
         $ext_checks = array_unique($ext_checks);
         // check for writable files and folders
         foreach ($write_checks as $relative_path) {
             $path = INSTALLATION_PATH . $relative_path;
             if (is_file($path)) {
                 if (file_is_writable($path)) {
                     $this->printMessage("File '{$relative_path}' exists and is writable");
                 } else {
                     $this->printMessage("File '{$relative_path}' is not writable", true);
                     return false;
                 }
                 // if
             } else {
                 if (is_dir($path)) {
                     if (folder_is_writable($path)) {
                         $this->printMessage("Folder '{$relative_path}' exists and is writable");
                     } else {
                         $this->printMessage("Folder '{$relative_path}' is not writable", true);
                         return false;
                     }
                     // if
                 } else {
                     $this->printMessage("'{$relative_path}' does not exists on the system", true);
                     return false;
                 }
             }
             // if
         }
         // foreach
         // check for loaded extensions
         foreach ($ext_checks as $extension_name) {
             if (extension_loaded($extension_name)) {
                 $this->printMessage("Extension '{$extension_name}' is loaded");
             } else {
                 $this->printMessage("Extension '{$extension_name}' is not loaded", true);
                 return false;
             }
             // if
         }
         // foreach
         // connect to database
         if ($dbc = mysql_connect(DB_HOST, DB_USER, DB_PASS)) {
             if (mysql_select_db(DB_NAME, $dbc)) {
                 $this->printMessage('Upgrade script has connected to the database.');
             } else {
                 $this->printMessage('Failed to select database ' . DB_NAME);
                 return false;
             }
             // if
         } else {
             $this->printMessage('Failed to connect to database');
             return false;
         }
         // if
         // check MySQL version
         $mysql_version = mysql_get_server_info($dbc);
         if ($mysql_version && version_compare($mysql_version, "4.1", '>=')) {
             $constants['DB_CHARSET'] = 'utf8';
             @mysql_query("SET NAMES 'utf8'", $dbc);
             tpl_assign('default_collation', $default_collation = 'collate utf8_unicode_ci');
             tpl_assign('default_charset', $default_charset = 'DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci');
         } else {
             tpl_assign('default_collation', $default_collation = '');
             tpl_assign('default_charset', $default_charset = '');
         }
         // if
         tpl_assign('table_prefix', TABLE_PREFIX);
         if (defined('DB_ENGINE')) {
             tpl_assign('engine', DB_ENGINE);
         } else {
             tpl_assign('engine', 'InnoDB');
         }
         // check test query
         $test_table_name = TABLE_PREFIX . 'test_table';
         $test_table_sql = "CREATE TABLE `{$test_table_name}` (\n\t\t\t\t`id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t\t`name` varchar(50) {$default_collation} NOT NULL default '',\n\t\t\t\tPRIMARY KEY  (`id`)\n\t\t\t\t) ENGINE=InnoDB {$default_charset};";
         if (@mysql_query($test_table_sql, $dbc)) {
             $this->printMessage('Test query has been executed. Its safe to proceed with database migration.');
             @mysql_query("DROP TABLE `{$test_table_name}`", $dbc);
         } else {
             $this->printMessage('Failed to executed test query. MySQL said: ' . mysql_error($dbc), true);
             return false;
         }
         // if
         // execute scripts
         foreach ($scripts as $script) {
             if (version_compare($script->getVersionTo(), $version_from) > 0 && version_compare($script->getVersionTo(), $version_to) <= 0) {
                 $script->setDatabaseConnection($dbc);
                 if ($script->execute() === false) {
                     $this->printMessage("Error upgrading to version " . $script->getVersionTo());
                     break;
                 }
                 $last_correct_version = $script->getVersionTo();
                 tpl_assign('version', $last_correct_version);
                 file_put_contents(INSTALLATION_PATH . '/config/installed_version.php', tpl_fetch(get_template_path('installed_version')));
             }
             // if
         }
         // foreach
         if (isset($last_correct_version)) {
             @mysql_query("UPDATE `" . TABLE_PREFIX . "config_options` SET `value` = 0 WHERE `name` = 'upgrade_last_check_new_version'");
             tpl_assign('version', $last_correct_version);
             return file_put_contents(INSTALLATION_PATH . '/config/installed_version.php', tpl_fetch(get_template_path('installed_version')));
         }
     }
     // if
 }
コード例 #9
0
function sim_delete_file($relpath, $name)
{
    if (!folder_is_writable(SIM_PATH . $relpath)) {
        exit;
    }
    unlink(SIM_PATH . $relpath . '/' . $name);
}
コード例 #10
0
/**
 * do daily backup
 *
 * @param null
 * @return null
 */
function backup_handle_on_daily()
{
    set_time_limit(0);
    $start_time = time();
    if (!ConfigOptions::getValue('backup_enabled')) {
        return true;
    }
    // if
    // check if backup path exists and if it's writable
    recursive_mkdir(BACKUP_PATH, 0777, WORK_PATH);
    if (!is_dir(BACKUP_PATH) || !folder_is_writable(BACKUP_PATH)) {
        backup_module_log_error('Backup path (' . BACKUP_PATH . ') does not exists or it is not writable', BACKUP_MODULE_SEND_ERROR_EMAIL);
        return false;
    }
    // if
    $htaccess = BACKUP_PATH . '/.htaccess';
    if (!is_file($htaccess)) {
        file_put_contents($htaccess, 'Deny from all');
    }
    $folder_name = "backup " . date('Y-m-d H-i') . " GMT";
    $backup_dir = BACKUP_PATH . '/' . $folder_name;
    // check if backup already exists
    if (is_dir($backup_dir)) {
        backup_module_log_error("Backup already exists ({$folder_name})", BACKUP_MODULE_SEND_ERROR_EMAIL);
        return false;
    }
    // if
    // try to create backup directory
    if (!recursive_mkdir($backup_dir, 0777, WORK_PATH)) {
        backup_module_log_error("Could not create backup folder ({$backup_dir})", BACKUP_MODULE_SEND_ERROR_EMAIL);
        return false;
    }
    // if
    chmod($backup_dir, 0777);
    // backup database (all tables that starts with TABLE_PREFIX)
    $tables = db_list_tables(TABLE_PREFIX);
    if (is_foreachable($tables)) {
        $result = db_dump_tables($tables, $backup_dir . '/database.sql');
        if (is_error($result)) {
            safe_delete_dir($backup_dir, BACKUP_PATH);
            backup_module_log_error($result->getMessage(), BACKUP_MODULE_SEND_ERROR_EMAIL);
            return false;
        }
        // if
    } else {
        safe_delete_dir($backup_dir, BACKUP_PATH);
        backup_module_log_error("Database specified in config.php file does not have exportable tables. Check your config settings", BACKUP_MODULE_SEND_ERROR_EMAIL);
        return false;
    }
    // backup uploads
    $errors = array();
    $result = backup_module_copy_dir(UPLOAD_PATH, $backup_dir . '/upload', true, $errors);
    if (!$result) {
        safe_delete_dir($backup_dir, BACKUP_PATH);
        backup_module_log_error($errors, BACKUP_MODULE_SEND_ERROR_EMAIL);
        return false;
    }
    // if
    // backup project icons
    $errors = array();
    $result = backup_module_copy_dir(PUBLIC_PATH . '/projects_icons', $backup_dir . '/projects_icons', true, $errors);
    if (!$result) {
        safe_delete_dir($backup_dir, BACKUP_PATH);
        backup_module_log_error($errors, BACKUP_MODULE_SEND_ERROR_EMAIL);
        return false;
    }
    // if
    // backup avatars
    $errors = array();
    $result = backup_module_copy_dir(PUBLIC_PATH . '/avatars', $backup_dir . '/avatars', true, $errors);
    if (!$result) {
        safe_delete_dir($backup_dir, BACKUP_PATH);
        backup_module_log_error($errors, BACKUP_MODULE_SEND_ERROR_EMAIL);
        return false;
    }
    // if
    // backup logos
    $errors = array();
    $result = backup_module_copy_dir(PUBLIC_PATH . '/logos', $backup_dir . '/logos', true, $errors);
    if (!$result) {
        safe_delete_dir($backup_dir, BACKUP_PATH);
        backup_module_log_error($errors, BACKUP_MODULE_SEND_ERROR_EMAIL);
        return false;
    }
    // if
    $app =& application();
    $checksum = backup_module_calculate_checksum($folder_name);
    $backup_note = "<?php \n/* \n";
    $backup_note .= 'Backup is created with activeCollab v' . $app->version . ' on ' . date(DATETIME_MYSQL, $start_time) . "\n\n";
    $backup_note .= "To restore system using this backup, visit this page: \n" . ROOT_URL . '/restore.php?backup=' . urlencode($folder_name) . '&checksum=' . $checksum;
    $backup_note .= "\n*/\n?>";
    if (!file_put_contents($backup_dir . '/restore_instructions.php', $backup_note)) {
        safe_delete_dir($backup_dir, BACKUP_PATH);
        backup_module_log_error("Could not create restore instructions for backup.", BACKUP_MODULE_SEND_ERROR_EMAIL);
        return false;
    }
    // if
    // remove old backups
    $how_many_backups = ConfigOptions::getValue('backup_how_many_backups');
    $how_many_backups = (int) $how_many_backups <= 0 ? 5 : $how_many_backups;
    $folders_in_backup_directory = backup_module_get_backups(BACKUP_PATH);
    if (count($folders_in_backup_directory) > $how_many_backups) {
        $old_backups = array_splice($folders_in_backup_directory, -(count($folders_in_backup_directory) - $how_many_backups));
        foreach ($old_backups as $old_backup) {
            safe_delete_dir($old_backup['path'], BACKUP_PATH);
        }
        // foreach
    }
    // if
    log_message('Daily backup created', LOG_LEVEL_INFO, 'backup');
}
コード例 #11
0
 /**
  * Import language from XML form
  * 
  * @param void
  * @return null
  */
 function import()
 {
     if (!extension_loaded('xml') || !function_exists('xml_parser_create')) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     $import_url = assemble_url('admin_languages_import');
     $this->wireframe->addBreadCrumb(lang('Import Language'), $import_url);
     $step = $this->request->post('wizard_step') ? $this->request->post('wizard_step') : 'initial';
     if ($step == 'initial') {
         $next_step = 'review';
     } else {
         if ($step == 'review') {
             $next_step = 'finalize';
         }
     }
     // if
     if (!folder_is_writable(LOCALIZATION_PATH)) {
         $this->wireframe->addPageMessage(lang('Localization folder: <strong>:folder</strong> is not writable', array('folder' => LOCALIZATION_PATH)), PAGE_MESSAGE_ERROR);
         $this->smarty->assign('import_enabled', false);
     } else {
         $this->smarty->assign(array('import_url' => $import_url, 'step' => $step, 'next_step' => $next_step, 'import_enabled' => true));
         if ($this->request->isSubmitted()) {
             switch ($step) {
                 case 'initial':
                     break;
                 case 'review':
                     $xml_file = $_FILES['xml']['tmp_name'];
                     if (!is_file($xml_file)) {
                         flash_error('You need to upload XML file first');
                         $this->redirectToReferer($import_url);
                     }
                     // if
                     require_once ANGIE_PATH . '/classes/xml/xml2array.php';
                     $language = xml2array(file_get_contents($xml_file));
                     if (!$language) {
                         flash_error('Language XML file is corrupted');
                         $this->redirectToReferer($import_url);
                     }
                     // if
                     $locale = $language['language']['info']['locale']['value'];
                     $name = $language['language']['info']['name']['value'];
                     $ac_version = $language['language']['info']['ac_version']['value'];
                     $system_version = $this->application->version ? $this->application->version : '1.0';
                     if (!$locale || !$name) {
                         flash_error('Language XML file is corrupted');
                         $this->redirectToReferer($import_url);
                     }
                     // if
                     if (Languages::localeExists($locale)) {
                         flash_error('Language with locale :locale is already installed on system', array('locale' => $locale));
                         $this->redirectToReferer($import_url);
                     }
                     // if
                     if (Languages::nameExists($name)) {
                         flash_error('Language with name :name is already installed on system', array('name' => $name));
                         $this->redirectToReferer($import_url);
                     }
                     // if
                     $attachment = make_attachment($_FILES['xml']);
                     if (!$attachment || is_error($attachment)) {
                         flash_error($attachment->getMessage(), array('name' => $name));
                         $this->redirectToReferer($import_url);
                     }
                     // if
                     if (version_compare($ac_version, $system_version, '=') != true) {
                         $this->wireframe->addPageMessage(lang('Current activeCollab version is <strong>:system_version</strong> and this translation is made for <strong>:ac_version</strong> version. Importing can continue, but this translation may not work on your system', array('system_version' => $system_version, 'ac_version' => $ac_version)), 'warning');
                     }
                     // if
                     $this->smarty->assign(array('language_ac_version' => $ac_version, 'language_name' => $name, 'language_locale' => $locale, 'system_version' => $system_version, 'attachment_id' => $attachment->getId()));
                     $this->setTemplate('import_review');
                     break;
                 case 'finalize':
                     $attachment_id = $this->request->post('attachment_id');
                     $attachment = Attachments::findById($attachment_id);
                     if (!instance_of($attachment, 'Attachment')) {
                         flash_error('There was some unknown error, please try again');
                         $this->redirectTo($import_url);
                     }
                     // if
                     require_once ANGIE_PATH . '/classes/xml/xml2array.php';
                     $language_array = xml2array(file_get_contents(UPLOAD_PATH . '/' . $attachment->getLocation()));
                     if (!$language_array) {
                         flash_error('Uploaded file is not valid XML');
                         $this->redirectToReferer($import_url);
                     }
                     // if
                     $language_locale = $language_array['language']['info']['locale']['value'];
                     $language_name = $language_array['language']['info']['name']['value'];
                     $language_version = $language_array['language']['info']['ac_version']['value'];
                     $language = new Language();
                     $language->setLocale($language_locale);
                     $language->setName($language_name);
                     $result = recursive_mkdir($language->getLocalizationPath(), 0777, LOCALIZATION_PATH);
                     if (!$result) {
                         flash_error('Could not create localization folder');
                         $this->redirectToReferer($import_url);
                     }
                     // if
                     $save = $language->save();
                     if (!$save || is_error($save)) {
                         flash_error($save->getMessage());
                         $this->redirectToReferer($import_url);
                     }
                     // if
                     $info = array('name' => $language_name, 'code' => $language_locale, 'version' => $language_version);
                     $result = file_put_contents($language->getLocalizationPath() . '/info.php', "<?php return " . var_export($info, true) . " ?>");
                     if (is_foreachable($language_array['language']['translations']['module'])) {
                         foreach ($language_array['language']['translations']['module'] as $module_translation) {
                             if (is_foreachable($module_translation['translation'])) {
                                 $module_name = $module_translation['attr']['name'];
                                 $output = array();
                                 foreach ($module_translation['translation'] as $translation) {
                                     if (is_array($translation)) {
                                         $phrase = $translation['attr']['phrase'];
                                         $translation_value = $translation['value'];
                                         $output[$phrase] = $translation_value;
                                     }
                                     // if
                                 }
                                 // foreach
                                 $filename = Languages::getTranslationPath($language, $module_name);
                                 file_put_contents($filename, "<?php return " . var_export($output, true) . " ?>");
                             }
                             // if
                         }
                         // foreach
                     }
                     // if
                     $attachment->delete();
                     flash_success('Language imported successfully');
                     $this->redirectTo('admin_languages');
                     break;
                 default:
                     break;
             }
         }
         // if
     }
     // if
 }
コード例 #12
0
 /**
  * Set repository_dir value
  *
  * @param string $value
  * @return null
  * @throws DirDnxError
  * @throws DirNotWritableError
  */
 function setRepositoryDir($value)
 {
     if (!is_null($value) && !is_dir($value)) {
         throw new DirDnxError($value);
     }
     // if
     if (!folder_is_writable($value)) {
         throw new DirNotWritableError($value);
     }
     // if
     $this->repository_dir = $value;
 }
コード例 #13
0
	/**
	 * Execute environment checks
	 *
	 * @access public
	 * @param void
	 * @return boolean
	 */
	function execute() {
		$all_ok = true;

		// Check PHP version
		if(version_compare(PHP_VERSION, '5.0.2', 'ge')) {
			$this->addToChecklist('PHP version is ' . PHP_VERSION, true);
		} else {
			$this->addToChecklist('You PHP version is ' . PHP_VERSION . '. PHP 5.0.2 or newer is required', false);
			$all_ok = false;
		} // if

		foreach($this->check_extensions as $extension_name) {
			if(extension_loaded($extension_name)) {
				$this->addToChecklist("'$extension_name' extension is loaded", true);
			} else {
				$this->addToChecklist("'$extension_name' extension is not loaded", false);
				$all_ok = false;
			} // if
		} // if

		if(is_array($this->check_is_writable)) {
			foreach($this->check_is_writable as $relative_folder_path) {
				$check_this = INSTALLATION_PATH . $relative_folder_path;

				$is_writable = false;
				if(is_file($check_this)) {
					$is_writable = file_is_writable($check_this);
				} elseif(is_dir($check_this)) {
					$is_writable = folder_is_writable($check_this);
				} else {
					 
				}

				if($is_writable) {
					$this->addToChecklist("$relative_folder_path is writable", true);
				} else {
					$this->addToChecklist("$relative_folder_path is not writable", false);
					$all_ok = false;
				} // if
			} // foreach
		} // if
		$memory_config_value = ini_get('memory_limit');
		if($memory_config_value && $memory_config_value!==0 && trim($memory_config_value) != ''){
			$memory_limit = $this->return_bytes($memory_config_value); // Memory allocated to PHP scripts
			if ($memory_limit > 0){
				$suggested_memory = 12582912;
				if ( $memory_limit < $suggested_memory ) {
					$this->addToChecklist("PHP Variable 'memory_limit' is $memory_limit which might not be enough for Feng Office. You should increase it to at least $suggested_memory in your php.ini.", false);
				}
			}
		}

		$this->setContentFromTemplate('checks.php');

		if(ini_get('zend.ze1_compatibility_mode')) {
			$this->addToChecklist('zend.ze1_compatibility_mode is set to On. This can cause some strange problems. It is strongly suggested to turn this value to Off (in your php.ini file)', false);
		} // if

		if($all_ok) {
			return $this->isSubmited();
		} // if

		$this->setNextDisabled(true);
		return false;
	} // execute
 /**
  * Save company details info
  * 
  * @param void
  * @return void
  */
 function index()
 {
     $brand_path = PUBLIC_PATH . '/brand';
     $default_image_name = 'invoicing_logo.jpg';
     $default_full_image_name = $brand_path . '/' . $default_image_name;
     if (!folder_is_writable($brand_path)) {
         $brand_folder_writable = false;
         $this->wireframe->addPageMessage(lang('Brand folder is not writable (:brand_folder). You will not be able to upload company logo.', array('brand_folder' => $brand_path)), PAGE_MESSAGE_WARNING);
     }
     // if
     $company_data = $this->request->post('company');
     if (!is_foreachable($company_data)) {
         $company_data = array('name' => ConfigOptions::getValue('invoicing_company_name'), 'details' => ConfigOptions::getValue('invoicing_company_details'));
     }
     // if
     if ($this->request->isSubmitted()) {
         $errors = new ValidationErrors();
         db_begin_work();
         $company_name = trim(array_var($company_data, 'name'));
         $company_details = trim(array_var($company_data, 'details'));
         if (!$company_name || !$company_details) {
             if (!$company_name) {
                 $errors->addError(lang('Company name is required'), 'company_name');
             }
             // if
             if (!$company_details) {
                 $errors->addError(lang('Company details are required'), 'company_details');
             }
             // if
         } else {
             // copy and convert logo
             $logo_file = array_var($_FILES, 'company_logo', null);
             if ($logo_file['name']) {
                 $pathinfo = pathinfo($logo_file['name']);
                 do {
                     $new_filename = make_string(30) . '.' . array_var($pathinfo, 'extension');
                     $new_file_full_path = $brand_path . '/' . $new_filename;
                 } while (is_file($new_file_full_path));
                 if (move_uploaded_file($logo_file['tmp_name'], $new_file_full_path)) {
                     if (FIX_UPLOAD_PERMISSION !== false) {
                         @chmod($new_file_full_path, FIX_UPLOAD_PERMISSION);
                     }
                     // if
                     scale_image($new_file_full_path, $new_file_full_path, 600, 150, IMAGETYPE_JPEG, 100);
                 } else {
                     $errors->addError(lang('Could not upload company logo'), 'company_logo');
                 }
                 // if
             }
             // if
             $company_logo_url = get_company_invoicing_logo_url();
             db_commit();
         }
         // if
         if (!$errors->hasErrors()) {
             // set config options
             ConfigOptions::setValue('invoicing_company_name', $company_name);
             ConfigOptions::setValue('invoicing_company_details', $company_details);
             @unlink($default_full_image_name);
             rename($new_file_full_path, $default_full_image_name);
             flash_success('Company identity successfully modified');
             $this->redirectTo('admin_invoicing_company_identity');
             db_commit();
         } else {
             @unlink($new_file_full_path);
             db_rollback();
             $this->smarty->assign('errors', $errors);
         }
         // if
     }
     // if
     $company_logo_url = get_company_invoicing_logo_url();
     $this->smarty->assign(array('company_data' => $company_data, 'company_logo_url' => $company_logo_url));
 }