2002-02-06 10:03:11 +01:00
< ? php
2008-03-20 19:43:11 +01:00
/**
2008-10-07 20:04:59 +02:00
* eGroupWare eTemplates - Editor
2008-03-20 19:43:11 +01:00
*
* @ link http :// www . egroupware . org
* @ author Ralf Becker < RalfBecker @ outdoor - training . de >
* @ copyright 2002 - 8 by RalfBecker @ outdoor - training . de
* @ license http :// opensource . org / licenses / gpl - license . php GPL - GNU General Public License
* @ package etemplate
* @ subpackage tools
* @ version $Id $
*/
/**
* template editor of the eTemplate package
*/
class editor
{
var $debug ;
2006-04-20 19:12:30 +02:00
/**
2008-03-20 19:43:11 +01:00
* eTemplate we edit
2006-04-20 19:12:30 +02:00
*
2008-03-20 19:43:11 +01:00
* @ var etemplate
2006-04-20 19:12:30 +02:00
*/
2008-03-20 19:43:11 +01:00
var $etemplate ;
2005-02-13 14:03:36 +01:00
/**
2008-03-20 19:43:11 +01:00
* editor eTemplate
2005-02-13 14:03:36 +01:00
*
2008-03-20 19:43:11 +01:00
* @ var etemplate
2005-02-13 14:03:36 +01:00
*/
2008-03-20 19:43:11 +01:00
var $editor ;
var $aligns = array (
'' => 'Left' ,
'right' => 'Right' ,
'center' => 'Center' ,
);
var $valigns = array (
'' => 'Middle' ,
'top' => 'Top' ,
'bottom' => 'Bottom' ,
'baseline' => 'Baseline' ,
);
2009-02-23 14:21:28 +01:00
var $parts = array (
'' => 'Body' ,
'header' => 'Header' ,
'footer' => 'Footer' ,
);
2008-03-20 19:43:11 +01:00
var $edit_menu = array (
'delete' => 'delete' ,
'cut' => 'cut' ,
'copy' => 'copy' ,
'paste' => 'paste' ,
'swap' => 'swap' ,
);
var $row_menu = array (
'row_delete' => 'delete this row' ,
'row_insert_above' => 'insert a row above' ,
'row_insert_below' => 'insert a row below' ,
'row_swap_next' => 'swap with next row' ,
);
var $column_menu = array (
'column_delete' => 'delete this column' ,
'column_insert_before' => 'insert a column before' ,
'column_insert_behind' => 'insert a column behind' ,
'column_swap_next' => 'swap with next column' ,
);
var $box_menu = array (
'box_insert_before' => 'insert a widget before' ,
'box_insert_behind' => 'insert a widget behind' ,
'box_swap_next' => 'swap widget with next one' ,
);
var $options = array (
'width' ,
'height' ,
'border' ,
'class' ,
'spacing' ,
'padding' ,
'overflow'
);
var $overflows = array (
'' => 'visible' ,
'hidden' => 'hidden' ,
'scroll' => 'scroll' ,
'auto' => 'auto'
);
var $onclick_types = array (
'' => 'nothing' ,
'confirm' => 'confirm' ,
'popup' => 'popup' ,
'custom' => 'custom' ,
);
var $onchange_types = array (
'' => 'nothing' ,
'submit' => 'submit form' ,
'custom' => 'custom' ,
);
var $extensions = '' ;
var $public_functions = array
(
'edit' => True ,
'widget' => True ,
'styles' => True ,
);
2008-10-07 20:04:59 +02:00
function __construct ()
2002-02-06 10:03:11 +01:00
{
2008-10-07 20:04:59 +02:00
$this -> etemplate = new etemplate ();
2002-02-06 10:03:11 +01:00
2008-03-20 19:43:11 +01:00
$this -> extensions = $GLOBALS [ 'egw' ] -> session -> appsession ( 'extensions' , 'etemplate' );
}
function export_xml ( & $xml , & $xml_label )
{
$name = $this -> etemplate -> name ;
$template = $this -> etemplate -> template != '' ? $this -> etemplate -> template : 'default' ;
list ( $app ) = explode ( '.' , $name );
2002-02-06 10:03:11 +01:00
2008-03-20 19:43:11 +01:00
if ( ! is_object ( $this -> etemplate -> xul_io ))
2002-02-06 10:03:11 +01:00
{
2008-03-20 19:43:11 +01:00
$this -> etemplate -> xul_io =& CreateObject ( 'etemplate.xul_io' );
}
$xml = $this -> etemplate -> xul_io -> export ( $this -> etemplate );
2002-02-06 10:03:11 +01:00
2008-03-20 19:43:11 +01:00
$dir = EGW_SERVER_ROOT . " / $app /templates/ $template " ;
if (( $create_it = ! is_dir ( $dir )))
{
$dir = EGW_SERVER_ROOT . " / $app /templates " ;
}
if ( ! is_writeable ( $dir ))
{
return lang ( " Error: webserver is not allowed to write into '%1' !!! " , $dir );
}
if ( $create_it )
{
mkdir ( $dir .= " / $template " );
}
$file = $dir . '/' . substr ( $name , strlen ( $app ) + 1 );
if ( $this -> etemplate -> lang )
{
$file .= '.' . $this -> etemplate -> lang ;
}
$old_file = $file . '.old.xet' ;
$file .= '.xet' ;
if ( file_exists ( $file ))
{
if ( file_exists ( $old_file ))
{
unlink ( $old_file );
}
rename ( $file , $old_file );
2002-02-06 10:03:11 +01:00
}
2008-03-20 19:43:11 +01:00
if ( ! ( $f = fopen ( $xml_label = $file , 'w' )))
{
return 0 ;
}
if ( ! is_object ( $this -> etemplate -> xul_io ))
2002-09-12 02:35:20 +02:00
{
2008-03-20 19:43:11 +01:00
$this -> etemplate -> xul_io =& CreateObject ( 'etemplate.xul_io' );
}
$xml = $this -> etemplate -> xul_io -> export ( $this -> etemplate );
2002-09-12 02:35:20 +02:00
2008-03-20 19:43:11 +01:00
fwrite ( $f , $xml );
fclose ( $f );
2002-09-12 02:35:20 +02:00
2008-03-20 19:43:11 +01:00
return lang ( " eTemplate '%1' written to '%2' " , $name , $file );
}
function import_xml ( $file , & $xml )
{
if ( $file == 'none' || $file == '' || ! ( $f = fopen ( $file , 'r' )))
{
return lang ( 'no filename given or selected via Browse...' ) . " file=' $file ' " ;
}
$xml = fread ( $f , filesize ( $file ));
fclose ( $f );
if ( ! is_object ( $this -> etemplate -> xul_io ))
{
$this -> etemplate -> xul_io =& CreateObject ( 'etemplate.xul_io' );
}
$imported = $this -> etemplate -> xul_io -> import ( $this -> etemplate , $xml );
$this -> etemplate -> modified = @ filemtime ( $f );
$this -> etemplate -> modified_set = 'xul-import' ;
2005-02-18 23:44:42 +01:00
2008-03-20 19:43:11 +01:00
if ( is_array ( $imported ))
{
if ( count ( $imported ) == 1 )
2002-09-12 02:35:20 +02:00
{
2008-03-20 19:43:11 +01:00
$imported = lang ( " eTemplate '%1' imported, use Save to put it in the database " , $this -> etemplate -> name );
2002-09-12 02:35:20 +02:00
}
2008-03-20 19:43:11 +01:00
else
2002-09-12 02:35:20 +02:00
{
2008-03-20 19:43:11 +01:00
$imported = lang ( 'File contains more than one eTemplate, last one is shown !!!' );
2002-09-12 02:35:20 +02:00
}
2008-03-20 19:43:11 +01:00
}
return $imported ;
}
function list_result ( $cont = '' , $msg = '' )
{
if ( $this -> debug )
{
echo " <p>etemplate.editor.list_result: cont= " ; _debug_array ( $cont );
}
if ( ! $cont || ! is_array ( $cont ))
{
return $this -> edit ( 'error' );
}
if ( ! isset ( $cont [ 'result' ]) || isset ( $cont [ 'search' ]))
{
$cont [ 'result' ] = $this -> etemplate -> search ( $cont );
}
$result = $cont [ 'result' ];
if ( isset ( $cont [ 'delete' ]))
{
list ( $delete ) = each ( $cont [ 'delete' ]);
$this -> etemplate -> init ( $result [ $delete - 1 ]);
if ( $this -> etemplate -> delete ())
2002-09-12 02:35:20 +02:00
{
2008-03-20 19:43:11 +01:00
$msg = lang ( 'Template deleted' );
unset ( $result [ $delete - 1 ]);
$result = array_values ( $result );
2002-09-12 02:35:20 +02:00
}
2008-03-20 19:43:11 +01:00
else
2002-09-12 02:35:20 +02:00
{
2008-03-20 19:43:11 +01:00
$msg = lang ( 'Error: Template not found !!!' );
2002-09-12 02:35:20 +02:00
}
2008-03-20 19:43:11 +01:00
}
if ( isset ( $cont [ 'delete_selected' ]))
{
foreach ( $cont [ 'selected' ] as $row => $sel )
2002-09-12 02:35:20 +02:00
{
2008-03-20 19:43:11 +01:00
if ( $sel )
2003-07-21 18:09:33 +02:00
{
2008-03-20 19:43:11 +01:00
$this -> etemplate -> init ( $result [ $row - 1 ]);
if ( $this -> etemplate -> delete ())
{
unset ( $result [ $row - 1 ]);
++ $n ;
}
2003-07-21 18:09:33 +02:00
}
2002-09-12 02:35:20 +02:00
}
2008-03-20 19:43:11 +01:00
if ( $n )
2002-09-17 15:27:37 +02:00
{
2008-03-20 19:43:11 +01:00
$msg = lang ( '%1 eTemplates deleted' , $n );
2002-09-17 15:27:37 +02:00
}
2008-03-20 19:43:11 +01:00
unset ( $cont [ 'selected' ]);
unset ( $cont [ 'delete_selected' ]);
$result = array_values ( $result );
}
if ( isset ( $cont [ 'read' ]))
{
list ( $read ) = each ( $cont [ 'read' ]);
$this -> etemplate -> read ( $result [ $read - 1 ]);
$this -> edit ();
return ;
}
if ( ! $msg )
{
$msg = lang ( '%1 eTemplates found' , count ( $result ));
}
unset ( $cont [ 'result' ]);
if ( ! isset ( $cont [ 'name' ]))
{
$cont += $this -> etemplate -> as_array ();
}
$content = $cont + array ( 'msg' => $msg );
2002-09-12 02:35:20 +02:00
2008-03-20 19:43:11 +01:00
reset ( $result );
for ( $row = 1 ; list (, $param ) = each ( $result ); ++ $row )
{
$content [ $row ] = $param ;
2002-09-12 12:04:22 +02:00
}
2009-06-08 18:21:14 +02:00
$list_result = new etemplate ( 'etemplate.editor.list_result' );
2008-03-20 19:43:11 +01:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] = lang ( 'Editable Templates - Search' );
$list_result -> exec ( 'etemplate.editor.list_result' , $content , '' , '' , array (
'result' => $result ,
), '' );
}
2002-09-12 12:04:22 +02:00
2008-03-20 19:43:11 +01:00
/**
* new eTemplate editor , which edits widgets in a popup
*
* @ param array $content content from the process_exec call
* @ param string $msg message to show
*/
function edit ( $content = null , $msg = '' )
{
if ( $this -> debug )
2002-09-12 12:04:22 +02:00
{
2008-03-20 19:43:11 +01:00
echo " <p>etemplate.editor.show: content= " ; _debug_array ( $content );
}
if ( ! is_array ( $content )) $content = array ();
$preserv = array ();
2002-09-12 12:04:22 +02:00
2008-03-20 19:43:11 +01:00
if ( $content [ 'import_xml' ])
{
$msg .= $this -> import_xml ( $content [ 'file' ][ 'tmp_name' ], $xml );
//$this->etemplate->echo_tmpl();
$xml_label = $content [ 'file' ][ 'name' ];
$preserv [ 'import' ] = $this -> etemplate -> as_array ( 1 );
}
elseif ( is_array ( $content [ 'import' ]) && ! $content [ 'read' ]) // imported not yet saved tmpl
{
$this -> etemplate -> init ( $content [ 'import' ]);
$preserv [ 'import' ] = $content [ 'import' ];
}
if ( $content [ 'save' ])
{
if ( ! is_array ( $content [ 'import' ])) $this -> etemplate -> read ( $content [ 'old_keys' ]);
2002-09-12 12:04:22 +02:00
2008-03-20 19:43:11 +01:00
if ( ! $this -> etemplate -> modified_set || ! $this -> etemplate -> modified )
2002-09-12 12:04:22 +02:00
{
2008-03-20 19:43:11 +01:00
$this -> etemplate -> modified = time ();
2002-09-12 12:04:22 +02:00
}
2008-03-20 19:43:11 +01:00
$ok = $this -> etemplate -> save ( trim ( $content [ 'name' ]), trim ( $content [ 'template' ]), trim ( $content [ 'lang' ]),( int ) $content [ 'group' ], trim ( $content [ 'version' ]));
$msg = $ok ? lang ( 'Template saved' ) : lang ( 'Error: while saving !!!' );
if ( $ok ) unset ( $preserv [ 'import' ]);
2002-09-12 02:35:20 +02:00
}
2008-03-20 19:43:11 +01:00
elseif ( ! $content [ 'import_xml' ] && ( isset ( $_GET [ 'name' ]) || isset ( $content [ 'name' ])))
2002-09-04 00:59:47 +02:00
{
2008-03-20 19:43:11 +01:00
if ( $_GET [ 'name' ])
2002-09-04 00:59:47 +02:00
{
2008-03-20 19:43:11 +01:00
foreach ( etemplate :: $db_key_cols as $var )
2005-05-07 16:05:10 +02:00
{
2008-03-20 19:43:11 +01:00
$content [ $var ] = $_GET [ $var ];
2005-05-07 16:05:10 +02:00
}
2002-09-04 00:59:47 +02:00
}
2008-03-20 19:43:11 +01:00
if ( $content [ 'version' ] != '' )
2002-10-28 02:17:32 +01:00
{
2008-03-20 19:43:11 +01:00
$save_version = $content [ 'version' ];
unset ( $content [ 'version' ]);
$this -> etemplate -> read ( $content );
$newest_version = $this -> etemplate -> version ;
$content [ 'version' ] = $save_version ;
}
if ( ! $this -> etemplate -> read ( $content ))
{
if ( isset ( $content [ 'name' ]))
2002-10-28 02:17:32 +01:00
{
2008-03-20 19:43:11 +01:00
$version_backup = $content [ 'version' ];
$content [ 'version' ] = '' ; // trying it without version
if ( $this -> etemplate -> read ( $content ))
{
$msg = lang ( 'only an other Version found !!!' );
}
else
2002-10-28 02:17:32 +01:00
{
2008-03-20 19:43:11 +01:00
$result = $this -> etemplate -> search ( $content );
if ( count ( $result ) > 1 )
{
return $this -> list_result ( array ( 'result' => $result ));
}
elseif ( ! count ( $result ) || ! $this -> etemplate -> read ( $result [ 0 ]))
2005-02-20 22:45:24 +01:00
{
2008-03-20 19:43:11 +01:00
$msg = lang ( 'Error: Template not found !!!' );
$this -> etemplate -> version = $content [ 'version' ] = $version_backup ;
}
elseif ( $content [ 'name' ] == $result [ 0 ][ 'name' ])
{
$msg = lang ( 'only an other Version found !!!' );
2005-02-20 22:45:24 +01:00
}
2002-10-28 02:17:32 +01:00
}
}
2008-03-20 19:43:11 +01:00
else
2002-10-28 02:17:32 +01:00
{
2008-03-20 19:43:11 +01:00
$msg = lang ( 'Error: Template not found !!!' );
2002-10-28 02:17:32 +01:00
}
2005-02-16 00:22:10 +01:00
}
2008-03-20 19:43:11 +01:00
elseif ( $newest_version != '' && $this -> etemplate -> version != $newest_version )
2002-09-04 00:59:47 +02:00
{
2008-03-20 19:43:11 +01:00
$link = $this -> etemplate -> as_array ( - 1 );
$link [ 'menuaction' ] = 'etemplate.editor.edit' ;
$link [ 'version' ] = $newest_version ;
$msg = lang ( " newer version '%1' exists !!! " , html :: a_href ( $newest_version , $link ));
2002-09-04 00:59:47 +02:00
}
2008-03-20 19:43:11 +01:00
}
if ( ! is_array ( $this -> extensions ))
{
if (( $extensions = $this -> scan_for_extensions ()))
2002-09-04 00:59:47 +02:00
{
2008-03-20 19:43:11 +01:00
$msg .= lang ( 'Extensions loaded:' ) . ' ' . $extensions ;
$msg_ext_loaded = True ;
2002-09-04 00:59:47 +02:00
}
2008-03-20 19:43:11 +01:00
}
list ( $app ) = explode ( '.' , $this -> etemplate -> name );
if ( $app && $app != 'etemplate' )
{
$GLOBALS [ 'egw' ] -> translation -> add_app ( $app ); // load translations for app
2002-09-04 00:59:47 +02:00
2008-03-20 19:43:11 +01:00
if (( $extensions = $this -> scan_for_extensions ( $app )))
2002-09-04 00:59:47 +02:00
{
2008-03-20 19:43:11 +01:00
$msg .= ( ! $msg_ext_loaded ? lang ( 'Extensions loaded:' ) . ' ' : ', ' ) . $extensions ;
2002-09-04 00:59:47 +02:00
}
2002-02-06 10:03:11 +01:00
}
2008-03-20 19:43:11 +01:00
if ( ! $msg && $content [ 'delete' ])
{
if ( ! $content [ 'version' ] && $this -> etemplate -> version )
2002-06-09 23:33:07 +02:00
{
2008-03-20 19:43:11 +01:00
$this -> etemplate -> version = '' ; // else the newest would get deleted and not the one without version
2002-06-09 23:33:07 +02:00
}
2008-03-20 19:43:11 +01:00
$ok = $this -> etemplate -> delete ();
$msg = $ok ? lang ( 'Template deleted' ) : lang ( 'Error: Template not found !!!' );
$preserv [ 'import' ] = $this -> etemplate -> as_array ( 1 ); // that way the content can be saved again
}
elseif ( $content [ 'dump' ])
{
if ( empty ( $app ) || !@ is_dir ( EGW_SERVER_ROOT . '/' . $app ))
2002-02-17 20:09:15 +01:00
{
2008-03-20 19:43:11 +01:00
$msg .= lang ( 'Application name needed to write a langfile or dump the eTemplates !!!' );
2002-02-17 20:09:15 +01:00
}
2008-03-20 19:43:11 +01:00
else
2002-10-19 13:03:00 +02:00
{
2008-03-20 19:43:11 +01:00
$msg .= $this -> etemplate -> dump4setup ( $app );
2002-10-19 13:03:00 +02:00
}
2008-03-20 19:43:11 +01:00
}
elseif ( $content [ 'langfile' ])
{
if ( empty ( $app ) || !@ is_dir ( EGW_SERVER_ROOT . '/' . $app ))
2002-02-06 10:03:11 +01:00
{
2008-03-20 19:43:11 +01:00
$msg = lang ( 'Application name needed to write a langfile or dump the eTemplates !!!' );
2005-02-22 22:02:26 +01:00
}
2008-03-20 19:43:11 +01:00
else
2005-02-22 22:02:26 +01:00
{
2008-03-20 19:43:11 +01:00
$additional = array ();
if ( $app == 'etemplate' )
2005-02-22 22:02:26 +01:00
{
2009-03-16 13:58:24 +01:00
$additional = etemplate :: $types + $this -> extensions + $this -> aligns + $this -> valigns +
2008-03-20 19:43:11 +01:00
$this -> edit_menu + $this -> box_menu + $this -> row_menu + $this -> column_menu + $this -> onclick_types + $this -> onchange_types ;
2005-02-22 22:02:26 +01:00
}
2008-03-20 19:43:11 +01:00
else // try to call the writeLangFile function of the app's ui-layer
2005-02-22 22:02:26 +01:00
{
2008-03-20 19:43:11 +01:00
foreach ( array ( 'ui' . $name , 'ui' , $name , 'bo' . $name ) as $class )
2005-02-16 00:22:10 +01:00
{
2008-03-20 19:43:11 +01:00
if ( file_exists ( EGW_INCLUDE_ROOT . '/' . $name . '/inc/class.' . $class . '.inc.php' ) &&
( $ui =& CreateObject ( $name . '.' . $class )) && is_object ( $ui ))
2005-02-16 00:22:10 +01:00
{
2008-03-20 19:43:11 +01:00
break ;
2005-02-16 00:22:10 +01:00
}
}
2008-03-20 19:43:11 +01:00
if ( is_object ( $ui ) && @ $ui -> public_functions [ 'writeLangFile' ])
2005-05-07 16:05:10 +02:00
{
2008-03-20 19:43:11 +01:00
$msg = " $class ::writeLangFile: " . $ui -> writeLangFile ();
2005-05-07 16:05:10 +02:00
}
2008-03-20 19:43:11 +01:00
unset ( $ui );
2002-09-12 12:58:20 +02:00
}
2008-03-20 19:43:11 +01:00
//if (empty($msg))
2005-02-22 22:02:26 +01:00
{
2008-03-20 19:43:11 +01:00
$msg = $this -> etemplate -> writeLangFile ( $app , 'en' , $additional );
2005-02-22 22:02:26 +01:00
}
2002-02-06 10:03:11 +01:00
}
2008-03-20 19:43:11 +01:00
}
elseif ( $content [ 'export_xml' ])
{
$msg .= $this -> export_xml ( $xml , $xml_label );
}
$new_content = $this -> etemplate -> as_array () + array (
'msg' => $msg ,
'xml_label' => $xml_label ,
'xml' => $xml ? '<pre>' . html :: htmlspecialchars ( $xml ) . " </pre> \n " : '' ,
);
2009-06-08 18:21:14 +02:00
$editor = new etemplate ( 'etemplate.editor.new' );
2008-03-20 19:43:11 +01:00
if ( ! $msg && isset ( $content [ 'values' ]) && ! isset ( $content [ 'vals' ]))
{
$r = 1 ;
foreach (( array ) $content [ 'cont' ] as $key => $val )
2002-02-06 10:03:11 +01:00
{
2008-03-20 19:43:11 +01:00
$vals [ " @ $r " ] = $key ;
$vals [ " A $r " ] = is_array ( $val ) ? serialize ( $val ) . '#SeR#' : $val ;
++ $r ;
2002-02-06 10:03:11 +01:00
}
2008-03-20 19:43:11 +01:00
$editor -> data [ $editor -> rows ][ 'A' ][ 'name' ] = 'etemplate.editor.values' ;
$editor -> data [ $editor -> rows ][ 'A' ][ 'size' ] = 'vals' ;
$new_content [ 'vals' ] = $vals ;
}
else
{
// set onclick handler
$this -> etemplate -> onclick_handler = " edit_widget('%p'); " ;
// setting the javascript via the content, allows looping too
$new_content [ 'onclick' ] = '
< script language = " javascript " >
function edit_widget ( path )
2005-02-20 22:45:24 +01:00
{
2008-03-20 19:43:11 +01:00
var url = " '. $GLOBALS['egw'] ->link('/index.php', $this->etemplate ->as_array(-1)+array(
'menuaction' => 'etemplate.editor.widget' ,
)) . ' " ;
url = url . replace ( / index . php\\ ? / , " index.php?path= " + path + " & " );
window . open ( url , " etemplate_editor_widget " , " dependent=yes,width=640,height=480,location=no,menubar=no,toolbar=no,scrollbars=yes,status=yes " );
2005-02-20 22:45:24 +01:00
}
2008-03-20 19:43:11 +01:00
</ script > ' ;
if ( $app != 'etemplate' && file_exists ( EGW_SERVER_ROOT . '/' . $app . '/templates/default/app.css' ))
2005-02-20 22:45:24 +01:00
{
2008-03-20 19:43:11 +01:00
$new_content [ 'onclick' ] .= html :: style ( '@import url(' . $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ] . '/' . $app . '/templates/default/app.css);' );
2005-02-20 22:45:24 +01:00
}
2009-07-03 10:38:25 +02:00
// check if application of template has a app.js file --> load it
if ( file_exists ( EGW_SERVER_ROOT . '/' . $app . '/js/app.js' ))
{
$GLOBALS [ 'egw' ] -> js -> validate_file ( '.' , 'app' , $app , false );
}
2008-03-20 19:43:11 +01:00
$editor -> data [ $editor -> rows ][ 'A' ][ 'obj' ] = & $this -> etemplate ;
$vals = $content [ 'vals' ];
$olds = $content [ 'olds' ];
for ( $r = 1 ; isset ( $vals [ " A $r " ]); ++ $r )
2005-02-20 22:45:24 +01:00
{
2008-03-20 19:43:11 +01:00
$new_content [ 'cont' ][ $olds [ " @ $r " ]] = substr ( $vals [ " A $r " ], - 5 ) == '#SeR#' ?
unserialize ( substr ( $vals [ " A $r " ], 0 , - 5 )) : $vals [ " A $r " ];
2005-02-20 22:45:24 +01:00
}
2008-03-20 19:43:11 +01:00
}
2009-05-14 19:45:00 +02:00
// check if bo class of $app exists and has a labels method --> add labels to content to display them in the editor
if ( class_exists ( $app . '_bo' ) && method_exists ( $app . '_bo' , 'labels' ))
{
$new_content [ 'labels' ] = ExecMethod ( $acm = $app . '.' . $app . '_bo.labels' );
$new_content [ 'cont' ][ 'labels' ] =& $new_content [ 'labels' ];
//echo $acm; _debug_array($new_content['labels']);
}
2008-03-20 19:43:11 +01:00
$preserv [ 'olds' ] = $vals ;
$preserv [ 'old_keys' ] = $this -> etemplate -> as_array ( - 1 ); // in case we do a save as
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] = lang ( 'Editable Templates - Show Template' );
$editor -> exec ( 'etemplate.editor.edit' , $new_content , array (), '' , $preserv , 0 , '/^cont/' );
}
/**
* initialises the children arrays for the new widget type , converts boxes <--> grids
*
2008-10-07 20:04:59 +02:00
* @ internal
2008-03-20 19:43:11 +01:00
* @ param array & $widget reference to the new widget data
* @ param array $old the old widget data
*/
function change_widget_type ( & $widget , $old )
{
//echo "<p>editor::change_widget_type($widget[type]=$old[type])</p>\n";
$old_type = $old [ 'type' ];
$old_had_children = isset ( etemplate :: $widgets_with_children [ $old_type ]);
if ( ! isset ( etemplate :: $widgets_with_children [ $widget [ 'type' ]]) ||
( $old_type == 'grid' ) == ( $widget [ 'type' ] == 'grid' ))
{
if ( etemplate :: $widgets_with_children [ $widget [ 'type' ]] == 'box' ) // box
2005-02-20 22:45:24 +01:00
{
2008-03-20 19:43:11 +01:00
if (( int ) $widget [ 'size' ] < 1 ) // min. 1 child
2005-02-20 22:45:24 +01:00
{
2008-03-20 19:43:11 +01:00
list (, $options ) = explode ( ',' , $widget [ 'size' ], 2 );
$widget [ 'size' ] = '1' . ( $options ? ',' . $options : '' );
2005-02-20 22:45:24 +01:00
}
2008-03-20 19:43:11 +01:00
// create the needed cells, if they dont exist
for ( $n = 1 ; $n <= ( int ) $widget [ 'size' ]; ++ $n )
2005-02-20 22:45:24 +01:00
{
2008-03-20 19:43:11 +01:00
if ( ! is_array ( $widget [ $n ])) $widget [ $n ] = $n == 1 ? $old : etemplate :: empty_cell ();
2005-02-20 22:45:24 +01:00
}
2008-03-20 19:43:11 +01:00
unset ( $widget [ 'onclick' ]); // not valid for a box
2005-02-20 22:45:24 +01:00
}
2008-03-20 19:43:11 +01:00
return ; // no change necessary, eg. between different box-types
}
switch ( etemplate :: $widgets_with_children [ $widget [ 'type' ]])
{
case 'grid' :
$widget [ 'data' ] = array ( array ());
$widget [ 'cols' ] = $widget [ 'rows' ] = 0 ;
2002-02-06 10:03:11 +01:00
2008-03-20 19:43:11 +01:00
if ( $old_had_children ) // box --> grid: hbox --> 1 row, other boxes --> 1 column
2002-02-06 10:03:11 +01:00
{
2008-03-20 19:43:11 +01:00
list ( $num ) = explode ( ',' , $old [ 'size' ]);
for ( $n = 1 ; is_array ( $old [ $n ]) && $n <= $num ; ++ $n )
2005-02-16 00:22:10 +01:00
{
2008-03-20 19:43:11 +01:00
$new_line = null ;
if ( $old_type != 'hbox' ) etemplate :: add_child ( $widget , $new_line );
etemplate :: add_child ( $widget , $old [ $n ]);
unset ( $widget [ $n ]);
2005-02-16 00:22:10 +01:00
}
2008-03-20 19:43:11 +01:00
$widget [ 'size' ] = '' ;
2005-04-15 00:08:25 +02:00
}
2008-03-20 19:43:11 +01:00
else // 1 row with 1 column/child
2002-02-06 10:03:11 +01:00
{
2008-03-20 19:43:11 +01:00
etemplate :: add_child ( $widget , $cell = etemplate :: empty_cell ());
2002-02-06 10:03:11 +01:00
}
2008-03-20 19:43:11 +01:00
break ;
2005-02-22 22:02:26 +01:00
2008-03-20 19:43:11 +01:00
case 'box' :
$widget [ 'size' ] = 0 ;
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
if ( $old_type == 'grid' )
2005-02-27 22:32:43 +01:00
{
2008-03-20 19:43:11 +01:00
if ( preg_match ( '/,(vertical|horizontal)/' , $widget [ 'size' ], $matches ))
2005-02-20 22:45:24 +01:00
{
2008-03-20 19:43:11 +01:00
$orient = $matches [ 1 ];
2005-02-20 22:45:24 +01:00
}
2008-03-20 19:43:11 +01:00
else
2005-02-20 22:45:24 +01:00
{
2008-03-20 19:43:11 +01:00
$orient = $widget [ 'type' ] == 'hbox' ? 'horizontal' : 'vertical' ;
2005-02-20 22:45:24 +01:00
}
2008-03-20 19:43:11 +01:00
if ( $orient == 'horizontal' ) // ==> use first row
2005-02-20 22:45:24 +01:00
{
2008-03-20 19:43:11 +01:00
$row =& $old [ 'data' ][ 1 ];
for ( $n = 0 ; $n < $old [ 'cols' ]; ++ $n )
2005-02-22 22:02:26 +01:00
{
2008-03-20 19:43:11 +01:00
$cell =& $row [ etemplate :: num2chrs ( $n )];
etemplate :: add_child ( $widget , $cell );
list ( $span ) = ( int ) explode ( ',' , $cell [ 'span' ]);
if ( $span == 'all' ) break ;
while ( $span -- > 1 ) ++ $n ;
2005-02-22 22:02:26 +01:00
}
2005-02-20 22:45:24 +01:00
}
2008-03-20 19:43:11 +01:00
else // vertical ==> use 1 column
2005-02-16 00:22:10 +01:00
{
2008-03-20 19:43:11 +01:00
for ( $n = 1 ; $n <= $old [ 'rows' ]; ++ $n )
2005-02-16 00:22:10 +01:00
{
2008-03-20 19:43:11 +01:00
etemplate :: add_child ( $widget , $old [ 'data' ][ $n ][ etemplate :: num2chrs ( 0 )]);
2005-02-16 00:22:10 +01:00
}
}
2008-03-20 19:43:11 +01:00
}
if ( ! $widget [ 'size' ]) // minimum one child
{
etemplate :: add_child ( $widget , etemplate :: empty_cell ());
}
break ;
2005-02-16 00:22:10 +01:00
}
2008-03-20 19:43:11 +01:00
//_debug_array($widget);
}
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
/**
* returns array with path => type pairs for each parent of $path
*
* @ param string $path path to the widget not the parent !
2008-10-07 20:04:59 +02:00
* @ return array
2008-03-20 19:43:11 +01:00
*/
function path_components ( $path )
{
$path_parts = explode ( '/' , $path );
array_pop ( $path_parts ); // removed the widget itself
array_shift ( $path_parts ); // removed the leading empty string
2005-02-18 23:44:42 +01:00
2008-03-20 19:43:11 +01:00
$components = array ();
$part_path = '' ;
foreach ( $path_parts as $part )
{
$part_path .= '/' . $part ;
$parent =& $this -> etemplate -> get_widget_by_path ( $part_path );
$components [ $part_path ] = $parent [ 'type' ];
2005-02-18 23:44:42 +01:00
}
2008-03-20 19:43:11 +01:00
return $components ;
}
2005-02-16 00:22:10 +01:00
2008-03-20 19:43:11 +01:00
/**
* returns array with path => type pairs for each parent of $path
*
* @ param array $parent the parent
* @ param string $child_id id of child
* @ param string $parent_path path of the parent
* @ return array with keys left , right , up and down and their pathes set ( if applicable )
*/
function parent_navigation ( $parent , $parent_path , $child_id , $widget )
{
if ( $parent [ 'type' ] == 'grid' && preg_match ( '/^([0-9]+)([A-Z]+)$/' , $child_id , $matches ))
{
list (, $r , $c ) = $matches ;
// find the column-number (base 0) for $c (A, B, C, ...)
for ( $col = 0 ; etemplate :: num2chrs ( $col ) != $c && $col < 100 ; ++ $col ) ;
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
if ( $col > 0 ) $left = $parent_path . '/' . $r . etemplate :: num2chrs ( $col - 1 );
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
if ( $col < $parent [ 'cols' ] - 1 ) $right = $parent_path . '/' . $r . etemplate :: num2chrs ( $col + 1 );
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
if ( $r > 1 ) $up = $parent_path . '/' . ( $r - 1 ) . $c ;
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
if ( $r < $parent [ 'rows' ]) $down = $parent_path . '/' . ( $r + 1 ) . $c ;
}
elseif ( $parent [ 'type' ]) // any box
{
if ( $child_id > 1 ) $previous = $parent_path . '/' . ( $child_id - 1 );
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
if ( $child_id < ( int ) $parent [ 'size' ]) $next = $parent_path . '/' . ( $child_id + 1 );
}
else // template
{
if ( $child_id > 0 ) $previous = '/' . ( $child_id - 1 );
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
if ( $child_id < count ( $this -> etemplate -> children ) - 1 ) $next = '/' . ( $child_id + 1 );
}
if ( $widget [ 'type' ] == 'grid' )
{
$in = $parent_path . '/' . $child_id . '/1A' ;
}
elseif ( isset ( etemplate :: $widgets_with_children [ $widget [ 'type' ]]) && $widget [ 'type' ] != 'template' )
{
if ( $widget [ 'type' ]) // box
2005-02-18 23:44:42 +01:00
{
2008-03-20 19:43:11 +01:00
$in = $parent_path . '/' . $child_id . '/1' ;
2005-02-18 23:44:42 +01:00
}
2008-03-20 19:43:11 +01:00
else
2005-02-18 23:44:42 +01:00
{
2008-03-20 19:43:11 +01:00
$in = '/0' ;
2005-02-18 23:44:42 +01:00
}
2008-03-20 19:43:11 +01:00
}
$navi = array ();
foreach ( array ( 'left' => '←' , 'up' => ' ↑ ' , 'down' => ' ↓ ' ,
'right' => '→' , 'previous' => '←↑' , 'next' => '↓→' , 'in' => '×' ) as $var => $dir )
{
if ( $$var ) $navi [ $$var ] = $dir ;
}
return $navi ;
}
/**
* functions of the edit - menu : paste , swap , cut , delete , copy
*
2008-10-07 20:04:59 +02:00
* @ internal
2008-03-20 19:43:11 +01:00
* @ param string & $action row_delete , row_insert_above , row_insert_below , row_swap , row_prefs
* @ param array & $parent referece to the parent
* @ param array & $content reference to the content - array
* @ param string $child_id id of a cell
* @ return string msg to display
*/
function edit_actions ( & $action , & $parent , & $content , $child_id )
{
switch ( $action )
{
case 'paste' :
case 'swap' :
$clipboard = $GLOBALS [ 'egw' ] -> session -> appsession ( 'clipboard' , 'etemplate' );
if ( ! is_array ( $clipboard ))
2005-02-16 00:22:10 +01:00
{
2008-03-20 19:43:11 +01:00
return lang ( 'nothing in clipboard to paste !!!' );
2005-02-16 00:22:10 +01:00
}
2008-03-20 19:43:11 +01:00
if ( $action == 'swap' )
2005-02-16 00:22:10 +01:00
{
2008-03-20 19:43:11 +01:00
$GLOBALS [ 'egw' ] -> session -> appsession ( 'clipboard' , 'etemplate' , $content [ 'cell' ]);
2005-02-18 23:44:42 +01:00
}
2008-03-20 19:43:11 +01:00
$content [ 'cell' ] = $clipboard ;
break ;
2005-02-18 23:44:42 +01:00
2008-03-20 19:43:11 +01:00
case 'copy' :
case 'cut' :
$GLOBALS [ 'egw' ] -> session -> appsession ( 'clipboard' , 'etemplate' , $content [ 'cell' ]);
if ( $action != 'cut' )
{
return lang ( 'widget copied into clipboard' );
}
// fall-through
case 'delete' :
if ( $parent [ 'type' ] != 'grid' )
{
// delete widget from parent
if ( $parent [ 'type' ]) // box
2005-02-18 23:44:42 +01:00
{
2008-03-20 19:43:11 +01:00
list ( $num , $options ) = explode ( ',' , $parent [ 'size' ], 2 );
if ( $num <= 1 ) // cant delete last child --> only empty it
2005-02-16 00:22:10 +01:00
{
2008-03-20 19:43:11 +01:00
$parent [ $num = 1 ] = etemplate :: empty_cell ();
2005-02-16 00:22:10 +01:00
}
2008-03-20 19:43:11 +01:00
else
2005-02-16 00:22:10 +01:00
{
2008-03-20 19:43:11 +01:00
for ( $n = $child_id ; $n < $num ; ++ $n )
2005-02-18 23:44:42 +01:00
{
2008-03-20 19:43:11 +01:00
$parent [ $n ] = $parent [ 1 + $n ];
2005-02-18 23:44:42 +01:00
}
2008-03-20 19:43:11 +01:00
unset ( $parent [ $num -- ]);
2005-02-16 00:22:10 +01:00
}
2008-03-20 19:43:11 +01:00
$parent [ 'size' ] = $num . ( $options ? ',' . $options : '' );
2005-02-18 23:44:42 +01:00
}
2008-03-20 19:43:11 +01:00
else // template itself
2005-02-18 23:44:42 +01:00
{
2008-03-20 19:43:11 +01:00
if ( count ( $this -> etemplate -> children ) <= 1 ) // cant delete last child
2005-02-16 00:22:10 +01:00
{
2008-03-20 19:43:11 +01:00
$this -> etemplate -> children [ 0 ] = etemplate :: empty_cell ();
2005-02-16 00:22:10 +01:00
}
2008-03-20 19:43:11 +01:00
else
2005-02-16 00:22:10 +01:00
{
2008-03-20 19:43:11 +01:00
unset ( $parent [ $child_id ]);
$this -> etemplate -> children = array_values ( $this -> etemplate -> children );
2005-02-16 00:22:10 +01:00
}
2005-02-18 23:44:42 +01:00
}
2008-03-20 19:43:11 +01:00
$action = 'save-no-merge' ;
}
else
{
$content [ 'cell' ] = etemplate :: empty_cell ();
return lang ( 'cant delete a single widget from a grid !!!' );
}
break ;
2005-02-18 23:44:42 +01:00
}
2008-03-20 19:43:11 +01:00
return '' ;
}
2005-02-18 23:44:42 +01:00
2008-03-20 19:43:11 +01:00
/**
* functions of the box - menu : insert - before , - behind und swap
*
2008-10-07 20:04:59 +02:00
* @ internal
2008-03-20 19:43:11 +01:00
* @ param string & $action row_delete , row_insert_above , row_insert_below , row_swap , row_prefs
* @ param array & $parent referece to the parent
* @ param array & $content reference to the content - array
* @ param string & $child_id id of a cell , may change to the next cell if inserting behind
* @ param string $parent_path path of parent
* @ return string msg to display
*/
function box_actions ( & $action , & $parent , & $content , & $child_id , $parent_path )
{
switch ( $action )
{
case 'box_insert_before' :
case 'box_insert_behind' :
$n = $child_id + ( int )( $action == 'box_insert_behind' );
if ( ! $parent [ 'type' ]) // template
2005-02-20 22:45:24 +01:00
{
2008-03-20 19:43:11 +01:00
$num = count ( $parent ) - 1 ; // 0..count()-1
2005-02-20 22:45:24 +01:00
}
2008-03-20 19:43:11 +01:00
else // boxes
2005-05-07 16:05:10 +02:00
{
2008-03-20 19:43:11 +01:00
list ( $num , $options ) = explode ( ',' , $parent [ 'size' ], 2 );
2005-05-07 16:05:10 +02:00
}
2008-03-20 19:43:11 +01:00
for ( $i = $num ; $i >= $n ; -- $i )
2005-02-20 22:45:24 +01:00
{
2008-03-20 19:43:11 +01:00
$parent [ 1 + $i ] = $parent [ $i ];
2005-02-20 22:45:24 +01:00
}
2008-03-20 19:43:11 +01:00
$parent [ $n ] = $content [ 'cell' ] = etemplate :: empty_cell ();
$child_id = $n ;
if ( $parent [ 'type' ]) $parent [ 'size' ] = ( 1 + $num ) . ( $options ? ',' . $options : '' );
break ;
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
case 'box_swap_next' :
if ( ! $parent [ 'type' ]) // template
2005-02-20 22:45:24 +01:00
{
2008-03-20 19:43:11 +01:00
$num = count ( $parent ) - 1 ; // 0..count()-1
2005-02-20 22:45:24 +01:00
}
2008-03-20 19:43:11 +01:00
else // boxes
2005-05-07 16:05:10 +02:00
{
2008-03-20 19:43:11 +01:00
list ( $num ) = explode ( ',' , $parent [ 'size' ], 2 );
2005-05-07 16:05:10 +02:00
}
2008-03-20 19:43:11 +01:00
if ( $child_id == $num ) // if on last cell, swap with the one before
2005-02-20 22:45:24 +01:00
{
2008-03-20 19:43:11 +01:00
$this -> swap ( $parent [ $child_id ], $parent [ $child_id - 1 ]);
-- $child_id ;
2005-02-20 22:45:24 +01:00
}
else
{
2008-03-20 19:43:11 +01:00
$this -> swap ( $parent [ $child_id ], $parent [ $child_id + 1 ]);
++ $child_id ;
2005-02-20 22:45:24 +01:00
}
2008-03-20 19:43:11 +01:00
break ;
2005-02-20 22:45:24 +01:00
}
2008-03-20 19:43:11 +01:00
$action = 'apply-no-merge' ;
2005-02-20 22:45:24 +01:00
2008-03-20 19:43:11 +01:00
return '' ;
}
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
/**
* functions of the row - menu : insert , deleting & swaping of rows
*
2008-10-07 20:04:59 +02:00
* @ internal
2008-03-20 19:43:11 +01:00
* @ param string & $action row_delete , row_insert_above , row_insert_below , row_swap_next , row_prefs
* @ param array & $grid grid
* @ param string $child_id id of a cell
* @ return string msg to display
*/
function row_actions ( & $action , & $grid , $child_id )
{
$data =& $grid [ 'data' ];
$rows =& $grid [ 'rows' ];
$cols =& $grid [ 'cols' ];
$opts =& $data [ 0 ];
if ( preg_match ( '/^([0-9]+)([A-Z]+)$/' , $child_id , $matches )) list (, $r , $c ) = $matches ;
if ( ! $c || ! $r || $r > $rows ) return " wrong child_id=' $child_id ' => r=' $r ', c=' $c ' " ;
switch ( $action )
{
case 'row_swap_next' :
if ( $r > $rows - 1 )
2006-03-08 00:44:21 +01:00
{
2008-03-20 19:43:11 +01:00
if ( $r != $rows ) return lang ( 'no row to swap with !!!' );
-- $r ; // in last row swap with row above
2006-03-08 00:44:21 +01:00
}
2008-03-20 19:43:11 +01:00
$this -> swap ( $data [ $r ], $data [ 1 + $r ]);
$this -> swap ( $opts [ 'c' . $r ], $opts [ 'c' . ( 1 + $r )]);
$this -> swap ( $opts [ 'h' . $r ], $opts [ 'h' . ( 1 + $r )]);
break ;
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
case 'row_delete' :
if ( $rows <= 1 ) // one row only => delete whole grid
2006-03-08 00:44:21 +01:00
{
2008-03-20 19:43:11 +01:00
return lang ( 'cant delete the only row in a grid !!!' );
// todo: delete whole grid instead
2006-03-08 00:44:21 +01:00
}
2008-03-20 19:43:11 +01:00
for ( $i = $r ; $i < $rows ; ++ $i )
2006-03-08 00:44:21 +01:00
{
2008-10-07 20:04:59 +02:00
$opts [ 'c' . $i ] = $opts [ 'c' . ( 1 + $i )];
$opts [ 'h' . $i ] = $opts [ 'h' . ( 1 + $i )];
2008-03-20 19:43:11 +01:00
$data [ $i ] = $data [ 1 + $i ];
2006-03-08 00:44:21 +01:00
}
2008-03-20 19:43:11 +01:00
unset ( $opts [ 'c' . $rows ]);
unset ( $opts [ 'h' . $rows ]);
unset ( $data [ $rows -- ]);
break ;
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
case 'row_insert_above' :
-- $r ;
// fall-through
case 'row_insert_below' :
//echo "row_insert_below($r) rows=$rows, cols=$cols"; _debug_array($grid);
// move height + class options of rows
for ( $i = $rows ; $i > $r ; -- $i )
2006-03-08 00:44:21 +01:00
{
2008-03-20 19:43:11 +01:00
echo ( $i + 1 ) . " = $i <br> \n " ;
2008-10-07 20:04:59 +02:00
$data [ 1 + $i ] = $data [ $i ];
$opts [ 'c' . ( 1 + $i )] = $opts [ 'c' . $i ];
$opts [ 'h' . ( 1 + $i )] = $opts [ 'h' . $i ];
2006-03-08 00:44:21 +01:00
}
2008-03-20 19:43:11 +01:00
for ( $i = 0 ; $i < $cols ; ++ $i )
2006-03-08 00:44:21 +01:00
{
2008-03-20 19:43:11 +01:00
echo ( 1 + $r ) . " : $i = " . etemplate :: num2chrs ( $i ) . " =empty_cell()<br> \n " ;
$data [ 1 + $r ][ etemplate :: num2chrs ( $i )] = etemplate :: empty_cell ();
2006-03-08 00:44:21 +01:00
}
2008-03-20 19:43:11 +01:00
$opts [ 'c' . ( 1 + $r )] = $opts [ 'h' . ( 1 + $r )] = '' ;
++ $rows ;
//_debug_array($grid); return '';
break ;
2006-03-08 00:44:21 +01:00
}
2008-03-20 19:43:11 +01:00
$action = 'save-no-merge' ;
2006-03-08 00:44:21 +01:00
2008-03-20 19:43:11 +01:00
return '' ;
}
/**
* functions of the column - menu : insert , deleting & swaping of columns
*
2008-10-07 20:04:59 +02:00
* @ internal
2008-03-20 19:43:11 +01:00
* @ param string & $action column_delete , column_insert_before , column_insert_behind , column_swap_next , column_prefs
* @ param array & $grid grid
* @ param string $child_id id of a cell
* @ return string msg to display
*/
function column_actions ( & $action , & $grid , $child_id )
{
$data =& $grid [ 'data' ];
$rows =& $grid [ 'rows' ];
$cols =& $grid [ 'cols' ];
$opts =& $data [ 0 ];
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
if ( preg_match ( '/^([0-9]+)([A-Z]+)$/' , $child_id , $matches )) list (, $r , $c ) = $matches ;
// find the column-number (base 0) for $c (A, B, C, ...)
for ( $col = 0 ; etemplate :: num2chrs ( $col ) != $c && $col < 100 ; ++ $col ) ;
if ( ! $c || ! $r || $r > $rows || $col >= $cols ) return " wrong child_id=' $child_id ' => r=' $r ', c=' $c ', col= $col " ;
switch ( $action )
{
case 'column_swap_next' :
if ( $col >= $cols - 1 )
{
if ( $col != $cols - 1 ) return lang ( 'no column to swap with !!!' );
$c = etemplate :: num2chrs ( -- $col ); // in last column swap with the one before
}
$c_next = etemplate :: num2chrs ( 1 + $col );
for ( $row = 1 ; $row <= $rows ; ++ $row )
{
$this -> swap ( $data [ $row ][ $c ], $data [ $row ][ $c_next ]);
}
$this -> swap ( $opts [ $c ], $opts [ $c_next ]);
//_debug_array($grid); return '';
break ;
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
case 'column_insert_behind' :
++ $col ;
case 'column_insert_before' :
//echo "<p>column_insert_before: col=$col</p>\n";
// $col is where the new column data goes
for ( $row = 1 ; $row <= $rows ; ++ $row )
2005-05-20 18:56:16 +02:00
{
2008-03-20 19:43:11 +01:00
for ( $i = $cols ; $i > $col ; -- $i )
2005-05-20 18:56:16 +02:00
{
2008-03-20 19:43:11 +01:00
$data [ $row ][ etemplate :: num2chrs ( $i )] = $data [ $row ][ etemplate :: num2chrs ( $i - 1 )];
2005-05-20 18:56:16 +02:00
}
2008-03-20 19:43:11 +01:00
$data [ $row ][ etemplate :: num2chrs ( $col )] = etemplate :: empty_cell ();
2005-05-20 18:56:16 +02:00
}
2008-03-20 19:43:11 +01:00
for ( $i = $cols ; $i > $col ; -- $i )
2005-02-18 23:44:42 +01:00
{
2008-03-20 19:43:11 +01:00
$opts [ etemplate :: num2chrs ( $i )] = $opts [ etemplate :: num2chrs ( $i - 1 )];
2005-02-18 23:44:42 +01:00
}
2008-03-20 19:43:11 +01:00
unset ( $opts [ etemplate :: num2chrs ( $col )]);
++ $cols ;
//_debug_array($grid); return '';
break ;
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
case 'column_delete' :
if ( $cols <= 1 )
{
return lang ( 'cant delete the only column of a grid !!!' );
// todo: delete whole grid instead
}
for ( $row = 1 ; $row <= $rows ; ++ $row )
2005-02-18 23:44:42 +01:00
{
2008-03-20 19:43:11 +01:00
for ( $i = $col ; $i < $cols - 1 ; ++ $i )
{
$data [ $row ][ etemplate :: num2chrs ( $i )] = $data [ $row ][ etemplate :: num2chrs ( $i + 1 )];
}
unset ( $data [ $row ][ etemplate :: num2chrs ( $cols - 1 )]);
2005-02-18 23:44:42 +01:00
}
2008-03-20 19:43:11 +01:00
for ( $i = $col ; $i < $cols - 1 ; ++ $i )
2005-02-18 23:44:42 +01:00
{
2008-03-20 19:43:11 +01:00
$opts [ etemplate :: num2chrs ( $i )] = $opts [ etemplate :: num2chrs ( $i + 1 )];
}
unset ( $opts [ etemplate :: num2chrs ( -- $cols )]);
2008-10-07 20:04:59 +02:00
break ;
2008-03-20 19:43:11 +01:00
}
$action = 'save-no-merge' ;
2005-02-18 23:44:42 +01:00
2008-03-20 19:43:11 +01:00
return '' ;
}
2006-10-05 10:49:09 +02:00
2008-03-20 19:43:11 +01:00
/**
* converts onclick selectbox and onclick text to one javascript call
*
* @ param array & $widget reference into the widget - tree
* @ param array & $cell_content cell array in content
* @ param boolean $widget2content = true copy from widget to content or other direction
*/
function fix_set_onclick ( & $widget , & $cell_content , $widget2content = true )
{
if ( $widget2content )
{
if ( preg_match ( '/^return confirm\(["\']{1}?(.*)["\']{1}\);?$/' , $widget [ 'onclick' ], $matches ))
{
$cell_content [ 'onclick' ] = $matches [ 1 ];
$cell_content [ 'onclick_type' ] = 'confirm' ;
}
elseif ( preg_match ( '/^window.open\(egw::link\(\'\/index.php\',\'([^\']+)\'\)(\+values2url\(.*\))?,\'([^\']+)\',\'dependent=yes,width=([0-9]+),height=([0-9]+),scrollbars=yes,status=yes\'\); return false;$/' , $widget [ 'onclick' ], $matches ))
{
$cell_content [ 'onclick' ] = $matches [ 1 ] . ( $matches [ 2 ] ? str_replace ( '+values2url(this.form,' , '&values2url(' , $matches [ 2 ]) : '' );
if ( $matches [ 3 ] != '_blank' )
{
$cell_content [ 'onclick' ] .= ',' . $matches [ 3 ];
2005-02-16 00:22:10 +01:00
}
2008-03-20 19:43:11 +01:00
if ( $matches [ 4 ] != '600' )
2005-02-16 00:22:10 +01:00
{
2008-03-20 19:43:11 +01:00
$cell_content [ 'onclick' ] .= ( $matches [ 3 ] == '_blank' ? ',' : '' ) . ',' . $matches [ 4 ];
}
if ( $matches [ 5 ] != '450' )
2005-02-16 00:22:10 +01:00
{
2008-03-20 19:43:11 +01:00
$cell_content [ 'onclick' ] .= ( $matches [ 4 ] == '600' ? ',' . ( $matches [ 3 ] == '_blank' ? ',' : '' ) : '' ) .
',' . $matches [ 5 ];
2005-02-16 00:22:10 +01:00
}
2008-03-20 19:43:11 +01:00
$cell_content [ 'onclick_type' ] = 'popup' ;
2005-02-16 00:22:10 +01:00
}
else
{
2008-03-20 19:43:11 +01:00
$cell_content [ 'onclick_type' ] = ! $widget [ 'onclick' ] ? '' : 'custom' ;
}
}
else // content --> widget
{
if ( preg_match ( '/^return confirm\(["\']{1}?(.*)["\']{1}\);?$/' , $cell_content [ 'onclick' ], $matches ) ||
$cell_content [ 'onclick_type' ] == 'confirm' && $cell_content [ 'onclick' ])
{
$cell_content [ 'onclick_type' ] = 'confirm' ;
$cell_content [ 'onclick' ] = is_array ( $matches ) && $matches [ 1 ] ? $matches [ 1 ] : $cell_content [ 'onclick' ];
$widget [ 'onclick' ] = " return confirm(' " . $cell_content [ 'onclick' ] . " '); " ;
}
elseif ( $cell_content [ 'onclick_type' ] == 'popup' && $cell_content [ 'onclick' ])
{
// eg: menuaction=calendar.uiforms.freetimesearch&values2url('start,end,participants'),ft_search,700,500
if (( $values2url = preg_match ( '/&values2url\((\'[^\']+\')\)/' , $cell_content [ 'onclick' ], $matches )))
2005-02-16 00:22:10 +01:00
{
2008-03-20 19:43:11 +01:00
$values2url = $matches [ 1 ];
$onclick = str_replace ( '&values2url(' . $values2url . ')' , '' , $cell_content [ 'onclick' ]);
2005-02-16 00:22:10 +01:00
}
2008-03-20 19:43:11 +01:00
list ( $get , $target , $width , $height ) = explode ( ',' , $values2url ? $onclick : $cell_content [ 'onclick' ]);
if ( ! $target ) $target = '_blank' ;
if ( ! $width ) $width = 600 ;
if ( ! $height ) $height = 450 ;
$widget [ 'onclick' ] = " window.open(egw::link('/index.php',' $get ') " . ( $values2url ? " +values2url(this.form, $values2url ) " : '' ) .
" ,' $target ','dependent=yes,width= $width ,height= $height ,scrollbars=yes,status=yes'); return false; " ;
2005-02-16 00:22:10 +01:00
}
2008-03-20 19:43:11 +01:00
elseif ( $cell_content [ 'onclick' ])
2005-02-18 23:44:42 +01:00
{
2008-03-20 19:43:11 +01:00
$wiget [ 'onclick' ] = $cell_content [ 'onclick' ];
$cell_content [ 'onclick_type' ] = 'custom' ;
2005-02-18 23:44:42 +01:00
}
else
{
2008-03-20 19:43:11 +01:00
$cell_content [ 'onclick_type' ] = '' ;
2005-02-18 23:44:42 +01:00
}
2008-03-20 19:43:11 +01:00
unset ( $widget [ 'onclick_type' ]);
}
//echo "<p>editor::fix_set_onclick(,,widget2content=".(int)$widget2content.") widget="; _debug_array($widget); echo "content="; _debug_array($cell_content);
}
2006-10-05 10:49:09 +02:00
2008-03-20 19:43:11 +01:00
/**
* converts onchange selectbox and onchange text to one javascript call
*
* @ param array & $widget reference into the widget - tree
* @ param array & $cell_content cell array in content
* @ param boolean $widget2content = true copy from widget to content or other direction
*/
function fix_set_onchange ( & $widget , & $cell_content , $widget2content = true )
{
if ( $widget2content )
{
if ( ! $widget [ 'onchange' ])
2005-02-16 00:22:10 +01:00
{
2008-03-20 19:43:11 +01:00
$cell_content [ 'onchange_type' ] = $cell_content [ 'onchange' ] = '' ;
2005-02-16 00:22:10 +01:00
}
2008-03-20 19:43:11 +01:00
elseif ( $widget [ 'onchange' ] == 1 || $widget [ 'onchange' ] == 'this.form.submit();' )
2005-02-18 23:44:42 +01:00
{
2008-03-20 19:43:11 +01:00
$cell_content [ 'onchange' ] = '' ;
$cell_content [ 'onchange_type' ] = 'submit' ;
2005-02-18 23:44:42 +01:00
}
else
{
2008-03-20 19:43:11 +01:00
$cell_content [ 'onchange_type' ] = 'custom' ;
2005-02-18 23:44:42 +01:00
}
2005-02-16 00:22:10 +01:00
}
2008-03-20 19:43:11 +01:00
else // content --> widget
{
if ( $cell_content [ 'onchange_type' ] == 'submit' || $cell_content [ 'onchange' ] == 'this.form.submit();' )
{
$widget [ 'onchange' ] = 1 ;
}
elseif ( ! $cell_content [ 'onchange' ])
{
$widget [ 'onchange' ] = 0 ;
}
unset ( $widget [ 'onchange_type' ]);
}
//echo "<p>editor::fix_set_onchange(,,widget2content=".(int)$widget2content.") widget="; _debug_array($widget); echo "content="; _debug_array($cell_content);
}
2005-02-16 00:22:10 +01:00
2008-03-20 19:43:11 +01:00
/**
* edit dialog for a widget
*
* @ param array $content the submitted content of the etemplate :: exec function , default null
* @ param string $msg msg to display , default ''
*/
function widget ( $content = null , $msg = '' )
{
if ( is_array ( $content ))
{
$path = $content [ 'goto' ] ? $content [ 'goto' ] : ( $content [ 'goto2' ] ? $content [ 'goto2' ] : $content [ 'path' ]);
$Ok = $this -> etemplate -> read ( $content [ 'name' ], $content [ 'template' ], $content [ 'lang' ], 0 , $content [ 'goto' ] || $content [ 'goto2' ] ? $content [ 'version' ] : $content [ 'old_version' ]);
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
// build size from options array, if applicable
if ( is_array ( $content [ 'cell' ][ 'options' ]))
2005-02-22 22:02:26 +01:00
{
2008-03-20 19:43:11 +01:00
$size = '' ;
for ( $n = max ( array_keys ( $content [ 'cell' ][ 'options' ])); $n >= 0 ; -- $n )
2005-02-22 22:02:26 +01:00
{
2008-03-20 19:43:11 +01:00
if ( strlen ( $content [ 'cell' ][ 'options' ][ $n ]) || strlen ( $size ))
{
$size = $content [ 'cell' ][ 'options' ][ $n ] . ( strlen ( $size ) ? ',' . $size : '' );
}
2005-02-22 22:02:26 +01:00
}
2008-03-20 19:43:11 +01:00
$content [ 'cell' ][ 'size' ] = $size ;
}
}
else
{
//echo "<p><b>".($_GET['path']).":</b></p>\n";
list ( $name , $version , $path ) = explode ( ':' , $_GET [ 'path' ], 3 ); // <name>:<version>:<path>
$Ok = $this -> etemplate -> read ( array (
'name' => $name ,
'version' => $version ,
));
}
if ( ! $Ok && ! $content [ 'cancel' ])
{
$msg .= lang ( 'Error: Template not found !!!' );
}
$path_parts = explode ( '/' , $path );
$child_id = array_pop ( $path_parts );
$parent_path = implode ( '/' , $path_parts );
//echo "<p>path='$path': child_id='$child_id', parent_path='$parent_path'</p>\n";
$parent =& $this -> etemplate -> get_widget_by_path ( $parent_path );
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
if ( is_array ( $content ))
{
foreach ( array ( 'save' , 'apply' , 'cancel' , 'goto' , 'goto2' , 'edit_menu' , 'box_menu' , 'row_menu' , 'column_menu' ) as $n => $name )
{
if (( $action = $content [ $name ] ? ( $n < 5 ? $name : $content [ $name ]) : false )) break ;
$name = '' ;
2005-02-22 22:02:26 +01:00
}
2008-03-20 19:43:11 +01:00
unset ( $content [ $name ]);
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
//echo "<p>name='$name', parent-type='$parent[type]', action='$action'</p>\n";
if (( $name == 'row_menu' || $name == 'column_menu' ) && $parent [ 'type' ] != 'grid' ||
$name == 'box_menu' && $parent [ 'type' ] == 'grid' )
2005-02-22 22:02:26 +01:00
{
2008-03-20 19:43:11 +01:00
$msg .= lang ( " parent is a '%1' !!! " , lang ( $parent [ 'type' ] ? $parent [ 'type' ] : 'template' ));
$action = false ;
2005-02-22 22:02:26 +01:00
}
2008-03-20 19:43:11 +01:00
switch ( $name )
2005-02-22 22:02:26 +01:00
{
2008-03-20 19:43:11 +01:00
case 'edit_menu' :
$msg .= $this -> edit_actions ( $action , $parent , $content , $child_id );
break ;
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
case 'box_menu' :
$msg .= $this -> box_actions ( $action , $parent , $content , $child_id , $parent_path );
break ;
case 'row_menu' :
$msg .= $this -> row_actions ( $action , $parent , $child_id );
break ;
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
case 'column_menu' :
$msg .= $this -> column_actions ( $action , $parent , $child_id );
break ;
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
case '' : // reload, eg. by changing the type
$widget = $content [ 'cell' ];
break ;
2008-10-07 20:04:59 +02:00
default :
// all menu's are (only) working on the parent, referencing widget is unnecessary
2008-03-20 19:43:11 +01:00
// and gives unexpected results, if parent is changed (eg. content gets copied)
$widget =& $this -> etemplate -> get_widget_by_path ( $path );
break ;
2005-02-22 22:02:26 +01:00
}
2008-03-20 19:43:11 +01:00
switch ( $action )
2005-02-22 22:02:26 +01:00
{
2008-03-20 19:43:11 +01:00
case 'goto' :
case 'goto2' :
$content [ 'cell' ] = $widget ;
$this -> fix_set_onclick ( $widget , $content [ 'cell' ], true );
$this -> fix_set_onchange ( $widget , $content [ 'cell' ], true );
break ;
case '' :
2008-10-07 20:04:59 +02:00
case 'save' : case 'apply' :
2008-03-20 19:43:11 +01:00
// initialise the children arrays if type is changed to a widget with children
//echo "<p>$content[path]: $widget[type] --> ".$content['cell']['type']."</p>\n";
if ( isset ( etemplate :: $widgets_with_children [ $content [ 'cell' ][ 'type' ]]))
2005-02-22 22:02:26 +01:00
{
2008-03-20 19:43:11 +01:00
$this -> change_widget_type ( $content [ 'cell' ], $widget );
2005-02-22 22:02:26 +01:00
}
2008-03-20 19:43:11 +01:00
if ( ! $action ) break ;
// save+apply only
$widget = $content [ 'cell' ];
if ( $content [ 'cell' ][ 'onclick_type' ] || $content [ 'cell' ][ 'onclick' ])
2005-02-22 22:02:26 +01:00
{
2008-03-20 19:43:11 +01:00
$this -> fix_set_onclick ( $widget , $content [ 'cell' ], false );
2005-02-22 22:02:26 +01:00
}
2008-03-20 19:43:11 +01:00
if ( $content [ 'cell' ][ 'onchange_type' ] || $content [ 'cell' ][ 'onchange' ])
2005-02-22 22:02:26 +01:00
{
2008-03-20 19:43:11 +01:00
$this -> fix_set_onchange ( $widget , $content [ 'cell' ], false );
}
// row- and column-attr for a grid
if ( $parent [ 'type' ] == 'grid' && preg_match ( '/^([0-9]+)([A-Z]+)$/' , $child_id , $matches ))
{
list (, $row , $col ) = $matches ;
$parent [ 'data' ][ 0 ][ 'h' . $row ] = $content [ 'grid_row' ][ 'height' ] .
2009-02-23 14:21:28 +01:00
( $content [ 'grid_row' ][ 'disabled' ] || $content [ 'grid_row' ][ 'part' ] ? ',' . $content [ 'grid_row' ][ 'disabled' ] : '' ) .
( $content [ 'grid_row' ][ 'part' ] ? ',' . $content [ 'grid_row' ][ 'part' ] : '' );
2008-03-20 19:43:11 +01:00
$parent [ 'data' ][ 0 ][ 'c' . $row ] = $content [ 'grid_row' ][ 'class' ] .
( $content [ 'grid_row' ][ 'valign' ] ? ',' . $content [ 'grid_row' ][ 'valign' ] : '' );
$parent [ 'data' ][ 0 ][ $col ] = $content [ 'grid_column' ][ 'width' ] .
( $content [ 'grid_column' ][ 'disabled' ] ? ',' . $content [ 'grid_column' ][ 'disabled' ] : '' );
2005-02-22 22:02:26 +01:00
}
2008-03-20 19:43:11 +01:00
// fall-through
case 'save-no-merge' :
case 'apply-no-merge' :
//$this->etemplate->echo_tmpl();
$ok = $this -> etemplate -> save ( $content );
$msg .= $ok ? lang ( 'Template saved' ) : lang ( 'Error: while saving !!!' );
// if necessary fix the version of our opener
if ( $content [ 'opener' ][ 'name' ] == $content [ 'name' ] &&
$content [ 'opener' ][ 'template' ] == $content [ 'template' ] &&
$content [ 'opener' ][ 'group' ] == $content [ 'group' ] &&
$content [ 'opener' ][ 'lang' ] == $content [ 'lang' ])
{
$content [ 'opener' ][ 'version' ] = $content [ 'version' ];
}
$js = " opener.location.href=' " . $GLOBALS [ 'egw' ] -> link ( '/index.php' , array (
'menuaction' => 'etemplate.editor.edit' ,
) + $content [ 'opener' ]) . " '; " ;
if ( $action == 'apply' || $action == 'apply-no-merge' ) break ;
// fall through
case 'cancel' :
$js .= 'window.close();' ;
echo " <html><body><script> $js </script></body></html> \n " ;
$GLOBALS [ 'egw' ] -> common -> egw_exit ();
break ;
2008-10-07 20:04:59 +02:00
}
2008-03-20 19:43:11 +01:00
if ( $js )
{
$content [ 'java_script' ] = " <script> $js </script> " ;
}
}
else
{
$widget =& $this -> etemplate -> get_widget_by_path ( $path );
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
$content = $this -> etemplate -> as_array ( - 1 );
$content [ 'cell' ] = $widget ;
$this -> fix_set_onclick ( $widget , $content [ 'cell' ], true );
$this -> fix_set_onchange ( $widget , $content [ 'cell' ], true );
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
foreach ( etemplate :: $db_key_cols as $var )
{
if ( isset ( $_GET [ $var ]))
2005-02-22 22:02:26 +01:00
{
2008-03-20 19:43:11 +01:00
$content [ 'opener' ][ $var ] = $_GET [ $var ];
2005-02-22 22:02:26 +01:00
}
}
2008-03-20 19:43:11 +01:00
}
unset ( $content [ 'cell' ][ 'obj' ]); // just in case it contains a template-object
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
if ( $parent [ 'type' ] == 'grid' && preg_match ( '/^([0-9]+)([A-Z]+)$/' , $child_id , $matches ))
{
list (, $row , $col ) = $matches ;
$grid_row =& $content [ 'grid_row' ];
2009-02-23 14:21:28 +01:00
list ( $grid_row [ 'height' ], $grid_row [ 'disabled' ], $grid_row [ 'part' ]) = explode ( ',' , $parent [ 'data' ][ 0 ][ 'h' . $row ]);
2008-03-20 19:43:11 +01:00
list ( $grid_row [ 'class' ], $grid_row [ 'valign' ]) = explode ( ',' , $parent [ 'data' ][ 0 ][ 'c' . $row ]);
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
$grid_column =& $content [ 'grid_column' ];
list ( $grid_column [ 'width' ], $grid_column [ 'disabled' ]) = explode ( ',' , $parent [ 'data' ][ 0 ][ $col ]);
//echo "<p>grid_row($row)=".print_r($grid_row,true).", grid_column($col)=".print_r($grid_column,true)."</p>\n";
2009-02-23 14:21:28 +01:00
list (,, $previous_part ) = explode ( ',' , $parent [ 'data' ][ 0 ][ 'h' . ( $row - 1 )]);
list (,, $next_part ) = explode ( ',' , $parent [ 'data' ][ 0 ][ 'h' . ( $row + 1 )]);
$allowed_parts = $this -> get_allowed_parts ( $row , $previous_part , $next_part );
//echo "<p>$row: previous=$previous_part, current={$grid_row['part']}, next=$next_part".(!isset($allowed_parts[$grid_row['part']])?': current part is NOT allowed!!!':'')."</p>\n"; _debug_array($allowed_parts);
2008-03-20 19:43:11 +01:00
}
else
{
unset ( $content [ 'grid_row' ]);
unset ( $content [ 'grid_column' ]);
}
$content [ 'path' ] = ( $parent_path != '/' ? $parent_path : '' ) . '/' . $child_id ;
$content [ 'msg' ] = $msg ;
$content [ 'goto' ] = $this -> path_components ( $content [ 'path' ]);
$content [ 'goto2' ] = $this -> parent_navigation ( $parent , $parent_path , $child_id , $widget );
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
$content [ 'cell' ][ 'options' ] = explode ( ',' , $content [ 'cell' ][ 'size' ]);
2009-06-08 18:21:14 +02:00
$editor = new etemplate ( 'etemplate.editor.widget' );
$type_tmpl = new etemplate ;
2008-03-20 19:43:11 +01:00
list ( $ext_type ) = explode ( '-' , $widget [ 'type' ]);
2009-05-17 13:41:58 +02:00
// allow to read template of app-specific widgets from their app: eg. "infolog-value" --> "infolog.widget.infolog-value"
if ( isset ( $GLOBALS [ 'egw_info' ][ 'apps' ][ $ext_type ]) && $type_tmpl -> read ( $ext_type . '.widget.' . $widget [ 'type' ]) ||
$type_tmpl -> read ( 'etemplate.editor.widget.' . $widget [ 'type' ]) ||
2008-03-20 19:43:11 +01:00
$type_tmpl -> read ( 'etemplate.editor.widget.' . $ext_type ))
{
$editor -> set_cell_attribute ( 'etemplate.editor.widget.generic' , 'obj' , $type_tmpl );
}
if ( $parent [ 'type' ] == 'grid' )
{
$editor -> disable_cells ( 'box_menu' );
}
else
{
$editor -> disable_cells ( 'row_menu' );
$editor -> disable_cells ( 'column_menu' );
}
$preserv = $this -> etemplate -> as_array () + array (
'path' => $content [ 'path' ],
'old_version' => $this -> etemplate -> version ,
'opener' => $content [ 'opener' ],
'cell' => $content [ 'cell' ],
'goto' => $content [ 'goto' ],
);
unset ( $preserv [ 'cell' ][ 'options' ]); // otherwise we never know if content is returned via options array or size
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'java_script' ] = " <script>window.focus();</script> \n " ;
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] = lang ( 'Editable Templates - Editor' );
$editor -> exec ( 'etemplate.editor.widget' , $content , array (
2009-03-16 13:58:24 +01:00
'type' => array_merge ( etemplate :: $types , $this -> extensions ),
2008-03-20 19:43:11 +01:00
'align' => & $this -> aligns ,
'valign' => & $this -> valigns ,
2009-02-23 14:21:28 +01:00
'part' => $allowed_parts ,
2008-03-20 19:43:11 +01:00
'edit_menu' => & $this -> edit_menu ,
'box_menu' => & $this -> box_menu ,
'row_menu' => & $this -> row_menu ,
'column_menu' => & $this -> column_menu ,
'onclick_type' =>& $this -> onclick_types ,
'onchange_type' =>& $this -> onchange_types ,
'options[6]' => & $this -> overflows ,
), '' , $preserv , 2 );
}
2009-02-23 14:21:28 +01:00
/**
* Get the allowed tables - part for a table rows based on row - number , previous and next part
*
* @ param int $row ( 1 - based ! )
* @ param string $previous_part '' = body , 'h' = header , 'f' = footer
* @ param string $next_part see above
* @ return array
*/
private function get_allowed_parts ( $row , $previous_part , $next_part )
{
$allowed_parts = $this -> parts ;
switch (( string ) $previous_part )
{
case 'footer' :
unset ( $allowed_parts [ 'header' ]);
break ;
case '' :
if ( $row > 1 ) $allowed_parts = array ( '' => $allowed_parts [ '' ]);
break ;
}
switch ( $next_part )
{
case 'header' :
$allowed_parts = array ( 'header' => $allowed_parts [ 'header' ]);
break ;
case 'footer' :
unset ( $allowed_parts [ '' ]);
break ;
}
return $allowed_parts ;
}
2008-03-20 19:43:11 +01:00
/**
* edit dialog for the styles of a templat or app
*
* @ param array $content the submitted content of the etemplate :: exec function , default null
* @ param string $msg msg to display , default ''
*/
function styles ( $content = null , $msg = '' )
{
if ( ! is_array ( $content ))
{
foreach ( etemplate :: $db_key_cols as $var )
2005-02-22 22:02:26 +01:00
{
2008-03-20 19:43:11 +01:00
if ( isset ( $_GET [ $var ])) $content [ $var ] = $_GET [ $var ];
2005-02-22 22:02:26 +01:00
}
2008-03-20 19:43:11 +01:00
}
//_debug_array($content);
// security check for content[from]
if ( $content [ 'from' ] && ! preg_match ( '/^[A-Za-z0-9_-]+\/templates\/[A-Za-z0-9_-]+\/app.css$/' , $content [ 'from' ]))
{
$content [ 'from' ] = '' ; // someone tried to trick us reading a file we are not suppost to read
}
if ( ! $this -> etemplate -> read ( $content ))
{
$msg .= lang ( 'Error: Template not found !!!' );
}
if ( $content [ 'save' ] || $content [ 'apply' ])
{
2005-02-22 22:02:26 +01:00
if ( $content [ 'from' ])
{
2005-11-09 21:50:45 +01:00
$path = EGW_SERVER_ROOT . '/' . $content [ 'from' ];
2008-03-20 19:43:11 +01:00
if ( is_writable ( dirname ( $path )) && file_exists ( $path ))
{
rename ( $path , str_replace ( '.css' , '.old.css' , $path ));
2005-02-22 22:02:26 +01:00
}
2008-03-20 19:43:11 +01:00
if ( file_exists ( $path ) && ! is_writable ( dirname ( $path )))
{
$msg .= lang ( " Error: webserver is not allowed to write into '%1' !!! " , dirname ( $path ));
}
else
{
$fp = fopen ( $path , 'w' );
if ( ! $fp || ! fwrite ( $fp , $content [ 'styles' ]))
{
$msg .= lang ( 'Error: while saving !!!' );
}
else
{
$msg .= lang ( " File writen " , $path );
}
@ fclose ( $fp );
}
2008-10-07 20:04:59 +02:00
}
2008-03-20 19:43:11 +01:00
else // the templates own embeded styles;
2005-02-22 22:02:26 +01:00
{
2008-03-20 19:43:11 +01:00
$this -> etemplate -> style = $content [ 'styles' ];
$ok = $this -> etemplate -> save ();
$msg = $ok ? lang ( 'Template saved' ) : lang ( 'Error: while saving !!!' );
2005-02-22 22:02:26 +01:00
}
2008-03-20 19:43:11 +01:00
$js = " opener.location.href=' " . $GLOBALS [ 'egw' ] -> link ( '/index.php' , array (
'menuaction' => 'etemplate.editor.edit' ,
) + $this -> etemplate -> as_array ( - 1 )) . " '; " ;
}
if ( $content [ 'save' ] || $content [ 'cancel' ])
{
$js .= 'window.close();' ;
echo " <html><body><script> $js </script></body></html> \n " ;
$GLOBALS [ 'egw' ] -> common -> egw_exit ();
}
$content = array (
'from' => $content [ 'from' ],
'java_script' => $js ? '<script>' . $js . '</script>' : '' ,
'msg' => $msg
);
2009-06-08 18:21:14 +02:00
$tmpl = new etemplate ( 'etemplate.editor.styles' );
2008-03-20 19:43:11 +01:00
if ( $content [ 'from' ])
{
$path = EGW_SERVER_ROOT . '/' . $content [ 'from' ];
$content [ 'styles' ] = file_exists ( $path ) && is_readable ( $path ) ? implode ( '' , file ( $path )) : '' ;
if ( ! is_writable ( dirname ( $path )) && ( ! file_exists ( $path ) || ! is_writable ( $path )))
2008-10-07 20:04:59 +02:00
{
2008-03-20 19:43:11 +01:00
$tmpl -> set_cell_attribute ( 'styles' , 'readonly' , true );
2005-02-22 22:02:26 +01:00
}
}
2008-03-20 19:43:11 +01:00
else
{
$content [ 'styles' ] = $this -> etemplate -> style ;
}
// generate list of style-sources
$keys = $this -> etemplate -> as_array ( - 1 ); unset ( $keys [ 'group' ]);
$sources [ '' ] = lang ( 'eTemplate' ) . ': ' . implode ( ':' , $keys );
list ( $app ) = explode ( '.' , $this -> etemplate -> name );
$app_templates = @ opendir ( EGW_SERVER_ROOT . '/' . $app . '/templates' );
while (( $template = @ readdir ( $app_templates )) !== false )
{
$dir = EGW_SERVER_ROOT . '/' . $app . '/templates/' . $template ;
if ( $template [ 0 ] == '.' || $template == 'CVS' || ! is_dir ( $dir . '/images' )) continue ; // not a template-dir
$exists = file_exists ( $dir . '/app.css' );
$writable = is_writable ( $dir ) || $exists && is_writable ( $dir . '/app.css' );
if ( ! $exists && ! $writable ) continue ; // nothing to show
$rel_path = $app . '/templates/' . $template . '/app.css' ;
$sources [ $rel_path ] = lang ( 'file' ) . ': ' . $rel_path . ( $exists && ! $writable ? ' (' . lang ( 'readonly' ) . ')' : '' );
}
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'java_script' ] = " <script>window.focus();</script> \n " ;
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] = lang ( 'etemplate' ) . ' - ' . lang ( 'CSS-styles' );
$tmpl -> exec ( 'etemplate.editor.styles' , $content , array ( 'from' => $sources ), '' , $keys , 2 );
}
2005-02-22 22:02:26 +01:00
2008-03-20 19:43:11 +01:00
/**
* search the inc - dirs of etemplate and the app whichs template is edited for extensions / custom widgets
*
* extensions are class - files in $app / inc / class . $ { name } _widget . inc . php
* the extensions found will be saved in a class - var and in the session
*
* @ param string $app = 'etemplate' app to scan
* @ return string comma delimited list of new found extensions
*/
function scan_for_extensions ( $app = 'etemplate' )
{
if ( ! is_array ( $this -> extensions )) $this -> extensions = array ();
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
if ( isset ( $this -> extensions [ '**loaded**' ][ $app ])) return '' ; // already loaded
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
$labels = array ();
$dir = @ opendir ( EGW_SERVER_ROOT . '/' . $app . '/inc' );
while ( $dir && ( $file = readdir ( $dir )))
{
2009-06-08 18:21:14 +02:00
if ( preg_match ( '/class\\.([a-zA-Z0-9_]*)_widget.inc.php/' , $file , $regs ) &&
2008-03-20 19:43:11 +01:00
( $regs [ 1 ] != 'xslt' || $this -> etemplate -> xslt ) &&
( $ext = $this -> etemplate -> loadExtension ( $regs [ 1 ] . '.' . $app , $this -> etemplate )))
2002-05-13 23:30:46 +02:00
{
2008-03-20 19:43:11 +01:00
if ( is_array ( $ext ))
2002-05-13 23:30:46 +02:00
{
2008-03-20 19:43:11 +01:00
$this -> extensions += $ext ;
$labels += $ext ;
}
else
{
$this -> extensions [ $regs [ 1 ]] = $ext ;
$labels [] = $ext ;
2002-05-13 23:30:46 +02:00
}
}
}
2008-03-20 19:43:11 +01:00
// store the information in the session, our constructor loads it from there
$GLOBALS [ 'egw' ] -> session -> appsession ( 'extensions' , 'etemplate' , $this -> extensions );
$apps_loaded = $GLOBALS [ 'egw' ] -> session -> appsession ( 'apps_loaded' , 'etemplate' );
$apps_loaded [ $app ] = true ;
$GLOBALS [ 'egw' ] -> session -> appsession ( 'apps_loaded' , 'etemplate' , $apps_loaded );
//_debug_array($this->extensions); _debug_array($apps_loaded);
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
return implode ( ', ' , $labels );
}
2008-10-07 20:04:59 +02:00
2008-03-20 19:43:11 +01:00
/**
* swap the values of $a and $b
*
* @ param mixed & $a
* @ param mixed & $b
*/
function swap ( & $a , & $b )
{
$h = $a ;
$a = $b ;
$b = $h ;
}
}