Ejemplo n.º 1
0
 public function updateSQL()
 {
     if (isset(JError::$legacy) && JError::$legacy == true) {
         JError::$legacy = false;
     }
     $structs = array('order' => array('order_serial_params' => 'TEXT NOT NULL DEFAULT \'\''));
     foreach ($structs as $table => &$v) {
         $sql = array();
         $current = array();
         if (!HIKASHOP_J25) {
             $tmp = $this->db->getTableFields(hikaserial::table('shop.' . $table));
             $current = reset($tmp);
             unset($tmp);
         } else {
             $current = $this->db->getTableColumns(hikaserial::table('shop.' . $table));
         }
         foreach ($v as $col => $colSql) {
             if (!isset($current[$col])) {
                 $sql[] = 'ADD COLUMN `' . $col . '` ' . $colSql;
             }
         }
         if (!empty($sql)) {
             $query = 'ALTER IGNORE TABLE `' . hikaserial::table('shop.' . $table) . '` ' . implode(',', $sql);
             $this->db->setQuery($query);
             $this->db->query();
             unset($query);
         }
         unset($sql);
     }
     if (!$this->update) {
         return true;
     }
     if (version_compare($this->fromVersion, '1.2.0', '<')) {
         $query = "CREATE TABLE IF NOT EXISTS `#__hikaserial_consumer` (" . "\t`consumer_id` INT(10) NOT NULL AUTO_INCREMENT," . "\t`consumer_type` VARCHAR(255) NOT NULL," . "\t`consumer_published` INT(4) NOT NULL DEFAULT 0," . "\t`consumer_name` VARCHAR(255) NOT NULL," . "\t`consumer_ordering` INT(10) NOT NULL DEFAULT 0," . "\t`consumer_description` TEXT NOT NULL DEFAULT ''," . "\t`consumer_params` TEXT NOT NULL DEFAULT ''," . "\t`consumer_access` VARCHAR(255) NOT NULL DEFAULT 'all'," . "\tPRIMARY KEY (`consumer_id`)" . ") ENGINE=MyISAM;";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if (version_compare($this->fromVersion, '1.3.0', '<')) {
         $query = "ALTER TABLE `#__hikaserial_serial` ADD `serial_extradata` TEXT NULL DEFAULT NULL;";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if (version_compare($this->fromVersion, '1.4.0', '<')) {
         $query = "CREATE TABLE IF NOT EXISTS `#__hikaserial_history` (" . "\t`history_id` INT(10) NOT NULL AUTO_INCREMENT," . "\t`history_serial_id` INT(10) unsigned NOT NULL DEFAULT '0'," . "\t`history_created` INT(10) unsigned NOT NULL DEFAULT '0'," . "\t`history_ip` VARCHAR(255) NOT NULL DEFAULT ''," . "\t`history_new_status` VARCHAR(255) NOT NULL DEFAULT ''," . "\t`history_type` VARCHAR(255) NOT NULL DEFAULT ''," . "\t`history_data` TEXT NOT NULL DEFAULT ''," . "\t`history_user_id` INT(10) unsigned DEFAULT '0'," . "\tPRIMARY KEY (`history_id`)" . ") ENGINE=MyISAM;";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if (version_compare($this->fromVersion, '1.5.0', '<')) {
         $file = HIKASERIAL_BACK . 'admin.hikaserial.php';
         if (file_exists($file)) {
             JFile::delete($file);
         }
     }
     if (version_compare($this->fromVersion, '1.5.1', '<')) {
         $query = "CREATE TABLE IF NOT EXISTS `#__hikaserial_plugin` (" . "\t`plugin_id` INT(10) NOT NULL AUTO_INCREMENT," . "\t`plugin_type` VARCHAR(255) NOT NULL," . "\t`plugin_published` INT(4) NOT NULL DEFAULT 0," . "\t`plugin_name` VARCHAR(255) NOT NULL," . "\t`plugin_ordering` INT(10) NOT NULL DEFAULT 0," . "\t`plugin_description` TEXT NOT NULL DEFAULT ''," . "\t`plugin_params` TEXT NOT NULL DEFAULT ''," . "\t`plugin_access` VARCHAR(255) NOT NULL DEFAULT 'all'," . "\tPRIMARY KEY (`plugin_id`)" . ") ENGINE=MyISAM;";
         $this->db->setQuery($query);
         $this->db->query();
     }
 }
Ejemplo n.º 2
0
 /**
  * Database object constructor
  *
  * @param  object|\JDatabase|\JDatabaseDriver  $cmsDatabase
  * @param  string                              $prefix
  * @param  string                              $cmsRelease
  */
 public function __construct($cmsDatabase, $prefix, $cmsRelease)
 {
     $this->_db = $cmsDatabase;
     $this->_table_prefix = $prefix;
     $this->cmsRelease = $cmsRelease;
     if (version_compare($this->cmsRelease, '3.0', '<') && class_exists('\\JError')) {
         // Make Joomla 2.5 use RunTimeExceptions
         \JError::$legacy = false;
     }
 }
Ejemplo n.º 3
0
define('JPATH_SITE', JPATH_ROOT);
define('JPATH_CONFIGURATION', JPATH_ROOT);
define('JPATH_ADMINISTRATOR', JPATH_ROOT . '/administrator');
define('JPATH_LIBRARIES', JPATH_ROOT . '/libraries');
define('JPATH_PLUGINS', JPATH_ROOT . '/plugins');
define('JPATH_INSTALLATION', JPATH_ROOT . '/installation');
define('JPATH_THEMES', JPATH_ADMINISTRATOR . '/templates');
define('JPATH_CACHE', JPATH_ROOT . '/cache');
define('JPATH_MANIFESTS', JPATH_ADMINISTRATOR . '/manifests');
define('JPATH_MYWEBAPP', JPATH_BASE);
// Usually this will be in the framework.php file in the
// includes folder.
require_once JPATH_PLATFORM . '/import.php';
require_once JPATH_LIBRARIES . '/import.legacy.php';
// Force library to be in JError legacy mode
JError::$legacy = true;
JError::setErrorHandling(E_NOTICE, 'message');
JError::setErrorHandling(E_WARNING, 'message');
JError::setErrorHandling(E_ERROR, 'message', array('JError', 'customErrorPage'));
// Botstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';
// Pre-Load configuration.
ob_start();
require_once JPATH_CONFIGURATION . '/configuration.php';
ob_end_clean();
// System configuration.
$config = new JConfig();
// Set the error_reporting
switch ($config->error_reporting) {
    case 'default':
    case '-1':
Ejemplo n.º 4
0
*/
'cli' == PHP_SAPI || die('This script must be executed from the command line.');
version_compare(PHP_VERSION, '5.3', '>=') || die('This script requires PHP >= 5.3');
define('_JEXEC', 1);
define('ECR_DEBUG', 0);
ini_set('error_reporting', -1);
$options = getopt('', array('basedir:'));
count($options) || die('Please specify a build path with the --basedir option');
define('THE_BUILD_PATH', $options['basedir']);
require THE_BUILD_PATH . '/libraries/import.php';
//-- @todo deprecated JRequest..
jimport('joomla.environment.request');
jimport('joomla.application.component.helper');
jimport('joomla.environment.uri');
//-- @todo deprecated JError..
JError::$legacy = false;
/**
 * EasyCreator client builder.
 */
class EcrCliBuilder extends JApplicationCli
{
    /**
     * DoIt
     *
     * @throws Exception
     * @return void
     */
    public function doExecute()
    {
        define('JPATH_BASE', THE_BUILD_PATH);
        define('JPATH_SITE', JPATH_BASE);
    function _updateDatabase()
    {
        if (version_compare(JVERSION, '2.5', '>=') && version_compare(JVERSION, '3.0', '<')) {
            if (JError::$legacy) {
                $tmp_legacy = true;
            } else {
                $tmp_legacy = false;
            }
            JError::$legacy = false;
        }
        jimport('joomla.filesystem.file');
        if (!file_exists(JPATH_ROOT . "/images/com_adsmanager/")) {
            JFolder::create(JPATH_ROOT . "/images/com_adsmanager/");
        }
        if (!file_exists(JPATH_ROOT . "/images/com_adsmanager/categories/")) {
            JFolder::create(JPATH_ROOT . "/images/com_adsmanager/categories/");
        }
        if (!file_exists(JPATH_ROOT . "/images/com_adsmanager/ads/")) {
            JFolder::create(JPATH_ROOT . "/images/com_adsmanager/ads/");
        }
        if (file_exists(JPATH_ROOT . "/images/com_adsmanager/ads/tmp")) {
            JFolder::move(JPATH_ROOT . "/images/com_adsmanager/ads/tmp", JPATH_ROOT . "/images/com_adsmanager/ads/waiting");
        }
        if (!file_exists(JPATH_ROOT . "/images/com_adsmanager/ads/waiting")) {
            JFolder::create(JPATH_ROOT . "/images/com_adsmanager/ads/waiting");
        }
        if (!file_exists(JPATH_ROOT . "/images/com_adsmanager/ads/uploaded")) {
            JFolder::create(JPATH_ROOT . "/images/com_adsmanager/ads/uploaded");
        }
        if (!file_exists(JPATH_ROOT . "/images/com_adsmanager/ads/tmp")) {
            JFolder::create(JPATH_ROOT . "/images/com_adsmanager/ads/tmp");
        }
        if (!file_exists(JPATH_ROOT . "/images/com_adsmanager/email/")) {
            JFolder::create(JPATH_ROOT . "/images/com_adsmanager/email/");
        }
        if (!file_exists(JPATH_ROOT . "/images/com_adsmanager/files/")) {
            JFolder::create(JPATH_ROOT . "/images/com_adsmanager/files/");
        }
        if (!file_exists(JPATH_ROOT . "/images/com_adsmanager/files/.htaccess")) {
            $content = "ForceType application/octet-stream";
            $content .= "\nHeader set Content-Disposition attachment";
            JFile::write(JPATH_ROOT . "/images/com_adsmanager/files/.htaccess", $content);
        }
        if (!file_exists(JPATH_ROOT . "/images/com_adsmanager/fields/")) {
            JFolder::create(JPATH_ROOT . "/images/com_adsmanager/fields/");
        }
        if (!file_exists(JPATH_ROOT . "/images/com_adsmanager/plugins/")) {
            JFolder::create(JPATH_ROOT . "/images/com_adsmanager/plugins/");
        }
        if (!file_exists(JPATH_ROOT . "/images/com_adsmanager/index.html")) {
            JFile::copy(JPATH_ROOT . "/components/com_adsmanager/index.html", JPATH_ROOT . "/images/com_adsmanager/index.html");
        }
        if (!file_exists(JPATH_ROOT . "/images/com_adsmanager/categories/index.html")) {
            JFile::copy(JPATH_ROOT . "/components/com_adsmanager/index.html", JPATH_ROOT . "/images/com_adsmanager/categories/index.html");
        }
        if (!file_exists(JPATH_ROOT . "/images/com_adsmanager/ads/index.html")) {
            JFile::copy(JPATH_ROOT . "/components/com_adsmanager/index.html", JPATH_ROOT . "/images/com_adsmanager/ads/index.html");
        }
        if (!file_exists(JPATH_ROOT . "/images/com_adsmanager/ads/waiting/index.html")) {
            JFile::copy(JPATH_ROOT . "/components/com_adsmanager/index.html", JPATH_ROOT . "/images/com_adsmanager/ads/waiting/index.html");
        }
        if (!file_exists(JPATH_ROOT . "/images/com_adsmanager/ads/uploaded/index.html")) {
            JFile::copy(JPATH_ROOT . "/components/com_adsmanager/index.html", JPATH_ROOT . "/images/com_adsmanager/ads/uploaded/index.html");
        }
        if (!file_exists(JPATH_ROOT . "/images/com_adsmanager/email/index.html")) {
            JFile::copy(JPATH_ROOT . "/components/com_adsmanager/index.html", JPATH_ROOT . "/images/com_adsmanager/email/index.html");
        }
        if (!file_exists(JPATH_ROOT . "/images/com_adsmanager/files/index.html")) {
            JFile::copy(JPATH_ROOT . "/components/com_adsmanager/index.html", JPATH_ROOT . "/images/com_adsmanager/files/index.html");
        }
        if (!file_exists(JPATH_ROOT . "/images/com_adsmanager/fields/index.html")) {
            JFile::copy(JPATH_ROOT . "/components/com_adsmanager/index.html", JPATH_ROOT . "/images/com_adsmanager/fields/index.html");
        }
        if (!file_exists(JPATH_ROOT . "/images/com_adsmanager/plugins/index.html")) {
            JFile::copy(JPATH_ROOT . "/components/com_adsmanager/index.html", JPATH_ROOT . "/images/com_adsmanager/plugins/index.html");
        }
        $lang = JFactory::getLanguage();
        $lang->load("com_adsmanager");
        // Schema modification -- BEGIN
        $db = JFactory::getDBO();
        $db->setQuery("CREATE TABLE IF NOT EXISTS `#__adsmanager_searchmodule_config` (\n\t\t\t`id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t`params` text NOT NULL,\n\t\t\tPRIMARY KEY  (`id`)\n\t);");
        try {
            $result = $db->query();
        } catch (Exception $e) {
        }
        $db->setQuery("INSERT IGNORE INTO `#__adsmanager_searchmodule_config` (`params`) VALUES ('')");
        try {
            $result = $db->query();
        } catch (Exception $e) {
        }
        $db->setQuery("SELECT count(*) FROM `#__adsmanager_fields` WHERE 1");
        $total = $db->loadResult();
        if ($total == 0) {
            $queries = array();
            $queries[] = " INSERT IGNORE INTO `#__adsmanager_columns` (`id`,`name`,`ordering`,`catsid`,`published`) VALUES " . " (2, 'ADSMANAGER_PRICE', 1, 1,1), " . " (3, 'ADSMANAGER_CITY', 2, 1,1), " . " (5, 'ADSMANAGER_STATE', 1, 0,1);";
            $queries[] = " UPDATE #__adsmanager_columns SET catsid = ',-1,'";
            $queries[] = " INSERT IGNORE INTO `#__adsmanager_field_values` (`fieldvalueid`,`fieldid`,`fieldtitle`,`fieldvalue`,`ordering`,`sys`) VALUES " . " (1, 8, 'ADSMANAGER_KINDOF2', 1, 1, 0), " . " (2, 8, 'ADSMANAGER_KINDOF1', 2, 2, 0), " . " (3, 9, 'ADSMANAGER_STATE_0', 4, 4, 0)," . " (4, 8, 'ADSMANAGER_KINDOFALL', 0, 0, 0)," . " (5, 9, 'ADSMANAGER_STATE_1', 3, 3, 0)," . " (6, 9, 'ADSMANAGER_STATE_3', 1, 1, 0)," . " (7, 9, 'ADSMANAGER_STATE_2', 2, 2, 0)," . " (8, 9, 'ADSMANAGER_STATE_4', 0, 0, 0);";
            $queries[] = " INSERT IGNORE INTO `#__adsmanager_fields` (`fieldid`, `name`, `title`, `description`, `type`, `maxlength`, `size`, `required`, `ordering`, `cols`, `rows`, `columnid`, `columnorder`, `pos`, `posorder`, `profile`, `cb_field`, `sort`, `sort_direction`, `published`, `options`) VALUES " . "(1, 'name', 'ADSMANAGER_FORM_NAME', '', 'text', 50, 35, 1, 0, 0, 0, -1, 5, 5, 1, 1, 41, 0, 'DESC', 1, '')," . "(2, 'email', 'ADSMANAGER_FORM_EMAIL', '', 'emailaddress', 50, 35, 1, 1, 0, 0, -1, 10, 5, 4, 1, 50, 0, 'DESC', 1, '')," . "(3, 'ad_city', 'ADSMANAGER_FORM_CITY', '', 'text', 50, 35, 0, 4, 0, 0, 3, 1, 5, 3, 1, 59, 1, 'ASC', 1, '')," . "(4, 'ad_zip', 'ADSMANAGER_FORM_ZIP', '', 'text', 6, 7, 0, 3, 0, 0, -1, 0, 5, 2, 1, -1, 0, 'ASC', 1, '')," . "(5, 'ad_headline', 'ADSMANAGER_FORM_AD_HEADLINE', '', 'text', 60, 35, 1, 5, 0, 0, -1, 0, 1, 1, 0, -1, 0, 'DESC', 1, '')," . "(6, 'ad_text', 'ADSMANAGER_FORM_AD_TEXT', '', 'textarea', 500, 0, 1, 6, 40, 20, -1, 0, 3, 1, 0, -1, 0, 'DESC', 1, '')," . "(7, 'ad_phone', 'ADSMANAGER_FORM_PHONE1', '', 'number', 50, 35, 0, 2, 0, 0, -1, 0, 5, 1, 1, -1, 0, 'DESC', 1, '')," . "(8, 'ad_kindof', 'ADSMANAGER_FORM_KINDOF', '', 'select', 0, 0, 1, 7, 0, 0, 5, 0, 2, 1, 0, -1, 0, 'DESC', 1, '')," . "(9, 'ad_state', 'ADSMANAGER_FORM_STATE', '', 'select', 0, 0, 1, 8, 0, 0, 5, 0, 2, 1, 0, -1, 0, 'DESC', 1, '')," . "(10, 'ad_price', 'ADSMANAGER_FORM_AD_PRICE', '', 'price', 10, 7, 1, 9, 0, 0, 2, 0, 4, 1, 0, -1, 1, 'DESC', 1, '{\"currency_symbol\":\"\\\\u20ac\",\"currency_position\":\"after\",\"currency_number_decimals\":\"2\",\"currency_decimal_separator\":\".\",\"currency_thousands_separator\":\" \"}');";
            $queries[] = " UPDATE #__adsmanager_fields SET catsid = ',-1,'";
            $queries[] = " INSERT IGNORE INTO `#__adsmanager_positions` (`id`,`name`,`title`) VALUES " . " (1, 'top', 'ADSMANAGER_POSITION_TOP')," . " (2, 'subtitle', 'ADSMANAGER_POSITION_SUBTITLE')," . " (3, 'description', 'ADSMANAGER_POSITION_DESCRIPTION')," . " (4, 'description2', 'ADSMANAGER_POSITION_DESCRIPTION2')," . " (5, 'contact', 'ADSMANAGER_POSITION_CONTACT');";
            $queries[] = " ALTER IGNORE TABLE `#__adsmanager_ads` ADD `name` TEXT DEFAULT NULL;";
            $queries[] = " ALTER IGNORE TABLE `#__adsmanager_ads` ADD `ad_zip` TEXT DEFAULT NULL;";
            $queries[] = " ALTER IGNORE TABLE `#__adsmanager_ads` ADD `ad_city` TEXT DEFAULT NULL;";
            $queries[] = " ALTER IGNORE TABLE `#__adsmanager_ads` ADD `ad_phone` TEXT DEFAULT NULL;";
            $queries[] = " ALTER IGNORE TABLE `#__adsmanager_ads` ADD `email` TEXT DEFAULT NULL;";
            $queries[] = " ALTER IGNORE TABLE `#__adsmanager_ads` ADD `ad_kindof` TEXT DEFAULT NULL;";
            $queries[] = " ALTER IGNORE TABLE `#__adsmanager_ads` ADD `ad_headline` TEXT DEFAULT NULL;";
            $queries[] = " ALTER IGNORE TABLE `#__adsmanager_ads` ADD `ad_text` TEXT DEFAULT NULL;";
            $queries[] = " ALTER IGNORE TABLE `#__adsmanager_ads` CHANGE `ad_state` `ad_state` TEXT DEFAULT NULL;";
            $queries[] = " ALTER IGNORE TABLE `#__adsmanager_ads` ADD `ad_price` TEXT DEFAULT NULL;";
            $queries[] = "ALTER IGNORE TABLE `#__adsmanager_profile` ADD `name` TEXT DEFAULT NULL;";
            $queries[] = "ALTER IGNORE TABLE  `#__adsmanager_profile` ADD `ad_zip` TEXT DEFAULT NULL;";
            $queries[] = "ALTER IGNORE TABLE `#__adsmanager_profile` ADD `ad_city` TEXT DEFAULT NULL;";
            $queries[] = "ALTER IGNORE TABLE `#__adsmanager_profile` ADD `ad_phone` TEXT NOT NULL;";
            $queries[] = " INSERT IGNORE INTO `#__adsmanager_categories` (`id`,`parent`,`name`,`published`) VALUES " . " (1, 0,'Category 1', 1)," . " (2, 0,'Category 2', 1)," . " (3, 1,'SubCat1', 1)," . " (4, 1,'SubCat2', 1)," . " (5, 1,'SubCat3', 1)," . " (6, 2,'SubCat4', 1)," . " (7, 2,'SubCat5', 1)," . " (8, 2,'SubCat6', 1);";
            foreach ($queries as $query) {
                $db->setQuery($query);
                try {
                    $result = $db->query();
                } catch (Exception $e) {
                }
            }
        }
        $queries = array();
        $queries[] = "ALTER IGNORE TABLE `#__adsmanager_fields` CHANGE `catsid` `catsid` TEXT NOT NULL;";
        $queries[] = "ALTER IGNORE TABLE `#__adsmanager_columns` CHANGE `catsid` `catsid` TEXT NOT NULL;";
        $queries[] = "ALTER IGNORE TABLE `#__adsmanager_ads` CHANGE `date_created` `date_created` DATETIME NOT NULL;";
        $queries[] = "ALTER IGNORE TABLE  `#__adsmanager_config` ADD `bannedwords` TEXT DEFAULT NULL;";
        $queries[] = "ALTER IGNORE TABLE  `#__adsmanager_config` ADD `replaceword` TEXT DEFAULT NULL;";
        $queries[] = "ALTER IGNORE TABLE  `#__adsmanager_config` ADD `after_expiration` TEXT DEFAULT NULL;";
        $queries[] = "ALTER IGNORE TABLE  `#__adsmanager_config` ADD `archive_catid` INT(10) NOT NULL default '1';";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_ads` ADD `metadata_description` TEXT DEFAULT NULL;";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_ads` ADD `metadata_keywords` TEXT DEFAULT NULL;";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_categories` ADD `metadata_description` TEXT DEFAULT NULL;";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_categories` ADD `metadata_keywords` TEXT DEFAULT NULL;";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `metadata_mode` TEXT DEFAULT NULL;";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `autocomplete` tinyint(1) default '1';";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `jquery` tinyint(1) default '1';";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `jqueryui` tinyint(1) default '1';";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `nb_last_cols` int(10) NOT NULL default '3';";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `nb_last_rows` int(10) NOT NULL default '1';";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `display_general_menu` tinyint(1) default '1';";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `display_list_sort` tinyint(1) default '1';";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `display_list_search` tinyint(1) default '1';";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `display_inner_pathway` tinyint(1) default '1';";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `display_front` tinyint(1) default '1';";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `send_email_on_new_to_user` tinyint(1) default '1';";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `send_email_on_update_to_user` tinyint(1) default '1';";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `send_email_on_validation_to_user` tinyint(1) default '1';";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `send_email_on_expiration_to_user` tinyint(1) default '1';";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `new_text` TEXT DEFAULT NULL;";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `update_text` TEXT DEFAULT NULL;";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `admin_new_text` TEXT DEFAULT NULL;";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `admin_update_text` TEXT DEFAULT NULL;";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `waiting_validation_text` TEXT DEFAULT NULL;";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `validation_text` TEXT DEFAULT NULL;";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `expiration_text` TEXT DEFAULT NULL;";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `new_subject` TEXT DEFAULT NULL;";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `update_subject` TEXT DEFAULT NULL;";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `admin_new_subject` TEXT DEFAULT NULL;";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `admin_update_subject` TEXT DEFAULT NULL;";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `waiting_validation_subject` TEXT DEFAULT NULL;";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `validation_subject` TEXT DEFAULT NULL;";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `expiration_subject` TEXT DEFAULT NULL;";
        $queries[] = " ALTER IGNORE TABLE `#__adsmanager_config` ADD `recall_subject` TEXT DEFAULT NULL;";
        $queries[] = "INSERT IGNORE INTO `#__adsmanager_positions` VALUES (6, 'description3', 'ADSMANAGER_POSITION_DESCRIPTION3');";
        $queries[] = " CREATE TABLE IF NOT EXISTS `#__adsmanager_pending_ads` (\n\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t  `userid` int(11) NOT NULL,\n\t  `date` date NOT NULL,\n\t  `content` text NOT NULL,\n\t  `contentid` int(11) NOT NULL,\n\t  PRIMARY KEY (`id`)\n\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
        foreach ($queries as $query) {
            $db->setQuery($query);
            try {
                $result = $db->query();
            } catch (Exception $e) {
            }
        }
        //We change the type of the show_contact column no matter what
        $queries = array();
        $queries[] = "ALTER IGNORE TABLE `#__adsmanager_config` MODIFY `show_contact` TEXT NULL;";
        foreach ($queries as $q) {
            $db->setQuery($q);
            try {
                $result = $db->query();
            } catch (Exception $e) {
            }
        }
        $db->setQuery(" SELECT new_subject FROM `#__adsmanager_config` WHERE id=1;");
        $new_subject = $db->loadResult();
        if ($new_subject == null) {
            $queries = array();
            $queries[] = "UPDATE #__adsmanager_config SET new_subject = " . $db->Quote(JText::_('ADSMANAGER_NEW_SUBJECT_EXAMPLE'));
            $queries[] = "UPDATE #__adsmanager_config SET update_subject = " . $db->Quote(JText::_('ADSMANAGER_UPDATE_SUBJECT_EXAMPLE'));
            $queries[] = "UPDATE #__adsmanager_config SET expiration_subject = " . $db->Quote(JText::_('ADSMANAGER_EXPIRATION_SUBJECT_EXAMPLE'));
            $queries[] = "UPDATE #__adsmanager_config SET recall_subject = " . $db->Quote(JText::_('ADSMANAGER_RECALL_SUBJECT_EXAMPLE'));
            $queries[] = "UPDATE #__adsmanager_config SET waiting_validation_subject = " . $db->Quote(JText::_('ADSMANAGER_WAITING_VALIDATION_SUBJECT_EXAMPLE'));
            $queries[] = "UPDATE #__adsmanager_config SET validation_subject = " . $db->Quote(JText::_('ADSMANAGER_VALIDATION_SUBJECT_EXAMPLE'));
            $queries[] = "UPDATE #__adsmanager_config SET admin_new_subject = " . $db->Quote(JText::_('ADSMANAGER_ADMIN_NEW_SUBJECT_EXAMPLE'));
            $queries[] = "UPDATE #__adsmanager_config SET admin_update_subject = " . $db->Quote(JText::_('ADSMANAGER_ADMIN_UPDATE_SUBJECT_EXAMPLE'));
            $queries[] = "UPDATE #__adsmanager_config SET new_text = " . $db->Quote(JText::_('ADSMANAGER_NEW_TEXT_EXAMPLE'));
            $queries[] = "UPDATE #__adsmanager_config SET update_text = " . $db->Quote(JText::_('ADSMANAGER_UPDATE_TEXT_EXAMPLE'));
            $queries[] = "UPDATE #__adsmanager_config SET expiration_text = " . $db->Quote(JText::_('ADSMANAGER_EXPIRATION_TEXT_EXAMPLE'));
            $queries[] = "UPDATE #__adsmanager_config SET recall_text = " . $db->Quote(JText::_('ADSMANAGER_RECALL_TEXT_EXAMPLE'));
            $queries[] = "UPDATE #__adsmanager_config SET waiting_validation_text = " . $db->Quote(JText::_('ADSMANAGER_WAITING_VALIDATION_TEXT_EXAMPLE'));
            $queries[] = "UPDATE #__adsmanager_config SET validation_text = " . $db->Quote(JText::_('ADSMANAGER_VALIDATION_TEXT_EXAMPLE'));
            $queries[] = "UPDATE #__adsmanager_config SET admin_new_text = " . $db->Quote(JText::_('ADSMANAGER_ADMIN_NEW_TEXT_EXAMPLE'));
            $queries[] = "UPDATE #__adsmanager_config SET admin_update_text = " . $db->Quote(JText::_('ADSMANAGER_ADMIN_UPDATE_TEXT_EXAMPLE'));
            foreach ($queries as $q) {
                $db->setQuery($q);
                try {
                    $result = $db->query();
                } catch (Exception $e) {
                }
            }
        }
        $db->setQuery("SELECT * FROM #__adsmanager_config LIMIT 1");
        $config = $db->loadObject();
        $db->setQuery("ALTER IGNORE TABLE `#__adsmanager_ads` ADD `images` TEXT;");
        try {
            $result = $db->query();
        } catch (Exception $e) {
        }
        if ($config == null) {
            $db->setQuery(" INSERT IGNORE INTO `#__adsmanager_config` (`id`,`version`,`ads_per_page`,`max_image_size`,`max_width`,`max_height`,`max_width_t`,`max_height_t`,`root_allowed`,`nb_images`," . " `show_contact`,`send_email_on_new`,`send_email_on_update`,`auto_publish`,`tag`,`fronttext`,`comprofiler`,`email_display`,`rules_text`," . " `display_expand`,`display_last`,`display_fullname`,`expiration`,`ad_duration`,`recall`,`recall_time`,`recall_text`,`image_display`," . " `cat_max_width`,`cat_max_height`,`cat_max_width_t`,`cat_max_height_t`,`submission_type`,`nb_ads_by_user`,`allow_attachement`," . " `allow_contact_by_pms`, `show_rss` ,`nbcats` ,`show_new`,`nbdays_new`,`show_hot`,`nbhits`,`bannedwords`,`replaceword`,`after_expiration`,`archive_catid`,`metadata_mode`) VALUES " . " (1, '3', 20, 2048000, 400, 300, 150, 100, 1,2," . "  1,1,1,1, 'Juloa.com', '<p align=\"center\"><strong>Welcome to Ads Section.</strong></p><p align=\"left\">The better place to sell or buy</p>',0,0,'Inform the users about the rules here...'," . "  2,1,0,1,30,1,7,'Add This Text to recall message<br />','default'," . "  150,150,30,30,0,-1,0," . "  0,0,1,1,5,1,100,'','****','delete','0','automatic')");
            try {
                $result = $db->query();
            } catch (Exception $e) {
            }
        } else {
            $continue = true;
            while ($continue) {
                $continue = false;
                switch ($config->version) {
                    case 15:
                        break;
                    case 14:
                        $queries = array();
                        $queries[] = "CREATE TABLE IF NOT EXISTS `#__adsmanager_tags` (\n\t\t\t\t\t\t\t\t\ttype varchar(50) default NULL,\n\t\t\t\t\t\t\t\t\tvalue varchar(255) default NULL,\n\t\t\t\t\t\t\t\t\tPRIMARY KEY  (`type`,`value`)\n\t\t\t\t\t\t\t\t) DEFAULT CHARACTER SET utf8;";
                        foreach ($queries as $q) {
                            $db->setQuery($q);
                            try {
                                $result = $db->query();
                            } catch (Exception $e) {
                            }
                        }
                        $obj = new stdClass();
                        $obj->id = 1;
                        $obj->version = 15;
                        $db->updateObject('#__adsmanager_config', $obj, 'id');
                        $config->version = 15;
                        $continue = true;
                        break;
                    case 13:
                        $queries = array();
                        $queries[] = "ALTER TABLE `#__adsmanager_ads` ENGINE = MYISAM";
                        foreach ($queries as $q) {
                            $db->setQuery($q);
                            try {
                                $result = $db->query();
                            } catch (Exception $e) {
                            }
                        }
                        $obj = new stdClass();
                        $obj->id = 1;
                        $obj->version = 14;
                        $db->updateObject('#__adsmanager_config', $obj, 'id');
                        $config->version = 14;
                        $continue = true;
                        break;
                    case 12:
                        $queries = array();
                        $queries[] = "CREATE TABLE IF NOT EXISTS `#__adsmanager_pending_mails` (\n                                    `id` int(11) NOT NULL AUTO_INCREMENT,\n                                    `from` varchar(255) NOT NULL,\n                                    `fromname` varchar(255) NOT NULL,\n                                    `recipient` text NOT NULL,\n                                    `created_on` datetime NOT NULL,\n                                    `subject` text NOT NULL,\n                                    `body` text NOT NULL,\n                                    `statut` tinyint(1) NOT NULL default 0,\n                                    PRIMARY KEY (`id`)\n                                  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
                        foreach ($queries as $q) {
                            $db->setQuery($q);
                            try {
                                $result = $db->query();
                            } catch (Exception $e) {
                            }
                        }
                        $obj = new stdClass();
                        $obj->id = 1;
                        $obj->version = 13;
                        $db->updateObject('#__adsmanager_config', $obj, 'id');
                        $config->version = 13;
                        $continue = true;
                        break;
                    case 11:
                        $queries = array();
                        $queries[] = "CREATE TABLE IF NOT EXISTS `#__adsmanager_favorite` (\n                                    `adid` int(10) unsigned NOT NULL ,\n                                    `userid` int(10) unsigned NOT NULL ,\n                                    PRIMARY KEY  (`adid`,`userid`)\n                                  ) DEFAULT CHARACTER SET utf8;";
                        foreach ($queries as $q) {
                            $db->setQuery($q);
                            try {
                                $result = $db->query();
                            } catch (Exception $e) {
                            }
                        }
                        $obj = new stdClass();
                        $obj->id = 1;
                        $obj->version = 12;
                        $db->updateObject('#__adsmanager_config', $obj, 'id');
                        $config->version = 12;
                        $continue = true;
                        break;
                    case 10:
                        $sql = "SELECT show_contact FROM #__adsmanager_config LIMIT 0,1";
                        $db->setQuery($sql);
                        $result = $db->loadObject();
                        if ($result->show_contact == 1) {
                            $sql = "SELECT id FROM #__usergroups WHERE title != 'Public'";
                            $db->setQuery($sql);
                            $results = $db->loadObjectList();
                        } else {
                            $sql = "SELECT id FROM #__usergroups";
                            $db->setQuery($sql);
                            $results = $db->loadObjectList();
                        }
                        $usergroups = array();
                        foreach ($results as $result) {
                            $usergroups[] = $result->id;
                        }
                        $usergroups = implode(',', $usergroups);
                        $queries = array();
                        $queries[] = "ALTER IGNORE TABLE `#__adsmanager_config` MODIFY `show_contact` TEXT NULL;";
                        $queries[] = "UPDATE `#__adsmanager_config` SET `show_contact` = '" . $usergroups . "';";
                        foreach ($queries as $q) {
                            $db->setQuery($q);
                            try {
                                $result = $db->query();
                            } catch (Exception $e) {
                            }
                        }
                        $obj = new stdClass();
                        $obj->id = 1;
                        $obj->version = 11;
                        $db->updateObject('#__adsmanager_config', $obj, 'id');
                        $config->version = 11;
                        $continue = true;
                        break;
                    case 9:
                        $queries = array();
                        $queries[] = "ALTER IGNORE TABLE `#__adsmanager_categories` ADD `limitads` INT(11) default '-1';";
                        $queries[] = "ALTER IGNORE TABLE `#__adsmanager_ads` ADD `publication_date` DATETIME NOT NULL;";
                        foreach ($queries as $q) {
                            $db->setQuery($q);
                            try {
                                $result = $db->query();
                            } catch (Exception $e) {
                            }
                        }
                        $obj = new stdClass();
                        $obj->id = 1;
                        $obj->version = 10;
                        $db->updateObject('#__adsmanager_config', $obj, 'id');
                        $config->version = 10;
                        $continue = true;
                        break;
                    case 8:
                        $queries = array();
                        $queries[] = "ALTER IGNORE TABLE `#__adsmanager_categories` ADD `limitads` INT(11) default '-1';";
                        $queries[] = "ALTER IGNORE TABLE `#__adsmanager_categories` ADD `usergroupsread` TEXT NOT NULL;";
                        $queries[] = "ALTER IGNORE TABLE `#__adsmanager_categories` ADD `usergroupswrite` TEXT NOT NULL;";
                        foreach ($queries as $q) {
                            $db->setQuery($q);
                            try {
                                $result = $db->query();
                            } catch (Exception $e) {
                            }
                        }
                        $obj = new stdClass();
                        $obj->id = 1;
                        $obj->version = 9;
                        $db->updateObject('#__adsmanager_config', $obj, 'id');
                        $config->version = 9;
                        $continue = true;
                        break;
                    case 7:
                        $q = "SELECT params FROM #__adsmanager_config";
                        $db->setQuery($q);
                        $json_params = $db->loadResult();
                        $params = json_decode($json_params);
                        if ($params == null) {
                            $params = new stdClass();
                        }
                        if (!isset($params->email_admin) || $params->email_admin == '') {
                            if (version_compare(JVERSION, '3.0.2', '>=')) {
                                $versionJoomla = 1;
                            } else {
                                $versionJoomla = 0;
                            }
                            $config = JFactory::getConfig();
                            $params->email_admin = $versionJoomla ? $config->get('mailfrom') : $config->getValue('config.mailfrom');
                            $params->name_admin = $versionJoomla ? $config->get('fromname') : $config->getValue('config.fromname');
                            $json_params = json_encode($params);
                            $q = "UPDATE #__adsmanager_config\n                            SET params = " . $db->Quote($json_params);
                            $db->setQuery($q);
                            try {
                                $result = $db->query();
                            } catch (Exception $e) {
                            }
                        }
                        $obj = new stdClass();
                        $obj->id = 1;
                        $obj->version = 8;
                        $db->updateObject('#__adsmanager_config', $obj, 'id');
                        $config->version = 8;
                        $continue = true;
                        break;
                    case 6:
                        $q = "ALTER IGNORE TABLE `#__adsmanager_categories` MODIFY `description` text;";
                        $db->setQuery($q);
                        try {
                            $result = $db->query();
                        } catch (Exception $e) {
                        }
                        $obj = new stdClass();
                        $obj->id = 1;
                        $obj->version = 7;
                        $db->updateObject('#__adsmanager_config', $obj, 'id');
                        $config->version = 7;
                        $continue = true;
                        break;
                    case 5:
                        $app = JFactory::getApplication();
                        $db->setQuery("SELECT count(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '" . $app->getCfg('db') . "' AND TABLE_NAME = '" . $db->getPrefix() . "adsmanager_fieldgmap_conf'");
                        $count = $db->loadResult();
                        if ($count > 0) {
                            $db->setQuery("SELECT fieldid,name FROM #__adsmanager_fields WHERE type='gmap'");
                            $fields = $db->loadObjectList("fieldid");
                            $queries = array();
                            foreach ($fields as $field) {
                                $queries[] = "ALTER IGNORE TABLE `#__adsmanager_ads` ADD `" . $field->name . "_lat` FLOAT default NULL;";
                                $queries[] = "ALTER IGNORE TABLE `#__adsmanager_ads` ADD `" . $field->name . "_lng` FLOAT default NULL;";
                                $queries[] = "ALTER IGNORE TABLE `#__adsmanager_ads` ADD `" . $field->name . "_zoom` int(10) unsigned default 8;";
                                $queries[] = "ALTER IGNORE TABLE `#__adsmanager_ads` ADD `" . $field->name . "_hide` int(1) unsigned default 0;";
                                $queries[] = "ALTER IGNORE TABLE `#__adsmanager_profile` ADD `" . $field->name . "_lat` FLOAT default NULL;";
                                $queries[] = "ALTER IGNORE TABLE `#__adsmanager_profile` ADD `" . $field->name . "_lng` FLOAT default NULL;";
                                $queries[] = "ALTER IGNORE TABLE `#__adsmanager_profile` ADD `" . $field->name . "_zoom` int(10) unsigned default 8;";
                                $queries[] = "ALTER IGNORE TABLE `#__adsmanager_profile` ADD `" . $field->name . "_hide` int(1) unsigned default 0;";
                                //Patch for an old error in the update file (TEXT instead of FLOAT)
                                $queries[] = "ALTER IGNORE TABLE `#__adsmanager_ads` MODIFY `" . $field->name . "_lat` FLOAT default NULL;";
                                $queries[] = "ALTER IGNORE TABLE `#__adsmanager_ads` MODIFY `" . $field->name . "_lng` FLOAT default NULL;";
                                $queries[] = "ALTER IGNORE TABLE `#__adsmanager_ads` MODIFY `" . $field->name . "_zoom` int(10) unsigned default 8;";
                                $queries[] = "ALTER IGNORE TABLE `#__adsmanager_ads` MODIFY `" . $field->name . "_hide` int(1) unsigned default 0;";
                                $queries[] = "ALTER IGNORE TABLE `#__adsmanager_profile` MODIFY `" . $field->name . "_lat` FLOAT default NULL;";
                                $queries[] = "ALTER IGNORE TABLE `#__adsmanager_profile` MODIFY `" . $field->name . "_lng` FLOAT default NULL;";
                                $queries[] = "ALTER IGNORE TABLE `#__adsmanager_profile` MODIFY `" . $field->name . "_zoom` int(10) unsigned default 8;";
                                $queries[] = "ALTER IGNORE TABLE `#__adsmanager_profile` MODIFY `" . $field->name . "_hide` int(1) unsigned default 0;";
                            }
                            foreach ($queries as $q) {
                                $db->setQuery($q);
                                try {
                                    $result = $db->query();
                                } catch (Exception $e) {
                                }
                            }
                        }
                        $obj = new stdClass();
                        $obj->id = 1;
                        $obj->version = 6;
                        $db->updateObject('#__adsmanager_config', $obj, 'id');
                        $config->version = 6;
                        $continue = true;
                        break;
                    case 4:
                        $db->setQuery("SELECT id,images FROM `#__adsmanager_ads`");
                        $ads = $db->loadObjectList("id");
                        foreach ($ads as $ad) {
                            $images = json_decode($ad->images);
                            $change = 0;
                            if (count($images) > 1) {
                                foreach ($images as $key => $image) {
                                    if (!isset($image->medium)) {
                                        $images[$key]->medium = $image->thumbnail;
                                        $change = 1;
                                    }
                                }
                            }
                            if ($change == 1) {
                                $obj = new stdClass();
                                $obj->id = $ad->id;
                                $obj->images = json_encode($images);
                                $ret = $db->updateObject('#__adsmanager_ads', $obj, 'id');
                            }
                        }
                        $db->setQuery(" ALTER IGNORE TABLE `#__adsmanager_config` ADD `special` TEXT DEFAULT NULL;");
                        try {
                            $result = $db->query();
                        } catch (Exception $e) {
                        }
                        $obj = new stdClass();
                        $obj->id = 1;
                        $obj->version = 5;
                        $db->updateObject('#__adsmanager_config', $obj, 'id');
                        $config->version = 5;
                        $continue = true;
                        break;
                    case 3:
                        $db->setQuery(" ALTER IGNORE TABLE `#__adsmanager_config` ADD `params` TEXT DEFAULT NULL;");
                        try {
                            $result = $db->query();
                        } catch (Exception $e) {
                        }
                        $db->setQuery(" ALTER IGNORE TABLE `#__adsmanager_fields` ADD `options` TEXT DEFAULT NULL;");
                        try {
                            $result = $db->query();
                        } catch (Exception $e) {
                        }
                        $obj = new stdClass();
                        $obj->id = 1;
                        $obj->version = 4;
                        $db->updateObject('#__adsmanager_config', $obj, 'id');
                        $config->version = 4;
                        $continue = true;
                        break;
                    case 2:
                        $db->setQuery("ALTER IGNORE TABLE `#__adsmanager_ads` ADD `date_modified` DATETIME;");
                        try {
                            $result = $db->query();
                        } catch (Exception $e) {
                        }
                        $db->setQuery("UPDATE `#__adsmanager_ads` SET `date_modified` = `date_created`");
                        try {
                            $result = $db->query();
                        } catch (Exception $e) {
                        }
                        $obj = new stdClass();
                        $obj->id = 1;
                        $obj->version = 3;
                        $db->updateObject('#__adsmanager_config', $obj, 'id');
                        $config->version = 3;
                        $continue = true;
                        break;
                    default:
                        $db->setQuery("SELECT id,images FROM `#__adsmanager_ads`");
                        $ads = $db->loadObjectList("id");
                        $imagefiles = scandir(JPATH_ROOT . "/images/com_adsmanager/ads/");
                        $lists = array();
                        sort($imagefiles);
                        foreach ($imagefiles as $imagefile) {
                            if (preg_match("/([0-9]*)[a-z ]*_t.jpg/", $imagefile, $matches)) {
                                $id = $matches[1];
                                if (!isset($lists[$id])) {
                                    $lists[$id] = array();
                                }
                                $newimg = new stdClass();
                                $newimg->index = count($lists[$id]) + 1;
                                $newimg->image = str_replace('_t.jpg', '.jpg', $imagefile);
                                $newimg->thumbnail = $imagefile;
                                $newimg->medium = str_replace('_t.jpg', '.jpg', $imagefile);
                                $lists[$id][] = $newimg;
                            }
                        }
                        foreach ($lists as $id => $list) {
                            $obj = new stdClass();
                            $obj->id = $id;
                            $obj->images = json_encode($list);
                            $ret = $db->updateObject('#__adsmanager_ads', $obj, 'id');
                        }
                        $app = JFactory::getApplication();
                        $db->setQuery("SELECT count(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '" . $app->getCfg('db') . "' AND TABLE_NAME = '" . $db->getPrefix() . "adsmanager_fieldgmap'");
                        $count = $db->loadResult();
                        if ($count > 0) {
                            $db->setQuery("SELECT fieldid,name FROM #__adsmanager_fields WHERE type='gmap'");
                            $fields = $db->loadObjectList("fieldid");
                            foreach ($fields as $field) {
                                $query = "ALTER IGNORE TABLE `#__adsmanager_ads` ADD `" . $field->name . "_lat` FLOAT default NULL;";
                                $db->setQuery($query);
                                try {
                                    $result = $db->query();
                                } catch (Exception $e) {
                                }
                                $query = "ALTER IGNORE TABLE `#__adsmanager_ads` ADD `" . $field->name . "_lng` FLOAT default NULL;";
                                $db->setQuery($query);
                                try {
                                    $result = $db->query();
                                } catch (Exception $e) {
                                }
                            }
                            $db->setQuery("SELECT * FROM #__adsmanager_fieldgmap");
                            $list = $db->loadObjectList();
                            $fields = array();
                            if ($list != null) {
                                foreach ($list as $item) {
                                    $name = $fields[$item->fieldid];
                                    $obj = new stdClass();
                                    $obj->id = $item->contentid;
                                    $lat = $name . "_lat";
                                    $obj->{$lat} = $item->lat;
                                    $lng = $name . "_lng";
                                    $obj->{$lng} = $item->lng;
                                    $db->updateObject('#__adsmanager_ads', $obj, 'id');
                                }
                            }
                            $db->setQuery("DROP TABLE #__adsmanager_fieldgmap");
                            try {
                                $result = $db->query();
                            } catch (Exception $e) {
                            }
                        }
                        $app = JFactory::getApplication();
                        $db->setQuery("SELECT count(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '" . $app->getCfg('db') . "' AND TABLE_NAME = '" . $db->getPrefix() . "adsmanager_youtube'");
                        $count = $db->loadResult();
                        if ($count > 0) {
                            $db->setQuery("SELECT fieldid,name FROM #__adsmanager_fields WHERE type='youtube'");
                            $fields = $db->loadObjectList("fieldid");
                            foreach ($fields as $field) {
                                $query = "ALTER IGNORE TABLE `#__adsmanager_ads` ADD `" . $field->name . "` TEXT default NULL;";
                                $db->setQuery($query);
                                try {
                                    $result = $db->query();
                                } catch (Exception $e) {
                                }
                            }
                            $db->setQuery("SELECT * FROM #__adsmanager_youtube");
                            $list = $db->loadObjectList();
                            if ($list != null) {
                                foreach ($list as $item) {
                                    $name = @$fields[$item->fieldid]->name;
                                    if ($name != null) {
                                        $obj = new stdClass();
                                        $obj->id = $item->contentid;
                                        $obj->{$name} = $item->key;
                                        $db->updateObject('#__adsmanager_ads', $obj, 'id');
                                    }
                                }
                            }
                            $db->setQuery("DROP TABLE #__adsmanager_youtube");
                            try {
                                $result = $db->query();
                            } catch (Exception $e) {
                            }
                        }
                        $obj = new stdClass();
                        $obj->id = 1;
                        $obj->version = 2;
                        $db->updateObject('#__adsmanager_config', $obj, 'id');
                        $config->version = 2;
                        $continue = true;
                }
            }
        }
        ?>
	<center>
	<table width="100%" border="0">
	   <tr>
	      <td>
	      Thank you for using AdsManager (Juloa.com)<br/>
		 <p>
			<em>support@juloa.com</em>
		 </p>
	      </td>
	      <td>
	         <p>
	            <br>
	            <br>
	            <br>
	         </p>
	      </td>
	   </tr>
	</table>
	</center>
	
<?php 
        if (version_compare(JVERSION, '2.5', '>=') && version_compare(JVERSION, '3.0', '<')) {
            JError::$legacy = $tmp_legacy;
        }
        return true;
    }
Ejemplo n.º 6
0
	/**
	 * Returns a list of tables and the number of rows or null if the
	 * table does not exist
	 * @param $tables  An array of table names without prefix
	 * @param $prefix  The table prefix (JEM and EL tables can have a different prefix!)
	 * @return array The list of tables
	 */
	public function getTablesCount($tables, $prefix)
	{
		$db = $this->_db;

		foreach ($tables as $table => $value) {
			$query = $db->getQuery('true');

			$query->select('COUNT(*)')
			      ->from($db->quoteName($prefix.$table));

			$db->setQuery($query);

			// Set legacy to false to be able to catch DB errors.
			$legacyValue = JError::$legacy;
			JError::$legacy = false;

			try {
				$tables[$table] = $db->loadResult();
				// Don't count the root category
				if (strcasecmp($table, 'jem_categories') == 0) {
					$tables[$table]--;
				}
			} catch (Exception $e) {
				$tables[$table] = null;
			}

			JError::$legacy = $legacyValue;
		}

		return $tables;
	}
Ejemplo n.º 7
0
 function saveContent($post, $plugins)
 {
     if (version_compare(JVERSION, '2.5', '>=') && version_compare(JVERSION, '3.0', '<')) {
         if (JError::$legacy) {
             $tmp_legacy = true;
         } else {
             $tmp_legacy = false;
         }
         JError::$legacy = false;
     }
     $fieldNames = @$post['vNames'];
     $fieldValues = @$post['vValues'];
     $fieldImagesSelect = @$post['vSelectImages'];
     $fieldImagesValues = @$post['vImagesValues'];
     $j = 1;
     if ($this->fieldid > 0) {
         /*$this->_db->setQuery( "DELETE FROM #__adsmanager_field_values"
         		. " WHERE fieldid='".(int)$this->fieldid."'" );*/
         $this->_db->setQuery("SELECT * FROM #__adsmanager_field_values" . " WHERE fieldid='" . (int) $this->fieldid . "'");
         $existingvalues = $this->_db->loadObjectList('fieldvalue');
     } else {
         $this->_db->setQuery("SELECT MAX(fieldid) FROM #__adsmanager_fields");
         $maxID = $this->_db->loadResult();
         $this->fieldid = $maxID;
         $existingvalues = array();
     }
     $options_tag = $this->type;
     //To erase previous values in case of update
     $listnewvalues = array();
     switch ($this->type) {
         case "select":
         case "multiselect":
         case "radio":
         case "multicheckbox":
         case "price":
         case "number":
             $options_tag = "multiple";
             $j = 0;
             $i = 0;
             while (isset($fieldNames[$i])) {
                 $fieldName = trim($fieldNames[$i]);
                 $fieldValue = trim($fieldValues[$i]);
                 $i++;
                 if ($fieldName != null) {
                     $obj = new stdClass();
                     $obj->fieldtitle = $fieldName;
                     $obj->fieldvalue = $fieldValue;
                     $obj->ordering = $j;
                     $obj->fieldid = $this->fieldid;
                     $listnewvalues[] = $this->_db->Quote($fieldValue);
                     if (isset($existingvalues[$fieldValue])) {
                         $obj->fieldvalueid = $existingvalues[$fieldValue]->fieldvalueid;
                         $this->_db->updateObject('#__adsmanager_field_values', $obj, 'fieldvalueid');
                     } else {
                         $this->_db->insertObject('#__adsmanager_field_values', $obj);
                     }
                     $j++;
                 }
             }
             break;
         case 'radioimage':
         case 'multicheckboximage':
             $j = 0;
             $i = 0;
             while (isset($fieldImagesSelect[$i])) {
                 $fieldName = trim($fieldImagesSelect[$i]);
                 $fieldValue = trim($fieldImagesValues[$i]);
                 $i++;
                 if ($fieldName != null) {
                     $obj = new stdClass();
                     $obj->fieldtitle = $fieldName;
                     $obj->fieldvalue = $fieldValue;
                     $obj->ordering = $j;
                     $obj->fieldid = $this->fieldid;
                     $listnewvalues[] = $this->_db->Quote($fieldValue);
                     if (isset($existingvalues[$fieldValue])) {
                         $obj->fieldvalueid = $existingvalues[$fieldValue]->fieldvalueid;
                         $this->_db->updateObject('#__adsmanager_field_values', $obj, 'fieldvalueid');
                     } else {
                         $this->_db->insertObject('#__adsmanager_field_values', $obj);
                     }
                     $j++;
                 }
             }
             break;
     }
     //If they was previous values then erase old values no more present
     if (count($listnewvalues) > 0 && count($existingvalues) > 0) {
         $this->_db->setQuery("DELETE FROM #__adsmanager_field_values \n\t\t\t\t\t\t\t      WHERE fieldid = " . $this->fieldid . " \n\t\t\t\t\t              AND fieldvalue NOT IN (" . implode(',', $listnewvalues) . ")");
         $this->_db->query();
     }
     $field_catsid = $post['field_catsid'];
     if (!is_array($field_catsid)) {
         $field_catsid = array();
     }
     $field_catsid = "," . implode(',', $field_catsid) . ",";
     if ($field_catsid != "") {
         $query = "UPDATE #__adsmanager_fields SET catsid =" . $this->_db->Quote($field_catsid) . " WHERE fieldid=" . (int) $this->fieldid;
         $this->_db->setQuery($query);
         $this->_db->query();
     }
     if (isset($plugins["{$this->type}"])) {
         $options = $plugins["{$this->type}"]->saveFieldOptions($this);
         if ($options == null) {
             $options = array();
         }
     } else {
         $options = array();
     }
     $data = $post;
     foreach ($data as $key => $d) {
         if (strpos($key, "options_{$options_tag}_") === 0) {
             $k = substr($key, strlen("options_{$options_tag}_"));
             $options[$k] = $d;
         }
         if (strpos($key, "options_common_") === 0) {
             $k = substr($key, strlen("options_common_"));
             $options[$k] = $d;
         }
         if (strpos($key, "options_{$this->type}_") === 0) {
             $k = substr($key, strlen("options_{$this->type}_"));
             $options[$k] = $d;
         }
     }
     $data = new stdClass();
     $data->fieldid = $this->fieldid;
     $data->options = json_encode($options);
     //var_dump($options);exit();
     $this->_db->updateObject("#__adsmanager_fields", $data, "fieldid");
     $app = JFactory::getApplication();
     //Update Ad Fields
     $this->_db->setQuery("SELECT count(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '" . $app->getCfg('db') . "' AND TABLE_NAME = '" . $this->_db->getPrefix() . "adsmanager_ads' AND column_name='{$this->name}'");
     $exist = $this->_db->loadResult();
     if (!$exist) {
         $this->_db->setQuery("ALTER IGNORE TABLE #__adsmanager_ads ADD `{$this->name}` TEXT NOT NULL");
         try {
             $result = $this->_db->query();
         } catch (Exception $e) {
         }
     }
     if ($this->profile == 1) {
         //Update Profile Fields
         $this->_db->setQuery("SELECT count(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '" . $app->getCfg('db') . "' AND TABLE_NAME = '" . $this->_db->getPrefix() . "adsmanager_profile' AND column_name='{$this->name}'");
         $exist = $this->_db->loadResult();
         if (!$exist) {
             $this->_db->setQuery("ALTER IGNORE TABLE #__adsmanager_profile ADD `{$this->name}` TEXT NOT NULL");
             try {
                 $result = $this->_db->query();
             } catch (Exception $e) {
             }
         }
     } else {
         //Update Profile Fields
         $this->_db->setQuery("SELECT count(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '" . $app->getCfg('db') . "' AND TABLE_NAME = '" . $this->_db->getPrefix() . "adsmanager_profile' AND column_name='{$this->name}'");
         $exist = $this->_db->loadResult();
         if ($exist) {
             $this->_db->setQuery("ALTER IGNORE TABLE #__adsmanager_profile DROP `{$this->name}`");
             try {
                 $result = $this->_db->query();
             } catch (Exception $e) {
             }
         }
     }
     if (version_compare(JVERSION, '2.5', '>=') && version_compare(JVERSION, '3.0', '<')) {
         JError::$legacy = $tmp_legacy;
     }
 }
Ejemplo n.º 8
0
 /**
  * Returns a list of tables and the number of rows or null if the
  * table does not exist
  * @param $tables  An array of table names without prefix
  * @return array The list of tables
  */
 public function getTablesCount($tables, $prefix)
 {
     $db = JFactory::getDbo();
     $dbPrefix = $db->getPrefix();
     foreach ($tables as $table => $value) {
         $query = $db->getQuery('true');
         if ($prefix) {
             $query->select("COUNT(*)")->from($this->prefix . $table);
         } else {
             $query->select("COUNT(*)")->from($dbPrefix . $table);
         }
         $db->setQuery($query);
         // Set legacy to false to be able to catch DB errors.
         $legacyValue = JError::$legacy;
         JError::$legacy = false;
         try {
             $tables[$table] = $db->loadResult();
             // Don't count the root category
             if ($table == "jem_categories") {
                 $tables[$table]--;
             }
             JError::$legacy = $legacyValue;
         } catch (Exception $e) {
             $tables[$table] = null;
             JError::$legacy = $legacyValue;
         }
     }
     return $tables;
 }