setupCustomFields('EcmMailingMessages');
foreach($this->field_defs as $field){
$this->field_name_map[$field['name']] = $field;
}
}
function get_summary_text(){
return $this->name;
}
function create_list_query($order_by, $where, $show_deleted = 0){
$custom_join = $this->custom_fields->getJOIN();
$query ="SELECT ";
$query.="ecmmailingmessages.*,users.user_name as assigned_user_name";
if($custom_join)$query.=$custom_join['select'];
$query.=" FROM ecmmailingmessages ";
$query.="LEFT JOIN users ON ecmmailingmessages.assigned_user_id=users.id";
$query.=" ";
if($custom_join)$query.=$custom_join['join'];
$where_auto='1=1';
if($show_deleted==0)$where_auto=" $this->table_name.deleted=0 ";
elseif($show_deleted==1)$where_auto=" $this->table_name.deleted=1 ";
if($where!="")$query.="where $where AND ".$where_auto;
else $query.="where ".$where_auto;
if(substr_count($order_by,'.')>0)$query .= " ORDER BY $order_by";
elseif($order_by != "")$query .= " ORDER BY $order_by";
else $query .= " ORDER BY ecmmailingmessages.name";
return $query;
}
function create_export_query($order_by,$where){
$custom_join = $this->custom_fields->getJOIN();
$query ="SELECT ";
$query.="ecmmailingmessages.*,users.user_name as assigned_user_name";
if($custom_join)$query.=$custom_join['select'];
$query.=" FROM ecmmailingmessages ";
$query.="LEFT JOIN users ON ecmmailingmessages.assigned_user_id=users.id";
$query.=" ";
if($custom_join)$query.=$custom_join['join'];
$where_auto='1=1';
if($show_deleted==0)$where_auto=" $this->table_name.deleted=0 ";
elseif($show_deleted==1)$where_auto=" $this->table_name.deleted=1 ";
if($where!="")$query.="where $where AND ".$where_auto;
else $query.="where ".$where_auto;
if(substr_count($order_by,'.')>0)$query .= " ORDER BY $order_by";
elseif($order_by != "")$query .= " ORDER BY $order_by";
else $query .= " ORDER BY ecmmailingmessages.name";
return $query;
}
function fill_in_additional_list_fields(){
}
function fill_in_additional_detail_fields(){
parent::fill_in_additional_detail_fields();
}
function get_list_view_data(){
global $current_language;
$the_array=parent::get_list_view_data();
$app_list_strings=return_app_list_strings_language($current_language);
$mod_strings=return_module_language($current_language,'EcmMailingMessages');
$the_array['NAME']=(($this->name == "") ? "blank" : $this->name);
$the_array['ENCODED_NAME']=$this->name;
return $the_array;
}
function build_generic_where_clause($the_query_string){
$where_clauses=array();
$the_query_string=PearDatabase::quote(from_html($the_query_string));
array_push($where_clauses,"ecmmailingmessages.name like '$the_query_string%'");
$the_where="";
foreach($where_clauses as $clause){
if($the_where!="")$the_where.=" or ";
$the_where.=$clause;
}
return $the_where;
}
function set_notification_body($xtpl,$ecmmailingmessage)
{
global $mod_strings,$app_list_strings;
$xtpl->assign("ECMPRODUCTCATEGORY_SUBJECT",$ecmmailingmessage->name);
return $xtpl;
}
function bean_implements($interface){
switch($interface){
case 'ACL':return true;
}
return false;
}
function save($check_notify=FALSE){
return parent::save($check_notify);
//$this->db->query("update ecmmailingmessages set send=0 where id='".$this->id."'");
}
function showPositions55(){
$arr=$this->getPositionList55(true);
global $mod_strings;
if(count($arr)>0){
$table='
| Nazwa grupy
| Aktywna
|
';
$i == 0;
foreach($arr as $a){
$i++;
$table.='
| '.$a['product_group'].' |
'.($a['discount']==1 ? 'Tak' : "Nie").' |
';
}
$table.='
';
}
return $table;
}
function getPositionList56($array = false) {
if(isset($this->id) && $this->id != '') {
$query = "SELECT * FROM ecmaccountcategories_bean WHERE bean_id='".$this->id."' AND deleted='0' AND bean_name='MailingContacts'";
$r = $this->db->query($query);
$return_array = array();
if($r) {
while($w = $this->db->fetchByAssoc($r)) {
//get category name && assigned_file
$n = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT name FROM ecmmailingcategories WHERE id='".$w['ecmaccountcategory_id']."'"));
$w['product_group'] = $n['name'];
$w['cat_id'] =$w['ecmaccountcategory_id'];
$return_array [] = $w;
}
$json = getJSONobj();
return $array ? $return_array : $json->encode($return_array);
}
}
return $array ? false : '[]';
}
function getPositionList55($array = false) {
if(isset($this->id) && $this->id != '') {
$query = "SELECT * FROM ecmaccountcategories_bean WHERE bean_id='".$this->id."' AND deleted='0' AND bean_name='Mailing'";
$r = $this->db->query($query);
$return_array = array();
if($r) {
while($w = $this->db->fetchByAssoc($r)) {
//get category name && assigned_file
$n = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT name FROM ecmaccountcategories WHERE id='".$w['ecmaccountcategory_id']."'"));
$w['product_group'] = $n['name'];
$w['cat_id'] =$w['ecmaccountcategory_id'];
$return_array [] = $w;
}
$json = getJSONobj();
return $array ? $return_array : $json->encode($return_array);
}
}
return $array ? false : '[]';
}
//end managing addresses
function savePositions55($pl) {
global $current_user;
$exists = array();
foreach ($pl as $p) {
if (!isset($p['product_group']) || $p['product_group']=='') continue;
if (isset($p['id']) && $p['id']!='') {
//update exists
$q = "
UPDATE ecmaccountcategories_bean set
date_modified = '".date("Y-m-d H:i:s")."',
modified_user_id = '".$current_user->id."',
bean_id = '".addslashes($this->id)."',
ecmaccountcategory_id = '".addslashes($p['cat_id'])."'
WHERE id = '".$p['id']."'
";
/*
$q = "
UPDATE ecmmailingcategories_relation set
parent_id = '".addslashes($this->id)."',
ecmmailingcategoriy_id= '".addslashes($p['cat_id'])."',
available = '".addslashes($p['discount'])."',
parent_type = 'MailingMessage',
parent_name = '".addslashes($p['product_group'])."'
WHERE id = '".$p['id']."'
";
*/
//$GLOBALS['db']->query("INSERT INTO log VALUES ('".addslashes($q)."')");
$GLOBALS['db']->query($q);
$exists[] = $p['id'];
} else {
//insert new record
$id = create_guid();
/*
$t = array(
$id,
addslashes($p['cat_id']),
'0',
addslashes($p['discount']),
$this->id,
addslashes($p['product_group']),
'MailingMessage'
); */
$t = array(
$id,
addslashes($p['cat_id']),
$this->id,
"Mailing",
date("Y-m-d H:i:s"),
date("Y-m-d H:i:s"),
$current_user->id,
$current_user->id,
'0'
);
$q = "INSERT INTO ecmaccountcategories_bean VALUES ('".implode("','", $t)."')";
$GLOBALS['db']->query($q);
$exists[] = $id;
}
}
//delete old
$GLOBALS['db']->query("UPDATE ecmaccountcategories_bean SET deleted='1', modified_user_id='".$current_user->id."',date_modified = '".date("Y-m-d H:i:s")."' WHERE bean_id='".$this->id."' AND bean_name='Mailing' and id NOT IN ('".implode("','",$exists)."')");
}
function savePositions56($pl) {
global $current_user;
$exists = array();
foreach ($pl as $p) {
if (!isset($p['product_group']) || $p['product_group']=='') continue;
if (isset($p['id']) && $p['id']!='') {
//update exists
$q = "
UPDATE ecmaccountcategories_bean set
date_modified = '".date("Y-m-d H:i:s")."',
modified_user_id = '".$current_user->id."',
bean_id = '".addslashes($this->id)."',
ecmaccountcategory_id = '".addslashes($p['cat_id'])."'
WHERE id = '".$p['id']."'
";
/*
$q = "
UPDATE ecmmailingcategories_relation set
parent_id = '".addslashes($this->id)."',
ecmmailingcategoriy_id= '".addslashes($p['cat_id'])."',
available = '".addslashes($p['discount'])."',
parent_type = 'MailingMessage',
parent_name = '".addslashes($p['product_group'])."'
WHERE id = '".$p['id']."'
";
*/
//$GLOBALS['db']->query("INSERT INTO log VALUES ('".addslashes($q)."')");
$GLOBALS['db']->query($q);
$exists[] = $p['id'];
} else {
//insert new record
$id = create_guid();
/*
$t = array(
$id,
addslashes($p['cat_id']),
'0',
addslashes($p['discount']),
$this->id,
addslashes($p['product_group']),
'MailingMessage'
); */
$t = array(
$id,
addslashes($p['cat_id']),
$this->id,
"MailingContacts",
date("Y-m-d H:i:s"),
date("Y-m-d H:i:s"),
$current_user->id,
$current_user->id,
'0'
);
$q = "INSERT INTO ecmaccountcategories_bean VALUES ('".implode("','", $t)."')";
$GLOBALS['db']->query($q);
$exists[] = $id;
}
}
//delete old
$GLOBALS['db']->query("UPDATE ecmaccountcategories_bean SET deleted='1', modified_user_id='".$current_user->id."',date_modified = '".date("Y-m-d H:i:s")."' WHERE bean_id='".$this->id."' and bean_name='MailingContacts' AND id NOT IN ('".implode("','",$exists)."')");
}
}
?>