Index: branches/RC/core/kernel/utility/temp_handler.php =================================================================== diff -u -r10294 -r11623 --- branches/RC/core/kernel/utility/temp_handler.php (.../temp_handler.php) (revision 10294) +++ branches/RC/core/kernel/utility/temp_handler.php (.../temp_handler.php) (revision 11623) @@ -768,46 +768,68 @@ } } - function CheckSimultaniousEdit() + /** + * Checks, that someone is editing selected records and returns true, when no one. + * + * @param Array $ids + * + * @return bool + */ + function CheckSimultaniousEdit($ids = null) { $tables = $this->Conn->GetCol('SHOW TABLES'); - $mask_edit_table = '/'.TABLE_PREFIX.'ses_(.*)_edit_'.$this->MasterTable.'$/'; + $mask_edit_table = '/' . TABLE_PREFIX . 'ses_(.*)_edit_' . $this->MasterTable . '$/'; - $sql='SELECT COUNT(*) FROM '.$this->TableName.' WHERE '.$this->IDField.' = \'%s\''; $my_sid = $this->Application->GetSID(); - $ids = join(',',$this->Tables['IDs']); - $sids = array(); - if (!$ids) return ; - foreach($tables as $table) - { - if( preg_match($mask_edit_table,$table,$rets) ) - { + $ids = implode(',', isset($ids) ? $ids : $this->Tables['IDs']); + $sids = Array (); + if (!$ids) { + return true; + } + + foreach ($tables as $table) { + if ( preg_match($mask_edit_table, $table, $rets) ) { $sid = preg_replace('/(.*)_(.*)/', '\\1', $rets[1]); // remove popup's wid from sid - if ($sid == $my_sid) continue; - $found = $this->Conn->GetOne("SELECT COUNT({$this->Tables['IdField']}) FROM $table WHERE {$this->Tables['IdField']} IN ($ids)"); - if (!$found || in_array($sid, $sids)) continue; + if ($sid == $my_sid) { + continue; + } + $sql = 'SELECT COUNT(' . $this->Tables['IdField'] . ') + FROM ' . $table . ' + WHERE ' . $this->Tables['IdField'] . ' IN (' . $ids . ')'; + $found = $this->Conn->GetOne($sql); + + if (!$found || in_array($sid, $sids)) { + continue; + } + $sids[] = $sid; } } + if ($sids) { - //detect who is it - $users = $this->Conn->GetCol( - ' SELECT + // detect who is it + $sql = 'SELECT CONCAT(IF (s.PortalUserId = -1, \'root\', IF (s.PortalUserId = -2, \'Guest\', CONCAT(FirstName, \' \', LastName, \' (\', Login, \')\') ) - ), \' IP: \', s.IpAddress, \'\') FROM '.TABLE_PREFIX.'UserSession AS s - LEFT JOIN '.TABLE_PREFIX.'PortalUser AS u + ), \' IP: \', s.IpAddress, \'\') FROM ' . TABLE_PREFIX . 'UserSession AS s + LEFT JOIN ' . TABLE_PREFIX . 'PortalUser AS u ON u.PortalUserId = s.PortalUserId - WHERE s.SessionKey IN ('.join(',',$sids).')'); + WHERE s.SessionKey IN (' . implode(',', $sids) . ')'; + $users = $this->Conn->GetCol($sql); + if ($users) { $this->Application->SetVar('_simultanious_edit_message', sprintf($this->Application->Phrase('la_record_being_edited_by'), join(",\n", $users)) ); + + return false; } } + + return true; } }