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