/** * public static getCloneFromID * * Clones a Row, changes some attributes * and writes it to persistence (MySQL for now) * * @param anyRowID as the ID of Row to be cloned * @param String label receive a new label for this Row * @param boolean $setPrivate Should the template be set as a private one ? ALSO determines if the new row should point to the same file * @return a valid new CMS_row */ static function getCloneFromID($rowID = 0, $label = false, $setPrivate = false) { $ret = false; $model = new CMS_row($rowID); if ($model->getID() > 0) { //New blank one $row = new CMS_row(); //First write a new object to get it's ID $row->writeToPersistence(); //Setting label $label = $label ? $label : $model->getLabel(); $row->setLabel($label); //Copying template definition file (if not private template) if ($setPrivate) { $filename = $model->getDefinitionFileName(); } else { $filename = "r" . $row->getID() . "_" . SensitiveIO::sanitizeAsciiString($row->getLabel()) . ".xml"; } if ($setPrivate || CMS_file::copyTo(PATH_TEMPLATES_ROWS_FS . "/" . $model->getDefinitionFileName(), PATH_TEMPLATES_ROWS_FS . "/" . $filename)) { $row->setDefinitionFile($filename); //Copying groupsStack from database foreach ($model->getGroups() as $grp) { $row->addGroup($grp); } //Copying image $row->setImage($model->getImage(CMS_file::WEBROOT, true)); //set private if asked to. if ($setPrivate) { $row->setPrivate(true); } //copy description $row->setDescription($model->getDescription()); //add filtered templates $row->setFilteredTemplates($model->getFilteredTemplates()); //Partial update for groups and image $row->writeToPersistence(); $ret = $row; } unset($model); } if ($row) { //Clean if any error when out if (!$ret) { $row->destroy(); } unset($row); } return $ret; }
} //load row if any if (sensitiveIO::isPositiveInteger($rowId)) { $row = CMS_rowsCatalog::getByID($rowId); if (!$row || $row->hasError()) { CMS_grandFather::raiseError('Unknown row for given Id : ' . $rowId); $view->show(); } } else { //create new row $row = new CMS_row(); } //MAIN TAB //Need to sanitize all datas which can contain single quotes $label = $row->getLabel(); $description = sensitiveIO::sanitizeJSString($row->getDescription(), false, true, true); //this is a textarea, we must keep cariage return $rowDefinition = $row->getDefinition(); $rowGroups = $row->getGroups(); //image $maxFileSize = CMS_file::getMaxUploadFileSize('K'); $imageDatas = array('filename' => '', 'filepath' => '', 'filesize' => '', 'fileicon' => '', 'extension' => ''); $imageDatas = sensitiveIO::jsonEncode($imageDatas); //Groups $allGroups = CMS_rowsCatalog::getAllGroups(); $groupsfield = ''; if ($allGroups) { $columns = sizeof($allGroups) < 5 ? sizeof($allGroups) : 5; $groupsfield .= "{\n\t\txtype: \t\t'checkboxgroup',\n\t\tfieldLabel: '<span class=\"atm-help\" ext:qtip=\"{$cms_language->getJsMessage(MESSAGE_FIELD_GROUPS_DESC)}\">{$cms_language->getJsMessage(MESSAGE_FIELD_GROUPS)}</span>',\n\t\tcolumns: \t{$columns},\n\t\titems: ["; foreach ($allGroups as $aGroup) { $groupsfield .= "{boxLabel: '{$aGroup}', inputValue:'{$aGroup}', name: 'groups[]', checked:" . (isset($rowGroups[$aGroup]) ? 'true' : 'false') . "},";