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