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.api.string.php');
19: cInclude('includes', 'functions.api.images.php');
20:
21: 22: 23: 24: 25: 26:
27: class cGuiNavigation {
28:
29: 30: 31: 32:
33: public $data = array();
34:
35: 36: 37: 38:
39: protected $errors = array();
40:
41: 42: 43: 44: 45:
46: public function __construct() {
47: global $cfg;
48:
49: $this->xml = new cXmlReader();
50: $this->plugxml = new cXmlReader();
51:
52:
53: if ($this->xml->load($cfg['path']['xml'] . "navigation.xml") == false) {
54: throw new cException('Unable to load any XML language file');
55: }
56: }
57:
58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68:
69: public function getName($location) {
70: global $cfg, $belang;
71:
72:
73:
74: if (strstr($location, ';')) {
75: $locs = explode(';', $location);
76: $file = trim($locs[0]);
77: $xpath = trim($locs[1]);
78:
79: $filepath = explode('/', $file);
80: $counter = count($filepath) - 1;
81:
82: if ($filepath[$counter] == '') {
83: unset($filepath[$counter]);
84: $counter--;
85: }
86:
87: if (strstr($filepath[$counter], '.xml')) {
88: $filename = $filepath[$counter];
89: unset($filepath[$counter]);
90: $counter--;
91: }
92:
93: $filepath[($counter + 1)] = '';
94:
95: $filepath = implode('/', $filepath);
96:
97: if ($this->plugxml->load($cfg['path']['plugins'] . $filepath . $cfg['lang'][$belang]) == false) {
98: if (!isset($filename)) {
99: $filename = 'lang_en_US.xml';
100: }
101: if ($this->plugxml->load($cfg['path']['plugins'] . $filepath . $filename) == false) {
102: throw new cException("Unable to load $filepath XML language file");
103: }
104: }
105: $caption = $this->plugxml->getXpathValue('/language/' . $xpath);
106: } else {
107: $caption = $this->xml->getXpathValue('/language/' . $location);
108: }
109:
110: return i18n($caption);
111: }
112:
113: 114: 115:
116: public function () {
117: global $cfg, $perm;
118:
119: $db = cRegistry::getDb();
120: $db2 = cRegistry::getDb();
121:
122:
123: $sql = "SELECT idnavm, location FROM " . $cfg['tab']['nav_main'] . " ORDER BY idnavm";
124:
125: $db->query($sql);
126:
127:
128: while ($db->nextRecord()) {
129:
130:
131: $main = $this->getName($db->f('location'));
132:
133:
134: $this->data[$db->f('idnavm')] = array($main);
135:
136: $sql = "SELECT
137: a.location AS location, b.name AS area, b.relevant
138: FROM
139: " . $cfg['tab']['nav_sub'] . " AS a, " . $cfg['tab']['area'] . " AS b
140: WHERE
141: a.idnavm = " . $db->f('idnavm') . " AND
142: a.level = 0 AND
143: b.idarea = a.idarea AND
144: a.online = 1 AND
145: b.online = 1
146: ORDER BY
147: a.idnavs";
148:
149: $db2->query($sql);
150:
151: while ($db2->nextRecord()) {
152: $area = $db2->f('area');
153: if ($perm->have_perm_area_action($area) || $db2->f('relevant') == 0) {
154:
155: if (strpos($db2->f('location'), ';') !== false && $cfg['debug']['disable_plugins']) {
156: continue;
157: }
158:
159: try {
160: $name = $this->getName($db2->f('location'));
161: } catch(cException $e) {
162: $this->errors[] = i18n('Unable to load ' . $db2->f('location'));
163: continue;
164: }
165: $this->data[$db->f('idnavm')][] = array($name, $area);
166: }
167: }
168: }
169:
170:
171: cDebug::out(print_r($this->data, true));
172: }
173:
174: 175: 176: 177: 178:
179: public function ($lang) {
180: global $cfg, $sess, $client, $auth, $cfgClient;
181:
182: $this->_buildHeaderData();
183:
184: $main = new cTemplate();
185: $sub = new cTemplate();
186:
187: $cnt = 0;
188: $t_sub = '';
189: $numSubMenus = 0;
190:
191: $properties = new cApiPropertyCollection();
192: $clientImage = $properties->getValue('idclient', $client, 'backend', 'clientimage', false);
193:
194: $sJsEvents = '';
195: foreach ($this->data as $id => $item) {
196: $sub->reset();
197: $genSubMenu = false;
198:
199: foreach ($item as $key => $value) {
200: if (is_array($value)) {
201: $sub->set('s', 'SUBID', 'sub_' . $id);
202:
203:
204: $link = new cHTMLLink();
205: $link->disableAutomaticParameterAppend();
206: $link->setClass('sub');
207: $link->setID('sub_' . $value[1]);
208: $link->setLink($sess->url('frameset.php?area=' . $value[1]));
209: $link->setTargetFrame('content');
210: $link->setContent(i18n($value[0]));
211:
212: if ($cfg['help'] == true) {
213: $sJsEvents .= "\n\t" . '$("#sub_' . $value[1] . '").click(function() { $("#help").attr("data", "' . $value[0] . '"); })';
214: }
215: $sub->set('d', 'CAPTION', $link->render());
216:
217: $sub->next();
218: $genSubMenu = true;
219: }
220: }
221:
222: if ($genSubMenu == true) {
223: $link = new cHTMLLink();
224: $link->setClass('main');
225: $link->setID('main_' . $id);
226: $link->setLink('javascript://');
227: $link->setAttribute('ident', 'sub_' . $id);
228: $link->setContent(i18n($item[0]));
229:
230: $main->set('d', 'CAPTION', $link->render());
231: $main->next();
232:
233: $numSubMenus++;
234: } else {
235:
236: }
237:
238:
239: $t_sub .= $sub->generate($cfg['path']['templates'] . $cfg['templates']['submenu'], true);
240: $cnt++;
241: }
242:
243: if ($numSubMenus == 0) {
244: $main->set('d', 'CAPTION', ' ');
245: $main->next();
246: }
247:
248: $main->set('s', 'SUBMENUS', $t_sub);
249:
250: $backendUrl = cRegistry::getBackendUrl();
251:
252:
253: $link = new cHTMLLink();
254: $link->setClass('main');
255: $link->setTargetFrame('content');
256: $link->setLink($sess->url("frameset.php?area=mycontenido&frame=4"));
257: $link->setContent('<img class="vAlignMiddle" src="' . $backendUrl . $cfg['path']['images'] . 'my_contenido.gif" border="0" alt="My CONTENIDO" id="imgMyContenido" title="' . i18n("My CONTENIDO") . '">');
258: $main->set('s', 'MYCONTENIDO', $link->render());
259:
260:
261: $link = new cHTMLLink();
262: $link->setClass('main');
263: $link->setTargetFrame('content');
264: $link->setLink($sess->url('frameset.php?area=info&frame=4'));
265: $link->setContent('<img class="vAlignMiddle" src="' . $backendUrl . $cfg['path']['images'] . 'info.gif" border="0" alt="Info" title="Info" id="imgInfo">');
266: $main->set('s', 'INFO', $link->render());
267:
268: $main->set('s', 'LOGOUT', $sess->url('logout.php'));
269:
270: if ($cfg['help'] == true) {
271:
272: $link = new cHTMLLink();
273: $link->setID('help');
274: $link->setClass('main');
275: $link->setLink('javascript://');
276: $link->setEvent('click', 'Con.Help.show($(\'#help\').attr(\'data\'));');
277: $link->setContent('<img class="vAlignMiddle" src="' . $backendUrl . $cfg['path']['images'] . 'but_help.gif" border="0" alt="Hilfe" title="Hilfe">');
278: $main->set('s', 'HELP', $link->render());
279: } else {
280: $main->set('s', 'HELP', '');
281: }
282:
283: $oUser = new cApiUser($auth->auth["uid"]);
284: $clientCollection = new cApiClientCollection();
285:
286: if (getEffectiveSetting('system', 'clickmenu') == 'true') {
287:
288: $main->set('s', 'HEADER_MENU_OBJ', 'Con.HeaderClickMenu');
289: $main->set('s', 'HEADER_MENU_OPTIONS', '{menuId: "main_0", subMenuId: "sub_0"}');
290: } else {
291:
292: $mouseOver = getEffectiveSetting('system', 'delaymenu_mouseover', 300);
293: $mouseOot = getEffectiveSetting('system', 'delaymenu_mouseout', 1000);
294: $main->set('s', 'HEADER_MENU_OBJ', 'Con.HeaderDelayMenu');
295: $main->set('s', 'HEADER_MENU_OPTIONS', '{menuId: "main_0", subMenuId: "sub_0", mouseOverDelay: ' . $mouseOver . ', mouseOutDelay: ' . $mouseOot . '}');
296: }
297:
298: $main->set('s', 'ACTION', $sess->url('index.php'));
299:
300: if ($this->hasErrors()) {
301: $errors = $this->getErrors();
302: $errorString = '';
303: foreach ($errors as $error) {
304: $errorString .= $error.'<br>';
305: }
306: $errorString .= '<br>' . i18n('Some plugin menus can not be shown because of these errors.');
307: $helpBox = new cGuiBackendHelpbox($errorString, './images/but_warn.gif');
308: $main->set('s', 'LANG', $helpBox->render(true) . $this->_renderLanguageSelect());
309: } else {
310: $main->set('s', 'LANG', $this->_renderLanguageSelect());
311: }
312:
313: $sClientName = $clientCollection->getClientName($client);
314: if (strlen($sClientName) > 25) {
315: $sClientName = cApiStrTrimHard($sClientName, 25);
316: }
317:
318: $client = cSecurity::toInteger($client);
319: if ($client == 0) {
320: $sClientNameTemplate = '<b>' . i18n("Client") . ':</b> %s';
321: $main->set('s', 'CHOSENCLIENT', sprintf($sClientNameTemplate, $sClientName));
322: } else {
323: $sClientNameTemplate = '<b>' . i18n("Client") . ':</b> <a href="%s" target="_blank">%s</a>';
324:
325: $sClientName = '<span id="chosenclient">' . $clientCollection->getClientName($client) . ' (' . $client . ')</span>';
326: $sClientUrl = cRegistry::getFrontendUrl();
327: $frontendPath = cRegistry::getFrontendPath();
328:
329: if ($clientImage !== false && $clientImage != "" && cFileHandler::exists($frontendPath . $clientImage)) {
330: $sClientImageTemplate = '<img src="%s" alt="%s" title="%s">';
331:
332: $sThumbnailPath = cApiImgScale($frontendPath . $clientImage, 80, 25, 0, 1);
333: $sClientImageTag = sprintf($sClientImageTemplate, $sThumbnailPath, $sClientName, $sClientName);
334:
335: $main->set('s', 'CHOSENCLIENT', sprintf($sClientNameTemplate, $sClientUrl, $sClientImageTag));
336: } else {
337: $html = sprintf($sClientNameTemplate, $sClientUrl, $sClientName);
338: $html .= $this->_renderClientSelect();
339: $main->set('s', 'CHOSENCLIENT', $html);
340: }
341: }
342:
343: $main->set('s', 'CHOSENUSER', "<b>" . i18n("User") . ":</b> " . $oUser->getEffectiveName());
344: $main->set('s', 'MAINLOGINLINK', $sess->url("frameset.php?area=mycontenido&frame=4"));
345:
346:
347: $footerJs = '';
348: if ($sJsEvents !== '') {
349: $footerJs = '$(function() {' . $sJsEvents . '});';
350: }
351: $main->set('s', 'FOOTER_JS', $footerJs);
352:
353: $main->generate($cfg['path']['templates'] . $cfg['templates']['header']);
354: }
355:
356: 357: 358: 359: 360:
361: public function _renderLanguageSelect() {
362: global $cfg, $client, $lang;
363:
364: $tpl = new cTemplate();
365:
366: $tpl->set('s', 'NAME', 'changelang');
367: $tpl->set('s', 'CLASS', 'vAlignMiddle text_medium');
368: $tpl->set('s', 'ID', 'cLanguageSelect');
369: $tpl->set('s', 'OPTIONS', 'onchange="Con.Header.changeContenidoLanguage(this.value)"');
370:
371: $availableLanguages = new cApiLanguageCollection();
372:
373: if (getEffectiveSetting('system', 'languageorder', 'name') == 'name') {
374: $availableLanguages->select('', '', 'name ASC');
375: } else {
376: $availableLanguages->select('', '', 'idlang ASC');
377: }
378:
379: if ($availableLanguages->count() > 0) {
380: while (($myLang = $availableLanguages->nextAccessible()) !== false) {
381: $key = $myLang->get('idlang');
382: $value = $myLang->get('name');
383:
384: $clientsLang = new cApiClientLanguage();
385: $clientsLang->loadBy('idlang', cSecurity::toInteger($key));
386: if ($clientsLang->isLoaded()) {
387: if ($clientsLang->get('idclient') == $client) {
388: if ($key == $lang) {
389: $tpl->set('d', 'SELECTED', 'selected');
390: } else {
391: $tpl->set('d', 'SELECTED', '');
392: }
393:
394: if (strlen($value) > 20) {
395: $value = cApiStrTrimHard($value, 20);
396: }
397:
398: $tpl->set('d', 'VALUE', $key);
399: $tpl->set('d', 'CAPTION', $value . ' (' . $key . ')');
400: $tpl->next();
401: }
402: }
403: }
404: } else {
405: $tpl->set('d', 'VALUE', 0);
406: $tpl->set('d', 'CAPTION', i18n('-- No Language available --'));
407: $tpl->next();
408: }
409:
410: return $tpl->generate($cfg['path']['templates'] . $cfg['templates']['generic_select'], true);
411: }
412:
413: 414: 415: 416: 417:
418: protected function _renderClientSelect() {
419: $cfg = cRegistry::getConfig();
420: $client = cRegistry::getClientId();
421:
422: $clientCollection = new cApiClientCollection();
423: $clients = $clientCollection->getAccessibleClients();
424: if (count($clients) === 1) {
425: return '';
426: }
427:
428: $tpl = new cTemplate();
429: $tpl->set('s', 'NAME', 'changeclient');
430: $tpl->set('s', 'CLASS', 'vAlignMiddle text_medium nodisplay');
431: $tpl->set('s', 'ID', 'cClientSelect');
432: $tpl->set('s', 'OPTIONS', 'onchange="changeContenidoClient(this.value)"');
433:
434:
435: foreach ($clients as $idclient => $clientInfo) {
436: $name = $clientInfo['name'];
437: if ($idclient == $client) {
438: $tpl->set('d', 'SELECTED', 'selected');
439: } else {
440: $tpl->set('d', 'SELECTED', '');
441: }
442:
443: if (strlen($name) > 20) {
444: $name = cApiStrTrimHard($name, 20);
445: }
446:
447: $tpl->set('d', 'VALUE', $idclient);
448: $tpl->set('d', 'CAPTION', $name . ' (' . $idclient . ')');
449: $tpl->next();
450: }
451:
452: $html = $tpl->generate($cfg['path']['templates'] . $cfg['templates']['generic_select'], true);
453: $editButton = new cHTMLImage(cRegistry::getBackendUrl() . $cfg['path']['images'] . 'but_edithead.gif');
454: $editButton->setID('changeclient');
455: $editButton->setClass("vAlignMiddle");
456: $editButton->appendStyleDefinition('cursor', 'pointer');
457:
458: return $html . $editButton->render();
459: }
460:
461: 462: 463: 464: 465:
466: public function hasErrors() {
467: return count($this->errors) > 0;
468: }
469:
470: 471: 472: 473: 474:
475: public function getErrors() {
476: return $this->errors;
477: }
478: }
479: