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