17 include_once (
"DATA/Class.Document.php");
27 function addAttribute(
$id,
$label, $order,
$type, $parent =
'', $visibility =
'W', $intitle =
false, $inabstract =
false, $needed =
false, $link =
'', $elink =
'', $phpfile =
"", $phpfunc =
'', $constraint =
'', $options = null)
30 $err = $this->doc->lock(
true);
37 $this->
setError(_(
"attribute identificator is null"));
38 $err = $this->doc->unlock(
true);
41 if (!preg_match(
"/^[a-z0-9_]+$/",
$id)) {
42 $this->
setError(sprintf(_(
"attribute [%s] identificator syntax is unavalaible. Must have only alphanumeric characters and must not includes spaces") ,
$id));
43 $err = $this->doc->unlock(
true);
47 if (!preg_match(
"/^[H|R|W|S|O|I|U]$/", $visibility)) {
48 $this->
setError(sprintf(_(
"attribute [%s] visibility must be one of H,R,W,S,O,I,U") , $visibility));
49 $err = $this->doc->unlock(
true);
52 $oattr =
new DocAttr($this->dbaccess, array(
56 if ($oattr->isAffected()) {
57 $this->
setError(sprintf(_(
"attribute [%s] already exists : cannot add it") ,
$id));
58 $err = $this->doc->unlock(
true);
63 $oap = $this->doc->getAttribute($parent);
65 $this->
setError(sprintf(_(
"parent attribute [%s] not exists : cannot add it") , $parent));
66 $err = $this->doc->unlock(
true);
71 if ($this->completeAttributes($oattr,
$id,
$label, $order,
$type, $parent, $visibility, $intitle, $inabstract, $needed, $link, $elink, $phpfile, $phpfunc, $constraint, $options)) {
76 $cmd = $wsh .
" --api=fdl_adoc --docid=" . intval($this->doc->initid);
82 $err = $this->doc->unlock(
true);
86 function modifyAttribute(
$id,
$label, $order,
$type, $parent =
'', $visibility =
'W', $intitle =
false, $inabstract =
false, $needed =
false, $link =
'', $elink =
'', $phpfile =
"", $phpfunc =
'', $constraint =
'', $options = null)
89 $err = $this->doc->lock(
true);
96 $this->
setError(_(
"attribute identificator is null"));
97 $err = $this->doc->unlock(
true);
101 $oa = $this->doc->getAttribute(
$id);
103 $this->
setError(sprintf(_(
"attribute [%s] not exists : cannot modify it") ,
$id));
104 $err = $this->doc->unlock(
true);
108 $oattr =
new DocAttr($this->dbaccess, array(
112 if (!$oattr->isAffected()) $oattr =
new DocAttr($this->dbaccess, array(
116 if (!$oattr->isAffected()) {
117 $this->
setError(sprintf(_(
"attribute [%s] not exists : cannot modify it") ,
$id));
118 $err = $this->doc->unlock(
true);
121 if ($this->completeAttributes($oattr, $oattr->id,
$label, $order,
$type, $parent, $visibility, $intitle, $inabstract, $needed, $link, $elink, $phpfile, $phpfunc, $constraint, $options)) {
122 $err = $oattr->modify();
126 $cmd = $wsh .
" --api=fdl_adoc --docid=" . intval($oa->docid);
133 $err = $this->doc->unlock(
true);
141 $err = $this->doc->lock(
true);
148 $this->
setError(_(
"attribute identificator is null"));
149 $err = $this->doc->unlock(
true);
153 $oattr =
new DocAttr($this->dbaccess, array(
157 if (!$oattr->isAffected()) {
158 $this->
setError(sprintf(_(
"attribute [%s] not exists : cannot delete it") ,
$id));
159 $err = $this->doc->unlock(
true);
162 $err = $oattr->delete();
166 $cmd = $wsh .
"--api=fdl_adoc --docid=" . intval($this->doc->initid);
172 $err = $this->doc->unlock(
true);
177 private function completeAttributes(&$oattr,
$id,
$label, $order,
$type, $parent =
'', $visibility =
'W', $intitle =
false, $inabstract =
false, $needed =
false, $link =
'', $elink =
'', $phpfile =
"", $phpfunc =
'', $constraint =
'', $options = null)
182 $this->
setError(_(
"attribute identificator is null"));
185 if (!preg_match(
"/^[a-z0-9_:]+$/",
$id)) {
186 $this->
setError(sprintf(_(
"attribute [%s] identificator syntax is unavalaible. Must have only alphanumeric characters and must not includes spaces") ,
$id));
190 if ($visibility !== null) {
191 if (!preg_match(
"/^[H|R|W|S|O|I|U]$/", $visibility)) {
192 $this->
setError(sprintf(_(
"attribute [%s] visibility must be one of H,R,W,S,O,I,U") , $visibility));
198 $oap = $this->doc->getAttribute($parent);
200 $this->
setError(sprintf(_(
"parent attribute [%s] not exists : cannot add it") , $parent));
201 $err = $this->doc->unlock(
true);
206 if ($order && (!is_numeric($order))) {
208 if (preg_match(
"/^(upto|downto) ([a-z0-9_]+)$/", $order, $reg)) {
209 $oar = $this->doc->getAttribute($reg[2]);
211 $reforder = $oar->ordered;
213 if ($updown ==
'upto') $order = $reforder - 1;
214 else $order = $reforder + 1;
215 uasort($this->doc->attributes->attr,
"tordered");
216 $la = $this->doc->getAttributes();
220 while (list($k, $v) = each(
$la)) {
221 if ($k == $oar->id) {
228 if ($updown ==
'upto') {
229 while (($v = prev(
$la)) !==
false) {
230 if ($v->ordered < $order) {
233 if ($v->id !=
$id) $needdown[] = $v;
236 while (($v = next(
$la)) !==
false) {
237 if ($v->ordered > $order) {
240 if ($v->id !=
$id) $needdown[] = $v;
243 $famtoupdate = array();
244 foreach ($needdown as $k => $v) {
245 $attr =
new DocAttr($this->dbaccess, array(
249 if (!$attr->isAffected()) $attr =
new DocAttr($this->dbaccess, array(
253 if ($attr->isAffected()) {
254 if ($updown ==
'upto') $attr->ordered = $v->ordered - 1;
255 else $attr->ordered = $v->ordered + 1;
256 $err = $attr->modify();
257 if ($v->docid != $this->doc->id) {
258 $famtoupdate[$v->docid] = $v->docid;
263 foreach ($famtoupdate as $k => $v) {
265 $cmd = $wsh .
" --api=fdl_adoc --docid=" . intval($k);
268 }
else $order = null;
270 $this->
setError(sprintf(_(
"syntax error for order %s. May be an integer or a relative upto or downto identificator") , $order));
276 $oattr->docid = $this->doc->id;
279 if ($intitle !== null) $oattr->title = $intitle ?
'Y' :
'N';
280 if ($inabtract !== null) $oattr->abstract = $inabtract ?
'Y' :
'N';
281 if ($needed !== null) $oattr->needed = $needed ?
'Y' :
'N';
283 if ($parent !== null) $oattr->frameid = $parent ? $parent :
"0";
284 if ($order !== null) $oattr->ordered = intval($order);
285 if ($visibility !== null) $oattr->visibility = $visibility;
286 if ($link !== null) $oattr->link = $link;
287 if ($phpfile !== null) $oattr->phpfile = $phpfile;
288 if ($phpfunc !== null) $oattr->phpfunc = $phpfunc;
289 if ($elink !== null) $oattr->elink = $elink;
290 if ($constraint !== null) $oattr->phpconstraint = $constraint;
292 if ($options !== null) {
294 foreach ($options as $k => $v) {
297 $oattr->options = implode(
"|", $opt);
300 $oattr->usefor =
'N';