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