[ PHPXref.com ] [ Generated: Sun Jul 20 19:34:26 2008 ] [ phpComasy 0.7.8 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/classes/ -> class.navigation.php (source)

   1  <?php
   2  /********************************************************************************
   3  * phpComasy, Content Management System                                          *
   4  * http://www.phpcomasy.org                                                      *
   5  *                                                                               *
   6  * Copyright (c) 2005 Emanuel Zuber (www.noreality.ch)                           *
   7  *                                                                               *
   8  * Released under the GNU General Public License                                 *
   9  ********************************************************************************/
  10  
  11  /* Includes */
  12  require_once("config.php");
  13  require_once ("classes/class.mysql.php");
  14  require_once ("classes/class.formular.php");
  15  
  16  class navigation {
  17      var $data; // data from POST and GET
  18      var $web; // object of the previous class (web)
  19      var $db; // database object
  20      var $echo;
  21  
  22      // constructor
  23  	function navigation(&$data, &$web) {
  24          $this->data = $data;
  25          $this->web = &$web;
  26          $this->db = new mysql();
  27      }
  28  
  29  	function get_navigation_select($root = 1) {
  30          // transfer pseudo array in a real array
  31          $categories_select_temp = explode("||", $this->get_navigation(2));
  32          
  33          $categories_select = array();
  34          $categories_select[0] = "(root)";
  35          
  36          for ($i = 0; $i <= count($categories_select_temp); $i++) {
  37              if (($i != 0) && ($categories_select_temp[$i] != '')) {
  38                  $categories_select[$categories_select_temp[$i]] = $categories_select_temp[++$i];
  39              }
  40          }
  41  
  42          if ($root == 0) {
  43              $categories_select[0] = _SELECT_CATEGORY;
  44          }
  45  
  46          return $categories_select;
  47      }
  48      
  49  	function get_navigation($param = 0) {
  50          // fill navigation in an array
  51          $result = $this->db->query("SELECT * FROM category INNER JOIN category_language ON category.category_id=category_language.category_id WHERE language = '".$this->web->language->get_current_language()."' ORDER BY sort;");        
  52          global $info;
  53          global $current;
  54          
  55          // check if current
  56          if ($this->data['id'] != '') {
  57              $result_current = mysql_fetch_assoc($this->db->query("SELECT * FROM page WHERE page_id = ".$this->data['id'].";"));
  58              $current_categories = $this->navigation_current_childs($result_current['category_id']);
  59              $current = explode(",", $current_categories);
  60              //$root_category_id = end($current);
  61              //echo $root_category_id;
  62          }
  63          else {$current = 0;}
  64          
  65          // fill in array
  66          $info = array();
  67          while ($row = mysql_fetch_array($result)) {
  68              $info[$row['parent_id']][] = $row;
  69          }
  70  
  71          $return = $this->navigation_child($param);
  72  
  73          return $return;
  74      }
  75      
  76      
  77      /*
  78      param = 0 => navigation (show normal navigation)
  79      param = 1 => edit navigation
  80      param = 2 => select navigation
  81      */
  82  	function navigation_child($param = 0, $parentid = 0, $depth = 0) {
  83          global $info;
  84          global $current;
  85          // abbruchbedingung
  86          if (!$info[$parentid]) return;
  87          $return = '';
  88  
  89          foreach($info[$parentid] as $row) {
  90              /* bad code!!!, this sql query will run every recursion (will bug fixed in version 0.6) */
  91              $result_page_query = mysql_fetch_assoc($this->db->query("SELECT page_id FROM page WHERE category_id = ".$row['category_id']." ORDER BY sort;"));
  92              $page_id = intval($result_page_query['page_id']);
  93              /* end bad code :-) */
  94              
  95              $a1 = ""; $a2 = "";
  96              if ($page_id != '') {
  97                  $a1 = '<a href="'.$this->web->settings->get_settings('global_standard_filename').'?id='.$page_id.'" title="'.$row['alt'].'">';
  98                  $a2 = '</a>';
  99              }
 100              else {
 101                  $a1 = '<a href="'.$this->web->settings->get_settings('global_standard_filename').'?category_id='.$row['category_id'].'&amp;action=form_add" title="'.$row['alt'].'">';
 102                  $a2 = '</a>';
 103              }
 104  
 105              if (intval($param) == 1) {
 106                  if ($row['sort'] == 0) {
 107                      $sort_html = ' <a title="'._MOVE_DOWN_CATEGORY.'" href="'.$this->web->settings->get_settings('global_standard_filename').'?action=move_down_category&amp;category_id='.$row['category_id'].'"><img src="img/icon_down.gif" alt="'._MOVE_DOWN_CATEGORY.'" /></a>';
 108                  }
 109                  else {
 110                      $sort_html = ' <a title="'._MOVE_UP_CATEGORY.'" href="'.$this->web->settings->get_settings('global_standard_filename').'?action=move_up_category&amp;category_id='.$row['category_id'].'"><img src="img/icon_up.gif" alt="'._MOVE_UP_CATEGORY.'" /></a>'.
 111                                   ' <a title="'._MOVE_DOWN_CATEGORY.'" href="'.$this->web->settings->get_settings('global_standard_filename').'?action=move_down_category&amp;category_id='.$row['category_id'].'"><img src="img/icon_down.gif" alt="'._MOVE_DOWN_CATEGORY.'" /></a>';
 112                  }
 113              
 114                  $return .= '<div>'.$a1.str_repeat('&nbsp;&nbsp;&nbsp;', $depth).$row['title'].$a2.' <a title="'._EDIT_CATEGORY.'"href="'.$this->web->settings->get_settings('global_standard_filename').'?action=edit_category_form&amp;category_id='.$row['category_id'].'"><img src="img/icon_edit.gif" alt="'._EDIT_CATEGORY.'" /></a> <a title="'._REMOVE_CATEGORY.'" href="'.$this->web->settings->get_settings('global_standard_filename').'?action=delete_category&amp;category_id='.$row['category_id'].'"><img src="img/icon_delete.gif" alt="'._REMOVE_CATEGORY.'" /></a>'.$sort_html.'</div>';
 115              }
 116              if (intval($param) == 2) {
 117                  $return .= "||".$row['category_id']."||".str_repeat('&nbsp;&nbsp;&nbsp;', $depth+1).' '.$row['title'];
 118              }
 119              if (intval($param) == 0) {
 120                  $curr = '';
 121                  if ($current) {
 122                      foreach ($current as $key => $value) {
 123                          if ($value == $row['category_id']) {
 124                              $curr = ' current';
 125                              
 126                              // set session variable
 127                              $_SESSION['navigation_depth'] = intval($depth);
 128                              $_SESSION['navigation_parent'] = intval($parentid);
 129                          }
 130                      }
 131                  }
 132  
 133  
 134                  if ($this->web->settings->get_settings('navigation_as_image') == "true") {
 135                      require_once ("classes/class.text_as_image.php");
 136                      $text_as_image = new text_as_image(&$this->web);
 137                      $menu = $text_as_image->make_menu($row['title'], $this->web->property_foreground_color, $this->web->property_background_color);
 138                      $return .= '<div class="navigation level'.$depth.$curr.'">'.$a1.'<img src="'.$menu.'" alt="'.$menu.'" />'.$a2.'</div>';
 139                      // $text_as_image->remove_menu_images();
 140  
 141                  }
 142                  else {
 143                      $return .= '<div class="navigation level'.$depth.$curr.'" id="nav-'.$row['category_id'].'">'.$a1.$row['title'].$a2.'</div>';
 144                  }
 145  
 146              }
 147              // recursive
 148  
 149              if ($this->web->settings->get_settings('navigation_expand') == "true") {
 150                  $return .= $this->navigation_child($param, $row['category_id'], $depth + 1);
 151              }
 152              else {
 153                  if (intval($param) == 0) {
 154                      if ($current) {
 155                          foreach ($current as $key => $value) {
 156                              if ($value == $row['category_id']) {
 157                                  $return .= $this->navigation_child($param, $row['category_id'], $depth + 1);
 158                              }
 159                          }
 160                      }
 161                  }
 162                  else {
 163                      $return .= $this->navigation_child($param, $row['category_id'], $depth + 1);
 164                  }
 165              }
 166          }
 167          return $return;
 168      }    
 169      
 170  	function navigation_current_childs($id) {
 171          if ($id != '') {
 172              $result = mysql_fetch_assoc($this->db->query("SELECT * FROM category WHERE category_id = ".$id.";"));    
 173      
 174              if ($result['parent_id'] == 0) {
 175                  $return .= $result['category_id'];
 176              }
 177              else { 
 178                  $return .= $result['category_id'].','.$this->navigation_current_childs($result['parent_id']);
 179              }
 180              return $return;
 181          }
 182      }
 183      
 184  	function get_root_navigation() {
 185          // read navigation in an array
 186          $result = $this->db->query("SELECT * FROM category INNER JOIN category_language ON category.category_id=category_language.category_id WHERE parent_id = 0 AND language = '".$this->web->language->get_current_language()."' ORDER BY sort;");        
 187          
 188          $root_navigation = '';
 189          
 190          while ($row = mysql_fetch_array($result)) {
 191              /* bad code!!!, this sql query will run every recursion (will bug fixed in version 0.6) */
 192              $result_page_query = mysql_fetch_assoc($this->db->query("SELECT * FROM page WHERE category_id = ".$row['category_id']." ORDER BY sort;"));
 193              $page_id = $result_page_query['page_id'];
 194              /* end bad code :-) */
 195  
 196              $current = '';
 197              if ($this->data['id'] == $result_page_query['page_id']) {
 198                  $current = ' current';
 199              }
 200              else {
 201                  if ($result_page_query['category_id'] == $_SESSION['navigation_parent']) {
 202                      $current = ' current';
 203                  }
 204              }
 205              
 206              $root_navigation .= '<a class="root_navigation'.$current.'" href="'.$this->web->settings->get_settings('global_standard_filename').'?id='.$page_id.'" title="'.$row['alt'].'">'.$row['title'].'</a>';
 207          }
 208          
 209          return $root_navigation;
 210      }
 211  }
 212  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]