/**
  * Searches the root-node for a users' widgets.
  * If not given, the node is created on the fly.
  * Those nodes are required to ensure a proper sort-handling on the system-table
  *
  * @param string $strUserid
  * @param string $strAspectId
  * @return string
  * @static
  */
 public static function getWidgetsRootNodeForUser($strUserid, $strAspectId = "")
 {
     if ($strAspectId == "") {
         $strAspectId = class_module_system_aspect::getCurrentAspectId();
     }
     $strQuery = "SELECT system_id\n        \t\t\t  FROM " . _dbprefix_ . "dashboard,\n        \t\t\t  \t   " . _dbprefix_ . "system\n        \t\t\t WHERE dashboard_id = system_id\n        \t\t\t   AND system_prev_id = ?\n        \t\t\t   AND dashboard_user = ?\n        \t\t\t   AND dashboard_aspect = ?\n        \t\t\t   AND dashboard_class = ?\n        \t     ORDER BY system_sort ASC ";
     $arrRow = class_carrier::getInstance()->getObjDB()->getPRow($strQuery, array(class_module_system_module::getModuleByName("dashboard")->getSystemid(), $strUserid, $strAspectId, "root_node"));
     if (!isset($arrRow["system_id"]) || !validateSystemid($arrRow["system_id"])) {
         //Create a new root-node on the fly
         $objWidget = new class_module_dashboard_widget();
         $objWidget->setStrAspect($strAspectId);
         $objWidget->setStrUser($strUserid);
         $objWidget->setStrClass("root_node");
         $objWidget->updateObjectToDb(class_module_system_module::getModuleByName("dashboard")->getSystemid());
         $strReturnId = $objWidget->getSystemid();
     } else {
         $strReturnId = $arrRow["system_id"];
     }
     return $strReturnId;
 }
 /**
  * Generates the forms to add a widget to the dashboard
  *
  * @return string, "" in case of success
  * @autoTestable
  * @permissions edit
  */
 protected function actionAddWidgetToDashboard()
 {
     $strReturn = "";
     //step 1: select a widget, plz
     if ($this->getParam("step") == "") {
         $arrWidgetsAvailable = class_module_dashboard_widget::getListOfWidgetsAvailable();
         $arrDD = array();
         foreach ($arrWidgetsAvailable as $strOneWidget) {
             /** @var $objWidget interface_adminwidget|class_adminwidget */
             $objWidget = new $strOneWidget();
             $arrDD[$strOneWidget] = $objWidget->getWidgetName();
         }
         $arrColumnsAvailable = array();
         foreach ($this->arrColumnsOnDashboard as $strOneColumn) {
             $arrColumnsAvailable[$strOneColumn] = $this->getLang($strOneColumn);
         }
         $strReturn .= $this->objToolkit->formHeader(class_link::getLinkAdminHref("dashboard", "addWidgetToDashboard"));
         $strReturn .= $this->objToolkit->formInputDropdown("widget", $arrDD, $this->getLang("widget"));
         $strReturn .= $this->objToolkit->formInputDropdown("column", $arrColumnsAvailable, $this->getLang("column"));
         $strReturn .= $this->objToolkit->formInputHidden("step", "2");
         $strReturn .= $this->objToolkit->formInputSubmit($this->getLang("addWidgetNextStep"));
         $strReturn .= $this->objToolkit->formClose();
         $strReturn .= $this->objToolkit->setBrowserFocus("widget");
     } else {
         if ($this->getParam("step") == "2") {
             $strWidgetClass = $this->getParam("widget");
             /** @var class_adminwidget|interface_adminwidget $objWidget */
             $objWidget = new $strWidgetClass();
             if ($objWidget->getEditForm() == "") {
                 $this->adminReload(class_link::getLinkAdminHref("dashboard", "addWidgetToDashboard", "&step=3&widget=" . $strWidgetClass . "&column=" . $this->getParam("column")));
             } else {
                 //ask the widget to generate its form-parts and wrap our elements around
                 $strReturn .= $this->objToolkit->formHeader(class_link::getLinkAdminHref("dashboard", "addWidgetToDashboard"));
                 $strReturn .= $objWidget->getEditForm();
                 $strReturn .= $this->objToolkit->formInputHidden("step", "3");
                 $strReturn .= $this->objToolkit->formInputHidden("widget", $strWidgetClass);
                 $strReturn .= $this->objToolkit->formInputHidden("column", $this->getParam("column"));
                 $strReturn .= $this->objToolkit->formInputSubmit($this->getLang("commons_save"));
                 $strReturn .= $this->objToolkit->formClose();
             }
         } else {
             if ($this->getParam("step") == "3") {
                 //instantiate the concrete widget
                 $strWidgetClass = $this->getParam("widget");
                 /** @var class_adminwidget|interface_adminwidget $objWidget */
                 $objWidget = new $strWidgetClass();
                 //let it process its fields
                 $objWidget->loadFieldsFromArray($this->getAllParams());
                 //and save the dashboard-entry
                 $objDashboard = new class_module_dashboard_widget();
                 $objDashboard->setStrClass($strWidgetClass);
                 $objDashboard->setStrContent($objWidget->getFieldsAsString());
                 $objDashboard->setStrColumn($this->getParam("column"));
                 $objDashboard->setStrUser($this->objSession->getUserID());
                 $objDashboard->setStrAspect(class_module_system_aspect::getCurrentAspectId());
                 if ($objDashboard->updateObjectToDb(class_module_dashboard_widget::getWidgetsRootNodeForUser($this->objSession->getUserID(), class_module_system_aspect::getCurrentAspectId()))) {
                     $this->adminReload(class_link::getLinkAdminHref($this->getArrModule("modul")));
                 } else {
                     return $this->getLang("errorSavingWidget");
                 }
             }
         }
     }
     return $strReturn;
 }