[ Index ]

PHP Cross Reference of phpwcms V1.4.7 _r403 (01.11.10)

title

Body

[close]

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

   1  <?php
   2  /*************************************************************************************
   3     Copyright notice
   4     
   5     (c) 2002-2010 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_\-]/', '', str_replace(' ', '-', 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']    = '';\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 .= "?>";
 107          write_textfile(PHPWCMS_ROOT.'/config/phpwcms/conf.indexpage.inc.php', $sql);
 108      }
 109      
 110      $acat_sort_fallback    = isset($_POST["acat_sort"]) ? intval(trim($_POST["acat_sort"])) : 0;
 111      $acat_sort_temp        = isset($_POST["acat_sort_temp"]) ? intval($_POST["acat_sort_temp"]) : 0;
 112      
 113      if($acat_sort_fallback === 0 && $acat_sort_temp > 0) {
 114          $acat_sort_fallback = $acat_sort_temp;
 115      }
 116  
 117      if(isset($_POST["acat_new"]) && intval($_POST["acat_new"]) == 1 && intval($_POST["acat_id"]) == 0 && $_POST["acat_id"] != 'index') {
 118          if(trim($_POST["acat_name"])) {
 119          
 120              $cache_timeout = clean_slweg($_POST["acat_timeout"]);
 121              if(isset($_POST['acat_cacheoff']) && intval($_POST['acat_cacheoff'])) $cache_timeout = 0; //check if cache = Off
 122          
 123              $sql =    "INSERT INTO ".DB_PREPEND."phpwcms_articlecat (acat_name, acat_info, acat_aktiv, acat_ssl, acat_regonly, ".
 124              "acat_public, acat_struct, acat_template, acat_sort, acat_uid, acat_alias, acat_hidden, acat_topcount, ".
 125              "acat_redirect, acat_order, acat_cache, acat_nosearch, acat_nositemap, acat_permit, acat_maxlist, ".
 126              "acat_cntpart, acat_pagetitle, acat_paginate, acat_overwrite, acat_archive, acat_class, acat_keywords) VALUES ('".
 127              getpostvar($_POST["acat_name"])."','".
 128              getpostvar($_POST["acat_info"], 32000)."',".
 129              (isset($_POST["acat_aktiv"]) ? 1 : 0).",".
 130              (isset($_POST["acat_ssl"]) ? 1 : 0).",".
 131              (isset($_POST["acat_regonly"]) ? 1 : 0).",".
 132              (isset($_POST["acat_public"]) ? 1 : 0).",".
 133              intval($_POST["acat_struct"]).",".
 134              intval($_POST["acat_template"]).",".
 135              $acat_sort_fallback.",".
 136              $_SESSION["wcs_user_id"].",'".
 137              proof_alias($_POST["acat_id"], $_POST["acat_alias"])."',".
 138              $acat_hidden.", ".
 139              intval($_POST["acat_topcount"]).",'".
 140              getpostvar($_POST["acat_redirect"])."', ".
 141              set_correct_ordersort().",'".
 142              $cache_timeout."', '".(isset($_POST['acat_nosearch']) ? 1 : '')."',".
 143              (isset($_POST["acat_nositemap"]) ? 1 : 0).",".
 144              "'".$acat_permit."', ".intval($_POST["acat_maxlist"]).", '".aporeplace($acat_cntpart)."','".
 145              getpostvar($_POST["acat_pagetitle"])."', ".(isset($_POST["acat_paginate"]) ? 1 : 0).", '".getpostvar($_POST["acat_overwrite"])."',".
 146              (empty($_POST["acat_archive"]) ? 0 : 1).", '".aporeplace($acat_class)."', '".aporeplace($acat_keywords)."')";
 147              if($result = mysql_query($sql, $db) or die("error")) {
 148                  $ref .= "&cat=".mysql_insert_id($db);
 149              }
 150          }
 151      }
 152  
 153      if(isset($_POST["acat_new"]) && isset($_POST["acat_id"]) && intval($_POST["acat_new"]) == 0 && intval($_POST["acat_id"])) {
 154          if(trim($_POST["acat_name"])) {
 155          
 156              $cache_timeout = clean_slweg($_POST["acat_timeout"]);
 157              if(isset($_POST['acat_cacheoff']) && intval($_POST['acat_cacheoff'])) $cache_timeout = 0; //check if cache = Off
 158          
 159              $sql =    "UPDATE ".DB_PREPEND."phpwcms_articlecat SET ".
 160              "acat_name='".getpostvar($_POST["acat_name"])."', ".
 161              "acat_info='".getpostvar($_POST["acat_info"], 32000)."', ".
 162              "acat_alias='".aporeplace(proof_alias($_POST["acat_id"], $_POST["acat_alias"]))."', ".
 163              "acat_aktiv=".(isset($_POST["acat_aktiv"]) ? 1 : 0).", ".
 164              "acat_public=".(isset($_POST["acat_public"]) ? 1 : 0).", ".
 165              "acat_struct=".intval($_POST["acat_struct"]).", ".
 166              "acat_template=".intval($_POST["acat_template"]).", ".
 167              "acat_sort=".$acat_sort_fallback.", ".
 168              "acat_uid=".$_SESSION["wcs_user_id"].", ".
 169              "acat_hidden=".$acat_hidden.", ".
 170              "acat_ssl=".(isset($_POST["acat_ssl"]) ? 1 : 0).", ".
 171              "acat_regonly=".(isset($_POST["acat_regonly"]) ? 1 : 0).", ".
 172              "acat_topcount=".intval($_POST["acat_topcount"]).", ".
 173              "acat_redirect='".getpostvar($_POST["acat_redirect"])."',".
 174              "acat_order=".set_correct_ordersort().", ".
 175              "acat_cache='".aporeplace($cache_timeout)."', ".
 176              "acat_nosearch='".(isset($_POST['acat_nosearch']) ? 1 : '')."', ".
 177              "acat_nositemap=".(isset($_POST["acat_nositemap"]) ? 1 : 0).", ".
 178              "acat_permit='".aporeplace($acat_permit)."', ".
 179              "acat_maxlist=".intval($_POST["acat_maxlist"]).", ".
 180              "acat_cntpart='".aporeplace($acat_cntpart)."', ".
 181              "acat_pagetitle='".getpostvar($_POST["acat_pagetitle"])."', ".
 182              "acat_paginate=".(isset($_POST["acat_paginate"]) ? 1 : 0).", ".
 183              "acat_overwrite='".getpostvar($_POST["acat_overwrite"])."', ".
 184              "acat_archive=".(empty($_POST["acat_archive"]) ? 0 : 1).", ".
 185              "acat_class='".aporeplace($acat_class)."', ".
 186              "acat_keywords='".aporeplace($acat_keywords)."'".
 187              " WHERE acat_id=".intval($_POST["acat_id"]);
 188          
 189              mysql_query($sql, $db) or die(_report_error('DB', $sql));
 190          }
 191      }
 192  
 193  //diverse Aktionen
 194  $do = explode("|", isset($_GET["do"]) ? $_GET["do"] : '');
 195  
 196  
 197  switch(intval($do[0])) {
 198  
 199      case 1:    //Einfügen in
 200      $do[1] = intval($do[1]); //cut ID
 201      $do[2] = intval($do[2]); //paste ID
 202      $do[3] = intval($do[3]); //sort Number
 203      if($do[1]) { // && $do[2] = 0 für Root
 204      $sql =  "UPDATE ".DB_PREPEND."phpwcms_articlecat SET acat_struct=".$do[2].", acat_sort=".$do[3]." WHERE acat_id=".$do[1];
 205      mysql_query($sql, $db) or die("error while updating structure level");
 206      }
 207      break;
 208  
 209      case 2:    //Sortierung ändern
 210      $do[1] = intval($do[1]); //sort ID1
 211      $do[2] = intval($do[2]); //sort NR1
 212      $do[3] = intval($do[3]); //sort ID2
 213      $do[4] = intval($do[4]); //sort NR2
 214      if($do[1] && $do[2]>=10 && $do[3] && $do[4]>=10) {
 215          $sql =  "UPDATE ".DB_PREPEND."phpwcms_articlecat SET acat_sort=".$do[2]." WHERE acat_id=".$do[1];
 216          mysql_query($sql, $db) or die("error while updating sorting ID1");
 217          $sql =  "UPDATE ".DB_PREPEND."phpwcms_articlecat SET acat_sort=".$do[4]." WHERE acat_id=".$do[3];
 218          mysql_query($sql, $db) or die("error while updating sorting ID1");
 219      }
 220      break;
 221  
 222      case 3:    //Artikel einfügen in
 223      $do[1] = intval($do[1]); //cut Article ID
 224      $do[2] = intval($do[2]); //paste level ID
 225      if($do[1]) { // && $do[2] = 0 für Root
 226          $new_sort = getArticleSortValue($do[2]);
 227          $sql =  "UPDATE ".DB_PREPEND."phpwcms_article SET article_cid=".$do[2].", article_sort=".$new_sort." WHERE article_id=".$do[1];
 228          mysql_query($sql, $db) or die("error while updating article level");
 229      }
 230      break;
 231  
 232      case 4:    //Sortierung Artikel ändern
 233      $do[1] = intval($do[1]); //article sort ID1
 234      $do[2] = intval($do[2]); //article sort NR1
 235      $do[3] = intval($do[3]); //article sort ID2
 236      $do[4] = intval($do[4]); //article sort NR2
 237      if($do[1] && $do[2]>=10 && $do[3] && $do[4]>=10) {
 238          $sql =  "UPDATE ".DB_PREPEND."phpwcms_article SET article_sort=".$do[2].", article_tstamp=article_tstamp WHERE article_id=".$do[1];
 239          mysql_query($sql, $db) or die("error while updating sorting article ID1");
 240          $sql =  "UPDATE ".DB_PREPEND."phpwcms_article SET article_sort=".$do[4].", article_tstamp=article_tstamp WHERE article_id=".$do[3];
 241          mysql_query($sql, $db) or die("error while updating sorting article ID1");
 242      }
 243      break;
 244  
 245  //19-11-2004  Fernando Batista start-----------------------------------------------------------------------------------------------------------
 246      case 5:    // COPY Article
 247      $do[1] = intval($do[1]); //copy Article ID
 248      $do[2] = intval($do[2]); //paste level ID
 249      $do[3] = isset($do[3]) && $do[3] == 'open' ? 'open' : 0; // special link to copy an existing article and open the new
 250      if($do[1]) { //also allowed for pasting in root structure
 251          copy_article_to_level($do, $db);
 252      }
 253      break;
 254  
 255      case 6:    //COPY Structure
 256      $do[1] = intval($do[1]); //copy level ID
 257      $do[2] = intval($do[2]); //paste level ID
 258      $do[3] = intval($do[3]); //sort Number
 259      if($do[1]) { // && $do[2] = 0 für Root
 260          copy_level_to_level($do, $db);
 261      }
 262      break;
 263  //19-11-2004  Fernando Batista  end-------------------
 264  
 265  //31-03-2005 Fernando Batista start-----------------------------------------------------------------------------------------------------------
 266      case 7:    //
 267      $do[1] = intval($do[1]); //cut Article Content ID
 268      $do[2] = intval($do[2]); //paste Article ID
 269      $do[3] = intval($do[3]); //sort Number
 270      if($do[1]) { 
 271          
 272      $sql = "SELECT acontent_aid, acontent_sorting FROM ".DB_PREPEND."phpwcms_articlecontent WHERE acontent_id=".$do[1];    
 273      $result = mysql_query($sql, $db) or die("error while updating Article Content");
 274      $row = mysql_fetch_assoc($result);
 275  
 276      $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";
 277      mysql_query($sql, $db) or die("error while updating Article Content");    
 278          
 279      $sql =  "UPDATE ".DB_PREPEND."phpwcms_articlecontent SET acontent_sorting=acontent_sorting+10 WHERE acontent_aid=".$do[2]." AND acontent_sorting >= ".$do[3]."+10";
 280      mysql_query($sql, $db) or die("error while updating Article Content");    
 281              
 282      $sql =  "UPDATE ".DB_PREPEND."phpwcms_articlecontent SET acontent_aid=".$do[2].", acontent_sorting=".$do[3]."+10 WHERE acontent_id=".$do[1];
 283      mysql_query($sql, $db) or die("error while updating Article Content");
 284  
 285      }
 286      break;    
 287  //-------------
 288      case 8:    //
 289      $do[1] = intval($do[1]); //copy Article Content ID
 290      $do[2] = intval($do[2]); //paste Article ID
 291      $do[3] = intval($do[3]); //sort Number
 292      if($do[1]) { 
 293              
 294      $sql =  "UPDATE ".DB_PREPEND."phpwcms_articlecontent SET acontent_sorting=acontent_sorting+10 WHERE acontent_aid=".$do[2]." AND acontent_sorting >= ".$do[3]."+10";
 295      mysql_query($sql, $db) or die("error while updating Article Content");    
 296  
 297      $sql  = "SELECT * FROM ".DB_PREPEND."phpwcms_articlecontent WHERE acontent_id=".$do[1];
 298              if($result = mysql_query($sql, $db) or die("error sql")) {
 299                    $row = mysql_fetch_assoc($result); 
 300                      foreach($row as $key => $value) {
 301                          if($key == "acontent_created") {
 302                              $key1s   .= ", ".$key;
 303                              $value1s .= ", NOW()";
 304                          }elseif($key == "acontent_id" ){
 305                              $key1s   = $key;
 306                              $value1s = "''";
 307                          }elseif($key == "acontent_aid" ){
 308                              $key1s   .= ", ".$key;
 309                              $value1s .= ", '".$do[2]."'";                                
 310                          }elseif($key == "acontent_sorting" ){
 311                              $key1s   .= ", ".$key;
 312                              $do[3] = $do[3] + 10;
 313                              $value1s .= ", '".$do[3]."'";                                
 314                          }else{
 315                              $key1s   .= ", ".$key;
 316                              $value1s .= ", '".aporeplace($value)."'";
 317                          }
 318                      }
 319                      $sql2 =  "INSERT INTO ".DB_PREPEND."phpwcms_articlecontent (".$key1s.") VALUES (".$value1s.")" ;
 320                      $result = mysql_query($sql2, $db) or die("error while copy article content <br>error while connecting to database: <br><pre>".$sql2."</pre>");
 321                  
 322              }
 323      
 324  
 325      }
 326      break;        
 327  //31-03-2005 Fernando Batista  end-------------------
 328      
 329  
 330      case 9: //Löschen des Levels
 331      $do[1] = intval($do[1]); //delete ID
 332      if($do[1]) {
 333          // extend deleting of structure levels also for deleting of all related child
 334          // structure levels and articles on structure level
 335          // this is necessary to be sure that such deleted articles/structures are
 336          // not available anymore
 337  
 338          // 1.) get all structure level IDs and put into an array
 339          $struct_del = array();
 340          $article_del = array();
 341  
 342          $struct_del[] = $do[1]; //start
 343  
 344          get_struct_del_id($do[1], $db);
 345  
 346          // create SQL query to set articles deleted
 347          if(count($article_del)) {
 348  
 349              $a_del = "";
 350              foreach($article_del as $value) {
 351                  //delete cached articles
 352                  $sql = "DELETE FROM ".DB_PREPEND."phpwcms_cache WHERE cache_aid=".intval($value);
 353                  mysql_query($sql, $db) or die("error while deleting cached article ID:".$value);
 354                  
 355                  $a_del .= ($a_del) ? " OR article_id=".$value : "article_id=".$value;
 356              }
 357  
 358              if($a_del) {
 359                  $sql = "UPDATE ".DB_PREPEND."phpwcms_article SET article_deleted=9, article_alias=CONCAT(article_alias,'_del-','".date('YmdHis')."') WHERE (".$a_del.")";
 360                  mysql_query($sql, $db) or die("error while deleting articles while deleting structures");
 361              }
 362          }
 363  
 364          // create SQL query to set structure levels deleted
 365          if(count($struct_del)) {
 366  
 367              $s_del = "";
 368              foreach($struct_del as $value) {
 369                  //delete cached categories
 370                  $sql = "DELETE FROM ".DB_PREPEND."phpwcms_cache WHERE cache_cid=".intval($value);
 371                  mysql_query($sql, $db) or die("error while deleting cached category ID:".$value);
 372              
 373                  $s_del .= ($s_del) ? " OR acat_id=".$value : "acat_id=".$value;
 374              }
 375  
 376              if($s_del) {
 377                  $sql = "UPDATE ".DB_PREPEND."phpwcms_articlecat SET acat_trash=9, acat_alias=CONCAT(acat_alias,'_del-','".date('YmdHis')."') WHERE (".$s_del.")";
 378                  mysql_query($sql, $db) or die("error while deleting structures");
 379              }
 380          }
 381  
 382      }
 383      break;
 384  
 385  }
 386  
 387  } //Ende Abarbeiten Aktion
 388  
 389  update_cache();
 390  
 391  // empty pre-rendered frontend structure for all visible modes
 392  // VISIBLE_MODE: 0 = frontend (all) mode, 1 = article user mode, 2 = admin user mode
 393  _setConfig('structure_array_vmode_all', false, 'frontend_render', 1);
 394  _setConfig('structure_array_vmode_editor', false, 'frontend_render', 1);
 395  _setConfig('structure_array_vmode_admin', false, 'frontend_render', 1);
 396  
 397  
 398  if(isset($_POST['SubmitClose'])) {
 399      headerRedirect(PHPWCMS_URL.'phpwcms.php?do=admin&p=6');
 400  } else {
 401      headerRedirect($ref);
 402  }
 403  
 404  function get_struct_del_id($s_id=0, $dbcon) {
 405  
 406      $s_id = intval($s_id);
 407  
 408      //retrieve article ID list that should be deleted
 409      $sql = "SELECT article_id FROM ".DB_PREPEND."phpwcms_article WHERE article_deleted=0 AND article_cid=".$s_id;
 410      if($result = mysql_query($sql, $dbcon)) {
 411          while($row = mysql_fetch_row($result)) {
 412              $GLOBALS["article_del"][] = $row[0];
 413          }
 414          mysql_free_result($result);
 415      }
 416  
 417      // retrieve structure ID list that should be deleted
 418      $sql = "SELECT acat_id FROM ".DB_PREPEND."phpwcms_articlecat WHERE acat_trash=0 AND acat_struct=".$s_id;
 419      if($result = mysql_query($sql, $dbcon)) {
 420          while($row = mysql_fetch_row($result)) {
 421              $GLOBALS["struct_del"][] = $row[0];
 422              get_struct_del_id($row[0], $dbcon);
 423          }
 424          mysql_free_result($result);
 425      }
 426  }
 427  
 428  //19-11-2004  Fernando Batista start-----------------------------------------------------------------------------------------------------------
 429  function copy_article_to_level($do, $dbcon) {
 430  
 431      $sql  = "SELECT * FROM ".DB_PREPEND."phpwcms_article WHERE article_deleted=0 AND article_id=".$do[1];
 432      if($result = mysql_query($sql, $dbcon) or die("error while connecting to database: <pre>".$sql."</pre>")) {
 433  
 434          if($row = mysql_fetch_assoc($result)) {
 435              $row["article_cid"]     = $do[2];
 436              $row["article_created"]    = now();
 437              $row["article_tstamp"]    = date('Y-m-d H:i:s', now() );
 438              $row["article_sort"]    = getArticleSortValue($row["article_cid"]);
 439              $row["article_alias"]    = proof_alias(0, empty($row["article_alias"]) ? $row['article_title'] : $row["article_alias"], 'ARTICLE');
 440  
 441              foreach($row as $key => $value) {
 442                  if($key == "article_id" ){
 443                      $keys   = $key;
 444                      $values = "''";
 445                  } else {
 446                      $keys   .= ", ".$key;
 447                      $values .= ", '".aporeplace($value)."'";
 448                  }
 449              }
 450          }
 451          mysql_free_result($result);
 452  
 453          $sql =  "INSERT INTO ".DB_PREPEND."phpwcms_article (".$keys.") VALUES (".$values.")" ;
 454  
 455          if($result = mysql_query($sql, $dbcon) or die("error while copy article <br>error while connecting to database: <pre>".$sql."</pre>")) {
 456  
 457              $article_insert_id = mysql_insert_id($dbcon);
 458  
 459              $sql1  = "SELECT * FROM ".DB_PREPEND."phpwcms_articlecontent WHERE acontent_aid=".$do[1];
 460              if($result1 = mysql_query($sql1, $dbcon) or die("error sql")) {
 461                  while ($row1 = mysql_fetch_assoc($result1)) {
 462                      $row1["acontent_aid"] = $article_insert_id;
 463                      foreach($row1 as $key1 => $value1) {
 464                          if($key1 == "acontent_id" ){
 465                              $key1s   = $key1;
 466                              $value1s = "''";
 467                          } else {
 468                              $key1s   .= ", ".$key1;
 469                              $value1s .= ", '".aporeplace($value1)."'";
 470                          }
 471                      }
 472                      $sql2 =  "INSERT INTO ".DB_PREPEND."phpwcms_articlecontent (".$key1s.") VALUES (".$value1s.")" ;
 473                      $result = mysql_query($sql2, $dbcon) or die("error while copy article content <br>error while connecting to database: <pre>".$sql2."</pre>");
 474                  }
 475                  mysql_free_result($result1);
 476              }
 477  
 478              if(empty($GLOBALS['phpwcms']['disallow_open_copied_article']) && isset($do[3]) && $do[3] == 'open' && $article_insert_id) {
 479              
 480                  headerRedirect(PHPWCMS_URL.'phpwcms.php?do=articles&p=2&s=1&id='.$article_insert_id);
 481              
 482              }
 483  
 484          }
 485  
 486      }
 487  }
 488  
 489  function copy_level_to_level($do, $dbcon) {
 490      // $do[1] -- copy level
 491      // $do[2] -- paste level
 492      // $do[3] -- sort Number
 493  
 494      $sql  = "SELECT * FROM ".DB_PREPEND."phpwcms_articlecat WHERE acat_trash=0 AND acat_id=".$do[1];
 495      if($result = mysql_query($sql, $dbcon) or die("error while connecting to database: <br><pre>".$sql."</pre>")) {
 496          if($row = mysql_fetch_assoc($result)) {
 497              $row["acat_struct"] = $do[2];
 498              $row["acat_sort"]   = $do[3];
 499              $row["acat_alias"]  = proof_alias(0, empty($row["acat_alias"]) ? $row['acat_name'] : $row["acat_alias"], 'CATEGORY');;
 500  
 501              foreach($row as $key => $value) {
 502                  if($key == "acat_id" ) {
 503                      $keys   = $key;
 504                      $values = "''";
 505                  } else {
 506                      $keys   .= ", ".$key;
 507                      $values .= ", '".aporeplace($value)."'";
 508                  }
 509              }
 510          }
 511          mysql_free_result($result);
 512  
 513          $sql =  "INSERT INTO ".DB_PREPEND."phpwcms_articlecat (".$keys.") VALUES (".$values.")" ;
 514          mysql_query($sql, $dbcon);
 515          $acat_insert_id = mysql_insert_id($dbcon);
 516      }
 517  
 518  
 519      $sql = "SELECT article_id FROM ".DB_PREPEND."phpwcms_article WHERE article_deleted=0 AND article_cid=".$do[1];
 520      if($result = mysql_query($sql, $dbcon)) {
 521          while($row = mysql_fetch_row($result)) {
 522              $do_article[1] = $row[0];
 523              $do_article[2] = $acat_insert_id;  
 524              copy_article_to_level($do_article, $dbcon);
 525          }
 526          mysql_free_result($result);
 527      }
 528  
 529  
 530      $sql = "SELECT acat_id,acat_sort FROM ".DB_PREPEND."phpwcms_articlecat WHERE acat_trash=0 AND acat_struct=".$do[1];
 531      if($result = mysql_query($sql, $dbcon)) {
 532          while($row = mysql_fetch_row($result)) {
 533              $do_struct[1] = $row[0];
 534              $do_struct[2] = $acat_insert_id ;  
 535              $do_struct[3] = $row[1];
 536              copy_level_to_level($do_struct, $dbcon);
 537          }
 538          mysql_free_result($result);
 539      }
 540  }
 541  //19-11-2004  Fernando Batista end-------------------
 542  
 543  function set_correct_ordersort() {
 544      // 0 = manual, 2 = creation date, 4 = start date -> + 0 = ASC, + 1 = DESC
 545      $val = 0;
 546      
 547      // but why not - should be possible too based on new sorting
 548      $val = intval($_POST["acat_order"]) + intval($_POST["acat_ordersort"]);
 549  
 550      return $val;
 551  }
 552  
 553  ?>


Generated: Tue Nov 16 22:51:00 2010 Cross-referenced by PHPXref 0.7