<?php
defined('_JEXEC') or die('Restricted access');
//JToolBarHelper::title(JText::_('NS Pro Manager'), 'user.png');

$db =& JFactory::getDBO();
$db->setQuery('SELECT `id`, `lname` FROM `#__nspro_lists` WHERE `published` = 1');
$mlists = $db->loadObjectList();

?>
<script type="text/javascript"><!--

  function submitbutton(pressbutton) {
    var form = document.adminForm;

    if (pressbutton == 'ncancel') {
      submitform( pressbutton );
      return;
    }

    selRef = document.getElementById('mailing_lists2');
    var mstring = '';
    for (var i=0; i < selRef.options.length;i++) {
      if (selRef.options[i].selected) {
        if (mstring == '') {
          mstring = selRef.options[i].value;
        }
        else  {
          mstring = mstring + ',' + selRef.options[i].value;
        }
      }
    }

    document.getElementById('mailing_lists').value = mstring;
    submitform( pressbutton );
  }

--></script>
<form action="index.php" method="post" name="adminForm" id="adminForm">
<div class="col width-10">
    <fieldset class="adminform">
        <legend><?php echo JText::_( 'Details' ); ?></legend>

        <table class="admintable">
        <tr>
            <td width="100" align="right" class="key">
                <label for="name">
                    <?php echo JText::_( 'Name' ); ?>:
                </label>
            </td>
            <td>
                <input class="text_area" type="text" name="name" id="name" size="60 " maxlength="250"
                value="<?php echo $this->sub->name;?>" />
            </td>
        </tr>
        <tr>
            <td width="110" class="key">
                <label for="url">
                    <?php echo JText::_( 'Email' ); ?>:
                </label>
            </td>
            <td>
                <input class="inputbox" type="text" name="email" id="email" size="60" value="<?php echo $this->sub->email; ?>" />
            </td>
        </tr>
        <tr>
            <td width="110" class="key">
                <label for="datetime">
                    <?php echo JText::_( 'Date and Time' ); ?>:
                </label>
            </td>
            <td>
                <input class="inputbox" type="text" name="datetime" id="datetime" size="60" value="<?php echo $this->sub->datetime; ?>" />
            </td>
        </tr>
        <tr>
            <td width="120" class="key">
                <?php echo JText::_( 'Confirmed' ); ?>:
            </td>
            <td>
                <?php echo JHTML::_( 'select.booleanlist',  'confirmed', 'class="inputbox"', $this->sub->confirmed ); ?>
            </td>
        </tr>
        <tr>
            <td width="110" class="key">
                <label for="mailing_lists">
                    <?php echo JText::_( 'Mailing Lists' ); ?>:
                </label>
            </td>
            <td>
                <input type="hidden" name="mailing_lists" id="mailing_lists" value="<?php echo $this->sub->mailing_lists; ?>" />
                <select class="inputbox" size="5" style="width: 258px;" multiple="multiple" name="mailing_lists2[]" id="mailing_lists2">
                <?php
                foreach($mlists as $mlist) {
                  print '<option value="' . $mlist->id . '" id="list_' . $mlist->id . '"';
                  print '>' . $mlist->lname . '</option>';
                }
                ?>
                </select>
            </td>
        </tr>
        <tr>
            <td width="110" class="key">
                <label for="notes">
                    <?php echo JText::_( 'Notes' ); ?>:
                </label>
            </td>
            <td>
                <input class="inputbox" type="text" name="notes" id="notes" size="60" value="<?php echo $this->sub->notes; ?>" />
            </td>
        </tr>
        </table>
    </fieldset>
</div>
<div class="clr"></div>

<input type="hidden" name="option" value="com_nspro" />
<input type="hidden" name="id" value="<?php echo $this->sub->id; ?>" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="controller" value="nspro" />
</form>

<small><i>NS Pro by <a href="http://www.mavrosxristoforos.com/">Mavrosxristoforos.com</a> Copyright 2010</i></small>
<script type="text/javascript"><!--
<?php
$mSubLists = explode(',', $this->sub->mailing_lists);
foreach ($mSubLists as $msublist) {
  print 'document.getElementById("list_'.$msublist.'").setAttribute("selected","selected");' . "\n";
}
?>
-->
</script>