<div id="menu2" class="tab-content">
  <?php if ($themoney_site_ads_txt == 0) { ?>
    <h3>
        <?php _e('Votre fichier ads.txt doit être intégré','themoneytizer');?>
    </h3>
  <?php } else { ?>
  <h3>
      <?php _e('Tags publicitaires disponibles pour votre site','themoneytizer');?>
  </h3>

  <p>
      <?php //_e('Les formats <b>Automatiques</b> se placent automatiquement aux bons endroits dans votre code, il suffit juste de les activer à l\'aide du tableau ci-dessous.','themoneytizer');?>
  </p>

    <?php _e('Les formats possédant un <b>Shortcode</b> se placent manuellement aux endroits désirés.<br>Vous pouvez donc utiliser notre <b>','themoneytizer');?><a href="<?php echo admin_url('widgets.php');?>">Widget</a></b>

    <?php _e('ou','themoneytizer');?> <b><a href="<?php echo admin_url('/post-new.php');?>"><?php _e('Ajouter un emplacement</a></b> directement dans vos articles.','themoneytizer');?>
      <br><br>

            <?php if (isset($themoney_api->message)) { ?>
              <div class="updated fade"><p><b><?php echo $themoney_api->message; ?></b></p></div>
            <?php } if (isset($themoney_api->errorMessage)) { ?>
              <div class="error fade"><p><?php echo $themoney_api->errorMessage; ?></p></div>
            <?php } ?>
      <form action='options-general.php?page=themoneytizer' method='post'>
        <input name='submit' type='submit' name='Submit' class='bouton_money' value="<?php _e('Enregistrer','themoneytizer');?>" style="margin:auto;display:block;margin-top:10px;" /><br>
        <table class="widefat page fixed sis">
          <thead>
          <tr>
            <th><?php _e('Format','themoneytizer');?></th>
            <th><?php _e('Action','themoneytizer');?></th>
            <th><?php _e('Activation Automatique','themoneytizer');?></th>
            <th><?php _e('Shortcode','themoneytizer');?></th>
            <th><?php _e('Placement manuel','themoneytizer');?></th>
          </tr>
          </thead>

          <tbody>
          <?php
          $themoney_not_allowed = array(32,33,29);
          $themoney_spaces      = $themoney_website->site_tags;
          $arr_rec_skin = array();
          $form_state_skin_reco = array('SKIN' => array(), 'RECO' => array());
          $displayed_formats = array();
          if (get_option('themoney_raison_refus') != 'adcash') {
              // formats avec tag
              foreach ($themoney_spaces as $space) {
                  if ($space->form_name == 'RECO CONTENUS') {
                      array_push($form_state_skin_reco['RECO'], $space->form_state);
                  }

                  if ($space->form_name == 'HABILLAGE') {
                      array_push($form_state_skin_reco['SKIN'], $space->form_state);
                  }

                  if(!in_array($space->ad_id,$themoney_not_allowed) && $space->tag_name == $space->form_name){
                      array_push($displayed_formats, $space->ad_id);
                      if($space->tag_type == 1){
                          $themoney_type = __("Automatique",'themoneytizer');
                          $themoney_automatic = true;
                      }else{
                          $themoney_type = __("Shortcode",'themoneytizer');
                          $themoney_automatic = false;
                      }
                      ?>
                    <tr>
                      <td style="text-align: center">
                        <img style="width:100px;" src="<?= $themoney_website->path_format_img . $space->ad_img ?>" alt="<?= $space->form_name ?>"/> <br>
                          <?= __($space->form_name,'themoneytizer') ?>
                      </td>
                      <td>
                          <?php
                          $disabled = '';
                          if (in_array($space->ad_id, [5,16])) {
                              array_push($arr_rec_skin, $space->ad_id);
                              if ($space->form_state == 1) {
                                  $disabled = 'disabled'; ?>
                                <div class="bouton_money centrar" style="background-color: #d64e07; cursor: default"><?php _e('En attente','themoneytizer'); ?></div>
                              <?php } elseif ($space->form_state == 0) {
                                  $disabled = 'disabled'; ?>
                                <div class="bouton_money centrar" style="cursor: default"><?php _e('Refusé','themoneytizer'); ?></div>
                              <?php } else { ?>
                                <div class="bouton_money centrar" style="background-color: #00d084; cursor: default"><?php _e('Accepté','themoneytizer'); ?></div>
                              <?php }
                          }
                          else {
                              array_push($arr_rec_skin, $space->ad_id);
                              if ($space->form_state == 0) {
                                $disabled = 'disabled'; ?>
                                <div class="bouton_money centrar" style="cursor: default"><?php _e('Refusé','themoneytizer'); ?></div>
                              <?php } else {
                                  if ($space->tag_id === null || $space->tag_name != $space->form_name) {
                                      $disabled = 'disabled'; ?>
                                      <div class="bouton_money centrar" id="generate-<?= $space->ad_id ?>-<?= $themoney_website->site_id ?>" onclick="generateTag(<?= $space->ad_id ?>, <?= $themoney_website->site_id; ?>)"><?php _e('Générer le script','themoneytizer'); ?></div>
                                  <?php }
                              }
                          }

                          if ($space->tag_actif == 0 && $space->form_state != 0) { ?>
                            <div class="bouton_money centrar" onclick="reactivateTag(<?= $space->tag_id ?>)"><?php _e('Réactiver le tag','themoneytizer'); ?></div>
                          <?php } ?>
                      </td>
                        <?php if($themoney_automatic && $space->form_state != 0){
                            if ($space->form_state == 1 || in_array($space->form_state, [0, 1])) {
                              $disabled = 'disabled';
                            }
                          ?>

                          <td style='text-align: center'>
                            <input class='checkbox_format beautiful_checkbox_themoneytizer' name='formatauto[]' id='<?= $space->ad_id ?>' value='<?= $themoney_website->site_id.'-'.$space->ad_id ?>' type='checkbox' <?php echo in_array($space->ad_id,$registered_format) ? 'checked' : ''; ?> <?php echo $disabled ?> >
                            <label for='<?= $space->ad_id ?>'></label>
                          </td>
                        <?php	} else { ?>
                          <td></td>
                        <?php } if(!$themoney_automatic && $space->form_state != 0){ ?>
                          <td><input style='width:100%' onFocus='this.select()' type='text' value='[themoneytizer id="<?= $token = $themoney_website->site_id; ?>-<?= $space->ad_id; ?>"]' <?php echo $disabled?>></td>
                        <?php }else{ ?>
                          <td></td>
                        <?php } ?>
                          <td>
                              <?php if ($space->form_state != 0) {?>
                                <textarea
                                id="tag_<?= $space->tag_name === $space->form_name ? $space->tag_id : ''; ?>"
                                style='width: 100%; height: 100px;'
                                onclick='this.select()' <?php echo $space->tag_actif == 0 ? 'disabled' : ''; ?> <?php echo $disabled ?>><?= $space->tag_name === $space->form_name ? htmlentities($space->tag_text_asynch) : ''; ?></textarea>
                              <?php } ?>
                          </td>
                    </tr>
                    <?php
                  }
              }

              // If mobile is not displayed we count it as displayed because it is available only for old website
              if (!in_array(15, $displayed_formats))
                  array_push($displayed_formats, 15);

              // formats sans tag
              foreach ($themoney_spaces as $space) {
                  if ($space->form_name == 'RECO CONTENUS') {
                      array_push($form_state_skin_reco['RECO'], $space->form_state);
                  }

                  if ($space->form_name == 'HABILLAGE') {
                      array_push($form_state_skin_reco['SKIN'], $space->form_state);
                  }

                  if(!in_array($space->ad_id,$themoney_not_allowed) && !in_array($space->ad_id, $displayed_formats)){
                      array_push($displayed_formats, $space->ad_id);
                      if($space->tag_type == 1){
                          $themoney_type = __("Automatique",'themoneytizer');
                          $themoney_automatic = true;
                      }else{
                          $themoney_type = __("Shortcode",'themoneytizer');
                          $themoney_automatic = false;
                      }
                      ?>
                    <tr>
                      <td style="text-align: center">
                        <img style="width:100px;" src="<?= $themoney_website->path_format_img . $space->ad_img ?>" alt="<?= $space->form_name ?>"/> <br>
                          <?= __($space->form_name,'themoneytizer') ?>
                      </td>
                      <td>
                          <?php
                          $disabled = '';
                          if (in_array($space->ad_id, [5,16])) {
                              array_push($arr_rec_skin, $space->ad_id);
                              if ($space->form_state == 1) {
                                  $disabled = 'disabled'; ?>
                                <div class="bouton_money centrar" style="background-color: #d64e07; cursor: default"><?php _e('En attente','themoneytizer'); ?></div>
                              <?php } elseif ($space->form_state == 0) {
                                  $disabled = 'disabled'; ?>
                                <div class="bouton_money centrar" style="cursor: default"><?php _e('Refusé','themoneytizer'); ?></div>
                              <?php } else { ?>
                                <div class="bouton_money centrar" style="background-color: #00d084; cursor: default"><?php _e('Accepté','themoneytizer'); ?></div>
                              <?php }
                          }
                          else {
                              array_push($arr_rec_skin, $space->ad_id);
                              if ($space->form_state == 0) {
                                  $disabled = 'disabled'; ?>
                                  <div class="bouton_money centrar" style="cursor: default"><?php _e('Refusé','themoneytizer'); ?></div>
                              <?php } else {
                                  if ($space->tag_id === null || $space->tag_name != $space->form_name) { // ICI POUR DISABLED
                                      $disabled = 'disabled'; ?>
                                    <div class="bouton_money centrar" id="generate-<?= $space->ad_id ?>-<?= $themoney_website->site_id ?>" onclick="generateTag(<?= $space->ad_id ?>, <?= $themoney_website->site_id; ?>)"><?php _e('Générer le script','themoneytizer'); ?></div>
                                  <?php }
                              }
                          }

                          if ($space->tag_actif == 0 && $space->form_state != 0) { ?>
                            <div class="bouton_money centrar" onclick="reactivateTag(<?= $space->tag_id ?>)"><?php _e('Réactiver le tag','themoneytizer'); ?></div>
                          <?php } ?>
                      </td>
                        <?php if($themoney_automatic && $space->form_state != 0){
                            if ($space->form_state == 1 || in_array($space->form_state, [0, 1])) {
                                $disabled = 'disabled';
                            }
                          ?>
                          <td style='text-align: center'>
                            <input class='checkbox_format beautiful_checkbox_themoneytizer' name='formatauto[]' id='<?= $space->ad_id ?>' value='<?= $themoney_website->site_id.'-'.$space->ad_id ?>' type='checkbox' <?php echo in_array($space->ad_id,$registered_format) ? 'checked' : ''; ?> <?php echo $disabled ?> >
                            <label for='<?= $space->ad_id ?>'></label>
                          </td>
                        <?php	} else { ?>
                          <td></td>
                        <?php } if(!$themoney_automatic && $space->form_state != 0){ ?>
                          <td><input style='width:100%' onFocus='this.select()' type='text' value='[themoneytizer id="<?= $token = $themoney_website->site_id; ?>-<?= $space->ad_id; ?>"]' <?php echo $disabled?>></td>
                        <?php }else{ ?>
                          <td></td>
                        <?php } ?>
                          <td>
                              <?php if ($space->form_state != 0) { ?>
                              <textarea
                              id="tag_<?= $space->tag_name === $space->form_name ? $space->tag_id : ''; ?>"
                              style='width: 100%; height: 100px;'
                              onclick='this.select()' <?php echo $space->tag_actif == 0 ? 'disabled' : ''; ?> <?php echo $disabled ?>><?= $space->tag_name === $space->form_name ? htmlentities($space->tag_text_asynch) : ''; ?></textarea>
                              <?php }  ?>
                          </td>
                    </tr>
                      <?php
                  }
              }

              // demande reco et skin
              if (!empty($arr_rec_skin[0])) {
                  if (!in_array(16, $arr_rec_skin)){
                      array_push($displayed_formats, 16); ?>
                    <tr>
                      <td style="text-align: center">
                        <img style="width:100px;" src="<?= $themoney_website->path_format_img . 'recocontenu.png' ?>" alt="RECO CONTENUS"/> <br>
                          <?= __('RECO CONTENUS','themoneytizer') ?>
                      </td>
                      <td>
                          <?php if ($form_state_skin_reco['RECO'][0] == 0 && !empty($form_state_skin_reco['RECO'][0])) { ?>
                            <div class="bouton_money centrar" style="cursor: default"><?php _e('Refusé','themoneytizer'); ?></div>
                          <?php } else { ?>
                            <div class="bouton_money centrar" onclick="addFormat(16, <?= $themoney_website->site_id; ?>)"><?php _e('Demander le format','themoneytizer'); ?></div>
                          <?php } ?>
                      </td>

                      <td></td>

                      <td>
                        <input style='width:100%' onFocus='this.select()' type='text' value='[themoneytizer id="<?= $token = $themoney_website->site_id; ?>-16"]' disabled>
                      </td>

                      <td>
                        <textarea id="tag_" style='width: 100%; height: 100px;' onclick='this.select()' disabled></textarea>
                      </td>
                    </tr>
                      <?php
                  }
                  if (!in_array(5, $arr_rec_skin)){
                      array_push($displayed_formats, 5); ?>
                    <tr>
                      <td style="text-align: center">
                        <img style="width:100px;" src="<?= $themoney_website->path_format_img . 'habillage.png' ?>" alt="HABILLAGE"/> <br>
                          <?= __('HABILLAGE','themoneytizer') ?>
                      </td>
                      <td>
                          <?php if ($form_state_skin_reco['SKIN'][0] == 0) { ?>
                            <div class="bouton_money centrar" style="cursor: default"><?php _e('Refusé','themoneytizer'); ?></div>
                          <?php } else { ?>
                            <div class="bouton_money centrar" onclick="addFormat(5, <?= $themoney_website->site_id; ?>)"><?php _e('Demander le format','themoneytizer'); ?></div>
                          <?php } ?>
                      </td>

                      <td></td>

                      <td></td>

                      <td>
                        <textarea id="tag_" style='width: 100%; height: 100px;' onclick='this.select()' disabled></textarea>
                      </td>
                    </tr>
                  <?php }
              }

              // format non demandé (ancien sites)
              foreach ($themoney_website->formats_authorized as $format) {
                  if (!in_array($format->ad_id, $displayed_formats)) { ?>
                    <tr>
                      <td style="text-align: center">
                        <img style="width:100px;" src="<?= $themoney_website->path_format_img . $space->ad_img ?>" alt="<?= $format->ad_name ?>"/> <br>
                          <?= __($format->ad_name,'themoneytizer') ?>
                      </td>
                      <td>
                        <div class="bouton_money centrar" id="generate-<?= $format->ad_id ?>-<?= $themoney_website->site_id ?>" onclick="generateTag(<?= $format->ad_id ?>, <?= $themoney_website->site_id; ?>)">
                            <?php _e('Générer le script','themoneytizer'); ?>
                        </div>
                      </td>

                      <td></td>
                      <td></td>

                      <td>
                    <textarea
                        id="tag_"
                        style='width: 100%; height: 100px;'
                        onclick='this.select()' disabled></textarea>
                      </td>
                    </tr>
                  <?php }
              }

              // we provide adcash for all sites so we display it if it's not yet
              if (!in_array(39, $displayed_formats)) {
                  array_push($displayed_formats, 39); ?>

                <tr>
                  <td style="text-align: center">
                    <img style="width:100px;" src="<?= $themoney_website->path_format_img . 'pop.png' ?>" alt="POP"/> <br>
                      <?= __('POP','themoneytizer') ?>
                  </td>
                  <td>
                    <div class="bouton_money centrar" id="generate-39-<?= $themoney_website->site_id ?>" onclick="generateTag(39, <?= $themoney_website->site_id; ?>)">
                      Générer le script
                    </div>
                  </td>

                  <td style="text-align: center">
                    <input class='checkbox_format beautiful_checkbox_themoneytizer' name='formatauto[]' id='39'
                           value='<?= $themoney_website->site_id . '-39'?>'
                           type='checkbox' <?php echo in_array(39, $registered_format) ? 'checked' : ''; ?> <?php echo $disabled ?> >
                    <label for='39'></label>
                  </td>

                  <td></td>

                  <td>
                    <textarea id="tag_" style='width: 100%; height: 100px;' onclick='this.select()' disabled></textarea>
                  </td>
                </tr>
                <?php
              }
          }
          else {
              foreach ($themoney_spaces as $space) {
                  if ($space->ad_id == 39) { ?>
                    <tr>
                      <td style="text-align: center">
                        <img style="width:100px;" src="<?= $themoney_website->path_format_img . 'pop.png' ?>" alt="POP"/> <br>
                          <?= __('POP', 'themoneytizer') ?>
                      </td>
                      <td>
                          <?php
                          if ($space->form_state == 0) {
                              $disabled = 'disabled'; ?>
                              <div class="bouton_money centrar" style="cursor: default"><?php _e('Refusé','themoneytizer'); ?></div>
                          <?php } else {
                              if ($space->tag_id === null || $space->tag_name != $space->form_name) { // ICI POUR DISABLED
                                $disabled = 'disabled'; ?>
                                <div class="bouton_money centrar" id="generate-39-<?= $themoney_website->site_id ?>" onclick="generateTag(39, <?= $themoney_website->site_id; ?>)">
                                  Générer le script
                                </div>
                              <?php }
                              if ($space->tag_actif === 0) { ?>
                                  <div class="bouton_money centrar" onclick="reactivateTag(<?= $space->tag_id ?>)">Réactiver le tag
                                  </div>
                              <?php }
                          } ?>
                      </td>
                      <td style='text-align: center'>
                          <?php if ($space->form_state != 0) { ?>
                            <input class='checkbox_format beautiful_checkbox_themoneytizer' name='formatauto[]' id='39'
                                   value='<?= $themoney_website->site_id . '-' . $space->ad_id ?>'
                                   type='checkbox' <?php echo in_array(39, $registered_format) ? 'checked' : ''; ?> <?php echo $disabled ?> >
                            <label for='39'></label>
                          <?php } ?>
                      </td>

                      <td></td>

                      <td>
                      <?php if ($space->form_state != 0) { ?>
                          <textarea
                          id="tag_<?= $space->tag_name === $space->form_name ? $space->tag_id : ''; ?>"
                          style='width: 100%; height: 100px;'
                          onclick='this.select()' <?php echo $space->tag_actif == 0 ? 'disabled' : ''; ?> <?php echo $disabled ?>><?= $space->tag_name === $space->form_name ? htmlentities($space->tag_text_asynch) : ''; ?></textarea>
                      <?php } ?>
                      </td>
                    </tr>
                      <?php
                  }
              }
          }
          ?>
          </tbody>
        </table>
        <input name='submit' type='submit' name='Submit' class='bouton_money' value="<?php _e('Enregistrer','themoneytizer');?>" style="margin:auto;display:block;margin-top:10px;" />
      </form><br/>
  <?php } ?>

</div>