[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/etemplate/inc/ -> class.advancedsearch_widget.inc.php (source)

   1  <?php
   2      /**************************************************************************\
   3      * eGroupWare - eTemplate Extension - Advanced search                       *
   4      * http://www.egroupware.org                                                *
   5      * Written by Cornelius Weiss <egw@von-und-zu-weiss.de>                     *
   6      * --------------------------------------------                             *
   7      *  This program is free software; you can redistribute it and/or modify it *
   8      *  under the terms of the GNU General Public License as published by the   *
   9      *  Free Software Foundation; either version 2 of the License, or (at your  *
  10      *  option) any later version.                                              *
  11      \**************************************************************************/
  12  
  13      /* $Id: class.advancedsearch_widget.inc.php 22505 2006-09-26 13:11:56Z nelius_weiss $ */
  14      
  15      /**
  16      * eTemplate Extension: Advanced Search
  17      *
  18      * $content[$name] = array(
  19      *    'input_template'    => app.template
  20      *    'search_method'        => app.class.method in so_sql style
  21      *    'colums_to_present'    => array with field_name => label
  22      *    'actions'        => array with actions for resultset in etemplates style
  23      *                   can also contain a field 'method' which gets executed with resultset as first param
  24      *    'row_actions'        => array with actions for each row
  25      *
  26      * @package etemplate
  27      * @subpackage extensions
  28      * @author Cornelius Weiss <egw@von-und-zu-weiss.de>
  29      * @license GPL - GNU General Public License
  30      */
  31      class advancedsearch_widget
  32      {
  33          /** 
  34           * @var $public_functions array with exported methods of this class
  35           */
  36          var $public_functions = array(
  37              'pre_process' => True,
  38              'post_process' => True
  39          );
  40          
  41          /**
  42           * @var $human_name
  43           */
  44          var $human_name = 'Advanced search';
  45          
  46          /**
  47          * @var $debug bool
  48          */
  49          var $debug = False;
  50  
  51          /**
  52           * Constructor of the extension
  53           *
  54           * @param string $ui '' for html
  55           */
  56  		function advancedsearch_widget($ui='')
  57          {
  58          }
  59  
  60          /**
  61           * pre-processing of the extension
  62           *
  63           * This function is called before the extension gets rendered
  64           *
  65           * @param string $name form-name of the control
  66           * @param mixed &$value value / existing content, can be modified
  67           * @param array &$cell array with the widget, can be modified for ui-independent widgets 
  68           * @param array &$readonlys names of widgets as key, to be made readonly
  69           * @param mixed &$extension_data data the extension can store persisten between pre- and post-process
  70           * @param object &$tmpl reference to the template we belong too
  71           * @return boolean true if extra label is allowed, false otherwise
  72           */
  73  		function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
  74          {
  75              $extension_data = is_array($extension_data) ? $extension_data :
  76                  (is_array($GLOBALS['egw']->session->appsession('advanced_search_query',$GLOBALS['egw_info']['flags']['currentapp'])) ? 
  77                  $GLOBALS['egw']->session->appsession('advanced_search_query',$GLOBALS['egw_info']['flags']['currentapp']) : $value);
  78              
  79              $tpl =& new etemplate;
  80              $tpl->init('*** generated advanced search widget','','',0,'',0,0);    // make an empty template
  81  
  82              if($extension_data['message'])
  83              {
  84                  $tpl->add_child($tpl,$message = $tpl->empty_cell('label','message',array(
  85                      'no_lang' => true,
  86                  )));
  87              }
  88              
  89              if (isset($extension_data['result_nm']))
  90              {
  91                  $tpl->add_child($tpl,$new_search_button = $tpl->empty_cell('button','button[new_search]',array(
  92                      'no_lang' => true,
  93                      'label' => lang('New search'),
  94                  )));
  95                  $tpl->add_child($tpl, $result_nm = $tpl->empty_cell('nextmatch','result_nm',array(
  96  //                     'width' => '800px',
  97                  )));
  98  
  99                  $result_rows_tpl =& new etemplate;
 100                  $result_rows_tpl->init('*** generated rows template for advanced search results','','',0,'',0,0);
 101                  $grid =& $result_rows_tpl->children[0];
 102                  foreach((array)$extension_data['colums_to_present'] as $field => $label)
 103                  {
 104                      if($label == '') continue;
 105                      $result_rows_tpl->add_child($grid,$result_nm_header = $result_rows_tpl->empty_cell('nextmatch-sortheader',$field,array(
 106                          'label' => $label,
 107                          'no_lang' => true,
 108                          'span' => ',nmh',
 109                      )));
 110                      unset($result_nm_header);
 111                  }
 112                  if(!empty($extension_data['row_actions']))
 113                  {
 114                      $result_rows_tpl->add_child($grid,$result_nm_header = $result_rows_tpl->empty_cell('label','action',array(
 115                          'label' => 'Action',
 116                          'no_lang' => true,
 117                          'span' => ',nmh',
 118                      )));
 119                      unset($result_nm_header);
 120                  }
 121                  $result_rows_tpl->add_child($grid,$rows);
 122                  foreach((array)$extension_data['colums_to_present'] as $field => $label)
 123                  {
 124                      if($label == '') continue;
 125                      $result_rows_tpl->add_child($grid,$result_nm_rows = $result_rows_tpl->empty_cell('text','$row}['.$field.']',array(
 126                          'no_lang' => true,
 127                          'readonly' => true,
 128                      )));
 129                      unset($result_nm_rows);
 130                  }
 131                  if(!empty($extension_data['row_actions']))
 132                  {
 133                      $row_actions =& $result_rows_tpl->empty_cell('hbox','row_action');
 134                      $result_rows_tpl->add_child($grid,$row_actions);
 135                      foreach($extension_data['row_actions'] as $action => $options)
 136                      {
 137                          $result_rows_tpl->add_child($row_actions, $row_action = $result_rows_tpl->empty_cell($options['type'],$action.'[$row_cont[id]]',$options['options']));
 138                          unset($row_action);
 139                      }
 140                  }
 141                  $value['result_nm'] = array_merge(
 142                      $extension_data['result_nm'],
 143                      array(
 144                          'no_filter' => true,
 145                          'no_filter2' => true,
 146                          'no_cat' => true,
 147                          'no_search' => true,
 148                          'get_rows' => 'etemplate.advancedsearch_widget.get_rows',
 149                          'search_method' => $extension_data['search_method'],
 150                          'colums_to_present' => $extension_data['colums_to_present'],
 151                          'template' => $result_rows_tpl,
 152                  ));
 153                  
 154                  $action_buttons =& $tpl->empty_cell('hbox','action_buttons');
 155                  $tpl->add_child($tpl, $action_buttons);
 156                  foreach ($extension_data['actions'] as $action => $options)
 157                  {
 158                      $tpl->add_child($action_buttons, $result_button = $tpl->empty_cell($options['type'],'action['.$action.']',$options['options']));
 159                      unset($result_button);
 160                  }    
 161              }
 162              else
 163              {
 164                  $GLOBALS['egw_info']['etemplate']['advanced_search'] = true;
 165  
 166                  $tpl->add_child($tpl, $search_template = $tpl->empty_cell('template',$extension_data['input_template']));
 167                  $button_box = $tpl->empty_cell('hbox','button_box');
 168                  $tpl->add_child($tpl, $button_box);
 169                  $tpl->add_child($button_box, $op_select = $tpl->empty_cell('select','opt_select',array(
 170                      'sel_options' => array(
 171                          'OR' => 'OR',
 172                          'AND' => 'AND'
 173                      ),
 174                      'label' => 'Operator',
 175                      'no_lang' => true,
 176                  )));
 177                  $tpl->add_child($button_box, $meth_select = $tpl->empty_cell('select','meth_select',array(
 178                      'sel_options' => array(
 179                          '%' => lang('contains'),
 180                          false => lang('exact'),
 181                      ),
 182                      'no_lang' => true,
 183                      'default' => '%',
 184                  )));
 185                  $tpl->add_child($button_box, $search_button = $tpl->empty_cell('button','button[search]',array(
 186                      'label' => 'Search',
 187                  )));
 188              }
 189  
 190              $cell['size'] = $cell['name'];
 191              $cell['type'] = 'template';
 192              $cell['name'] = $tpl->name;
 193              $cell['obj'] =& $tpl;
 194                  
 195              // keep the editor away from the generated tmpls
 196              $tpl->no_onclick = true;
 197  //_debug_array($tpl);
 198              return True;
 199          }
 200          
 201          /**
 202           * postprocessing method, called after the submission of the form
 203           *
 204           * It has to copy the allowed/valid data from $value_in to $value, otherwise the widget
 205           * will return no data (if it has a preprocessing method). The framework insures that
 206           * the post-processing of all contained widget has been done before.
 207           *
 208           * @param string $name form-name of the widget
 209           * @param mixed &$value the extension returns here it's input, if there's any
 210           * @param mixed &$extension_data persistent storage between calls or pre- and post-process
 211           * @param boolean &$loop can be set to true to request a re-submision of the form/dialog
 212           * @param object &$tmpl the eTemplate the widget belongs too
 213           * @param mixed &value_in the posted values (already striped of magic-quotes)
 214           * @return boolean true if $value has valid content, on false no content will be returned!
 215           */
 216  		function post_process($name,&$value,&$extension_data,&$loop,&$tmpl,$value_in)
 217          {
 218              //echo 'advancedsearch_widget::post_process->value'; _debug_array($value);
 219              //echo 'advancedsearch_widget::post_process->extension_data'; _debug_array($extension_data);
 220              if(!isset($extension_data['result_nm']['search_values']))
 221              {
 222                  foreach($value as $haystack => $needle)
 223                  {
 224                      if($needle == '') unset($value[$haystack]);
 225                      elseif($haystack{0} != '!' && $needle{0} != '!' && $value['!'.$haystack] == 1 ) $value[$haystack] = '!'.$value[$haystack];
 226                  }
 227                  $extension_data['result_nm']['search_values'] = $value;
 228              }
 229              else
 230              {
 231                  $extension_data['result_nm'] = array_merge($extension_data['result_nm'],$value['result_nm']);
 232              }
 233              
 234              //we store extension_data in session to save it over a new request
 235              $GLOBALS['egw']->session->appsession('advanced_search_query',$GLOBALS['egw_info']['flags']['currentapp'],$extension_data);
 236              
 237              if(isset($value['action']))
 238              {
 239                  // Also inputfileds etc. could be in actions
 240                  foreach($value['action'] as $action => $label)
 241                  {
 242                      if($extension_data['actions'][$action]['type'] == 'button')
 243                      {
 244                          $result = $GLOBALS['egw']->session->appsession('advanced_search_result',$GLOBALS['egw_info']['flags']['currentapp']);
 245                          $extension_data['message'] = ExecMethod2($extension_data['actions'][$action]['method'],$result);
 246                      }
 247                  }
 248              }
 249              if(is_array($value['result_nm']['rows']))
 250              {
 251                  // Also inputfileds etc. could be in actions
 252                  foreach($value['result_nm']['rows'] as $action => $id)
 253                  {
 254                      if($extension_data['row_actions'][$action]['type'] == 'button')
 255                      {
 256                          $result = $GLOBALS['egw']->session->appsession('advanced_search_result',$GLOBALS['egw_info']['flags']['currentapp']);
 257                          $extension_data['message'] = ExecMethod2($extension_data['row_actions'][$action]['method'],key($id));
 258                      }
 259                  }
 260              }
 261              
 262              if(isset($value['button']['new_search']))
 263              {
 264                  $GLOBALS['egw']->session->appsession('advanced_search_query',$GLOBALS['egw_info']['flags']['currentapp'],false);
 265                  $extension_data = '';
 266              }
 267          }
 268          
 269  		function get_rows($query,&$rows,&$readonlys)
 270          {
 271              $order_by = $query['order'] ? $query['order'].' '.$query['sort'] : '';
 272              $only_keys = implode(',',array_flip($query['colums_to_present']));
 273              $rows = ExecMethod2($query['search_method'],$query['search_values'],$only_keys,
 274                  $order_by,'',$query['search_values']['meth_select'],'',$query['search_values']['opt_select'],$query['start']);
 275              $result = ExecMethod2($query['search_method'],$query['search_values'],$only_keys,
 276                  '','',$query['search_values']['meth_select'],'',$query['search_values']['opt_select'],false,'','',false);
 277              // We store the result in session so actions can fetch them here:
 278              $GLOBALS['egw']->session->appsession('advanced_search_result',$GLOBALS['egw_info']['flags']['currentapp'],$result);
 279              return count($result);
 280  
 281          }
 282      }


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7