phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] CVS: etemplate/inc class.date_widget.inc.php,NONE,1.1


From: Ralf Becker <address@hidden>
Subject: [Phpgroupware-cvs] CVS: etemplate/inc class.date_widget.inc.php,NONE,1.1 class.datefield_widget.inc.php,NONE,1.1 class.boetemplate.inc.php,1.5,1.6 class.editor.inc.php,1.4,1.5 class.uietemplate.inc.php,1.4,1.5
Date: Mon, 13 May 2002 17:30:49 -0400

Update of /cvsroot/phpgroupware/etemplate/inc
In directory subversions:/tmp/cvs-serv1131

Modified Files:
        class.boetemplate.inc.php class.editor.inc.php 
        class.uietemplate.inc.php 
Added Files:
        class.date_widget.inc.php class.datefield_widget.inc.php 
Log Message:
Added interface to extend eTemplates with new widgets.
The widget got automaticaly loaded from the app's inc dir (or etemplate's inc 
dir).
Two examples ilustrate how to use the interface:
 - date: class.date_widget.inc.php reads dates via sbox.getDate
 - datefield: class.datefield_widget.inc.php reads dates via 3 textfields

***** Error reading new file: [Errno 2] No such file or directory: 
'class.date_widget.inc.php'
***** Error reading new file: [Errno 2] No such file or directory: 
'class.datefield_widget.inc.php'
Index: class.boetemplate.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/etemplate/inc/class.boetemplate.inc.php,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** class.boetemplate.inc.php   11 May 2002 15:16:23 -0000      1.5
--- class.boetemplate.inc.php   13 May 2002 21:30:46 -0000      1.6
***************
*** 23,26 ****
--- 23,28 ----
        class boetemplate extends soetemplate
        {
+               var $extensions = array();
+ 
                var $types = array(
                        'label' => 'Label',                     // Label 
$cell['label'] is (to be translated) textual content
***************
*** 35,39 ****
                        'template' => 'Template',       // $cell['name'] 
contains template-name, $cell['size'] index into $content,$cname,$readonlys
                        'image' => 'Image',                     // label = url, 
name=link or method, help=alt or title
!                       'date'  => 'Date',                      // Datefield, 
size='' timestamp or size=format like 'm/d/Y'
                        'select'        =>      'Selectbox',    // Selectbox 
($sel_options[$name] or $content[options-$name] is array with options)
                                                                                
                // if size > 1 then multiple selections, size lines showed
--- 37,41 ----
                        'template' => 'Template',       // $cell['name'] 
contains template-name, $cell['size'] index into $content,$cname,$readonlys
                        'image' => 'Image',                     // label = url, 
name=link or method, help=alt or title
!                       'date'  => '',                  // Datefield, size='' 
timestamp or size=format like 'm/d/Y'
                        'select'        =>      'Selectbox',    // Selectbox 
($sel_options[$name] or $content[options-$name] is array with options)
                                                                                
                // if size > 1 then multiple selections, size lines showed
***************
*** 48,57 ****
                        'raw'           => 'Raw',       // Raw html in 
$content[$cell['name']]
                );
-               var $aligns = array(
-                       '' => 'Left',
-                       'right' => 'Right',
-                       'center' => 'Center'
-               );
- 
                /*!
                @function boetemplate
--- 50,53 ----
***************
*** 62,65 ****
--- 58,65 ----
                {
                        $this->soetemplate();
+ 
+                       $this->public_functions += array(
+                               'disable_cells' => True
+                       );
                }
  
***************
*** 219,222 ****
--- 219,258 ----
  
                        return $n;
+               }
+ 
+               /*!
+               @function loadExtension($name,$ui='')
+               @abstact trys to load the Extension / Widget-class from the app 
or etemplate
+               @param $name name of the extension the classname should be 
class.${name}_widget.inc.php
+               @note the $name might be "$name.$app" to give a app-name 
(default is the current app)
+               */
+               function loadExtension($name,&$parent,$ui='html')
+               {
+                       list($class,$app) = explode('.',$name);
+                       $class .= '_widget';
+ 
+                       if ($app == '')
+                       {
+                               $app = 
$GLOBALS['phpgw_info']['flags']['current_app'];
+                       }
+                       if 
(!file_exists(PHPGW_SERVER_ROOT."/$app/inc/class.$class.inc.php"))
+                       {
+                               $app = 'etemplate';
+                       }
+                       if 
(!file_exists(PHPGW_SERVER_ROOT."/$app/inc/class.$class.inc.php"))
+                       {
+                               return $this->extension[$name] = False;
+                       }
+                       $this->extension[$name] = 
CreateObject($app.'.'.$class,$ui);
+ 
+                       if(floor(phpversion()) >= 4)
+                       {
+                               $this->extension[$name]->et = &$parent;
+                       }
+                       else
+                       {
+                               $this->extension[$name]->et = $parent;
+                       }
+                       return $this->extension[$name];
                }
        };

