Ejemplo n.º 1
0
 function Admin()
 {
     global $IN, $LANG, $SESS, $LOG, $DSP;
     // This flag determines if a user can edit categories from the publish page.
     $category_exception = ($IN->GBL('M') == 'blog_admin' and in_array($IN->GBL('P'), array('category_editor', 'edit_category', 'update_category', 'del_category_conf', 'del_category', 'cat_order')) and $IN->GBL('Z') == 1) ? TRUE : FALSE;
     if ($category_exception == FALSE and !$DSP->allowed_group('can_access_admin') and $IN->GBL('P', 'GET') != 'save_ping_servers') {
         return $DSP->no_access_message();
     }
     switch ($IN->GBL('M')) {
         case 'config_mgr':
             if (!$DSP->allowed_group('can_admin_preferences')) {
                 return $DSP->no_access_message();
             }
             switch ($IN->GBL('P')) {
                 case 'update_cfg':
                     $this->update_config_prefs();
                     break;
                 case 'member_cfg':
                     $this->member_config_manager();
                     break;
                 default:
                     $this->config_manager();
                     break;
             }
             break;
         case 'members':
             // Instantiate the member administration class
             require PATH_CP . 'cp.members' . EXT;
             $MBR = new Members();
             switch ($IN->GBL('P')) {
                 case 'view_members':
                     $MBR->view_all_members();
                     break;
                 case 'mbr_conf':
                     $MBR->member_confirm();
                     break;
                 case 'mbr_del_conf':
                     $MBR->member_delete_confirm();
                     break;
                 case 'mbr_delete':
                     $MBR->member_delete();
                     break;
                 case 'resend_act_email':
                     $MBR->resend_activation_emails();
                     break;
                 case 'member_reg_form':
                     $MBR->new_member_profile_form();
                     break;
                 case 'register_member':
                     $MBR->create_member_profile();
                     break;
                 case 'mbr_group_manager':
                     $MBR->member_group_manager();
                     break;
                 case 'edit_mbr_group':
                     $MBR->edit_member_group_form();
                     break;
                 case 'update_mbr_group':
                     $MBR->update_member_group();
                     break;
                 case 'mbr_group_del_conf':
                     $MBR->delete_member_group_conf();
                     break;
                 case 'delete_mbr_group':
                     $MBR->delete_member_group();
                     break;
                 case 'member_banning':
                     $MBR->member_banning_forms();
                     break;
                 case 'save_ban_data':
                     $MBR->update_banning_data();
                     break;
                 case 'profile_fields':
                     $MBR->custom_profile_fields();
                     break;
                 case 'edit_field':
                     $MBR->edit_profile_field_form();
                     break;
                 case 'del_field_conf':
                     $MBR->delete_profile_field_conf();
                     break;
                 case 'delete_field':
                     $MBR->delete_profile_field();
                     break;
                 case 'edit_field_order':
                     $MBR->edit_field_order_form();
                     break;
                 case 'update_field_order':
                     $MBR->update_field_order();
                     break;
                 case 'update_profile_fields':
                     $MBR->update_profile_fields();
                     break;
                 case 'member_search':
                     $MBR->member_search_form();
                     break;
                 case 'do_member_search':
                     $MBR->do_member_search();
                     break;
                 case 'ip_search':
                     $MBR->ip_search_form();
                     break;
                 case 'do_ip_search':
                     $MBR->do_ip_search();
                     break;
                 case 'member_validation':
                     $MBR->member_validation();
                     break;
                 case 'validate_members':
                     $MBR->validate_members();
                     break;
                 case 'email_console_logs':
                     $MBR->email_console_logs();
                     break;
                 case 'view_email':
                     $MBR->view_email();
                     break;
                 case 'delete_email_console':
                     $MBR->delete_email_console_messages();
                     break;
                 case 'profile_templates':
                     $MBR->profile_templates();
                     break;
                 case 'list_templates':
                     $MBR->list_templates();
                     break;
                 case 'edit_template':
                     $MBR->edit_template();
                     break;
                 case 'save_template':
                     $MBR->save_template();
                     break;
                 case 'login_as_member':
                     $MBR->login_as_member();
                     break;
                 case 'do_login_as_member':
                     $MBR->do_login_as_member();
                     break;
                 default:
                     return FALSE;
                     break;
             }
             break;
         case 'sp_templ':
             // Instantiate the specialty templates class
             require PATH_CP . 'cp.specialty_tmp' . EXT;
             $SP = new Specialty_Templates();
             switch ($IN->GBL('P')) {
                 case 'mbr_notification_tmpl':
                     $SP->mbr_notification_tmpl();
                     break;
                 case 'edit_notification_tmpl':
                     $SP->edit_notification_tmpl();
                     break;
                 case 'update_notification_tmpl':
                     $SP->update_notification_tmpl();
                     break;
                 case 'offline_tmpl':
                     $SP->offline_template();
                     break;
                 case 'update_offline_template':
                     $SP->update_offline_template();
                     break;
                 case 'user_messages_tmpl':
                     $SP->user_messages_template();
                     break;
                 case 'update_user_messages_tmpl':
                     $SP->update_user_messages_template();
                     break;
             }
             break;
         case 'site_admin':
             if (!$DSP->allowed_group('can_admin_sites')) {
                 return $DSP->no_access_message();
             }
             // Instantiate the site administration class
             require PATH_CP . 'cp.sites' . EXT;
             $SA = new SitesAdmin();
             switch ($IN->GBL('P')) {
                 case 'sites_list':
                     $SA->sites_list();
                     break;
                 case 'new_site':
                     $SA->new_site_form();
                     break;
                 case 'edit_site':
                     $SA->edit_site_form();
                     break;
                 case 'update_site':
                     $SA->update_site();
                     break;
                 case 'delete_site':
                     $SA->delete_site();
                     break;
                 case 'delete_site_confirm':
                     $SA->delete_site_confirm();
                     break;
                 default:
                     $SA->sites_list();
                     break;
             }
             break;
         case 'blog_admin':
             if ($category_exception == FALSE and !$DSP->allowed_group('can_admin_weblogs') and $IN->GBL('P', 'GET') != 'save_ping_servers') {
                 return $DSP->no_access_message();
             }
             // Instantiate the publish administration class
             require PATH_CP . 'cp.publish_ad' . EXT;
             $PA = new PublishAdmin();
             switch ($IN->GBL('P')) {
                 case 'blog_list':
                     $PA->weblog_overview();
                     break;
                 case 'new_weblog':
                     $PA->new_weblog_form();
                     break;
                 case 'blog_prefs':
                     $PA->edit_blog_form();
                     break;
                 case 'group_prefs':
                     $PA->edit_group_form();
                     break;
                 case 'create_blog':
                     $PA->update_weblog_prefs();
                     break;
                 case 'update_preferences':
                     $PA->update_weblog_prefs();
                     break;
                 case 'delete_conf':
                     $PA->delete_weblog_conf();
                     break;
                 case 'delete':
                     $PA->delete_weblog();
                     break;
                 case 'categories':
                     $PA->category_overview();
                     break;
                 case 'cat_group_editor':
                     $PA->edit_category_group_form();
                     break;
                 case 'update_cat_group':
                     $PA->update_category_group();
                     break;
                 case 'cat_group_del_conf':
                     $PA->delete_category_group_conf();
                     break;
                 case 'delete_group':
                     $PA->delete_category_group();
                     break;
                 case 'category_editor':
                     $PA->category_manager();
                     break;
                 case 'update_category':
                     $PA->update_category();
                     break;
                 case 'edit_category':
                     $PA->edit_category_form();
                     break;
                 case 'cat_order':
                     $PA->change_category_order();
                     break;
                 case 'global_cat_order':
                     $PA->global_category_order();
                     break;
                 case 'del_category_conf':
                     $PA->delete_category_confirm();
                     break;
                 case 'del_category':
                     $PA->delete_category();
                     break;
                 case 'cat_field_group_edit':
                     $PA->category_field_group_manager();
                     break;
                 case 'del_cat_field_conf':
                     $PA->delete_category_field_confirm();
                     break;
                 case 'del_cat_field':
                     $PA->delete_category_field();
                     break;
                 case 'edit_cat_field':
                     $PA->edit_category_field_form();
                     break;
                 case 'edit_cat_field_order':
                     $PA->edit_category_field_order_form();
                     break;
                 case 'ud_cat_field_order':
                     $PA->update_category_field_order();
                     break;
                 case 'update_cat_fields':
                     $PA->update_category_fields();
                     break;
                 case 'statuses':
                     $PA->status_overview();
                     break;
                 case 'status_group_editor':
                     $PA->edit_status_group_form();
                     break;
                 case 'update_status_group':
                     $PA->update_status_group();
                     break;
                 case 'status_group_del_conf':
                     $PA->delete_status_group_conf();
                     break;
                 case 'delete_status_group':
                     $PA->delete_status_group();
                     break;
                 case 'status_editor':
                     $PA->status_manager();
                     break;
                 case 'update_status':
                     $PA->update_status();
                     break;
                 case 'edit_status':
                     $PA->edit_status_form();
                     break;
                 case 'del_status_conf':
                     $PA->delete_status_confirm();
                     break;
                 case 'del_status':
                     $PA->delete_status();
                     break;
                 case 'edit_status_order':
                     $PA->edit_status_order();
                     break;
                 case 'update_status_order':
                     $PA->update_status_order();
                     break;
                 case 'custom_fields':
                     $PA->field_overview();
                     break;
                 case 'update_field_group':
                     $PA->update_field_group();
                     break;
                 case 'del_field_group_conf':
                     $PA->delete_field_group_conf();
                     break;
                 case 'delete_field_group':
                     $PA->delete_field_group();
                     break;
                 case 'field_editor':
                     $PA->field_manager();
                     break;
                 case 'edit_field':
                     $PA->edit_field_form();
                     break;
                 case 'update_weblog_fields':
                     $PA->update_weblog_fields();
                     break;
                 case 'field_group_editor':
                     $PA->edit_field_group_form();
                     break;
                 case 'del_field_conf':
                     $PA->delete_field_conf();
                     break;
                 case 'delete_field':
                     $PA->delete_field();
                     break;
                 case 'edit_field_order':
                     $PA->edit_field_order_form();
                     break;
                 case 'update_field_order':
                     $PA->update_field_order();
                     break;
                 case 'edit_fmt_buttons':
                     $PA->edit_formatting_buttons();
                     break;
                 case 'update_fmt_buttons':
                     $PA->update_formatting_buttons();
                     break;
                 case 'html_buttons':
                     $PA->html_buttons();
                     break;
                 case 'save_html_buttons':
                     $PA->save_html_buttons();
                     break;
                 case 'ping_servers':
                     $PA->ping_servers();
                     break;
                 case 'save_ping_servers':
                     $PA->save_ping_servers();
                     break;
                 case 'upload_prefs':
                     $PA->file_upload_preferences();
                     break;
                 case 'edit_upload_pref':
                     $PA->edit_upload_preferences_form();
                     break;
                 case 'update_upload_prefs':
                     $PA->update_upload_preferences();
                     break;
                 case 'del_upload_pref_conf':
                     $PA->delete_upload_preferences_conf();
                     break;
                 case 'del_upload_pref':
                     $PA->delete_upload_preferences();
                     break;
                 default:
                     return FALSE;
                     break;
             }
             break;
         case 'utilities':
             if (!$DSP->allowed_group('can_admin_utilities')) {
                 return $DSP->no_access_message();
             }
             // We handle the pMachine import via a different class,
             // so we'll test for that separately
             if ($IN->GBL('P') == 'pm_import') {
                 require PATH_CP . 'cp.pm_import' . EXT;
                 $PMI = new PM_Import();
                 return;
             }
             if ($IN->GBL('P') == 'mt_import') {
                 require PATH_CP . 'cp.mt_import' . EXT;
                 $MT = new MT_Import();
                 return;
             }
             if ($IN->GBL('P') == 'member_import') {
                 require PATH_CP . 'cp.member_import' . EXT;
                 $MI = new Member_Import();
                 return;
             }
             require PATH_CP . 'cp.utilities' . EXT;
             switch ($IN->GBL('P')) {
                 case 'view_logs':
                     $LOG->view_logs();
                     break;
                 case 'clear_cplogs':
                     $LOG->clear_cp_logs();
                     break;
                 case 'view_search_log':
                     $LOG->view_search_log();
                     break;
                 case 'view_throttle_log':
                     $LOG->view_throttle_log();
                     break;
                 case 'blacklist_ips':
                     $LOG->blacklist_ips();
                     break;
                 case 'clear_search_log':
                     $LOG->clear_search_log();
                     break;
                 case 'clear_cache_form':
                     Utilities::clear_cache_form();
                     break;
                 case 'clear_caching':
                     Utilities::clear_caching();
                     break;
                 case 'run_query':
                     Utilities::sql_manager('run_query');
                     break;
                 case 'sql_query':
                     Utilities::sql_query_form();
                     break;
                     //case 'sql_backup'			: Utilities::sql_backup();
                     //	break;
                     //case 'do_sql_backup'		: Utilities::do_sql_backup();
                     //	break;
                 //case 'sql_backup'			: Utilities::sql_backup();
                 //	break;
                 //case 'do_sql_backup'		: Utilities::do_sql_backup();
                 //	break;
                 case 'view_database':
                     Utilities::view_database();
                     break;
                 case 'table_action':
                     Utilities::run_table_action();
                     break;
                 case 'sandr':
                     Utilities::search_and_replace_form();
                     break;
                 case 'recount_stats':
                     Utilities::recount_statistics();
                     break;
                 case 'recount_prefs':
                     Utilities::recount_preferences_form();
                     break;
                 case 'set_recount_prefs':
                     Utilities::set_recount_prefs();
                     break;
                 case 'do_recount':
                     Utilities::do_recount();
                     break;
                 case 'do_stats_recount':
                     Utilities::do_stats_recount();
                     break;
                 case 'prune':
                     Utilities::data_pruning();
                     break;
                 case 'member_pruning':
                     Utilities::member_pruning();
                     break;
                 case 'prune_member_conf':
                     Utilities::prune_member_confirm();
                     break;
                 case 'prune_members':
                     Utilities::prune_members();
                     break;
                 case 'entry_pruning':
                     Utilities::entry_pruning();
                     break;
                 case 'prune_entry_conf':
                     Utilities::prune_entry_confirm();
                     break;
                 case 'prune_entries':
                     Utilities::prune_entries();
                     break;
                 case 'comment_pruning':
                     Utilities::comment_pruning();
                     break;
                 case 'prune_comment_conf':
                     Utilities::prune_comment_confirmation();
                     break;
                 case 'prune_comments':
                     Utilities::prune_comments();
                     break;
                 case 'trackback_pruning':
                     Utilities::trackback_pruning();
                     break;
                 case 'prune_trackback_conf':
                     Utilities::prune_trackback_confirmation();
                     break;
                 case 'prune_trackbacks':
                     Utilities::prune_trackbacks();
                     break;
                     /* Someday, oh someday...
                     		 case 'pm_pruning'			: Utilities::pm_pruning();
                     			break;
                     		 case 'prune_pm_conf'		: Utilities::prune_pm_confirmation();
                     			break;
                     		 case 'prune_pms'			: Utilities::prune_pms();
                     			break;
                     		 */
                 /* Someday, oh someday...
                 		 case 'pm_pruning'			: Utilities::pm_pruning();
                 			break;
                 		 case 'prune_pm_conf'		: Utilities::prune_pm_confirmation();
                 			break;
                 		 case 'prune_pms'			: Utilities::prune_pms();
                 			break;
                 		 */
                 case 'topic_pruning':
                     Utilities::topic_pruning();
                     break;
                 case 'prune_topic_conf':
                     Utilities::prune_topic_confirmation();
                     break;
                 case 'prune_topics':
                     Utilities::prune_topics();
                     break;
                 case 'run_sandr':
                     Utilities::search_and_replace();
                     break;
                 case 'php_info':
                     Utilities::php_info();
                     break;
                 case 'sql_manager':
                     Utilities::sql_info();
                     break;
                 case 'sql_status':
                     Utilities::sql_manager('status');
                     break;
                 case 'sql_sysvars':
                     Utilities::sql_manager('sysvars');
                     break;
                 case 'sql_plist':
                     Utilities::sql_manager('plist');
                     break;
                 case 'plugin_manager':
                     Utilities::plugin_manager();
                     break;
                 case 'plugin_info':
                     Utilities::plugin_info();
                     break;
                 case 'plugin_remove_conf':
                     Utilities::plugin_remove_confirm();
                     break;
                 case 'plugin_remove':
                     Utilities::plugin_remove();
                     break;
                 case 'plugin_install':
                     Utilities::plugin_install('file');
                     break;
                 case 'import_utilities':
                     Utilities::import_utilities();
                     break;
                 case 'trans_menu':
                     Utilities::translate_select();
                     break;
                 case 'translate':
                     Utilities::translate();
                     break;
                 case 'save_translation':
                     Utilities::save_translation();
                     break;
                 case 'extensions_manager':
                     Utilities::extensions_manager();
                     break;
                 case 'toggle_extension_confirm':
                     Utilities::toggle_extension_confirm();
                     break;
                 case 'toggle_extension':
                     Utilities::toggle_extension();
                     break;
                 case 'extension_settings':
                     Utilities::extension_settings();
                     break;
                 case 'save_extension_settings':
                     Utilities::save_extension_settings();
                     break;
                 default:
                     return FALSE;
                     break;
             }
             break;
         default:
             $this->admin_home_page();
             break;
     }
 }
