/**
     * Saves the passed Element to the database (edit or new modes)
     *
     * @throws class_exception
     * @return string "" in case of success
     */
    protected function actionSaveElement()
    {
        $strReturn = "";
        //There are two modes - edit and new
        //The element itself just knows the edit mode, so in case of new, we have to create a dummy element - before
        //passing control to the element
        if ($this->getParam("mode") == "new") {
            //Using the passed placeholder-param to load the element and get the table
            $strPlaceholder = $this->getParam("placeholder");
            //Split up the placeholder
            $arrPlaceholder = explode("_", $strPlaceholder);
            $strPlaceholderName = $arrPlaceholder[0];
            $strPlaceholderElement = $this->getParam("element");
            //Now, load all infos about the requested element
            $objElement = class_module_pages_element::getElement($strPlaceholderElement);
            //Load the class to create an object
            $strElementClass = str_replace(".php", "", $objElement->getStrClassAdmin());
            //and finally create the object
            /** @var class_element_admin $objElement */
            $objElement = new $strElementClass();
            //really continue? try to validate the passed data.
            if ($objElement->getAdminForm() !== null && !$objElement->getAdminForm()->validateForm()) {
                class_carrier::getInstance()->setParam("peClose", "");
                $strReturn .= $this->actionNew(true);
                return $strReturn;
            } else {
                if (!$objElement->validateForm()) {
                    class_carrier::getInstance()->setParam("peClose", "");
                    $strReturn .= $this->actionNew(true);
                    return $strReturn;
                }
            }
            //So, lets do the magic - create the records
            $objPageElement = new class_module_pages_pageelement();
            $objPageElement->setStrName($strPlaceholderName);
            $objPageElement->setStrPlaceholder($strPlaceholder);
            $objPageElement->setStrElement($strPlaceholderElement);
            $objPageElement->setStrLanguage($this->getParam("page_element_ph_language"));
            if (!$objPageElement->updateObjectToDb($this->getSystemid())) {
                throw new class_exception("Error saving new element-object to db", class_exception::$level_ERROR);
            }
            $strElementSystemId = $objPageElement->getSystemid();
            $objLockmanager = new class_lockmanager($strElementSystemId);
            $objLockmanager->lockRecord();
            //To have the element working as expected, set the systemid
            $this->setSystemid($strElementSystemId);
        }
        // ************************************* Edit the current Element *******************************
        //check, if the element isn't locked
        $objCommons = new class_module_system_common($this->getSystemid());
        $strPageSystemid = $objCommons->getPrevId();
        $objLockmanager = new class_lockmanager($this->getSystemid());
        if ($objLockmanager->isLockedByCurrentUser()) {
            //Load the data of the current element
            $objElementData = new class_module_pages_pageelement($this->getSystemid());
            /** @var $objElement class_element_admin */
            $objElement = $objElementData->getConcreteAdminInstance();
            //really continue? try to validate the passed data.
            if ($objElement->getAdminForm() !== null && !$objElement->getAdminForm()->validateForm()) {
                class_carrier::getInstance()->setParam("peClose", "");
                $strReturn .= $this->actionEdit(true);
                return $strReturn;
            } else {
                if (!$objElement->validateForm()) {
                    class_carrier::getInstance()->setParam("peClose", "");
                    $strReturn .= $this->actionEdit(true);
                    return $strReturn;
                }
            }
            //pass the data to the element, maybe the element wants to update some data
            $objElement->setArrParamData($this->getAllParams());
            if ($objElement->getAdminForm() !== null) {
                $objElement->getAdminForm()->updateSourceObject();
            }
            $objElement->doBeforeSaveToDb();
            //check, if we could save the data, so the element needn't to
            //woah, we are soooo great
            $objElement->updateForeignElement();
            //Edit Date of page & unlock
            $objPage = class_objectfactory::getInstance()->getObject($strPageSystemid);
            $objPage->updateObjectToDb();
            $objLockmanager->unlockRecord();
            //And update the internal comment and language
            $objElementData->setStrTitle($this->getParam("page_element_ph_title"));
            $objElementData->setStrLanguage($this->getParam("page_element_ph_language"));
            //placeholder to update?
            if ($this->getParam("placeholder") != "") {
                $objElementData->setStrPlaceholder($this->getParam("placeholder"));
            }
            $objStartDate = new class_date("0");
            $objEndDate = new class_date("0");
            $objStartDate->generateDateFromParams("start", $this->getAllParams());
            $objEndDate->generateDateFromParams("end", $this->getAllParams());
            if ($objStartDate->getIntYear() == "0000") {
                $objElementData->setObjStartDate(null);
            } else {
                $objElementData->setObjStartDate($objStartDate);
            }
            if ($objEndDate->getIntYear() == "0000") {
                $objElementData->setObjEndDate(null);
            } else {
                $objElementData->setObjEndDate($objEndDate);
            }
            if (!$objElementData->updateObjectToDb()) {
                throw new class_exception("Error updating object to db", class_exception::$level_ERROR);
            }
            //allow the element to run actions after saving
            $objElement->doAfterSaveToDb();
            //Loading the data of the corresponding site
            $objPage = new class_module_pages_page($strPageSystemid);
            $this->flushCompletePagesCache();
            if ($this->getParam("peClose") == "1") {
                //generate the elements' output
                $objPortalElement = $objElementData->getConcretePortalInstance();
                $strElementContent = $objPortalElement->getElementOutput();
                $strContent = json_encode($strElementContent, JSON_FORCE_OBJECT);
                //JSON_HEX_QUOT|JSON_HEX_APOS
                $strReturn = <<<JS
                    parent.KAJONA.admin.portaleditor.changeElementData('{$objElementData->getStrPlaceholder()}', '{$objElementData->getSystemid()}', {$strContent});
                    parent.KAJONA.admin.portaleditor.closeDialog(true);

JS;
                class_carrier::getInstance()->setParam("peClose", null);
                return "<script type='text/javascript'>{$strReturn}</script>";
            }
            $this->adminReload(class_link::getLinkAdminHref("pages_content", "list", "systemid=" . $objPage->getSystemid()));
        } else {
            $strReturn = $this->objToolkit->warningBox($this->getLang("ds_gesperrt"));
        }
        return $strReturn;
    }