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