1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: cInclude('includes', 'functions.tpl.php');
18: cInclude('includes', 'functions.con.php');
19:
20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44:
45: function modEditModule($idmod, $name, $description, $input, $output, $template, $type = '') {
46: global $db, $client, $cfgClient, $auth, $cfg, $sess, $area, $area_tree, $perm, $frame;
47: $description = stripslashes($description);
48:
49: $date = date('Y-m-d H:i:s');
50: $author = $auth->auth['uname'];
51: $contenidoModuleHandler = '';
52: $messageIfError = '';
53:
54:
55: $alias = cString::toLowerCase(cModuleHandler::getCleanName($name));
56:
57:
58: $oVersion = new cVersionModule($idmod, $cfg, $cfgClient, $db, $client, $area, $frame);
59: $oVersion->createNewVersion();
60:
61: if (!$idmod) {
62: $cApiModuleCollection = new cApiModuleCollection();
63: $cApiModule = $cApiModuleCollection->create($name);
64:
65: $idmod = $cApiModule->get('idmod');
66:
67: cInclude('includes', 'functions.rights.php');
68: createRightsForElement('mod', $idmod);
69: } else {
70: $cApiModule = new cApiModule($idmod);
71: }
72:
73: $contenidoModuleHandler = new cModuleHandler($idmod);
74:
75:
76: $retInput = $contenidoModuleHandler->saveInput(stripslashes($input));
77: $retOutput = $contenidoModuleHandler->saveOutput(stripslashes($output));
78:
79:
80: if ($retInput || $retOutput) {
81: $purge = new cSystemPurge();
82: $purge->clearClientCache($client);
83: }
84:
85: if ($cApiModule->get('name') != stripslashes($name) || $cApiModule->get('alias') != stripslashes($alias) || $cApiModule->get('template') != stripslashes($template) || $cApiModule->get('description') != stripslashes($description) || $cApiModule->get('type') != stripslashes($type)) {
86:
87:
88: $change = false;
89: $oldName = $cApiModule->get('alias');
90:
91: if ($cApiModule->get('alias') != $alias) {
92: $change = true;
93:
94: if ($contenidoModuleHandler->modulePathExistsInDirectory($alias)) {
95: cRegistry::addErrorMessage(i18n('Module name exist in module directory, please choose another name.'));
96: $page = new cGuiPage('generic_page');
97: $page->abortRendering();
98: $page->render();
99: die();
100: }
101: }
102:
103:
104: if ($change == true) {
105: cRegistry::addOkMessage(i18n('Renamed module successfully!'));
106: $cApiModule->set('name', $name);
107: $cApiModule->set('template', $template);
108: $cApiModule->set('description', $description);
109: $cApiModule->set('type', $type);
110: $cApiModule->set('lastmodified', date('Y-m-d H:i:s'));
111:
112:
113: if ($contenidoModuleHandler->renameModul($oldName, $alias) == false) {
114: cRegistry::addWarningMessage(i18n("Can't rename module, is a module file open?! Saving only database changes!"));
115: } else {
116: $cApiModule->set('alias', $alias);
117: }
118:
119: $cApiModule->store();
120:
121:
122: $contenidoModuleHandler->changeModuleName($alias);
123:
124: if ($contenidoModuleHandler->saveInput(stripslashes($input)) == false) {
125: $messageIfError .= '<br>' . i18n("Can't save input !");
126: }
127:
128: if ($contenidoModuleHandler->saveOutput(stripslashes($output)) == false) {
129: $messageIfError .= '<br>' . i18n("Can't save output !");
130: }
131:
132: if ($contenidoModuleHandler->saveInfoXML($name, $description, $type, $alias) == false) {
133: $messageIfError .= '<br>' . i18n("Can't save xml module info file!");
134: }
135:
136:
137: if ($messageIfError !== '') {
138: cRegistry::addErrorMessage($messageIfError);
139:
140: $cApiModule->set('name', $oldName);
141: $cApiModule->store();
142: }
143: } else {
144: $cApiModule->set('name', $name);
145: $cApiModule->set('template', $template);
146: $cApiModule->set('description', $description);
147: $cApiModule->set('type', $type);
148: $cApiModule->set('lastmodified', date('Y-m-d H:i:s'));
149: $cApiModule->set('alias', $alias);
150: $cApiModule->store();
151:
152: if ($contenidoModuleHandler->saveInfoXML($name, $description, $type, $alias) == false) {
153: cRegistry::addErrorMessage(i18n("Can't save xml module info file!"));
154: }
155:
156: if ($retInput === true && $retOutput === true) {
157: cRegistry::addOkMessage(i18n('Saved module successfully!'));
158: } else {
159: $messageIfError = '<br>' . i18n("Can't save input !");
160: $messageIfError .= '<br>' . i18n("Can't save output !");
161: cRegistry::addErrorMessage($messageIfError);
162: }
163: }
164: } else {
165:
166: if ($retInput == true && $retOutput == true) {
167:
168: $cApiModule->store();
169: cRegistry::addOkMessage(i18n('Saved module successfully!'));
170: } else {
171: $messageIfError = i18n("Can't save input !");
172: $messageIfError .= ' ' . i18n("Can't save output !");
173: cRegistry::addErrorMessage($messageIfError);
174: }
175: }
176:
177: return $idmod;
178: }
179:
180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190:
191: function modDeleteModule($idmod) {
192: global $db, $client, $cfg;
193: global $sess, $area_tree, $perm;
194:
195: $sql = 'DELETE FROM ' . $cfg['tab']['mod'] . ' WHERE idmod = ' . (int) $idmod . ' AND idclient = ' . (int) $client;
196: $db->query($sql);
197:
198:
199: cInclude('includes', 'functions.rights.php');
200: deleteRightsForElement('mod', $idmod);
201: }
202: