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: cInclude('includes', 'functions.rights.php');
85: createRightsForElement('lay', $idlay);
86:
87: return $idlay;
88: } else {
89:
90: $layoutInFile = new cLayoutHandler($idlay, $code, $cfg, $lang);
91:
92: if ($layoutAlias != $layoutInFile->getLayoutName()) {
93:
94: if (cLayoutHandler::existLayout($layoutAlias, $cfgClient, $client) == true) {
95:
96: if ($layoutInFile->saveLayout($code) == false) {
97: cRegistry::addErrorMessage(i18n("Can't save layout in file!"));
98: }
99:
100:
101: cRegistry::addErrorMessage(i18n("Can't rename the layout!"));
102: die();
103: }
104:
105:
106: if ($layoutInFile->rename($layoutInFile->getLayoutName(), $layoutAlias)) {
107: if ($layoutInFile->saveLayout($code) == false) {
108: cRegistry::addWarningMessage(sprintf(i18n("The file %s has no write permissions. Saving only database changes!"), $layoutInFile->_getFileName()));
109: } else {
110: cRegistry::addOkMessage(i18n("Renamed layout succsessfully!"));
111: }
112: $layout = new cApiLayout(cSecurity::toInteger($idlay));
113: $layout->set('name', $name);
114: $layout->set('alias', $layoutAlias);
115: $layout->set('description', $description);
116: $layout->set('author', $author);
117: $layout->set('lastmodified', $date);
118: $layout->store();
119: } else {
120:
121:
122: if ($layoutInFile->saveLayout($code) == false) {
123: cRegistry::addErrorMessage(i18n("Can't save layout file!"));
124: }
125: }
126: } else {
127:
128: if ($layoutInFile->saveLayout($code) == false) {
129: cRegistry::addWarningMessage(sprintf(i18n("The file %s has no write permissions. Saving only database changes!"), $layoutInFile->_getFileName()));
130: } else {
131: cRegistry::addOkMessage(i18n("Saved layout successfully!"));
132: }
133: $layout = new cApiLayout(cSecurity::toInteger($idlay));
134: $layout->set('name', $name);
135: $layout->set('alias', $layoutAlias);
136: $layout->set('description', $description);
137: $layout->set('author', $author);
138: $layout->set('lastmodified', $date);
139: $layout->store();
140: }
141:
142:
143: conGenerateCodeForAllartsUsingLayout($idlay);
144:
145: return $idlay;
146: }
147: }
148:
149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161:
162: function layDeleteLayout($idlay) {
163: global $client, $cfg, $area_tree, $perm, $cfgClient;
164:
165: $tplColl = new cApiTemplateCollection();
166: $tplColl->select('`idlay`=' . $idlay);
167: if ($tplColl->next()) {
168:
169: return '0301';
170: } else {
171:
172:
173: $layoutInFile = new cLayoutHandler($idlay, '', $cfg, 1);
174: if ($layoutInFile->eraseLayout()) {
175: if (cFileHandler::exists($cfgClient[$client]['version']['path'] . "layout" . DIRECTORY_SEPARATOR . $idlay)) {
176: cDirHandler::recursiveRmdir($cfgClient[$client]['version']['path'] . "layout" . DIRECTORY_SEPARATOR . $idlay);
177: }
178:
179:
180: $layoutCollection = new cApiLayoutCollection();
181: $layoutCollection->delete($idlay);
182: } else {
183: cRegistry::addErrorMessage(i18n("Can't delete layout!"));
184: }
185: }
186:
187:
188: cInclude('includes', 'functions.rights.php');
189: deleteRightsForElement('lay', $idlay);
190: }
191: