/**
  * Execute the script
  *
  * @param void
  * @return boolean
  */
 function execute()
 {
     // ---------------------------------------------------
     //  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);
     if (defined('DB_ENGINE')) {
         tpl_assign('engine', DB_ENGINE);
     } else {
         tpl_assign('engine', 'InnoDB');
     }
     // ---------------------------------------------------
     //  Execute migration
     // ---------------------------------------------------
     $total_queries = 0;
     $executed_queries = 0;
     $installed_version = installed_version();
     if (version_compare($installed_version, "1.1") <= 0) {
         $upgrade_script = tpl_fetch(get_template_path('db_migration/1_2_chinchulin'));
     } else {
         $upgrade_script = "DELETE FROM `" . TABLE_PREFIX . "config_options` WHERE `name` = 'time_format_use_24';\r\n\t\t\tUPDATE `" . TABLE_PREFIX . "config_options` SET `category_name` = 'modules' WHERE `name` = 'enable_email_module';\r\n\t\t\tALTER TABLE `" . TABLE_PREFIX . "mail_contents` ADD COLUMN `content_file_id` VARCHAR(40) NOT NULL default '';\r\n\t\t\t";
     }
     @unlink("../../language/de_de/._lang.js");
     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
     $this->printMessage('Feng Office has been upgraded. You are now running Feng Office ' . $this->getVersionTo() . ' Enjoy!');
 }
Beispiel #2
0
  <link rel="stylesheet" href="assets/style.css" media="all" />
</head>
<body>
  <div id="wrapper">
    <div id="header">
      <h1><?php 
echo clean($upgrader->getName());
?>
</h1>
      <div id="installationDesc"><?php 
echo clean($upgrader->getDescription());
?>
</div>
    </div>
