Index: branches/RC/kernel/admin_templates/img/toolbar/tool_primary_file.gif =================================================================== diff -u -N Binary files differ Index: branches/RC/kernel/units/files/file_eh.php =================================================================== diff -u -N --- branches/RC/kernel/units/files/file_eh.php (revision 0) +++ branches/RC/kernel/units/files/file_eh.php (revision 9581) @@ -0,0 +1,166 @@ +Application->getUnitOption('#file', 'Clones'); + $clones[$event->MasterEvent->Prefix.'-file'] = Array ( + 'ParentPrefix' => $event->MasterEvent->Prefix, + ); + $this->Application->setUnitOption('#file', 'Clones', $clones); + } + + /** + * Remembers user, who is created file record. Makes file primary if no other files are uploaded. + * + * @param kEvent $event + */ + function OnBeforeItemCreate(&$event) + { + parent::OnBeforeItemCreate($event); + + $object =& $event->getObject(); + + $this->resetPrimary($object); + + if (!$this->primaryFileFound($object)) { + $object->SetDBField('IsPrimary', 1); + $object->SetDBField('Status', STATUS_ACTIVE); + } + + $object->SetDBField('CreatedById', $this->Application->RecallVar('user_id')); + } + + /** + * Resets primary file mark when more then one file is marked as primary + * + * @param kEvent $event + */ + function OnBeforeItemUpdate(&$event) + { + $object =& $event->getObject(); + + $this->resetPrimary($object); + + if (!$object->GetDBField('FileName')) { + $object->SetDBField('FileName', basename($object->GetDBField('FilePath'))); + } + } + + /** + * Checks for primary file along all files with same main item + * + * @param kDBItem $object + * @return int + */ + function primaryFileFound(&$object) + { + $sql = 'SELECT '.$object->IDField.' + FROM '.$object->TableName.' + WHERE (IsPrimary = 1) AND ('.$this->getParentClause($object).')'; + return $this->Conn->GetOne($sql); + } + + /** + * Resets primary mark from all item files + * + * @param kDBItem $object + */ + function resetPrimary(&$object) + { + if (!$object->GetDBField('IsPrimary')) { + return ; + } + + $sql = 'UPDATE '.$object->TableName.' + SET IsPrimary = 0 + WHERE '.$this->getParentClause($object); + $this->Conn->Query($sql); + + $object->SetDBField('Status', STATUS_ACTIVE); + } + + /** + * Makes selected file primary + * + * @param kEvent $event + */ + function OnSetPrimary(&$event) + { + $ids = $this->StoreSelectedIDs($event); + if (!$ids) { + return ; + } + + $object =& $event->getObject( Array('skip_autoload' => true) ); + $object->Load( array_shift($ids) ); + + $object->SetDBField('IsPrimary', 1); + $object->Update(); + + $this->clearSelectedIDs($event); + } + + /** + * Don't allow to delete other user's messages + * + * @param kEvent $event + */ + function customProcessing(&$event, $type) + { + parent::customProcessing($event, $type); + if ($event->Name == 'OnMassDelete' && $type == 'before') { + $ids = $event->getEventParam('ids'); + if ($ids) { + $object =& $event->getObject(); + /* @var $object kDBItem */ + + $primary_file_id = $this->primaryFileFound($object); + if ($primary_file_id && ($primary_index = array_search($primary_file_id, $ids))) { + $sql = 'SELECT COUNT(*) + FROM '.$object->TableName.' + WHERE (IsPrimary = 0) AND ('.$this->getParentClause($object).')'; + $non_primary_found = $this->Conn->Query($sql); + + if ($non_primary_found) { + // non-primary files found for same main item -> don't delete primary file until all non-primary files are deleted + unset($ids[$primary_index]); + } + } + + $event->setEventParam('ids', $ids); + } + } + } + + function SetCustomQuery(&$event) + { + parent::SetCustomQuery($event); + + $object =& $event->getObject(); + + if (!$this->Application->IsAdmin()) { + $object->addFilter('active_filter', '%1$s.Status = '.STATUS_ACTIVE); + } + } + + /** + * Returns sql clause, that links file to it's parent item + * + * @param kDBItem $object + * @return string + */ + function getParentClause(&$object) + { + $parent_info = $object->getLinkedInfo($object->Special); + return $parent_info['ForeignKey'].' = '.$parent_info['ParentId']; + } + } + +?> \ No newline at end of file Index: branches/RC/kernel/admin_templates/img/toolbar/tool_primary_file_f2.gif =================================================================== diff -u -N Binary files differ Index: branches/RC/kernel/admin_templates/img/itemicons/icon16_file.gif =================================================================== diff -u -N Binary files differ Index: branches/RC/core/units/files/file_eh.php =================================================================== diff -u -N --- branches/RC/core/units/files/file_eh.php (revision 0) +++ branches/RC/core/units/files/file_eh.php (revision 9581) @@ -0,0 +1,166 @@ +Application->getUnitOption('#file', 'Clones'); + $clones[$event->MasterEvent->Prefix.'-file'] = Array ( + 'ParentPrefix' => $event->MasterEvent->Prefix, + ); + $this->Application->setUnitOption('#file', 'Clones', $clones); + } + + /** + * Remembers user, who is created file record. Makes file primary if no other files are uploaded. + * + * @param kEvent $event + */ + function OnBeforeItemCreate(&$event) + { + parent::OnBeforeItemCreate($event); + + $object =& $event->getObject(); + + $this->resetPrimary($object); + + if (!$this->primaryFileFound($object)) { + $object->SetDBField('IsPrimary', 1); + $object->SetDBField('Status', STATUS_ACTIVE); + } + + $object->SetDBField('CreatedById', $this->Application->RecallVar('user_id')); + } + + /** + * Resets primary file mark when more then one file is marked as primary + * + * @param kEvent $event + */ + function OnBeforeItemUpdate(&$event) + { + $object =& $event->getObject(); + + $this->resetPrimary($object); + + if (!$object->GetDBField('FileName')) { + $object->SetDBField('FileName', basename($object->GetDBField('FilePath'))); + } + } + + /** + * Checks for primary file along all files with same main item + * + * @param kDBItem $object + * @return int + */ + function primaryFileFound(&$object) + { + $sql = 'SELECT '.$object->IDField.' + FROM '.$object->TableName.' + WHERE (IsPrimary = 1) AND ('.$this->getParentClause($object).')'; + return $this->Conn->GetOne($sql); + } + + /** + * Resets primary mark from all item files + * + * @param kDBItem $object + */ + function resetPrimary(&$object) + { + if (!$object->GetDBField('IsPrimary')) { + return ; + } + + $sql = 'UPDATE '.$object->TableName.' + SET IsPrimary = 0 + WHERE '.$this->getParentClause($object); + $this->Conn->Query($sql); + + $object->SetDBField('Status', STATUS_ACTIVE); + } + + /** + * Makes selected file primary + * + * @param kEvent $event + */ + function OnSetPrimary(&$event) + { + $ids = $this->StoreSelectedIDs($event); + if (!$ids) { + return ; + } + + $object =& $event->getObject( Array('skip_autoload' => true) ); + $object->Load( array_shift($ids) ); + + $object->SetDBField('IsPrimary', 1); + $object->Update(); + + $this->clearSelectedIDs($event); + } + + /** + * Don't allow to delete other user's messages + * + * @param kEvent $event + */ + function customProcessing(&$event, $type) + { + parent::customProcessing($event, $type); + if ($event->Name == 'OnMassDelete' && $type == 'before') { + $ids = $event->getEventParam('ids'); + if ($ids) { + $object =& $event->getObject(); + /* @var $object kDBItem */ + + $primary_file_id = $this->primaryFileFound($object); + if ($primary_file_id && ($primary_index = array_search($primary_file_id, $ids))) { + $sql = 'SELECT COUNT(*) + FROM '.$object->TableName.' + WHERE (IsPrimary = 0) AND ('.$this->getParentClause($object).')'; + $non_primary_found = $this->Conn->Query($sql); + + if ($non_primary_found) { + // non-primary files found for same main item -> don't delete primary file until all non-primary files are deleted + unset($ids[$primary_index]); + } + } + + $event->setEventParam('ids', $ids); + } + } + } + + function SetCustomQuery(&$event) + { + parent::SetCustomQuery($event); + + $object =& $event->getObject(); + + if (!$this->Application->IsAdmin()) { + $object->addFilter('active_filter', '%1$s.Status = '.STATUS_ACTIVE); + } + } + + /** + * Returns sql clause, that links file to it's parent item + * + * @param kDBItem $object + * @return string + */ + function getParentClause(&$object) + { + $parent_info = $object->getLinkedInfo($object->Special); + return $parent_info['ForeignKey'].' = '.$parent_info['ParentId']; + } + } + +?> \ No newline at end of file Index: branches/RC/kernel/admin_templates/img/toolbar/tool_primary_file_f3.gif =================================================================== diff -u -N Binary files differ Index: branches/RC/admin/install/inportal_schema.sql =================================================================== diff -u -N -r9376 -r9581 --- branches/RC/admin/install/inportal_schema.sql (.../inportal_schema.sql) (revision 9376) +++ branches/RC/admin/install/inportal_schema.sql (.../inportal_schema.sql) (revision 9581) @@ -109,6 +109,24 @@ # -------------------------------------------------------- +CREATE TABLE ItemFiles ( + FileId int(11) NOT NULL auto_increment, + ResourceId int(11) unsigned NOT NULL default '0', + FileName varchar(255) NOT NULL default '', + FilePath varchar(255) NOT NULL default '', + Size int(11) NOT NULL default '0', + `Status` tinyint(4) NOT NULL default '0', + IsPrimary tinyint(4) NOT NULL default '0', + Priority smallint(6) NOT NULL default '0', + CreatedOn int(11) unsigned NOT NULL default '0', + CreatedById int(11) NOT NULL default '-1', + MimeType varchar(255) NOT NULL default '', + PRIMARY KEY (FileId), + KEY ResourceId (ResourceId) +) + +# -------------------------------------------------------- + CREATE TABLE Relationship ( RelationshipId int(11) NOT NULL auto_increment, SourceId int(11) default NULL, Index: branches/RC/core/units/files/files_config.php =================================================================== diff -u -N --- branches/RC/core/units/files/files_config.php (revision 0) +++ branches/RC/core/units/files/files_config.php (revision 9581) @@ -0,0 +1,86 @@ + '#file', + 'ItemClass' => Array ('class' => 'kDBItem', 'file' => '', 'build_event' => 'OnItemBuild'), + 'ListClass' => Array ('class' => 'kDBList', 'file' => '', 'build_event' => 'OnListBuild'), + 'EventHandlerClass' => Array ('class' => 'FileEventHandler', 'file' => 'file_eh.php', 'build_event' => 'OnBuild'), + 'TagProcessorClass' => Array ('class' => 'kDBTagProcessor', 'file' => '', 'build_event' => 'OnBuild'), + + 'AutoLoad' => true, + + 'QueryString' => Array ( + 1 => 'id', + 2 => 'page', + 3 => 'event', + ), + + 'IDField' => 'FileId', + 'StatusField' => Array('Status', 'IsPrimary'), + + 'TitleField' => 'FileName', + 'TableName' => TABLE_PREFIX.'ItemFiles', + + 'ParentTableKey' => 'ResourceId', + 'ForeignKey' => 'ResourceId', + 'AutoDelete' => true, + 'AutoClone' => true, + + 'FilterMenu' => Array ( + 'Groups' => Array ( + Array ('mode' => 'AND', 'filters' => Array ('show_active','show_disabled'), 'type' => WHERE_FILTER), + ), + + 'Filters' => Array( + 'show_active' => Array('label' =>'la_Active', 'on_sql' => '', 'off_sql' => '%1$s.Status != 1' ), + 'show_disabled' => Array('label' => 'la_Disabled', 'on_sql' => '', 'off_sql' => '%1$s.Status != 0' ), + ) + ), + + 'ListSQLs' => Array ( + '' => 'SELECT * FROM %s', + ), + + 'ItemSQLs' => Array ( + '' => 'SELECT * FROM %s', + ), + + 'ListSortings' => Array ( + '' => Array ( + 'ForcedSorting' => Array('Priority' => 'desc'), + 'Sorting' => Array ('FileName' => 'asc'), + ) + ), + + 'Fields' => Array ( + 'FileId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), + 'ResourceId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), + 'FileName' => Array ('type' => 'string', 'max_len' => 255, 'required' => 1, 'not_null' => 1, 'default' => ''), + 'FilePath' => Array ( + 'type' => 'string', 'max_len' => 255, + 'formatter' => 'kUploadFormatter', 'upload_dir' => '/kernel/downloads/', 'include_path' => false, + 'size_field' => 'Size', 'content_type_field' => 'MimeType', 'max_size' => 50000000, + 'not_null' => 1, 'required' => 1, 'default' => '' + ), + 'Size' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), + 'Status' => Array ('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (1 => 'la_Enabled', 0 => 'la_Disabled'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 0), + 'IsPrimary' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), + 'Priority' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), + 'CreatedOn' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'not_null' => 1, 'default' => '#NOW#'), + 'CreatedById' => Array ('type' => 'int', 'not_null' => 1, 'default' => -1), + 'MimeType' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'default' => ''), + ), + + 'Grids' => Array ( + 'Default' => Array ( + 'Icons' => Array ('default' => 'icon16_custom.gif', '1_0' => 'icon16_file.gif', '1_1' => 'icon16_file_primary.gif', '0_0' => 'icon16_file_disabled.gif'), + 'Fields' => Array( + 'FileId' => Array ('title' => 'la_col_Id' , 'data_block' => 'grid_checkbox_td', 'module' => 'In-Portal'), + 'FileName' => Array ('title' => 'la_col_FileName'), + 'Status' => Array ('title' => 'la_col_Status'), + ), + ), + ), + ); + +?> \ No newline at end of file Index: branches/RC/kernel/admin_templates/img/itemicons/icon16_file_primary.gif =================================================================== diff -u -N Binary files differ Index: branches/RC/kernel/units/files/files_config.php =================================================================== diff -u -N --- branches/RC/kernel/units/files/files_config.php (revision 0) +++ branches/RC/kernel/units/files/files_config.php (revision 9581) @@ -0,0 +1,86 @@ + '#file', + 'ItemClass' => Array ('class' => 'kDBItem', 'file' => '', 'build_event' => 'OnItemBuild'), + 'ListClass' => Array ('class' => 'kDBList', 'file' => '', 'build_event' => 'OnListBuild'), + 'EventHandlerClass' => Array ('class' => 'FileEventHandler', 'file' => 'file_eh.php', 'build_event' => 'OnBuild'), + 'TagProcessorClass' => Array ('class' => 'kDBTagProcessor', 'file' => '', 'build_event' => 'OnBuild'), + + 'AutoLoad' => true, + + 'QueryString' => Array ( + 1 => 'id', + 2 => 'page', + 3 => 'event', + ), + + 'IDField' => 'FileId', + 'StatusField' => Array('Status', 'IsPrimary'), + + 'TitleField' => 'FileName', + 'TableName' => TABLE_PREFIX.'ItemFiles', + + 'ParentTableKey' => 'ResourceId', + 'ForeignKey' => 'ResourceId', + 'AutoDelete' => true, + 'AutoClone' => true, + + 'FilterMenu' => Array ( + 'Groups' => Array ( + Array ('mode' => 'AND', 'filters' => Array ('show_active','show_disabled'), 'type' => WHERE_FILTER), + ), + + 'Filters' => Array( + 'show_active' => Array('label' =>'la_Active', 'on_sql' => '', 'off_sql' => '%1$s.Status != 1' ), + 'show_disabled' => Array('label' => 'la_Disabled', 'on_sql' => '', 'off_sql' => '%1$s.Status != 0' ), + ) + ), + + 'ListSQLs' => Array ( + '' => 'SELECT * FROM %s', + ), + + 'ItemSQLs' => Array ( + '' => 'SELECT * FROM %s', + ), + + 'ListSortings' => Array ( + '' => Array ( + 'ForcedSorting' => Array('Priority' => 'desc'), + 'Sorting' => Array ('FileName' => 'asc'), + ) + ), + + 'Fields' => Array ( + 'FileId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), + 'ResourceId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), + 'FileName' => Array ('type' => 'string', 'max_len' => 255, 'required' => 1, 'not_null' => 1, 'default' => ''), + 'FilePath' => Array ( + 'type' => 'string', 'max_len' => 255, + 'formatter' => 'kUploadFormatter', 'upload_dir' => '/kernel/downloads/', 'include_path' => false, + 'size_field' => 'Size', 'content_type_field' => 'MimeType', 'max_size' => 50000000, + 'not_null' => 1, 'required' => 1, 'default' => '' + ), + 'Size' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), + 'Status' => Array ('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (1 => 'la_Enabled', 0 => 'la_Disabled'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 0), + 'IsPrimary' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), + 'Priority' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), + 'CreatedOn' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'not_null' => 1, 'default' => '#NOW#'), + 'CreatedById' => Array ('type' => 'int', 'not_null' => 1, 'default' => -1), + 'MimeType' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'default' => ''), + ), + + 'Grids' => Array ( + 'Default' => Array ( + 'Icons' => Array ('default' => 'icon16_custom.gif', '1_0' => 'icon16_file.gif', '1_1' => 'icon16_file_primary.gif', '0_0' => 'icon16_file_disabled.gif'), + 'Fields' => Array( + 'FileId' => Array ('title' => 'la_col_Id' , 'data_block' => 'grid_checkbox_td', 'module' => 'In-Portal'), + 'FileName' => Array ('title' => 'la_col_FileName'), + 'Status' => Array ('title' => 'la_col_Status'), + ), + ), + ), + ); + +?> \ No newline at end of file Index: branches/RC/admin/install/inportal_remove.sql =================================================================== diff -u -N -r9431 -r9581 --- branches/RC/admin/install/inportal_remove.sql (.../inportal_remove.sql) (revision 9431) +++ branches/RC/admin/install/inportal_remove.sql (.../inportal_remove.sql) (revision 9581) @@ -134,6 +134,8 @@ # -------------------------------------------------------- DROP TABLE ItemReview # -------------------------------------------------------- +DROP TABLE ItemFiles +# -------------------------------------------------------- DROP TABLE ItemTypes # -------------------------------------------------------- DROP TABLE Language Index: branches/RC/kernel/admin_templates/img/itemicons/icon16_file_disabled.gif =================================================================== diff -u -N Binary files differ Index: branches/RC/core/kernel/processors/main_processor.php =================================================================== diff -u -N -r9527 -r9581 --- branches/RC/core/kernel/processors/main_processor.php (.../main_processor.php) (revision 9527) +++ branches/RC/core/kernel/processors/main_processor.php (.../main_processor.php) (revision 9581) @@ -806,10 +806,11 @@ /** * Checks if debug mode is on * + * @param Array $params * @return bool * @access public */ - function IsDebugMode() + function IsDebugMode($params) { return $this->Application->isDebugMode(); } Index: branches/RC/admin/install/upgrades/inportal_upgrade_v4.2.1.sql =================================================================== diff -u -N -r9531 -r9581 --- branches/RC/admin/install/upgrades/inportal_upgrade_v4.2.1.sql (.../inportal_upgrade_v4.2.1.sql) (revision 9531) +++ branches/RC/admin/install/upgrades/inportal_upgrade_v4.2.1.sql (.../inportal_upgrade_v4.2.1.sql) (revision 9581) @@ -17,5 +17,7 @@ INSERT INTO ConfigurationValues VALUES (DEFAULT, 'Catalog_PreselectModuleTab', 1, 'In-Portal', 'in-portal:configure_categories'); INSERT INTO ConfigurationAdmin VALUES ('Catalog_PreselectModuleTab', 'la_Text_General', 'la_config_CatalogPreselectModuleTab', 'checkbox', NULL, NULL, 10.09, 0, 1); +CREATE TABLE ItemFiles (FileId int(11) NOT NULL auto_increment, ResourceId int(11) unsigned NOT NULL default '0', FileName varchar(255) NOT NULL default '', FilePath varchar(255) NOT NULL default '', Size int(11) NOT NULL default '0', `Status` tinyint(4) NOT NULL default '0', IsPrimary tinyint(4) NOT NULL default '0', Priority smallint(6) NOT NULL default '0', CreatedOn int(11) unsigned NOT NULL default '0', CreatedById int(11) NOT NULL default '-1', MimeType varchar(255) NOT NULL default '', PRIMARY KEY (FileId), KEY ResourceId (ResourceId)); + UPDATE Modules SET Version = '4.2.1' WHERE Name = 'Core'; UPDATE Modules SET Version = '4.2.1' WHERE Name = 'In-Portal'; \ No newline at end of file