function upload($field_id = 'advert_file')
 {
     $app = JFactory::getApplication();
     $wbAdvert_config = wbAdvert_config::getInstance();
     // Pre-Processing Checks
     if (!$this->id) {
         if (!$this->store()) {
             $this->setError(JText::sprintf('ERR_INVALIDX', JText::_("Advertisement ID")));
             return false;
         }
     }
     // Check File Permissions
     if (!is_writable(JPATH_ROOT . '/media/')) {
         $this->setError(JText::sprintf('ERR_FILEWRITEFAIL', "/media"));
         return false;
     }
     // Check File Permissions
     $ad_path = $wbAdvert_config->getAdPath();
     if (!wbAdvert_Common::isWritable($ad_path)) {
         $this->setError(JText::sprintf('ERR_FILEWRITEFAIL', $wbAdvert_config->getAdPath(false)));
         return false;
     }
     // Pre-Processing Checks
     if (!isset($_FILES[$field_id]) || !is_array($_FILES[$field_id]) || $_FILES[$field_id]['tmp_name'] == '') {
         return true;
     }
     // Check Upload File
     if (!is_uploaded_file($_FILES[$field_id]['tmp_name'])) {
         $this->setError(JText::_('No Upload File Provided'));
         return false;
     }
     // Get File Type
     $this->file_type = strtolower(preg_replace("/^.*\\.(\\w+)\$/", "\$1", $_FILES[$field_id]['name']));
     // Get File Dimensions
     if (in_array($this->file_type, array('gif', 'jpg', 'png', 'bmp'))) {
         $imginfo = getimagesize($_FILES[$field_id]['tmp_name']);
         if ($imginfo == null) {
             $this->setError(JText::_('Error Pulling File Dimensions'));
             return false;
         }
         $this->width = $imginfo[0];
         $this->height = $imginfo[1];
     } else {
         if (in_array($this->file_type, array('swf'))) {
             $swf = new wbAdvert_swfHeader(false);
             $swf->loadswf($_FILES[$field_id]['tmp_name']);
             if (!$swf->size) {
                 $this->setError(JText::_('Error Pulling File Dimensions'));
                 return false;
             }
             $this->width = $swf->width;
             $this->height = $swf->height;
         } else {
             $this->width = 0;
             $this->height = 0;
         }
     }
     // Delete Existing File
     // if( $this->file_type && file_exists(JPATH_ROOT.'/'.$wbAdvert_config->get('ad_path').$this->id.'.'.$this->file_type) && !unlink(JPATH_ROOT.'/'.$wbAdvert_config->get('ad_path').$this->id.'.'.$this->file_type) ){
     if ($this->file_type && file_exists($wbAdvert_config->getAdPath() . $this->id . '.' . $this->file_type) && !unlink($wbAdvert_config->getAdPath() . $this->id . '.' . $this->file_type)) {
         $this->setError(JText::_('Error Deleting Existing File'));
         return false;
     }
     // Verify Formats
     if (!in_array($this->target, array('_blank', '_self', '_top', '_parent'))) {
         $this->setError(JText::sprintf('ERR_INVALIDX', JText::_('Advertisement Link Target')));
         return false;
     }
     // Verify Formats
     if (!in_array($this->file_type, array('gif', 'jpg', 'png', 'bmp', 'swf'))) {
         $this->setError(JText::_('ERR_INVALIDFORMAT'));
         return false;
     }
     // Copy or Overwrite
     // if( !copy($_FILES[$field_id]['tmp_name'], JPATH_ROOT.'/'.$wbAdvert_config->get('ad_path').$this->id.'.'.$this->file_type) ) {
     if (!copy($_FILES[$field_id]['tmp_name'], $wbAdvert_config->getAdPath() . $this->id . '.' . $this->file_type)) {
         $this->setError(JText::_('Error Saving Record'));
         return false;
     }
     return true;
 }
 function group_list()
 {
     JToolBarHelper::title(WBADVERT_TITLE . ' ' . JText::_('TB_GROUPLIST'), 'categories.png');
     JToolBarHelper::addNew('group.edit');
     JToolBarHelper::editList('group.edit');
     JToolBarHelper::publishList('group.publish');
     JToolBarHelper::unpublishList('group.unpublish');
     JToolBarHelper::deleteList(JText::_('VALIDDELETEITEMS'), 'group.delete');
     $canDo = wbAdvert_Common::userGetPermissions();
     if ($canDo->get('core.admin')) {
         JToolbarHelper::preferences('com_wbadvert');
     }
 }
    function group_edit(&$row, &$lists, $option)
    {
        JFilterOutput::objectHTMLSafe($row, ENT_QUOTES);
        JHTML::_('behavior.tooltip');
        ?>
    <script language="javascript">
    Joomla.submitbutton = function(pressbutton) {
      var form = document.adminForm;
      if (pressbutton == 'group.cancel') {
        submitform( pressbutton );
        return;
      }
      // do field validation
      if (form.name.value == "") {
        alert( "You must provide a banner name." );
      } else {
        submitform( pressbutton );
      }
    }
    </script>
    <form action="<?php 
        echo JRoute::_('index.php?option=com_wbadvert&task=group.edit');
        ?>
" method="post" name="adminForm" id="adminForm">
      <table class="adminHeading" width="100%">
        <tr><th class="icon-48-group">
          <?php 
        echo $row->id ? JText::sprintf('HEAD_GROUPEDIT', $row->name) : JText::_('HEAD_GROUPNEW');
        ?>
<br/>
          <font size="-1"><?php 
        if (is_object($row->_report)) {
            echo '<a href="index.php?option=' . $option . '&task=advert&filter_group_id=' . $row->id . '">' . JText::_('BTN_VIEWADVERTLIST') . '</a> ';
            foreach ($row->_report as $k => $v) {
                echo ' | <span>' . JText::_('FLD_' . strtoupper($k)) . ': ' . (int) $v . '</span>';
            }
        }
        ?>
</font>
        </th></tr>
      </table>
      <div class="col100">
        <fieldset class="adminForm">
          <legend><?php 
        echo JText::_('Details');
        ?>
</legend>
          <table class="adminTable" width="100%">
            <tbody>
              <tr>
                <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_GROUPNAME'), JText::_('FLD_GROUPNAME_TIP'));
        ?>
</td>
                <td><input class="inputbox" type="text" name="name" value="<?php 
        echo $row->name;
        ?>
"></td>
              </tr>
              <tr>
                <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_DESCRIPTION'), JText::_('FLD_DESCRIPTION_TIP'));
        ?>
</td>
                <td><input class="inputbox" type="text" name="description" value="<?php 
        echo $row->description;
        ?>
"></td>
              </tr>
              <tr>
                <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_MODULEPOS'), JText::_('FLD_MODULEPOS_TIP'));
        ?>
</td>
                <td><?php 
        echo $lists['module_id'];
        ?>
</td>
              </tr>
              <tr>
                <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_SHOWCOUNT'), JText::_('FLD_SHOWCOUNT_TIP'));
        ?>
</td>
                <td><input class="inputbox" type="text" name="count" value="<?php 
        echo $row->count;
        ?>
"></td>
              </tr>
              <tr>
                <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_DISPLAYORD'), JText::_('FLD_DISPLAYORD_TIP'));
        ?>
</td>
                <td><?php 
        echo $lists['order'];
        ?>
</td>
              </tr>
            </tbody>
          </table>
        </fieldset>
      </div>
      <div class="clr"></div>
      <input type="hidden" name="option" value="<?php 
        echo $option;
        ?>
">
      <input type="hidden" name="task" value="group.apply">
      <input type="hidden" name="id" value="<?php 
        echo $row->id;
        ?>
">
      <?php 
        echo JHTML::_('form.token');
        ?>
    </form>
    <?php 
    }
    function client_edit(&$row, &$lists, $option)
    {
        JFilterOutput::objectHTMLSafe($row, ENT_QUOTES, 'extrainfo');
        JHTML::_('behavior.tooltip');
        ?>
    <script>
    Joomla.submitbutton = function(pressbutton) {
      var form = document.adminForm;
      if (pressbutton == 'client.cancel') {
        submitform( pressbutton );
        return;
      }
      // do field validation
      if (form.name.value == "") {
        alert( "<?php 
        echo JText::_('FLD_VAL_CLIENTNAME');
        ?>
" );
      } else {
        submitform( pressbutton );
      }
    }
    </script>
    <form action="<?php 
        echo JRoute::_('index.php?option=com_wbadvert&task=client.edit');
        ?>
" method="post" name="adminForm" id="adminForm">
      <table class="adminHeading" width="100%">
        <tr><th class="icon-48-client">
          <?php 
        echo $row->id ? JText::sprintf('HEAD_CLIENTEDIT', $row->name) : JText::_('HEAD_CLIENTNEW');
        ?>
<br/>
          <font size="-1"><?php 
        if (is_object($row->_report)) {
            echo '<a href="index.php?option=' . $option . '&task=advert&filter_client_id=' . $row->id . '">' . JText::_('BTN_VIEWADVERTLIST') . '</a> ';
            foreach ($row->_report as $k => $v) {
                echo ' | <span>' . JText::_('FLD_' . strtoupper($k)) . ': ' . (int) $v . '</span>';
            }
        }
        ?>
</font>
        </th></tr>
      </table>
      <div class="col100">
        <fieldset class="adminform">
          <legend><?php 
        echo JText::_('Details');
        ?>
</legend>
          <table class="admintable">
            <tbody>
              <tr>
                <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_CLIENTNAME'), JText::_('FLD_CLIENTNAME_TIP'));
        ?>
</td>
                <td><input class="inputbox" type="text" name="name" size="30" maxlength="60" valign="top" value="<?php 
        echo $row->name;
        ?>
"></td>
              </tr>
              <tr>
                <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_PUBLISHED'), JText::_('FLD_PUBLISHED_TIP'));
        ?>
</td>
                <td>
                  <fieldset id="jform_type" class="radio inputbox">
                  <?php 
        echo $lists['published'];
        ?>
                  </fieldset>
                </td>
              </tr>
              <tr>
                <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_CLIENTCONTACT'), JText::_('FLD_CLIENTCONTACT_TIP'));
        ?>
</td>
                <td><input class="inputbox" type="text" name="contact" size="30" maxlength="60" value="<?php 
        echo $row->contact;
        ?>
"></td>
              </tr>
              <tr>
                <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_CLIENTEMAIL'), JText::_('FLD_CLIENTEMAIL_TIP'));
        ?>
</td>
                <td><input class="inputbox" type="text" name="email" size="30" maxlength="60" value="<?php 
        echo $row->email;
        ?>
"></td>
              </tr>
              <tr>
                <td valign="top"><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_CLIENTEXTRA'), JText::_('FLD_CLIENTEXTRA_TIP'));
        ?>
</td>
                <td><textarea class="inputbox" name="extrainfo" cols="60" rows="10"><?php 
        echo str_replace('&', '&amp;', $row->extrainfo);
        ?>
</textarea></td>
              </tr>
            </tbody>
          </table>
        </fieldset>
      </div>
      <div class="clr"></div>
      <input type="hidden" name="option" value="<?php 
        echo $option;
        ?>
">
      <input type="hidden" name="id" value="<?php 
        echo $row->id;
        ?>
">
      <input type="hidden" name="task" value="client.apply">
      <?php 
        echo JHTML::_('form.token');
        ?>
    </form>
    <?php 
    }
    function advert_edit(&$row, &$lists, $option)
    {
        $app = JFactory::getApplication();
        JFilterOutput::objectHTMLSafe($row, ENT_QUOTES, 'custombannercode');
        JHTML::_('behavior.tooltip');
        JHTML::_('behavior.calendar');
        $db =& JFactory::getDBO();
        $wbAdvert = new wbAdvert_advert($db);
        ?>
    <script>
      var dimRatio = '<?php 
        echo $row->width ? $row->height / $row->width : 0;
        ?>
';
      function dimCheck( myObj ){
        if( !dimRatio )return;
        var form = document.adminForm;
        if( form.constrain.checked == true ){
          if( myObj.name == 'height' )
            form.width.value = Math.round(myObj.value / dimRatio);
          else
            form.height.value = Math.round(myObj.value * dimRatio);
        }
      }
      function getSelectedValue(formName,fieldName){
        var form = document[formName];
        if( form[fieldName].selectedIndex >= 0 )
          return form[fieldName].options[form[fieldName].selectedIndex].value;
        return 0;
      }
      Joomla.submitbutton = function(pressbutton) {
        var form = document.adminForm;
        if (pressbutton == 'advert.cancel') {
          submitform( pressbutton );
          return;
        }
        // do field validation
        if (form.name.value == "") {
          alert( "<?php 
        echo JText::_('FLD_VAL_ADVERTNAME');
        ?>
" );
        }
        else if (getSelectedValue('adminForm','client_id') < 1) {
          alert( "<?php 
        echo JText::_('FLD_VAL_ADVERTCLIENT');
        ?>
" );
        }
        else if (getSelectedValue('adminForm','idx_group') < 1) {
          alert( "<?php 
        echo JText::_('FLD_VAL_ADVERTGROUP');
        ?>
" );
        }
        else if (form.id.value == '' && form.code.value == '' && form.advert_file.value == ''){
          alert( "<?php 
        echo JText::_('FLD_VAL_ADVERTADMEDIA');
        ?>
" );
        }
        else {
          submitform( pressbutton );
        }
      }
      function toggleAllDays(el){
        var isAll = el.checked;
        var fields = document.adminForm['weekdays[]'];
        for(var i=1;i<fields.length;i++){
          fields[i].checked = isAll?false:true;
          fields[i].disabled = isAll?true:false;
        }
      }
    </script>
    <style>
      .adminform select.idx_menu { width:400px; height:190px; }
      .adminform select.idx_category { width:400px; height:190px; }
      .adminform textarea.idx_content { width:400px;height:80px; }
      .adminform textarea.code { width:360px;height:140px; }
    </style>
    <form action="<?php 
        echo JRoute::_('index.php?option=com_wbadvert&task=advert.edit');
        ?>
" method="post" name="adminForm" id="adminForm" enctype="multipart/form-data">
      <table class="adminHeading" width="100%">
        <tr><th class="icon-48-advert">
          <?php 
        echo $row->id ? JText::sprintf('HEAD_ADVERTEDIT', $row->name) : JText::_('HEAD_ADVERTNEW');
        ?>
<br/>
          <font size="-1"><?php 
        echo $row->id ? JText::_('LBL_ADVERTLINK') . ': <a href="' . JURI::root() . 'index.php?option=' . $option . '&task=load&id=' . $row->id . '" target="_blank">index.php?option=' . $option . '&task=load&id=' . $row->id . '</a>' : '&nbsp;';
        ?>
</font>
        </th></tr>
      </table>
      <div class="col100">
        <table class="adminTable" width="100%">
          <tr><td valign="top" width="50%">
            <fieldset class="adminForm">
              <legend><?php 
        echo JText::_('SET_ADVERTDETAIL');
        ?>
</legend>
              <table class="adminTable" width="100%">
                <tr>
                  <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_ADVERTNAME'), JText::_('FLD_ADVERTNAME_TIP'));
        ?>
</td>
                  <td><input class="inputbox" type="text" name="name" size="30" value="<?php 
        echo $row->name;
        ?>
" required="true"></td>
                </tr>
                <tr>
                  <td valign="top"><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_ADVERTGROUPIDX'), JText::_('FLD_ADVERTGROUPIDX_TIP'));
        ?>
</td>
                  <td><?php 
        echo $lists['idx_group'];
        ?>
</td>
                </tr>
                <tr>
                  <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_ADVERTCLIENT'), JText::_('FLD_ADVERTCLIENT_TIP'));
        ?>
</td>
                  <td><?php 
        echo $lists['client_id'];
        ?>
</td>
                </tr>
                <tr>
                  <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_PUBLISHED'), JText::_('FLD_PUBLISHED_TIP'));
        ?>
</td>
                  <td><?php 
        echo $lists['published'];
        ?>
</td>
                </tr>
                <tr>
                  <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_IMPTOTAL'), JText::_('FLD_IMPTOTAL_TIP'));
        ?>
</td>
                  <td><input class="inputbox" type="text" name="imptotal" size="12" maxlength="11" value="<?php 
        echo $row->imptotal ? $row->imptotal : null;
        ?>
">
                    <span><?php 
        echo JText::_('FLD_IMPTOTAL_NOTE');
        ?>
</span></td>
                </tr>
                <tr>
                  <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_IMPMADE'), JText::_('FLD_IMPMADE_TIP'));
        ?>
</td>
                  <td>
                    <?php 
        echo '<b> ' . (int) $row->impmade . ' </b>';
        if ($row->id) {
            echo '&nbsp;&nbsp;&nbsp;<input type="button" onClick="submitbutton(\'advert.reset\');" value="' . JText::_('BTN_RESETCOUNTER') . '" />';
        }
        ?>
</td>
                </tr>
                <tr>
                  <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_DATESTART'), JText::_('FLD_DATESTART_TIP'));
        ?>
</td>
                  <td><?php 
        echo JHTML::_('calendar', $row->date_start, 'date_start', 'date_start_cal', '%Y-%m-%d', array('class' => 'inputbox'));
        ?>
</td>
                </tr>
                <tr>
                  <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_DATESTOP'), JText::_('FLD_DATESTOP_TIP'));
        ?>
</td>
                  <td><?php 
        echo JHTML::_('calendar', $row->date_stop == 'Never' ? null : $row->date_stop, 'date_stop', 'date_stop_cal', '%Y-%m-%d', array('class' => 'inputbox'));
        ?>
</td>
                </tr>
              </table>
            </fieldset>
            <fieldset class="adminForm">
              <legend><?php 
        echo JText::_('SET_ADVERTMEDIA');
        ?>
</legend>
              <table class="adminTable" width="100%">
                <tr>
                  <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_URL'), JText::_('FLD_URL_TIP'));
        ?>
</td>
                  <td><input class="inputbox" type="text" name="url" size="30" maxlength="200" value="<?php 
        echo $row->url;
        ?>
"></td>
                </tr>
                <tr>
                  <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_TARGET'), JText::_('FLD_TARGET_TIP'));
        ?>
</td>
                  <td><?php 
        echo $lists['target'];
        ?>
</td>
                </tr>
                <tr>
                  <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_CAPTION'), JText::_('FLD_CAPTION_TIP'));
        ?>
</td>
                  <td><input class="inputbox" type="text" name="caption" size="30" maxlength="200" value="<?php 
        echo $row->caption;
        ?>
"></td>
                </tr>
                <tr>
                  <td nowrap valign="top"><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_UPLOADFILE'), JText::_('FLD_UPLOADFILE_TIP'));
        ?>
</td>
                  <td>
                    <input class="inputbox" type="file" name="advert_file" size="30" /><br/>
                    <span><?php 
        echo JText::_('FLD_UPLOADFILE_NOTE');
        ?>
</span>
                  </td>
                </tr>
                <tr>
                  <td nowrap valign="top"><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_DIMENSIONS'), JText::_('FLD_DIMENSIONS_TIP'));
        ?>
</td>
                  <td>
                    <input class="inputbox" type="text" name="width" size="5" value="<?php 
        echo $row->width;
        ?>
" onkeypress="dimCheck(this);" onchange="dimCheck(this);" /> x
                    <input class="inputbox" type="text" name="height" size="5" value="<?php 
        echo $row->height;
        ?>
" onkeypress="dimCheck(this);" onchange="dimCheck(this);" /><br/>
                    <input type="checkbox" id="constrain" name="constrain" <?php 
        echo $row->height && $row->width ? 'checked' : '';
        ?>
> <label for="constrain"><?php 
        echo JText::_('CHK_CONSTRAIN');
        ?>
</label>
                  </td>
                </tr>
                <tr><th colspan="2"><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_CODE'), JText::_('FLD_CODE_TIP'));
        ?>
</th></tr>
                <tr><td colspan="2"><textarea class="inputbox code" name="code"><?php 
        echo $row->code;
        ?>
</textarea></td></tr>
              </table>
            </fieldset>
          </td>
          <td valign="top" width="50%">
            <fieldset class="adminForm">
              <legend><?php 
        echo JText::_('SET_ADVERTFILTERS');
        ?>
</legend>
              <table class="adminTable" width="100%">
                <tr>
                  <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_WEEKDAYS'), JText::_('FLD_WEEKDAYS_TIP'));
        ?>
</td>
                  <td><?php 
        echo $lists['weekdays'];
        ?>
</td>
                </tr>
                <tr>
                  <td>
                    <?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_TIMESTART'), JText::_('FLD_TIMESTART_TIP'));
        ?>
 /
                    <?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_TIMESTOP'), JText::_('FLD_TIMESTOP_TIP'));
        ?>
                    </td>
                  <td>
                    <?php 
        echo $lists['time_start'];
        ?>
 /
                    <?php 
        echo $lists['time_stop'];
        ?>
                    </td>
                </tr>
                <tr>
                  <td valign="top"><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_IDXMENU'), JText::_('FLD_IDXMENU_TIP'));
        ?>
</td>
                  <td><?php 
        echo $lists['idx_menu'];
        ?>
</td>
                </tr>
                <tr>
                  <td valign="top"><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_IDXCATEGORY'), JText::_('FLD_IDXCATEGORY_TIP'));
        ?>
</td>
                  <td><?php 
        echo $lists['idx_category'];
        ?>
</td>
                </tr>
                <tr>
                  <td valign="top"><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_IDXCONTENT'), JText::_('FLD_IDXCONTENT_TIP'));
        ?>
</td>
                  <td><textarea class="inputbox idx_content" name="idx_content"><?php 
        echo $row->idx_content;
        ?>
</textarea></td>
                </tr>
              </table>
            </fieldset>
          </td></tr>
        </table>
      </div>
      <input type="hidden" name="option" value="<?php 
        echo $option;
        ?>
">
      <input type="hidden" name="id" value="<?php 
        echo $row->id;
        ?>
">
      <input type="hidden" name="task" value="advert.apply">
      <?php 
        echo JHTML::_('form.token');
        ?>
    </form>
    <?php 
        if ($row->id) {
            ?>
    <fieldset class="adminForm">
      <legend><?php 
            echo JText::_('SET_ADVERTMEDIA');
            ?>
</legend>
      <table class="adminTable report" width="100%">
        <tbody>
          <tr>
            <td><label><?php 
            echo JText::_('SET_ADVERTSAMPLE');
            ?>
 - <?php 
            echo $row->file_type;
            ?>
</label></td>
            <td><?php 
            echo $wbAdvert->getAdvertCode($row->id);
            ?>
</td>
          </tr>
          <?php 
            if (!$row->code) {
                ?>
          <tr>
            <td><label><?php 
                echo JText::_('SET_ADVERTCODE');
                ?>
</label></td>
            <td><textarea class="inputbox" style="width:100%;height:100px;"><?php 
                echo $wbAdvert->getAdvertCode($row->id);
                ?>
</textarea></td>
          </tr>
          <?php 
            }
            ?>
        </tbody>
      </table>
    </fieldset>
    <?php 
        }
        ?>
    <?php 
    }
function config_save($option)
{
    $wbAdvert_config = wbAdvert_config::getInstance();
    $errors = array();
    $params = JRequest::getVar('params', array(), 'method', 'array');
    if (count($params)) {
        $txt = array();
        // Build Advertisement Path
        $ad_path = preg_replace('/\\\\/', '/', trim($params['ad_path']));
        if (!preg_match('/\\/$/', $ad_path)) {
            $ad_path .= '/';
        }
        if (preg_match('/^\\//', $ad_path)) {
            $ad_path = substr($ad_path, 1);
        }
        $params['ad_path'] = $ad_path;
        $ad_path = preg_replace('/\\\\/', '/', JPATH_ROOT . DS . $params['ad_path']);
        // Check Advertisement Path
        if (!file_exists($ad_path)) {
            $errors[] = JText::_('ERR_ADPATHINVALID');
        }
        if (!is_writable($ad_path)) {
            $errors[] = JText::_('ERR_ADPATHNOWRITE');
        }
        // Check Wrapper Exists
        if ($params['wrap_swf'] == 1) {
            if (!file_exists($ad_path . 'wbadvert_wrapper.swf')) {
                $params['wrap_swf'] = 0;
                $errors[] = JText::sprintf('ERR_FILENOTFOUND', $ad_path . 'wbadvert_wrapper.swf');
            }
        }
        // Build SWFObject Library Path
        $swf_jsloaderpath = preg_replace('/\\\\/', '/', trim($params['swf_jsloaderpath']));
        if (!preg_match('/\\/$/', $swf_jsloaderpath)) {
            $swf_jsloaderpath .= '/';
        }
        if (preg_match('/^\\//', $swf_jsloaderpath)) {
            $swf_jsloaderpath = substr($swf_jsloaderpath, 1);
        }
        $params['swf_jsloaderpath'] = $swf_jsloaderpath;
        $swf_jsloaderpath = preg_replace('/\\\\/', '/', JPATH_ROOT . DS . $params['swf_jsloaderpath']);
        // Check SWFObject Exists
        if ($params['swf_jsloader'] == 1) {
            if (!file_exists($swf_jsloaderpath . 'swfobject.js')) {
                $params['swf_jsloader'] = 0;
                $errors[] = JText::sprintf('ERR_FILENOTFOUND', $swf_jsloaderpath . 'swfobject.js');
            }
        }
        // Collect Values
        foreach ($params as $key => $val) {
            $wbAdvert_config->set($key, $val);
        }
    }
    if (!$wbAdvert_config->storeExtension()) {
        echo "<script type=\"text/javascript\"> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
        exit;
    }
    $framed_template = JRequest::getVar('framed_template', '', 'post', 'string', JREQUEST_ALLOWRAW);
    if ($framed_template !== null) {
        if ($fh = fopen($wbAdvert_config->getFramePath(), 'w')) {
            fwrite($fh, $framed_template);
            fclose($fh);
        } else {
            $errors[] = JText::sprintf('ERR_FILEWRITEFAIL', $wbAdvert_config->getFramePath(false));
        }
    }
    // Create Advertistment Folder
    $ad_path = $wbAdvert_config->getAdPath();
    if (!is_dir($ad_path)) {
        if (!wbAdvert_Common::create_dir($ad_path)) {
            $errors[] = JText::_('ERR_CREATEDIRFAIL', $ad_path);
        }
    }
    // Redirect
    $app = JFactory::getApplication();
    $app->redirect('index.php?option=' . WBADVERT_NAME . '&task=config', count($errors) ? implode('<br>', $errors) : 'Settings successfully Saved', count($errors) ? 'error' : 'message');
}