Index: class.editor.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/etemplate/inc/class.editor.inc.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** class.editor.inc.php        13 May 2002 18:17:44 -0000      1.4
--- class.editor.inc.php        13 May 2002 21:30:46 -0000      1.5
***************
*** 25,28 ****
--- 25,34 ----
                        'other_version' => 'only an other Version found !!!'
                );
+               var $aligns = array(
+                       '' => 'Left',
+                       'right' => 'Right',
+                       'center' => 'Center'
+               );
+               var $extensions = '';
  
                var $public_functions = array
***************
*** 58,61 ****
--- 64,76 ----
                                $msg .= $this->messages['not_found'];
                        }
+                       if ($this->extensions == '')
+                       {
+                               $this->extensions = 
$this->scan_for_extensions();
+                               list($app) = explode('.',$this->name);
+                               if ($app != '' && $app != 'etemplate')
+                               {
+                                       $this->extensions += 
$this->scan_for_extensions($app);
+                               }
+                       }
                        $content = $this->etemplate->as_array() + array(
                                'cols' => $this->etemplate->cols,
***************
*** 124,131 ****
                        
$this->editor->exec('etemplate.editor.process_edit',$content,
                                array(
!                                       'type' => $this->etemplate->types,
!                                       'align' => $this->etemplate->aligns
                                ),
!                               $no_button,$cols_spanned);
                }
  
--- 139,146 ----
                        
$this->editor->exec('etemplate.editor.process_edit',$content,
                                array(
!                                       'type' => 
array_merge($this->etemplate->types,$this->extensions),
!                                       'align' => $this->aligns
                                ),
!                               $no_button,$cols_spanned + 
array('**extensions**' => $this->extensions));
                }
  
