/**
  * Adds a Flexiskin defined by data via request parameter
  * @return String encoded result JSON string
  */
 public function addFlexiskin()
 {
     $aData = FormatJson::decode($this->getMain()->getVal('data', ""));
     $oData = $aData[0];
     if (is_null($oData->template)) {
         return FormatJson::encode(array('success' => false, 'msg' => wfMessage('bs-flexiskin-error-templatenotexists')->plain()));
     }
     if (empty($oData->template)) {
         $oData->template = 'default';
     }
     $sId = str_replace(" ", "_", strtolower($oData->name));
     $sFlexiskinPath = BsFileSystemHelper::getDataDirectory('flexiskin' . DS . md5($sId));
     if (is_dir($sFlexiskinPath)) {
         return FormatJson::encode(array('success' => false, 'msg' => wfMessage('bs-flexiskin-error-skinexists')->plain()));
     }
     //PW(27.11.2013) TODO: add check template really exists before add
     if (empty($oData->name)) {
         //PW(27.11.2013) TODO: add msg
         return FormatJson::encode(array('success' => false, 'msg' => wfMessage('bs-flexiskin-error-nameempty')->plain()));
     }
     if ($oData->template != 'default') {
         $oConfig = $this->getConfigFromId($oData->template);
         if (!$oConfig->isGood()) {
             return FormatJson::encode(array('success' => false, 'msg' => wfMessage('bs-flexiskin-error-templatenotexists')->plain()));
         }
         $oConf = FormatJson::decode($oConfig->getValue());
         $oConf[0]->name = $oData->name;
         $oConf[0]->desc = $oData->desc;
         $sConfigFile = FormatJson::encode($oConf);
     } else {
         $sConfigFile = Flexiskin::generateConfigFile($oData);
     }
     $oStatus = BsFileSystemHelper::saveToDataDirectory('conf.json', $sConfigFile, "flexiskin" . DS . md5($sId));
     if (!$oStatus->isGood()) {
         return FormatJson::encode(array('success' => false, 'msg' => wfMessage('bs-flexiskin-error-fail-add-skin', $this->getErrorMessage($oStatus))->plain()));
     }
     if ($oData->template != 'default') {
         $oStatus = BsFileSystemHelper::copyFile('variables.less', "flexiskin" . DS . $oData->template, "flexiskin" . DS . md5($sId));
         $oStatus = BsFileSystemHelper::copyFolder("images", "flexiskin" . DS . $oData->template, "flexiskin" . DS . md5($sId));
     } else {
         $oStatus = BsFileSystemHelper::saveToDataDirectory('variables.less', Flexiskin::generateStyleFile($sConfigFile), "flexiskin" . DS . md5($sId));
     }
     $oStatus = BsFileSystemHelper::saveToDataDirectory('screen.less', Flexiskin::generateScreenFile(), "flexiskin" . DS . md5($sId));
     $oStatus = BsFileSystemHelper::saveToDataDirectory('screen.tmp.less', Flexiskin::generateScreenFile(true), "flexiskin" . DS . md5($sId));
     //tbd: check 1st, 2nd and 3rd status
     if (!$oStatus->isGood()) {
         return FormatJson::encode(array('success' => false, 'msg' => wfMessage('bs-flexiskin-error-fail-add-skin', $this->getErrorMessage($oStatus))->plain()));
     }
     BsFileSystemHelper::ensureDataDirectory("flexiskin" . DS . md5($sId) . DS . "images");
     return FormatJson::encode(array('success' => true));
 }