Commit 9354090c4cd47dd3d1398de3df07491fc8a33da6

Authored by Brad Shuttleworth
1 parent 98ead185

actually sanely handle request input in a non-broken way.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5305 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 26 additions and 16 deletions
lib/browse/Criteria.inc
... ... @@ -165,17 +165,27 @@ class BrowseCriterion {
165 165 if ($aPreValue != null) {
166 166 // !#@&)*( (*&!@# *(&@NOT (*&!@#
167 167 $k = array_keys($aPreValue);
168   - $k = $k[0];
  168 + $k = $this->getWidgetBase();
169 169 $preval = $aPreValue[$k];
170   - return $this->getNotWidget() . "<input type=\"text\" size=\"50\" name=\"" . $this->getWidgetBase() . "\" value=\"" . $preval . "\"/>";
  170 + return $this->getNotWidget($aPreValue) . "<input type=\"text\" size=\"50\" name=\"" . $this->getWidgetBase() . "\" value=\"" . $preval . "\"/>";
171 171 } else {
172   - return $this->getNotWidget() . "<input type=\"text\" size=\"50\" name=\"" . $this->getWidgetBase() . "\" />";
  172 + return $this->getNotWidget($aPreValue) . "<input type=\"text\" size=\"50\" name=\"" . $this->getWidgetBase() . "\" />";
173 173 }
174 174 }
175 175  
176   - function getNotWidget() {
  176 + function getNotWidget($aPreValue=null) {
  177 + if (is_null($aPreValue)) {
  178 + $is_positive = true;
  179 + }
177 180 // not perfect, but acceptable.
178 181 $form_name = $this->getWidgetBase() . '_not';
  182 + $pos_select = '';
  183 + $neg_select = '';
  184 + if ($is_positive) {
  185 + $pos_select = ' selected="true"';
  186 + } else {
  187 + $neg_select = ' selected="true"';
  188 + }
179 189 if (!$this->bContains) {
180 190 $not_string = _kt('is not');
181 191 $is_string = _kt('is');
... ... @@ -183,7 +193,7 @@ class BrowseCriterion {
183 193 $not_string = _kt('does not contain');
184 194 $is_string = _kt('contains');
185 195 }
186   - $widget = sprintf('<select name="%s"><option value="0">%s</option><option value="1">%s</option></select>&nbsp;', $form_name, $is_string, $not_string);
  196 + $widget = sprintf('<select name="%s"><option value="0"%s>%s</option><option value="1"%s>%s</option></select>&nbsp;', $form_name, $pos_select, $is_string, $neg_select, $not_string);
187 197 return $widget;
188 198 }
189 199  
... ... @@ -308,10 +318,10 @@ class CreatorCriterion extends BrowseCriterion {
308 318 if ($aPreValue != null) {
309 319 // !#@&)*( (*&!@# *(&@NOT (*&!@#
310 320 $k = array_keys($aPreValue);
311   - $k = $k[0];
  321 + $k = $this->getWidgetBase();
312 322 $preval = $aPreValue[$k];
313 323 }
314   - $sRet = $this->getNotWidget() . "<select size=\"1\" name=\"" . $this->getWidgetBase() . "\">\n";
  324 + $sRet = $this->getNotWidget($aPreValue) . "<select size=\"1\" name=\"" . $this->getWidgetBase() . "\">\n";
315 325 $aUsers = User::getList();/*ok*/
316 326 $sRet .= "<option value=\"-1\">None</option>\n";
317 327 foreach ($aUsers as $oUser) {
... ... @@ -345,9 +355,9 @@ class DateCreatedCriterion extends BrowseCriterion {
345 355 $sToRender .= " &nbsp; Before date: <input type=\"text\" size=\"10\" name=\"" . $sEndWidget . "\" />";
346 356 $sToRender .= "&nbsp;&nbsp;<a href=\"javascript:show_calendar('MainForm." . $sEndWidget . "',null,null,'YYYY-MM-DD', false);\" onmouseover=\"window.status='Date Picker';return true;\" onmouseout=\"window.status='';return true;\"><img src=\"$default->graphicsUrl/calendar/calendar.gif\" name=\"imgCalendar\" width=\"34\" height=\"21\" border=\"0\" alt=\"\"></a>";
347 357 */
348   - $sToRender = $this->getNotWidget();
349   - $sToRender .= 'After Date: <span class="kt_calendar_holder"><strong class="kt_calendar_datetext">' . $aPreValue[$sStartWidget] . '</strong><input type="hidden" name="' . $sStartWidget . '" class="kt_calendar_value" value="' . $aPreValue[$sStartWidget] . '"/> <input type="button" onclick="init_kt_calendar(this);" value="select"></span> and ';
350   - $sToRender .= 'Before Date: <span class="kt_calendar_holder"><strong class="kt_calendar_datetext">' . $aPreValue[$sStartWidget] . '</strong><input type="hidden" name="' . $sEndWidget . '" class="kt_calendar_value" value="' . $aPreValue[$sEndWidget] . '"/> <input type="button" onclick="init_kt_calendar(this);" value="select"></span><br />';
  358 + $sToRender = $this->getNotWidget($aPreValue);
  359 + $sToRender .= 'after: <span class="kt_calendar_holder"><strong class="kt_calendar_datetext">' . $aPreValue[$sStartWidget] . '</strong><input type="hidden" name="' . $sStartWidget . '" class="kt_calendar_value" value="' . $aPreValue[$sStartWidget] . '"/> <input type="button" onclick="init_kt_calendar(this);" value="select"></span> and ';
  360 + $sToRender .= 'before: <span class="kt_calendar_holder"><strong class="kt_calendar_datetext">' . $aPreValue[$sStartWidget] . '</strong><input type="hidden" name="' . $sEndWidget . '" class="kt_calendar_value" value="' . $aPreValue[$sEndWidget] . '"/> <input type="button" onclick="init_kt_calendar(this);" value="select"></span><br />';
351 361 return $sToRender;
352 362 }
353 363 function searchSQL ($aRequest) {
... ... @@ -412,10 +422,10 @@ class DocumentTypeCriterion extends BrowseCriterion {
412 422 if ($aPreValue != null) {
413 423 // !#@&)*( (*&!@# *(&@NOT (*&!@#
414 424 $k = array_keys($aPreValue);
415   - $k = $k[0];
  425 + $k = $this->getWidgetBase();
416 426 $preval = $aPreValue[$k];
417 427 }
418   - $sRet = $this->getNotWidget();
  428 + $sRet = $this->getNotWidget($aPreValue);
419 429 $sRet .= "<select size=\"1\" name=\"" . $this->getWidgetBase() . "\">\n";
420 430 $aUsers = DocumentType::getList();/*ok*/
421 431 $sRet .= "<option value=\"-1\">None</option>\n";
... ... @@ -476,7 +486,7 @@ class GenericMetadataCriterion extends BrowseCriterion {
476 486 if ($aPreValue != null) {
477 487 // !#@&)*( (*&!@# *(&@NOT (*&!@#
478 488 $k = array_keys($aPreValue);
479   - $k = $k[0];
  489 + $k = $this->getWidgetBase();
480 490 $preval = $aPreValue[$k];
481 491 }
482 492 // If there's no lookup, just use the standard text input
... ... @@ -485,7 +495,7 @@ class GenericMetadataCriterion extends BrowseCriterion {
485 495 return parent::searchWidget($aRequest, $aPreValue);
486 496 }
487 497 $this->bContains = false; // is
488   - $sRet = $this->getNotWidget();
  498 + $sRet = $this->getNotWidget($aPreValue);
489 499 $sRet .= "<select size=\"1\" name=\"" . $this->getWidgetBase() . "\">\n";
490 500 $aSearch = array('document_field_id = ?', $this->getID());
491 501 $aMetaData = MetaData::getByDocumentField(DocumentField::get($this->getID()));/*ok*/
... ... @@ -635,10 +645,10 @@ class WorkflowStateCriterion extends BrowseCriterion {
635 645 if ($aPreValue != null) {
636 646 // !#@&)*( (*&!@# *(&@NOT (*&!@#
637 647 $k = array_keys($aPreValue);
638   - $k = $k[0];
  648 + $k = $this->getWidgetBase();
639 649 $preval = $aPreValue[$k];
640 650 }
641   - $sRet = $this->getNotWidget();
  651 + $sRet = $this->getNotWidget($aPreValue);
642 652 $sRet .= "<select size=\"1\" name=\"" . $this->getWidgetBase() . "\">\n";
643 653 $aStates = KTWorkflowState::getList("ORDER BY workflow_id");
644 654 $sRet .= "<option value=\"-1\">None</option>\n";
... ...