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: 37: 38: 39: 40:
41: function layEditLayout($idlay, $name, $description, $code) {
42: global $client, $auth, $cfg, $sess, $lang, $area_tree, $perm, $area, $frame, $cfgClient;
43:
44: $db2 = cRegistry::getDb();
45: $db = cRegistry::getDb();
46:
47: $date = date('Y-m-d H:i:s');
48: $author = (string) $auth->auth['uname'];
49: if (true === cRegistry::getConfigValue('simulate_magic_quotes')) {
50: $name = stripslashes($name);
51: $description = stripslashes($description);
52: $code = stripslashes($code);
53: }
54:
55: if (cString::getStringLength(trim($name)) == 0) {
56: $name = i18n('-- Unnamed layout --');
57: }
58:
59:
60: $layoutAlias = cModuleHandler::getCleanName(cString::toLowerCase($name));
61:
62:
63: $layoutInFile = new cLayoutHandler($idlay, $code, $cfg, $lang);
64:
65:
66: $oVersion = new cVersionLayout($idlay, $cfg, $cfgClient, $db, $client, $area, $frame);
67:
68: $oVersion->setCode($layoutInFile->getLayoutCode());
69:
70: $oVersion->createNewVersion();
71:
72: if (!$idlay) {
73: $layoutCollection = new cApiLayoutCollection();
74: $layout = $layoutCollection->create($name, $client, $layoutAlias, $description, '1', $author);
75: $idlay = $layout->get('idlay');
76:
77: if ($layoutInFile->saveLayout($code) == false) {
78: cRegistry::addErrorMessage(i18n("Can't save layout in file"));
79: } else {
80: cRegistry::addOkMessage(i18n("Saved layout successfully!"));
81: }
82:
83:
84: cRights::createRightsForElement('lay', $idlay);
85:
86: return $idlay;
87: } else {
88:
89: $layoutInFile = new cLayoutHandler($idlay, $code, $cfg, $lang);
90:
91: if ($layoutAlias != $layoutInFile->getLayoutName()) {
92:
93: if (cLayoutHandler::existLayout($layoutAlias, $cfgClient, $client) == true) {
94:
95: if ($layoutInFile->saveLayout($code) == false) {
96: cRegistry::addErrorMessage(i18n("Can't save layout in file!"));
97: }
98:
99:
100: cRegistry::addErrorMessage(i18n("Can't rename the layout!"));
101: die();
102: }
103:
104:
105: if ($layoutInFile->rename($layoutInFile->getLayoutName(), $layoutAlias)) {
106: if ($layoutInFile->saveLayout($code) == false) {
107: cRegistry::addWarningMessage(sprintf(i18n("The file %s has no write permissions. Saving only database changes!"), $layoutInFile->_getFileName()));
108: } else {
109: cRegistry::addOkMessage(i18n("Renamed layout succsessfully!"));
110: }
111: $layout = new cApiLayout(cSecurity::toInteger($idlay));
112: $layout->set('name', $name);
113: $layout->set('alias', $layoutAlias);
114: $layout->set('description', $description);
115: $layout->set('author', $author);
116: $layout->set('lastmodified', $date);
117: $layout->store();
118: } else {
119:
120:
121: if ($layoutInFile->saveLayout($code) == false) {
122: cRegistry::addErrorMessage(i18n("Can't save layout file!"));
123: }
124: }
125: } else {
126:
127: if ($layoutInFile->saveLayout($code) == false) {
128: cRegistry::addWarningMessage(sprintf(i18n("The file %s has no write permissions. Saving only database changes!"), $layoutInFile->_getFileName()));
129: } else {
130: cRegistry::addOkMessage(i18n("Saved layout successfully!"));
131: }
132: $layout = new cApiLayout(cSecurity::toInteger($idlay));
133: $layout->set('name', $name);
134: $layout->set('alias', $layoutAlias);
135: $layout->set('description', $description);
136: $layout->set('author', $author);
137: $layout->set('lastmodified', $date);
138: $layout->store();
139: }
140:
141:
142: conGenerateCodeForAllartsUsingLayout($idlay);
143:
144: return $idlay;
145: }
146: }
147:
148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160:
161: function layDeleteLayout($idlay) {
162: global $client, $cfg, $area_tree, $perm, $cfgClient;
163:
164: $tplColl = new cApiTemplateCollection();
165: $tplColl->select('`idlay`=' . $idlay);
166: if ($tplColl->next()) {
167:
168: return '0301';
169: } else {
170:
171:
172: $layoutInFile = new cLayoutHandler($idlay, '', $cfg, 1);
173: if ($layoutInFile->eraseLayout()) {
174: if (cFileHandler::exists($cfgClient[$client]['version']['path'] . "layout" . DIRECTORY_SEPARATOR . $idlay)) {
175: cDirHandler::recursiveRmdir($cfgClient[$client]['version']['path'] . "layout" . DIRECTORY_SEPARATOR . $idlay);
176: }
177:
178:
179: $layoutCollection = new cApiLayoutCollection();
180: $layoutCollection->delete($idlay);
181: } else {
182: cRegistry::addErrorMessage(i18n("Can't delete layout!"));
183: }
184: }
185:
186:
187: cRights::deleteRightsForElement('lay', $idlay);
188: }
189: