Commit 16322ff6bf96d5b8f6963372e0ba9c7a3bacc53a

Authored by Mark Holtzhausen
1 parent 4a47d90c

CRLF Fixes - PLEASE USE "git config --global core.autocrlf true"

plugins/multiselect/InetWidgets.php
1   -<?php
2   -/**
3   - * $Id$
4   - *
5   - * KnowledgeTree Community Edition
6   - * Document Management Made Simple
7   - * Copyright (C) 2008, 2009 KnowledgeTree Inc.
8   - * Portions copyright The Jam Warehouse Software (Pty) Limited
9   - *
10   - * This program is free software; you can redistribute it and/or modify it under
11   - * the terms of the GNU General Public License version 3 as published by the
12   - * Free Software Foundation.
13   - *
14   - * This program is distributed in the hope that it will be useful, but WITHOUT
15   - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16   - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17   - * details.
18   - *
19   - * You should have received a copy of the GNU General Public License
20   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - *
22   - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
23   - * California 94120-7775, or email info@knowledgetree.com.
24   - *
25   - * The interactive user interfaces in modified source and object code versions
26   - * of this program must display Appropriate Legal Notices, as required under
27   - * Section 5 of the GNU General Public License version 3.
28   - *
29   - * In accordance with Section 7(b) of the GNU General Public License version 3,
30   - * these Appropriate Legal Notices must retain the display of the "Powered by
31   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
32   - * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
33   - * must display the words "Powered by KnowledgeTree" and retain the original
34   - * copyright notice.
35   - * Contributor( s): ______________________________________
36   - *
37   - */
38   -
39   -require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php');
40   -require_once(KT_LIB_DIR . '/widgets/basewidget.inc.php');
41   -require_once(KT_LIB_DIR . '/templating/templating.inc.php');
42   -require_once(KT_LIB_DIR . '/browse/DocumentCollection.inc.php');
43   -
44   -class InetMultiselectWidget extends KTBaseWidget
45   -{
46   - var $sTemplate = "multiselect/selection";
47   -
48   -
49   - /**
50   - * assign the class variables
51   - * @return
52   - * @param $sLabel Object
53   - * @param $sDescription Object
54   - * @param $sName Object
55   - * @param $value Object
56   - * @param $oPage Object
57   - * @param $bRequired Object[optional]
58   - * @param $sId Object[optional]
59   - * @param $aErrors Object[optional]
60   - * @param $aOptions Object[optional]
61   - *
62   - * iNET Process
63   - */
64   - function InetMultiselectWidget($sLabel, $sDescription, $sName, $value, &$oPage, $bRequired = false, $sId = null, $aErrors = null, $aOptions = null)
65   - {
66   - $this->sLabel = $sLabel;
67   - $this->sDescription = $sDescription;
68   - $this->sName = $sName;
69   - $this->value = $value;
70   - $this->oPage =& $oPage;
71   - $this->bRequired = $bRequired;
72   - $this->sId = $sId;
73   - $this->aOptions = $aOptions;
74   - $this->aErrors = $aErrors;
75   -
76   - if (is_null($this->aOptions)) { $this->aOptions = array(); }
77   - // default to being a bit bigger.
78   - $this->aOptions['width'] = KTUtil::arrayGet($this->aOptions, 'width', '45');
79   - if($this->aOptions['lookup_type'] == "multiwithcheckboxes")
80   - {
81   - $this->sTemplate = "multiselect/simple_selection";
82   - }
83   -
84   - }
85   -
86   -
87   - /**
88   - * returns the rendered templates
89   - * @return
90   - *
91   - * iNET Process
92   - */
93   - function render() {
94   - // very simple, general purpose passthrough. Chances are this is sufficient,
95   - // just override the template being used.
96   - $bHasErrors = false;
97   - if (count($this->aErrors) != 0) { $bHasErrors = true; }
98   -
99   - $oTemplating =& KTTemplating::getSingleton();
100   - $oTemplate = $oTemplating->loadTemplate($this->sTemplate);
101   -
102   - $aTemplateData = array(
103   - "context" => $this,
104   - "label" => $this->sLabel,
105   - "description" => $this->sDescription,
106   - "name" => $this->sName,
107   - "required" => $this->bRequired,
108   - "page" => $this->oPage,
109   - "has_id" => ($this->sId !== null),
110   - "id" => $this->sId,
111   - "has_value" => ($this->value !== null),
112   - "value" => $this->value,
113   - "has_errors" => $bHasErrors,
114   - "errors" => $this->aErrors,
115   - "options" => $this->aOptions,
116   - "vocab" => $this->aOptions['vocab'],
117   - );
118   - return $oTemplate->render($aTemplateData);
119   - }
120   -
121   -
122   - /**
123   - * returns the selected lookup value
124   - * @return
125   - * @param $lookup Object
126   - *
127   - * iNET Process
128   - */
129   - function selected($lookup) {
130   - if ($this->bMulti) {
131   - return $this->_valuesearch[$lookup];
132   - } else {
133   - return ($this->value == $lookup);
134   - }
135   - }
136   -
137   - /**
138   - *
139   - * @return array
140   - * @param $raw_data array
141   - *
142   - * iNET Process
143   - */
144   - function process($raw_data) {
145   - return array($this->sBasename => $raw_data[$this->sBasename]);
146   - }
147   -}
148   -
  1 +<?php
  2 +/**
  3 + * $Id$
  4 + *
  5 + * KnowledgeTree Community Edition
  6 + * Document Management Made Simple
  7 + * Copyright (C) 2008, 2009 KnowledgeTree Inc.
  8 + * Portions copyright The Jam Warehouse Software (Pty) Limited
  9 + *
  10 + * This program is free software; you can redistribute it and/or modify it under
  11 + * the terms of the GNU General Public License version 3 as published by the
  12 + * Free Software Foundation.
  13 + *
  14 + * This program is distributed in the hope that it will be useful, but WITHOUT
  15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  17 + * details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + *
  22 + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
  23 + * California 94120-7775, or email info@knowledgetree.com.
  24 + *
  25 + * The interactive user interfaces in modified source and object code versions
  26 + * of this program must display Appropriate Legal Notices, as required under
  27 + * Section 5 of the GNU General Public License version 3.
  28 + *
  29 + * In accordance with Section 7(b) of the GNU General Public License version 3,
  30 + * these Appropriate Legal Notices must retain the display of the "Powered by
  31 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  32 + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
  33 + * must display the words "Powered by KnowledgeTree" and retain the original
  34 + * copyright notice.
  35 + * Contributor( s): ______________________________________
  36 + *
  37 + */
  38 +
  39 +require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php');
  40 +require_once(KT_LIB_DIR . '/widgets/basewidget.inc.php');
  41 +require_once(KT_LIB_DIR . '/templating/templating.inc.php');
  42 +require_once(KT_LIB_DIR . '/browse/DocumentCollection.inc.php');
  43 +
  44 +class InetMultiselectWidget extends KTBaseWidget
  45 +{
  46 + var $sTemplate = "multiselect/selection";
  47 +
  48 +
  49 + /**
  50 + * assign the class variables
  51 + * @return
  52 + * @param $sLabel Object
  53 + * @param $sDescription Object
  54 + * @param $sName Object
  55 + * @param $value Object
  56 + * @param $oPage Object
  57 + * @param $bRequired Object[optional]
  58 + * @param $sId Object[optional]
  59 + * @param $aErrors Object[optional]
  60 + * @param $aOptions Object[optional]
  61 + *
  62 + * iNET Process
  63 + */
  64 + function InetMultiselectWidget($sLabel, $sDescription, $sName, $value, &$oPage, $bRequired = false, $sId = null, $aErrors = null, $aOptions = null)
  65 + {
  66 + $this->sLabel = $sLabel;
  67 + $this->sDescription = $sDescription;
  68 + $this->sName = $sName;
  69 + $this->value = $value;
  70 + $this->oPage =& $oPage;
  71 + $this->bRequired = $bRequired;
  72 + $this->sId = $sId;
  73 + $this->aOptions = $aOptions;
  74 + $this->aErrors = $aErrors;
  75 +
  76 + if (is_null($this->aOptions)) { $this->aOptions = array(); }
  77 + // default to being a bit bigger.
  78 + $this->aOptions['width'] = KTUtil::arrayGet($this->aOptions, 'width', '45');
  79 + if($this->aOptions['lookup_type'] == "multiwithcheckboxes")
  80 + {
  81 + $this->sTemplate = "multiselect/simple_selection";
  82 + }
  83 +
  84 + }
  85 +
  86 +
  87 + /**
  88 + * returns the rendered templates
  89 + * @return
  90 + *
  91 + * iNET Process
  92 + */
  93 + function render() {
  94 + // very simple, general purpose passthrough. Chances are this is sufficient,
  95 + // just override the template being used.
  96 + $bHasErrors = false;
  97 + if (count($this->aErrors) != 0) { $bHasErrors = true; }
  98 +
  99 + $oTemplating =& KTTemplating::getSingleton();
  100 + $oTemplate = $oTemplating->loadTemplate($this->sTemplate);
  101 +
  102 + $aTemplateData = array(
  103 + "context" => $this,
  104 + "label" => $this->sLabel,
  105 + "description" => $this->sDescription,
  106 + "name" => $this->sName,
  107 + "required" => $this->bRequired,
  108 + "page" => $this->oPage,
  109 + "has_id" => ($this->sId !== null),
  110 + "id" => $this->sId,
  111 + "has_value" => ($this->value !== null),
  112 + "value" => $this->value,
  113 + "has_errors" => $bHasErrors,
  114 + "errors" => $this->aErrors,
  115 + "options" => $this->aOptions,
  116 + "vocab" => $this->aOptions['vocab'],
  117 + );
  118 + return $oTemplate->render($aTemplateData);
  119 + }
  120 +
  121 +
  122 + /**
  123 + * returns the selected lookup value
  124 + * @return
  125 + * @param $lookup Object
  126 + *
  127 + * iNET Process
  128 + */
  129 + function selected($lookup) {
  130 + if ($this->bMulti) {
  131 + return $this->_valuesearch[$lookup];
  132 + } else {
  133 + return ($this->value == $lookup);
  134 + }
  135 + }
  136 +
  137 + /**
  138 + *
  139 + * @return array
  140 + * @param $raw_data array
  141 + *
  142 + * iNET Process
  143 + */
  144 + function process($raw_data) {
  145 + return array($this->sBasename => $raw_data[$this->sBasename]);
  146 + }
  147 +}
  148 +
