1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: cInclude('includes', 'functions.tpl.php');
19: cInclude('includes', 'functions.con.php');
20: cInclude('classes', 'class.layout.handler.php');
21:
22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35:
36: function layEditLayout($idlay, $name, $description, $code) {
37: global $client, $auth, $cfg, $sess, $lang, $area_tree, $perm, $area, $frame, $cfgClient;
38:
39: $db2 = cRegistry::getDb();
40: $db = cRegistry::getDb();
41:
42: $date = date('Y-m-d H:i:s');
43: $author = (string) $auth->auth['uname'];
44: if (true === cRegistry::getConfigValue('simulate_magic_quotes')) {
45: $name = stripslashes($name);
46: $description = stripslashes($description);
47: $code = stripslashes($code);
48: }
49:
50: if (strlen(trim($name)) == 0) {
51: $name = i18n('-- Unnamed layout --');
52: }
53:
54:
55: $layoutAlias = cModuleHandler::getCleanName(strtolower($name));
56:
57:
58: $layoutInFile = new cLayoutHandler($idlay, $code, $cfg, $lang);
59:
60:
61: $oVersion = new cVersionLayout($idlay, $cfg, $cfgClient, $db, $client, $area, $frame);
62:
63: $oVersion->setCode($layoutInFile->getLayoutCode());
64:
65: $oVersion->createNewVersion();
66:
67: if (!$idlay) {
68: $layoutCollection = new cApiLayoutCollection();
69: $layout = $layoutCollection->create($name, $client, $layoutAlias, $description, '1', $author);
70: $idlay = $layout->get('idlay');
71:
72: if ($layoutInFile->saveLayout($code) == false) {
73: cRegistry::addErrorMessage(i18n("Can't save layout in file"));
74: } else {
75: cRegistry::addOkMessage(i18n("Saved layout successfully!"));
76: }
77:
78:
79: cInclude('includes', 'functions.rights.php');
80: createRightsForElement('lay', $idlay);
81:
82: return $idlay;
83: } else {
84:
85: $layoutInFile = new cLayoutHandler($idlay, $code, $cfg, $lang);
86:
87: if ($layoutAlias != $layoutInFile->getLayoutName()) {
88:
89: if (cLayoutHandler::existLayout($layoutAlias, $cfgClient, $client) == true) {
90:
91: if ($layoutInFile->saveLayout($code) == false) {
92: cRegistry::addErrorMessage(i18n("Can't save layout in file!"));
93: }
94:
95:
96: cRegistry::addErrorMessage(i18n("Can't rename the layout!"));
97: die();
98: }
99:
100:
101: if ($layoutInFile->rename($layoutInFile->getLayoutName(), $layoutAlias)) {
102: if ($layoutInFile->saveLayout($code) == false) {
103: cRegistry::addWarningMessage(sprintf(i18n("The file %s has no write permissions. Saving only database changes!"), $layoutInFile->_getFileName()));
104: } else {
105: cRegistry::addOkMessage(i18n("Renamed layout succsessfully!"));
106: }
107: $layout = new cApiLayout(cSecurity::toInteger($idlay));
108: $layout->set('name', $name);
109: $layout->set('alias', $layoutAlias);
110: $layout->set('description', $description);
111: $layout->set('author', $author);
112: $layout->set('lastmodified', $date);
113: $layout->store();
114: } else {
115:
116:
117: if ($layoutInFile->saveLayout($code) == false) {
118: cRegistry::addErrorMessage(i18n("Can't save layout file!"));
119: }
120: }
121: } else {
122:
123: if ($layoutInFile->saveLayout($code) == false) {
124: cRegistry::addWarningMessage(sprintf(i18n("The file %s has no write permissions. Saving only database changes!"), $layoutInFile->_getFileName()));
125: } else {
126: cRegistry::addOkMessage(i18n("Saved layout successfully!"));
127: }
128: $layout = new cApiLayout(cSecurity::toInteger($idlay));
129: $layout->set('name', $name);
130: $layout->set('alias', $layoutAlias);
131: $layout->set('description', $description);
132: $layout->set('author', $author);
133: $layout->set('lastmodified', $date);
134: $layout->store();
135: }
136:
137:
138: conGenerateCodeForAllartsUsingLayout($idlay);
139:
140: return $idlay;
141: }
142: }
143:
144: 145: 146: 147: 148: 149: 150: 151:
152: function layDeleteLayout($idlay) {
153: global $client, $cfg, $area_tree, $perm, $cfgClient;
154:
155: $tplColl = new cApiTemplateCollection();
156: $tplColl->select('`idlay`=' . $idlay);
157: if ($tplColl->next()) {
158:
159: return '0301';
160: } else {
161:
162:
163: $layoutInFile = new cLayoutHandler($idlay, '', $cfg, 1);
164: if ($layoutInFile->eraseLayout()) {
165: if (cFileHandler::exists($cfgClient[$client]['version']['path'] . "layout" . DIRECTORY_SEPARATOR . $idlay)) {
166: cDirHandler::recursiveRmdir($cfgClient[$client]['version']['path'] . "layout" . DIRECTORY_SEPARATOR . $idlay);
167: }
168:
169:
170: $layoutCollection = new cApiLayoutCollection();
171: $layoutCollection->delete($idlay);
172: } else {
173: cRegistry::addErrorMessage(i18n("Can't delete layout!"));
174: }
175: }
176:
177:
178: cInclude('includes', 'functions.rights.php');
179: deleteRightsForElement('lay', $idlay);
180: }
181: