From 129601366e56154ce60698368c38921dde7d6f8e Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 4 Feb 2013 12:35:30 +0000 Subject: [PATCH] Some extra debug for et2 --- etemplate/inc/class.etemplate.inc.php | 2 +- etemplate/inc/class.etemplate_widget.inc.php | 23 +++++++- .../inc/class.etemplate_widget_grid.inc.php | 1 + .../inc/class.etemplate_widget_vfs.inc.php | 56 +++++++++++++++++++ 4 files changed, 78 insertions(+), 4 deletions(-) diff --git a/etemplate/inc/class.etemplate.inc.php b/etemplate/inc/class.etemplate.inc.php index 138c30cf5d..680590a8af 100644 --- a/etemplate/inc/class.etemplate.inc.php +++ b/etemplate/inc/class.etemplate.inc.php @@ -138,7 +138,7 @@ class etemplate_new extends etemplate_widget_template // instanciate template to fill self::$request->sel_options for select-* widgets // not sure if we want to handle it this way, thought otherwise we will have a few ajax request for each dialog fetching predefined selectboxes $template = etemplate_widget_template::instance($this->name, $this->template_set, $this->version, $this->laod_via); - $template->run('beforeSendToClient'); + $template->run('beforeSendToClient', array('', array('cont'=>$content))); $data = array( 'etemplate_exec_id' => self::$request->id(), diff --git a/etemplate/inc/class.etemplate_widget.inc.php b/etemplate/inc/class.etemplate_widget.inc.php index 9e335a64f1..f2b9b375b3 100644 --- a/etemplate/inc/class.etemplate_widget.inc.php +++ b/etemplate/inc/class.etemplate_widget.inc.php @@ -345,7 +345,7 @@ class etemplate_widget // maintain $expand array name-expansion $cname = $params[0]; $expand =& $params[1]; - if ($expand['cname'] !== $cname) + if ($expand['cname'] && $expand['cname'] !== $cname) { $expand['cont'] =& self::get_array(self::$request->content, $cname); $expand['cname'] = $cname; @@ -360,7 +360,23 @@ class etemplate_widget } if (method_exists($this, $method_name)) { - call_user_func_array(array($this, $method_name), $params); + // Some parameter checking to avoid fatal errors + $call = true; + $method = new ReflectionMethod($this, $method_name); + foreach($method->getParameters() as $index => $param) + { + if(!$param->isOptional() && !array_key_exists($index,$params)) + { + error_log("Missing required parameter {$param->getPosition()}: {$param->getName()}"); + $call = false; + } + if($param->isArray() && !is_array($params[$index])) + { + error_log("$method_name expects an array for {$param->getPosition()}: {$param->getName()}"); + $params[$index] = (array)$params[$index]; + } + } + if($call) call_user_func_array(array($this, $method_name), $params); } foreach($this->children as $child) { @@ -537,7 +553,8 @@ class etemplate_widget */ public function __toString() { - return $this->type.($this->attrs['type'] && $this->attrs['type'] != $this->type ? '('.$this->attrs['type'].')' : '').'#'.$this->id; + return '['.get_class($this).'] ' . + $this->type.($this->attrs['type'] && $this->attrs['type'] != $this->type ? '('.$this->attrs['type'].')' : '').'#'.$this->id; } /** diff --git a/etemplate/inc/class.etemplate_widget_grid.inc.php b/etemplate/inc/class.etemplate_widget_grid.inc.php index 896b96b0f3..f0a4d7eb08 100644 --- a/etemplate/inc/class.etemplate_widget_grid.inc.php +++ b/etemplate/inc/class.etemplate_widget_grid.inc.php @@ -128,6 +128,7 @@ class etemplate_widget_grid extends etemplate_widget_box continue; // do NOT run $method_name on disabled columns } } + //error_log('Running ' . $method_name . ' on child ' . $n . '(' . $child . ') ['.$expand['row'] . ','.$expand['c'] . ']'); $disabled = $child->run($method_name, $params, $respect_disabled, $columns_disabled) === false; if ($this->type == 'columns' && $disabled) diff --git a/etemplate/inc/class.etemplate_widget_vfs.inc.php b/etemplate/inc/class.etemplate_widget_vfs.inc.php index df397fff76..800e031421 100644 --- a/etemplate/inc/class.etemplate_widget_vfs.inc.php +++ b/etemplate/inc/class.etemplate_widget_vfs.inc.php @@ -25,6 +25,62 @@ class etemplate_widget_vfs extends etemplate_widget_file if($xml) parent::__construct($xml); } + /** + * If widget is a vfs-file widget, and there are files in the specified directory, + * they should be displayed. + */ + public function beforeSendToClient($cname, $expand = array()) + { + if($this->type == 'vfs-upload') + { +echo "EXPAND"; +_debug_array($expand); + $form_name = self::form_name($cname, $this->id, $expand ? $expand : array('cont'=>self::$request->content)); + +echo "this-ID: {$this->id}
"; +echo "Form name: $form_name
"; + // ID maps to path - check there for any existing files + list($app,$id,$relpath) = explode(':',$this->id,3); + if($app && $id) + { +echo "ID: $id
"; + if(!is_numeric($id)) + { + $_id = self::expand_name($id,0,0,0,0,self::$request->content); + if($_id != $id) + { + $id = $_id; + $form_name = "$app:$id:$relpath"; +echo "Form name: $form_name
"; + } + } + $value =& self::get_array(self::$request->content, $form_name, true); +echo "ID: $id
"; + $path = egw_link::vfs_path($app,$id,'',true); + if (!empty($relpath)) $path .= '/'.$relpath; + + // Single file, already existing + if (substr($path,-1) != '/' && egw_vfs::file_exists($path) && !egw_vfs::is_dir($path)) + { + $value = $path; + } + else if (substr($path, -1) == '/' && egw_vfs::is_dir($path)) + { + $value = egw_vfs::scandir($path); +echo 'HERE!'; + foreach($value as &$file) + { +echo $file.'
'; + $file = egw_vfs::stat("$path$file"); +_debug_array($file); + } + } + } +echo $this; +_debug_array($value); + } + } + public static function ajax_upload() { parent::ajax_upload(); error_log(array2string($_FILES));