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: cRights::createRightsForElement('mod', $idmod);
68: } else {
69: $cApiModule = new cApiModule($idmod);
70: }
71:
72: $contenidoModuleHandler = new cModuleHandler($idmod);
73:
74:
75: $retInput = $contenidoModuleHandler->saveInput(stripslashes($input));
76: $retOutput = $contenidoModuleHandler->saveOutput(stripslashes($output));
77:
78:
79: if ($retInput || $retOutput) {
80: $purge = new cSystemPurge();
81: $purge->clearClientCache($client);
82: }
83:
84: 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)) {
85:
86:
87: $change = false;
88: $oldName = $cApiModule->get('alias');
89:
90: if ($cApiModule->get('alias') != $alias) {
91: $change = true;
92:
93: if ($contenidoModuleHandler->modulePathExistsInDirectory($alias)) {
94: cRegistry::addErrorMessage(i18n('Module name exist in module directory, please choose another name.'));
95: $page = new cGuiPage('generic_page');
96: $page->abortRendering();
97: $page->render();
98: die();
99: }
100: }
101:
102:
103: if ($change == true) {
104: cRegistry::addOkMessage(i18n('Renamed module successfully!'));
105: $cApiModule->set('name', $name);
106: $cApiModule->set('template', $template);
107: $cApiModule->set('description', $description);
108: $cApiModule->set('type', $type);
109: $cApiModule->set('lastmodified', date('Y-m-d H:i:s'));
110:
111:
112: if ($contenidoModuleHandler->renameModul($oldName, $alias) == false) {
113: cRegistry::addWarningMessage(i18n("Can't rename module, is a module file open?! Saving only database changes!"));
114: } else {
115: $cApiModule->set('alias', $alias);
116: }
117:
118: $cApiModule->store();
119:
120:
121: $contenidoModuleHandler->changeModuleName($alias);
122:
123: if ($contenidoModuleHandler->saveInput(stripslashes($input)) == false) {
124: $messageIfError .= '<br>' . i18n("Can't save input !");
125: }
126:
127: if ($contenidoModuleHandler->saveOutput(stripslashes($output)) == false) {
128: $messageIfError .= '<br>' . i18n("Can't save output !");
129: }
130:
131: if ($contenidoModuleHandler->saveInfoXML($name, $description, $type, $alias) == false) {
132: $messageIfError .= '<br>' . i18n("Can't save xml module info file!");
133: }
134:
135:
136: if ($messageIfError !== '') {
137: cRegistry::addErrorMessage($messageIfError);
138:
139: $cApiModule->set('name', $oldName);
140: $cApiModule->store();
141: }
142: } else {
143: $cApiModule->set('name', $name);
144: $cApiModule->set('template', $template);
145: $cApiModule->set('description', $description);
146: $cApiModule->set('type', $type);
147: $cApiModule->set('lastmodified', date('Y-m-d H:i:s'));
148: $cApiModule->set('alias', $alias);
149: $cApiModule->store();
150:
151: if ($contenidoModuleHandler->saveInfoXML($name, $description, $type, $alias) == false) {
152: cRegistry::addErrorMessage(i18n("Can't save xml module info file!"));
153: }
154:
155: if ($retInput === true && $retOutput === true) {
156: cRegistry::addOkMessage(i18n('Saved module successfully!'));
157: } else {
158: $messageIfError = '<br>' . i18n("Can't save input !");
159: $messageIfError .= '<br>' . i18n("Can't save output !");
160: cRegistry::addErrorMessage($messageIfError);
161: }
162: }
163: } else {
164:
165: if ($retInput == true && $retOutput == true) {
166:
167: $cApiModule->store();
168: cRegistry::addOkMessage(i18n('Saved module successfully!'));
169: } else {
170: $messageIfError = i18n("Can't save input !");
171: $messageIfError .= ' ' . i18n("Can't save output !");
172: cRegistry::addErrorMessage($messageIfError);
173: }
174: }
175:
176: return $idmod;
177: }
178:
179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189:
190: function modDeleteModule($idmod) {
191: global $db, $client, $cfg;
192: global $sess, $area_tree, $perm;
193:
194: $sql = 'DELETE FROM ' . $cfg['tab']['mod'] . ' WHERE idmod = ' . (int) $idmod . ' AND idclient = ' . (int) $client;
195: $db->query($sql);
196:
197:
198: cRights::deleteRightsForElement('mod', $idmod);
199: }
200: