tbrehm
2012-02-22 dec0dfa3a81e23a5a123be56ae8b36e0f1ed9137
interface/lib/classes/listform.inc.php
@@ -51,12 +51,14 @@
        $this->module = $module;
      
      //* Fill datasources
      foreach($this->listDef['item'] as $key => $field) {
         if(@is_array($field['datasource'])) {
                $this->listDef['item'][$key]['value'] = $this->getDatasourceData($field);
            }
        if(@is_array($this->listDef['item'])) {
          foreach($this->listDef['item'] as $key => $field) {
             if(@is_array($field['datasource'])) {
                    $this->listDef['item'][$key]['value'] = $this->getDatasourceData($field);
                }
          }
      }
      //* Set local Language File
      $lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_'.$this->listDef['name'].'_list.lng';
      if(!file_exists($lng_file)) $lng_file = 'lib/lang/en_'.$this->listDef['name'].'_list.lng';
@@ -136,51 +138,53 @@
      }
        //* store retrieval query
        foreach($this->listDef['item'] as $i) {
            $field = $i['field'];
        if(@is_array($this->listDef['item'])) {
            foreach($this->listDef['item'] as $i) {
                $field = $i['field'];
            //* The search string has been changed
            if(isset($_REQUEST[$search_prefix.$field]) && isset($_SESSION['search'][$list_name][$search_prefix.$field]) && $_REQUEST[$search_prefix.$field] != $_SESSION['search'][$list_name][$search_prefix.$field]){
                    $this->searchChanged = 1;
               //* Jump back to page 1 of the list when search has changed.
               $_SESSION['search'][$list_name]['page'] = 0;
            }
                //* The search string has been changed
                if(isset($_REQUEST[$search_prefix.$field]) && isset($_SESSION['search'][$list_name][$search_prefix.$field]) && $_REQUEST[$search_prefix.$field] != $_SESSION['search'][$list_name][$search_prefix.$field]){
                        $this->searchChanged = 1;
                   //* Jump back to page 1 of the list when search has changed.
                   $_SESSION['search'][$list_name]['page'] = 0;
                }
            //* Store field in session
            if(isset($_REQUEST[$search_prefix.$field])){
                $_SESSION['search'][$list_name][$search_prefix.$field] = $_REQUEST[$search_prefix.$field];
            }
                //* Store field in session
                if(isset($_REQUEST[$search_prefix.$field])){
                    $_SESSION['search'][$list_name][$search_prefix.$field] = $_REQUEST[$search_prefix.$field];
                }
            if(isset($i['formtype']) && $i['formtype'] == 'SELECT'){
                if(is_array($i['value'])) {
                    $out = '<option value=""></option>';
                    foreach($i['value'] as $k => $v) {
                        // TODO: this could be more elegant
                        $selected = (isset($_SESSION['search'][$list_name][$search_prefix.$field])
                                        && $k == $_SESSION['search'][$list_name][$search_prefix.$field]
                                        && $_SESSION['search'][$list_name][$search_prefix.$field] != '')
                                        ? ' SELECTED' : '';
                        $out .= "<option value='$k'$selected>$v</option>\r\n";
                if(isset($i['formtype']) && $i['formtype'] == 'SELECT'){
                    if(is_array($i['value'])) {
                        $out = '<option value=""></option>';
                        foreach($i['value'] as $k => $v) {
                            // TODO: this could be more elegant
                            $selected = (isset($_SESSION['search'][$list_name][$search_prefix.$field])
                                            && $k == $_SESSION['search'][$list_name][$search_prefix.$field]
                                            && $_SESSION['search'][$list_name][$search_prefix.$field] != '')
                                            ? ' SELECTED' : '';
                            $out .= "<option value='$k'$selected>$v</option>\r\n";
                        }
                    }
                        $this->searchValues[$search_prefix.$field] = $out;
                } else {
                    if(isset($_SESSION['search'][$list_name][$search_prefix.$field])){
                        $this->searchValues[$search_prefix.$field] = htmlspecialchars($_SESSION['search'][$list_name][$search_prefix.$field]);
                    }
                }
                    $this->searchValues[$search_prefix.$field] = $out;
            } else {
                if(isset($_SESSION['search'][$list_name][$search_prefix.$field])){
                    $this->searchValues[$search_prefix.$field] = htmlspecialchars($_SESSION['search'][$list_name][$search_prefix.$field]);
            }
        }
        //* Store variables in object | $this->searchValues = $_SESSION["search"][$list_name];
        if(@is_array($this->listDef['item'])) {
            foreach($this->listDef['item'] as $i) {
                $field = $i['field'];
                // if($_REQUEST[$search_prefix.$field] != '') $sql_where .= " $field ".$i["op"]." '".$i["prefix"].$_REQUEST[$search_prefix.$field].$i["suffix"]."' and";
              if(isset($_SESSION['search'][$list_name][$search_prefix.$field]) && $_SESSION['search'][$list_name][$search_prefix.$field] != ''){
                    $sql_where .= " $field ".$i['op']." '".$i['prefix'].$_SESSION['search'][$list_name][$search_prefix.$field].$i['suffix']."' and";
                }
            }
        }
        //* Store variables in object | $this->searchValues = $_SESSION["search"][$list_name];
        foreach($this->listDef['item'] as $i) {
            $field = $i['field'];
            // if($_REQUEST[$search_prefix.$field] != '') $sql_where .= " $field ".$i["op"]." '".$i["prefix"].$_REQUEST[$search_prefix.$field].$i["suffix"]."' and";
          if(isset($_SESSION['search'][$list_name][$search_prefix.$field]) && $_SESSION['search'][$list_name][$search_prefix.$field] != ''){
                $sql_where .= " $field ".$i['op']." '".$i['prefix'].$_SESSION['search'][$list_name][$search_prefix.$field].$i['suffix']."' and";
            }
        }
        return ( $sql_where != '' ) ? $sql_where = substr($sql_where,0,-3) : '1';
    }
@@ -277,8 +281,8 @@
    public function decode($record) 
    {
        global $conf;
        if(is_array($record)) {
        global $conf, $app;
        if(is_array($record) && count($record) > 0 && is_array($this->listDef['item'])) {
            foreach($this->listDef['item'] as $field){
                $key = $field['field'];
            if(isset($record[$key])) {
@@ -291,7 +295,7 @@
                    case 'DATETSTAMP':
                        if ($record[$key] > 0) {
                     // is value int?
                     if (ereg("^[0-9]+[.]?[0-9]*$", $record[$key], $p)) {
                     if (preg_match("/^[0-9]+[\.]?[0-9]*$/", $record[$key], $p)) {
                              $record[$key] = date($this->lng('conf_format_dateshort'), $record[$key]);
                     } else {
                              $record[$key] = date($this->lng('conf_format_dateshort'), strtotime($record[$key]));
@@ -301,7 +305,7 @@
               case 'DATE':
                        if ($record[$key] > 0) {
                     // is value int?
                     if (ereg("^[0-9]+[.]?[0-9]*$", $record[$key], $p)) {
                     if (preg_match("/^[0-9]+[\.]?[0-9]*$/", $record[$key], $p)) {
                              $record[$key] = date($this->lng('conf_format_dateshort'), $record[$key]);
                     } else {
                              $record[$key] = date($this->lng('conf_format_dateshort'), strtotime($record[$key]));
@@ -312,7 +316,7 @@
                    case 'DATETIME':
                        if ($record[$key] > 0) {
                     // is value int?
                     if (ereg("^[0-9]+[.]?[0-9]*$", $record[$key], $p)) {
                     if (preg_match("/^[0-9]+[\.]?[0-9]*$/", $record[$key], $p)) {
                              $record[$key] = date($this->lng('conf_format_datetime'), $record[$key]);
                     } else {
                              $record[$key] = date($this->lng('conf_format_datetime'), strtotime($record[$key]));
@@ -329,7 +333,7 @@
                        break;
                    case 'CURRENCY':
                        $record[$key] = number_format($record[$key], 2, ',', '');
                        $record[$key] = $app->functions->currency_format($record[$key]);
                        break;
                    default:
@@ -343,6 +347,7 @@
    public function encode($record)
    {
   global $app;
        if(is_array($record)) {
            foreach($this->listDef['item'] as $field){
                $key = $field['field'];
@@ -351,7 +356,7 @@
                    case 'VARCHAR':
                    case 'TEXT':
                        if(!is_array($record[$key])) {
                            $record[$key] = mysql_real_escape_string($record[$key]);
                            $record[$key] = $app->db->quote($record[$key]);
                        } else {
                            $record[$key] = implode($this->tableDef[$key]['separator'],$record[$key]);
                        }
@@ -380,7 +385,7 @@
                        break;
                    case 'DOUBLE':
                        $record[$key] = mysql_real_escape_string($record[$key]);
                        $record[$key] = $app->db->quote($record[$key]);
                        break;
                    case 'CURRENCY':
@@ -418,4 +423,4 @@
}
?>
?>