***************
*** 137,146 ****
                function process_edit($content)
                {
-                       //$content = $GLOBALS['HTTP_POST_VARS']['cont'];
- 
                        if ($this->debug)
                        {
                                echo "editor.process_edit: content ="; 
_debug_array($content);
                        }
                        $this->etemplate->init($content);
                        $this->etemplate->size = $content['size'];
--- 152,160 ----
                function process_edit($content)
                {
                        if ($this->debug)
                        {
                                echo "editor.process_edit: content ="; 
_debug_array($content);
                        }
+                       $this->extensions = $content['**extensions**']; 
unset($content['**extensions**']);
                        $this->etemplate->init($content);
                        $this->etemplate->size = $content['size'];
***************
*** 307,311 ****
                                {
                                        $m = new editor(False);
!                                       $additional = $m->messages + 
$this->etemplate->types + $this->etemplate->aligns;
                                }
                                $msg = 
$this->etemplate->writeLangFile($content['name'],'en',$additional);
--- 321,325 ----
                                {
                                        $m = new editor(False);
!                                       $additional = $m->messages + 
$this->etemplate->types + $this->aligns;
                                }
                                $msg = 
$this->etemplate->writeLangFile($content['name'],'en',$additional);
***************
*** 393,397 ****
                        {
                                $cont = $post_vars['cont'];
!                               $this->etemplate->process_show($cont);  // need 
to be done manually as name is set to $this->etemplate object 
                                for ($r = 1; list($key,$val) = @each($cont); 
++$r)
                                {
--- 407,411 ----
                        {
                                $cont = $post_vars['cont'];
!                               $this->etemplate->process_show($cont);  // need 
to be done manually as name is set to $this->etemplate object
                                for ($r = 1; list($key,$val) = @each($cont); 
++$r)
                                {
***************
*** 415,418 ****
--- 429,455 ----
                        }
                        
$show->exec('etemplate.editor.show',$content,array(),$no_buttons,array('olds' 
=> $vals),'');
+               }
+ 
+               /*!
+               @function scan_for_extensions()
+               @abstract search the inc-dirs of etemplate and the app whichs 
template is edited for extensions / custom widgets
+               @note extensions are class-files in 
$app/inc/class.${name}_widget.inc.php
+               @returns array with name => human_name of the extensions found
+               */
+               function scan_for_extensions($app='etemplate')
+               {
+                       $extensions = array();
+ 
+                       $dir = @opendir(PHPGW_SERVER_ROOT.'/'.$app.'/inc');
+ 
+                       while ($dir && ($file = readdir($dir)))
+                       {
+                               if 
(ereg('class\\.([a-zA-Z0-9_]*)_widget.inc.php',$file,$regs) &&
+                                        ($ext = 
$this->etemplate->loadExtension($regs[1].'.'.$app,$this->etemplate)))
+                               {
+                                       $extensions[$regs[1]] = 
$ext->human_name;
+                               }
+                       }
+                       return $extensions;
                }
        };

Index: class.uietemplate.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/etemplate/inc/class.uietemplate.inc.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** class.uietemplate.inc.php   11 May 2002 21:05:13 -0000      1.4
--- class.uietemplate.inc.php   13 May 2002 21:30:46 -0000      1.5
***************
*** 327,330 ****
--- 327,338 ----
                                $value = '';
                        }
+                       $extra_label = True;
+ 
+                       if (!$this->types[$cell['type']] &&
+                           (isset($this->extension[$cell['type']]) || 
$this->loadExtension($cell['type'],$this)))
+                       {
+                               $extra_label = 
$this->extension[$cell['type']]->pre_process($cell,$value);
+                               $content[$name] = $value;       // set result 
for template
+                       }
                        if ($cell['help'])
                        {
***************
*** 375,406 ****
                                                
$options.$this->html->formatOptions($cell['size'],'ROWS,COLS'));
                                        break;
-                               case 'date':
-                                       if ($cell['size'] != '')
-                                       {
-                                               $date = split('[/.-]',$value);
-                                               $mdy  = 
split('[/.-]',$cell['size']);
-                                               for ($value=array(),$n = 0; $n 
< 3; ++$n)
-                                               {
-                                                       switch($mdy[$n])
-                                                       {
-                                                               case 'Y': 
$value[0] = $date[$n]; break;
-                                                               case 'm': 
$value[1] = $date[$n]; break;
-                                                               case 'd': 
$value[2] = $date[$n]; break;
-                                                       }
-                                               }
-                                       }
-                                       else
-                                       {
-                                               $value = 
array(date('Y',$value),date('m',$value),date('d',$value));
-                                       }
-                                       if ($readonly)
-                                       {
-                                               $html .= 
$GLOBALS['phpgw']->common->dateformatorder($value[0],$value[1],$value[2]);
-                                       }
-                                       else
-                                       {
-                                               $html .= 
$this->sbox->getDate($name.'[Y]',$name.'[m]',$name.'[d]',$value,$options);
-                                       }
-                                       break;
                                case 'checkbox':
                                        if ($value)
--- 383,386 ----
***************
*** 420,423 ****
--- 400,404 ----
                                        $html .= 
$this->html->submit_button($form_name,$cell['label'],'',
                                                strlen($cell['label']) <= 1 || 
$cell['no_lang'],$options);
+                                       $extra_label = False;
                                        break;
                                case 'hrule':
***************
*** 447,451 ****
                                                $readonlys['__ALL__'] = True;
                                        }
!                                       $templ = is_object($cell['name']) ? 
$cell['name'] : new etemplate($name);
                                        $html .= 
$templ->show($content,$sel_options,$readonlys,$cname,$show_c,$show_row);
                                        break;
--- 428,432 ----
                                                $readonlys['__ALL__'] = True;
                                        }
