Commit 9b8512737d927deb75018292f6602e59cd25257a
1 parent
94a73181
KTS-3191
"Add Document: Missing Document type deletes source File selection" Fixed. Updated the javascript to only fill in the title if the field is empty. Added a message to reselect the filename. Committed by: Megan Watson Reviewed by: Jonathan Byrne git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@8358 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
119 additions
and
114 deletions
plugins/ktcore/KTValidators.php
| 1 | <?php | 1 | <?php |
| 2 | /** | 2 | /** |
| 3 | * $Id$ | 3 | * $Id$ |
| 4 | - * | 4 | + * |
| 5 | * KnowledgeTree Open Source Edition | 5 | * KnowledgeTree Open Source Edition |
| 6 | * Document Management Made Simple | 6 | * Document Management Made Simple |
| 7 | * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited | 7 | * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited |
| 8 | - * | 8 | + * |
| 9 | * This program is free software; you can redistribute it and/or modify it under | 9 | * This program is free software; you can redistribute it and/or modify it under |
| 10 | * the terms of the GNU General Public License version 3 as published by the | 10 | * the terms of the GNU General Public License version 3 as published by the |
| 11 | * Free Software Foundation. | 11 | * Free Software Foundation. |
| 12 | - * | 12 | + * |
| 13 | * This program is distributed in the hope that it will be useful, but WITHOUT | 13 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 15 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | 15 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 16 | * details. | 16 | * details. |
| 17 | - * | 17 | + * |
| 18 | * You should have received a copy of the GNU General Public License | 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | - * | 20 | + * |
| 21 | * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, | 21 | * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, |
| 22 | * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. | 22 | * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. |
| 23 | - * | 23 | + * |
| 24 | * The interactive user interfaces in modified source and object code versions | 24 | * The interactive user interfaces in modified source and object code versions |
| 25 | * of this program must display Appropriate Legal Notices, as required under | 25 | * of this program must display Appropriate Legal Notices, as required under |
| 26 | * Section 5 of the GNU General Public License version 3. | 26 | * Section 5 of the GNU General Public License version 3. |
| 27 | - * | 27 | + * |
| 28 | * In accordance with Section 7(b) of the GNU General Public License version 3, | 28 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 29 | * these Appropriate Legal Notices must retain the display of the "Powered by | 29 | * these Appropriate Legal Notices must retain the display of the "Powered by |
| 30 | - * KnowledgeTree" logo and retain the original copyright notice. If the display of the | 30 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the |
| 31 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | 31 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices |
| 32 | - * must display the words "Powered by KnowledgeTree" and retain the original | ||
| 33 | - * copyright notice. | 32 | + * must display the words "Powered by KnowledgeTree" and retain the original |
| 33 | + * copyright notice. | ||
| 34 | * Contributor( s): ______________________________________ | 34 | * Contributor( s): ______________________________________ |
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| @@ -40,54 +40,54 @@ require_once(KT_LIB_DIR . "/util/ktutil.inc"); | @@ -40,54 +40,54 @@ require_once(KT_LIB_DIR . "/util/ktutil.inc"); | ||
| 40 | 40 | ||
| 41 | class KTStringValidator extends KTValidator { | 41 | class KTStringValidator extends KTValidator { |
| 42 | var $sNamespace = 'ktcore.validators.string'; | 42 | var $sNamespace = 'ktcore.validators.string'; |
| 43 | - | 43 | + |
| 44 | var $iMinLength; | 44 | var $iMinLength; |
| 45 | var $iMaxLength; | 45 | var $iMaxLength; |
| 46 | var $sMinLengthWarning; | 46 | var $sMinLengthWarning; |
| 47 | - var $sMaxLengthWarning; | ||
| 48 | - | ||
| 49 | - | ||
| 50 | - | 47 | + var $sMaxLengthWarning; |
| 48 | + | ||
| 49 | + | ||
| 50 | + | ||
| 51 | function configure($aOptions) { | 51 | function configure($aOptions) { |
| 52 | $res = parent::configure($aOptions); | 52 | $res = parent::configure($aOptions); |
| 53 | if (PEAR::isError($res)) { | 53 | if (PEAR::isError($res)) { |
| 54 | return $res; | 54 | return $res; |
| 55 | } | 55 | } |
| 56 | - | 56 | + |
| 57 | $this->iMinLength = KTUtil::arrayGet($aOptions, 'min_length', 0); | 57 | $this->iMinLength = KTUtil::arrayGet($aOptions, 'min_length', 0); |
| 58 | $this->iMaxLength = KTUtil::arrayGet($aOptions, 'max_length', 254); // sane default for char fields... | 58 | $this->iMaxLength = KTUtil::arrayGet($aOptions, 'max_length', 254); // sane default for char fields... |
| 59 | - | 59 | + |
| 60 | $this->sMinLengthWarning = KTUtil::arrayGet($aOptions, 'min_length_warning', | 60 | $this->sMinLengthWarning = KTUtil::arrayGet($aOptions, 'min_length_warning', |
| 61 | sprintf(_kt('You must provide a value which is at least %d characters long.'), $this->iMinLength)); | 61 | sprintf(_kt('You must provide a value which is at least %d characters long.'), $this->iMinLength)); |
| 62 | $this->sMaxLengthWarning = KTUtil::arrayGet($aOptions, 'max_length_warning', | 62 | $this->sMaxLengthWarning = KTUtil::arrayGet($aOptions, 'max_length_warning', |
| 63 | - sprintf(_kt('You must provide a value which is at most %d characters long.'), $this->iMaxLength)); | ||
| 64 | - | ||
| 65 | - $this->bTrim = KTUtil::arrayGet($aOptions, 'trim', true, false); | 63 | + sprintf(_kt('You must provide a value which is at most %d characters long.'), $this->iMaxLength)); |
| 64 | + | ||
| 65 | + $this->bTrim = KTUtil::arrayGet($aOptions, 'trim', true, false); | ||
| 66 | } | 66 | } |
| 67 | - | 67 | + |
| 68 | function validate($data) { | 68 | function validate($data) { |
| 69 | $results = array(); | 69 | $results = array(); |
| 70 | $errors = array(); | 70 | $errors = array(); |
| 71 | - | 71 | + |
| 72 | // very simple if we're required and not present, fail | 72 | // very simple if we're required and not present, fail |
| 73 | // otherwise, its ok. | 73 | // otherwise, its ok. |
| 74 | $val = KTUtil::arrayGet($data, $this->sInputVariable); | 74 | $val = KTUtil::arrayGet($data, $this->sInputVariable); |
| 75 | - | 75 | + |
| 76 | if ($this->bTrim) { | 76 | if ($this->bTrim) { |
| 77 | $val = trim($val); | 77 | $val = trim($val); |
| 78 | } | 78 | } |
| 79 | - | 79 | + |
| 80 | $l = KTUtil::utf8_strlen($val); | 80 | $l = KTUtil::utf8_strlen($val); |
| 81 | if ($l < $this->iMinLength) { | 81 | if ($l < $this->iMinLength) { |
| 82 | $errors[$this->sBasename] = $this->sMinLengthWarning; | 82 | $errors[$this->sBasename] = $this->sMinLengthWarning; |
| 83 | } else if ($l > $this->iMaxLength) { | 83 | } else if ($l > $this->iMaxLength) { |
| 84 | $errors[$this->sBasename] = $this->sMaxLengthWarning; | 84 | $errors[$this->sBasename] = $this->sMaxLengthWarning; |
| 85 | } | 85 | } |
| 86 | - | 86 | + |
| 87 | if ($this->bProduceOutput) { | 87 | if ($this->bProduceOutput) { |
| 88 | $results[$this->sOutputVariable] = $val; | 88 | $results[$this->sOutputVariable] = $val; |
| 89 | } | 89 | } |
| 90 | - | 90 | + |
| 91 | return array( | 91 | return array( |
| 92 | 'errors' => $errors, | 92 | 'errors' => $errors, |
| 93 | 'results' => $results, | 93 | 'results' => $results, |
| @@ -98,28 +98,28 @@ class KTStringValidator extends KTValidator { | @@ -98,28 +98,28 @@ class KTStringValidator extends KTValidator { | ||
| 98 | class KTIllegalCharValidator extends KTValidator { | 98 | class KTIllegalCharValidator extends KTValidator { |
| 99 | var $sNamespace = 'ktcore.validators.illegal_char'; | 99 | var $sNamespace = 'ktcore.validators.illegal_char'; |
| 100 | var $sWarning; | 100 | var $sWarning; |
| 101 | - | 101 | + |
| 102 | function configure($aOptions) { | 102 | function configure($aOptions) { |
| 103 | $res = parent::configure($aOptions); | 103 | $res = parent::configure($aOptions); |
| 104 | if (PEAR::isError($res)) { | 104 | if (PEAR::isError($res)) { |
| 105 | return $res; | 105 | return $res; |
| 106 | } | 106 | } |
| 107 | - | 107 | + |
| 108 | $sChars = "\/*<>|%+':\"?"; | 108 | $sChars = "\/*<>|%+':\"?"; |
| 109 | $sWarning = sprintf(_kt('The value you have entered is invalid. The following characters are not allowed: %s'), $sChars); | 109 | $sWarning = sprintf(_kt('The value you have entered is invalid. The following characters are not allowed: %s'), $sChars); |
| 110 | $this->sWarning = KTUtil::arrayGet($aOptions, 'illegal_character_warning', $sWarning); | 110 | $this->sWarning = KTUtil::arrayGet($aOptions, 'illegal_character_warning', $sWarning); |
| 111 | - | ||
| 112 | - $this->bTrim = KTUtil::arrayGet($aOptions, 'trim', true, false); | 111 | + |
| 112 | + $this->bTrim = KTUtil::arrayGet($aOptions, 'trim', true, false); | ||
| 113 | } | 113 | } |
| 114 | - | 114 | + |
| 115 | function validate($data) { | 115 | function validate($data) { |
| 116 | $results = array(); | 116 | $results = array(); |
| 117 | $errors = array(); | 117 | $errors = array(); |
| 118 | - | 118 | + |
| 119 | // very simple if we're required and not present, fail | 119 | // very simple if we're required and not present, fail |
| 120 | // otherwise, its ok. | 120 | // otherwise, its ok. |
| 121 | $val = KTUtil::arrayGet($data, $this->sInputVariable); | 121 | $val = KTUtil::arrayGet($data, $this->sInputVariable); |
| 122 | - | 122 | + |
| 123 | if ($this->bTrim) { | 123 | if ($this->bTrim) { |
| 124 | $val = trim($val); | 124 | $val = trim($val); |
| 125 | } | 125 | } |
| @@ -134,7 +134,7 @@ class KTIllegalCharValidator extends KTValidator { | @@ -134,7 +134,7 @@ class KTIllegalCharValidator extends KTValidator { | ||
| 134 | if ($this->bProduceOutput) { | 134 | if ($this->bProduceOutput) { |
| 135 | $results[$this->sOutputVariable] = $val; | 135 | $results[$this->sOutputVariable] = $val; |
| 136 | } | 136 | } |
| 137 | - | 137 | + |
| 138 | return array( | 138 | return array( |
| 139 | 'errors' => $errors, | 139 | 'errors' => $errors, |
| 140 | 'results' => $results, | 140 | 'results' => $results, |
| @@ -144,16 +144,16 @@ class KTIllegalCharValidator extends KTValidator { | @@ -144,16 +144,16 @@ class KTIllegalCharValidator extends KTValidator { | ||
| 144 | 144 | ||
| 145 | class KTEntityValidator extends KTValidator { | 145 | class KTEntityValidator extends KTValidator { |
| 146 | var $sNamespace = 'ktcore.validators.entity'; | 146 | var $sNamespace = 'ktcore.validators.entity'; |
| 147 | - | 147 | + |
| 148 | var $sEntityClass; | 148 | var $sEntityClass; |
| 149 | var $sGetFunction; | 149 | var $sGetFunction; |
| 150 | - | 150 | + |
| 151 | function configure($aOptions) { | 151 | function configure($aOptions) { |
| 152 | $res = parent::configure($aOptions); | 152 | $res = parent::configure($aOptions); |
| 153 | if (PEAR::isError($res)) { | 153 | if (PEAR::isError($res)) { |
| 154 | return $res; | 154 | return $res; |
| 155 | } | 155 | } |
| 156 | - | 156 | + |
| 157 | $this->sEntityClass = KTUtil::arrayGet($aOptions, 'class'); | 157 | $this->sEntityClass = KTUtil::arrayGet($aOptions, 'class'); |
| 158 | if (empty($this->sEntityClass)) { | 158 | if (empty($this->sEntityClass)) { |
| 159 | return PEAR::raiseError(_kt("No entity class specified.")); | 159 | return PEAR::raiseError(_kt("No entity class specified.")); |
| @@ -161,16 +161,16 @@ class KTEntityValidator extends KTValidator { | @@ -161,16 +161,16 @@ class KTEntityValidator extends KTValidator { | ||
| 161 | $this->sGetFunction = KTUtil::arrayGet($aOptions, 'id_method', 'get'); | 161 | $this->sGetFunction = KTUtil::arrayGet($aOptions, 'id_method', 'get'); |
| 162 | $this->bMultiple = KTUtil::arrayGet($aOptions, 'multi', false, false); | 162 | $this->bMultiple = KTUtil::arrayGet($aOptions, 'multi', false, false); |
| 163 | } | 163 | } |
| 164 | - | 164 | + |
| 165 | function validate($data) { | 165 | function validate($data) { |
| 166 | $results = array(); | 166 | $results = array(); |
| 167 | $errors = array(); | 167 | $errors = array(); |
| 168 | - | ||
| 169 | 168 | ||
| 170 | - | 169 | + |
| 170 | + | ||
| 171 | $aFunc = array($this->sEntityClass, $this->sGetFunction); | 171 | $aFunc = array($this->sEntityClass, $this->sGetFunction); |
| 172 | 172 | ||
| 173 | - | 173 | + |
| 174 | $val = KTUtil::arrayGet($data, $this->sInputVariable); | 174 | $val = KTUtil::arrayGet($data, $this->sInputVariable); |
| 175 | $output = null; | 175 | $output = null; |
| 176 | if (!empty($val)) { | 176 | if (!empty($val)) { |
| @@ -198,7 +198,7 @@ class KTEntityValidator extends KTValidator { | @@ -198,7 +198,7 @@ class KTEntityValidator extends KTValidator { | ||
| 198 | $oEntity =& call_user_func($aFunc, $val); | 198 | $oEntity =& call_user_func($aFunc, $val); |
| 199 | if (PEAR::isError($oEntity)) { | 199 | if (PEAR::isError($oEntity)) { |
| 200 | $errors[$this->sBasename] = sprintf(_kt("No such id: %s"), $val); | 200 | $errors[$this->sBasename] = sprintf(_kt("No such id: %s"), $val); |
| 201 | - } | 201 | + } |
| 202 | if ($this->aOptions['ids']) { | 202 | if ($this->aOptions['ids']) { |
| 203 | $output = $val; | 203 | $output = $val; |
| 204 | } else { | 204 | } else { |
| @@ -210,7 +210,7 @@ class KTEntityValidator extends KTValidator { | @@ -210,7 +210,7 @@ class KTEntityValidator extends KTValidator { | ||
| 210 | if ($this->bProduceOutput) { | 210 | if ($this->bProduceOutput) { |
| 211 | $results[$this->sOutputVariable] = $output; | 211 | $results[$this->sOutputVariable] = $output; |
| 212 | } | 212 | } |
| 213 | - | 213 | + |
| 214 | return array( | 214 | return array( |
| 215 | 'errors' => $errors, | 215 | 'errors' => $errors, |
| 216 | 'results' => $results, | 216 | 'results' => $results, |
| @@ -222,15 +222,15 @@ class KTEntityValidator extends KTValidator { | @@ -222,15 +222,15 @@ class KTEntityValidator extends KTValidator { | ||
| 222 | // in the data array. | 222 | // in the data array. |
| 223 | class KTRequiredValidator extends KTValidator { | 223 | class KTRequiredValidator extends KTValidator { |
| 224 | var $sNamespace = 'ktcore.validators.required'; | 224 | var $sNamespace = 'ktcore.validators.required'; |
| 225 | - | 225 | + |
| 226 | function validate($data) { | 226 | function validate($data) { |
| 227 | $errors = array(); | 227 | $errors = array(); |
| 228 | - | 228 | + |
| 229 | $val = KTUtil::arrayGet($data, $this->sInputVariable); | 229 | $val = KTUtil::arrayGet($data, $this->sInputVariable); |
| 230 | if (empty($val)) { | 230 | if (empty($val)) { |
| 231 | $errors[$this->sBasename] = _kt("You must provide a value for this field."); | 231 | $errors[$this->sBasename] = _kt("You must provide a value for this field."); |
| 232 | } | 232 | } |
| 233 | - | 233 | + |
| 234 | return array( | 234 | return array( |
| 235 | 'errors' => $errors, | 235 | 'errors' => $errors, |
| 236 | 'results' => array(), | 236 | 'results' => array(), |
| @@ -242,15 +242,17 @@ class KTRequiredValidator extends KTValidator { | @@ -242,15 +242,17 @@ class KTRequiredValidator extends KTValidator { | ||
| 242 | // in the data array. | 242 | // in the data array. |
| 243 | class KTRequiredFileValidator extends KTValidator { | 243 | class KTRequiredFileValidator extends KTValidator { |
| 244 | var $sNamespace = 'ktcore.validators.requiredfile'; | 244 | var $sNamespace = 'ktcore.validators.requiredfile'; |
| 245 | - | 245 | + |
| 246 | function validate($data) { | 246 | function validate($data) { |
| 247 | $errors = array(); | 247 | $errors = array(); |
| 248 | - | 248 | + |
| 249 | $val = KTUtil::arrayGet($_FILES, $this->sInputVariable); | 249 | $val = KTUtil::arrayGet($_FILES, $this->sInputVariable); |
| 250 | if (empty($val) || empty($val['name'])) { | 250 | if (empty($val) || empty($val['name'])) { |
| 251 | $errors[$this->sBasename] = _kt("You must select a file to upload."); | 251 | $errors[$this->sBasename] = _kt("You must select a file to upload."); |
| 252 | - } | ||
| 253 | - | 252 | + }else{ |
| 253 | + $errors[$this->sBasename] = _kt("Please reselect the file to upload."); | ||
| 254 | + } | ||
| 255 | + | ||
| 254 | return array( | 256 | return array( |
| 255 | 'errors' => $errors, | 257 | 'errors' => $errors, |
| 256 | 'results' => array(), | 258 | 'results' => array(), |
| @@ -260,27 +262,27 @@ class KTRequiredFileValidator extends KTValidator { | @@ -260,27 +262,27 @@ class KTRequiredFileValidator extends KTValidator { | ||
| 260 | 262 | ||
| 261 | class KTEmailValidator extends KTValidator { | 263 | class KTEmailValidator extends KTValidator { |
| 262 | var $sNamespace = 'ktcore.validators.emailaddress'; | 264 | var $sNamespace = 'ktcore.validators.emailaddress'; |
| 263 | - | 265 | + |
| 264 | function validate($data) { | 266 | function validate($data) { |
| 265 | $results = array(); | 267 | $results = array(); |
| 266 | $errors = array(); | 268 | $errors = array(); |
| 267 | - | 269 | + |
| 268 | // very simple if we're required and not present, fail | 270 | // very simple if we're required and not present, fail |
| 269 | // otherwise, its ok. | 271 | // otherwise, its ok. |
| 270 | $val = KTUtil::arrayGet($data, $this->sInputVariable); | 272 | $val = KTUtil::arrayGet($data, $this->sInputVariable); |
| 271 | 273 | ||
| 272 | $sEmailAddress = trim($val); | 274 | $sEmailAddress = trim($val); |
| 273 | - | 275 | + |
| 274 | if (!ereg ("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $sEmailAddress )) { | 276 | if (!ereg ("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $sEmailAddress )) { |
| 275 | $errors[$this->sBasename] = KTUtil::arrayGet($this->aOptions, | 277 | $errors[$this->sBasename] = KTUtil::arrayGet($this->aOptions, |
| 276 | - 'message', | 278 | + 'message', |
| 277 | _kt("This is not a valid email address.")); | 279 | _kt("This is not a valid email address.")); |
| 278 | } | 280 | } |
| 279 | - | 281 | + |
| 280 | if ($this->bProduceOutput) { | 282 | if ($this->bProduceOutput) { |
| 281 | $results[$this->sOutputVariable] = $sEmailAddress; | 283 | $results[$this->sOutputVariable] = $sEmailAddress; |
| 282 | } | 284 | } |
| 283 | - | 285 | + |
| 284 | return array( | 286 | return array( |
| 285 | 'errors' => $errors, | 287 | 'errors' => $errors, |
| 286 | 'results' => $results, | 288 | 'results' => $results, |
| @@ -291,21 +293,21 @@ class KTEmailValidator extends KTValidator { | @@ -291,21 +293,21 @@ class KTEmailValidator extends KTValidator { | ||
| 291 | 293 | ||
| 292 | class KTBooleanValidator extends KTValidator { | 294 | class KTBooleanValidator extends KTValidator { |
| 293 | var $sNamespace = 'ktcore.validators.boolean'; | 295 | var $sNamespace = 'ktcore.validators.boolean'; |
| 294 | - | 296 | + |
| 295 | function validate($data) { | 297 | function validate($data) { |
| 296 | $results = array(); | 298 | $results = array(); |
| 297 | $errors = array(); | 299 | $errors = array(); |
| 298 | - | 300 | + |
| 299 | // very simple if we're required and not present, fail | 301 | // very simple if we're required and not present, fail |
| 300 | // otherwise, its ok. | 302 | // otherwise, its ok. |
| 301 | $val = KTUtil::arrayGet($data, $this->sInputVariable); | 303 | $val = KTUtil::arrayGet($data, $this->sInputVariable); |
| 302 | 304 | ||
| 303 | - $out = ($val == true); | ||
| 304 | - | 305 | + $out = ($val == true); |
| 306 | + | ||
| 305 | if ($this->bProduceOutput) { | 307 | if ($this->bProduceOutput) { |
| 306 | $results[$this->sOutputVariable] = $out; | 308 | $results[$this->sOutputVariable] = $out; |
| 307 | } | 309 | } |
| 308 | - | 310 | + |
| 309 | return array( | 311 | return array( |
| 310 | 'errors' => $errors, | 312 | 'errors' => $errors, |
| 311 | 'results' => $results, | 313 | 'results' => $results, |
| @@ -316,7 +318,7 @@ class KTBooleanValidator extends KTValidator { | @@ -316,7 +318,7 @@ class KTBooleanValidator extends KTValidator { | ||
| 316 | 318 | ||
| 317 | class KTPasswordValidator extends KTValidator { | 319 | class KTPasswordValidator extends KTValidator { |
| 318 | var $sNamespace = 'ktcore.validators.password'; | 320 | var $sNamespace = 'ktcore.validators.password'; |
| 319 | - | 321 | + |
| 320 | function validate($data) { | 322 | function validate($data) { |
| 321 | $results = array(); | 323 | $results = array(); |
| 322 | $errors = array(); | 324 | $errors = array(); |
| @@ -325,11 +327,11 @@ class KTPasswordValidator extends KTValidator { | @@ -325,11 +327,11 @@ class KTPasswordValidator extends KTValidator { | ||
| 325 | if ($bundle['base'] != $bundle['confirm']) { | 327 | if ($bundle['base'] != $bundle['confirm']) { |
| 326 | $errors[$this->sBasename] = _kt('Your passwords do not match.'); | 328 | $errors[$this->sBasename] = _kt('Your passwords do not match.'); |
| 327 | } | 329 | } |
| 328 | - | 330 | + |
| 329 | if ($this->bProduceOutput) { | 331 | if ($this->bProduceOutput) { |
| 330 | $results[$this->sOutputVariable] = $val; | 332 | $results[$this->sOutputVariable] = $val; |
| 331 | } | 333 | } |
| 332 | - | 334 | + |
| 333 | return array( | 335 | return array( |
| 334 | 'errors' => $errors, | 336 | 'errors' => $errors, |
| 335 | 'results' => $results, | 337 | 'results' => $results, |
| @@ -339,16 +341,16 @@ class KTPasswordValidator extends KTValidator { | @@ -339,16 +341,16 @@ class KTPasswordValidator extends KTValidator { | ||
| 339 | 341 | ||
| 340 | class KTMembershipValidator extends KTValidator { | 342 | class KTMembershipValidator extends KTValidator { |
| 341 | var $sNamespace = 'ktcore.validators.membership'; | 343 | var $sNamespace = 'ktcore.validators.membership'; |
| 342 | - | 344 | + |
| 343 | var $bMulti; | 345 | var $bMulti; |
| 344 | var $aVocab; | 346 | var $aVocab; |
| 345 | - | 347 | + |
| 346 | function configure($aOptions) { | 348 | function configure($aOptions) { |
| 347 | $res = parent::configure($aOptions); | 349 | $res = parent::configure($aOptions); |
| 348 | - if (PEAR::isError($res)) { | 350 | + if (PEAR::isError($res)) { |
| 349 | return $res; | 351 | return $res; |
| 350 | } | 352 | } |
| 351 | - | 353 | + |
| 352 | $this->bMulti = KTUtil::arrayGet($aOptions, 'multi', false); | 354 | $this->bMulti = KTUtil::arrayGet($aOptions, 'multi', false); |
| 353 | $vocab = (array) KTUtil::arrayGet($aOptions, 'vocab'); | 355 | $vocab = (array) KTUtil::arrayGet($aOptions, 'vocab'); |
| 354 | $this->aVocab = array(); | 356 | $this->aVocab = array(); |
| @@ -356,17 +358,17 @@ class KTMembershipValidator extends KTValidator { | @@ -356,17 +358,17 @@ class KTMembershipValidator extends KTValidator { | ||
| 356 | $this->aVocab[$v] = true; | 358 | $this->aVocab[$v] = true; |
| 357 | } | 359 | } |
| 358 | } | 360 | } |
| 359 | - | 361 | + |
| 360 | function validate($data) { | 362 | function validate($data) { |
| 361 | $results = array(); | 363 | $results = array(); |
| 362 | $errors = array(); | 364 | $errors = array(); |
| 363 | - | 365 | + |
| 364 | // very simple if we're required and not present, fail | 366 | // very simple if we're required and not present, fail |
| 365 | // otherwise, its ok. | 367 | // otherwise, its ok. |
| 366 | $val = KTUtil::arrayGet($data, $this->sInputVariable); | 368 | $val = KTUtil::arrayGet($data, $this->sInputVariable); |
| 367 | if (empty($val)) { | 369 | if (empty($val)) { |
| 368 | ; // pass | 370 | ; // pass |
| 369 | - } else { | 371 | + } else { |
| 370 | if ($this->bMulti) { | 372 | if ($this->bMulti) { |
| 371 | $val = (array) $val; | 373 | $val = (array) $val; |
| 372 | $failed = array(); | 374 | $failed = array(); |
| @@ -376,32 +378,32 @@ class KTMembershipValidator extends KTValidator { | @@ -376,32 +378,32 @@ class KTMembershipValidator extends KTValidator { | ||
| 376 | } | 378 | } |
| 377 | } | 379 | } |
| 378 | if (!empty($failed)) { | 380 | if (!empty($failed)) { |
| 379 | - $errors[$this->sBasename] = KTUtil::arrayGet($this->aOptions, | ||
| 380 | - 'error_message', sprintf(_kt('"%s" are not valid selections.'), | ||
| 381 | - implode(', ', $failed))); | 381 | + $errors[$this->sBasename] = KTUtil::arrayGet($this->aOptions, |
| 382 | + 'error_message', sprintf(_kt('"%s" are not valid selections.'), | ||
| 383 | + implode(', ', $failed))); | ||
| 382 | } | 384 | } |
| 383 | } else { | 385 | } else { |
| 384 | - | 386 | + |
| 385 | $mandatory=true; | 387 | $mandatory=true; |
| 386 | - | 388 | + |
| 387 | if (substr($this->sInputVariable, 0, 9) == 'metadata_') | 389 | if (substr($this->sInputVariable, 0, 9) == 'metadata_') |
| 388 | { | 390 | { |
| 389 | $fieldid = substr($this->sInputVariable, 9); | 391 | $fieldid = substr($this->sInputVariable, 9); |
| 390 | $field = DocumentField::get($fieldid); | 392 | $field = DocumentField::get($fieldid); |
| 391 | $mandatory = $field->getIsMandatory(); | 393 | $mandatory = $field->getIsMandatory(); |
| 392 | - } | ||
| 393 | - | 394 | + } |
| 395 | + | ||
| 394 | if (!array_key_exists($val, $this->aVocab) && $mandatory) { | 396 | if (!array_key_exists($val, $this->aVocab) && $mandatory) { |
| 395 | - $errors[$this->sBasename] = KTUtil::arrayGet($this->aOptions, | 397 | + $errors[$this->sBasename] = KTUtil::arrayGet($this->aOptions, |
| 396 | 'error_message', sprintf(_kt('"%s"is not a valid selection.'), $val)); | 398 | 'error_message', sprintf(_kt('"%s"is not a valid selection.'), $val)); |
| 397 | } | 399 | } |
| 398 | } | 400 | } |
| 399 | } | 401 | } |
| 400 | - | 402 | + |
| 401 | if ($this->bProduceOutput) { | 403 | if ($this->bProduceOutput) { |
| 402 | $results[$this->sOutputVariable] = $val; | 404 | $results[$this->sOutputVariable] = $val; |
| 403 | } | 405 | } |
| 404 | - | 406 | + |
| 405 | return array( | 407 | return array( |
| 406 | 'errors' => $errors, | 408 | 'errors' => $errors, |
| 407 | 'results' => $results, | 409 | 'results' => $results, |
| @@ -412,34 +414,34 @@ class KTMembershipValidator extends KTValidator { | @@ -412,34 +414,34 @@ class KTMembershipValidator extends KTValidator { | ||
| 412 | 414 | ||
| 413 | class KTFieldsetValidator extends KTValidator { | 415 | class KTFieldsetValidator extends KTValidator { |
| 414 | var $sNamespace = 'ktcore.validators.fieldset'; | 416 | var $sNamespace = 'ktcore.validators.fieldset'; |
| 415 | - | 417 | + |
| 416 | var $_validators; | 418 | var $_validators; |
| 417 | - | 419 | + |
| 418 | function configure($aOptions) { | 420 | function configure($aOptions) { |
| 419 | $res = parent::configure($aOptions); | 421 | $res = parent::configure($aOptions); |
| 420 | - if (PEAR::isError($res)) { | 422 | + if (PEAR::isError($res)) { |
| 421 | return $res; | 423 | return $res; |
| 422 | } | 424 | } |
| 423 | 425 | ||
| 424 | $this->_validators = (array) KTUtil::arrayGet($aOptions, 'validators', array()); | 426 | $this->_validators = (array) KTUtil::arrayGet($aOptions, 'validators', array()); |
| 425 | } | 427 | } |
| 426 | - | 428 | + |
| 427 | function validate($data) { | 429 | function validate($data) { |
| 428 | $results = array(); | 430 | $results = array(); |
| 429 | $errors = array(); | 431 | $errors = array(); |
| 430 | - | 432 | + |
| 431 | // very simple if we're required and not present, fail | 433 | // very simple if we're required and not present, fail |
| 432 | // otherwise, its ok. | 434 | // otherwise, its ok. |
| 433 | $d = (array) KTUtil::arrayGet($data, $this->sInputVariable); | 435 | $d = (array) KTUtil::arrayGet($data, $this->sInputVariable); |
| 434 | //var_dump($this); exit(0); | 436 | //var_dump($this); exit(0); |
| 435 | foreach ($this->_validators as $v) { | 437 | foreach ($this->_validators as $v) { |
| 436 | $res = $v->validate($d); | 438 | $res = $v->validate($d); |
| 437 | - | 439 | + |
| 438 | // results comes out with a set of names and values. | 440 | // results comes out with a set of names and values. |
| 439 | // these *shouldn't* overlap, so just merge them | 441 | // these *shouldn't* overlap, so just merge them |
| 440 | $extra_results = KTUtil::arrayGet($res, 'results', array()); | 442 | $extra_results = KTUtil::arrayGet($res, 'results', array()); |
| 441 | $results = kt_array_merge($results, $extra_results); | 443 | $results = kt_array_merge($results, $extra_results); |
| 442 | - | 444 | + |
| 443 | // errors *can* overlap | 445 | // errors *can* overlap |
| 444 | // the format is: | 446 | // the format is: |
| 445 | // basename => array(errors) | 447 | // basename => array(errors) |
| @@ -451,7 +453,7 @@ class KTFieldsetValidator extends KTValidator { | @@ -451,7 +453,7 @@ class KTFieldsetValidator extends KTValidator { | ||
| 451 | $extra_errors = KTUtil::arrayGet($res, 'errors', array()); | 453 | $extra_errors = KTUtil::arrayGet($res, 'errors', array()); |
| 452 | foreach ($extra_errors as $varname => $aErrors) { | 454 | foreach ($extra_errors as $varname => $aErrors) { |
| 453 | if (is_string($aErrors)) { | 455 | if (is_string($aErrors)) { |
| 454 | - $errors[$varname][] = $aErrors; | 456 | + $errors[$varname][] = $aErrors; |
| 455 | } else { | 457 | } else { |
| 456 | $errors[$varname] = kt_array_merge($errors[$varname], $aErrors); | 458 | $errors[$varname] = kt_array_merge($errors[$varname], $aErrors); |
| 457 | } | 459 | } |
| @@ -461,7 +463,7 @@ class KTFieldsetValidator extends KTValidator { | @@ -461,7 +463,7 @@ class KTFieldsetValidator extends KTValidator { | ||
| 461 | if ($this->bProduceOutput) { | 463 | if ($this->bProduceOutput) { |
| 462 | $final_results[$this->sOutputVariable] = $results; | 464 | $final_results[$this->sOutputVariable] = $results; |
| 463 | } | 465 | } |
| 464 | - | 466 | + |
| 465 | $final_errors = array(); | 467 | $final_errors = array(); |
| 466 | if (!empty($errors)) { | 468 | if (!empty($errors)) { |
| 467 | $final_errors[$this->sInputVariable] = $errors; | 469 | $final_errors[$this->sInputVariable] = $errors; |
| @@ -478,7 +480,7 @@ class KTFieldsetValidator extends KTValidator { | @@ -478,7 +480,7 @@ class KTFieldsetValidator extends KTValidator { | ||
| 478 | class KTFileValidator extends KTValidator { | 480 | class KTFileValidator extends KTValidator { |
| 479 | var $sNamespace = 'ktcore.validators.file'; | 481 | var $sNamespace = 'ktcore.validators.file'; |
| 480 | // we don't actual need to do *anything* | 482 | // we don't actual need to do *anything* |
| 481 | - | 483 | + |
| 482 | function validate($data) { | 484 | function validate($data) { |
| 483 | $d = (array) KTUtil::arrayGet($data, $this->sInputVariable); | 485 | $d = (array) KTUtil::arrayGet($data, $this->sInputVariable); |
| 484 | $results = array(); | 486 | $results = array(); |
| @@ -495,26 +497,26 @@ class KTFileValidator extends KTValidator { | @@ -495,26 +497,26 @@ class KTFileValidator extends KTValidator { | ||
| 495 | class KTFileIllegalCharValidator extends KTValidator { | 497 | class KTFileIllegalCharValidator extends KTValidator { |
| 496 | var $sNamespace = 'ktcore.validators.fileillegalchar'; | 498 | var $sNamespace = 'ktcore.validators.fileillegalchar'; |
| 497 | var $sWarning; | 499 | var $sWarning; |
| 498 | - | 500 | + |
| 499 | function configure($aOptions) { | 501 | function configure($aOptions) { |
| 500 | $res = parent::configure($aOptions); | 502 | $res = parent::configure($aOptions); |
| 501 | if (PEAR::isError($res)) { | 503 | if (PEAR::isError($res)) { |
| 502 | return $res; | 504 | return $res; |
| 503 | } | 505 | } |
| 504 | - | 506 | + |
| 505 | $sChars = "\/*<>|%+':\"?"; | 507 | $sChars = "\/*<>|%+':\"?"; |
| 506 | $sWarning = sprintf(_kt('The name of the document selected is invalid. The following characters are not allowed: %s'), $sChars); | 508 | $sWarning = sprintf(_kt('The name of the document selected is invalid. The following characters are not allowed: %s'), $sChars); |
| 507 | $this->sWarning = KTUtil::arrayGet($aOptions, 'file_illegal_character_warning', $sWarning); | 509 | $this->sWarning = KTUtil::arrayGet($aOptions, 'file_illegal_character_warning', $sWarning); |
| 508 | - | ||
| 509 | - $this->bTrim = KTUtil::arrayGet($aOptions, 'trim', true, false); | 510 | + |
| 511 | + $this->bTrim = KTUtil::arrayGet($aOptions, 'trim', true, false); | ||
| 510 | } | 512 | } |
| 511 | - | 513 | + |
| 512 | function validate($data) { | 514 | function validate($data) { |
| 513 | $results = array(); | 515 | $results = array(); |
| 514 | $errors = array(); | 516 | $errors = array(); |
| 515 | - | 517 | + |
| 516 | $aFile = (array) KTUtil::arrayGet($data, $this->sInputVariable); | 518 | $aFile = (array) KTUtil::arrayGet($data, $this->sInputVariable); |
| 517 | - | 519 | + |
| 518 | // Get the file name | 520 | // Get the file name |
| 519 | $val = $aFile['name']; | 521 | $val = $aFile['name']; |
| 520 | if ($this->bTrim) { | 522 | if ($this->bTrim) { |
| @@ -530,7 +532,7 @@ class KTFileIllegalCharValidator extends KTValidator { | @@ -530,7 +532,7 @@ class KTFileIllegalCharValidator extends KTValidator { | ||
| 530 | if ($this->bProduceOutput) { | 532 | if ($this->bProduceOutput) { |
| 531 | $results[$this->sOutputVariable] = $aFile; | 533 | $results[$this->sOutputVariable] = $aFile; |
| 532 | } | 534 | } |
| 533 | - | 535 | + |
| 534 | return array( | 536 | return array( |
| 535 | 'errors' => $errors, | 537 | 'errors' => $errors, |
| 536 | 'results' => $results, | 538 | 'results' => $results, |
| @@ -541,19 +543,19 @@ class KTFileIllegalCharValidator extends KTValidator { | @@ -541,19 +543,19 @@ class KTFileIllegalCharValidator extends KTValidator { | ||
| 541 | 543 | ||
| 542 | class KTArrayValidator extends KTValidator { | 544 | class KTArrayValidator extends KTValidator { |
| 543 | var $sNamespace = 'ktcore.validators.array'; | 545 | var $sNamespace = 'ktcore.validators.array'; |
| 544 | - | 546 | + |
| 545 | function validate($data) { | 547 | function validate($data) { |
| 546 | $results = array(); | 548 | $results = array(); |
| 547 | $errors = array(); | 549 | $errors = array(); |
| 548 | - | 550 | + |
| 549 | // very simple if we're required and not present, fail | 551 | // very simple if we're required and not present, fail |
| 550 | // otherwise, its ok. | 552 | // otherwise, its ok. |
| 551 | $val = KTUtil::arrayGet($data, $this->sInputVariable); | 553 | $val = KTUtil::arrayGet($data, $this->sInputVariable); |
| 552 | - //var_dump($data); exit(0); | 554 | + //var_dump($data); exit(0); |
| 553 | if ($this->bProduceOutput) { | 555 | if ($this->bProduceOutput) { |
| 554 | $results[$this->sOutputVariable] = $val; | 556 | $results[$this->sOutputVariable] = $val; |
| 555 | } | 557 | } |
| 556 | - | 558 | + |
| 557 | return array( | 559 | return array( |
| 558 | 'errors' => $errors, | 560 | 'errors' => $errors, |
| 559 | 'results' => $results, | 561 | 'results' => $results, |
plugins/ktcore/folder/addDocument.php
| @@ -95,17 +95,20 @@ class KTFolderAddDocumentAction extends KTFolderAction { | @@ -95,17 +95,20 @@ class KTFolderAddDocumentAction extends KTFolderAction { | ||
| 95 | 95 | ||
| 96 | // Onchange gets the name of the file and inserts it as the document title. | 96 | // Onchange gets the name of the file and inserts it as the document title. |
| 97 | $sFileOnchange = "javascript: | 97 | $sFileOnchange = "javascript: |
| 98 | - var arrPath=this.value.split('/'); | ||
| 99 | - if(arrPath.length == 1){ | ||
| 100 | - var arrPath=this.value.split('\\\'); | ||
| 101 | - } | ||
| 102 | - var name=arrPath[arrPath.length-1]; | ||
| 103 | - var name=name.split('.'); | ||
| 104 | - if(name.length > 1){ | ||
| 105 | - name.pop(); | ||
| 106 | - } | ||
| 107 | - var title=name.join('.'); | ||
| 108 | - document.getElementById('document_name').value=title;"; | 98 | + var doc = document.getElementById('document_name'); |
| 99 | + if(doc.value == ''){ | ||
| 100 | + var arrPath=this.value.split('/'); | ||
| 101 | + if(arrPath.length == 1){ | ||
| 102 | + var arrPath=this.value.split('\\\'); | ||
| 103 | + } | ||
| 104 | + var name=arrPath[arrPath.length-1]; | ||
| 105 | + var name=name.split('.'); | ||
| 106 | + if(name.length > 1){ | ||
| 107 | + name.pop(); | ||
| 108 | + } | ||
| 109 | + var title=name.join('.'); | ||
| 110 | + doc.value=title; | ||
| 111 | + }"; | ||
| 109 | 112 | ||
| 110 | $oForm->setWidgets(array( | 113 | $oForm->setWidgets(array( |
| 111 | array('ktcore.widgets.file',array( | 114 | array('ktcore.widgets.file',array( |