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