<?php
// +-------------------------------------------------+
// | 2002-2011 PMB Services / www.sigb.net pmb@sigb.net et contributeurs (voir www.sigb.net)
// +-------------------------------------------------+
// $Id: campaigns_logs_controller.class.php,v 1.1.2.5 2026/07/02 09:08:25 dgoron Exp $

if (stristr($_SERVER['REQUEST_URI'], ".class.php")) die("no access");

global $class_path;
require_once($class_path."/campaigns/campaign.class.php");
require_once($class_path."/campaigns/campaign_stats.class.php");

class campaigns_logs_controller extends lists_controller {
	
	protected static $model_class_name = 'campaign_logs';
	
	protected static $list_ui_class_name = 'list_campaigns_logs_ui';
	
	protected static $num_campaign;
	
	protected static $view_name;
	
	protected static function get_list_ui_instance($filters=array(), $pager=array(), $applied_sort=array()) {
	    $filters['campaigns'] = [static::$num_campaign];
	    return new static::$list_ui_class_name($filters, $pager, $applied_sort);
	}
	
	public static function proceed($id=0) {
	    $list_ui_class_name = static::$list_ui_class_name;
	    $list_ui_class_name::set_num_campaign(static::$num_campaign);
	    $list_ui_class_name::set_view_name(static::$view_name);
	    parent::proceed($id);
	}
	
	public static function proceed_ajax($object_type, $directory='campaigns') {
	    global $filters, $pager, $sort_by, $sort_asc_desc;
	    
	    $objects_type=substr($object_type,0,strpos($object_type, '_ui_')+3);
	    if(isset($objects_type) && $objects_type) {
	        $class_name = 'list_'.$objects_type;
	        $filters = (!empty($filters) ? encoding_normalize::json_decode(stripslashes($filters), true) : array());
	        $pager = (!empty($pager) ? encoding_normalize::json_decode(stripslashes($pager), true) : array());
	        $class_name::set_num_campaign(static::$num_campaign);
	        $class_name::set_view_name(static::$view_name);
	        $instance_class_name = new $class_name($filters, $pager, array('by' => $sort_by, 'asc_desc' => (!empty($sort_asc_desc) ? $sort_asc_desc : '')));
	        print encoding_normalize::utf8_normalize($instance_class_name->get_display_caption_list());
	        print encoding_normalize::utf8_normalize($instance_class_name->get_display_header_list());
	        print encoding_normalize::utf8_normalize($instance_class_name->get_display_content_list());
	    }
	}
	
	public static function set_num_campaign($num_campaign) {
	    static::$num_campaign = intval($num_campaign);
	}
	
	public static function set_view_name($view_name) {
	    static::$view_name = $view_name;
	}
}