13 include_once (
"DATA/Class.Collection.php");
14 include_once (
"OFFLINE/Class.ExceptionCode.php");
15 include_once (
"FDL/Class.DocWaitManager.php");
24 private $domain = null;
29 private $domainApi = null;
32 $this->domain = $domain;
33 $this->domainApi = $domainApi;
35 private static function setError($err)
37 throw new Exception($err);
42 include_once (
"FDL/Class.DocumentList.php");
43 $families = $this->domain->getFamilies();
44 $list =
new DocumentList();
45 $list->addDocumentIdentificators($families);
47 $domain = $this->domain;
48 $callback =
function (&$family) use($domain)
50 $maskId = $domain->getOfflineMask($family->id);
52 $family->applyMask($maskId,
true);
57 $list->listMap($callback);
61 foreach ( $list as $family ) {
69 $lay =
new Layout(getLayoutFile(
"OFFLINE",
"familyBinding.xml"));
70 $lay->set(
"FAMNAME", $family->name);
71 $lay->set(
"FAMID", $family->id);
72 $oas = $family->getAttributes();
74 simpleQuery($family->dbaccess, sprintf(
"select defval from docfam where id=%d", $family->id), $defval,
true,
true);
75 $family->defval=$defval;
76 $this->_defaultValues=$family->getDefValues($defval);
79 foreach ( $oas as $aid => &$oa ) {
80 if (($oa->usefor !=
"Q") && ($oa->type ==
'tab')) {
81 $node[$aid] = array();
82 $tree[$aid] = &$node[$aid];
83 if ($oa->ordered === null) {
84 $oa->ordered = $this->getNodeOrder($oa, $oas);
88 foreach ( $oas as $aid => &$oa ) {
89 if (($oa->usefor !=
"Q") && ($oa->type ==
'frame')) {
90 $fid = $oa->fieldSet->id;
91 if ($fid && $fid !=
"FIELD_HIDDENS") {
92 $node[$aid] = array();
94 $node[$fid][$aid] = &$node[$aid];
96 $node[$aid] = array();
97 $tree[$aid] = &$node[$aid];
99 if ($oa->ordered === null) {
100 $oa->ordered = $this->getNodeOrder($oa, $oas);
105 foreach ( $oas as $aid => &$oa ) {
106 if (($oa->usefor !=
"Q") && ($oa->type ==
'array')) {
107 $fid = $oa->fieldSet->id;
108 if ($fid && $fid !=
"FIELD_HIDDENS") {
109 $node[$aid] = array();
111 $node[$fid][$aid] = &$node[$aid];
113 $node[$aid] = array();
114 $tree[$aid] = &$node[$aid];
116 if ($oa->ordered === null) {
117 $oa->ordered = $this->getNodeOrder($oa, $oas);
122 foreach ( $oas as $aid => &$oa ) {
123 if (($oa->usefor !=
"Q") && ($oa->type !=
'menu') && ($oa->type !=
'action')&& ($oa->type !=
'array') && ($oa->type !=
'frame') && ($oa->type !=
'tab')) {
124 $fid = $oa->fieldSet->id;
125 if ($fid && $fid !=
"FIELD_HIDDENS") {
127 $node[$fid][$aid] = $node[$aid];
129 $node[$aid] = array();
130 $tree[$aid] = &$node[$aid];
134 unset($tree[
"FIELD_HIDDENS"]);
136 $lay->set(
"viewContent", $this->bindingViewNodeAttribute($tree, $oas));
138 $lay->set(
"editContent", $this->bindingEditNodeAttribute($tree, $oas));
141 $binding = $lay->gen();
145 private function getNodeOrder(BasicAttribute &$noa, array &$oas)
147 if ($noa->ordered === null) {
148 foreach ( $oas as $aid => &$oa ) {
149 $fid = $oa->fieldSet->id;
150 if ($fid == $noa->id) {
151 $noa->ordered = intval($this->getNodeOrder($oa, $oas)) - 1;
156 return intval($noa->ordered);
158 private function bindingViewNodeAttribute(array &$node, array &$oas, BasicAttribute &$oa = null)
162 $visibility = $oa->mvisibility ? $oa->mvisibility : $oa->visibility;
164 if ((!$oa) || (($visibility !=
'I') && ($visibility !=
'H') && ($visibility !=
'O'))) {
167 $label = $oa->encodeXml($oa->getLabel(),
true);
168 $out .= sprintf(
'<xul:dcpAttribute label="%s" type="%s" attrid="%s" mode="view">', $label, $oa->type, $oa->id);
171 $callback =
function ($a, $b) use(&$oas)
174 if ($oas[$a]->type==
"tab" && $oas[$b]->type!=
"tab")
return 1;
175 else if ($oas[$a]->type!=
"tab" && $oas[$b]->type==
"tab")
return -1;
176 if ($oas[$a]->ordered > $oas[$b]->ordered)
return 1;
177 else if ($oas[$a]->ordered < $oas[$b]->ordered)
return -1;
180 uksort($node, $callback);
188 foreach ( $node as $k => $v ) {
189 if ((!$tabbox) && ($oas[$k]->type ==
"tab")) {
191 $out .=
"<xul:tabbox><xul:tabs/><xul:tabpanels>";
194 $out .= $this->bindingViewNodeAttribute($v, $oas, $oas[$k]);
196 $out .= $this->bindingViewLeafAttribute($oas[$k]) .
"\n";
198 if ($tabbox && ($oas[$k]->type !=
"tab")) {
200 $out .=
"</xul:tabpanels></xul:tabbox>";
205 $out .=
"</xul:tabpanels></xul:tabbox>";
208 $out .= sprintf(
'</xul:dcpAttribute>');
215 private function bindingViewLeafAttribute(BasicAttribute &$oa)
218 $visibility = $oa->mvisibility ? $oa->mvisibility : $oa->visibility;
219 if (($visibility !=
"I") && ($visibility !=
"H")) {
220 $label = $oa->encodeXml($oa->getLabel(),
true);
223 $out = sprintf(
'<xul:dcpAttribute label="%s" type="%s" attrid="%s" mode="view" relationFamily="%s" multiple="%s"/>', $label, $oa->type, $oa->id, trim($oa->format), ($oa->getOption(
"multiple") ==
"yes") ?
"true" :
"false");
226 $out = sprintf(
'<xul:dcpAttribute label="%s" type="%s" attrid="%s" mode="view" multiple="%s"/>', $label, $oa->type, $oa->id, ($oa->getOption(
"multiple") ==
"yes") ?
"true" :
"false");
229 $out = sprintf(
'<xul:dcpAttribute label="%s" type="%s" attrid="%s" mode="view"/>', $label, $oa->type, $oa->id);
235 private function bindingEditNodeAttribute(array &$node, array &$oas, BasicAttribute &$oa = null)
240 $visibility = $oa->mvisibility ? $oa->mvisibility : $oa->visibility;
242 if ((!$oa) || ($visibility !=
'I')) {
244 $label = $oa->encodeXml($oa->getLabel(),
true);
245 $out = sprintf(
'<xul:dcpAttribute label="%s" type="%s" attrid="%s" mode="edit" visibility="%s">', $label, $oa->type, $oa->id, $visibility);
247 $callback =
function ($a, $b) use(&$oas)
250 if ($oas[$a]->type==
"tab" && $oas[$b]->type!=
"tab")
return 1;
251 else if ($oas[$a]->type!=
"tab" && $oas[$b]->type==
"tab")
return -1;
252 if ($oas[$a]->ordered > $oas[$b]->ordered)
return 1;
253 else if ($oas[$a]->ordered < $oas[$b]->ordered)
return -1;
256 uksort($node, $callback);
258 foreach ( $node as $k => $v ) {
260 if ((!$tabbox) && ($oas[$k]->type ==
"tab")) {
262 $out .=
"<xul:tabbox><xul:tabs/><xul:tabpanels>";
265 $out .= $this->bindingEditNodeAttribute($v, $oas, $oas[$k]);
267 $out .= $this->bindingEditLeafAttribute($oas[$k]) .
"\n";
269 if ($tabbox && ($oas[$k]->type !=
"tab")) {
271 $out .=
"</xul:tabpanels></xul:tabbox>";
276 $out .=
"</xul:tabpanels></xul:tabbox>";
279 $out .= sprintf(
'</xul:dcpAttribute>');
286 private function getDefaultValue($aid) {
287 if (is_array($this->_defaultValues)) {
288 $def=$this->_defaultValues[$aid];
289 if (strtolower($def)==
"::getuserid()") $def=Doc::getUserId();
290 elseif (strtolower($def)==
"::userdocid()") $def=Doc::userDocId();
291 elseif (substr($def,0,2)=="::") $def='';
297 private function bindingEditLeafAttribute(BasicAttribute &$oa)
300 $visibility = $oa->mvisibility ? $oa->mvisibility : $oa->visibility;
301 if ($visibility !=
'I') {
308 foreach ( $options as $option ) {
309 if ($oa->getOption($option)) {
310 $opt .= $option .
'="';
311 $opt .= $oa->encodeXml($oa->getOption($option),
true);
315 $label = $oa->encodeXml($oa->getLabel(),
true);
316 $common=sprintf(
' label="%s" type="%s" attrid="%s" mode="edit" visibility="%s" required="%s" defaultValue="%s" %s', $label, $oa->type, $oa->id, $visibility, $oa->needed?
'true':
'false', $this->getDefaultValue($oa->id), $opt);
319 $out = sprintf(
'<xul:dcpAttribute %s relationFamily="%s" multiple="%s"/>', $common, trim($oa->format), ($oa->getOption(
"multiple") ==
"yes") ?
"true" :
"false");
322 $out = sprintf(
'<xul:dcpAttribute %s multiple="%s"/>', $common, ($oa->getOption(
"multiple") ==
"yes") ?
"true" :
"false");
325 $out = sprintf(
'<xul:dcpAttribute %s/>', $common);
getFamilyBindings(DocFam &$family)
__construct(Dir &$domain=null, DomainApi &$domainApi=null)
getFamiliesBindings($config)