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