Index: branches/5.1.x/core/units/categories/categories_event_handler.php =================================================================== diff -u -N -r13921 -r13951 --- branches/5.1.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 13921) +++ branches/5.1.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 13951) @@ -1,6 +1,6 @@ Conn->qstr($template) . ') OR (NamedParentPath = ' . $this->Conn->qstr('Content/' . $template) . ') OR - (IsSystem = 1 AND CachedTemplate = ' . $this->Conn->qstr($template) . ') + (`Type` = ' . PAGE_TYPE_TEMPLATE . ' AND CachedTemplate = ' . $this->Conn->qstr($template) . ') ) AND (ThemeId = ' . $this->_getCurrentThemeId() . ' OR ThemeId = 0)'; $page_id = $this->Conn->GetOne($sql); @@ -1143,7 +1143,7 @@ $sql = 'SELECT ' . $id_field . ' FROM ' . $table_name . ' - WHERE ' . $id_field . ' IN (' . implode(',', $clipboard_data['copy']) . ') AND (IsSystem = 0) AND (ThemeId = 0)'; + WHERE ' . $id_field . ' IN (' . implode(',', $clipboard_data['copy']) . ') AND (`Type` = ' . PAGE_TYPE_VIRTUAL . ') AND (ThemeId = 0)'; $allowed_ids = $this->Conn->GetCol($sql); if (!$allowed_ids) { @@ -1405,29 +1405,21 @@ $ids = $this->StoreSelectedIDs($event); if ($ids) { + $propagate_category_status = $this->Application->GetVar('propagate_category_status'); $status_field = array_shift( $this->Application->getUnitOption($event->Prefix,'StatusField') ); foreach ($ids as $id) { $object->Load($id); + $object->SetDBField($status_field, $event->Name == 'OnMassApprove' ? 1 : 0); - switch ($event->Name) { - case 'OnMassApprove': - $object->SetDBField($status_field, 1); - break; - - case 'OnMassDecline': - $object->SetDBField($status_field, 0); - break; - } - - if ($this->Application->GetVar('propagate_category_status')) { - $sql = 'UPDATE '.$object->TableName.' - SET '.$status_field.' = '.$object->GetDBField($status_field).' - WHERE TreeLeft BETWEEN '.$object->GetDBField('TreeLeft').' AND '.$object->GetDBField('TreeRight'); - $this->Conn->Query($sql); - } - if ($object->Update()) { + if ($propagate_category_status) { + $sql = 'UPDATE '.$object->TableName.' + SET '.$status_field.' = '.$object->GetDBField($status_field).' + WHERE TreeLeft BETWEEN '.$object->GetDBField('TreeLeft').' AND '.$object->GetDBField('TreeRight'); + $this->Conn->Query($sql); + } + $event->status = erSUCCESS; $email_event = $event->Name == 'OnMassApprove' ? 'CATEGORY.APPROVE' : 'CATEGORY.DENY'; @@ -1568,6 +1560,18 @@ $now = adodb_mktime(); + if ( !$this->Application->isDebugMode() ) { + $object->SetDBField('Type', $object->GetOriginalField('Type')); + $object->SetDBField('Protected', $object->GetOriginalField('Protected')); + + if ( $object->GetDBField('Protected') ) { + // some fields are read-only for protected pages, when debug mode is off + $object->SetDBField('AutomaticFilename', $object->GetOriginalField('AutomaticFilename')); + $object->SetDBField('Filename', $object->GetOriginalField('Filename')); + $object->SetDBField('Status', $object->GetOriginalField('Status')); + } + } + if ($object->GetChangedFields()) { $object->SetDBField('Modified_date', $now); $object->SetDBField('Modified_time', $now); @@ -1576,7 +1580,7 @@ $object->setRequired('PageCacheKey', $object->GetDBField('OverridePageCacheKey')); $object->SetDBField('Template', $this->_stripTemplateExtension( $object->GetDBField('Template') )); - if ($object->GetDBField('IsSystem') == 1) { + if ($object->GetDBField('Type') == PAGE_TYPE_TEMPLATE) { if (!$this->_templateFound($object->GetDBField('Template'), $object->GetDBField('ThemeId'))) { $object->SetError('Template', 'template_file_missing', 'la_error_TemplateFileMissing'); } @@ -1636,7 +1640,8 @@ function OnBeforeItemDelete(&$event) { $object =& $event->getObject(); - if ($object->GetDBField('IsSystem') && !$this->Application->isDebugMode()) { + + if ( $object->GetDBField('Protected') && !$this->Application->isDebugMode() ) { $event->status = erFAIL; } } @@ -1652,13 +1657,13 @@ $template = $this->_stripTemplateExtension($template); if ($system_mode == SMS_MODE_AUTO) { - $system = $this->_templateFound($template, $theme_id) ? 1 : 0; + $page_type = $this->_templateFound($template, $theme_id) ? PAGE_TYPE_TEMPLATE : PAGE_TYPE_VIRTUAL; } else { - $system = $system_mode == SMS_MODE_FORCE ? 1 : 0; + $page_type = $system_mode == SMS_MODE_FORCE ? PAGE_TYPE_TEMPLATE : PAGE_TYPE_VIRTUAL; } - if ($system && $template_info === false) { + if (($page_type == PAGE_TYPE_TEMPLATE) && ($template_info === false)) { // do not autocreate system pages, when browsing through site return false; } @@ -1674,18 +1679,18 @@ $this->Application->SetVar('m_cat_id', $page_category); } - if (!$system && strpos($template, '/') !== false) { + if (($page_type == PAGE_TYPE_VIRTUAL) && (strpos($template, '/') !== false)) { // virtual page, but have "/" in template path -> create it's path $category_path = explode('/', $template); $template = array_pop($category_path); $page_category = $this->_getParentCategoryFromPath($category_path, $root_category, $theme_id); } - $page_name = $system ? '_Auto: ' . $template : $template; + $page_name = ($page_type == PAGE_TYPE_TEMPLATE) ? '_Auto: ' . $template : $template; $page_description = ''; - if ($system) { + if ($page_type == PAGE_TYPE_TEMPLATE) { $design_template = strtolower($template); // leading "/" not added ! if ($template_info) { if (array_key_exists('name', $template_info) && $template_info['name']) { @@ -1708,10 +1713,11 @@ $object->Clear(); $object->SetDBField('ParentId', $page_category); - $object->SetDBField('IsSystem', $system); + $object->SetDBField('Type', $page_type); + $object->SetDBField('Protected', 1); // $page_type == PAGE_TYPE_TEMPLATE $object->SetDBField('IsMenu', 0); - $object->SetDBField('ThemeId', $theme_id); // $system ? $theme_id : 0 + $object->SetDBField('ThemeId', $theme_id); // put all templates to then end of list (in their category) $min_priority = $this->_getNextPriority($page_category, $object->TableName);