ActionApps PHP Cross Reference Groupware Applications

Source: /modules/site/util.php3 - 192 lines - 7629 bytes - Summary - Text - Print

   1  <?php
   2  //$Id: util.php3 2778 2009-04-15 15:17:12Z honzam $
   3  /*
   4  Copyright (C) 1999, 2000 Association for Progressive Communications
   5  http://www.apc.org/
   6  
   7      This program is free software; you can redistribute it and/or modify
   8      it under the terms of the GNU General Public License as published by
   9      the Free Software Foundation; either version 2 of the License, or
  10      (at your option) any later version.
  11  
  12      This program is distributed in the hope that it will be useful,
  13      but WITHOUT ANY WARRANTY; without even the implied warranty of
  14      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15      GNU General Public License for more details.
  16  
  17      You should have received a copy of the GNU General Public License
  18      along with this program (LICENSE); if not, write to the Free Software
  19      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  20  */
  21  
  22  // Miscellaneous utility functions for "site" module
  23  
  24  define ('MODW_FLAG_DISABLE',   1);   // deactivated spot
  25  define ('MODW_FLAG_JUST_TEXT', 2);   // not used - planed for site speedup
  26                                       // (= flag means "don't stringexpand text)"
  27  define ('MODW_FLAG_COLLAPSE',  4);   // (visualy) Collapsed spot
  28  
  29  
  30  function SiteAdminPage($spot_id, $add = null) {
  31      global $sess, $slice_id;
  32      $url = get_url($_SERVER['PHP_SELF'], array('spot_id'=>$spot_id, 'slice_id'=>$slice_id));   // Always used this way
  33      if ($add) {
  34          $url = get_url($url, $add);
  35      }
  36      // Don't add AA_CP_Session if already there (it isn't in PHP_SELF)
  37      return htmlentities((strpos($url, 'AA_CP_Session') === false) ? $sess->url($url) : $url);
  38  }
  39  
  40  function ModW_HiddenRSpotId() {
  41      print('<input type="hidden" name="spot_id" value="'.$GLOBALS['r_spot_id'].'">');
  42  }
  43  
  44  function ModW_StoreTree(&$tree, $site_id) {
  45      $p_site_id = q_pack_id($site_id);
  46      $data      = addslashes(serialize($tree));
  47      $SQL       = "UPDATE site SET structure='$data' WHERE id='$p_site_id'";
  48      tryQuery($SQL);
  49  }
  50  
  51  function ModW_GetTree( &$tree, $site_id ){
  52      $db        = getDB();
  53      $p_site_id = q_pack_id($site_id);
  54  
  55      $SQL = "SELECT structure FROM site WHERE id='$p_site_id'";
  56      $db->query();
  57      if ($db->next_record()) {
  58          $tree = unserialize( $db->f('structure') );
  59      }
  60      freeDB($db);
  61  }
  62  
  63  // This function does nothing and is used when walking the tree fixing it
  64  function ModW_DoNothing($spot_id,$depth) {
  65      return;
  66  }
  67  
  68  function ModW_SpotHtml($spot_id, $spot_name, $selected, $disabled) {
  69      // get class for this spot div
  70      $class  = ($selected) ? ' class="selected"' : '';
  71  
  72      // get actions (eye for disable/enable, at this moment
  73      $action = $disabled ?
  74          '<a href="'. SiteAdminPage($spot_id, 'akce=e'). '">' .GetModuleImage('site', 'disabled.gif', '', 16, 12, 'class="eye"') .'</a>' :
  75          '<a href="'. SiteAdminPage($spot_id, 'akce=h'). '">' .GetModuleImage('site', 'enabled.gif',  '', 16, 12, 'class="eye"') .'</a>';
  76  
  77      // print the spot <div>
  78      echo "<div$class>$action}<a href=\"". SiteAdminPage($spot_id, "go_sid=$spot_id"). "\" class=\"spot\">$spot_name</a></div>";
  79  }
  80  
  81  function ModW_PrintSpotName_Start($spot_id, $depth) {
  82      global $r_spot_id, $tree;
  83  
  84      // print the spot itself
  85      ModW_SpotHtml($spot_id, $tree->getName($spot_id), $spot_id == $r_spot_id, ($tree->get('flag', $spot_id) & MODW_FLAG_DISABLE));
  86  
  87      // variables defined? - print it
  88      if (!$tree->isFlag($spot_id, MODW_FLAG_COLLAPSE) AND ($vars = $tree->get('variables', $spot_id))) {
  89          echo "\n  <div class=\"variables\">(". implode($vars, ',') .')</div>';
  90      }
  91  }
  92  
  93  function ModW_PrintChoice_Start($spot_id, $depth, $choices_index, $choices_count) {
  94      global $tree;
  95      // begin of the choice (open <div>)
  96  
  97      // last choice in the list is special
  98      $last  = ($choices_index == $choices_count-1);    // just shortcut variable
  99      $class = $last ? 'lastchoice' : 'choice';
 100  
 101      if ($tree->isLeaf($spot_id)) {
 102          $colaps = GetModuleImage('site', $last ? 'l.gif' : 't.gif', '', 21, 13);
 103      } elseif ($tree->get('flag', $spot_id) & MODW_FLAG_COLLAPSE) {
 104          $colaps = '<a href="'. SiteAdminPage($spot_id, "akce=m").'">'. GetModuleImage('site', 'plus.gif', '', 21, 13) .'</a> ';
 105      } else {
 106          $colaps = '<a href="'. SiteAdminPage($spot_id, "akce=p").'">'. GetModuleImage('site', 'minus.gif', '', 21, 13) .'</a> ';
 107      }
 108      echo "\n<div class=\"$class\">$colaps";
 109  
 110      // print conditions
 111      $conditions = '';
 112      if ($conds = $tree->get('conditions', $spot_id)) {
 113          $delim = ' ';
 114          foreach ($conds as $k => $v) {
 115              $conditions .= "$delim$k=$v";
 116              $delim = ', ';
 117          }
 118      }
 119      if ($conditions == '') {
 120          $conditions = '&nbsp;';
 121      }
 122      echo "\n  <div class=\"conditions\"><a href=\"". SiteAdminPage($spot_id, "go_sid=$spot_id"). "\">$conditions</a></div>";
 123  }
 124  
 125  function ModW_PrintChoice_End($spot_id, $depth, $choices_index, $choices_count) {
 126      // close previously opened <div class="choice">
 127      echo "\n</div>";
 128  }
 129  
 130  function ModW_PrintVariables( $spot_id, $vars ) {
 131      global $sess;
 132      FrmTabCaption();
 133      echo "<tr><td valign=top><b>"._m("Spot&nbsp;variables")."</b></td><td>";
 134      if (isset($vars) AND is_array($vars)) {
 135          foreach ($vars as $k => $v) {
 136              echo "$v <span align=right><a href=\"". SiteAdminPage($spot_id, "delvar=". urlencode($k)) ."\">"._m("Delete")."</a></span><br>";
 137          }
 138      }
 139      echo "<form name=fvar action=\"".$_SERVER['PHP_SELF']."\"><input type='text' name='addvar' value='' size='20' maxlength='50'><span align=right><a href='javascript:document.fvar.submit()'>"._m("Add")."</a></span>";
 140      ModW_HiddenRSpotId();
 141      $sess->hidden_session();
 142      echo "</form></td></tr>";
 143      FrmTabEnd();
 144  }
 145  
 146  function ModW_PrintConditions($spot_id, $conds, $vars) {
 147      global $sess;
 148      FrmTabCaption();
 149      echo "<tr><td valign=top><b>"._m("Spot&nbsp;conditions")."</b></td><td>";
 150      if ( isset($vars) AND is_array($vars) ) {
 151          $i=0;
 152          foreach ($vars as $k => $v) {
 153              if ($conds[$v]) {
 154                  echo "$v = $conds[$v] <span align=right><a href=\"". SiteAdminPage($spot_id, "delcond=$v") ."\">"._m("Delete")."</a></span><br>";
 155              } else {
 156                  echo "<form name=fcond$i action=\"". $_SERVER['PHP_SELF'] ."\">$k = <input type='text' name='addcond' value='' size='20' maxlength='50'>
 157                       <input type='hidden' name='addcondvar' value='$v'>
 158                       <span align=right><a href='javascript:document.fcond$i.submit()'>"._m("Add")."</a></span>";
 159                  $sess->hidden_session();
 160                  ModW_HiddenRSpotId();
 161                  echo "</form>";
 162              }
 163              $i++;
 164          }
 165      }
 166      echo "</td></tr>";
 167      FrmTabEnd();
 168  }
 169  
 170  function ModW_ShowSpot(&$tree, $site_id, $spot_id) {
 171      global $sess;
 172  
 173      $db  = getDB();
 174      $SQL = "SELECT * FROM site_spot WHERE site_id = '". q_pack_id($site_id). "' AND spot_id = '$spot_id'";
 175      $db->query($SQL);
 176      $content = $db->next_record() ? $db->f('content') : "";
 177      freeDB($db);
 178  
 179      ModW_PrintVariables($spot_id, $tree->get('variables',$spot_id));
 180      if (($vars=$tree->isOption($spot_id))) {
 181          ModW_PrintConditions($spot_id, $tree->get('conditions',$spot_id), $vars);
 182      }
 183  
 184      echo "<form method='post' name=fs action=\"". $_SERVER['PHP_SELF'] ."\">";
 185      FrmTabCaption();
 186      ModW_HiddenRSpotId();
 187      FrmInputText('name', _m("Spot name"), $tree->get('name', $spot_id), 50, 50, true, false, false, false);
 188      FrmTextarea('content', '', $content, 30, 80, false, AA_View::getViewJumpLinks($content), "", true);
 189      FrmTabEnd(array('submit'), $sess);
 190      echo "</form>";
 191  }
 192  ?>

title

Description

title

Description

title

Description

title

title

Body