<?php
if (isset($tpl['status']))
{
	$status = __('status', true);
	switch ($tpl['status'])
	{
		case 2:
			pjUtil::printNotice(NULL, $status[2]);
			break;
	}
} else {
	?>
	<?php 
	include_once PJ_VIEWS_PATH . 'pjLayouts/elements/optmenu.php';
	pjUtil::printNotice(__('infoAddNotificationTitle', true, false), __('infoAddNotificationDesc', true, false));  
	?>
	<form action="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminNotifications&amp;action=pjActionCreate" method="post" id="frmCreateNotification" class="pj-form form">
		<input type="hidden" name="notification_create" value="1" />
		<input type="hidden" name="csrf_token" value="<?php echo pjAppController::getCsrfToken(); ?>" />
		<?php if ((int) $tpl['option_arr']['o_multi_lang'] === 1 && count($tpl['lp_arr']) > 1) : ?>
		<div class="multilang b10"></div>
		<?php endif;?>
		<div class="clear_both">
			<p>
				<label class="title"><?php __('lblType'); ?></label>
				<span class="inline_block">
					<select name="type" id="type" class="pj-form-field required w200">
						<option value="">-- <?php __('lblChoose'); ?>--</option>
						<?php
						$notification_types = __('notification_types', true);
						?>
						<option value="NewClient"><?php echo $notification_types['NewClient']?></option>
						<option value="NewTicket"><?php echo $notification_types['NewTicket']?></option>
						<option value="NewClientReply"><?php echo $notification_types['NewClientReply']?></option>
						<option value="NewSupportReply"><?php echo $notification_types['NewSupportReply']?></option>
						<option value="AccountActivation"><?php echo $notification_types['AccountActivation']?></option>
					</select>
					<a href="#" class="pj-form-langbar-tip tss-tip" title="<?php __('lblNotifyTypeTip');?>"></a>
				</span>
			</p>
			<p class="boxRecipient">
				<label class="title"><?php __('lblRecipientDepartments'); ?></label>
				<span class="inline_block" id="boxDepartment">
					<?php
					if(count($tpl['department_arr']) > 0)
					{ 
						?>
						<select data-placeholder="--<?php __('lblChoose'); ?>--" name="department_id[]" id="department_id" multiple="multiple" class="pj-form-field w300">
							<?php
							foreach ($tpl['department_arr'] as $v)
							{
								
								?><option value="<?php echo $v['id']; ?>"><?php echo stripslashes($v['name']); ?></option><?php
								
							}
							?>
						</select>
						<a href="#" class="pj-form-langbar-tip tss-tip" title="<?php __('lblNotifyDepartmentTip');?>"></a>
						<?php
					}else{
						$message = __('lblNoDepartmentsMessage', true);
						$message = str_replace("{STAG}", '<a href="'.$_SERVER['PHP_SELF'].'?controller=pjAdminDepartments&amp;action=pjActionCreate">', $message);
						$message = str_replace("{ETAG}", '</a>', $message);
						?><label class="block t5"><?php echo $message;?></label><?php
					} 
					?>
					
				</span>
			</p>
			<p class="boxRecipient">
				<label class="title"><?php __('lblRecipientUsers'); ?></label>
				<span class="inline_block">
					<select data-placeholder="--<?php __('lblChoose'); ?>--" name="user_id[]" id="user_id" multiple="multiple" class="pj-form-field w300">
						<?php
						foreach ($tpl['user_arr'] as $v)
						{
							
							?><option value="<?php echo $v['id']; ?>"><?php echo stripslashes($v['name']); ?></option><?php
							
						}
						?>
					</select>
				</span>
				<a href="#" class="pj-form-langbar-tip tss-tip" title="<?php __('lblNotifyUserTip');?>"></a>
			</p>
			<p class="boxRecipient">
				<label class="title"><?php __('lblRecipientClients'); ?></label>
				<span class="pj-form-field-custom pj-form-field-custom-before">
					<input type="checkbox" name="recipient_client" id="recipient_client" class="t5"/>
					<a href="#" class="pj-form-langbar-tip tss-tip" title="<?php __('lblNotifyClientTip');?>"></a>
				</span>
			</p>
			<?php
			foreach ($tpl['lp_arr'] as $v)
			{
			?>
				<p class="pj-multilang-wrap" data-index="<?php echo $v['id']; ?>" style="display: <?php echo (int) $v['is_default'] === 0 ? 'none' : NULL; ?>">
					<label class="title"><?php __('lblSubject'); ?></label>
					<span class="inline_block">
						<input type="text" name="i18n[<?php echo $v['id']; ?>][subject]" class="pj-form-field w300<?php echo (int) $v['is_default'] === 0 ? NULL : ' required'; ?>" />
						<?php if ((int) $tpl['option_arr']['o_multi_lang'] === 1 && count($tpl['lp_arr']) > 1) : ?>
						<span class="pj-multilang-input"><img src="<?php echo PJ_INSTALL_URL . PJ_FRAMEWORK_LIBS_PATH . 'pj/img/flags/' . $v['file']; ?>" alt="" /></span>
						<?php endif;?>
					</span>
				</p>
				<?php
			}
			?>
			<?php
			foreach ($tpl['lp_arr'] as $v)
			{
			?>
				<p class="pj-multilang-wrap" data-index="<?php echo $v['id']; ?>" style="display: <?php echo (int) $v['is_default'] === 0 ? 'none' : NULL; ?>">
					<label class="title">
						<?php __('lblMessage'); ?><br/><br/>
						<?php __('lblAvailableTokens'); ?>
					</label>
					<span class="inline_block">
						<textarea name="i18n[<?php echo $v['id']; ?>][message]" class="pj-form-field mceEditor<?php echo (int) $v['is_default'] === 0 ? NULL : ' required'; ?>"></textarea>
						<?php if ((int) $tpl['option_arr']['o_multi_lang'] === 1 && count($tpl['lp_arr']) > 1) : ?>
						<span class="pj-multilang-input"><img src="<?php echo PJ_INSTALL_URL . PJ_FRAMEWORK_LIBS_PATH . 'pj/img/flags/' . $v['file']; ?>" alt="" /></span>
						<?php endif;?>
					</span>
				</p>
				<?php
			}
			?>
			<p>
				<label class="title">&nbsp;</label>
				<input type="submit" value="<?php __('btnSave'); ?>" class="pj-button" />
				<input type="button" value="<?php __('btnCancel'); ?>" class="pj-button" onclick="window.location.href='<?php echo PJ_INSTALL_URL; ?>index.php?controller=pjAdminNotifications&action=pjActionIndex';" />
			</p>
		</div>
	</form>
	<script type="text/javascript">
	var myLabel = myLabel || {};
	myLabel.field_required = "<?php __('ts_field_required'); ?>";
	</script>
	<script type="text/javascript">
	(function ($) {
		$(function() {
			$(".multilang").multilang({
				langs: <?php echo $tpl['locale_str']; ?>,
				flagPath: "<?php echo PJ_FRAMEWORK_LIBS_PATH; ?>pj/img/flags/",
				tooltip: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris sit amet faucibus enim.",
				select: function (event, ui) {
					$("input[name='locale']").val(ui.index);
					var department_id = $('#department_id').val();
					var department_id_str = '';
					if(department_id != null)
					{
						department_id_str = department_id.join(',');
					} 
					$.get("index.php?controller=pjAdminNotifications&action=pjActionGetLocale&", {
						"locale" : ui.index,
						"department_id": department_id_str
					}).done(function (data) {
						$("#boxDepartment").html(data.department);
						$("#department_id").chosen();
					});
				}
			});
		});
	})(jQuery_1_8_2);
	</script>
	<?php
}
?>