Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Wed, May 21, 12:55 AM

in-portal

Index: branches/unlabeled/unlabeled-1.6.2/kernel/units/category_items/category_items_event_handler.php
===================================================================
--- branches/unlabeled/unlabeled-1.6.2/kernel/units/category_items/category_items_event_handler.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.6.2/kernel/units/category_items/category_items_event_handler.php (revision 4315)
@@ -0,0 +1,115 @@
+<?php
+
+ class CategoryItemsEventHander extends InpDBEventHandler
+ {
+ /**
+ * Set's new category as primary for product
+ *
+ * @param kEvent $event
+ */
+ function OnSetPrimary(&$event)
+ {
+ $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
+ $object =& $event->getObject();
+ $this->StoreSelectedIDs($event);
+ $ids=$this->getSelectedIDs($event);
+ if($ids)
+ {
+ $id = array_shift($ids);
+ $table_info = $object->getLinkedInfo();
+
+ $this->Conn->Query('UPDATE '.$object->TableName.' SET PrimaryCat = 0 WHERE '.$table_info['ForeignKey'].' = '.$table_info['ParentId']);
+ $this->Conn->Query('UPDATE '.$object->TableName.' SET PrimaryCat = 1 WHERE ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].') AND (CategoryId = '.$id.')');
+ }
+ $event->redirect_params = Array('opener' => 's', 'pass_events' => true); //stay!
+ }
+
+ /**
+ * Apply custom processing to item
+ *
+ * @param kEvent $event
+ */
+ function customProcessing(&$event, $type)
+ {
+ if($event->Name == 'OnMassDelete')
+ {
+ $object =& $event->getObject();
+ $table_info = $object->getLinkedInfo();
+
+ switch ($type)
+ {
+ case 'before':
+ $ids = $event->getEventParam('ids');
+ if($ids)
+ {
+ $ids = $this->Conn->GetCol('SELECT CategoryId FROM '.$object->TableName.' WHERE (PrimaryCat=0) AND ('.$table_info['ForeignKey'].'='.$table_info['ParentId'].') AND CategoryId IN ('.implode(',',$ids).')');
+ $event->setEventParam('ids',$ids);
+ }
+ break;
+
+ // not needed because 'before' does not allow to delete primary cat!
+ /*case 'after':
+ // set 1st not deleted category as primary
+ $has_primary = $this->Conn->GetOne('SELECT COUNT(*) FROM '.$object->TableName.' WHERE (PrimaryCat=1) AND ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].')');
+ if(!$has_primary)
+ {
+ $cat_id = $this->Conn->GetOne('SELECT CategoryId FROM '.$object->TableName.' WHERE '.$table_info['ForeignKey'].' = '.$table_info['ParentId']);
+ $this->Conn->Query('UPDATE '.$object->TableName.' SET PrimaryCat = 1 WHERE ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].') AND (CategoryId = '.$cat_id.')');
+ }
+ break;*/
+ }
+ }
+ }
+
+ /**
+ * Removes primary mark from cloned category items record
+ *
+ * @param kEvent $event
+ */
+ function OnAfterClone(&$event)
+ {
+ $id = $event->getEventParam('id');
+ $table = $this->Application->getUnitOption($event->Prefix, 'TableName');
+ $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField');
+ $sql = 'UPDATE %s SET PrimaryCat = 0 WHERE %s = %s';
+
+ $this->Conn->Query( sprintf($sql, $table, $id_field, $id) );
+ }
+
+ /**
+ * Deletes items of requested type from requested categories.
+ * In case if item is deleted from it's last category, then delete item too.
+ *
+ * @param kEvent $event
+ */
+ function OnDeleteFromCategory(&$event)
+ {
+ $category_ids = $event->getEventParam('category_ids');
+ if(!$category_ids) return false;
+
+ $item_prefix = $event->getEventParam('item_prefix');
+ $this->Application->setUnitOption($item_prefix, 'AutoLoad', false);
+ $item =& $this->Application->recallObject($item_prefix.'.-item');
+
+ $ci_table = $this->Application->getUnitOption($event->Prefix, 'TableName');
+ $item_table = $this->Application->getUnitOption($item_prefix, 'TableName');
+
+ $sql = 'SELECT ItemResourceId, CategoryId FROM %1$s INNER JOIN %2$s ON (%1$s.ResourceId = %2$s.ItemResourceId) WHERE CategoryId IN (%3$s)';
+ $category_items = $this->Conn->Query( sprintf($sql, $item_table, $ci_table, implode(',', $category_ids) ) );
+
+ $item_hash = Array();
+ foreach($category_items as $ci_row)
+ {
+ $item_hash[ $ci_row['ItemResourceId'] ][] = $ci_row['CategoryId'];
+ }
+
+ foreach($item_hash as $item_resource_id => $delete_category_ids)
+ {
+ $item->Load($item_resource_id, 'ResourceId');
+ $item->DeleteFromCategories($delete_category_ids);
+ }
+ }
+
+ }
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.6.2/kernel/units/category_items/category_items_event_handler.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.6
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.6.2/kernel/include/adodb/drivers/adodb-mysql.inc.php
===================================================================
--- branches/unlabeled/unlabeled-1.6.2/kernel/include/adodb/drivers/adodb-mysql.inc.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.6.2/kernel/include/adodb/drivers/adodb-mysql.inc.php (revision 4315)
@@ -0,0 +1,569 @@
+<?php
+/*
+V3.60 16 June 2003 (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.
+ Released under both BSD license and Lesser GPL library license.
+ Whenever there is any discrepancy between the two licenses,
+ the BSD license will take precedence.
+ Set tabs to 8.
+
+ MySQL code that does not support transactions. Use mysqlt if you need transactions.
+ Requires mysql client. Works on Windows and Unix.
+
+ 28 Feb 2001: MetaColumns bug fix - suggested by Freek Dijkstra (phpeverywhere@macfreek.com)
+*/
+
+if (! defined("_ADODB_MYSQL_LAYER")) {
+ define("_ADODB_MYSQL_LAYER", 1 );
+
+class ADODB_mysql extends ADOConnection {
+ var $databaseType = 'mysql';
+ var $dataProvider = 'mysql';
+ var $hasInsertID = true;
+ var $hasAffectedRows = true;
+ var $metaTablesSQL = "SHOW TABLES";
+ var $metaColumnsSQL = "SHOW COLUMNS FROM %s";
+ var $fmtTimeStamp = "'Y-m-d H:i:s'";
+ var $hasLimit = true;
+ var $hasMoveFirst = true;
+ var $hasGenID = true;
+ var $upperCase = 'upper';
+ var $isoDates = true; // accepts dates in ISO format
+ var $sysDate = 'CURDATE()';
+ var $sysTimeStamp = 'NOW()';
+ var $hasTransactions = false;
+ var $forceNewConnect = false;
+ var $poorAffectedRows = true;
+ var $clientFlags = 0;
+ var $dbxDriver = 1;
+
+ function ADODB_mysql()
+ {
+ }
+
+ function ServerInfo()
+ {
+ $arr['description'] = $this->GetOne("select version()");
+ $arr['version'] = ADOConnection::_findvers($arr['description']);
+ return $arr;
+ }
+
+ // if magic quotes disabled, use mysql_real_escape_string()
+ function qstr($s,$magic_quotes=false)
+ {
+ if (!$magic_quotes) {
+
+ if (ADODB_PHPVER >= 0x4300) {
+ if (is_resource($this->_connectionID))
+ return "'".mysql_real_escape_string($s,$this->_connectionID)."'";
+ }
+ if ($this->replaceQuote[0] == '\\'){
+ $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);
+ }
+ return "'".str_replace("'",$this->replaceQuote,$s)."'";
+ }
+
+ // undo magic quotes for "
+ $s = str_replace('\\"','"',$s);
+ return "'$s'";
+ }
+
+ function _insertid()
+ {
+ return mysql_insert_id($this->_connectionID);
+ }
+
+ function _affectedrows()
+ {
+ return mysql_affected_rows($this->_connectionID);
+ }
+
+ // See http://www.mysql.com/doc/M/i/Miscellaneous_functions.html
+ // Reference on Last_Insert_ID on the recommended way to simulate sequences
+ var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
+ var $_genSeqSQL = "create table %s (id int not null)";
+ var $_genSeq2SQL = "insert into %s values (%s)";
+ var $_dropSeqSQL = "drop table %s";
+
+ function CreateSequence($seqname='adodbseq',$startID=1)
+ {
+ if (empty($this->_genSeqSQL)) return false;
+ $u = strtoupper($seqname);
+
+ $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname));
+ if (!$ok) return false;
+ return $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
+ }
+
+ function GenID($seqname='adodbseq',$startID=1)
+ {
+ // post-nuke sets hasGenID to false
+ if (!$this->hasGenID) return false;
+
+ $getnext = sprintf($this->_genIDSQL,$seqname);
+ $rs = @$this->Execute($getnext);
+ if (!$rs) {
+ $u = strtoupper($seqname);
+ $this->Execute(sprintf($this->_genSeqSQL,$seqname));
+ $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
+ $rs = $this->Execute($getnext);
+ }
+ $this->genID = mysql_insert_id($this->_connectionID);
+
+ if ($rs) $rs->Close();
+
+ return $this->genID;
+ }
+
+ function &MetaDatabases()
+ {
+ $qid = mysql_list_dbs($this->_connectionID);
+ $arr = array();
+ $i = 0;
+ $max = mysql_num_rows($qid);
+ while ($i < $max) {
+ $db = mysql_tablename($qid,$i);
+ if ($db != 'mysql') $arr[] = $db;
+ $i += 1;
+ }
+ return $arr;
+ }
+
+
+ // Format date column in sql string given an input format that understands Y M D
+ function SQLDate($fmt, $col=false)
+ {
+ if (!$col) $col = $this->sysTimeStamp;
+ $s = 'DATE_FORMAT('.$col.",'";
+ $concat = false;
+ $len = strlen($fmt);
+ for ($i=0; $i < $len; $i++) {
+ $ch = $fmt[$i];
+ switch($ch) {
+ case 'Y':
+ case 'y':
+ $s .= '%Y';
+ break;
+ case 'Q':
+ case 'q':
+ $s .= "'),Quarter($col)";
+
+ if ($len > $i+1) $s .= ",DATE_FORMAT($col,'";
+ else $s .= ",('";
+ $concat = true;
+ break;
+ case 'M':
+ $s .= '%b';
+ break;
+
+ case 'm':
+ $s .= '%m';
+ break;
+ case 'D':
+ case 'd':
+ $s .= '%d';
+ break;
+
+ case 'H':
+ $s .= '%H';
+ break;
+
+ case 'h':
+ $s .= '%I';
+ break;
+
+ case 'i':
+ $s .= '%i';
+ break;
+
+ case 's':
+ $s .= '%s';
+ break;
+
+ case 'a':
+ case 'A':
+ $s .= '%p';
+ break;
+
+ default:
+
+ if ($ch == '\\') {
+ $i++;
+ $ch = substr($fmt,$i,1);
+ }
+ $s .= $ch;
+ break;
+ }
+ }
+ $s.="')";
+ if ($concat) $s = "CONCAT($s)";
+ return $s;
+ }
+
+
+ // returns concatenated string
+ // much easier to run "mysqld --ansi" or "mysqld --sql-mode=PIPES_AS_CONCAT" and use || operator
+ function Concat()
+ {
+ $s = "";
+ $arr = func_get_args();
+ $first = true;
+ /*
+ foreach($arr as $a) {
+ if ($first) {
+ $s = $a;
+ $first = false;
+ } else $s .= ','.$a;
+ }*/
+
+ // suggestion by andrew005@mnogo.ru
+ $s = implode(',',$arr);
+ if (strlen($s) > 0) return "CONCAT($s)";
+ else return '';
+ }
+
+ function OffsetDate($dayFraction,$date=false)
+ {
+ if (!$date) $date = $this->sysDate;
+ return "from_unixtime(unix_timestamp($date)+($dayFraction)*24*3600)";
+ }
+
+ // returns true or false
+ function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
+ {
+ if (ADODB_PHPVER >= 0x4300)
+ $this->_connectionID = @mysql_connect($argHostname,$argUsername,$argPassword,
+ $this->forceNewConnect,$this->clientFlags);
+ else if (ADODB_PHPVER >= 0x4200)
+ $this->_connectionID = @mysql_connect($argHostname,$argUsername,$argPassword,
+ $this->forceNewConnect);
+ else
+ $this->_connectionID = @mysql_connect($argHostname,$argUsername,$argPassword);
+
+ if ($this->_connectionID === false) return false;
+ if ($argDatabasename) return $this->SelectDB($argDatabasename);
+ return true;
+ }
+
+ // returns true or false
+ function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
+ {
+ if (ADODB_PHPVER >= 0x4300)
+ $this->_connectionID = @mysql_pconnect($argHostname,$argUsername,$argPassword,$this->clientFlags);
+ else
+ $this->_connectionID = @mysql_pconnect($argHostname,$argUsername,$argPassword);
+ if ($this->_connectionID === false) return false;
+ if ($this->autoRollback) $this->RollbackTrans();
+ if ($argDatabasename) return $this->SelectDB($argDatabasename);
+ return true;
+ }
+
+ function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
+ {
+ $this->forceNewConnect = true;
+ return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename);
+ }
+
+ function &MetaColumns($table)
+ {
+
+ if ($this->metaColumnsSQL) {
+ global $ADODB_FETCH_MODE;
+
+ $save = $ADODB_FETCH_MODE;
+ $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
+ if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
+
+ $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
+
+ if (isset($savem)) $this->SetFetchMode($savem);
+ $ADODB_FETCH_MODE = $save;
+
+ if ($rs === false) return false;
+
+ $retarr = array();
+ while (!$rs->EOF){
+ $fld = new ADOFieldObject();
+ $fld->name = $rs->fields[0];
+ $type = $rs->fields[1];
+
+ // split type into type(length):
+ if (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
+ $fld->type = $query_array[1];
+ $fld->max_length = $query_array[2];
+ } else {
+ $fld->max_length = -1;
+ $fld->type = $type;
+ }
+ $fld->not_null = ($rs->fields[2] != 'YES');
+ $fld->primary_key = ($rs->fields[3] == 'PRI');
+ $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
+ $fld->binary = (strpos($fld->type,'blob') !== false);
+ if (!$fld->binary) {
+ $d = $rs->fields[4];
+ if ($d != "" && $d != "NULL") {
+ $fld->has_default = true;
+ $fld->default_value = $d;
+ } else {
+ $fld->has_default = false;
+ }
+ }
+
+ $retarr[strtoupper($fld->name)] = $fld;
+ $rs->MoveNext();
+ }
+ $rs->Close();
+ return $retarr;
+ }
+ return false;
+ }
+
+ // returns true or false
+ function SelectDB($dbName)
+ {
+ $this->databaseName = $dbName;
+ if ($this->_connectionID) {
+ return @mysql_select_db($dbName,$this->_connectionID);
+ }
+ else return false;
+ }
+
+ // parameters use PostgreSQL convention, not MySQL
+ function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false, $arg3=false,$secs=0)
+ {
+ $offsetStr =($offset>=0) ? "$offset," : '';
+
+ if ($secs) {
+ $limit =& $this->CacheExecute($secs,$sql." LIMIT $offsetStr$nrows",$inputarr,$arg3);
+ }
+ else {
+ $limit =& $this->Execute($sql." LIMIT $offsetStr$nrows",$inputarr,$arg3);
+ }
+
+ return $limit;
+ }
+
+
+ // returns queryID or false
+ function _query($sql,$inputarr)
+ {
+ //global $ADODB_COUNTRECS;
+ //if($ADODB_COUNTRECS)
+ return mysql_query($sql,$this->_connectionID);
+ //else return @mysql_unbuffered_query($sql,$this->_connectionID); // requires PHP >= 4.0.6
+ }
+
+ /* Returns: the last error message from previous database operation */
+ function ErrorMsg()
+ {
+ if (empty($this->_connectionID)) $this->_errorMsg = @mysql_error();
+ else $this->_errorMsg = @mysql_error($this->_connectionID);
+ return $this->_errorMsg;
+ }
+
+ /* Returns: the last error number from previous database operation */
+ function ErrorNo()
+ {
+ if (empty($this->_connectionID)) return @mysql_errno();
+ else return @mysql_errno($this->_connectionID);
+ }
+
+
+
+ // returns true or false
+ function _close()
+ {
+ @mysql_close($this->_connectionID);
+ $this->_connectionID = false;
+ }
+
+
+ /*
+ * Maximum size of C field
+ */
+ function CharMax()
+ {
+ return 255;
+ }
+
+ /*
+ * Maximum size of X field
+ */
+ function TextMax()
+ {
+ return 4294967295;
+ }
+
+}
+
+/*--------------------------------------------------------------------------------------
+ Class Name: Recordset
+--------------------------------------------------------------------------------------*/
+
+class ADORecordSet_mysql extends ADORecordSet{
+
+ var $databaseType = "mysql";
+ var $canSeek = true;
+
+ function ADORecordSet_mysql($queryID,$mode=false)
+ {
+ if ($mode === false) {
+ global $ADODB_FETCH_MODE;
+ $mode = $ADODB_FETCH_MODE;
+ }
+ switch ($mode)
+ {
+ case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break;
+ case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break;
+ default:
+ case ADODB_FETCH_DEFAULT:
+ case ADODB_FETCH_BOTH:$this->fetchMode = MYSQL_BOTH; break;
+ }
+
+ $this->ADORecordSet($queryID);
+ }
+
+ function _initrs()
+ {
+ //GLOBAL $ADODB_COUNTRECS;
+ // $this->_numOfRows = ($ADODB_COUNTRECS) ? @mysql_num_rows($this->_queryID):-1;
+ $this->_numOfRows = @mysql_num_rows($this->_queryID);
+ $this->_numOfFields = @mysql_num_fields($this->_queryID);
+ }
+
+ function &FetchField($fieldOffset = -1)
+ {
+
+ if ($fieldOffset != -1) {
+ $o = @mysql_fetch_field($this->_queryID, $fieldOffset);
+ $f = @mysql_field_flags($this->_queryID,$fieldOffset);
+ $o->max_length = @mysql_field_len($this->_queryID,$fieldOffset); // suggested by: Jim Nicholson (jnich@att.com)
+ //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
+ $o->binary = (strpos($f,'binary')!== false);
+ }
+ else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */
+ $o = @mysql_fetch_field($this->_queryID);
+ $o->max_length = @mysql_field_len($this->_queryID); // suggested by: Jim Nicholson (jnich@att.com)
+ //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
+ }
+
+ return $o;
+ }
+
+ function &GetRowAssoc($upper=true)
+ {
+ if ($this->fetchMode == MYSQL_ASSOC && !$upper) return $this->fields;
+ return ADORecordSet::GetRowAssoc($upper);
+ }
+
+ /* Use associative array to get fields array */
+ function Fields($colname)
+ {
+ // added @ by "Michael William Miller" <mille562@pilot.msu.edu>
+ if ($this->fetchMode != MYSQL_NUM) return @$this->fields[$colname];
+
+ if (!$this->bind) {
+ $this->bind = array();
+ for ($i=0; $i < $this->_numOfFields; $i++) {
+ $o = $this->FetchField($i);
+ $this->bind[strtoupper($o->name)] = $i;
+ }
+ }
+ return $this->fields[$this->bind[strtoupper($colname)]];
+ }
+
+ function _seek($row)
+ {
+ if ($this->_numOfRows == 0) return false;
+ return @mysql_data_seek($this->_queryID,$row);
+ }
+
+
+ // 10% speedup to move MoveNext to child class
+ function MoveNext()
+ {
+ //global $ADODB_EXTENSION;if ($ADODB_EXTENSION) return adodb_movenext($this);
+
+ if ($this->EOF) return false;
+
+ $this->_currentRow++;
+ $this->fields = @mysql_fetch_array($this->_queryID,$this->fetchMode);
+ if (is_array($this->fields)) return true;
+
+ $this->EOF = true;
+
+ /* -- tested raising an error -- appears pointless
+ $conn = $this->connection;
+ if ($conn && $conn->raiseErrorFn && ($errno = $conn->ErrorNo())) {
+ $fn = $conn->raiseErrorFn;
+ $fn($conn->databaseType,'MOVENEXT',$errno,$conn->ErrorMsg().' ('.$this->sql.')',$conn->host,$conn->database);
+ }
+ */
+ return false;
+ }
+
+ function _fetch()
+ {
+ $this->fields = @mysql_fetch_array($this->_queryID,$this->fetchMode);
+ return is_array($this->fields);
+ }
+
+ function _close() {
+ @mysql_free_result($this->_queryID);
+ $this->_queryID = false;
+ }
+
+ function MetaType($t,$len=-1,$fieldobj=false)
+ {
+ if (is_object($t)) {
+ $fieldobj = $t;
+ $t = $fieldobj->type;
+ $len = $fieldobj->max_length;
+ }
+
+ $len = -1; // mysql max_length is not accurate
+ switch (strtoupper($t)) {
+ case 'STRING':
+ case 'CHAR':
+ case 'VARCHAR':
+ case 'TINYBLOB':
+ case 'TINYTEXT':
+ case 'ENUM':
+ case 'SET':
+ if ($len <= $this->blobSize) return 'C';
+
+ case 'TEXT':
+ case 'LONGTEXT':
+ case 'MEDIUMTEXT':
+ return 'X';
+
+ // php_mysql extension always returns 'blob' even if 'text'
+ // so we have to check whether binary...
+ case 'IMAGE':
+ case 'LONGBLOB':
+ case 'BLOB':
+ case 'MEDIUMBLOB':
+ return !empty($fieldobj->binary) ? 'B' : 'X';
+ case 'YEAR':
+ case 'DATE': return 'D';
+
+ case 'TIME':
+ case 'DATETIME':
+ case 'TIMESTAMP': return 'T';
+
+ case 'INT':
+ case 'INTEGER':
+ case 'BIGINT':
+ case 'TINYINT':
+ case 'MEDIUMINT':
+ case 'SMALLINT':
+
+ if (!empty($fieldobj->primary_key)) return 'R';
+ else return 'I';
+
+ default: return 'N';
+ }
+ }
+
+}
+}
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.6.2/kernel/include/adodb/drivers/adodb-mysql.inc.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.6
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.6.2/core/units/category_items/category_items_event_handler.php
===================================================================
--- branches/unlabeled/unlabeled-1.6.2/core/units/category_items/category_items_event_handler.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.6.2/core/units/category_items/category_items_event_handler.php (revision 4315)
@@ -0,0 +1,115 @@
+<?php
+
+ class CategoryItemsEventHander extends InpDBEventHandler
+ {
+ /**
+ * Set's new category as primary for product
+ *
+ * @param kEvent $event
+ */
+ function OnSetPrimary(&$event)
+ {
+ $this->Application->setUnitOption($event->Prefix,'AutoLoad',false);
+ $object =& $event->getObject();
+ $this->StoreSelectedIDs($event);
+ $ids=$this->getSelectedIDs($event);
+ if($ids)
+ {
+ $id = array_shift($ids);
+ $table_info = $object->getLinkedInfo();
+
+ $this->Conn->Query('UPDATE '.$object->TableName.' SET PrimaryCat = 0 WHERE '.$table_info['ForeignKey'].' = '.$table_info['ParentId']);
+ $this->Conn->Query('UPDATE '.$object->TableName.' SET PrimaryCat = 1 WHERE ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].') AND (CategoryId = '.$id.')');
+ }
+ $event->redirect_params = Array('opener' => 's', 'pass_events' => true); //stay!
+ }
+
+ /**
+ * Apply custom processing to item
+ *
+ * @param kEvent $event
+ */
+ function customProcessing(&$event, $type)
+ {
+ if($event->Name == 'OnMassDelete')
+ {
+ $object =& $event->getObject();
+ $table_info = $object->getLinkedInfo();
+
+ switch ($type)
+ {
+ case 'before':
+ $ids = $event->getEventParam('ids');
+ if($ids)
+ {
+ $ids = $this->Conn->GetCol('SELECT CategoryId FROM '.$object->TableName.' WHERE (PrimaryCat=0) AND ('.$table_info['ForeignKey'].'='.$table_info['ParentId'].') AND CategoryId IN ('.implode(',',$ids).')');
+ $event->setEventParam('ids',$ids);
+ }
+ break;
+
+ // not needed because 'before' does not allow to delete primary cat!
+ /*case 'after':
+ // set 1st not deleted category as primary
+ $has_primary = $this->Conn->GetOne('SELECT COUNT(*) FROM '.$object->TableName.' WHERE (PrimaryCat=1) AND ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].')');
+ if(!$has_primary)
+ {
+ $cat_id = $this->Conn->GetOne('SELECT CategoryId FROM '.$object->TableName.' WHERE '.$table_info['ForeignKey'].' = '.$table_info['ParentId']);
+ $this->Conn->Query('UPDATE '.$object->TableName.' SET PrimaryCat = 1 WHERE ('.$table_info['ForeignKey'].' = '.$table_info['ParentId'].') AND (CategoryId = '.$cat_id.')');
+ }
+ break;*/
+ }
+ }
+ }
+
+ /**
+ * Removes primary mark from cloned category items record
+ *
+ * @param kEvent $event
+ */
+ function OnAfterClone(&$event)
+ {
+ $id = $event->getEventParam('id');
+ $table = $this->Application->getUnitOption($event->Prefix, 'TableName');
+ $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField');
+ $sql = 'UPDATE %s SET PrimaryCat = 0 WHERE %s = %s';
+
+ $this->Conn->Query( sprintf($sql, $table, $id_field, $id) );
+ }
+
+ /**
+ * Deletes items of requested type from requested categories.
+ * In case if item is deleted from it's last category, then delete item too.
+ *
+ * @param kEvent $event
+ */
+ function OnDeleteFromCategory(&$event)
+ {
+ $category_ids = $event->getEventParam('category_ids');
+ if(!$category_ids) return false;
+
+ $item_prefix = $event->getEventParam('item_prefix');
+ $this->Application->setUnitOption($item_prefix, 'AutoLoad', false);
+ $item =& $this->Application->recallObject($item_prefix.'.-item');
+
+ $ci_table = $this->Application->getUnitOption($event->Prefix, 'TableName');
+ $item_table = $this->Application->getUnitOption($item_prefix, 'TableName');
+
+ $sql = 'SELECT ItemResourceId, CategoryId FROM %1$s INNER JOIN %2$s ON (%1$s.ResourceId = %2$s.ItemResourceId) WHERE CategoryId IN (%3$s)';
+ $category_items = $this->Conn->Query( sprintf($sql, $item_table, $ci_table, implode(',', $category_ids) ) );
+
+ $item_hash = Array();
+ foreach($category_items as $ci_row)
+ {
+ $item_hash[ $ci_row['ItemResourceId'] ][] = $ci_row['CategoryId'];
+ }
+
+ foreach($item_hash as $item_resource_id => $delete_category_ids)
+ {
+ $item->Load($item_resource_id, 'ResourceId');
+ $item->DeleteFromCategories($delete_category_ids);
+ }
+ }
+
+ }
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.6.2/core/units/category_items/category_items_event_handler.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.6
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.6.2/admin/category/permcacheupdate.php
===================================================================
--- branches/unlabeled/unlabeled-1.6.2/admin/category/permcacheupdate.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.6.2/admin/category/permcacheupdate.php (revision 4315)
@@ -0,0 +1,348 @@
+<?php
+class clsRecursionStack
+{
+ var $Stack;
+
+ function clsRecursionStack()
+ {
+ $this->Stack = Array();
+ }
+
+ function Push($values)
+ {
+ array_push($this->Stack, $values);
+ }
+
+ function Pop()
+ {
+ if ($this->Count() > 0) {
+ return array_pop($this->Stack);
+ }
+ else {
+ return false;
+ }
+ }
+
+ function Get()
+ {
+ if ($this->Count() > 0) {
+// return end($this->Stack);
+ return $this->Stack[count($this->Stack)-1];
+ }
+ else {
+ return false;
+ }
+ }
+
+ function Update($values)
+ {
+ $this->Stack[count($this->Stack)-1] = $values;
+ }
+
+ function Count()
+ {
+ return count($this->Stack);
+ }
+}
+
+
+class clsCachedPermissions
+{
+ var $Allow;
+ var $Deny;
+ var $CatId;
+
+ function clsCachedPermissions($CatId)
+ {
+ $this->CatId = $CatId;
+ }
+
+ function SetCatId($CatId)
+ {
+ $this->CatId = $CatId;
+ }
+
+ function CheckPermArray($Perm)
+ {
+ if (!isset($this->Allow[$Perm])) {
+ $this->Allow[$Perm] = array();
+ $this->Deny[$Perm] = array();
+ }
+ }
+
+ function AddAllow($Perm, $GroupId)
+ {
+ $this->CheckPermArray($Perm);
+ if (!in_array($GroupId, $this->Allow[$Perm])) {
+ array_push($this->Allow[$Perm], $GroupId);
+ $this->RemoveDeny($Perm, $GroupId);
+ }
+ }
+
+ function AddDeny($Perm, $GroupId)
+ {
+ $this->CheckPermArray($Perm);
+ if (!in_array($GroupId, $this->Deny[$Perm])) {
+ array_push($this->Deny[$Perm], $GroupId);
+ $this->RemoveAllow($Perm, $GroupId);
+ }
+ }
+
+ function RemoveDeny($Perm, $GroupId)
+ {
+ if (in_array($GroupId, $this->Deny[$Perm])) {
+ array_splice($this->Deny[$Perm], array_search($GroupId, $this->Deny[$Perm]), 1);
+ }
+ }
+
+ function RemoveAllow($Perm, $GroupId)
+ {
+ if (in_array($GroupId, $this->Allow[$Perm])) {
+ array_splice($this->Allow[$Perm], array_search($GroupId, $this->Allow[$Perm]), 1);
+ }
+ }
+
+ function GetInsertSQL()
+ {
+ $values = array();
+
+ $has_deny = array();
+
+ foreach ($this->Deny as $perm => $groups) {
+ if (count($groups) > 0) {
+ $values[] = '('.$this->CatId.', '.$perm.', "", "'.join(',', $groups).'")';
+ $has_deny[] = $perm;
+ }
+ }
+
+ foreach ($this->Allow as $perm => $groups) {
+ if (in_array($perm, $has_deny)) continue;
+ if (count($groups) > 0) {
+ $values[] = '(' .$this->CatId. ', ' .$perm. ', "' .join(',', $groups). '", "")';
+ }
+ }
+ if (!$values) return '';
+ $sql = 'INSERT INTO '.GetTablePrefix().'PermCache (CategoryId, PermId, ACL, DACL) VALUES '.join(',', $values);
+ return $sql;
+ }
+}
+
+class clsCacheUpdater
+{
+ var $Stack;
+ var $iteration;
+ var $totalCats;
+ var $doneCats;
+ var $table;
+
+ /**
+ * Kernel Application
+ *
+ * @var kApplication
+ */
+ var $Application = null;
+ /**
+ * Enter description here...
+ *
+ * @var kDBConnection
+ */
+ var $Conn = null;
+
+ function clsCacheUpdater($continuing=false)
+ {
+ $this->Application =& kApplication::Instance();
+ $this->Conn =& $this->Application->GetADODBConnection();
+
+ $this->conn =& GetADODBConnection();
+ $this->iteration = 0;
+ $this->table=$GLOBALS['objSession']->GetEditTable('permCacheUpdate');
+
+ if (!$continuing) {
+ $this->Stack =& new clsRecursionStack();
+ $sql = 'DELETE FROM '.GetTablePrefix().'PermCache';
+ $this->conn->Execute($sql);
+ $this->initData();
+ }
+ else {
+ $this->getData();
+// $this->SetStack($data);
+ }
+ }
+ function getDonePercent()
+ {
+ if(!$this->totalCats)return 0;
+ return intval( round( $this->doneCats / $this->totalCats * 100 ) );
+ }
+ function getData()
+ {
+ $sql='SELECT data FROM '.$this->table;
+ if( $rs = $this->conn->Execute($sql) )
+ $tmp = unserialize($rs->fields['data']);
+
+ $this->totalCats = isset($tmp['totalCats']) ? $tmp['totalCats'] : 0;
+ $this->doneCats = isset($tmp['doneCats']) ? $tmp['doneCats'] : 0;
+ if(isset($tmp['stack']))
+ $this->Stack = $tmp['stack'];
+ else
+ $this->Stack = & new clsRecursionStack();
+
+ }
+ function setData()
+ {
+ $tmp=Array
+ (
+ 'totalCats' =>$this->totalCats,
+ 'doneCats' =>$this->doneCats,
+ 'stack' =>$this->Stack,
+
+ );
+ $sql='DELETE FROM '.$this->table;
+ $this->conn->Execute($sql);
+ $sql='INSERT '.$this->table.' SET data="'.addslashes(serialize($tmp)).'"';
+ $this->conn->Execute($sql);
+ }
+ function initData()
+ {
+ $sql='CREATE TABLE '.$this->table.'(data LONGTEXT)';
+ $this->conn->Execute($sql);
+
+ $sql='SELECT COUNT(*) as count FROM '.GetTablePrefix().'Category';
+ if( $rs = $this->conn->Execute($sql) )
+ $this->totalCats=$rs->fields['count'];
+
+ $this->doneCats=0;
+ }
+ function clearData()
+ {
+ $sql='DROP TABLE IF EXISTS '.$this->table;
+ $this->conn->Execute($sql);
+ }
+
+ function DoTheJob()
+ {
+ $data = $this->Stack->Get();
+ if ($data === false) { //If Stack is empty
+ $data['current_id'] = 0;
+ $data['title'] = Array();
+ $data['named_path'] = Array();
+ $data['category_template'] = '';
+ $data['item_template'] = '';
+ $this->Stack->Push($data);
+ }
+
+ if (!isset($data['queried'])) {
+
+ $this->QueryTitle($data);
+ $this->QueryChildren($data);
+ $this->QueryPermissions($data);
+ $data['queried'] = 1;
+
+ if($sql = $data['perms']->GetInsertSQL())
+ {
+ $this->conn->Execute($sql);
+ $this->doneCats++;
+ }
+ $this->iteration++;
+ }
+
+ // start with first child if we haven't started yet
+ if (!isset($data['current_child'])) $data['current_child'] = 0;
+
+ // if we have more children
+ if (isset($data['children'][$data['current_child']]))
+ {
+ $next_data = Array();
+ $next_data['title'] = $data['title'];
+ $next_data['named_path'] = $data['named_path'];
+ $next_data['category_template'] = $data['category_template'];
+ $next_data['item_template'] = $data['item_template'];
+ $next_data['current_id'] = $data['children'][$data['current_child']]; //next iteration should process child
+ $next_data['perms'] = $data['perms']; //we should copy our permissions to child - inheritance
+ $next_data['perms']->SetCatId($next_data['current_id']);
+ $data['current_child']++;
+ $this->Stack->Update($data); //we need to update ourself for the iteration after the next (or further) return to next child
+ $this->Stack->Push($next_data); //next iteration should process this child
+ return true;
+ }
+ else {
+ $this->UpdateCachedPath($data);
+ $this->Stack->Pop(); //remove ourself from stack if we have finished all the childs (or there are none)
+ // we are getting here if we finished with current level, so check if it's first level - then bail out.
+ return $this->Stack->Count() > 0;
+ }
+ }
+ function UpdateCachedPath(&$data)
+ {
+ $fields_hash = Array( 'CachedNavbar' => implode('>', $data['title']),
+ 'NamedParentPath' => implode('/', $data['named_path'] ),
+ 'CachedCategoryTemplate'=> $data['category_template'],
+ 'CachedItemTemplate' => $data['item_template'],
+ );
+
+ $this->Conn->doUpdate($fields_hash, TABLE_PREFIX.'Category', 'CategoryId = '.$data['current_id']);
+ }
+
+ function QueryTitle(&$data)
+ {
+ $sql = 'SELECT Name, Filename, CategoryTemplate, ItemTemplate
+ FROM '.GetTablePrefix().'Category
+ WHERE CategoryId = '.$data['current_id'];
+
+ $rs = $this->conn->Execute($sql);
+
+ if ($rs && !$rs->EOF)
+ {
+ $data['title'][] = $rs->fields['Name'];
+ $data['named_path'][] = $rs->fields['Filename'];
+
+ // if explicitly set, then use it; use parent template otherwise
+ if ($rs->fields['CategoryTemplate']) {
+ $data['category_template'] = $rs->fields['CategoryTemplate'];
+ }
+ if ($rs->fields['ItemTemplate']) {
+ $data['item_template'] = $rs->fields['ItemTemplate'];
+ }
+ }
+ }
+
+ function QueryChildren(&$data)
+ {
+ $sql = sprintf('SELECT CategoryId FROM '.GetTablePrefix().'Category WHERE ParentId = %s',
+ $data['current_id']);
+ $rs = $this->conn->Execute($sql);
+
+ $data['children'] = Array();
+ while ($rs && !$rs->EOF)
+ {
+ $data['children'][] = $rs->fields['CategoryId'];
+ $rs->MoveNext();
+ }
+ }
+
+ function QueryPermissions(&$data)
+ {
+ $sql = sprintf('SELECT ipc.PermissionConfigId, ip.GroupId, ip.PermissionValue FROM '.GetTablePrefix().'Permissions AS ip
+ LEFT JOIN '.GetTablePrefix().'PermissionConfig AS ipc
+ ON ipc.PermissionName = ip.Permission
+ WHERE CatId = %s AND Permission LIKE "%%.VIEW"',
+ $data['current_id']);
+ $rs = $this->conn->Execute($sql);
+
+ //create permissions array only if we don't have it yet (set by parent)
+ if (!isset($data['perms'])) {
+ $data['perms'] = new clsCachedPermissions($data['current_id']);
+ }
+
+ while ($rs && !$rs->EOF)
+ {
+ if ($rs->fields['PermissionValue'] == 1) {
+ $data['perms']->AddAllow($rs->fields['PermissionConfigId'], $rs->fields['GroupId']);
+ }
+ else {
+ $data['perms']->AddDeny($rs->fields['PermissionConfigId'], $rs->fields['GroupId']);
+ }
+ $rs->MoveNext();
+ }
+ }
+}
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.6.2/admin/category/permcacheupdate.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.6
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property

Event Timeline