Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1084466
customfield.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Aug 6, 12:25 PM
Size
7 KB
Mime Type
text/x-php
Expires
Fri, Aug 8, 12:25 PM (4 m, 49 s)
Engine
blob
Format
Raw Data
Handle
704442
Attached To
rINP In-Portal
customfield.php
View Options
<?php
class
clsCustomField
extends
clsItem
{
function
clsCustomField
(
$CustomFieldId
=-
1
)
{
$this
->
clsItem
();
$this
->
tablename
=
GetTablePrefix
().
"CustomField"
;
$this
->
type
=
10
;
$this
->
BasePermission
=
""
;
$this
->
id_field
=
"CustomFieldId"
;
$this
->
NoResourceId
=
1
;
//set this to avoid using a resource ID
$this
->
debuglevel
=
0
;
if
(
$CustomFieldId
>-
1
)
$this
->
LoadFromDatabase
(
$CustomFieldId
);
}
function
GetAdminUI
()
{
$a
=
new
clsConfigAdminItem
();
$a
->
name
=
"_"
.
$this
->
Get
(
"FieldName"
);
$a
->
heading
=
$this
->
Get
(
"Heading"
);
$a
->
prompt
=
$this
->
Get
(
"Prompt"
);
$a
->
ElementType
=
$this
->
Get
(
"ElementType"
);
$a
->
ValidationRules
=
""
;
$a
->
default_value
=
""
;
$a
->
ValueList
=
$this
->
Get
(
"ValueList"
);
if
(!
strlen
(
$a
->
ElementType
))
$a
->
ElementType
=
"text"
;
if
(!
strlen
(
$a
->
prompt
))
$a
->
prompt
=
"lu_fieldcustom__"
.
strtolower
(
$this
->
Get
(
"FieldName"
));
return
$a
;
}
function
parsetag
(
$tag
)
{
if
(
is_object
(
$tag
))
{
$tagname
=
$tag
->
name
;
}
else
$tagname
=
$tag
;
switch
(
$tagname
)
{
case
"fieldlabel"
:
return
$this
->
Get
(
"FieldLabel"
);
break
;
case
"fieldname"
:
return
$this
->
Get
(
"FieldName"
);
break
;
case
"customfieldid"
:
return
$this
->
Get
(
"CustomFieldId"
);
default
:
return
"Undefined:$tagname"
;
break
;
}
}
}
class
clsCustomFieldList
extends
clsItemCollection
{
var
$Type
;
function
clsCustomFieldList
(
$type
=-
1
,
$table
=
"CustomField"
)
{
$this
->
clsItemCollection
();
$this
->
Type
=
$type
;
$this
->
classname
=
"clsCustomField"
;
if
(
$table
==
"CustomField"
)
$table
=
GetTablePrefix
().
$table
;
$this
->
SourceTable
=
$table
;
if
(
$this
->
Type
>
0
)
$this
->
LoadFields
();
}
function
LoadFields
()
{
$this
->
Clear
();
$sql
=
"SELECT * FROM "
.
$this
->
SourceTable
.
" WHERE Type="
.
$this
->
Type
.
" ORDER BY DisplayOrder DESC, CustomFieldId ASC"
;
if
(
$this
->
debuglevel
>
1
)
echo
$sql
.
"<br>
\n
"
;
$rs
=
$this
->
adodbConnection
->
Execute
(
$sql
);
while
(
$rs
&&
!
$rs
->
EOF
)
{
$data
=
$rs
->
fields
;
$this
->
AddItemFromArray
(
$data
);
$rs
->
MoveNext
();
}
}
function
LoadFieldsAndValues
(
$ResourceId
)
{
$this
->
Clear
();
$table
=
$this
->
SourceTable
;
$DataTable
=
GetTablePrefix
().
"CustomMetaData"
;
$sql
=
"SELECT $table.*,$DataTable.Value as Value, $DataTable.CustomDataId as CustomDataId FROM "
.
$table
.
" LEFT JOIN $DataTable ON "
;
$sql
.=
"("
.
$table
.
".CustomFieldId=$DataTable.CustomFieldId AND $DataTable.ResourceId=$ResourceId) WHERE Type="
.
$this
->
Type
;
if
(
isset
(
$GLOBALS
[
"debuglevel"
])
&&
$GLOBALS
[
"debuglevel"
])
echo
$sql
.
"<br>
\n
"
;
$rs
=
$this
->
adodbConnection
->
Execute
(
$sql
);
while
(
$rs
&&
!
$rs
->
EOF
)
{
$data
=
$rs
->
fields
;
$this
->
AddItemFromArray
(
$data
);
$rs
->
MoveNext
();
}
}
function
GetFieldUIList
(
$GeneralTab
=
FALSE
)
{
$ret
=
new
clsConfigAdmin
();
if
(
$this
->
NumItems
()>
0
)
{
foreach
(
$this
->
Items
as
$field
)
{
if
(
$GeneralTab
==
TRUE
&&
$field
->
Get
(
"OnGeneralTab"
)==
1
||
!
$GeneralTab
)
{
$ui
=
$field
->
GetAdminUI
();
array_push
(
$ret
->
Items
,
$ui
);
}
}
}
return
$ret
;
}
function
GetFieldNames
()
{
$res
=
array
();
foreach
(
$this
->
Items
as
$f
)
$res
[]
=
$f
->
Get
(
"FieldName"
);
return
$res
;
}
function
SaveFields
()
{
foreach
(
$this
->
Items
as
$i
)
{
if
(
$i
->
Get
(
"CustomFieldId"
))
{
$i
->
Update
();
}
else
$i
->
Create
();
}
}
function
Query_CustomField
(
$where
=
NULL
,
$orderby
=
NULL
,
$limit
=
NULL
)
{
$this
->
Clear
();
$sql
=
"SELECT * FROM "
.
$this
->
SourceTable
;
if
(
isset
(
$where
))
$sql
=
sprintf
(
'%s WHERE %s'
,
$sql
,
$where
);
if
(
isset
(
$orderby
)
&&
strlen
(
trim
(
$orderby
))>
0
)
$sql
=
sprintf
(
'%s ORDER BY %s'
,
$sql
,
$orderby
);
if
(
isset
(
$limit
)
&&
strlen
(
trim
(
$limit
)))
$sql
.=
" "
.
$limit
;
// $sql."<br>";
$this
->
Query_Item
(
$sql
);
return
$this
->
Items
;
}
function
AddField
(
$Type
,
$FieldName
,
$FieldLabel
,
$ShowGeneral
=
0
,
$Heading
=
""
,
$Prompt
=
""
,
$ElementType
=
""
,
$ValueList
=
""
)
{
global
$objItemTypes
,
$objSearchConfig
,
$objLanguages
;
//if(!is_numeric($Type))
// {
$f
=
new
clsCustomField
();
$f
->
tablename
=
$this
->
SourceTable
;
$f
->
Set
(
array
(
"Type"
,
"FieldName"
,
"FieldLabel"
,
"OnGeneralTab"
,
"Heading"
,
"Prompt"
,
"ElementType"
,
"ValueList"
),
array
(
$Type
,
$FieldName
,
$FieldLabel
,
$ShowGeneral
,
$Heading
,
$Prompt
,
$ElementType
,
$ValueList
));
$f
->
Create
();
$Item
=
$objItemTypes
->
GetItem
(
$Type
);
if
(
is_object
(
$Item
))
{
//$Table = $Item->Get("SourceTable");
$Table
=
GetTablePrefix
().
"CustomField"
;
$Header
=
"la_text_"
.
strtolower
(
$Item
->
Get
(
"ItemName"
));
$Module
=
$Item
->
Get
(
"Module"
);
$Desc
=
$FieldLabel
;
if
(!
is_object
(
$objSearchConfig
))
{
$objSearchConfig
=
new
clsSearchConfigList
();
}
$NextOrder
=
$objSearchConfig
->
GetNextDisplayOrder
(
$Module
);
$desc
=
"lu_fieldcustom__"
.
strtolower
(
$FieldName
);
if
(!
strlen
(
$FieldLabel
))
{
$FieldLabel
=
$FieldName
;
}
$l
=
$objLanguages
->
GetPrimary
();
$phrases
=
new
clsPhraseList
();
$phrases
->
AddPhrase
(
$desc
,
$l
,
$FieldLabel
,
2
);
$dtable
=
GetTablePrefix
().
"CustomMetaData"
;
$Join
=
"($dtable.ResourceId={Table}.ResourceId)"
;
$objSearchConfig
->
AddSearchField
(
$Table
,
$FieldName
,
$Module
,
0
,
0
,
$FieldLabel
,
$desc
,
$Header
,
$NextOrder
,
0
,
"text"
,
$Join
,
NULL
,
NULL
,
NULL
,
NULL
,
$f
->
Get
(
"CustomFieldId"
),
"CustomMetaData.Value"
);
}
return
$f
;
//}
//else
// return FALSE;
}
function
EditField
(
$FieldId
,
$Type
,
$FieldName
,
$FieldLabel
,
$ShowGeneral
=
0
,
$Heading
=
""
,
$Prompt
=
""
,
$ElementType
=
""
,
$ValueList
=
""
)
{
$f
=
$this
->
GetItem
(
$FieldId
);
$f
->
Set
(
array
(
"Type"
,
"FieldName"
,
"FieldLabel"
,
"OnGeneralTab"
,
"Heading"
,
"Prompt"
,
"ElementType"
,
"ValueList"
),
array
(
$Type
,
$FieldName
,
$FieldLabel
,
$ShowGeneral
,
$Heading
,
$Prompt
,
$ElementType
,
$ValueList
));
$f
->
Update
();
return
$f
;
}
function
DeleteField
(
$FieldId
)
{
global
$objItemTypes
,
$objSearchConfig
;
//echo "<pre>"; print_r($objSearchConfig); echo "</pre>";
$f
=
$this
->
GetItem
(
$FieldId
);
$Type
=
$f
->
Get
(
"Type"
);
$Item
=
$objItemTypes
->
GetItem
(
$Type
);
$Module
=
$Item
->
Get
(
"Module"
);
if
(
is_object
(
$Item
))
{
//$table = $Item->Get("TableName");
$table
=
GetTablePrefix
().
"CustomField"
;
if
(!
is_object
(
$objSearchConfig
))
{
$objSearchConfig
=
new
clsSearchConfigList
(
$Module
);
}
if
(
is_object
(
$objSearchConfig
))
{
$s
=
$objSearchConfig
->
GetItemByName
(
$table
,
$f
->
Get
(
"FieldName"
));
//echo "$table ".$f->Get("FieldName")."<pre>"; print_r($s); echo "</pre>";
if
(
is_object
(
$s
))
{
$s
->
Delete
();
}
}
}
$f
->
Delete
();
}
}
/*clsCustomFieldList*/
?>
Event Timeline
Log In to Comment