<?php

$url = '/server/listServer';
if (isset($argv[1])) {
    $url = $argv[1];
}
require_once dirname(__FILE__) . '/../bootstrap/dbunit.php';
Console::$profilingEnabled = true;
register_shutdown_function(array('Console', 'profile'), 'end');
class AuthenticatedBrowser extends sfBrowser
{
    protected function doCall()
    {
        $this->context = $this->getContext(true);
        $admin = sfGuardUserPeer::retrieveByPk(1);
        $this->context->getUser()->signIn($admin);
        ob_start();
        $this->context->getController()->dispatch();
        $html = ob_get_clean();
    }
}
$browser = new AuthenticatedBrowser();
sfConfig::set('app_parser_panels', array());
sfConfig::set('app_parser_skip_toolbar', true);
$browser->get($url);
Console::profile('end');
Console::restartProfiling();
$browser->get($url);
Exemplo n.º 2
0
    private function postProcess($build = false, $uri = null)
    {
        if ($uri) {
            $this->process["parses"][$this->iteration]["module"] = strtok($uri, "/");
            $this->process["parses"][$this->iteration]["component_name"] = strtok("/");
        }
        Console::profile('postProcess');
        /*
         * Create widgets in advanced for the text link script (widget launcher)
         */
        sfApplicationConfiguration::getActive()->loadHelpers(array("Helper", "Url", "afUrl"));
        // Update session if needed..
        $module = $this->context->getModuleName();
        $action = $this->context->getActionName();
        $this->context->getUser()->getAttributeHolder()->removeNamespace('parser/grid');
        if ($this->type === self::WIZARD) {
            if (isset($this->attribute_holder["init"])) {
                $this->context->getUser()->getAttributeHolder()->removeNamespace('parser/wizard');
            }
            self::updateSession(false, "parser/wizard", null, $this->datastore, $this->process);
        }
        if (!$build) {
            $pageHelp = $this->type !== self::WIZARD && isset($this->process["parses"][0]["extra"]) && $this->widgetHelpSettings->getWidgetHelpIsEnabled();
        } else {
            $pageHelp = null;
        }
        if ($this->multi) {
            $this->page = $this->process["parses"][0];
            unset($this->process["parses"][0]);
            if ($pageHelp) {
                $this->layout->addHelp($this->page["extra"]);
            }
            $this->layout->setTitle($this->page["title"] . (class_exists('afExtjsWidgetConfig') ? afExtjsWidgetConfig::getPostfixTitle() : ''));
        }
        if ($this->tree) {
            $this->layout->addItem('west', $this->tree);
        }
        foreach ($this->process["parses"] as $it => $parse) {
            // Parse additional scripts..
            if (array_key_exists("scripts", $parse)) {
                $this->parseScripts($parse);
            }
            /*
             * Moved the tools in this loop to have different tools on different portlets depending upon their types.
             */
            $tools = new afExtjsTools();
            // Help popup
            if ($this->widgetHelpSettings && $this->widgetHelpSettings->getPopupHelpIsEnabled()) {
                $tools->addItem(array('id' => 'help', 'qtip' => "Widget Help", 'handler' => array('parameters' => 'e,target,panel', 'source' => "afApp.loadPopupHelp(panel.idxml);")));
            }
            //Print - for grids it is added later due parameters.
            if ($parse["view"] != "list") {
                $tools->addItem(array('id' => 'print', 'qtip' => "Printer friendly version", 'handler' => array('parameters' => 'e,target,panel', 'source' => "window.open('/'+panel.idxml+'?af_format=pdf&" . $this->getQueryString() . "','print');")));
            }
            if (isset($parse['params']) && isset($parse['params']['settings'])) {
                $tools->addItem(array('id' => 'gear', 'qtip' => 'Setting', 'handler' => array('parameters' => 'e,target,panel', 'source' => "afApp.widgetPopup('" . $parse['params']['settings'] . "','Settings',panel)")));
            }
            //$tools->addItem(array('id'=>'start-reload','handler'=>array('parameter'=>'e,target,panel','source'=>'this.id="stop-reload"')));
            $tools->addItem(array('id' => 'close', 'qtip' => 'Close', 'handler' => array('parameters' => 'e,target,panel', 'source' => "var portal=panel.ownerCt.ownerCt;panel.ownerCt.remove(panel, true);portal.onWidgetDrop();")));
            /***********************************************************/
            if (!$build) {
                $widgetHelp = $this->type !== self::WIZARD && isset($parse["description"]) && $this->widgetHelpSettings->getWidgetHelpIsEnabled();
                if ($widgetHelp) {
                    if ($this->type === self::PANEL) {
                        $this->layout->addHelp($parse["description"]);
                    }
                }
            }
            if ($this->multi) {
                $current_area = $this->page["areas"][$parse["area"]];
            } else {
                $current_area = isset($parse["area"]) ? $parse["area"] : null;
            }
            $view = $parse["view"];
            $parsedgroups = array();
            if (!isset($parse["multipart"])) {
                $parse["multipart"] = false;
            }
            if ($this->multi && isset($this->page["confirm"])) {
                $this->layout->attributes['listeners']['beforerender'] = $this->layout->afExtjs->asMethod(array('parameters' => 'el', 'source' => "Ext.Msg.confirm('" . $this->page["confirm"]["title"] . "','" . $this->page["confirm"]["text"] . "', function(btn){if (btn=='yes'){ return true; }else{ window.location.href='" . $this->page["confirm"]["url"] . "';return false;} });"));
            }
            //echo "<pre>";print_r($parse);exit;
            $formoptions = $this->multi ? array("title" => $parse["title"], "fileUpload" => $parse["multipart"], "portal" => true, "tools" => $tools) : array("fileUpload" => $parse["multipart"]);
            if ($it == 1 && $this->multi && $this->type === self::WIZARD) {
                $panel = $this->layout->startColumn(array('columnWidth' => isset($current_area["attributes"]["width"]) ? $current_area["attributes"]["width"] : '0.98'));
            }
            if ($this->type == self::PAGE) {
                $action_name = preg_replace("/[0-9]+/", "", $parse["component"]);
            }
            // Determine group - Wizards
            if (!$this->openGroup && $this->tabbedWizard) {
                $this->openGroup = true;
                $wizard_group = $this->layout->startGroup();
            }
            if ($view == "edit" || $view == "show") {
                $formoptions["action"] = url_for($parse["form"]);
                $formoptions["name"] = "form" . $it;
                $formoptions["classic"] = $parse["classic"] !== "false";
                $formoptions["labelWidth"] = isset($parse['labelWidth']) ? $parse['labelWidth'] : '75';
                if ($this->type == self::PANEL) {
                    $widget = $this->context->getActionName();
                } else {
                    if ($this->type == self::PAGE) {
                        #1048 - element should have unique id
                        $widget = $action_name;
                        $formoptions["idxml"] = $parse['module'] . "/" . $action_name;
                    }
                }
                if ($this->type === self::WIZARD) {
                    //$formoptions["classic"] = true;
                }
                $form = new afExtjsForm($formoptions);
                if ($widgetHelp) {
                    if ($this->multi) {
                        $form->addHelp($parse["description"]);
                    }
                }
                foreach ($parse["fields"] as $setname => $set) {
                    $this->is_floated = array();
                    if (!isset($set["attributes"]["tabtitle"])) {
                        if (isset($tabx)) {
                            unset($tabx);
                        }
                    } else {
                        if (!isset($tabs)) {
                            $set["attributes"]["isSetting"] = $parse['isSetting'];
                            $set["attributes"]["description"] = isset($parse['description']) ? $parse['description'] : "";
                            $tabs = $form->startTabs($set["attributes"]);
                        }
                    }
                    // Fieldset
                    if ($parse["isgrouped"]) {
                        if (!$this->tabbedWizard) {
                            $attributes = array("legend" => $set["attributes"]["title"], "collapsed" => $set["attributes"]["collapsed"]);
                        } else {
                            $attributes = array();
                        }
                        $this->is_floated[] = !$this->tabbedWizard ? $this->isFloatedSet($set) : false;
                        if ($this->is_floated[0]) {
                            $attrs = array("columnWidth" => sprintf("%1.2f", (double) 1 / $this->is_floated[0]), 'labelAlign' => 'top');
                        } else {
                            $attrs = array('columnWidth' => 1, 'labelAlign' => 'left');
                        }
                    } else {
                        $attributes = array();
                        $fieldset = $form;
                        $set = $parse["fields"];
                        $attrs = array('columnWidth' => 1, 'labelAlign' => 'left');
                    }
                    if (isset($set["attributes"]["tabtitle"])) {
                        $tabattrs = array('title' => $set["attributes"]["tabtitle"], 'height' => $set["attributes"]["tabHeight"], "iconCls" => $set["attributes"]["tabIconCls"]);
                        if ($set["attributes"]["tabIcon"] && file_exists($this->root . "/web" . $set["attributes"]["tabIcon"])) {
                            $tabattrs["icon"] = $set["attributes"]["tabIcon"];
                            unset($tabattrs["iconCls"]);
                        }
                        $tabx = $tabs->startTab($tabattrs);
                        $fieldset = $tabx->startFieldset($attributes);
                    } else {
                        $fieldset = $form->startFieldSet($attributes);
                    }
                    if ($parse["isgrouped"]) {
                        $columns = $fieldset->startColumns();
                    }
                    // Field data
                    foreach ($set as $name => $data) {
                        $rcf = new ReConfigureFields($data);
                        $data = $rcf->getField();
                        if ($parse["isgrouped"]) {
                            $columnx = $columns->startColumn($attrs);
                        }
                        if ($name == "attributes" || !is_array($data)) {
                            continue;
                        }
                        // Convert to attributes field's children's default values here!
                        $this->childToAttribute($data, $it);
                        $attributes = $data["attributes"];
                        $attributes['labelStyle'] = 'width:' . $parse['labelWidth'] . 'px;font-size:11px;font-weight:bold;padding:0 3px 3px 0;';
                        // Put validators into af_formcfg.
                        if (isset($data['validators'])) {
                            $form->addValidator($name, $data['validators']);
                        }
                        $classname = $attributes["type"];
                        // Add file types for af_formcfg
                        $form->addFieldType($name, $classname);
                        if ($setname == $name) {
                            $this->process["parses"][$it]["fields"][$name]["attributes"] = $attributes;
                        } else {
                            $this->process["parses"][$it]["fields"][$setname][$name]["attributes"] = $attributes;
                        }
                        if ($attributes["type"] == "link") {
                            continue;
                        } else {
                            if ($attributes["type"] == "radio" || $attributes["type"] == "checkbox" && $this->isInGroup($attributes["name"])) {
                                $groupname = $attributes["group"];
                                if (!in_array($groupname, $parsedgroups)) {
                                    // Radio and Checkbox groups
                                    $radiogroup = $fieldset->startGroup($attributes["type"], $parse["groups"][$groupname]["attributes"]);
                                    foreach ($parse["groups"][$groupname]["members"] as $key => $member) {
                                        $elem = $this->shiftItem($member);
                                        $this->childToAttribute($elem, $it);
                                        $attributes = $elem["attributes"];
                                        $attributes["name"] = $groupname;
                                        $tmp_name = "afExtjsField" . ucfirst($classname);
                                        if ($view == "edit") {
                                            $obj = new $tmp_name($radiogroup, $attributes);
                                        } else {
                                            $this->showAttributes($attributes);
                                            $obj = new afExtjsFieldStatic($radiogroup, $attributes);
                                        }
                                    }
                                    $fieldset->endGroup($radiogroup);
                                    $parsedgroups[] = $groupname;
                                }
                            } else {
                                if ($attributes["type"] == "linkButton" || $attributes["type"] == "button") {
                                    $attributes["url"] = $attributes["action"];
                                    $tmp_name = "afExtjs" . ucfirst($classname);
                                    $obj = new $tmp_name($form, $attributes);
                                } else {
                                    if ($attributes["type"] == "date" || $attributes["type"] == "datetime") {
                                        $classname = "dateTime";
                                        if (!isset($attributes["dateFormat"])) {
                                            $attributes["dateFormat"] = "Y-m-d";
                                        }
                                    }
                                    if ($attributes["type"] == "multicombo" || $attributes["type"] == "doublemulticombo" || $attributes["type"] == "itemSelectorAutoSuggest" || $attributes["type"] == "doubletree") {
                                        switch ($attributes["type"]) {
                                            case "multicombo":
                                                $classname = "multiCombo";
                                                break;
                                            case "doublemulticombo":
                                                $classname = "doubleMultiCombo";
                                                break;
                                            case "doubletree":
                                                $classname = "doubleTree";
                                                break;
                                        }
                                        $attributes["clear"] = true;
                                        if (!isset($attributes["selected"])) {
                                            $attributes["selected"] = array();
                                        } else {
                                            if (!is_array($attributes["selected"]) && $classname != "doubleTree") {
                                                $attributes["selected"] = explode(",", $attributes["selected"]);
                                            }
                                        }
                                    }
                                    if ($attributes["type"] == "textarea" && $attributes["rich"] == "false") {
                                        $attributes["rich"] = false;
                                    }
                                    if ($attributes["type"] != "include") {
                                        $tmp_name = "afExtjsField" . ucfirst($classname);
                                        if ($view == "edit" || $attributes["type"] == "doubletree") {
                                            if ($tmp_name == 'afExtjsFieldCombo') {
                                                $obj = new $tmp_name(isset($columnx) ? $columnx : $form, $attributes, $data);
                                            } else {
                                                $obj = new $tmp_name(isset($columnx) ? $columnx : $form, $attributes);
                                            }
                                            /*
                                            if(isset($attributes["window"])) {
                                            	//$obj = new afExtjsFieldCombo($fieldset,array('name'=>'my_combo_button','label'=>'My combo button','help'=>"combo box with button",'comment'=>'comment for combo w button','options'=>array('a'=>'Value A','b'=>'Value B'),'selected'=>'b','button'=>array('text'=>'Trigger','icon'=>'/images/famfamfam/cancel.png'),'window'=>array('title'=>'Window Title','component'=>$this->getForm(),'className'=>'ServerPeer','methodName'=>'getAllAsOptions')));
                                            	//$columnx = $columns->startColumn(array('columnWidth'=>5,'labelAlign'=> 'left'));
                                            	//$obj = new afExtjsFieldCombo($columnx,array('name'=>'my_combo_button','label'=>'My combo button','help'=>"combo box with button",'comment'=>'comment for combo w button','options'=>array('a'=>'Value A','b'=>'Value B'),'selected'=>'b','button'=>array('text'=>'Trigger','icon'=>'/images/famfamfam/cancel.png'),'window'=>array('title'=>'Window Title','component'=>$this->getForm(),'className'=>'ServerPeer','methodName'=>'getAllAsOptions')));
                                            	//$obj = new afExtjsFieldCombo($columnx,$attributes);							
                                            } else {
                                            	
                                            	;	
                                            
                                            }
                                            */
                                        } else {
                                            if ($attributes["type"] != "file") {
                                                $this->showAttributes($attributes);
                                                $obj = new afExtjsFieldStatic(isset($columnx) ? $columnx : $form, $attributes);
                                            }
                                        }
                                    } else {
                                        $prs = new XmlParser(self::PANEL, false, false, false, false, $attributes["url"]);
                                        if (isset($columnx)) {
                                            $columnx->addMember($prs->getResult());
                                        } else {
                                            $form->addMember($prs->getResult());
                                        }
                                    }
                                }
                            }
                        }
                        if ($parse["isgrouped"]) {
                            $columns->endColumn($columnx);
                        }
                        if (isset($attributes["break"]) && $attributes["break"] == "true") {
                            $attrs["columnWidth"] = 1;
                            $columnx = $columns->startColumn($attrs);
                            $columns->endColumn($columnx);
                            $this->is_floated[] = $this->isFloatedSet($set, Util::arraySum($this->is_floated));
                            if (!$this->is_floated[sizeof($this->is_floated) - 1]) {
                                $this->is_floated[sizeof($this->is_floated) - 1] = 1;
                            }
                            $attrs["columnWidth"] = sprintf("%1.2f", (double) 1 / $this->is_floated[sizeof($this->is_floated) - 1]);
                        }
                    }
                    if ($parse["isgrouped"]) {
                        $fieldset->endColumns($columns);
                        if (isset($tabx)) {
                            $tabx->endFieldSet($fieldset);
                            $tabs->endTab($tabx);
                        } else {
                            $form->endFieldSet($fieldset);
                        }
                    } else {
                        break;
                    }
                }
                if ($view == "edit") {
                    if ($this->type !== self::WIZARD && $parse["submit"] !== "false") {
                        if (!$this->multisubmit) {
                            $form_params = null;
                            if (isset($parse["redirect"])) {
                                if ($parse["redirect"]) {
                                    $form_params = array("redirect" => $parse["redirect"], "message" => "");
                                }
                            }
                            $obj = new afExtjsSubmitButton($form, array("action" => $formoptions["action"], "label" => $parse["submitlabel"], "params" => $form_params));
                        } else {
                            $this->formaction = $formoptions["action"];
                        }
                        if ((!isset($parse['isSetting']) || $parse['isSetting'] === "false") && $parse["resetable"] !== "false") {
                            $obj = new afExtjsResetButton($form, array("action" => $formoptions["action"], "text" => $parse["resetlabel"]));
                        }
                    }
                }
                if (isset($parse["actions"]) && $this->type !== self::WIZARD) {
                    foreach ($parse["actions"] as $aname => $action) {
                        if (!self::toggleAction($aname, $action)) {
                            continue;
                        }
                        if (array_key_exists("handlers", $action)) {
                            ExtEvent::attachAll($action);
                        }
                        $action["attributes"]["label"] = ucfirst($action["attributes"]["name"]);
                        $action["attributes"]["name"] = $this->view . $this->iteration . "_" . $action["attributes"]["name"];
                        $action["attributes"]["url"] = url_for($action["attributes"]["url"]);
                        //$temp_grid = new afExtjsGrid();
                        //$params = $temp_grid->getListenerParams($action,"action");
                        // TODO:foo
                        if ($action["attributes"]["post"] === "true") {
                            $this->prepareButton($form, $action['attributes']);
                        } else {
                            if ($action["attributes"]["updater"] === "true") {
                                $updater = new afExtjsUpdater(array('url' => $action["attributes"]["url"], 'width' => 500));
                                $action["attributes"]["handlers"]["click"] = array('parameters' => 'field,event', 'source' => $updater->privateName . '.start();');
                                $obj = new afExtjsButton($form, $action['attributes']);
                            } else {
                                $obj = $this->prepareButton($form, $action['attributes']);
                            }
                        }
                    }
                }
                if (isset($parse["moreactions"]) && $this->type !== self::WIZARD) {
                    foreach ($parse["moreactions"] as $aname => $action) {
                        if (!self::toggleAction($aname, $action)) {
                            continue;
                        }
                        if (isset($action["handlers"])) {
                            ExtEvent::attachAll($action);
                        }
                        $parameterForButton = ExtEvent::getButtonParams($action, "moreactions", $this->view . $this->iteration, $parse["select"]);
                        $form->addMenuActionsItem($parameterForButton);
                    }
                }
                if (isset($tabs)) {
                    $form->endTabs($tabs);
                }
                if (array_key_exists("scripts", $parse)) {
                    $form->addScripts($parse["scripts"]);
                }
                if (!$this->multisubmit) {
                    $form->end();
                }
                $this->forms[] = $form;
                if ($this->type == self::PAGE && $current_area["attributes"]["type"] == "content") {
                    $this->addPortal($form, $parse["module"] . "/" . $parse["component"]);
                }
                if ($build) {
                    $this->result = $form;
                    return $form;
                }
                if (!$this->multi) {
                    $this->layout->addItem($this->area_types[$current_area], $form);
                    if ($this->area_types[$current_area] == "center") {
                        $this->layout->addCenterComponent($tools, array('title' => $parse["title"] . (class_exists('afExtjsWidgetConfig') ? afExtjsWidgetConfig::getPostfixTitle() : ''), "idxml" => $this->panelIdXml));
                    }
                } else {
                    if ($current_area["attributes"]["type"] == "content") {
                        if ($this->type != self::PAGE) {
                            $panel->addItem($form);
                        }
                    } else {
                        $this->layout->addItem($this->area_types[$current_area["attributes"]["type"]], $form);
                    }
                }
            } else {
                if ($view == "html") {
                    if (!isset($parse["options"])) {
                        $parse["options"]["autoScroll"] = true;
                        $parse["options"]["border"] = false;
                        $parse["options"]["header"] = true;
                        $parse["options"]["autoHeight"] = true;
                        $parse["options"]["autoEnd"] = false;
                    }
                    $plugins = afExtjsWidgets::getReloadPlugin($parse);
                    if ($this->multi) {
                        if (isset($action_name)) {
                            $idxml = $parse["module"] . "/" . $action_name;
                        } else {
                            $idxml = false;
                        }
                        $pn = new afExtjsPanel(array('plugins' => $plugins, 'title' => $parse["title"], 'autoScroll' => $parse["options"]["autoScroll"], 'border' => $parse["options"]["border"], 'header' => $parse["options"]["header"], 'style' => '', 'autoHeight' => $parse["options"]["autoHeight"], 'autoEnd' => $parse["options"]["autoEnd"], 'portal' => true, 'tools' => $tools, 'idxml' => $idxml));
                        if (isset($parse["description"])) {
                            $html = $parse["description"];
                            if ($this->widgetHelpSettings->getWidgetHelpIsEnabled()) {
                                $pn->addHelp($html);
                            }
                        }
                        $pn->addMember(self::defineHtmlComponent($parse['params']));
                        /*if(isset($parse["actions"])) {
                        	
                        			foreach($parse["actions"] as $aname => $action) {
                        				
                        				if(!self::toggleAction($aname,$action)) {
                        					continue;
                        				}
                        				
                        				if(isset($action["handlers"])) {
                        					ExtEvent::attachAll($action);
                        				}
                        				
                        				$parameterForButton = ExtEvent::getButtonParams($action,"actions",$this->view.$this->iteration,$parse["select"]);			
                        				$obj = new afExtjsButton($pn,$parameterForButton);
                        			}
                        		}*/
                        if (isset($parse["moreactions"])) {
                            foreach ($parse["moreactions"] as $aname => $action) {
                                if (!self::toggleAction($aname, $action)) {
                                    continue;
                                }
                                if (isset($action["handlers"])) {
                                    ExtEvent::attachAll($action);
                                }
                                $parameterForButton = ExtEvent::getButtonParams($action, "moreactions", $this->view . $this->iteration, false);
                                $pn->addMenuActionsItem($parameterForButton);
                            }
                        }
                        $pn->end();
                        if ($this->type != self::PAGE) {
                            $panel->addItem($pn);
                        }
                        if ($build) {
                            $this->result = $pn;
                            return $pn;
                        }
                        //radu
                        if ($this->type == self::PAGE && $current_area["attributes"]["type"] == "content") {
                            $this->addPortal($pn, $parse["module"] . "/" . $action_name);
                        }
                    } else {
                        $pn = new afExtjsPanel(array('plugins' => $plugins, 'title' => $parse["title"], 'autoScroll' => $parse["options"]["autoScroll"], 'border' => $parse["options"]["border"], 'header' => $parse["options"]["header"], 'style' => '', 'autoHeight' => $parse["options"]["autoHeight"], 'autoEnd' => $parse["options"]["autoEnd"], 'portal' => true));
                        $pn->addMember(self::defineHtmlComponent($parse['params']));
                        /*if(isset($parse["actions"])) {
                        	
                        			foreach($parse["actions"] as $aname => $action) {
                        				
                        				if(!self::toggleAction($aname,$action)) {
                        					continue;
                        				}
                        				
                        				if(isset($action["handlers"])) {
                        					ExtEvent::attachAll($action);
                        				}
                        				
                        				$parameterForButton = ExtEvent::getButtonParams($action,"actions",$this->view.$this->iteration,false);			
                        				$obj = new afExtjsButton($pn,$parameterForButton);
                        			}
                        		}
                        		*/
                        if (isset($parse["moreactions"])) {
                            foreach ($parse["moreactions"] as $aname => $action) {
                                if (!self::toggleAction($aname, $action)) {
                                    continue;
                                }
                                if (isset($action["handlers"])) {
                                    ExtEvent::attachAll($action);
                                }
                                $parameterForButton = ExtEvent::getButtonParams($action, "moreactions", $this->view . $this->iteration, false);
                                $pn->addMenuActionsItem($parameterForButton);
                            }
                        }
                        $pn->end();
                        if ($build) {
                            $this->result = $pn;
                            return $pn;
                        }
                        $this->layout->addItem("center", $pn);
                        $this->layout->addCenterComponent($tools, array('title' => $parse["title"] . (class_exists('afExtjsWidgetConfig') ? afExtjsWidgetConfig::getPostfixTitle() : ''), "idxml" => $this->panelIdXml));
                    }
                } else {
                    if ($view == "info") {
                        $form = new afExtjsForm($formoptions);
                        if (isset($parse["settitle"])) {
                            $legend = $parse["settitle"];
                        } else {
                            $legend = "Default";
                        }
                        $attributes = array("legend" => $legend, "collapsed" => false);
                        $fieldset = $form->startFieldSet($attributes);
                        if (isset($parse["actions"])) {
                            foreach ($parse["actions"] as $aname => $action) {
                                if (!self::toggleAction($aname, $action)) {
                                    continue;
                                }
                                $action["attributes"]["label"] = ucfirst($action["attributes"]["name"]);
                                $action["attributes"]["name"] = $this->view . $this->iteration . "_" . $action["attributes"]["name"];
                                $action["attributes"]["url"] = url_for($action["attributes"]["url"]);
                                $obj = $this->prepareButton($form, $action['attributes']);
                            }
                        }
                        $attributes = array('name' => 'msg', 'label' => 'Message:', 'value' => $parse["message"], 'comment' => '', 'submitValue' => false);
                        $obj = new afExtjsFieldStatic($fieldset, $attributes);
                        $form->endFieldSet($fieldset);
                        $form->end();
                        if ($build) {
                            return $form;
                        }
                        if (!$this->multi) {
                            $this->layout->addItem('center', $form);
                            $this->layout->addCenterComponent($tools, array('title' => $parse["title"] . (class_exists('afExtjsWidgetConfig') ? afExtjsWidgetConfig::getPostfixTitle() : '')));
                        } else {
                            if ($this->type != self::PAGE) {
                                $panel->addItem($form);
                            } else {
                                if ($current_area["attributes"]["type"] == "content") {
                                    $this->addPortal($form, $parse["module"] . "/" . $action_name);
                                }
                            }
                        }
                    } else {
                        if ($view == "list") {
                            if (isset($parse["params"]["name"])) {
                                $formoptions['name'] = $parse["params"]["name"];
                            }
                            if (isset($parse["remoteSort"])) {
                                $formoptions["remoteSort"] = $parse["remoteSort"] == "false" ? false : true;
                            }
                            if (isset($parse["pagerTemplate"])) {
                                $formoptions["pagerTemplate"] = $parse["pagerTemplate"];
                            }
                            if (isset($this->page) && is_array($this->page)) {
                                foreach ($this->page["areas"]["content"]["tabs"] as $thisTab) {
                                    if (isset($thisTab["components"][$parse["component"]]) && isset($thisTab["components"][$parse["component"]]["bindForm"])) {
                                        $formoptions["bindForm"] = $thisTab["components"][$parse["component"]]["bindForm"];
                                    }
                                }
                            }
                            if (!isset($formoptions["bindForm"])) {
                                $formoptions["bindForm"] = -1;
                            }
                            $formoptions["autoHeight"] = true;
                            $formoptions["clearGrouping"] = false;
                            $formoptions["frame"] = false;
                            $formoptions["tree"] = $parse["tree"] == "false" ? false : true;
                            $formoptions["select"] = $parse["select"] == "false" ? false : true;
                            $formoptions["pager"] = $parse["pager"] == "false" ? false : true;
                            $formoptions["border"] = $parse["border"] == "false" ? false : true;
                            $formoptions["portal"] = $parse["portal"] == "false" ? false : true;
                            //$formoptions["id"] = strtolower(str_replace(" ","_",$parse['title']));
                            $formoptions["remoteLoad"] = ArrayUtil::isTrue($parse, 'remoteLoad');
                            $formoptions["remoteFilter"] = isset($parse['remoteFilter']) ? true : false;
                            $formoptions["expandButton"] = isset($parse['expandButton']) ? true : false;
                            $formoptions["path"] = $this->context->getModuleName() . "/" . $this->context->getActionName();
                            if ($parse['action'] != '') {
                                $formoptions['action'] = $parse['action'];
                            }
                            if ($this->type == self::PAGE) {
                                $formoptions["idxml"] = $parse["module"] . "/" . $action_name;
                            }
                            if (isset($parse["plugin"])) {
                                $formoptions["plugin"] = $parse["plugin"];
                            }
                            if (isset($parse["iconCls"])) {
                                $formoptions["iconCls"] = $parse["iconCls"];
                            }
                            if (isset($parse["bodyStyle"])) {
                                $formoptions["bodyStyle"] = $parse["bodyStyle"];
                            }
                            if (is_array($current_area) && $this->area_types[$current_area["attributes"]["type"]] == "south" || $current_area == "footer") {
                                $formoptions["title"] = "";
                            }
                            if (!isset($formoptions["title"])) {
                                if ($current_area == "footer") {
                                    $formoptions["title"] = " ";
                                } else {
                                    if (isset($parse["title"])) {
                                        $formoptions["title"] = $parse["title"];
                                    }
                                }
                            }
                            if ($formoptions["tree"]) {
                                $formoptions["root_title"] = isset($parse["title"]) ? $parse["title"] : "root";
                            }
                            if (is_array($current_area) && $this->area_types[$current_area["attributes"]["type"]] == "west" || $current_area == "sidebar") {
                                $formoptions["tools"] = null;
                            }
                            $formoptions['datasource'] = $parse['datasource'];
                            // Add the select fields in grid if it has moreactions..............
                            if (isset($parse["moreactions"])) {
                                $formoptions['select'] = "true";
                            }
                            //..................................................................
                            $formoptions['plugins'][] = afExtjsWidgets::getReloadPlugin($parse);
                            $grid = new afExtjsGrid($formoptions);
                            if (!$build && $widgetHelp) {
                                if ($this->multi) {
                                    $grid->addHelp($parse["description"]);
                                }
                            }
                            foreach ($parse["fields"] as $colname => $column) {
                                unset($column["attributes"]["id"]);
                                $column["attributes"]["hidden"] = ArrayUtil::isTrue($column['attributes'], 'hidden');
                                if (isset($column["attributes"]["qtip"]) && $column["attributes"]["qtip"] == "false") {
                                    $column["attributes"]["qtip"] = false;
                                }
                                $grid->addColumn($column["attributes"]);
                            }
                            $grid->setProxy(self::getProxyAttributes($parse));
                            if (isset($parse["rowactions"])) {
                                $actions = $grid->startRowActions(array('header' => 'Actions'));
                                $cnt = 1;
                                foreach ($parse["rowactions"] as $action_name => $action) {
                                    self::addConfirmation($action_name, $action['attributes']);
                                    self::fillTooltip($action["attributes"]);
                                    if (isset($parse["form"]) && $action["attributes"]["url"] === "/#") {
                                        $parse["rowactions"][$action_name]["attributes"]["url"] = $parse["form"] . "#";
                                    }
                                    if (isset($action["attributes"]["condition"])) {
                                        $parse["conditions"]["rowaction" . $cnt] = $action["attributes"]["condition"];
                                    }
                                    $parameterForRowAction = ExtEvent::getButtonParams($action, "rowactions", $this->view . $this->iteration, $parse["select"], $grid);
                                    $actions->addAction($action["attributes"]);
                                    $cnt++;
                                }
                                $grid->endRowActions($actions);
                            }
                            /**
                             * ticket 1140
                             */
                            //Check for more actions....................................................
                            $export_config = sfConfig::get('app_parser_export');
                            if (isset($export_config["enabled"]) && $export_config["enabled"] === true && $parse["exportable"] == "true") {
                                $exportConfig = array();
                                if (isset($parse["pager"]) && $parse["pager"] === "true") {
                                    //$grid->addMenuActionsItem(array('label'=>'Export Page as CSV', 'icon'=>'/images/famfamfam/database_save.png','listeners'=>array('click'=> array('parameters'=>'','source'=>'window.location.href='.$grid->getFileExportJsUrl('page')))));
                                    $exportConfig['csv']['current'] = 'window.location.href=' . $grid->getFileExportJsUrl('page');
                                }
                                if ($parse["tree"] === "false") {
                                    $confirmFunction = '
								Ext.Msg.show({
								   title:"Confirmation Required",
								   msg: "Are you sure you want export ' . sfConfig::get("app_parser_max_items") . ' items? This may take a while..",
								   buttons: Ext.Msg.YESNO,
								   fn: function(buttonId){if(buttonId == "yes"){' . 'window.location.href=' . $grid->getFileExportJsUrl('all') . '}},
								   icon: Ext.MessageBox.QUESTION								   
								});
							';
                                    //$grid->addMenuActionsItem(array('label'=>'Export first '.sfConfig::get("app_parser_max_items").' rows as CSV', 'confirmMsg' => 'foo', 'icon'=>'/images/famfamfam/database_save.png','listeners'=>array('click'=> array('parameters'=>'','source'=>$confirmFunction))));
                                    $exportConfig['csv']['firstx'] = $confirmFunction;
                                }
                                if ($formoptions["select"]) {
                                    $noItemsSelectedFunction = '								
							if(!' . $grid->privateName . '.getSelectionModel().getCount()){
								Ext.Msg.alert("No items selected","Please select at least one item");
								return;
							}
						';
                                    if (!ArrayUtil::isTrue($parse, 'remoteLoad')) {
                                        /*$grid->addMenuActionsItem(array('label'=>'Export Selected as CSV', 'forceSelection' => "true",
                                        		'icon'=>'/images/famfamfam/database_save.png','listeners'=>array('click'=> array('parameters'=>'','source'=>
                                        		"frm = document.createElement('form'); field = document.createElement('input'); field.setAttribute('type','hidden'); field.setAttribute('name','selections'); field.value = ".
                                        		$grid->privateName.".getSelectionModel().getSelectionsJSON(); frm.appendChild(field); frm.action = ".$grid->getFileExportJsUrl('selected')."+'&_csrf_token=".$this->context->getRequest()->getAttribute("_csrf_token")."'; frm.method='POST'; frm.name='frm1'; document.body.appendChild(frm); ".$noItemsSelectedFunction." frm.submit();"))));*/
                                        $exportConfig['csv']['selected'] = "frm = document.createElement('form'); field = document.createElement('input'); field.setAttribute('type','hidden'); field.setAttribute('name','selections'); field.value = " . $grid->privateName . ".getSelectionModel().getSelectionsJSON(); frm.appendChild(field); frm.action = " . $grid->getFileExportJsUrl('selected') . "+'&_csrf_token=" . $this->context->getRequest()->getAttribute("_csrf_token") . "'; frm.method='POST'; frm.name='frm1'; document.body.appendChild(frm); " . $noItemsSelectedFunction . " frm.submit();";
                                    }
                                }
                                /** sample example of other format type					
                                				$exportConfig['pdf']['current'] = 'handler source';
                                				$exportConfig['pdf']['selected'] = '';
                                				$exportConfig['xml']['current'] = '';
                                				$exportConfig['xml']['selected'] = '';
                                				$exportConfig['xml']['firstx'] = '';					
                                				*/
                                $grid->addMenuActionsExportButton($exportConfig);
                            }
                            if (isset($parse["moreactions"])) {
                                $parse["select"] = "true";
                                $items = array();
                                foreach ($parse["moreactions"] as $aname => $action) {
                                    if (!self::toggleAction($aname, $action)) {
                                        continue;
                                    }
                                    if (isset($action["handlers"])) {
                                        ExtEvent::attachAll($action);
                                    }
                                    $parameterForButton = ExtEvent::getButtonParams($action, "moreactions", $this->view . $this->iteration, $parse["select"], $grid);
                                    $grid->addMenuActionsItem($parameterForButton);
                                }
                            }
                            //More actions End............................................................
                            //...........................................................................
                            if (isset($parse["actions"])) {
                                foreach ($parse["actions"] as $aname => $action) {
                                    if (!self::toggleAction($aname, $action)) {
                                        continue;
                                    }
                                    if (isset($action["handlers"])) {
                                        ExtEvent::attachAll($action);
                                    }
                                    $parameterForButton = ExtEvent::getButtonParams($action, "actions", $this->view . $this->iteration, $parse["select"], $grid);
                                    $obj = new afExtjsButton($grid, $parameterForButton);
                                }
                            }
                            if ($parse["select"] != "false") {
                                $post_url = $parse["action"] != "false" && $parse["action"] != "n/a" ? "/" . $parse["action"] : "/" . $this->context->getModuleName() . "/" . $this->context->getActionName();
                                if ($parse["action"] != "false" && $parse["action"] != "n/a") {
                                    if (!$this->multisubmit) {
                                        new afExtjsButton($grid, array('label' => $parse["label"], 'icon' => $parse["icon"], 'handlers' => array('click' => array('parameters' => 'field,event', 'source' => 'Ext.Ajax.request({ url: "' . $post_url . '", 
							method:"post", params:{"selections":' . $grid->privateName . '.getSelectionModel().getSelectionsJSON()}, success:function(response, options){response=Ext.decode(response.responseText);if(response.message){Ext.Msg.alert("Success",response.message,function(){if(response.redirect){afApp.loadCenterWidget(response.redirect);}});}},failure: function(response,options) {if(response.message){Ext.Msg.alert("Failure",response.message);}}});'))));
                                    }
                                }
                            }
                            // Printing for grids..
                            $grid->updateTools($tools->addItem(array('id' => 'print', 'qtip' => "Printer friendly version", 'handler' => array('parameters' => 'e,target,panel', 'source' => "window.open(" . $grid->getFileExportJsUrl('page', 'pdf') . "+'&" . $this->getQueryString() . "','print');")), "item"));
                            // Add extra scripts..
                            if (array_key_exists("scripts", $parse)) {
                                $grid->addScripts($parse["scripts"]);
                            }
                            $grid->end();
                            if ($this->type == self::PAGE && $current_area["attributes"]["type"] == "content") {
                                $this->addPortal($grid, $parse["module"] . "/" . $parse["component"]);
                            }
                            if (is_array($current_area) && $this->area_types[$current_area["attributes"]["type"]] == "center") {
                                $this->multigrid = $grid;
                            }
                            if ($build === false) {
                                if (!$this->multi) {
                                    $this->layout->addItem($this->area_types[$current_area], $grid);
                                    if ($this->area_types[$current_area] == "center") {
                                        $this->layout->addCenterComponent($tools, array('title' => $parse["title"] . (class_exists('afExtjsWidgetConfig') ? afExtjsWidgetConfig::getPostfixTitle() : ''), "idxml" => $this->panelIdXml));
                                    }
                                } else {
                                    if ($current_area["attributes"]["type"] == "content") {
                                        if ($this->type != self::PAGE) {
                                            $panel->addItem($grid);
                                        }
                                    } else {
                                        $this->layout->addItem($this->area_types[$current_area["attributes"]["type"]], $grid);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if ($this->tabbedWizard) {
                switch ($view) {
                    case "show":
                    case "edit":
                    case "info":
                        $obj = $form;
                        break;
                    case "list":
                        $obj = $grid;
                        break;
                    case "html":
                        $obj = $pn;
                        break;
                }
                $wiztab = $this->getTabData($parse["component_name"]);
                $wizard_group->addItem($obj, array("title" => $wiztab[1], "tabTip" => $wiztab[2], "iconCls" => ""));
                if ($this->isLastGroupMember($parse["component_name"])) {
                    $this->openGroup = false;
                    $this->layout->endGroup($wizard_group);
                }
            }
        }
        if ($this->multi) {
            if ($this->type === self::WIZARD && !$this->tabbedWizard) {
                $this->layout->endColumn($panel);
            }
        }
        if ($this->multisubmit && $this->type !== self::WIZARD) {
            new afExtjsSubmitButton($this->forms[0], array('action' => $this->formaction, "label" => $parse["submitlabel"], 'afterSuccess' => '
				var myMask = new Ext.LoadMask(Ext.getBody(), {msg:"Saving additional information... <br>Please wait..."});
				myMask.show();
				Ext.Ajax.request({ url: "' . $this->multisubmit . '", method:"post", params:{"selections":' . $this->multigrid->privateName . '.getSelectionModel().getSelectionsJSON()}, success:function(response, options){response=Ext.decode(response.responseText);
if(response.message) {
	Ext.Msg.alert("Success", response.message, function(){
		if(response.redirect) {
			afApp.loadCenterWidget(response.redirect);
		}
	});
} else {
	if(response.redirect) {
		afApp.loadCenterWidget(response.redirect);
	}
}
	  	myMask.hide();
	  	},failure: function(response,options) {if(response.message){Ext.Msg.alert("Failure",response.message);myMask.hide();}}});'));
            $form->end();
        }
        // Adding layout buttons
        if ($this->type == self::WIZARD) {
            $actions = array("Previous" => 1, "Next" => 1, "Cancel" => 0, "Add new" => 1, "Finish" => 1);
            $add = "false";
            $finish = false;
            foreach ($actions as $key => $value) {
                if (isset($this->attribute_holder["last"]) && $key == "Next") {
                    continue;
                }
                if ($key == "Finish" && isset($this->page["actions"][$key])) {
                    $finish = true;
                }
                if ($key == "Add new" && isset($this->page["actions"][$key])) {
                    $add = "true";
                }
                if ($key == "Next") {
                    $icon = "/images/famfamfam/arrow_right.png";
                } else {
                    if ($key == "Previous") {
                        $icon = "/images/famfamfam/arrow_left.png";
                    } else {
                        $icon = "/images/famfamfam/accept.png";
                    }
                }
                if (isset($this->page["actions"][$key])) {
                    /*
                     * Find if grid data save request
                     */
                    $preExecute = '';
                    //$file = 'appFlowerPlugin/js/custom/'.self::isRequest($this->page["actions"][$key]["attributes"]["url"],'js').".js";
                    $file = '';
                    if (isset($this->page["actions"][$key]["attributes"]["script"])) {
                        if (file_exists(sfConfig::get('sf_root_dir') . "/plugins/appFlowerPlugin/web/js/custom/" . $this->page["actions"][$key]["attributes"]["script"] . ".js")) {
                            $file = 'appFlowerPlugin/js/custom/' . $this->page["actions"][$key]["attributes"]["script"] . ".js";
                        } else {
                            $file = '/js/custom/' . $this->page["actions"][$key]["attributes"]["script"] . ".js";
                        }
                    }
                    $preExecute = $file;
                    if ($this->page["actions"][$key]["attributes"]["post"] === "false" || !$value) {
                        new afExtjsLinkButton($this->layout, array('preExecute' => $preExecute, 'label' => $key, 'loadas' => 'page', 'url' => $this->page["actions"][$key]["attributes"]["url"], 'icon' => isset($icon) ? $icon : $this->page["actions"][$key]["attributes"]["icon"]));
                    } else {
                        $wizardSubmit = ArrayUtil::get($parse, 'params', 'wizard_submit', 'true') === 'true';
                        new afExtjsSubmitButton($this->layout, array('wizard' => $wizardSubmit, 'preExecute' => $preExecute, 'label' => $key, 'icon' => isset($icon) ? $icon : "/images/famfamfam/accept.png", 'action' => $this->page["actions"][$key]["attributes"]["url"]), $this->forms[0]);
                    }
                }
            }
            if (!$finish && isset($this->attribute_holder["last"])) {
                $id = '';
                if (isset($this->attribute_holder["id"])) {
                    $id = $this->attribute_holder["id"];
                }
                new afExtjsSubmitButton($this->layout, array('wizard' => true, 'label' => 'Finish', 'action' => "/wizard/finalize?last=" . $this->current . "&end=" . urlencode($this->attribute_holder['end']) . "&id=" . $id . "&add=" . $add), $this->forms[0]);
            }
        }
        if ($this->type == self::PAGE) {
            if ($this->portalStateObj->getLayoutType() == afPortalStatePeer::TYPE_TABBED) {
                $content = $this->portalStateObj->getContent();
                foreach ($content as $item => $itemDetails) {
                    $portalLayoutType = $this->portalStateObj->getPortalLayoutType($item);
                    $portalColumns = $this->portalStateObj->getColumns($item);
                    $portalColumnsSize = $this->portalStateObj->getColumnsSize($item);
                    ${'tab' . $item} = $this->layout->startTab(array('title' => isset($itemDetails["tabTitle"]) ? $itemDetails["tabTitle"] : $itemDetails["portalTitle"], 'portalLayoutType' => $portalLayoutType, 'portalWidgets' => $this->filterWidgets($item, $content, $this->widgets)));
                    foreach ($portalColumns as $k => $widgets) {
                        //instanciate a column
                        ${'column' . $k} = ${'tab' . $item}->startColumn(array('columnWidth' => $portalColumnsSize[$k] / 100));
                        foreach ($widgets as $widget) {
                            if (isset($this->extobjects[$widget->idxml])) {
                                ${'column' . $k}->addItem($this->extobjects[$widget->idxml]);
                            }
                        }
                        //end the instanciation of a column
                        ${'tab' . $item}->endColumn(${'column' . $k});
                    }
                    $this->layout->endTab(${'tab' . $item});
                }
            } else {
                foreach ($this->portalColumns as $k => $widgets) {
                    //instanciate a column
                    ${'column' . $k} = $this->layout->startColumn(array('columnWidth' => $this->portalColumnsSize[$k] / 100));
                    foreach ($widgets as $widget) {
                        if (isset($this->extobjects[$widget->idxml])) {
                            ${'column' . $k}->addItem($this->extobjects[$widget->idxml]);
                        }
                    }
                    //end the instanciation of a column
                    $this->layout->endColumn(${'column' . $k});
                }
            }
        }
        if ($this->multi) {
            self::$instance = null;
        }
        if ($build) {
            $this->result = $grid;
        }
        $layout_items = afExtjs::getInstance()->private;
        if (is_array($layout_items)) {
            $gridNames = $formIds = array();
            foreach ($layout_items as $privateName => $it) {
                if (preg_match("/bindForm: ([0-9]+),/", $it, $match)) {
                    $gridNames[$privateName] = trim($match[1]);
                }
                if (preg_match("/^form_[0-9a-zA-Z]+\$/", $privateName)) {
                    $formIds[] = $privateName;
                }
            }
            foreach ($gridNames as $privateName => $fid) {
                if (isset($formIds[$fid])) {
                    $layout_items[$privateName] = str_replace("bindForm: " . $fid . ",", "bindForm: '" . $formIds[$fid] . "',", $layout_items[$privateName]);
                }
            }
            afExtjs::$instance->private = $layout_items;
        }
        return true;
    }