Index: trunk/kernel/include/config.php =================================================================== diff -u -N -r676 -r912 --- trunk/kernel/include/config.php (.../config.php) (revision 676) +++ trunk/kernel/include/config.php (.../config.php) (revision 912) @@ -1,4 +1,5 @@ Connect($db_info['DBHost'],$db_info['DBUser'],$db_info['DBUserPassword'],$db_info['DBName']); + + $sub_folder=$tool_db->GetOne('SELECT VariableValue FROM '.TABLE_PREFIX.'ConfigurationValues WHERE VariableName=\'Site_Path\''); + define('BASE_PATH', $_SERVER['DOCUMENT_ROOT'].rtrim($sub_folder,'/')); + unset($sub_folder); + + /** + * Same as print_r, but for html pages + * + * @param string $s + * @param bool $returnResult + * @return string + * @access public + */ + function tool_printPre($s,$returnResult=false) + { + $ret='
'.print_r($s,true).'
'; + if($returnResult) return $ret; + echo $ret; + } + +?> \ No newline at end of file Index: trunk/tools/phrase_locator.php =================================================================== diff -u -N -r907 -r912 --- trunk/tools/phrase_locator.php (.../phrase_locator.php) (revision 907) +++ trunk/tools/phrase_locator.php (.../phrase_locator.php) (revision 912) @@ -1,34 +1,26 @@ GetCol($sql); + foreach ($db_phrases as $phrase) { - unset($phrases[ $row['Phrase'] ]); // phrase is translated + unset($phrases[$phrase]); // phrase is translated } - mysql_free_result($rs); $ret = Array(); foreach($phrases as $phrase => $dummy_value) { $ret[] = $phrase; } - print_pre($ret); + tool_printPre($ret); - if( unlink($dir.'new_phrases.txt') ) + if( unlink(BASE_PATH.'/new_phrases.txt') ) { - $fp = fopen($dir.'new_phrases.txt','w'); + $fp = fopen(BASE_PATH.'/new_phrases.txt','w'); foreach ($ret as $phrase) { fwrite($fp,$phrase."\n"); @@ -80,9 +68,4 @@ { die('Can\'t create file new_phrases.txt'); } - - function print_pre($s) - { - echo '
',print_r($s,true),'
'; - } ?> \ No newline at end of file Index: trunk/tools/flush_tables.php =================================================================== diff -u -N --- trunk/tools/flush_tables.php (revision 0) +++ trunk/tools/flush_tables.php (revision 912) @@ -0,0 +1,27 @@ +GetCol('SHOW TABLES LIKE \''.TABLE_PREFIX.'%\''); + foreach($tables as $table) + { + $tool_db->Query($sql_prefix.' '.$table); + } + +?> \ No newline at end of file Index: trunk/tools/xml2txt.php =================================================================== diff -u -N --- trunk/tools/xml2txt.php (revision 0) +++ trunk/tools/xml2txt.php (revision 912) @@ -0,0 +1,70 @@ +'DateFormat','TIMEFORMAT'=>'TimeFormat', + 'DECIMAL'=>'Decimal','THOUSANDS'=>'Thousands', + 'CHARSET'=>'Charset'); + + $fp = fopen(SRC_NAME,'r'); + $xml = fread($fp,filesize(SRC_NAME)); + fclose($fp); + + $objInXML = new xml_doc($xml); + unset($xml); + $objInXML->parse(); + $objInXML->getTag(0,$name,$attribs,$contents,$tags); + + $fp=fopen(DST_NAME,'w'); + + foreach($tags as $t) + { + $LangRoot =& $objInXML->getTagByID($t); + fwrite($fp,'PackName='.$LangRoot->attributes['PACKNAME']."\n"); + + foreach($LangRoot->children as $tag) + { + switch($tag->name) + { + case 'PHRASES': + $tag_index = 0; $tag_count = count($tag->children); + while($tag_index < $tag_count) + { + $inner_tag =& $tag->children[$tag_index]; + $Phrase = $inner_tag->attributes['LABEL']; + $Translation = $inner_tag->contents; + $PhraseType = $inner_tag->attributes['TYPE']; + fwrite($fp,'P_='.$Phrase.';'.$Translation.';'.$PhraseType."\n"); + $tag_index++; + } + break; + + case 'EVENTS': + $tag_index = 0; $tag_count = count($tag->children); + while($tag_index < $tag_count) + { + $inner_tag =& $tag->children[$tag_index]; + $event = $inner_tag->attributes["EVENT"]; + $MsgType = strtolower($inner_tag->attributes["MESSAGETYPE"]); + $template = $inner_tag->contents; + $Type = $inner_tag->attributes["TYPE"]; + + fwrite($fp,'E_='.$event.';'.$template.';'.$Type.';'.$MsgType."\n"); + $tag_index++; + } + break; + + default: + fwrite($fp,$xml2txt_map[$tag->name].'='.base64_encode($tag->contents)."\n"); + break; + } + } + } + + fclose($fp); +?> \ No newline at end of file Index: trunk/kernel/include/language.php =================================================================== diff -u -N -r898 -r912 --- trunk/kernel/include/language.php (.../language.php) (revision 898) +++ trunk/kernel/include/language.php (.../language.php) (revision 912) @@ -374,13 +374,13 @@ $this->Query_Item($sql); } - function &AddLanguage($PackName,$LocalName,$Enabled,$Primary, $IconUrl="",$Datefmt,$TimeFmt,$Dec,$Thousand) + function &AddLanguage($PackName,$LocalName,$Enabled,$Primary, $IconUrl="",$Datefmt,$TimeFmt,$Dec,$Thousand,$Charset) { $l = new clsLanguage(); $l->tablename = $this->SourceTable; $l->Set(array("PackName","LocalName","Enabled","PrimaryLang","IconUrl","DateFormat","TimeFormat", - "DecimalPoint","ThousandSep"), - array($PackName,$LocalName,$Enabled,$Primary,$IconUrl,$Datefmt,$TimeFmt,$Dec,$Thousand)); + "DecimalPoint","ThousandSep",'Charset'), + array($PackName,$LocalName,$Enabled,$Primary,$IconUrl,$Datefmt,$TimeFmt,$Dec,$Thousand,$Charset)); $l->Dirty(); $l->Create(); return $l; Index: trunk/kernel/include/db.class.php =================================================================== diff -u -N --- trunk/kernel/include/db.class.php (revision 0) +++ trunk/kernel/include/db.class.php (revision 912) @@ -0,0 +1,400 @@ +dbType = $dbType; + $this->initMetaFunctions(); + if(!$errorHandler) + { + $this->errorHandler = Array(&$this,'handleError'); + } + } + + /** + * Set's custom error + * + * @param int $code + * @param string $msg + * @access public + */ + function setError($code,$msg) + { + $this->errorCode=$code; + $this->errorMessage=$msg; + } + + /** + * Checks if previous query execution + * raised an error. + * + * @return bool + * @access public + */ + function hasError() + { + return !($this->errorCode == 0); + } + + /** + * Caches function specific to requested + * db type + * + * @access private + */ + function initMetaFunctions() + { + $ret = Array(); + switch($this->dbType) + { + case 'mysql': + $ret = Array(); // only define functions, that name differs from "dbType_" + + break; + + + } + $this->metaFunctions = $ret; + } + + /** + * Get's function for specific db type + * based on it's meta name + * + * @param string $name + * @return string + * @access private + */ + function getMetaFunction($name) + { + if( !isset($this->metaFunctions[$name]) ) + { + if(function_exists($this->dbType.'_'.$name)) return $this->dbType.'_'.$name; + } + else + { + return $this->dbType.$name; + } + return false; + } + + + /** + * Try to connect to database server + * using specified parameters and set + * database to $db if connection made + * + * @param string $host + * @param string $user + * @param string $pass + * @param string $db + * @access public + */ + function Connect($host,$user,$pass,$db) + { + $func = $this->getMetaFunction('connect'); + $this->connectionID = $func($host,$user,$pass) or die('Can\'t connect to db'); + if($this->connectionID) + { + $this->setDB($db); + $this->showError(); + } + } + + /** + * Shows error message from previous operation + * if it failed + * + * @access private + */ + function showError($sql='') + { + $this->setError(0,''); // reset error + if($this->connectionID) + { + $func = $this->getMetaFunction('errno'); $this->errorCode = $func($this->connectionID); + if($this->hasError()) + { + $func = $this->getMetaFunction('error'); $this->errorMessage = $func($this->connectionID); + if(is_array($this->errorHandler)) + { + $func = $this->errorHandler[1]; + $ret = $this->errorHandler[0]->$func($this->errorCode,$this->errorMessage,$sql); + } + else + { + $func = $this->errorHandler; + $ret = $func($this->errorCode,$this->errorMessage,$sql); + } + if(!$ret) exit; + } + } + } + + /** + * Default error handler for sql errors + * + * @param int $code + * @param string $msg + * @param string $sql + * @return bool + * @access private + */ + function handleError($code,$msg,$sql) + { + echo 'Processing SQL: '.$sql.'
'; + echo 'Error ('.$code.'): '.$msg.'
'; + return false; + } + + /** + * Set's database name for connection + * to $new_name + * + * @param string $new_name + * @return bool + * @access public + */ + function setDB($new_name) + { + if(!$this->connectionID) return false; + $func = $this->getMetaFunction('select_db'); + return $func($new_name); + } + + /** + * Returns first field of first line + * of recordset if query ok or false + * otherwise + * + * @param string $sql + * @return string + * @access public + */ + function GetOne($sql) + { + $row = $this->GetRow($sql); + if(!$row) return false; + + return array_shift($row); + } + + /** + * Returns first row of recordset + * if query ok, false otherwise + * + * @param stirng $sql + * @return Array + * @access public + */ + function GetRow($sql) + { + $sql .= ' '.$this->getLimitClause(0,1); + $ret = $this->Query($sql); + if(!$ret) return $ret; + + return array_shift($ret); + } + + /** + * Returns 1st column of recordset as + * one-dimensional array or false otherwise + * Optional parameter $key_field can be used + * to set field name to be used as resulting + * array key + * + * @param string $sql + * @param string $key_field + * @return Array + * @access public + */ + function GetCol($sql, $key_field = null) + { + $rows = $this->Query($sql); + if(!$rows) return $rows; + + $i = 0; $row_count = count($rows); + $ret = Array(); + if(isset($key_field)) + { + while ($i < $row_count) + { + $ret[$rows[$i][$key_field]] = array_shift($rows[$i]); + $i++; + } + } + else + { + while ($i < $row_count) + { + $ret[] = array_shift($rows[$i]); + $i++; + } + } + return $ret; + } + + /** + * Queries db with $sql query supplied + * and returns rows selected if any, false + * otherwise. Optional parameter $key_field + * allows to set one of the query fields + * value as key in string array. + * + * @param string $sql + * @param string $key_field + * @return Array + */ + function Query($sql, $key_field = null) + { + $query_func = $this->getMetaFunction('query'); + $this->queryID = $query_func($sql,$this->connectionID); + if( is_resource($this->queryID) ) + { + $ret = Array(); + $fetch_func = $this->getMetaFunction('fetch_assoc'); + if( isset($key_field) ) + { + while( ($row = $fetch_func($this->queryID)) ) + { + $ret[$row[$key_field]] = $row; + } + } + else + { + while( ($row = $fetch_func($this->queryID)) ) + { + $ret[] = $row; + } + } + $this->Destroy(); + return $ret; + } + $this->showError($sql); + return false; + } + + /** + * Free memory used to hold recordset handle + * + * @access private + */ + function Destroy() + { + if($this->queryID) + { + $free_func = $this->getMetaFunction('free_result'); + $free_func($this->queryID); + $this->queryID = null; + } + } + + /** + * Returns auto increment field value from + * insert like operation if any, zero otherwise + * + * @return int + * @access public + */ + function getInsertID() + { + $func = $this->getMetaFunction('insert_id'); + return $func($this->connectionID); + } + + /** + * Returns row count affected by last query + * + * @return int + * @access public + */ + function getAffectedRows() + { + $func = $this->getMetaFunction('affected_rows'); + return $func($this->connectionID); + } + + /** + * Returns LIMIT sql clause part for specific db + * + * @param int $offset + * @param int $rows + * @return string + * @access private + */ + function getLimitClause($offset, $rows) + { + switch ($this->dbType) { + + default: + return 'LIMIT '.$offset.','.$rows; + break; + } + } + } +?> \ No newline at end of file Index: trunk/kernel/action.php =================================================================== diff -u -N -r900 -r912 --- trunk/kernel/action.php (.../action.php) (revision 900) +++ trunk/kernel/action.php (.../action.php) (revision 912) @@ -1263,7 +1263,7 @@ $l = $objEditItems->AddLanguage($_POST["packname"],$_POST["localname"], (int)$_POST["enabled"],(int)$_POST["primary"], $_POST["icon"],$_POST["date_format"],$_POST["time_format"], - $_POST["decimal"],$_POST["thousand"]); + $_POST["decimal"],$_POST["thousand"],$_POST['charset']); $ado = &GetADODBConnection(); $rs = $ado->Execute("SELECT MIN(LanguageId) as MinValue FROM ".$objEditItems->SourceTable);