[ Index ]
 

Code source de CMS made simple 1.0.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/admin/ -> multicontent.php (source)

   1  <?php
   2  #CMS - CMS Made Simple
   3  #(c)2004 by Ted Kulp (wishy@users.sf.net)
   4  #This project's homepage is: http://cmsmadesimple.sf.net
   5  #
   6  #This program is free software; you can redistribute it and/or modify
   7  #it under the terms of the GNU General Public License as published by
   8  #the Free Software Foundation; either version 2 of the License, or
   9  #(at your option) any later version.
  10  #
  11  #This program is distributed in the hope that it will be useful,
  12  #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13  #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14  #GNU General Public License for more details.
  15  #You should have received a copy of the GNU General Public License
  16  #along with this program; if not, write to the Free Software
  17  #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18  #
  19  #$Id$
  20  
  21  $CMS_ADMIN_PAGE=1;
  22  
  23  require_once ("../include.php");
  24  
  25  if (isset($_POST['cancel']))
  26      redirect('listcontent.php');
  27  
  28  check_login();
  29  
  30  $action = '';
  31  if (isset($_POST['multiaction'])) $action = $_POST['multiaction'];
  32  if (isset($_POST['reorderpages'])) $action = 'reorder';
  33  
  34  include_once ("header.php");
  35  
  36  global $gCms;
  37  $db =& $gCms->GetDb();
  38  $hm =& $gCms->GetHierarchyManager();
  39  
  40  $nodelist = array();
  41  
  42  function toggleexpand($contentid, $collapse = false)
  43  {
  44      $userid = get_userid();
  45      $openedArray=array();
  46      if (get_preference($userid, 'collapse', '') != '')
  47      {
  48          $tmp  = explode('.',get_preference($userid, 'collapse'));
  49          foreach ($tmp as $thisCol)
  50          {
  51              $colind = substr($thisCol,0,strpos($thisCol,'='));
  52              $openedArray[$colind] = 1;
  53          }
  54      }
  55      if ($collapse)
  56      {
  57          $openedArray[$contentid] = 0;
  58      }
  59      else
  60      {
  61          $openedArray[$contentid] = 1;
  62      }
  63      $cs = '';
  64      foreach ($openedArray as $key=>$val)
  65      {
  66          if ($val == 1)
  67          {
  68              $cs .= $key.'=1.';
  69          }
  70      }
  71      set_preference($userid, 'collapse', $cs);
  72  }
  73  
  74  function DoContent(&$list, &$node, $checkdefault = true, $checkchildren = true)
  75  {
  76      $content =& $node->GetContent();
  77      if (isset($content))
  78      {
  79          if (!$checkdefault || ($checkdefault && !$content->DefaultContent()))
  80          {
  81              $inarray = false;
  82              foreach ($list as $oneitem)
  83              {
  84                  if ($oneitem == $content)
  85                  {
  86                      $inarray = true;
  87                      break;
  88                  }
  89              }
  90  
  91              if (!$inarray)
  92                  $list[] =& $content;
  93  
  94              if ($checkchildren)
  95              {
  96                  $children =& $node->getChildren();
  97                  if (isset($children) && count($children))
  98                  {
  99                      reset($children);
 100                      while (list($key) = each($children))
 101                      {
 102                          $onechild =& $children[$key];
 103                          DoContent($list, $onechild, $checkdefault, $checkchildren);
 104                      }
 105                  }
 106              }
 107          }
 108      }
 109  }
 110  $reorder_error = FALSE;
 111  if (isset($_POST['idlist']))
 112  {
 113      foreach (explode(':', $_POST['idlist']) as $id)
 114      {
 115          $node =& $hm->sureGetNodeById($id);
 116          if (isset($node))
 117          {
 118              $content =& $node->GetContent();
 119              if (isset($content))
 120              {
 121                  $nodelist[] =& $content;
 122              }
 123          }
 124      }
 125  }
 126  else
 127  {
 128      foreach ($_POST as $k=>$v)
 129      {
 130          if (startswith($k, 'multicontent-'))
 131          {
 132              $id = substr($k, strlen('multicontent-'));
 133              $node =& $hm->sureGetNodeById($id);
 134              if (isset($node))
 135              {
 136                  if ($action == 'inactive')
 137                      DoContent($nodelist, $node, true, false);
 138                  else if ($action == 'active')
 139                      DoContent($nodelist, $node, false, false);
 140                  else if ($action == 'delete')
 141                     DoContent($nodelist, $node, false, true);
 142              }
 143          }
 144          if ($action == 'reorder')
 145            {      
 146              if (startswith($k, 'order-'))
 147                {
 148              $id = substr($k, strlen('order-'));
 149              $node =& $hm->sureGetNodeById($id);
 150              $one =& $node->getContent();
 151              $parentNode = &$node->getParentNode();
 152              if (FALSE == empty($reorder_parents_array[$one->ParentId()]) && array_key_exists($v, $reorder_parents_array[$one->ParentId()]))
 153                {
 154                  $reorder_error = 'sibling_duplicate_order';
 155                }
 156              else if ($v > count($parentNode->getChildren()))
 157                {
 158                  $reorder_error = 'order_too_large';
 159                }
 160              else if (0 == $v)
 161                {
 162                  $reorder_error = 'order_too_small';
 163                }
 164              else
 165                {
 166                  $reorder_array[$id] = $v;
 167                  $reorder_parents_array[$one->ParentId()][$v] = $v;
 168                }
 169                }
 170  
 171            }
 172      }
 173      if ($action == 'reorder' && $reorder_error == FALSE)
 174        {
 175          $order_changed = FALSE;
 176          foreach ($reorder_array AS $page_id => $page_order)
 177            {
 178          $node =& $hm->sureGetNodeById($page_id);
 179          $one =& $node->getContent();
 180          // Only update if order has changed.
 181          if ($one->ItemOrder() != $page_order)
 182            {
 183              $order_changed = TRUE;
 184              $query = 'UPDATE '.cms_db_prefix().'content SET item_order ='.intval($page_order).' WHERE content_id = ?';
 185              $db->Execute($query, array($page_id));
 186            }
 187            }
 188          if (TRUE == $order_changed)
 189          {
 190              global $gCms;
 191              $contentops =& $gCms->GetContentOperations();
 192              $contentops->SetAllHierarchyPositions();
 193          }
 194          else
 195            {
 196          $reorder_error = 'no_orders_changed';
 197            }
 198        }
 199   }
 200  
 201  if (count($nodelist) == 0 && 'reorder' != $action)
 202  {
 203      redirect("listcontent.php");
 204  }
 205  else
 206  {
 207      if ($action == 'delete')
 208      {
 209          ?>
 210          <div class="pagecontainer">
 211              <p class="pageheader"><?php echo lang('deletecontent') ?></p><br />
 212          <?php
 213          $userid = get_userid();
 214          $access = (check_permission($userid, 'Remove Pages') ||
 215              check_permission($userid, 'Modify Page Structure'));
 216          if ($access)
 217          {
 218              echo '<form method="post" action="multicontent.php">' . "\n";
 219              echo '<p>'.lang('deletepages').'</p><p>' . "\n";
 220              $idlist = array();
 221              foreach ($nodelist as $node)
 222              {
 223                if ($node->DefaultContent())
 224                  {
 225                    redirect('listcontent.php?error=error_delete_default_parent');
 226                  }
 227  
 228                  echo $node->Name() . ' (' . $node->Hierarchy() . ')' . '<br />' . "\n";
 229                  $idlist[] = $node->Id();
 230              }
 231              echo '</p>';
 232  
 233              echo '<div class="pageoverflow">
 234                  <p class="pagetext">&nbsp;</p>
 235                  <p class="pageinput">';
 236  
 237              echo '<input type="hidden" name="multiaction" value="dodelete" /><input type="hidden" name="idlist" value="'.implode(':', $idlist).'" />' . "\n";
 238              ?>
 239                                  <input type="submit" name="confirm" value="<?php echo lang('submit') ?>"  class="pagebutton" onmouseover="this.className='pagebuttonhover'" onmouseout="this.className='pagebutton'" />
 240                                  <input type="submit" name="cancel" value="<?php echo lang('cancel') ?>" class="pagebutton" onmouseover="this.className='pagebuttonhover'" onmouseout="this.className='pagebutton'" />
 241                              </p>
 242                          </div>
 243                      </form>
 244                  </div>
 245              </div>
 246              <?php
 247          }
 248          else
 249          {
 250              redirect('listcontent.php');
 251          }
 252      }
 253      else if ($action == 'dodelete')
 254      {
 255          $userid = get_userid();
 256          $access = check_permission($userid, 'Remove Pages' || check_persmission($userid, 'Modify Page Structure'));
 257          if ($access)
 258          {
 259              global $gCms;
 260              $db = $gCms->GetDb();
 261              foreach (array_reverse($nodelist) as $node)
 262              {
 263                  $id = $node->Id();
 264                  $title = $node->Name() . ' (' . $node->Hierarchy() . ') -- ' . $id;
 265                  
 266                  $childcount = 0;
 267                  $parentid = -1;
 268  
 269                  #Hack alert...  hierarchy manager doesn't take into account for deleted nodes
 270                  $query = 'SELECT parent_id FROM '.cms_db_prefix().'content WHERE content_id = '.$db->qstr($id);
 271                  $result = &$db->Execute($query);
 272  
 273                  while ($result && !$result->EOF)
 274                  {
 275                      $parentid = $result->fields['parent_id'];
 276                      $result->MoveNext();
 277                  }
 278                  
 279                  $query = 'SELECT count(*) as thecount FROM '.cms_db_prefix().'content WHERE parent_id = '.$db->qstr($parentid);
 280                  $result = &$db->Execute($query);
 281  
 282                  while ($result && !$result->EOF)
 283                  {
 284                      $childcount = $result->fields['thecount'];
 285                      $result->MoveNext();
 286                  }
 287                  
 288                  $node->Delete();
 289  
 290                  #See if this is the last child... if so, remove
 291                  #the expand for it
 292                  if ($childcount == 1 && $parentid > -1)
 293                  {
 294                      toggleexpand($parentid, true);
 295                  }
 296                  
 297                  #Do the same with this page as well
 298                  toggleexpand($id, true);
 299  
 300                  audit($id, $title, 'Deleted Content');
 301              }
 302              ContentManager::SetAllHierarchyPositions();
 303          }
 304          //include_once("footer.php");
 305          redirect("listcontent.php");
 306      }
 307      else if ($action == 'inactive')
 308      {
 309          $userid = get_userid();
 310          $modifyall = check_permission($userid, 'Modify Any Page');
 311  
 312          foreach ($nodelist as $node)
 313          {
 314              $permission = ($modifyall || check_ownership($userid, $node->Id()) || check_authorship($userid, $node->Id()) || check_persmission($userid, 'Modify Page Structure'));
 315  
 316              if ($permission)
 317              {
 318                  if ($node->Active())
 319                  {
 320                      $node->SetActive(false);
 321                      $node->Save();
 322                  }
 323              }
 324          }
 325          redirect("listcontent.php");
 326      }
 327      else if ($action == 'active')
 328      {
 329          $userid = get_userid();
 330          $modifyall = check_permission($userid, 'Modify Any Page');
 331  
 332          foreach ($nodelist as $node)
 333          {
 334              $permission = ($modifyall || check_ownership($userid, $node->Id()) || check_authorship($userid, $node->Id()) || check_persmission($userid, 'Modify Page Structure'));
 335  
 336              if ($permission)
 337              {
 338                  if (!$node->Active())
 339                  {
 340                      $node->SetActive(true);
 341                      $node->Save();
 342                  }
 343              }
 344          }
 345          redirect("listcontent.php");
 346      }
 347      else if ($action == 'reorder')
 348      {
 349        if (FALSE == $reorder_error)
 350          {
 351            redirect('listcontent.php?message=pages_reordered');
 352          }
 353        else
 354          {
 355            redirect('listcontent.php?error='.$reorder_error);
 356          }
 357      }
 358      else
 359      {
 360          redirect('listcontent.php');
 361      }
 362  }
 363  
 364  include_once ("footer.php");
 365  
 366  # vim:ts=4 sw=4 noet
 367  ?>


Généré le : Tue Apr 3 18:50:37 2007 par Balluche grâce à PHPXref 0.7