!                                       $templ = is_object($cell['name']) ? 
$cell['name'] : new etemplate($cell['name']);
                                        $html .= 
$templ->show($content,$sel_options,$readonlys,$cname,$show_c,$show_row);
                                        break;
***************
*** 496,505 ****
                                                
$cell['label'],lang($cell['help']),'BORDER=0');
                                        $html .= $name == '' ? $image : 
$this->html->a_href($image,$name);
                                        break;
                                default:
!                                       $html .= '<i>unknown type</i>';
                                        break;
                        }
!                       if ($cell['type'] != 'button' && $cell['type'] != 
'image' && (($label = $cell['label']) != '' || $html == ''))
                        {
                                if (strlen($label) > 1)
--- 477,494 ----
                                                
$cell['label'],lang($cell['help']),'BORDER=0');
                                        $html .= $name == '' ? $image : 
$this->html->a_href($image,$name);
+                                       $extra_label = False;
                                        break;
                                default:
!                                       if 
(!isset($this->extension[$cell['type']]))
!                                       {
!                                               $html .= '<i>unknown type</i>';
!                                       }
!                                       else
!                                       {
!                                               $html .= 
$this->extension[$cell['type']]->render($cell,$form_name,$value,$readonly);
!                                       }
                                        break;
                        }
!                       if ($extra_label && (($label = $cell['label']) != '' || 
$html == ''))
                        {
                                if (strlen($label) > 1)
***************
*** 668,672 ****
                        if ($this->debug >= 3 || $this->debug == $this->name || 
$this->debug == $cell['type'])
                        {
!                               echo "<p>process_show_cell(c=$c, r=$r, 
name='$name',type='${cell['type']}) start: isset(value)=".(0+isset($value)).", 
value=";
                                if (is_array($value))
                                {
--- 657,661 ----
                        if ($this->debug >= 3 || $this->debug == $this->name || 
$this->debug == $cell['type'])
                        {
!                               echo "<p>process_show_cell(c=$c, r=$r, 
name='$name',type='${cell['type']}') start: isset(value)=".(0+isset($value)).", 
value=";
                                if (is_array($value))
                                {
***************
*** 694,733 ****
                                        }
                                        break;
-                               case 'date':
-                                       if ($value['d'])
-                                       {
-                                               if (!$value['m'])
-                                               {
-                                                       $value['m'] = date('m');
-                                               }
-                                               if (!$value['Y'])
-                                               {
-                                                       $value['Y'] = date('Y');
-                                               }
-                                               if ($cell['size'] == '')
-                                               {
-                                                       $value = 
mktime(0,0,0,$value['m'],$value['d'],$value['Y']);
-                                               }
-                                               else
-                                               {
-                                                       for ($n = 0,$str = ''; 
$n < strlen($cell['size']); ++$n)
-                                                       {
-                                                               if 
(strstr('Ymd',$c = $cell['size'][$n]))
-                                                               {
-                                                                       $str .= 
sprintf($c=='Y'?'%04d':'%02d',$value[$c]);
-                                                               }
-                                                               else
-                                                               {
-                                                                       $str .= 
$c;
-                                                               }
-                                                       }
-                                                       $value = $str;
-                                               }
-                                       }
-                                       else
-                                       {
-                                               $value = '';
-                                       }
-                                       break;
                                case 'checkbox':
                                        if (!isset($value))     // checkbox was 
not checked
--- 683,686 ----
***************
*** 749,752 ****
--- 702,712 ----
                                        break;
                                default: // do nothing, $value is correct as is
+                                       if 
((isset($this->extension[$cell['type']]) || 
$this->loadExtension($cell['type'],$this)) &&
+                                           
isset($this->extension[$cell['type']]->public_functions['post_process']))
+                                       {
+                                               //echo "value for post_process: 
"; _debug_array($value);
+                                               
$this->extension[$cell['type']]->post_process($cell,$value);
+                                               //echo "<p>value after 
post_process: '$value'";
+                                       }
                        }
                        if ($this->debug >= 3 || $this->debug == $this->name || 
$this->debug == $cell['type'])




reply via email to

[Prev in Thread] Current Thread [Next in Thread]