Esempio n. 1
0
 /**
  * Process the user response from $_GET, $_POST or $_SESSION.
  * @return void
  */
 function processResponse()
 {
     global $PHP_SELF;
     global $_SESSION;
     global $validator_clearance;
     global $system_settings;
     $this->list_query = '';
     // declare list query
     $this->ste_query = '';
     // declare main query
     $this->menu = new ExtendedMenu($this->itemValidator, $this->page);
     if (isset($this->rawNames)) {
         $this->menu->setRawNames($this->rawNames);
     }
     $this->menu->setFieldPrefix('veld');
     $this->menu->setItemDefQuery("select column_name,data_type,item_length," . "edit_type,query,capability,precision,placeholder,regex_name\n" . "from menu_item_defs where menu_name='{$this->menuName}'");
     $this->menu->setDBConn($this->dbConn);
     /*  let the menu learn about its content */
     $this->menu->setMenuName($this->menuName);
     $this->menu->setSubRel($this->subRel);
     $this->menu->setSubRelJoinColumns($this->subRelJoinColumns);
     /* now menu knows its columns, process the inputs */
     if (!empty($_SESSION['list_query']) && $PHP_SELF == $_SESSION['ste_referer']) {
         $this->list_query = $_SESSION['list_query'];
     }
     /* pick up potential key values from $_GET */
     $this->keyValues = $this->getKeyValues($_GET);
     //    $this->dbConn->log('keyValues={'.bvar_dump($this->keyValues).'}<br/>');
     /* pick up the _POST inputs such as the submit values */
     //    echo '<br><span style="color:red;"> _POST=',bvar_dump($_POST).'</span><br>';
     if (count($_POST) > 0) {
         if (isset($_POST['Clear'])) {
             /*
              * L E E G
              */
             /* throw away any old search result, i.e. the query */
             /* by kicking it out of the $_GET array */
             //	  echo '<span style="color:red;">Meuk it<br><br></span>';
             $_GET = array();
             $_POST = array();
             $this->list_query = '';
             $this->keyValues = array();
             /* meuk */
             unset($_SESSION['list_query']);
             unset($_SESSION['ste_query']);
             $this->list_query = '';
             $this->ste_query = '';
             /* THATS all folks, empty results etc */
             return;
         }
         /* load only  if request is not LEEG */
         $this->setMenuValues($_POST);
         if ($validator_clearance) {
             // save edit values to session.
             if (isset($system_settings['edit_to_session'])) {
                 $save = explode(',', $system_settings['edit_to_session']);
                 foreach ($save as $s) {
                     list($k, $d) = split('=', $s);
                     $v = $d;
                     if (isset($_POST[$k]) && $_POST[$k] !== '') {
                         $v = $_POST[$k];
                     }
                     $_SESSION[$k] = $v;
                 }
             }
             if (isset($_POST['Search'])) {
                 /*
                  * S E A R C H
                  */
                 /** build a query from the $_POST data */
                 $sq = new SearchQuery($this->dbConn, $this->relation);
                 $sq->setKeyColumns($this->keyColumns);
                 $sq->setNameExpression($this->nameExpression);
                 if (isset($this->listRowTemplate)) {
                     $sq->setAuxColNames($this->listRowTemplate);
                 }
                 $sq->setQueryExtension($this->listQueryExtension);
                 $sq->setOrderList($this->orderList);
                 $sq->setSubmitValueSet($_POST);
                 $this->list_query = $sq->setSubRel($this->subRel)->setSubRelJoinColumns($this->subRelJoinColumns)->getExtendedQuery();
                 // test if must show searchquery through log
                 //$this->dbMessage .="\n<br/>list_query=[" . $this->list_query . "]=list_query\n";
                 $this->addLogQuery($sq->getLog());
                 $this->ste_query = $sq->getAllQuery();
                 $this->spreadSheetWriter->setQuery($this->ste_query);
                 if ($this->showQuery) {
                     $this->dbConn->log("<br/>\nste query=" . $this->ste_query . "<br/>");
                 }
                 //$this->dbMessage .= "\nste query=".$this->ste_query;
                 $rs = $this->dbConnExecute($this->ste_query);
                 if ($rs !== false && !$rs->EOF) {
                     /* if search succeeded, load the first hit */
                     $this->setMenuValues($rs->fields);
                     $this->keyValues = $this->getKeyValues($rs->fields);
                 } else {
                     /* reload screen from _POST data */
                     $this->setMenuValues($_POST);
                     $this->dbMessage .= "\nNothing found";
                 }
             } else {
                 if ($this->allowIUD && isset($_POST['Insert'])) {
                     /*
                      * I N S E R T
                      */
                     $this->doInsert();
                 } else {
                     if ($this->allowIUD && isset($_POST['Update'])) {
                         $this->doUpdate();
                     } else {
                         if ($this->allowIUD && isset($_POST['Delete'])) {
                             /*
                              * D E L E T E
                              */
                             $this->doDelete();
                         } else {
                             if (isset($_POST['Reset'])) {
                                 /*
                                  * reset is handled by the browser
                                  */
                             }
                         }
                     }
                 }
             }
         } else {
             // redisplay input
             $this->setMenuValues($_POST);
         }
     }
     /*
      * use _GET to determine the key columns
      */
     $sq = new SearchQuery($this->dbConn, $this->relation);
     $sq->setKeyColumns($this->keyColumns);
     $sq->setNameExpression($this->nameExpression);
     $sq->setOrderList($this->orderList)->setSubRel($this->subRel)->setSubRelJoinColumns($this->subRelJoinColumns);
     $sq->setSubmitValueSet($_GET);
     $this->dbMessage .= $sq->getQuery();
     if ($sq->areKeyColumnsSet()) {
         $sql = $sq->getAllQuery();
         $arr = array();
         $rs = $this->dbConnExecute($sql);
         if ($this->showQuery) {
             $this->dbConn->log('query ' . $sql);
         }
         $this->addLogQuery("<pre>all=[{$sql}]=all</pre><br/>");
         if ($rs !== false && !$rs->EOF) {
             $this->setMenuValues($rs->fields);
             $this->dbConn->log("<pre>" . print_r($rs->fields, true) . "</pre><br>");
             $this->keyValues = $this->getKeyValues($rs->fields);
         } else {
             $this->dbMessage .= "\n Found nothing " . $this->dbConn->ErrorMsg() . ' ' . $sql;
         }
     }
     /* end of else branch if (count($_POST)) */
 }