[ 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.uietemplate_gtk.inc.php (source)

   1  <?php
   2      /**************************************************************************\
   3      * eGroupWare - EditableTemplates - GTK User Interface                      *
   4      * http://www.egroupware.org                                                *
   5      * Written by Ralf Becker <RalfBecker@outdoor-training.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.uietemplate_gtk.inc.php 19711 2005-11-09 20:50:45Z ralfbecker $ */
  14  
  15      include_once (EGW_INCLUDE_ROOT . '/etemplate/inc/class.boetemplate.inc.php');
  16  
  17      /**
  18       * @author ralfbecker
  19       * creates dialogs / HTML-forms from eTemplate descriptions
  20       *
  21       * etemplate or uietemplate extends boetemplate, all vars and public functions are inherited
  22       * $tmpl =& CreateObject('etemplate.etemplate','app.template.name');
  23       * $tmpl->exec('app.class.callback',$content_to_show);
  24       * This creates a form from the eTemplate 'app.template.name' and takes care that
  25       * the method / public function 'callback' in (bo)class 'class' of 'app' gets called
  26       * if the user submitts the form. Vor the complete param's see the description of exec.
  27       * @param $debug enables debug messages: 0=no, 1=calls to show and process_show, 2=content of process_show
  28       * @param                                3=calls to show_cell OR template- or cell-type name
  29       */
  30      class etemplate extends boetemplate
  31      {
  32          var $debug;//='etemplate.editor.edit'; // 1=calls to show and process_show, 2=content after process_show,
  33                          // 3=calls to show_cell and process_show_cell, or template-name or cell-type
  34  
  35          var $no_result = array(    // field-types which generate no direct result
  36              'label' => True,
  37              'hrule' => True,
  38              'image' => True,
  39              'raw' => True,
  40              'template' => True
  41          );
  42          var $font_width=8;
  43  
  44          /**
  45           * constructor of etemplate class, reads an eTemplate if $name is given
  46           *
  47           * @param as soetemplate.read
  48           */
  49  		function etemplate($name='',$template='default',$lang='default',$group=0,$version='',$rows=2,$cols=2)
  50          {
  51              $this->public_functions += array(
  52                  'exec'            => True,
  53              );
  54              $this->boetemplate();
  55  
  56              if (!$this->read($name,$template,$lang,$group,$version))
  57              {
  58                  $this->init($name,$template,$lang,$group,$version,$rows,$cols);
  59                  return False;
  60              }
  61              return True;
  62          }
  63  
  64          /**
  65           * Generats a Dialog from an eTemplate - abstract the UI-layer
  66           *
  67           * This is the only function an application should use, all other are INTERNAL and
  68           * do NOT abstract the UI-layer, because they return HTML.
  69           * Generates a webpage with a form from the template and puts process_exec in the
  70           * form as submit-url to call process_show for the template before it
  71           * ExecuteMethod's the given $methode of the caller.
  72           * @param $methode Methode (e.g. 'etemplate.editor.edit') to be called if form is submitted
  73           * @param $content Array with content to fill the input-fields of template, eg. the text-field
  74           * @param          with name 'name' gets its content from $content['name']
  75           * @param $sel_options Array or arrays with the options for each select-field, keys are the
  76           * @param              field-names, eg. array('name' => array(1 => 'one',2 => 'two')) set the
  77           * @param              options for field 'name'. ($content['options-name'] is possible too !!!)
  78           * @param $readonlys Array with field-names as keys for fields with should be readonly
  79           * @param            (eg. to implement ACL grants on field-level or to remove buttons not applicable)
  80           * @param $preserv Array with vars which should be transported to the $method-call (eg. an id) array('id' => $id) sets $_POST['id'] for the $method-call
  81           * @return nothing
  82           */
  83  		function exec($method,$content,$sel_options='',$readonlys='',$preserv='')
  84          {
  85              if (!$sel_options)
  86              {
  87                  $sel_options = array();
  88              }
  89              if (!$readonlys)
  90              {
  91                  $readonlys = array();
  92              }
  93              if (!$preserv)
  94              {
  95                  $preserv = array();
  96              }
  97              if (!class_exists('gtk'))    // load the gtk extension
  98              {
  99                  if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
 100                  {
 101                      dl('php_gtk.dll');
 102                  }
 103                  else
 104                  {
 105                      dl('php_gtk.so');
 106                  }
 107              }
 108              /*
 109              * Create a new top-level window and connect the signals to the appropriate
 110              * functions if the window not already exists.
 111              */
 112              if (!$GLOBALS['egw_info']['etemplate']['window'])
 113              {
 114                  $window = &new GtkWindow();
 115                  $window->connect('destroy',array('etemplate','destroy'));
 116                  $window->connect('delete-event',array('etemplate','delete_event'));
 117                  $window->set_title('eGroupWareGTK: '.$GLOBALS['egw_info']['server']['site_title']);
 118                  $window->set_default_size(1024,600);
 119  
 120                  $GLOBALS['egw_info']['etemplate']['window'] = &$window;
 121              }
 122              else
 123              {
 124                  $window = &$GLOBALS['egw_info']['etemplate']['window'];
 125              }
 126              $this->result = array('test' => 'test');
 127              $table = &$this->show($this->result,$content,$sel_options,$readonlys);
 128              $table->set_border_width(10);
 129              $table->show();
 130  
 131              $swindow = &new GtkScrolledWindow(null,null);
 132              $swindow->set_policy(GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
 133              $swindow->add_with_viewport($table);
 134              $swindow->show();
 135  
 136              $window->add($swindow);
 137              $window->show_all();
 138  
 139              /* Run the main loop. */
 140              Gtk::main();
 141  
 142              $this->collect_results();
 143  
 144              $swindow->hide();
 145              $window->remove($swindow);
 146              unset($swindow);
 147              unset($this->widgets);
 148  
 149              // set application name so that lang, etc. works
 150              list($GLOBALS['egw_info']['flags']['currentapp']) = explode('.',$method);
 151  
 152              ExecMethod($method,array_merge($this->result,$preserv));
 153          }
 154  
 155          /**
 156           * this is only an empty function for the GTK ui
 157           *
 158           * @return the adjusted content (in the simplest case that would be $content)
 159           */
 160  		function process_show(&$content,$readonlys='')
 161          {
 162          }
 163  
 164          /*
 165          * Called when delete-event happens. Returns false to indicate that the event
 166          * should proceed.
 167          */
 168  		function delete_event()
 169          {
 170              return false;
 171          }
 172  
 173          /*
 174          * Called when the window is being destroyed: destroy the session
 175          */
 176  		function destroy()
 177          {
 178              Gtk::main_quit();
 179              $GLOBALS['egw']->session->destroy($GLOBALS['egw_info']['user']['sessionid'],$GLOBALS['egw_info']['user']['kp3']);
 180              $GLOBALS['egw_info']['flags']['nodisplay'] = True;
 181              exit;
 182          }
 183  
 184  		function button_clicked(&$var,$form_name)
 185          {
 186              echo "button '$form_name' pressed\n";
 187              $var = 'pressed';
 188              Gtk::main_quit();
 189          }
 190  
 191  		function submit()
 192          {
 193              echo "OnChange --> submit\n";
 194              Gtk::main_quit();
 195          }
 196  
 197  		function collect_results()
 198          {
 199              for($i=0; isset($this->widgets[$i]); ++$i)
 200              {
 201                  $set = &$this->widgets[$i];
 202                  $widget = &$set['widget'];
 203  
 204                  $val_is_set = False;
 205                  echo "$i: $set[name]/$set[type]/".Gtk::type_name($widget->get_type());
 206                  switch ($set['type'])
 207                  {
 208                      case 'button':    // is set to 'pressed' or is '' (not unset !!!)
 209                          $val_is_set = ($val = $this->get_array($this->result,$set['name']));
 210                          break;
 211                      case 'int':
 212                      case 'float':
 213                      case 'text':
 214                      case 'textarea':
 215                          $val = $widget->get_chars(0,-1);
 216                          $val_is_set = True;
 217                          break;
 218                      case 'checkbox':
 219                          $val = $widget->get_active();
 220                          $val_is_set = True;
 221                          break;
 222                      case 'radio':
 223                          if ($widget->get_active())
 224                          {
 225                              $val = $set['set_val'];
 226                              $val_is_set = True;
 227                          }
 228                          break;
 229                      case 'select':
 230                          $entry = $widget->entry;
 231                          $selected = $entry->get_chars(0,-1);
 232                          $options = $set['set_val'];
 233                          reset($options);
 234                          while (list($key,$val) = each($options))
 235                          {
 236                              if ($val == $selected)
 237                              {
 238                                  $val = $key;
 239                                  $val_is_set = True;
 240                                  break;
 241                              }
 242                          }
 243                          break;
 244                      case 'date':
 245                  }
 246                  echo $val_is_set && !$set['readonly'] ? " = '$val'\n" : " NOT SET\n";
 247  
 248                  $this->set_array($this->result,$set['name'],$val,$val_is_set && !$set['readonly']);
 249              }
 250          }
 251  
 252          /**
 253           * creates HTML from an eTemplate
 254           *
 255           * This is done by calling show_cell for each cell in the form. show_cell itself
 256           * calls show recursivly for each included eTemplate.
 257           * You can use it in the UI-layer of an app, just make shure to call process_show !!!
 258           * This is intended as internal function and should NOT be called by new app's direct,
 259           * as it deals with HTML and is so UI-dependent, use exec instead.
 260           * @param $content array with content for the cells, keys are the names given in the cells/form elements
 261           * @param $sel_options array with options for the selectboxes, keys are the name of the selectbox
 262           * @param $readonlys array with names of cells/form-elements to be not allowed to change
 263           * @param            This is to facilitate complex ACL's which denies access on field-level !!!
 264           * @param $cname basename of names for form-elements, means index in $_POST
 265           * @param        eg. $cname='cont', element-name = 'name' returned content in $_POST['cont']['name']
 266           * @param $show_xxx row,col name/index for name expansion
 267           * @return the generated HTML
 268           */
 269  		function show(&$result,$content,$sel_options='',$readonlys='',$cname='',$show_c=0,$show_row=0)
 270          {
 271              if (!$sel_options)
 272              {
 273                  $sel_options = array();
 274              }
 275              if (!$readonlys)
 276              {
 277                  $readonlys = array();
 278              }
 279              if ($this->debug >= 1 || $this->debug == $this->name && $this->name)
 280              {
 281                  echo "<p>etemplate.show($this->name): $cname =\n"; _debug_array($content);
 282              }
 283              if (!is_array($content))
 284              {
 285                  $content = array();    // happens if incl. template has no content
 286              }
 287              $content += array(    // for var-expansion in names in show_cell
 288                  '.c' => $show_c,
 289                  '.col' => $this->num2chrs($show_c-1),
 290                  '.row' => $show_row
 291              );
 292  
 293              $table = &new GtkTable($this->rows,$this->cols,False);
 294              $table->set_row_spacings(2);
 295              $table->set_col_spacings(5);
 296              $table->show();
 297  
 298              reset($this->data);
 299              if (isset($this->data[0]))
 300              {
 301                  list($nul,$width) = each($this->data);
 302              }
 303              else
 304              {
 305                  $width = array();
 306              }
 307              for ($r = 0; $row = 1+$r /*list($row,$cols) = each($this->data)*/; ++$r)
 308              {
 309                  $old_cols = $cols; $old_class = $class; $old_height = $height;
 310                  if (!(list($nul,$cols) = each($this->data)))    // no further row
 311                  {
 312                      $cols = $old_cols; $class = $old_class; $height = $old_height;
 313                      list($nul,$cell) = each($cols); reset($cols);
 314                      if (!($this->autorepeat_idx($cols['A'],0,$r,$idx,$idx_cname) && $idx_cname) &&
 315                          !($this->autorepeat_idx($cols['B'],1,$r,$idx,$idx_cname) && $idx_cname) ||
 316                          !$this->isset_array($content,$idx))
 317                      {
 318                          break;                         // no auto-row-repeat
 319                      }
 320                  }
 321                  else
 322                  {
 323                      $height = $this->data[0]["h$row"];
 324                      list($class,$valign) = explode(',',$this->data[0]["c$row"]);
 325                      switch($valign)
 326                      {
 327                          case 'top':
 328                              $valign = 0.0;
 329                              break;
 330                          case 'bottom':
 331                              $valign = 1.0;
 332                              break;
 333                          default:
 334                              $valign = 0.5;
 335                      }
 336                  }
 337                  $row_data = array();
 338                  for ($c = 0; True /*list($col,$cell) = each($cols)*/; ++$c)
 339                  {
 340                      $old_cell = $cell;
 341                      if (!(list($nul,$cell) = each($cols)))        // no further cols
 342                      {
 343                          $cell = $old_cell;
 344                          if (!$this->autorepeat_idx($cell,$c,$r,$idx,$idx_cname,True) ||
 345                              !$this->isset_array($content,$idx))
 346                          {
 347                              break;    // no auto-col-repeat
 348                          }
 349                      }
 350                      $col = $this->num2chrs($c);
 351  
 352                      //$row_data[$col] = $this->show_cell($cell,$content,$sel_options,$readonlys,$cname,$c,$r,$span);
 353                      $widget = &$this->show_cell($cell,$content,$sel_options,$readonlys,$cname,$c,$r,$span,$result);
 354  
 355                      if (($colspan = $span == 'all' ? $this->cols-$c : 0+$span) < 1)
 356                      {
 357                          $colspan = 1;
 358                      }
 359                      if ($widget)
 360                      {
 361                          $widget->show();
 362                          if ($align = ($cell['align'] || $valign))
 363                          {
 364                              switch ($cell['align'])
 365                              {
 366                                  case 'center':
 367                                      $align = 0.5;
 368                                      break;
 369                                  case 'right':
 370                                      $align = 1.0;
 371                                      break;
 372                                  default:
 373                                      $align = 0.0;
 374                              }
 375                              $align = &new GtkAlignment($align,$valign,$cell['type'] == 'hrule' ? 1.0 : 0.0,0.0);
 376                              $align->add($widget);
 377                          }
 378                          $table->attach($align ? $align : $widget, $c, $c+$colspan, $r, $r+1,GTK_FILL,GTK_FILL,0,0);
 379                      }
 380                      if ($row_data[$col] == '' && $this->rows == 1)
 381                      {
 382                          unset($row_data[$col]);    // omit empty/disabled cells if only one row
 383                          continue;
 384                      }
 385                      if ($colspan > 1)
 386                      {
 387                          $row_data[".$col"] .= " COLSPAN=$colspan";
 388                          for ($i = 1; $i < $colspan; ++$i,++$c)
 389                          {
 390                              each($cols);    // skip next cell(s)
 391                          }
 392                      }
 393                      elseif ($width[$col])    // width only once for a non colspan cell
 394                      {
 395                          $row_data[".$col"] .= ' WIDTH='.$width[$col];
 396                          $width[$col] = 0;
 397                      }
 398  //                    $row_data[".$col"] .= $this->html->formatOptions($cell['align'],'ALIGN');
 399  //                    $row_data[".$col"] .= $this->html->formatOptions($cell['span'],',CLASS');
 400                  }
 401                  $rows[$row] = $row_data;
 402  
 403  //                $rows[".$row"] .= $this->html->formatOptions($height,'HEIGHT');
 404                  list($cl) = explode(',',$class);
 405                  if ($cl == 'nmr')
 406                  {
 407                      $cl .= $nmr_alternate++ & 1; // alternate color
 408                  }
 409  //                $rows[".$row"] .= $this->html->formatOptions($cl,'CLASS');
 410  //                $rows[".$row"] .= $this->html->formatOptions($class,',VALIGN');
 411              }
 412              if (!$GLOBALS['egw_info']['etemplate']['styles_included'][$this->name])
 413              {
 414  //                $style = $this->html->style($this->style);
 415                  $GLOBALS['egw_info']['etemplate']['styles_included'][$this->name] = True;
 416              }
 417              return $table;
 418          }
 419  
 420  		function draw_image($area, $event, $pixbuf)
 421          {
 422              $pixbuf->render_to_drawable($area->window,
 423                                          $area->style->fg_gc[GTK_STATE_NORMAL],
 424                                          $event->area->x, $event->area->y,
 425                                          $event->area->x, $event->area->y,
 426                                          $event->area->width, $event->area->height,
 427                                          GDK_RGB_DITHER_NORMAL,
 428                                          $event->area->x, $event->area->y);
 429          }
 430  
 431          /**
 432           * generates HTML for 1 input-field / cell
 433           *
 434           * calls show to generate included eTemplates. Again only an INTERMAL function.
 435           * @param $cell array with data of the cell: name, type, ...
 436           * @param for rest see show
 437           * @return the generated HTML
 438           */
 439  		function show_cell($cell,$content,$sel_options,$readonlys,$cname,$show_c,$show_row,&$span,&$result)
 440          {
 441              if ($this->debug >= 3 || $this->debug == $cell['type'])
 442              {
 443                  echo "<p>etemplate.show_cell($this->name,name='$cell['name']}',type='$cell['type']}',cname='$cname')</p>\n";
 444              }
 445              list($span) = explode(',',$cell['span']);    // evtl. overriten later for type template
 446  
 447              $name = $this->expand_name($cell['name'],$show_c,$show_row,$content['.c'],$content['.row'],$content);
 448  
 449              // building the form-field-name depending on prefix $cname and possibl. Array-subscript in name
 450              if (ereg('^([^[]*)(\\[.*\\])$',$name,$regs))    // name contains array-index
 451              {
 452                  $form_name = $cname == '' ? $name : $cname.'['.$regs[1].']'.$regs[2];
 453                  eval(str_replace(']',"']",str_replace('[',"['",'$value = $content['.$regs[1].']'.$regs[2].';')));
 454                  $org_name = substr($regs[2],1,-1);
 455                  eval(str_replace(']',"']",str_replace('[',"['",'$var = &$result['.$regs[1].']'.$regs[2].';')));
 456              }
 457              else
 458              {
 459                  $form_name = $cname == '' ? $name : $cname.'['.$name.']';
 460                  $value = $content[$name];
 461                  $org_name = $name;
 462                  $var = &$result[$name];
 463              }
 464              $readonly = $cell['readonly'] || $readonlys[$name] || $readonlys['__ALL__'];
 465  
 466              if ($cell['disabled'] || $cell['type'] == 'button' && $readonly)
 467              {
 468                  if ($this->rows == 1) {
 469                      return '';    // if only one row omit cell
 470                  }
 471                  $cell = $this->empty_cell(); // show nothing
 472                  $value = '';
 473              }
 474              if ($cell['onchange'])    // values != '1' can only set by a program (not in the editor so far)
 475              {
 476                  $options .= ' onChange="'.($cell['onchange']=='1'?'this.form.submit();':$cell['onchange']).'"';
 477              }
 478  
 479              if (strlen($label = $cell['label']) > 1)
 480              {
 481                  $label = lang($label);
 482              }
 483              list($left_label,$right_label) = explode('%s',$label);
 484  
 485              //echo "show_cell: type='$cell[type]', name='$cell[name]'-->'$name', value='$value'\n";
 486              $widget = False;
 487              switch ($cell['type'])
 488              {
 489                  case 'label':        //  size: [[b]old][[i]talic]
 490                      $value = strlen($value) > 1 && !$cell['no_lang'] ? lang($value) : $value;
 491  
 492                      //if ($value != '' && strstr($cell['size'],'b')) $value = $this->html->bold($value);
 493                      //if ($value != '' && strstr($cell['size'],'i')) $value = $this->html->italic($value);
 494                      $html .= $value;
 495  
 496                      if ($value)
 497                      {
 498                          $widget = &new GtkLabel($value);
 499                          if ($cell['align'] != 'center')
 500                          {
 501                              $widget->set_justify($cell['align'] == 'right' ? GTK_JUSTIFY_RIGHT : GTK_JUSTIFY_LEFT);
 502                          }
 503                      }
 504                      break;
 505                  case 'raw':
 506                      //$html .= $value;
 507                      break;
 508                  case 'int':        // size: [min][,[max][,len]]
 509                  case 'float':
 510                      list($min,$max,$cell['size']) = explode(',',$cell['size']);
 511                      if ($cell['size'] == '')
 512                      {
 513                          $cell['size'] = $cell['type'] == 'int' ? 5 : 8;
 514                      }
 515                      // fall-through
 516                  case 'text':        // size: [length][,maxLength]
 517                      if ($readonly)
 518                      {
 519                          //$html .= $this->html->bold($value);
 520                      }
 521                      else
 522                      {
 523                          //$html .= $this->html->input($form_name,$value,'',$options.$this->html->formatOptions($cell['size'],'SIZE,MAXLENGTH'));
 524                      }
 525                      list($len,$max) = explode(',',$cell['size']);
 526                      $widget = &new GtkEntry();
 527                      $widget->set_text($value);
 528                      if ($max)
 529                      {
 530                          $widget->set_max_length($max);
 531                      }
 532                      $widget->set_editable(!$readonly);
 533                      if ($len)
 534                      {
 535                          $widget->set_usize($len*$this->font_width,0);
 536                      }
 537                      break;
 538                  case 'textarea':    // Multiline Text Input, size: [rows][,cols]
 539                      //$html .= $this->html->textarea($form_name,$value,$options.$this->html->formatOptions($cell['size'],'ROWS,COLS'));
 540                      $widget = &new GtkText(null,null);
 541                      $widget->insert_text($value,strlen($value));
 542                      $widget->set_editable(!$readonly);
 543                      break;
 544  /*                case 'date':
 545                      if ($cell['size'] != '')
 546                      {
 547                          $date = split('[/.-]',$value);
 548                          $mdy  = split('[/.-]',$cell['size']);
 549                          for ($value=array(),$n = 0; $n < 3; ++$n)
 550                          {
 551                              switch($mdy[$n])
 552                              {
 553                                  case 'Y': $value[0] = $date[$n]; break;
 554                                  case 'm': $value[1] = $date[$n]; break;
 555                                  case 'd': $value[2] = $date[$n]; break;
 556                              }
 557                          }
 558                      }
 559                      else
 560                      {
 561                          $value = array(date('Y',$value),date('m',$value),date('d',$value));
 562                      }
 563                      if ($readonly)
 564                      {
 565                          $html .= $GLOBALS['egw']->common->dateformatorder($value[0],$value[1],$value[2]);
 566                      }
 567                      else
 568                      {
 569                          $html .= $this->sbox->getDate($name.'[Y]',$name.'[m]',$name.'[d]',$value,$options);
 570                      }
 571                      break;
 572  */                case 'checkbox':
 573                      if ($value)
 574                      {
 575                          $options .= ' CHECKED';
 576                      }
 577                      //$html .= $this->html->input($form_name,'1','CHECKBOX',$options);
 578                      $widget = &new GtkCheckButton($right_label);
 579                      $right_label = '';
 580                      $widget->set_active($value);
 581                      break;
 582                  case 'radio':        // size: value if checked
 583                      if ($value == $cell['size'])
 584                      {
 585                          $options .= ' CHECKED';
 586                      }
 587                      //$html .= $this->html->input($form_name,$cell['size'],'RADIO',$options);
 588                      if (isset($this->buttongroup[$form_name]))
 589                      {
 590                          $widget = &new GtkRadioButton($this->buttongroup[$form_name],$right_label);
 591                      }
 592                      else
 593                      {
 594                          $this->buttongroup[$form_name] = $widget = &new GtkRadioButton(null,$right_label);
 595                      }
 596                      $right_label = '';
 597                      $widget->set_active($value == $cell['size']);
 598                      break;
 599                  case 'button':
 600                      //$html .= $this->html->submit_button($form_name,$cell['label'],'',strlen($cell['label']) <= 1 || $cell['no_lang'],$options);
 601                      $widget = &new GtkButton(strlen($cell['label']) > 1 ? lang($cell['label']) : $cell['label']);
 602                      $widget->connect_object('clicked', array('etemplate', 'button_clicked'),&$var,$form_name);
 603                      break;
 604                  case 'hrule':
 605                      //$html .= $this->html->hr($cell['size']);
 606                      $widget = &new GtkHSeparator();
 607                      break;
 608                  case 'template':    // size: index in content-array (if not full content is past further on)
 609                      if ($this->autorepeat_idx($cell,$show_c,$show_row,$idx,$idx_cname) || $cell['size'] != '')
 610                      {
 611                          if ($span == '' && isset($content[$idx]['span']))
 612                          {    // this allows a colspan in autorepeated cells like the editor
 613                              $span = explode(',',$content[$idx]['span']); $span = $span[0];
 614                              if ($span == 'all')
 615                              {
 616                                  $span = 1 + $content['cols'] - $show_c;
 617                              }
 618                          }
 619                          $readonlys = $readonlys[$idx];
 620                          $content = $content[$idx];
 621                          $var = &$result[$idx];
 622                          if ($idx_cname != '')
 623                          {
 624                              $cname .= $cname == '' ? $idx_cname : "[$idx_cname]";
 625                          }
 626                          //echo "<p>show_cell-autorepeat($name,$show_c,$show_row,cname='$cname',idx='$idx',idx_cname='$idx_cname',span='$span'): readonlys[$idx] ="; _debug_array($readonlys);
 627                      }
 628                      else
 629                      {
 630                          $var = &$result;
 631                      }
 632                      if ($readonly)
 633                      {
 634                          $readonlys['__ALL__'] = True;
 635                      }
 636                      $templ = is_object($cell['name']) ? $cell['name'] : new etemplate($name);
 637                      $templ->widgets = &$this->widgets;
 638                      //$html .= $templ->show($content,$sel_options,$readonlys,$cname,$show_c,$show_row);
 639                      $widget = $templ->show($var,$content,$sel_options,$readonlys,$cname,$show_c,$show_row);
 640                      break;
 641                  case 'select':    // size:[linesOnMultiselect]
 642                      if (isset($sel_options[$name]))
 643                      {
 644                          $sel_options = $sel_options[$name];
 645                      }
 646                      elseif (isset($sel_options[$org_name]))
 647                      {
 648                          $sel_options = $sel_options[$org_name];
 649                      } elseif (isset($content["options-$name"]))
 650                      {
 651                          $sel_options = $content["options-$name"];
 652                      }
 653                      //$html .= $this->sbox->getArrayItem($form_name.'[]',$value,$sel_options,$cell['no_lang'],$options,$cell['size']);
 654  
 655                      reset($sel_options);
 656                      for ($maxlen=0; list($key,$val) = each($sel_options); )
 657                      {
 658                          if (!$cell['no_lang'])
 659                          {
 660                              $sel_options[$key] = lang($val);
 661                          }
 662                          if (($len = strlen($sel_options[$key])) > $maxlen)
 663                          {
 664                              $maxlen = $len;
 665                          }
 666                      }
 667                      $widget = &new GtkCombo();
 668                      $widget->set_popdown_strings($sel_options);
 669                      $entry = $widget->entry;
 670                      $entry->set_text($sel_options[$value]);
 671                      $entry->set_editable(False);
 672                      $entry->set_usize($maxlen*$this->font_width,0);
 673                      if ($cell['onchange'] == '1')
 674                      {
 675                          $entry->connect('changed',array('etemplate', 'submit'));
 676                      }
 677                      break;
 678  /*                case 'select-percent':
 679                      $html .= $this->sbox->getPercentage($form_name,$value,$options);
 680                      break;
 681                  case 'select-priority':
 682                      $html .= $this->sbox->getPriority($form_name,$value,$options);
 683                      break;
 684                  case 'select-access':
 685                      $html .= $this->sbox->getAccessList($form_name,$value,$options);
 686                      break;
 687                  case 'select-country':
 688                      $html .= $this->sbox->getCountry($form_name,$value,$options);
 689                      break;
 690                  case 'select-state':
 691                      $html .= $this->sbox->list_states($form_name,$value);  // no helptext - old Function!!!
 692                      break;
 693                  case 'select-cat':
 694                      $html .= $this->sbox->getCategory($form_name.'[]',$value,$cell['size'] >= 0,
 695                          False,$cell['size'],$options);
 696                      break;
 697                  case 'select-account':
 698                      $type = substr(strstr($cell['size'],','),1);
 699                      if ($type == '')
 700                      {
 701                          $type = 'accounts';    // default is accounts
 702                      }
 703                      $html .= $this->sbox->getAccount($form_name.'[]',$value,2,$type,0+$cell['size'],$options);
 704                      break;
 705  */                case 'image':
 706                      if (!($path = $GLOBALS['egw']->common->image(substr($this->name,0,strpos($this->name,'.')),$cell['label'])))
 707                          $path = $cell['label'];        // name may already contain absolut path
 708                      if (!isset($GLOBALS['egw_info']['etemplate']['pixbufs'][$path]))
 709                      {
 710                          $GLOBALS['egw_info']['etemplate']['pixbufs'][$path] = GdkPixbuf::new_from_file('../..'.$path);
 711                      }
 712                      $pixbuf = &$GLOBALS['egw_info']['etemplate']['pixbufs'][$path];
 713                      if ($pixbuf)
 714                      {
 715                          $widget = &new GtkDrawingArea();
 716                          $widget->size($pixbuf->get_width(),$pixbuf->get_height());
 717                          $widget->connect('expose_event',array('etemplate','draw_image'),$pixbuf);
 718                      }
 719                      else
 720                      {
 721                          echo "Can't load image '$path'";
 722                      }
 723                      break;
 724                  default:
 725                      //$html .= '<i>unknown type</i>';
 726                      $widget = &new GtkLabel('unknown type: '.$cell['type']);
 727                      $widget->set_justify(GTK_JUSTIFY_LEFT);
 728                      break;
 729              }
 730              if ($widget && !$readonly && !$this->no_result[$cell['type']])
 731              {
 732                  $this->widgets[] = array(
 733                      'widget' => &$widget,
 734                      'type' => $cell['type'],
 735                      'set_val' => $cell['type'] == 'radio' ? $cell['size'] : $sel_options,
 736                      'name' => $form_name,
 737                      'readonly' => $readonly
 738                  );
 739              }
 740              if ($cell['type'] != 'button' && $cell['type'] != 'image' && ($left_label || $right_label))
 741              {
 742                  if (!$widget && !$right_label)
 743                  {
 744                      $widget = &new GtkLabel($left_label);
 745                  }
 746                  else
 747                  {
 748                      $hbox = &new GtkHBox(False,5);
 749                      if ($left_label)
 750                      {
 751                          $left = &new GtkLabel($left_label);
 752                          $left->show();
 753                          $hbox->add($left);
 754                      }
 755                      if ($widget)
 756                      {
 757                          $widget->show();
 758                          $hbox->add($widget);
 759                      }
 760                      if ($right_label)
 761                      {
 762                          $right = &new GtkLabel($right_label);
 763                          $right->show();
 764                          $hbox->add($right);
 765                      }
 766                  }
 767              }
 768              if ($cell['help'] && $widget)
 769              {
 770                  if (!$this->tooltips)
 771                  {
 772                      $this->tooltips = &new GtkTooltips();
 773                  }
 774                  $this->tooltips->set_tip($widget,lang($cell['help']),$this->name.'/'.$form_name);
 775              }
 776              return $hbox ? $hbox : $widget;
 777          }
 778      };


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