Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    [freephp]Flat File Database Manager + invio email

    Ciao a tutti,
    avrei un problema e vi chiedo gentilmente una mano.

    Sto utilizzando lo script gratuito Flat File Database Manager , uno dei pochi che non ho prelevato dal vostro sito, e vorrei utilizzarlo in maniera particolare, vi spiego:

    Questo script permette di aggiungere dei dati in un database fatto su file di testo.
    Quello che vorrei fare è inserire un invio email ogni qualvolta viene aggiornato il database.
    Ho già utilizzato altre volte la funzione mail in PHP, ma in questo caso non so proprio come piazzarla.

    Grazie mille a chiunque mi aiuterà in anticipo.

    Vi posto il codice:

    PAGINA PRINCIPALE
    codice:
    <?php
    
    // Database file, i.e. file with real data
    $data_file = 'formazione.txt';
    
    // Database definition file. You have to describe database format in this file.
    // See flatfile.inc.php header for sample.
    $structure_file = 'giocatori.def';
    
    // Fields delimiter
    $delimiter = '  |  ';
    
    // Number of header lines to skip. This is needed if you have some heder saved in the 
    // database file, like comment or description
    $skip_lines = 0;
    
    // run flatfile manager
    include ('flatfile.inc.php');
    
    ?>
    CORE DELLO SCRIPT:
    codice:
    <?php
    
    #####################################################################################
    # Flat File Database Manager 1.2
    #####################################################################################
    # Visit http://www.zubrag.com/scripts/ for updates
    #####################################################################################
    # Expects:
    #
    # Database file name, i.e. file with real data
    # --> $data_file
    #####################################################################################
    # Database definition file. You have to describe database format in this file.
    # Each row describes one field
    # Allowed data types: 
    # STRING:  Rendered as regular input field. Row format:
    #          title,STRING,length
    # TEXT:    Rendered as text area. Row format:
    #          title,TEXT,columns,rows
    # LOGICAL: Rendered as check box (flag). Row format:
    #          title,LOGICAL,1,value for Yes,value for No
    # LIST:    Rendered as list box or combo box. Row format:
    #          title,LIST,number of rows visible at a time,colon ":" separated allowed values
    #
    # Sample data definition file contents:
    # City,LIST,3,City1:City2:City3:City4:City5
    # State,LIST,1,NY:CA:LA
    # Zip,STRING,8
    # Active,LOGICAL,1,Y:N
    # Comments,TEXT,30:2
    # --> $structure_file
    ######################################################################################
    # Fields delimiter
    # --> $delimiter
    #####################################################################################
    
    // strip slashes
    if (get_magic_quotes_gpc()) {
      function stripslashes_deep($value) {
        $value = is_array($value) ? array_map('stripslashes_deep', $value) : (isset($value) ? stripslashes($value) : null);
        return $value;
      }
    
      $_POST = stripslashes_deep($_POST);
      $_GET = stripslashes_deep($_GET);
      //$_COOKIE = stripslashes_deep($_COOKIE);
    }
    
    $structure_tmp = file($structure_file);
    $structure = array();
    foreach($structure_tmp as $key=>$tmp) {
      /*if(strpos($tmp,':') === 0) {
        $code = explode(':',$tmp);
        ${$code[1]} = trim($code[2]);
        continue;
      }*/
      $line = explode(',',$tmp);
      $name_will_be = str_replace(' ','',trim($line[0]));
      foreach($structure as $key1=>$value1) {
        if ($value1['name'] == $name_will_be)
          die("Few columns have the similar name (not counting spaces): '{$line[0]}'. Please rename.");
      }
      $structure[$key]['name_original'] = trim($line[0]);
      $structure[$key]['name'] = str_replace(' ','',$structure[$key]['name_original']);
      $structure[$key]['type'] = trim($line[1]);
      if (isset($line[2])) $structure[$key]['format'] = trim($line[2]);
      if (isset($line[3])) {
        $values = explode(':',$line[3]);
        foreach($values as $item) {
          $structure[$key]['values'][] = trim($item);
        }
      }
    }
    
    // Save data (Submit button pressed)
    if (isset($_POST['submit'])) {
      /////////////////////////////////////////////////
    
      if ($skip_lines > 0) {
        // read header lines
        $tmp_data = file($data_file);
      }
    
      $f = fopen($data_file,'w+');
      if ($f) {
    
        // save header back to file
        if ($skip_lines > 0) {
          for($i=0; $i < $skip_lines; $i++) {
            fputs($f,$tmp_data[$i]);
          }
        }
    
        for( $i=0; $i < count($_POST[$structure[0]['name']]); $i++ ) {
          // do not save records marked for delete
          if (isset($_POST['d_e_l_e_t_e'][$i])) continue;
    
          $s = '';
          $isfirst = true;
          foreach($structure as $key => $field) {
            $n1 = isset($_POST[$structure[$key]['name']]) ? $_POST[$structure[$key]['name']] : '';
            $v1 = isset($n1[$i]) ? $n1[$i] : $structure[$key]['values'][1];
            // remove new line characters as each new line represents new database row
            $v1 = str_replace(array("\r\n","\n","\r"),'',$v1);
            $s = $s . ($isfirst ? '' : $delimiter) . $v1;
            $isfirst = false;
          }
          // do not save empty lines
          if (trim(str_replace($delimiter,'',$s)) == '') continue;
    
          // save database record to file
          fputs($f,$s."\n");
        } // for
        fclose($f);
      } // if
      
    }
    
    $data = file($data_file);
    
    // skip header lines
    if ($skip_lines > 0) $data = array_slice($data, $skip_lines);
    
    // add "new line" holder
    $data[] = str_repeat($delimiter,count($structure)-1);
    
    echo '<html>';
    echo "<head><title>$data_file</title></head>";
    echo "<body><h1>$data_file</h1>";
    echo '<form method="post">';
    echo '<table>'."\n";
    
    
    // output header
    echo '<tr style="background: #AAAAAA; border: 1px solid blue">';
    foreach ($structure as $key=>$line) {
      echo "<th>{$line['name_original']}</th>";
    }
    echo '<th>Mark</th>';
    echo '</tr>'."\n";
    
    // output data
    foreach($data as $datakey => $line) {
    
      // skip empty rows
      if (trim($line) == '') continue;
    
      echo '<tr style="background: #'.($datakey % 2 == 0 ? 'F0F0F0' : 'FAFAFA').'">';
    
      $items = explode($delimiter,$line);
    
      // any fields not defined? add empty
      while (count($items) < count($structure))
        $items[] = '';
    
      foreach ($items as $key => $item) {
        $item = htmlspecialchars(trim($item));
        $name = $structure[$key]['name'];
        echo "\n".'  <td valign="top">';
        switch ($structure[$key]['type']) {
          case 'STRING':
            echo '<input onchange="cdf('.$datakey.')" name="'.$name.'['.$datakey.']" value="'.$item.'" size="'.$structure[$key]['format'].'" />';
            break;
          case 'TEXT':
            $rc = explode(':',$structure[$key]['format']);
            $cols = trim($rc[0]);
            $rows = trim($rc[1]);
            echo '<textarea onchange="cdf('.$datakey.')" name="'.$name.'['.$datakey.']" rows="'.$rows.'" cols="'.$cols.'">'.$item.'</textarea>';
            break;
          case 'LOGICAL':
            $val_yes = trim($structure[$key]['values'][0]);
            echo '<input onchange="cdf('.$datakey.')" name="'.$name.'['.$datakey.']" type="checkbox" '.(($item == $val_yes) ? 'checked' : '').' value="'.$val_yes.'" />';
            break;
          case 'LIST':
            echo '<select onchange="cdf('.$datakey.')" name="'.$name.'['.$datakey.']" size="'.$structure[$key]['format'].'">';
            foreach($structure[$key]['values'] as $value) {
              echo '<option value="'.$value.'" '.($value == $item ? 'selected' : '').'>'.$value.'</option>';
            }
            echo '</select>';
            break;
        }
        echo '</td>';
      }
      
      // Mark for delete if last record (i.e. Add option). In this way we'll skip adding empty records
      echo "\n  <td><input id='d_e_l_e_t_e[{$datakey}]'  name='d_e_l_e_t_e[{$datakey}]' type='checkbox' ".($datakey == count($data)-1 ? 'checked' : '')." /></td>";
      echo "\n</tr>\n";
    
    }
    
    
    
    echo '<tr><td colspan=255 align=center><input type="submit" name="submit" value="Save Changes and Delete marked" style="border:1px solid red"></td></tr>';
    echo '</table>';
    echo "</form>
    
    <script>
    function cdf(theid) {
    document.getElementById('d_e_l_e_t_e['+theid+']').checked = false;
    }
    </script>";
    
    echo '</body>';
    echo '</html>';
    ?>
    All'interno di quest'ultimo vorrei inserire una funzione "mail" per inviare i record aggiunti/modificati/rimossi:
    codice:
      /* Per inviare email in formato HTML, si deve impostare l'intestazione Content-type. */
    $Subject = "Prova\r\n";
    $Body = "<a href=\"http://fmiosito.com/$data_file\">formazione</a>";
    $intestazioni  = "MIME-Version: 1.0\r\n";
    $intestazioni .= "Content-type: text/html; charset=iso-8859-1\r\n";
    
    /* intestazioni addizionali */
    $intestazioni .= "To: admin <paolo@paolo.it>\r\n";
    $intestazioni .= "From: admin <paolo@paolo.it>\r\n";
    $intestazioni .= "Cc: paolo@paolo.it\r\n";
    $intestazioni .= "Bcc: paolo@paolo.it\r\n";
    
    // send email 
    $success = mail($Subject, $Body, $intestazioni);
    Grazie milleeeee!

  2. #2
    Nessuno ha idee?
    ... io ci ho sbattuto la testa, ma nulla!

    Ho trovato un modo, attraverso una pagina per formattare i dati, ma nel caso qualcuno saprebbe dirmi almeno come posso inviarla via email?
    Vi allego questo ultimo sorgente "leggi.php":
    codice:
    <?php
    $userinfo = file("formazione.txt");
    
       echo '<table>';
    
    foreach($userinfo as $key => $val) 
    {
       //explode that data into a new array:  
       $data[$key] = explode("||", $val);
    }
    
    for($k = 0; $k < sizeof($userinfo); $k++) 
    { 
       echo '<tr><td>Nome:</td><td>[b]'.$data[$k][0].'[b]</td></tr>';
       echo '<tr><td>Confermato:</td><td>'.$data[$k][1].'</td></tr>';
       echo '<tr><td>Note:</td><td>'.$data[$k][2].'</td></tr>';
       echo '<tr><td colspan=2> </td></tr>';
       
    
    }
    
       echo '</table>';
    ?>
    Grazie

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.