<?php

/**
 *
 * @copyright  2017 izend.org
 * @version    1
 * @link       http://www.izend.org
 */
?>
<?php if ($sms_modified): ?>
<?php require_once 'dateen.php'; ?>
<p class="info" title="Last modification"><?php echo longdate_en($sms_modified); ?> at <?php echo date('H:i', $sms_modified); ?></p>
<?php endif; ?>
<p class="info">Press the assistance button <span class="btn_edit btn_help" title="Help">help</span> to toggle the display of help messages.</p>
<p class="help helptoggle">Slide the handle <span class="btn_edit btn_grippie">===</span> to extend a text area.</p>
<?php extract($errors); ?>
<form class="compact" action="" method="post">
<input name="clang" type="hidden" value="<?php echo $clang; ?>" />
<?php if ($sms_modified): ?>
<input name="sms_modified" type="hidden" value="<?php echo $sms_modified; ?>" />
<?php endif; ?>
<p>
<?php echo $inlanguages; ?>
<span id="node_hidy" class="hidy">+</span>
</p>
<div id="node">
<p class="inlabel<?php if ($missing_title or $bad_title): ?> inerror<?php endif; ?>">Title:</p>
<p><input id="sms_title" name="sms_title" type="text" size="40" maxlength="100" value="<?php echo htmlspecialchars($sms_title, ENT_COMPAT, 'UTF-8'); ?>" title="Campaign title" onkeypress="return focusonenter(event, 'sms_cloud')"/></p>
<p class="inlabel">Cloud:</p>
<p>
<textarea id="sms_cloud" name="sms_cloud" cols="80" rows="2" title="Series of keywords for the search engine"><?php echo htmlspecialchars($sms_cloud, ENT_COMPAT, 'UTF-8'); ?></textarea>
<br/><span class="grippie btn_edit btn_grippie">===</span>
</p>
<p class="help helptoggle">
Associate keywords to this campaign.
</p>
<p class="inlabel<?php if ($missing_subject): ?> inerror<?php endif; ?>">Subject:</p>
<p>
<textarea id="sms_subject" name="sms_subject" cols="80" rows="2" title="Just a paragraph"><?php echo htmlspecialchars($sms_subject, ENT_COMPAT, 'UTF-8'); ?></textarea>
<br/><span class="grippie btn_edit btn_grippie">===</span>
</p>
<p class="help helptoggle">
Describe the subject of the campaign.
</p>
</div>
<p class="inlabel<?php if ($missing_text): ?> inerror<?php endif; ?>">Message:</p>
<textarea id="sms_text" name="sms_text" cols="80" rows="5" title="SMS" placeholder="" onkeyup="return filtersms()"><?php echo htmlspecialchars($sms_text, ENT_COMPAT, 'UTF-8'); ?></textarea>
<br/><span class="grippie btn_edit btn_grippie">===</span>
<p id="sms_params">
<span id="sms_msglen"><?php echo $sms_msglen; ?></span>
/
<span id="sms_len"><?php echo $sms_len; ?></span>
&nbsp;-&nbsp;
<span id="sms_count"><?php echo $sms_count; ?></span>
SMS
<span id="sms_coding"><?php echo $sms_coding; ?></span>
</p>
<script type="text/javascript">
//<![CDATA[
function filtersms() {
	var charset7bit = "@£\$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑÜ§¿abcdefghijklmnopqrstuvwxyzäöñüà";
	var charset7bitext = "\f^{}\\[~]|€";

	input = document.getElementById('sms_text');
	if (input == null)
		return;

	s = input.value.trim();

	s = s.replace(/[ \t]+/gm, ' ').replace(/^ /gm, '').replace(/ *\n+/gm, "\r\n");

	msglen = s.length;

	if (s.match(new RegExp('[^' + preg_quote(charset7bit + charset7bitext, '/') + ']'))) {
		coding='16bit';
		maxlen=70;
		extlen=67;
	}
	else {
		coding='7bit';
		maxlen=160;
		extlen=153;

		if (r = s.match(new RegExp('[' + preg_quote(charset7bitext, '/') + ']', 'g'))) {
			msglen += r.length;
		}
	}

	if (msglen > maxlen) {
		count = 1 + Math.floor(msglen / extlen);
		len = count * extlen;
	}
	else {
		count = 1;
		len = maxlen;
	}

	document.getElementById('sms_msglen').innerHTML=msglen;
	document.getElementById('sms_len').innerHTML=len;
	document.getElementById('sms_count').innerHTML=count;
	document.getElementById('sms_coding').innerHTML=coding;
}

function preg_quote (s, delim) {
	return s.replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + delim + '-]', 'g'), '\\$&');
}
//]]>
</script>
<p class="help helptoggle">
</p>
<p><input type="submit" class="submit submit_configure<?php if ($missing_title or $bad_title): ?> inerror<?php endif; ?>" name="sms_configure" id="sms_configure" value="Configure" title="Configure the campaign" /></p>
</form>
<?php if (!$missing_title): ?>
<?php head('javascript', 'jquery.cookie'); ?>
<script type="text/javascript">
if ($.cookie('hidenode') == 1) {
	$('#node').hide();
}
$('#node_hidy').click(function() {
	$('#node').toggle();
	$.cookie('hidenode', $('#node').is(':hidden') ? 1 : 0, { path: '/' });
});
</script>
<?php endif; ?>
<?php
$focus=false;
if ($missing_title or $bad_title) {
	$focus='#sms_title';
}
else if ($missing_text) {
	$focus='#sms_text';
}
?>
<?php if ($focus): ?>
<script type="text/javascript">
$(document).ready(function() {
	$('<?php echo $focus; ?>').focus();
});
</script>
<?php endif; ?>
<?php head('javascript', 'jquery.cookie'); ?>
<script type="text/javascript">
function togglehelp() {
	$('.helptoggle').each(function() {
		$(this).toggle();
	});
	$.cookie('nommshelp', $.cookie('nommshelp') == 1 ? '0' : '1');
}

if ($.cookie('nommshelp') == 1) {
	$('.helptoggle').each(function() {
		$(this).hide();
	});
}

$('.btn_help').each(function() {
	$(this).click(function() {togglehelp();});
});
</script>
<script type="text/javascript">
$(document).ready(function() {
	$('.grippie').each(function() {
		var grippie = $(this);
		var textarea = grippie.prev().prev();
		var offset;

		grippie.mousedown(startDrag);

	    function startDrag(e) {
	      offset = textarea.height() - e.pageY;
	      textarea.css('opacity', 0.25);
	      $(document).mousemove(performDrag).mouseup(endDrag);
	      return false;
	    }

	    function performDrag(e) {
	      textarea.height(Math.max(32, offset + e.pageY) + 'px');
	      return false;
	    }

	    function endDrag(e) {
	      $(document).unbind('mousemove', performDrag).unbind('mouseup', endDrag);
	      textarea.css('opacity', 1);
	    }
	});
});
</script>
