Index: branches/unlabeled/unlabeled-1.4.10/core/units/selectors/selectors_event_handler.php =================================================================== diff -u -r2053 -r2805 --- branches/unlabeled/unlabeled-1.4.10/core/units/selectors/selectors_event_handler.php (.../selectors_event_handler.php) (revision 2053) +++ branches/unlabeled/unlabeled-1.4.10/core/units/selectors/selectors_event_handler.php (.../selectors_event_handler.php) (revision 2805) @@ -5,7 +5,55 @@ class SelectorsEventHandler extends InpDBEventHandler { + /** + * Occures before an item has been cloned + * Id of newly created item is passed as event' 'id' param + * + * @param kEvent $event + */ + function OnBeforeClone(&$event) + { + $event->Init($event->Prefix, '-item'); + $object =& $event->getObject(); + + $title_field = 'SelectorName'; + $new_name = $object->GetDBField($title_field); + $original_checked = false; + + $foreign_key = $event->getEventParam('foreign_key'); // in case if whole stylesheet is cloned + if($foreign_key === false) $foreign_key = $object->GetDBField('StylesheetId'); // in case if selector is copied ifself + + do { + if ( preg_match('/(.*)-([\d]+)/', $new_name, $regs) ) { + $new_name = $regs[1].'-'.($regs[2]+1); + } + elseif ($original_checked) { + $new_name = $new_name.'-1'; + } + + // if we are cloning in temp table this will look for names in temp table, + // since object' TableName contains correct TableName (for temp also!) + // if we are cloning live - look in live + $query = ' SELECT '.$title_field.' + FROM '.$object->TableName.' + WHERE '.$title_field.' = '.$this->Conn->qstr($new_name).' AND StylesheetId = '.$foreign_key; + + $res = $this->Conn->GetOne($query); + + /*// if not found in live table, check in temp table if applicable + if ($res === false && $object->Special == 'temp') { + $query = 'SELECT '.$name_field.' FROM '.$this->GetTempName($master['TableName']).' + WHERE '.$name_field.' = '.$this->Conn->qstr($new_name); + $res = $this->Conn->GetOne($query); + }*/ + + $original_checked = true; + } while ($res !== false); + $object->SetDBField($title_field, $new_name); + } + + /** * Show base styles or block styles * * @param kEvent $event Index: branches/unlabeled/unlabeled-1.7.2/core/units/visits/visits_tag_processor.php =================================================================== diff -u -r2740 -r2805 --- branches/unlabeled/unlabeled-1.7.2/core/units/visits/visits_tag_processor.php (.../visits_tag_processor.php) (revision 2740) +++ branches/unlabeled/unlabeled-1.7.2/core/units/visits/visits_tag_processor.php (.../visits_tag_processor.php) (revision 2805) @@ -44,12 +44,17 @@ $sql = 'SELECT '.$affil_idfield.' FROM '.$affil_table.' WHERE PortalUserId = '.$this->Application->GetVar('u_id'); $affiliate_id = $this->Conn->GetOne($sql); - $sql = 'SELECT COUNT(DISTINCT vis.PortalUserId) AS TotalVisitors, COUNT(ord.OrderId) AS OrderCount + $sql = 'SELECT COUNT(ord.OrderId) AS OrderCount FROM '.$list->TableName.' vis LEFT JOIN '.TABLE_PREFIX.'Orders ord ON ord.VisitId = vis.VisitId WHERE (vis.AffiliateId = '.$affiliate_id.') AND (ord.Status = '.ORDER_STATUS_PROCESSED.')'.($date_limit ? ' AND '.$date_limit : ''); $result = $this->Conn->GetRow($sql); + + $sql = 'SELECT COUNT(*) FROM '.$list->TableName.' vis + WHERE AffiliateId = '.$affiliate_id.($date_limit ? ' AND '.$date_limit : ''); + + $result['TotalVisitors'] = $this->Conn->GetOne($sql); $result['OrderTotalAmount'] = $list->getTotal('OrderTotalAmount', 'SUM'); $result['OrderAffiliateCommission'] = $list->getTotal('OrderAffiliateCommission', 'SUM'); Index: branches/unlabeled/unlabeled-1.4.10/core/units/selectors/selectors_config.php =================================================================== diff -u -r2053 -r2805 --- branches/unlabeled/unlabeled-1.4.10/core/units/selectors/selectors_config.php (.../selectors_config.php) (revision 2053) +++ branches/unlabeled/unlabeled-1.4.10/core/units/selectors/selectors_config.php (.../selectors_config.php) (revision 2805) @@ -7,6 +7,23 @@ 'EventHandlerClass' => Array('class'=>'SelectorsEventHandler','file'=>'selectors_event_handler.php','build_event'=>'OnBuild'), 'TagProcessorClass' => Array('class'=>'SelectorsTagProcessor','file'=>'selectors_tag_processor.php','build_event'=>'OnBuild'), 'AutoLoad' => true, + + 'Clones' => Array( + 'selectorsbase' => Array( + 'Hooks' => Array(), + 'Constrain' => 'Type = 1', + 'SubItems' => Array('selectorsblock'), + ), + + 'selectorsblock' => Array( + 'Hooks' => Array(), + 'Constrain' => 'Type = 2', + 'ForeignKey' => Array('css' => 'StylesheetId', 'selectorsbase' => 'ParentId'), + 'ParentTableKey' => Array('css' => 'StylesheetId', 'selectorsbase' => 'SelectorId'), + 'ParentPrefix' => 'selectorsbase', + ), + ), + 'Hooks' => Array( Array( 'Mode' => hAFTER, @@ -58,10 +75,6 @@ 'ParentPrefix' => 'css', 'AutoDelete' => true, 'AutoClone' => true, - - 'Constrain' => 'Type = 1', - 'SubItems' => Array('SAME: Type=2'), - 'ForeignKey1' => 'ParentId', 'ListSQLs' => Array( ''=>' SELECT %1$s.* FROM %s', @@ -75,9 +88,9 @@ ), 'Fields' => Array( 'SelectorId' => Array(), - 'StylesheetId' => Array('type' => 'int', 'unique'=>Array('SelectorName'), 'not_null' => '1','default' => '0'), + 'StylesheetId' => Array('type' => 'int', 'unique'=>Array('SelectorName'), 'current_table_only' => 1, 'not_null' => '1','default' => '0'), 'Name' => Array('type' => 'string','not_null' => '1','default' => '','required'=>1), - 'SelectorName' => Array('type' => 'string', 'unique'=>Array('StylesheetId'), 'not_null' => '1','default' => '','required'=>1), + 'SelectorName' => Array('type' => 'string', 'unique'=>Array('StylesheetId'), 'current_table_only' => 1, 'not_null' => '1','default' => '','required'=>1), 'SelectorData' => Array('not_null' => '1','default' => ''), 'Description' => Array('type' => 'string','not_null' => '1','default' => ''), 'Type' => Array('type' => 'int', 'formatter'=>'kOptionsFormatter', 'options'=>Array( 1 => 'la_BaseSelectors', 2 => 'la_BlockSelectors'), 'use_phrases' => 1, 'not_null' => '1','default' => '0'),