Location: PHPKode > projects > Esvon Personals > esvon-personals/modules/Mailing_Lists/admin/modifym.php
<?php

// --------------------------------------------------------------------------
//
// Esvon Classifieds v.4.0
// Copyright(C), Esvon LTD, 2001-2010, All Rights Reserved.
// E-mail: hide@address.com
//
// All forms of reproduction, including, but not limited to, internet posting, 
// printing, e-mailing, faxing and recording are strictly prohibited.
// One license required per site running Esvon Classifieds. 
// To obtain a license for using Esvon Classifieds, please register at
// http://www.esvon.com/pg/products/p_classifieds/
//
// --------------------------------------------------------------------------

if(!defined('SITE_PATH')) die('Access denied');

global $db,$err_msg,$id;

$id = (int)$_REQUEST['id'];

if($_POST['go']) ProcessForm();
elseif($_POST['em_export']){
  if($id > 0) $ql = 'SELECT email FROM '.TBL_ML.' WHERE list_id='.$id;
  else{
    $ql = ML_getEmailsAmountSQL($id);
    $ql = preg_replace('/COUNT\(.*?\)\s/','DISTINCT email ',$ql);
  }
  $o_ex = new ExportData;
  $o_ex->TBL = HW_MOD.'_'.($id > 0 ? $id : 'u'.abs($id));
  $o_ex->SQL = $ql;
  $o_ex->Export();
}
elseif($_POST['em_del'] || $_POST['em_del_all']) {
  $ql = '';
  if($_POST['em_del_all']) $ql = "DELETE FROM ".TBL_ML." WHERE list_id = '$id'";
  elseif(is_array($_POST['chk_id'])){
    $ql = '"'.implode('","', array_map('intval', $_POST['chk_id'])).'"';
    $ql = "DELETE FROM ".TBL_ML." WHERE id IN (".$ql.")";
  }
  if($ql){
	  $db->query($ql);
    $err_msg = 'Emails deleted successfully : '.$db->affected_rows();
  }
}
elseif($_POST['em_add']){
  $em_val = trim($_POST['em_val']);
  if($em_val){
    $err_msg = '';
    // SQL query
    if(preg_match('/^SELECT\s/i', $em_val)){ 
      $db->ERR_EXIT = FALSE;
      $em_val = $db->one_col_array($em_val);
      $err_msg = $db->ERR_MSG;
      $db->ERR_EXIT = TRUE;
    }
    else $em_val = preg_split('/[,\n]+/',$em_val);
    $cnt = 0;
    if(is_array($em_val)) foreach($em_val as $em){
      $em = trim($em);
      if(IsEmail($em)){ 
        $db->query('INSERT IGNORE INTO '.TBL_ML." (list_id,email,date) VALUES ('$id',".$db->esc($em).",".SQL_NOW.")");
        $cnt+=$db->affected_rows();
      }
    }
    if(!$err_msg) $err_msg = "Email(s) added successfully : $cnt";
  }
}

ShowForm();


// sub area

function ShowForm() {
  global $db,$id;

  $tpl_v = $db->one_assoc('SELECT id,hide,capture,name,descr,bottom_text FROM '.TBL_ML_IDX.' where id="'.$id.'"');
  if(!$tpl_v) return;
  $tpl_v['hide'] = $tpl_v['hide'] ? 'checked' : '';
  $tpl_v['capture'] = $tpl_v['capture'] ? 'checked' : '';

  $tpl = new HawkTpl;
  $tpl->InitArray('tr');

  if($id > 0){

    //nav stuff starts
    define('DISP_ROWS',10);

    $off = (ctype_digit($_GET['off']) && $_SERVER['REQUEST_METHOD']=='GET') ? $_GET['off'] : 0;
    $num = $off*DISP_ROWS;

    $ql = 'SELECT COUNT(*) FROM '.TBL_ML.' WHERE list_id='.$id;
    if($_REQUEST['q']) $ql.=" AND email LIKE '%".addcslashes($db->quote($_REQUEST['q']), '%_')."%'";

    $tpl_v['em_total'] = $db->one_data($ql);
    $tpl_v['nav'] = GetNavigation(HW_MOD_URL,DISP_ROWS,10,$tpl_v['em_total'],$off,"&file=modifym&id=$id&q=".urlencode($_REQUEST['q']));
    
    $ql = str_replace('COUNT(*)','*',$ql).' ORDER BY email LIMIT '.$num.','.DISP_ROWS;
    $res = $db->query($ql);

     while($v = mysql_fetch_assoc($res)){
       $v['num'] = ++$num;
       $v['emid'] = $v['id'];
       $tpl->AddCell('tr',$v);
    }

    $tpl_v['q'] = html_esc($_REQUEST['q']);
  }
  else{
    $tpl_v['em_total'] = $db->one_data( ML_getEmailsAmountSQL($id) );
  }

  $tpl->Parse(HW_MOD_TPL.'add_mlist.htm',$tpl_v,1);
}

function ProcessForm() {
  global $db,$err_msg,$id;

  if(!$_POST['name']) $err_msg = 'Mailing list name cannot be empty';
  if(!$err_msg) {
	  $db->query("UPDATE ".TBL_ML_IDX." SET name=?,hide=?,capture=?,bottom_text=?,descr=? WHERE id='$id'",
      array($_POST['name'], $_POST['hide'], $_POST['capture'], $_POST['bottom_text'], $_POST['descr']) );
    $err_msg = 'Mailing list has been updated';
  }

}

?>
Return current item: Esvon Personals