149 149 ?>
150 150 \ No newline at end of file
... ...
plugins/multiselect/InetdocumentFieldsv2.php
1   -<?php
2   -/**
3   - * $Id$
4   - *
5   - * KnowledgeTree Community Edition
6   - * Document Management Made Simple
7   - * Copyright (C) 2008, 2009 KnowledgeTree Inc.
8   - * Portions copyright The Jam Warehouse Software (Pty) Limited
9   - *
10   - * This program is free software; you can redistribute it and/or modify it under
11   - * the terms of the GNU General Public License version 3 as published by the
12   - * Free Software Foundation.
13   - *
14   - * This program is distributed in the hope that it will be useful, but WITHOUT
15   - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16   - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17   - * details.
18   - *
19   - * You should have received a copy of the GNU General Public License
20   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - *
22   - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
23   - * California 94120-7775, or email info@knowledgetree.com.
24   - *
25   - * The interactive user interfaces in modified source and object code versions
26   - * of this program must display Appropriate Legal Notices, as required under
27   - * Section 5 of the GNU General Public License version 3.
28   - *
29   - * In accordance with Section 7(b) of the GNU General Public License version 3,
30   - * these Appropriate Legal Notices must retain the display of the "Powered by
31   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
32   - * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
33   - * must display the words "Powered by KnowledgeTree" and retain the original
34   - * copyright notice.
35   - * Contributor( s): ______________________________________
36   - *
37   - */
38   -
39   -require_once(KT_LIB_DIR . '/dispatcher.inc.php');
40   -require_once(KT_LIB_DIR . '/metadata/fieldset.inc.php');
41   -require_once(KT_LIB_DIR . '/widgets/forms.inc.php');
42   -require_once(KT_LIB_DIR . '/plugins/pluginutil.inc.php');
43   -
44   -class InetDocumentFieldDispatcher extends KTAdminDispatcher {
45   - var $bAutomaticTransaction = true;
46   - var $bHaveConditional = null;
47   - var $sHelpPage = 'ktcore/admin/document fieldsets.html';
48   -
49   - /**
50   - *
51   - * @return.
52   - * @param.
53   - *
54   - * iNET Process
55   - */
56   - function predispatch() {
57   - $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Document Field Management'));
58   - $this->persistParams(array('fFieldsetId'));
59   -
60   - $this->oFieldset = KTFieldset::get(KTUtil::arrayGet($_REQUEST, 'fFieldsetId'));
61   - if (PEAR::isError($this->oFieldset)) {
62   - $this->oFieldset = null;
63   - unset($_REQUEST['fFieldset']); // prevent further attacks.
64   - } else {
65   - $this->aBreadcrumbs[] = array('url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","edit")), 'name' => $this->oFieldset->getName());
66   - }
67   - $this->bHaveConditional = KTPluginUtil::pluginIsActive('ktextra.conditionalmetadata.plugin');
68   - }
69   -
70   - /**
71   - * create template
72   - * @Param.
73   - * @return template.
74   - *
75   - * iNET Process
76   - */
77   - function do_main () {
78   - $oTemplate =& $this->oValidator->validateTemplate('ktcore/metadata/admin/list');
79   -
80   - $oTemplate->setData(array(
81   - 'context' => $this,
82   - 'fieldsets' => KTFieldset::getList("disabled != true AND namespace != 'tagcloud'"),
83   - ));
84   - return $oTemplate;
85   - }
86   -
87   - /**
88   - * form for creating new fieldset.
89   - * @Param.
90   - * @return form.
91   - *
92   - * iNET Process
93   - */
94   - function form_create() {
95   - $oForm = new KTForm;
96   - $oForm->setOptions(array(
97   - 'identifier' => 'ktcore.fieldsets.create',
98   - 'label' => _kt("Create New Fieldset"),
99   - 'submit_label' => _kt('Create Fieldset'),
100   - 'cancel_action' => 'main',
101   - 'fail_action' => 'newfieldset',
102   - 'action' => 'create',
103   - 'context' => $this,
104   - ));
105   -
106   -
107   - // construct the widget set.
108   - // we use a slight variation here, because "type" is only present in certain circumstances.
109   - $widgets = array(
110   - array('ktcore.widgets.string',array(
111   - 'label' => _kt("Fieldset Name"),
112   - 'name' => 'name',
113   - 'required' => true,
114   - 'description' => _kt("Each fieldset needs a unique name."),
115   - )),
116   - array('ktcore.widgets.text',array(
117   - 'label' => _kt("Description"),
118   - 'name' => 'description',
119   - 'required' => true,
120   - 'description' => _kt("In order to ensure that the data that users enter is useful, it is essential that you provide a good example."),
121   - )),
122   - );
123   - if ($this->bHaveConditional) {
124   -
125   - // FIXME get this from some external source.
126   - $type_vocab = array(
127   - 'normal' => _kt("Normal"),
128   - 'conditional' => _kt("Conditional"),
129   - );
130   -
131   - $widgets[] = array('ktcore.widgets.selection', array(
132   - 'label' => _kt("Fieldset Type"),
133   - 'use_simple' => false,
134   - 'description' => _kt("It is possibler to create different types of fieldsets. The most common kind is a \"normal\" fieldset, which can be configured to have different kinds of fields. The administrator may have installed additional plugins which provide different types of fieldsets."),
135   - 'important_description' => _kt('Note that it is not possible to convert between different types of fieldsets, so please choose carefully.'),
136   - 'name' => 'fieldset_type',
137   - 'required' => true,
138   - 'value' => 'normal',
139   - 'vocab' => $type_vocab,
140   - ));
141   - }
142   -
143   - $widgets[] = array('ktcore.widgets.boolean',array(
144   - 'label' => _kt("Generic"),
145   - 'name' => 'generic',
146   - 'description' => _kt("A generic fieldset is one that is available for every document by default. These fieldsets will be available for users to edit and add for every document in the document management system."),
147   - ));
148   -
149   - $oForm->setWidgets($widgets);
150   -
151   - // similarly, we construct validators here.
152   - $validators = array(
153   - array('ktcore.validators.string', array(
154   - 'test' => 'name',
155   - 'output' => 'name',
156   - )),
157   - array('ktcore.validators.string', array(
158   - 'test' => 'description',
159   - 'output' => 'description',
160   - )),
161   - array('ktcore.validators.boolean', array(
162   - 'test' => 'generic',
163   - 'output' => 'generic',
164   - )),
165   - );
166   -
167   - if ($this->bHaveConditional) {
168   - $validators[] = array('ktcore.validators.string', array(
169   - 'test' => 'fieldset_type',
170   - 'output' => 'fieldset_type',
171   - ));
172   - }
173   -
174   - $oForm->setValidators($validators);
175   -
176   - return $oForm;
177   - }
178   - /**
179   - * Creates a new page
180   - * @return form
181   - *
182   - * iNET Process
183   - */
184   - function do_newfieldset() {
185   - $this->oPage->setBreadcrumbDetails(_kt("Create New Fieldset"));
186   - $oForm = $this->form_create();
187   -
188   - return $oForm->render();
189   - }
190   - /**
191   - * Creates a fieldsets
192   - * @return
193   - *
194   - * iNET Process
195   - */
196   - function do_create() {
197   - $oForm = $this->form_create();
198   - $res = $oForm->validate();
199   -
200   - $data = $res['results'];
201   - $errors = $res['errors'];
202   - $extra_errors = array();
203   -
204   - if (!empty($data['name'])) {
205   - $oFieldset = KTFieldset::getByName($data['name']);
206   - if (!PEAR::isError($oFieldset)) {
207   - // means we're looking at an existing name
208   - $extra_errors['name'] = _kt("There is already a fieldset with that name.");
209   - }
210   - }
211   -
212   - $is_conditional = false;
213   - // FIXME this is inelegant. get it from somewhere else.
214   - if ($this->bHaveConditional && ($data['fieldset_type'] == 'conditional')) {
215   - $is_conditional = true;
216   - }
217   -
218   -
219   - if (!empty($errors) || !empty($extra_errors)) {
220   - return $oForm->handleError(null, $extra_errors);
221   - }
222   -
223   - // we also need a namespace.
224   - $temp_name = $data['name'];
225   - $namespace = KTUtil::nameToLocalNamespace('fieldsets', $temp_name);
226   - $oOldFieldset = KTFieldset::getByNamespace($namespace);
227   -
228   - while (!PEAR::isError($oOldFieldset)) {
229   - $temp_name .= '_';
230   - $namespace = KTUtil::nameToLocalNamespace('fieldsets', $temp_name);
231   - $oOldFieldset = KTFieldset::getByNamespace($namespace);
232   - }
233   -
234   - // we now know its a non-conflicting one.
235   - // FIXME handle conditional fieldsets, which should be ... a different object.
236   - $oFieldset = KTFieldset::createFromArray(array(
237   - "name" => $data['name'],
238   - "description" => $data['description'],
239   - "namespace" => $namespace,
240   - "mandatory" => false, // FIXME deprecated
241   - "isConditional" => $is_conditional, // handle this
242   - "isGeneric" => $data['generic'],
243   - "isComplete" => false,
244   - "isComplex" => false,
245   - "isSystem" => false,
246   - ));
247   - if (PEAR::isError($oFieldset)) {
248   - return $oForm->handleError(sprintf(_kt("Failed to create fieldset: %s"), $oFieldset->getMessage()));
249   - }
250   -
251   - $this->successRedirectTo('edit',_kt("Fieldset created."), sprintf('fFieldsetId=%d', $oFieldset->getId()));
252   - }
253   - /**
254   - * Gets tyoes for fieldsets
255   - * @return string
256   - * @param $oFieldset Object
257   - *
258   - * iNET Process
259   - */
260   - function getTypesForFieldset($oFieldset) {
261   - global $default;
262   - if ($oFieldset->getIsGeneric()) {
263   - return _kt('All types use this generic fieldset.');
264   - }
265   -
266   - $types = $oFieldset->getAssociatedTypes();
267   - if (PEAR::isError($types)) {
268   - $default->log->debug('Fieldsets admin: Error retrieving list of associated document types.');
269   - return _kt('Error retrieving list of types.');
270   - }
271   - if (empty($types)) {
272   - return _kt('None');
273   - }
274   -
275   - $aNames = array();
276   - foreach ($types as $oType) {
277   - if (!PEAR::isError($oType)) {
278   - $aNames[] = $oType->getName();
279   - }else{
280   - $default->log->debug('Fieldsets admin: Document type gives error: '.$oType->getMessage());
281   - }
282   - }
283   -
284   - $list = implode(', ', $aNames);
285   - $length = mb_strlen($list);
286   -
287   - if($length < 50){
288   - return $list;
289   - }
290   - $default->log->debug('Fieldsets admin: wrapping the list of doc types from length '.$length);
291   -
292   - // Wrap the list to 50 characters per line
293   - $wrapList = '';
294   - $cut = 0;
295   - while ($length > 50 && $cut !== false){
296   - $cut = strpos($list, ' ', 50);
297   - $wrapList .= mb_strcut($list, 0, $cut);
298   - $wrapList .= '<br />';
299   - $list = mb_strcut($list, $cut);
300   - $length = mb_strlen($list);
301   - }
302   - $wrapList .= $list;
303   -
304   - return $wrapList;
305   - }
306   -
307   - /**
308   - * Edits fields
309   - * @return template
310   - *
311   - * iNET Process
312   - */
313   - function do_edit() {
314   -
315   - // here we engage in some major evil.
316   - // we check for the subevent var
317   - // and subdispatch if appropriate.
318   - //
319   - // saves a little code-duplication (actually, a lot of code-duplication)
320   -
321   - // FIXME this is essentially a stub for the fieldset-delegation code.
322   - if ($this->oFieldset->getIsConditional()) {
323   -
324   - require_once(KT_DIR.'/plugins/ktcore/admin/fieldsets/conditional.inc.php');
325   - $oSubDispatcher = new ConditionalFieldsetManagementDispatcher;
326   - } else {
327   - // multiselect change start
328   - if(KTPluginUtil::pluginIsActive('inet.multiselect.lookupvalue.plugin'))
329   - {
330   - require_once(KT_DIR.'/plugins/multiselect/inetbasic.inc.php');
331   - $oSubDispatcher = new InetBasicFieldsetManagementDispatcher;
332   - }
333   - else
334   - {
335   -
336   - require_once(KT_DIR.'/plugins/ktcore/admin/fieldsets/basic.inc.php');
337   - $oSubDispatcher = new BasicFieldsetManagementDispatcher;
338   - }
339   - // multiselect change end
340   -
341   -
342   - }
343   -
344   - $subevent_var = 'fieldset_action';
345   - $subevent = KTUtil::arrayGet($_REQUEST, $subevent_var);
346   - if (!empty($subevent)) {
347   - // do nothing, since this will handle everything
348   - $this_url = KTUtil::addQueryStringSelf($this->meldPersistQuery("","edit"));
349   - $oSubDispatcher->redispatch($subevent_var, null, $this, $this_url);
350   - exit(0);
351   - } else {
352   - // what we want is the "additional info" section
353   - $additional = $oSubDispatcher->describe_fieldset($this->oFieldset);
354   - }
355   -
356   - $oTemplate =& $this->oValidator->validateTemplate('ktcore/metadata/admin/edit');
357   - $oTemplate->setData(array(
358   - 'context' => $this,
359   - 'fieldset_name' => $this->oFieldset->getName(),
360   - 'additional' => $additional,
361   - ));
362   - return $oTemplate->render();
363   - }
364   - /**
365   - * deletes field
366   - * @return
367   - *
368   - * iNET Process
369   - */
370   - function do_delete() {
371   - $this->startTransaction();
372   -
373   - // check if fieldset is associated with a document type - remove association
374   - $types = $this->oFieldset->getAssociatedTypes();
375   - $sFieldSetId = $this->oFieldset->getId();
376   - if(!PEAR::isError($types) AND !empty($types)){
377   - foreach($types as $oType){
378   - $res = KTMetadataUtil::removeSetsFromDocumentType($oType, $sFieldSetId);
379   - }
380   - }
381   -
382   - $res = $this->oFieldset->delete('true');
383   - $this->oValidator->notErrorFalse($res, array(
384   - 'redirect_to' => array('main', ''),
385   - 'message' => _kt('Could not delete fieldset'),
386   - ));
387   - $this->successRedirectToMain(_kt('Fieldset deleted'));
388   - }
389   - /**
390   - * Form for edit
391   - * @return form
392   - *
393   - * iNET Process
394   - */
395   - function form_edit() {
396   - $oForm = new KTForm;
397   - $oForm->setOptions(array(
398   - 'identifier' => 'ktcore.fieldsets.edit',
399   - 'label' => _kt("Change Fieldset Details"),
400   - 'submit_label' => _kt('Update Fieldset'),
401   - 'cancel_action' => 'edit',
402   - 'fail_action' => 'editfieldset',
403   - 'action' => 'savefieldset',
404   - 'context' => $this,
405   - ));
406   -
407   -
408   - // construct the widget set.
409   - // we use a slight variation here, because "type" is only present in certain circumstances.
410   - $widgets = array(
411   - array('ktcore.widgets.string',array(
412   - 'label' => _kt("Fieldset Name"),
413   - 'name' => 'name',
414   - 'required' => true,
415   - 'description' => _kt("Each fieldset needs a unique name."),
416   - 'value' => sanitizeForHTML($this->oFieldset->getName()),
417   - )),
418   - array('ktcore.widgets.text',array(
419   - 'label' => _kt("Description"),
420   - 'name' => 'description',
421   - 'required' => true,
422   - 'description' => _kt("In order to ensure that the data that users enter is useful, it is essential that you provide a good example."),
423   - 'value' => sanitizeForHTML($this->oFieldset->getDescription()),
424   - )),
425   - );
426   -
427   - $widgets[] = array('ktcore.widgets.boolean',array(
428   - 'label' => _kt("Generic"),
429   - 'name' => 'generic',
430   - 'description' => _kt("A generic fieldset is one that is available for every document by default. These fieldsets will be available for users to edit and add for every document in the document management system."),
431   - 'value' => $this->oFieldset->getIsGeneric(),
432   - ));
433   -
434   - $oForm->setWidgets($widgets);
435   -
436   - // similarly, we construct validators here.
437   - $validators = array(
438   - array('ktcore.validators.string', array(
439   - 'test' => 'name',
440   - 'output' => 'name',
441   - )),
442   - array('ktcore.validators.string', array(
443   - 'test' => 'description',
444   - 'output' => 'description',
445   - )),
446   - array('ktcore.validators.boolean', array(
447   - 'test' => 'generic',
448   - 'output' => 'generic',
449   - )),
450   - );
451   -
452   - $oForm->setValidators($validators);
453   -
454   - return $oForm;
455   - }
456   - /**
457   - * Edits a fieldsets
458   - * @return form
459   - *
460   - * iNET Process
461   - */
462   - function do_editfieldset() {
463   - $oForm = $this->form_edit();
464   - $this->oPage->setBreadcrumbDetails(_kt('edit fieldset'));
465   - return $oForm->renderPage(_kt("Edit Fieldset"));
466   - }
467   - /**
468   - * saves a fieldset
469   - * @return
470   - *
471   - * iNET Process
472   - */
473   - function do_savefieldset() {
474   - $oForm = $this->form_edit();
475   - $res = $oForm->validate();
476   -
477   - $data = $res['results'];
478   - $errors = $res['errors'];
479   - $extra_errors = array();
480   - if ($data['name'] != $this->oFieldset->getName()) {
481   - $oOldFieldset = KTFieldset::getByName($data['name']);
482   - if (!PEAR::isError($oOldFieldset)) {
483   - $extra_errors['name'][] = _kt("A fieldset with that name already exists.");
484   - }
485   - }
486   -
487   - if (!empty($errors) || !empty($extra_errors)) {
488   - return $oForm->handleError(null, $extra_errors);
489   - }
490   -
491   - $this->startTransaction();
492   -
493   - $this->oFieldset->setName($data['name']);
494   - $this->oFieldset->setDescription($data['description']);
495   - $bGeneric = $data['generic'];
496   - if ($bGeneric != $this->oFieldset->getIsGeneric() && $bGeneric == true) {
497   - // delink it from all doctypes.
498   - $aTypes = $this->oFieldset->getAssociatedTypes();
499   - foreach ($aTypes as $oType) {
500   - $res = KTMetadataUtil::removeSetsFromDocumentType($oType, $this->oFieldset->getId());
501   - if (PEAR::isError($res)) {
502   - $this->errorRedirectTo('edit', _kt('Could not save fieldset changes'));
503   - exit(0);
504   - }
505   - }
506   - }
507   -
508   - $this->oFieldset->setIsGeneric($data['generic']);
509   -
510   - $res = $this->oFieldset->update();
511   - if (PEAR::isError($res)) {
512   - $this->errorRedirectTo('edit', _kt('Could not save fieldset changes'));
513   - exit(0);
514   - }
515   -
516   - return $this->successRedirectTo('edit', _kt("Fieldset details updated."));
517   - }
518   -}
519   -
  1 +<?php
  2 +/**
  3 + * $Id$
  4 + *
  5 + * KnowledgeTree Community Edition
  6 + * Document Management Made Simple
  7 + * Copyright (C) 2008, 2009 KnowledgeTree Inc.
  8 + * Portions copyright The Jam Warehouse Software (Pty) Limited
  9 + *
  10 + * This program is free software; you can redistribute it and/or modify it under
  11 + * the terms of the GNU General Public License version 3 as published by the
  12 + * Free Software Foundation.
  13 + *
  14 + * This program is distributed in the hope that it will be useful, but WITHOUT
  15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  17 + * details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + *
  22 + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
  23 + * California 94120-7775, or email info@knowledgetree.com.
  24 + *
  25 + * The interactive user interfaces in modified source and object code versions
  26 + * of this program must display Appropriate Legal Notices, as required under
  27 + * Section 5 of the GNU General Public License version 3.
  28 + *
  29 + * In accordance with Section 7(b) of the GNU General Public License version 3,
  30 + * these Appropriate Legal Notices must retain the display of the "Powered by
  31 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  32 + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
  33 + * must display the words "Powered by KnowledgeTree" and retain the original
  34 + * copyright notice.
  35 + * Contributor( s): ______________________________________
  36 + *
  37 + */
  38 +
  39 +require_once(KT_LIB_DIR . '/dispatcher.inc.php');
  40 +require_once(KT_LIB_DIR . '/metadata/fieldset.inc.php');
  41 +require_once(KT_LIB_DIR . '/widgets/forms.inc.php');
  42 +require_once(KT_LIB_DIR . '/plugins/pluginutil.inc.php');
  43 +
  44 +class InetDocumentFieldDispatcher extends KTAdminDispatcher {
  45 + var $bAutomaticTransaction = true;
  46 + var $bHaveConditional = null;
  47 + var $sHelpPage = 'ktcore/admin/document fieldsets.html';
  48 +
  49 + /**
  50 + *
  51 + * @return.
  52 + * @param.
  53 + *
  54 + * iNET Process
  55 + */
  56 + function predispatch() {
  57 + $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Document Field Management'));
  58 + $this->persistParams(array('fFieldsetId'));
  59 +
  60 + $this->oFieldset = KTFieldset::get(KTUtil::arrayGet($_REQUEST, 'fFieldsetId'));
  61 + if (PEAR::isError($this->oFieldset)) {
  62 + $this->oFieldset = null;
  63 + unset($_REQUEST['fFieldset']); // prevent further attacks.
  64 + } else {
  65 + $this->aBreadcrumbs[] = array('url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","edit")), 'name' => $this->oFieldset->getName());
  66 + }
  67 + $this->bHaveConditional = KTPluginUtil::pluginIsActive('ktextra.conditionalmetadata.plugin');
  68 + }
  69 +
  70 + /**
  71 + * create template
  72 + * @Param.
  73 + * @return template.
  74 + *
  75 + * iNET Process
  76 + */
  77 + function do_main () {
  78 + $oTemplate =& $this->oValidator->validateTemplate('ktcore/metadata/admin/list');
  79 +
  80 + $oTemplate->setData(array(
  81 + 'context' => $this,
  82 + 'fieldsets' => KTFieldset::getList("disabled != true AND namespace != 'tagcloud'"),
  83 + ));
  84 + return $oTemplate;
  85 + }
  86 +
  87 + /**
  88 + * form for creating new fieldset.
  89 + * @Param.
  90 + * @return form.
  91 + *
  92 + * iNET Process
  93 + */
  94 + function form_create() {
  95 + $oForm = new KTForm;
  96 + $oForm->setOptions(array(
  97 + 'identifier' => 'ktcore.fieldsets.create',
  98 + 'label' => _kt("Create New Fieldset"),
  99 + 'submit_label' => _kt('Create Fieldset'),
  100 + 'cancel_action' => 'main',
  101 + 'fail_action' => 'newfieldset',
  102 + 'action' => 'create',
  103 + 'context' => $this,
  104 + ));
  105 +
  106 +
  107 + // construct the widget set.
  108 + // we use a slight variation here, because "type" is only present in certain circumstances.
  109 + $widgets = array(
  110 + array('ktcore.widgets.string',array(
  111 + 'label' => _kt("Fieldset Name"),
  112 + 'name' => 'name',
  113 + 'required' => true,
  114 + 'description' => _kt("Each fieldset needs a unique name."),
  115 + )),
  116 + array('ktcore.widgets.text',array(
  117 + 'label' => _kt("Description"),
  118 + 'name' => 'description',
  119 + 'required' => true,
  120 + 'description' => _kt("In order to ensure that the data that users enter is useful, it is essential that you provide a good example."),
  121 + )),
  122 + );
  123 + if ($this->bHaveConditional) {
  124 +
  125 + // FIXME get this from some external source.
  126 + $type_vocab = array(
  127 + 'normal' => _kt("Normal"),
  128 + 'conditional' => _kt("Conditional"),
  129 + );
  130 +
  131 + $widgets[] = array('ktcore.widgets.selection', array(
  132 + 'label' => _kt("Fieldset Type"),
  133 + 'use_simple' => false,
  134 + 'description' => _kt("It is possibler to create different types of fieldsets. The most common kind is a \"normal\" fieldset, which can be configured to have different kinds of fields. The administrator may have installed additional plugins which provide different types of fieldsets."),
  135 + 'important_description' => _kt('Note that it is not possible to convert between different types of fieldsets, so please choose carefully.'),
  136 + 'name' => 'fieldset_type',
  137 + 'required' => true,
  138 + 'value' => 'normal',
  139 + 'vocab' => $type_vocab,
  140 + ));
  141 + }
  142 +
  143 + $widgets[] = array('ktcore.widgets.boolean',array(
  144 + 'label' => _kt("Generic"),
  145 + 'name' => 'generic',
  146 + 'description' => _kt("A generic fieldset is one that is available for every document by default. These fieldsets will be available for users to edit and add for every document in the document management system."),
  147 + ));
  148 +
  149 + $oForm->setWidgets($widgets);
  150 +
  151 + // similarly, we construct validators here.
  152 + $validators = array(
  153 + array('ktcore.validators.string', array(
  154 + 'test' => 'name',
  155 + 'output' => 'name',
  156 + )),
  157 + array('ktcore.validators.string', array(
  158 + 'test' => 'description',
  159 + 'output' => 'description',
  160 + )),
  161 + array('ktcore.validators.boolean', array(
  162 + 'test' => 'generic',
  163 + 'output' => 'generic',
  164 + )),
  165 + );
  166 +
  167 + if ($this->bHaveConditional) {
  168 + $validators[] = array('ktcore.validators.string', array(
  169 + 'test' => 'fieldset_type',
  170 + 'output' => 'fieldset_type',
  171 + ));
  172 + }
  173 +
  174 + $oForm->setValidators($validators);
  175 +
  176 + return $oForm;
  177 + }
  178 + /**
  179 + * Creates a new page
  180 + * @return form
  181 + *
  182 + * iNET Process
  183 + */
  184 + function do_newfieldset() {
  185 + $this->oPage->setBreadcrumbDetails(_kt("Create New Fieldset"));
  186 + $oForm = $this->form_create();
  187 +
  188 + return $oForm->render();
  189 + }
  190 + /**
  191 + * Creates a fieldsets
  192 + * @return
  193 + *
  194 + * iNET Process
  195 + */
  196 + function do_create() {
  197 + $oForm = $this->form_create();
  198 + $res = $oForm->validate();
  199 +
  200 + $data = $res['results'];
  201 + $errors = $res['errors'];
  202 + $extra_errors = array();
  203 +
  204 + if (!empty($data['name'])) {
  205 + $oFieldset = KTFieldset::getByName($data['name']);
  206 + if (!PEAR::isError($oFieldset)) {
  207 + // means we're looking at an existing name
  208 + $extra_errors['name'] = _kt("There is already a fieldset with that name.");
  209 + }
  210 + }
  211 +
  212 + $is_conditional = false;
  213 + // FIXME this is inelegant. get it from somewhere else.
  214 + if ($this->bHaveConditional && ($data['fieldset_type'] == 'conditional')) {
  215 + $is_conditional = true;
  216 + }
  217 +
  218 +
  219 + if (!empty($errors) || !empty($extra_errors)) {
  220 + return $oForm->handleError(null, $extra_errors);
  221 + }
  222 +
  223 + // we also need a namespace.
  224 + $temp_name = $data['name'];
  225 + $namespace = KTUtil::nameToLocalNamespace('fieldsets', $temp_name);
  226 + $oOldFieldset = KTFieldset::getByNamespace($namespace);
  227 +
  228 + while (!PEAR::isError($oOldFieldset)) {
  229 + $temp_name .= '_';
  230 + $namespace = KTUtil::nameToLocalNamespace('fieldsets', $temp_name);
  231 + $oOldFieldset = KTFieldset::getByNamespace($namespace);
  232 + }
  233 +
  234 + // we now know its a non-conflicting one.
  235 + // FIXME handle conditional fieldsets, which should be ... a different object.
  236 + $oFieldset = KTFieldset::createFromArray(array(
  237 + "name" => $data['name'],
  238 + "description" => $data['description'],
  239 + "namespace" => $namespace,
  240 + "mandatory" => false, // FIXME deprecated
  241 + "isConditional" => $is_conditional, // handle this
  242 + "isGeneric" => $data['generic'],
  243 + "isComplete" => false,
  244 + "isComplex" => false,
  245 + "isSystem" => false,
  246 + ));
  247 + if (PEAR::isError($oFieldset)) {
  248 + return $oForm->handleError(sprintf(_kt("Failed to create fieldset: %s"), $oFieldset->getMessage()));
  249 + }
  250 +
  251 + $this->successRedirectTo('edit',_kt("Fieldset created."), sprintf('fFieldsetId=%d', $oFieldset->getId()));
  252 + }
  253 + /**
  254 + * Gets tyoes for fieldsets
  255 + * @return string
  256 + * @param $oFieldset Object
  257 + *
  258 + * iNET Process
  259 + */
  260 + function getTypesForFieldset($oFieldset) {
  261 + global $default;
  262 + if ($oFieldset->getIsGeneric()) {
  263 + return _kt('All types use this generic fieldset.');
  264 + }
  265 +
  266 + $types = $oFieldset->getAssociatedTypes();
  267 + if (PEAR::isError($types)) {
  268 + $default->log->debug('Fieldsets admin: Error retrieving list of associated document types.');
  269 + return _kt('Error retrieving list of types.');
  270 + }
  271 + if (empty($types)) {
  272 + return _kt('None');
  273 + }
  274 +
  275 + $aNames = array();
  276 + foreach ($types as $oType) {
  277 + if (!PEAR::isError($oType)) {
  278 + $aNames[] = $oType->getName();
  279 + }else{
  280 + $default->log->debug('Fieldsets admin: Document type gives error: '.$oType->getMessage());
  281 + }
  282 + }
  283 +
  284 + $list = implode(', ', $aNames);
  285 + $length = mb_strlen($list);
  286 +
  287 + if($length < 50){
  288 + return $list;
  289 + }
  290 + $default->log->debug('Fieldsets admin: wrapping the list of doc types from length '.$length);
  291 +
  292 + // Wrap the list to 50 characters per line
  293 + $wrapList = '';
  294 + $cut = 0;
  295 + while ($length > 50 && $cut !== false){
  296 + $cut = strpos($list, ' ', 50);
  297 + $wrapList .= mb_strcut($list, 0, $cut);
  298 + $wrapList .= '<br />';
  299 + $list = mb_strcut($list, $cut);
  300 + $length = mb_strlen($list);
  301 + }
  302 + $wrapList .= $list;
  303 +
  304 + return $wrapList;
  305 + }
  306 +
  307 + /**
  308 + * Edits fields
  309 + * @return template
  310 + *
  311 + * iNET Process
  312 + */
  313 + function do_edit() {
  314 +
  315 + // here we engage in some major evil.
  316 + // we check for the subevent var
  317 + // and subdispatch if appropriate.
  318 + //
  319 + // saves a little code-duplication (actually, a lot of code-duplication)
  320 +
  321 + // FIXME this is essentially a stub for the fieldset-delegation code.
  322 + if ($this->oFieldset->getIsConditional()) {
  323 +
  324 + require_once(KT_DIR.'/plugins/ktcore/admin/fieldsets/conditional.inc.php');
  325 + $oSubDispatcher = new ConditionalFieldsetManagementDispatcher;
  326 + } else {
  327 + // multiselect change start
  328 + if(KTPluginUtil::pluginIsActive('inet.multiselect.lookupvalue.plugin'))
  329 + {
  330 + require_once(KT_DIR.'/plugins/multiselect/inetbasic.inc.php');
  331 + $oSubDispatcher = new InetBasicFieldsetManagementDispatcher;
  332 + }
  333 + else
  334 + {
  335 +
  336 + require_once(KT_DIR.'/plugins/ktcore/admin/fieldsets/basic.inc.php');
  337 + $oSubDispatcher = new BasicFieldsetManagementDispatcher;
  338 + }
  339 + // multiselect change end
  340 +
  341 +
  342 + }
  343 +
  344 + $subevent_var = 'fieldset_action';
  345 + $subevent = KTUtil::arrayGet($_REQUEST, $subevent_var);
  346 + if (!empty($subevent)) {
  347 + // do nothing, since this will handle everything
  348 + $this_url = KTUtil::addQueryStringSelf($this->meldPersistQuery("","edit"));
  349 + $oSubDispatcher->redispatch($subevent_var, null, $this, $this_url);
  350 + exit(0);
  351 + } else {
  352 + // what we want is the "additional info" section
  353 + $additional = $oSubDispatcher->describe_fieldset($this->oFieldset);
  354 + }
  355 +
  356 + $oTemplate =& $this->oValidator->validateTemplate('ktcore/metadata/admin/edit');
  357 + $oTemplate->setData(array(
  358 + 'context' => $this,
  359 + 'fieldset_name' => $this->oFieldset->getName(),
  360 + 'additional' => $additional,
  361 + ));
  362 + return $oTemplate->render();
  363 + }
  364 + /**
  365 + * deletes field
  366 + * @return
  367 + *
  368 + * iNET Process
  369 + */
  370 + function do_delete() {
  371 + $this->startTransaction();
  372 +
  373 + // check if fieldset is associated with a document type - remove association
  374 + $types = $this->oFieldset->getAssociatedTypes();
  375 + $sFieldSetId = $this->oFieldset->getId();
  376 + if(!PEAR::isError($types) AND !empty($types)){
  377 + foreach($types as $oType){
  378 + $res = KTMetadataUtil::removeSetsFromDocumentType($oType, $sFieldSetId);
  379 + }
  380 + }
  381 +
  382 + $res = $this->oFieldset->delete('true');
  383 + $this->oValidator->notErrorFalse($res, array(
  384 + 'redirect_to' => array('main', ''),
  385 + 'message' => _kt('Could not delete fieldset'),
  386 + ));
  387 + $this->successRedirectToMain(_kt('Fieldset deleted'));
  388 + }
  389 + /**
  390 + * Form for edit
  391 + * @return form
  392 + *
  393 + * iNET Process
  394 + */
  395 + function form_edit() {
  396 + $oForm = new KTForm;
  397 + $oForm->setOptions(array(
  398 + 'identifier' => 'ktcore.fieldsets.edit',
  399 + 'label' => _kt("Change Fieldset Details"),
  400 + 'submit_label' => _kt('Update Fieldset'),
  401 + 'cancel_action' => 'edit',
  402 + 'fail_action' => 'editfieldset',
  403 + 'action' => 'savefieldset',
  404 + 'context' => $this,
  405 + ));
  406 +
  407 +
  408 + // construct the widget set.
  409 + // we use a slight variation here, because "type" is only present in certain circumstances.
  410 + $widgets = array(
  411 + array('ktcore.widgets.string',array(
  412 + 'label' => _kt("Fieldset Name"),
  413 + 'name' => 'name',
  414 + 'required' => true,
  415 + 'description' => _kt("Each fieldset needs a unique name."),
  416 + 'value' => sanitizeForHTML($this->oFieldset->getName()),
  417 + )),
  418 + array('ktcore.widgets.text',array(
  419 + 'label' => _kt("Description"),
  420 + 'name' => 'description',
  421 + 'required' => true,
  422 + 'description' => _kt("In order to ensure that the data that users enter is useful, it is essential that you provide a good example."),
  423 + 'value' => sanitizeForHTML($this->oFieldset->getDescription()),
  424 + )),
  425 + );
  426 +
  427 + $widgets[] = array('ktcore.widgets.boolean',array(
  428 + 'label' => _kt("Generic"),
  429 + 'name' => 'generic',
  430 + 'description' => _kt("A generic fieldset is one that is available for every document by default. These fieldsets will be available for users to edit and add for every document in the document management system."),
  431 + 'value' => $this->oFieldset->getIsGeneric(),
  432 + ));
  433 +
  434 + $oForm->setWidgets($widgets);
  435 +
  436 + // similarly, we construct validators here.
  437 + $validators = array(
  438 + array('ktcore.validators.string', array(
  439 + 'test' => 'name',
  440 + 'output' => 'name',
  441 + )),
  442 + array('ktcore.validators.string', array(
  443 + 'test' => 'description',
  444 + 'output' => 'description',
  445 + )),
  446 + array('ktcore.validators.boolean', array(
  447 + 'test' => 'generic',
  448 + 'output' => 'generic',
  449 + )),
  450 + );
  451 +
  452 + $oForm->setValidators($validators);
  453 +
  454 + return $oForm;
  455 + }
  456 + /**
  457 + * Edits a fieldsets
  458 + * @return form
  459 + *
  460 + * iNET Process
  461 + */
  462 + function do_editfieldset() {
  463 + $oForm = $this->form_edit();
  464 + $this->oPage->setBreadcrumbDetails(_kt('edit fieldset'));
  465 + return $oForm->renderPage(_kt("Edit Fieldset"));
  466 + }
  467 + /**
  468 + * saves a fieldset
  469 + * @return
  470 + *
  471 + * iNET Process
  472 + */
  473 + function do_savefieldset() {
  474 + $oForm = $this->form_edit();
  475 + $res = $oForm->validate();
  476 +
  477 + $data = $res['results'];
  478 + $errors = $res['errors'];
  479 + $extra_errors = array();
  480 + if ($data['name'] != $this->oFieldset->getName()) {
  481 + $oOldFieldset = KTFieldset::getByName($data['name']);
  482 + if (!PEAR::isError($oOldFieldset)) {
  483 + $extra_errors['name'][] = _kt("A fieldset with that name already exists.");
  484 + }
  485 + }
  486 +
  487 + if (!empty($errors) || !empty($extra_errors)) {
  488 + return $oForm->handleError(null, $extra_errors);
  489 + }
  490 +
  491 + $this->startTransaction();
  492 +
  493 + $this->oFieldset->setName($data['name']);
  494 + $this->oFieldset->setDescription($data['description']);
  495 + $bGeneric = $data['generic'];
  496 + if ($bGeneric != $this->oFieldset->getIsGeneric() && $bGeneric == true) {
  497 + // delink it from all doctypes.
  498 + $aTypes = $this->oFieldset->getAssociatedTypes();
  499 + foreach ($aTypes as $oType) {
  500 + $res = KTMetadataUtil::removeSetsFromDocumentType($oType, $this->oFieldset->getId());
  501 + if (PEAR::isError($res)) {
  502 + $this->errorRedirectTo('edit', _kt('Could not save fieldset changes'));
  503 + exit(0);
  504 + }
  505 + }
  506 + }
  507 +
  508 + $this->oFieldset->setIsGeneric($data['generic']);
  509 +
  510 + $res = $this->oFieldset->update();
  511 + if (PEAR::isError($res)) {
  512 + $this->errorRedirectTo('edit', _kt('Could not save fieldset changes'));
  513 + exit(0);
  514 + }
  515 +
  516 + return $this->successRedirectTo('edit', _kt("Fieldset details updated."));
  517 + }
  518 +}
  519 +
520 520 ?>
521 521 \ No newline at end of file
... ...
plugins/multiselect/MultiSelectPlugin.php
1   -<?php
2   -/**
3   - * $Id$
4   - *
5   - * KnowledgeTree Community Edition
6   - * Document Management Made Simple
7   - * Copyright (C) 2008, 2009 KnowledgeTree Inc.
8   - * Portions copyright The Jam Warehouse Software (Pty) Limited
9   - *
10   - * This program is free software; you can redistribute it and/or modify it under
11   - * the terms of the GNU General Public License version 3 as published by the
12   - * Free Software Foundation.
13   - *
14   - * This program is distributed in the hope that it will be useful, but WITHOUT
15   - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16   - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17   - * details.
18   - *
19   - * You should have received a copy of the GNU General Public License
20   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - *
22   - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
23   - * California 94120-7775, or email info@knowledgetree.com.
24   - *
25   - * The interactive user interfaces in modified source and object code versions
26   - * of this program must display Appropriate Legal Notices, as required under
27   - * Section 5 of the GNU General Public License version 3.
28   - *
29   - * In accordance with Section 7(b) of the GNU General Public License version 3,
30   - * these Appropriate Legal Notices must retain the display of the "Powered by
31   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
32   - * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
33   - * must display the words "Powered by KnowledgeTree" and retain the original
34   - * copyright notice.
35   - * Contributor( s): ______________________________________
36   - *
37   - */
38   -
39   -require_once(KT_LIB_DIR . '/plugins/plugin.inc.php');
40   -require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php');
41   -
42   -class MultiSelectPlugin extends KTPlugin {
43   - var $sNamespace = "inet.multiselect.lookupvalue.plugin";
44   - var $autoRegister = false;
45   -
46   - /**
47   - * returns plugin name
48   - * @param string.
49   - * @return string.
50   - *
51   - * iNET Process
52   - */
53   - function MultiSelectPlugin($sFilename = null) {
54   - $res = parent::KTPlugin($sFilename);
55   - $this->sFriendlyName = _kt('Multi-select Plugin');
56   - return $res;
57   - }
58   -
59   - /**
60   - * Register the action, location, call adminsetup function and sql function
61   - * iNET Process
62   - */
63   - function setup() {
64   - $oTemplating =& KTTemplating::getSingleton();
65   - $oTemplating->addLocation('Multiselect in metadata Part {lookup Value}', '/plugins/multiselect/templates');
66   -
67   - $dir = dirname(__FILE__);
68   - $this->applySQL(realpath($dir . '/sql/script.sql'));
69   -
70   - //For adding documents
71   - $this->registerAction('folderaction', 'MultiDocumentAddAction', 'inet.multiselect.actions.document.addDocument', 'addDocument.php');
72   -
73   - //For bulk upload
74   - $this->registerAction('folderaction', 'InetBulkUploadFolderAction', 'inet.actions.folder.bulkUpload', 'BulkUpload.php');
75   - /**
76   - * Change Starts | iNET Process
77   - * Code is Added 2009-03-04 :SL
78   - * Reason : To Register "import from folder location" action for multiselect
79   - */
80   - $this->registerAction('folderaction', 'InetBulkImportFolderMultiSelectAction', 'inet.actions.folder.bulkImport.multiselect', 'BulkImport.php');
81   - /**
82   - * Change Ends | iNET Process
83   - */
84   - $this->setupAdmin();
85   - }
86   - /**
87   - * applies queries to the database
88   - * @return
89   - * @param $filename Object
90   - */
91   - function applySQL($filename)
92   - {
93   - global $default;
94   - DBUtil::setupAdminDatabase();
95   - $db = $default->_admindb;
96   -
97   - $content = file_get_contents($filename);
98   - $aQueries = SQLFile::splitSQL($content);
99   -
100   - DBUtil::startTransaction();
101   - foreach($aQueries as $sQuery)
102   - {
103   - $res = DBUtil::runQuery($sQuery, $db);
104   - if (PEAR::isError($res)) {
105   - continue;
106   - }
107   - }
108   - DBUtil::commit();
109   - }
110   - /**
111   - * Sets up an admin
112   - * @return
113   - */
114   - function setupAdmin()
115   - {
116   - $js = "<script src='plugins/multiselect/js/jquery-1.2.6.js' type='text/javascript'></script>";
117   - $js .= "<script src='plugins/multiselect/js/hideadminlink.js' type='text/javascript'></script>";
118   - $this->registerAdminPage('ratpfieldset', 'InetDocumentFieldDispatcher', 'documents',
119   - $js._kt('Document Fieldsets'),
120   - _kt('Manage the different types of information with multiselect functionality that can be associated with classes of documents.'),
121   - 'InetdocumentFieldsv2.php', null);
122   - }
123   -}
124   -$oPluginRegistry =& KTPluginRegistry::getSingleton();
125   -$oPluginRegistry->registerPlugin('MultiSelectPlugin', 'inet.multiselect.lookupvalue.plugin', __FILE__);
  1 +<?php
  2 +/**
  3 + * $Id$
  4 + *
  5 + * KnowledgeTree Community Edition
  6 + * Document Management Made Simple
  7 + * Copyright (C) 2008, 2009 KnowledgeTree Inc.
  8 + * Portions copyright The Jam Warehouse Software (Pty) Limited
  9 + *
  10 + * This program is free software; you can redistribute it and/or modify it under
  11 + * the terms of the GNU General Public License version 3 as published by the
  12 + * Free Software Foundation.
  13 + *
  14 + * This program is distributed in the hope that it will be useful, but WITHOUT
  15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  17 + * details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + *
  22 + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
  23 + * California 94120-7775, or email info@knowledgetree.com.
  24 + *
  25 + * The interactive user interfaces in modified source and object code versions
  26 + * of this program must display Appropriate Legal Notices, as required under
  27 + * Section 5 of the GNU General Public License version 3.
  28 + *
  29 + * In accordance with Section 7(b) of the GNU General Public License version 3,
  30 + * these Appropriate Legal Notices must retain the display of the "Powered by
  31 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  32 + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
  33 + * must display the words "Powered by KnowledgeTree" and retain the original
  34 + * copyright notice.
  35 + * Contributor( s): ______________________________________
  36 + *
  37 + */
  38 +
  39 +require_once(KT_LIB_DIR . '/plugins/plugin.inc.php');
  40 +require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php');
  41 +
  42 +class MultiSelectPlugin extends KTPlugin {
  43 + var $sNamespace = "inet.multiselect.lookupvalue.plugin";
  44 + var $autoRegister = false;
  45 +
  46 + /**
  47 + * returns plugin name
  48 + * @param string.
  49 + * @return string.
  50 + *
  51 + * iNET Process
  52 + */
  53 + function MultiSelectPlugin($sFilename = null) {
  54 + $res = parent::KTPlugin($sFilename);
  55 + $this->sFriendlyName = _kt('Multi-select Plugin');
  56 + return $res;
  57 + }
  58 +
  59 + /**
  60 + * Register the action, location, call adminsetup function and sql function
  61 + * iNET Process
  62 + */
  63 + function setup() {
  64 + $oTemplating =& KTTemplating::getSingleton();
  65 + $oTemplating->addLocation('Multiselect in metadata Part {lookup Value}', '/plugins/multiselect/templates');
  66 +
  67 + $dir = dirname(__FILE__);
  68 + $this->applySQL(realpath($dir . '/sql/script.sql'));
  69 +
  70 + //For adding documents
  71 + $this->registerAction('folderaction', 'MultiDocumentAddAction', 'inet.multiselect.actions.document.addDocument', 'addDocument.php');
  72 +
  73 + //For bulk upload
  74 + $this->registerAction('folderaction', 'InetBulkUploadFolderAction', 'inet.actions.folder.bulkUpload', 'BulkUpload.php');
  75 + /**
  76 + * Change Starts | iNET Process
  77 + * Code is Added 2009-03-04 :SL
  78 + * Reason : To Register "import from folder location" action for multiselect
  79 + */
  80 + $this->registerAction('folderaction', 'InetBulkImportFolderMultiSelectAction', 'inet.actions.folder.bulkImport.multiselect', 'BulkImport.php');
  81 + /**
  82 + * Change Ends | iNET Process
  83 + */
  84 + $this->setupAdmin();
  85 + }
  86 + /**
  87 + * applies queries to the database
  88 + * @return
  89 + * @param $filename Object
  90 + */
  91 + function applySQL($filename)
  92 + {
  93 + global $default;
  94 + DBUtil::setupAdminDatabase();
  95 + $db = $default->_admindb;
  96 +
  97 + $content = file_get_contents($filename);
  98 + $aQueries = SQLFile::splitSQL($content);
  99 +
  100 + DBUtil::startTransaction();
  101 + foreach($aQueries as $sQuery)
  102 + {
  103 + $res = DBUtil::runQuery($sQuery, $db);
  104 + if (PEAR::isError($res)) {
  105 + continue;
  106 + }
  107 + }
  108 + DBUtil::commit();
  109 + }
  110 + /**
  111 + * Sets up an admin
  112 + * @return
  113 + */
  114 + function setupAdmin()
  115 + {
  116 + $js = "<script src='plugins/multiselect/js/jquery-1.2.6.js' type='text/javascript'></script>";
  117 + $js .= "<script src='plugins/multiselect/js/hideadminlink.js' type='text/javascript'></script>";
  118 + $this->registerAdminPage('ratpfieldset', 'InetDocumentFieldDispatcher', 'documents',
  119 + $js._kt('Document Fieldsets'),
  120 + _kt('Manage the different types of information with multiselect functionality that can be associated with classes of documents.'),
  121 + 'InetdocumentFieldsv2.php', null);
  122 + }
  123 +}
  124 +$oPluginRegistry =& KTPluginRegistry::getSingleton();
  125 +$oPluginRegistry->registerPlugin('MultiSelectPlugin', 'inet.multiselect.lookupvalue.plugin', __FILE__);
126 126 ?>
127 127 \ No newline at end of file
... ...
plugins/multiselect/inetbasic.inc.php
1   -<?php
2   -/**
3   - * $Id$
4   - *
5   - * KnowledgeTree Community Edition
6   - * Document Management Made Simple
7   - * Copyright (C) 2008, 2009 KnowledgeTree Inc.
8   - * Portions copyright The Jam Warehouse Software (Pty) Limited
9   - *
10   - * This program is free software; you can redistribute it and/or modify it under
11   - * the terms of the GNU General Public License version 3 as published by the
12   - * Free Software Foundation.
13   - *
14   - * This program is distributed in the hope that it will be useful, but WITHOUT
15   - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16   - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17   - * details.
18   - *
19   - * You should have received a copy of the GNU General Public License
20   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - *
22   - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
23   - * California 94120-7775, or email info@knowledgetree.com.
24   - *
25   - * The interactive user interfaces in modified source and object code versions
26   - * of this program must display Appropriate Legal Notices, as required under
27   - * Section 5 of the GNU General Public License version 3.
28   - *
29   - * In accordance with Section 7(b) of the GNU General Public License version 3,
30   - * these Appropriate Legal Notices must retain the display of the "Powered by
31   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
32   - * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
33   - * must display the words "Powered by KnowledgeTree" and retain the original
34   - * copyright notice.
35   - * Contributor( s): ______________________________________
36   - *
37   - */
38   -
39   -require_once(KT_LIB_DIR . '/dispatcher.inc.php');
40   -require_once(KT_LIB_DIR . '/metadata/fieldset.inc.php');
41   -require_once(KT_LIB_DIR . '/widgets/forms.inc.php');
42   -require_once(KT_LIB_DIR . '/plugins/pluginutil.inc.php');
43   -require_once(KT_LIB_DIR . "/documentmanagement/MDTree.inc");
44   -
45   -class InetBasicFieldsetManagementDispatcher extends KTAdminDispatcher {
46   - var $bAutomaticTransaction = true;
47   - var $bHaveConditional = null;
48   - var $sHelpPage = 'ktcore/admin/document fieldsets.html';
49   -
50   - /**
51   - * @param.
52   - * @return.
53   - *
54   - * iNET Process
55   - */
56   - function predispatch() {
57   - $this->persistParams(array('fFieldId'));
58   - $this->oFieldset = KTFieldset::get(KTUtil::arrayGet($_REQUEST, 'fFieldsetId'));
59   - if (PEAR::isError($this->oFieldset)) {
60   - $this->oFieldset = null;
61   - unset($_REQUEST['fFieldsetId']); // prevent further attacks.
62   - }
63   - $this->oField = DocumentField::get(KTUtil::arrayGet($_REQUEST, 'fFieldId'));
64   - if (PEAR::isError($this->oField)) {
65   - $this->oField = null;
66   - unset($_REQUEST['fFieldId']); // prevent further attacks.
67   - } else {
68   - $this->aBreadcrumbs[] = array('url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","managefield")), 'name' => $this->oField->getName());
69   - }
70   - }
71   -
72   - /**
73   - * API: this provides information about the fieldset, including which actions are available.
74   - *
75   - * @param $oFieldset object.
76   - * @return template.
77   - *
78   - * iNET Process
79   - */
80   - function describe_fieldset($oFieldset) {
81   - $this->persistParams(array('fFieldsetId','action'));
82   - $oTemplate =& $this->oValidator->validateTemplate('ktcore/metadata/admin/basic_overview');
83   - $oTemplate->setData(array(
84   - 'context' => $this,
85   - 'fields' => $oFieldset->getFields(),
86   - ));
87   - return $oTemplate->render();
88   - }
89   - /**
90   - * Nothing doing
91   - * iNET Process
92   - */
93   - function do_main () {
94   - return _kt("Something very unexpected happened.");
95   - }
96   -
97   - /**
98   - * returns array of field type.
99   - *
100   - * @param.
101   - * @return array.
102   - *
103   - * iNET Process
104   - */
105   - function getFieldTypeVocab() {
106   - $types = array(
107   - 'normal' => _kt("Normal (String)"),
108   - 'lookup' => _kt("Lookup"),
109   - 'tree' => _kt("Tree"),
110   - 'Multiselect' => _kt("Multiselect"),
111   - );
112   - return $types;
113   - }
114   -
115   -
116   - /**
117   - * multiselect change starts
118   - * @return array
119   - *
120   - * iNET Process
121   - */
122   - function getLookupFieldTypeVocab() {
123   - $types = array(
124   -
125   - 'multiwithlist' => _kt("Multiselect with a list"),
126   - 'multiwithcheckboxes' => _kt("Multiselect with checkboxes"),
127   - );
128   - return $types;
129   - }
130   -
131   - /**
132   - * returns lookup type
133   - * @return string
134   - *
135   - * iNET Process
136   - */
137   - function getDefaultLookupType() {
138   - return 'multiwithlist';
139   -
140   - }
141   -
142   - /**
143   - * multiselect change end
144   - * @return
145   - *
146   - * iNET Process
147   - */
148   - function getDefaultType() {
149   - return 'normal';
150   - }
151   - /**
152   - * For for displaying new field
153   - * @return
154   - *
155   - * iNET Process
156   - */
157   - function form_newfield() {
158   - $this->oPage->setBreadcrumbDetails(_kt('add field'));
159   -
160   - $oForm = new KTForm;
161   - $oForm->setOptions(array(
162   - 'identifier' => 'ktcore.fieldsets.basic.field.create',
163   - 'label' => _kt("Add New Field"),
164   - 'submit_label' => _kt('Add Field'),
165   - 'cancel_url' => $this->sParentUrl,
166   - 'fail_action' => 'newfield',
167   - 'action' => 'createfield',
168   - 'context' => $this,
169   - ));
170   -
171   - $type_vocab = $this->getFieldTypeVocab();
172   -
173   - $oForm->setWidgets(array(
174   - array('ktcore.widgets.string',array(
175   - 'label' => _kt("Field Name"),
176   - 'name' => 'name',
177   - 'required' => true,
178   - 'description' => _kt("Within a given fieldset, each field needs a unique name."),
179   - )),
180   - array('ktcore.widgets.text',array(
181   - 'label' => _kt("Description"),
182   - 'name' => 'description',
183   - 'required' => true,
184   - 'description' => _kt("A good description can be the difference between useful metadata and poor metadata. At the same time, overly long descriptions are far less valuable than concise ones."),
185   - )),
186   - array('ktcore.widgets.selection', array(
187   - 'label' => _kt('Field Type'),
188   - 'name' => 'field_type',
189   - 'vocab' => $this->getFieldTypeVocab(),
190   - 'description' => _kt("Different types of fields may be available, depending on the system."),
191   - 'required' => true,
192   - 'value' => $this->getDefaultType(),
193   - )),
194   - array('ktcore.widgets.boolean',array(
195   - 'label' => _kt("Required"),
196   - 'name' => 'required',
197   - 'description' => _kt("Required fields must be filled in, or the adding process will be rejected."),
198   - )),
199   -
200   - ));
201   -
202   - $oForm->setValidators(array(
203   - array('ktcore.validators.string', array(
204   - 'test' => 'name',
205   - 'output' => 'name',
206   - )),
207   - array('ktcore.validators.string', array(
208   - 'test' => 'description',
209   - 'output' => 'description',
210   - )),
211   - array('ktcore.validators.boolean', array(
212   - 'test' => 'required',
213   - 'output' => 'required',
214   - )),
215   - array('ktcore.validators.string', array(
216   - 'test' => 'field_type',
217   - 'output' => 'field_type',
218   - )),
219   - ));
220   -
221   - return $oForm;
222   - }
223   - /**
224   - * Renders the page for new field
225   - * @return
226   - *
227   - * iNET Process
228   - */
229   - function do_newfield() {
230   - $oForm = $this->form_newfield();
231   -
232   - return $oForm->render();
233   - }
234   -
235   - /**
236   - * Creats a new field->multiselect
237   - * @return
238   - *
239   - *
240   - * iNET Process
241   - */
242   - function do_createfield() {
243   - $oForm = $this->form_newfield();
244   - $res = $oForm->validate();
245   -
246   - $data = $res['results'];
247   - $errors = $res['errors'];
248   - $extra_errors = array();
249   -
250   - $oField = DocumentField::getByFieldsetAndName($this->oFieldset, $data['name']);
251   - if (!PEAR::isError($oField)) {
252   - $extra_errors['name'] = _kt("A field with that name already exists in this fieldset.");
253   - }
254   -
255   - if (!empty($errors) || !empty($extra_errors)) {
256   - return $oForm->handleError(null, $extra_errors);
257   - }
258   -
259   - $lookup = false;
260   - $tree = false;
261   - // multiselect change start
262   - $inetlookup = false;
263   - $inetlookupvalue = '';
264   - // multiselect change end
265   -
266   - if ($data['field_type'] == 'lookup') {
267   - $lookup = true;
268   - } else if ($data['field_type'] == 'tree') {
269   - $lookup = true;
270   - $tree = true;
271   - }
272   - // multiselect change start
273   - else if($data['field_type'] == 'Multiselect')
274   - {
275   - $inetlookup = true;
276   - $inetlookupvalue = $this->getDefaultLookupType();
277   - }
278   - // multiselect change end
279   -
280   - $oField = DocumentField::createFromArray(array(
281   - 'Name' => $data['name'],
282   - 'Description' => $data['description'],
283   - 'DataType' => 'STRING',
284   - 'IsGeneric' => false,
285   - 'HasLookup' => $lookup,
286   - 'HasLookupTree' => $tree,
287   - 'ParentFieldset' => $this->oFieldset->getId(),
288   - 'IsMandatory' => $data['required'],
289   - // multiselect change start
290   - 'HasInetLookup' => $inetlookup,
291   - 'InetLookupType' => $inetlookupvalue,
292   - // multiselect change end
293   - ));
294   -
295   - if (PEAR::isError($oField)) {
296   - return $oForm->handleError(sprintf(_kt("Unable to create field: %s"), $oField->getMessage()));
297   - }
298   -
299   - $this->successRedirectTo('managefield', _kt("Field created."), sprintf('fFieldId=%d', $oField->getId()));
300   - }
301   - /**
302   - * Form for editing a field
303   - * @return form
304   - * @param $oField Object
305   - *
306   - * iNET Process
307   - */
308   - function form_editfield($oField) {
309   - $oForm = new KTForm;
310   - $oForm->setOptions(array(
311   - 'identifier' => 'ktcore.fieldsets.basic.field.edit',
312   - 'label' => _kt("Edit Field"),
313   - 'submit_label' => _kt('Update Field'),
314   - 'cancel_url' => $this->sParentUrl,
315   - 'fail_action' => 'managefield',
316   - 'action' => 'updatefield',
317   - 'context' => $this,
318   - ));
319   -
320   - $field_type = $oField->getType();
321   - if($field_type == "Multiselect")
322   - {
323   - $oForm->setWidgets(array(
324   - array('ktcore.widgets.string',array(
325   - 'label' => _kt("Field Name"),
326   - 'name' => 'name',
327   - 'value' => sanitizeForHTML($oField->getName()),
328   - 'required' => true,
329   - 'description' => _kt("Within a given fieldset, each field needs a unique name."),
330   - )),
331   - array('ktcore.widgets.text',array(
332   - 'label' => _kt("Description"),
333   - 'name' => 'description',
334   - 'value' => sanitizeForHTML($oField->getDescription()),
335   - 'required' => true,
336   - 'description' => _kt("A good description can be the difference between useful metadata and poor metadata. At the same time, overly long descriptions are far less valuable than concise ones."),
337   - )),
338   - array('ktcore.widgets.boolean',array(
339   - 'label' => _kt("Required"),
340   - 'value' => $oField->getIsMandatory(),
341   - 'name' => 'required',
342   - 'description' => _kt("Required fields must be filled in, or the adding process will be rejected."),
343   - )),
344   - array('ktcore.widgets.selection', array(
345   - 'label' => _kt('Type of field'),
346   - 'name' => 'inetlookup_type',
347   - 'vocab' => $this->getLookupFieldTypeVocab(),
348   - 'description' => _kt("Permits to create a multiselect or single select choices."),
349   - 'required' => true,
350   - 'value' => $oField->getInetLookupType(),
351   - 'simple_select' => false,
352   - )),
353   - ));
354   -
355   - $oForm->setValidators(array(
356   - array('ktcore.validators.string', array(
357   - 'test' => 'name',
358   - 'output' => 'name',
359   - )),
360   - array('ktcore.validators.string', array(
361   - 'test' => 'description',
362   - 'output' => 'description',
363   - )),
364   - array('ktcore.validators.boolean', array(
365   - 'test' => 'required',
366   - 'output' => 'required',
367   - )),
368   - array('ktcore.validators.string', array(
369   - 'test' => 'inetlookup_type',
370   - 'output' => 'inetlookup_type',
371   - )),
372   - ));
373   - }
374   - else
375   - {
376   -
377   - $oForm->setWidgets(array(
378   - array('ktcore.widgets.string',array(
379   - 'label' => _kt("Field Name"),
380   - 'name' => 'name',
381   - 'value' => sanitizeForHTML($oField->getName()),
382   - 'required' => true,
383   - 'description' => _kt("Within a given fieldset, each field needs a unique name."),
384   - )),
385   - array('ktcore.widgets.text',array(
386   - 'label' => _kt("Description"),
387   - 'name' => 'description',
388   - 'value' => sanitizeForHTML($oField->getDescription()),
389   - 'required' => true,
390   - 'description' => _kt("A good description can be the difference between useful metadata and poor metadata. At the same time, overly long descriptions are far less valuable than concise ones."),
391   - )),
392   - array('ktcore.widgets.boolean',array(
393   - 'label' => _kt("Required"),
394   - 'value' => $oField->getIsMandatory(),
395   - 'name' => 'required',
396   - 'description' => _kt("Required fields must be filled in, or the adding process will be rejected."),
397   - )),
398   -
399   - ));
400   -
401   - $oForm->setValidators(array(
402   - array('ktcore.validators.string', array(
403   - 'test' => 'name',
404   - 'output' => 'name',
405   - )),
406   - array('ktcore.validators.string', array(
407   - 'test' => 'description',
408   - 'output' => 'description',
409   - )),
410   - array('ktcore.validators.boolean', array(
411   - 'test' => 'required',
412   - 'output' => 'required',
413   - )),
414   - ));
415   - }
416   - return $oForm;
417   - }
418   - /**
419   - * Manages a field
420   - * @return template
421   - *
422   - *
423   - * iNET Process
424   - */
425   - function do_managefield() {
426   - $oTemplate = $this->oValidator->validateTemplate('manage_field');
427   -
428   - $oTemplate->setData(array(
429   - 'context' => $this,
430   - 'field_name' => $this->oField->getName(),
431   - 'field_id' => $this->oField->getId(),
432   - 'form' => $this->form_editfield($this->oField),
433   - 'field' => $this->oField,
434   - ));
435   - return $oTemplate->render();
436   - }
437   - /**
438   - * Updates a field
439   - * @return.
440   - *
441   - *
442   - * iNET Process
443   - */
444   - function do_updatefield() {
445   - $oForm = $this->form_editfield($this->oField);
446   - $res = $oForm->validate();
447   - $data = $res['results'];
448   - $errors = $res['errors'];
449   - $extra_errors = array();
450   -
451   - // check that the field name either hasn't changed, or doesn't exist.
452   - if ($data['name'] != $this->oField->getName()) {
453   - $oOldField = DocumentField::getByFieldsetAndName($this->oFieldset, $data['name']);
454   - if (!PEAR::isError($oOldField)) {
455   - $extra_errors['name'] = _kt("That name is already in use in this fieldset. Please specify a unique name.");
456   - }
457   - }
458   -
459   - if (!empty($errors) || !empty($extra_errors)) {
460   - return $oForm->handleError(null, $extra_errors);
461   - }
462   -
463   - $this->oField->setName($data['name']);
464   - $this->oField->setDescription($data['description']);
465   - $this->oField->setIsMandatory($data['required']);
466   -
467   - // multiselect change start
468   - if(isset($data['inetlookup_type']) && $this->oField->getHasInetLookup())
469   - {
470   - $this->oField->setInetLookupType($data['inetlookup_type']);
471   - }
472   - // multiselect change end
473   -
474   - $res = $this->oField->update();
475   - if (PEAR::isError($res)) {
476   - return $oForm->handleError(sprintf(_kt("Failed to update field: %s"), $res->getMessage()));
477   - }
478   -
479   - $this->successRedirectTo('managefield',_kt("Field updated."));
480   - }
481   - /**
482   - * Add lookup
483   - * @return form
484   - *
485   - * iNET Process
486   - */
487   - function form_addlookups() {
488   - $oForm = new KTForm;
489   - $oForm->setOptions(array(
490   - 'identifier' => 'ktcore.fieldsets.basic.field.addlookup',
491   - 'label' => _kt("Add Lookup Values"),
492   - 'submit_label' => _kt('Add Lookups'),
493   - 'cancel_action' => 'managefield',
494   - 'fail_action' => 'addlookupvalues',
495   - 'action' => 'createlookupvalues',
496   - 'context' => $this,
497   - ));
498   -
499   - $oForm->setWidgets(array(
500   - array('ktcore.widgets.text',array(
501   - 'label' => _kt("Lookup Values"),
502   - 'name' => 'lookups',
503   - 'required' => true,
504   - 'description' => _kt("Lookup values are what a user can select from a dropdown. These pre-created lookup values are useful, since they help you keep the metadata in the system organised."),
505   - 'important_description' => _kt("Please enter the lookup values you wish to add, one per line."),
506   - )),
507   - ));
508   -
509   - $oForm->setValidators(array(
510   - array('ktcore.validators.string', array(
511   - 'test' => 'lookups',
512   - 'output' => 'lookups',
513   - 'max_length' => 9999,
514   - )),
515   - ));
516   -
517   - return $oForm;
518   - }
519   -
520   - /**
521   - * Add lookup values
522   - * @return
523   - *
524   - * iNET Process
525   - */
526   - function do_addlookupvalues() {
527   - $this->oPage->setBreadcrumbDetails(_kt('add lookup values'));
528   -
529   - $oForm = $this->form_addlookups();
530   - return $oForm->render();
531   - }
532   - /**
533   - * Create lookup values
534   - * @return
535   - */
536   - function do_createlookupvalues() {
537   - $oForm = $this->form_addlookups();
538   - $res = $oForm->validate();
539   - $data = $res['results'];
540   - $errors = $res['errors'];
541   - $extra_errors = array();
542   -
543   -
544   - $failed = array();
545   - $lookups = array();
546   -
547   - $raw_lookups = $data['lookups'];
548   - $lookup_candidates = explode("\n", $raw_lookups);
549   - foreach ($lookup_candidates as $candidate) {
550   - $name = trim($candidate);
551   -
552   - if (empty($name)) {
553   - continue;
554   - }
555   -
556   - // check for existing or to-be-created lookups.
557   - if ($lookups[$name]) {
558   - $failed[$name] = $name;
559   - continue;
560   - }
561   -
562   - if ($failed[$name]) {
563   - continue; // already blown up, fix it.
564   - }
565   -
566   - $oOldLookup = MetaData::getByValueAndDocumentField($name, $this->oField);
567   - if (!PEAR::isError($oOldLookup)) {
568   - $failed[$name] = $name;
569   - continue;
570   - }
571   -
572   - $lookups[$name] = $name;
573   - }
574   - if (!empty($failed)) {
575   - $extra_errors['lookups'][] = sprintf(_kt("The following lookups you specified already exist, or are specified twice: %s"), implode(', ', $failed));
576   - } else if (empty($lookups)) {
577   - $extra_errors['lookups'][] = _kt("You must have at least 1 new lookup value.");
578   - }
579   -
580   - if (!empty($errors) || !empty($extra_errors)) {
581   - return $oForm->handleError(null, $extra_errors);
582   - }
583   -
584   - $data['lookups'] = $lookups;
585   -
586   - foreach ($lookups as $value) {
587   - $oLookup = MetaData::createFromArray(array(
588   - 'DocFieldId' => $this->oField->getId(),
589   - 'sName' => $value,
590   - 'iTreeParent' => null,
591   - 'bDisabled' => false,
592   - 'bIsStuck' => false,
593   - ));
594   - if (PEAR::isError($oLookup)) {
595   - return $oForm->handleError(sprintf(_kt("Failed to create lookup: %s"), $oLookup->getMessage()));
596   - }
597   - }
598   -
599   - $this->successRedirectTo('managefield', sprintf(_kt("%d lookups added."), count($lookups)));
600   - }
601   - /**
602   - * Manages lookups
603   - * @return template
604   - *
605   - * iNET Process
606   - */
607   - function do_managelookups() {
608   - $this->oPage->setBreadcrumbDetails(_kt('manage lookup values'));
609   -
610   - // Add javascript to create the edit form
611   - $sJavaScript = "\nfunction editLookup(id)\n
612   - {\n
613   - var div = document.getElementById(id);\n
614   - var value = div.innerHTML;
615   -
616   - <!-- Replace all double quotes with &#34; -->\n
617   - matches = value.match(/\"/g);\n
618   - var newValue = value;\n
619   - if(matches){\n
620   - for(var i = 0; i < matches.length; i++){\n
621   - newValue = newValue.replace('\"', '&#34;');\n
622   - }\n
623   - }\n\n
624   -
625   - var inner = '<input type=\"text\" name=\"lookup['+id+']\" id=\"lookup_'+id+'\" value=\"'+newValue+'\" />';\n
626   - inner += '<input type=\"hidden\" id=\"original_'+id+'\" value=\"'+newValue+'\" />';\n
627   - inner += '<input type=\"submit\" name=\"submit[edit]\" value=\""._kt('Save')."\" />';\n
628   - inner += '<input type=\"button\" onclick=\"javascript: closeLookupEdit('+id+');\" name=\"cancel\" value=\""._kt('Cancel')."\" />';\n
629   - div.innerHTML = inner;\n
630   - document.getElementById('lookup_'+id).focus();\n
631   - }\n\n
632   -
633   - function closeLookupEdit(id)
634   - {\n
635   - value = document.getElementById('original_'+id).value;\n
636   - document.getElementById(id).innerHTML = value;\n
637   - }\n\n";
638   -
639   - $this->oPage->requireJSStandalone($sJavaScript);
640   -
641   - $lookups =& MetaData::getByDocumentField($this->oField);
642   - $args = $this->meldPersistQuery("","metadataMultiAction", true);
643   -
644   - $oTemplate =& $this->oValidator->validateTemplate("ktcore/metadata/admin/manage_lookups");
645   - $oTemplate->setData(array(
646   - 'context' => $this,
647   - 'field_name' => $this->oField->getName(),
648   - 'lookups' => $lookups,
649   - 'args' => $args,
650   - ));
651   - return $oTemplate->render();
652   - }
653   -
654   - // {{{ do_metadataMultiAction
655   - /**
656   - * call metadata multiaction methods
657   - * @param.
658   - * @return.
659   - *
660   - * iNET Process
661   - */
662   - function do_metadataMultiAction() {
663   - $subaction = array_keys(KTUtil::arrayGet($_REQUEST, 'submit', array()));
664   - $this->oValidator->notEmpty($subaction, array("message" => _kt("No action specified")));
665   - $subaction = $subaction[0];
666   - $method = null;
667   - if (method_exists($this, 'lookup_' . $subaction)) {
668   - $method = 'lookup_' . $subaction;
669   - }
670   - $this->oValidator->notEmpty($method, array("message" => _kt("Unknown action specified")));
671   - return $this->$method();
672   - }
673   - // }}}
674   -
675   - // {{{ lookup_remove
676   - /**
677   - * remove lookup value.
678   - * @param
679   - * @return
680   - *
681   - * iNET Process
682   - */
683   - function lookup_remove() {
684   - $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']);
685   - $oField =& DocumentField::get($_REQUEST['fFieldId']);
686   - $aMetadata = KTUtil::arrayGet($_REQUEST, 'metadata');
687   - if (empty($aMetadata)) {
688   - $this->errorRedirectTo('managelookups', _kt('No lookups selected'));
689   - }
690   - foreach ($_REQUEST['metadata'] as $iMetaDataId) {
691   - $oMetaData =& MetaData::get($iMetaDataId);
692   - if (PEAR::isError($oMetaData)) {
693   - $this->errorRedirectTo('managelookups', _kt('Invalid lookup selected'));
694   - }
695   - $oMetaData->delete();
696   - }
697   - $this->successRedirectTo('managelookups', _kt('Lookups removed'));
698   - exit(0);
699   - }
700   - // }}}
701   -
702   - // {{{ lookup_disable
703   - /**
704   - * disable lookup value.
705   - * @param
706   - * @return
707   - *
708   - * iNET Process
709   - */
710   - function lookup_disable() {
711   - $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']);
712   - $oField =& DocumentField::get($_REQUEST['fFieldId']);
713   - $aMetadata = KTUtil::arrayGet($_REQUEST, 'metadata');
714   - if (empty($aMetadata)) {
715   - $this->errorRedirectTo('managelookups', _kt('No lookups selected'));
716   - }
717   - foreach ($_REQUEST['metadata'] as $iMetaDataId) {
718   - $oMetaData =& MetaData::get($iMetaDataId);
719   - if (PEAR::isError($oMetaData)) {
720   - $this->errorRedirectTo('managelookups', _kt('Invalid lookup selected'));
721   - }
722   - $oMetaData->setDisabled(true);
723   - $oMetaData->update();
724   - }
725   - $this->successRedirectTo('managelookups', _kt('Lookups disabled'));
726   - exit(0);
727   - }
728   - // }}}
729   -
730   - /**
731   - * Save the edited lookup values
732   - *
733   - * @param.
734   - * @return.
735   - *
736   - *iNET Process
737   - */
738   - function lookup_edit(){
739   - $aLookupValues = $_REQUEST['lookup'];
740   -
741   - if(empty($aLookupValues)){
742   - $this->errorRedirectTo('managelookups', _kt('No lookups were selected for editing'));
743   - exit;
744   - }
745   -
746   - foreach ($aLookupValues as $iMetaDataId => $sValue){
747   - $oMetaData = MetaData::get($iMetaDataId);
748   - if (PEAR::isError($oMetaData)) {
749   - $this->addErrorMessage(_kt('Invalid lookup selected').': '.$sValue);
750   - continue;
751   -
752   - }
753   - if(empty($sValue)){
754   - $this->addErrorMessage(_kt('Lookup cannot be empty').': '.$oMetaData->getName());
755   - if(count($aLookupValues) == 1){
756   - $this->redirectTo('managelookups');
757   - }
758   - continue;
759   - }
760   - $oMetaData->setName($sValue);
761   - $oMetaData->update();
762   - }
763   -
764   - $this->successRedirectTo('managelookups', _kt('Lookup values saved'));
765   - exit(0);
766   - }
767   -
768   - // {{{ lookup_enable
769   - /**
770   - * enable lookup value
771   - * @param
772   - * @return
773   - *
774   - * iNET Process
775   - */
776   - function lookup_toggleenabled() {
777   - $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']);
778   - $oField =& DocumentField::get($_REQUEST['fFieldId']);
779   - $aMetadata = KTUtil::arrayGet($_REQUEST, 'metadata');
780   - if (empty($aMetadata)) {
781   - $this->errorRedirectTo('managelookups', _kt('No lookups selected'));
782   - }
783   - foreach ($_REQUEST['metadata'] as $iMetaDataId) {
784   - $oMetaData =& MetaData::get($iMetaDataId);
785   - if (PEAR::isError($oMetadata)) {
786   - $this->errorRedirectTo('managelookups', _kt('Invalid lookup selected'));
787   - }
788   - $oMetaData->setDisabled(!$oMetaData->getDisabled());
789   - $oMetaData->update();
790   - }
791   - $this->successRedirectTo('managelookups', _kt('Status Toggled'));
792   - exit(0);
793   - }
794   - // }}}
795   -
796   - // {{{ lookup_togglestickiness
797   - /**
798   - * toggle stickiness of lookup values
799   - * @param
800   - * @return
801   - *
802   - * iNET Process
803   - */
804   - function lookup_togglestickiness() {
805   - $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']);
806   - $oField =& DocumentField::get($_REQUEST['fFieldId']);
807   - $aMetadata = KTUtil::arrayGet($_REQUEST, 'metadata');
808   - if (empty($aMetadata)) {
809   - $this->errorRedirectTo('managelookups', _kt('No lookups selected'));
810   - }
811   - foreach ($_REQUEST['metadata'] as $iMetaDataId) {
812   - $oMetaData =& MetaData::get($iMetaDataId);
813   - if (PEAR::isError($oMetaData)) {
814   - $this->errorRedirectTo('managelookups', _kt('Invalid lookups selected'));
815   - }
816   - $bStuck = (boolean)$oMetaData->getIsStuck();
817   - $oMetaData->setIsStuck(!$bStuck);
818   - $oMetaData->update();
819   - }
820   - $this->successRedirectTo('managelookups', _kt('Lookup stickiness toggled'));
821   - exit(0);
822   - }
823   - // }}}
824   -
825   -// {{{ TREE
826   - // create and display the tree editing form.
827   - /**
828   - * create and display the tree editing form.
829   - * @param.
830   - * @return template
831   - *
832   - * iNET Process
833   - */
834   - function do_managetree() {
835   - global $default;
836   - // extract.
837   - $iFieldsetId = KTUtil::getId($this->oFieldset);
838   - $iFieldId = KTUtil::getId($this->oField);
839   -
840   - $oFieldset =& $this->oFieldset;
841   - $oField =& $this->oField;
842   -
843   - $this->oPage->setBreadcrumbDetails(_kt('edit lookup tree'));
844   -
845   - $field_id = $iFieldId;
846   - $current_node = KTUtil::arrayGet($_REQUEST, 'current_node', 0);
847   - $subaction = KTUtil::arrayGet($_REQUEST, 'subaction');
848   -
849   - // validate
850   - if (empty($field_id)) { return $this->errorRedirectToMain(_kt("Must select a field to edit.")); }
851   - $oField =& DocumentField::get($field_id);
852   - if (PEAR::isError($oField)) { return $this->errorRedirectToMain(_kt("Invalid field.")); }
853   -
854   - $aErrorOptions = array(
855   - 'redirect_to' => array('editTree', sprintf('field_id=%d', $field_id)),
856   - );
857   -
858   - // under here we do the subaction rendering.
859   - // we do this so we don't have to do _very_ strange things with multiple actions.
860   -
861   - $fieldTree =& new MDTree();
862   - $fieldTree->buildForField($oField->getId());
863   -
864   - if ($subaction !== null) {
865   - $target = 'managetree';
866   - $msg = _kt('Changes saved.');
867   - if ($subaction === "addCategory") {
868   - $new_category = KTUtil::arrayGet($_REQUEST, 'category_name');
869   - if (empty($new_category)) {
870   - return $this->errorRedirectTo("managetree", _kt("Must enter a name for the new category."), array("field_id" => $field_id, "fFieldsetId" => $iFieldsetId));
871   - } else {
872   - $this->subact_addCategory($field_id, $current_node, $new_category, $fieldTree);
873   - }
874   - $msg = _kt('Category added'). ': ' . $new_category;
875   - }
876   - if ($subaction === "deleteCategory") {
877   - $this->subact_deleteCategory($fieldTree, $current_node);
878   - $current_node = 0; // clear out, and don't try and render the newly deleted category.
879   - $msg = _kt('Category removed.');
880   - }
881   - if ($subaction === "linkKeywords") {
882   - $keywords = KTUtil::arrayGet($_REQUEST, 'keywordsToAdd');
883   - $aErrorOptions['message'] = _kt("No keywords selected");
884   - $this->oValidator->notEmpty($keywords, $aErrorOptions);
885   - $this->subact_linkKeywords($fieldTree, $current_node, $keywords);
886   - $current_node = 0; // clear out, and don't try and render the newly deleted category.
887   - $msg = _kt('Keywords added to category.');
888   - }
889   - if ($subaction === "unlinkKeyword") {
890   - $keyword = KTUtil::arrayGet($_REQUEST, 'keyword_id');
891   - $this->subact_unlinkKeyword($fieldTree, $keyword);
892   - $msg = _kt('Keyword moved to base of tree.');
893   - }
894   - // now redirect
895   - $query = sprintf('field_id=%d&fFieldsetId=%d', $field_id, $iFieldsetId);
896   - return $this->successRedirectTo($target, $msg, $query);
897   - }
898   - if ($fieldTree->root === null) {
899   - return $this->errorRedirectToMain(_kt("Error building tree. Is this a valid tree-lookup field?"));
900   - }
901   -
902   - // FIXME extract this from MDTree (helper method?)
903   - $free_metadata = MetaData::getList('document_field_id = '.$oField->getId().' AND (treeorg_parent = 0 OR treeorg_parent IS NULL) AND (disabled = 0)');
904   -
905   - // render edit template.
906   -
907   - $oTemplate = $this->oValidator->validateTemplate("ktcore/metadata/admin/edit_lookuptree");
908   - $renderedTree = $this->_evilTreeRenderer($fieldTree);
909   -
910   - $this->oPage->setTitle(_kt('Edit Lookup Tree'));
911   -
912   - if ($current_node == 0) { $category_name = 'Root'; }
913   - else {
914   - $oNode = MDTreeNode::get($current_node);
915   - $category_name = $oNode->getName();
916   - }
917   -
918   - $aTemplateData = array(
919   - "context" => $this,
920   - "args" => $this->meldPersistQuery("","managetree", true),
921   - "field" => $oField,
922   - "oFieldset" => $oFieldset,
923   - "tree" => $fieldTree,
924   - "renderedTree" => $renderedTree,
925   - "currentNode" => $current_node,
926   - 'category_name' => $category_name,
927   - "freechildren" => $free_metadata,
928   -
929   - );
930   - return $oTemplate->render($aTemplateData);
931   - }
932   - /**
933   - * Adds a category
934   - * @return
935   - * @param $field_id Object
936   - * @param $current_node Object
937   - * @param $new_category Object
938   - * @param $constructedTree Object
939   - *
940   - * iNET Process
941   - */
942   - function subact_addCategory($field_id, $current_node, $new_category, &$constructedTree) {
943   - $newCategory = MDTreeNode::createFromArray(array (
944   - "iFieldId" => $field_id,
945   - "sName" => $new_category,
946   - "iParentNode" => $current_node,
947   - ));
948   - if (PEAR::isError($newCategory))
949   - {
950   - return false;
951   - }
952   - $constructedTree->addNode($newCategory);
953   - return true;
954   - }
955   - /**
956   - * Deletes a catagory
957   - * @return
958   - * @param $constructedTree Object
959   - * @param $current_node Object
960   - */
961   - function subact_deleteCategory(&$constructedTree, $current_node) {
962   - $constructedTree->deleteNode($current_node);
963   - return true;
964   - }
965   -
966   - /**
967   - *
968   - * @param $constructedTree object
969   - * @param $keywords
970   - * @return true.
971   - *
972   - * iNET Process
973   - */
974   - function subact_unlinkKeyword(&$constructedTree, $keyword) {
975   - $oKW = MetaData::get($keyword);
976   - if (PEAR::isError($oKW)) {
977   - return true;
978   - }
979   - $constructedTree->reparentKeyword($oKW->getId(), 0);
980   - return true;
981   - }
982   -
983   - /**
984   - *
985   - * @param $constructedTree object
986   - * @param $current_node node id
987   - * @param $keywords array
988   - * @return true.
989   - *
990   - * iNET Process
991   - */
992   - function subact_linkKeywords(&$constructedTree, $current_node, $keywords) {
993   - foreach ($keywords as $md_id)
994   - {
995   - $constructedTree->reparentKeyword($md_id, $current_node);
996   - }
997   - return true;
998   - }
999   -
1000   - /* ----------------------- EVIL HACK --------------------------
1001   - *
1002   - * This whole thing needs to replaced, as soon as I work out how
1003   - * to non-sucking Smarty recursion.
1004   - */
1005   -
1006   - /**
1007   - * render to subnode of tree
1008   - *
1009   - * @param $subnode node
1010   - * @param $treeToRender object
1011   - * @Return string
1012   - *
1013   - * iNET Process
1014   - */
1015   - function _evilTreeRecursion($subnode, $treeToRender)
1016   - {
1017   - // deliver us from evil....
1018   - $iFieldId = $treeToRender->field_id;
1019   - $oField = DocumentField::get($iFieldId);
1020   - $iFieldsetId = $oField->getParentFieldsetId();
1021   -
1022   - $treeStr = "<ul>";
1023   - foreach ($treeToRender->contents[$subnode] as $subnode_id => $subnode_val)
1024   - {
1025   - if ($subnode_id !== "leaves") {
1026   - $treeStr .= '<li class="treenode active"><a class="pathnode inactive" onclick="toggleElementClass(\'active\', this.parentNode); toggleElementClass(\'inactive\', this.parentNode);">' . $treeToRender->mapnodes[$subnode_val]->getName() . '</a>';
1027   - $treeStr .= $this->_evilActionHelper($iFieldsetId, $iFieldId, false, $subnode_val);
1028   - $treeStr .= $this->_evilTreeRecursion($subnode_val, $treeToRender);
1029   - $treeStr .= '</li>';
1030   - }
1031   - else
1032   - {
1033   - foreach ($subnode_val as $leaf)
1034   - {
1035   - $treeStr .= '<li class="leafnode">' . $treeToRender->lookups[$leaf]->getName();
1036   - $treeStr .= $this->_evilActionHelper($iFieldsetId, $iFieldId, true, $leaf);
1037   - $treeStr .= '</li>'; }
1038   - }
1039   - }
1040   - $treeStr .= '</ul>';
1041   - return $treeStr;
1042   -
1043   - }
1044   -
1045   - // I can't seem to do recursion in smarty, and recursive templates seems a bad solution.
1046   - // Come up with a better way to do this (? NBM)
1047   -
1048   - /**
1049   - * render tree
1050   - *
1051   - * @param $treeToRender object
1052   - * @return tree string
1053   - *
1054   - * iNET Process
1055   - */
1056   - function _evilTreeRenderer($treeToRender) {
1057   - //global $default;
1058   -
1059   - $treeStr = "<!-- this is rendered with an unholy hack. sorry. -->";
1060   - $stack = array();
1061   - $exitstack = array();
1062   -
1063   - // since the root is virtual, we need to fake it here.
1064   - // the inner section is generised.
1065   - $treeStr .= '<ul class="kt_treenodes"><li class="treenode active"><a class="pathnode" onclick="toggleElementClass(\'active\', this.parentNode);toggleElementClass(\'inactive\', this.parentNode);">' . _kt('Root') . '</a>';
1066   - $treeStr .= ' (<a href="' . KTUtil::addQueryStringSelf($this->meldPersistQuery('current_node=0', 'managetree')) . '">' . _kt('attach keywords') . '</a>)';
1067   - $treeStr .= '<ul>';
1068   -
1069   -
1070   - foreach ($treeToRender->getRoot() as $node_id => $subtree_nodes)
1071   - {
1072   -
1073   - // leaves are handled differently.
1074   - if ($node_id !== "leaves") {
1075   -
1076   - $treeStr .= '<li class="treenode active"><a class="pathnode" onclick="toggleElementClass(\'active\', this.parentNode);toggleElementClass(\'inactive\', this.parentNode);">' . $treeToRender->mapnodes[$subtree_nodes]->getName() . '</a>';
1077   - $treeStr .= $this->_evilActionHelper($iFieldsetId, $iFieldId, false, $subtree_nodes);
1078   - $treeStr .= $this->_evilTreeRecursion($subtree_nodes, $treeToRender);
1079   - $treeStr .= '</li>';
1080   - }
1081   - else
1082   - {
1083   - foreach ($subtree_nodes as $leaf)
1084   - {
1085   - $treeStr .= '<li class="leafnode">' . $treeToRender->lookups[$leaf]->getName();
1086   - $treeStr .= $this->_evilActionHelper($iFieldsetId, $iFieldId, true, $leaf);
1087   - $treeStr .= '</li>';
1088   - }
1089   - }
1090   - }
1091   - $treeStr .= '</ul></li>';
1092   - $treeStr .= '</ul>';
1093   -
1094   - return $treeStr;
1095   - }
1096   -
1097   - // BS: don't hate me.
1098   - // BD: sorry. I hate you.
1099   - /**
1100   - * KT function
1101   - *
1102   - * @param $iFieldsetId ID
1103   - * @param $iFieldId ID
1104   - * @param $bIsKeyword boolean
1105   - * @param $current_node node ID
1106   - * @return string.
1107   - *
1108   - * iNET Process
1109   - */
1110   - function _evilActionHelper($iFieldsetId, $iFieldId, $bIsKeyword, $current_node) {
1111   - $actionStr = " (";
1112   - if ($bIsKeyword === true) {
1113   - $actionStr .= '<a href="' . KTUtil::addQueryStringSelf(KTUtil::addQueryStringSelf($this->meldPersistQuery('keyword_id='.$current_node.'&subaction=unlinkKeyword', 'managetree'))) . '">' . _kt('unlink') . '</a>';
1114   - } else {
1115   - $actionStr .= '<a href="' . KTUtil::addQueryStringSelf($this->meldPersistQuery('current_node=' . $current_node, 'managetree')) .'">' . _kt('attach keywords') . '</a> ';
1116   - $actionStr .= '| <a href="' . KTUtil::addQueryStringSelf($this->meldPersistQuery('current_node='.$current_node.'&subaction=deleteCategory', 'managetree')) . '">' . _kt('delete') . '</a>';
1117   - }
1118   - $actionStr .= ")";
1119   - return $actionStr;
1120   - }
1121   - /**
1122   - * Deletes a field
1123   - * @return
1124   - *
1125   - * iNET Process
1126   - */
1127   - function do_deletefield() {
1128   - $res = $this->oField->delete();
1129   - if (PEAR::isError($res)) {
1130   - $this->errorRedirectToParent(sprintf(_kt("Unable to delete field: %s"), $res->getMessage()));
1131   - }
1132   -
1133   - $this->successRedirectToParent(_kt("Field deleted."));
1134   - }
1135   -
1136   - /**
1137   - * Move field up in the order
1138   - *
1139   - * iNET Process
1140   - */
1141   - function do_orderUp() {
1142   - $iId = $this->oField->getID();
1143   - $iFieldsetId = $this->oField->getParentFieldsetId();
1144   -
1145   - $res = $this->oField->movePosition($iFieldsetId, $iId, 'up');
1146   - if ($res === false) {
1147   - $this->errorRedirectToParent(_kt("Unable to move field up"));
1148   - }
1149   -
1150   - $this->successRedirectToParent(_kt("Field moved up."));
1151   - }
1152   -
1153   - /**
1154   - * Move field down in the order
1155   - *
1156   - * iNET Process
1157   - */
1158   - function do_orderDown() {
1159   - $iId = $this->oField->getID();
1160   - $iFieldsetId = $this->oField->getParentFieldsetId();
1161   -
1162   - $res = $this->oField->movePosition($iFieldsetId, $iId, 'down');
1163   - if ($res === false) {
1164   - $this->errorRedirectToParent(_kt("Unable to move field down"));
1165   - }
1166   -
1167   - $this->successRedirectToParent(_kt("Field moved down."));
1168   - }
1169   -}
1170   -
1171   -?>
  1 +<?php
  2 +/**
  3 + * $Id$
  4 + *
  5 + * KnowledgeTree Community Edition
  6 + * Document Management Made Simple
  7 + * Copyright (C) 2008, 2009 KnowledgeTree Inc.
  8 + * Portions copyright The Jam Warehouse Software (Pty) Limited
  9 + *
  10 + * This program is free software; you can redistribute it and/or modify it under
  11 + * the terms of the GNU General Public License version 3 as published by the
  12 + * Free Software Foundation.
  13 + *
  14 + * This program is distributed in the hope that it will be useful, but WITHOUT
  15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  17 + * details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + *
  22 + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
  23 + * California 94120-7775, or email info@knowledgetree.com.
  24 + *
  25 + * The interactive user interfaces in modified source and object code versions
  26 + * of this program must display Appropriate Legal Notices, as required under
  27 + * Section 5 of the GNU General Public License version 3.
  28 + *
  29 + * In accordance with Section 7(b) of the GNU General Public License version 3,
  30 + * these Appropriate Legal Notices must retain the display of the "Powered by
  31 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  32 + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
  33 + * must display the words "Powered by KnowledgeTree" and retain the original
  34 + * copyright notice.
  35 + * Contributor( s): ______________________________________
  36 + *
  37 + */
  38 +
  39 +require_once(KT_LIB_DIR . '/dispatcher.inc.php');
  40 +require_once(KT_LIB_DIR . '/metadata/fieldset.inc.php');
  41 +require_once(KT_LIB_DIR . '/widgets/forms.inc.php');
  42 +require_once(KT_LIB_DIR . '/plugins/pluginutil.inc.php');
  43 +require_once(KT_LIB_DIR . "/documentmanagement/MDTree.inc");
  44 +
  45 +class InetBasicFieldsetManagementDispatcher extends KTAdminDispatcher {
  46 + var $bAutomaticTransaction = true;
  47 + var $bHaveConditional = null;
  48 + var $sHelpPage = 'ktcore/admin/document fieldsets.html';
  49 +
  50 + /**
  51 + * @param.
  52 + * @return.
  53 + *
  54 + * iNET Process
  55 + */
  56 + function predispatch() {
  57 + $this->persistParams(array('fFieldId'));
  58 + $this->oFieldset = KTFieldset::get(KTUtil::arrayGet($_REQUEST, 'fFieldsetId'));
  59 + if (PEAR::isError($this->oFieldset)) {
  60 + $this->oFieldset = null;
  61 + unset($_REQUEST['fFieldsetId']); // prevent further attacks.
  62 + }
  63 + $this->oField = DocumentField::get(KTUtil::arrayGet($_REQUEST, 'fFieldId'));
  64 + if (PEAR::isError($this->oField)) {
  65 + $this->oField = null;
  66 + unset($_REQUEST['fFieldId']); // prevent further attacks.
  67 + } else {
  68 + $this->aBreadcrumbs[] = array('url' => KTUtil::addQueryStringSelf($this->meldPersistQuery("","managefield")), 'name' => $this->oField->getName());
  69 + }
  70 + }
  71 +
  72 + /**
  73 + * API: this provides information about the fieldset, including which actions are available.
  74 + *
  75 + * @param $oFieldset object.
  76 + * @return template.
  77 + *
  78 + * iNET Process
  79 + */
  80 + function describe_fieldset($oFieldset) {
  81 + $this->persistParams(array('fFieldsetId','action'));
  82 + $oTemplate =& $this->oValidator->validateTemplate('ktcore/metadata/admin/basic_overview');
  83 + $oTemplate->setData(array(
  84 + 'context' => $this,
  85 + 'fields' => $oFieldset->getFields(),
  86 + ));
  87 + return $oTemplate->render();
  88 + }
  89 + /**
  90 + * Nothing doing
  91 + * iNET Process
  92 + */
  93 + function do_main () {
  94 + return _kt("Something very unexpected happened.");
  95 + }
  96 +
  97 + /**
  98 + * returns array of field type.
  99 + *
  100 + * @param.
  101 + * @return array.
  102 + *
  103 + * iNET Process
  104 + */
  105 + function getFieldTypeVocab() {
  106 + $types = array(
  107 + 'normal' => _kt("Normal (String)"),
  108 + 'lookup' => _kt("Lookup"),
  109 + 'tree' => _kt("Tree"),
  110 + 'Multiselect' => _kt("Multiselect"),
  111 + );
  112 + return $types;
  113 + }
  114 +
  115 +
  116 + /**
  117 + * multiselect change starts
  118 + * @return array
  119 + *
  120 + * iNET Process
  121 + */
  122 + function getLookupFieldTypeVocab() {
  123 + $types = array(
  124 +
  125 + 'multiwithlist' => _kt("Multiselect with a list"),
  126 + 'multiwithcheckboxes' => _kt("Multiselect with checkboxes"),
  127 + );
  128 + return $types;
  129 + }
  130 +
  131 + /**
  132 + * returns lookup type
  133 + * @return string
  134 + *
  135 + * iNET Process
  136 + */
  137 + function getDefaultLookupType() {
  138 + return 'multiwithlist';
  139 +
  140 + }
  141 +
  142 + /**
  143 + * multiselect change end
  144 + * @return
  145 + *
  146 + * iNET Process
  147 + */
  148 + function getDefaultType() {
  149 + return 'normal';
  150 + }
  151 + /**
  152 + * For for displaying new field
  153 + * @return
  154 + *
  155 + * iNET Process
  156 + */
  157 + function form_newfield() {
  158 + $this->oPage->setBreadcrumbDetails(_kt('add field'));
  159 +
  160 + $oForm = new KTForm;
  161 + $oForm->setOptions(array(
  162 + 'identifier' => 'ktcore.fieldsets.basic.field.create',
  163 + 'label' => _kt("Add New Field"),
  164 + 'submit_label' => _kt('Add Field'),
  165 + 'cancel_url' => $this->sParentUrl,
  166 + 'fail_action' => 'newfield',
  167 + 'action' => 'createfield',
  168 + 'context' => $this,
  169 + ));
  170 +
  171 + $type_vocab = $this->getFieldTypeVocab();
  172 +
  173 + $oForm->setWidgets(array(
  174 + array('ktcore.widgets.string',array(
  175 + 'label' => _kt("Field Name"),
  176 + 'name' => 'name',
  177 + 'required' => true,
  178 + 'description' => _kt("Within a given fieldset, each field needs a unique name."),
  179 + )),
  180 + array('ktcore.widgets.text',array(
  181 + 'label' => _kt("Description"),
  182 + 'name' => 'description',
  183 + 'required' => true,
  184 + 'description' => _kt("A good description can be the difference between useful metadata and poor metadata. At the same time, overly long descriptions are far less valuable than concise ones."),
  185 + )),
  186 + array('ktcore.widgets.selection', array(
  187 + 'label' => _kt('Field Type'),
  188 + 'name' => 'field_type',
  189 + 'vocab' => $this->getFieldTypeVocab(),
  190 + 'description' => _kt("Different types of fields may be available, depending on the system."),
  191 + 'required' => true,
  192 + 'value' => $this->getDefaultType(),
  193 + )),
  194 + array('ktcore.widgets.boolean',array(
  195 + 'label' => _kt("Required"),
  196 + 'name' => 'required',
  197 + 'description' => _kt("Required fields must be filled in, or the adding process will be rejected."),
  198 + )),
  199 +
  200 + ));
  201 +
  202 + $oForm->setValidators(array(
  203 + array('ktcore.validators.string', array(
  204 + 'test' => 'name',
  205 + 'output' => 'name',
  206 + )),
  207 + array('ktcore.validators.string', array(
  208 + 'test' => 'description',
  209 + 'output' => 'description',
  210 + )),
  211 + array('ktcore.validators.boolean', array(
  212 + 'test' => 'required',
  213 + 'output' => 'required',
  214 + )),
  215 + array('ktcore.validators.string', array(
  216 + 'test' => 'field_type',
  217 + 'output' => 'field_type',
  218 + )),
  219 + ));
  220 +
  221 + return $oForm;
  222 + }
  223 + /**
  224 + * Renders the page for new field
  225 + * @return
  226 + *
  227 + * iNET Process
  228 + */
  229 + function do_newfield() {
  230 + $oForm = $this->form_newfield();
  231 +
  232 + return $oForm->render();
  233 + }
  234 +
  235 + /**
  236 + * Creats a new field->multiselect
  237 + * @return
  238 + *
  239 + *
  240 + * iNET Process
  241 + */
  242 + function do_createfield() {
  243 + $oForm = $this->form_newfield();
  244 + $res = $oForm->validate();
  245 +
  246 + $data = $res['results'];
  247 + $errors = $res['errors'];
  248 + $extra_errors = array();
  249 +
  250 + $oField = DocumentField::getByFieldsetAndName($this->oFieldset, $data['name']);
  251 + if (!PEAR::isError($oField)) {
  252 + $extra_errors['name'] = _kt("A field with that name already exists in this fieldset.");
  253 + }
  254 +
  255 + if (!empty($errors) || !empty($extra_errors)) {
  256 + return $oForm->handleError(null, $extra_errors);
  257 + }
  258 +
  259 + $lookup = false;
  260 + $tree = false;
  261 + // multiselect change start
  262 + $inetlookup = false;
  263 + $inetlookupvalue = '';
  264 + // multiselect change end
  265 +
  266 + if ($data['field_type'] == 'lookup') {
  267 + $lookup = true;
  268 + } else if ($data['field_type'] == 'tree') {
  269 + $lookup = true;
  270 + $tree = true;
  271 + }
  272 + // multiselect change start
  273 + else if($data['field_type'] == 'Multiselect')
  274 + {
  275 + $inetlookup = true;
  276 + $inetlookupvalue = $this->getDefaultLookupType();
  277 + }
  278 + // multiselect change end
  279 +
  280 + $oField = DocumentField::createFromArray(array(
  281 + 'Name' => $data['name'],
  282 + 'Description' => $data['description'],
  283 + 'DataType' => 'STRING',
  284 + 'IsGeneric' => false,
  285 + 'HasLookup' => $lookup,
  286 + 'HasLookupTree' => $tree,
  287 + 'ParentFieldset' => $this->oFieldset->getId(),
  288 + 'IsMandatory' => $data['required'],
  289 + // multiselect change start
  290 + 'HasInetLookup' => $inetlookup,
  291 + 'InetLookupType' => $inetlookupvalue,
  292 + // multiselect change end
  293 + ));
  294 +
  295 + if (PEAR::isError($oField)) {
  296 + return $oForm->handleError(sprintf(_kt("Unable to create field: %s"), $oField->getMessage()));
  297 + }
  298 +
  299 + $this->successRedirectTo('managefield', _kt("Field created."), sprintf('fFieldId=%d', $oField->getId()));
  300 + }
  301 + /**
  302 + * Form for editing a field
  303 + * @return form
  304 + * @param $oField Object
  305 + *
  306 + * iNET Process
  307 + */
  308 + function form_editfield($oField) {
  309 + $oForm = new KTForm;
  310 + $oForm->setOptions(array(
  311 + 'identifier' => 'ktcore.fieldsets.basic.field.edit',
  312 + 'label' => _kt("Edit Field"),
  313 + 'submit_label' => _kt('Update Field'),
  314 + 'cancel_url' => $this->sParentUrl,
  315 + 'fail_action' => 'managefield',
  316 + 'action' => 'updatefield',
  317 + 'context' => $this,
  318 + ));
  319 +
  320 + $field_type = $oField->getType();
  321 + if($field_type == "Multiselect")
  322 + {
  323 + $oForm->setWidgets(array(
  324 + array('ktcore.widgets.string',array(
  325 + 'label' => _kt("Field Name"),
  326 + 'name' => 'name',
  327 + 'value' => sanitizeForHTML($oField->getName()),
  328 + 'required' => true,
  329 + 'description' => _kt("Within a given fieldset, each field needs a unique name."),
  330 + )),
  331 + array('ktcore.widgets.text',array(
  332 + 'label' => _kt("Description"),
  333 + 'name' => 'description',
  334 + 'value' => sanitizeForHTML($oField->getDescription()),
  335 + 'required' => true,
  336 + 'description' => _kt("A good description can be the difference between useful metadata and poor metadata. At the same time, overly long descriptions are far less valuable than concise ones."),
  337 + )),
  338 + array('ktcore.widgets.boolean',array(
  339 + 'label' => _kt("Required"),
  340 + 'value' => $oField->getIsMandatory(),
  341 + 'name' => 'required',
  342 + 'description' => _kt("Required fields must be filled in, or the adding process will be rejected."),
  343 + )),
  344 + array('ktcore.widgets.selection', array(
  345 + 'label' => _kt('Type of field'),
  346 + 'name' => 'inetlookup_type',
  347 + 'vocab' => $this->getLookupFieldTypeVocab(),
  348 + 'description' => _kt("Permits to create a multiselect or single select choices."),
  349 + 'required' => true,
  350 + 'value' => $oField->getInetLookupType(),
  351 + 'simple_select' => false,
  352 + )),
  353 + ));
  354 +
  355 + $oForm->setValidators(array(
  356 + array('ktcore.validators.string', array(
  357 + 'test' => 'name',
  358 + 'output' => 'name',
  359 + )),
  360 + array('ktcore.validators.string', array(
  361 + 'test' => 'description',
  362 + 'output' => 'description',
  363 + )),
  364 + array('ktcore.validators.boolean', array(
  365 + 'test' => 'required',
  366 + 'output' => 'required',
  367 + )),
  368 + array('ktcore.validators.string', array(
  369 + 'test' => 'inetlookup_type',
  370 + 'output' => 'inetlookup_type',
  371 + )),
  372 + ));
  373 + }
  374 + else
  375 + {
  376 +
  377 + $oForm->setWidgets(array(
  378 + array('ktcore.widgets.string',array(
  379 + 'label' => _kt("Field Name"),
  380 + 'name' => 'name',
  381 + 'value' => sanitizeForHTML($oField->getName()),
  382 + 'required' => true,
  383 + 'description' => _kt("Within a given fieldset, each field needs a unique name."),
  384 + )),
  385 + array('ktcore.widgets.text',array(
  386 + 'label' => _kt("Description"),
  387 + 'name' => 'description',
  388 + 'value' => sanitizeForHTML($oField->getDescription()),
  389 + 'required' => true,
  390 + 'description' => _kt("A good description can be the difference between useful metadata and poor metadata. At the same time, overly long descriptions are far less valuable than concise ones."),
  391 + )),
  392 + array('ktcore.widgets.boolean',array(
  393 + 'label' => _kt("Required"),
  394 + 'value' => $oField->getIsMandatory(),
  395 + 'name' => 'required',
  396 + 'description' => _kt("Required fields must be filled in, or the adding process will be rejected."),
  397 + )),
  398 +
  399 + ));
  400 +
  401 + $oForm->setValidators(array(
  402 + array('ktcore.validators.string', array(
  403 + 'test' => 'name',
  404 + 'output' => 'name',
  405 + )),
  406 + array('ktcore.validators.string', array(
  407 + 'test' => 'description',
  408 + 'output' => 'description',
  409 + )),
  410 + array('ktcore.validators.boolean', array(
  411 + 'test' => 'required',
  412 + 'output' => 'required',
  413 + )),
  414 + ));
  415 + }
  416 + return $oForm;
  417 + }
  418 + /**
  419 + * Manages a field
  420 + * @return template
  421 + *
  422 + *
  423 + * iNET Process
  424 + */
  425 + function do_managefield() {
  426 + $oTemplate = $this->oValidator->validateTemplate('manage_field');
  427 +
  428 + $oTemplate->setData(array(
  429 + 'context' => $this,
  430 + 'field_name' => $this->oField->getName(),
  431 + 'field_id' => $this->oField->getId(),
  432 + 'form' => $this->form_editfield($this->oField),
  433 + 'field' => $this->oField,
  434 + ));
  435 + return $oTemplate->render();
  436 + }
  437 + /**
  438 + * Updates a field
  439 + * @return.
  440 + *
  441 + *
  442 + * iNET Process
  443 + */
  444 + function do_updatefield() {
  445 + $oForm = $this->form_editfield($this->oField);
  446 + $res = $oForm->validate();
  447 + $data = $res['results'];
  448 + $errors = $res['errors'];
  449 + $extra_errors = array();
  450 +
  451 + // check that the field name either hasn't changed, or doesn't exist.
  452 + if ($data['name'] != $this->oField->getName()) {
  453 + $oOldField = DocumentField::getByFieldsetAndName($this->oFieldset, $data['name']);
  454 + if (!PEAR::isError($oOldField)) {
  455 + $extra_errors['name'] = _kt("That name is already in use in this fieldset. Please specify a unique name.");
  456 + }
  457 + }
  458 +
  459 + if (!empty($errors) || !empty($extra_errors)) {
  460 + return $oForm->handleError(null, $extra_errors);
  461 + }
  462 +
  463 + $this->oField->setName($data['name']);
  464 + $this->oField->setDescription($data['description']);
  465 + $this->oField->setIsMandatory($data['required']);
  466 +
  467 + // multiselect change start
  468 + if(isset($data['inetlookup_type']) && $this->oField->getHasInetLookup())
  469 + {
  470 + $this->oField->setInetLookupType($data['inetlookup_type']);
  471 + }
  472 + // multiselect change end
  473 +
  474 + $res = $this->oField->update();
  475 + if (PEAR::isError($res)) {
  476 + return $oForm->handleError(sprintf(_kt("Failed to update field: %s"), $res->getMessage()));
  477 + }
  478 +
  479 + $this->successRedirectTo('managefield',_kt("Field updated."));
  480 + }
  481 + /**
  482 + * Add lookup
  483 + * @return form
  484 + *
  485 + * iNET Process
  486 + */
  487 + function form_addlookups() {
  488 + $oForm = new KTForm;
  489 + $oForm->setOptions(array(
  490 + 'identifier' => 'ktcore.fieldsets.basic.field.addlookup',
  491 + 'label' => _kt("Add Lookup Values"),
  492 + 'submit_label' => _kt('Add Lookups'),
  493 + 'cancel_action' => 'managefield',
  494 + 'fail_action' => 'addlookupvalues',
  495 + 'action' => 'createlookupvalues',
  496 + 'context' => $this,
  497 + ));
  498 +
  499 + $oForm->setWidgets(array(
  500 + array('ktcore.widgets.text',array(
  501 + 'label' => _kt("Lookup Values"),
  502 + 'name' => 'lookups',
  503 + 'required' => true,
  504 + 'description' => _kt("Lookup values are what a user can select from a dropdown. These pre-created lookup values are useful, since they help you keep the metadata in the system organised."),
  505 + 'important_description' => _kt("Please enter the lookup values you wish to add, one per line."),
  506 + )),
  507 + ));
  508 +
  509 + $oForm->setValidators(array(
  510 + array('ktcore.validators.string', array(
  511 + 'test' => 'lookups',
  512 + 'output' => 'lookups',
  513 + 'max_length' => 9999,
  514 + )),
  515 + ));
  516 +
  517 + return $oForm;
  518 + }
  519 +
  520 + /**
  521 + * Add lookup values
  522 + * @return
  523 + *
  524 + * iNET Process
  525 + */
  526 + function do_addlookupvalues() {
  527 + $this->oPage->setBreadcrumbDetails(_kt('add lookup values'));
  528 +
  529 + $oForm = $this->form_addlookups();
  530 + return $oForm->render();
  531 + }
  532 + /**
  533 + * Create lookup values
  534 + * @return
  535 + */
  536 + function do_createlookupvalues() {
  537 + $oForm = $this->form_addlookups();
  538 + $res = $oForm->validate();
  539 + $data = $res['results'];
  540 + $errors = $res['errors'];
  541 + $extra_errors = array();
  542 +
  543 +
  544 + $failed = array();
  545 + $lookups = array();
  546 +
  547 + $raw_lookups = $data['lookups'];
  548 + $lookup_candidates = explode("\n", $raw_lookups);
  549 + foreach ($lookup_candidates as $candidate) {
  550 + $name = trim($candidate);
  551 +
  552 + if (empty($name)) {
  553 + continue;
  554 + }
  555 +
  556 + // check for existing or to-be-created lookups.
  557 + if ($lookups[$name]) {
  558 + $failed[$name] = $name;
  559 + continue;
  560 + }
  561 +
  562 + if ($failed[$name]) {
  563 + continue; // already blown up, fix it.
  564 + }
  565 +
  566 + $oOldLookup = MetaData::getByValueAndDocumentField($name, $this->oField);
  567 + if (!PEAR::isError($oOldLookup)) {
  568 + $failed[$name] = $name;
  569 + continue;
  570 + }
  571 +
  572 + $lookups[$name] = $name;
  573 + }
  574 + if (!empty($failed)) {
  575 + $extra_errors['lookups'][] = sprintf(_kt("The following lookups you specified already exist, or are specified twice: %s"), implode(', ', $failed));
  576 + } else if (empty($lookups)) {
  577 + $extra_errors['lookups'][] = _kt("You must have at least 1 new lookup value.");
  578 + }
  579 +
  580 + if (!empty($errors) || !empty($extra_errors)) {
  581 + return $oForm->handleError(null, $extra_errors);
  582 + }
  583 +
  584 + $data['lookups'] = $lookups;
  585 +
  586 + foreach ($lookups as $value) {
  587 + $oLookup = MetaData::createFromArray(array(
  588 + 'DocFieldId' => $this->oField->getId(),
  589 + 'sName' => $value,
  590 + 'iTreeParent' => null,
  591 + 'bDisabled' => false,
  592 + 'bIsStuck' => false,
  593 + ));
  594 + if (PEAR::isError($oLookup)) {
  595 + return $oForm->handleError(sprintf(_kt("Failed to create lookup: %s"), $oLookup->getMessage()));
  596 + }
  597 + }
  598 +
  599 + $this->successRedirectTo('managefield', sprintf(_kt("%d lookups added."), count($lookups)));
  600 + }
  601 + /**
  602 + * Manages lookups
  603 + * @return template
  604 + *
  605 + * iNET Process
  606 + */
  607 + function do_managelookups() {
  608 + $this->oPage->setBreadcrumbDetails(_kt('manage lookup values'));
  609 +
  610 + // Add javascript to create the edit form
  611 + $sJavaScript = "\nfunction editLookup(id)\n
  612 + {\n
  613 + var div = document.getElementById(id);\n
  614 + var value = div.innerHTML;
  615 +
  616 + <!-- Replace all double quotes with &#34; -->\n
  617 + matches = value.match(/\"/g);\n
  618 + var newValue = value;\n
  619 + if(matches){\n
  620 + for(var i = 0; i < matches.length; i++){\n
  621 + newValue = newValue.replace('\"', '&#34;');\n
  622 + }\n
  623 + }\n\n
  624 +
  625 + var inner = '<input type=\"text\" name=\"lookup['+id+']\" id=\"lookup_'+id+'\" value=\"'+newValue+'\" />';\n
  626 + inner += '<input type=\"hidden\" id=\"original_'+id+'\" value=\"'+newValue+'\" />';\n
  627 + inner += '<input type=\"submit\" name=\"submit[edit]\" value=\""._kt('Save')."\" />';\n
  628 + inner += '<input type=\"button\" onclick=\"javascript: closeLookupEdit('+id+');\" name=\"cancel\" value=\""._kt('Cancel')."\" />';\n
  629 + div.innerHTML = inner;\n
  630 + document.getElementById('lookup_'+id).focus();\n
  631 + }\n\n
  632 +
  633 + function closeLookupEdit(id)
  634 + {\n
  635 + value = document.getElementById('original_'+id).value;\n
  636 + document.getElementById(id).innerHTML = value;\n
  637 + }\n\n";
  638 +
  639 + $this->oPage->requireJSStandalone($sJavaScript);
  640 +
  641 + $lookups =& MetaData::getByDocumentField($this->oField);
  642 + $args = $this->meldPersistQuery("","metadataMultiAction", true);
  643 +
  644 + $oTemplate =& $this->oValidator->validateTemplate("ktcore/metadata/admin/manage_lookups");
  645 + $oTemplate->setData(array(
  646 + 'context' => $this,
  647 + 'field_name' => $this->oField->getName(),
  648 + 'lookups' => $lookups,
  649 + 'args' => $args,
  650 + ));
  651 + return $oTemplate->render();
  652 + }
  653 +
  654 + // {{{ do_metadataMultiAction
  655 + /**
  656 + * call metadata multiaction methods
  657 + * @param.
  658 + * @return.
  659 + *
  660 + * iNET Process
  661 + */
  662 + function do_metadataMultiAction() {
  663 + $subaction = array_keys(KTUtil::arrayGet($_REQUEST, 'submit', array()));
  664 + $this->oValidator->notEmpty($subaction, array("message" => _kt("No action specified")));
  665 + $subaction = $subaction[0];
  666 + $method = null;
  667 + if (method_exists($this, 'lookup_' . $subaction)) {
  668 + $method = 'lookup_' . $subaction;
  669 + }
  670 + $this->oValidator->notEmpty($method, array("message" => _kt("Unknown action specified")));
  671 + return $this->$method();
  672 + }
  673 + // }}}
  674 +
  675 + // {{{ lookup_remove
  676 + /**
  677 + * remove lookup value.
  678 + * @param
  679 + * @return
  680 + *
  681 + * iNET Process
  682 + */
  683 + function lookup_remove() {
  684 + $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']);
  685 + $oField =& DocumentField::get($_REQUEST['fFieldId']);
  686 + $aMetadata = KTUtil::arrayGet($_REQUEST, 'metadata');
  687 + if (empty($aMetadata)) {
  688 + $this->errorRedirectTo('managelookups', _kt('No lookups selected'));
  689 + }
  690 + foreach ($_REQUEST['metadata'] as $iMetaDataId) {
  691 + $oMetaData =& MetaData::get($iMetaDataId);
  692 + if (PEAR::isError($oMetaData)) {
  693 + $this->errorRedirectTo('managelookups', _kt('Invalid lookup selected'));
  694 + }
  695 + $oMetaData->delete();
  696 + }
  697 + $this->successRedirectTo('managelookups', _kt('Lookups removed'));
  698 + exit(0);
  699 + }
  700 + // }}}
  701 +
  702 + // {{{ lookup_disable
  703 + /**
  704 + * disable lookup value.
  705 + * @param
  706 + * @return
  707 + *
  708 + * iNET Process
  709 + */
  710 + function lookup_disable() {
  711 + $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']);
  712 + $oField =& DocumentField::get($_REQUEST['fFieldId']);
  713 + $aMetadata = KTUtil::arrayGet($_REQUEST, 'metadata');
  714 + if (empty($aMetadata)) {
  715 + $this->errorRedirectTo('managelookups', _kt('No lookups selected'));
  716 + }
  717 + foreach ($_REQUEST['metadata'] as $iMetaDataId) {
  718 + $oMetaData =& MetaData::get($iMetaDataId);
  719 + if (PEAR::isError($oMetaData)) {
  720 + $this->errorRedirectTo('managelookups', _kt('Invalid lookup selected'));
  721 + }
  722 + $oMetaData->setDisabled(true);
  723 + $oMetaData->update();
  724 + }
  725 + $this->successRedirectTo('managelookups', _kt('Lookups disabled'));
  726 + exit(0);
  727 + }
  728 + // }}}
  729 +
  730 + /**
  731 + * Save the edited lookup values
  732 + *
  733 + * @param.
  734 + * @return.
  735 + *
  736 + *iNET Process
  737 + */
  738 + function lookup_edit(){
  739 + $aLookupValues = $_REQUEST['lookup'];
  740 +
  741 + if(empty($aLookupValues)){
  742 + $this->errorRedirectTo('managelookups', _kt('No lookups were selected for editing'));
  743 + exit;
  744 + }
  745 +
  746 + foreach ($aLookupValues as $iMetaDataId => $sValue){
  747 + $oMetaData = MetaData::get($iMetaDataId);
  748 + if (PEAR::isError($oMetaData)) {
  749 + $this->addErrorMessage(_kt('Invalid lookup selected').': '.$sValue);
  750 + continue;
  751 +
  752 + }
  753 + if(empty($sValue)){
  754 + $this->addErrorMessage(_kt('Lookup cannot be empty').': '.$oMetaData->getName());
  755 + if(count($aLookupValues) == 1){
  756 + $this->redirectTo('managelookups');
  757 + }
  758 + continue;
  759 + }
  760 + $oMetaData->setName($sValue);
  761 + $oMetaData->update();
  762 + }
  763 +
  764 + $this->successRedirectTo('managelookups', _kt('Lookup values saved'));
  765 + exit(0);
  766 + }
  767 +
  768 + // {{{ lookup_enable
  769 + /**
  770 + * enable lookup value
  771 + * @param
  772 + * @return
  773 + *
  774 + * iNET Process
  775 + */
  776 + function lookup_toggleenabled() {
  777 + $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']);
  778 + $oField =& DocumentField::get($_REQUEST['fFieldId']);
  779 + $aMetadata = KTUtil::arrayGet($_REQUEST, 'metadata');
  780 + if (empty($aMetadata)) {
  781 + $this->errorRedirectTo('managelookups', _kt('No lookups selected'));
  782 + }
  783 + foreach ($_REQUEST['metadata'] as $iMetaDataId) {
  784 + $oMetaData =& MetaData::get($iMetaDataId);
  785 + if (PEAR::isError($oMetadata)) {
  786 + $this->errorRedirectTo('managelookups', _kt('Invalid lookup selected'));
  787 + }
  788 + $oMetaData->setDisabled(!$oMetaData->getDisabled());
  789 + $oMetaData->update();
  790 + }
  791 + $this->successRedirectTo('managelookups', _kt('Status Toggled'));
  792 + exit(0);
  793 + }
  794 + // }}}
  795 +
  796 + // {{{ lookup_togglestickiness
  797 + /**
  798 + * toggle stickiness of lookup values
  799 + * @param
  800 + * @return
  801 + *
  802 + * iNET Process
  803 + */
  804 + function lookup_togglestickiness() {
  805 + $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']);
  806 + $oField =& DocumentField::get($_REQUEST['fFieldId']);
  807 + $aMetadata = KTUtil::arrayGet($_REQUEST, 'metadata');
  808 + if (empty($aMetadata)) {
  809 + $this->errorRedirectTo('managelookups', _kt('No lookups selected'));
  810 + }
  811 + foreach ($_REQUEST['metadata'] as $iMetaDataId) {
  812 + $oMetaData =& MetaData::get($iMetaDataId);
  813 + if (PEAR::isError($oMetaData)) {
  814 + $this->errorRedirectTo('managelookups', _kt('Invalid lookups selected'));
  815 + }
  816 + $bStuck = (boolean)$oMetaData->getIsStuck();
  817 + $oMetaData->setIsStuck(!$bStuck);
  818 + $oMetaData->update();
  819 + }
  820 + $this->successRedirectTo('managelookups', _kt('Lookup stickiness toggled'));
  821 + exit(0);
  822 + }
  823 + // }}}
  824 +
  825 +// {{{ TREE
  826 + // create and display the tree editing form.
  827 + /**
  828 + * create and display the tree editing form.
  829 + * @param.
  830 + * @return template
  831 + *
  832 + * iNET Process
  833 + */
  834 + function do_managetree() {
  835 + global $default;
  836 + // extract.
  837 + $iFieldsetId = KTUtil::getId($this->oFieldset);
  838 + $iFieldId = KTUtil::getId($this->oField);
  839 +
  840 + $oFieldset =& $this->oFieldset;
  841 + $oField =& $this->oField;
  842 +
  843 + $this->oPage->setBreadcrumbDetails(_kt('edit lookup tree'));
  844 +
  845 + $field_id = $iFieldId;
  846 + $current_node = KTUtil::arrayGet($_REQUEST, 'current_node', 0);
  847 + $subaction = KTUtil::arrayGet($_REQUEST, 'subaction');
  848 +
  849 + // validate
  850 + if (empty($field_id)) { return $this->errorRedirectToMain(_kt("Must select a field to edit.")); }
  851 + $oField =& DocumentField::get($field_id);
  852 + if (PEAR::isError($oField)) { return $this->errorRedirectToMain(_kt("Invalid field.")); }
  853 +
  854 + $aErrorOptions = array(
  855 + 'redirect_to' => array('editTree', sprintf('field_id=%d', $field_id)),
  856 + );
  857 +
  858 + // under here we do the subaction rendering.
  859 + // we do this so we don't have to do _very_ strange things with multiple actions.
  860 +
  861 + $fieldTree =& new MDTree();
  862 + $fieldTree->buildForField($oField->getId());
  863 +
  864 + if ($subaction !== null) {
  865 + $target = 'managetree';
  866 + $msg = _kt('Changes saved.');
  867 + if ($subaction === "addCategory") {
  868 + $new_category = KTUtil::arrayGet($_REQUEST, 'category_name');
  869 + if (empty($new_category)) {
  870 + return $this->errorRedirectTo("managetree", _kt("Must enter a name for the new category."), array("field_id" => $field_id, "fFieldsetId" => $iFieldsetId));
  871 + } else {
  872 + $this->subact_addCategory($field_id, $current_node, $new_category, $fieldTree);
  873 + }
  874 + $msg = _kt('Category added'). ': ' . $new_category;
  875 + }
  876 + if ($subaction === "deleteCategory") {
  877 + $this->subact_deleteCategory($fieldTree, $current_node);
  878 + $current_node = 0; // clear out, and don't try and render the newly deleted category.
  879 + $msg = _kt('Category removed.');
  880 + }
  881 + if ($subaction === "linkKeywords") {
  882 + $keywords = KTUtil::arrayGet($_REQUEST, 'keywordsToAdd');
  883 + $aErrorOptions['message'] = _kt("No keywords selected");
  884 + $this->oValidator->notEmpty($keywords, $aErrorOptions);
  885 + $this->subact_linkKeywords($fieldTree, $current_node, $keywords);
  886 + $current_node = 0; // clear out, and don't try and render the newly deleted category.
  887 + $msg = _kt('Keywords added to category.');
  888 + }
  889 + if ($subaction === "unlinkKeyword") {
  890 + $keyword = KTUtil::arrayGet($_REQUEST, 'keyword_id');
  891 + $this->subact_unlinkKeyword($fieldTree, $keyword);
  892 + $msg = _kt('Keyword moved to base of tree.');
  893 + }
  894 + // now redirect
  895 + $query = sprintf('field_id=%d&fFieldsetId=%d', $field_id, $iFieldsetId);
  896 + return $this->successRedirectTo($target, $msg, $query);
  897 + }
  898 + if ($fieldTree->root === null) {
  899 + return $this->errorRedirectToMain(_kt("Error building tree. Is this a valid tree-lookup field?"));
  900 + }
  901 +
  902 + // FIXME extract this from MDTree (helper method?)
  903 + $free_metadata = MetaData::getList('document_field_id = '.$oField->getId().' AND (treeorg_parent = 0 OR treeorg_parent IS NULL) AND (disabled = 0)');
  904 +
  905 + // render edit template.
  906 +
  907 + $oTemplate = $this->oValidator->validateTemplate("ktcore/metadata/admin/edit_lookuptree");
  908 + $renderedTree = $this->_evilTreeRenderer($fieldTree);
  909 +
  910 + $this->oPage->setTitle(_kt('Edit Lookup Tree'));
  911 +
  912 + if ($current_node == 0) { $category_name = 'Root'; }
  913 + else {
  914 + $oNode = MDTreeNode::get($current_node);
  915 + $category_name = $oNode->getName();
  916 + }
  917 +
  918 + $aTemplateData = array(
  919 + "context" => $this,
  920 + "args" => $this->meldPersistQuery("","managetree", true),
  921 + "field" => $oField,
  922 + "oFieldset" => $oFieldset,
  923 + "tree" => $fieldTree,
  924 + "renderedTree" => $renderedTree,
  925 + "currentNode" => $current_node,
  926 + 'category_name' => $category_name,
  927 + "freechildren" => $free_metadata,
  928 +
  929 + );
  930 + return $oTemplate->render($aTemplateData);
  931 + }
  932 + /**
  933 + * Adds a category
  934 + * @return
  935 + * @param $field_id Object
  936 + * @param $current_node Object
  937 + * @param $new_category Object
  938 + * @param $constructedTree Object
  939 + *
  940 + * iNET Process
  941 + */
  942 + function subact_addCategory($field_id, $current_node, $new_category, &$constructedTree) {
  943 + $newCategory = MDTreeNode::createFromArray(array (
  944 + "iFieldId" => $field_id,
  945 + "sName" => $new_category,
  946 + "iParentNode" => $current_node,
  947 + ));
  948 + if (PEAR::isError($newCategory))
  949 + {
  950 + return false;
  951 + }
  952 + $constructedTree->addNode($newCategory);
  953 + return true;
  954 + }
  955 + /**
  956 + * Deletes a catagory
  957 + * @return
  958 + * @param $constructedTree Object
  959 + * @param $current_node Object
  960 + */
  961 + function subact_deleteCategory(&$constructedTree, $current_node) {
  962 + $constructedTree->deleteNode($current_node);
  963 + return true;
  964 + }
  965 +
  966 + /**
  967 + *
  968 + * @param $constructedTree object
  969 + * @param $keywords
  970 + * @return true.
  971 + *
  972 + * iNET Process
  973 + */
  974 + function subact_unlinkKeyword(&$constructedTree, $keyword) {
  975 + $oKW = MetaData::get($keyword);
  976 + if (PEAR::isError($oKW)) {
  977 + return true;
  978 + }
  979 + $constructedTree->reparentKeyword($oKW->getId(), 0);
  980 + return true;
  981 + }
  982 +
  983 + /**
  984 + *
  985 + * @param $constructedTree object
  986 + * @param $current_node node id
  987 + * @param $keywords array
  988 + * @return true.
  989 + *
  990 + * iNET Process
  991 + */
  992 + function subact_linkKeywords(&$constructedTree, $current_node, $keywords) {
  993 + foreach ($keywords as $md_id)
  994 + {
  995 + $constructedTree->reparentKeyword($md_id, $current_node);
  996 + }
  997 + return true;
  998 + }
  999 +
  1000 + /* ----------------------- EVIL HACK --------------------------
  1001 + *
  1002 + * This whole thing needs to replaced, as soon as I work out how
  1003 + * to non-sucking Smarty recursion.
  1004 + */
  1005 +
  1006 + /**
  1007 + * render to subnode of tree
  1008 + *
  1009 + * @param $subnode node
  1010 + * @param $treeToRender object
  1011 + * @Return string
  1012 + *
  1013 + * iNET Process
  1014 + */
  1015 + function _evilTreeRecursion($subnode, $treeToRender)
  1016 + {
  1017 + // deliver us from evil....
  1018 + $iFieldId = $treeToRender->field_id;
  1019 + $oField = DocumentField::get($iFieldId);
  1020 + $iFieldsetId = $oField->getParentFieldsetId();
  1021 +
  1022 + $treeStr = "<ul>";
  1023 + foreach ($treeToRender->contents[$subnode] as $subnode_id => $subnode_val)
  1024 + {
  1025 + if ($subnode_id !== "leaves") {
  1026 + $treeStr .= '<li class="treenode active"><a class="pathnode inactive" onclick="toggleElementClass(\'active\', this.parentNode); toggleElementClass(\'inactive\', this.parentNode);">' . $treeToRender->mapnodes[$subnode_val]->getName() . '</a>';
  1027 + $treeStr .= $this->_evilActionHelper($iFieldsetId, $iFieldId, false, $subnode_val);
  1028 + $treeStr .= $this->_evilTreeRecursion($subnode_val, $treeToRender);
  1029 + $treeStr .= '</li>';
  1030 + }
  1031 + else
  1032 + {
  1033 + foreach ($subnode_val as $leaf)
  1034 + {
  1035 + $treeStr .= '<li class="leafnode">' . $treeToRender->lookups[$leaf]->getName();
  1036 + $treeStr .= $this->_evilActionHelper($iFieldsetId, $iFieldId, true, $leaf);
  1037 + $treeStr .= '</li>'; }
  1038 + }
  1039 + }
  1040 + $treeStr .= '</ul>';
  1041 + return $treeStr;
  1042 +
  1043 + }
  1044 +
  1045 + // I can't seem to do recursion in smarty, and recursive templates seems a bad solution.
  1046 + // Come up with a better way to do this (? NBM)
  1047 +
  1048 + /**
  1049 + * render tree
  1050 + *
  1051 + * @param $treeToRender object
  1052 + * @return tree string
  1053 + *
  1054 + * iNET Process
  1055 + */
  1056 + function _evilTreeRenderer($treeToRender) {
  1057 + //global $default;
  1058 +
  1059 + $treeStr = "<!-- this is rendered with an unholy hack. sorry. -->";
  1060 + $stack = array();
  1061 + $exitstack = array();
  1062 +
  1063 + // since the root is virtual, we need to fake it here.
  1064 + // the inner section is generised.
  1065 + $treeStr .= '<ul class="kt_treenodes"><li class="treenode active"><a class="pathnode" onclick="toggleElementClass(\'active\', this.parentNode);toggleElementClass(\'inactive\', this.parentNode);">' . _kt('Root') . '</a>';
  1066 + $treeStr .= ' (<a href="' . KTUtil::addQueryStringSelf($this->meldPersistQuery('current_node=0', 'managetree')) . '">' . _kt('attach keywords') . '</a>)';
  1067 + $treeStr .= '<ul>';
  1068 +
  1069 +
  1070 + foreach ($treeToRender->getRoot() as $node_id => $subtree_nodes)
  1071 + {
  1072 +
  1073 + // leaves are handled differently.
  1074 + if ($node_id !== "leaves") {
  1075 +
  1076 + $treeStr .= '<li class="treenode active"><a class="pathnode" onclick="toggleElementClass(\'active\', this.parentNode);toggleElementClass(\'inactive\', this.parentNode);">' . $treeToRender->mapnodes[$subtree_nodes]->getName() . '</a>';
  1077 + $treeStr .= $this->_evilActionHelper($iFieldsetId, $iFieldId, false, $subtree_nodes);
  1078 + $treeStr .= $this->_evilTreeRecursion($subtree_nodes, $treeToRender);
  1079 + $treeStr .= '</li>';
  1080 + }
  1081 + else
  1082 + {
  1083 + foreach ($subtree_nodes as $leaf)
  1084 + {
  1085 + $treeStr .= '<li class="leafnode">' . $treeToRender->lookups[$leaf]->getName();
  1086 + $treeStr .= $this->_evilActionHelper($iFieldsetId, $iFieldId, true, $leaf);
  1087 + $treeStr .= '</li>';
  1088 + }
  1089 + }
  1090 + }
  1091 + $treeStr .= '</ul></li>';
  1092 + $treeStr .= '</ul>';
  1093 +
  1094 + return $treeStr;
  1095 + }
  1096 +
  1097 + // BS: don't hate me.
  1098 + // BD: sorry. I hate you.
  1099 + /**
  1100 + * KT function
  1101 + *
  1102 + * @param $iFieldsetId ID
  1103 + * @param $iFieldId ID
  1104 + * @param $bIsKeyword boolean
  1105 + * @param $current_node node ID
  1106 + * @return string.
  1107 + *
  1108 + * iNET Process
  1109 + */
  1110 + function _evilActionHelper($iFieldsetId, $iFieldId, $bIsKeyword, $current_node) {
  1111 + $actionStr = " (";
  1112 + if ($bIsKeyword === true) {
  1113 + $actionStr .= '<a href="' . KTUtil::addQueryStringSelf(KTUtil::addQueryStringSelf($this->meldPersistQuery('keyword_id='.$current_node.'&subaction=unlinkKeyword', 'managetree'))) . '">' . _kt('unlink') . '</a>';
  1114 + } else {
  1115 + $actionStr .= '<a href="' . KTUtil::addQueryStringSelf($this->meldPersistQuery('current_node=' . $current_node, 'managetree')) .'">' . _kt('attach keywords') . '</a> ';
  1116 + $actionStr .= '| <a href="' . KTUtil::addQueryStringSelf($this->meldPersistQuery('current_node='.$current_node.'&subaction=deleteCategory', 'managetree')) . '">' . _kt('delete') . '</a>';
  1117 + }
  1118 + $actionStr .= ")";
  1119 + return $actionStr;
  1120 + }
  1121 + /**
  1122 + * Deletes a field
  1123 + * @return
  1124 + *
  1125 + * iNET Process
  1126 + */
  1127 + function do_deletefield() {
  1128 + $res = $this->oField->delete();
  1129 + if (PEAR::isError($res)) {
  1130 + $this->errorRedirectToParent(sprintf(_kt("Unable to delete field: %s"), $res->getMessage()));
  1131 + }
  1132 +
  1133 + $this->successRedirectToParent(_kt("Field deleted."));
  1134 + }
  1135 +
  1136 + /**
  1137 + * Move field up in the order
  1138 + *
  1139 + * iNET Process
  1140 + */
  1141 + function do_orderUp() {
  1142 + $iId = $this->oField->getID();
  1143 + $iFieldsetId = $this->oField->getParentFieldsetId();
  1144 +
  1145 + $res = $this->oField->movePosition($iFieldsetId, $iId, 'up');
  1146 + if ($res === false) {
  1147 + $this->errorRedirectToParent(_kt("Unable to move field up"));
  1148 + }
  1149 +
  1150 + $this->successRedirectToParent(_kt("Field moved up."));
  1151 + }
  1152 +
  1153 + /**
  1154 + * Move field down in the order
  1155 + *
  1156 + * iNET Process
  1157 + */
  1158 + function do_orderDown() {
  1159 + $iId = $this->oField->getID();
  1160 + $iFieldsetId = $this->oField->getParentFieldsetId();
  1161 +
  1162 + $res = $this->oField->movePosition($iFieldsetId, $iId, 'down');
  1163 + if ($res === false) {
  1164 + $this->errorRedirectToParent(_kt("Unable to move field down"));
  1165 + }
  1166 +
  1167 + $this->successRedirectToParent(_kt("Field moved down."));
  1168 + }
  1169 +}
  1170 +
  1171 +?>
... ...
plugins/multiselect/js/hideadminlink.js
1   -//To hide the link for existing document fieldset
2   -JQ(document).ready(function(){
3   - var elems = JQ("dl.panel_menu").find("a");
4   - for (i = 0; i < elems.length; i++) {
5   - if(elems[i].href.search("kt_path_info=documents/fieldmanagement2") > -1)
6   - {
7   - JQ(elems[i]).parent("dt").hide();
8   - }
9   - }
10   -
11   - var elemsDesc = JQ("dl.panel_menu").find("dd");
12   - for (i = 0; i < elemsDesc.length; i++) {
13   - if(elemsDesc[i].innerHTML.search("Manage the different types of information that can be associated with classes of documents.") > -1)
14   - {
15   - JQ(elemsDesc[i]).hide();
16   - }
17   - }
18   -});
  1 +//To hide the link for existing document fieldset
  2 +JQ(document).ready(function(){
  3 + var elems = JQ("dl.panel_menu").find("a");
  4 + for (i = 0; i < elems.length; i++) {
  5 + if(elems[i].href.search("kt_path_info=documents/fieldmanagement2") > -1)
  6 + {
  7 + JQ(elems[i]).parent("dt").hide();
  8 + }
  9 + }
  10 +
  11 + var elemsDesc = JQ("dl.panel_menu").find("dd");
  12 + for (i = 0; i < elemsDesc.length; i++) {
  13 + if(elemsDesc[i].innerHTML.search("Manage the different types of information that can be associated with classes of documents.") > -1)
  14 + {
  15 + JQ(elemsDesc[i]).hide();
  16 + }
  17 + }
  18 +});
... ...
plugins/multiselect/js/hidelink.js
1   -//To hide the link for existing bulk upload link
2   -JQ(document).ready(function(){
3   - var elems = JQ("ul.actionlist").find("a");
4   - for (i = 0; i < elems.length; i++) {
5   - if(elems[i].href.search("kt_path_info=ktcore.actions.folder.bulkUpload") > -1 || elems[i].href.search("kt_path_info=inetfoldermetadata.actions.folder.bulkUpload") > -1)
6   - {
7   - JQ(elems[i]).parent("li").hide();
8   - }
9   - }
10   -});
11   -// added by SL:2009-03-04
12   -JQ(document).ready(function(){
13   - var elems = JQ("ul.actionlist").find("a");
14   - for (i = 0; i < elems.length; i++) {
15   - if(elems[i].href.search("kt_path_info=ktcore.actions.folder.bulkImport") > -1 || elems[i].href.search("kt_path_info=inetfoldermetadata.actions.folder.bulkUpload") > -1)
16   - {
17   - JQ(elems[i]).parent("li").hide();
18   - }
19   - }
  1 +//To hide the link for existing bulk upload link
  2 +JQ(document).ready(function(){
  3 + var elems = JQ("ul.actionlist").find("a");
  4 + for (i = 0; i < elems.length; i++) {
  5 + if(elems[i].href.search("kt_path_info=ktcore.actions.folder.bulkUpload") > -1 || elems[i].href.search("kt_path_info=inetfoldermetadata.actions.folder.bulkUpload") > -1)
  6 + {
  7 + JQ(elems[i]).parent("li").hide();
  8 + }
  9 + }
  10 +});
  11 +// added by SL:2009-03-04
  12 +JQ(document).ready(function(){
  13 + var elems = JQ("ul.actionlist").find("a");
  14 + for (i = 0; i < elems.length; i++) {
  15 + if(elems[i].href.search("kt_path_info=ktcore.actions.folder.bulkImport") > -1 || elems[i].href.search("kt_path_info=inetfoldermetadata.actions.folder.bulkUpload") > -1)
  16 + {
  17 + JQ(elems[i]).parent("li").hide();
  18 + }
  19 + }
20 20 });
21 21 \ No newline at end of file
... ...
plugins/multiselect/sql/script.sql
1   -ALTER TABLE `document_fields`
2   - ADD `has_inetlookup` tinyint(1) default NULL;
3   -
4   -ALTER TABLE `document_fields`
  1 +ALTER TABLE `document_fields`
  2 + ADD `has_inetlookup` tinyint(1) default NULL;
  3 +
  4 +ALTER TABLE `document_fields`
5 5 ADD `inetlookup_type` varchar(255) default NULL;
6 6 \ No newline at end of file
... ...
plugins/multiselect/templates/multiselect/selection.smarty
1   -<div class="field {if ($has_errors)}error{/if}">
2   - <label for="{$name}">{$label}{if ($required === true)}<span class="required">({i18n}Required{/i18n})</span>{/if}</label>
3   - <p class="descriptiveText">{$description}</p>
4   - {if empty($vocab)}
5   - <div class="ktInfoMessage"><span>{$context->sEmptyMessage}</span></div>
6   - {else}
7   - <select name="{$name}{* multiselect change start *}{if $options.multi}[]{/if}{* multiselect change end *}"
8   - {if $has_id}id="{$id}"{/if}
9   - {if $options.multi}multiple="true"{/if}
10   - >
11   - {if $options.initial_string}
12   - <option value="">{$options.initial_string}</option>
13   - {/if}
14   - {foreach item=lookup key=lookup_key from=$vocab}
15   - {* multiselect change start *}
16   - {if $options.multi}
17   - {capture assign=selected}{""}{/capture}
18   - {foreach item=value1 key=key from=$value}
19   - {if $value1 == $lookup_key}
20   - {capture assign=selected}selected='selected'{/capture}
21   - {/if}
22   - {/foreach}
23   - <option value="{$lookup_key|sanitize}" {$selected} >{$lookup|sanitize}</option>
24   - {else}{* multiselect change end *}
25   - <option value="{$lookup_key|sanitize}" {if ($value == $lookup_key)}selected="selected"{/if}>{$lookup|sanitize}</option>
26   - {* multiselect change start *}{/if}{* multiselect change end *}
27   - {/foreach}
28   - </select>
29   -{/if}
  1 +<div class="field {if ($has_errors)}error{/if}">
  2 + <label for="{$name}">{$label}{if ($required === true)}<span class="required">({i18n}Required{/i18n})</span>{/if}</label>
  3 + <p class="descriptiveText">{$description}</p>
  4 + {if empty($vocab)}
  5 + <div class="ktInfoMessage"><span>{$context->sEmptyMessage}</span></div>
  6 + {else}
  7 + <select name="{$name}{* multiselect change start *}{if $options.multi}[]{/if}{* multiselect change end *}"
  8 + {if $has_id}id="{$id}"{/if}
  9 + {if $options.multi}multiple="true"{/if}
  10 + >
  11 + {if $options.initial_string}
  12 + <option value="">{$options.initial_string}</option>
  13 + {/if}
  14 + {foreach item=lookup key=lookup_key from=$vocab}
  15 + {* multiselect change start *}
  16 + {if $options.multi}
  17 + {capture assign=selected}{""}{/capture}
  18 + {foreach item=value1 key=key from=$value}
  19 + {if $value1 == $lookup_key}
  20 + {capture assign=selected}selected='selected'{/capture}
  21 + {/if}
  22 + {/foreach}
  23 + <option value="{$lookup_key|sanitize}" {$selected} >{$lookup|sanitize}</option>
  24 + {else}{* multiselect change end *}
  25 + <option value="{$lookup_key|sanitize}" {if ($value == $lookup_key)}selected="selected"{/if}>{$lookup|sanitize}</option>
  26 + {* multiselect change start *}{/if}{* multiselect change end *}
  27 + {/foreach}
  28 + </select>
  29 +{/if}
30 30 </div>
31 31 \ No newline at end of file
... ...
plugins/multiselect/templates/multiselect/simple_selection.smarty
1   -<div class="field {if ($has_errors)}error{/if}">
2   - <label for="{$name}">{$label}{if ($required === true)}<span class="required">({i18n}Required{/i18n})</span>{/if}</label>
3   - <p class="descriptiveText">{$description}</p>
4   - {if empty($vocab)}
5   - <div class="ktInfoMessage"><span>{$context->sEmptyMessage}</span></div>
6   - {else}
7   -
8   - {* radio or checkboxes *}
9   - {if $options.multi}
10   - {foreach item=lookup key=lookup_key from=$vocab}
11   - <input type="checkbox" name="{$name}[]" value="{$lookup_key}" {if $context->selected($lookup_key)}checked="true"{/if}>{$lookup} <br />
12   - {/foreach}
13   - {else}
14   - {if $options.initial_string}
15   - <input type="radio" name="{$name}" {if $context->selected('')}checked="true"{/if}>{$options.initial_string} <br />
16   - {/if}
17   - {foreach item=lookup key=lookup_key from=$vocab}
18   - <input type="radio" name="{$name}" value="{$lookup_key}" {if $context->selected($lookup_key)}checked="true"{/if}>{$lookup} <br />
19   - {/foreach}
20   - {/if}
21   -
22   - {/if}
  1 +<div class="field {if ($has_errors)}error{/if}">
  2 + <label for="{$name}">{$label}{if ($required === true)}<span class="required">({i18n}Required{/i18n})</span>{/if}</label>
  3 + <p class="descriptiveText">{$description}</p>
  4 + {if empty($vocab)}
  5 + <div class="ktInfoMessage"><span>{$context->sEmptyMessage}</span></div>
  6 + {else}
  7 +
  8 + {* radio or checkboxes *}
  9 + {if $options.multi}
  10 + {foreach item=lookup key=lookup_key from=$vocab}
  11 + <input type="checkbox" name="{$name}[]" value="{$lookup_key}" {if $context->selected($lookup_key)}checked="true"{/if}>{$lookup} <br />
  12 + {/foreach}
  13 + {else}
  14 + {if $options.initial_string}
  15 + <input type="radio" name="{$name}" {if $context->selected('')}checked="true"{/if}>{$options.initial_string} <br />
  16 + {/if}
  17 + {foreach item=lookup key=lookup_key from=$vocab}
  18 + <input type="radio" name="{$name}" value="{$lookup_key}" {if $context->selected($lookup_key)}checked="true"{/if}>{$lookup} <br />
  19 + {/foreach}
  20 + {/if}
  21 +
  22 + {/if}
23 23 </div>
24 24 \ No newline at end of file
... ...