public static function createSearchString($obj) { $str = ''; if ($obj) { foreach ($obj as $value) { if (is_scalar($value)) { $str .= strip_tags($value) . " "; } else { $str .= BrightUtils::createSearchString($value); } } } return $str; }
/** * Saves a full poly * @param OPoly $poly * @return OPoly */ public function setFullPoly($poly) { $page = new Page(); $p = $page->setPage($poly, false, false); if ($poly->pageId == 0) { $poly->pageId = $p->pageId; } $sql = 'UPDATE `gm_polys` ' . 'SET `layer`=' . (int) $poly->layer . ', ' . '`uselayercolor`=' . (int) $poly->uselayercolor . ', ' . '`enabled`=' . (int) $poly->enabled . ', ' . '`pageId`=' . (int) $poly->pageId . ', ' . '`color`=' . (int) $poly->color . ', ' . '`label`=\'' . Connection::getInstance()->escape_string($poly->label) . '\', ' . '`search`=\'' . Connection::getInstance()->escape_string(BrightUtils::createSearchString($poly)) . '\' ' . 'WHERE `polyId`=' . (int) $poly->polyId; $this->_conn->updateRow($sql); $cache = new Cache(); $cache->deleteCacheByPrefix('marker'); return $this->getPoly($poly->polyId, true); }
/** * Saves a element * @param OPage $element The element to save * @param bool $returnall * @return \stdClass An object containing element, the just saved element and elements, an array of all elements * @throws \Exception */ public function setElement($element, $returnall = true) { if (!$this->IS_AUTH) { throw $this->throwException(AuthenticationException::NO_USER_AUTH); } if (method_exists($this->_hook, 'preSetElement')) { $element = $this->_hook->preSetElement($element); } $element = $this->_page->setPage($element, false, false); if (method_exists($this->_hook, 'postSetElement')) { $this->_hook->postSetElement($element); } $c = new Cache(); $c->deleteCacheByPrefix("element_filter_"); $search = BrightUtils::createSearchString($element); $search = Connection::getInstance()->escape_string($search); $sql = "INSERT INTO pageindex (pageId, search) VALUES ({$element->pageId}, '{$search}') ON DUPLICATE KEY UPDATE search='{$search}' "; Connection::getInstance()->insertRow($sql); if (!$returnall) { return $element; } return $this->_page->getPages(4, null, true); }
/** * Creates or updates a calendar event * @param OCalendarEvent $event event The event to create or update * @param boolean $executeHook * @param boolean $updateContent When false, oContent is left untouched * @throws \Exception * @return bool */ public function setEvent(OCalendarEvent $event, $executeHook = true, $updateContent = true) { $ch = null; if (!isset($event->dates) || count($event->dates) == 0) { throw $this->throwException(EventException::NOT_ENOUGH_DATES); } $c = new Cache(); $c->deleteCacheByLabel("calendaritem_{$event->calendarId}"); $c->deleteCacheByPrefix("eventsByIdRange_"); $c->deleteCacheByPrefix('calendar_getEventsByRange'); // Execute hook if present if (class_exists('CalendarHook') && $executeHook) { $ch = new \CalendarHook(); if (method_exists($ch, 'preSetEvent')) { $event = $ch->preSetEvent($event); } } // Set modification values $aid = isset($_SESSION['administratorId']) ? $_SESSION['administratorId'] : 0; $event->createdby = $aid; $event->modifiedby = $aid; $event->label = $this->generateLabel($event->label, $event->calendarId); BrightUtils::forceInt($event, array('calendarId', 'itemType', 'createdby', 'locationId', 'modifiedby')); BrightUtils::escape($event, array('recur', 'label')); $event->enabled = $event->enabled === 1 || $event->enabled === true || $event->enabled === 'true' ? 1 : 0; $until = (double) $event->until; $event->until = date(BrightUtils::$SQLDateTime, $until); $sql = "INSERT INTO calendarnew (`calendarId`, `locationId`, `itemType`, `label`, `recur`, `until`, `enabled`, `deleted`, `creationdate`, `modificationdate`, `createdby`, `modifiedby`) VALUES (\n\t\t\t\t{$event->calendarId},\n\t\t\t\t{$event->locationId},\n\t\t\t\t{$event->itemType},\n\t\t\t\t'{$event->label}',\n\t\t\t\t'{$event->recur}',\n\t\t\t\t'{$event->until}',\n\t\t\t\t{$event->enabled},\n\t\t\t\tNULL, NOW(), NOW(),\n\t\t\t\t{$event->createdby},\n\t\t\t\t{$event->modifiedby})\n\t\t\t\tON DUPLICATE KEY UPDATE\n\t\t\t\titemType = VALUES(`itemType`),\n\t\t\t\tlocationId = VALUES(`locationId`),\n\t\t\t\tlabel = VALUES(`label`),\n\t\t\t\trecur = VALUES(`recur`),\n\t\t\t\tenabled = VALUES(`enabled`),\n\t\t\t\tuntil = VALUES(`until`),\n\t\t\t\tmodificationdate = NOW(),\n\t\t\t\tmodifiedby = VALUES(`modifiedby`),\n\t\t\t\t`calendarId`=LAST_INSERT_ID(`calendarId`)"; $event->calendarId = $this->_conn->insertRow($sql); $sql = 'UPDATE `calendardates` SET `deleted`=1 WHERE `calendarId`=' . $event->calendarId; $this->_conn->updateRow($sql); $sql = 'INSERT INTO `calendardates` (`calendarId`,`starttime`, `endtime`,`allday`,`deleted`,`noend`) VALUES '; $sqla = array(); // Store also for calendarevents $evdates = array(); foreach ($event->dates as &$date) { $date = (object) $date; if ($date->endtime < $date->starttime) { // Quick fix, just add 1 day to the endtime // We could (or should) throw an exception here, since it's not a valid range... $date->endtime = strtotime('+1 day', $date->endtime); } $starttime = date(BrightUtils::$SQLDateTime, $date->starttime); $endtime = date(BrightUtils::$SQLDateTime, $date->endtime); $date->allday = $date->allday == true ? 1 : 0; $date->noend = $date->noend == true ? 1 : 0; $sqla[] = "({$event->calendarId}, '{$starttime}','{$endtime}', {$date->allday},0, {$date->noend})"; $evdates[] = "({$event->calendarId}, '{$starttime}','{$endtime}', {$date->allday}, 0, {$date->noend})"; } $sql .= implode(",\r\n", $sqla); $sql .= ' ON DUPLICATE KEY UPDATE `allday`=VALUES(`allday`), `noend`=VALUES(`noend`), `deleted`=0'; $this->_conn->insertRow($sql); $sql = "DELETE FROM calendardates WHERE deleted=1"; $this->_conn->insertRow($sql); // Delete stored dates // $sql = 'DELETE FROM calendarevents WHERE eventId=' . (int) $event -> calendarId; // $this -> _conn -> deleteRow($sql); $sql = 'UPDATE calendareventsnew SET `deleted`=1 WHERE `calendarId`=' . (int) $event->calendarId; $this->_conn->updateRow($sql); $sql = 'INSERT INTO `calendareventsnew` (`calendarId`, `starttime`, `endtime`, `allday`, `deleted`,`noend`) VALUES '; $sqla = array(); $earr = array(); if ($event->recur && $event->recur != '') { $recur = $event->recur; // Recurring event, process it and add if needed $recarr = explode(';', $recur); $freq = ''; $interval = 0; // If recur has trailing ;, pop last item if ($recarr[count($recarr) - 1] == '') { array_pop($recarr); } foreach ($recarr as $recitem) { $recitemarr = explode('=', $recitem); $key = $recitemarr[0]; $val = $recitemarr[1]; $dayarr = null; $monthrepeat = 'dom'; switch ($key) { case 'FREQ': // Frequency, valid values are: DAILY, WEEKLY, MONTHLY, YEARLY $freq = $val; break; case 'INTERVAL': $interval = (int) $val; break; case 'BYDAY': // Difference between monthly and weekly switch ($freq) { case 'WEEKLY': $days = explode(',', $val); $dayarr = array(); // Find out which days are checked foreach ($days as $day) { switch ($day) { case 'SU': $dayarr[0] = 1; break; case 'MO': $dayarr[1] = 1; break; case 'TU': $dayarr[2] = 1; break; case 'WE': $dayarr[3] = 1; break; case 'TH': $dayarr[4] = 1; break; case 'FR': $dayarr[5] = 1; break; case 'SA': $dayarr[6] = 1; break; } } break; case 'MONTHLY': $monthrepeat = 'dow'; break; } break; case 'BYMONTHDAY': // Difference between monthly and yearly /** * @todo implement Is more implementation really needed, or is this switch just useless an could it be * replaced with an if statement. */ switch ($freq) { case 'MONTHLY': $monthrepeat = 'dom'; break; } break; } } // Add dates, if event recurs, calculate all dates $sqla[] = $evdates[0]; $evstart = $event->dates[0]->starttime; $evend = $event->dates[0]->endtime; $startenddiff = $evend - $evstart; switch ($freq) { case 'DAILY': // Easy! while ($evstart < $until) { $evstart += 86400 * $interval; $evend += 86400 * $interval; $ev = new \stdClass(); $ev->starttime = $evstart; $ev->endtime = $evend; $ev->calendarId = $event->calendarId; $earr[] = $ev; } break; case 'WEEKLY': // Get timestamp of the first day of the week $fdow = date('w', $evstart); $edow = date('w', $evend); $startweek = mktime(date('H', $evstart), date('i', $evstart), date('s', $evstart), date('n', $evstart), date('j', $evstart) - $fdow, date('Y', $evstart)); $ddow = $edow - $fdow; if ($ddow < 0) { $ddow += 7; } $first = true; while ($startweek < $until) { // On the first week, skip the sunday, because, // if the sunday is checked, it is already added before $dow = $first ? $fdow + 1 : 0; $first = false; while ($dow < 7) { if (array_key_exists($dow, $dayarr)) { $ev = new \stdClass(); $ev->starttime = mktime(date('H', $evstart), date('i', $evstart), date('s', $evstart), date('n', $startweek), date('j', $startweek) + $dow, date('Y', $startweek)); // $edow = $dow + $ddow; // if($edow < 0) // $edow +=7; $ev->endtime = mktime(date('H', $evend), date('i', $evend), date('s', $evend), date('n', $startweek), date('j', $startweek) + $dow + $ddow, date('Y', $startweek)); $ev->calendarId = $event->calendarId; if ($ev->starttime < $until) { $earr[] = $ev; } } $dow++; } $startweek += $interval * 604800; } // Now add 1 * $interval weeks and start with the first available day of dayarr break; case 'MONTHLY': if ($monthrepeat == 'dom') { // Day Of Month while ($evstart < $until) { $evstart = mktime(date('H', $evstart), date('i', $evstart), date('s', $evstart), date('n', $evstart) + $interval, date('j', $evstart), date('Y', $evstart)); $evend = mktime(date('H', $evend), date('i', $evend), date('s', $evend), date('n', $evend) + $interval, date('j', $evend), date('Y', $evend)); $ev = new \stdClass(); $ev->starttime = $evstart; $ev->endtime = $evend; $ev->calendarId = $event->calendarId; $earr[] = $ev; } } else { // Day of Week // Get the day of the week (sun - sat) $dow = date('w', $evstart); // Calculate how often that day has occured in the month (eg. the 2nd monday) $nd = ceil(date('j', $evstart) / 7); $mon = date('n', $evstart); while ($evstart < $until) { // Add the interval of months $a = $evstart = strtotime("+{$interval} month", $evstart); // Check the 'new' day of the week $newdow = date('w', $evstart); $delta = $dow - $newdow; if ($delta < 0) { $delta += 7; } // And correct it to the old dow $evstart += $delta * 86400; // We've accidently moved to the next month, correct date // by removing 1 week; if (date('m', $evstart) > date('m', $a)) { $evstart -= 7 * 86400; } // Check how often that day has occured $newnd = ceil(date('j', $evstart) / 7); // And correct it to the original occurence while ($newnd < $nd) { $evstart += 604800; $newnd++; } while ($newnd > $nd) { $evstart -= 604800; $newnd--; } $evend = $evstart + $startenddiff; $ev = new \stdClass(); $ev->starttime = $evstart; $ev->endtime = $evend; $ev->calendarId = $event->calendarId; $earr[] = $ev; } } break; case 'YEARLY': while ($evstart < $until) { $evstart = mktime(date('H', $evstart), date('i', $evstart), date('s', $evstart), date('n', $evstart), date('j', $evstart), date('Y', $evstart) + $interval); $evend = mktime(date('H', $evend), date('i', $evend), date('s', $evend), date('n', $evend), date('j', $evend), date('Y', $evend) + $interval); $ev = new \stdClass(); $ev->starttime = $evstart; $ev->endtime = $evend; $ev->calendarId = $event->calendarId; $earr[] = $ev; } break; } $ad = $event->dates[0]->allday; $ne = $event->dates[0]->noend; foreach ($earr as $ev) { if ($ev->endtime < $ev->starttime) { // Quick fix, just add 1 day to the endtime $ev->endtime = strtotime('+1 day', $ev->endtime); } $sqla[] = "({$event->calendarId},\n\t\t\t\t\t\t\t'" . date(BrightUtils::$SQLDateTime, $ev->starttime) . "',\n\t\t\t\t\t\t\t'" . date(BrightUtils::$SQLDateTime, $ev->endtime) . "',\n\t\t\t\t\t\t\t{$ad},\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t{$ne})"; } } else { $sqla = $evdates; } // Add dates to db $sql .= join(',', $sqla); $sql .= ' ON DUPLICATE KEY UPDATE starttime=VALUES(starttime), endtime=VALUES(endtime), `deleted`=0, allday=VALUES(`allday`), noend=VALUES(`noend`)'; $this->_conn->insertRow($sql); $sql = 'DELETE FROM calendareventsnew WHERE `deleted`=1 AND `calendarId`=' . (int) $event->calendarId; $this->_conn->deleteRow($sql); if ($updateContent) { $this->setContent($event, 'calendarcontent'); $search = BrightUtils::createSearchString($event); if ((int) $event->locationId > 0) { $search .= $this->conn->getField("SELECT search FROM gm_markers WHERE pageId={$event->locationId}"); } $search = Connection::getInstance()->escape_string($search); $sql = "INSERT INTO calendarindex (calendarId, search) VALUES ({$event->calendarId}, '{$search}') ON DUPLICATE KEY UPDATE search='{$search}' "; $this->_conn->insertRow($sql); } if (isset($ch) && method_exists($ch, 'postSetEvent')) { $ch->postSetEvent($event); } return true; }
/** * Checks if database updates are needed * @param string $version The version string from the Frontend */ public function check($version) { $permissions = $this->getPermissions(); $this->updatePermissions(array('IS_AUTH', 'MANAGE_ADMIN', 'MANAGE_USER', 'CREATE_PAGE', 'DELETE_PAGE', 'EDIT_PAGE', 'MOVE_PAGE', 'DELETE_FILE', 'MANAGE_TEMPLATE', 'MANAGE_SETTINGS', 'UPLOAD_FILE', 'MANAGE_MAILINGS', 'MANAGE_CALENDARS', 'MANAGE_ELEMENTS', 'MANAGE_MAPS')); $varr = explode(' ', $version); $build = (int) array_pop($varr); if (file_exists(BASEPATH . 'bright/site/hooks/UpdateHook.php')) { require_once BASEPATH . 'bright/site/hooks/UpdateHook.php'; $ch = new \UpdateHook(); if (method_exists($ch, 'update')) { $ch->update($build); } } $prevbuild = $build - 1; $this->_conn->updateRow("UPDATE `update` SET `build`={$prevbuild} WHERE `build`=99999"); $prevbuild = (int) $this->_conn->getField('SELECT MAX(`build`) FROM `update`'); if ($prevbuild >= $build) { return; } $sqla[] = 'CREATE TABLE IF NOT EXISTS `treeaccess` ( `treeId` int(11) NOT NULL, `groupId` int(11) NOT NULL, KEY `treeId` (`treeId`,`groupId`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;'; $sqla[] = 'CREATE TABLE IF NOT EXISTS `mailqueue` ( `id` int(11) NOT NULL AUTO_INCREMENT, `pageId` int(11) NOT NULL, `groups` varchar(255) CHARACTER SET utf8 NOT NULL, `dateadded` datetime NOT NULL, `issend` tinyint(4) NOT NULL DEFAULT \'0\', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;'; $sqla[] = 'CREATE TABLE IF NOT EXISTS `parsers` ( `parserId` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , `label` VARCHAR( 255 ) NOT NULL , UNIQUE (`label`) ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;'; $colcheck = "SHOW COLUMNS FROM `user` WHERE `field`='deleted'"; $field = $this->_conn->getRow($colcheck); if (strpos($field->Type, 'tinyint') !== false) { $sqla[] = "ALTER TABLE `user` CHANGE `deleted` `deleted` TINYINT( 1 ) NULL DEFAULT '0'"; $sqla[] = "UPDATE `user` SET `deleted`= null WHERE `deleted`=0"; $sqla[] = "ALTER TABLE `user` CHANGE `deleted` `deleted` VARCHAR( 50 ) NULL DEFAULT NULL"; $sqla[] = "UPDATE `user` SET `deleted`= NOW() WHERE `deleted`='1'"; $sqla[] = "ALTER TABLE `user` CHANGE `deleted` `deleted` DATETIME NULL DEFAULT NULL"; $sqla[] = "ALTER TABLE `user` ADD UNIQUE (`email` ,`deleted`)"; } $colcheck = "SHOW COLUMNS FROM `userfields` WHERE `field`='lang'"; $hasField = $this->_conn->getField($colcheck); if ($hasField == null) { $sqla[] = "ALTER TABLE `userfields` ADD `lang` VARCHAR( 3 ) NOT NULL DEFAULT 'tpl' AFTER `userId`"; $sqla[] = "ALTER TABLE `userfields` ADD `index` TINYINT( 1 ) NOT NULL DEFAULT '1' AFTER `value`"; } $colcheck = "SHOW COLUMNS FROM `page` WHERE `field`='alwayspublished'"; $hasField = $this->_conn->getField($colcheck); if ($hasField == null) { $sqla[] = "ALTER TABLE `page` CHANGE `allwayspublished` `alwayspublished` TINYINT( 1 ) NOT NULL ;"; $sqla[] = "UPDATE administrators SET settings = REPLACE(settings, 'allwayspublished', 'alwayspublished') WHERE settings LIKE '%allwayspublished%';"; } $colcheck = "SHOW COLUMNS FROM `content` WHERE `field`='deleted'"; $hasField = $this->_conn->getField($colcheck); if ($hasField == null) { $sqla[] = "ALTER TABLE `content` ADD UNIQUE (`pageId` ,`lang` ,`field` ,`index`);"; $sqla[] = "ALTER TABLE `userfields` ADD UNIQUE (`userId` ,`lang` ,`field` ,`index`);"; $sqla[] = "ALTER TABLE `content` ADD `deleted` TINYINT( 1 ) NOT NULL DEFAULT '0'"; } $sqla[] = "CREATE TABLE IF NOT EXISTS `calendarnew` (\n\t\t\t\t\t `calendarId` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t `itemType` int(11) NOT NULL,\n\t\t\t\t\t `label` varchar(255) NOT NULL,\n\t\t\t\t\t `recur` varchar(255) DEFAULT NULL,\n\t\t\t\t\t `until` datetime DEFAULT NULL,\n\t\t\t\t\t `deleted` datetime DEFAULT NULL,\n\t\t\t\t\t `creationdate` timestamp NULL DEFAULT NULL,\n\t\t\t\t\t `modificationdate` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n\t\t\t\t\t `createdby` int(11) DEFAULT NULL,\n\t\t\t\t\t `modifiedby` int(11) DEFAULT NULL,\n\t\t\t\t\t PRIMARY KEY (`calendarId`)\n\t\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"; $sqla[] = "CREATE TABLE IF NOT EXISTS `calendardates` (\n\t\t\t\t `dateId` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t `calendarId` int(11) NOT NULL,\n\t\t\t\t `starttime` TIMESTAMP NULL DEFAULT NULL,\n\t\t\t\t `endtime` TIMESTAMP NULL DEFAULT NULL,\n\t\t\t\t `allday` tinyint(1) NOT NULL DEFAULT '0',\n\t\t\t\t `deleted` tinyint(1) NOT NULL DEFAULT '0',\n\t\t\t\t PRIMARY KEY (`dateId`),\n\t\t\t\t UNIQUE KEY `calendarId` (`calendarId`,`starttime`,`endtime`)\n\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8"; $sqla[] = "CREATE TABLE IF NOT EXISTS `calendarcontent` (\n\t\t\t\t `contentId` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t `calendarId` int(11) NOT NULL,\n\t\t\t\t `lang` varchar(3) NOT NULL DEFAULT 'ALL',\n\t\t\t\t `field` varchar(20) NOT NULL,\n\t\t\t\t `value` longtext NOT NULL,\n\t\t\t\t `index` int(11) NOT NULL DEFAULT '0',\n\t\t\t\t `deleted` tinyint(1) NOT NULL DEFAULT '0',\n\t\t\t\t `searchable` tinyint(1) NOT NULL DEFAULT '0',\n\t\t\t\t PRIMARY KEY (`contentId`),\n\t\t\t\t UNIQUE KEY `callangfield` (`calendarId`,`lang`,`field`, `index`),\n\t\t\t\t KEY `lang` (`lang`,`field`),\n\t\t\t\t FULLTEXT KEY `value` (`value`)\n\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8;"; $sqla[] = "CREATE TABLE IF NOT EXISTS `calendareventsnew` (\n\t\t\t\t `eventId` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t `calendarId` int(11) NOT NULL,\n\t\t\t\t `starttime` TIMESTAMP NULL DEFAULT NULL,\n\t\t\t\t `endtime` TIMESTAMP NULL DEFAULT NULL,\n\t\t\t\t `deleted` tinyint(1) NOT NULL,\n\t\t\t\t PRIMARY KEY (`eventId`),\n \t\t\t\t `allday` TINYINT( 1 ) NOT NULL DEFAULT '0',\n\t\t\t\t UNIQUE KEY `calendarId` (`calendarId`,`starttime`,`endtime`),\n\t\t\t\t KEY `calendarId2` (`calendarId`),\n\t\t\t\t KEY `starttime` (`starttime`)\n\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8;"; $this->_performQueries($sqla); $tblcheck = "show tables like 'calendareventsnew'"; if ($this->_conn->getField($tblcheck)) { $colcheck = "SHOW COLUMNS FROM `calendareventsnew` WHERE `field`='allday'"; $hasField = $this->_conn->getField($colcheck); if ($hasField == null) { $sqla[] = "ALTER TABLE `calendareventsnew` ADD `allday` TINYINT( 1 ) NOT NULL DEFAULT '0'"; $sqla[] = "ALTER TABLE `calendareventsnew` CHANGE `starttime` `starttime` TIMESTAMP NULL DEFAULT NULL ,CHANGE `endtime` `endtime` TIMESTAMP NULL DEFAULT NULL"; } $colcheck = "SHOW COLUMNS FROM `calendareventsnew` WHERE `field`='noend'"; $hasField = $this->_conn->getField($colcheck); if ($hasField == null) { $sqla[] = "ALTER TABLE `calendareventsnew` ADD `noend` TINYINT( 1 ) NOT NULL DEFAULT '0'"; } } $tblcheck = "show tables like 'calendardates'"; if ($this->_conn->getField($tblcheck)) { $colcheck = "SHOW COLUMNS FROM `calendardates` WHERE `field`='noend'"; $hasField = $this->_conn->getField($colcheck); if ($hasField == null) { $sqla[] = "ALTER TABLE `calendardates` ADD `noend` TINYINT( 1 ) NOT NULL DEFAULT '0'"; } } $colcheck = "SHOW COLUMNS FROM `calendarnew` WHERE `field`='enabled'"; $hasField = $this->_conn->getField($colcheck); if ($hasField == null) { $sql = "ALTER TABLE `calendarnew` ADD `enabled` TINYINT( 1 ) NOT NULL DEFAULT '1' AFTER `until` , ADD INDEX ( `enabled` )"; $this->_conn->updateRow($sql); } $colcheck = "SHOW COLUMNS FROM `calendarnew` WHERE `field`='locationId'"; $hasField = $this->_conn->getField($colcheck); if ($hasField == null) { $sqla[] = "ALTER TABLE `calendarnew` ADD `locationId` INT( 11 ) NULL DEFAULT NULL AFTER `calendarId`, ADD INDEX ( `locationId` )"; } $colcheck = "SHOW COLUMNS FROM `gm_markers` WHERE `field`='enabled'"; $hasField = $this->_conn->getField($colcheck); if ($hasField == null) { $sql = "ALTER TABLE `gm_markers` ADD `enabled` TINYINT( 1 ) NOT NULL DEFAULT '1' AFTER `deleted` , ADD INDEX ( `enabled` )"; $this->_conn->updateRow($sql); $sql = "ALTER TABLE `gm_polys` ADD `enabled` TINYINT( 1 ) NOT NULL DEFAULT '1' AFTER `deleted` , ADD INDEX ( `enabled` )"; $this->_conn->updateRow($sql); } $colcheck = "SHOW COLUMNS FROM `gm_markers` WHERE `field`='street'"; $hasField = $this->_conn->getField($colcheck); if ($hasField == null) { $sql = "ALTER TABLE `gm_markers` ADD `street` VARCHAR( 255 ) NULL DEFAULT NULL ,\n\t\t\t\t\t\tADD `number` VARCHAR( 255 ) NULL DEFAULT NULL ,\n\t\t\t\t\t\tADD `zip` VARCHAR( 255 ) NULL DEFAULT NULL ,\n\t\t\t\t\t\tADD `city` VARCHAR( 255 ) NULL DEFAULT NULL ,\n\t\t\t\t\t\tADD `country` INT( 11 ) NULL DEFAULT NULL"; $this->_conn->updateRow($sql); } $colcheck = "SHOW COLUMNS FROM `gm_polys` WHERE `field`='search'"; $hasField = $this->_conn->getField($colcheck); if ($hasField == null) { $sql = "ALTER TABLE `gm_polys` ADD `search` LONGTEXT NULL , ADD FULLTEXT (`search`)"; $this->_conn->updateRow($sql); } $colcheck = "SHOW COLUMNS FROM `gm_markers` WHERE `field`='search'"; $hasField = $this->_conn->getField($colcheck); if ($hasField == null) { $sqla[] = "ALTER TABLE `gm_polys` CHANGE `pageId` `pageId` INT( 11 ) NULL DEFAULT NULL ,\nCHANGE `label` `label` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL"; $sql = "ALTER TABLE `gm_markers` ADD `search` LONGTEXT NULL , ADD FULLTEXT (`search`)"; $this->_conn->updateRow($sql); $maps = new Maps(); $lay = new Layers(); $layers = $lay->getLayers(); $markers = $this->_conn->getRows("SELECT markerId, pageId FROM gm_markers"); foreach ($markers as $marker) { if ($marker->pageId) { $sql = "SELECT `value` FROM content WHERE pageId = {$marker->pageId}"; $rows = $this->_conn->getFields($sql); $search = implode("\r\n", $rows); $search = Connection::getInstance()->escape_string($search); $sql = "UPDATE gm_markers SET `search`='{$search}' WHERE markerId={$marker->markerId}"; $this->_conn->updateRow($sql); } } } $colcheck = "SHOW COLUMNS FROM `page` WHERE `field`='creationdate'"; if ($this->_conn->getField($colcheck) == null) { $sqla[] = "ALTER TABLE `page` ADD `creationdate` TIMESTAMP NULL DEFAULT NULL ,\n\t\t\t\t\t\tADD `createdby` INT( 11 ) NULL DEFAULT NULL ,\n\t\t\t\t\t\tADD `modifiedby` INT( 11 ) NULL DEFAULT NULL"; } $colcheck = "SHOW COLUMNS FROM `backup` WHERE `field`='content'"; $c = $this->_conn->getRow($colcheck); if ($c->Type == 'text') { $sqla[] = "ALTER TABLE `backup` CHANGE `content` `content` LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL"; } $tblcheck = "SHOW TABLES LIKE 'calendarindex'"; if (!$this->_conn->getField($tblcheck)) { $this->_conn->insertRow("CREATE TABLE IF NOT EXISTS `calendarindex` (\n\t\t\t\t\t\t\t\t\t\t `calendarId` int(11) NOT NULL DEFAULT '0',\n\t\t\t\t\t\t\t\t\t\t `search` text,\n\t\t\t\t\t\t\t\t\t\t PRIMARY KEY (`calendarId`),\n\t\t\t\t\t\t\t\t\t\t FULLTEXT KEY `search` (`search`)\n\t\t\t\t\t\t\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8;"); $cal = new Calendar(); $ids = $this->_conn->getFields("SELECT calendarId FROM calendarnew"); $sqlc = "INSERT INTO calendarindex (calendarId, search) VALUES"; $sqlca = array(); foreach ($ids as $id) { $ev = $cal->getEvent($id); $search = BrightUtils::createSearchString($ev); if ((int) $ev->locationId > 0) { $search .= $this->_conn->getField("SELECT search FROM gm_markers WHERE pageId={$ev->locationId}"); } $search = Connection::getInstance()->escape_string($search); $sqlca[] = "({$ev->calendarId}, '{$search}')"; } if (count($sqlca) > 0) { $sqlc .= implode(",\r\n", $sqlca); $sqla[] = $sqlc; } $sqla[] = "ALTER TABLE `calendareventsnew` ADD INDEX ( `starttime` )"; } $tblcheck = "SHOW TABLES LIKE 'pageindex'"; if (!$this->_conn->getField($tblcheck)) { $this->_conn->insertRow("CREATE TABLE IF NOT EXISTS `pageindex` (\n\t\t\t\t\t\t\t\t\t\t `pageId` int(11) NOT NULL DEFAULT '0',\n\t\t\t\t\t\t\t\t\t\t `search` text,\n\t\t\t\t\t\t\t\t\t\t PRIMARY KEY (`pageId`),\n\t\t\t\t\t\t\t\t\t\t FULLTEXT KEY `search` (`search`)\n\t\t\t\t\t\t\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8;"); $el = new Element(); $page = new Page(); $ids = $el->getElements(false); $sqle = "INSERT INTO pageindex (pageId, search) VALUES"; $sqlea = array(); foreach ($ids as $elm) { $ev = $page->getPageById($elm->pageId); $search = BrightUtils::createSearchString($ev); $search = Connection::getInstance()->escape_string($search); $sqlea[] = "({$ev->pageId}, '{$search}')"; } if (count($sqlea) > 0) { $sqle .= implode(",\r\n", $sqlea); $sqla[] = $sqle; } } if ($prevbuild < 7098) { // Update user settings, this fixes a bug with AmfPHP 2.x, // which does not correctly deserialize flex.messaging.io.objectproxy to php stdClass objects $rows = Connection::getInstance()->getRows("SELECT id, settings FROM `administrators`"); foreach ($rows as $row) { $settings = json_decode($row->settings); if ($settings) { if (isset($settings->_externalizedData)) { $settings = $settings->_externalizedData; } // Clean up settings object foreach ($settings as $key => $value) { if (strpos($key, 'pageDivider_') === 0) { unset($settings->{$key}); } } $settings = Connection::getInstance()->escape_string(json_encode($settings)); $sql = "UPDATE administrators SET settings='{$settings}' WHERE id={$row->id}"; Connection::getInstance()->updateRow($sql); } } } // Update to latest version $sqla[] = 'TRUNCATE `update`'; $sqla[] = 'INSERT INTO `update` (`build`) VALUES (' . $build . ')'; $this->_performQueries($sqla); $sql = "SHOW TABLES LIKE 'calendar'"; $rows = $this->_conn->getRow($sql); if ($rows) { $sql = 'SELECT * FROM calendar'; $rows = $this->_conn->getRows($sql); if ($rows) { $page = new Page(); $cal = new Calendar(); $ids = array(); foreach ($rows as $row) { $ids[] = $row->pageId; $ev = $page->getPageById($row->pageId); $cdo = new OCalendarDateObject(); $cdo->starttime = $ev->publicationdate; $cdo->endtime = $ev->expirationdate; $cdo->allday = date('d-m-Y', $cdo->starttime) != date('d-m-Y', $cdo->endtime) || $row->allday; if (date('H', $cdo->starttime) == 22) { $cdo->starttime += 7200; $cdo->endtime += 7200; $cdo->allday = 1; } if (date('H', $cdo->starttime) == 23) { $cdo->starttime += 3600; $cdo->endtime += 3600; $cdo->allday = 1; } if (date('H', $cdo->endtime) == 22) { $cdo->starttime += 7200; $cdo->endtime += 7200; $cdo->allday = 1; } if (date('H', $cdo->endtime) == 23) { $cdo->starttime += 3600; $cdo->endtime += 3600; $cdo->allday = 1; } $cestring = serialize($ev); $cestring = str_replace('O:5:"OPage"', 'O:14:"OCalendarEvent"', $cestring); $cestring = str_replace('s:13:"_explicitType";s:5:"OPage"', 's:13:"_explicitType";s:14:"OCalendarEvent"', $cestring); $ev = unserialize($cestring); $ev->dates = array($cdo); $cal->setEvent($ev); } $page->deletePages($ids); $sql = 'DELETE FROM calendar'; $rows = $this->_conn->deleteRow($sql); $sql = 'DELETE FROM calendarevents'; $rows = $this->_conn->deleteRow($sql); } } $this->updatePermissions($permissions); }