Added in class member variables, fixed warnings about undefined values, prettied up the code to Campware coding conventions.

This commit is contained in:
paul 2006-09-01 09:15:32 +00:00
parent 601d88fe37
commit 5b86229054
1 changed files with 206 additions and 109 deletions

View File

@ -20,32 +20,30 @@ function errCallBack($err)
function _getLanguages()
{
$languages =& $_SESSION[UI_LOCALIZATION_SESSNAME]['languages'];
$languages =& $_SESSION[UI_LOCALIZER_SESSNAME]['languages'];
if (!is_array($languages)) {
include_once dirname(__FILE__).'/localizer/loader.inc.php';
foreach (getLanguages() as $k => $lang) {
$languages[$lang->m_languageId] = $lang->m_nativeName;
}
}
include_once dirname(__FILE__).'/localizer/loader.inc.php';
foreach (getLanguages() as $k => $lang) {
$languages[$lang->m_languageId] = $lang->m_nativeName;
}
}
return $languages;
}
/**
* tra
*
* Translate the given string using localisation files.
*
* @param input string, string to translate
* @param string $input - string to translate
* @return string, translated string
*/
function tra($input)
{
global $uiBase;
if (UI_LOCALIZER_SESSNAME) {
$GS =& $_SESSION[UI_LOCALIZATION_SESSNAME]['GS'];
if (defined(UI_LOCALIZER_SESSNAME)) {
$GS =& $_SESSION[UI_LOCALIZER_SESSNAME]['GS'];
} else {
static $GS;
}
@ -54,23 +52,24 @@ function tra($input)
#echo "load translation";
include_once dirname(__FILE__).'/localizer/loader.inc.php';
#echo $uiBase->langid;
$GS = loadTranslations($uiBase->langid);
$GS = loadTranslations($uiBase->langid);
#print_r($GS);
}
## end init ####################################
if ($GS[$input])
if (isset($GS[$input]) && !empty($GS[$input])) {
$input = $GS[$input];
}
$nr = func_num_args();
if ($nr > 1)
for ($i = 1; $i < $nr; $i++){
$name = '$'.$i;
$val = func_get_arg($i);
$input = str_replace($name, $val, $input);
if ($nr > 1) {
for ($i = 1; $i < $nr; $i++){
$name = '$'.$i;
$val = func_get_arg($i);
$input = str_replace($name, $val, $input);
}
}
return $input;
}
} // fn tra
function _getDArr($format)
@ -92,7 +91,8 @@ function _getDArr($format)
}
return $arr;
}
} // fn _getDArr
function _getNumArr($start, $end, $step=1)
{
@ -100,7 +100,8 @@ function _getNumArr($start, $end, $step=1)
$arr[$n] = $n;
}
return $arr;
}
} // fn _getNumArr
/**
* uiBase class
@ -122,6 +123,31 @@ class uiBase
*/
var $redirUrl;
var $alertMsg;
var $dbc;
var $gb; // GreenBox
var $config;
var $sessid;
var $userid;
var $login;
var $langid;
var $id;
var $pid;
var $type;
var $fid;
var $homeid;
var $InputTextStandardAttrib;
var $STATIONPREFS;
var $SCRATCHPAD;
var $SEARCH;
var $BROWSE;
var $HUBBROWSE;
var $HUBSEARCH;
var $PLAYLIST;
var $SCHEDULER;
var $SUBJECTS;
var $EXCHANGE;
var $TRANSFERS;
var $_self_;
function uiBase(&$config)
{
@ -135,18 +161,30 @@ class uiBase
$this->config['accessRawAudioUrl'] = $config['storageUrlPath'].'/xmlrpc/simpleGet.php';
$this->sessid = $_REQUEST[$config['authCookieName']];
$this->sessid = isset($_REQUEST[$config['authCookieName']]) ?
$_REQUEST[$config['authCookieName']] : null;
$this->userid = $this->gb->getSessUserId($this->sessid);
$this->login = $this->gb->getSessLogin($this->sessid);
if (PEAR::isError($this->login)) {
$this->login = null;
}
$this->langid =& $_SESSION['langid'];
$this->id = $_REQUEST['id'] ? $_REQUEST['id'] : $this->gb->getObjId($this->login, $this->gb->storId);
$this->pid = $this->gb->getparent($this->id) != 1 ? $this->gb->getparent($this->id) : FALSE;
$this->type = $this->gb->getFileType($this->id);
$this->fid = $this->type=='Folder' ? $this->id : $this->pid;
$this->homeid = $this->gb->getObjId($this->login, $this->gb->storId);
$this->InputTextStandardAttrib = array('size' =>UI_INPUT_STANDARD_SIZE,
'maxlength'=>UI_INPUT_STANDARD_MAXLENGTH);
if (!is_null($this->login)) {
if (isset($_REQUEST['id'])) {
$this->id = $_REQUEST['id'];
} else {
$this->id = $this->gb->getObjId($this->login, $this->gb->storId);
}
$this->pid = $this->gb->getparent($this->id) != 1 ?
$this->gb->getparent($this->id) : FALSE;
$this->type = $this->gb->getFileType($this->id);
$this->fid = ($this->type == 'Folder') ? $this->id : $this->pid;
$this->homeid = $this->gb->getObjId($this->login, $this->gb->storId);
}
$this->InputTextStandardAttrib = array('size'=>UI_INPUT_STANDARD_SIZE,
'maxlength'=>UI_INPUT_STANDARD_MAXLENGTH);
$this->STATIONPREFS =& $_SESSION[UI_STATIONINFO_SESSNAME];
$this->SCRATCHPAD =& new uiScratchPad($this);
$this->SEARCH =& new uiSearch($this);
@ -159,16 +197,21 @@ class uiBase
$this->EXCHANGE =& new uiExchange($this);
$this->TRANSFERS =& new uiTransfers($this);
$this->_self_ =& $this;
}
} // fn uiBase
/**
* Load system preferences.
*
* @param array $mask
* @param boolean $reload
*/
function loadStationPrefs(&$mask, $reload=FALSE)
{
if (!is_array($this->STATIONPREFS) || $reload===TRUE) {
if (!is_array($this->STATIONPREFS) || ($reload === TRUE) ) {
$this->STATIONPREFS = array();
foreach ($mask as $key=>$val) {
if ($val['isPref']) {
foreach ($mask as $key => $val) {
if (isset($val['isPref']) && $val['isPref']) {
if (is_string($setting = $this->gb->loadGroupPref(NULL, 'StationPrefs', $val['element']))) {
$this->STATIONPREFS[$val['element']] = $setting;
} elseif ($val['required']){
@ -179,7 +222,7 @@ class uiBase
}
}
}
}
} // fn loadStationPrefs
/**
@ -187,47 +230,76 @@ class uiBase
*
* Add elements/rules/groups to an given HTML_QuickForm object
*
* @param form object, reference to HTML_QuickForm object
* @param mask array, reference to array defining to form elements
* @param side string, side where the validation should beeing
* @param HTML_Quickform $form - reference to HTML_QuickForm object
* @param array $mask - reference to array defining the form elements
* @param string $side - can be 'client' or 'server' - this is where the form validation occurs.
*/
function _parseArr2Form(&$form, &$mask, $side='client')
{
foreach($mask as $k=>$v) {
foreach ($mask as $v) {
$attrs = isset($v['attributes']) ? $v['attributes'] : null;
$type = isset($v['type']) ? $v['type'] : null;
$label = isset($v['label']) ? tra($v['label']) : '';
$required = (isset($v['required']) && $v['required']);
$groupit = (isset($v['groupit']) && $v['groupit']);
## add elements ########################
if ($v['type']=='radio') {
foreach($v['options'] as $rk=>$rv) {
$radio[] =& $form->createElement($v['type'], NULL, NULL, $rv, $rk, $v['attributes']);
if ($type == 'radio') {
foreach ($v['options'] as $textLabel => $radioValue) {
$radio[] =& $form->createElement($type, NULL, NULL, $textLabel, $radioValue, $attrs);
}
$form->addGroup($radio, $v['element'], tra($v['label']));
$form->addGroup($radio, $v['element'], $label);
unset($radio);
} elseif ($type == 'select') {
$elem[$v['element']] =& $form->createElement($type, $v['element'], $label, $v['options'], $attrs);
} elseif ($v['type']=='select') {
$elem[$v['element']] =& $form->createElement($v['type'], $v['element'], tra($v['label']), $v['options'], $v['attributes']);
$elem[$v['element']]->setMultiple($v['multiple']);
if (isset($v['selected'])) $elem[$v['element']]->setSelected($v['selected']);
if (!$v['groupit']) $form->addElement($elem[$v['element']]);
$multiple = isset($v['multiple']) && $v['multiple'];
$elem[$v['element']]->setMultiple($multiple);
} elseif ($v['type']=='date') {
$elem[$v['element']] =& $form->createElement($v['type'], $v['element'], tra($v['label']), $v['options'], $v['attributes']);
if (!$v['groupit']) $form->addElement($elem[$v['element']]);
if (isset($v['selected'])) {
$elem[$v['element']]->setSelected($v['selected']);
}
if (!$groupit) {
$form->addElement($elem[$v['element']]);
}
} elseif ($type == 'date') {
$elem[$v['element']] =& $form->createElement($type, $v['element'], $label, $v['options'], $attrs);
if (!$groupit) {
$form->addElement($elem[$v['element']]);
}
} elseif ( ($type == 'checkbox') || ($type == 'static') ) {
$elem[$v['element']] =& $form->createElement($type, $v['element'], $label, tra($v['text']), $attrs);
if (!$groupit) {
$form->addElement($elem[$v['element']]);
}
} elseif (!is_null($type)) {
if (is_null($attrs)) {
$attrs = array();
}
if (in_array($type, array('text','file','password'))) {
$addAttrs = array('size' => UI_INPUT_STANDARD_SIZE,
'maxlength'=>UI_INPUT_STANDARD_MAXLENGTH);
$attrs = array_merge($addAttrs, $attrs);
} elseif ($type=='textarea') {
$addAttrs = array('rows'=>UI_TEXTAREA_STANDART_ROWS,
'cols'=>UI_TEXTAREA_STANDART_COLS);
$attrs = array_merge($addAttrs, $attrs);
} elseif (in_array($type, array('button', 'submit', 'reset'))) {
$addAttrs = array('class'=>UI_BUTTON_STYLE);
$attrs = array_merge($addAttrs, $attrs);
}
} elseif ($v['type']=='checkbox' || $v['type']=='static') {
$elem[$v['element']] =& $form->createElement($v['type'], $v['element'], tra($v['label']), tra($v['text']), $v['attributes']);
if (!$v['groupit']) $form->addElement($elem[$v['element']]);
} elseif (isset($v['type'])) {
if (!is_array($v['attributes'])) $v['attributes'] = array();
$elem[$v['element']] =& $form->createElement($v['type'], $v['element'], tra($v['label']),
($v[type]=='text' || $v['type']=='file' || $v['type']=='password') ? array_merge(array('size'=>UI_INPUT_STANDARD_SIZE, 'maxlength'=>UI_INPUT_STANDARD_MAXLENGTH), $v['attributes']) :
($v['type']=='textarea' ? array_merge(array('rows'=>UI_TEXTAREA_STANDART_ROWS, 'cols'=>UI_TEXTAREA_STANDART_COLS), $v['attributes']) :
($v['type']=='button' || $v['type']=='submit' || $v['type']=='reset' ? array_merge(array('class'=>UI_BUTTON_STYLE), $v['attributes']) : $v['attributes']))
);
if (!$v['groupit']) $form->addElement($elem[$v['element']]);
$elem[$v['element']] =& $form->createElement($type,
$v['element'],
$label,
$attrs);
if (!$groupit) {
$form->addElement($elem[$v['element']]);
}
}
## add required rule ###################
if ($v['required']) {
$form->addRule($v['element'], isset($v['requiredmsg']) ? tra($v['requiredmsg']) : tra('Missing value for $1', tra($v['label'])), 'required', NULL, $side);
if ($required) {
$form->addRule($v['element'], isset($v['requiredmsg']) ? tra($v['requiredmsg']) : tra('Missing value for $1', $label), 'required', NULL, $side);
}
## add constant value ##################
if (isset($v['constant'])) {
@ -238,46 +310,47 @@ class uiBase
$form->setDefaults(array($v['element']=>$v['default']));
}
## add other rules #####################
if ($v['rule']) {
if (isset($v['rule']) && $v['rule']) {
$form->addRule($v['element'], isset($v['rulemsg']) ? tra($v['rulemsg']) : tra('$1 must be $2', tra($v['element']), tra($v['rule'])), $v['rule'] ,$v['format'], $side);
}
## add group ###########################
if (is_array($v['group'])) {
foreach($v['group'] as $val) {
if (isset($v['group']) && is_array($v['group'])) {
foreach ($v['group'] as $val) {
$groupthose[] =& $elem[$val];
}
$form->addGroup($groupthose, $v['name'], tra($v['label']), $v['seperator'], $v['appendName']);
if ($v['rule']) {
$groupName = isset($v['name']) ? $v['name'] : null;
$seperator = isset($v['seperator']) ? $v['seperator'] : null;
$appendName = isset($v['appendName']) ? $v['appendName'] : null;
$form->addGroup($groupthose, $groupName, $label, $seperator, $appendName);
if (isset($v['rule']) && $v['rule']) {
$form->addRule($v['name'], isset($v['rulemsg']) ? tra($v['rulemsg']) : tra('$1 must be $2', tra($v['name'])), $v['rule'], $v['format'], $side);
}
if ($v['grouprule']) {
if (isset($v['grouprule']) && $v['grouprule']) {
$form->addGroupRule($v['name'], $v['arg1'], $v['grouprule'], $v['format'], $v['howmany'], $side, $v['reset']);
}
unset($groupthose);
}
## check error on type file ##########
if ($v['type']=='file') {
if ($_POST[$v['element']]['error']) {
$form->setElementError($v['element'], isset($v['requiredmsg']) ? tra($v['requiredmsg']) : tra('Missing value for $1', tra($v['label'])));
if ($type == 'file') {
if (isset($_POST[$v['element']]['error'])) {
$form->setElementError($v['element'], isset($v['requiredmsg']) ? tra($v['requiredmsg']) : tra('Missing value for $1', $label));
}
}
}
reset($mask);
$form->validate();
}
} // fn _parseArr2Form
/**
* _dateArr2Str
* Converts date-array from form into string
*
* Converts date-array from form into string
*
* @param input array, array of form-elements
* @param array $input - array of form-elements
*/
function _dateArr2Str(&$input)
{
foreach ($input as $k=>$v){
foreach ($input as $k => $v){
if (is_array($v)) {
if ( ( isset($v['d']) ) && ( isset($v['M']) || isset($v['m']) ) && ( isset($v['Y']) || isset($v['y']) ) ) {
$input[$k] = $v['Y'].$v['y'].'-'.sprintf('%02d', $v['M'].$v['m']).'-'.sprintf('%02d', $v['d']);
@ -289,16 +362,14 @@ class uiBase
}
return $input;
}
} // fn _dateArr2Str
/**
* _analyzeFile
*
* Call getid3 library to analyze media file and show some results
*
* @param $id int local ID of file
* @param $format string
* @param int $id local ID of file
* @param string $format
*/
function _analyzeFile($id, $format)
{
@ -322,34 +393,48 @@ class uiBase
<dcterms:extent>'.$extent.'</dcterms:extent>
</metadata>
</audioClip>';
}
return FALSE;
}
} // fn _analyzeFile
function _toHex($gunid)
{
$res = $this->dbc->query("SELECT to_hex($gunid)");
$row = $res->fetchRow();
return $row['to_hex'];
}
} // fn _toHex
function _toInt8($gunid)
{
$res = $this->dbc->query("SELECT x'$gunid'::bigint");
$row = $res->fetchRow();
return $row['int8'];
}
} // fn _toInt8
/**
* Add an alert message to the session var.
*
* @param string $msg
* @param string $p1
* @param string $p2
* @param string $p3
* @param string $p4
* @param string $p5
* @param string $p6
* @param string $p7
* @param string $p8
* @param string $p9
*/
function _retMsg($msg, $p1=NULL, $p2=NULL, $p3=NULL, $p4=NULL, $p5=NULL, $p6=NULL, $p7=NULL, $p8=NULL, $p9=NULL)
{
if (!isset($_SESSION['alertMsg'])) {
$_SESSION['alertMsg'] = '';
}
$_SESSION['alertMsg'] .= tra($msg, $p1, $p2, $p3, $p4, $p5, $p6, $p7, $p8, $p9).'\n';
}
} // fn _retMsg
function _getMetaInfo($id)
@ -364,34 +449,45 @@ class uiBase
#'isAvailable' => $type == 'playlist' ? $this->gb->playlistIsAvailable($id, $this->sessid) : NULL,
);
return ($data);
}
} // fn _getMetaInfo
function _getMDataValue($id, $key, $langid=NULL, $deflangid=UI_DEFAULT_LANGID)
{
if (!$langid) $langid = $_SESSION['langid'];
if (!$langid) {
$langid = $_SESSION['langid'];
}
if (is_array($arr = $this->gb->getMDataValue($id, $key, $this->sessid, $langid, $deflangid))) {
$value = current($arr);
return $value['value'];
}
return FALSE;
}
} // fn _getMDataValue
function _setMDataValue($id, $key, $value, $langid=NULL)
{
if (!$langid) $langid = UI_DEFAULT_LANGID;
if (ini_get('magic_quotes_gpc')) $value = str_replace("\'", "'", $value);
{
if (!$langid) {
$langid = UI_DEFAULT_LANGID;
}
if (ini_get('magic_quotes_gpc')) {
$value = str_replace("\'", "'", $value);
}
if ($this->gb->setMDataValue($id, $key, $this->sessid, $value, $langid)) {
return TRUE;
}
}
return FALSE;
}
} // fn _setMDataValue
/**
* Enter description here...
*
* @param unknown_type $id
* @return string/FALSE
*/
function _getFileTitle($id)
{
if (is_array($arr = $this->gb->getPath($id))) {
@ -399,7 +495,7 @@ class uiBase
return $file['name'];
}
return FALSE;
}
} // fn _getFileTitle
function _isFolder($id)
@ -408,7 +504,7 @@ class uiBase
return FALSE;
}
return TRUE;
}
} // fn _isFolder
function _formElementEncode($str)
@ -416,7 +512,7 @@ class uiBase
$str = str_replace(':', '__', $str);
#$str = str_replace('.', '_', $str);
return $str;
}
} // fn _formElementEncode
function _formElementDecode($str)
@ -424,6 +520,7 @@ class uiBase
$str = str_replace('__', ':', $str);
#$str = str_replace('_', '.', $str);
return $str;
}
}
} // fn _formElementDecode
} // class uiBase
?>