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