Ejemplo n.º 2
0
 /**
  * Module Installer
  *
  * @access	public
  * @return	bool
  */
 public function install()
 {
     // Already installed, let's not install again. That would be silly.
     if ($this->database_version() !== FALSE) {
         return FALSE;
     }
     // -------------------------------------
     //  Do any field groups already exist?
     // -------------------------------------
     $calendars_fields = array();
     $calendars_field_group = '';
     $events_fields = array();
     $events_field_group = '';
     $calendars_weblogs = array();
     $events_weblogs = array();
     // -------------------------------------
     //  calendars
     // -------------------------------------
     $sql = "SELECT\t\twf.field_id, wf.field_name, wf.group_id\n\t\t\t\tFROM\t\texp_field_groups fg\n\t\t\t\tLEFT JOIN\t{$this->sc->db->channel_fields} AS wf\n\t\t\t\tON\t\t\tfg.group_id = wf.group_id\n\t\t\t\tWHERE\t\tfg.group_name = '" . CALENDAR_CALENDARS_FIELD_GROUP . "'\n\t\t\t\tAND\t\t\tfg.site_id = '" . ee()->db->escape_str($this->data->get_site_id()) . "'";
     $query = ee()->db->query($sql);
     if ($query->num_rows() > 0) {
         foreach ($query->result_array() as $row) {
             if ($calendars_field_group == '') {
                 $calendars_field_group = $row['group_id'];
             }
             $calendars_fields[$row['field_name']] = $row['field_id'];
         }
     }
     // -------------------------------------
     //  events
     // -------------------------------------
     $sql = "SELECT \t\twf.field_id, wf.field_name, wf.group_id\n\t\t\t\tFROM \t\texp_field_groups AS fg\n\t\t\t\tLEFT JOIN \t{$this->sc->db->channel_fields} AS wf\n\t\t\t\tON \t\t\tfg.group_id = wf.group_id\n\t\t\t\tWHERE \t\tfg.group_name = '" . CALENDAR_EVENTS_FIELD_GROUP . "'\n\t\t\t\tAND \t\tfg.site_id = '" . ee()->db->escape_str($this->data->get_site_id()) . "'";
     $query = ee()->db->query($sql);
     if ($query->num_rows() > 0) {
         foreach ($query->result_array() as $row) {
             if ($events_field_group == '') {
                 $events_field_group = $row['group_id'];
             }
             $events_fields[$row['field_name']] = $row['field_id'];
         }
     }
     // -------------------------------------
     //  default names
     // -------------------------------------
     $sql = "SELECT \tw.*\n\t\t\t\tFROM \t{$this->sc->db->channels} AS w\n\t\t\t\tWHERE \t{$this->sc->db->channel_name} = '" . CALENDAR_CALENDARS_CHANNEL_NAME_DEFAULT . "'\n\t\t\t\tAND \tw.site_id = '" . ee()->db->escape_str($this->data->get_site_id()) . "'";
     $query = ee()->db->query($sql);
     if ($query->num_rows() > 0) {
         foreach ($query->result_array() as $row) {
             $calendars_weblogs[$row[$this->sc->db->channel_name]] = $row;
         }
     }
     // -------------------------------------
     //  default event names
     // -------------------------------------
     $sql = "SELECT \tw.*\n\t\t\t\tFROM \t{$this->sc->db->channels} AS w\n\t\t\t\tWHERE \t{$this->sc->db->channel_name} = '" . CALENDAR_EVENTS_CHANNEL_NAME_DEFAULT . "'\n\t\t\t\tAND \tw.site_id = '" . ee()->db->escape_str($this->data->get_site_id()) . "'";
     $query = ee()->db->query($sql);
     if ($query->num_rows() > 0) {
         foreach ($query->result_array() as $row) {
             $events_weblogs[$row[$this->sc->db->channel_name]] = $row;
         }
     }
     // --------------------------------------------
     //  Our Default Install
     // --------------------------------------------
     if ($this->default_module_install() == FALSE) {
         return FALSE;
     }
     $sql = array();
     // --------------------------------------------
     //  Module Install
     // --------------------------------------------
     $insert_data = array('module_name' => $this->class_name, 'module_version' => CALENDAR_VERSION, 'has_cp_backend' => 'y');
     if (APP_VER >= 2.0) {
         $data['has_publish_fields'] = 'n';
     }
     $sql[] = ee()->db->insert_string('exp_modules', $insert_data);
     foreach ($sql as $query) {
         ee()->db->query($query);
     }
     // -------------------------------------
     //  Create the calendars field group
     // -------------------------------------
     if (APP_VER < 2.0) {
         if (!class_exists('PublishAdmin')) {
             require_once PATH_CP . 'cp.publish_ad' . EXT;
         }
         $PA = new PublishAdmin();
     } else {
         if (!class_exists('Content_publish')) {
             ee()->load->library('Cp');
         }
         $PA =& ee()->cp;
         ee()->load->library('api');
         ee()->api->instantiate('channel_fields');
     }
     $old_POST = $_POST;
     if ($calendars_field_group == '') {
         $data = array('site_id' => $this->data->get_site_id(), 'group_name' => CALENDAR_CALENDARS_FIELD_GROUP);
         ee()->db->query(ee()->db->insert_string('exp_field_groups', $data));
         $calendars_field_group = ee()->db->insert_id();
     }
     // -------------------------------------
     // Create the calendars fields
     // -------------------------------------
     $fields = array();
     $order_count = 0;
     if (!isset($calendars_fields[CALENDAR_CALENDARS_FIELD_PREFIX . 'summary'])) {
         $fields[] = array('site_id' => $this->data->get_site_id(), 'group_id' => $calendars_field_group, 'field_name' => CALENDAR_CALENDARS_FIELD_PREFIX . 'summary', 'field_label' => lang('summary'), 'field_instructions' => '', 'field_type' => 'textarea', 'field_list_items' => '', 'field_pre_populate' => 'n', 'field_pre_blog_id' => '0', 'field_pre_field_id' => '0', 'field_related_to' => APP_VER < 2.0 ? 'blog' : 'channel', 'field_related_id' => '0', 'field_related_orderby' => 'date', 'field_related_sort' => 'desc', 'field_related_max' => '0', 'field_ta_rows' => '4', 'field_maxl' => '0', 'field_required' => 'n', 'field_text_direction' => 'ltr', 'field_search' => 'y', 'field_is_hidden' => 'n', 'field_fmt' => 'xhtml', 'field_show_fmt' => 'y', 'field_order' => ++$order_count);
     }
     if (!isset($calendars_fields[CALENDAR_CALENDARS_FIELD_PREFIX . 'tz_offset'])) {
         $fields[] = array('site_id' => $this->data->get_site_id(), 'group_id' => $calendars_field_group, 'field_name' => CALENDAR_CALENDARS_FIELD_PREFIX . 'tz_offset', 'field_label' => lang('timezone'), 'field_instructions' => '', 'field_type' => APP_VER < 2.0 ? 'text' : 'calendar', 'field_list_items' => '', 'field_pre_populate' => 'n', 'field_pre_blog_id' => '0', 'field_pre_field_id' => '0', 'field_related_to' => APP_VER < 2.0 ? 'blog' : 'channel', 'field_related_id' => '0', 'field_related_orderby' => 'date', 'field_related_sort' => 'desc', 'field_related_max' => '0', 'field_ta_rows' => '0', 'field_maxl' => '100', 'field_required' => 'n', 'field_text_direction' => 'ltr', 'field_search' => 'n', 'field_is_hidden' => 'n', 'field_fmt' => 'none', 'field_show_fmt' => 'n', 'field_order' => ++$order_count);
     }
     if (!isset($calendars_fields[CALENDAR_CALENDARS_FIELD_PREFIX . 'time_format'])) {
         $fields[] = array('site_id' => $this->data->get_site_id(), 'group_id' => $calendars_field_group, 'field_name' => CALENDAR_CALENDARS_FIELD_PREFIX . 'time_format', 'field_label' => lang('time_format_label'), 'field_instructions' => lang('time_format_desc'), 'field_type' => 'text', 'field_list_items' => '', 'field_pre_populate' => 'n', 'field_pre_blog_id' => '0', 'field_pre_field_id' => '0', 'field_related_to' => APP_VER < 2.0 ? 'blog' : 'channel', 'field_related_id' => '0', 'field_related_orderby' => 'date', 'field_related_sort' => 'desc', 'field_related_max' => '0', 'field_ta_rows' => '0', 'field_maxl' => '20', 'field_required' => 'n', 'field_text_direction' => 'ltr', 'field_search' => 'n', 'field_is_hidden' => 'y', 'field_fmt' => 'none', 'field_show_fmt' => 'n', 'field_order' => ++$order_count);
     }
     if (!isset($calendars_fields[CALENDAR_CALENDARS_FIELD_PREFIX . 'ics_url'])) {
         $fields[] = array('site_id' => $this->data->get_site_id(), 'group_id' => $calendars_field_group, 'field_name' => CALENDAR_CALENDARS_FIELD_PREFIX . 'ics_url', 'field_label' => lang('ics_url_label'), 'field_instructions' => lang('ics_url_desc'), 'field_type' => 'textarea', 'field_list_items' => '', 'field_pre_populate' => 'n', 'field_pre_blog_id' => '0', 'field_pre_field_id' => '0', 'field_related_to' => APP_VER < 2.0 ? 'blog' : 'channel', 'field_related_id' => '0', 'field_related_orderby' => 'date', 'field_related_sort' => 'desc', 'field_related_max' => '0', 'field_ta_rows' => '3', 'field_maxl' => '20', 'field_required' => 'n', 'field_text_direction' => 'ltr', 'field_search' => 'n', 'field_is_hidden' => 'y', 'field_fmt' => 'none', 'field_show_fmt' => 'n', 'field_order' => ++$order_count);
     }
     foreach ($fields as $field) {
         $_POST = $field;
         if (APP_VER < 2.0) {
             $PA->update_weblog_fields();
         } else {
             $this->update_channel_fields();
         }
     }
     // -------------------------------------
     //  Create the events field group
     // -------------------------------------
     if ($events_field_group == '') {
         $data = array('site_id' => $this->data->get_site_id(), 'group_name' => CALENDAR_EVENTS_FIELD_GROUP);
         ee()->db->query(ee()->db->insert_string('exp_field_groups', $data));
         $events_field_group = ee()->db->insert_id();
     }
     // -------------------------------------
     // Create the events fields
     // -------------------------------------
     $fields = array();
     $order_count = 0;
     if (APP_VER >= 2.0 and !isset($events_fields[CALENDAR_EVENTS_FIELD_PREFIX . 'dates_and_options'])) {
         $fields[] = array('site_id' => $this->data->get_site_id(), 'group_id' => $events_field_group, 'field_name' => CALENDAR_EVENTS_FIELD_PREFIX . 'dates_and_options', 'field_label' => lang('dates_and_options'), 'field_instructions' => '', 'field_type' => 'calendar', 'field_list_items' => '', 'field_pre_populate' => 'n', 'field_pre_blog_id' => '0', 'field_pre_field_id' => '0', 'field_related_to' => APP_VER < 2.0 ? 'blog' : 'channel', 'field_related_id' => '0', 'field_related_orderby' => 'date', 'field_related_sort' => 'desc', 'field_related_max' => '0', 'field_ta_rows' => '0', 'field_maxl' => '0', 'field_required' => 'n', 'field_text_direction' => 'ltr', 'field_search' => 'n', 'field_is_hidden' => 'n', 'field_fmt' => 'none', 'field_show_fmt' => 'n', 'field_order' => ++$order_count);
     }
     if (!isset($events_fields[CALENDAR_EVENTS_FIELD_PREFIX . 'summary'])) {
         $fields[] = array('site_id' => $this->data->get_site_id(), 'group_id' => $events_field_group, 'field_name' => CALENDAR_EVENTS_FIELD_PREFIX . 'summary', 'field_label' => lang('summary'), 'field_instructions' => '', 'field_type' => 'textarea', 'field_list_items' => '', 'field_pre_populate' => 'n', 'field_pre_blog_id' => '0', 'field_pre_field_id' => '0', 'field_related_to' => APP_VER < 2.0 ? 'blog' : 'channel', 'field_related_id' => '0', 'field_related_orderby' => 'date', 'field_related_sort' => 'desc', 'field_related_max' => '0', 'field_ta_rows' => '4', 'field_maxl' => '0', 'field_required' => 'n', 'field_text_direction' => 'ltr', 'field_search' => 'y', 'field_is_hidden' => 'n', 'field_fmt' => 'xhtml', 'field_show_fmt' => 'y', 'field_order' => ++$order_count);
     }
     if (!isset($events_fields[CALENDAR_EVENTS_FIELD_PREFIX . 'location'])) {
         $fields[] = array('site_id' => $this->data->get_site_id(), 'group_id' => $events_field_group, 'field_name' => CALENDAR_EVENTS_FIELD_PREFIX . 'location', 'field_label' => lang('location'), 'field_instructions' => '', 'field_type' => 'text', 'field_list_items' => '', 'field_pre_populate' => 'n', 'field_pre_blog_id' => '0', 'field_pre_field_id' => '0', 'field_related_to' => APP_VER < 2.0 ? 'blog' : 'channel', 'field_related_id' => '0', 'field_related_orderby' => 'date', 'field_related_sort' => 'desc', 'field_related_max' => '0', 'field_ta_rows' => '0', 'field_maxl' => '200', 'field_required' => 'n', 'field_text_direction' => 'ltr', 'field_search' => 'y', 'field_is_hidden' => 'n', 'field_fmt' => 'none', 'field_show_fmt' => 'n', 'field_order' => ++$order_count);
     }
     foreach ($fields as $field) {
         $_POST = $field;
         if (APP_VER < 2.0) {
             $PA->update_weblog_fields();
         } else {
             $this->update_channel_fields();
         }
     }
     // -------------------------------------
     //	Find an avaialble status group
     // -------------------------------------
     $status_q = ee()->db->query("SELECT MIN(group_id) as group_id\n\t\t\t FROM exp_status_groups");
     $status_group = 0;
     if ($status_q->num_rows() > 0) {
         $status_group = $status_q->row('group_id');
     }
     // -------------------------------------
     //  Create the calendars weblog
     // -------------------------------------
     if (empty($calendars_weblogs)) {
         $_POST = array('edit_group_prefs' => 'y', 'status_group' => $status_group, 'field_group' => $calendars_field_group, 'create_templates' => 'no', 'template_theme' => 'default', 'old_group_id' => '', 'group_name' => '', 'default_entry_title' => '');
         if (APP_VER < 2.0) {
             $_POST['duplicate_weblog_prefs'] = '';
             $_POST['blog_title'] = CALENDAR_CALENDARS_CHANNEL_TITLE;
             $_POST['blog_name'] = CALENDAR_CALENDARS_CHANNEL_NAME_DEFAULT;
             $PA->update_weblog_prefs();
         } else {
             $_POST['duplicate_channel_prefs'] = '';
             $_POST['channel_title'] = CALENDAR_CALENDARS_CHANNEL_TITLE;
             $_POST['channel_name'] = CALENDAR_CALENDARS_CHANNEL_NAME_DEFAULT;
             // If there are no channels, EE pitches a fit. Kill the error, Part 1.
             $errors = array();
             if (isset(ee()->api_channel_structure->errors) and !empty(ee()->api_channel_structure->errors)) {
                 $errors = ee()->api_channel_structure->errors;
                 ee()->api_channel_structure->errors = array();
             }
             ee()->api_channel_structure->create_channel($_POST);
             // Part 2 of the fix
             ee()->api_channel_structure->errors = $errors;
         }
     }
     // -------------------------------------
     //  Create the events weblog
     // -------------------------------------
     if (empty($events_weblogs)) {
         $_POST = array('edit_group_prefs' => 'y', 'status_group' => $status_group, 'field_group' => $events_field_group, 'create_templates' => 'no', 'template_theme' => 'default', 'old_group_id' => '', 'group_name' => '', 'default_entry_title' => '');
         if (APP_VER < 2.0) {
             $_POST['duplicate_weblog_prefs'] = '';
             $_POST['blog_title'] = CALENDAR_EVENTS_CHANNEL_TITLE;
             $_POST['blog_name'] = CALENDAR_EVENTS_CHANNEL_NAME_DEFAULT;
             $PA->update_weblog_prefs();
         } else {
             $_POST['duplicate_channel_prefs'] = '';
             $_POST['channel_title'] = CALENDAR_EVENTS_CHANNEL_TITLE;
             $_POST['channel_name'] = CALENDAR_EVENTS_CHANNEL_NAME_DEFAULT;
             // If there are no channels, EE pitches a fit. Kill the error, Part 1.
             $errors = array();
             if (isset(ee()->api_channel_structure->errors) and !empty(ee()->api_channel_structure->errors)) {
                 $errors = ee()->api_channel_structure->errors;
                 ee()->api_channel_structure->errors = array();
             }
             ee()->api_channel_structure->create_channel($_POST);
             // Part 2 of the fix
             ee()->api_channel_structure->errors = $errors;
         }
     }
     // -------------------------------------
     //  Preferences
     // -------------------------------------
     $query = ee()->db->query("SELECT {$this->sc->db->channel_id},\n\t\t\t\t\t{$this->sc->db->channel_name} AS blog_name\n\t\t\t FROM \t{$this->sc->db->channels}\n\t\t\t WHERE \t{$this->sc->db->channel_name}\n\t\t\t IN \t('" . CALENDAR_CALENDARS_CHANNEL_NAME_DEFAULT . "', '" . CALENDAR_EVENTS_CHANNEL_NAME_DEFAULT . "')");
     $channels = array();
     foreach ($query->result_array() as $row) {
         $which = $row['blog_name'] == CALENDAR_CALENDARS_CHANNEL_NAME_DEFAULT ? 'calendar' : 'event';
         $channels[] = $row;
     }
     $sql = ee()->db->insert_string('exp_calendar_preferences', array('site_id' => $this->data->get_site_id(), 'preferences' => $this->_default_preferences($channels)));
     ee()->db->query($sql);
     // -------------------------------------
     //  Retore $_POST
     // -------------------------------------
     $_POST = $old_POST;
     return TRUE;
 }