Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
backend_outputter.inc
1 <?php
18 require_once SQ_LIB_PATH.'/html_form/html_form.inc';
19 
20 // just normal messages, eg update confirmations
21 define('SQ_BO_MSG_NOTICE', 1);
22 // warnings, you entered something a bit a-miss and the system fixed it up for you
23 define('SQ_BO_MSG_WARNING', 2);
24 // something is just plain wrong, fix immediately
25 define('SQ_BO_MSG_ERROR', 4);
26 
27 
41 {
42 
43  // any messages to be displayed to the user
44  var $_messages = Array();
45 
46  // an link to redirect to when we print, any messages will be carried over to the next page
47  var $_redirect = '';
48  var $_redirect_target = '';
49 
50  // an array of fns to be called when the page loads
51  var $_on_load_calls = Array();
52 
53  // an array assets that are going to be refreshed in the flash menu
54  var $_refreshing_assets = Array();
55 
56  // the form action
57  var $_action = '';
58 
59  // form GET vars that the backend outputter will endevour to ensure are on each screen
60  var $_persistant_get_vars = Array();
61 
62  // the anchor the form will be submitted to
63  var $_anchor = '';
64 
65  // the page heading
66  var $_page_title = '';
67  var $_heading = '';
68  var $_heading_icon = '';
69  var $_sub_heading = '';
70 
71  // stylesheet files to include
72  var $_css_includes = Array();
73 
74  // javascript files to include
75  var $_js_includes = Array();
76 
77  // an array of fns to be called when the form is submitted
78  var $_on_submit_calls = Array();
79 
80  // hidden fields for the form Array([field name] => [value])
81  var $_hidden_fields = Array();
82 
83  // edit screens
84  var $_screens = Array();
85  var $_static_screens = Array();
86 
87  // the contents of the page split into sections
88  var $_contents = Array();
89 
90  // used to make sure that each img gets a unique name
91  var $_img_button_count = 0;
92 
93  // all the preload images names on the page and their preloaded images
94  // Array(name => img);
95  var $_preload_imgs = Array();
96 
97  var $_files_path;
98 
99  var $_raw_opened = FALSE;
100 
101  var $_section_stack = Array();
102  var $_current_field = NULL;
103 
104  var $_section_count = 0;
105  var $_field_count = 0;
106 
107  var $_charset = '';
108 
113  var $_buffering = TRUE;
114 
119  var $_is_open_section = FALSE;
120 
125  var $_is_open_field = FALSE;
126 
131  var $_current_field_type = '';
132 
137  var $_current_field_note = '';
138 
143  var $_nb_section_count = 0;
144 
145 
151  function Backend_Outputter()
152  {
153 
154  // if there are some messages from the previous page we had better add them in
155  if (!empty($_SESSION['backend_outputter_msgs'])) {
156  $this->_messages = $_SESSION['backend_outputter_msgs'];
157  $_SESSION['backend_outputter_msgs'] = Array();
158  }
159 
160  $this->_files_path = sq_web_path('lib').'/web';
161  $this->_action = $_SERVER['PHP_SELF'];
162 
163  // register that we want to listen to link update events
164  $em = $GLOBALS['SQ_SYSTEM']->getEventManager();
165 
166  $em->addEventListener($this, Array(
167  'CreateLink',
168  'DeleteLink',
169  'AssetUpdate',
170  'AssetTypeUpdate',
171  'BackendMessage',
172  'AssetStatusUpdate',
173  )
174  );
175 
176  }//end constructor
177 
178 
187  function setBuffering($buffer=TRUE)
188  {
189  $this->_buffering = (bool) $buffer;
190  return TRUE;
191 
192  }//end setBuffering()
193 
194 
204  function setRedirect($link, $target='self')
205  {
206  // ensure that any persistant GET vars are appended to the redirect URL
207  $link_extras = '';
208  foreach ($this->_persistant_get_vars as $name => $value) {
209  $link_extras .= '&'.rawurlencode($name).'='.rawurlencode($value);
210  }
211  $link_extras = trim($link_extras, ' &');
212  if (!empty($link_extras)) {
213  $link .= ((strstr($link, '?')) ? '&' : '?').$link_extras;
214  }
215 
216  $this->_redirect = trim($link);
217  $this->_redirect_target = trim($target);
218 
219  }//end setRedirect()
220 
221 
230  function addOnLoad($call)
231  {
232  $this->_on_load_calls[] = $call;
233 
234  }//end addOnLoad()
235 
236 
247  function addFormActionGetVar($name, $value, $persistant=FALSE)
248  {
249  if (FALSE === strpos($this->_action, '?')) {
250  $url = $this->_action;
251  $query = '';
252  } else {
253  list($url, $query) = explode('?', $this->_action);
254  }
255  $this->_action = replace_query_string_vars(Array($name => rawurlencode($value)), $url, $query);
256  if ($persistant) {
257  $this->_persistant_get_vars[$name] = $value;
258  }
259 
260  }//end addFormActionGetVar()
261 
262 
270  {
271  return $this->_action;
272 
273  }//end getCurrentLocation()
274 
275 
284  function setFormAnchor($anchor)
285  {
286  $anchor = trim($anchor);
287  $this->_anchor = ($anchor) ? '//'.rawurlencode($anchor) : '';
288 
289  }//end setFormAnchor()
290 
291 
298  function setPageTitle($title)
299  {
300  $this->_page_title = trim($title);
301 
302  }//end setPageTitle()
303 
304 
314  function setHeading($heading, $icon='')
315  {
316  $this->_heading = trim($heading);
317  $this->_heading_icon = $icon;
318 
319  }//end setHeading()
320 
321 
331  function setSubHeading($heading, $icon='')
332  {
333  $this->_sub_heading = trim($heading);
334 
335  }//end setSubHeading()
336 
337 
347  function addMessage($type, $msg)
348  {
349  $msg = trim($msg);
350  // if the type is valid and there is a message
351  if (strlen($msg)) {
352  $this->_messages[] = Array('type' => $type, 'msg' => $msg);
353  }
354 
355  }//end addMessage()
356 
357 
366  function addCssInclude($file)
367  {
368  if (in_array($file, $this->_css_includes)) return;
369  $this->_css_includes[] = $file;
370 
371  }//end addCssInclude()
372 
373 
382  function addJsInclude($file)
383  {
384  if (in_array($file, $this->_js_includes)) return;
385  $this->_js_includes[] = $file;
386 
387  }//end addJsInclude()
388 
389 
398  function addOnSubmit($call)
399  {
400  $this->_on_submit_calls[] = $call;
401 
402  }//end addOnSubmit()
403 
404 
414  function addHiddenField($name, $value='')
415  {
416  $this->_hidden_fields[$name] = $value;
417 
418  }//end addHiddenField()
419 
420 
430  function addScreen($url, $name)
431  {
432  if (empty($url)) return;
433  if (in_array($name, $this->_screens)) {
434  trigger_localised_error('SYS0202', E_USER_ERROR, $name);
435  }
436  $this->_screens[$url] = $name;
437 
438  }//end addScreen()
439 
440 
450  function addStaticScreen($url, $name)
451  {
452  if (empty($url)) return;
453  if (in_array($name, $this->_static_screens)) {
454  trigger_localised_error('SYS0207', E_USER_ERROR, $name);
455  }
456  $this->_static_screens[$url] = $name;
457 
458  }//end addStaticScreen()
459 
460 
469  function addPreloadImg($file)
470  {
471  $this->_preload_imgs[] = $file;
472 
473  }//end addPreloadImg()
474 
475 
484  function setCharset($charset)
485  {
486  $this->_charset = $charset;
487 
488  }//end setCharset()
489 
490 
497  function openRaw()
498  {
499  $init_arr = Array(
500  'area_type' => 'section',
501  'type' => 'raw',
502  'contents' => '',
503  );
504 
505  $ret_val = $this->_openSection($init_arr);
506  ob_start();
507  $this->_raw_opened = TRUE;
508  return $ret_val;
509 
510  }//end openRaw()
511 
512 
519  function closeRaw()
520  {
521  if (!$this->_raw_opened) return;
522  $stack_i = count($this->_section_stack) - 1;
523  $this->_section_stack[$stack_i]['contents'] = ob_get_contents();
524  ob_end_clean();
525  $this->_raw_opened = FALSE;
526  $this->_closeSection();
527 
528  }//end closeRaw()
529 
530 
540  function openSection($heading='', $icon='')
541  {
542  $init_arr = Array(
543  'area_type' => 'section',
544  'type' => 'normal',
545  'heading' => $heading,
546  'icon' => $icon,
547  'areas' => Array(),
548  );
549  return $this->_openSection($init_arr);
550 
551  }//end openSection()
552 
553 
560  function closeSection()
561  {
562  if (!is_null($this->_current_field)) {
563  $this->closeField();
564  }
565 
566  if ($this->_buffering) {
567  $this->_closeSection();
568  } else {
569  $this->_nbCloseSection();
570  $this->_nb_section_count--;
571  if ($this->_nb_section_count == 0) {
572  $this->_is_open_section = FALSE;
573  }
574  }
575 
576  }//end closeSection()
577 
578 
587  function _openSection($init_arr)
588  {
589  if ($this->_is_open_field) $this->closeField();
590 
591  if ($this->_buffering) {
592  if (!is_null($this->_current_field)) {
593  $this->closeField();
594  }
595  if ($this->_raw_opened) $this->closeRaw();
596 
597  $this->_section_count++;
598  $init_arr['section_count'] = $this->_section_count;
599 
600  // Nothing in the stack ? we are in the top level
601  if (empty($this->_section_stack)) {
602  $j = count($this->_contents);
603  $this->_contents[$j] = $init_arr;
604  $this->_section_stack[] =& $this->_contents[$j];
605  } else {
606  $i = count($this->_section_stack) - 1;
607  $j = count($this->_section_stack[$i]['areas']);
608  $this->_section_stack[$i]['areas'][$j] = $init_arr;
609  $this->_section_stack[] =& $this->_section_stack[$i]['areas'][$j];
610  }
611 
612  return 'section_'.$this->_section_count;
613 
614  } else {
615  $this->_nbOpenSection($init_arr);
616  }
617 
618  }//end _openSection()
619 
620 
629  function _nbOpenSection($init_arr)
630  {
631  if ($this->_nb_section_count > 0) echo '<tr><td>';
632 
633  $this->_nb_section_count++;
634 
635  ?>
636  <a name="section_<?php echo $this->_nb_section_count; ?>"></a>
637  <table class="sq-backend-section-table">
638  <?php
639  if (isset($init_arr['heading']) && $init_arr['heading']) {
640  if ($this->_is_open_section) {
641  // printing a nested section - needs to look a little different
642  ?>
643  <tr>
644  <td class="sq-backend-section-subheading"><?php echo $init_arr['heading'];?></td>
645  </tr>
646  <?php
647  } else {
648  $this->_is_open_section = TRUE;
649  // printing a top level section
650  ?>
651  <tr class="sq-backend-section-heading-container">
652  <td>
653  <table border="0" cellspacing="0" cellpadding="0">
654  <tr>
655  <td class="sq-backend-section-heading"><?php echo $init_arr['heading'];?></td>
656  <td><img src="<?php echo $this->filesPath('images/section_icon.gif');?>" width="27" height="21" /></td>
657  </tr>
658  </table>
659  </td>
660  </tr>
661  <?php
662  }//endif
663  }//endif
664 
665  ?>
666  <tr>
667  <td>
668  <table class="sq-backend-section-table-inner">
669  <?php
670 
671 
672  }//end _nbOpenSection()
673 
674 
681  function _closeSection()
682  {
683  if ($this->_buffering) {
684  array_pop($this->_section_stack);
685  } else {
686  $this->_nbCloseSection();
687  }
688 
689  }//end _closeSection()
690 
691 
698  function _nbCloseSection()
699  {
700  if ($this->_nb_section_count > 0) echo '</td></tr>';
701 
702  ?>
703  </table>
704  </td>
705  </tr>
706  </table>
707  <?php
708 
709  }//end _nbCloseSection()
710 
711 
724  function openField($name, $format='', $note='', $hidden=FALSE, $id_name='')
725  {
726  if ($this->_buffering) {
727  if (!is_null($this->_current_field)) {
728  $this->closeField();
729  }
730  if (empty($this->_section_stack)) $this->openSection();
731  if (!trim($name)) $name = '&nbsp;';
732 
733  $this->_field_count++;
734 
735  $stack_i = count($this->_section_stack) - 1;
736  $i = count($this->_section_stack[$stack_i]['areas']);
737  $this->_section_stack[$stack_i]['areas'][$i] = Array(
738  'area_type' => 'field',
739  'type' => 'normal',
740  'field_count' => $this->_field_count,
741  'name' => $name,
742  'format' => $format,
743  'note' => $note,
744  'contents' => '',
745  'hidden' => $hidden,
746  'id_name' => $id_name,
747  );
748 
749  $this->_current_field =& $this->_section_stack[$stack_i]['areas'][$i];
750  ob_start();
751 
752  return 'field_'.$this->_field_count;
753 
754  } else {
755  // we are not buffering
756  $this->_nbOpenField($name, $format, $note, $hidden);
757  }
758 
759  }//end openField()
760 
761 
773  function _nbOpenField($name, $format='', $note='', $hidden=FALSE)
774  {
775  if ($this->_is_open_field) $this->closeField();
776  $this->_is_open_field = TRUE;
777 
778  // store the format and note of the current field for future reference
779  $this->_current_field_type = $format;
780  $this->_current_field_note = $note;
781 
782  switch ($format) {
783  case 'new_line' :
784  ?>
785  <tr <?php if ($hidden) echo 'style="display: none"'; ?>>
786  <td class="sq-backend-field sq-backend-field-newline" colspan="2">
787  <a name="field_<?php echo $this->_field_count; ?>"></a>
788  <?php echo $name;?>
789  </td>
790  </tr>
791  <tr <?php if ($hidden) echo 'style="display: none"'; ?>>
792  <td class="sq-backend-data sq-backend-data-newline" colspan="2">
793  <?php
794  break;
795 
796  case 'commit' :
797  ?>
798  <tr <?php if ($hidden) echo 'style="display: none"'; ?>>
799  <td class="sq-backend-data" style="text-align: right;" colspan="2">
800  <?php
801  break;
802 
803  case 'blank' :
804  // a blank field to be used just for formatting
805  break;
806 
807  default :
808  ?>
809  <tr <?php if ($hidden) echo 'style="display: none"'; ?>>
810  <td class="sq-backend-field">
811  <a name="field_<?php echo $this->_field_count; ?>"></a>
812  <?php echo $name;?>
813  </td>
814  <td class="sq-backend-data">
815  <?php
816  }//end switch
817 
818  }//end _nbOpenField()
819 
820 
827  function closeField()
828  {
829 
830  if ($this->_buffering) {
831  if (is_null($this->_current_field)) return;
832  $this->_current_field['contents'] = ob_get_contents();
833  ob_end_clean();
834  // unset the reference before setting to null, so we don't blow away the field's array
835  unset($this->_current_field);
836  $this->_current_field = NULL;
837  } else {
838  $this->_nbCloseField();
839  }
840 
841  }//end closeField()
842 
843 
850  function _nbCloseField()
851  {
852  $this->_is_open_field = FALSE;
853 
854  // We need to end the field that we started
855  // Because they all start differently, we have to end what we started
856  switch ($this->_current_field_type) {
857 
858  case 'blank' :
859  // a blank field to be used just for formatting
860  break;
861 
862  default :
863  if ($this->_current_field_note) {
864  $this->note($this->_current_field_note);
865  }
866  ?>
867  </td>
868  </tr>
869  <?php
870  }//end switch
871 
872  }//end _nbCloseField()
873 
874 
883  function filesPath($file='')
884  {
885  if ($file && substr($file, 0, 1) != '/') {
886  $file = '/'.$file;
887  }
888  return $this->_files_path.$file;
889 
890  }//end filesPath()
891 
892 
899  function paint()
900  {
901  if ($this->_raw_opened) $this->closeRaw();
902  // close all sections
903  while (!empty($this->_section_stack)) {
904  $this->closeSection();
905  }
906 
907  if ($this->_redirect) {
908  // save the messages so they come through on the next page
909  $_SESSION['backend_outputter_msgs'] = $this->_messages;
910  $this->addOnLoad($this->_redirect_target.'.location = "'.addslashes($this->_redirect).'";');
911  }
912 
913  $this->_paintHeader();
914 
915  if (!$this->_redirect) {
916  for ($i = 0; $i < count($this->_contents); $i++) {
917  $this->_paintSection($this->_contents[$i]);
918  }
919  }
920 
921  $this->_paintFooter();
922 
923  }//end paint()
924 
925 
932  function getAsString()
933  {
934  ob_start();
935  $this->paint();
936  $str = ob_get_contents();
937  ob_end_clean();
938 
939  return $str;
940 
941  }//end getAsString()
942 
943 
950  function _paintHeader()
951  {
952  if (!headers_sent()) {
953  if ($this->_charset) {
954  header('Content-type: text/html; charset='.$this->_charset);
955  } else {
956  header('Content-type: text/html; charset='.SQ_CONF_DEFAULT_CHARACTER_SET);
957  }
958  }
959  ?>
960  <html>
961  <head>
962  <title><?php echo htmlspecialchars(str_replace('&nbsp;', ' ', $this->_page_title)); ?></title>
963  <?php
964  $this->addCssInclude($this->filesPath('css/edit.css'));
965  if (!empty($_REQUEST['print_view'])) {
966  $this->addCssInclude($this->filesPath('css/print.css'));
967  $this->addOnLoad('pagePrint()');
968  }
969 
970  foreach ($this->_css_includes as $file) {
971  $this->_paintCssInclude($file);
972  }
973 
974  // Add IE6-specific styles if main frame AND "lock commit button to frame" preference turned on
975  if ((array_get_index($_GET, 'SQ_BACKEND_PAGE') == 'main') && SQ_IN_BACKEND && $GLOBALS['SQ_SYSTEM']->getUserPrefs('user', 'SQ_USER_COMMIT_BUTTON_POS')) {
976 
977  // Bug #3096 - Printing incorrectly in IE
978  // Associated with the CSS involved with hanging the Commit Button to the bottom of the page
979  // If print_view is not enabled show the commit button code
980  if (!isset($_REQUEST['print_view'])) {
981  ?>
982  <!--[if gte IE 6]>
983  <link href="<?php echo $this->filesPath('css/edit_ie6.css') ?>" type="text/css" rel="stylesheet" />
984  <![endif]-->
985  <?php
986  }//end if
987  }
988 
989  // first add the js translation files
990  foreach ($GLOBALS['SQ_SYSTEM']->lm->getJavascriptIncludes() as $js_include) {
991  $this->addJsInclude($js_include);
992  }
993 
994  // now other general stuff
995  $this->addJsInclude(sq_web_path('lib').'/html_form/html_form.js');
996  $this->addJsInclude(sq_web_path('lib').'/js/general.js');
997  $this->addJsInclude(sq_web_path('lib').'/js/backend_search.js');
998  $this->addJsInclude(sq_web_path('lib').'/js/debug.js');
999  $this->addJsInclude(sq_web_path('lib').'/js/edit.js');
1000  $this->addJsInclude(sq_web_path('lib').'/js/state.js');
1001  $this->addJsInclude(sq_web_path('lib').'/js/tooltip.js');
1002  $this->addOnLoad('fixIcons(\''.sq_web_path('lib').'/web/images/blank.gif\');');
1003 
1004  // and paint them all out
1005  foreach ($this->_js_includes as $file) {
1006  $this->_paintJsInclude($file);
1007  }
1008  ?>
1009  <script type="text/javascript"><!--
1010  //<![CDATA[
1011  var SQ_DOCUMENT_LOADED = false;
1012  function page_on_load()
1013  {
1014  <?php
1015  if (isset($_SESSION['backend_outputter_msgs'])) {
1016  $this->_messages = array_merge($this->_messages, $_SESSION['backend_outputter_msgs']);
1017  $_SESSION['backend_outputter_msgs'] = Array();
1018  }
1019  if (count($this->_messages)) {
1020  require_once 'XML/Tree.php';
1021  require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
1022  $msgs = new XML_Tree();
1023  $msgs_root = $msgs->addRoot('messages');
1024  foreach ($this->_messages as $data) {
1025  $msg_body = '<p>'.htmlentities(nl2br($data['msg']), ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET).'</p>';
1026  $msg_body .= '<span style="color: #333333">'.$GLOBALS['SQ_SYSTEM']->datetime().'<span>';
1027  $msgs_root->addChild('message', $msg_body, Array('type' => get_bit_names('SQ_BO_MSG_', $data['type'])));
1028  }
1029  ?>
1030  if (parent.frames["sq_sidenav"] && parent.frames["sq_sidenav"].add_messages) {
1031  parent.frames["sq_sidenav"].add_messages("<?php echo str_replace(Array("\r\n", "\n", "\r"), "\\n", addslashes($msgs->get())); ?>");
1032  }
1033  <?php
1034  }//end if messages
1035  ?>
1036 
1037  if (window.self.name == 'sq_main') {
1038  tooltip.print();
1039  }
1040 
1041  <?php
1042  foreach ($this->_on_load_calls as $call) {
1043  echo "\n".$call;
1044  }
1045  ?>
1046 
1047  // let everyone know the document is loaded
1048  SQ_DOCUMENT_LOADED = true;
1049 
1050  // if IE
1051  if (document.all) {
1052  if (document.getElementById('sq-commit-button-div')) {
1053  commit_div = document.getElementById('sq-commit-button-div');
1054  if (commit_div.currentStyle && (commit_div.currentStyle.position == 'absolute')) {
1055  document.body.style.paddingBottom = (commit_div.clientHeight + 2) + "px";
1056  }
1057  }
1058  } else {
1059  if (document.getElementById('sq-commit-button-div')) {
1060  document.getElementById('sq-commit-button-spacer').style.height = (document.getElementById('sq-commit-button-div').clientHeight + 2) + "px";
1061  }
1062  }
1063 
1064  // Remember state
1065  resetChanges();
1066  document.forms[0]['state'].value = saveState();
1067 
1068  }//end page_on_load()
1069 
1070 
1071  function page_on_unload()
1072  {
1073  if (parent.frames['sq_sidenav'] && window.self.name == 'sq_main' && parent.frames['sq_sidenav'].asset_finder_onunload) {
1074  parent.frames['sq_sidenav'].asset_finder_onunload();
1075  }
1076 
1077  }//end page_on_unload()
1078 
1079 
1080  var SQ_FORM_SUBMITTED = false;
1081  var SQ_FORM_ERROR_CONTAINED = false;
1082  function form_on_submit()
1083  {
1084  if (SQ_FORM_SUBMITTED) {
1085  alert(js_translate('form_already_submitted'));
1086  return;
1087  }
1088 
1089  <?php
1090  foreach ($this->_on_submit_calls as $call) {
1091  echo $call.";\n";
1092  }
1093  ?>
1094 
1095  // if the form contains errors and we don't want to submit, handle at here.
1096  if (SQ_FORM_ERROR_CONTAINED) {
1097  alert(js_translate('form_contains_error'));
1098  return;
1099  }
1100 
1101  // basically if they get this far then we can submit
1102  SQ_FORM_SUBMITTED = true;
1103 
1104  // If we are submitting the header frame, we are probably
1105  // submitting the search... so add "search in progress"
1106  // screen
1107  if (self.name == 'sq_header') {
1108  // Only pop-up the "search in progress" box if there's something to search on
1109  if (self.document.getElementById("asset_search").value != '') {
1110  top.frames["sq_main"].document.getElementById("sq-search-wait-popup").style.display = "block";
1111  }
1112 
1113  screenMenu = top.frames["sq_main"].document.getElementById("sq_screen_menu");
1114  screenMenuFiller = top.frames["sq_main"].document.getElementById("sq_screen_menu_filler");
1115 
1116  if (screenMenu) {
1117  if (window.navigator.userAgent.indexOf('MSIE') > 0) {
1118  screenMenuFiller.style.width = screenMenu.offsetWidth;
1119  screenMenuFiller.style.height = screenMenu.offsetHeight;
1120  screenMenuFiller.style.display = "block";
1121  screenMenu.style.display = "none";
1122  }
1123  screenMenu.style.MozOpacity = "0";
1124  }
1125 
1126  if (reload_timeout) {
1127  clearTimeout(reload_timeout);
1128  }
1129  }
1130 
1131  // disable all submit buttons
1132  disable_buttons();
1133 
1134  // Update the form state
1135  makeChanges();
1136 
1137  return true;
1138 
1139  }//end form_on_submit()
1140 
1141  <?php
1142  foreach ($this->_preload_imgs as $file) {
1143  ?>
1144  preload_image('<?php echo $file;?>');
1145  <?php
1146  }//end foreach
1147  ?>
1148 
1149  //]]> -->
1150  </script>
1151  </head>
1152  <body onload="page_on_load();" onunload="page_on_unload();">
1153  <div id="sq-search-wait-popup"><div id="sq-search-wait-popup-titlebar"><div id="sq-search-wait-popup-close">[ <a href="#" onclick="document.getElementById('sq-search-wait-popup').style.display = 'none'; return false;">x</a> ]</div><span id="sq-search-wait-popup-title">Search in Progress</span></div>
1154  <div id="sq-search-wait-popup-details">Your search is being processed, please wait...</div>
1155  </div>
1156  <form style="display: inline" action="<?php echo $this->_action.$this->_anchor;?>" id="main_form" name="main_form" method="post" enctype="multipart/form-data" onclick="changesMade();" onkeypress="changesMade();" onsubmit="return form_on_submit();">
1157  <?php
1158  if (!empty($_REQUEST['print_view'])) {
1159  ?>
1160  <div id="matrix-print-logo">
1161  </div>
1162  <?php
1163  }
1164  ?>
1165  <div id="sq-content">
1166  <?php
1167  hidden_field('process_form', '1');
1168  hidden_field('changes', '0');
1169  hidden_field('state', '');
1170  hidden_field('allowconfirm', !defined('SQ_CONF_CONFIRM_SAVE_CHANGES') ? '1' : SQ_CONF_CONFIRM_SAVE_CHANGES);
1171  // insert nonce token
1172  hidden_field('token', get_unique_token());
1173 
1174  foreach ($this->_hidden_fields as $name => $value) {
1175  hidden_field($name, $value);
1176  }
1177 
1178  if ($this->_heading || count($this->_screens) || count($this->_static_screens)) {
1179  ?>
1180  <table class="sq-backend-main-headings">
1181  <tr>
1182  <?php
1183  if ($this->_heading_icon) {
1184  ?>
1185  <td class="sq-backend-heading-icon"><?php echo $this->_heading_icon; ?></td>
1186  <?php
1187  }
1188  ?>
1189  <td class="sq-backend-main-heading">
1190  <?php
1191  echo $this->_heading;
1192  if ($this->_sub_heading) {
1193  echo '<br /><span class="sq-backend-sub-heading">'.$this->_sub_heading.'</span>';
1194  }
1195  ?>
1196  </td>
1197  <?php
1198  if (empty($_REQUEST['print_view'])) {
1199  ?>
1200  <td class="sq-backend-screen-menu">
1201  <div id="sq_screen_menu_filler" style="display: none"></div>
1202  <div id="sq_screen_menu">
1203  <?php
1204  $this->printContextSwitcher();
1205  $this->printScreenMenu();
1206  sq_print_icon(sq_web_path('lib').'/web/images/icons/printer.png', 16, 16, translate('print_this_page'), NULL, 'onclick="showPrintPopup()" class="clickable" style="margin-bottom: -2px; margin-right: 4px"');
1207  ?>
1208  </div>
1209  </td>
1210  <?php
1211  }
1212  ?>
1213  </tr>
1214  </table>
1215  <?php
1216 
1217  if (isset($_SESSION['sq_nav_history']) && empty($_REQUEST['print_view'])) {
1218  ?>
1219  <table class="sq-backend-nav-history-container">
1220  <tr>
1221  <td class="sq-backend-nav-history-title">
1222  <?php sq_print_icon($this->filesPath('images/icons/history.png'), 20, 20, 'Navigation History'); ?>
1223  <?php echo translate('back_to'); ?>:
1224  </td>
1225  <td class="sq-backend-nav-history">
1226  <?php
1227  $nav_count = count($_SESSION['sq_nav_history']);
1228  if ($nav_count < 5) {
1229  $start = 0;
1230  } else {
1231  $start = $nav_count - 5;
1232  }
1233 
1234  for ($i = $start; $i < $nav_count; $i++) {
1235  if (!isset($_SESSION['sq_nav_history'][$i])) continue;
1236  $nav_details = $_SESSION['sq_nav_history'][$i];
1237 
1238  $nav_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($nav_details['assetid'], '', TRUE);
1239  if (is_null($nav_asset)) {
1240  array_splice($_SESSION['sq_nav_history'], $i, 1);
1241  continue;
1242  }
1243  ?>
1244  <a href="<?php echo $nav_asset->getBackendHref($nav_details['screen']); ?>&sq_nav_goback=<?php echo $i; ?>">
1245  <?php
1246  sq_print_icon($GLOBALS['SQ_SYSTEM']->am->getAssetIconURL($nav_asset->type()), 16, 16, htmlspecialchars($nav_asset->short_name));
1247  echo htmlspecialchars($nav_asset->short_name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
1248  ?>
1249  <span> [<?php echo ($i + 1); ?>]</span>
1250  </a>
1251  <?php
1252  if ($i < ($nav_count -1)) {
1253  ?> <span class="divider">+</span> &nbsp;<?php
1254  }
1255 
1256  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($nav_asset);
1257  unset($nav_asset);
1258  }
1259  ?>
1260  </td>
1261  </tr>
1262  </table>
1263  <?php
1264  }//end if
1265 
1266  }//end if
1267 
1268  }//end _paintHeader()
1269 
1270 
1280  function _paintSection($section, $depth=0)
1281  {
1282  if ($section['type'] == 'raw') {
1283  echo $section['contents'];
1284  } else {
1285  ?>
1286  <a name="section_<?php echo $section['section_count']; ?>"></a>
1287  <table class="sq-backend-section-table" id="backend_section_<?php echo $section['section_count']; ?>">
1288  <?php
1289  if ($section['heading'] != '') {
1290  if ($depth > 0) {
1291  // printing a nested section - needs to look a little different
1292  ?>
1293  <tr>
1294  <td class="sq-backend-section-subheading"><?php echo $section['heading'];?></td>
1295  </tr>
1296  <?php
1297  } else {
1298  // printing a top level section
1299  ?>
1300  <tr class="sq-backend-section-heading-container">
1301  <td>
1302  <table border="0" cellspacing="0" cellpadding="0">
1303  <tr>
1304  <td class="sq-backend-section-heading"><?php echo $section['heading'];?></td>
1305  <td><img src="<?php echo $this->filesPath('images/section_icon.gif');?>" width="27" height="21" alt="" /></td>
1306  </tr>
1307  </table>
1308  </td>
1309  </tr>
1310  <?php
1311  }
1312  }//endif
1313  ?>
1314  <tr>
1315  <td>
1316  <table class="sq-backend-section-table-inner" cellspacing="0" cellpadding="0" border="0">
1317  <?php
1318  for ($j = 0; $j < count($section['areas']); $j++) {
1319  switch ($section['areas'][$j]['area_type']) {
1320  case 'section' :
1321  ?>
1322  <tr>
1323  <td colspan="2">
1324  <?php
1325  $this->_paintSection($section['areas'][$j], $depth + 1);
1326  ?>
1327  </td>
1328  </tr>
1329  <?php
1330  break;
1331 
1332  case 'field' :
1333  $field = $section['areas'][$j];
1334  switch ($field['format']) {
1335  case 'new_line' :
1336  ?>
1337  <tr <?php
1338  if ($field['hidden']) echo 'style="display: none"';
1339  if ($field['id_name']) {
1340  echo 'id="'.$field['id_name'].'"';
1341  }
1342  ?>>
1343  <td class="sq-backend-field sq-backend-field-newline" colspan="2">
1344  <a name="field_<?php echo $field['field_count']; ?>"></a>
1345  <?php echo $field['name'];?>
1346  </td>
1347  </tr>
1348  <tr <?php if ($field['hidden']) echo 'style="display: none"'; ?>>
1349  <td class="sq-backend-data sq-backend-data-newline" colspan="2">
1350  <?php
1351  echo $field['contents'];
1352  if ($field['note']) $this->note($field['note']);
1353  ?>
1354  </td>
1355  </tr>
1356  <?php
1357  break;
1358 
1359  case 'commit' :
1360  ?>
1361  <tr <?php
1362  if ($field['hidden']) echo 'style="display: none"';
1363  if ($field['id_name']) {
1364  echo 'id="'.$field['id_name'].'"';
1365  }
1366  ?>>
1367  <td class="sq-backend-data sq-backend-commit" colspan="2">
1368  <?php
1369  echo $field['contents'];
1370  if ($field['note']) $this->note($field['note']);
1371  ?>
1372  </td>
1373  </tr>
1374  <?php
1375  break;
1376 
1377  case 'blank' :
1378  // a blank field to be used just for formatting
1379  break;
1380 
1381  default :
1382  ?>
1383  <tr <?php
1384  if ($field['hidden']) echo 'style="display: none"';
1385  ?> <?php
1386  if ($field['id_name']) {
1387  echo 'id="'.$field['id_name'].'"';
1388  }
1389  ?>>
1390  <td class="sq-backend-field">
1391  <a name="field_<?php echo $field['field_count']; ?>"></a>
1392  <?php echo $field['name'];?>
1393  </td>
1394  <td class="sq-backend-data">
1395  <?php
1396  echo $field['contents'];
1397  if ($field['note']) $this->note($field['note']);
1398  ?>
1399  </td>
1400  </tr>
1401  <?php
1402  }//end switch
1403 
1404  break;
1405 
1406  default :
1407  trigger_localised_error('SYS0257', E_USER_ERROR, $section['areas'][$j]['area_type']);
1408 
1409  }//end switch area type
1410 
1411  }//end for
1412 
1413  if (isset($section['note'])) {
1414  $this->_nbSectionNote($section['note']);
1415  }
1416 
1417  ?>
1418  </table>
1419  </td>
1420  </tr>
1421  </table>
1422  <?php
1423 
1424  }//end else
1425 
1426  }//end _paintSection()
1427 
1428 
1435  function _paintFooter()
1436  {
1437  ?>
1438  </div>
1439  </form>
1440  </body>
1441  </html>
1442  <?php
1443 
1444  }//end _paintFooter()
1445 
1446 
1455  function _paintCssInclude($file)
1456  {
1457  ?>
1458  <link rel="stylesheet" type="text/css" href="<?php echo $file;?>" />
1459  <?php
1460 
1461  }//end _paintCssInclude()
1462 
1463 
1472  function _paintJsInclude($file)
1473  {
1474  ?>
1475  <script type="text/javascript" src="<?php echo $file;?>"></script>
1476  <?php
1477 
1478  }//end _paintJsInclude()
1479 
1480 
1489  function note($str)
1490  {
1491  echo '<div class="sq-backend-smallprint">'.$str.'</div>';
1492 
1493  }//end note()
1494 
1495 
1506  function sectionNote($str='')
1507  {
1508  if ($this->_buffering) {
1509  $stack_i = count($this->_section_stack) - 1;
1510  $this->_section_stack[$stack_i]['note'] = $str;
1511 
1512  } else {
1513  // we are not buffering
1514  $this->_nbSectionNote($str);
1515  }
1516 
1517  }//end sectionNote()
1518 
1519 
1530  function _nbSectionNote($str)
1531  {
1532  ?>
1533  </td>
1534  </tr>
1535  <tr>
1536  <td colspan="2">
1537  <div class="sq-backend-section-note"><strong><?php echo translate('note'); ?>: </strong><?php echo $str ?></div>
1538  <?php
1539 
1540  }//end _nbSectionNote()
1541 
1542 
1554  function commitButton($value='', $release_lock=TRUE, $include_section=TRUE)
1555  {
1556  // value is empty, use default caption
1557  if (empty($value)) {
1558  $value = !defined('SQ_CONF_COMMIT_BUTTON_TEXT') ? 'Commit' : SQ_CONF_COMMIT_BUTTON_TEXT;
1559  }
1560  $release_lock = (int) $release_lock;
1561  if ($include_section) {
1562  // Lock commit button to bottom of frame if the preference is turned on AND we're in backend
1563  if (SQ_IN_BACKEND && $GLOBALS['SQ_SYSTEM']->getUserPrefs('user', 'SQ_USER_COMMIT_BUTTON_POS')) {
1564  $this->openRaw();
1565  ?></div><div id="sq-commit-button-spacer"></div><div id="sq-commit-button-div"><div id="sq-commit-button-div-inside"><?php
1566  } else {
1567  $this->openSection(' ');
1568  $this->openField('', 'commit');
1569  }
1570  }
1571  hidden_field('sq_lock_release', $release_lock);
1572  normal_button('sq_commit_button', $value, 'if (submit_form) { submit_form(this.form); } else { this.form.submit(); this.disabled = \'disabled\'; } ', 'accesskey="s"');
1573  if ($include_section) {
1574  if (SQ_IN_BACKEND && $GLOBALS['SQ_SYSTEM']->getUserPrefs('user', 'SQ_USER_COMMIT_BUTTON_POS')) {
1575  ?></div></div>
1576  <div>
1577  <?php
1578  $this->closeRaw();
1579  } else {
1580  $this->closeField();
1581  $this->closeSection();
1582  }
1583  }
1584 
1585  }//end commitButton()
1586 
1587 
1594  function printScreenMenu()
1595  {
1596  if (empty($this->_screens) && empty($this->_static_screens)) {
1597  echo '&nbsp;';
1598  } else {
1599  if (!empty($this->_screens)) {
1600  $this->_screens = array_reverse($this->_screens);
1601  $this->_screens['#'] = '------';
1602  foreach (array_reverse($this->_static_screens) as $url => $code) {
1603  $this->_screens[$url] = $code;
1604  }
1605  $this->_screens = array_reverse($this->_screens);
1606  } else {
1607  $this->_screens = $this->_static_screens;
1608  }
1609  combo_box('screen_menu', $this->_screens, FALSE, $this->_action, 1, 'id="screen_menu" onchange="self.location = this.value"');
1610  echo '&nbsp;';
1611  normal_button('screen_menu_go', ' '.translate('go').' ', 'self.location = get_form_element_value("screen_menu");');
1612  echo '&nbsp;';
1613  }
1614 
1615  }//end printScreenMenu()
1616 
1617 
1628  public function printContextSwitcher()
1629  {
1630  $contexts = $GLOBALS['SQ_SYSTEM']->getAllContexts();
1631  $current_context = $GLOBALS['SQ_SYSTEM']->getContextId();
1632  if (count($contexts) > 1) {
1633  ?>
1634  <span id="sq_context_switcher_current">
1635  Context: <strong><?php echo $contexts[$current_context]['name'] ?></strong> [ <a href="#" onclick="this.parentNode.nextSibling.style.display = 'inline'; this.parentNode.style.display = 'none'; return false;">Change</a> ]
1636  </span><span id="sq_context_switcher_change">Change Context: <?php
1637  $this->printSimpleContextSwitcher();
1638  ?></span> <?php
1639  }
1640 
1641  }//end printContextSwitcher()
1642 
1643 
1653  public function printSimpleContextSwitcher()
1654  {
1655  $current_location = $this->getCurrentLocation();
1656  list($current_loc_base, $current_loc_query) = explode('?', $current_location);
1657  $default_url = NULL;
1658 
1659  $contexts = $GLOBALS['SQ_SYSTEM']->getAllContexts();
1660  $current_context = $GLOBALS['SQ_SYSTEM']->getContextId();
1661  if (count($contexts) > 1) {
1662 
1663  $context_list = Array();
1664  foreach ($contexts as $context_item_id => $context_item) {
1665  $url = replace_query_string_vars(Array('SQ_ACTION' => 'set_backend_context', 'SQ_CONTEXT_NAME' => rawurlencode($context_item['name'])), $current_loc_base, $current_loc_query);
1666  if ((int)$current_context === (int)$context_item_id) {
1667  $default_url = $url;
1668  }
1669 
1670  $context_list[$url] = $context_item['name'];
1671  }
1672  combo_box('sq_context_switcher', $context_list, FALSE, Array($default_url), 1, ' onchange="self.location = this.value;"');
1673  }
1674 
1675 
1676  }//end printSimpleContextSwitcher()
1677 
1678 
1688  function onBackendMessage(&$broadcaster, $event_data=Array())
1689  {
1690  $this->addMessage($event_data['type'], $event_data['message']);
1691 
1692  }//end onBackendMessage()
1693 
1694 
1704  function onCreateLink(&$broadcaster, $event_data=Array())
1705  {
1706  if (!is_null($broadcaster) && isset($broadcaster->id)) {
1707  if (!in_array($broadcaster->id, $this->_refreshing_assets)) {
1708  $this->addOnLoad('if (parent.frames["sq_sidenav"] && parent.frames["sq_sidenav"].reload_asset) parent.frames["sq_sidenav"].reload_asset("'.$broadcaster->id.'");');
1709  $this->_refreshing_assets[] = $broadcaster->id;
1710  }
1711  }//end if
1712 
1713  }//end onCreateLink()
1714 
1715 
1725  function onDeleteLink(&$broadcaster, $event_data=Array())
1726  {
1727  if (!($broadcaster instanceof Asset)) return;
1728  if (!in_array($broadcaster->id, $this->_refreshing_assets)) {
1729  $this->addOnLoad('if (parent.frames["sq_sidenav"] && parent.frames["sq_sidenav"].reload_asset) parent.frames["sq_sidenav"].reload_asset("'.$broadcaster->id.'");');
1730  $this->_refreshing_assets[] = $broadcaster->id;
1731  }
1732 
1733  }//end onDeleteLink()
1734 
1735 
1745  function onAssetUpdate(&$broadcaster, $event_data=Array())
1746  {
1747  if (!($broadcaster instanceof Asset)) return;
1748  if (!in_array($broadcaster->id, $this->_refreshing_assets)) {
1749  $this->addOnLoad('if (parent.frames["sq_sidenav"] && parent.frames["sq_sidenav"].reload_asset) parent.frames["sq_sidenav"].reload_asset("'.$broadcaster->id.'");');
1750  $this->_refreshing_assets[] = $broadcaster->id;
1751  }
1752 
1753  }//end onAssetUpdate()
1754 
1755 
1765  function onAssetTypeUpdate(&$broadcaster, $event_data=Array())
1766  {
1767  if (!($broadcaster instanceof Asset)) return;
1768  if (!in_array($broadcaster->id, $this->_refreshing_assets)) {
1769  if ($event_data['old_type'] != $event_data['new_type']) {
1770  $this->addOnLoad('if (parent.frames["sq_sidenav"] && parent.frames["sq_sidenav"].reload_asset) parent.frames["sq_sidenav"].reload_asset("'.$broadcaster->id.'");');
1771  $this->_refreshing_assets[] = $broadcaster->id;
1772  }
1773  }
1774 
1775  }//end onAssetTypeUpdate()
1776 
1777 
1787  function onAssetStatusUpdate(&$broadcaster, $event_data=Array())
1788  {
1789  if (!($broadcaster instanceof Asset)) return;
1790  if (!in_array($broadcaster->id, $this->_refreshing_assets)) {
1791  if ($event_data['old_status'] != $event_data['new_status']) {
1792  $this->addOnLoad('if (parent.frames["sq_sidenav"] && parent.frames["sq_sidenav"].reload_asset) parent.frames["sq_sidenav"].reload_asset("'.$broadcaster->id.'");');
1793  $this->_refreshing_assets[] = $broadcaster->id;
1794  }
1795  }
1796 
1797  }//end onAssetStatusUpdate()
1798 
1799 
1807  {
1808  return $this->_section_count;
1809 
1810  }//end getCurrentSectionNumber()
1811 
1812 
1813 }//end class
1814 
1815 ?>