<?php 
$installed_version = installed_version();
$product_version = (include ROOT . '/version.php');
if (!is_array($form_data)) {
    $form_data = array('upgrade_from' => $installed_version, 'upgrade_to' => $product_version);
}
if (array_var($form_data, 'upgrade_from') == 'unknown') {
    $form_data['upgrade_from'] = '1.1';
}
$scripts = $upgrader->getScriptsSince($installed_version);
if (count($scripts) > 0) {
    ?>
    <form class="internalForm" action="index.php" id="upgraderForm" method="post">
      <div id="upgraderControls">
      	<div class="warning">
      		<strong><?php 
    echo lang('upgrade warning');
 /**
  * Execute the script
  *
  * @param void
  * @return boolean
  */
 function execute()
 {
     // ---------------------------------------------------
     //  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);
     if (defined('DB_ENGINE')) {
         tpl_assign('engine', DB_ENGINE);
     } else {
         tpl_assign('engine', 'InnoDB');
     }
     // ---------------------------------------------------
     //  Execute migration
     // ---------------------------------------------------
     $total_queries = 0;
     $executed_queries = 0;
     $installed_version = installed_version();
     if (version_compare($installed_version, $this->getVersionFrom()) <= 0) {
         // upgrading from a version lower than this script's 'from' version
         $upgrade_script = tpl_fetch(get_template_path('db_migration/1_4_nutria'));
     } else {
         // upgrading from a pre-release of this version (beta, rc, etc)
         $upgrade_script = "";
         if (version_compare($installed_version, '1.4-beta') == 0) {
             $upgrade_script .= "\r\n\t\t\t\tINSERT INTO `" . TABLE_PREFIX . "user_ws_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\r\n\t\t\t\t\t('task panel', 'noOfTasks', '8', 'IntegerConfigHandler', '0', '100', NULL),\r\n\t\t\t\t\t('calendar panel', 'start_monday', '', 'BoolConfigHandler', 0, 0, ''),\r\n\t\t\t\t\t('calendar panel', 'show_week_numbers', '', 'BoolConfigHandler', 0, 0, ''),\r\n\t\t\t\t\t('context help', 'show_reporting_panel_context_help', '1', 'BoolConfigHandler', '1', '0', NULL)\r\n\t\t\t\tON DUPLICATE KEY UPDATE id=id;\r\n\t\t\t\tUPDATE `" . TABLE_PREFIX . "user_ws_config_options`\r\n\t\t\t\t\tSET `is_system` = 0 WHERE `name` IN ('start_monday', 'show_week_numbers');\r\n\t\t\t\tUPDATE `" . TABLE_PREFIX . "user_ws_config_categories`\r\n\t\t\t\t\tSET `is_system` = 0 WHERE `name` = 'calendar panel';\r\n\t\t\t\tINSERT INTO `" . TABLE_PREFIX . "config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\r\n\t\t\t\t\t('general', 'show_feed_links', '0', 'BoolConfigHandler', '0', '0', NULL),\r\n\t\t\t\t\t('mailing', 'user_email_fetch_count', '10', 'IntegerConfigHandler', 0, 0, 'How many emails to fetch when checking for email')\r\n\t\t\t\tON DUPLICATE KEY UPDATE id=id;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "custom_properties` ADD COLUMN `visible_by_default` TINYINT(1) NOT NULL DEFAULT 0 AFTER `property_order`;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "custom_property_values` MODIFY COLUMN `value` text {$default_collation} NOT NULL;\r\n\t\t\t\t-- larger contact fields\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `firstname` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `lastname` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `middlename` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `department` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `job_title` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `w_city` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `w_state` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `w_zipcode` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `w_country` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `w_phone_number` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `w_phone_number2` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `w_fax_number` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `w_assistant_number` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `w_callback_number` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `h_city` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `h_state` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `h_zipcode` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `h_country` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `h_phone_number` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `h_phone_number2` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `h_fax_number` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `h_mobile_number` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `h_pager_number` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `o_city` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `o_state` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `o_zipcode` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `o_country` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `o_phone_number` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `o_phone_number2` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "contacts` MODIFY COLUMN `o_fax_number` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\t\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "companies` MODIFY COLUMN `phone_number` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "companies` MODIFY COLUMN `fax_number` varchar(50) {$default_collation} default NULL;\r\n\t\t\t\t";
         }
         if (version_compare($installed_version, '1.4-rc') <= 0) {
             $upgrade_script .= "\r\n\t\t\t\tINSERT INTO `" . TABLE_PREFIX . "user_ws_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\r\n\t\t\t\t ('context help', 'show_administration_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_member_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_contact_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_company_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_upload_file_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_upload_file_workspace_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_upload_file_tags_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_upload_file_description_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_upload_file_custom_properties_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_upload_file_subscribers_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_upload_file_linked_objects_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_note_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_note_workspace_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_note_tags_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_note_custom_properties_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_note_subscribers_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_note_linked_object_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_milestone_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_milestone_workspace_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_milestone_tags_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_milestone_description_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_milestone_reminders_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_milestone_custom_properties_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_milestone_linked_object_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_milestone_subscribers_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_workspace_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_print_report_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_task_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_task_workspace_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_task_tags_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_task_reminders_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_task_custom_properties_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_task_linked_objects_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_task_subscribers_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_list_task_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_time_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_webpage_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_webpage_workspace_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_webpage_tags_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_webpage_description_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_webpage_custom_properties_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_webpage_subscribers_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_webpage_linked_objects_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('dashboard', 'show calendar widget', '1', 'BoolConfigHandler', 0, 80, ''),\r\n\t\t\t\t ('dashboard', 'show late tasks and milestones widget', '1', 'BoolConfigHandler', 0, 100, ''),\r\n\t\t\t\t ('dashboard', 'show pending tasks widget', '1', 'BoolConfigHandler', 0, 200, ''),\r\n\t\t\t\t ('dashboard', 'pending tasks widget assigned to filter', '0:0', 'UserCompanyConfigHandler', 0, 210, ''),\r\n\t\t\t\t ('dashboard', 'show emails widget', '1', 'BoolConfigHandler', 0, 300, ''),\r\n\t\t\t\t ('dashboard', 'show messages widget', '1', 'BoolConfigHandler', 0, 400, ''),\r\n\t\t\t\t ('dashboard', 'show documents widget', '1', 'BoolConfigHandler', 0, 500, ''),\r\n\t\t\t\t ('dashboard', 'show charts widget', '1', 'BoolConfigHandler', 0, 600, ''),\r\n\t\t\t\t ('dashboard', 'show tasks in progress widget', '1', 'BoolConfigHandler', 0, 700, ''),\r\n\t\t\t\t ('dashboard', 'show comments widget', '1', 'BoolConfigHandler', 0, 800, ''),\r\n\t\t\t\t ('dashboard', 'show dashboard info widget', '1', 'BoolConfigHandler', 0, 900, ''),\r\n\t\t\t\t ('dashboard', 'always show unread mail in dashboard', '0', 'BoolConfigHandler', 0, 10, 'when false, active workspace email is shown'),\r\n\t\t\t\t ('dashboard', 'calendar_widget_expanded', '1', 'BoolConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('dashboard', 'emails_widget_expanded', '1', 'BoolConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('dashboard', 'messages_widget_expanded', '1', 'BoolConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('dashboard', 'active_tasks_widget_expanded', '1', 'BoolConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('dashboard', 'pending_tasks_widget_expanded', '1', 'BoolConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('dashboard', 'late_tasks_widget_expanded', '1', 'BoolConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('dashboard', 'comments_widget_expanded', '1', 'BoolConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('dashboard', 'documents_widget_expanded', '1', 'BoolConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('dashboard', 'charts_widget_expanded', '1', 'BoolConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('dashboard', 'dashboard_info_widget_expanded', '1', 'BoolConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('task panel', 'can notify from quick add', '1', 'BoolConfigHandler', 0, 0, ''),\r\n\t\t\t\t ('task panel', 'tasksShowWorkspaces', '1', 'BoolConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('task panel', 'tasksShowTime', '1', 'BoolConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('task panel', 'tasksShowDates', '1', 'BoolConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('task panel', 'tasksShowTags', '1', 'BoolConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('task panel', 'tasksGroupBy', 'milestone', 'StringConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('task panel', 'tasksOrderBy', 'priority', 'StringConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('task panel', 'task panel status', '1', 'IntegerConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('task panel', 'task panel filter', 'assigned_to', 'StringConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('task panel', 'task panel filter value', '0:0', 'UserCompanyConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('time panel', 'TM show time type', '0', 'IntegerConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('time panel', 'TM report show time type', '0', 'IntegerConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('time panel', 'TM user filter', '0', 'IntegerConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('time panel', 'TM tasks user filter', '0', 'IntegerConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('general', 'localization', '', 'LocalizationConfigHandler', 0, 100, ''),\r\n\t\t\t\t ('general', 'initialWorkspace', '0', 'InitialWorkspaceConfigHandler', 0, 200, ''),\r\n\t\t\t\t ('general', 'lastAccessedWorkspace', '0', 'IntegerConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('general', 'rememberGUIState', '0', 'BoolConfigHandler', 0, 300, ''),\r\n\t\t\t\t ('general', 'work_day_start_time', '9:00', 'TimeConfigHandler', 0, 400, 'Work day start time'),\r\n\t\t\t\t ('general', 'time_format_use_24', '0', 'BoolConfigHandler', 0, 500, 'Use 24 hours time format'),\r\n\t\t\t\t ('general', 'date_format', 'd/m/Y', 'StringConfigHandler', 0, 600, 'Date objects will be displayed using this format.'),\r\n\t\t\t\t ('general', 'descriptive_date_format', 'l, j F', 'StringConfigHandler', 0, 700, 'Descriptive dates will be displayed using this format.'),\r\n\t\t\t\t ('calendar panel', 'calendar view type', 'viewweek', 'StringConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('calendar panel', 'calendar user filter', '0', 'IntegerConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('calendar panel', 'calendar status filter', '', 'StringConfigHandler', 1, 0, ''),\r\n\t\t\t\t ('calendar panel', 'start_monday', '', 'BoolConfigHandler', 0, 0, ''),\r\n\t\t\t\t ('calendar panel', 'show_week_numbers', '', 'BoolConfigHandler', 0, 0, ''),\r\n\t\t\t\t ('dashboard', 'show getting started widget', '1', 'BoolConfigHandler', '0', '1000', NULL),\r\n\t\t\t\t ('dashboard', 'getting_started_widget_expanded', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_tasks_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_account_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_active_tasks_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_general_timeslots_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_late_tasks_widget_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_pending_tasks_widget_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_documents_widget_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_active_tasks_widget_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_calendar_widget_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_messages_widget_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_dashboard_info_widget_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_comments_widget_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_emails_widget_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_reporting_panel_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('context help', 'show_add_file_context_help', '1', 'BoolConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('general', 'custom_report_tab', 'tasks', 'StringConfigHandler', '1', '0', NULL),\r\n\t\t\t\t ('general', 'show_context_help', 'until_close', 'ShowContextHelpConfigHandler', '0', '0', NULL),\r\n\t\t\t\t ('task panel', 'noOfTasks', '8', 'IntegerConfigHandler', '0', '100', NULL)\r\n\t\t\t\t ON DUPLICATE KEY UPDATE id=id;\r\n\t\t\t\tUPDATE `" . TABLE_PREFIX . "user_ws_config_options`\r\n\t\t\t\t\tSET `is_system` = 1, `category_name` = 'context help' WHERE `name` = 'show_tasks_context_help';\r\n\t\t\t\tDELETE FROM `" . TABLE_PREFIX . "config_options` where name='upgrade_check_enabled';\r\n\t\t\t\t";
         }
         if (!$this->checkColumnExists(TABLE_PREFIX . 'reports', 'is_order_by_asc', $this->database_connection)) {
             $upgrade_script .= "\r\n\t\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "reports` ADD COLUMN `is_order_by_asc` TINYINT(1) {$default_collation} NOT NULL DEFAULT 1;\r\n\t\t\t\t";
         }
     }
     $upgrade_script .= "\r\n\t\t\tUPDATE `" . TABLE_PREFIX . "user_ws_config_categories` SET `is_system` = 0 WHERE `name` = 'calendar_panel';\r\n\t\t";
     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
     // ---------------------------------------------------
     //  Add SEED to config file
     // ---------------------------------------------------
     $config_file = INSTALLATION_PATH . '/config/config.php';
     $config_lines = file($config_file);
     $new_config = array();
     // Check SEED definition existence
     $add_seed = true;
     foreach ($config_lines as $line) {
         if (str_starts_with(trim($line), "define('SEED'")) {
             $add_seed = false;
             break;
         }
     }
     foreach ($config_lines as $line) {
         $new_config[] = $line;
         if ($add_seed && trim($line) == "<?php") {
             $new_config[] = "  define('SEED', '" . DB_USER . DB_PASS . rand(0, 10000000000.0) . "');\n";
         }
     }
     if (!$add_seed) {
         //remove repeated SEED definitions
         $i = 0;
         $lines_to_remove = array();
         while ($i < count($config_lines)) {
             $line = $new_config[$i];
             if (str_starts_with(trim($line), "define('SEED'")) {
                 $lines_to_remove[] = $i;
             }
             $i++;
         }
         // remove SEED lines except the last one
         unset($lines_to_remove[count($lines_to_remove) - 1]);
         foreach ($lines_to_remove as $index) {
             $new_config[$index] = '';
         }
     }
     $new_content = join('', $new_config);
     $fp = fopen($config_file, 'w');
     fwrite($fp, $new_content);
     $this->printMessage('Feng Office has been upgraded. You are now running Feng Office ' . $this->getVersionTo() . ' Enjoy!');
 }
 /**
  * Execute the script
  *
  * @param void
  * @return boolean
  */
 function execute()
 {
     if (!@mysql_ping($this->database_connection)) {
         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;
             }
             $this->setDatabaseConnection($dbc);
         } else {
             $this->printMessage('Failed to connect to database');
             return false;
         }
     }
     // ---------------------------------------------------
     //  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
     $installed_version = installed_version();
     $t_prefix = TABLE_PREFIX;
     $additional_upgrade_steps = array();
     // RUN QUERIES
     $total_queries = 0;
     $executed_queries = 0;
     $upgrade_script = "";
     $upgrade_loop_script = "";
     $upgrade_after_loop_script = "";
     $multi_assignment_create = "";
     $multi_assignment = "";
     if ($this->checkColumnExists($t_prefix . 'project_tasks', 'multi_assignment', $this->database_connection)) {
         $multi_assignment_create .= "ALTER TABLE `" . $t_prefix . "template_tasks` ADD `multi_assignment` TINYINT( 1 ) NULL DEFAULT 0;";
         $multi_assignment .= ", `multi_assignment`";
     }
     $v_from = array_var($_POST, 'form_data');
     $original_version_from = array_var($v_from, 'upgrade_from', $installed_version);
     if (false && version_compare($installed_version, $this->getVersionFrom()) <= 0 && version_compare($original_version_from, '2.0.0.0-beta') > 0 && (!isset($_SESSION['from_feng1']) || !$_SESSION['from_feng1'])) {
         // upgrading from a version lower than this script's 'from' version
         $upgrade_script = tpl_fetch(get_template_path('db_migration/2_4_morcilla'));
     } else {
         if (version_compare($installed_version, '2.4-beta') < 0) {
             $upgrade_script .= "\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES \r\n\t\t\t\t\t\t('general', 'timeReportDate', '4', 'IntegerConfigHandler', 1, 0, ''),\r\n\t\t\t\t\t\t('general', 'timeReportDateStart', '0000-00-00 00:00:00', 'DateTimeConfigHandler', 1, 0, ''),\r\n\t\t\t\t\t\t('general', 'timeReportDateEnd', '0000-00-00 00:00:00', 'DateTimeConfigHandler', 1, 0, ''),\r\n\t\t\t\t\t\t('general', 'timeReportPerson', '0', 'IntegerConfigHandler', 1, 0, ''),\r\n\t\t\t\t\t\t('general', 'timeReportTimeslotType', '2', 'IntegerConfigHandler', 1, 0, ''),\r\n\t\t\t\t\t\t('general', 'timeReportGroupBy', '0,0,0', 'StringConfigHandler', 1, 0, ''),\r\n\t\t\t\t\t\t('general', 'timeReportAltGroupBy', '0,0,0', 'StringConfigHandler', 1, 0, ''),\r\n\t\t\t\t\t\t('general', 'timeReportShowBilling', '0', 'BoolConfigHandler', 1, 0, '')\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t\t";
             if (!$this->checkColumnExists($t_prefix . "contact_addresses", "street", $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\t\tALTER TABLE `" . $t_prefix . "contact_addresses` MODIFY COLUMN `street` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL;\r\n\t\t\t\t\t";
             }
             if (!$this->checkColumnExists($t_prefix . "system_permissions", "can_manage_contacts", $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\t\tALTER TABLE `" . $t_prefix . "system_permissions` ADD COLUMN `can_manage_contacts` BOOLEAN NOT NULL DEFAULT 0;\r\n\t\t\t\t\t";
             }
             $upgrade_script .= "\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES \r\n\t\t\t\t\t\t('listing preferences', 'breadcrumb_member_count', '5', 'IntegerConfigHandler', '0', '5', NULL)\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t\t\t\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "object_types` (`name`,`handler_class`,`table_name`,`type`,`icon`,`plugin_id`) VALUES\r\n \t\t\t\t\t\t('template_task', 'TemplateTasks', 'template_tasks', 'content_object', 'task', null),\r\n\t\t\t\t\t\t('template_milestone', 'TemplateMilestones', 'template_milestones', 'content_object', 'milestone', null)\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t\t";
             if (!$this->checkColumnExists($t_prefix . "project_tasks", "from_template_object_id", $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\t\tALTER TABLE `" . $t_prefix . "project_tasks` ADD `from_template_object_id` int(10) unsigned DEFAULT '0' AFTER from_template_id;\r\n\t\t\t\t\t\t/* from template object id queda en 0 para todos los objetos instanciados de templates ya que no se puede obtener */\r\n\t\t\t\t\t";
             }
             if (!$this->checkColumnExists($t_prefix . "project_milestones", "from_template_object_id", $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\t\tALTER TABLE `" . $t_prefix . "project_milestones` ADD `from_template_object_id` int(10) unsigned DEFAULT '0' AFTER from_template_id;\r\n\t\t\t\t\t\t/* from template object id queda en 0 para todos los objetos instanciados de templates ya que no se puede obtener */\r\n\t\t\t\t\t";
             }
             $upgrade_script .= "\r\n\t\t\t\t\tCREATE TABLE IF NOT EXISTS `" . $t_prefix . "template_tasks` (\r\n\t\t\t\t\t  `template_id` int(10) unsigned DEFAULT NULL,\r\n\t\t\t\t\t  `session_id` int(10) DEFAULT NULL,\r\n\t\t\t\t\t  `object_id` int(10) unsigned NOT NULL,\r\n\t\t\t\t\t  `parent_id` int(10) unsigned DEFAULT NULL,\r\n\t\t\t\t\t  `text` text COLLATE utf8_unicode_ci NOT NULL,\r\n\t\t\t\t\t  `due_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\r\n\t\t\t\t\t  `start_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\r\n\t\t\t\t\t  `assigned_to_contact_id` int(10) unsigned DEFAULT NULL,\r\n\t\t\t\t\t  `assigned_on` datetime DEFAULT NULL,\r\n\t\t\t\t\t  `assigned_by_id` int(10) unsigned DEFAULT NULL,\r\n\t\t\t\t\t  `time_estimate` int(10) unsigned NOT NULL DEFAULT '0',\r\n\t\t\t\t\t  `completed_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\r\n\t\t\t\t\t  `completed_by_id` int(10) unsigned DEFAULT NULL,\r\n\t\t\t\t\t  `started_on` datetime DEFAULT NULL,\r\n\t\t\t\t\t  `started_by_id` int(10) unsigned NOT NULL,\r\n\t\t\t\t\t  `priority` int(10) unsigned DEFAULT '200',\r\n\t\t\t\t\t  `state` int(10) unsigned DEFAULT NULL,\r\n\t\t\t\t\t  `order` int(10) unsigned DEFAULT '0',\r\n\t\t\t\t\t  `milestone_id` int(10) unsigned DEFAULT NULL,\r\n\t\t\t\t\t  `is_template` tinyint(1) NOT NULL DEFAULT '0',\r\n\t\t\t\t\t  `from_template_id` int(10) NOT NULL DEFAULT '0',\r\n\t\t\t\t\t  `from_template_object_id` int(10) unsigned DEFAULT '0',\r\n\t\t\t\t\t  `repeat_end` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\r\n\t\t\t\t\t  `repeat_forever` tinyint(1) NOT NULL,\r\n\t\t\t\t\t  `repeat_num` int(10) unsigned NOT NULL DEFAULT '0',\r\n\t\t\t\t\t  `repeat_d` int(10) unsigned NOT NULL,\r\n\t\t\t\t\t  `repeat_m` int(10) unsigned NOT NULL,\r\n\t\t\t\t\t  `repeat_y` int(10) unsigned NOT NULL,\r\n\t\t\t\t\t  `repeat_by` varchar(15) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '',\r\n\t\t\t\t\t  `object_subtype` int(10) unsigned NOT NULL DEFAULT '0',\r\n\t\t\t\t\t  `percent_completed` int(10) unsigned NOT NULL DEFAULT '0',\r\n\t\t\t\t\t  `use_due_time` tinyint(1) DEFAULT '0',\r\n\t\t\t\t\t  `use_start_time` tinyint(1) DEFAULT '0',\r\n\t\t\t\t\t  `original_task_id` int(10) unsigned DEFAULT '0',\r\n\t\t\t\t\t  `type_content` enum('text','html') NOT NULL DEFAULT 'text',\r\n\t\t\t\t\t  PRIMARY KEY (`object_id`),\r\n\t\t\t\t\t  KEY `parent_id` (`parent_id`),\r\n\t\t\t\t\t  KEY `completed_on` (`completed_on`),\r\n\t\t\t\t\t  KEY `order` (`order`),\r\n\t\t\t\t\t  KEY `milestone_id` (`milestone_id`),\r\n\t\t\t\t\t  KEY `priority` (`priority`),\r\n\t\t\t\t\t  KEY `assigned_to` USING HASH (`assigned_to_contact_id`)\r\n\t\t\t\t\t) ENGINE= InnoDB;\r\n\t\t\t\t\t\r\n\t\t\t\t\tCREATE TABLE IF NOT EXISTS `" . $t_prefix . "template_milestones` (\r\n\t\t\t\t\t  `template_id` int(10) unsigned DEFAULT NULL,\r\n\t\t\t\t\t  `session_id` int(10) DEFAULT NULL,\r\n\t\t\t\t\t  `object_id` int(10) unsigned NOT NULL,\r\n\t\t\t\t\t  `description` text COLLATE utf8_unicode_ci NOT NULL,\r\n\t\t\t\t\t  `due_date` datetime NOT NULL default '0000-00-00 00:00:00',\r\n\t\t\t\t\t  `is_urgent` BOOLEAN NOT NULL default '0',\r\n\t\t\t\t\t  `completed_on` datetime NOT NULL default '0000-00-00 00:00:00',\r\n\t\t\t\t\t  `completed_by_id` int(10) unsigned default NULL,\r\n\t\t\t\t\t  `is_template` BOOLEAN NOT NULL default '0',\r\n\t\t\t\t\t  `from_template_id` int(10) NOT NULL default '0',\r\n\t\t\t\t\t  `from_template_object_id` int(10) unsigned DEFAULT '0',\r\n\t\t\t\t\t  PRIMARY KEY  (`object_id`),\r\n\t\t\t\t\t  KEY `due_date` (`due_date`),\r\n\t\t\t\t\t  KEY `completed_on` (`completed_on`)\r\n\t\t\t\t\t) ENGINE= InnoDB;\r\n\t\t\t\t\t\r\n\t\t\t\t\t/* copy milestones */\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "template_milestones`(`template_id`, `session_id`, `object_id`, `description`, `due_date`, `is_urgent`, `completed_on`, `completed_by_id`, `is_template`, `from_template_id`, `from_template_object_id`)\r\n\t\t\t\t\tSELECT " . $t_prefix . "template_objects.template_id,'0' AS `session_id` ," . $t_prefix . "project_milestones.`object_id`, `description`, `due_date`, `is_urgent`, `completed_on`, `completed_by_id`, `is_template`, `from_template_id`, `from_template_object_id`\r\n\t\t\t\t\tFROM `" . $t_prefix . "template_objects` \r\n\t\t\t\t\tINNER JOIN `" . $t_prefix . "project_milestones` \r\n\t\t\t\t\tON " . $t_prefix . "template_objects.object_id = " . $t_prefix . "project_milestones.object_id\r\n\t\t\t\t\tAND " . $t_prefix . "project_milestones.is_template =1\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE " . $t_prefix . "template_milestones.template_id=" . $t_prefix . "template_milestones.template_id;\r\n\t\t\t\t\t\r\n\t\t\t\t\t/* delete from project milestones, milestones that are template milestones */\r\n\t\t\t\t\tDELETE FROM `" . $t_prefix . "project_milestones` WHERE `is_template` = 1;\r\n\t\t\t\t\t\r\n\t\t\t\t\t/* change the object type from project milestone to template milestone */\r\n\t\t\t\t\tUPDATE `" . $t_prefix . "objects` SET object_type_id = (SELECT id FROM `" . $t_prefix . "object_types` WHERE name = 'template_milestone')\r\n\t\t\t\t\tWHERE id IN (SELECT object_id FROM `" . $t_prefix . "template_milestones`);\r\n\t\t\t\t\t\r\n\t\t\t\t\tUPDATE `" . $t_prefix . "cron_events` set enabled=0, is_system=1 WHERE name='check_upgrade';\r\n\t\t\t\t\tupdate " . $t_prefix . "project_tasks set percent_completed=100 where completed_on <> '0000-00-00 00:00:00';\r\n\t\t\t\t";
         }
         if (version_compare($installed_version, '2.4.1-beta') <= 0) {
             $upgrade_script .= "\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`)\r\n\t\t\t\t\tVALUES ('mails panel', 'attach_to_notification', '1', 'BoolConfigHandler', '0', '0', NULL)\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t\t";
             if (!$this->checkColumnExists($t_prefix . "project_files", "attach_to_notification", $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\t\tALTER TABLE `" . $t_prefix . "project_files` ADD `attach_to_notification` TINYINT( 1 ) NOT NULL DEFAULT 0;\r\n\t\t\t\t\t";
             }
             if (!$this->checkColumnExists($t_prefix . "project_files", "default_subject", $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\t\tALTER TABLE `" . $t_prefix . "project_files` ADD `default_subject` TEXT;\r\n\t\t\t\t\t";
             }
             $upgrade_script .= "\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) \r\n\t\t\t\t\tVALUES ('general', 'notify_myself_too', 0, 'BoolConfigHandler', '0', '100', '')\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t\t";
             $upgrade_script .= "\r\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "contact_member_permissions` ADD INDEX (`member_id`);\r\n\t\t\t\t";
         }
     }
     if ($this->executeMultipleQueries($upgrade_script, $total_queries, $executed_queries, $this->database_connection)) {
         if (version_compare($installed_version, '2.4-beta') < 0) {
             $while_condition = true;
             //add multi_assignment to template tasks table
             $upgrade_before_loop_script = $multi_assignment_create;
             //copy tasks
             $upgrade_before_loop_script .= "\r\n\t\t\t\t\t/* Copy tasks that are in templates objects */\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "template_tasks`(`template_id`, `session_id`, `object_id`, `parent_id`, `text`, `due_date`, `start_date`, `assigned_to_contact_id`, `assigned_on`, `assigned_by_id`, `time_estimate`, `completed_on`, `completed_by_id`, `started_on`, `started_by_id`, `priority`, `state`, `order`, `milestone_id`, `is_template`, `from_template_id`, `from_template_object_id`, `repeat_end`, `repeat_forever`, `repeat_num`, `repeat_d`, `repeat_m`, `repeat_y`, `repeat_by`, `object_subtype`, `percent_completed`, `use_due_time`, `use_start_time`, `original_task_id`, `type_content`" . $multi_assignment . ")\r\n\t\t\t\t\tSELECT " . $t_prefix . "template_objects.template_id,'0' AS `session_id` ," . $t_prefix . "project_tasks.`object_id`, `parent_id`, `text`, `due_date`, `start_date`, `assigned_to_contact_id`, `assigned_on`, `assigned_by_id`, `time_estimate`, `completed_on`, `completed_by_id`, `started_on`, `started_by_id`, `priority`, `state`, `order`, `milestone_id`, `is_template`, `from_template_id`, `from_template_object_id`, `repeat_end`, `repeat_forever`, `repeat_num`, `repeat_d`, `repeat_m`, `repeat_y`, `repeat_by`, `object_subtype`, `percent_completed`, `use_due_time`, `use_start_time`, `original_task_id`, `type_content`" . $multi_assignment . "\r\n\t\t\t\t\tFROM `" . $t_prefix . "template_objects` \r\n\t\t\t\t\tINNER JOIN `" . $t_prefix . "project_tasks` \r\n\t\t\t\t\tON " . $t_prefix . "template_objects.object_id = " . $t_prefix . "project_tasks.object_id\r\n\t\t\t\t\tAND " . $t_prefix . "project_tasks.is_template =1\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE session_id = 0;\r\n\t\t\t\t";
             // Copy subtasks for tasks that are in template tasks.
             $upgrade_loop_script = "\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "template_tasks`(`template_id`, `session_id`, `object_id`, `parent_id`, `text`, `due_date`, `start_date`, `assigned_to_contact_id`, `assigned_on`, `assigned_by_id`, `time_estimate`, `completed_on`, `completed_by_id`, `started_on`, `started_by_id`, `priority`, `state`, `order`, `milestone_id`, `is_template`, `from_template_id`, `from_template_object_id`, `repeat_end`, `repeat_forever`, `repeat_num`, `repeat_d`, `repeat_m`, `repeat_y`, `repeat_by`, `object_subtype`, `percent_completed`, `use_due_time`, `use_start_time`, `original_task_id`, `type_content`" . $multi_assignment . ")\n\t\t\t\t\tSELECT '0' AS `template_id`,'0' AS `session_id`, pt.`object_id`, pt.`parent_id`, pt.`text`, pt.`due_date`, pt.`start_date`, pt.`assigned_to_contact_id`, pt.`assigned_on`, pt.`assigned_by_id`, pt.`time_estimate`, pt.`completed_on`, pt.`completed_by_id`, pt.`started_on`, pt.`started_by_id`, pt.`priority`, pt.`state`, pt.`order`, pt.`milestone_id`, pt.`is_template`, pt.`from_template_id`, pt.`from_template_object_id`, pt.`repeat_end`, pt.`repeat_forever`, pt.`repeat_num`, pt.`repeat_d`, pt.`repeat_m`, pt.`repeat_y`, pt.`repeat_by`, pt.`object_subtype`, pt.`percent_completed`, pt.`use_due_time`, pt.`use_start_time`, pt.`original_task_id`, pt.`type_content`" . $multi_assignment . "\r\n\t\t\t\t\tFROM `" . $t_prefix . "project_tasks` AS pt\n\t\t\t\t\tWHERE pt.parent_id IN\n\t\t\t\t\t(SELECT pt2.`object_id`\n\t\t\t\t\tFROM `" . $t_prefix . "template_tasks` AS pt2)\n\t\t\t\t\tON DUPLICATE KEY UPDATE " . $t_prefix . "template_tasks.parent_id = pt.parent_id;\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t/* copy template id from task to subtask */\r\n\t\t\t\t\tUPDATE " . $t_prefix . "template_tasks AS t1, " . $t_prefix . "template_tasks AS t2 SET t1.template_id=t2.template_id\r\n\t\t\t\t\tWHERE t1.parent_id=t2.object_id;\r\n\t\t\t\t";
             $check_continue_condition = "\n\t\t\t\t\tSELECT object_id\n\t\t\t\t\tFROM `" . $t_prefix . "project_tasks` AS pt\n\t\t\t\t\tWHERE pt.parent_id IN (SELECT pt2.object_id\n\t\t\t\t\t\tFROM `" . $t_prefix . "template_tasks` AS pt2)\n\t\t\t\t\tAND NOT EXISTS (SELECT * FROM `" . $t_prefix . "template_tasks` AS pt3\n\t\t\t\t\t\tWHERE pt3.object_id = pt.object_id);\n\t\t\t\t\t";
             $upgrade_after_loop_script .= "\n\t\t\t\t\t/* insert into template objects subtasks */\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "template_objects`(`template_id`, `object_id`)\r\n\t\t\t\t\tSELECT tt.template_id, tt.object_id\r\n\t\t\t\t\tFROM `" . $t_prefix . "template_tasks` AS tt\r\n\t\t\t\t\tWHERE NOT EXISTS (SELECT * FROM `" . $t_prefix . "template_objects` AS to1 WHERE tt.object_id = to1.object_id);\r\n\t\t\t\t\tUPDATE `" . $t_prefix . "template_objects` t1, `" . $t_prefix . "template_objects` t2\r\n\t\t\t\t\tSET t1.created_by_id = t2.created_by_id, t1.created_on = t2.created_on\r\n\t\t\t\t\tWHERE t1.template_id = t2.template_id AND t2.created_by_id IS NOT NULL;\r\n\t\t\t\t\t\r\n\t\t\t\t\t/* delete from project task, tasks that are template tasks */\n\t\t\t\t\tDELETE FROM `" . $t_prefix . "project_tasks` WHERE `is_template` = 1;\n\n\t\t\t\t\t/* change the object type from project task to template task */\n\t\t\t\t\tUPDATE `" . $t_prefix . "objects` SET object_type_id = (SELECT id FROM `" . $t_prefix . "object_types` WHERE name = 'template_task')\n\t\t\t\t\tWHERE id IN (SELECT object_id FROM `" . $t_prefix . "template_tasks`);\r\n\t\t\t\t";
             // Copy tasks
             if (!$this->executeMultipleQueries($upgrade_before_loop_script, $total_queries, $executed_queries, $this->database_connection)) {
                 $this->printMessage('Failed to execute DB schema transformations. MySQL said: ' . mysql_error(), true);
                 return false;
             }
             while ($while_condition) {
                 // Copy subtasks
                 if ($this->executeMultipleQueries($upgrade_loop_script, $total_queries, $executed_queries, $this->database_connection)) {
                     // Check if continue
                     $res = mysql_query($check_continue_condition, $this->database_connection);
                     $rows = array();
                     while ($row = mysql_fetch_array($res)) {
                         $rows[] = $row;
                     }
                     // is empty?
                     if (!is_array($rows) || count($rows) < 1) {
                         $while_condition = false;
                     }
                 } else {
                     $this->printMessage('Failed to execute DB schema transformations. MySQL said: ' . mysql_error(), true);
                     return false;
                 }
             }
         }
         if (version_compare($installed_version, '2.4-rc') < 0) {
             $upgrade_after_loop_script .= "\r\n\t\t\t\t\tDELETE FROM `" . $t_prefix . "object_members` where object_id IN (SELECT object_id FROM  `" . TABLE_PREFIX . "template_tasks`);\r\n\t\t\t\t\tDELETE FROM `" . $t_prefix . "sharing_table` where object_id IN (SELECT object_id FROM  `" . TABLE_PREFIX . "template_tasks`);\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "config_options` (`category_name`,`name`,`value`,`config_handler_class`,`is_system`) VALUES\r\n\t\t\t\t\t\t('general', 'add_default_permissions_for_users', '0', 'BoolConfigHandler', '0')\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t\t";
         }
         // after loop
         if (!$this->executeMultipleQueries($upgrade_after_loop_script, $total_queries, $executed_queries, $this->database_connection)) {
             $this->printMessage('Failed to execute DB schema transformations. MySQL said: ' . mysql_error(), true);
             return false;
         }
         $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 (version_compare($installed_version, '2.5.0.4') < 0) {
         if (!$this->checkColumnExists("queued_emails", "attachments", $this->database_connection)) {
             $sqls = "\r\n\t\t\t\t\tALTER TABLE " . $t_prefix . "queued_emails` ADD COLUMN `attachments` TEXT;\r\n\t\t\t\t";
             $this->executeMultipleQueries($sqls, $t_queries, $e_queries, $this->database_connection);
         }
     }
     $this->printMessage('Feng Office has been upgraded. You are now running Feng Office ' . $this->getVersionTo() . ' Enjoy!');
     tpl_assign('additional_steps', $additional_upgrade_steps);
 }
 /**
  * Execute the script
  *
  * @param void
  * @return boolean
  */
 function execute()
 {
     // ---------------------------------------------------
     //  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
     $installed_version = installed_version();
     $t_prefix = TABLE_PREFIX;
     if (version_compare($installed_version, '1.7.5') <= 0 && TABLE_PREFIX != "fo_") {
         $t_prefix = "fo_";
     }
     tpl_assign('table_prefix', $t_prefix);
     if (defined('DB_ENGINE')) {
         tpl_assign('engine', DB_ENGINE);
     } else {
         tpl_assign('engine', 'InnoDB');
     }
     // ---------------------------------------------------
     //  Execute migration
     // ---------------------------------------------------
     $additional_upgrade_steps = array();
     // RUN QUERIES
     $total_queries = 0;
     $executed_queries = 0;
     $upgrade_script = "";
     // upgrading from version 1.x
     if (version_compare($installed_version, '2.0.0.0-beta') < 0) {
         ini_set('memory_limit', '1024M');
         @set_time_limit(0);
         $upgrade_script .= tpl_fetch(get_template_path('db_migration/2_0_asado'));
         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;
         }
         $_SESSION['from_feng1'] = true;
         $upgrade_script = "";
         @unlink(ROOT . '/cache/autoloader.php');
         include ROOT . '/environment/classes/AutoLoader.class.php';
         include ROOT . '/environment/constants.php';
         if (!($callbacks = spl_autoload_functions())) {
             $callbacks = array();
         }
         foreach ($callbacks as $callback) {
             spl_autoload_unregister($callback);
         }
         spl_autoload_register('feng_upg_autoload');
         foreach ($callbacks as $callback) {
             spl_autoload_register($callback);
         }
         @(include ROOT . '/cache/autoloader.php');
         define('DONT_LOG', true);
         define('FORCED_TABLE_PREFIX', 'fo_');
         if (!defined('FILE_STORAGE_FILE_SYSTEM')) {
             define('FILE_STORAGE_FILE_SYSTEM', 'fs');
         }
         if (!defined('FILE_STORAGE_MYSQL')) {
             define('FILE_STORAGE_MYSQL', 'mysql');
         }
         if (!defined('MAX_SEARCHABLE_FILE_SIZE')) {
             define('MAX_SEARCHABLE_FILE_SIZE', 1048576);
         }
         try {
             DB::connect(DB_ADAPTER, array('host' => DB_HOST, 'user' => DB_USER, 'pass' => DB_PASS, 'name' => DB_NAME, 'persist' => DB_PERSIST));
             if (defined('DB_CHARSET') && trim(DB_CHARSET)) {
                 DB::execute("SET NAMES ?", DB_CHARSET);
             }
         } catch (Exception $e) {
             $this->printMessage("Error connecting to database: " . $e->getMessage() . "\n" . $e->getTraceAsString());
         }
         try {
             $db_result = DB::execute("SELECT value FROM " . $t_prefix . "config_options WHERE name = 'file_storage_adapter'");
             $db_result_row = $db_result->fetchRow();
             if ($db_result_row['value'] == FILE_STORAGE_FILE_SYSTEM) {
                 if (!defined('FILES_DIR')) {
                     define('FILES_DIR', ROOT . '/upload');
                 }
                 FileRepository::setBackend(new FileRepository_Backend_FileSystem(FILES_DIR, TABLE_PREFIX));
             } else {
                 FileRepository::setBackend(new FileRepository_Backend_DB(TABLE_PREFIX));
             }
             PublicFiles::setRepositoryPath(ROOT . '/public/files');
             if (!defined('PUBLIC_FOLDER')) {
                 define('PUBLIC_FOLDER', 'public');
             }
             if (trim(PUBLIC_FOLDER) == '') {
                 PublicFiles::setRepositoryUrl(with_slash(ROOT_URL) . 'files');
             } else {
                 PublicFiles::setRepositoryUrl(with_slash(ROOT_URL) . 'public/files');
             }
             $member_parents = array();
             $members = Members::findAll();
             foreach ($members as $member) {
                 $member_parents[$member->getId()] = $member->getAllParentMembersInHierarchy(false, false);
             }
             $object_members = DB::executeAll('SELECT * FROM ' . $t_prefix . 'object_members WHERE is_optimization=0 and not exists (SELECT x.object_id FROM ' . $t_prefix . 'object_members x where x.object_id=fo_object_members.object_id and x.is_optimization=1)');
             foreach ($object_members as $om) {
                 $parents = isset($member_parents[$om['member_id']]) ? $member_parents[$om['member_id']] : array();
                 if (count($parents) > 0) {
                     $sql_values = "";
                     foreach ($parents as $p) {
                         $sql_values .= ($sql_values == "" ? "" : ",") . "(" . $om['object_id'] . "," . $p->getId() . ",1)";
                     }
                     $sql = "INSERT INTO " . $t_prefix . "object_members (object_id, member_id, is_optimization) VALUES {$sql_values} ON DUPLICATE KEY UPDATE is_optimization=1;";
                     DB::execute($sql);
                 }
             }
             $this->printMessage("Finished generating Object Members");
             foreach ($members as $m) {
                 if ($m->getParentMember() instanceof Member && $m->getDimensionId() != $m->getParentMember()->getDimensionId()) {
                     $m->setDimensionId($m->getParentMember()->getDimensionId());
                     $m->save();
                 }
             }
             $app_move_logs = ApplicationLogs::findAll(array("conditions" => "action = 'move'"));
             foreach ($app_move_logs as &$app_log) {
                 /* @var $app_log ApplicationLog */
                 $exp_log_data = explode(";", $app_log->getLogData());
                 if (count($exp_log_data) > 1) {
                     $old_to = array_var($exp_log_data, 1);
                     $old_from = array_var($exp_log_data, 0);
                 } else {
                     $old_to = array_var($exp_log_data, 0);
                     $old_from = "";
                 }
                 $to_id = str_replace("to:", "", $old_to);
                 $new_to_id = Members::instance()->findOne(array("id" => true, "conditions" => "ws_id = '{$to_id}'"));
                 if (count($new_to_id) > 0) {
                     $new_to_id = $new_to_id[0];
                 }
                 $new_from_ids = "";
                 $from_ids = str_replace("from:", "", $old_from);
                 if ($from_ids != "") {
                     $new_from_ids_array = Members::instance()->findAll(array("id" => true, "conditions" => "ws_id IN ({$from_ids})"));
                     $new_from_ids = implode(",", $new_from_ids_array);
                 }
                 if ($new_to_id) {
                     if ($new_from_ids) {
                         $log_data = "from:{$new_from_ids};to:{$new_to_id}";
                     } else {
                         $log_data = "to:{$new_to_id}";
                     }
                     $app_log->setLogData($log_data);
                     $app_log->save();
                 }
             }
         } catch (Exception $e) {
             die("\nError occurred:\n-----------------\n" . $e->getMessage() . "\n" . $e->getTraceAsString());
         }
         //tpl_assign('install_inv_dw', true);
         $additional_upgrade_steps[] = array('url' => 'complete_migration.php?out=file', 'name' => 'Fill searchable objects and sharing table', 'filename' => dirname(__FILE__) . "/../complete_migration.php");
     } else {
         // upgrading from a pre-release of this version (beta, rc, etc)
         if (version_compare($installed_version, '2.0.0.4') <= 0) {
             if (!$this->checkTableExists($t_prefix . 'role_object_type_permissions', $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\t\tCREATE TABLE `" . $t_prefix . "role_object_type_permissions` (\r\n\t\t\t\t\t\t  `role_id` INTEGER UNSIGNED NOT NULL,\r\n\t\t\t\t\t\t  `object_type_id` INTEGER UNSIGNED NOT NULL,\r\n\t\t\t\t\t\t  `can_delete` BOOLEAN NOT NULL,\r\n\t\t\t\t\t\t  `can_write` BOOLEAN NOT NULL,\r\n\t\t\t\t\t\t  PRIMARY KEY (`role_id`, `object_type_id`)\r\n\t\t\t\t\t\t) ENGINE = InnoDB;\r\n\t\t\t\t\t\tINSERT INTO " . $t_prefix . "role_object_type_permissions (role_id, object_type_id, can_delete, can_write)\r\n\t\t\t\t\t\t SELECT p.id, o.id, 1, 1\r\n\t\t\t\t\t\t FROM `" . $t_prefix . "object_types` o JOIN `" . $t_prefix . "permission_groups` p\r\n\t\t\t\t\t\t WHERE o.`name` IN ('message','weblink','file','task','milestone','event','contact','mail','timeslot','report','comment')\r\n\t\t\t\t\t\t AND p.`name` IN ('Super Administrator','Administrator','Manager','Executive');\r\n\t\t\t\t\t\tINSERT INTO " . $t_prefix . "role_object_type_permissions (role_id, object_type_id, can_delete, can_write)\r\n\t\t\t\t\t\t SELECT p.id, o.id, 0, 1\r\n\t\t\t\t\t\t FROM `" . $t_prefix . "object_types` o JOIN `" . $t_prefix . "permission_groups` p\r\n\t\t\t\t\t\t WHERE o.`name` IN ('message','weblink','file','task','milestone','event','contact','timeslot','report','comment')\r\n\t\t\t\t\t\t AND p.`name` IN ('Collaborator Customer');\r\n\t\t\t\t\t\tINSERT INTO " . $t_prefix . "role_object_type_permissions (role_id, object_type_id, can_delete, can_write)\r\n\t\t\t\t\t\t SELECT p.id, o.id, 0, 1\r\n\t\t\t\t\t\t FROM `" . $t_prefix . "object_types` o JOIN `" . $t_prefix . "permission_groups` p\r\n\t\t\t\t\t\t WHERE o.`name` IN ('message','weblink','file','task','milestone','event','timeslot','comment')\r\n\t\t\t\t\t\t AND p.`name` IN ('Internal Collaborator','External Collaborator');\r\n\t\t\t\t\t\tINSERT INTO " . $t_prefix . "role_object_type_permissions (role_id, object_type_id, can_delete, can_write)\r\n\t\t\t\t\t\t SELECT p.id, o.id, 0, 0\r\n\t\t\t\t\t\t FROM `" . $t_prefix . "object_types` o JOIN `" . $t_prefix . "permission_groups` p\r\n\t\t\t\t\t\t WHERE o.`name` IN ('message','weblink','file','event','comment')\r\n\t\t\t\t\t\t AND p.`name` IN ('Guest Customer');\r\n\t\t\t\t\t\tINSERT INTO " . $t_prefix . "role_object_type_permissions (role_id, object_type_id, can_delete, can_write)\r\n\t\t\t\t\t\t SELECT p.id, o.id, 0, 0\r\n\t\t\t\t\t\t FROM `" . $t_prefix . "object_types` o JOIN `" . $t_prefix . "permission_groups` p\r\n\t\t\t\t\t\t WHERE o.`name` IN ('message','weblink','event','comment')\r\n\t\t\t\t\t\t AND p.`name` IN ('Guest');\r\n\t\t\t\t\t\tINSERT INTO " . $t_prefix . "role_object_type_permissions (role_id, object_type_id, can_delete, can_write)\r\n\t\t\t\t\t\t SELECT p.id, o.id, 0, 0\r\n\t\t\t\t\t\t FROM `" . $t_prefix . "object_types` o JOIN `" . $t_prefix . "permission_groups` p\r\n\t\t\t\t\t\t WHERE o.`name` IN ('message','weblink','file','task','milestone','event','contact','timeslot','report','comment')\r\n\t\t\t\t\t\t AND p.`name` IN ('Non-Exec Director');\r\n\t\t\t\t\t\tUPDATE " . $t_prefix . "role_object_type_permissions SET can_write = 1 WHERE object_type_id = (SELECT id FROM " . $t_prefix . "object_types WHERE name='comment');\r\n\t\t\t\t\t";
             }
             if (!$this->checkTableExists($t_prefix . 'widgets', $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\t\tCREATE TABLE  `" . $t_prefix . "widgets` (\r\n\t\t\t\t\t\t  `name` varchar(64) NOT NULL,\r\n\t\t\t\t\t\t  `title` varchar(255) NOT NULL,\r\n\t\t\t\t\t\t  `plugin_id` int(10) unsigned NOT NULL,\r\n\t\t\t\t\t\t  `path` varchar(512) NOT NULL,\r\n\t\t\t\t\t\t  `default_options` text NOT NULL,\r\n\t\t\t\t\t\t  `default_section` varchar(64) NOT NULL,\r\n\t\t\t\t\t\t  `default_order` int(10) NOT NULL,\r\n\t\t\t\t\t\t  PRIMARY KEY (`name`)\r\n\t\t\t\t\t\t) ENGINE = InnoDB;\r\n\t\t\t\t\t";
             }
             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 (version_compare($installed_version, '2.0.0.5') <= 0) {
             if (!$this->checkColumnExists($t_prefix . 'contacts', 'default_billing_id', $this->database_connection)) {
                 $upgrade_script = "\r\n\t\t\t\t\t\tALTER TABLE `" . $t_prefix . "contacts` ADD COLUMN `default_billing_id` INTEGER NOT NULL DEFAULT 0;\r\n\t\t\t\t\t\tALTER TABLE `" . $t_prefix . "project_tasks`\r\n\t\t\t\t\t\t ADD COLUMN `use_due_time` BOOLEAN DEFAULT 0,\r\n\t\t\t\t\t\t ADD COLUMN `use_start_time` BOOLEAN DEFAULT 0;\r\n\t\t\t\t\t\tUPDATE " . $t_prefix . "project_tasks t SET\r\n\t\t\t\t\t\t t.due_date = ADDTIME(t.due_date, CONCAT(SUBSTRING_INDEX((SELECT c.timezone FROM " . $t_prefix . "contacts c WHERE c.object_id=(SELECT o.updated_by_id FROM " . $t_prefix . "objects o WHERE o.id=t.object_id)), '.', 1), ':', SUBSTRING_INDEX(abs((SELECT c.timezone FROM " . $t_prefix . "contacts c WHERE c.object_id=(SELECT o.updated_by_id FROM " . $t_prefix . "objects o WHERE o.id=t.object_id)) % 1)*60, '.', 1)))\r\n\t\t\t\t\t\t WHERE t.due_date > 0;\r\n\t\t\t\t\t\tUPDATE " . $t_prefix . "project_tasks t SET\r\n\t\t\t\t\t\t t.start_date = ADDTIME(t.start_date, CONCAT(SUBSTRING_INDEX((SELECT c.timezone FROM " . $t_prefix . "contacts c WHERE c.object_id=(SELECT o.updated_by_id FROM " . $t_prefix . "objects o WHERE o.id=t.object_id)), '.', 1), ':', SUBSTRING_INDEX(abs((SELECT c.timezone FROM " . $t_prefix . "contacts c WHERE c.object_id=(SELECT o.updated_by_id FROM " . $t_prefix . "objects o WHERE o.id=t.object_id)) % 1)*60, '.', 1)))\r\n\t\t\t\t\t\t WHERE t.start_date > 0;\r\n\t\t\t\t\t\tINSERT INTO `" . $t_prefix . "contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\r\n\t\t\t\t\t\t ('general', 'work_day_end_time', '18:00', 'TimeConfigHandler', 0, 410, 'Work day end time');\t\t\t\t\t\t\r\n\t\t\t\t\t";
             }
             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 (version_compare($installed_version, '2.0.0.6') <= 0) {
             //WS Widgets
             $upgrade_script = "\r\n\t\t\t\t\tUPDATE `" . $t_prefix . "contact_config_options` SET `default_value` = '15' WHERE `" . $t_prefix . "contact_config_options`.`name` = 'noOfTasks' LIMIT 1 ;\r\n\t\t\t\t\tUPDATE " . $t_prefix . "widgets SET default_section = 'none' WHERE name = 'people' AND NOT EXISTS (SELECT id from " . $t_prefix . "plugins WHERE name = 'crpm');\r\n\t\t\t\t\tUPDATE " . $t_prefix . "dimensions SET options = '{\"defaultAjax\":{\"controller\":\"dashboard\", \"action\": \"main_dashboard\"}, \"quickAdd\":true,\"showInPaths\":true}' \r\n\t\t\t\t\t\tWHERE  code='workspaces';\r\n\t\t\t\t\tUPDATE `" . $t_prefix . "tab_panels` SET default_action = 'main_dashboard', initial_action = 'main_dashboard'\r\n\t\t\t\t\t\tWHERE id = 'overview-panel' ;\r\n\t\t\t\t\tUPDATE " . $t_prefix . "object_types SET type = 'dimension_object', handler_class='Workspaces', table_name = 'workpaces' WHERE name = 'workspace' ;\r\n\t\t\t\t\tUPDATE " . $t_prefix . "dimension_object_types SET OPTIONS = '{\"defaultAjax\":{\"controller\":\"dashboard\", \"action\": \"main_dashboard\"}}' \r\n\t\t\t\t\t\tWHERE dimension_id = (SELECT id FROM " . $t_prefix . "dimensions WHERE code = 'workspaces');\r\n\t\t\t\t\tCREATE TABLE IF NOT EXISTS `" . $t_prefix . "contact_widgets` (\r\n\t\t\t\t\t  `widget_name` varchar(40) NOT NULL,\r\n\t\t\t\t\t  `contact_id` int(11) NOT NULL,\r\n\t\t\t\t\t  `section` varchar(40) NOT NULL,\r\n\t\t\t\t\t  `order` int(11) NOT NULL,\r\n\t\t\t\t\t  `options` varchar(255) NOT NULL,\r\n\t\t\t\t\t  PRIMARY KEY (`widget_name`,`contact_id`) USING BTREE\r\n\t\t\t\t\t) ENGINE=InnoDB;\r\n\t\t\t\t\tINSERT INTO " . $t_prefix . "widgets(name, title, plugin_id, default_section,default_order) \r\n\t\t\t\t\t VALUES ('messages','notes',0,'none',1000)\r\n\t\t\t\t\t ON DUPLICATE KEY update name = name;\r\n\t\t\t\t\tINSERT INTO " . $t_prefix . "dimension_object_type_contents (dimension_id, dimension_object_type_id, content_object_type_id, is_required, is_multiple)\r\n\t\t\t\t\t SELECT d.id, ot.id, (SELECT tmp.id FROM " . $t_prefix . "object_types tmp WHERE tmp.name='contact'), 0, 1\r\n\t\t\t\t\t FROM " . $t_prefix . "dimensions d JOIN " . $t_prefix . "object_types ot\r\n\t\t\t\t\t WHERE d.code = 'customer_project' AND ot.name IN ('customer', 'project', 'folder', 'customer_folder', 'project_folder')\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE dimension_id=dimension_id;\r\n\t\t\t\t\tUPDATE " . $t_prefix . "dimension_object_type_contents SET is_multiple = 1 WHERE content_object_type_id = (SELECT id FROM " . $t_prefix . "object_types WHERE name='mail');\r\n\t\t\t\t";
             if (@mysql_fetch_row(@mysql_query("SELECT id from " . $t_prefix . "plugins WHERE name = 'workspaces'"))) {
                 $upgrade_script .= "INSERT INTO " . $t_prefix . "widgets(name, title, plugin_id, default_section,default_order) \r\n\t\t\t\t\t\tVALUES ('ws_description', 'workspace description',(SELECT id from " . $t_prefix . "plugins WHERE name = 'workspaces'), 'left',-100)\r\n\t\t\t\t\t\tON DUPLICATE KEY update name = name ;";
             }
             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 ($obj = @mysql_fetch_object(@mysql_query("SELECT id FROM " . $t_prefix . "object_types WHERE name = 'workspace' "))) {
                 $wsTypeId = $obj->id;
                 $res = @mysql_query("SELECT * FROM " . $t_prefix . "members WHERE dimension_id = (SELECT id FROM " . $t_prefix . "dimensions WHERE code='workspaces')");
                 while ($m = @mysql_fetch_object($res)) {
                     @mysql_query("INSERT INTO " . $t_prefix . "objects (object_type_id, name) VALUES ({$wsTypeId}, '" . $m->name . "' )");
                     if ($id = @mysql_insert_id()) {
                         @mysql_query("INSERT INTO " . $t_prefix . "workspaces (object_id) VALUES ({$id})");
                         @mysql_query("UPDATE " . $t_prefix . "members SET object_id={$id} WHERE id = {$m->id} ");
                     }
                 }
             }
         }
         if (version_compare($installed_version, '2.0.0.7') <= 0) {
             $upgrade_script = "";
             if (!$this->checkTableExists($t_prefix . 'mail_spam_filters', $this->database_connection)) {
                 $upgrade_script .= "\r\n                                                    CREATE TABLE IF NOT EXISTS `" . $t_prefix . "mail_spam_filters` (\r\n                                                     `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\r\n                                                     `account_id` int(10) unsigned NOT NULL,\r\n                                                     `text_type` enum('email_address','subject') COLLATE utf8_unicode_ci NOT NULL,\r\n                                                     `text` text COLLATE utf8_unicode_ci NOT NULL,\r\n                                                     `spam_state` enum('no spam','spam') COLLATE utf8_unicode_ci NOT NULL,\r\n                                                     PRIMARY KEY (`id`)\r\n                                                    ) ENGINE=InnoDB;\r\n                                        ";
             }
             $upgrade_script .= "INSERT INTO `" . $t_prefix . "config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) \r\n\t\t\t\t\tVALUES ('general', 'untitled_notes', '0', 'BoolConfigHandler', '0', '0', NULL) ON DUPLICATE KEY UPDATE name=name;";
             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 (version_compare($installed_version, '2.0.0.8') < 0) {
             $upgrade_script = "";
             if (!$this->checkTableExists($t_prefix . 'external_calendar_users', $this->database_connection)) {
                 $upgrade_script .= "\r\n                                                    CREATE TABLE IF NOT EXISTS `" . $t_prefix . "external_calendar_users` (\r\n                                                      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\r\n                                                      `contact_id` int(10) unsigned NOT NULL,\r\n                                                      `auth_user` varchar(100) COLLATE utf8_unicode_ci NOT NULL,\r\n                                                      `auth_pass` varchar(100) COLLATE utf8_unicode_ci NOT NULL,\r\n                                                      `type` text COLLATE utf8_unicode_ci NOT NULL,\r\n                                                      `sync` TINYINT( 1 ) NULL DEFAULT '0',\r\n                                                      PRIMARY KEY (`id`)\r\n                                                    ) ENGINE = InnoDB;\r\n\t\t\t\t\t";
             }
             if (!$this->checkTableExists($t_prefix . 'external_calendars', $this->database_connection)) {
                 $upgrade_script .= "\r\n                                                    CREATE TABLE IF NOT EXISTS `" . $t_prefix . "external_calendars` (\r\n                                                      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\r\n                                                      `ext_cal_user_id` int(10) unsigned NOT NULL,\r\n                                                      `calendar_user` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\r\n                                                      `calendar_visibility` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\r\n                                                      `calendar_name` text COLLATE utf8_unicode_ci NOT NULL,\r\n                                                      `calendar_feng` TINYINT( 1 ) NOT NULL DEFAULT '0',\r\n                                                      PRIMARY KEY (`id`)\r\n                                                    ) ENGINE = InnoDB;\r\n\t\t\t\t\t";
             }
             if (!$this->checkColumnExists($t_prefix . 'project_events', 'ext_cal_id', $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\t\tALTER TABLE `" . $t_prefix . "project_events`  ADD `ext_cal_id` INT(10) UNSIGNED NOT NULL;\r\n\t\t\t\t\t";
             }
             $upgrade_script .= "\r\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "project_events` CHANGE `special_id` `special_id` VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL;\r\n\t\t\t\t\tUPDATE `" . $t_prefix . "file_types` SET `is_searchable` = '1' WHERE `extension` = 'docx';\r\n\t\t\t\t\tUPDATE `" . $t_prefix . "file_types` SET `is_searchable` = '1' WHERE `extension` = 'pdf';\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`)\r\n\t\t\t\t\t\tVALUES ('general', 'repeating_task', '0', 'BoolConfigHandler', '0', '0', '')\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`)\r\n\t\t\t\t\t\tVALUES ('calendar panel', 'calendar task filter', 'pending', 'StringConfigHandler', '1', '0', NULL),\r\n\t\t\t\t\t\t\t('task panel', 'close timeslot open', '1', 'BoolConfigHandler', '0', '0', NULL),\r\n\t\t\t\t\t\t\t('calendar panel', 'reminders_events', 'reminder_email,1,60', 'StringConfigHandler', '0', '0', NULL)\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "cron_events` (`name`, `recursive`, `delay`, `is_system`, `enabled`, `date`)\r\n\t\t\t\t\t\tVALUES ('import_google_calendar', '1', '10', '0', '0', '0000-00-00 00:00:00'),\r\n\t\t\t\t\t\t\t('export_google_calendar', '1', '10', '0', '0', '0000-00-00 00:00:00')\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t\t\t";
             $upgrade_script .= "\r\n\t\t\t\t\tDELETE FROM `" . $t_prefix . "config_options` WHERE `name`='use_time_in_task_dates' AND NOT EXISTS (SELECT id FROM `" . $t_prefix . "plugins` WHERE `name`='crpm' AND is_activated=1);\r\n\t\t\t\t\tINSERT INTO " . $t_prefix . "contact_config_options (category_name, name, default_value, config_handler_class, is_system, option_order) VALUES\r\n\t\t\t\t\t\t('general','show_object_direct_url',0,'BoolConfigHandler',0,0),\r\n\t\t\t\t\t\t('general','drag_drop_prompt','prompt','DragDropPromptConfigHandler',0,0)\r\n\t\t\t\t\t ON DUPLICATE KEY UPDATE name = name;\r\n\t\t\t\t";
             $upgrade_script .= "\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "tab_panels` (`id`,`title`,`icon_cls`,`refresh_on_context_change`,`default_controller`,`default_action`,`initial_controller`,`initial_action`,`enabled`,`type`,`ordering`,`plugin_id`,`object_type_id`) VALUES \r\n\t\t\t\t\t('contacts-panel','contacts','ico-contacts',1,'contact','init','','',0,'system',7,0,16) ON DUPLICATE KEY UPDATE title=title;\r\n\t\t\t\t";
             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 (version_compare($installed_version, '2.0.1') < 0) {
             $upgrade_script = "";
             $upgrade_script .= "INSERT INTO `" . $t_prefix . "config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`)\r\n\t\t\t\t\tVALUES ('general', 'working_days', '1,2,3,4,5,6,7', 'StringConfigHandler', '0', '0', NULL);\r\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "project_tasks` ADD `original_task_id` INT( 10 ) UNSIGNED NULL DEFAULT '0';\r\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "project_tasks` ADD `type_content` ENUM( 'text', 'html' ) NOT NULL DEFAULT 'text';\r\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "project_events` ADD `original_event_id` INT( 10 ) UNSIGNED NULL DEFAULT '0';\r\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "project_messages` ADD `type_content` ENUM( 'text', 'html' ) NOT NULL DEFAULT 'text';\r\n\t\t\t\t";
             $upgrade_script .= "INSERT INTO `" . $t_prefix . "config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`)\r\n\t\t\t\t\tVALUES ('general', 'wysiwyg_tasks', '0', 'BoolConfigHandler', '0', '0', NULL),\r\n\t\t\t\t\t('general', 'wysiwyg_messages', '0', 'BoolConfigHandler', '0', '0', NULL),\r\n\t\t\t\t\t('task panel', 'tasksShowTimeEstimates', '1', 'BoolConfigHandler', '1', '0', NULL)\r\n\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t\t";
             $upgrade_script .= "UPDATE `" . $t_prefix . "widgets` SET plugin_id = (SELECT id FROM `" . $t_prefix . "plugins` WHERE name='workspaces') WHERE name='workspaces';\r\n\t\t\t\t";
             // clean old users dimension
             $upgrade_script .= "DELETE FROM `" . $t_prefix . "object_members` WHERE member_id IN (SELECT `id` FROM `" . $t_prefix . "members` WHERE `dimension_id` IN (SELECT `id` FROM `" . $t_prefix . "dimensions` WHERE `code`='feng_users'));\r\n\t\t\t\t\tDELETE FROM `" . $t_prefix . "contact_dimension_permissions` WHERE dimension_id IN (SELECT `id` FROM `" . $t_prefix . "dimensions` WHERE `code`='feng_users');\r\n\t\t\t\t\tDELETE FROM `" . $t_prefix . "members` WHERE dimension_id IN (SELECT `id` FROM `" . $t_prefix . "dimensions` WHERE `code`='feng_users');\r\n\t\t\t\t\tDELETE FROM `" . $t_prefix . "dimension_object_type_contents` WHERE dimension_id IN (SELECT `id` FROM `" . $t_prefix . "dimensions` WHERE `code`='feng_users');\r\n\t\t\t\t\tDELETE FROM `" . $t_prefix . "dimension_object_type_hierarchies` WHERE dimension_id IN (SELECT `id` FROM `" . $t_prefix . "dimensions` WHERE `code`='feng_users');\r\n\t\t\t\t\tDELETE FROM `" . $t_prefix . "dimension_object_types` WHERE dimension_id IN (SELECT `id` FROM `" . $t_prefix . "dimensions` WHERE `code`='feng_users');\r\n\t\t\t\t\tDELETE FROM `" . $t_prefix . "dimensions` WHERE code='feng_users';\r\n\t\t\t\t\tDELETE FROM `" . $t_prefix . "object_types` WHERE name='user';\r\n\t\t\t\t\tUPDATE " . $t_prefix . "contacts c SET c.personal_member_id = 0 WHERE c.user_type>0 AND NOT (SELECT count(m2.id) FROM " . $t_prefix . "members m2 WHERE m2.object_id=c.personal_member_id)=0;\r\n\t\t\t\t";
             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;
             }
         }
         // Plugin Version Support
         $upgrade_script = '';
         if (!$this->checkColumnExists($t_prefix . "plugins", 'version', $this->database_connection)) {
             $upgrade_script = 'ALTER TABLE ' . $t_prefix . 'plugins ADD COLUMN `version` INTEGER  NOT NULL  DEFAULT 1 AFTER `name` ';
             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;
             }
         }
     }
     $this->printMessage('Feng Office has been upgraded. You are now running Feng Office ' . $this->getVersionTo() . ' Enjoy!');
     tpl_assign('additional_steps', $additional_upgrade_steps);
 }
 /**
  * Execute the script
  *
  * @param void
  * @return boolean
  */
 function execute()
 {
     if (!@mysql_ping($this->database_connection)) {
         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;
             }
             $this->setDatabaseConnection($dbc);
         } else {
             $this->printMessage('Failed to connect to database');
             return false;
         }
     }
     // ---------------------------------------------------
     //  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
     $installed_version = installed_version();
     $t_prefix = TABLE_PREFIX;
     $additional_upgrade_steps = array();
     // RUN QUERIES
     $total_queries = 0;
     $executed_queries = 0;
     $upgrade_script = "";
     $v_from = array_var($_POST, 'form_data');
     $original_version_from = array_var($v_from, 'upgrade_from', $installed_version);
     if (false && version_compare($installed_version, $this->getVersionFrom()) <= 0 && version_compare($original_version_from, '2.0.0.0-beta') > 0 && (!isset($_SESSION['from_feng1']) || !$_SESSION['from_feng1'])) {
         // upgrading from a version lower than this script's 'from' version
         $upgrade_script = tpl_fetch(get_template_path('db_migration/2_7_provolone'));
     } else {
         if (version_compare($installed_version, '2.7-beta') < 0) {
             $upgrade_script .= "\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\n\t\t\t\t\t\t('mails panel', 'view_mail_attachs_expanded', '1', 'BoolConfigHandler', 0, 0, ''),\n\t\t\t\t\t\t('mails panel', 'auto_classify_attachments', '1', 'BoolConfigHandler', 0, 0, ''),\n\t\t\t\t\t\t('calendar panel', 'show_birthdays_in_calendar', '1', 'BoolConfigHandler', 1, 0, '')\n\t\t\t\t\tON DUPLICATE KEY UPDATE name=name;\n\t\t\t\t";
             $upgrade_script .= "\n\t\t\t\t\tdelete from " . $t_prefix . "contact_widgets where widget_name='active_context_info';\n\t\t\t\t\tdelete from " . $t_prefix . "widgets where name='active_context_info';\n\t\t\t\t";
             $upgrade_script .= "\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\n\t\t\t\t\t\t('general', 'give_member_permissions_to_new_users', '', 'UserTypeMultipleConfigHandler', '0', '0', NULL),\n\t\t\t\t\t\t('general', 'show_owner_company_name_header', 1, 'BoolConfigHandler', '0', '0', NULL)\n\t\t\t\t\tON DUPLICATE KEY UPDATE name=name;\n\t\t\t\t\tUPDATE `" . $t_prefix . "config_options` SET `value`=(\n\t\t\t\t\t\tSELECT GROUP_CONCAT(id) FROM " . $t_prefix . "permission_groups WHERE `name` IN ('Super Administrator', 'Administrator')\n\t\t\t\t\t)\n\t\t\t\t\tWHERE `name`='give_member_permissions_to_new_users';\n\t\t\t\t";
             if (!$this->checkColumnExists($t_prefix . "sharing_table_flags", "object_id", $this->database_connection)) {
                 $upgrade_script .= "ALTER TABLE `" . $t_prefix . "sharing_table_flags` ADD COLUMN `object_id` INTEGER UNSIGNED NOT NULL DEFAULT 0;";
             }
             if (!$this->checkTableExists($t_prefix . "contact_member_cache", $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\tCREATE TABLE `" . $t_prefix . "contact_member_cache` (\r\n\t\t\t\t\t`contact_id` int(10) UNSIGNED NOT NULL,\r\n\t\t\t\t\t`member_id` int(10) UNSIGNED NOT NULL,\r\n\t\t\t\t\t`parent_member_id` int(10) UNSIGNED NOT NULL default '0',\r\n\t\t\t\t\t`last_activity` DATETIME NOT NULL default '0000-00-00 00:00:00',\r\n\t\t\t\t\tPRIMARY KEY  (`contact_id` , `member_id`),\r\n\t\t\t\t\tKEY `by_contact` USING HASH (`contact_id`),\r\n\t\t\t\t\tKEY `by_parent` USING HASH (`parent_member_id`),\r\n\t\t\t\t\tKEY `last_activity` (`last_activity`)\r\n\t\t\t\t\t)\n\t\t\t\t\tENGINE=InnoDB " . $default_charset . ";\r\n\t\t\t\t\t";
             }
         }
         if (version_compare($installed_version, '2.7.1.8') < 0) {
             $upgrade_script .= "\n\t\t\t\t\tDELETE FROM " . $t_prefix . "widgets WHERE name IN ('ws_description', 'summary');\n\t\t\t\t\tDELETE FROM " . $t_prefix . "contact_widgets WHERE widget_name IN ('ws_description', 'summary');\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "widgets` (`name`,`title`,`plugin_id`,`path`,`default_options`,`default_section`,`default_order`,`icon_cls`) VALUES\n\t\t\t\t\t('active_context_info','active_context_info',0,'','','left',1,'ico-summary')\n\t\t\t\t\tON DUPLICATE KEY UPDATE name=name;\n\t\t\t\t";
         }
         if (version_compare($installed_version, '2.7.1.9') < 0) {
             $upgrade_script .= "\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\n\t\t\t\t\t\t('general', 'inherit_permissions_from_parent_member', 1, 'BoolConfigHandler', '0', '0', NULL)\n\t\t\t\t\tON DUPLICATE KEY UPDATE name=name;\n\t\t\t\t";
         }
         if (!$this->executeMultipleQueries($upgrade_script, $total_queries, $executed_queries, $this->database_connection)) {
             $this->printMessage('Failed to execute DB schema transformations. MySQL said: ' . mysql_error(), true);
             return false;
         }
         $this->printMessage("Database schema transformations executed (total queries: {$total_queries})");
     }
     $this->printMessage('Feng Office has been upgraded. You are now running Feng Office ' . $this->getVersionTo() . ' Enjoy!');
     tpl_assign('additional_steps', $additional_upgrade_steps);
 }
 /**
  * Execute the script
  *
  * @param void
  * @return boolean
  */
 function execute()
 {
     // ---------------------------------------------------
     //  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);
     if (defined('DB_ENGINE')) {
         tpl_assign('engine', DB_ENGINE);
     } else {
         tpl_assign('engine', 'InnoDB');
     }
     // ---------------------------------------------------
     //  Execute migration
     // ---------------------------------------------------
     // RUN QUERIES
     $total_queries = 0;
     $executed_queries = 0;
     $installed_version = installed_version();
     if (version_compare($installed_version, $this->getVersionFrom()) <= 0) {
         // upgrading from a version lower than this script's 'from' version
         $upgrade_script = tpl_fetch(get_template_path('db_migration/1_7_pastafrola'));
     } else {
         // upgrading from a pre-release of this version (beta, rc, etc)
         $upgrade_script = "";
         if (version_compare($installed_version, '1.7-beta') <= 0) {
             $upgrade_script .= "\r\n\t\t\t\t\tINSERT INTO `" . TABLE_PREFIX . "config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\r\n\t\t\t\t\t\t('system', 'notification_from_address', '', 'StringConfigHandler', 1, 0, 'Address to use as from field in email notifications. If empty, users address is used');\r\n\t\t\t\t";
         }
         if (version_compare($installed_version, '1.7-rc') <= 0) {
             $upgrade_script .= "\r\n\t\t\t\t\tINSERT INTO `" . TABLE_PREFIX . "config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\r\n\t\t\t\t\t\t('general', 'use_owner_company_logo_at_header', '0', 'BoolConfigHandler', 0, 0, '')\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE id=id;\r\n\t\t\t\t\tDELETE FROM `" . TABLE_PREFIX . "config_options` WHERE `category_name`='general' AND `name`='detect_mime_type_from_extension';\r\n\t\t\t\t\tINSERT INTO `" . TABLE_PREFIX . "user_ws_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES \r\n \t\t\t\t\t\t('general', 'detect_mime_type_from_extension', '0', 'BoolConfigHandler', 0, 800, '')\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE id=id;\r\n\t\t\t\t";
         }
         if (version_compare($installed_version, '1.7-rc2') <= 0) {
             $upgrade_script .= "\r\n\t\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "administration_tools` ADD COLUMN `visible` BOOLEAN NOT NULL DEFAULT 1;\r\n\t\t\t\t\tUPDATE `" . TABLE_PREFIX . "administration_tools` SET `visible`=0 WHERE `name`='mass_mailer';\r\n\t\t\t\t";
         }
         if (version_compare($installed_version, '1.7') <= 0) {
             $upgrade_script .= "\r\n\t\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "mail_accounts` \r\n\t\t\t\t\t ADD COLUMN `last_error_date` DATETIME NOT NULL default '0000-00-00 00:00:00',\r\n\t\t\t\t\t ADD COLUMN `last_error_msg` VARCHAR(255) NOT NULL default '',\r\n\t\t\t\t\t ADD COLUMN `sync_addr` VARCHAR( 100 ) NOT NULL default '',\r\n\t\t\t\t\t ADD COLUMN `sync_pass` VARCHAR( 40 ) NOT NULL default '',\r\n\t\t\t\t\t ADD COLUMN `sync_server` VARCHAR( 100 ) NOT NULL default '',\r\n\t\t\t\t\t ADD COLUMN `sync_ssl` BOOL NOT NULL DEFAULT '0',\r\n\t\t\t\t\t ADD COLUMN `sync_ssl_port` INT( 11 ) NOT NULL DEFAULT '993',\r\n\t\t\t\t\t ADD COLUMN `sync_folder` VARCHAR( 100 ) NOT NULL default '';\r\n\t\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "mail_account_users` ADD COLUMN `last_error_state` INT(1) UNSIGNED NOT NULL DEFAULT 0 COMMENT '0:no error,1:err unread, 2:err read';\r\n\t\t\t\t\tINSERT INTO `" . TABLE_PREFIX . "user_ws_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES \r\n\t\t\t\t\t ('mails panel', 'mail_account_err_check_interval', '300', 'IntegerConfigHandler', 0, 120, NULL),\r\n\t\t\t\t\t ('mails panel', 'classify_mail_with_conversation', '1', 'BoolConfigHandler', 0, 130, NULL),\r\n\t\t\t\t\t ('task panel', 'tasksShowEmptyMilestones', '1', 'BoolConfigHandler', 1, 0, '')\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE id=id;\r\n\t\t\t\t\tINSERT INTO `" . TABLE_PREFIX . "file_types` (`extension`, `icon`, `is_searchable`, `is_image`) VALUES\r\n\t\t\t\t\t\t('docx', 'doc.png', 0, 0),\r\n\t\t\t\t\t\t('xlsx', 'xls.png', 0, 0)\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE id=id;\r\n\t\t\t\t\tINSERT INTO `" . TABLE_PREFIX . "config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\r\n\t\t\t\t\t\t('system', 'min_chars_for_match', '3', 'IntegerConfigHandler', 1, 0, 'If search criteria len is less than this, then use always LIKE'),\r\n\t\t\t\t\t\t('mailing', 'sent_mails_sync', '1', 'BoolConfigHandler', '0', '0', 'imap email accounts synchronization possibility')\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE id=id;\r\n\t\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "application_logs` MODIFY COLUMN `action` enum('upload','open','close','delete','edit','add','trash','untrash','subscribe','unsubscribe','tag','untag','comment','link','unlink','login','logout','archive','unarchive','move','copy','read','download','checkin','checkout') collate utf8_unicode_ci default NULL;\r\n\t\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "mail_contents` ADD COLUMN `sync` BOOL NOT NULL DEFAULT '0';\r\n\t\t\t\t";
         }
         if (version_compare($installed_version, '1.7.2') <= 0) {
             $upgrade_script .= "\r\n\t\t\t\t\tINSERT INTO `" . TABLE_PREFIX . "config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\r\n\t\t\t\t\t\t('passwords', 'block_login_after_x_tries', '0', 'BoolConfigHandler', '0', '20', NULL),\r\n\t\t\t\t\t\t('mailing', 'check_spam_in_subject', '0', 'BoolConfigHandler', 0, 0, '')\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE id=id;\r\n\t\t\t\t";
         }
         if (!$this->checkTableExists(TABLE_PREFIX . 'administration_logs', $this->database_connection)) {
             $upgrade_script .= "\r\n\t\t\t\t\tCREATE TABLE  `" . TABLE_PREFIX . "administration_logs` (\r\n\t\t\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t\t\t  `created_on` datetime NOT NULL default '0000-00-00 00:00:00',\r\n\t\t\t\t\t  `title` varchar(50) NOT NULL default '',\r\n\t\t\t\t\t  `log_data` text NOT NULL,\r\n\t\t\t\t\t  `category` enum('system','security') NOT NULL,\r\n\t\t\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t\t\t  KEY `created_on` (`created_on`),\r\n\t\t\t\t\t  KEY `category` (`category`)\r\n\t\t\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t\t\t";
         }
     }
     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
     $this->printMessage('Feng Office has been upgraded. You are now running Feng Office ' . $this->getVersionTo() . ' Enjoy!');
 }
	/**
	 * Execute the script
	 *
	 * @param void
	 * @return boolean
	 */
	function execute() {
		if (!@mysql_ping($this->database_connection)) {
			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;
				}
				$this->setDatabaseConnection($dbc);
			} else {
				$this->printMessage('Failed to connect to database');
				return false;
			}
		}
		
		// ---------------------------------------------------
		//  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

		$installed_version = installed_version();
		$t_prefix = TABLE_PREFIX;
		$additional_upgrade_steps = array();
		
		// RUN QUERIES
		$total_queries = 0;
		$executed_queries = 0;

		$upgrade_script = "";

		$original_version_from = array_var(array_var($_POST, 'form_data'), 'upgrade_from', $installed_version);
		if (version_compare($installed_version, $this->getVersionFrom()) <= 0 && version_compare($original_version_from, '2.0.0.0-beta') > 0
			 && (!isset($_SESSION['from_feng1']) || !$_SESSION['from_feng1'])) {
			// upgrading from a version lower than this script's 'from' version
			$upgrade_script = tpl_fetch(get_template_path('db_migration/2_2_pamplona'));
		} else {
			
			//UPDATE VERSION 2.2-beta
			if (version_compare($installed_version, '2.2-beta') < 0) {
				//ACTIVITY FEED
				$upgrade_script .= "
					INSERT INTO `".$t_prefix."widgets` (`name`, `title`, `plugin_id`, `path`, `default_options`, `default_section`, `default_order`)
						VALUES ('activity_feed', 'activity_feed', 0, '', '', 'left', 0)
					ON DUPLICATE KEY UPDATE name=name;
					INSERT INTO `".$t_prefix."contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`)
						VALUES ('dashboard', 'filters_dashboard', '0,0,10,0', 'StringConfigHandler', '0', '0', 'first position: entry to see the dimension, second position: view timeslot, third position: recent activities to show, fourth position: view views and downloads')
					ON DUPLICATE KEY UPDATE name=name;
				";
				if (!$this->checkColumnExists($t_prefix."contact_config_option_values", "member_id", $this->database_connection)) {
					$upgrade_script .= "
						ALTER TABLE `".$t_prefix."contact_config_option_values` ADD `member_id` INT( 10 ) UNSIGNED NULL DEFAULT '0';
						ALTER TABLE `".$t_prefix."contact_config_option_values` drop PRIMARY KEY;
						ALTER TABLE `".$t_prefix."contact_config_option_values` ADD PRIMARY KEY ( `option_id` , `contact_id` , `member_id` );
					";
				}
				
				// color config options
				$upgrade_script .= "
					INSERT INTO `".$t_prefix."config_categories` (`name`, `is_system`) VALUES ('brand_colors', 1) ON DUPLICATE KEY UPDATE name=name;
					INSERT INTO `".$t_prefix."config_options` (`category_name`,`name`,`value`,`config_handler_class`,`is_system`) VALUES
						('brand_colors', 'brand_colors_head_back', '', 'StringConfigHandler', 1),
						('brand_colors', 'brand_colors_head_font', '', 'StringConfigHandler', 1),
						('brand_colors', 'brand_colors_tabs_back', '', 'StringConfigHandler', 1),
						('brand_colors', 'brand_colors_tabs_font', '', 'StringConfigHandler', 1)
					ON DUPLICATE KEY UPDATE name=name;
				";
				
				//SYNC GOOGLE CALENDARS
				$upgrade_script .= "
					ALTER TABLE `".$t_prefix."project_events` CHANGE `special_id` `special_id` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL;
				";
				//CLASSIFY EMAILS
				if (!$this->checkColumnExists($t_prefix."project_file_revisions", "hash", $this->database_connection)) {
					$upgrade_script .= "
						ALTER TABLE `".$t_prefix."project_file_revisions` ADD `hash` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL;
					";
				}
				
				//SCRIPT UPDATE OLD NOTES SEARCH BY NAME
				$upgrade_script .= "
					INSERT INTO `".$t_prefix."searchable_objects` (`rel_object_id`, `column_name`, `content`, `contact_id`)
						SELECT id,'name',name,'0' FROM `".$t_prefix."objects` WHERE `object_type_id` = (SELECT id FROM ".$t_prefix."object_types WHERE name='message')
					ON DUPLICATE KEY UPDATE rel_object_id=id,column_name='name';
				";

				//add the contact tab to the database if it does not exist
				if (!$this->checkValueExists($t_prefix."tab_panels", 'id', 'contacts-panel', $this->database_connection)) {
					$upgrade_script .= "
						INSERT INTO `".$t_prefix."tab_panels` (`id`,`title`,`icon_cls`,`refresh_on_context_change`,`default_controller`,`default_action`,`initial_controller`,`initial_action`,`enabled`,`type`,`ordering`,`plugin_id`,`object_type_id`) VALUES 
						 ('contacts-panel','contacts','ico-contacts',1,'contact','init','','',0,'system',7,0, (SELECT id FROM ".$t_prefix."object_types WHERE name='contact'))
						ON DUPLICATE KEY UPDATE name=name;
						INSERT INTO `".$t_prefix."tab_panel_permissions` (`permission_group_id`, `tab_panel_id`) VALUES 
						 ((SELECT id FROM ".$t_prefix."permission_groups WHERE name = 'Super Administrator'),	'contacts-panel'),
						 ((SELECT id FROM ".$t_prefix."permission_groups WHERE name = 'Administrator'), 'contacts-panel'),  
						 ((SELECT id FROM ".$t_prefix."permission_groups WHERE name = 'Manager'), 'contacts-panel'),  
						 ((SELECT id FROM ".$t_prefix."permission_groups WHERE name = 'Executive'), 'contacts-panel'),  
						 ((SELECT id FROM ".$t_prefix."permission_groups WHERE name = 'Collaborator Customer'), 'contacts-panel'),  
						 ((SELECT id FROM ".$t_prefix."permission_groups WHERE name = 'Non-Exec Director'), 'contacts-panel')
						ON DUPLICATE KEY UPDATE tab_panel_id=tab_panel_id;
					";
				}
				
				//change tasks and notes to WYSIWYG text
				$upgrade_script .="
					UPDATE `".$t_prefix."config_options` SET `value` = '1' WHERE `".$t_prefix."config_options`.`name` = 'wysiwyg_messages' OR `".$t_prefix."config_options`.`name` = 'wysiwyg_tasks';
				";
			}
			
			if (version_compare($installed_version, '2.2.0.1') < 0) {
				if (!$this->checkColumnExists($t_prefix."dimensions", 'permission_query_method', $this->database_connection)) {
					$upgrade_script .= "
						ALTER TABLE `".$t_prefix."dimensions` ADD COLUMN `permission_query_method` ENUM('mandatory','not_mandatory') NOT NULL DEFAULT 'mandatory';
					";
				}
			}
			
			if (version_compare($installed_version, '2.2.1-beta') < 0) {
				$upgrade_script .= "
					UPDATE ".$t_prefix."contact_config_options SET default_value='due_date' WHERE name='tasksGroupBy';
					INSERT INTO `".$t_prefix."config_options` (`category_name`,`name`,`value`,`config_handler_class`,`is_system`) VALUES
						('general', 'use_milestones', (SELECT count(*) FROM ".$t_prefix."project_milestones)>0, 'BoolConfigHandler', 0),
						('general', 'show_tab_icons', '1', 'BoolConfigHandler', '0')
					ON DUPLICATE KEY UPDATE name=name;
				";
			}
			
			if (version_compare($installed_version, '2.2.2-beta') < 0 ) {
				if (!$this->checkColumnExists($t_prefix."system_permissions", "can_see_assigned_to_other_tasks", $this->database_connection)) {
					$upgrade_script .= "
						ALTER TABLE `".$t_prefix."system_permissions` ADD COLUMN `can_see_assigned_to_other_tasks` TINYINT(1) UNSIGNED NOT NULL DEFAULT 1;
					";
				}
				$upgrade_script .= "
					UPDATE `".$t_prefix."system_permissions` SET can_see_assigned_to_other_tasks = 1;
					INSERT INTO ".$t_prefix."widgets (name, title, plugin_id, path, default_options, default_section, default_order) VALUES
					 ('completed_tasks_list', 'completed tasks list', 0, '', '', 'right', 150)
					ON DUPLICATE KEY UPDATE name=name;
				";
			}
			
			if (version_compare($installed_version, '2.2.3-beta') < 0 ) {
				if (!$this->checkColumnExists($t_prefix."reports", "ignore_context", $this->database_connection)) {
					$upgrade_script .= "
						ALTER TABLE `".$t_prefix."reports`
						 ADD COLUMN `ignore_context` BOOLEAN NOT NULL DEFAULT 1,
						 ADD INDEX `object_type`(`report_object_type_id`);
					";
				}
			}
			
			if (version_compare($installed_version, '2.2.4.1') < 0 ) {
				if (!$this->checkColumnExists($t_prefix."dimensions", "is_required", $this->database_connection)) {
					$upgrade_script .= "
						ALTER TABLE `".$t_prefix."dimensions` ADD COLUMN `is_required` BOOLEAN NOT NULL DEFAULT 0;
						INSERT INTO `".$t_prefix."contact_config_categories` (`name`, `is_system`, `type`, `category_order`) VALUES
						 ('listing preferences', 0, 0, 10)
						ON DUPLICATE KEY UPDATE name=name;
						INSERT INTO ".$t_prefix."searchable_objects (rel_object_id, column_name, content, contact_id)
						 SELECT id, 'object_id', id, 0 FROM ".$t_prefix."objects
						ON DUPLICATE KEY UPDATE rel_object_id=rel_object_id;
					";
				}
			}
		}
		
		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 (version_compare($installed_version, '2.2-beta') < 0) {
			// drop brand_colors column and use config options
			if ($this->checkColumnExists($t_prefix."contacts", 'brand_colors', $this->database_connection)) {
				$db_res = mysql_query("SELECT brand_colors FROM ".$t_prefix."contacts WHERE is_company=1 LIMIT 1", $this->database_connection);
				$row = mysql_fetch_assoc($db_res);
				$colors = explode("#", $row['brand_colors']);
				$head_back = (isset($colors[1]) && $colors[1] != "" ? $colors[1] : "000000");
				$tabs_back = (isset($colors[2]) && $colors[2] != "" ? $colors[2] : "14780e");
				$tabs_font = (isset($colors[3]) && $colors[3] != "" ? $colors[3] : "ffffff");
				$head_font = (isset($colors[4]) && $colors[4] != "" ? $colors[4] : "ffffff");
				
				$sqls = "
					UPDATE ".$t_prefix."config_options SET value='$head_back' WHERE name='brand_colors_head_back';
					UPDATE ".$t_prefix."config_options SET value='$head_font' WHERE name='brand_colors_head_font';
					UPDATE ".$t_prefix."config_options SET value='$tabs_back' WHERE name='brand_colors_tabs_back';
					UPDATE ".$t_prefix."config_options SET value='$tabs_font' WHERE name='brand_colors_tabs_font';
					ALTER TABLE ".$t_prefix."contacts DROP COLUMN brand_colors;
				";
				$this->executeMultipleQueries($sqls, $t_queries, $e_queries, $this->database_connection);
			}
		}
		
		$this->printMessage('Feng Office has been upgraded. You are now running Feng Office '.$this->getVersionTo().' Enjoy!');

		tpl_assign('additional_steps', $additional_upgrade_steps);

	} // execute
Beispiel #9
0
<?php

@set_time_limit(0);
define('ROOT', dirname(__FILE__) . '/../..');
define('PRODUCT_NAME', 'Feng Office');
define('PRODUCT_URL', 'http://www.fengoffice.com');
require_once dirname(__FILE__) . '/include.php';
$upgrader = new ScriptUpgrader(new Output_Html(), lang('upgrade fengoffice'), lang('upgrade your fengoffice installation'));
$form_data = array_var($_POST, 'form_data');
$upgrade_to = array_var($_GET, 'upgrade_to');
if (!is_array($form_data) && isset($upgrade_to)) {
    $form_data = array('upgrade_from' => installed_version(), 'upgrade_to' => $upgrade_to);
}
tpl_assign('upgrader', $upgrader);
tpl_assign('form_data', $form_data);
if (is_array($form_data)) {
    ob_start();
    $upgrader->upgrade(trim(array_var($form_data, 'upgrade_from')), trim(array_var($form_data, 'upgrade_to')));
    $status_messages = explode("\n", trim(ob_get_clean()));
    tpl_assign('status_messages', $status_messages);
}
// if
tpl_display(get_template_path('layout'));
 /**
  * Execute the script
  *
  * @param void
  * @return boolean
  */
 function execute()
 {
     if (!@mysql_ping($this->database_connection)) {
         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;
             }
             $this->setDatabaseConnection($dbc);
         } else {
             $this->printMessage('Failed to connect to database');
             return false;
         }
     }
     // ---------------------------------------------------
     //  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
     $installed_version = installed_version();
     $t_prefix = TABLE_PREFIX;
     $additional_upgrade_steps = array();
     // RUN QUERIES
     $total_queries = 0;
     $executed_queries = 0;
     $upgrade_script = "";
     $v_from = array_var($_POST, 'form_data');
     $original_version_from = array_var($v_from, 'upgrade_from', $installed_version);
     // Set upgrade queries
     if (version_compare($installed_version, '3.3-beta') < 0) {
         if (!$this->checkColumnExists($t_prefix . "dimension_object_types", "enabled", $this->database_connection)) {
             $upgrade_script .= "\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "dimension_object_types`\n\t\t\t\t\t\tADD COLUMN `enabled` BOOLEAN NOT NULL DEFAULT 1;\n\t\t\t\t";
         }
         $upgrade_script .= "\n\t\t\t\tCREATE TABLE IF NOT EXISTS `" . $t_prefix . "dimension_options` (\n\t\t\t\t  `dimension_id` INTEGER UNSIGNED NOT NULL,\n\t\t\t\t  `name` VARCHAR(100) NOT NULL,\n\t\t\t\t  `value` TEXT NOT NULL,\n\t\t\t\t  PRIMARY KEY (`dimension_id`, `name`)\n\t\t\t\t) ENGINE=InnoDB;\n\t\t\t";
         $upgrade_script .= "\n\t\t\t\tCREATE TABLE IF NOT EXISTS `" . $t_prefix . "dimension_object_type_options` (\n\t\t\t\t  `dimension_id` INTEGER UNSIGNED NOT NULL,\n\t\t\t\t  `object_type_id` INTEGER UNSIGNED NOT NULL,\n\t\t\t\t  `name` VARCHAR(100) NOT NULL,\n\t\t\t\t  `value` TEXT NOT NULL,\n\t\t\t\t  PRIMARY KEY (`dimension_id`, object_type_id, `name`)\n\t\t\t\t) ENGINE=InnoDB;\n\t\t\t";
         if (!$this->checkColumnExists($t_prefix . "members", "description", $this->database_connection)) {
             $upgrade_script .= "\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "members` ADD COLUMN `description` TEXT NOT NULL;\n\t\t\t\t";
         }
         if ($this->checkTableExists($t_prefix . "member_custom_properties", $this->database_connection) && !$this->checkColumnExists($t_prefix . "member_custom_properties", "is_special", $this->database_connection)) {
             // add columns in member custom properties to specify fixed properties
             $upgrade_script .= "\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "member_custom_properties`\n\t\t\t\t\t ADD COLUMN `is_special` BOOLEAN NOT NULL,\n\t\t\t\t\t ADD COLUMN `is_disabled` BOOLEAN NOT NULL;\n\t\t\t\t";
             // create special member custom properties for description and color and fill their values with the current description and color values
             $upgrade_script .= "\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "member_custom_properties` (`object_type_id`, `name`, `code`, `type`, `description`, `values`, `default_value`, `is_system`, `is_required`, `is_multiple_values`, `property_order`, `visible_by_default`, `is_special`, `is_disabled`)\n\t\t\t\t\t  SELECT mt.id, 'Color', 'color_special','color','','','',0,0,0,30,1, 1, 0\n\t\t\t\t\t  FROM " . $t_prefix . "object_types mt WHERE mt.`type` IN ('dimension_object','dimension_group')\n\t\t\t\t\tON DUPLICATE KEY UPDATE `code`=`code`;\n\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "member_custom_properties` (`object_type_id`, `name`, `code`, `type`, `description`, `values`, `default_value`, `is_system`, `is_required`, `is_multiple_values`, `property_order`, `visible_by_default`, `is_special`, `is_disabled`)\n\t\t\t\t\t  SELECT mt.id, 'Description', 'description_special', 'memo','','','',0,0,0,31,1, 1, 0\n\t\t\t\t\t  FROM " . $t_prefix . "object_types mt WHERE mt.`type` IN ('dimension_object','dimension_group')\n\t\t\t\t\tON DUPLICATE KEY UPDATE `code`=`code`;\n\n\t\t\t\t\tinsert into " . $t_prefix . "member_custom_property_values (`member_id`, `custom_property_id`, `value`)\n\t\t\t\t\t  select m.id, (select id from " . $t_prefix . "member_custom_properties where code='description_special' and is_special=1 and object_type_id=m.object_type_id), m.description\n\t\t\t\t\t  from fo_members m where m.description != ''\n\t\t\t\t\ton duplicate key update `value`=description;\n\t\t\t\t\t\n\t\t\t\t\tinsert into " . $t_prefix . "member_custom_property_values (`member_id`, `custom_property_id`, `value`)\n\t\t\t\t\t  select m.id, (select id from " . $t_prefix . "member_custom_properties where code='color_special' and is_special=1 and object_type_id=m.object_type_id), m.color\n\t\t\t\t\t  from fo_members m where m.color != ''\n\t\t\t\t\ton duplicate key update `value`=color;\n\t\t\t\t";
         }
         $upgrade_script .= "\r\n\t\t\t\tINSERT INTO `" . $t_prefix . "contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\r\n\t\t\t\t\t('task panel', 'tasksShowDimensionCols', '', 'StringConfigHandler', 1, 0, '')\r\n\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t";
         $upgrade_script .= "\n\t\t\t\tCREATE TABLE IF NOT EXISTS `" . $t_prefix . "sent_notifications` (\n\t\t\t\t `id` int(10) NOT NULL AUTO_INCREMENT,\n\t\t\t\t `queued_email_id` int(10) NOT NULL DEFAULT 0,\n\t\t\t\t `sent_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t `to` text COLLATE utf8_unicode_ci,\n\t\t\t\t `cc` text COLLATE utf8_unicode_ci,\n\t\t\t\t `bcc` text COLLATE utf8_unicode_ci,\n\t\t\t\t `from` text COLLATE utf8_unicode_ci,\n\t\t\t\t `subject` text COLLATE utf8_unicode_ci,\n\t\t\t\t `body` text COLLATE utf8_unicode_ci,\n\t\t\t\t `attachments` text COLLATE utf8_unicode_ci,\n\t\t\t\t `timestamp` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t PRIMARY KEY (`id`)\n\t\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t\t";
         $upgrade_script .= "\n\t\t\t\tUPDATE `" . $t_prefix . "contact_config_options` SET is_system=1 WHERE `name`='show_notify_checkbox_in_quick_add';\n\t\t\t";
         $upgrade_script .= "\n\t\t\t\tUPDATE `" . $t_prefix . "contact_config_options` SET default_value=1 WHERE `name`='can notify from quick add';\n\t\t\t";
     }
     // Execute all queries
     if (!$this->executeMultipleQueries($upgrade_script, $total_queries, $executed_queries, $this->database_connection)) {
         $this->printMessage('Failed to execute DB schema transformations. MySQL said: ' . mysql_error(), true);
         return false;
     }
     $this->printMessage("Database schema transformations executed (total queries: {$total_queries})");
     $this->printMessage('Feng Office has been upgraded. You are now running Feng Office ' . $this->getVersionTo() . ' Enjoy!');
     tpl_assign('additional_steps', $additional_upgrade_steps);
 }
 /**
  * Execute the script
  *
  * @param void
  * @return boolean
  */
 function execute()
 {
     if (!@mysql_ping($this->database_connection)) {
         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;
             }
             $this->setDatabaseConnection($dbc);
         } else {
             $this->printMessage('Failed to connect to database');
             return false;
         }
     }
     // ---------------------------------------------------
     //  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
     $installed_version = installed_version();
     $t_prefix = TABLE_PREFIX;
     $additional_upgrade_steps = array();
     // RUN QUERIES
     $total_queries = 0;
     $executed_queries = 0;
     $upgrade_script = "";
     $v_from = array_var($_POST, 'form_data');
     $original_version_from = array_var($v_from, 'upgrade_from', $installed_version);
     // Set upgrade queries
     if (version_compare($installed_version, '3.0-beta') < 0) {
         if (!$this->checkColumnExists($t_prefix . "system_permissions", "can_manage_contacts", $this->database_connection)) {
             $upgrade_script .= "\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "system_permissions` ADD COLUMN `can_manage_contacts` BOOLEAN NOT NULL DEFAULT 0;\n\t\t\t\t";
         }
         $upgrade_script .= "\n\t\t\t\tINSERT INTO " . $t_prefix . "tab_panels (id, title, icon_cls, default_controller, default_action, type, ordering, refresh_on_context_change, initial_controller, initial_action, enabled, plugin_id, object_type_id) VALUES\n\t\t\t\t('more-panel','getting started','ico-more-tab','more','index','system',100,0,'','',1,0,0)\n\t\t\t\tON DUPLICATE KEY UPDATE id=id;\n\t\t\t\t\n\t\t\t\tINSERT INTO " . $t_prefix . "tab_panel_permissions (permission_group_id, tab_panel_id)\n\t\t\t\tSELECT c.permission_group_id, 'more-panel' FROM " . $t_prefix . "contacts c WHERE c.user_type > 0\n\t\t\t\tON DUPLICATE KEY UPDATE tab_panel_id=tab_panel_id;\n\t\t\t\t\n\t\t\t\tINSERT INTO `" . $t_prefix . "config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\n\t\t\t\t('system', 'getting_started_step', '99', 'IntegerConfigHandler', '1', '0', NULL)\n\t\t\t\tON DUPLICATE KEY UPDATE name=name;\n\t\t\t\t\t\t\n\t\t\t\tUPDATE `" . $t_prefix . "config_options` SET `value`= '0'\n\t\t\t\t\tWHERE `name`='show_owner_company_name_header';\n\t\t\t\t\n\t\t\t\tCREATE TABLE `fixed_sharing_table` (\n\t\t\t\t  `group_id` INTEGER UNSIGNED NOT NULL,\n\t\t\t\t  `object_id` INTEGER UNSIGNED NOT NULL,\n\t\t\t\t  PRIMARY KEY (`group_id`, `object_id`),\n\t\t\t\t  INDEX `object_id`(`object_id`)\n\t\t\t\t) ENGINE = InnoDB;\n\t\t\t\t\n\t\t\t\tINSERT INTO fixed_sharing_table (group_id, object_id)\n\t\t\t\t  SELECT group_id, object_id FROM " . $t_prefix . "sharing_table\n\t\t\t\tON DUPLICATE KEY UPDATE fixed_sharing_table.group_id=fixed_sharing_table.group_id;\n\t\t\t\t\n\t\t\t\tDROP TABLE " . $t_prefix . "sharing_table;\n\t\t\t\tRENAME TABLE fixed_sharing_table TO " . $t_prefix . "sharing_table;\n\t\t\t";
         $upgrade_script .= "\n\t\t\t\tINSERT INTO `" . $t_prefix . "contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\n\t\t\t\t\t('task panel', 'tasksShowPercentCompletedBar', '0', 'BoolConfigHandler', 1, 0, ''),\n\t\t\t\t\t('task panel', 'tasksShowTimeEstimates', '1', 'BoolConfigHandler', 1, 0, ''),\n\t\t\t\t\t('task panel', 'tasksShowTimePending', '0', 'BoolConfigHandler', 1, 0, ''),\n\t\t\t\t\t('task panel', 'tasksShowTimeWorked', '0', 'BoolConfigHandler', 1, 0, ''),\n\t\t\t\t\t('task panel', 'tasksShowQuickEdit', '1', 'BoolConfigHandler', 1, 0, ''),\n\t\t\t\t\t('task panel', 'tasksShowQuickComplete', '0', 'BoolConfigHandler', 1, 0, ''),\n\t\t\t\t\t('task panel', 'tasksShowQuickComment', '0', 'BoolConfigHandler', 1, 0, ''),\n\t\t\t\t\t('task panel', 'tasksShowQuickAddSubTasks', '0', 'BoolConfigHandler', 1, 0, ''),\n\t\t\t\t\t('task panel', 'tasksShowStartDates', '0', 'BoolConfigHandler', 1, 0, ''),\n\t\t\t\t\t('task panel', 'tasksShowEndDates', '1', 'BoolConfigHandler', 1, 0, ''),\n\t\t\t\t\t('task panel', 'tasksShowAssignedBy', '0', 'BoolConfigHandler', 1, 0, ''),\n\t\t\t\t\t('task panel', 'tasksShowClassification', '1', 'BoolConfigHandler', 1, 0, ''),\n\t\t\t\t\t('task panel', 'tasksShowDescriptionOnTimeForms', '1', 'BoolConfigHandler', 0, 0, '')\n\t\t\t\tON DUPLICATE KEY UPDATE name=name;\n\n\t\t\t\tDELETE FROM " . $t_prefix . "config_options WHERE name = 'tasksShowTimeEstimates';\n\t\t\t";
         $upgrade_script .= "\n\t\t\t\tINSERT INTO `" . $t_prefix . "config_categories` (`name`, `is_system`, `category_order`) VALUES\n\t\t\t\t\t('brand_colors', 0, 6)\n\t\t\t\tON DUPLICATE KEY UPDATE is_system=0;\n\t\t\t\tUPDATE `" . $t_prefix . "config_options` SET is_system=0 WHERE name IN ('brand_colors_head_back', 'brand_colors_head_font');\n\t\t\t\tUPDATE `" . $t_prefix . "config_options` SET config_handler_class='ColorPickerConfigHandler' WHERE name IN ('brand_colors_head_back', 'brand_colors_head_font', 'brand_colors_tabs_back', 'brand_colors_tabs_font');\n\t\t\t\tUPDATE `" . $t_prefix . "config_options` SET is_system=1 WHERE name IN ('brand_colors_tabs_back', 'brand_colors_tabs_font');\n\t\t\t\tUPDATE `" . $t_prefix . "config_options` SET `value`='e7e7e7' WHERE `name`='brand_colors_tabs_back';\n\t\t\t\tUPDATE `" . $t_prefix . "config_options` SET `value`='000000' WHERE `name`='brand_colors_tabs_font';\n\t\t\t\t\n\t\t\t\tDELETE FROM " . $t_prefix . "widgets WHERE name IN ('ws_description', 'summary');\n\t\t\t\tDELETE FROM " . $t_prefix . "contact_widgets WHERE widget_name IN ('ws_description', 'summary');\n\t\t\t\t\n\t\t\t\tINSERT INTO `" . $t_prefix . "widgets` (`name`,`title`,`plugin_id`,`path`,`default_options`,`default_section`,`default_order`,`icon_cls`) VALUES\n\t\t\t\t ('active_context_info','active_context_info',0,'','','left',1,'ico-summary')\n\t\t\t\tON DUPLICATE KEY UPDATE name=name;\n\t\t\t\t\n\t\t\t\tINSERT INTO `" . $t_prefix . "contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES \n \t\t\t\t ('general', 'settings_closed', '0', 'BoolConfigHandler', 1, 0, '')\n \t\t\t\tON DUPLICATE KEY UPDATE name=name;\n\t\t\t\t\n\t\t\t\tINSERT INTO `" . $t_prefix . "config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\n\t\t\t\t ('general', 'enabled_dimensions', (SELECT GROUP_CONCAT(id) FROM `" . $t_prefix . "dimensions` WHERE `code` NOT IN ('feng_persons')), 'RootDimensionsConfigHandler', '1', '0', NULL)\n\t\t\t\tON DUPLICATE KEY UPDATE name=name;\n\t\t\t\t\n\t\t\t\tupdate " . $t_prefix . "tab_panels set plugin_id=(SELECT id from " . $t_prefix . "plugins where name='mail') where id='mails-panel';\n\t\t\t";
         if (!$this->checkTableExists($t_prefix . "max_system_permissions", $this->database_connection)) {
             $upgrade_script .= "\n\t\t\t\t\tCREATE TABLE " . $t_prefix . "max_system_permissions LIKE " . $t_prefix . "system_permissions;\n\t\t\t\t\t\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "max_system_permissions` (`permission_group_id`, `can_manage_security`, `can_manage_configuration`, `can_manage_templates`, `can_manage_time`, `can_add_mail_accounts`, `can_manage_dimensions`, `can_manage_dimension_members`, `can_manage_tasks`, `can_task_assignee`, `can_manage_billing`, `can_view_billing`, `can_see_assigned_to_other_tasks`, `can_manage_contacts`) VALUES\n\t\t\t\t\t((SELECT id FROM " . $t_prefix . "permission_groups WHERE name = 'Super Administrator'),\t1,\t1,\t1,\t1,\t1,\t\t1,\t1,\t1,\t1,\t1,\t1,\t1, 1),\n\t\t\t\t\t((SELECT id FROM " . $t_prefix . "permission_groups WHERE name = 'Administrator'),\t1,\t1,\t1,\t1,\t1,\t\t1,\t1,\t1,\t1,\t1,\t1,\t1, 1),\n\t\t\t\t\t((SELECT id FROM " . $t_prefix . "permission_groups WHERE name = 'Manager'),\t1,\t0,\t1,\t1,\t1,\t\t0,\t1,\t1,\t1,\t1,\t1,\t1, 1),\n\t\t\t\t\t((SELECT id FROM " . $t_prefix . "permission_groups WHERE name = 'Executive'),\t1,\t0,\t0,\t0,\t1,\t\t0,\t1,\t1,\t1,\t0,\t1,\t1, 1),\n\t\t\t\t\t((SELECT id FROM " . $t_prefix . "permission_groups WHERE name = 'Collaborator Customer'),\t0,\t0,\t0,\t0,\t0,\t\t0,\t0,\t0,\t1,\t0,\t0,\t0, 0),\n\t\t\t\t\t((SELECT id FROM " . $t_prefix . "permission_groups WHERE name = 'Internal Collaborator'),\t0,\t0,\t0,\t0,\t0,\t\t0,\t0,\t0,\t1,\t0,\t0,\t1, 0),\n\t\t\t\t\t((SELECT id FROM " . $t_prefix . "permission_groups WHERE name = 'External Collaborator'),\t0,\t0,\t0,\t0,\t0,\t\t0,\t0,\t0,\t1,\t0,\t0,\t0, 0),\n\t\t\t\t\t((SELECT id FROM " . $t_prefix . "permission_groups WHERE name = 'Guest Customer'),\t0,\t0,\t0,\t0,\t0,\t\t0,\t0,\t0,\t0,\t0,\t0,\t0, 0),\n\t\t\t\t\t((SELECT id FROM " . $t_prefix . "permission_groups WHERE name = 'Guest'),\t0,\t0,\t0,\t0,\t0,\t\t0,\t0,\t0,\t0,\t0,\t0,\t0, 0),\n\t\t\t\t\t((SELECT id FROM " . $t_prefix . "permission_groups WHERE name = 'Non-Exec Director'),\t0,\t0,\t0,\t0,\t0,\t\t0,\t0,\t0,\t0,\t0,\t1,\t1, 0)\n\t\t\t\t\tON DUPLICATE KEY UPDATE permission_group_id=permission_group_id;\n\t\t\t\t";
         }
     }
     if (version_compare($installed_version, '3.0-rc') < 0) {
         $upgrade_script .= "\n\t\t\t\tUPDATE " . $t_prefix . "role_object_type_permissions SET can_delete=0, can_write=0 WHERE \n\t\t\t\t\tobject_type_id IN (SELECT id FROM " . $t_prefix . "object_types WHERE name NOT IN ('file','timeslot','comment')) AND \n\t\t\t\t\trole_id IN (SELECT id FROM " . $t_prefix . "permission_groups WHERE type='roles' AND name IN ('Internal Collaborator','External Collaborator','Collaborator Customer'));\n\t\t\t";
     }
     if (version_compare($installed_version, '3.0') < 0) {
         $upgrade_script .= "\n\t\t\t\tUPDATE " . $t_prefix . "system_permissions SET can_see_assigned_to_other_tasks=0, can_view_billing=0\n\t\t\t\tWHERE permission_group_id IN (SELECT id FROM " . $t_prefix . "permission_groups WHERE name IN ('Collaborator Customer'));\n\t\t\t\tUPDATE " . $t_prefix . "max_system_permissions SET can_see_assigned_to_other_tasks=0, can_view_billing=0\n\t\t\t\tWHERE permission_group_id IN (SELECT id FROM " . $t_prefix . "permission_groups WHERE name IN ('Collaborator Customer'));\n\t\t\t\tUPDATE " . $t_prefix . "system_permissions SET can_see_assigned_to_other_tasks=0, can_view_billing=0\n\t\t\t\tWHERE permission_group_id IN (SELECT permission_group_id FROM " . $t_prefix . "contacts WHERE user_type IN (SELECT id FROM " . $t_prefix . "permission_groups WHERE name IN ('Collaborator Customer')));\n\t\t\t\t\n\t\t\t\tUPDATE " . $t_prefix . "system_permissions SET can_see_assigned_to_other_tasks=0\n\t\t\t\tWHERE permission_group_id IN (SELECT id FROM " . $t_prefix . "permission_groups WHERE name IN ('External Collaborator', 'Guest Customer', 'Guest'));\n\t\t\t\tUPDATE " . $t_prefix . "max_system_permissions SET can_see_assigned_to_other_tasks=0\n\t\t\t\tWHERE permission_group_id IN (SELECT id FROM " . $t_prefix . "permission_groups WHERE name IN ('External Collaborator', 'Guest Customer', 'Guest'));\n\t\t\t\tUPDATE " . $t_prefix . "system_permissions SET can_see_assigned_to_other_tasks=0\n\t\t\t\tWHERE permission_group_id IN (SELECT permission_group_id FROM " . $t_prefix . "contacts WHERE user_type IN (SELECT id FROM " . $t_prefix . "permission_groups WHERE name IN ('External Collaborator', 'Guest Customer', 'Guest')));\n\t\t\t\t\n\t\t\t\tUPDATE " . $t_prefix . "role_object_type_permissions SET can_write = 1 \n\t\t\t\tWHERE object_type_id = (SELECT id FROM " . $t_prefix . "object_types WHERE name='comment') \n\t\t\t\t\tAND role_id IN (SELECT p.id FROM `" . $t_prefix . "permission_groups` p WHERE p.`name` IN ('Non-Exec Director','Guest Customer'));\n\t\t\t\tUPDATE " . $t_prefix . "role_object_type_permissions SET can_write = 0 \n\t\t\t\tWHERE object_type_id = (SELECT id FROM " . $t_prefix . "object_types WHERE name='comment') \n\t\t\t\t\tAND role_id IN (SELECT p.id FROM `" . $t_prefix . "permission_groups` p WHERE p.`name` IN ('Guest'));\n\t\t\t";
     }
     if (version_compare($installed_version, '3.0.4') < 0) {
         $upgrade_script .= "\n\t\t\t\tALTER TABLE `" . $t_prefix . "project_file_revisions` ADD INDEX (`filesize`);\n\t\t\t";
     }
     if (version_compare($installed_version, '3.0.5') < 0) {
         if (!$this->checkColumnExists($t_prefix . "system_permissions", "can_update_other_users_invitations", $this->database_connection)) {
             $upgrade_script .= "\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "system_permissions` ADD COLUMN `can_update_other_users_invitations` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0;\n\t\t\t\t\tUPDATE " . $t_prefix . "system_permissions SET can_update_other_users_invitations=1\n\t\t\t\t\tWHERE permission_group_id IN (SELECT id FROM " . $t_prefix . "permission_groups WHERE name IN ('Super Administrator', 'Administrator'));\n\t\t\t\t";
         }
         if (!$this->checkColumnExists($t_prefix . "max_system_permissions", "can_update_other_users_invitations", $this->database_connection)) {
             $upgrade_script .= "\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "max_system_permissions` ADD COLUMN `can_update_other_users_invitations` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0;\n\t\t\t\t\tUPDATE " . $t_prefix . "max_system_permissions SET can_update_other_users_invitations=1\n\t\t\t\t\tWHERE permission_group_id IN (SELECT id FROM " . $t_prefix . "permission_groups WHERE name IN ('Super Administrator', 'Administrator', 'Manager', 'Executive'));\n\t\t\t\t";
         }
     }
     if (version_compare($installed_version, '3.0.6') < 0) {
         $upgrade_script .= "\n\t\t\t\tINSERT INTO `" . $t_prefix . "contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\n\t\t\t\t\t('calendar panel', 'show_multiple_color_events', '0', 'BoolConfigHandler', 0, 0, '')\n\t\t\t\tON DUPLICATE KEY UPDATE name=name;\n\t\t\t";
     }
     if (version_compare($installed_version, '3.0.7') < 0) {
         $upgrade_script .= "\n\t\t\t\tINSERT INTO `" . $t_prefix . "contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\n\t\t\t\t\t('task panel', 'tasksShowSubtasksStructure', '1', 'BoolConfigHandler', 1, 0, '')\n\t\t\t\tON DUPLICATE KEY UPDATE name=name;\n\t\t\t\t\n\t\t\t\tUPDATE `" . $t_prefix . "project_tasks` SET `assigned_to_contact_id`=0 WHERE `assigned_to_contact_id` IS NULL;\n\t\t\t\tUPDATE `" . $t_prefix . "project_tasks` SET `completed_by_id`=0 WHERE `completed_by_id` IS NULL;\n\t\t\t\tUPDATE `" . $t_prefix . "project_tasks` SET `milestone_id`=0 WHERE `milestone_id` IS NULL;\n\t\t\t\t\n\t\t\t\tUPDATE " . $t_prefix . "system_permissions SET can_task_assignee=0 WHERE permission_group_id IN (\n\t\t\t\t  SELECT c.permission_group_id FROM " . $t_prefix . "contacts c WHERE c.user_type IN (SELECT pg.id FROM " . $t_prefix . "permission_groups pg WHERE pg.name IN ('Guest', 'Guest Customer', 'Non-Exec Director'))\n\t\t\t\t);\n\t\t\t";
     }
     if (version_compare($installed_version, '3.0.8') < 0) {
         if (!$this->checkColumnExists($t_prefix . "object_types", "uses_order", $this->database_connection)) {
             $upgrade_script .= "\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "object_types` ADD COLUMN `uses_order` INTEGER UNSIGNED NOT NULL DEFAULT 0;\n\t\t\t\t";
         }
         if (!$this->checkColumnExists($t_prefix . "members", "order", $this->database_connection)) {
             $upgrade_script .= "\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "members` ADD COLUMN `order` INTEGER UNSIGNED NOT NULL DEFAULT 0;\n\t\t\t\t";
         }
     }
     // Execute all queries
     if (!$this->executeMultipleQueries($upgrade_script, $total_queries, $executed_queries, $this->database_connection)) {
         $this->printMessage('Failed to execute DB schema transformations. MySQL said: ' . mysql_error(), true);
         return false;
     }
     $this->printMessage("Database schema transformations executed (total queries: {$total_queries})");
     $this->printMessage('Feng Office has been upgraded. You are now running Feng Office ' . $this->getVersionTo() . ' Enjoy!');
     tpl_assign('additional_steps', $additional_upgrade_steps);
 }
 /**
  * Execute the script
  *
  * @param void
  * @return boolean
  */
 function execute()
 {
     if (!@mysql_ping($this->database_connection)) {
         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;
             }
             $this->setDatabaseConnection($dbc);
         } else {
             $this->printMessage('Failed to connect to database');
             return false;
         }
     }
     // ---------------------------------------------------
     //  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
     $installed_version = installed_version();
     $t_prefix = TABLE_PREFIX;
     $additional_upgrade_steps = array();
     // RUN QUERIES
     $total_queries = 0;
     $executed_queries = 0;
     $upgrade_script = "";
     $original_version_from = array_var(array_var($_POST, 'form_data'), 'upgrade_from', $installed_version);
     if (version_compare($installed_version, $this->getVersionFrom()) <= 0 && version_compare($original_version_from, '2.0.0.0-beta') > 0 && (!isset($_SESSION['from_feng1']) || !$_SESSION['from_feng1'])) {
         // upgrading from a version lower than this script's 'from' version
         $upgrade_script = tpl_fetch(get_template_path('db_migration/2_3_chorizo'));
     } else {
         if (version_compare($installed_version, '2.3-beta') < 0) {
             $upgrade_script .= "\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`)\r\n\t\t\t\t\t\tVALUES \r\n\t\t\t\t\t\t('task panel', 'reminders_tasks', 'reminder_email,1,1440', 'StringConfigHandler', '0', '23', NULL),\r\n\t\t\t\t\t\t('task panel', 'add_task_autoreminder', '0', 'BoolConfigHandler', '0', '21', NULL),\r\n\t\t\t\t\t\t('task panel', 'add_self_task_autoreminder', '1', 'BoolConfigHandler', '0', '22', NULL),\r\n\t\t\t\t\t\t('task panel', 'add_task_default_reminder', '1', 'BoolConfigHandler', '0', '20', NULL),\r\n\t\t\t\t\t\t('calendar panel', 'add_event_autoreminder', '1', 'BoolConfigHandler', '0', '0', NULL),\r\n\t\t\t\t\t\t('calendar panel', 'autoassign_events', '0', 'BoolConfigHandler', '0', '0', NULL),\r\n\t\t\t\t\t\t('calendar panel', 'event_send_invitations', '1', 'BoolConfigHandler', '0', '0', NULL),\r\n\t\t\t\t\t\t('calendar panel', 'event_subscribe_invited', '1', 'BoolConfigHandler', '0', '0', NULL),\r\n\t\t\t\t\t\t('mails panel', 'mails_per_page', '50', 'IntegerConfigHandler', '0', '0', NULL),\r\n\t\t\t\t\t\t('general', 'access_member_after_add', '1', 'BoolConfigHandler', '0', '1300', NULL),\r\n\t\t\t\t\t\t('general', 'access_member_after_add_remember', '0', 'BoolConfigHandler', '0', '1301', NULL),\r\n\t\t\t\t\t\t('general', 'sendEmailNotification', '1', 'BoolConfigHandler', '1', '0', 'Send email notification to new user'),\r\n \t\t\t\t\t\t('general', 'viewContactsChecked', '1', 'BoolConfigHandler', '1', '0', 'in people panel is view contacts checked'),\r\n \t\t\t\t\t\t('general', 'viewUsersChecked', '1', 'BoolConfigHandler', '0', '0', 'in people panel is view users checked'),\r\n \t\t\t\t\t\t('general', 'viewCompaniesChecked', '1', 'BoolConfigHandler', '1', '0', 'in people panel is view companies checked'),\r\n\t\t\t\t\t\t('general', 'contacts_per_page', '50', 'IntegerConfigHandler', '0', '1200', NULL)\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "config_options` (`category_name`,`name`,`value`,`config_handler_class`,`is_system`) VALUES\r\n\t\t\t\t\t\t('general', 'can_assign_tasks_to_companies', '1', 'BoolConfigHandler', '0'),\r\n\t\t\t\t\t\t('general', 'use_object_properties', '0', 'BoolConfigHandler', '0')\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t\t\tUPDATE `" . $t_prefix . "config_options` SET `value` = if ((SELECT count(*) FROM " . $t_prefix . "object_properties)>0, 1, 0) WHERE `name`='use_object_properties';\r\n\t\t\t\t\tUPDATE `" . $t_prefix . "config_options` SET `value` = '1' WHERE `name`='can_assign_tasks_to_companies';\r\n\t\t\t\t";
         }
         if (version_compare($installed_version, '2.3.1-beta') < 0) {
             $upgrade_script .= "\r\n\t\t\t\t\tINSERT INTO " . $t_prefix . "searchable_objects (rel_object_id, column_name, content, contact_id)\r\n\t\t\t\t\t\tSELECT contact_id, CONCAT('email_adress', id), email_address , '0' FROM " . $t_prefix . "contact_emails\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE rel_object_id=rel_object_id;\r\n\t\t\t\t\tINSERT INTO " . $t_prefix . "searchable_objects (rel_object_id, column_name, content, contact_id)\r\n\t\t\t\t\t\tSELECT contact_id, CONCAT('phone_number', id), number, '0' FROM " . $t_prefix . "contact_telephones\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE rel_object_id=rel_object_id;\r\n\t\t\t\t\tINSERT INTO " . $t_prefix . "searchable_objects (rel_object_id, column_name, content, contact_id)\r\n\t\t\t\t\t\tSELECT contact_id, CONCAT('web_url', id), url , '0' FROM " . $t_prefix . "contact_web_pages\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE rel_object_id=rel_object_id;\r\n\t\t\t\t\tINSERT INTO " . $t_prefix . "searchable_objects (rel_object_id, column_name, content, contact_id)\r\n\t\t\t\t\t\tSELECT contact_id, CONCAT('im_value', id), value , '0' FROM " . $t_prefix . "contact_im_values\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE rel_object_id=rel_object_id;\r\n\t\t\t\t\tINSERT INTO " . $t_prefix . "searchable_objects (rel_object_id, column_name, content, contact_id)\r\n\t\t\t\t\t\tSELECT contact_id, CONCAT('address', id), CONCAT(street,' ',city,' ',state,' ',country,' ',zip_code) , '0' FROM " . $t_prefix . "contact_addresses\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE rel_object_id=rel_object_id;\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "contact_config_options`(`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES ('task panel','tasksDateStart','0000-00-00 00:00:00','DateTimeConfigHandler',1,0,'date from to filter out task list'),\r\n('task panel','tasksDateEnd','0000-00-00 00:00:00','DateTimeConfigHandler',1,0,'the date up to filter the list of tasks')\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE id=id;\r\n\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\tupdate " . $t_prefix . "contacts set company_id=0 where company_id is null;\r\n\t\t\t\t\tupdate " . $t_prefix . "contacts set display_name='' where display_name is null;\r\n\t\t\t\t\tupdate " . $t_prefix . "contacts set avatar_file='' where avatar_file is null;\r\n\t\t\t\t\tupdate " . $t_prefix . "contacts set last_login='******' where last_login is null;\r\n\t\t\t\t\tupdate " . $t_prefix . "contacts set last_visit='0000-00-00 00:00:00' where last_visit is null;\r\n\t\t\t\t\tupdate " . $t_prefix . "contacts set personal_member_id=0 where personal_member_id is null;\r\n\t\t\t\t\tUPDATE `" . $t_prefix . "config_options` SET `is_system` = '1' WHERE `name`='viewUsersChecked';\r\n\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`)\r\n\t\t\t\t\tVALUES ('general', 'updateOnLinkedObjects', '0', 'BoolConfigHandler', '0', '0', 'Update objects when linking others')ON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t\t";
             if (!$this->checkColumnExists($t_prefix . "event_invitations", "synced", $this->database_connection)) {
                 $upgrade_script .= "\n\t\t\t\t\t\tALTER TABLE " . $t_prefix . "event_invitations ADD synced int(1) DEFAULT '0';\n\t\t\t\t\t";
             }
             if (!$this->checkColumnExists($t_prefix . "event_invitations", "special_id", $this->database_connection)) {
                 $upgrade_script .= "\n\t\t\t\t\t\tALTER TABLE " . $t_prefix . "event_invitations ADD special_id text CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL;\n\t\t\t\t\t";
             }
         }
         if (version_compare($installed_version, '2.3.1-rc') < 0) {
             $upgrade_script .= "\r\n\t\t\t\t\tupdate " . $t_prefix . "config_options set is_system=1 where name='exchange_compatible';\r\n\t\t\t\t\tUPDATE `" . $t_prefix . "widgets` SET `default_section` = 'right' WHERE `title`='people';\r\n\t\t\t\t\tUPDATE `" . $t_prefix . "contact_config_options` SET `default_value` = 'F j, Y (l)' WHERE `name`='descriptive_date_format';\r\n\t\t\t\t\t\t\t\r\n\t\t\t\tINSERT INTO `" . $t_prefix . "contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`)\r\n\t\t\t\tVALUES ('dashboard', 'overviewAsList', '0', 'BoolConfigHandler', '1', '0', 'View Overview as list')\r\n\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t\t";
         }
     }
     if (version_compare($installed_version, '2.3.1.1') < 0) {
         $upgrade_script .= "\r\n\t\t\t\t\tDELETE FROM `" . $t_prefix . "contact_config_option_values` WHERE `option_id` = ( SELECT `id` FROM `" . $t_prefix . "contact_config_options` WHERE `name` = 'updateOnLinkedObjects');\r\n\t\t\t\t\tDELETE FROM `" . $t_prefix . "contact_config_options` WHERE `name` = 'updateOnLinkedObjects';\r\n\t\t\t\t\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`)\r\n\t\t\t\t\tVALUES ('general', 'updateOnLinkedObjects', '0', 'BoolConfigHandler', '0', '0', 'Update objects when linking others')\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t\t";
     }
     if (version_compare($installed_version, '2.3.2-beta') < 0) {
         $upgrade_script .= "\r\n\t\t\t\tINSERT INTO `" . $t_prefix . "config_options` (`category_name`,`name`,`value`,`config_handler_class`,`is_system`) VALUES\r\n\t\t\t\t\t('general', 'let_users_create_objects_in_root', '1', 'BoolConfigHandler', '0')\r\n\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t\t\r\n\t\t\t\tINSERT INTO " . $t_prefix . "contact_member_permissions (permission_group_id, member_id, object_type_id, can_delete, can_write)\r\n\t\t\t\t  SELECT c.permission_group_id, 0, rtp.object_type_id, rtp.can_delete, rtp.can_write FROM " . $t_prefix . "role_object_type_permissions rtp \r\n\t\t\t\t  INNER JOIN " . $t_prefix . "contacts c ON c.user_type=rtp.role_id\r\n\t\t\t\t  WHERE rtp.object_type_id NOT IN (SELECT id FROM " . $t_prefix . "object_types WHERE name IN ('mail','template','file_revision')) AND rtp.role_id in (\r\n\t\t\t\t    SELECT pg.id FROM " . $t_prefix . "permission_groups pg WHERE pg.type='roles' AND pg.name IN ('Super Administrator','Administrator','Manager','Executive')\r\n\t\t\t\t  )\r\n\t\t\t\tON DUPLICATE KEY UPDATE member_id=0;\r\n\t\t\t\t\r\n\t\t\t\tINSERT INTO " . $t_prefix . "sharing_table (group_id, object_id)\r\n\t\t\t\tSELECT cmp.permission_group_id, o.id FROM " . $t_prefix . "objects o\r\n\t\t\t\tINNER JOIN " . $t_prefix . "contact_member_permissions cmp ON cmp.object_type_id=o.object_type_id AND cmp.member_id=0\r\n\t\t\t\tWHERE o.object_type_id IN (SELECT ot.id FROM " . $t_prefix . "object_types ot WHERE ot.name!='mail' and ot.type IN ('content_object','comment','located'))\r\n\t\t\t\tAND NOT EXISTS (\r\n\t\t\t\t  SELECT om.object_id FROM " . $t_prefix . "object_members om\r\n\t\t\t\t  WHERE om.object_id=o.id\r\n\t\t\t\t  AND om.member_id IN (\r\n\t\t\t\t    SELECT m.id FROM " . $t_prefix . "members m WHERE m.dimension_id IN (SELECT d.id FROM " . $t_prefix . "dimensions d WHERE d.defines_permissions=1 AND d.is_manageable=1)\r\n\t\t\t\t  )\r\n\t\t\t\t) ON DUPLICATE KEY UPDATE group_id=group_id;\r\n\t\t\t";
         if (version_compare($installed_version, '2.3.2-rc') < 0) {
             $upgrade_script .= "\r\n\t\t\t\t\tCREATE TABLE `to_delete` (`id` INTEGER UNSIGNED, PRIMARY KEY (`id`)) ENGINE = InnoDB;\r\n\t\t\t\t\tinsert into to_delete select o.id from " . $t_prefix . "object_types o inner join " . $t_prefix . "object_types o2 on o.id>o2.id and o.name=o2.name;\r\n\t\t\t\t\tdelete from " . $t_prefix . "object_types where id in (select id from to_delete);\r\n\t\t\t\t\tDROP TABLE `to_delete`;\r\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "object_types` DROP INDEX `name`,\r\n\t\t\t\t\t ADD UNIQUE INDEX `name` USING BTREE(`name`);\r\n\t\t\t\t";
         }
         if (version_compare($installed_version, '2.3.2-rc2') < 0) {
             $upgrade_script .= "\r\n\t\t\t\t\tUPDATE `" . $t_prefix . "administration_tools` SET `visible` = '0' WHERE `name`='mass_mailer';\r\n\t\t\t\t\tDELETE FROM `" . $t_prefix . "contact_emails` WHERE `contact_id` = '0';\r\n\t\t\t\t";
             if (!$this->checkColumnExists($t_prefix . "application_logs", "member_id", $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\t\tALTER TABLE " . $t_prefix . "application_logs ADD member_id int(10) NOT NULL default '0';\r\n\t\t\t\t\t";
             }
         }
     }
     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;
     }
     $this->printMessage('Feng Office has been upgraded. You are now running Feng Office ' . $this->getVersionTo() . ' Enjoy!');
     tpl_assign('additional_steps', $additional_upgrade_steps);
 }
 /**
  * Execute the script
  *
  * @param void
  * @return boolean
  */
 function execute()
 {
     if (!@mysql_ping($this->database_connection)) {
         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;
             }
             $this->setDatabaseConnection($dbc);
         } else {
             $this->printMessage('Failed to connect to database');
             return false;
         }
     }
     // ---------------------------------------------------
     //  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
     $installed_version = installed_version();
     $t_prefix = TABLE_PREFIX;
     $additional_upgrade_steps = array();
     include_once ROOT . "/public/upgrade/helpers/rebuild_tasks_tree.php";
     // RUN QUERIES
     $total_queries = 0;
     $executed_queries = 0;
     $upgrade_script = "";
     $v_from = array_var($_POST, 'form_data');
     $original_version_from = array_var($v_from, 'upgrade_from', $installed_version);
     // Set upgrade queries
     if (version_compare($installed_version, '3.1.1') < 0) {
         if (!$this->checkColumnExists($t_prefix . "project_tasks", "parents_path", $this->database_connection)) {
             $upgrade_script .= "\r\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "project_tasks` ADD COLUMN `parents_path` varchar(255) NOT NULL default '';\r\n\t\t\t\t";
         }
         if (!$this->checkColumnExists($t_prefix . "project_tasks", "depth", $this->database_connection)) {
             $upgrade_script .= "\r\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "project_tasks` ADD COLUMN `depth` int(2) unsigned NOT NULL default '0';\r\n\t\t\t\t";
         }
         if (!$this->checkColumnExists($t_prefix . "template_tasks", "parents_path", $this->database_connection)) {
             $upgrade_script .= "\r\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "template_tasks` ADD COLUMN `parents_path` varchar(255) NOT NULL default '';\r\n\t\t\t\t";
         }
         if (!$this->checkColumnExists($t_prefix . "template_tasks", "depth", $this->database_connection)) {
             $upgrade_script .= "\r\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "template_tasks` ADD COLUMN `depth` int(2) unsigned NOT NULL default '0';\r\n\t\t\t\t";
         }
         $upgrade_script .= rebuild_tasks_depth_and_parents_path($t_prefix . "project_tasks", $this->database_connection);
         $upgrade_script .= rebuild_tasks_depth_and_parents_path($t_prefix . "template_tasks", $this->database_connection);
     }
     if (version_compare($installed_version, '3.1.2') < 0) {
         $upgrade_script .= "\r\n\t\t\t\tINSERT INTO `" . $t_prefix . "config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\r\n\t\t\t\t ('general', 'last_sharing_table_rebuild', NOW(), 'StringConfigHandler', '1', '0', NULL)\r\n\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t";
         $upgrade_script .= "\r\n\t\t\t\tINSERT INTO `" . $t_prefix . "cron_events` (`name`, `recursive`, `delay`, `is_system`, `enabled`, `date`) VALUES\r\n\t\t\t\t('sharing_table_partial_rebuild', '1', '1440', '1', '1', '0000-00-00 00:00:00')\r\n\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t";
     }
     if (version_compare($installed_version, '3.1.2.7') < 0) {
         $upgrade_script .= "\r\n\t\t\t\tALTER TABLE `" . $t_prefix . "object_members` ADD INDEX (`member_id`);\r\n\t\t\t";
     }
     if (version_compare($installed_version, '3.1.3') < 0) {
         $upgrade_script .= "\r\n\t\t\t\tUPDATE " . $t_prefix . "max_system_permissions SET can_see_assigned_to_other_tasks=1 \r\n\t\t\t\tWHERE permission_group_id IN (\r\n\t\t\t\t\t\tSELECT id FROM " . $t_prefix . "permission_groups WHERE `type`='roles' AND name IN ('Collaborator Customer')\r\n\t\t\t\t);\r\n\t\t\t";
     }
     if (version_compare($installed_version, '3.1.4') < 0) {
         if (!$this->checkColumnExists($t_prefix . "system_permissions", "can_link_objects", $this->database_connection)) {
             $upgrade_script .= "\r\n\t\t\t\tALTER TABLE `" . $t_prefix . "system_permissions`\r\n\t\t\t\tADD COLUMN `can_link_objects` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0;\r\n\t\t\t\t\r\n\t\t\t\tUPDATE `" . $t_prefix . "system_permissions` SET `can_link_objects`=1 WHERE `permission_group_id` IN (\r\n\t\t\t\t\tSELECT id FROM `" . $t_prefix . "permission_groups` WHERE `type`='roles' AND `name` IN ('Super Administrator','Administrator','Manager','Executive','Internal Collaborator','Collaborator Customer','External Collaborator')\r\n\t\t\t\t);\r\n\t\t\t\t\r\n\t\t\t\tUPDATE `" . $t_prefix . "system_permissions` SET `can_link_objects`=1 WHERE `permission_group_id` IN (\r\n\t\t\t\t\tSELECT permission_group_id FROM `" . $t_prefix . "contacts` WHERE `user_type` IN (\r\n\t\t\t\t\t\tSELECT id FROM `" . $t_prefix . "permission_groups` WHERE `type`='roles' AND `name` IN ('Super Administrator','Administrator','Manager','Executive','Internal Collaborator','Collaborator Customer','External Collaborator')\r\n\t\t\t\t\t)\r\n\t\t\t\t);\r\n\t\t\t";
         }
         if (!$this->checkColumnExists($t_prefix . "max_system_permissions", "can_link_objects", $this->database_connection)) {
             $upgrade_script .= "\r\n\t\t\t\tALTER TABLE `" . $t_prefix . "max_system_permissions`\r\n\t\t\t\t ADD COLUMN `can_link_objects` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0;\r\n\t\t\r\n\t\t\t\tUPDATE `" . $t_prefix . "max_system_permissions` SET `can_link_objects`=1 WHERE `permission_group_id` IN (\r\n\t\t\t\t\tSELECT id FROM `" . $t_prefix . "permission_groups` WHERE `type`='roles' AND `name` IN ('Super Administrator','Administrator','Manager','Executive','Internal Collaborator','Collaborator Customer','External Collaborator')\r\n\t\t\t\t);\r\n\t\t\t";
         }
     }
     if (version_compare($installed_version, '3.1.5') < 0) {
         $upgrade_script .= "\r\n\t\t\t\tinsert into " . $t_prefix . "role_object_type_permissions (role_id, object_type_id, can_delete, can_write)\r\n\t\t\t\t  select id,(select id from " . $t_prefix . "object_types where name='report'),0,0 from " . $t_prefix . "permission_groups where type='roles' and parent_id>0\r\n\t\t\t\ton duplicate key update role_id=role_id;\r\n\t\t\t";
         $upgrade_script .= "\r\n\t\t\t\tINSERT INTO `" . $t_prefix . "cron_events` (`name`, `recursive`, `delay`, `is_system`, `enabled`, `date`) VALUES\r\n\t\t\t\t\t('send_outbox_mails', '1', '1', '1', '1', '0000-00-00 00:00:00')\r\n\t\t\t\tON DUPLICATE KEY UPDATE `name`=`name`;\r\n\t\t\t";
         $upgrade_script .= "\r\n\t\t\t\tINSERT INTO `" . $t_prefix . "config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\r\n\t\t\t\t\t('general', 'inherit_permissions_from_parent_member', 1, 'BoolConfigHandler', '0', '0', NULL)\r\n\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t";
     }
     // Execute all queries
     if (!$this->executeMultipleQueries($upgrade_script, $total_queries, $executed_queries, $this->database_connection)) {
         $this->printMessage('Failed to execute DB schema transformations. MySQL said: ' . mysql_error(), true);
         return false;
     }
     $this->printMessage("Database schema transformations executed (total queries: {$total_queries})");
     $this->printMessage('Feng Office has been upgraded. You are now running Feng Office ' . $this->getVersionTo() . ' Enjoy!');
     tpl_assign('additional_steps', $additional_upgrade_steps);
 }
	/**
	 * Execute the script
	 *
	 * @param void
	 * @return boolean
	 */
	function execute() {

		// ---------------------------------------------------
		//  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);
		if (defined('DB_ENGINE'))
		tpl_assign('engine', DB_ENGINE);
		else
		tpl_assign('engine', 'InnoDB');

		// ---------------------------------------------------
		//  Execute migration
		// ---------------------------------------------------
		
		// RUN QUERIES
		$total_queries = 0;
		$executed_queries = 0;
		$installed_version = installed_version();
		if (version_compare($installed_version, $this->getVersionFrom()) <= 0) {
			// upgrading from a version lower than this script's 'from' version
			$upgrade_script = tpl_fetch(get_template_path('db_migration/1_5_figazza'));
		} else {
			// upgrading from a pre-release of this version (beta, rc, etc)
			$upgrade_script = "";
			if (version_compare($installed_version, "1.5-beta3") < 0) {
				$upgrade_script .= "
				  ALTER TABLE `".TABLE_PREFIX."users` ADD COLUMN `can_manage_time` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0;
				  ALTER TABLE `".TABLE_PREFIX."groups` ADD COLUMN `can_manage_time` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0;
				";
			}
			if (version_compare($installed_version, "1.5-rc") < 0) {
				$upgrade_script .= "
					INSERT INTO `".TABLE_PREFIX."config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES
						('mailing', 'smtp_address', '', 'StringConfigHandler', 0, 0, '')
					ON DUPLICATE KEY UPDATE id=id;
				";
			}
			$upgrade_script .= "
				DELETE FROM `".TABLE_PREFIX."cron_events` WHERE `name` = 'backup';
				INSERT INTO `".TABLE_PREFIX."user_ws_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES 
					('mails panel', 'email_polling', '0', 'IntegerConfigHandler', '1', '0', NULL),
					('mails panel', 'show_unread_on_title', '0', 'BoolConfigHandler', '1', '0', NULL)
				ON DUPLICATE KEY UPDATE id=id;
			";
		}
		
		$upgrade_script .= "
			ALTER TABLE `".TABLE_PREFIX."mail_accounts` MODIFY COLUMN `del_from_server` INTEGER NOT NULL default 0;
		";

		if (version_compare($installed_version, '1.4.4') < 0) {
			$upgrade_script .= "
				ALTER TABLE `".TABLE_PREFIX."project_tasks`
				 ADD COLUMN `repeat_end` DATETIME NOT NULL default '0000-00-00 00:00:00',
				 ADD COLUMN `repeat_forever` tinyint(1) NOT NULL,
				 ADD COLUMN `repeat_num` int(10) unsigned NOT NULL default '0',
				 ADD COLUMN `repeat_d` int(10) unsigned NOT NULL,
				 ADD COLUMN `repeat_m` int(10) unsigned NOT NULL,
				 ADD COLUMN `repeat_y` int(10) unsigned NOT NULL,
				 ADD COLUMN `repeat_by` varchar(15) collate utf8_unicode_ci NOT NULL default '';
			";
		}
		
		if (!$this->checkColumnExists(TABLE_PREFIX.'users', 'updated_by_id', $this->database_connection)) {
			$upgrade_script .= "
				ALTER TABLE `".TABLE_PREFIX."users` ADD COLUMN `updated_by_id` int(10) unsigned default NULL;
			";
		}
		if (!$this->checkColumnExists(TABLE_PREFIX.'reports', 'is_order_by_asc', $this->database_connection)) {
			$upgrade_script = "
				ALTER TABLE `".TABLE_PREFIX."reports` ADD COLUMN `is_order_by_asc` TINYINT(1) $default_collation NOT NULL DEFAULT 1;
				$upgrade_script
			";
		}
		
		// rename gelsheet tables before upgrading if name is wrong and if engine is case sensitive
		if ($this->checkTableExists(TABLE_PREFIX.'gs_fontStyles', $this->database_connection) && !$this->checkTableExists(TABLE_PREFIX.'gs_fontstyles', $this->database_connection)) {
			$upgrade_script = "
				RENAME TABLE `" . TABLE_PREFIX . "gs_fontStyles` TO `" . TABLE_PREFIX . "gs_fontstyles`;
			" . $upgrade_script;
		}
		if ($this->checkTableExists(TABLE_PREFIX.'gs_mergedCells', $this->database_connection) && !$this->checkTableExists(TABLE_PREFIX.'gs_mergedcells', $this->database_connection)) {
			$upgrade_script = "
				RENAME TABLE `" . TABLE_PREFIX . "gs_mergedCells` TO `" . TABLE_PREFIX . "gs_mergedcells`;
			" . $upgrade_script;
		}

		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
		
		// UPGRADE CUSTOM PROPERTY MULTIPLE VALUES
		if (version_compare($installed_version, $this->getVersionFrom()) <= 0) {
			$res = mysql_query("SELECT * FROM `".TABLE_PREFIX."custom_property_values` WHERE `custom_property_id` IN (SELECT `id` FROM `".TABLE_PREFIX."custom_properties` WHERE `is_multiple_values` = 1)");
			while ($row = mysql_fetch_assoc($res)) {
				$id = $row['id'];
				$cid = $row['custom_property_id'];
				$oid = $row['object_id'];
				$value = $row['value'];
				$values = explode(",", $value);
				$valuestrings = array();
				foreach ($values as $val) {
					$valuestrings[] = "($oid, $cid, '$val')";
				}
				$valuestring = implode(",", $valuestrings);
				mysql_query("INSERT INTO `".TABLE_PREFIX."custom_property_values` (`object_id`, `custom_property_id`, `value`) VALUES $valuestring");
				mysql_query("DELETE FROM `".TABLE_PREFIX."custom_property_values` WHERE `id` = $id");
			}
		}
		
		// UPGRADE PUBLIC FILES
		if (version_compare($installed_version, $this->getVersionFrom()) <= 0) {
			// load FileRepository classes
			include_once ROOT . "/environment/library/database/adapters/AbstractDBAdapter.class.php";
			include_once ROOT . "/environment/library/database/DB.class.php";
			include_once ROOT . "/environment/library/database/DBResult.class.php";
			include_once ROOT . "/environment/classes/Inflector.class.php";
			include_once ROOT . "/library/filerepository/FileRepository.class.php";
			include_once ROOT . "/library/filerepository/errors/FileNotInRepositoryError.class.php";
			include_once ROOT . "/library/filerepository/errors/FileRepositoryAddError.class.php";
			include_once ROOT . "/library/filerepository/errors/FileRepositoryDeleteError.class.php";
			include_once ROOT . "/library/filerepository/backend/FileRepository_Backend.class.php";
			DB::connect(DB_ADAPTER, array(
				'host'    => DB_HOST,
				'user'    => DB_USER,
				'pass'    => DB_PASS,
				'name'    => DB_NAME,
				'persist' => DB_PERSIST
			)); // connect
			if(defined('DB_CHARSET') && trim(DB_CHARSET)) {
				DB::execute("SET NAMES ?", DB_CHARSET);
			} // if
			$res = mysql_query("SELECT `value` FROM `".TABLE_PREFIX."config_options` WHERE `name` = 'file_storage_adapter'");
			$row = mysql_fetch_assoc($res);
			$adapter = $row['value'];
			if ($adapter == 'mysql') {
				include_once ROOT . "/library/filerepository/backend/FileRepository_Backend_DB.class.php";
				FileRepository::setBackend(new FileRepository_Backend_DB(TABLE_PREFIX));
			} else {
				include_once ROOT . "/library/filerepository/backend/FileRepository_Backend_FileSystem.class.php";
				FileRepository::setBackend(new FileRepository_Backend_FileSystem(ROOT . "/upload", TABLE_PREFIX));
			}
			$res = mysql_query("SELECT `id`, `avatar_file` FROM `".TABLE_PREFIX."users` WHERE `avatar_file` <> ''", $this->database_connection);
			$count = 0;
			while ($row = mysql_fetch_assoc($res)) {
				$avatar = $row['avatar_file'];
				$id = $row['id'];
				$path = ROOT . "/public/files/$avatar";
				if (is_file($path)) {
					$fid = FileRepository::addFile($path, array('type' => 'image/png'));
					mysql_query("UPDATE `".TABLE_PREFIX."users` SET `avatar_file` = '$fid' WHERE `id` = $id", $this->database_connection);
					$count++;
				}
			}
			$res = mysql_query("SELECT `id`, `picture_file` FROM `".TABLE_PREFIX."contacts` WHERE `picture_file` <> ''", $this->database_connection);
			while ($row = mysql_fetch_assoc($res)) {
				$picture = $row['picture_file'];
				$id = $row['id'];
				$path = ROOT . "/public/files/$picture";
				if (is_file($path)) {
					$fid = FileRepository::addFile($path, array('type' => 'image/png'));
					mysql_query("UPDATE `".TABLE_PREFIX."contacts` SET `picture_file` = '$fid' WHERE `id` = $id", $this->database_connection);
					$count++;
				}
			}
			$res = mysql_query("SELECT `id`, `logo_file` FROM `".TABLE_PREFIX."companies` WHERE `logo_file` <> ''", $this->database_connection);
			while ($row = mysql_fetch_assoc($res)) {
				$logo = $row['logo_file'];
				$id = $row['id'];
				$path = ROOT . "/public/files/$logo";
				if (is_file($path)) {
					$fid = FileRepository::addFile($path, array('type' => 'image/png'));
					mysql_query("UPDATE `".TABLE_PREFIX."companies` SET `logo_file` = '$fid' WHERE `id` = $id", $this->database_connection);
					$count++;
				}
			}
			$this->printMessage("$count public files migrated to upload directory.");
		}
		
		$this->printMessage('Feng Office has been upgraded. You are now running Feng Office '.$this->getVersionTo().' Enjoy!');
	} // execute
 /**
  * Execute the script
  *
  * @param void
  * @return boolean
  */
 function execute()
 {
     if (!@mysql_ping($this->database_connection)) {
         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;
             }
             $this->setDatabaseConnection($dbc);
         } else {
             $this->printMessage('Failed to connect to database');
             return false;
         }
     }
     // ---------------------------------------------------
     //  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
     $installed_version = installed_version();
     $t_prefix = TABLE_PREFIX;
     $additional_upgrade_steps = array();
     // RUN QUERIES
     $total_queries = 0;
     $executed_queries = 0;
     $upgrade_script = "";
     $v_from = array_var($_POST, 'form_data');
     $original_version_from = array_var($v_from, 'upgrade_from', $installed_version);
     if (false && version_compare($installed_version, $this->getVersionFrom()) <= 0 && version_compare($original_version_from, '2.0.0.0-beta') > 0 && (!isset($_SESSION['from_feng1']) || !$_SESSION['from_feng1'])) {
         // upgrading from a version lower than this script's 'from' version
         $upgrade_script = tpl_fetch(get_template_path('db_migration/2_6_choto'));
     } else {
         if (version_compare($installed_version, '2.6-beta') < 0) {
             if (!$this->checkTableExists($t_prefix . "member_custom_properties", $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\t\tCREATE TABLE `" . $t_prefix . "member_custom_properties` (\r\n\t\t\t\t\t\t  `id` int(10) NOT NULL AUTO_INCREMENT,\r\n\t\t\t\t\t\t  `object_type_id` int(10) unsigned NOT NULL,\r\n\t\t\t\t\t\t  `name` varchar(255) " . $default_collation . " NOT NULL,\r\n\t\t\t\t\t\t  `type` varchar(255) " . $default_collation . " NOT NULL,\r\n\t\t\t\t\t\t  `description` text " . $default_collation . " NOT NULL,\r\n\t\t\t\t\t\t  `values` text " . $default_collation . " NOT NULL,\r\n\t\t\t\t\t\t  `default_value` text " . $default_collation . " NOT NULL,\r\n\t\t\t\t\t\t  `is_system` tinyint(1) NOT NULL,\r\n\t\t\t\t\t\t  `is_required` tinyint(1) NOT NULL,\r\n\t\t\t\t\t\t  `is_multiple_values` tinyint(1) NOT NULL,\r\n\t\t\t\t\t\t  `property_order` int(10) NOT NULL,\r\n\t\t\t\t\t\t  `visible_by_default` tinyint(1) NOT NULL,\r\n\t\t\t\t\t\t  PRIMARY KEY (`id`)\r\n\t\t\t\t\t\t) ENGINE=InnoDB " . $default_charset . ";\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\tCREATE TABLE IF NOT EXISTS `" . $t_prefix . "member_custom_property_values` (\r\n\t\t\t\t\t\t  `id` int(10) NOT NULL AUTO_INCREMENT,\r\n\t\t\t\t\t\t  `member_id` int(10) NOT NULL,\r\n\t\t\t\t\t\t  `custom_property_id` int(10) NOT NULL,\r\n\t\t\t\t\t\t  `value` text " . $default_collation . " NOT NULL,\r\n\t\t\t\t\t\t  PRIMARY KEY (`id`)\r\n\t\t\t\t\t\t) ENGINE=InnoDB " . $default_charset . ";\r\n\t\t\t\t\t";
             }
             if (!$this->checkColumnExists($t_prefix . "members", "color", $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\t\tALTER TABLE `" . $t_prefix . "members` ADD COLUMN `color` INTEGER UNSIGNED NOT NULL DEFAULT 0;\r\n\t\t\t\t\t\tUPDATE " . $t_prefix . "members SET color=(SELECT color FROM " . $t_prefix . "workspaces w WHERE w.object_id=" . $t_prefix . "members.object_id) \r\n\t\t\t\t\t\tWHERE object_type_id=(SELECT id FROM " . $t_prefix . "object_types WHERE name='workspace');\r\n\t\t\t\t\t";
             }
             $upgrade_script .= "\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "widgets` (`name`,`title`,`plugin_id`,`path`,`default_options`,`default_section`,`default_order`,`icon_cls`) VALUES \r\n\t\t\t\t\t('active_context_info', 'active context info', 0, '', '', 'left', 0, 'ico-workspace')\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE name=name;";
             $upgrade_script .= "\r\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "custom_property_values` MODIFY COLUMN `value` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci;\r\n\t\t\t\t";
             $upgrade_script .= "\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\r\n\t\t\t\t\t('task panel', 'quick_add_task_view_dimensions_combos', '', 'ManageableDimensionsConfigHandler', '0', '0', 'dimensions ids for skip')\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE `name`=`name`;\r\n\t\t\t\t\t\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\r\n\t\t\t\t\t('time panel', 'add_timeslot_view_dimensions_combos', '', 'ManageableDimensionsConfigHandler', '0', '0', 'dimensions ids for skip'),\r\n\t\t\t\t\t('task panel', 'show_notify_checkbox_in_quick_add', '0', 'BoolConfigHandler', 0, 0, 'Show notification checkbox in quick add task view')\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE `name`=`name`;\r\n\t\t\t\t\t\r\n\t\t\t\t\tUPDATE `" . $t_prefix . "contact_config_categories` \r\n\t\t\t\t\t SET is_system = 0\r\n\t\t\t\t\t WHERE name='time panel';\r\n\t\t\t\t";
             $upgrade_script .= "\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\r\n\t\t\t\t\t ('general', 'milestone_selector_filter', 'current_and_parents', 'MilestoneSelectorFilterConfigHandler', 0, 0, NULL)\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE `name`=`name`;\r\n\t\t\t\t";
             $upgrade_script .= "\r\n\t\t\t\t\tUPDATE " . $t_prefix . "dimension_object_type_contents SET is_multiple=1 \r\n\t\t\t\t\t WHERE content_object_type_id =(SELECT id FROM " . $t_prefix . "object_types WHERE name = 'milestone') \r\n\t\t\t\t\t AND dimension_object_type_id IN (SELECT id FROM " . $t_prefix . "object_types WHERE name IN ('customer','project','folder','project_folder','customer_folder'));\r\n\t\t\t\t";
         }
         if (version_compare($installed_version, '2.6-rc') < 0) {
             if (!$this->checkKeyExists($t_prefix . "application_logs", "member", $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\t\tALTER TABLE `" . $t_prefix . "application_logs` ADD INDEX `member`(`member_id`, `created_on`, `is_silent`);\r\n\t\t\t\t\t";
             }
             $upgrade_script .= "\r\n\t\t\t\t\tUPDATE `" . $t_prefix . "config_options` SET `value` = '1' WHERE `name` = 'use tasks dependencies';\r\n\t\t\t\t";
         }
         if (version_compare($installed_version, '2.6.0.2') < 0) {
             $upgrade_script .= "\r\n\t\t\t\tUPDATE `" . $t_prefix . "contact_config_options`\r\n\t\t\t\tSET default_value = ''\r\n\t\t\t\tWHERE name='quick_add_task_view_dimensions_combos';\r\n\t\t\t\t\t\r\n\t\t\t\tUPDATE `" . $t_prefix . "contact_config_options`\r\n\t\t\t\tSET default_value = ''\r\n\t\t\t\tWHERE name='add_timeslot_view_dimensions_combos';\r\n\t\t\t\t";
         }
         if (version_compare($installed_version, '2.6.1') < 0) {
             if (!$this->checkColumnExists($t_prefix . "custom_properties", "code", $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "custom_properties` ADD COLUMN `code` VARCHAR(255) NOT NULL DEFAULT '';\r\n\t\t\t\t\t";
             }
             if (!$this->checkColumnExists($t_prefix . "member_custom_properties", "code", $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "member_custom_properties` ADD COLUMN `code` VARCHAR(255) NOT NULL DEFAULT '';\r\n\t\t\t\t\t";
             }
         }
         if (version_compare($installed_version, '2.6.2-beta') < 0) {
             $upgrade_script .= "\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES \r\n\t\t\t\t\t\t('general', 'timeReportShowEstimatedTime', '1', 'BoolConfigHandler', 1, 0, '')\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t\t";
         }
         if (version_compare($installed_version, '2.6.3-beta') < 0) {
             if (!$this->checkTableExists($t_prefix . "sharing_table_flags", $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\t\tCREATE TABLE `" . $t_prefix . "sharing_table_flags` (\r\n\t\t\t\t\t\t  `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,\r\n\t\t\t\t\t\t  `permission_group_id` INTEGER UNSIGNED NOT NULL,\r\n\t\t\t\t\t\t  `member_id` INTEGER UNSIGNED NOT NULL,\r\n\t\t\t\t\t\t  `execution_date` DATETIME NOT NULL,\r\n\t\t\t\t\t\t  `permission_string` TEXT collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\t\t\t  `created_by_id` INTEGER UNSIGNED NOT NULL,\r\n\t\t\t\t\t\t  PRIMARY KEY (`id`)\r\n\t\t\t\t\t\t)\r\n\t\t\t\t\t\tENGINE = InnoDB;\r\n\t\t\t\t\t";
             }
             $upgrade_script .= "\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "cron_events` (`name`, `recursive`, `delay`, `is_system`, `enabled`, `date`) VALUES\r\n\t\t\t\t\t\t('check_sharing_table_flags', '1', '10', '1', '1', '0000-00-00 00:00:00')\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE `name`=`name`;\r\n\t\t\t\t";
         }
         if (version_compare($installed_version, '2.6.3-rc') < 0) {
             if (!$this->checkColumnExists($t_prefix . "contact_telephones", "name", $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\t\tALTER TABLE `" . $t_prefix . "contact_telephones` ADD COLUMN `name` VARCHAR(256) NOT NULL DEFAULT '';\r\n\t\t\t\t\t";
             }
             $upgrade_script .= "\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES \r\n\t\t\t\t\t\t('general', 'can_modify_navigation_panel', '1', 'BoolConfigHandler', 1, 0, '')\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t\t";
         }
         if (!$this->executeMultipleQueries($upgrade_script, $total_queries, $executed_queries, $this->database_connection)) {
             $this->printMessage('Failed to execute DB schema transformations. MySQL said: ' . mysql_error(), true);
             return false;
         }
         $this->printMessage("Database schema transformations executed (total queries: {$total_queries})");
     }
     if (version_compare($installed_version, '2.5.0.4') < 0) {
         if (!$this->checkColumnExists("queued_emails", "attachments", $this->database_connection)) {
             $sqls = "\r\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "queued_emails` ADD COLUMN `attachments` TEXT;\r\n\t\t\t\t";
             $this->executeMultipleQueries($sqls, $t_queries, $e_queries, $this->database_connection);
         }
     }
     $this->printMessage('Feng Office has been upgraded. You are now running Feng Office ' . $this->getVersionTo() . ' Enjoy!');
     tpl_assign('additional_steps', $additional_upgrade_steps);
 }
 /**
  * Execute the script
  *
  * @param void
  * @return boolean
  */
 function execute()
 {
     if (!@mysql_ping($this->database_connection)) {
         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;
             }
             $this->setDatabaseConnection($dbc);
         } else {
             $this->printMessage('Failed to connect to database');
             return false;
         }
     }
     // ---------------------------------------------------
     //  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
     $installed_version = installed_version();
     $t_prefix = TABLE_PREFIX;
     $additional_upgrade_steps = array();
     // RUN QUERIES
     $total_queries = 0;
     $executed_queries = 0;
     $upgrade_script = "";
     $v_from = array_var($_POST, 'form_data');
     $original_version_from = array_var($v_from, 'upgrade_from', $installed_version);
     // Set upgrade queries
     if (version_compare($installed_version, '3.2-beta') < 0) {
         $upgrade_script .= "\n\t\t\t\tCREATE TABLE IF NOT EXISTS `" . $t_prefix . "external_calendar_properties` (\n\t\t\t\t  `external_calendar_id` int(10) unsigned NOT NULL,\n\t\t\t\t  `key` varchar(255) " . $default_collation . " NOT NULL,\n\t\t\t\t  `value` text  " . $default_collation . " NOT NULL, \n\t\t\t\t  PRIMARY KEY (`external_calendar_id`,`key`)\n\t\t\t\t) ENGINE=InnoDB " . $default_charset . ";\n\t\t\t";
         $upgrade_script .= "\n\t\t\t\tTRUNCATE TABLE `" . $t_prefix . "external_calendar_users`;\n\t\t\t\tALTER TABLE `" . $t_prefix . "external_calendar_users` MODIFY auth_pass text;\n\t\t\t";
         $upgrade_script .= "\n\t\t\t\tUPDATE `" . $t_prefix . "project_events` SET ext_cal_id=0\n\t\t\t\tWHERE ext_cal_id > 0;\n\t\t\t";
         $upgrade_script .= "\n\t\t\t\tTRUNCATE TABLE `" . $t_prefix . "external_calendars`;\n\t\t\t";
         if ($this->checkColumnExists($t_prefix . "external_calendars", "calendar_user", $this->database_connection)) {
             $upgrade_script .= "\r\n\t\t\t\t\tALTER TABLE  `" . $t_prefix . "external_calendars` CHANGE `calendar_user` `original_calendar_id` varchar(255);\r\n\t\t\t\t";
         }
         if (!$this->checkColumnExists($t_prefix . "external_calendars", "sync", $this->database_connection)) {
             $upgrade_script .= "\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "external_calendars` ADD COLUMN `sync` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER calendar_feng;\n\t\t\t\t";
         }
         if (!$this->checkColumnExists($t_prefix . "external_calendars", "related_to", $this->database_connection)) {
             $upgrade_script .= "\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "external_calendars` ADD COLUMN `related_to` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER sync;\n\t\t\t\t";
         }
         $upgrade_script .= "\n\t\t\t\tCREATE TABLE IF NOT EXISTS `" . $t_prefix . "template_instantiated_parameters` (\n\t\t\t\t  `template_id` INTEGER UNSIGNED NOT NULL,\n\t\t\t\t  `instantiation_id` INTEGER UNSIGNED NOT NULL,\n\t\t\t\t  `parameter_name` VARCHAR(255) NOT NULL DEFAULT '',\n\t\t\t\t  `value` TEXT NOT NULL,\n\t\t\t\t  PRIMARY KEY (`template_id`, `instantiation_id`, `parameter_name`)\n\t\t\t\t) ENGINE = InnoDB;\n\t\t\t";
         if (!$this->checkColumnExists($t_prefix . "project_tasks", "instantiation_id", $this->database_connection)) {
             $upgrade_script .= "\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "project_tasks` ADD COLUMN `instantiation_id` INTEGER UNSIGNED NOT NULL DEFAULT 0;\n\t\t\t\t";
         }
         if (!$this->checkColumnExists($t_prefix . "queued_emails", "cc", $this->database_connection)) {
             $upgrade_script .= "\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "queued_emails`\n\t\t\t\t\t ADD COLUMN `cc` TEXT NOT NULL AFTER `to`,\n\t\t\t\t\t ADD COLUMN `bcc` TEXT NOT NULL AFTER `cc`;\n\t\t\t\t";
         }
         $upgrade_script .= "\n\t\t\t\tINSERT INTO `" . $t_prefix . "config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\n\t\t\t\t ('system', 'last_template_instantiation_id', '0', 'IntegerConfigHandler', '1', '0', NULL)\n\t\t\t\tON DUPLICATE KEY UPDATE name=name;\n\t\t\t";
         // max member permissions by role
         if (!$this->checkTableExists($t_prefix . 'max_role_object_type_permissions', $this->database_connection)) {
             $upgrade_script .= "\n\t\t\t\t\tCREATE TABLE `" . $t_prefix . "max_role_object_type_permissions` (\n\t\t\t\t\t  `role_id` INTEGER UNSIGNED NOT NULL,\n\t\t\t\t\t  `object_type_id` INTEGER UNSIGNED NOT NULL,\n\t\t\t\t\t  `can_delete` BOOLEAN NOT NULL,\n\t\t\t\t\t  `can_write` BOOLEAN NOT NULL,\n\t\t\t\t\t  PRIMARY KEY (`role_id`, `object_type_id`)\n\t\t\t\t\t) ENGINE = InnoDB;\n\t\t\t\t";
             $upgrade_script .= "\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "max_role_object_type_permissions` SELECT * FROM `" . $t_prefix . "role_object_type_permissions`;\n\t\t\t\t";
             $upgrade_script .= "\n\t\t\t\t\tDELETE FROM `" . $t_prefix . "role_object_type_permissions` \n\t\t\t\t\tWHERE object_type_id=(select id from " . $t_prefix . "object_types where name='report') \n\t\t\t\t\t\tAND role_id IN (SELECT id FROM " . $t_prefix . "permission_groups WHERE `type`='roles' AND name IN ('Guest Customer','Guest','Non-Exec Director'));\n\t\t\t\t";
         }
         if (!$this->checkColumnExists($t_prefix . "template_parameters", "default_value", $this->database_connection)) {
             $upgrade_script .= "\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "template_parameters`\n\t\t\t\t\t ADD COLUMN `default_value` TEXT NOT NULL;\n\t\t\t\t";
         }
         if ($mysql_version && version_compare($mysql_version, '5.6', '>=')) {
             //bad performance
             /*	$upgrade_script .= "
             				CREATE TABLE `".$t_prefix."searchable_objects_new` (
             					`rel_object_id` int(10) unsigned NOT NULL default '0',
             					`column_name` varchar(50) collate utf8_unicode_ci NOT NULL default '',
             					`content` text collate utf8_unicode_ci NOT NULL,
             					`contact_id` int(10) unsigned NOT NULL default '0',
             					PRIMARY KEY  (`rel_object_id`,`column_name`),
             					FULLTEXT KEY `content` (`content`),
             					KEY `rel_obj_id` (`rel_object_id`)
             				) ENGINE = InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
             			";
             			$upgrade_script .= "
             				INSERT INTO `".$t_prefix."searchable_objects_new` SELECT * FROM `".$t_prefix."searchable_objects` ORDER BY rel_object_id, column_name;
             				RENAME TABLE `".$t_prefix."searchable_objects` TO `".$t_prefix."searchable_objects_old`;
             				RENAME TABLE `".$t_prefix."searchable_objects_new` TO `".$t_prefix."searchable_objects`;
             				DROP TABLE `".$t_prefix."searchable_objects_old`;
             			";*/
         }
     }
     if (version_compare($installed_version, '3.2-rc') < 0) {
         $upgrade_script .= "\n\t\t\t\tINSERT INTO " . $t_prefix . "max_role_object_type_permissions (role_id, object_type_id, can_delete, can_write)\n\t\t\t\t SELECT p.id, o.id, 0, 0\n\t\t\t\t FROM `" . $t_prefix . "object_types` o JOIN `" . $t_prefix . "permission_groups` p\n\t\t\t\t WHERE o.`name` IN ('message','weblink','file','task','milestone','event','contact','mail','timeslot','report','comment','invoice','expense','objective')\n\t\t\t\t AND p.`name` IN ('Guest Customer')\n\t\t\t\tON DUPLICATE KEY UPDATE role_id=role_id;\n\t\t\t\tUPDATE " . $t_prefix . "max_system_permissions SET can_see_assigned_to_other_tasks=1\n\t\t\t\tWHERE permission_group_id IN (SELECT id FROM " . $t_prefix . "permission_groups WHERE `type`='roles' AND name IN ('Guest Customer'));\n\t\t\t\tUPDATE " . $t_prefix . "system_permissions SET can_see_assigned_to_other_tasks=1\n\t\t\t\tWHERE permission_group_id IN (SELECT id FROM " . $t_prefix . "permission_groups WHERE `type`='roles' AND name IN ('Guest Customer'));\n\t\t\t";
     }
     if (version_compare($installed_version, '3.2-rc2') < 0) {
         $upgrade_script .= "\r\n\t\t\t\tINSERT INTO `" . $t_prefix . "contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\n\t\t\t\t\t('general', 'listingContactsBy', '0', 'BoolConfigHandler', '0', '0', NULL),\n\t\t\t\t\t('task panel', 'pushUseWorkingDays', '1', 'BoolConfigHandler', '1', '0', NULL),\n\t\t\t\t\t('task panel', 'zoom in gantt', '3', 'IntegerConfigHandler', 1, 0, NULL)\n\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t";
         //max_role_object_type_permissions
         $upgrade_script .= "\n\t\t\t\tDELETE FROM " . $t_prefix . "max_role_object_type_permissions \n\t\t\t\tWHERE object_type_id IN (\n\t\t\t\t\t SELECT o.id\n\t\t\t\t\t FROM `" . $t_prefix . "object_types` o \n\t\t\t\t\t WHERE o.`name` IN ('message','weblink','file','task','milestone','event','contact','timeslot','report','comment','template')\t\t\t\t\n\t\t\t\t );\n\t\t\t\t \n\t\t\t\t INSERT INTO " . $t_prefix . "max_role_object_type_permissions (role_id, object_type_id, can_delete, can_write)\n\t\t\t\t SELECT p.id, o.id, 1, 1\n\t\t\t\t FROM `" . $t_prefix . "object_types` o JOIN `" . $t_prefix . "permission_groups` p\n\t\t\t\t WHERE o.`name` IN ('message','weblink','file','task','milestone','event','contact','timeslot','report','comment','template')\n\t\t\t\t AND p.`name` IN ('Super Administrator','Administrator','Manager','Executive');\n\t\t\t\t\t\t\t\t \n\t\t\t\tINSERT INTO " . $t_prefix . "max_role_object_type_permissions (role_id, object_type_id, can_delete, can_write)\n\t\t\t\t SELECT p.id, o.id, 0, 1\n\t\t\t\t FROM `" . $t_prefix . "object_types` o JOIN `" . $t_prefix . "permission_groups` p\n\t\t\t\t WHERE o.`name` IN ('message','weblink','file','timeslot','comment','contact','report')\n\t\t\t\t AND p.`name` IN ('Collaborator Customer','Internal Collaborator','External Collaborator');\n\t\t\t\t \n\t\t\t\tINSERT INTO " . $t_prefix . "max_role_object_type_permissions (role_id, object_type_id, can_delete, can_write)\n\t\t\t\t SELECT p.id, o.id, 0, 0\n\t\t\t\t FROM `" . $t_prefix . "object_types` o JOIN `" . $t_prefix . "permission_groups` p\n\t\t\t\t WHERE o.`name` IN ('task','milestone','event')\n\t\t\t\t AND p.`name` IN ('Collaborator Customer','Internal Collaborator','External Collaborator');\n\t\t\t\t\t\t\t\t \n\t\t\t\tINSERT INTO " . $t_prefix . "max_role_object_type_permissions (role_id, object_type_id, can_delete, can_write)\n\t\t\t\t SELECT p.id, o.id, 0, 0\n\t\t\t\t FROM `" . $t_prefix . "object_types` o JOIN `" . $t_prefix . "permission_groups` p\n\t\t\t\t WHERE o.`name` IN ('message','weblink','file','task','milestone','event','contact','timeslot','report','comment')\n\t\t\t\t AND p.`name` IN ('Guest Customer','Guest','Non-Exec Director');\r\n\t\t\t";
         //role_object_type_permissions
         $upgrade_script .= "\r\n\t\t\t\tDELETE FROM " . $t_prefix . "role_object_type_permissions\r\n\t\t\t\tWHERE object_type_id IN (\r\n\t\t\t\t\tSELECT o.id\r\n\t\t\t\t\tFROM `" . $t_prefix . "object_types` o\r\n\t\t\t\t\tWHERE o.`name` IN ('message','weblink','file','task','milestone','event','contact','timeslot','report','comment','template')\r\n\t\t\t\t);\n\n\t\t\t\tINSERT INTO " . $t_prefix . "role_object_type_permissions (role_id, object_type_id, can_delete, can_write)\n\t\t\t\t SELECT p.id, o.id, 1, 1\n\t\t\t\t FROM `" . $t_prefix . "object_types` o JOIN `" . $t_prefix . "permission_groups` p\n\t\t\t\t WHERE o.`name` IN ('message','weblink','file','task','milestone','event','contact','timeslot','report','comment','template')\n\t\t\t\t AND p.`name` IN ('Super Administrator','Administrator','Manager')\n\t\t\t\tON DUPLICATE KEY UPDATE role_id=role_id;\n\t\t\t\t \n\t\t\t\tINSERT INTO " . $t_prefix . "role_object_type_permissions (role_id, object_type_id, can_delete, can_write)\n\t\t\t\t SELECT p.id, o.id, 0, 1\n\t\t\t\t FROM `" . $t_prefix . "object_types` o JOIN `" . $t_prefix . "permission_groups` p\n\t\t\t\t WHERE o.`name` IN ('message','weblink','file','task','milestone','event','contact','timeslot','report','comment','template')\n\t\t\t\t AND p.`name` IN ('Executive')\n\t\t\t\tON DUPLICATE KEY UPDATE role_id=role_id;\n\t\t\t\t\n\t\t\t\tINSERT INTO " . $t_prefix . "role_object_type_permissions (role_id, object_type_id, can_delete, can_write)\n\t\t\t\t SELECT p.id, o.id, 0, 1\n\t\t\t\t FROM `" . $t_prefix . "object_types` o JOIN `" . $t_prefix . "permission_groups` p\n\t\t\t\t WHERE o.`name` IN ('file','timeslot','comment')\n\t\t\t\t AND p.`name` IN ('Collaborator Customer','Internal Collaborator')\n\t\t\t\tON DUPLICATE KEY UPDATE role_id=role_id;\n\t\t\t\t\n\t\t\t\tINSERT INTO " . $t_prefix . "role_object_type_permissions (role_id, object_type_id, can_delete, can_write)\n\t\t\t\t SELECT p.id, o.id, 0, 0\n\t\t\t\t FROM `" . $t_prefix . "object_types` o JOIN `" . $t_prefix . "permission_groups` p\n\t\t\t\t WHERE o.`name` IN ('task','milestone','event','report','contact')\n\t\t\t\t AND p.`name` IN ('Collaborator Customer','Internal Collaborator')\n\t\t\t\tON DUPLICATE KEY UPDATE role_id=role_id;\n\t\t\t\t\n\t\t\t\tINSERT INTO " . $t_prefix . "role_object_type_permissions (role_id, object_type_id, can_delete, can_write)\n\t\t\t\t SELECT p.id, o.id, 0, 1\n\t\t\t\t FROM `" . $t_prefix . "object_types` o JOIN `" . $t_prefix . "permission_groups` p\n\t\t\t\t WHERE o.`name` IN ('timeslot','comment')\n\t\t\t\t AND p.`name` IN ('External Collaborator')\n\t\t\t\tON DUPLICATE KEY UPDATE role_id=role_id;\n\t\t\t\t\n\t\t\t\tINSERT INTO " . $t_prefix . "role_object_type_permissions (role_id, object_type_id, can_delete, can_write)\n\t\t\t\t SELECT p.id, o.id, 0, 0\n\t\t\t\t FROM `" . $t_prefix . "object_types` o JOIN `" . $t_prefix . "permission_groups` p\n\t\t\t\t WHERE o.`name` IN ('task','file','milestone')\n\t\t\t\t AND p.`name` IN ('External Collaborator')\n\t\t\t\tON DUPLICATE KEY UPDATE role_id=role_id;\n\t\t\t\t \n\t\t\t\tINSERT INTO " . $t_prefix . "role_object_type_permissions (role_id, object_type_id, can_delete, can_write)\n\t\t\t\t SELECT p.id, o.id, 0, 1\n\t\t\t\t FROM `" . $t_prefix . "object_types` o JOIN `" . $t_prefix . "permission_groups` p\n\t\t\t\t WHERE o.`name` IN ('comment')\n\t\t\t\t AND p.`name` IN ('Non-Exec Director','Guest Customer')\n\t\t\t\tON DUPLICATE KEY UPDATE role_id=role_id;\r\n\t\t\t";
         //max_system_permissions
         $upgrade_script .= "\n\t\t\t\tUPDATE `" . $t_prefix . "max_system_permissions` SET `can_see_assigned_to_other_tasks`=1 WHERE `permission_group_id` IN (\n\t\t\t\t\t\tSELECT id FROM `" . $t_prefix . "permission_groups` WHERE `type`='roles' AND `name` IN ('External Collaborator','Guest')\n\t\t\t\t\t);\n\t\t\t";
         //system_permissions
         $upgrade_script .= "\r\n\t\t\t\tUPDATE `" . $t_prefix . "system_permissions` SET `can_update_other_users_invitations`=1 WHERE `permission_group_id` IN (\n\t\t\t\t\tSELECT permission_group_id FROM `" . $t_prefix . "contacts` WHERE `user_type` IN (\n\t\t\t\t\t\tSELECT id FROM `" . $t_prefix . "permission_groups` WHERE `type`='roles' AND `name` IN ('Manager')\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t\t\n\t\t\t\tUPDATE `" . $t_prefix . "system_permissions` SET `can_manage_security`=0 WHERE `permission_group_id` IN (\n\t\t\t\t\tSELECT permission_group_id FROM `" . $t_prefix . "contacts` WHERE `user_type` IN (\n\t\t\t\t\t\tSELECT id FROM `" . $t_prefix . "permission_groups` WHERE `type`='roles' AND `name` IN ('Executive')\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t\t\n\t\t\t\tUPDATE `" . $t_prefix . "system_permissions` SET `can_manage_tasks`=1 WHERE `permission_group_id` IN (\n\t\t\t\t\tSELECT permission_group_id FROM `" . $t_prefix . "contacts` WHERE `user_type` IN (\n\t\t\t\t\t\tSELECT id FROM `" . $t_prefix . "permission_groups` WHERE `type`='roles' AND `name` IN ('Executive')\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t\t\n\t\t\t\tUPDATE `" . $t_prefix . "system_permissions` SET `can_see_assigned_to_other_tasks`=1 WHERE `permission_group_id` IN (\n\t\t\t\t\tSELECT permission_group_id FROM `" . $t_prefix . "contacts` WHERE `user_type` IN (\n\t\t\t\t\t\tSELECT id FROM `" . $t_prefix . "permission_groups` WHERE `type`='roles' AND `name` IN ('Collaborator Customer')\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t\t\n\t\t\t\tUPDATE `" . $t_prefix . "system_permissions` SET `can_see_assigned_to_other_tasks`=0 WHERE `permission_group_id` IN (\n\t\t\t\t\tSELECT permission_group_id FROM `" . $t_prefix . "contacts` WHERE `user_type` IN (\n\t\t\t\t\t\tSELECT id FROM `" . $t_prefix . "permission_groups` WHERE `type`='roles' AND `name` IN ('Internal Collaborator')\n\t\t\t\t\t)\n\t\t\t\t);\r\n\t\t\t";
         // config option to specify mail field where the notification recipients should go
         $upgrade_script .= "\n\t\t\t\tINSERT INTO `" . $t_prefix . "config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\n\t\t\t\t ('general', 'check_unique_mail_contact_comp', '0', 'BoolConfigHandler', 0, 0, NULL),\n\t\t\t\t ('mailing', 'notification_recipients_field', 'to', 'MailFieldConfigHandler', '0', '10', NULL)\n\t\t\t\tON DUPLICATE KEY UPDATE name=name;\n\t\t\t";
         $upgrade_script .= "\n\t\t\t\tUPDATE " . $t_prefix . "tab_panels SET title='settings', icon_cls='ico-administration' WHERE id='more-panel';\n\t\t\t";
         if (!$this->checkColumnExists($t_prefix . "templates", "can_instance_from_mail", $this->database_connection)) {
             $upgrade_script .= "\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "templates` ADD COLUMN `can_instance_from_mail` int(1) NOT NULL default '0';\r\n\t\t\t\t";
         }
         $upgrade_script .= "\n\t\t\t\tALTER TABLE `" . $t_prefix . "member_custom_property_values` ADD INDEX (`member_id`);\n\t\t\t";
     }
     if (version_compare($installed_version, '3.2.1-beta') < 0) {
         $upgrade_script .= "\n\t\t\t\tALTER TABLE `" . $t_prefix . "objects` ADD INDEX (`object_type_id`, `trashed_on`, `archived_on`);\n\t\t\t";
         $upgrade_script .= "\r\n\t\t\t\tINSERT INTO `" . $t_prefix . "contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`)\r\n\t\t\t\tVALUES ('general', 'notify_myself_too', 0, 'BoolConfigHandler', '0', '100', '')\r\n\t\t\t\tON DUPLICATE KEY UPDATE name=name;\r\n\t\t\t";
         $upgrade_script .= "\r\n\t\t\t\tDELETE FROM " . $t_prefix . "config_options\r\n\t\t\t\tWHERE name = 'notify_myself_too';\r\n\t\t\t";
     }
     if (version_compare($installed_version, '3.2.1.1') < 0) {
         if (!$this->checkColumnExists($t_prefix . "contacts", "picture_file_small", $this->database_connection)) {
             $upgrade_script .= "\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "contacts`\n\t\t\t\t\t ADD COLUMN `picture_file_small` VARCHAR(100) NOT NULL AFTER `picture_file`,\n\t\t\t\t\t ADD COLUMN `picture_file_medium` VARCHAR(100) NOT NULL AFTER `picture_file_small`;\n\t\t\t\t";
         }
     }
     if (version_compare($installed_version, '3.2.2-alpha') < 0) {
         // config option to specify which address fields are mandatory in case of adding an address
         $upgrade_script .= "\n\t\t\t\tINSERT INTO `" . $t_prefix . "config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\n\t\t\t\t ('general', 'mandatory_address_fields', '', 'AddressFieldsConfigHandler', 0, 0, NULL)\n\t\t\t\tON DUPLICATE KEY UPDATE name=name;\n\t\t\t";
     }
     if (version_compare($installed_version, '3.2.2-beta') < 0) {
         $upgrade_script .= "\r\n\t\t\t\tDELETE FROM " . $t_prefix . "role_object_type_permissions\r\n\t\t\t\tWHERE object_type_id IN (\r\n\t\t\t\t\tSELECT o.id\r\n\t\t\t\t\tFROM `" . $t_prefix . "object_types` o\r\n\t\t\t\t\tWHERE o.`name` IN ('comment','template')\r\n\t\t\t\t);\n\t\t\t\t\n\t\t\t\tDELETE FROM " . $t_prefix . "max_role_object_type_permissions \n\t\t\t\tWHERE object_type_id IN (\n\t\t\t\t\t SELECT o.id\n\t\t\t\t\t FROM `" . $t_prefix . "object_types` o \n\t\t\t\t\t WHERE o.`name` IN ('comment','template')\t\t\t\t\n\t\t\t\t);\n\t\t\t\t \n\t\t\t\t \n\t\t\t\tDELETE FROM " . $t_prefix . "contact_member_permissions \n\t\t\t\tWHERE object_type_id IN (\n\t\t\t\t\t SELECT o.id\n\t\t\t\t\t FROM `" . $t_prefix . "object_types` o \n\t\t\t\t\t WHERE o.`name` IN ('comment','template')\t\t\t\t\n\t\t\t\t);\n\t\t\t";
     }
     if (version_compare($installed_version, '3.2.3-beta') < 0) {
         $upgrade_script .= "\n\t\t\tINSERT INTO `" . $t_prefix . "contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES \n\t\t\t\t('task panel', 'tasksPreviousPendingTasks', '1', 'BoolConfigHandler', 1, 0, ''),\n\t\t\t\t('task panel', 'can notify subscribers', '1', 'BoolConfigHandler', 0, 0, 'Notification checkbox default value')\n\t\t\t\t\tON DUPLICATE KEY UPDATE id=id;\n\t\t\t";
     }
     // Execute all queries
     if (!$this->executeMultipleQueries($upgrade_script, $total_queries, $executed_queries, $this->database_connection)) {
         $this->printMessage('Failed to execute DB schema transformations. MySQL said: ' . mysql_error(), true);
         return false;
     }
     $this->printMessage("Database schema transformations executed (total queries: {$total_queries})");
     $this->printMessage('Feng Office has been upgraded. You are now running Feng Office ' . $this->getVersionTo() . ' Enjoy!');
     tpl_assign('additional_steps', $additional_upgrade_steps);
 }
Beispiel #17
0
<?php
@set_time_limit(0);
define('ROOT', dirname(__FILE__) . '/../..');
define('PRODUCT_NAME', 'Feng Office');
define('PRODUCT_URL', 'http://www.fengoffice.com');


require_once dirname(__FILE__) . '/include.php';


$upgrader = new ScriptUpgrader(new Output_Html(), lang('upgrade fengoffice'), lang('upgrade your fengoffice installation'));
$form_data = array_var($_POST, 'form_data');
$upgrade_to = array_var($_GET, 'upgrade_to');
if (!is_array($form_data) && isset($upgrade_to)) {
	$form_data = array(
		'upgrade_from' => installed_version(),
		'upgrade_to' => $upgrade_to
	);
}

tpl_assign('upgrader', $upgrader);
tpl_assign('form_data', $form_data);
if(is_array($form_data)) {
	ob_start();
	$upgrader->upgrade(trim(array_var($form_data, 'upgrade_from')), trim(array_var($form_data, 'upgrade_to')));
	$status_messages = explode("\n", trim(ob_get_clean()));

	tpl_assign('status_messages', $status_messages);
} // if

tpl_display(get_template_path('layout'));
 /**
  * Execute the script
  *
  * @param void
  * @return boolean
  */
 function execute()
 {
     // ---------------------------------------------------
     //  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);
     if (defined('DB_ENGINE')) {
         tpl_assign('engine', DB_ENGINE);
     } else {
         tpl_assign('engine', 'InnoDB');
     }
     // ---------------------------------------------------
     //  Execute migration
     // ---------------------------------------------------
     // RUN QUERIES
     $total_queries = 0;
     $executed_queries = 0;
     $installed_version = installed_version();
     if (version_compare($installed_version, $this->getVersionFrom()) <= 0) {
         // upgrading from a version lower than this script's 'from' version
         $upgrade_script = tpl_fetch(get_template_path('db_migration/1_6_chivito'));
     } else {
         // upgrading from a pre-release of this version (beta, rc, etc)
         $upgrade_script = "";
         if (version_compare($installed_version, "1.6-beta2") < 0) {
             $upgrade_script .= "\r\n\t\t\t\t\tINSERT INTO `" . TABLE_PREFIX . "user_ws_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\r\n\t\t\t\t\t\t('general', 'search_engine', 'match', 'SearchEngineConfigHandler', 0, 700, ''),\r\n\t\t\t\t\t \t('mails panel', 'mails account filter', '', 'StringConfigHandler', '1', '0', NULL),\r\n\t\t\t\t\t\t('mails panel', 'mails classification filter', 'all', 'StringConfigHandler', '1', '0', NULL),\r\n\t\t\t\t\t\t('mails panel', 'mails read filter', 'all', 'StringConfigHandler', '1', '0', NULL),\r\n\t\t \t\t\t\t('dashboard', 'show_two_weeks_calendar', '1', 'BoolConfigHandler', '0', '0', NULL)\r\n\t\t \t\t\tON DUPLICATE KEY UPDATE id=id;\r\n\t\t \t\t\tUPDATE `" . TABLE_PREFIX . "user_ws_config_options` SET `category_name` = 'general' WHERE `name` = 'work_day_start_time';\r\n\t\t \t\t\tALTER TABLE `" . TABLE_PREFIX . "mail_contents` ADD INDEX `in_reply_to_id` (`in_reply_to_id`);\r\n\t\t\t\t";
         }
         if (version_compare($installed_version, "1.6-beta3") < 0) {
             $upgrade_script .= "\r\n\t\t \t\t\tALTER TABLE `" . TABLE_PREFIX . "mail_contents`\r\n\t\t \t\t\t  ADD COLUMN `received_date` datetime NOT NULL default '0000-00-00 00:00:00',\r\n\t\t \t\t\t  ADD INDEX `received_date` (`received_date`);\r\n\t\t \t\t\tUPDATE `" . TABLE_PREFIX . "mail_contents` SET `received_date` = `sent_date`;\r\n\t\t \t\t\tUPDATE `" . TABLE_PREFIX . "user_ws_config_options` SET `default_value` = '1' WHERE `name` = 'autodetect_time_zone';\r\n\t\t\t\t";
         }
         if (version_compare($installed_version, "1.6-rc") < 0) {
             $upgrade_script .= "\r\n\t\t\t\t\tINSERT INTO `" . TABLE_PREFIX . "cron_events` (`name`, `recursive`, `delay`, `is_system`, `enabled`, `date`) VALUES\r\n\t\t\t\t\t\t('clear_tmp_folder', '1', '1440', '1', '1', '0000-00-00 00:00:00')\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE id=id;\r\n\t\t\t\t\tALTER TABLE `" . TABLE_PREFIX . "mail_contents`\r\n\t\t\t\t\t\tMODIFY COLUMN `message_id` varchar(255) {$default_collation} NOT NULL COMMENT 'Message-Id header',\r\n\t\t\t\t\t\tMODIFY COLUMN `in_reply_to_id` varchar(255) {$default_collation} NOT NULL COMMENT 'Message-Id header of the previous email in the conversation',\r\n\t\t\t\t\t\tMODIFY COLUMN `uid` varchar(255) {$default_collation} NOT NULL default '';\r\n\t\t\t\t\tINSERT INTO `" . TABLE_PREFIX . "user_ws_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\r\n\t\t\t\t\t\t('mails panel', 'hide_quoted_text_in_emails', '1', 'BoolConfigHandler', 0, 110, NULL)\r\n\t\t \t\t\tON DUPLICATE KEY UPDATE id=id;\r\n\t\t\t\t";
         }
         if (version_compare($installed_version, "1.6") < 0) {
             $upgrade_script .= "\r\n\t\t \t\t\tALTER TABLE `" . TABLE_PREFIX . "mail_contents`\r\n\t\t \t\t\t  ADD INDEX `state` (`state`);\r\n\t\t\t\t";
         }
         if (version_compare($installed_version, "1.6.1") < 0) {
             $upgrade_script .= "\r\n\t\t\t\t\tINSERT INTO `" . TABLE_PREFIX . "config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\r\n\t\t\t\t\t  ('general', 'detect_mime_type_from_extension', '0', 'BoolConfigHandler', '0', '0', NULL)\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE id=id;\r\n\t\t\t\t\tUPDATE `" . TABLE_PREFIX . "user_ws_config_options` SET `config_handler_class` = 'RememberGUIConfigHandler' WHERE `name` = 'rememberGUIState';\r\n\t\t\t\t";
         }
         if (version_compare($installed_version, "1.6.2") < 0) {
             $upgrade_script .= "\r\n\t\t\t\t\tINSERT INTO `" . TABLE_PREFIX . "user_ws_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES\r\n\t\t\t\t\t  ('task panel', 'task_display_limit', '500', 'IntegerConfigHandler', '0', '200', NULL)\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE id=id;\r\n\t\t\t\t";
         }
     }
     // rename gelsheet tables before upgrading if name is wrong and if engine is case sensitive
     if ($this->checkTableExists(TABLE_PREFIX . 'gs_fontStyles', $this->database_connection) && !$this->checkTableExists(TABLE_PREFIX . 'gs_fontstyles', $this->database_connection)) {
         $upgrade_script = "\r\n\t\t\t\tRENAME TABLE `" . TABLE_PREFIX . "gs_fontStyles` TO `" . TABLE_PREFIX . "gs_fontstyles`;\r\n\t\t\t" . $upgrade_script;
     }
     if ($this->checkTableExists(TABLE_PREFIX . 'gs_mergedCells', $this->database_connection) && !$this->checkTableExists(TABLE_PREFIX . 'gs_mergedcells', $this->database_connection)) {
         $upgrade_script = "\r\n\t\t\t\tRENAME TABLE `" . TABLE_PREFIX . "gs_mergedCells` TO `" . TABLE_PREFIX . "gs_mergedcells`;\r\n\t\t\t" . $upgrade_script;
     }
     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
     // UPGRADE PUBLIC FILES (mark as public)
     if (version_compare($installed_version, $this->getVersionFrom()) <= 0) {
         // load FileRepository classes
         include_once ROOT . "/environment/library/database/adapters/AbstractDBAdapter.class.php";
         include_once ROOT . "/environment/library/database/DB.class.php";
         include_once ROOT . "/environment/library/database/DBResult.class.php";
         include_once ROOT . "/environment/classes/Inflector.class.php";
         include_once ROOT . "/library/filerepository/FileRepository.class.php";
         include_once ROOT . "/library/filerepository/errors/FileNotInRepositoryError.class.php";
         include_once ROOT . "/library/filerepository/errors/FileRepositoryAddError.class.php";
         include_once ROOT . "/library/filerepository/errors/FileRepositoryDeleteError.class.php";
         include_once ROOT . "/library/filerepository/backend/FileRepository_Backend.class.php";
         DB::connect(DB_ADAPTER, array('host' => DB_HOST, 'user' => DB_USER, 'pass' => DB_PASS, 'name' => DB_NAME, 'persist' => DB_PERSIST));
         // connect
         if (defined('DB_CHARSET') && trim(DB_CHARSET)) {
             DB::execute("SET NAMES ?", DB_CHARSET);
         }
         // if
         $res = mysql_query("SELECT `value` FROM `" . TABLE_PREFIX . "config_options` WHERE `name` = 'file_storage_adapter'");
         $row = mysql_fetch_assoc($res);
         $adapter = $row['value'];
         if ($adapter == 'mysql') {
             include_once ROOT . "/library/filerepository/backend/FileRepository_Backend_DB.class.php";
             FileRepository::setBackend(new FileRepository_Backend_DB(TABLE_PREFIX));
         } else {
             include_once ROOT . "/library/filerepository/backend/FileRepository_Backend_FileSystem.class.php";
             FileRepository::setBackend(new FileRepository_Backend_FileSystem(ROOT . "/upload", TABLE_PREFIX));
         }
         $res = mysql_query("SELECT `id`, `avatar_file` FROM `" . TABLE_PREFIX . "users` WHERE `avatar_file` <> ''", $this->database_connection);
         $count = 0;
         while ($row = mysql_fetch_assoc($res)) {
             $fid = $row['avatar_file'];
             FileRepository::setFileAttribute($fid, 'public', true);
             $count++;
         }
         $res = mysql_query("SELECT `id`, `picture_file` FROM `" . TABLE_PREFIX . "contacts` WHERE `picture_file` <> ''", $this->database_connection);
         while ($row = mysql_fetch_assoc($res)) {
             $fid = $row['picture_file'];
             FileRepository::setFileAttribute($fid, 'public', true);
             $count++;
         }
         $res = mysql_query("SELECT `id`, `logo_file` FROM `" . TABLE_PREFIX . "companies` WHERE `logo_file` <> ''", $this->database_connection);
         while ($row = mysql_fetch_assoc($res)) {
             $fid = $row['logo_file'];
             FileRepository::setFileAttribute($fid, 'public', true);
             $count++;
         }
         $this->printMessage("{$count} public files updated.");
     }
     $this->printMessage('Feng Office has been upgraded. You are now running Feng Office ' . $this->getVersionTo() . ' Enjoy!');
 }
 /**
  * Execute the script
  *
  * @param void
  * @return boolean
  */
 function execute()
 {
     if (!@mysql_ping($this->database_connection)) {
         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;
             }
             $this->setDatabaseConnection($dbc);
         } else {
             $this->printMessage('Failed to connect to database');
             return false;
         }
     }
     // ---------------------------------------------------
     //  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
     $installed_version = installed_version();
     $t_prefix = TABLE_PREFIX;
     $additional_upgrade_steps = array();
     // RUN QUERIES
     $total_queries = 0;
     $executed_queries = 0;
     $upgrade_script = "";
     $original_version_from = array_var(array_var($_POST, 'form_data'), 'upgrade_from', $installed_version);
     if (version_compare($installed_version, $this->getVersionFrom()) <= 0 && version_compare($original_version_from, '2.0.0.0-beta') > 0 && (!isset($_SESSION['from_feng1']) || !$_SESSION['from_feng1'])) {
         // upgrading from a version lower than this script's 'from' version
         $upgrade_script = tpl_fetch(get_template_path('db_migration/2_1_molleja'));
     } else {
         // UPDATE VERSION 2.1-beta
         if (version_compare($installed_version, '2.1-beta') < 0) {
             if (!$this->checkColumnExists($t_prefix . "members", 'archived_on', $this->database_connection)) {
                 $upgrade_script .= "ALTER TABLE `" . $t_prefix . "members`\r\n\t\t\t\t\t\t ADD COLUMN `archived_by_id` INTEGER UNSIGNED NOT NULL,\r\n\t\t\t\t\t\t ADD COLUMN `archived_on` DATETIME NOT NULL,\r\n\t\t\t\t\t\t ADD INDEX `archived_on`(`archived_on`);";
             }
             // INDEXED ODT AND FODT
             $upgrade_script .= "\r\n\t\t\t\t\tINSERT INTO `" . $t_prefix . "file_types` (`id` ,`extension` ,`icon` ,`is_searchable` ,`is_image`) VALUES\r\n\t\t\t\t\t ('34', 'odt', 'doc.png', '1', '0'), ('35', 'fodt', 'doc.png', '1', '0')\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE id=id;";
         }
         // UPDATE VERSION 2.1-rc
         if (version_compare($installed_version, '2.1-rc') < 0) {
             //TYPES IN PERMISSION GROUPS
             if (!$this->checkColumnExists($t_prefix . "permission_groups", 'type', $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\t\tALTER TABLE  `" . $t_prefix . "permission_groups` ADD `type` ENUM(  'roles',  'permission_groups',  'user_groups' ) NOT NULL;";
             }
             $upgrade_script .= "\r\n\t\t\t\t\tUPDATE `" . $t_prefix . "permission_groups` SET `type` = 'roles' WHERE `id` <= 13;\r\n\t\t\t\t\tUPDATE `" . $t_prefix . "permission_groups` SET `type` = 'permission_groups' WHERE `contact_id` > 0;\r\n\t\t\t\t\tUPDATE `" . $t_prefix . "permission_groups` SET `type` = 'user_groups' WHERE `contact_id` = 0 AND `id` > 13;";
         }
         //UPDATE VERSION 2.1
         if (version_compare($installed_version, '2.1') < 0) {
             // FILE EXTENSION PREVENTION UPLOADING
             if (!$this->checkColumnExists($t_prefix . "file_types", 'is_allow', $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\t\tALTER TABLE `" . $t_prefix . "file_types` ADD COLUMN `is_allow` TINYINT(1) NOT NULL DEFAULT '1';";
             }
             //CLASIFFY EVENTS
             if (!$this->checkColumnExists($t_prefix . "external_calendar_users", 'related_to', $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\t\tALTER TABLE `" . $t_prefix . "external_calendar_users` ADD `related_to` VARCHAR( 255 ) NOT NULL;";
             }
             //PERFORMANCE SYNC EVENTS
             if (!$this->checkColumnExists($t_prefix . "project_events", 'update_sync', $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\t\tALTER TABLE `" . $t_prefix . "project_events` ADD `update_sync` DATETIME NOT NULL AFTER `special_id`;";
             }
         }
     }
     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;
     }
     $this->printMessage('Feng Office has been upgraded. You are now running Feng Office ' . $this->getVersionTo() . ' Enjoy!');
     tpl_assign('additional_steps', $additional_upgrade_steps);
 }
 /**
  * Execute the script
  *
  * @param void
  * @return boolean
  */
 function execute()
 {
     // ---------------------------------------------------
     //  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);
     if (defined('DB_ENGINE')) {
         tpl_assign('engine', DB_ENGINE);
     } else {
         tpl_assign('engine', 'InnoDB');
     }
     // ---------------------------------------------------
     //  Execute migration
     // ---------------------------------------------------
     $total_queries = 0;
     $executed_queries = 0;
     $installed_version = installed_version();
     if (version_compare($installed_version, "1.2.1") <= 0) {
         $upgrade_script = tpl_fetch(get_template_path('db_migration/1_3_matambrito'));
     } else {
         // change from es_uy to es_la
         $upgrade_script = "UPDATE `" . TABLE_PREFIX . "user_ws_config_options` SET `default_value` = 'es_la' WHERE `name` = 'localization' AND `default_value` = 'es_uy';\n\t\t\tUPDATE `" . TABLE_PREFIX . "user_ws_config_option_values` `v`, `" . TABLE_PREFIX . "user_ws_config_options` `o` SET `v`.`value` = 'es_la' WHERE `o`.`name` = 'localization' AND `o`.`id` = `v`.`option_id` AND `v`.`value` = 'es_uy';\n\t\t\tALTER TABLE `" . TABLE_PREFIX . "users` MODIFY COLUMN `default_billing_id` INTEGER(10) UNSIGNED DEFAULT 0;\n\t\t\tUPDATE `" . TABLE_PREFIX . "user_ws_config_options` SET\n\t\t\t\t`config_handler_class` = 'BoolConfigHandler',\n\t\t\t\t`dev_comment` = 'Notification checkbox default value'\n\t\t\t\tWHERE `name` = 'can notify from quick add';\n\t\t\t";
     }
     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
     @unlink('templates/db_migration/onion.php');
     @unlink('templates/db_migration/dulceDeLeche.php');
     @unlink('templates/db_migration/tortaFrita.php');
     @unlink('templates/db_migration/churro.php');
     @unlink('templates/db_migration/empanada.php');
     @unlink('templates/db_migration/milanga.php');
     @unlink('templates/db_migration/bondiola.php');
     @unlink('templates/db_migration/chinchulin.php');
     @unlink('templates/db_migration/matambrito.php');
     @unlink('scripts/OnionUpgradeScript.class.php');
     @unlink('scripts/PapayaUpgradeScript.class.php');
     @unlink(INSTALLATION_PATH . '/language/es_uy.php');
     @unlink_dir(INSTALLATION_PATH . '/language/es_uy');
     $cookiepath = "/";
     $configfile = @file_get_contents(INSTALLATION_PATH . '/config/config.php');
     if ($configfile) {
         $configfile = str_replace("es_uy", "es_la", $configfile);
         $configfile = preg_replace("/[^\\(]*COOKIE_PATH[^,]*,[^\\)]*/", "'COOKIE_PATH', '/'", $configfile);
         @file_put_contents(INSTALLATION_PATH . '/config/config.php', $configfile);
     }
     $this->printMessage('Feng Office has been upgraded. You are now running Feng Office ' . $this->getVersionTo() . ' Enjoy!');
 }
	/**
	 * Execute the script
	 *
	 * @param void
	 * @return boolean
	 */
	function execute() {
		if (!@mysql_ping($this->database_connection)) {
			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;
				}
				$this->setDatabaseConnection($dbc);
			} else {
				$this->printMessage('Failed to connect to database');
				return false;
			}
		}
		
		// ---------------------------------------------------
		//  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

		$installed_version = installed_version();
		$t_prefix = TABLE_PREFIX;
		$additional_upgrade_steps = array();
		
		// RUN QUERIES
		$total_queries = 0;
		$executed_queries = 0;

		$upgrade_script = "";

		$original_version_from = array_var(array_var($_POST, 'form_data'), 'upgrade_from', $installed_version);
		if (version_compare($installed_version, $this->getVersionFrom()) <= 0 && version_compare($original_version_from, '2.0.0.0-beta') > 0
			 && (!isset($_SESSION['from_feng1']) || !$_SESSION['from_feng1'])) {
			// upgrading from a version lower than this script's 'from' version
			$upgrade_script = tpl_fetch(get_template_path('db_migration/2_3_chorizo'));
		} else {
			
			if (version_compare($installed_version, '2.3-beta') < 0) {
				$upgrade_script .= "
					INSERT INTO `".$t_prefix."contact_config_options` (`category_name`, `name`, `default_value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`)
						VALUES 
						('task panel', 'reminders_tasks', 'reminder_email,1,1440', 'StringConfigHandler', '0', '23', NULL),
						('task panel', 'add_task_autoreminder', '0', 'BoolConfigHandler', '0', '21', NULL),
						('task panel', 'add_self_task_autoreminder', '1', 'BoolConfigHandler', '0', '22', NULL),
						('task panel', 'add_task_default_reminder', '1', 'BoolConfigHandler', '0', '20', NULL),
						('calendar panel', 'add_event_autoreminder', '1', 'BoolConfigHandler', '0', '0', NULL),
						('calendar panel', 'autoassign_events', '0', 'BoolConfigHandler', '0', '0', NULL),
						('calendar panel', 'event_send_invitations', '1', 'BoolConfigHandler', '0', '0', NULL),
						('calendar panel', 'event_subscribe_invited', '1', 'BoolConfigHandler', '0', '0', NULL),
						('mails panel', 'mails_per_page', '50', 'IntegerConfigHandler', '0', '0', NULL),
						('general', 'access_member_after_add', '1', 'BoolConfigHandler', '0', '1300', NULL),
						('general', 'access_member_after_add_remember', '0', 'BoolConfigHandler', '0', '1301', NULL),
						('general', 'sendEmailNotification', '1', 'BoolConfigHandler', '1', '0', 'Send email notification to new user'),
 						('general', 'viewContactsChecked', '1', 'BoolConfigHandler', '1', '0', 'in people panel is view contacts checked'),
 						('general', 'viewUsersChecked', '0', 'BoolConfigHandler', '0', '0', 'in people panel is view users checked'),
 						('general', 'viewCompaniesChecked', '1', 'BoolConfigHandler', '1', '0', 'in people panel is view companies checked'),
						('general', 'contacts_per_page', '50', 'IntegerConfigHandler', '0', '1200', NULL)
					ON DUPLICATE KEY UPDATE name=name;
					INSERT INTO `".$t_prefix."config_options` (`category_name`,`name`,`value`,`config_handler_class`,`is_system`) VALUES
						('general', 'can_assign_tasks_to_companies', '1', 'BoolConfigHandler', '0'),
						('general', 'use_object_properties', '0', 'BoolConfigHandler', '0')
					ON DUPLICATE KEY UPDATE name=name;
					UPDATE `".$t_prefix."config_options` SET `value` = if ((SELECT count(*) FROM ".$t_prefix."object_properties)>0, 1, 0) WHERE `name`='use_object_properties';
					UPDATE `".$t_prefix."config_options` SET `value` = '1' WHERE `name`='can_assign_tasks_to_companies';
				";
			}
		}
		
		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;
		}
		
		$this->printMessage('Feng Office has been upgraded. You are now running Feng Office '.$this->getVersionTo().' Enjoy!');

		tpl_assign('additional_steps', $additional_upgrade_steps);

	} // execute
 /**
  * Execute the script
  *
  * @param void
  * @return boolean
  */
 function execute()
 {
     if (!@mysql_ping($this->database_connection)) {
         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;
             }
             $this->setDatabaseConnection($dbc);
         } else {
             $this->printMessage('Failed to connect to database');
             return false;
         }
     }
     // ---------------------------------------------------
     //  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
     $installed_version = installed_version();
     $t_prefix = TABLE_PREFIX;
     $additional_upgrade_steps = array();
     // RUN QUERIES
     $total_queries = 0;
     $executed_queries = 0;
     $upgrade_script = "";
     $v_from = array_var($_POST, 'form_data');
     $original_version_from = array_var($v_from, 'upgrade_from', $installed_version);
     if (false && version_compare($installed_version, $this->getVersionFrom()) <= 0 && version_compare($original_version_from, '2.0.0.0-beta') > 0 && (!isset($_SESSION['from_feng1']) || !$_SESSION['from_feng1'])) {
         // upgrading from a version lower than this script's 'from' version
         $upgrade_script = tpl_fetch(get_template_path('db_migration/2_5_vacio'));
     } else {
         if (version_compare($installed_version, '2.5.1-beta') < 0) {
             if (!$this->checkColumnExists($t_prefix . "widgets", "icon_cls", $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "widgets` ADD COLUMN `icon_cls` VARCHAR(50) NOT NULL DEFAULT '';\r\n\t\t\t\t\t";
             }
             $upgrade_script .= "\r\n\t\t\t\tINSERT INTO " . $t_prefix . "widgets (name,title,plugin_id,path,default_options,default_section,default_order,icon_cls) values\r\n\t\t\t\t ('comments','comments',0,'','','left',5, 'ico-comment')\r\n\t\t\t\ton duplicate key update name=name;\r\n\t\t\t\t\r\n\t\t\t\tDELETE FROM " . $t_prefix . "widgets WHERE name IN ('completed_tasks', 'crpm_people');\r\n\t\t\t\t\r\n\t\t\t\tUPDATE " . $t_prefix . "widgets SET icon_cls='ico-properties' WHERE name='activity_feed';\r\n\t\t\t\tUPDATE " . $t_prefix . "widgets SET icon_cls='ico-event' WHERE name='calendar';\r\n\t\t\t\tUPDATE " . $t_prefix . "widgets SET icon_cls='ico-task' WHERE name='completed_tasks_list';\r\n\t\t\t\tUPDATE " . $t_prefix . "widgets SET icon_cls='ico-customer' WHERE name='customers';\r\n\t\t\t\tUPDATE " . $t_prefix . "widgets SET icon_cls='ico-file' WHERE name='documents';\r\n\t\t\t\tUPDATE " . $t_prefix . "widgets SET icon_cls='ico-email' WHERE name='emails';\r\n\t\t\t\tUPDATE " . $t_prefix . "widgets SET icon_cls='ico-task' WHERE name='estimated_worked_time';\r\n\t\t\t\tUPDATE " . $t_prefix . "widgets SET icon_cls='ico-folder' WHERE name='folders';\r\n\t\t\t\tUPDATE " . $t_prefix . "widgets SET icon_cls='ico-message' WHERE name='messages';\r\n\t\t\t\tUPDATE " . $t_prefix . "widgets SET icon_cls='ico-task' WHERE name='overdue_upcoming';\r\n\t\t\t\tUPDATE " . $t_prefix . "widgets SET icon_cls='ico-contact' WHERE name='people';\r\n\t\t\t\tUPDATE " . $t_prefix . "widgets SET icon_cls='ico-project' WHERE name='projects';\r\n\t\t\t\tUPDATE " . $t_prefix . "widgets SET icon_cls='ico-properties' WHERE name='statics';\r\n\t\t\t\tUPDATE " . $t_prefix . "widgets SET icon_cls='ico-properties' WHERE name='summary';\r\n\t\t\t\tUPDATE " . $t_prefix . "widgets SET icon_cls='ico-workspace' WHERE name='workspaces';\r\n\t\t\t\tUPDATE " . $t_prefix . "widgets SET icon_cls='ico-workspace' WHERE name='ws_description';\r\n\t\t\t\tUPDATE " . $t_prefix . "widgets SET icon_cls='ico-comment' WHERE name='comments';\r\n\t\t\t\t";
             if (!$this->checkTableExists($t_prefix . "contact_widget_options", $this->database_connection)) {
                 $upgrade_script .= "\r\n\t\t\t\t\t\tCREATE TABLE `" . $t_prefix . "contact_widget_options` (\r\n\t\t\t\t\t\t  `widget_name` varchar(40) COLLATE utf8_unicode_ci NOT NULL,\r\n\t\t\t\t\t\t  `contact_id` int(11) NOT NULL,\r\n\t\t\t\t\t\t  `member_type_id` int(11) NOT NULL DEFAULT 0,\r\n\t\t\t\t\t\t  `option` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\r\n\t\t\t\t\t\t  `value` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\r\n\t\t\t\t\t\t  `config_handler_class` varchar(50) COLLATE utf8_unicode_ci NOT NULL,\r\n\t\t\t\t\t\t  `is_system` tinyint(1) unsigned default 0,\r\n\t\t\t\t\t\t  PRIMARY KEY (`widget_name`,`contact_id`,`member_type_id`,`option`) USING BTREE\r\n\t\t\t\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t\t\t\t";
             }
             $upgrade_script .= "\r\n\t\t\t\tINSERT INTO `" . $t_prefix . "contact_widget_options` (widget_name,contact_id,member_type_id,`option`,`value`,config_handler_class,is_system) VALUES\r\n\t\t\t\t('overdue_upcoming',0,0,'assigned_to_user',0,'UserCompanyConfigHandler',0),\r\n\t\t\t\t('calendar',0,0,'filter_by_myself',0,'BooleanConfigHandler',0)\r\n\t\t\t\tON DUPLICATE KEY UPDATE widget_name=widget_name;\r\n\t\t\t\t";
         }
         if (version_compare($installed_version, '2.5.1.1') < 0) {
             $upgrade_script .= "\r\n\t\t\t\t\tupdate " . $t_prefix . "system_permissions set can_manage_tasks=1 where permission_group_id in (select id from " . $t_prefix . "permission_groups where name in ('Super Administrator','Administrator','Manager','Executive'));\r\n\t\t\t\t";
         }
         if (version_compare($installed_version, '2.5.1.4') < 0) {
             $upgrade_script .= "\r\n\t\t\t\t\tupdate `" . $t_prefix . "contact_config_options` set `default_value`=1 where `name`='viewUsersChecked';\r\n\t\t\t\t";
         }
         if (!$this->executeMultipleQueries($upgrade_script, $total_queries, $executed_queries, $this->database_connection)) {
             $this->printMessage('Failed to execute DB schema transformations. MySQL said: ' . mysql_error(), true);
             return false;
         }
         $this->printMessage("Database schema transformations executed (total queries: {$total_queries})");
     }
     if (version_compare($installed_version, '2.5.0.4') < 0) {
         if (!$this->checkColumnExists("queued_emails", "attachments", $this->database_connection)) {
             $sqls = "\r\n\t\t\t\t\tALTER TABLE `" . $t_prefix . "queued_emails` ADD COLUMN `attachments` TEXT;\r\n\t\t\t\t";
             $this->executeMultipleQueries($sqls, $t_queries, $e_queries, $this->database_connection);
         }
     }
     $this->printMessage('Feng Office has been upgraded. You are now running Feng Office ' . $this->getVersionTo() . ' Enjoy!');
     tpl_assign('additional_steps', $additional_upgrade_steps);
 }