Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/templates/default/extend/ajax/manage_category.plugin.php
Строк: 140
<?php
defined
('_VALID') or die('Restricted Access!');
function 
ajax_plugin_manage_category()
{
    
$data = array('status' => 0'code' => '''msg' => '''debug' => '');
    if (isset(
$_POST['cat_id']) OR isset($_POST['options'])) {
          
$cat_id     = (isset($_POST['cat_id'])) ? (int) trim($_POST['cat_id']) : NULL;
          if (isset(
$_POST['options'])) {
              
parse_str($_POST['options'], $options);
              
$cat_id = (int) $options['cat_id'];
          }
          
          
$db    VF::factory('database');
          
$db->query("SELECT cat_id FROM #__video_categories WHERE cat_id = ".$cat_id." LIMIT 1");
          if (
$db->affected_rows()) {
              
$db->query("SELECT adv_group_id FROM #__adv_groups WHERE adv_group_slug = 'video-player' LIMIT 1");
              if (
$db->affected_rows()) {
                  
$adv_group_id_p = (int) $db->fetch_field('adv_group_id');
              }

              
$db->query("SELECT adv_group_id FROM #__adv_groups WHERE adv_group_slug = 'video-view-right' LIMIT 1");
              if (
$db->affected_rows()) {
                  
$adv_group_id_r = (int) $db->fetch_field('adv_group_id');
              }
          
              
$db->query("SELECT adv_group_id FROM #__adv_groups WHERE adv_group_slug = 'video-category-top' LIMIT 1");
              if (
$db->affected_rows()) {
                  
$adv_group_id_t = (int) $db->fetch_field('adv_group_id');
              }

              
$db->query("SELECT adv_group_id FROM #__adv_groups WHERE adv_group_slug = 'video-category-square' LIMIT 1");
              if (
$db->affected_rows()) {
                  
$adv_group_id_s = (int) $db->fetch_field('adv_group_id');
              }

              
$db->query("SELECT adv_group_id FROM #__adv_groups WHERE adv_group_slug = 'video-category-left' LIMIT 1");
              if (
$db->affected_rows()) {
                  
$adv_group_id_l = (int) $db->fetch_field('adv_group_id');
              }

              
$db->query("SELECT adv_group_id FROM #__adv_groups WHERE adv_group_slug = 'video-category-bottom' LIMIT 1");
              if (
$db->affected_rows()) {
                  
$adv_group_id_b = (int) $db->fetch_field('adv_group_id');
              }


              if (isset(
$options)) {
                  
$db->query("DELETE FROM #__adv_category WHERE adv_group_id = ".$adv_group_id_p." AND cat_id = ".$cat_id);
                  if (isset(
$options['advs_player']) && isset($adv_group_id_p)) {
                      foreach (
$options['advs_player'] as $adv_id) {
                          
$db->query("INSERT INTO #__adv_category
                                      SET adv_group_id = "
.$adv_group_id_p.",
                                          cat_id = "
.$cat_id.",
                                          adv_id = "
.$adv_id);
                      }
                  }

                  
$db->query("DELETE FROM #__adv_category WHERE adv_group_id = ".$adv_group_id_r." AND cat_id = ".$cat_id);
                  if (isset(
$options['advs_right']) && isset($adv_group_id_r)) {
                      foreach (
$options['advs_right'] as $adv_id) {
                          
$db->query("INSERT INTO #__adv_category
                                      SET adv_group_id = "
.$adv_group_id_r.",
                                          cat_id = "
.$cat_id.",
                                          adv_id = "
.$adv_id);
                      }
                  }
                  
                  
$db->query("DELETE FROM #__adv_category WHERE adv_group_id = ".$adv_group_id_t." AND cat_id = ".$cat_id);
                  if (isset(
$options['advs_top']) && isset($adv_group_id_t)) {
                      foreach (
$options['advs_top'] as $adv_id) {
                          
$db->query("INSERT INTO #__adv_category
                                      SET adv_group_id = "
.$adv_group_id_t.",
                                          cat_id = "
.$cat_id.",
                                          adv_id = "
.$adv_id);
                      }
                  }

                  
$db->query("DELETE FROM #__adv_category WHERE adv_group_id = ".$adv_group_id_s." AND cat_id = ".$cat_id);
                  if (isset(
$options['advs_square']) && isset($adv_group_id_s)) {
                      foreach (
$options['advs_square'] as $adv_id) {
                          
$db->query("INSERT INTO #__adv_category
                                      SET adv_group_id = "
.$adv_group_id_s.",
                                          cat_id = "
.$cat_id.",
                                          adv_id = "
.$adv_id);
                      }
                  }

                  
$db->query("DELETE FROM #__adv_category WHERE adv_group_id = ".$adv_group_id_l." AND cat_id = ".$cat_id);
                  if (isset(
$options['advs_left']) && isset($adv_group_id_l)) {
                      foreach (
$options['advs_left'] as $adv_id) {
                          
$db->query("INSERT INTO #__adv_category
                                      SET adv_group_id = "
.$adv_group_id_l.",
                                          cat_id = "
.$cat_id.",
                                          adv_id = "
.$adv_id);
                      }
                  }

                  
$db->query("DELETE FROM #__adv_category WHERE adv_group_id = ".$adv_group_id_b." AND cat_id = ".$cat_id);
                  if (isset(
$options['advs_bottom']) && isset($adv_group_id_b)) {
                      foreach (
$options['advs_bottom'] as $adv_id) {
                          
$db->query("INSERT INTO #__adv_category
                                      SET adv_group_id = "
.$adv_group_id_b.",
                                          cat_id = "
.$cat_id.",
                                          adv_id = "
.$adv_id);
                      }
                  }
              }
              
              
$advs_player        = array();
              
$advs_player_cur    = array();
              if (isset(
$adv_group_id_p)) {
                  
$sql                "SELECT a.adv_id, a.adv_name
                                           FROM #__adv_groups AS g
                                           INNER JOIN #__adv AS a ON (a.adv_group_id = g.adv_group_id)
                                           WHERE g.adv_group_id = "
.$adv_group_id_p."
                                           ORDER BY a.adv_name ASC"
;
                  
$advs_player        $db->get_rows($sql);
                  
$sql                "SELECT adv_id
                                         FROM #__adv_category
                                         WHERE adv_group_id = "
.$adv_group_id_p."
                                         AND cat_id = "
.$cat_id;
                  
$advs_player_cur    rows_to_assoc($db->get_rows($sql));
              }

              
$advs_right        = array();
              
$advs_right_cur    = array();
              if (isset(
$adv_group_id_p)) {
                  
$sql            "SELECT a.adv_id, a.adv_name
                                     FROM #__adv_groups AS g
                                     INNER JOIN #__adv AS a ON (a.adv_group_id = g.adv_group_id)
                                     WHERE g.adv_group_id = "
.$adv_group_id_r."
                                     ORDER BY a.adv_name ASC"
;
                  
$advs_right        $db->get_rows($sql);
                  
$sql            "SELECT adv_id
                                     FROM #__adv_category
                                     WHERE adv_group_id = "
.$adv_group_id_r."
                                     AND cat_id = "
.$cat_id;
                  
$advs_right_cur    rows_to_assoc($db->get_rows($sql));
              }
          
              
$advs_top        = array();
              
$advs_top_cur    = array();
              if (isset(
$adv_group_id_t)) {
                  
$sql            "SELECT a.adv_id, a.adv_name
                                   FROM #__adv_groups AS g
                                   INNER JOIN #__adv AS a ON (a.adv_group_id = g.adv_group_id)
                                   WHERE g.adv_group_id = "
.$adv_group_id_t."
                                   ORDER BY a.adv_name ASC"
;
                
$advs_top        $db->get_rows($sql);
                
$sql            "SELECT adv_id
                                   FROM #__adv_category
                                   WHERE adv_group_id = "
.$adv_group_id_t."
                                   AND cat_id = "
.$cat_id;
                
$advs_top_cur    rows_to_assoc($db->get_rows($sql));
              }

              
$advs_square        = array();
              
$advs_square_cur    = array();
              if (isset(
$adv_group_id_s)) {
                  
$sql                "SELECT a.adv_id, a.adv_name
                                       FROM #__adv_groups AS g
                                       INNER JOIN #__adv AS a ON (a.adv_group_id = g.adv_group_id)
                                       WHERE g.adv_group_id = "
.$adv_group_id_s."
                                       ORDER BY a.adv_name ASC"
;
                
$advs_square        $db->get_rows($sql);
                
$sql                "SELECT adv_id
                                         FROM #__adv_category
                                       WHERE adv_group_id = "
.$adv_group_id_s."
                                       AND cat_id = "
.$cat_id;
                
$advs_square_cur    rows_to_assoc($db->get_rows($sql));
              }

              
$advs_left        = array();
              
$advs_left_cur    = array();
              if (isset(
$adv_group_id_l)) {
                  
$sql            "SELECT a.adv_id, a.adv_name
                                   FROM #__adv_groups AS g
                                   INNER JOIN #__adv AS a ON (a.adv_group_id = g.adv_group_id)
                                   WHERE g.adv_group_id = "
.$adv_group_id_l."
                                   ORDER BY a.adv_name ASC"
;
                
$advs_left        $db->get_rows($sql);
                
$sql            "SELECT adv_id
                                   FROM #__adv_category
                                   WHERE adv_group_id = "
.$adv_group_id_l."
                                   AND cat_id = "
.$cat_id;
                
$advs_left_cur    rows_to_assoc($db->get_rows($sql));
              }

              
$advs_bottom        = array();
              
$advs_bottom_cur    = array();
              if (isset(
$adv_group_id_b)) {
                  
$sql                "SELECT a.adv_id, a.adv_name
                                       FROM #__adv_groups AS g
                                       INNER JOIN #__adv AS a ON (a.adv_group_id = g.adv_group_id)
                                       WHERE g.adv_group_id = "
.$adv_group_id_b."
                                       ORDER BY a.adv_name ASC"
;
                
$advs_bottom        $db->get_rows($sql);
                
$sql                "SELECT adv_id
                                         FROM #__adv_category
                                       WHERE adv_group_id = "
.$adv_group_id_b."
                                       AND cat_id = "
.$cat_id;
                
$advs_bottom_cur    rows_to_assoc($db->get_rows($sql));
              }
              
            
$code       = array();
            
$code[]     = '<form id="manage-category-form" method="post" action="'.BASE_URL.'/?q=ajax&s=manage_category&d=backend">';
            
$code[]     = '<input name="cat_id" type="hidden" id="cat_id" value="'.$cat_id.'" />';
            
$code[]        = '<fieldset>';
            
$code[]        = '<legend>Video Player Advertising</legend>';
            if (
$advs_player) {
                  
$code[]    = '<ul class="adv-embed">';
                  foreach (
$advs_player as $adv) {
                      
$checked    = (isset($advs_player_cur[$adv['adv_id']])) ? ' checked="checked"' '';
                      
$code[]        = '<li><input name="advs_player[]" type="checkbox" class="radio" value="'.$adv['adv_id'].'"'.$checked.' /> '.e($adv['adv_name']).'</li>';
                  }
                  
$code[] = '</ul>';
            } else {
                  
$code[]    = '<div class="none-small">No advertising banners found for the Video Player position!';
            }
            
$code[]        = '</fieldset>';
            
$code[]        = '<fieldset>';
            
$code[]        = '<legend>Video View Right Advertising</legend>';
            if (
$advs_right) {
                  
$code[]    = '<ul class="adv-embed">';
                  foreach (
$advs_right as $adv) {
                      
$checked    = (isset($advs_right_cur[$adv['adv_id']])) ? ' checked="checked"' '';
                      
$code[]        = '<li><input name="advs_right[]" type="checkbox" class="radio" value="'.$adv['adv_id'].'"'.$checked.' /> '.e($adv['adv_name']).'</li>';
                  }
                  
$code[] = '</ul>';
            } else {
                  
$code[]    = '<div class="none-small">No advertising banners found for the Video Player position!';
            }
            
$code[]        = '</fieldset>';            
            
$code[]        = '<fieldset>';
            
$code[]        = '<legend>Category Top Advertising</legend>';
            if (
$advs_top) {
                  
$code[]    = '<ul class="adv-embed">';
                  foreach (
$advs_top as $adv) {
                      
$checked    = (isset($advs_top_cur[$adv['adv_id']])) ? ' checked="checked"' '';
                      
$code[]        = '<li><input name="advs_top[]" type="checkbox" class="radio" value="'.$adv['adv_id'].'"'.$checked.' /> '.e($adv['adv_name']).'</li>';
                  }
                  
$code[]    = '</ul>';
            } else {
                  
$code[]    = '<div class="none-small">No advertising banners found for the Category Top Header position!';
            }            
            
$code[]        = '</fieldset>';
            
$code[]        = '<fieldset>';
            
$code[]        = '<legend>Category Square Advertising</legend>';
            if (
$advs_square) {
                  
$code[]    = '<ul class="adv-embed">';
                  foreach (
$advs_square as $adv) {
                      
$checked    = (isset($advs_square_cur[$adv['adv_id']])) ? ' checked="checked"' '';
                      
$code[]        = '<li><input name="advs_square[]" type="checkbox" class="radio" value="'.$adv['adv_id'].'"'.$checked.' /> '.e($adv['adv_name']).'</li>';
                  }
                  
$code[]    = '</ul>';
            } else {
                  
$code[]    = '<div class="none-small">No advertising banners found for the Category Square position!';
            }            
            
$code[]        = '</fieldset>';
            
$code[]        = '<fieldset>';
            
$code[]        = '<legend>Category Left Advertising</legend>';
            if (
$advs_left) {
                  
$code[]    = '<ul class="adv-embed">';
                  foreach (
$advs_left as $adv) {
                      
$checked    = (isset($advs_left_cur[$adv['adv_id']])) ? ' checked="checked"' '';
                      
$code[]        = '<li><input name="advs_left[]" type="checkbox" class="radio" value="'.$adv['adv_id'].'"'.$checked.' /> '.e($adv['adv_name']).'</li>';
                  }
                  
$code[]    = '</ul>';
            } else {
                  
$code[]    = '<div class="none-small">No advertising banners found for the Category Left position!';
            }            
            
$code[]        = '</fieldset>';
            
$code[]        = '<fieldset>';
            
$code[]        = '<legend>Category Bottom Advertising</legend>';
            if (
$advs_bottom) {
                  
$code[]    = '<ul class="adv-embed">';
                  foreach (
$advs_bottom as $adv) {
                      
$checked    = (isset($advs_bottom_cur[$adv['adv_id']])) ? ' checked="checked"' '';
                      
$code[]        = '<li><input name="advs_bottom[]" type="checkbox" class="radio" value="'.$adv['adv_id'].'"'.$checked.' /> '.e($adv['adv_name']).'</li>';
                  }
                  
$code[]    = '</ul>';
            } else {
                  
$code[]    = '<div class="none-small">No advertising banners found for the Category Bottom position!';
            }            
            
$code[]        = '</fieldset>';
            
            
$code[]        = '</form>';          
              
$data['status'] = 1;
            
$data['code']   = implode("n"$code);
          } else {
              
$data['code'] = '<div class="none-small">Invalid video category! What exactly did you click!?</div>';
          }
    } else {
          
$data['msg'] = 'Invalid ajax request!';
    }
    
    return 
json_encode($data);
}

function 
rows_to_assoc($rows)
{
    
$advs    = array();
    foreach (
$rows as $row) {
        
$advs[$row['adv_id']] = 1;
    }
    
    return 
$advs;
}
Онлайн: 0
Реклама