<?php
/*
v1.2
    Copyright 2009-2011 GetWebActive  (email : cookies@getwebactive.com)
    Released under license from GetWebActive
    Use of this plugin is governed by the software licence included in the package. Contact the author if there is no licence in your package.
    *THIS IS NOT FREE SOFTWARE* 
    *All rights reserved* 

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
class ar_gwa_wizard {

var $Step = array();
var $step;
var $list;

   function ar_gwa_wizard() {

    global $wpdb;
    $wpdb->show_errors();
    $table_name = $wpdb->prefix . "ar_gwa_bounce";
      if($wpdb->get_var("show tables like '$table_name'") != $table_name) {   
      $sql = "";
#      $results = $wpdb->query( $sql );
      }   
   }
   

   function admin_ar_gwa_wiz() {
    global $wpdb;
    $wpdb->show_errors();
    $this->step = (int)$_REQUEST['ar_gwa_wstep'];
    if(!isset($_REQUEST['submit2']) && !isset($_REQUEST['ar_gwa_wadd']) && !isset($_REQUEST['ar_gwa_del']) && !isset($_REQUEST['sendTest']))$this->step = 0;
    $this->list_id = (int)$_REQUEST['ar_gwa_list'];
    $msg = $this->ar_gwa_wprocess();
    $body = $this->ar_gwa_wdisplay();    
  echo '<div id=""><div class="wrap"><h2>'.__("Setup Wizard",'argwa').'</h2>';
  if(isset($msg)) echo '<div id="message" class="updated fade"><p>'.$msg.'</p></div>';
  echo $body.'</div></div>';
   }
   
   function ar_gwa_wdisplay() {
   $step = $this->step;
   $this->WizStep($step);
   
   
if(!file_exists(ABSPATH.'wp-content/plugins/autoresponder-gwa/gwa-xinha.txt')){

if (function_exists('wp_tiny_mce')) wp_tiny_mce( false ,
array(
"editor_selector" => "editorContent",
"plugins" => "spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
"theme_advanced_buttons1" => "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
"theme_advanced_buttons2" => "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
"theme_advanced_buttons3" => "hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen,|,spellchecker",
"extended_valid_elements" => "form[*],div[*],style[*],p[*],table[*],td[*]",
"skin" => "o2k7",
"skin_variant" => "silver",)
);
}   
   return '<style>.arHelp{color:#000}</style>'.$this->Step[$step];
   }
   function ar_gwa_wprocess() {
    global $wpdb,$phpmailerDir;
   $step = $this->step;
   if($_REQUEST['ar_gwa_del']!='')$delete = $this->list_id;
   if($step==1) {
if(!$delete){
  $tbl_name = $wpdb->prefix . "ar_gwa_lists";
  $lname = $wpdb->escape($_REQUEST['ar_gwa_wname']);
  $lemail = $wpdb->escape($_REQUEST['ar_gwa_wfrom']);
	$list_count = $wpdb->get_var("SELECT COUNT(xID) FROM ".	$tbl_name);
	if($this->list_id>0) {
  $wpdb->query("UPDATE ".$tbl_name." SET xEmail='$lemail',xName='$lname',xLabel='$lname' WHERE xID='".$this->list_id."'");
  } else {
  $wpdb->query("INSERT INTO ".$tbl_name." (xID,xEmail,xName,xLabel,xPage,xReturn) VALUES('','$lemail','$lname','$lname','0','0')");
   $lst_num = $wpdb->insert_id;
}
   if ($lst_num>0) {
   $this->list_id = $lst_num;
if($_REQUEST['ar_gwa_captcha']!='') {
   $onsubmit = ' onsubmit="return jcap();"';
   $jscap='<script type="text/javascript">sjcap();</script>';
   update_option('ar_gwa_captcha_'.$lst_num,'checked');
}
   $onclick = 'onclick="return gwaCheckForm'.$lst_num.'(this.form)"';
$subscribe = '<!-- [GWA] AutoResponder Begin --><form name="ARGWA" action="'.get_bloginfo('url').'/index.php" method="post"'.$onsubmit.'><table style="border-collapse: collapse; padding: 10px;" border="0" cellspacing="0" cellpadding="0" bordercolor="#111111"><tbody><tr> <td><div><strong>Name:</strong> <input id="argwa_name" name="name" size="20" type="text" /><br /> <strong>Email:</strong> <input id="argwa_email" name="email" size="20" type="text" />'.$jscap.'<br /><input class="button" '.$onclick.' name="Add" type="submit" value="SUBSCRIBE" /></div></td></tr></tbody></table> <input name="act" type="hidden" value="s_add" /> <input name="listid" type="hidden" value="'.$lst_num.'" /></form><!-- [GWA] AutoResponder End -->';
$wpdb->query( "UPDATE `".$tbl_name."` set `xSubscribe`='".mysql_real_escape_string($subscribe)."' WHERE xID='".$lst_num."'" );
$wpdb->query("UPDATE `".$tbl_name."` set `xPopin`=`xSubscribe`, `xSlide`=`xSubscribe` WHERE xID='".$lst_num."'");
    update_option('ar_gwa_widget_num',$list_count+1);
    update_option('ar_gwa_sldht_'.$this->list_id,'100');
    update_option('ar_gwa_wheight_'.$this->list_id,'300');
    update_option('ar_gwa_wwidth_'.$this->list_id,'220');
  }

if($_REQUEST['arThrottle'] != "" && preg_match("/^\d+$/",$_REQUEST['arThrottle']) && $_REQUEST['arThrottle']>0 && $_REQUEST['arThrottle']<301)
$throttle = $_REQUEST['arThrottle'];
else
$throttle = get_option('ar_gwa_throttle');

if($_REQUEST['arMpr'] != "" && preg_match("/^\d+$/",$_REQUEST['arMpr']) 
  && $_REQUEST['arMpr']>0 && $_REQUEST['arMpr']<101)
$mpr = $_REQUEST['arMpr'];
else
$mpr = get_option('ar_gwa_mpr');

if($_REQUEST['arRun'] != "" && preg_match("/^\d+$/",$_REQUEST['arRun']) 
  && $_REQUEST['arRun']>0 && $_REQUEST['arRun']<61)
$run = $_REQUEST['arRun'];
else
$run = get_option('ar_gwa_run');
update_option('ar_gwa_throttle',$throttle,'');
update_option('ar_gwa_mpr',$mpr,'');
update_option('ar_gwa_run',$run,'');
return __("Step",'argwa')." ".$this->step." ".__("completed successfully.",'argwa');
}
return $return;
    } else if($step==2) {
    if($delete) {
      $this->delList($delete);
      $this->step=0;$this->list_id=0;
      return "List ID: ".$delete." removed successfully. Start again.";
    } else {
    $xReturn1 = $pcommon1 = $_REQUEST['xReturn1'];
    $xReturn2 = $pcommon2 = $_REQUEST['xReturn2'];
    $xReturn3 = $pcommon3 = $_REQUEST['xReturn3'];
    $url1 = $wpdb->escape($_REQUEST['ar_gwa_url1']);
    $url2 = $wpdb->escape($_REQUEST['ar_gwa_url2']);
    $url3 = $wpdb->escape($_REQUEST['ar_gwa_url3']);
    
    if($url1!='' && $xReturn1=='') $pcommon1 = $url1;
    $wpdb->query("UPDATE ".$wpdb->prefix."ar_gwa_lists SET xReturn='$pcommon1' WHERE xID='".$this->list_id."'");
    if($url2!='' && $xReturn2=='') $pcommon2 = $url2;
    update_option('ar_gwa_confirm_'.$this->list_id,$pcommon2);

    if($url3!='' && $xReturn3=='') $pcommon3 = $url3;
    update_option('ar_gwa_unsub_'.$this->list_id,$pcommon3);
    }
    return "Step ".$this->step." completed successfully.";
   } else if($step==3) {
    if($delete) {
      $this->delList($delete);
      $this->step=0;$this->list_id=0;
      return "List ID: ".$delete." removed successfully. Start again.";
    } else {
    $wpdb->query("UPDATE ".$wpdb->prefix."ar_gwa_lists SET xSubscribe='".mysql_real_escape_string($_REQUEST['subscribe'])."' WHERE xID='".$this->list_id."'");    
    return __("Subscription form display updated for List ID:",'argwa')."&nbsp;".$this->list_id;
    }   
   } else if($step==4) {
    if($delete) {
      $this->delList($delete);
      $this->step=0;$this->list_id=0;
      return __('List ID:','argwa').' '.$delete." ".__('removed successfully. Start again.','argwa');
    } else {
    $interval = $wpdb->escape($_REQUEST['ar_gwa_interval']);
    if(!$interval) $interval=0;
    if($interval<366 && strlen($_REQUEST['ar_gwa_subject'])>3){
    $ex = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->prefix."ar_gwa_msg WHERE mLID='".$this->list_id."' AND mDay='$interval'");
		if((int)$ex==0) {
    $qry = "INSERT INTO ".$wpdb->prefix."ar_gwa_msg(mSubject, mBody, mDay, mType, mLID) VALUES('".$wpdb->escape($_REQUEST['ar_gwa_subject'])."','".$wpdb->escape($_REQUEST['ar_gwa_message'])."','".$interval."','".$_REQUEST['mType']."','".$this->list_id."')";
    $wpdb->query($qry);
      if(isset($_REQUEST['ar_gwa_wadd'])) 
      $this->step = $step-1;
      return __('Day:','argwa').' '.$interval.' '.__('message successfully added for List ID:','argwa')." ".$this->list_id;
      } else {
      if(isset($_REQUEST['ar_gwa_wadd']))
      $this->step = $step-1;
      return __('Sorry the Day','argwa').' '.$interval.__('already has a message scheduled? Please try again.','argwa');
      }
    } else {
    if(isset($_REQUEST['ar_gwa_wadd'])) {
    $this->step = $step-1;
    return __('Sorry there was a problem inserting that message. Please try again.','argwa');
    } else {
    return __('No message was inserted.','argwa');    
    }
    }
    }   
    } else if($step==5) {
    if($_REQUEST['sendTest']!='') {
      $rec = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."ar_gwa_msg WHERE mLID='".$this->list_id."' ORDER BY mDay ASC",ARRAY_A);      
$ms = new MailProcess(); 
		 if($rec){
     foreach($rec as $row) 
		 {
		$aMsg		= array('mType' => $wpdb->escape($row['mType']), 'mSubject' =>$wpdb->escape($row['mSubject']), 'mBody' => $wpdb->escape($row['mBody']));
			if($ms->setLead2($row['mLID']) && $ms->setMsg2($aMsg))
			{
				$ms->mailLead(NULL,NULL,1);
				++$lEmailed;
      }			
		 }
    } 
     return __('Number of messages processed and sent:','argwa').' '.$lEmailed;     
    }
   }
}   
   function delList($delid) {
		global $wpdb;
    $wpdb->query("DELETE FROM " . $wpdb->prefix.'ar_gwa_lists'. " WHERE xID='$delid'");
		$wpdb->query("DELETE FROM " . $wpdb->prefix.'ar_gwa_msg'. " WHERE mLID='$delid'");
		delete_option('ar_gwa_unsub_'.$delid);
		delete_option('ar_gwa_confirm_'.$delid);
   }
   
   function ar_gwa_buildlistselect($listid=NULL) {
 global $wpdb;
# $wpdb->show_errors();
 $option = '<select name="ar_gwa_list"  onChange="this.form.submit()" style="border: solid 1px #000;">';
 $qry = "SELECT * FROM ".$wpdb->prefix."ar_gwa_lists WHERE 1";
 $res = $wpdb->get_results($qry);
   $option .= '<option value="0">'.__('NEW','argwa').'</option>';
 if (count($res)>0) {
  foreach($res as $r) {
  $option .= '<option value="'.$r->xID.'" ';
  if($listid && ($listid == $r->xID || $_REQUEST['listid'] == $r->xID)) $option .= 'selected';
  $option .= '>'.$r->xName.'</option>';
  }
 } else {
  $option .= '<option value="'.$res[0]->xI.'">'.$res[0]->xName.'</option>';
 }
if($_REQUEST['listid']=='-1') $optionn = ' selected';
if($_REQUEST['page'] == 'ar_gwa_leads' && ((!$_REQUEST['admin_ar_gwa_export_leads'] | $_REQUEST['admin_ar_gwa_export_leads']=='') && (!$_REQUEST['admin_ar_gwa_add_leads'] | $_REQUEST['admin_ar_gwa_add_leads']=='')))
return $option.'<option value="-1" style="color:#f00"'.$optionn.'>Unconfirmed</option></select>';
else
return $option.'</select>';
}
   function WizStep($step=0) {
   global $phpmailerDir,$wpdb;
   $lstname = $wpdb->get_var("SELECT xName FROM ".$wpdb->prefix."ar_gwa_lists WHERE xID='".$this->list_id."'");
   if($step==0){

$listSelect = $this->ar_gwa_buildlistselect($this->list_id);
if($this->list_id) {
$res = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."ar_gwa_lists WHERE xID='".$this->list_id."'",ARRAY_A);
}
if($res[0]['xName']!='') $xName = $res[0]['xName'];
else $xName=mysql_real_escape_string(get_bloginfo('name')).' '.__('Newsletter','argwa');
if($res[0]['xEmail']!='') $xEmail = $res[0]['xEmail'];
else $xEmail=mysql_real_escape_string(get_bloginfo('admin_email'));
$this->Step[$step] = '  <div class="arHelp" style="float:left;width:200px;border: solid 1px #ccc;padding:6px; background-color:#e4f2fd;"><p>'.__('The <b>From:</b> address will be used for all email messages generated. Make sure it is an active local account on your host for best results.</p><p>Throttle settings will directly affect the amount of email generated per hour and therefore allow you to limit the amount sent per day according to your requirements.</p><p>For Example:<br />If you can send 1000 emails per day and you want to run your Queue every 15 minutes calculate(&nbsp;(&nbsp;1000&nbsp;/&nbsp;24&nbsp;)&nbsp;/&nbsp;4)&nbsp;=&nbsp;10 messages per queue run with a 15 minute pause.</p><p><b>IMPORTANT:</b> Know your MAIL LIMIT before changing these settings. The default values are appropriate for a shared host.','argwa').'</p>';
if($_REQUEST['ar_gwa_list']==0)
$this->Step[$step] .= '<p>'.__('See <a href="?page=ar_gwa_help" target="_blank" title="Opens HELP Page in new Window">HELP Page</a> for more detailed info on using CAPTCHA Human verification in your subscription forms.','argwa').'</p>';
$this->Step[$step] .= '</div><div style="float:left;margin-left:15px;width:200px;"><form name="mForm" id="wizForm" method="post" action="?page=ar_gwa_wizard"><h3 style="display:inline;">'.__("Wizard Step",'argwa').': '.($step+1).'</h3>&nbsp;'.$listSelect.'<br />'.__('Select an existing list above to edit it using the wizard or create a <b>NEW</b> Newsletter Campaign by completing the form below','argwa').':<br>
<div style="border: solid 1px #ccc;padding:6px; background-color:#e4f2fd;width:450px;">'.__('Enter a unique name for your new Newsletter','argwa').':<br><input type="text" name="ar_gwa_wname" size="51" value="'.$xName.'" style="border:solid 1px #666;"><br>
'.__('Enter the <b>From:</b> address to be used when sending this Newsletter','argwa').':<br><input style="border:solid 1px #666;" type="text" name="ar_gwa_wfrom" size="51" value="'.$xEmail.'"></div><p style="width:450px">'.__('<b>The following are <u>global options</u> affecting plugin operation.</b><br />Always know your mailing limits before changing these settings.','argwa').'</p><p style="width:450px">'.__('These settings control your Queue speed and functioning.','argwa').'</p><div style="border: solid 1px #ccc;padding:6px; background-color:#e4f2fd;width:450px;">
<p align="left"><strong>'.__("Intelligent-Queue Throttle Settings",'argwa').'</strong></p><table border=0><tr><td>'.__("Max script run-time in seconds.",'argwa').' (1-300):</td><td><input style="border:solid 1px #666;" type="text" size=2 name="arThrottle" value="'.stripslashes(get_option('ar_gwa_throttle')).'"></td></tr>
<tr><td>'.__("Messages sent per queue run.",'argwa').' (1-100):</td><td><input style="border:solid 1px #666;" type="text" size=2 name="arMpr" value="'.stripslashes(get_option('ar_gwa_mpr')).'"></td></tr>
<tr><td>'.__("Pause between queue runs.",'argwa').' (1-60):</td><td><input style="border:solid 1px #666;" type="text" size=2 name="arRun" value="'.stripslashes(get_option('ar_gwa_run')).'">&nbsp;'.__("Minutes",'argwa').'</td></tr></table>
</div>';
if($_REQUEST['ar_gwa_list']==0)
$this->Step[$step] .= '<br /><input type="checkbox" name="ar_gwa_captcha" value="1">&nbsp;'.__('Use CAPTCHA IMAGE TEST for this Subscription Form.','argwa').'<br />';
$this->Step[$step] .= '<p><input type="submit" value="'.__('Next Step','argwa').'" name="submit2"><input type="reset" value="'.__('Clear Form','argwa').'" name="B2"></p><input type="hidden" name="ar_gwa_wstep" value="'.($step+1).'"></form></div>';     
  } else if($step==1) {
  $xReturn=$wpdb->get_var("SELECT xReturn FROM ".$wpdb->prefix."ar_gwa_lists WHERE xID='".$this->list_id."'");
#  echo $xReturn;exit;
  $xConfirm = get_option('ar_gwa_confirm_'.$this->list_id);
  $xUnsub = get_option('ar_gwa_unsub_'.$this->list_id);
  
  if(preg_match("/^http:\/\//",$xReturn)) $xReturnUrl = $xReturn;
  if(preg_match("/^http:\/\//",$xConfirm)) $xConfirmUrl = $xConfirm;
  if(preg_match("/^http:\/\//",$xUnsub)) $xUnsubUrl = $xUnsub;
$extern = __("Use External URL",'argwa');
$this->Step[$step] = '
<script>
<!--
function Validate(urlid) {
    var v = new RegExp();
    v.compile("^http://[A-Za-z0-9-_]+\.[A-Za-z]\\.[A-Za-z0-9-_%&\?\/.=]+$");
    if (!v.test(document.getElementById(urlid).value)) {
        return false;
    }
}
function checkForm ()
{
  rex1 = document.getElementById(\'xReturn1\').value;
  rex2 = document.getElementById(\'xReturn2\').value;
  rex3 = document.getElementById(\'xReturn3\').value;
  urex1 = document.getElementById(\'ar_gwa_url1\').value;
  urex2 = document.getElementById(\'ar_gwa_url2\').value;
  urex3 = document.getElementById(\'ar_gwa_url3\').value;
 if(document.getElementById("del").value==0){
  if(rex1==""&&(urex1==""||urex1=="http://")) {
  	alert('.__("Sorry, you must select a page or enter a URL for Subscribe!",'argwa').');  
  	return false;
  } else if(rex1=="" && Validate("ar_gwa_url1")==false) {
  	alert('.__("Sorry, you must enter a complete URL for Subscribe!",'argwa').');  
  	return false;
  } else if(rex2==""&&(urex2==""||urex2=="http://")) {
  	alert('.__("Sorry, you must select a page or enter a URL for Confirm!",'argwa').');  
  	return false;
  } else if(rex2=="" && Validate("ar_gwa_url2")==false) {
  	alert('.__("Sorry, you must enter a complete URL for Confirm!",'argwa').');  
  	return false;
  } else if(rex3==""&&(urex3==""||urex3=="http://")) {
  	alert('.__("Sorry, you must select a page or enter a URL for Unsubscribe!",'argwa').');  
  	return false;
  } else if(rex3=="" && Validate("ar_gwa_url3")==false) {
  	alert('.__("Sorry, you must enter a complete URL for Unsubscribe!",'argwa').');  
  	return false;  
  } else
    	return true;
 }
}
-->
</script>
<div class="arHelp" style="float:left;width:200px;border: solid 1px #ccc;padding:6px; background-color:#e4f2fd;">'.__('<p>These settings control where a subscriber is sent after interacting with your mailer plugin. You may select one of your blog pages or enter an external URL to any other web page.</p><p>To get confirmation displayed to the subscriber there are a few options. Use the &lt;?php ... ?&gt; tags in your template files or the shortcode option. Check the HELP Page for details.</p><p>If you insert the WordPress Shortcode','argwa').' <b>[gwa-autoresponder listid="<font color="red">'.$this->list_id.'</font>"]</b> '.__('in the page selected your subscribers will receive a confirmation message displayed on that page and after each step.</p><p>Always test your Newsletter operation after making changes to your list or weblog settings. Also it is recommended to do so after modifying your theme package or installing/removing other plugins.','argwa').'</p></div><div style="float:left;width:200px;margin-left:15px"><h3>'.__('Wizard Step','argwa').': '.($step+1).' '.__('for','argwa').' <font color="blue">'.$lstname.'</font></h3><form name="mForm" method="post" action="?page=ar_gwa_wizard" onsubmit="return checkForm();">'.__('Make your Forward Page Selections below','argwa').':<br><br><div style="border: solid 1px #ccc;padding:6px; background-color:#e4f2fd;width:450px;">'.__('AFTER SUBSCRIBING','argwa').':&nbsp;'.wp_dropdown_pages(array('depth' => 0, 'child_of' => 0, 'selected' => $xReturn, 'echo' => 0,'name' => 'xReturn1', 'show_option_none' => $extern)).'<br>
  '.__('Select blog page above or set an External URL','argwa').': (http://...) <br>
  <input style="border:solid 1px #666;"  type="text" name="ar_gwa_url1" id="ar_gwa_url1" size="51" value="'.$xReturnUrl.'"></div><p>&nbsp;</p><div style="border: solid 1px #ccc;padding:6px; background-color:#e4f2fd;width:450px;">'.__('AFTER CLICK CONFIRM LINK','argwa').':&nbsp;'.wp_dropdown_pages(array('depth' => 0, 'child_of' => 0, 'selected' => $xConfirm, 'echo' => 0,'name' => 'xReturn2', 'show_option_none' => $extern)).'<br>
  '.__('Select blog page above or set an External URL','argwa').': (http://...) <br>
  <input style="border:solid 1px #666;"  type="text" name="ar_gwa_url2" id="ar_gwa_url2" size="51" value="'.$xConfirmUrl.'"></div><p>&nbsp;</p>  <div style="border: solid 1px #ccc;padding:6px; background-color:#e4f2fd;width:450px;">'.__('AFTER UNSUBSCRIBING','argwa').':&nbsp;'.wp_dropdown_pages(array('depth' => 0, 'child_of' => 0, 'selected' => $xUnsub, 'echo' => 0,'name' => 'xReturn3', 'show_option_none' => $extern)).'<br>'.__('Select blog page above or set an External URL','argwa').': (http://...)<br><input style="border:solid 1px #666;"  type="text" name="ar_gwa_url3" id="ar_gwa_url3" size="51" value="'.$xUnsubUrl.'"><p><input type="submit" value="'.__('Next Step','argwa').'" name="submit2"><input type="reset" value="'.__('Clear Form','argwa').'" name="B2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="ar_gwa_del" id="ar_gwa_del" value="'.__('CANCEL & DELETE','argwa').'"  onclick="document.getElementById(\'del\').value=1;return confirm(\'Are you sure? Everything will be lost and you must start again!\')">&nbsp;&nbsp;<input type="submit" name="ar_gwa_dl" id="" value="'.__('CANCEL','argwa').'"  onclick="return confirm(\''.__('Abandon wizard? Nothing will be deleted!','argwa').'\')"></p><input type="hidden" name="ar_gwa_list" value="'.$this->list_id.'"><input type="hidden" name="ar_gwa_wstep" value="'.($step+1).'"><input type="hidden" id="del" name="del" value="0"></form></div>';          
  } else if($step==2) {
  $subscribe = $wpdb->get_var("SELECT xSubscribe FROM ".$wpdb->prefix."ar_gwa_lists WHERE xID='".$this->list_id."'");
$this->Step[$step] = '<h3>Wizard Step: '.($step+1).' for <font color="blue">'.$lstname.'</font></h3><form name="mForm" method="post" action="?page=ar_gwa_wizard">'.__('Customize your subscription form / Get the <b>Portable Raw HTML Code</b> with VIEW SOURCE [HTML] in editor window.','argwa').'<br /><br />';
if(!file_exists(ABSPATH.'wp-content/plugins/autoresponder-gwa/gwa-xinha.txt')) {
$this->Step[$step] .= '
<script type="text/javascript">
<!--
function toggleEditor(id) {
	if (!tinyMCE.getInstanceById(id))
		tinyMCE.execCommand(\'mceAddControl\', false, id);
	else
		tinyMCE.execCommand(\'mceRemoveControl\', false, id);
}
-->
</script>';
$this->Step[$step] .= '<select name="mType" style="width:100px;" onchange="toggleEditor(\'editorContent\')" /><option value="html" selected>HTML';
$this->Step[$step] .= '		<option value="text">'.__("PLAIN TEXT",'argwa').'</select>';
}
$this->Step[$step] .= '<div style="float:left;width:200px;border: solid 1px #ccc;padding:6px; background-color:#e4f2fd;" class="arHelp">
		'.__('<p>This is the subscription form currently set to be displayed in the widget as well as inserted by the WP Shortcode in your pages and posts. You may use the TinyMCE WYSIWYG Editor to customize the display with additional options.</p><p>If this is your first installation and newsletter setup you may wish to proceed to the next page, finish your setup and test your new list before modifying the form contents. You can always update the form display anytime after your Newsletter has been created and tested. See all the display options available to you on the HELP page.</p><p>If you setup CAPTCHA in Step 1 it will be displayed publicly once you publish your subscription form. <b>Please note: The CAPTCHA items are NOT visible in the TinyMCE Editor window above.</b></p>','argwa').'</div><textarea rows="15" name="subscribe" id="editorContent" class="editorContent" cols="27">'.htmlentities(stripslashes($subscribe)).'</textarea><p>&nbsp;</p><p><input type="submit" value="'.__('Next Step','argwa').'" name="submit2"><input type="reset" value="'.__('Clear Form','argwa').'" name="B2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="ar_gwa_del" id="ar_gwa_del" value="'.__('CANCEL & DELETE','argwa').'"   onclick="return confirm(\''.__('Are you sure? Everything will be lost and you must start again!\'','argwa').')">&nbsp;&nbsp;<input type="submit" name="ar_gwa_dl" id="" value="'.__('CANCEL','argwa').'"  onclick="return confirm(\''.__('Abandon wizard? Nothing will be deleted!','argwa').'\')"></p><input type="hidden" name="ar_gwa_list" value="'.$this->list_id.'"><input type="hidden" name="ar_gwa_wstep" value="'.($step+1).'"></form>';               
  } else if($step==3) {
  $msg = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."ar_gwa_msg WHERE mLID='".$this->list_id."'",ARRAY_A);
  if($msg) {
  foreach($msg as $m) {
  $options .= 'Day# <b>'.$m['mDay'].'</b> Subject: <a href="?page=ar_gwa_edit_message&mDay='.$m['mDay'].'&mID='.$m['mID'].'&listid='.$this->list_id.'" target="_blank" title="Open Edit Message page in New Window.">'.$m['mSubject'].'</a><br />';
  $mm++;
  }
  }
  $option=__("You have existing messages that can be edited or deleted from the",'argwa')." <a href='?page=ar_gwa_edit_message' target='_blank' title='".__('Open page in New Window.','argwa')."'>".__('Messages page','argwa')."</a> ".__('in the [GWA] Autoresponder Menu','argwa').".<br /><br />";
  if($mm>0) $messages = $option.$options;
$this->Step[$step] = '<h3>'.__('Wizard Step','argwa').': '.($step+1).' '.__('for','argwa').' <font color="blue">'.$lstname.'</font></h3><form name="mForm" method="post" action="?page=ar_gwa_wizard">'.$messages.'<br />'.__('Add your Messages below. Continue adding messages until you are done. Select the message format, enter the interval before it is to be sent, and enter your message content. To Copy&Paste Raw HTML click the TinyMCE Editor [HTML] button to open the Source Code HTML Window and paste your raw code there. DO NOT PASTE HTML INTO PLAIN-TEXT WINDOW or it will not display properly to the subcriber.','argwa').'<br /><br /><div style="border: solid 1px #ccc;padding:6px; background-color:#e4f2fd;">';
if(!file_exists(ABSPATH.'wp-content/plugins/autoresponder-gwa/gwa-xinha.txt')) {
$this->Step[$step] .= '
<!-- TinyMCE -->
<script type="text/javascript">
<!--
function toggleEditor(id) {
	if (!tinyMCE.getInstanceById(id))
		tinyMCE.execCommand(\'mceAddControl\', false, id);
	else
		tinyMCE.execCommand(\'mceRemoveControl\', false, id);
}
-->
</script>
<!-- /TinyMCE -->
'.__('Choose message format','argwa').':&nbsp;<select name="mType" style="width:100px;" onchange="toggleEditor(\'editorContent\')" />
		<option value="html" selected>HTML
		<option value="text">'.__("PLAIN TEXT",'argwa').'</select><br>';
		}
$this->Step[$step] .= __('Send Interval / Number of days after subscribing','argwa').': <input style="border:solid 1px #666;"  type="text" name="ar_gwa_interval" value="" size="2">&nbsp;Day 0 = '.__('Instant Response','argwa').'<br>
'.__('Subject','argwa').': <input style="border:solid 1px #666;"  type="text" name="ar_gwa_subject" value="" size="60"><br />
		<br><b>&lt;?Name?&gt; : '.__("Subscriber's name.",'argwa').'<br>
&lt;?Email?&gt; : '.__("Subscriber's email address.",'argwa').'<br /><br />
<textarea rows="15" name="ar_gwa_message" id="editorContent" class="editorContent" cols="42"></textarea></div><p>&nbsp;</p><p><input type="submit" value="'.__('Add Another Message','argwa').'" name="ar_gwa_wadd">&nbsp;&nbsp;<input type="submit" value="'.__('Continue','argwa').'" name="submit2">&nbsp;&nbsp;<input type="reset" value="'.__('Clear Form','argwa').'" name="B2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="ar_gwa_del" id="ar_gwa_del" value="'.__('CANCEL & DELETE','argwa').'" onclick="return confirm(\''.__('Are you sure? Everything will be lost and you must start again!','argwa').'\')">&nbsp;&nbsp;<input type="submit" name="ar_gwa_dl" id="" value="'.__('CANCEL','argwa').'"  onclick="return confirm(\''.__('Abandon wizard? Nothing will be deleted!','argwa').'\')"></p>
<input type="hidden" name="ar_gwa_list" value="'.$this->list_id.'"><input type="hidden" name="ar_gwa_wstep" value="'.($step+1).'"></form>';               
  } else if($step==4) {

$this->Step[$step] = '<h3>'.__('Wizard Step','argwa').': '.($step+1).' '.__('for','argwa').' <font color="blue">'.$lstname.'</font></h3><form name="mForm" method="post" action="?page=ar_gwa_wizard">'.__('Congratulations your newsletter is setup. There are  more options available  and accessible from the List page using the','argwa').' <a href="?page=ar_gwa_lists&lLID='.$this->list_id.'&update=1" title="'.__('Go to it now!','argwa').'">'.__('Update Details','argwa').'</a> '.__('link displayed for each record. You can edit messages by clicking the subject on the','argwa').' <a href="?page=ar_gwa_edit_message">'.__('Messages page','argwa').'.</a><br />
  <br>
  '.__('Try out your new campaign now. Have all the messages sent immediately to your WP-Admin email address','argwa').': '.get_bloginfo('admin_email').'.<br>
  <br /><input type="submit" value="'.__('Send Entire Autoresponder Campaign Now','argwa').'" name="sendTest"></p><input type="hidden" name="ar_gwa_wstep" value="'.($step+1).'"><input type="hidden" name="ar_gwa_list" value="'.$this->list_id.'"></form><br />'.__('Use the <a href="widgets.php">autoresponder widget</a> to easily add a subscription form to your sidebar and test the double opt-in list form. There are other display options. Check the <a href="?page=ar_gwa_help">Help Page</a> for more instructions.','argwa'); 
  } else if($step==5) {
$this->Step[$step] = '<h3>'.__('Wizard Step','argwa').': '.($step+1).' '.__('for','argwa').' <font color="blue">'.$lstname.'</font></h3><form name="mForm" method="post" action="?page=ar_gwa_wizard"><p><a href="?page=ar_gwa_edit_message">'.__('You can see your messages are waiting in the Queue now.','argwa').'</a></p><input type="hidden" name="ar_gwa_wstep" value="'.($step+1).'"><input type="hidden" name="ar_gwa_list" value="'.$this->list_id.'"></form>';  
 }
}

 function helpText() {
 $return[]= __('Newsletter Setup Wizard','argwa');
 $return[]= __('Follow the steps to <a href="?page=ar_gwa_wizard">create a new newsletter.</a> Can also be used to edit existing lists, add messages, and more.','argwa');
 return $return;
 }
}