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