Example #1
0
 function doModel()
 {
     switch ($this->action) {
         case 'advanced':
             //calling the advanced settings view
             $this->doView('settings/advanced.php');
             break;
         case 'advanced_post':
             // updating advanced settings
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action can't be done because it's a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=advanced');
             }
             osc_csrf_check();
             $subdomain_type = Params::getParam('e_type');
             if (!in_array($subdomain_type, array('category', 'country', 'region', 'city', 'user'))) {
                 $subdomain_type = '';
             }
             $iUpdated = osc_set_preference('subdomain_type', $subdomain_type);
             $iUpdated += osc_set_preference('subdomain_host', Params::getParam('s_host'));
             if ($iUpdated > 0) {
                 osc_add_flash_ok_message(_m("Advanced settings have been updated"), 'admin');
             }
             osc_calculate_location_slug(osc_subdomain_type());
             $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=advanced');
             break;
         case 'advanced_cache_flush':
             osc_cache_flush();
             osc_add_flash_ok_message(_m("Cache flushed correctly"), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=advanced');
             break;
     }
 }
Example #2
0
    osc_set_preference('mailserver_name_from', '');
    osc_set_preference('seo_url_search_prefix', '');
    $comm->query(sprintf("ALTER TABLE  %st_category ADD  `b_price_enabled` TINYINT(1) NOT NULL DEFAULT 1", DB_TABLE_PREFIX));
    osc_set_preference('subdomain_type', '');
    osc_set_preference('subdomain_host', '');
    // email_new_admin
    $comm->query(sprintf("INSERT INTO %st_pages (s_internal_name, b_indelible, dt_pub_date) VALUES ('email_new_admin', 1, '%s' )", DB_TABLE_PREFIX, date('Y-m-d H:i:s')));
    $comm->query(sprintf("INSERT INTO %st_pages_description (fk_i_pages_id, fk_c_locale_code, s_title, s_text) VALUES (%d, 'en_US', '{WEB_TITLE} - Success creating admin account!', '<p>Hi {ADMIN_NAME},</p><p>The admin of {WEB_LINK} has created an account for you,</p><ul><li>Username: {USERNAME}</li><li>Password: {PASSWORD}</li></ul><p>You can access the admin panel here {WEB_ADMIN_LINK}.</p><p>Thank you!</p><p>Regards,</p>')", DB_TABLE_PREFIX, $comm->insertedId()));
    osc_set_preference('warn_expiration', '0', 'osclass', 'INTEGER');
    $comm->query(sprintf("INSERT INTO %st_pages (s_internal_name, b_indelible, dt_pub_date) VALUES ('email_warn_expiration', 1, '%s' )", DB_TABLE_PREFIX, date('Y-m-d H:i:s')));
    $comm->query(sprintf("INSERT INTO %st_pages_description (fk_i_pages_id, fk_c_locale_code, s_title, s_text) VALUES (%d, 'en_US', '{WEB_TITLE} - Your ad is about to expire', '<p>Hi {USER_NAME},</p><p>Your listing <a href=\"{ITEM_URL}\">{ITEM_TITLE}</a> is about to expire at {WEB_LINK}.')", DB_TABLE_PREFIX, $comm->insertedId()));
    osc_set_preference('force_aspect_image', '0', 'osclass', 'BOOLEAN');
}
if (osc_version() < 321) {
    if (function_exists('osc_calculate_location_slug')) {
        osc_calculate_location_slug(osc_subdomain_type());
    }
}
if (osc_version() < 330) {
    @mkdir(osc_content_path() . 'uploads/temp/');
    @mkdir(osc_content_path() . 'downloads/oc-temp/', 0777);
    @unlink(osc_lib_path() . 'osclass/classes/Watermark.php');
    osc_set_preference('title_character_length', '100', 'osclass', 'INTEGER');
    osc_set_preference('description_character_length', '5000', 'osclass', 'INTEGER');
}
if (osc_version() < 340) {
    $comm->query(sprintf("ALTER TABLE `%st_widget` ADD INDEX `idx_s_description` (`s_description`);", DB_TABLE_PREFIX));
    osc_set_preference('force_jpeg', '0', 'osclass', 'BOOLEAN');
    @unlink(ABS_PATH . '.maintenance');
    // THESE LINES PROBABLY HIT LOW TIMEOUT SCRIPTS, RUN THE LAST OF THE UPGRADE PROCESS
    //osc_calculate_location_slug('country');
Example #3
0
        function doModel()
        {
            // calling the locations settings view
            $location_action = Params::getParam('type');
            $mCountries = new Country();

            switch ($location_action) {
                case('add_country'):    // add country
                                        if( defined('DEMO') ) {
                                            osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin');
                                            $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                                        }
                                        osc_csrf_check();
                                        $countryCode = strtoupper(Params::getParam('c_country'));
                                        $countryName = Params::getParam('country');
                                        $exists = $mCountries->findByCode($countryCode);
                                        if(isset($exists['s_name'])) {
                                            osc_add_flash_error_message(sprintf(_m('%s already was in the database'), $countryName), 'admin');
                                        } else {
                                            if(Params::getParam('c_manual')==1) {
                                                $mCountries->insert(array('pk_c_code' => $countryCode,
                                                                        's_name' => $countryName));
                                                osc_add_flash_ok_message(sprintf(_m('%s has been added as a new country'), $countryName), 'admin');
                                            } else {
                                                if(!osc_validate_min($countryCode, 1) || !osc_validate_min($countryName, 1)) {
                                                    osc_add_flash_error_message(_m('Country code and name should have at least two characters'), 'admin');
                                                } else {
                                                    $data_sql = osc_file_get_contents('http://geo.osclass.org/newgeo.download.php?action=country&term=' . urlencode($countryCode) );

                                                    if($data_sql!='') {
                                                        $conn = DBConnectionClass::newInstance();
                                                        $c_db = $conn->getOsclassDb();
                                                        $comm = new DBCommandClass($c_db);
                                                        $comm->query("SET FOREIGN_KEY_CHECKS = 0");
                                                        $comm->importSQL($data_sql);
                                                        $comm->query("SET FOREIGN_KEY_CHECKS = 1");
                                                    } else {
                                                        $mCountries->insert(array('pk_c_code' => $countryCode,
                                                                                's_name' => $countryName));
                                                    }
                                                    osc_add_flash_ok_message(sprintf(_m('%s has been added as a new country'), $countryName), 'admin');
                                                }
                                            }
                                        }
                                        osc_calculate_location_slug(osc_subdomain_type());
                                        $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                break;
                case('edit_country'):   // edit country
                                        if( defined('DEMO') ) {
                                            osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin');
                                            $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                                        }
                                        osc_csrf_check();
                                        if(!osc_validate_min(Params::getParam('e_country'), 1)) {
                                            osc_add_flash_error_message(_m('Country name cannot be blank'), 'admin');
                                        } else {
                                            $name = Params::getParam('e_country');
                                            $slug = Params::getParam('e_country_slug');
                                            if($slug=='') {
                                                $slug_tmp = $slug = osc_sanitizeString($name);
                                            } else {
                                                $exists = $mCountries->findBySlug($slug);
                                                if(isset($exists['s_slug']) && $exists['pk_c_code']!=Params::getParam('country_code')) {
                                                    $slug_tmp = $slug = osc_sanitizeString($name);
                                                } else {
                                                    $slug_tmp = $slug = osc_sanitizeString($slug);
                                                }
                                            }
                                            $slug_unique = 1;
                                            while(true) {
                                                $location_slug = $mCountries->findBySlug($slug);
                                                if(isset($location_slug['s_slug']) && $location_slug['pk_c_code']!=Params::getParam('country_code')) {
                                                    $slug = $slug_tmp . '-' . $slug_unique;
                                                    $slug_unique++;
                                                } else {
                                                    break;
                                                }
                                            }

                                            $ok = $mCountries->update(array('s_name'=> $name, 's_slug' => $slug), array('pk_c_code' => Params::getParam('country_code')));

                                            if( $ok ) {
                                                osc_add_flash_ok_message(_m('Country has been edited'), 'admin');
                                            } else {
                                                osc_add_flash_error_message(_m('There were some problems editing the country'), 'admin');
                                            }
                                        }
                                        $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                break;
                case('delete_country'): // delete country
                                        if( defined('DEMO') ) {
                                            osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin');
                                            $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                                        }
                                        osc_csrf_check();
                                        $countryIds = Params::getParam('id');

                                        if(is_array($countryIds)) {
                                            $locations = 0;
                                            $del_locations = 0;
                                            foreach($countryIds as $countryId) {
                                                $ok = $mCountries->deleteByPrimaryKey($countryId);
                                            }
                                            if($ok==0) {
                                                $del_locations++;
                                            } else {
                                                $locations += $ok;
                                            }
                                            if($locations==0) {
                                                osc_add_flash_ok_message(sprintf(_n('One location has been deleted', '%s locations have been deleted', $del_locations), $del_locations), 'admin');
                                            } else {
                                                osc_add_flash_error_message(_m('There was a problem deleting locations'), 'admin');
                                            }
                                        } else {
                                            osc_add_flash_error_message(_m('No country was selected'), 'admin');
                                        }
                                        $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                break;
                case('add_region'):     // add region
                                        if( defined('DEMO') ) {
                                            osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin');
                                            $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                                        }
                                        osc_csrf_check();
                                        if( !Params::getParam('r_manual') ) {
                                            $regionId    = Params::getParam('region_id');
                                            $regionName  = Params::getParam('region');
                                            if($regionId!='') {
                                                $data_sql = osc_file_get_contents('http://geo.osclass.org/newgeo.download.php?action=region&term=' . urlencode($regionId) );

                                                $conn = DBConnectionClass::newInstance();
                                                $c_db = $conn->getOsclassDb();
                                                $comm = new DBCommandClass($c_db);
                                                $comm->query("SET FOREIGN_KEY_CHECKS = 0");
                                                $comm->importSQL($data_sql);
                                                $comm->query("SET FOREIGN_KEY_CHECKS = 1");
                                                osc_add_flash_ok_message(sprintf(_m('%s has been added as a new region'), $regionName), 'admin');
                                            } else {
                                                osc_add_flash_error_message(sprintf(_m("%s can't be added"), $regionName), 'admin');
                                            }

                                        } else {
                                            $mRegions    = new Region();
                                            $regionName  = Params::getParam('region');
                                            $countryCode = Params::getParam('country_c_parent');
                                            $country     = Country::newInstance()->findByCode($countryCode);

                                            if(!osc_validate_min($regionName, 1)) {
                                                osc_add_flash_error_message(_m('Region name cannot be blank'), 'admin');
                                            } else {
                                                $exists = $mRegions->findByName($regionName, $countryCode);
                                                if(!isset($exists['s_name'])) {
                                                    $data = array('fk_c_country_code' => $countryCode
                                                                ,'s_name' => $regionName);
                                                    $mRegions->insert($data);
                                                    $id = $mRegions->dao->insertedId();
                                                    RegionStats::newInstance()->setNumItems($id, 0);

                                                    osc_add_flash_ok_message(sprintf(_m('%s has been added as a new region'), $regionName), 'admin');
                                                } else {
                                                    osc_add_flash_error_message(sprintf(_m('%s already was in the database'), $regionName), 'admin');
                                                }
                                            }
                                        }
                                        osc_calculate_location_slug(osc_subdomain_type());
                                        $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations&country_code='.@$countryCode."&country=".@$country['s_name']);
                break;
                case('edit_region'):    // edit region
                                        if( defined('DEMO') ) {
                                            osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin');
                                            $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                                        }
                                        osc_csrf_check();
                                        $mRegions  = new Region();
                                        $newRegion = Params::getParam('e_region');
                                        $regionId  = Params::getParam('region_id');

                                        if(!osc_validate_min($newRegion, 1)) {
                                            osc_add_flash_error_message(_m('Region name cannot be blank'), 'admin');
                                        } else {
                                            $exists = $mRegions->findByName($newRegion);
                                            if(!isset($exists['pk_i_id']) || $exists['pk_i_id']==$regionId) {
                                                if($regionId != '') {
                                                    $aRegion = $mRegions->findByPrimaryKey($regionId);
                                                    $country = Country::newInstance()->findByCode($aRegion['fk_c_country_code']);

                                                    $name = $newRegion;
                                                    $slug = Params::getParam('e_region_slug');
                                                    if($slug=='') {
                                                        $slug_tmp = $slug = osc_sanitizeString($name);
                                                    } else {
                                                        $exists = $mRegions->findBySlug($slug);
                                                        if(isset($exists['s_slug']) && $exists['pk_i_id']!=$regionId) {
                                                            $slug_tmp = $slug = osc_sanitizeString($name);
                                                        } else {
                                                            $slug_tmp = $slug = osc_sanitizeString($slug);
                                                        }
                                                    }
                                                    $slug_unique = 1;
                                                    while(true) {
                                                        $location_slug = $mRegions->findBySlug($slug);
                                                        if(isset($location_slug['s_slug']) && $location_slug['pk_i_id']!=$regionId) {
                                                            $slug = $slug_tmp . '-' . $slug_unique;
                                                            $slug_unique++;
                                                        } else {
                                                            break;
                                                        }
                                                    }

                                                    $mRegions->update(array('s_name' => $newRegion, 's_slug' => $slug)
                                                                     ,array('pk_i_id' => $regionId));
                                                    ItemLocation::newInstance()->update(
                                                        array('s_region'       => $newRegion),
                                                        array('fk_i_region_id' => $regionId)
                                                    );
                                                    osc_add_flash_ok_message(sprintf(_m('%s has been edited'), $newRegion), 'admin');
                                                }
                                            } else {
                                                osc_add_flash_error_message(sprintf(_m('%s already was in the database'), $newRegion), 'admin');
                                            }
                                        }
                                        $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations&country_code='.@$country['pk_c_code']."&country=".@$country['s_name']);
                break;
                case('delete_region'):  // delete region
                                        if( defined('DEMO') ) {
                                            osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin');
                                            $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                                        }
                                        osc_csrf_check();
                                        $mRegion  = new Region();
                                        $regionIds = Params::getParam('id');

                                        if(is_array($regionIds)) {
                                            $locations = 0;
                                            $del_locations = 0;
                                            if(count($regionIds)>0) {
                                                $region = $mRegion->findByPrimaryKey($regionIds[0]);
                                                $country = Country::newInstance()->findByCode($region['fk_c_country_code']);
                                                foreach($regionIds as $regionId) {
                                                    if($regionId != '') {
                                                        $ok = $mRegion->deleteByPrimaryKey($regionId);
                                                        if($ok==0) {
                                                            $del_locations++;
                                                        } else {
                                                            $locations += $ok;
                                                        }
                                                    }
                                                }
                                            }
                                            if($locations==0) {
                                                osc_add_flash_ok_message(sprintf(_n('One location has been deleted', '%s locations have been deleted', $del_locations), $del_locations), 'admin');
                                            } else {
                                                osc_add_flash_error_message(_m('There was a problem deleting locations'), 'admin');
                                            }
                                        } else {
                                            osc_add_flash_error_message(_m('No region was selected'), 'admin');
                                        }
                                        $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations&country_code='.@$country['pk_c_code']."&country=".@$country['s_name']);
                break;
                case('add_city'):       // add city
                                        if( defined('DEMO') ) {
                                            osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin');
                                            $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                                        }
                                        osc_csrf_check();
                                        $regionId    = Params::getParam('region_parent');
                                        $countryCode = Params::getParam('country_c_parent');
                                        $mRegion     = new Region();
                                        $region = $mRegion->findByPrimaryKey($regionId);
                                        $country = Country::newInstance()->findByCode($region['fk_c_country_code']);
                                        if( !Params::getParam('ci_manual') ) {
                                            $cityId    = Params::getParam('city_id');
                                            $cityName  = Params::getParam('city');
                                            if($cityId!='') {
                                                $data_sql = osc_file_get_contents('http://geo.osclass.org/newgeo.download.php?action=city&term=' . urlencode($cityId) );

                                                $conn = DBConnectionClass::newInstance();
                                                $c_db = $conn->getOsclassDb();
                                                $comm = new DBCommandClass($c_db);
                                                $comm->query("SET FOREIGN_KEY_CHECKS = 0");
                                                $comm->importSQL($data_sql);
                                                $comm->query("SET FOREIGN_KEY_CHECKS = 1");
                                                osc_add_flash_ok_message(sprintf(_m('%s has been added as a new city'), $cityName), 'admin');
                                            } else {
                                                osc_add_flash_error_message(sprintf(_m("%s can't be added"), $cityName), 'admin');
                                            }

                                        } else {
                                            $mCities     = new City();
                                            $newCity     = Params::getParam('city');

                                            if(!osc_validate_min($newCity, 1)) {
                                                osc_add_flash_error_message(_m('New city name cannot be blank'), 'admin');
                                            } else {
                                                $exists = $mCities->findByName($newCity, $regionId);
                                                if(!isset($exists['s_name'])) {
                                                    $mCities->insert(array('fk_i_region_id'    => $regionId
                                                                        ,'s_name'            => $newCity
                                                                        ,'fk_c_country_code' => $countryCode));
                                                    $id = $mCities->dao->insertedId();
                                                    CityStats::newInstance()->setNumItems($id, 0);

                                                    osc_add_flash_ok_message(sprintf(_m('%s has been added as a new city'), $newCity), 'admin');
                                                } else {
                                                    osc_add_flash_error_message(sprintf(_m('%s already was in the database'), $newCity), 'admin');
                                                }
                                            }
                                        }
                                        osc_calculate_location_slug('city');
                                        $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations&country_code='.@$country['pk_c_code']."&country=".@$country['s_name']."&region=".$regionId);
                break;
                case('edit_city'):      // edit city
                                        if( defined('DEMO') ) {
                                            osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin');
                                            $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                                        }
                                        osc_csrf_check();
                                        $mRegion = new Region();
                                        $mCities = new City();
                                        $newCity = Params::getParam('e_city');
                                        $cityId  = Params::getParam('city_id');

                                        if(!osc_validate_min($newCity, 1)) {
                                            osc_add_flash_error_message(_m('City name cannot be blank'), 'admin');
                                        } else {
                                            $exists = $mCities->findByName($newCity);
                                            if(!isset($exists['pk_i_id']) || $exists['pk_i_id']==$cityId) {
                                                $city = $mCities->findByPrimaryKey($cityId);
                                                $region = $mRegion->findByPrimaryKey($city['fk_i_region_id']);
                                                $country = Country::newInstance()->findByCode($region['fk_c_country_code']);

                                                $name = $newCity;
                                                $slug = Params::getParam('e_country_slug');
                                                if($slug=='') {
                                                    $slug_tmp = $slug = osc_sanitizeString($name);
                                                } else {
                                                    $exists = $mCities->findBySlug($slug);
                                                    if(isset($exists['s_slug']) && $exists['pk_i_id']!=$cityId) {
                                                        $slug_tmp = $slug = osc_sanitizeString($name);
                                                    } else {
                                                        $slug_tmp = $slug = osc_sanitizeString($slug);
                                                    }
                                                }
                                                $slug_unique = 1;
                                                while(true) {
                                                    $location_slug = $mCities->findBySlug($slug);
                                                    if(isset($location_slug['s_slug']) && $location_slug['pk_i_id']!=$cityId) {
                                                        $slug = $slug_tmp . '-' . $slug_unique;
                                                        $slug_unique++;
                                                    } else {
                                                        break;
                                                    }
                                                }

                                                $mCities->update(array('s_name' => $newCity, 's_slug' => $slug)
                                                                ,array('pk_i_id' => $cityId));
                                                ItemLocation::newInstance()->update(
                                                    array('s_city'       => $newCity),
                                                    array('fk_i_city_id' => $cityId)
                                                );
                                                osc_add_flash_ok_message(sprintf(_m('%s has been edited'), $newCity), 'admin');
                                            } else {
                                                osc_add_flash_error_message(sprintf(_m('%s already was in the database'), $newCity), 'admin');
                                            }
                                        }
                                        $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations&country_code='.@$country['pk_c_code']."&country=".@$country['s_name']."&region=".@$region['pk_i_id']);
                break;
                case('delete_city'):    // delete city
                                        if( defined('DEMO') ) {
                                            osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin');
                                            $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
                                        }
                                        osc_csrf_check();
                                        $mCities = new City();
                                        $cityIds  = Params::getParam('id');
                                        if(is_array($cityIds)) {
                                            $locations = 0;
                                            $del_locations = 0;
                                            $cCity = end($cityIds);
                                            $cCity = $mCities->findByPrimaryKey($cCity);
                                            $region = Region::newInstance()->findByPrimaryKey($cCity['fk_i_region_id']);
                                            $country = Country::newInstance()->findByCode($cCity['fk_c_country_code']);
                                            foreach($cityIds as $cityId) {
                                                $ok = $mCities->deleteByPrimaryKey($cityId);
                                                if($ok==0) {
                                                    $del_locations++;
                                                } else {
                                                    $locations += $ok;
                                                }
                                            }
                                            if($locations==0) {
                                                osc_add_flash_ok_message(sprintf(_n('One location has been deleted', '%d locations have been deleted', $del_locations), $del_locations), 'admin');
                                            } else {
                                                osc_add_flash_error_message(_m('There was a problem deleting locations'), 'admin');
                                            }
                                        } else {
                                            osc_add_flash_error_message(_m('No city was selected'), 'admin');
                                        }
                                        $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations&country_code='.@$country['pk_c_code']."&country=".@$country['s_name']."&region=".@$region['pk_i_id']);
                break;
            }

            $aCountries = $mCountries->listAll();
            $this->_exportVariableToView('aCountries', $aCountries);

            $this->doView('settings/locations.php');
        }
Example #4
0
 function doModel()
 {
     parent::doModel();
     switch ($this->action) {
         case 'import':
             // calling import view
             $this->doView('tools/import.php');
             break;
         case 'import_post':
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=import');
             }
             // calling
             osc_csrf_check();
             $sql = Params::getFiles('sql');
             if (isset($sql['size']) && $sql['size'] != 0) {
                 $content_file = file_get_contents($sql['tmp_name']);
                 $conn = DBConnectionClass::newInstance();
                 $c_db = $conn->getOsclassDb();
                 $comm = new DBCommandClass($c_db);
                 if ($comm->importSQL($content_file)) {
                     osc_calculate_location_slug(osc_subdomain_type());
                     osc_add_flash_ok_message(_m('Import complete'), 'admin');
                 } else {
                     osc_add_flash_error_message(_m('There was a problem importing data to the database'), 'admin');
                 }
             } else {
                 osc_add_flash_warning_message(_m('No file was uploaded'), 'admin');
             }
             @unlink($sql['tmp_name']);
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=import');
             break;
         case 'category':
             $this->doView('tools/category.php');
             break;
         case 'category_post':
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=category');
             }
             osc_update_cat_stats();
             osc_add_flash_ok_message(_m("Recount category stats has been successful"), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=category');
             break;
         case 'locations':
             $this->doView('tools/locations.php');
             break;
         case 'locations_post':
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=locations');
             }
             osc_update_location_stats(true);
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=locations');
             break;
         case 'upgrade':
             $this->doView('tools/upgrade.php');
             break;
         case 'version':
             $this->doView('tools/version.php');
             break;
         case 'backup':
             $this->doView('tools/backup.php');
             break;
         case 'backup-sql':
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup');
             }
             osc_csrf_check();
             //databasse dump...
             if (Params::getParam('bck_dir') != '') {
                 $path = trim(Params::getParam('bck_dir'));
                 if (substr($path, -1, 1) != "/") {
                     $path .= '/';
                 }
             } else {
                 $path = osc_base_path();
             }
             $filename = 'Osclass_mysqlbackup.' . date('YmdHis') . '.sql';
             switch (osc_dbdump($path, $filename)) {
                 case -1:
                     $msg = _m('Path is empty');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case -2:
                     $msg = sprintf(_m('Could not connect with the database. Error: %s'), mysql_error());
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case -3:
                     $msg = _m('There are no tables to back up');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case -4:
                     $msg = _m('The folder is not writable');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 default:
                     $msg = _m('Backup completed successfully');
                     osc_add_flash_ok_message($msg, 'admin');
                     break;
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup');
             break;
         case 'backup-sql_file':
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup');
             }
             //databasse dump...
             $filename = 'Osclass_mysqlbackup.' . date('YmdHis') . '.sql';
             $path = sys_get_temp_dir() . "/";
             switch (osc_dbdump($path, $filename)) {
                 case -1:
                     $msg = _m('Path is empty');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case -2:
                     $msg = sprintf(_m('Could not connect with the database. Error: %s'), mysql_error());
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case -3:
                     $msg = sprintf(_m('Could not select the database. Error: %s'), mysql_error());
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case -4:
                     $msg = _m('There are no tables to back up');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case -5:
                     $msg = _m('The folder is not writable');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 default:
                     $msg = _m('Backup completed successfully');
                     osc_add_flash_ok_message($msg, 'admin');
                     header('Content-Description: File Transfer');
                     header('Content-Type: application/octet-stream');
                     header('Content-Disposition: attachment; filename=' . basename($filename));
                     header('Content-Transfer-Encoding: binary');
                     header('Expires: 0');
                     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                     header('Pragma: public');
                     header('Content-Length: ' . filesize($path . $filename));
                     flush();
                     readfile($path . $filename);
                     exit;
                     break;
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup');
             break;
         case 'backup-zip_file':
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup');
             }
             $filename = "Osclass_backup." . date('YmdHis') . ".zip";
             $path = sys_get_temp_dir() . "/";
             if (osc_zip_folder(osc_base_path(), $path . $filename)) {
                 $msg = _m('Archived successfully!');
                 osc_add_flash_ok_message($msg, 'admin');
                 header('Content-Description: File Transfer');
                 header('Content-Type: application/octet-stream');
                 header('Content-Disposition: attachment; filename=' . basename($filename));
                 header('Content-Transfer-Encoding: binary');
                 header('Expires: 0');
                 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                 header('Pragma: public');
                 header('Content-Length: ' . filesize($path . $filename));
                 flush();
                 readfile($path . $filename);
                 exit;
             } else {
                 $msg = _m('Error, the zip file was not created in the specified directory');
                 osc_add_flash_error_message($msg, 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup');
             break;
         case 'backup-zip':
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup');
             }
             //zip of the code just to back it up
             osc_csrf_check();
             if (Params::getParam('bck_dir') != '') {
                 $archive_name = trim(Params::getParam('bck_dir'));
                 if (substr(trim($archive_name), -1, 1) != "/") {
                     $archive_name .= '/';
                 }
                 $archive_name = Params::getParam('bck_dir') . '/Osclass_backup.' . date('YmdHis') . '.zip';
             } else {
                 $archive_name = osc_base_path() . "Osclass_backup." . date('YmdHis') . ".zip";
             }
             $archive_folder = osc_base_path();
             if (osc_zip_folder($archive_folder, $archive_name)) {
                 $msg = _m('Archived successfully!');
                 osc_add_flash_ok_message($msg, 'admin');
             } else {
                 $msg = _m('Error, the zip file was not created in the specified directory');
                 osc_add_flash_error_message($msg, 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup');
             break;
         case 'backup_post':
             $this->doView('tools/backup.php');
             break;
         case 'maintenance':
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin');
                 $this->doView('tools/maintenance.php');
                 break;
             }
             $mode = Params::getParam('mode');
             if ($mode == 'on') {
                 osc_csrf_check();
                 $maintenance_file = osc_base_path() . '.maintenance';
                 $fileHandler = @fopen($maintenance_file, 'w');
                 if ($fileHandler) {
                     osc_add_flash_ok_message(_m('Maintenance mode is ON'), 'admin');
                 } else {
                     osc_add_flash_error_message(_m('There was an error creating the .maintenance file, please create it manually at the root folder'), 'admin');
                 }
                 fclose($fileHandler);
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=maintenance');
             } else {
                 if ($mode == 'off') {
                     osc_csrf_check();
                     $deleted = @unlink(osc_base_path() . '.maintenance');
                     if ($deleted) {
                         osc_add_flash_ok_message(_m('Maintenance mode is OFF'), 'admin');
                     } else {
                         osc_add_flash_error_message(_m('There was an error removing the .maintenance file, please remove it manually from the root folder'), 'admin');
                     }
                     $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=maintenance');
                 }
             }
             $this->doView('tools/maintenance.php');
             break;
         default:
     }
 }