[ Index ]

PHP Cross Reference of phpwcms V1.5.0 _r431 (28.01.12)

title

Body

[close]

/include/inc_act/ -> act_structure.php (source)

   1  <?php
   2  /*************************************************************************************
   3     Copyright notice
   4     
   5     (c) 2002-2012 Oliver Georgi <oliver@phpwcms.de> // All rights reserved.
   6  
   7  This script is part of PHPWCMS. The PHPWCMS web content management system is
   8  free software; you can redistribute it and/or modify it under the terms of
   9  the GNU General Public License as published by the Free Software Foundation;
  10  either version 2 of the License, or (at your option) any later version.
  11  
  12  The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
  13  A copy is found in the textfile GPL.txt and important notices to the license
  14  from the author is found in LICENSE.txt distributed with these scripts.
  15  
  16  This script is distributed in the hope that it will be useful, but WITHOUT ANY
  17  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  18  PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  19  
  20  This copyright notice MUST APPEAR in all copies of the script!
  21  *************************************************************************************/
  22  
  23  //19-11-2004 Fernando Batista -> Copy article, Copy strutures :http://fernandobatista.web.pt
  24  //31-03-2005 Fernando Batista -> copy&cut Article Content :http://fernandobatista.web.pt
  25  
  26  // session_name('hashID');
  27  session_start();
  28  $phpwcms = array();
  29  require_once ('../../config/phpwcms/conf.inc.php');
  30  require_once  ('../inc_lib/default.inc.php');
  31  require_once  (PHPWCMS_ROOT.'/include/inc_lib/dbcon.inc.php');
  32  
  33  require_once  (PHPWCMS_ROOT.'/include/inc_lib/general.inc.php');
  34  checkLogin();
  35  require_once  (PHPWCMS_ROOT.'/include/inc_lib/backend.functions.inc.php');
  36  
  37  if(empty($_SESSION['REFERER_URL'])) {
  38      die('Goood bye.');
  39  } else {
  40      $ref = $_SESSION['REFERER_URL'];
  41  }
  42  
  43  if($_SESSION["wcs_user_admin"] == 1) { //Wenn Benutzer Admin-Rechte hat
  44  
  45      if(isset($_POST["acat_access"]) && is_array($_POST["acat_access"]) && count($_POST["acat_access"])) {
  46          $acat_permit = implode(',', $_POST["acat_access"]);
  47      } else {
  48          $acat_permit = '';
  49      }
  50      
  51      $acat_hidden = 0;
  52      if(isset($_POST["acat_hidden"])) {
  53          $acat_hidden    = 1;
  54          if(isset($_POST["acat_hiddenactive"])) {
  55              $acat_hidden = 2;
  56          }
  57      }
  58      
  59      $acat_cntpart = '';
  60      if(isset($_POST['acat_cp']) && is_array($_POST['acat_cp'])) {
  61  
  62          $acat_cntpart = $_POST['acat_cp'];
  63          $acat_cntpart = array_unique($acat_cntpart);        
  64          $acat_cntpart = implode(',', $acat_cntpart);
  65      
  66      }
  67      
  68      $acat_class = empty($_POST["acat_class"]) ? '' : preg_replace('/[^a-zA-Z0-9_\- ]/', '', clean_slweg($_POST["acat_class"], 150));
  69      
  70      if(empty($_POST["acat_keywords"])) {
  71          $acat_keywords = '';
  72      } else {
  73          $acat_keywords = substr( implode(', ', convertStringToArray( clean_slweg($_POST["acat_keywords"], 255) ) ), 0, 255);
  74      }
  75  
  76      if(isset($_POST["acat_id"]) && $_POST["acat_id"] === 'index') {
  77          // write index page config into flat file
  78          $sql  = "<?php\n";
  79          $sql .= "\$indexpage['acat_name']        = '".    str_replace("''", "\\'", getpostvar($_POST["acat_name"]))."';\n";
  80          $sql .= "\$indexpage['acat_info']        = '".    str_replace("''", "\\'", getpostvar($_POST["acat_info"], 32000))."';\n";
  81          $sql .= "\$indexpage['acat_alias']        = '".    proof_alias($_POST["acat_id"], $_POST["acat_alias"])."';\n";
  82          $sql .= "\$indexpage['acat_aktiv']        = ".    (isset($_POST["acat_aktiv"]) ? 1 : 0).";\n";
  83          $sql .= "\$indexpage['acat_public']        = ".    (isset($_POST["acat_public"]) ? 1 : 0).";\n";
  84          $sql .= "\$indexpage['acat_template']    = ".    intval($_POST["acat_template"]).";\n";
  85      
  86          $sql .= "\$indexpage['acat_hidden']        = ".    $acat_hidden.";\n";
  87          $sql .= "\$indexpage['acat_ssl']        = ".    (isset($_POST["acat_ssl"]) ? 1 : 0).";\n";
  88          $sql .= "\$indexpage['acat_regonly']    = ".    (isset($_POST["acat_regonly"]) ? 1 : 0).";\n";
  89          $sql .= "\$indexpage['acat_topcount']    = ".    intval($_POST["acat_topcount"]).";\n";
  90          $sql .= "\$indexpage['acat_maxlist']    = ".    intval($_POST["acat_maxlist"]).";\n";
  91          $sql .= "\$indexpage['acat_redirect']    = '".    str_replace("''", "\\'", getpostvar($_POST["acat_redirect"]))."';\n";
  92          $cache_timeout = clean_slweg($_POST["acat_timeout"]);
  93          if(isset($_POST['acat_cacheoff']) && intval($_POST['acat_cacheoff'])) $cache_timeout = 0; //check if cache = Off
  94          $sql .= "\$indexpage['acat_timeout']    = '".    $cache_timeout."';\n";
  95          $sql .= "\$indexpage['acat_nosearch']    = '".    ((isset($_POST['acat_nosearch']) && intval($_POST['acat_nosearch'])) ? '1' : '')."';\n";
  96          $sql .= "\$indexpage['acat_nositemap']    = ".    (isset($_POST["acat_nositemap"]) ? 1 : 0).";\n";
  97          $sql .= "\$indexpage['acat_order']        = ".     set_correct_ordersort() .";\n";
  98          $sql .= "\$indexpage['acat_permit']        = '".    $acat_permit."';\n";
  99          $sql .= "\$indexpage['acat_cntpart']    = '".    $acat_cntpart."';\n";
 100          $sql .= "\$indexpage['acat_pagetitle']    = '".    str_replace("''", "\\'", getpostvar($_POST["acat_pagetitle"]))."';\n";
 101          $sql .= "\$indexpage['acat_paginate']    = ".    (isset($_POST["acat_paginate"]) ? 1 : 0).";\n";
 102          $sql .= "\$indexpage['acat_overwrite']    = '".    str_replace("''", "\\'", getpostvar($_POST["acat_overwrite"]))."';\n";
 103          $sql .= "\$indexpage['acat_archive']    = ".    (empty($_POST["acat_archive"]) ? 0 : 1) .";\n";
 104          $sql .= "\$indexpage['acat_class']        = '".    str_replace("'", "\\'", $acat_class)."';\n";
 105          $sql .= "\$indexpage['acat_keywords']    = '".    str_replace("'", "\\'", $acat_keywords)."';\n";
 106          $sql .= "\$indexpage['acat_cpdefault']    = ".    intval($_POST["acat_cpdefault"]).";\n";
 107          $sql .= "?>";
 108          write_textfile(PHPWCMS_ROOT.'/config/phpwcms/conf.indexpage.inc.php', $sql);
 109      }
 110      
 111      $acat_sort_fallback    = isset($_POST["acat_sort"]) ? intval(trim($_POST["acat_sort"])) : 0;
 112      $acat_sort_temp        = isset($_POST["acat_sort_temp"]) ? intval($_POST["acat_sort_temp"]) : 0;
 113      
 114      if($acat_sort_fallback === 0 && $acat_sort_temp > 0) {
 115          $acat_sort_fallback = $acat_sort_temp;
 116      }
 117  
 118      if(isset($_POST["acat_new"]) && intval($_POST["acat_new"]) == 1 && intval($_POST["acat_id"]) == 0 && $_POST["acat_id"] != 'index') {
 119          if(trim($_POST["acat_name"])) {
 120          
 121              $cache_timeout = clean_slweg($_POST["acat_timeout"]);
 122              if(isset($_POST['acat_cacheoff']) && intval($_POST['acat_cacheoff'])) $cache_timeout = 0; //check if cache = Off
 123          
 124              $sql =    "INSERT INTO ".DB_PREPEND."phpwcms_articlecat (acat_name, acat_info, acat_aktiv, acat_ssl, acat_regonly, ".
 125              "acat_public, acat_struct, acat_template, acat_sort, acat_uid, acat_alias, acat_hidden, acat_topcount, ".
 126              "acat_redirect, acat_order, acat_cache, acat_nosearch, acat_nositemap, acat_permit, acat_maxlist, ".
 127              "acat_cntpart, acat_pagetitle, acat_paginate, acat_overwrite, acat_archive, acat_class, acat_keywords, acat_cpdefault) VALUES ('".
 128              getpostvar($_POST["acat_name"])."','".
 129              getpostvar($_POST["acat_info"], 32000)."',".
 130              (isset($_POST["acat_aktiv"]) ? 1 : 0).",".
 131              (isset($_POST["acat_ssl"]) ? 1 : 0).",".
 132              (isset($_POST["acat_regonly"]) ? 1 : 0).",".
 133              (isset($_POST["acat_public"]) ? 1 : 0).",".
 134              intval($_POST["acat_struct"]).",".
 135              intval($_POST["acat_template"]).",".
 136              $acat_sort_fallback.",".
 137              $_SESSION["wcs_user_id"].",'".
 138              proof_alias($_POST["acat_id"], $_POST["acat_alias"])."',".
 139              $acat_hidden.", ".
 140              intval($_POST["acat_topcount"]).",'".
 141              getpostvar($_POST["acat_redirect"])."', ".
 142              set_correct_ordersort().",'".
 143              $cache_timeout."', '".(isset($_POST['acat_nosearch']) ? 1 : '')."',".
 144              (isset($_POST["acat_nositemap"]) ? 1 : 0).",".
 145              "'".$acat_permit."', ".intval($_POST["acat_maxlist"]).", '".aporeplace($acat_cntpart)."','".
 146              getpostvar($_POST["acat_pagetitle"])."', ".(isset($_POST["acat_paginate"]) ? 1 : 0).", '".getpostvar($_POST["acat_overwrite"])."',".
 147              (empty($_POST["acat_archive"]) ? 0 : 1).", '".aporeplace($acat_class)."', '".aporeplace($acat_keywords)."', ".intval($_POST["acat_cpdefault"]).")";
 148              if($result = mysql_query($sql, $db) or die("error")) {
 149                  $ref .= "&cat=".mysql_insert_id($db);
 150              }
 151          }
 152      }
 153  
 154      if(isset($_POST["acat_new"]) && isset($_POST["acat_id"]) && intval($_POST["acat_new"]) == 0 && intval($_POST["acat_id"])) {
 155          if(trim($_POST["acat_name"])) {
 156          
 157              $cache_timeout = clean_slweg($_POST["acat_timeout"]);
 158              if(isset($_POST['acat_cacheoff']) && intval($_POST['acat_cacheoff'])) $cache_timeout = 0; //check if cache = Off
 159          
 160              $sql =    "UPDATE ".DB_PREPEND."phpwcms_articlecat SET ".
 161              "acat_name='".getpostvar($_POST["acat_name"])."', ".
 162              "acat_info='".getpostvar($_POST["acat_info"], 32000)."', ".
 163              "acat_alias='".aporeplace(proof_alias($_POST["acat_id"], $_POST["acat_alias"]))."', ".
 164              "acat_aktiv=".(isset($_POST["acat_aktiv"]) ? 1 : 0).", ".
 165              "acat_public=".(isset($_POST["acat_public"]) ? 1 : 0).", ".
 166              "acat_struct=".intval($_POST["acat_struct"]).", ".
 167              "acat_template=".intval($_POST["acat_template"]).", ".
 168              "acat_sort=".$acat_sort_fallback.", ".
 169              "acat_uid=".$_SESSION["wcs_user_id"].", ".
 170              "acat_hidden=".$acat_hidden.", ".
 171              "acat_ssl=".(isset($_POST["acat_ssl"]) ? 1 : 0).", ".
 172              "acat_regonly=".(isset($_POST["acat_regonly"]) ? 1 : 0).", ".
 173              "acat_topcount=".intval($_POST["acat_topcount"]).", ".
 174              "acat_redirect='".getpostvar($_POST["acat_redirect"])."',".
 175              "acat_order=".set_correct_ordersort().", ".
 176              "acat_cache='".aporeplace($cache_timeout)."', ".
 177              "acat_nosearch='".(isset($_POST['acat_nosearch']) ? 1 : '')."', ".
 178              "acat_nositemap=".(isset($_POST["acat_nositemap"]) ? 1 : 0).", ".
 179              "acat_permit='".aporeplace($acat_permit)."', ".
 180              "acat_maxlist=".intval($_POST["acat_maxlist"]).", ".
 181              "acat_cntpart='".aporeplace($acat_cntpart)."', ".
 182              "acat_pagetitle='".getpostvar($_POST["acat_pagetitle"])."', ".
 183              "acat_paginate=".(isset($_POST["acat_paginate"]) ? 1 : 0).", ".
 184              "acat_overwrite='".getpostvar($_POST["acat_overwrite"])."', ".
 185              "acat_archive=".(empty($_POST["acat_archive"]) ? 0 : 1).", ".
 186              "acat_class='".aporeplace($acat_class)."', ".
 187              "acat_keywords='".aporeplace($acat_keywords)."',".
 188              "acat_cpdefault=".intval($_POST["acat_cpdefault"]).
 189              " WHERE acat_id=".intval($_POST["acat_id"]);
 190          
 191              mysql_query($sql, $db) or die(_report_error('DB', $sql));
 192          }
 193      }
 194  
 195  //diverse Aktionen
 196  $do = explode("|", isset($_GET["do"]) ? $_GET["do"] : '');
 197  
 198  
 199  switch(intval($do[0])) {
 200  
 201      case 1:    //Einfügen in
 202      $do[1] = intval($do[1]); //cut ID
 203      $do[2] = intval($do[2]); //paste ID
 204      $do[3] = intval($do[3]); //sort Number
 205      if($do[1]) { // && $do[2] = 0 für Root
 206      $sql =  "UPDATE ".DB_PREPEND."phpwcms_articlecat SET acat_struct=".$do[2].", acat_sort=".$do[3]." WHERE acat_id=".$do[1];
 207      mysql_query($sql, $db) or die("error while updating structure level");
 208      }
 209      break;
 210  
 211      case 2:    //Sortierung ändern
 212      $do[1] = intval($do[1]); //sort ID1
 213      $do[2] = intval($do[2]); //sort NR1
 214      $do[3] = intval($do[3]); //sort ID2
 215      $do[4] = intval($do[4]); //sort NR2
 216      if($do[1] && $do[2]>=10 && $do[3] && $do[4]>=10) {
 217          $sql =  "UPDATE ".DB_PREPEND."phpwcms_articlecat SET acat_sort=".$do[2]." WHERE acat_id=".$do[1];
 218          mysql_query($sql, $db) or die("error while updating sorting ID1");
 219          $sql =  "UPDATE ".DB_PREPEND."phpwcms_articlecat SET acat_sort=".$do[4]." WHERE acat_id=".$do[3];
 220          mysql_query($sql, $db) or die("error while updating sorting ID1");
 221      }
 222      break;
 223  
 224      case 3:    //Artikel einfügen in
 225      $do[1] = intval($do[1]); //cut Article ID
 226      $do[2] = intval($do[2]); //paste level ID
 227      if($do[1]) { // && $do[2] = 0 für Root
 228          $new_sort = getArticleSortValue($do[2]);
 229          $sql =  "UPDATE ".DB_PREPEND."phpwcms_article SET article_cid=".$do[2].", article_sort=".$new_sort." WHERE article_id=".$do[1];
 230          mysql_query($sql, $db) or die("error while updating article level");
 231      }
 232      break;
 233  
 234      case 4:    //Sortierung Artikel ändern
 235      $do[1] = intval($do[1]); //article sort ID1
 236      $do[2] = intval($do[2]); //article sort NR1
 237      $do[3] = intval($do[3]); //article sort ID2
 238      $do[4] = intval($do[4]); //article sort NR2
 239      if($do[1] && $do[2]>=10 && $do[3] && $do[4]>=10) {
 240          $sql =  "UPDATE ".DB_PREPEND."phpwcms_article SET article_sort=".$do[2].", article_tstamp=article_tstamp WHERE article_id=".$do[1];
 241          mysql_query($sql, $db) or die("error while updating sorting article ID1");
 242          $sql =  "UPDATE ".DB_PREPEND."phpwcms_article SET article_sort=".$do[4].", article_tstamp=article_tstamp WHERE article_id=".$do[3];
 243          mysql_query($sql, $db) or die("error while updating sorting article ID1");
 244      }
 245      break;
 246  
 247  //19-11-2004  Fernando Batista start-----------------------------------------------------------------------------------------------------------
 248      case 5:    // COPY Article
 249      $do[1] = intval($do[1]); //copy Article ID
 250      $do[2] = intval($do[2]); //paste level ID
 251      $do[3] = isset($do[3]) && $do[3] == 'open' ? 'open' : 0; // special link to copy an existing article and open the new
 252      if($do[1]) { //also allowed for pasting in root structure
 253          copy_article_to_level($do, $db);
 254      }
 255      break;
 256  
 257      case 6:    //COPY Structure
 258      $do[1] = intval($do[1]); //copy level ID
 259      $do[2] = intval($do[2]); //paste level ID
 260      $do[3] = intval($do[3]); //sort Number
 261      if($do[1]) { // && $do[2] = 0 für Root
 262          copy_level_to_level($do, $db);
 263      }
 264      break;
 265  //19-11-2004  Fernando Batista  end-------------------
 266  
 267  //31-03-2005 Fernando Batista start-----------------------------------------------------------------------------------------------------------
 268      case 7:    //
 269      $do[1] = intval($do[1]); //cut Article Content ID
 270      $do[2] = intval($do[2]); //paste Article ID
 271      $do[3] = intval($do[3]); //sort Number
 272      if($do[1]) { 
 273          
 274      $sql = "SELECT acontent_aid, acontent_sorting FROM ".DB_PREPEND."phpwcms_articlecontent WHERE acontent_id=".$do[1];    
 275      $result = mysql_query($sql, $db) or die("error while updating Article Content");
 276      $row = mysql_fetch_assoc($result);
 277  
 278      $sql =  "UPDATE ".DB_PREPEND."phpwcms_articlecontent SET acontent_sorting=acontent_sorting-10 WHERE acontent_aid=".$row['acontent_aid']." AND acontent_sorting >= ".$row['acontent_sorting']."+10";
 279      mysql_query($sql, $db) or die("error while updating Article Content");    
 280          
 281      $sql =  "UPDATE ".DB_PREPEND."phpwcms_articlecontent SET acontent_sorting=acontent_sorting+10 WHERE acontent_aid=".$do[2]." AND acontent_sorting >= ".$do[3]."+10";
 282      mysql_query($sql, $db) or die("error while updating Article Content");    
 283              
 284      $sql =  "UPDATE ".DB_PREPEND."phpwcms_articlecontent SET acontent_aid=".$do[2].", acontent_sorting=".$do[3]."+10 WHERE acontent_id=".$do[1];
 285      mysql_query($sql, $db) or die("error while updating Article Content");
 286  
 287      }
 288      break;    
 289  //-------------
 290      case 8:    //
 291      $do[1] = intval($do[1]); //copy Article Content ID
 292      $do[2] = intval($do[2]); //paste Article ID
 293      $do[3] = intval($do[3]); //sort Number
 294      if($do[1]) { 
 295              
 296      $sql =  "UPDATE ".DB_PREPEND."phpwcms_articlecontent SET acontent_sorting=acontent_sorting+10 WHERE acontent_aid=".$do[2]." AND acontent_sorting >= ".$do[3]."+10";
 297      mysql_query($sql, $db) or die("error while updating Article Content");    
 298  
 299      $sql  = "SELECT * FROM ".DB_PREPEND."phpwcms_articlecontent WHERE acontent_id=".$do[1];
 300              if($result = mysql_query($sql, $db) or die("error sql")) {
 301                    $row = mysql_fetch_assoc($result); 
 302                      foreach($row as $key => $value) {
 303                          if($key == "acontent_created") {
 304                              $key1s   .= ", ".$key;
 305                              $value1s .= ", NOW()";
 306                          }elseif($key == "acontent_id" ){
 307                              $key1s   = $key;
 308                              $value1s = "''";
 309                          }elseif($key == "acontent_aid" ){
 310                              $key1s   .= ", ".$key;
 311                              $value1s .= ", '".$do[2]."'";                                
 312                          }elseif($key == "acontent_sorting" ){
 313                              $key1s   .= ", ".$key;
 314                              $do[3] = $do[3] + 10;
 315                              $value1s .= ", '".$do[3]."'";                                
 316                          }else{
 317                              $key1s   .= ", ".$key;
 318                              $value1s .= ", '".aporeplace($value)."'";
 319                          }
 320                      }
 321                      $sql2 =  "INSERT INTO ".DB_PREPEND."phpwcms_articlecontent (".$key1s.") VALUES (".$value1s.")" ;
 322                      $result = mysql_query($sql2, $db) or die("error while copy article content <br>error while connecting to database: <br><pre>".$sql2."</pre>");
 323                  
 324              }
 325      
 326  
 327      }
 328      break;        
 329  //31-03-2005 Fernando Batista  end-------------------
 330      
 331  
 332      case 9: //Löschen des Levels
 333      $do[1] = intval($do[1]); //delete ID
 334      if($do[1]) {
 335          // extend deleting of structure levels also for deleting of all related child
 336          // structure levels and articles on structure level
 337          // this is necessary to be sure that such deleted articles/structures are
 338          // not available anymore
 339  
 340          // 1.) get all structure level IDs and put into an array
 341          $struct_del = array();
 342          $article_del = array();
 343  
 344          $struct_del[] = $do[1]; //start
 345  
 346          get_struct_del_id($do[1], $db);
 347  
 348          // create SQL query to set articles deleted
 349          if(count($article_del)) {
 350  
 351              $a_del = "";
 352              foreach($article_del as $value) {
 353                  //delete cached articles
 354                  $sql = "DELETE FROM ".DB_PREPEND."phpwcms_cache WHERE cache_aid=".intval($value);
 355                  mysql_query($sql, $db) or die("error while deleting cached article ID:".$value);
 356                  
 357                  $a_del .= ($a_del) ? " OR article_id=".$value : "article_id=".$value;
 358              }
 359  
 360              if($a_del) {
 361                  $sql = "UPDATE ".DB_PREPEND."phpwcms_article SET article_deleted=9, article_alias=CONCAT(article_alias,'_del-','".date('YmdHis')."') WHERE (".$a_del.")";
 362                  mysql_query($sql, $db) or die("error while deleting articles while deleting structures");
 363              }
 364          }
 365  
 366          // create SQL query to set structure levels deleted
 367          if(count($struct_del)) {
 368  
 369              $s_del = "";
 370              foreach($struct_del as $value) {
 371                  //delete cached categories
 372                  $sql = "DELETE FROM ".DB_PREPEND."phpwcms_cache WHERE cache_cid=".intval($value);
 373                  mysql_query($sql, $db) or die("error while deleting cached category ID:".$value);
 374              
 375                  $s_del .= ($s_del) ? " OR acat_id=".$value : "acat_id=".$value;
 376              }
 377  
 378              if($s_del) {
 379                  $sql = "UPDATE ".DB_PREPEND."phpwcms_articlecat SET acat_trash=9, acat_alias=CONCAT(acat_alias,'_del-','".date('YmdHis')."') WHERE (".$s_del.")";
 380                  mysql_query($sql, $db) or die("error while deleting structures");
 381              }
 382          }
 383  
 384      }
 385      break;
 386  
 387  }
 388  
 389  } //Ende Abarbeiten Aktion
 390  
 391  update_cache();
 392  
 393  // empty pre-rendered frontend structure for all visible modes
 394  // VISIBLE_MODE: 0 = frontend (all) mode, 1 = article user mode, 2 = admin user mode
 395  _setConfig('structure_array_vmode_all', false, 'frontend_render', 1);
 396  _setConfig('structure_array_vmode_editor', false, 'frontend_render', 1);
 397  _setConfig('structure_array_vmode_admin', false, 'frontend_render', 1);
 398  
 399  
 400  if(isset($_POST['SubmitClose'])) {
 401      headerRedirect(PHPWCMS_URL.'phpwcms.php?do=admin&p=6');
 402  } else {
 403      headerRedirect($ref);
 404  }
 405  
 406  function get_struct_del_id($s_id=0, $dbcon) {
 407  
 408      $s_id = intval($s_id);
 409  
 410      //retrieve article ID list that should be deleted
 411      $sql = "SELECT article_id FROM ".DB_PREPEND."phpwcms_article WHERE article_deleted=0 AND article_cid=".$s_id;
 412      if($result = mysql_query($sql, $dbcon)) {
 413          while($row = mysql_fetch_row($result)) {
 414              $GLOBALS["article_del"][] = $row[0];
 415          }
 416          mysql_free_result($result);
 417      }
 418  
 419      // retrieve structure ID list that should be deleted
 420      $sql = "SELECT acat_id FROM ".DB_PREPEND."phpwcms_articlecat WHERE acat_trash=0 AND acat_struct=".$s_id;
 421      if($result = mysql_query($sql, $dbcon)) {
 422          while($row = mysql_fetch_row($result)) {
 423              $GLOBALS["struct_del"][] = $row[0];
 424              get_struct_del_id($row[0], $dbcon);
 425          }
 426          mysql_free_result($result);
 427      }
 428  }
 429  
 430  //19-11-2004  Fernando Batista start-----------------------------------------------------------------------------------------------------------
 431  function copy_article_to_level($do, $dbcon) {
 432  
 433      $sql  = "SELECT * FROM ".DB_PREPEND."phpwcms_article WHERE article_deleted=0 AND article_id=".$do[1];
 434      if($result = mysql_query($sql, $dbcon) or die("error while connecting to database: <pre>".$sql."</pre>")) {
 435  
 436          if($row = mysql_fetch_assoc($result)) {
 437              $row["article_cid"]     = $do[2];
 438              $row["article_created"]    = now();
 439              $row["article_tstamp"]    = date('Y-m-d H:i:s', now() );
 440              $row["article_sort"]    = getArticleSortValue($row["article_cid"]);
 441              $row["article_alias"]    = proof_alias(0, empty($row["article_alias"]) ? $row['article_title'] : $row["article_alias"], 'ARTICLE');
 442  
 443              foreach($row as $key => $value) {
 444                  if($key == "article_id" ){
 445                      $keys   = $key;
 446                      $values = "''";
 447                  } else {
 448                      $keys   .= ", ".$key;
 449                      $values .= ", '".aporeplace($value)."'";
 450                  }
 451              }
 452          }
 453          mysql_free_result($result);
 454  
 455          $sql =  "INSERT INTO ".DB_PREPEND."phpwcms_article (".$keys.") VALUES (".$values.")" ;
 456  
 457          if($result = mysql_query($sql, $dbcon) or die("error while copy article <br>error while connecting to database: <pre>".$sql."</pre>")) {
 458  
 459              $article_insert_id = mysql_insert_id($dbcon);
 460  
 461              $sql1  = "SELECT * FROM ".DB_PREPEND."phpwcms_articlecontent WHERE acontent_aid=".$do[1];
 462              if($result1 = mysql_query($sql1, $dbcon) or die("error sql")) {
 463                  while ($row1 = mysql_fetch_assoc($result1)) {
 464                      $row1["acontent_aid"] = $article_insert_id;
 465                      foreach($row1 as $key1 => $value1) {
 466                          if($key1 == "acontent_id" ){
 467                              $key1s   = $key1;
 468                              $value1s = "''";
 469                          } else {
 470                              $key1s   .= ", ".$key1;
 471                              $value1s .= ", '".aporeplace($value1)."'";
 472                          }
 473                      }
 474                      $sql2 =  "INSERT INTO ".DB_PREPEND."phpwcms_articlecontent (".$key1s.") VALUES (".$value1s.")" ;
 475                      $result = mysql_query($sql2, $dbcon) or die("error while copy article content <br>error while connecting to database: <pre>".$sql2."</pre>");
 476                  }
 477                  mysql_free_result($result1);
 478              }
 479  
 480              if(empty($GLOBALS['phpwcms']['disallow_open_copied_article']) && isset($do[3]) && $do[3] == 'open' && $article_insert_id) {
 481              
 482                  headerRedirect(PHPWCMS_URL.'phpwcms.php?do=articles&p=2&s=1&id='.$article_insert_id);
 483              
 484              }
 485  
 486          }
 487  
 488      }
 489  }
 490  
 491  function copy_level_to_level($do, $dbcon) {
 492      // $do[1] -- copy level
 493      // $do[2] -- paste level
 494      // $do[3] -- sort Number
 495  
 496      $sql  = "SELECT * FROM ".DB_PREPEND."phpwcms_articlecat WHERE acat_trash=0 AND acat_id=".$do[1];
 497      if($result = mysql_query($sql, $dbcon) or die("error while connecting to database: <br><pre>".$sql."</pre>")) {
 498          if($row = mysql_fetch_assoc($result)) {
 499              $row["acat_struct"] = $do[2];
 500              $row["acat_sort"]   = $do[3];
 501              $row["acat_alias"]  = proof_alias(0, empty($row["acat_alias"]) ? $row['acat_name'] : $row["acat_alias"], 'CATEGORY');;
 502  
 503              foreach($row as $key => $value) {
 504                  if($key == "acat_id" ) {
 505                      $keys   = $key;
 506                      $values = "''";
 507                  } else {
 508                      $keys   .= ", ".$key;
 509                      $values .= ", '".aporeplace($value)."'";
 510                  }
 511              }
 512          }
 513          mysql_free_result($result);
 514  
 515          $sql =  "INSERT INTO ".DB_PREPEND."phpwcms_articlecat (".$keys.") VALUES (".$values.")" ;
 516          mysql_query($sql, $dbcon);
 517          $acat_insert_id = mysql_insert_id($dbcon);
 518      }
 519  
 520  
 521      $sql = "SELECT article_id FROM ".DB_PREPEND."phpwcms_article WHERE article_deleted=0 AND article_cid=".$do[1];
 522      if($result = mysql_query($sql, $dbcon)) {
 523          while($row = mysql_fetch_row($result)) {
 524              $do_article[1] = $row[0];
 525              $do_article[2] = $acat_insert_id;  
 526              copy_article_to_level($do_article, $dbcon);
 527          }
 528          mysql_free_result($result);
 529      }
 530  
 531  
 532      $sql = "SELECT acat_id,acat_sort FROM ".DB_PREPEND."phpwcms_articlecat WHERE acat_trash=0 AND acat_struct=".$do[1];
 533      if($result = mysql_query($sql, $dbcon)) {
 534          while($row = mysql_fetch_row($result)) {
 535              $do_struct[1] = $row[0];
 536              $do_struct[2] = $acat_insert_id ;  
 537              $do_struct[3] = $row[1];
 538              copy_level_to_level($do_struct, $dbcon);
 539          }
 540          mysql_free_result($result);
 541      }
 542  }
 543  //19-11-2004  Fernando Batista end-------------------
 544  
 545  function set_correct_ordersort() {
 546      // 0 = manual, 2 = creation date, 4 = start date -> + 0 = ASC, + 1 = DESC
 547      $val = 0;
 548      
 549      // but why not - should be possible too based on new sorting
 550      $val = intval($_POST["acat_order"]) + intval($_POST["acat_ordersort"]);
 551  
 552      return $val;
 553  }
 554  
 555  ?>


Generated: Sun Jan 29 16:31:14 2012 Cross-referenced by PHPXref 0.7.1