<?php

/**
* @version 2.7.18
* @package Joomla 2.5
* @subpackage DT Register
* @copyright Copyright (C) 2006 DTH Development
* @copyright contact dthdev@dthdevelopment.com
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/

$editor =& JFactory::getEditor();
$event = $this->getModel('event')->table;
$reminder = $this->reminder;
$document =& JFactory::getDocument();

$document->addScript( JURI::root(true).'/components/com_dtregister/assets/js/dt_jquery.js');
 
?>

 <form action="index.php" method="post" name="adminForm" enctype="multipart/form-data">
  <table>
    <tr>
      <td>
         <?php echo JText::_('DT_MESSAGE'); ?>:
      </td>
      <td colspan="2">
        <?php echo $editor->display("reminder[message]",$reminder->message,'id = ""','340','70','20','0'); ?>
      </td>
    </tr>
     <tr>
      <td>
         <?php echo JText::_('DT_SUBJECT'); ?>:
      </td>
      <td>
        <input name="reminder[subject]" id="subject" value="<?php echo $reminder->subject; ?>" />
      </td>
      <td align="left">
	    <?php echo JHTML::tooltip((JText::_( 'DT_REMINDERS_SUBJECT_HELP' )), '', 'tooltip.png', '', ''); ?>
	  </td>
    </tr>
     <tr>
      <td>
         <?php echo JText::_('DT_DAYS_PRIOR'); ?>:
      </td>
      <td>
        <input name="reminder[timer]" id="timer" value="<?php echo $reminder->timer; ?>" size="10" />
      </td>
      <td align="left">
	    <?php echo JHTML::tooltip((JText::_( 'DT_REMINDERS_DAYS_PRIOR_HELP' )), '', 'tooltip.png', '', ''); ?>
	  </td>
    </tr>
    <tr>
     
      <td>
        <?php echo JText::_('DT_SELECT_EVENT'); ?>:
      </td>
      <td>

	  		<?php
	
	  			 $events = DtHtml::options($event->optionslist(),JText::_('DT_SELECT_EVENT'));
				 // echo '<pre>';
				 // print_r($event->optionslist());

				 echo JHTML::_('select.genericlist', $events,"reminder[eventId]","","value","text",$reminder->eventId);

	  		?>

	  </td>
      </td>
      <td align="left">
	    <?php echo JHTML::tooltip((JText::_( 'DT_REMINDERS_SELECT_EVENT_HELP' )), '', 'tooltip.png', '', ''); ?>
	  </td>
    </tr>
    <tr>
       <td>
        <?php echo JText::_( 'DT_UPLOAD_ATTACHMENT' ); ?>:
       </td>
       <td>
       <script type="text/javascript">

                DTjQuery(function(){
                        
						//jQuery('.fields').trigger('click');
						
				        DTjQuery(".remove_file").click(function(event){

					        event.preventDefault();

						    element = this;

					    	DTjQuery.get(DTjQuery(this).attr('href'), function(data){

								DTjQuery(element).parent().parent().remove();

						    });

						    return false;

					});

                	var fileMax = 10;

                	DTjQuery("input.upload").change(function(){

                		doIt(this, fileMax);

                	});

                });	

                function doIt(obj, fm) {

                	if(DTjQuery('input.upload').size() > fm) {alert('Max files is '+fm); obj.value='';return true;}

                	DTjQuery(obj).hide();

                	DTjQuery(obj).parent().prepend('<input type="file" class="upload" name="reminder_files[]" value="'+obj.value+'" />').find("input:first").change(function() {doIt(this, fm)});

                	var v = obj.value;

               		 if(v != '') {

                		DTjQuery("div#files_list").append('<div>'+v+' <input type="button" class="remove" value="Delete" /></div>')

                		.find("input").click(function(){

               			 	DTjQuery(this).parent().remove();

                			DTjQuery(obj).remove();

                			return true;

                		});

                	}

                };

	</script>

            <span>
			<input type="file" name="reminder_files[]" class="upload"/>
 
            <div id="files_list">

            </div>

            </span>

       </td>

      <td align="left">
	    <?php echo JHTML::tooltip((JText::_( 'DT_REMINDERS_UPLOAD_ATTACHMENTS_HELP' )), '', 'tooltip.png', '', ''); ?>
	  </td>
    
    </tr>
    <?php echo $this->loadTemplate('editfile');?>
    <tr>
      <td colspan="2">
         <input type="submit" name="frmsubmit" value="<?php echo ($reminder->id)?JText::_('DT_SAVE'):JText::_('DT_ADD'); ?>" />
      </td>
     
    </tr>
  </table>
    <input type="hidden" name="option" value="<?php echo DTR_COM_COMPONENT; ?>" />

    <input type="hidden" name="reminder[id]" value="<?php echo $reminder->id; ?>" />

    <input type="hidden" name="controller" value="reminder" />

	<input type="hidden" name="task" value="<?php echo $_REQUEST['task']?>" />

    </form>
    <script type="text/javascript">
	   
	    DTjQuery(function(){

		  DTjQuery(document.adminForm).submit(function(){
			    DTjQuery("#reminder\\[message\\]").html(<?php  echo substr( $editor->getContent('reminder\[message\]') ,0,-1); ?>);
			 }).validate({
	  
				  success: function(label) {
	  
					  label.addClass("success");
	  
				  },
				  rules : {
				  		
						timer: {
							required: true,
							number: true
						  },
						subject : {
						    required: true
						}
						
				  },
				  errorPlacement: function(label, element) {
					  // position error label after generated textarea
					  if (element.is("textarea")) {
						  label.insertAfter(element.next());
					  } else {
						  label.insertAfter(element)
					  }
				  }
			
		  });
		  
		  DTjQuery("#reminder\\[message\\]").rules('add','required');
		  DTjQuery("#subject").rules('add','required');
		  DTjQuery("#timer").rules('add','required');
		  DTjQuery("#timer").rules('add','number');
		  
		});

	</script>