00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00101 class Element
00102 {
00107 var $elementid;
00108
00113 var $templateid;
00114
00133 var $type;
00134
00139 var $name;
00140
00147 var $desc;
00148
00154 var $folderObjectId = 0;
00155
00160 var $defaultObjectId = 0;
00161
00166 var $writable;
00167
00172 var $allLanguages;
00173
00174 var $readonlyElementNames = array('copy','linkinfo','info','infodate','code','dynamic');
00175
00181 var $subtype = '';
00182 var $withIcon = false;
00183 var $dateformat = 'r';
00184 var $wiki = false;
00185 var $html = false;
00186 var $decimals = 0;
00187 var $decPoint = '.';
00188 var $thousandSep = '';
00189 var $code = '';
00190 var $defaultText = '';
00191
00192
00197 function Element( $elementid=0 )
00198 {
00199 if ( intval($elementid)!=0 )
00200 $this->elementid = $elementid;
00201 }
00202
00203
00208 function add()
00209 {
00210 $db = db_connection();
00211
00212 $sql = new Sql('SELECT MAX(id) FROM {t_element}');
00213 $this->elementid = intval($db->getOne($sql->query))+1;
00214
00215 $sql = new Sql( 'INSERT INTO {t_element}'.
00216 ' (id,templateid,name,descr,type,writable) '.
00217 " VALUES ( {elementid},{templateid},{name},{description},{type},{writable} ) " );
00218
00219 $sql->setInt ( 'elementid' ,$this->elementid );
00220 $sql->setString ( 'name' ,$this->name );
00221 $sql->setString ( 'type' ,$this->type );
00222 $sql->setInt ( 'templateid' ,$this->templateid );
00223 $sql->setBoolean( 'writable' ,$this->writable );
00224 $sql->setString ( 'description',$this->desc );
00225
00226 $db->query( $sql->query );
00227 }
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00245 function load()
00246 {
00247 $db = db_connection();
00248
00249 if ( intval($this->elementid) != 0 )
00250 {
00251 $sql = new Sql( 'SELECT * FROM {t_element}'.
00252 ' WHERE id={elementid}' );
00253 $sql->setInt( 'elementid',$this->elementid );
00254 }
00255 else
00256 {
00257 $sql = new Sql( 'SELECT * FROM {t_element}'.
00258 ' WHERE name={name}' );
00259 $sql->setString( 'name',$this->name );
00260 }
00261
00262 $this->setDatabaseRow( $db->getRow( $sql->query ) );
00263 }
00264
00265
00266 function setDatabaseRow( $prop )
00267 {
00268 if ( count($prop) <= 0 )
00269 return;
00270
00271 $this->elementid = $prop['id' ];
00272 $this->templateid = $prop['templateid'];
00273 $this->name = $prop['name' ];
00274 $this->desc = $prop['descr' ];
00275 $this->type = $prop['type' ];
00276 $this->subtype = $prop['subtype' ];
00277
00278 $this->dateformat = $prop['dateformat'];
00279 $this->wiki = ( $prop['wiki' ] == '1' );
00280 $this->withIcon = ( $prop['with_icon' ] == '1' );
00281 $this->html = ( $prop['html' ] == '1' );
00282 $this->allLanguages = ( $prop['all_languages'] == '1' );
00283 $this->writable = ( $prop['writable' ] == '1' );
00284
00285 if ( !$this->writable)
00286 $this->withIcon = false;
00287
00288 $this->decimals = intval( $prop['decimals' ] );
00289 $this->decPoint = strval( $prop['dec_point' ] );
00290 $this->thousandSep = strval( $prop['thousand_sep' ] );
00291 $this->code = strval( $prop['code' ] );
00292 $this->defaultText = strval( $prop['default_text' ] );
00293 $this->folderObjectId = intval( $prop['folderobjectid' ] );
00294 $this->defaultObjectId = intval( $prop['default_objectid'] );
00295 }
00296
00297
00302 function save()
00303 {
00304 $db = db_connection();
00305
00306 $sql = new Sql( 'UPDATE {t_element}'.
00307 ' SET templateid = {templateid},'.
00308 ' name = {name},'.
00309 ' descr = {desc},'.
00310 ' type = {type},'.
00311 ' subtype = {subtype},'.
00312 ' with_icon = {withIcon},'.
00313 ' dateformat = {dateformat},'.
00314 ' wiki = {wiki},'.
00315 ' html = {html},'.
00316 ' all_languages = {allLanguages},'.
00317 ' writable = {writable},'.
00318 ' decimals = {decimals},'.
00319 ' dec_point = {decPoint},'.
00320 ' thousand_sep = {thousandSep},'.
00321 ' code = {code},'.
00322 ' default_text = {defaultText},'.
00323 ' folderobjectid = {folderObjectId},'.
00324 ' default_objectid= {defaultObjectId}'.
00325 ' WHERE id={elementid}' );
00326
00327 $sql->setInt ( 'elementid' ,$this->elementid );
00328 $sql->setInt ( 'templateid' ,$this->templateid );
00329 $sql->setString ( 'name' ,$this->name );
00330 $sql->setString ( 'desc' ,$this->desc );
00331 $sql->setString ( 'type' ,$this->type );
00332 $sql->setString ( 'subtype' ,$this->subtype );
00333 $sql->setBoolean( 'withIcon' ,$this->withIcon );
00334 $sql->setString ( 'dateformat' ,$this->dateformat );
00335 $sql->setBoolean( 'wiki' ,$this->wiki );
00336 $sql->setBoolean( 'html' ,$this->html );
00337 $sql->setBoolean( 'writable' ,$this->writable );
00338 $sql->setBoolean( 'allLanguages' ,$this->allLanguages );
00339 $sql->setInt ( 'decimals' ,$this->decimals );
00340 $sql->setString ( 'decPoint' ,$this->decPoint );
00341 $sql->setString ( 'thousandSep' ,$this->thousandSep );
00342 $sql->setString ( 'code' ,$this->code );
00343 $sql->setString ( 'defaultText' ,$this->defaultText );
00344
00345 if ( intval($this->folderObjectId)==0 )
00346 $sql->setNull( 'folderObjectId' );
00347 else $sql->setInt ( 'folderObjectId' ,$this->folderObjectId );
00348
00349 if ( intval($this->defaultObjectId)==0 )
00350 $sql->setNull( 'defaultObjectId' );
00351 else $sql->setInt ( 'defaultObjectId' ,$this->defaultObjectId );
00352
00353 $db->query( $sql->query );
00354 }
00355
00356
00357
00364 function setType( $type )
00365 {
00366 $this->type = $type;
00367 $db = db_connection();
00368
00369 $sql = new Sql( 'UPDATE {t_element}'.
00370 ' SET type = {type}'.
00371 ' WHERE id={elementid}' );
00372
00373 $sql->setInt ( 'elementid',$this->elementid );
00374 $sql->setString ( 'type' ,$this->type );
00375
00376 $db->query( $sql->query );
00377 }
00378
00379
00384 function setPrefix( $prefix )
00385 {
00386 list( $oldprefix,$name ) = explode('%',$this->name.'%');
00387
00388 $this->name = $prefix.'%'.$name;
00389 }
00390
00391
00395 function delete()
00396 {
00397 $db = db_connection();
00398
00399
00400 $this->deleteValues();
00401
00402
00403 $sql = new Sql('DELETE FROM {t_element} '.
00404 ' WHERE id={elementid}' );
00405 $sql->setInt( 'elementid',$this->elementid );
00406
00407 $db->query( $sql->query );
00408 }
00409
00410
00415 function deleteValues()
00416 {
00417 $db = db_connection();
00418
00419
00420 $sql = new Sql('DELETE FROM {t_value} '.
00421 ' WHERE elementid={elementid}' );
00422 $sql->setInt( 'elementid',$this->elementid );
00423 $db->query( $sql->query );
00424 }
00425
00426
00431 function getRelatedProperties()
00432 {
00433 $prp = array('text' =>array('withIcon','allLanguages','writable','htmlwiki','defaultText'),
00434 'longtext'=>array('withIcon','allLanguages','writable','htmlwiki','defaultText'),
00435 'select' =>array('withIcon','allLanguages','writable','defaultText','code'),
00436 'number' =>array('withIcon','allLanguages','writable','decPoint','decimals','thousandSep'),
00437 'link' =>array('subtype','withIcon','allLanguages','writable','linktype','folderObjectId','defaultObjectId'),
00438 'date' =>array('withIcon','allLanguages','writable','dateformat','defaultText'),
00439 'list' =>array('subtype','withIcon','allLanguages','writable','folderObjectId','defaultObjectId'),
00440 'insert' =>array('subtype','withIcon','allLanguages','writable','folderObjectId','defaultObjectId'),
00441 'copy' =>array('prefix','name','defaultText'),
00442 'linkinfo'=>array('prefix','subtype','defaultText'),
00443 'code' =>array('code'),
00444 'dynamic' =>array('subtype','code'),
00445 'info' =>array('subtype'),
00446 'infodate'=>array('subtype','dateformat') );
00447 return $prp[ $this->type ];
00448 }
00449
00450
00451
00452 function getDefaultValue()
00453 {
00454 switch( $this->type )
00455 {
00456 case 'text':
00457 case 'longtext':
00458 return $this->defaultText;
00459
00460 case 'number';
00461 return '0';
00462
00463 default:
00464 }
00465
00466 return lang('EL_TYPE_'.$this->type);
00467
00468 }
00469
00474 function getAvailableTypes()
00475 {
00476 return array('text',
00477 'longtext',
00478 'select',
00479 'number',
00480 'link',
00481 'date',
00482 'insert',
00483 'copy',
00484 'linkinfo',
00485 'code',
00486 'dynamic',
00487 'info',
00488 'infodate');
00489 }
00490
00491
00498 function getTypeClass()
00499 {
00500 switch( $this->type )
00501 {
00502 case 'text':
00503 case 'longtext':
00504 case 'select':
00505 case 'number':
00506 case 'link':
00507 case 'date':
00508 case 'list':
00509 case 'insert':
00510 return 'text';
00511
00512 case 'code':
00513 case 'dynamic':
00514 return 'dynamic';
00515
00516 case 'copy':
00517 case 'info':
00518 case 'infodate':
00519 case 'linkinfo':
00520 return 'info';
00521 }
00522 }
00523
00524
00525 function getSelectItems()
00526 {
00527 $parameters = explode( "\n",$this->code );
00528 $items = array();
00529
00530 foreach( $parameters as $it )
00531 {
00532 $paar = explode( ":",$it,2 );
00533 $param_name = trim($paar[0]);
00534
00535 if ( count($paar) > 1 )
00536 $param_value = trim($paar[1]);
00537 else
00538 $param_value = trim($paar[0]);
00539
00540
00541 if ( substr($param_value,0,1) == "'" && substr($param_value,strlen($param_value)-1,1) == "'" )
00542 $param_value = substr($param_value,1,strlen($param_value)-2);
00543
00544 $items[$param_name] = $param_value;
00545 }
00546 return $items;
00547 }
00548
00549
00550 function getDynamicParameters()
00551 {
00552 $parameters = explode( "\n",$this->code );
00553 $items = array();
00554
00555 foreach( $parameters as $it )
00556 {
00557 $paar = explode( ":",$it,2 );
00558 if ( count($paar) > 1 )
00559 {
00560 $param_name = trim($paar[0]);
00561 $param_value = trim($paar[1]);
00562
00563
00564
00565
00566
00567 if ( !empty($param_value) )
00568 $items[$param_name] = $param_value;
00569 }
00570 }
00571 return $items;
00572 }
00573
00574
00580 function isWritable()
00581 {
00582
00583 if ( in_array($this->type,$this->readonlyElementNames) )
00584 return false;
00585
00586 return $this->writable;
00587 }
00588 }
00589
00590 ?>