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